From 272a189e8bf9d42215d0be6d85e2a938a5af0609 Mon Sep 17 00:00:00 2001 From: xenohedron Date: Sun, 8 Dec 2024 20:46:56 -0500 Subject: [PATCH] update Portal Mage to common class --- Mage.Sets/src/mage/cards/p/PortalMage.java | 94 ++-------------------- 1 file changed, 6 insertions(+), 88 deletions(-) diff --git a/Mage.Sets/src/mage/cards/p/PortalMage.java b/Mage.Sets/src/mage/cards/p/PortalMage.java index a5b88d854fae..2f2c2c130c2e 100644 --- a/Mage.Sets/src/mage/cards/p/PortalMage.java +++ b/Mage.Sets/src/mage/cards/p/PortalMage.java @@ -1,4 +1,3 @@ - package mage.cards.p; import mage.MageInt; @@ -6,29 +5,18 @@ import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.condition.common.IsStepCondition; import mage.abilities.decorator.ConditionalTriggeredAbility; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.combat.ReselectDefenderAttackedByTargetEffect; import mage.abilities.keyword.FlashAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.Outcome; import mage.constants.PhaseStep; import mage.constants.SubType; -import mage.filter.StaticFilters; -import mage.filter.common.FilterAttackingCreature; -import mage.game.Game; -import mage.game.combat.CombatGroup; -import mage.game.permanent.Permanent; -import mage.players.Player; -import mage.target.common.TargetCreaturePermanent; -import mage.target.common.TargetDefender; +import mage.target.common.TargetAttackingCreature; -import java.util.LinkedHashSet; -import java.util.Set; import java.util.UUID; /** - * * @author LevelX2 */ public final class PortalMage extends CardImpl { @@ -46,11 +34,11 @@ public PortalMage(UUID ownerId, CardSetInfo setInfo) { // When Portal Mage enters the battlefield during the declare attackers step, you may reselect which player or planeswalker target attacking creature is attacking. Ability ability = new ConditionalTriggeredAbility( - new EntersBattlefieldTriggeredAbility(new PortalMageEffect(), true), + new EntersBattlefieldTriggeredAbility(new ReselectDefenderAttackedByTargetEffect(true), true), new IsStepCondition(PhaseStep.DECLARE_ATTACKERS, false), - "When {this} enters during the declare attackers step, you may reselect which player or planeswalker target attacking creature is attacking. " - + "(It can't attack its controller or its controller's planeswalkers.)"); - ability.addTarget(new TargetCreaturePermanent(new FilterAttackingCreature())); + "When {this} enters during the declare attackers step, you may reselect which player or permanent target attacking creature is attacking. " + + "(It can't attack its controller or their permanents)"); + ability.addTarget(new TargetAttackingCreature()); this.addAbility(ability); } @@ -63,73 +51,3 @@ public PortalMage copy() { return new PortalMage(this); } } - -class PortalMageEffect extends OneShotEffect { - - PortalMageEffect() { - super(Outcome.Benefit); - this.staticText = "you may reselect which player or planeswalker target attacking creature is attacking"; - } - - private PortalMageEffect(final PortalMageEffect effect) { - super(effect); - } - - @Override - public PortalMageEffect copy() { - return new PortalMageEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - Permanent attackingCreature = game.getPermanent(getTargetPointer().getFirst(game, source)); - if (attackingCreature != null) { - CombatGroup combatGroupTarget = null; - for (CombatGroup combatGroup : game.getCombat().getGroups()) { - if (combatGroup.getAttackers().contains(attackingCreature.getId())) { - combatGroupTarget = combatGroup; - break; - } - } - if (combatGroupTarget == null) { - return false; - } - // Reselecting which player or planeswalker a creature is attacking ignores all requirements, - // restrictions, and costs associated with attacking. - - // Update possible defender - Set defenders = new LinkedHashSet<>(); - for (UUID playerId : game.getCombat().getAttackablePlayers(game)) { - defenders.add(playerId); - for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_PLANESWALKER, playerId, game)) { - defenders.add(permanent.getId()); - } - } - // Select the new defender - TargetDefender target = new TargetDefender(defenders); - if (controller.chooseTarget(Outcome.Damage, target, source, game)) { - if (combatGroupTarget.getDefenderId() != null && !combatGroupTarget.getDefenderId().equals(target.getFirstTarget())) { - if (combatGroupTarget.changeDefenderPostDeclaration(target.getFirstTarget(), game)) { - String attacked = ""; - Player player = game.getPlayer(target.getFirstTarget()); - if (player != null) { - attacked = player.getLogName(); - } else { - Permanent permanent = game.getPermanent(target.getFirstTarget()); - if (permanent != null) { - attacked = permanent.getLogName(); - } - } - game.informPlayers(attackingCreature.getLogName() + " now attacks " + attacked); - return true; - } - } - } - } - return true; - } - return false; - } -}