refactor some instances of ConditionalInterveningIfTriggeredAbility

This commit is contained in:
theelk801 2025-06-04 14:56:12 -04:00
parent 5fcd99ba44
commit d05d3bbc97
10 changed files with 85 additions and 102 deletions

View file

@ -1,36 +1,35 @@
package mage.cards.a;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.triggers.BeginningOfUpkeepTriggeredAbility;
import mage.abilities.condition.common.ControlsCreatureGreatestToughnessCondition;
import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility;
import mage.abilities.decorator.ConditionalOneShotEffect;
import mage.abilities.effects.common.DrawCardSourceControllerEffect;
import mage.abilities.triggers.BeginningOfUpkeepTriggeredAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import java.util.UUID;
/**
*
* @author LevelX2
*/
public final class AbzanBeastmaster extends CardImpl {
public AbzanBeastmaster(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{2}{G}");
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{G}");
this.subtype.add(SubType.DOG);
this.subtype.add(SubType.SHAMAN);
this.power = new MageInt(2);
this.toughness = new MageInt(1);
// At the beginning of your upkeep, draw a card if you control the creature with the greatest toughness or tied for the greatest toughness.
this.addAbility(new ConditionalInterveningIfTriggeredAbility(
new BeginningOfUpkeepTriggeredAbility(new DrawCardSourceControllerEffect(1)),
ControlsCreatureGreatestToughnessCondition.instance,
"At the beginning of your upkeep, draw a card if you control the creature with the greatest toughness or tied for the greatest toughness."
));
this.addAbility(new BeginningOfUpkeepTriggeredAbility(new ConditionalOneShotEffect(
new DrawCardSourceControllerEffect(1), ControlsCreatureGreatestToughnessCondition.instance,
"draw a card if you control the creature with the greatest toughness or tied for the greatest toughness"
)));
}
private AbzanBeastmaster(final AbzanBeastmaster card) {

View file

@ -4,7 +4,6 @@ import mage.MageInt;
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
import mage.abilities.condition.Condition;
import mage.abilities.condition.common.PermanentsOnTheBattlefieldCondition;
import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility;
import mage.abilities.effects.common.LookLibraryAndPickControllerEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
@ -25,7 +24,7 @@ import java.util.UUID;
*/
public final class AcclaimedContender extends CardImpl {
private static final FilterPermanent filter = new FilterControlledPermanent(SubType.KNIGHT);
private static final FilterPermanent filter = new FilterControlledPermanent(SubType.KNIGHT, "you control another Knight");
private static final FilterCard filter2
= new FilterCard("a Knight, Aura, Equipment, or legendary artifact card");
@ -53,14 +52,9 @@ public final class AcclaimedContender extends CardImpl {
this.toughness = new MageInt(3);
// When Acclaimed Contender enters the battlefield, if you control another Knight, look at the top five cards of your library. You may reveal a Knight, Aura, Equipment, or legendary artifact card from among them and put it into your hand. Put the rest on the bottom of your library in a random order.
this.addAbility(new ConditionalInterveningIfTriggeredAbility(
new EntersBattlefieldTriggeredAbility(new LookLibraryAndPickControllerEffect(
5, 1, filter2, PutCards.HAND, PutCards.BOTTOM_RANDOM
)), condition, "When {this} enters, " +
"if you control another Knight, look at the top five cards of your library. " +
"You may reveal a Knight, Aura, Equipment, or legendary artifact card from among them " +
"and put it into your hand. Put the rest on the bottom of your library in a random order."
));
this.addAbility(new EntersBattlefieldTriggeredAbility(new LookLibraryAndPickControllerEffect(
5, 1, filter2, PutCards.HAND, PutCards.BOTTOM_RANDOM
)).withInterveningIf(condition));
}
private AcclaimedContender(final AcclaimedContender card) {

View file

@ -6,7 +6,6 @@ import mage.abilities.common.AttacksTriggeredAbility;
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
import mage.abilities.condition.Condition;
import mage.abilities.condition.common.CompletedDungeonCondition;
import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.ReturnToHandSourceEffect;
import mage.abilities.effects.keyword.VentureIntoTheDungeonEffect;
@ -22,8 +21,6 @@ import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.game.permanent.token.ZombieToken;
import mage.players.Player;
import mage.target.TargetPermanent;
import mage.target.common.TargetControlledCreaturePermanent;
import mage.target.common.TargetSacrifice;
import mage.watchers.common.CompletedDungeonWatcher;
@ -44,13 +41,9 @@ public final class AcererakTheArchlich extends CardImpl {
this.toughness = new MageInt(5);
// When Acererak the Archlich enters the battlefield, if you have not completed Tomb of Annihilation, return Acererak the Archlich to its owner's hand and venture into the dungeon.
Ability ability = new ConditionalInterveningIfTriggeredAbility(
new EntersBattlefieldTriggeredAbility(new ReturnToHandSourceEffect(true)),
AcererakTheArchlichCondition.instance, "When {this} enters, " +
"if you haven't completed Tomb of Annihilation, return {this} " +
"to its owner's hand and venture into the dungeon."
);
ability.addEffect(new VentureIntoTheDungeonEffect());
Ability ability = new EntersBattlefieldTriggeredAbility(new ReturnToHandSourceEffect(true))
.withInterveningIf(AcererakTheArchlichCondition.instance);
ability.addEffect(new VentureIntoTheDungeonEffect().concatBy("and"));
ability.addHint(CurrentDungeonHint.instance);
ability.addHint(CompletedDungeonCondition.getHint());
this.addAbility(ability, new CompletedDungeonWatcher());
@ -78,6 +71,11 @@ enum AcererakTheArchlichCondition implements Condition {
source.getControllerId(), game
).contains("Tomb of Annihilation");
}
@Override
public String toString() {
return "you haven't completed Tomb of Annihilation";
}
}
class AcererakTheArchlichEffect extends OneShotEffect {

View file

@ -1,45 +1,41 @@
package mage.cards.a;
import mage.MageInt;
import mage.abilities.triggers.BeginningOfCombatTriggeredAbility;
import mage.abilities.condition.Condition;
import mage.abilities.condition.common.PermanentsOnTheBattlefieldCondition;
import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.abilities.hint.ConditionHint;
import mage.abilities.hint.Hint;
import mage.abilities.triggers.BeginningOfCombatTriggeredAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.counters.CounterType;
import mage.filter.common.FilterControlledPermanent;
import mage.filter.common.FilterControlledPlaneswalkerPermanent;
import java.util.UUID;
/**
*
* @author htrajan
*/
public final class AdherentOfHope extends CardImpl {
private static final FilterControlledPermanent filter = new FilterControlledPermanent();
static {
filter.add(CardType.PLANESWALKER.getPredicate());
filter.add(SubType.BASRI.getPredicate());
}
private static final Condition condition = new PermanentsOnTheBattlefieldCondition(
new FilterControlledPlaneswalkerPermanent(SubType.BASRI, "you control a Basri planeswalker")
);
private static final Hint hint = new ConditionHint(condition);
public AdherentOfHope(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{W}");
this.subtype.add(SubType.HUMAN);
this.subtype.add(SubType.SOLDIER);
this.power = new MageInt(2);
this.toughness = new MageInt(1);
// At the beginning of combat on your turn, if you control a Basri planeswalker, put a +1/+1 counter on Adherent of Hope.
this.addAbility(new ConditionalInterveningIfTriggeredAbility(
new BeginningOfCombatTriggeredAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance())),
new PermanentsOnTheBattlefieldCondition(filter),
"At the beginning of combat on your turn, if you control a Basri planeswalker, put a +1/+1 counter on {this}."));
this.addAbility(new BeginningOfCombatTriggeredAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance())).withInterveningIf(condition).addHint(hint));
}
private AdherentOfHope(final AdherentOfHope card) {

View file

@ -1,40 +1,38 @@
package mage.cards.a;
import java.util.*;
import mage.MageInt;
import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.abilities.common.AttacksTriggeredAbility;
import mage.abilities.condition.Condition;
import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.effects.common.DrawCardSourceControllerEffect;
import mage.abilities.effects.common.continuous.AddCardSubTypeSourceEffect;
import mage.abilities.hint.ConditionHint;
import mage.abilities.hint.Hint;
import mage.constants.*;
import mage.abilities.keyword.IslandwalkAbility;
import mage.abilities.keyword.CrewAbility;
import mage.abilities.keyword.IslandwalkAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.*;
import mage.filter.common.FilterCreaturePermanent;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.watchers.Watcher;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/**
*
* @author Grath
*/
public final class Adrestia extends CardImpl {
private static final Condition condition = AdrestiaCondition.instance;
public Adrestia(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{3}");
this.supertype.add(SuperType.LEGENDARY);
this.subtype.add(SubType.VEHICLE);
this.power = new MageInt(4);
@ -44,16 +42,14 @@ public final class Adrestia extends CardImpl {
this.addAbility(new IslandwalkAbility());
// Whenever Adrestia attacks, if an Assassin crewed it this turn, draw a card. Adrestia becomes an Assassin in addition to its other types until end of turn.
Ability ability = new ConditionalInterveningIfTriggeredAbility(
new AttacksTriggeredAbility(new DrawCardSourceControllerEffect(1), false),
condition, "Whenever {this} attacks, if an Assassin crewed it this turn, draw a card. {this} becomes an Assassin in addition to its other types until end of turn.");
Ability ability = new AttacksTriggeredAbility(new DrawCardSourceControllerEffect(1), false)
.withInterveningIf(AdrestiaCondition.instance);
ability.addEffect(new AddCardSubTypeSourceEffect(Duration.EndOfTurn, true, SubType.ASSASSIN));
ability.addHint(AdrestiaCondition.getHint());
this.addAbility(ability, new AdrestiaWatcher());
// Crew 1
this.addAbility(new CrewAbility(1));
}
private Adrestia(final Adrestia card) {
@ -68,13 +64,18 @@ public final class Adrestia extends CardImpl {
enum AdrestiaCondition implements Condition {
instance;
private static final Hint hint = new ConditionHint(instance, "an Assassin crewed it this turn");
private static final Hint hint = new ConditionHint(instance);
@Override
public boolean apply(Game game, Ability source) {
return AdrestiaWatcher.checkIfAssassinCrewed(source.getSourcePermanentOrLKI(game), game);
}
@Override
public String toString() {
return "an Assassin crewed it this turn";
}
public static Hint getHint() {
return hint;
}
@ -97,8 +98,7 @@ class AdrestiaWatcher extends Watcher {
if (crewer != null) {
if (!crewMap.containsKey(vehicle)) {
crewMap.put(vehicle, filter.match(crewer, game));
}
else {
} else {
crewMap.put(vehicle, crewMap.get(vehicle) || filter.match(crewer, game));
}
}

View file

@ -4,7 +4,6 @@ import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.AttacksTriggeredAbility;
import mage.abilities.condition.Condition;
import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility;
import mage.abilities.effects.common.search.SearchLibraryPutInPlayEffect;
import mage.abilities.hint.Hint;
import mage.abilities.hint.common.LandsYouControlHint;
@ -46,13 +45,10 @@ public final class AerialSurveyor extends CardImpl {
this.addAbility(FlyingAbility.getInstance());
// Whenever Aerial Surveyor attacks, if defending player controls more lands than you, search your library for a basic Plains card, put it onto the battlefield tapped, then shuffle.
this.addAbility(new ConditionalInterveningIfTriggeredAbility(
new AttacksTriggeredAbility(
new SearchLibraryPutInPlayEffect(new TargetCardInLibrary(filter), true)
), AerialSurveyorCondition.instance, "Whenever {this} attacks, if defending player " +
"controls more lands than you, search your library for a basic Plains card, " +
"put it onto the battlefield tapped, then shuffle."
).addHint(LandsYouControlHint.instance).addHint(AerialSurveyorHint.instance));
this.addAbility(new AttacksTriggeredAbility(new SearchLibraryPutInPlayEffect(new TargetCardInLibrary(filter), true))
.withInterveningIf(AerialSurveyorCondition.instance)
.addHint(LandsYouControlHint.instance)
.addHint(AerialSurveyorHint.instance));
// Crew 2
this.addAbility(new CrewAbility(2));
@ -85,6 +81,11 @@ enum AerialSurveyorCondition implements Condition {
source.getControllerId(), source, game
);
}
@Override
public String toString() {
return "";
}
}
enum AerialSurveyorHint implements Hint {

View file

@ -3,7 +3,6 @@ package mage.game.command.emblems;
import mage.abilities.Ability;
import mage.abilities.common.OneOrMoreCombatDamagePlayerTriggeredAbility;
import mage.abilities.condition.Condition;
import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility;
import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
@ -25,13 +24,9 @@ public final class LolthSpiderQueenEmblem extends Emblem {
// 8: You get an emblem with "Whenever an opponent is dealt combat damage by one or more creatures you control, if that player lost less than 8 life this turn, they lose life equal to the difference."
public LolthSpiderQueenEmblem() {
super("Emblem Lolth");
this.getAbilities().add(new ConditionalInterveningIfTriggeredAbility(
new OneOrMoreCombatDamagePlayerTriggeredAbility(
Zone.COMMAND, new LolthSpiderQueenEmblemEffect(), StaticFilters.FILTER_PERMANENT_CREATURES, SetTargetPointer.PLAYER, false
), LolthSpiderQueenEmblemCondition.instance, "Whenever an opponent " +
"is dealt combat damage by one or more creatures you control, " +
"if that player lost less than 8 life this turn, they lose life equal to the difference."
));
this.getAbilities().add(new OneOrMoreCombatDamagePlayerTriggeredAbility(
Zone.COMMAND, new LolthSpiderQueenEmblemEffect(), StaticFilters.FILTER_PERMANENT_CREATURES, SetTargetPointer.PLAYER, false
).withInterveningIf(LolthSpiderQueenEmblemCondition.instance).setTriggerPhrase("Whenever an opponent is dealt combat damage by one or more creatures you control, "));
}
private LolthSpiderQueenEmblem(final LolthSpiderQueenEmblem card) {
@ -61,12 +56,18 @@ enum LolthSpiderQueenEmblemCondition implements Condition {
PlayerLostLifeWatcher watcher = game.getState().getWatcher(PlayerLostLifeWatcher.class);
return player != null && watcher != null && watcher.getLifeLost(player.getId()) < 8;
}
@Override
public String toString() {
return "that player lost less than 8 life this turn";
}
}
class LolthSpiderQueenEmblemEffect extends OneShotEffect {
LolthSpiderQueenEmblemEffect() {
super(Outcome.Benefit);
staticText = "they lose life equal to the difference";
}
private LolthSpiderQueenEmblemEffect(final LolthSpiderQueenEmblemEffect effect) {

View file

@ -1,10 +1,9 @@
package mage.game.command.emblems;
import mage.abilities.Ability;
import mage.abilities.triggers.BeginningOfFirstMainTriggeredAbility;
import mage.abilities.condition.Condition;
import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.triggers.BeginningOfFirstMainTriggeredAbility;
import mage.cards.Cards;
import mage.cards.FrameStyle;
import mage.cards.repository.TokenInfo;
@ -31,12 +30,9 @@ public class RadiationEmblem extends Emblem {
super("Radiation");
this.frameStyle = FrameStyle.M15_NORMAL;
this.getAbilities().add(new ConditionalInterveningIfTriggeredAbility(
new BeginningOfFirstMainTriggeredAbility(Zone.ALL, TargetController.YOU, new RadiationEffect(), false),
RadiationCondition.instance,
"At the beginning of your precombat main phase, if you have any rad counters, "
+ "mill that many cards. For each nonland card milled this way, you lose 1 life and a rad counter."
));
this.getAbilities().add(new BeginningOfFirstMainTriggeredAbility(
Zone.ALL, TargetController.YOU, new RadiationEffect(), false
).withInterveningIf(RadiationCondition.instance).setTriggerPhrase("At the beginning of each player's precombat main phase, "));
TokenInfo foundInfo = TokenRepository.instance.findPreferredTokenInfoForXmage(TokenRepository.XMAGE_IMAGE_NAME_RADIATION, null);
if (foundInfo != null) {
@ -69,6 +65,11 @@ enum RadiationCondition implements Condition {
Player player = game.getPlayer(source.getControllerId());
return player != null && player.getCountersCount(CounterType.RAD) > 0;
}
@Override
public String toString() {
return "that player has one or more rad counters";
}
}
/**

View file

@ -1,12 +1,11 @@
package mage.game.permanent.token;
import mage.MageInt;
import mage.abilities.triggers.BeginningOfCombatTriggeredAbility;
import mage.abilities.condition.common.WasCardExiledThisTurnCondition;
import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.abilities.hint.ConditionHint;
import mage.abilities.hint.Hint;
import mage.abilities.triggers.BeginningOfCombatTriggeredAbility;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.counters.CounterType;
@ -22,21 +21,16 @@ public final class AshiokWickedManipulatorNightmareToken extends TokenImpl {
* /!\ You need to add CardsExiledThisTurnWatcher to any card using this token
*/
public AshiokWickedManipulatorNightmareToken() {
super("Nightmare Token", "1/1 black Nightmare creature tokens with \"At the beginning of combat on your turn, if a card was put into exile this turn, put a +1/+1 counter on this creature.\"");
super("Nightmare Token", "1/1 black Nightmare creature token with \"At the beginning of combat on your turn, if a card was put into exile this turn, put a +1/+1 counter on this token.\"");
cardType.add(CardType.CREATURE);
color.setBlack(true);
subtype.add(SubType.NIGHTMARE);
power = new MageInt(1);
toughness = new MageInt(1);
this.addAbility(new ConditionalInterveningIfTriggeredAbility(
new BeginningOfCombatTriggeredAbility(
new AddCountersSourceEffect(CounterType.P1P1.createInstance())
),
WasCardExiledThisTurnCondition.instance,
"At the beginning of combat on your turn, if a card was put into exile "
+ "this turn, put a +1/+1 counter on this creature."
).addHint(hint));
this.addAbility(new BeginningOfCombatTriggeredAbility(
new AddCountersSourceEffect(CounterType.P1P1.createInstance())
).withInterveningIf(WasCardExiledThisTurnCondition.instance).addHint(hint));
}
private AshiokWickedManipulatorNightmareToken(final AshiokWickedManipulatorNightmareToken token) {

View file

@ -5,7 +5,6 @@ import mage.abilities.common.AttacksTriggeredAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.condition.Condition;
import mage.abilities.condition.common.SourceMatchesFilterCondition;
import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility;
import mage.abilities.effects.common.AttachEffect;
import mage.abilities.effects.common.continuous.GainAbilityAttachedEffect;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
@ -23,7 +22,7 @@ import mage.target.common.TargetCreaturePermanent;
*/
public final class YoungHeroRoleToken extends TokenImpl {
private static final FilterPermanent filter = new FilterCreaturePermanent();
private static final FilterPermanent filter = new FilterCreaturePermanent("its toughness is 3 or less");
static {
filter.add(new ToughnessPredicate(ComparisonType.FEWER_THAN, 4));
@ -45,10 +44,10 @@ public final class YoungHeroRoleToken extends TokenImpl {
// Enchanted creature has "Whenever this creature attacks, if its toughness is 3 or less, put a +1/+1 counter on it."
this.addAbility(new SimpleStaticAbility(new GainAbilityAttachedEffect(
new ConditionalInterveningIfTriggeredAbility(
new AttacksTriggeredAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance())),
condition, "Whenever this creature attacks, if its toughness is 3 or less, put a +1/+1 counter on it."
), AttachmentType.AURA
new AttacksTriggeredAbility(
new AddCountersSourceEffect(CounterType.P1P1.createInstance())
.setText("put a +1/+1 counter on it")
).withInterveningIf(condition), AttachmentType.AURA
)));
}