[RIX] refactor some TDFCs

This commit is contained in:
theelk801 2025-07-29 10:17:25 -04:00
parent b70362416b
commit 18a852047f
6 changed files with 97 additions and 143 deletions

View file

@ -1,12 +1,15 @@
package mage.cards.a; package mage.cards.a;
import mage.MageObject; import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.condition.Condition;
import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.costs.mana.GenericManaCost; import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.decorator.ConditionalOneShotEffect;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.DrawCardSourceControllerEffect;
import mage.abilities.effects.common.GainLifeEffect;
import mage.abilities.effects.common.TransformSourceEffect; import mage.abilities.effects.common.TransformSourceEffect;
import mage.abilities.effects.common.UntapSourceEffect; import mage.abilities.effects.common.UntapSourceEffect;
import mage.abilities.keyword.TransformAbility; import mage.abilities.keyword.TransformAbility;
@ -19,11 +22,10 @@ import mage.constants.SuperType;
import mage.game.ExileZone; import mage.game.ExileZone;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.target.TargetCard;
import mage.target.common.TargetCardInHand; import mage.target.common.TargetCardInHand;
import mage.util.CardUtil; import mage.util.CardUtil;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
/** /**
@ -41,8 +43,13 @@ public final class AzorsGateway extends CardImpl {
// If cards with five or more different converted mana costs are exiled with Azor's Gateway, // If cards with five or more different converted mana costs are exiled with Azor's Gateway,
// you gain 5 life, untap Azor's Gateway, and transform it. // you gain 5 life, untap Azor's Gateway, and transform it.
this.addAbility(new TransformAbility()); this.addAbility(new TransformAbility());
Ability ability = new SimpleActivatedAbility(new AzorsGatewayEffect(), new GenericManaCost(1)); Ability ability = new SimpleActivatedAbility(new DrawCardSourceControllerEffect(1), new GenericManaCost(1));
ability.addCost(new TapSourceCost()); ability.addCost(new TapSourceCost());
ability.addEffect(new AzorsGatewayEffect());
ability.addEffect(new ConditionalOneShotEffect(
new GainLifeEffect(5), AzorsGatewayCondition.instance, "If cards with five or more " +
"different mana values are exiled with {this}, you gain 5 life, untap {this}, and transform it."
).addEffect(new UntapSourceEffect()).addEffect(new TransformSourceEffect()));
this.addAbility(ability); this.addAbility(ability);
} }
@ -56,13 +63,28 @@ public final class AzorsGateway extends CardImpl {
} }
} }
enum AzorsGatewayCondition implements Condition {
instance;
@Override
public boolean apply(Game game, Ability source) {
ExileZone exileZone = game.getExile().getExileZone(CardUtil.getExileZoneId(game, source));
return exileZone != null
&& exileZone
.getCards(game)
.stream()
.map(MageObject::getManaValue)
.distinct()
.mapToInt(x -> 1)
.sum() >= 5;
}
}
class AzorsGatewayEffect extends OneShotEffect { class AzorsGatewayEffect extends OneShotEffect {
AzorsGatewayEffect() { AzorsGatewayEffect() {
super(Outcome.Benefit); super(Outcome.Benefit);
this.staticText = "Draw a card, then exile a card from your hand. " + this.staticText = ", then exile a card from your hand";
"If cards with five or more different mana values are exiled with {this}, " +
"you gain 5 life, untap {this}, and transform it";
} }
private AzorsGatewayEffect(final AzorsGatewayEffect effect) { private AzorsGatewayEffect(final AzorsGatewayEffect effect) {
@ -76,37 +98,18 @@ class AzorsGatewayEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player player = game.getPlayer(source.getControllerId());
if (controller == null) { if (player == null || player.getHand().isEmpty()) {
return false; return false;
} }
TargetCard target = new TargetCardInHand();
MageObject sourceObject = source.getSourceObject(game); target.withChooseHint("to exile");
if (sourceObject == null) { player.choose(outcome, player.getHand(), target, source, game);
return false; Card card = game.getCard(target.getFirstTarget());
} return card != null && player.moveCardsToExile(
card, source, game, true,
UUID exileId = CardUtil.getCardExileZoneId(game, source); CardUtil.getExileZoneId(game, source),
CardUtil.getSourceLogName(game, source)
controller.drawCards(1, source, game); );
TargetCardInHand target = new TargetCardInHand();
controller.choose(outcome, target, source, game);
Card cardToExile = game.getCard(target.getFirstTarget());
if (cardToExile != null) {
controller.moveCardsToExile(cardToExile, source, game, true, exileId, sourceObject.getIdName());
}
Set<Integer> usedCMC = new HashSet<>();
ExileZone exileZone = game.getExile().getExileZone(exileId);
if (exileZone != null) {
for (Card card : exileZone.getCards(game)) {
usedCMC.add(card.getManaValue());
}
if (usedCMC.size() > 4) {
controller.gainLife(4, game, source);
new UntapSourceEffect().apply(game, source);
new TransformSourceEffect().apply(game, source);
}
}
return true;
} }
} }

View file

@ -104,17 +104,11 @@ class GoldenGuardianReturnTransformedEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
if (controller != null) { if (controller == null || game.getState().getZone(source.getSourceId()) != Zone.GRAVEYARD) {
if (game.getState().getZone(source.getSourceId()) == Zone.GRAVEYARD) { return false;
game.getState().setValue(TransformAbility.VALUE_KEY_ENTER_TRANSFORMED + source.getSourceId(), Boolean.TRUE);
Card card = game.getCard(source.getSourceId());
if (card != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
}
return true;
} }
return false; game.getState().setValue(TransformAbility.VALUE_KEY_ENTER_TRANSFORMED + source.getSourceId(), Boolean.TRUE);
Card card = game.getCard(source.getSourceId());
return card != null && controller.moveCards(card, Zone.BATTLEFIELD, source, game);
} }
} }

View file

@ -1,8 +1,6 @@
package mage.cards.j; package mage.cards.j;
import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.DiesAttachedTriggeredAbility; import mage.abilities.common.DiesAttachedTriggeredAbility;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
@ -13,16 +11,14 @@ import mage.abilities.keyword.TransformAbility;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.constants.CardType; import mage.constants.*;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.constants.SuperType;
import mage.constants.Zone;
import mage.filter.StaticFilters; import mage.filter.StaticFilters;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.target.TargetPermanent; import mage.target.TargetPermanent;
import java.util.UUID;
/** /**
* @author LevelX2 * @author LevelX2
*/ */
@ -40,12 +36,11 @@ public final class JourneyToEternity extends CardImpl {
TargetPermanent auraTarget = new TargetPermanent(StaticFilters.FILTER_PERMANENT_CREATURE_CONTROLLED); TargetPermanent auraTarget = new TargetPermanent(StaticFilters.FILTER_PERMANENT_CREATURE_CONTROLLED);
this.getSpellAbility().addTarget(auraTarget); this.getSpellAbility().addTarget(auraTarget);
this.getSpellAbility().addEffect(new AttachEffect(Outcome.BoostCreature)); this.getSpellAbility().addEffect(new AttachEffect(Outcome.BoostCreature));
Ability ability = new EnchantAbility(auraTarget); this.addAbility(new EnchantAbility(auraTarget));
this.addAbility(ability);
// When enchanted creature dies, return it to the battlefield under your control, then return Journey to Eternity to the battlefield transformed under your control. // When enchanted creature dies, return it to the battlefield under your control, then return Journey to Eternity to the battlefield transformed under your control.
this.addAbility(new TransformAbility()); this.addAbility(new TransformAbility());
ability = new DiesAttachedTriggeredAbility(new ReturnToBattlefieldUnderYourControlAttachedEffect("it"), "enchanted creature"); Ability ability = new DiesAttachedTriggeredAbility(new ReturnToBattlefieldUnderYourControlAttachedEffect("it"), "enchanted creature");
ability.addEffect(new JourneyToEternityReturnTransformedSourceEffect()); ability.addEffect(new JourneyToEternityReturnTransformedSourceEffect());
this.addAbility(ability); this.addAbility(ability);

View file

@ -1,10 +1,5 @@
package mage.cards.m; package mage.cards.m;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import mage.MageObjectReference;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.common.TapSourceCost;
@ -18,15 +13,16 @@ import mage.constants.CardType;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.SuperType; import mage.constants.SuperType;
import mage.constants.TargetController; import mage.constants.TargetController;
import mage.constants.Zone;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.util.RandomUtil; import mage.util.RandomUtil;
import mage.watchers.Watcher;
import mage.watchers.common.AttackedThisTurnWatcher; import mage.watchers.common.AttackedThisTurnWatcher;
import java.util.Objects;
import java.util.UUID;
import java.util.stream.Collectors;
/** /**
*
* @author LevelX2 * @author LevelX2
*/ */
public final class MetzaliTowerOfTriumph extends CardImpl { public final class MetzaliTowerOfTriumph extends CardImpl {
@ -51,7 +47,6 @@ public final class MetzaliTowerOfTriumph extends CardImpl {
ability = new SimpleActivatedAbility(new MetzaliTowerOfTriumphEffect(), new ManaCostsImpl<>("{2}{W}")); ability = new SimpleActivatedAbility(new MetzaliTowerOfTriumphEffect(), new ManaCostsImpl<>("{2}{W}"));
ability.addCost(new TapSourceCost()); ability.addCost(new TapSourceCost());
this.addAbility(ability); this.addAbility(ability);
} }
private MetzaliTowerOfTriumph(final MetzaliTowerOfTriumph card) { private MetzaliTowerOfTriumph(final MetzaliTowerOfTriumph card) {
@ -69,7 +64,7 @@ class MetzaliTowerOfTriumphEffect extends OneShotEffect {
MetzaliTowerOfTriumphEffect() { MetzaliTowerOfTriumphEffect() {
super(Outcome.DestroyPermanent); super(Outcome.DestroyPermanent);
this.staticText = "Choose a creature at random that attacked this turn. Destroy that creature"; this.staticText = "choose a creature at random that attacked this turn. Destroy that creature";
} }
private MetzaliTowerOfTriumphEffect(final MetzaliTowerOfTriumphEffect effect) { private MetzaliTowerOfTriumphEffect(final MetzaliTowerOfTriumphEffect effect) {
@ -83,24 +78,15 @@ class MetzaliTowerOfTriumphEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Watcher watcher = game.getState().getWatcher(AttackedThisTurnWatcher.class); Permanent permanent = RandomUtil.randomFromCollection(
if (watcher instanceof AttackedThisTurnWatcher) { game.getState()
Set<MageObjectReference> attackedThisTurn = ((AttackedThisTurnWatcher) watcher).getAttackedThisTurnCreatures(); .getWatcher(AttackedThisTurnWatcher.class)
List<Permanent> available = new ArrayList<>(); .getAttackedThisTurnCreatures()
for (MageObjectReference mor : attackedThisTurn) { .stream()
Permanent permanent = mor.getPermanent(game); .map(mor -> mor.getPermanent(game))
if (permanent != null && permanent.isCreature(game)) { .filter(Objects::nonNull)
available.add(permanent); .collect(Collectors.toSet())
} );
} return permanent != null && permanent.destroy(source, game);
if (!available.isEmpty()) {
Permanent permanent = available.get(RandomUtil.nextInt(available.size()));
if (permanent != null) {
permanent.destroy(source, game, false);
}
}
return true;
}
return false;
} }
} }

View file

@ -1,28 +1,25 @@
package mage.cards.p; package mage.cards.p;
import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.condition.Condition;
import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.OneShotEffect; import mage.abilities.decorator.ConditionalOneShotEffect;
import mage.abilities.effects.common.ExileTargetEffect; import mage.abilities.effects.common.ExileTargetForSourceEffect;
import mage.abilities.effects.common.TransformSourceEffect; import mage.abilities.effects.common.TransformSourceEffect;
import mage.abilities.keyword.TransformAbility; import mage.abilities.keyword.TransformAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.SuperType; import mage.constants.SuperType;
import mage.constants.Zone;
import mage.game.ExileZone;
import mage.game.Game; import mage.game.Game;
import mage.players.Player;
import mage.target.common.TargetCreaturePermanent; import mage.target.common.TargetCreaturePermanent;
import mage.util.CardUtil; import mage.util.CardUtil;
import java.util.Optional;
import java.util.UUID;
/** /**
* @author LevelX2 * @author LevelX2
*/ */
@ -37,7 +34,11 @@ public final class ProfaneProcession extends CardImpl {
// {3}{W}{B}: Exile target creature. Then if there are three or more cards exiled with Profane Procession, transform it. // {3}{W}{B}: Exile target creature. Then if there are three or more cards exiled with Profane Procession, transform it.
this.addAbility(new TransformAbility()); this.addAbility(new TransformAbility());
Ability ability = new SimpleActivatedAbility(new ProfaneProcessionEffect(), new ManaCostsImpl<>("{3}{W}{B}")); Ability ability = new SimpleActivatedAbility(new ExileTargetForSourceEffect(), new ManaCostsImpl<>("{3}{W}{B}"));
ability.addEffect(new ConditionalOneShotEffect(
new TransformSourceEffect(), ProfaneProcessionCondition.instance,
"Then if there are three or more cards exiled with {this}, transform it"
));
ability.addTarget(new TargetCreaturePermanent()); ability.addTarget(new TargetCreaturePermanent());
this.addAbility(ability); this.addAbility(ability);
} }
@ -52,36 +53,14 @@ public final class ProfaneProcession extends CardImpl {
} }
} }
class ProfaneProcessionEffect extends OneShotEffect { enum ProfaneProcessionCondition implements Condition {
instance;
ProfaneProcessionEffect() {
super(Outcome.Exile);
this.staticText = "Exile target creature. Then if there are three or more cards exiled with {this}, transform it.";
}
private ProfaneProcessionEffect(final ProfaneProcessionEffect effect) {
super(effect);
}
@Override
public ProfaneProcessionEffect copy() {
return new ProfaneProcessionEffect(this);
}
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); return Optional
UUID exileId = CardUtil.getCardExileZoneId(game, source); .ofNullable(game.getExile().getExileZone(CardUtil.getExileZoneId(game, source)))
MageObject sourceObject = source.getSourceObject(game); .filter(cards -> cards.size() >= 3)
if (controller != null && exileId != null && sourceObject != null) { .isPresent();
new ExileTargetEffect(exileId, sourceObject.getIdName()).setTargetPointer(this.getTargetPointer().copy()).apply(game, source);
game.processAction();
ExileZone exileZone = game.getExile().getExileZone(exileId);
if (exileZone != null && exileZone.size() > 2) {
new TransformSourceEffect().apply(game, source);
}
return true;
}
return false;
} }
} }

View file

@ -1,7 +1,5 @@
package mage.cards.t; package mage.cards.t;
import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.common.TapSourceCost;
@ -20,10 +18,12 @@ import mage.game.ExileZone;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.target.TargetCard; import mage.target.TargetCard;
import mage.target.common.TargetCardInExile;
import mage.util.CardUtil; import mage.util.CardUtil;
import java.util.UUID;
/** /**
*
* @author LevelX2 * @author LevelX2
*/ */
public final class TombOfTheDuskRose extends CardImpl { public final class TombOfTheDuskRose extends CardImpl {
@ -60,7 +60,7 @@ class TombOfTheDuskRoseEffect extends OneShotEffect {
TombOfTheDuskRoseEffect() { TombOfTheDuskRoseEffect() {
super(Outcome.PutCardInPlay); super(Outcome.PutCardInPlay);
this.staticText = "Put a creature card exiled with this permanent onto the battlefield under your control"; this.staticText = "put a creature card exiled with this permanent onto the battlefield under your control";
} }
private TombOfTheDuskRoseEffect(final TombOfTheDuskRoseEffect effect) { private TombOfTheDuskRoseEffect(final TombOfTheDuskRoseEffect effect) {
@ -75,20 +75,17 @@ class TombOfTheDuskRoseEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
UUID exileId = CardUtil.getCardExileZoneId(game, source); if (controller == null) {
MageObject sourceObject = source.getSourceObject(game); return false;
if (controller != null && exileId != null && sourceObject != null) {
ExileZone exileZone = game.getExile().getExileZone(exileId);
if (exileZone != null) {
TargetCard targetCard = new TargetCard(Zone.EXILED, StaticFilters.FILTER_CARD_CREATURE);
controller.chooseTarget(outcome, exileZone, targetCard, source, game);
Card card = game.getCard(targetCard.getFirstTarget());
if (card != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
}
return true;
} }
return false; ExileZone exileZone = game.getExile().getExileZone(CardUtil.getExileZoneId(game, source));
if (exileZone == null || exileZone.count(StaticFilters.FILTER_CARD_CREATURE, game) < 1) {
return false;
}
TargetCard targetCard = new TargetCardInExile(StaticFilters.FILTER_CARD_CREATURE, exileZone.getId());
targetCard.withNotTarget(true);
controller.choose(outcome, targetCard, source, game);
Card card = game.getCard(targetCard.getFirstTarget());
return card != null && controller.moveCards(card, Zone.BATTLEFIELD, source, game);
} }
} }