diff --git a/Mage.Sets/src/mage/cards/c/CrewCaptain.java b/Mage.Sets/src/mage/cards/c/CrewCaptain.java index a6bfde66d4..a97cc96712 100644 --- a/Mage.Sets/src/mage/cards/c/CrewCaptain.java +++ b/Mage.Sets/src/mage/cards/c/CrewCaptain.java @@ -1,9 +1,8 @@ package mage.cards.c; import mage.MageInt; -import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.condition.Condition; +import mage.abilities.condition.common.SourceEnteredThisTurnCondition; import mage.abilities.decorator.ConditionalContinuousEffect; import mage.abilities.effects.common.continuous.GainAbilitySourceEffect; import mage.abilities.keyword.HasteAbility; @@ -12,10 +11,7 @@ import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.SubType; -import mage.game.Game; -import mage.game.permanent.Permanent; -import java.util.Optional; import java.util.UUID; /** @@ -36,7 +32,7 @@ public final class CrewCaptain extends CardImpl { // Crew Captain has indestructible as long as it entered the battlefield this turn. this.addAbility(new SimpleStaticAbility(new ConditionalContinuousEffect( - new GainAbilitySourceEffect(IndestructibleAbility.getInstance()), CrewCaptainCondition.instance, + new GainAbilitySourceEffect(IndestructibleAbility.getInstance()), SourceEnteredThisTurnCondition.instance, "{this} has indestructible as long as it entered the battlefield this turn" ))); } @@ -50,14 +46,3 @@ public final class CrewCaptain extends CardImpl { return new CrewCaptain(this); } } - -enum CrewCaptainCondition implements Condition { - instance; - - @Override - public boolean apply(Game game, Ability source) { - return Optional.ofNullable(source.getSourcePermanentIfItStillExists(game)) - .map(Permanent::getTurnsOnBattlefield) - .orElseGet(() -> -1) == 0; - } -} \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/d/DrownyardBehemoth.java b/Mage.Sets/src/mage/cards/d/DrownyardBehemoth.java index 70a2be47ba..f6e59773c4 100644 --- a/Mage.Sets/src/mage/cards/d/DrownyardBehemoth.java +++ b/Mage.Sets/src/mage/cards/d/DrownyardBehemoth.java @@ -3,8 +3,10 @@ package mage.cards.d; import java.util.UUID; import mage.MageInt; -import mage.abilities.common.AsEntersBattlefieldAbility; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.condition.common.SourceEnteredThisTurnCondition; import mage.abilities.costs.mana.ManaCostsImpl; +import mage.abilities.decorator.ConditionalContinuousEffect; import mage.abilities.effects.common.continuous.GainAbilitySourceEffect; import mage.abilities.keyword.EmergeAbility; import mage.abilities.keyword.FlashAbility; @@ -34,7 +36,10 @@ public final class DrownyardBehemoth extends CardImpl { this.addAbility(new EmergeAbility(this, new ManaCostsImpl<>("{7}{U}"))); // Drownyard Behemoth has hexproof as long as it entered the battlefield this turn. - this.addAbility(new AsEntersBattlefieldAbility(new GainAbilitySourceEffect(HexproofAbility.getInstance(), Duration.EndOfTurn))); + this.addAbility(new SimpleStaticAbility(new ConditionalContinuousEffect( + new GainAbilitySourceEffect(HexproofAbility.getInstance(), Duration.WhileOnBattlefield), + SourceEnteredThisTurnCondition.instance, "{this} has hexproof as long as it entered the battlefield this turn" + ))); } private DrownyardBehemoth(final DrownyardBehemoth card) { diff --git a/Mage.Sets/src/mage/cards/f/FungusElemental.java b/Mage.Sets/src/mage/cards/f/FungusElemental.java index 9a9ba8c729..5341c2bf80 100644 --- a/Mage.Sets/src/mage/cards/f/FungusElemental.java +++ b/Mage.Sets/src/mage/cards/f/FungusElemental.java @@ -3,7 +3,7 @@ package mage.cards.f; import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; -import mage.abilities.condition.Condition; +import mage.abilities.condition.common.SourceEnteredThisTurnCondition; import mage.abilities.costs.common.SacrificeTargetCost; import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.decorator.ConditionalActivatedAbility; @@ -15,8 +15,6 @@ import mage.constants.CardType; import mage.constants.Zone; import mage.counters.CounterType; import mage.filter.common.FilterControlledPermanent; -import mage.game.Game; -import mage.game.permanent.Permanent; import mage.target.common.TargetControlledPermanent; /** @@ -44,7 +42,7 @@ public final class FungusElemental extends CardImpl { Zone.BATTLEFIELD, new AddCountersSourceEffect(CounterType.P2P2.createInstance()), new ManaCostsImpl<>("{G}"), - FungusElementalCondition.instance + SourceEnteredThisTurnCondition.instance ); ability.addCost(new SacrificeTargetCost(new TargetControlledPermanent(filter))); this.addAbility(ability); @@ -59,23 +57,3 @@ public final class FungusElemental extends CardImpl { return new FungusElemental(this); } } - -enum FungusElementalCondition implements Condition { - - instance; - - @Override - public boolean apply(Game game, Ability source) { - Permanent permanent = game.getBattlefield().getPermanent(source.getSourceId()); - if (permanent != null) { - return permanent.getTurnsOnBattlefield() == 0; - } - return false; - } - - @Override - public String toString() { - return "{this} entered the battlefield this turn"; - } - -} diff --git a/Mage.Sets/src/mage/cards/k/KaitoShizuki.java b/Mage.Sets/src/mage/cards/k/KaitoShizuki.java index 9188588216..0975ae307a 100644 --- a/Mage.Sets/src/mage/cards/k/KaitoShizuki.java +++ b/Mage.Sets/src/mage/cards/k/KaitoShizuki.java @@ -6,6 +6,7 @@ import mage.abilities.common.BeginningOfEndStepTriggeredAbility; import mage.abilities.condition.Condition; import mage.abilities.condition.InvertCondition; import mage.abilities.condition.common.RaidCondition; +import mage.abilities.condition.common.SourceEnteredThisTurnCondition; import mage.abilities.decorator.ConditionalOneShotEffect; import mage.abilities.effects.common.CreateTokenEffect; import mage.abilities.effects.common.DrawCardSourceControllerEffect; @@ -18,9 +19,7 @@ import mage.abilities.hint.common.RaidHint; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.*; -import mage.game.Game; import mage.game.command.emblems.KaitoShizukiEmblem; -import mage.game.permanent.Permanent; import mage.game.permanent.token.NinjaToken; import mage.watchers.common.PlayerAttackedWatcher; @@ -32,7 +31,7 @@ import java.util.UUID; public final class KaitoShizuki extends CardImpl { private static final Hint hint = new ConditionHint( - KaitoShizukiCondition.instance, "This permanent entered the battlefield this turn" + SourceEnteredThisTurnCondition.instance, "This permanent entered the battlefield this turn" ); private static final Condition condition = new InvertCondition(RaidCondition.instance); @@ -46,7 +45,7 @@ public final class KaitoShizuki extends CardImpl { // At the beginning of your end step, if Kaito Shizuki entered the battlefield this turn, he phases out. this.addAbility(new BeginningOfEndStepTriggeredAbility( Zone.BATTLEFIELD, new PhaseOutSourceEffect().setText("he phases out"), - TargetController.YOU, KaitoShizukiCondition.instance, false + TargetController.YOU, SourceEnteredThisTurnCondition.instance, false ).addHint(hint)); // +1: Draw a card. Then discard a card unless you attacked this turn. @@ -73,18 +72,3 @@ public final class KaitoShizuki extends CardImpl { return new KaitoShizuki(this); } } - -enum KaitoShizukiCondition implements Condition { - instance; - - @Override - public boolean apply(Game game, Ability source) { - Permanent permanent = source.getSourcePermanentIfItStillExists(game); - return permanent != null && permanent.getTurnsOnBattlefield() == 0; - } - - @Override - public String toString() { - return "if {this} entered the battlefield this turn"; - } -} diff --git a/Mage.Sets/src/mage/cards/k/KeldonStrikeTeam.java b/Mage.Sets/src/mage/cards/k/KeldonStrikeTeam.java index f89301e3b0..8ec9685d57 100644 --- a/Mage.Sets/src/mage/cards/k/KeldonStrikeTeam.java +++ b/Mage.Sets/src/mage/cards/k/KeldonStrikeTeam.java @@ -1,11 +1,10 @@ package mage.cards.k; import mage.MageInt; -import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.condition.Condition; import mage.abilities.condition.common.KickedCondition; +import mage.abilities.condition.common.SourceEnteredThisTurnCondition; import mage.abilities.decorator.ConditionalContinuousEffect; import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility; import mage.abilities.effects.common.CreateTokenEffect; @@ -18,12 +17,8 @@ import mage.constants.CardType; import mage.constants.Duration; import mage.constants.SubType; import mage.filter.StaticFilters; -import mage.game.Game; -import mage.game.permanent.Permanent; import mage.game.permanent.token.SoldierToken; -import java.util.Objects; -import java.util.Optional; import java.util.UUID; /** @@ -54,7 +49,7 @@ public final class KeldonStrikeTeam extends CardImpl { new GainAbilityControlledEffect( HasteAbility.getInstance(), Duration.WhileOnBattlefield, StaticFilters.FILTER_CONTROLLED_CREATURE - ), KeldonStrikeTeamCondition.instance, "as long as {this} " + + ), SourceEnteredThisTurnCondition.instance, "as long as {this} " + "entered the battlefield this turn, creatures you control have haste" ))); } @@ -68,15 +63,3 @@ public final class KeldonStrikeTeam extends CardImpl { return new KeldonStrikeTeam(this); } } - -enum KeldonStrikeTeamCondition implements Condition { - instance; - - @Override - public boolean apply(Game game, Ability source) { - return Optional.ofNullable(source.getSourcePermanentIfItStillExists(game)) - .filter(Objects::nonNull) - .map(Permanent::getTurnsOnBattlefield) - .orElse(-1) == 0; - } -} diff --git a/Mage.Sets/src/mage/cards/m/Mirrex.java b/Mage.Sets/src/mage/cards/m/Mirrex.java index 5b191db9c6..e7e737a999 100644 --- a/Mage.Sets/src/mage/cards/m/Mirrex.java +++ b/Mage.Sets/src/mage/cards/m/Mirrex.java @@ -4,7 +4,7 @@ import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; -import mage.abilities.condition.Condition; +import mage.abilities.condition.common.SourceEnteredThisTurnCondition; import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.mana.GenericManaCost; import mage.abilities.effects.common.CreateTokenEffect; @@ -16,8 +16,6 @@ import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.Zone; -import mage.game.Game; -import mage.game.permanent.Permanent; import mage.game.permanent.token.PhyrexianMiteToken; /** @@ -36,7 +34,7 @@ public final class Mirrex extends CardImpl { // {T}: Add one mana of any color. Activate only if Mirrex entered the battlefield this turn. this.addAbility(new ActivateIfConditionManaAbility( Zone.BATTLEFIELD, new AddManaOfAnyColorEffect(), - new TapSourceCost(), MirrexCondition.instance + new TapSourceCost(), SourceEnteredThisTurnCondition.instance )); // {3}, {T}: Create a 1/1 colorless Phyrexian Mite artifact creature token with toxic 1 and "This creature can't block." @@ -56,18 +54,3 @@ public final class Mirrex extends CardImpl { return new Mirrex(this); } } - -enum MirrexCondition implements Condition { - instance; - - @Override - public boolean apply(Game game, Ability source) { - Permanent permanent = source.getSourcePermanentIfItStillExists(game); - return permanent != null && permanent.getTurnsOnBattlefield() == 0; - } - - @Override - public String toString() { - return "{this} entered the battlefield this turn"; - } -} \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/m/MoonCircuitHacker.java b/Mage.Sets/src/mage/cards/m/MoonCircuitHacker.java index 793733e416..3a70c4956d 100644 --- a/Mage.Sets/src/mage/cards/m/MoonCircuitHacker.java +++ b/Mage.Sets/src/mage/cards/m/MoonCircuitHacker.java @@ -4,6 +4,8 @@ import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility; import mage.abilities.condition.Condition; +import mage.abilities.condition.InvertCondition; +import mage.abilities.condition.common.SourceEnteredThisTurnCondition; import mage.abilities.decorator.ConditionalOneShotEffect; import mage.abilities.effects.common.DrawCardSourceControllerEffect; import mage.abilities.effects.common.discard.DiscardControllerEffect; @@ -12,8 +14,6 @@ import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.SubType; -import mage.game.Game; -import mage.game.permanent.Permanent; import java.util.UUID; @@ -22,6 +22,8 @@ import java.util.UUID; */ public final class MoonCircuitHacker extends CardImpl { + private static final Condition condition = new InvertCondition(SourceEnteredThisTurnCondition.instance); + public MoonCircuitHacker(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT, CardType.CREATURE}, "{1}{U}"); @@ -38,7 +40,7 @@ public final class MoonCircuitHacker extends CardImpl { new DrawCardSourceControllerEffect(1), true ); ability.addEffect(new ConditionalOneShotEffect( - new DiscardControllerEffect(1), MoonCircuitHackerCondition.instance, + new DiscardControllerEffect(1), condition, "If you do, discard a card unless {this} entered the battlefield this turn" )); this.addAbility(ability); @@ -53,13 +55,3 @@ public final class MoonCircuitHacker extends CardImpl { return new MoonCircuitHacker(this); } } - -enum MoonCircuitHackerCondition implements Condition { - instance; - - @Override - public boolean apply(Game game, Ability source) { - Permanent permanent = source.getSourcePermanentOrLKI(game); - return permanent == null || permanent.getTurnsOnBattlefield() > 0; - } -} \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/t/ThrastaTempestsRoar.java b/Mage.Sets/src/mage/cards/t/ThrastaTempestsRoar.java index c6661edd1b..b81047801d 100644 --- a/Mage.Sets/src/mage/cards/t/ThrastaTempestsRoar.java +++ b/Mage.Sets/src/mage/cards/t/ThrastaTempestsRoar.java @@ -3,7 +3,7 @@ package mage.cards.t; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.condition.Condition; +import mage.abilities.condition.common.SourceEnteredThisTurnCondition; import mage.abilities.decorator.ConditionalContinuousEffect; import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.effects.Effect; @@ -18,7 +18,6 @@ import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.*; import mage.game.Game; -import mage.game.permanent.Permanent; import mage.watchers.common.CastSpellLastTurnWatcher; import java.util.UUID; @@ -50,7 +49,7 @@ public final class ThrastaTempestsRoar extends CardImpl { // Thrasta has hexproof as long as it entered the battlefield this turn. this.addAbility(new SimpleStaticAbility(new ConditionalContinuousEffect( new GainAbilitySourceEffect(HexproofAbility.getInstance(), Duration.WhileOnBattlefield), - ThrastaCondition.instance, "{this} has hexproof as long as it entered the battlefield this turn" + SourceEnteredThisTurnCondition.instance, "{this} has hexproof as long as it entered the battlefield this turn" ))); } @@ -91,13 +90,3 @@ enum ThrastaDynamicValue implements DynamicValue { return "other spell cast this turn"; } } - -enum ThrastaCondition implements Condition { - instance; - - @Override - public boolean apply(Game game, Ability source) { - Permanent permanent = source.getSourcePermanentIfItStillExists(game); - return permanent != null && permanent.getTurnsOnBattlefield() == 0; - } -} \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/z/ZurgoAndOjutai.java b/Mage.Sets/src/mage/cards/z/ZurgoAndOjutai.java index 3031652abe..16e08d415d 100644 --- a/Mage.Sets/src/mage/cards/z/ZurgoAndOjutai.java +++ b/Mage.Sets/src/mage/cards/z/ZurgoAndOjutai.java @@ -4,7 +4,7 @@ import mage.MageInt; import mage.abilities.Ability; import mage.abilities.TriggeredAbilityImpl; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.condition.Condition; +import mage.abilities.condition.common.SourceEnteredThisTurnCondition; import mage.abilities.decorator.ConditionalContinuousEffect; import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.LookLibraryAndPickControllerEffect; @@ -29,7 +29,6 @@ import mage.target.targetpointer.FixedTargets; import java.util.List; import java.util.Objects; -import java.util.Optional; import java.util.UUID; import java.util.stream.Collectors; @@ -56,7 +55,7 @@ public final class ZurgoAndOjutai extends CardImpl { // Zurgo and Ojutai has hexproof as long as it entered the battlefield this turn. this.addAbility(new SimpleStaticAbility(new ConditionalContinuousEffect( new GainAbilitySourceEffect(HexproofAbility.getInstance(), Duration.WhileOnBattlefield), - ZurgoAndOjutaiCondition.instance, "{this} has hexproof as long as it entered the battlefield this turn" + SourceEnteredThisTurnCondition.instance, "{this} has hexproof as long as it entered the battlefield this turn" ))); // Whenever one or more Dragons you control deal combat damage to a player or battle, look at the top three cards of your library. Put one of them into your hand and the rest on the bottom of your library in any order. You may return one of those Dragons to its owner's hand. @@ -73,19 +72,6 @@ public final class ZurgoAndOjutai extends CardImpl { } } -enum ZurgoAndOjutaiCondition implements Condition { - instance; - - @Override - public boolean apply(Game game, Ability source) { - return Optional - .ofNullable(source.getSourcePermanentIfItStillExists(game)) - .filter(Objects::nonNull) - .map(Permanent::getTurnsOnBattlefield) - .equals(0); - } -} - class ZurgoAndOjutaiTriggeredAbility extends TriggeredAbilityImpl { ZurgoAndOjutaiTriggeredAbility() { diff --git a/Mage/src/main/java/mage/abilities/condition/common/SourceEnteredThisTurnCondition.java b/Mage/src/main/java/mage/abilities/condition/common/SourceEnteredThisTurnCondition.java new file mode 100644 index 0000000000..d2165c9239 --- /dev/null +++ b/Mage/src/main/java/mage/abilities/condition/common/SourceEnteredThisTurnCondition.java @@ -0,0 +1,28 @@ + +package mage.abilities.condition.common; + +import mage.abilities.Ability; +import mage.abilities.condition.Condition; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * @author xenohedron + */ + +public enum SourceEnteredThisTurnCondition implements Condition { + + instance; + + @Override + public boolean apply(Game game, Ability source) { + Permanent permanent = source.getSourcePermanentOrLKI(game); + return permanent != null && permanent.getTurnsOnBattlefield() == 0; + } + + @Override + public String toString() { + return "{this} entered the battlefield this turn"; + } + +}