remove AbilityUtils.getCause

This commit is contained in:
Hans Mackowiak
2021-04-19 18:12:16 +02:00
parent c216498198
commit 40a52ed00b
4 changed files with 8 additions and 37 deletions

View File

@@ -2052,19 +2052,6 @@ public class AbilityUtils {
} }
} }
public static SpellAbility getCause(SpellAbility sa) {
final SpellAbility root = sa.getRootAbility();
SpellAbility cause = sa;
if (root.isReplacementAbility()) {
SpellAbility replacingObject = (SpellAbility) root.getReplacingObject(AbilityKey.Cause);
if (replacingObject != null) {
cause = replacingObject;
}
}
return cause;
}
public static SpellAbility addSpliceEffects(final SpellAbility sa) { public static SpellAbility addSpliceEffects(final SpellAbility sa) {
final Card source = sa.getHostCard(); final Card source = sa.getHostCard();
final Player player = sa.getActivatingPlayer(); final Player player = sa.getActivatingPlayer();

View File

@@ -448,8 +448,6 @@ public class ChangeZoneEffect extends SpellAbilityEffect {
final Game game = player.getGame(); final Game game = player.getGame();
final CardCollection commandCards = new CardCollection(); final CardCollection commandCards = new CardCollection();
SpellAbility cause = AbilityUtils.getCause(sa);
ZoneType destination = ZoneType.smartValueOf(sa.getParam("Destination")); ZoneType destination = ZoneType.smartValueOf(sa.getParam("Destination"));
final List<ZoneType> origin = Lists.newArrayList(); final List<ZoneType> origin = Lists.newArrayList();
if (sa.hasParam("Origin")) { if (sa.hasParam("Origin")) {
@@ -553,7 +551,7 @@ public class ChangeZoneEffect extends SpellAbilityEffect {
} }
} }
movedCard = game.getAction().moveToLibrary(gameCard, libraryPosition, cause); movedCard = game.getAction().moveToLibrary(gameCard, libraryPosition, sa);
} else { } else {
if (destination.equals(ZoneType.Battlefield)) { if (destination.equals(ZoneType.Battlefield)) {
@@ -659,7 +657,7 @@ public class ChangeZoneEffect extends SpellAbilityEffect {
setFaceDownState(gameCard, sa); setFaceDownState(gameCard, sa);
} }
movedCard = game.getAction().moveTo(gameCard.getController().getZone(destination), gameCard, cause, moveParams); movedCard = game.getAction().moveTo(gameCard.getController().getZone(destination), gameCard, sa, moveParams);
if (sa.hasParam("Unearth")) { if (sa.hasParam("Unearth")) {
movedCard.setUnearthed(true); movedCard.setUnearthed(true);
movedCard.addChangedCardKeywords(Lists.newArrayList("Haste"), null, false, false, movedCard.addChangedCardKeywords(Lists.newArrayList("Haste"), null, false, false,
@@ -699,7 +697,7 @@ public class ChangeZoneEffect extends SpellAbilityEffect {
gameCard.setExiledWith(host); gameCard.setExiledWith(host);
gameCard.setExiledBy(host.getController()); gameCard.setExiledBy(host.getController());
} }
movedCard = game.getAction().moveTo(destination, gameCard, cause); movedCard = game.getAction().moveTo(destination, gameCard, sa);
if (ZoneType.Hand.equals(destination) && ZoneType.Command.equals(originZone.getZoneType())) { if (ZoneType.Hand.equals(destination) && ZoneType.Command.equals(originZone.getZoneType())) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(movedCard.getName()).append(" has moved from Command Zone to ").append(player).append("'s hand."); sb.append(movedCard.getName()).append(" has moved from Command Zone to ").append(player).append("'s hand.");
@@ -1181,15 +1179,6 @@ public class ChangeZoneEffect extends SpellAbilityEffect {
final boolean forget = sa.hasParam("ForgetChanged"); final boolean forget = sa.hasParam("ForgetChanged");
final boolean champion = sa.hasParam("Champion"); final boolean champion = sa.hasParam("Champion");
final boolean imprint = sa.hasParam("Imprint"); final boolean imprint = sa.hasParam("Imprint");
final SpellAbility root = sa.getRootAbility();
SpellAbility cause = sa;
if (root.isReplacementAbility()) {
SpellAbility replacingObject = (SpellAbility) root.getReplacingObject(AbilityKey.Cause);
if (replacingObject != null) {
cause = replacingObject;
}
}
boolean combatChanged = false; boolean combatChanged = false;
final CardZoneTable triggerList = new CardZoneTable(); final CardZoneTable triggerList = new CardZoneTable();
@@ -1211,7 +1200,7 @@ public class ChangeZoneEffect extends SpellAbilityEffect {
Map<AbilityKey, Object> moveParams = Maps.newEnumMap(AbilityKey.class); Map<AbilityKey, Object> moveParams = Maps.newEnumMap(AbilityKey.class);
moveParams.put(AbilityKey.FoundSearchingLibrary, searchedLibrary); moveParams.put(AbilityKey.FoundSearchingLibrary, searchedLibrary);
if (destination.equals(ZoneType.Library)) { if (destination.equals(ZoneType.Library)) {
movedCard = game.getAction().moveToLibrary(c, libraryPos, cause, moveParams); movedCard = game.getAction().moveToLibrary(c, libraryPos, sa, moveParams);
} }
else if (destination.equals(ZoneType.Battlefield)) { else if (destination.equals(ZoneType.Battlefield)) {
if (sa.hasParam("Tapped")) { if (sa.hasParam("Tapped")) {
@@ -1302,7 +1291,7 @@ public class ChangeZoneEffect extends SpellAbilityEffect {
c.turnFaceDown(true); c.turnFaceDown(true);
setFaceDownState(c, sa); setFaceDownState(c, sa);
} }
movedCard = game.getAction().moveToPlay(c, c.getController(), cause, moveParams); movedCard = game.getAction().moveToPlay(c, c.getController(), sa, moveParams);
if (sa.hasParam("Tapped")) { if (sa.hasParam("Tapped")) {
movedCard.setTapped(true); movedCard.setTapped(true);
} else if (sa.hasParam("Untapped")) { } else if (sa.hasParam("Untapped")) {
@@ -1333,7 +1322,7 @@ public class ChangeZoneEffect extends SpellAbilityEffect {
} }
} }
else { else {
movedCard = game.getAction().moveTo(destination, c, 0, cause, moveParams); movedCard = game.getAction().moveTo(destination, c, 0, sa, moveParams);
} }
movedCards.add(movedCard); movedCards.add(movedCard);

View File

@@ -3,7 +3,6 @@ package forge.game.ability.effects;
import java.util.Map; import java.util.Map;
import forge.game.ability.AbilityKey; import forge.game.ability.AbilityKey;
import forge.game.ability.AbilityUtils;
import forge.game.ability.SpellAbilityEffect; import forge.game.ability.SpellAbilityEffect;
import forge.game.card.Card; import forge.game.card.Card;
import forge.game.spellability.SpellAbility; import forge.game.spellability.SpellAbility;
@@ -19,6 +18,6 @@ public class ETBReplacementEffect extends SpellAbilityEffect {
Map<AbilityKey, Object> params = AbilityKey.newMap(); Map<AbilityKey, Object> params = AbilityKey.newMap();
params.put(AbilityKey.CardLKI, sa.getReplacingObject(AbilityKey.CardLKI)); params.put(AbilityKey.CardLKI, sa.getReplacingObject(AbilityKey.CardLKI));
params.put(AbilityKey.ReplacementEffect, sa.getReplacementEffect()); params.put(AbilityKey.ReplacementEffect, sa.getReplacementEffect());
sa.getActivatingPlayer().getGame().getAction().moveToPlay(card, card.getController(), AbilityUtils.getCause(sa), params); sa.getActivatingPlayer().getGame().getAction().moveToPlay(card, card.getController(), sa, params);
} }
} }

View File

@@ -67,10 +67,6 @@ public class TokenEffect extends TokenEffectBase {
} }
} }
// Cause of the Token Effect, in general it should be this
// but if its a Replacement Effect, it might be something else or null
SpellAbility cause = AbilityUtils.getCause(sa);
Card prototype = loadTokenPrototype(sa); Card prototype = loadTokenPrototype(sa);
final int finalAmount = AbilityUtils.calculateAmount(host, sa.getParamOrDefault("TokenAmount", "1"), sa); final int finalAmount = AbilityUtils.calculateAmount(host, sa.getParamOrDefault("TokenAmount", "1"), sa);
@@ -88,7 +84,7 @@ public class TokenEffect extends TokenEffectBase {
MutableBoolean combatChanged = new MutableBoolean(false); MutableBoolean combatChanged = new MutableBoolean(false);
for (final Player owner : AbilityUtils.getDefinedPlayers(host, sa.getParamOrDefault("TokenOwner", "You"), sa)) { for (final Player owner : AbilityUtils.getDefinedPlayers(host, sa.getParamOrDefault("TokenOwner", "You"), sa)) {
makeTokens(prototype, owner, sa, finalAmount, cause != null, false, triggerList, combatChanged); makeTokens(prototype, owner, sa, finalAmount, true, false, triggerList, combatChanged);
} }
if (!useZoneTable) { if (!useZoneTable) {