From 2d54604fd2ea37781cc721f20b880cb4fd7a1c09 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sun, 19 Jul 2015 19:27:20 +0200 Subject: [PATCH 1/3] Some redesign for split cards. --- Mage/src/mage/cards/Card.java | 106 +++++++----- Mage/src/mage/cards/SplitCard.java | 177 ++------------------- Mage/src/mage/cards/SplitCardHalf.java | 16 ++ Mage/src/mage/cards/SplitCardHalfImpl.java | 81 ++++++++++ 4 files changed, 178 insertions(+), 202 deletions(-) create mode 100644 Mage/src/mage/cards/SplitCardHalf.java create mode 100644 Mage/src/mage/cards/SplitCardHalfImpl.java diff --git a/Mage/src/mage/cards/Card.java b/Mage/src/mage/cards/Card.java index 91217b0c02..6e5ec8c1d3 100644 --- a/Mage/src/mage/cards/Card.java +++ b/Mage/src/mage/cards/Card.java @@ -1,31 +1,30 @@ /* -* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, are -* permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, this list of -* conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright notice, this list -* of conditions and the following disclaimer in the documentation and/or other materials -* provided with the distribution. -* -* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR -* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -* -* The views and conclusions contained in the software and documentation are those of the -* authors and should not be interpreted as representing official policies, either expressed -* or implied, of BetaSteward_at_googlemail.com. -*/ - + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ package mage.cards; import java.util.ArrayList; @@ -33,7 +32,6 @@ import java.util.List; import java.util.UUID; import mage.MageObject; import mage.Mana; -import mage.ObjectColor; import mage.abilities.Abilities; import mage.abilities.Ability; import mage.abilities.SpellAbility; @@ -46,26 +44,45 @@ import mage.game.Game; public interface Card extends MageObject { UUID getOwnerId(); + int getCardNumber(); + Rarity getRarity(); + void setOwnerId(UUID ownerId); + public Abilities getAbilities(Game game); + void setSpellAbility(SpellAbility ability); + SpellAbility getSpellAbility(); + List getRules(); // gets base card rules + List getRules(Game game); // gets card rules + in game modifications + String getExpansionSetCode(); + String getTokenSetCode(); + void setFaceDown(boolean value, Game game); + boolean isFaceDown(Game game); + boolean turnFaceUp(Game game, UUID playerId); + boolean turnFaceDown(Game game, UUID playerId); + boolean isFlipCard(); + String getFlipCardName(); + boolean isSplitCard(); boolean canTransform(); + Card getSecondCardFace(); + boolean isNightCard(); void assignNewId(); @@ -74,14 +91,18 @@ public interface Card extends MageObject { /** * Moves the card to the specified zone + * * @param zone * @param sourceId * @param game * @param flag If zone *
    - *
  • LIBRARY:
    • true - put on top
    • false - put on bottom
  • - *
  • BATTLEFIELD:
    • true - tapped
    • false - untapped
  • - *
  • GRAVEYARD:
    • true - not from Battlefield
    • false - from Battlefield
  • + *
  • LIBRARY:
    • true - put on top
    • false - put on + * bottom
  • + *
  • BATTLEFIELD:
    • true - tapped
    • false - + * untapped
  • + *
  • GRAVEYARD:
    • true - not from Battlefield
    • false - from + * Battlefield
  • *
* @return true if card was moved to zone */ @@ -91,6 +112,7 @@ public interface Card extends MageObject { /** * Moves the card to an exile zone + * * @param exileId set to null for generic exile zone * @param name used for exile zone with the specified exileId * @param sourceId @@ -98,15 +120,19 @@ public interface Card extends MageObject { * @return true if card was moved to zone */ boolean moveToExile(UUID exileId, String name, UUID sourceId, Game game); - + boolean moveToExile(UUID exileId, String name, UUID sourceId, Game game, ArrayList appliedEffects); - boolean cast(Game game, Zone fromZone, SpellAbility ability, UUID controllerId); + boolean putOntoBattlefield(Game game, Zone fromZone, UUID sourceId, UUID controllerId); + boolean putOntoBattlefield(Game game, Zone fromZone, UUID sourceId, UUID controllerId, boolean tapped); + boolean putOntoBattlefield(Game game, Zone fromZone, UUID sourceId, UUID controllerId, boolean tapped, boolean facedown); + boolean putOntoBattlefield(Game game, Zone fromZone, UUID sourceId, UUID controllerId, boolean tapped, boolean facedown, ArrayList appliedEffects); + List getMana(); void build(); @@ -116,24 +142,30 @@ public interface Card extends MageObject { * @return true if there exists various art images for this card */ boolean getUsesVariousArt(); + Counters getCounters(Game game); void addCounters(String name, int amount, Game game); + void addCounters(String name, int amount, Game game, ArrayList appliedEffects); + void addCounters(Counter counter, Game game); + void addCounters(Counter counter, Game game, ArrayList appliedEffects); void removeCounters(String name, int amount, Game game); + void removeCounters(Counter counter, Game game); - + @Override Card copy(); - + /** * - * @return The main card of a split half card, otherwise thae card itself is returned + * @return The main card of a split half card, otherwise thae card itself is + * returned */ Card getMainCard(); - void setZone(Zone zone, Game game); + void setZone(Zone zone, Game game); } diff --git a/Mage/src/mage/cards/SplitCard.java b/Mage/src/mage/cards/SplitCard.java index 1bfe550d54..7aef9b2756 100644 --- a/Mage/src/mage/cards/SplitCard.java +++ b/Mage/src/mage/cards/SplitCard.java @@ -25,7 +25,6 @@ * authors and should not be interpreted as representing official policies, either expressed * or implied, of BetaSteward_at_googlemail.com. */ - package mage.cards; import java.util.ArrayList; @@ -53,9 +52,9 @@ public abstract class SplitCard extends CardImpl { protected Card rightHalfCard; public SplitCard(UUID ownerId, int cardNumber, String nameLeft, String nameRight, Rarity rarity, CardType[] cardTypes, String costsLeft, String costsRight, boolean fused) { - super(ownerId, cardNumber, new StringBuilder(nameLeft).append(" // ").append(nameRight).toString(), rarity, cardTypes, costsLeft + costsRight, (fused ?SpellAbilityType.SPLIT_FUSED:SpellAbilityType.SPLIT)); - this.createLeftHalfCard(nameLeft, costsLeft); - this.createRightHalfCard(nameRight, costsRight); + super(ownerId, cardNumber, new StringBuilder(nameLeft).append(" // ").append(nameRight).toString(), rarity, cardTypes, costsLeft + costsRight, (fused ? SpellAbilityType.SPLIT_FUSED : SpellAbilityType.SPLIT)); + leftHalfCard = new SplitCardHalfImpl(this.getOwnerId(), this.getCardNumber(), nameLeft, this.rarity, cardTypes, costsLeft, this, SpellAbilityType.SPLIT_LEFT); + rightHalfCard = new SplitCardHalfImpl(this.getOwnerId(), this.getCardNumber(), nameRight, this.rarity, cardTypes, costsRight, this, SpellAbilityType.SPLIT_RIGHT); this.splitCard = true; } @@ -65,29 +64,11 @@ public abstract class SplitCard extends CardImpl { this.rightHalfCard = card.rightHalfCard.copy(); } - private Card createLeftHalfCard (String nameLeft, String costsLeft) { - CardType[] cardTypes = new CardType[getCardType().size()]; - this.getCardType().toArray(cardTypes); - leftHalfCard = new LeftHalfCard(this.getOwnerId(), this.getCardNumber(), nameLeft, this.rarity, cardTypes, costsLeft, this); - //leftHalfCard.getAbilities().setSourceId(objectId); + public Card getLeftHalfCard() { return leftHalfCard; } - private Card createRightHalfCard (String nameRight, String costsRight) { - CardType[] cardTypes = new CardType[getCardType().size()]; - this.getCardType().toArray(cardTypes); - rightHalfCard = new RightHalfCard(this.getOwnerId(), this.getCardNumber(), nameRight, this.rarity, cardTypes, costsRight, this); - //rightHalfCard.getAbilities().setSourceId(objectId); - return rightHalfCard; - } - - - - public Card getLeftHalfCard () { - return leftHalfCard; - } - - public Card getRightHalfCard () { + public Card getRightHalfCard() { return rightHalfCard; } @@ -114,7 +95,7 @@ public abstract class SplitCard extends CardImpl { @Override public boolean cast(Game game, Zone fromZone, SpellAbility ability, UUID controllerId) { - switch(ability.getSpellAbilityType()) { + switch (ability.getSpellAbilityType()) { case SPLIT_LEFT: return this.getLeftHalfCard().cast(game, fromZone, ability, controllerId); case SPLIT_RIGHT: @@ -131,17 +112,16 @@ public abstract class SplitCard extends CardImpl { game.setZone(getRightHalfCard().getId(), zone); } - @Override - public Abilities getAbilities(){ + public Abilities getAbilities() { Abilities allAbilites = new AbilitiesImpl<>(); for (Ability ability : super.getAbilities()) { - if (ability instanceof SpellAbility && !((SpellAbility)ability).getSpellAbilityType().equals(SpellAbilityType.SPLIT)) { + if (ability instanceof SpellAbility && !((SpellAbility) ability).getSpellAbilityType().equals(SpellAbilityType.SPLIT)) { allAbilites.add(ability); } } allAbilites.addAll(leftHalfCard.getAbilities()); - allAbilites.addAll(rightHalfCard.getAbilities()); + allAbilites.addAll(rightHalfCard.getAbilities()); return allAbilites; } @@ -149,15 +129,15 @@ public abstract class SplitCard extends CardImpl { public Abilities getAbilities(Game game) { Abilities allAbilites = new AbilitiesImpl<>(); for (Ability ability : super.getAbilities(game)) { - if (ability instanceof SpellAbility && !((SpellAbility)ability).getSpellAbilityType().equals(SpellAbilityType.SPLIT)) { + if (ability instanceof SpellAbility && !((SpellAbility) ability).getSpellAbilityType().equals(SpellAbilityType.SPLIT)) { allAbilites.add(ability); } } allAbilites.addAll(leftHalfCard.getAbilities(game)); - allAbilites.addAll(rightHalfCard.getAbilities(game)); + allAbilites.addAll(rightHalfCard.getAbilities(game)); return allAbilites; } - + @Override public List getRules() { List rules = new ArrayList<>(); @@ -179,136 +159,3 @@ public abstract class SplitCard extends CardImpl { } } - -/* - * The left side card of the split card - */ -class LeftHalfCard extends CardImpl { - - SplitCard splitCardParent; - - public LeftHalfCard(UUID ownerId, int cardNumber, String name, Rarity rarity, CardType[] cardTypes, String costs, SplitCard splitCardParent) { - super(ownerId, cardNumber, name, rarity, cardTypes, costs, SpellAbilityType.SPLIT_LEFT); - this.splitCardParent = splitCardParent; - } - - public LeftHalfCard(final LeftHalfCard card) { - super(card); - this.splitCardParent = card.splitCardParent; - } - - @Override - public LeftHalfCard copy() { - return new LeftHalfCard(this); - } - - @Override - public UUID getOwnerId() { - return splitCardParent.getOwnerId(); - } - - @Override - public String getImageName() { - return splitCardParent.getImageName(); - } - - @Override - public String getExpansionSetCode() { - return splitCardParent.getExpansionSetCode(); - } - - @Override - public int getCardNumber() { - return splitCardParent.getCardNumber(); - } - - @Override - public boolean moveToZone(Zone toZone, UUID sourceId, Game game, boolean flag, ArrayList appliedEffects) { - return splitCardParent.moveToZone(toZone, sourceId, game, flag, appliedEffects); - } - - @Override - public boolean moveToExile(UUID exileId, String name, UUID sourceId, Game game, ArrayList appliedEffects) { - return splitCardParent.moveToExile(exileId, name, sourceId, game, appliedEffects); - } - - @Override - public Card getMainCard() { - return splitCardParent; - } - - @Override - public void setZone(Zone zone, Game game) { - super.setZone(zone, game); - game.setZone(splitCardParent.getId(), zone); - game.setZone(splitCardParent.getRightHalfCard().getId(), zone); - } - - -} - -/* - * The right side card of the split card - */ -class RightHalfCard extends CardImpl { - - SplitCard splitCardParent; - - public RightHalfCard(UUID ownerId, int cardNumber, String name, Rarity rarity, CardType[] cardTypes, String costs, SplitCard splitCardParent) { - super(ownerId, cardNumber, name, rarity, cardTypes, costs, SpellAbilityType.SPLIT_RIGHT); - this.splitCardParent = splitCardParent; - } - - public RightHalfCard(final RightHalfCard card) { - super(card); - this.splitCardParent = card.splitCardParent; - } - - @Override - public RightHalfCard copy() { - return new RightHalfCard(this); - } - - @Override - public UUID getOwnerId() { - return splitCardParent.getOwnerId(); - } - - @Override - public String getImageName() { - return splitCardParent.getImageName(); - } - - @Override - public String getExpansionSetCode() { - return splitCardParent.getExpansionSetCode(); - } - - @Override - public int getCardNumber() { - return splitCardParent.getCardNumber(); - } - - @Override - public boolean moveToZone(Zone toZone, UUID sourceId, Game game, boolean flag, ArrayList appliedEffects) { - return splitCardParent.moveToZone(toZone, sourceId, game, flag, appliedEffects); - } - - @Override - public boolean moveToExile(UUID exileId, String name, UUID sourceId, Game game, ArrayList appliedEffects) { - return splitCardParent.moveToExile(exileId, name, sourceId, game, appliedEffects); - } - - @Override - public Card getMainCard() { - return splitCardParent; - } - - @Override - public void setZone(Zone zone, Game game) { - super.setZone(zone, game); - game.setZone(splitCardParent.getId(), zone); - game.setZone(splitCardParent.getLeftHalfCard().getId(), zone); - } - -} diff --git a/Mage/src/mage/cards/SplitCardHalf.java b/Mage/src/mage/cards/SplitCardHalf.java new file mode 100644 index 0000000000..52fa1086bb --- /dev/null +++ b/Mage/src/mage/cards/SplitCardHalf.java @@ -0,0 +1,16 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package mage.cards; + +/** + * + * @author LevelX2 + */ +public interface SplitCardHalf extends Card { + + @Override + Card copy(); +} diff --git a/Mage/src/mage/cards/SplitCardHalfImpl.java b/Mage/src/mage/cards/SplitCardHalfImpl.java new file mode 100644 index 0000000000..af6cc3f6ab --- /dev/null +++ b/Mage/src/mage/cards/SplitCardHalfImpl.java @@ -0,0 +1,81 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package mage.cards; + +import java.util.ArrayList; +import java.util.UUID; +import mage.constants.CardType; +import mage.constants.Rarity; +import mage.constants.SpellAbilityType; +import mage.constants.Zone; +import mage.game.Game; + +/** + * + * @author LevelX2 + */ +public class SplitCardHalfImpl extends CardImpl implements SplitCardHalf { + + SplitCard splitCardParent; + + public SplitCardHalfImpl(UUID ownerId, int cardNumber, String name, Rarity rarity, CardType[] cardTypes, String costs, SplitCard splitCardParent, SpellAbilityType spellAbilityType) { + super(ownerId, cardNumber, name, rarity, cardTypes, costs, spellAbilityType); + this.splitCardParent = splitCardParent; + } + + public SplitCardHalfImpl(final SplitCardHalfImpl card) { + super(card); + this.splitCardParent = card.splitCardParent; + } + + @Override + public UUID getOwnerId() { + return splitCardParent.getOwnerId(); + } + + @Override + public String getImageName() { + return splitCardParent.getImageName(); + } + + @Override + public String getExpansionSetCode() { + return splitCardParent.getExpansionSetCode(); + } + + @Override + public int getCardNumber() { + return splitCardParent.getCardNumber(); + } + + @Override + public boolean moveToZone(Zone toZone, UUID sourceId, Game game, boolean flag, ArrayList appliedEffects) { + return splitCardParent.moveToZone(toZone, sourceId, game, flag, appliedEffects); + } + + @Override + public boolean moveToExile(UUID exileId, String name, UUID sourceId, Game game, ArrayList appliedEffects) { + return splitCardParent.moveToExile(exileId, name, sourceId, game, appliedEffects); + } + + @Override + public Card getMainCard() { + return splitCardParent; + } + + @Override + public void setZone(Zone zone, Game game) { + game.setZone(splitCardParent.getId(), zone); + game.setZone(splitCardParent.getLeftHalfCard().getId(), zone); + game.setZone(splitCardParent.getRightHalfCard().getId(), zone); + } + + @Override + public SplitCardHalfImpl copy() { + return new SplitCardHalfImpl(this); + } + +} From 0df798393788c6b5bb48760d0f12506b12012444 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sun, 19 Jul 2015 19:27:49 +0200 Subject: [PATCH 2/3] Added some test. --- .../org/mage/test/AI/basic/CombatTest.java | 2 + .../test/AI/basic/TriggeredAbilityTest.java | 47 +++++++++++ .../test/cards/single/OmniscienceTest.java | 83 ++++++++++++++----- 3 files changed, 110 insertions(+), 22 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/AI/basic/TriggeredAbilityTest.java diff --git a/Mage.Tests/src/test/java/org/mage/test/AI/basic/CombatTest.java b/Mage.Tests/src/test/java/org/mage/test/AI/basic/CombatTest.java index f95d8e9aab..4310dac892 100644 --- a/Mage.Tests/src/test/java/org/mage/test/AI/basic/CombatTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/AI/basic/CombatTest.java @@ -45,5 +45,7 @@ public class CombatTest extends CardTestPlayerBaseAI { * AI is not blocking also if able if the damage the attacker will do will kill the AI * AI is not able to block with two or more creatures one attacking creature to kill it. Even if none of the AI creatures will die * AI attacks with a flyer even if opponent has a bigger flyer that kills AI + * Opponent of AI has only 1 life. AI has more creatures that can attack taht do at least 1 damage than opponent has blockers. Ai should attack with all needed creatures + * */ } diff --git a/Mage.Tests/src/test/java/org/mage/test/AI/basic/TriggeredAbilityTest.java b/Mage.Tests/src/test/java/org/mage/test/AI/basic/TriggeredAbilityTest.java new file mode 100644 index 0000000000..16087622d1 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/AI/basic/TriggeredAbilityTest.java @@ -0,0 +1,47 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package org.mage.test.AI.basic; + +import org.mage.test.serverside.base.CardTestPlayerBaseAI; + +/** + * + * @author LevelX2 + */ +public class TriggeredAbilityTest extends CardTestPlayerBaseAI { + + /* + * + * TODO: Create tests and fix AI to be able to handle tested situations + * + * Tests to create: + * AI has the only one creature in play and plays a Gilt-Leaf Winnower. AI should select No if asked to use the destray effect becuase it targets the AI creature + * + * + */ +} diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/OmniscienceTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/OmniscienceTest.java index a75dbc61e3..ad4f7febe7 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/single/OmniscienceTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/OmniscienceTest.java @@ -25,11 +25,11 @@ * authors and should not be interpreted as representing official policies, either expressed * or implied, of BetaSteward_at_googlemail.com. */ - package org.mage.test.cards.single; import mage.constants.PhaseStep; import mage.constants.Zone; +import org.junit.Ignore; import org.junit.Test; import org.mage.test.serverside.base.CardTestPlayerBase; @@ -37,27 +37,24 @@ import org.mage.test.serverside.base.CardTestPlayerBase; * * @author LevelX2 */ - public class OmniscienceTest extends CardTestPlayerBase { /** - * Omniscience {7}{U}{U}{U} + * Omniscience {7}{U}{U}{U} * - * Enchantment - * You may cast nonland cards from your hand without paying their mana costs. + * Enchantment You may cast nonland cards from your hand without paying + * their mana costs. * */ - @Test public void testCastingCreature() { addCard(Zone.BATTLEFIELD, playerA, "Omniscience"); - - /* player.getPlayable does not take alternate - casting costs in account, so for the test the mana has to be available - but won't be used - */ - addCard(Zone.BATTLEFIELD, playerA, "Plains", 2); + /* player.getPlayable does not take alternate + casting costs in account, so for the test the mana has to be available + but won't be used + */ + addCard(Zone.BATTLEFIELD, playerA, "Plains", 2); addCard(Zone.HAND, playerA, "Silvercoat Lion"); @@ -80,7 +77,7 @@ public class OmniscienceTest extends CardTestPlayerBase { addCard(Zone.BATTLEFIELD, playerA, "Island", 1); addCard(Zone.BATTLEFIELD, playerA, "Mountain", 1); - + // Fire deals 2 damage divided as you choose among one or two target creatures and/or players. addCard(Zone.HAND, playerA, "Fire // Ice"); @@ -94,7 +91,7 @@ public class OmniscienceTest extends CardTestPlayerBase { assertLife(playerA, 20); assertLife(playerB, 18); - + assertTapped("Island", false); assertTapped("Mountain", false); } @@ -104,9 +101,9 @@ public class OmniscienceTest extends CardTestPlayerBase { addCard(Zone.BATTLEFIELD, playerA, "Omniscience"); /* player.getPlayable does not take alternate - casting costs in account, so for the test the mana has to be available - but won't be used - */ + casting costs in account, so for the test the mana has to be available + but won't be used + */ addCard(Zone.BATTLEFIELD, playerA, "Mountain", 2); addCard(Zone.BATTLEFIELD, playerA, "Ornithopter", 1); @@ -124,12 +121,13 @@ public class OmniscienceTest extends CardTestPlayerBase { assertGraveyardCount(playerA, "Ornithopter", 1); assertTapped("Mountain", false); } - /** - * Spell get cast for 0 if Omniscience is being in play. - * But with Trinisphere it costs at least {3}. - * Cost/alternate cost (Omniscience) + additional costs - cost reductions + minimum cost (Trinishpere) = total cost. - */ + /** + * Spell get cast for 0 if Omniscience is being in play. But with + * Trinisphere it costs at least {3}. Cost/alternate cost (Omniscience) + + * additional costs - cost reductions + minimum cost (Trinishpere) = total + * cost. + */ @Test public void testCastingWithTrinisphere() { addCard(Zone.BATTLEFIELD, playerA, "Omniscience"); @@ -153,4 +151,45 @@ public class OmniscienceTest extends CardTestPlayerBase { assertPermanentCount(playerA, "Silvercoat Lion", 1); assertTapped("Plains", true); // plains have to be tapped because {3} have to be paid } + + /** + * Omniscience is not allowing me to cast spells for free. I'm playing a + * Commander game against the Computer, if that helps. + * + * Edit: It's not letting me cast fused spells for free. Others seems to be + * working. + */ + @Test + @Ignore // targeting of fused/split spells not supported by thestplayer + public void testCastingFusedSpell() { + addCard(Zone.BATTLEFIELD, playerA, "Omniscience"); + addCard(Zone.BATTLEFIELD, playerA, "Island", 2); + addCard(Zone.BATTLEFIELD, playerA, "Swamp", 3); + addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion"); + + addCard(Zone.BATTLEFIELD, playerB, "Pillarfield Ox"); + + /* + * Instant + * Far {1}{U} Return target creature to its owner's hand. + * Away{2}{B} Target player sacrifices a creature. + * Fuse (You may cast one or both halves of this card from your hand.) + */ + addCard(Zone.HAND, playerA, "Far // Away"); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "fused Far // Away", "Silvercoat Lion^targetPlayer=PlayerB"); + playerB.addTarget("Pillarfield Ox"); + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertHandCount(playerA, 1); + assertHandCount(playerB, 0); + + assertGraveyardCount(playerA, "Far // Away", 1); + + assertPermanentCount(playerB, "Pillarfield Ox", 0); + assertGraveyardCount(playerB, "Pillarfield Ox", 1); + } + } From 4b0ae51c07a16ac0b160a205d415524497584809 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sun, 19 Jul 2015 19:28:46 +0200 Subject: [PATCH 3/3] * Omniscience - Workaround to be able to use Omniscience alternate casting cost for fused spells. --- .../src/mage/sets/magic2013/Omniscience.java | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/Mage.Sets/src/mage/sets/magic2013/Omniscience.java b/Mage.Sets/src/mage/sets/magic2013/Omniscience.java index 6c9b7cf932..1b2f082a67 100644 --- a/Mage.Sets/src/mage/sets/magic2013/Omniscience.java +++ b/Mage.Sets/src/mage/sets/magic2013/Omniscience.java @@ -28,7 +28,6 @@ package mage.sets.magic2013; import java.util.UUID; - import mage.MageObject; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; @@ -39,6 +38,7 @@ import mage.abilities.costs.AlternativeCostSourceAbility; import mage.abilities.effects.ContinuousEffectImpl; import mage.cards.Card; import mage.cards.CardImpl; +import mage.cards.SplitCardHalf; import mage.constants.CardType; import mage.constants.Duration; import mage.constants.Layer; @@ -61,7 +61,6 @@ public class Omniscience extends CardImpl { super(ownerId, 63, "Omniscience", Rarity.MYTHIC, new CardType[]{CardType.ENCHANTMENT}, "{7}{U}{U}{U}"); this.expansionSetCode = "M13"; - // You may cast nonland cards from your hand without paying their mana costs. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new OmniscienceCastingEffect())); } @@ -116,19 +115,18 @@ class OmniscienceCastingEffect extends ContinuousEffectImpl { class IsBeingCastFromHandCondition implements Condition { - @Override - public boolean apply(Game game, Ability source) { + @Override + public boolean apply(Game game, Ability source) { MageObject object = game.getObject(source.getSourceId()); - if(object instanceof Spell) { - Spell spell = (Spell) object; - return spell != null && spell.getFromZone() == Zone.HAND; - } - if(object instanceof Card) { - Card card = (Card)object; - return game.getPlayer(card.getOwnerId()).getHand().get(card.getId(), game) != null; - } - - return false; - } + if (object instanceof SplitCardHalf) { + UUID splitCardId = ((Card) object).getMainCard().getId(); + object = game.getObject(splitCardId); + } + if (object instanceof Spell) { + Spell spell = (Spell) object; + return spell.getFromZone() == Zone.HAND; + } + return false; + } }