From f13ba5d7fbc00b2ad623ed4989dce960980e246b Mon Sep 17 00:00:00 2001 From: magenoxx Date: Sun, 14 Aug 2011 10:30:26 +0400 Subject: [PATCH] More correct checking for having subtypes (card.hasSubtype()). Changeling ability. Refactored all cards. --- .../championsofkamigawa/AshenSkinZubera.java | 2 +- .../DrippingTongueZubera.java | 2 +- .../championsofkamigawa/EmberFistZubera.java | 2 +- .../FloatingDreamZubera.java | 2 +- .../SeshiroTheAnointed.java | 2 +- .../SilentChantZubera.java | 2 +- .../sets/magic2011/StormtideLeviathan.java | 2 +- .../sets/riseoftheeldrazi/EldraziTemple.java | 4 +- .../sets/scarsofmirrodin/MyrReservoir.java | 2 +- .../sets/scarsofmirrodin/PrecursorGolem.java | 2 +- .../src/mage/sets/shadowmoor/ReaperKing.java | 2 +- Mage.Sets/src/mage/sets/tenth/Juggernaut.java | 2 +- .../src/mage/sets/worldwake/EyeOfUgin.java | 2 +- .../sets/worldwake/KalastriaHighborn.java | 2 +- .../sets/zendikar/BladeOfTheBloodchief.java | 2 +- .../zendikar/ValakutTheMoltenPinnacle.java | 2 +- Mage/src/mage/MageObject.java | 1 + Mage/src/mage/MageObjectImpl.java | 22 +++++++ ...AllyEntersBattlefieldTriggeredAbility.java | 2 +- .../abilities/keyword/ChangelingAbility.java | 66 +++++++++++++++++++ Mage/src/mage/filter/FilterObject.java | 7 +- Mage/src/mage/game/command/Emblem.java | 5 ++ Mage/src/mage/game/stack/Spell.java | 5 ++ Mage/src/mage/game/stack/StackAbility.java | 5 ++ 24 files changed, 126 insertions(+), 21 deletions(-) create mode 100644 Mage/src/mage/abilities/keyword/ChangelingAbility.java diff --git a/Mage.Sets/src/mage/sets/championsofkamigawa/AshenSkinZubera.java b/Mage.Sets/src/mage/sets/championsofkamigawa/AshenSkinZubera.java index afed7041bda..8e21e38e9d3 100644 --- a/Mage.Sets/src/mage/sets/championsofkamigawa/AshenSkinZubera.java +++ b/Mage.Sets/src/mage/sets/championsofkamigawa/AshenSkinZubera.java @@ -100,7 +100,7 @@ class AshenSkinZuberaWatcher extends WatcherImpl { if (((ZoneChangeEvent) event).getFromZone() == Constants.Zone.BATTLEFIELD && ((ZoneChangeEvent) event).getToZone() == Constants.Zone.GRAVEYARD) { Card card = game.getLastKnownInformation(event.getTargetId(), Constants.Zone.BATTLEFIELD); - if (card != null && card.getSubtype().contains("Zubera")) { + if (card != null && card.hasSubtype("Zubera")) { zuberasDiedThisTurn++; } } diff --git a/Mage.Sets/src/mage/sets/championsofkamigawa/DrippingTongueZubera.java b/Mage.Sets/src/mage/sets/championsofkamigawa/DrippingTongueZubera.java index f11f2e537ce..e28f5c4386f 100644 --- a/Mage.Sets/src/mage/sets/championsofkamigawa/DrippingTongueZubera.java +++ b/Mage.Sets/src/mage/sets/championsofkamigawa/DrippingTongueZubera.java @@ -99,7 +99,7 @@ class DrippingTongueZuberaWatcher extends WatcherImpl { if (((ZoneChangeEvent) event).getFromZone() == Constants.Zone.BATTLEFIELD && ((ZoneChangeEvent) event).getToZone() == Constants.Zone.GRAVEYARD) { Card card = game.getLastKnownInformation(event.getTargetId(), Constants.Zone.BATTLEFIELD); - if (card != null && card.getSubtype().contains("Zubera")) { + if (card != null && card.hasSubtype("Zubera")) { zuberasDiedThisTurn++; } } diff --git a/Mage.Sets/src/mage/sets/championsofkamigawa/FloatingDreamZubera.java b/Mage.Sets/src/mage/sets/championsofkamigawa/FloatingDreamZubera.java index 834521718d8..6378855a472 100644 --- a/Mage.Sets/src/mage/sets/championsofkamigawa/FloatingDreamZubera.java +++ b/Mage.Sets/src/mage/sets/championsofkamigawa/FloatingDreamZubera.java @@ -98,7 +98,7 @@ class FloatingDreamZuberaWatcher extends WatcherImpl if (((ZoneChangeEvent) event).getFromZone() == Constants.Zone.BATTLEFIELD && ((ZoneChangeEvent) event).getToZone() == Constants.Zone.GRAVEYARD) { Card card = game.getLastKnownInformation(event.getTargetId(), Constants.Zone.BATTLEFIELD); - if (card != null && card.getSubtype().contains("Zubera")) { + if (card != null && card.hasSubtype("Zubera")) { zuberasDiedThisTurn++; } } diff --git a/Mage.Sets/src/mage/sets/championsofkamigawa/SeshiroTheAnointed.java b/Mage.Sets/src/mage/sets/championsofkamigawa/SeshiroTheAnointed.java index 4f65295fa3b..5f204abf6a2 100644 --- a/Mage.Sets/src/mage/sets/championsofkamigawa/SeshiroTheAnointed.java +++ b/Mage.Sets/src/mage/sets/championsofkamigawa/SeshiroTheAnointed.java @@ -100,7 +100,7 @@ class SeshiroTheAnointedAbility extends TriggeredAbilityImpl { if (((ZoneChangeEvent) event).getFromZone() == Constants.Zone.BATTLEFIELD && ((ZoneChangeEvent) event).getToZone() == Constants.Zone.GRAVEYARD) { Card card = game.getLastKnownInformation(event.getTargetId(), Constants.Zone.BATTLEFIELD); - if (card != null && card.getSubtype().contains("Zubera")) { + if (card != null && card.hasSubtype("Zubera")) { zuberasDiedThisTurn++; } } diff --git a/Mage.Sets/src/mage/sets/magic2011/StormtideLeviathan.java b/Mage.Sets/src/mage/sets/magic2011/StormtideLeviathan.java index d165adf9be3..af6976ab6ca 100644 --- a/Mage.Sets/src/mage/sets/magic2011/StormtideLeviathan.java +++ b/Mage.Sets/src/mage/sets/magic2011/StormtideLeviathan.java @@ -101,7 +101,7 @@ class StormtideLeviathanEffect extends ContinuousEffectImpl { Permanent permanent = game.getPermanent(targetId); if (permanent.getControllerId().equals(this.controllerId) && permanent.getCardType().contains(CardType.CREATURE) - && permanent.getSubtype().contains("Scarecrow") + && permanent.hasSubtype("Scarecrow") && !targetId.equals(this.getSourceId())) { return true; } diff --git a/Mage.Sets/src/mage/sets/tenth/Juggernaut.java b/Mage.Sets/src/mage/sets/tenth/Juggernaut.java index 3fcf352f017..a3fd57efdf0 100644 --- a/Mage.Sets/src/mage/sets/tenth/Juggernaut.java +++ b/Mage.Sets/src/mage/sets/tenth/Juggernaut.java @@ -102,7 +102,7 @@ class JuggernautEffect extends CantBlockSourceEffect { @Override public boolean canBeBlocked(Permanent attacker, Permanent blocker, Game game) { - return !blocker.getSubtype().contains("Wall"); + return !blocker.hasSubtype("Wall"); } @Override diff --git a/Mage.Sets/src/mage/sets/worldwake/EyeOfUgin.java b/Mage.Sets/src/mage/sets/worldwake/EyeOfUgin.java index 6b9265c0eec..3588917a341 100644 --- a/Mage.Sets/src/mage/sets/worldwake/EyeOfUgin.java +++ b/Mage.Sets/src/mage/sets/worldwake/EyeOfUgin.java @@ -115,7 +115,7 @@ class EyeOfUginCostReductionEffect extends CostModificationEffectImpl getCardType(); public List getSubtype(); + public boolean hasSubtype(String subtype); public List getSupertype(); public Abilities getAbilities(); diff --git a/Mage/src/mage/MageObjectImpl.java b/Mage/src/mage/MageObjectImpl.java index 749bfccf44f..2440c148de9 100644 --- a/Mage/src/mage/MageObjectImpl.java +++ b/Mage/src/mage/MageObjectImpl.java @@ -39,6 +39,7 @@ import mage.abilities.Ability; import mage.abilities.costs.mana.ManaCost; import mage.abilities.costs.mana.ManaCosts; import mage.abilities.costs.mana.ManaCostsImpl; +import mage.abilities.keyword.ChangelingAbility; import mage.game.Game; public abstract class MageObjectImpl> implements MageObject { @@ -150,4 +151,25 @@ public abstract class MageObjectImpl> implements Mag @Override public void adjustCosts(Ability ability, Game game) {} + @Override + public boolean hasSubtype(String subtype) { + if (subtype == null) { + return false; + } + if (subtype.contains(subtype)) { + return true; + } + else { // checking for Changeling + // first make sure input parameter is not creature type + // if so, then ChangelingAbility doesn't matter + if (subtype.equals("Mountain") || subtype.equals("Island") || subtype.equals("Plains") + || subtype.equals("Forest") || subtype.equals("Swamp") || subtype.equals("Aura") + || subtype.equals("Equipment") || subtype.equals("Fortification")) { + return false; + } + // as it is creature subtype, then check the existence of Changeling + return abilities.contains(ChangelingAbility.getInstance()); + } + } + } diff --git a/Mage/src/mage/abilities/common/AllyEntersBattlefieldTriggeredAbility.java b/Mage/src/mage/abilities/common/AllyEntersBattlefieldTriggeredAbility.java index b802b1cfe72..34186da8d58 100644 --- a/Mage/src/mage/abilities/common/AllyEntersBattlefieldTriggeredAbility.java +++ b/Mage/src/mage/abilities/common/AllyEntersBattlefieldTriggeredAbility.java @@ -60,7 +60,7 @@ public class AllyEntersBattlefieldTriggeredAbility extends TriggeredAbilityImpl if (zEvent.getToZone() == Zone.BATTLEFIELD && permanent.getControllerId().equals(this.controllerId) && (targetId.equals(this.getSourceId()) - || (permanent.getSubtype().contains("Ally") && !targetId.equals(this.getSourceId())))) { + || (permanent.hasSubtype("Ally") && !targetId.equals(this.getSourceId())))) { return true; } } diff --git a/Mage/src/mage/abilities/keyword/ChangelingAbility.java b/Mage/src/mage/abilities/keyword/ChangelingAbility.java new file mode 100644 index 00000000000..639148f82f3 --- /dev/null +++ b/Mage/src/mage/abilities/keyword/ChangelingAbility.java @@ -0,0 +1,66 @@ +/* +* 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.abilities.keyword; + +import mage.Constants.Zone; +import mage.abilities.StaticAbility; + +import java.io.ObjectStreamException; + +/** + * + * @author nantuko + */ +public class ChangelingAbility extends StaticAbility { + + private static final ChangelingAbility fINSTANCE = new ChangelingAbility(); + + private Object readResolve() throws ObjectStreamException { + return fINSTANCE; + } + + public static ChangelingAbility getInstance() { + return fINSTANCE; + } + + private ChangelingAbility() { + super(Zone.BATTLEFIELD, null); + } + + @Override + public String getRule() { + return "Changeling (This card is every creature type at all times.)"; + } + + @Override + public ChangelingAbility copy() { + return fINSTANCE; + } + +} diff --git a/Mage/src/mage/filter/FilterObject.java b/Mage/src/mage/filter/FilterObject.java index 3f788a1d1b8..c1b8c2aeec5 100644 --- a/Mage/src/mage/filter/FilterObject.java +++ b/Mage/src/mage/filter/FilterObject.java @@ -37,6 +37,7 @@ import mage.ObjectColor; import mage.abilities.Abilities; import mage.abilities.AbilitiesImpl; import mage.abilities.Ability; +import mage.abilities.keyword.ChangelingAbility; /** * @@ -169,8 +170,10 @@ public class FilterObject> ex } if (subtype.size() > 0) { - if (!compString.compare(subtype, object.getSubtype(), scopeSubtype, notSubtype)) - return notFilter; + if (!object.getAbilities().contains(ChangelingAbility.getInstance())) { + if (!compString.compare(subtype, object.getSubtype(), scopeSubtype, notSubtype)) + return notFilter; + } } if (supertype.size() > 0) { diff --git a/Mage/src/mage/game/command/Emblem.java b/Mage/src/mage/game/command/Emblem.java index 0974865ede9..64bd6d3f16e 100644 --- a/Mage/src/mage/game/command/Emblem.java +++ b/Mage/src/mage/game/command/Emblem.java @@ -119,6 +119,11 @@ public class Emblem implements CommandObject { return emptyList; } + @Override + public boolean hasSubtype(String subtype) { + return false; + } + @Override public List getSupertype() { return emptyList; diff --git a/Mage/src/mage/game/stack/Spell.java b/Mage/src/mage/game/stack/Spell.java index d75942211a1..92141239a5d 100644 --- a/Mage/src/mage/game/stack/Spell.java +++ b/Mage/src/mage/game/stack/Spell.java @@ -206,6 +206,11 @@ public class Spell> implements StackObject, Card { return card.getSubtype(); } + @Override + public boolean hasSubtype(String subtype) { + return card.hasSubtype(subtype); + } + @Override public List getSupertype() { return card.getSupertype(); diff --git a/Mage/src/mage/game/stack/StackAbility.java b/Mage/src/mage/game/stack/StackAbility.java index e3b8c60447c..4fb3e2825eb 100644 --- a/Mage/src/mage/game/stack/StackAbility.java +++ b/Mage/src/mage/game/stack/StackAbility.java @@ -119,6 +119,11 @@ public class StackAbility implements StackObject, Ability { return emptyList; } + @Override + public boolean hasSubtype(String subtype) { + return false; + } + @Override public List getSupertype() { return emptyList;