mirror of
https://github.com/correl/mage.git
synced 2024-11-25 11:09:53 +00:00
new common class: SourceEnteredThisTurnCondition (#10415)
* Create new common condition class * Use common condition on nine cards where appropriate
This commit is contained in:
parent
749f2e3991
commit
50105c0372
10 changed files with 55 additions and 142 deletions
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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) {
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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() {
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue