...
 
Commits (22)
......@@ -2079,8 +2079,7 @@ public class AiController {
return true;
}
public ReplacementEffect chooseSingleReplacementEffect(List<ReplacementEffect> list,
Map<String, Object> runParams) {
public ReplacementEffect chooseSingleReplacementEffect(List<ReplacementEffect> list) {
// no need to choose anything
if (list.size() <= 1) {
return Iterables.getFirst(list, null);
......
......@@ -29,6 +29,7 @@ import forge.card.MagicColor;
import forge.card.mana.ManaCostShard;
import forge.game.*;
import forge.game.ability.AbilityFactory;
import forge.game.ability.AbilityKey;
import forge.game.ability.AbilityUtils;
import forge.game.ability.ApiType;
import forge.game.ability.effects.CharmEffect;
......@@ -2849,10 +2850,9 @@ public class ComputerUtil {
}
// Run any applicable replacement effects.
final Map<String, Object> repParams = Maps.newHashMap();
repParams.put("Affected", player);
repParams.put("LifeGained", 1);
repParams.put("Source", source);
final Map<AbilityKey, Object> repParams = AbilityKey.mapFromAffected(player);
repParams.put(AbilityKey.LifeGained, 1);
repParams.put(AbilityKey.Source, source);
List<ReplacementEffect> list = player.getGame().getReplacementHandler().getReplacementList(
ReplacementType.GainLife,
......@@ -2880,15 +2880,15 @@ public class ComputerUtil {
}
// Run any applicable replacement effects.
final Map<String, Object> repParams = Maps.newHashMap();
repParams.put("Affected", player);
repParams.put("LifeGained", n);
repParams.put("Source", source);
final Map<AbilityKey, Object> repParams = AbilityKey.mapFromAffected(player);
repParams.put(AbilityKey.LifeGained, n);
repParams.put(AbilityKey.Source, source);
List<ReplacementEffect> list = player.getGame().getReplacementHandler().getReplacementList(
ReplacementType.GainLife,
repParams,
ReplacementLayer.Other);
ReplacementType.GainLife,
repParams,
ReplacementLayer.Other
);
if (Iterables.any(list, CardTraitPredicates.hasParam("AiLogic", "NoLife"))) {
// no life gain is not negative
......
......@@ -29,6 +29,7 @@ import forge.game.CardTraitBase;
import forge.game.Game;
import forge.game.GameEntity;
import forge.game.ability.AbilityFactory;
import forge.game.ability.AbilityKey;
import forge.game.ability.AbilityUtils;
import forge.game.ability.ApiType;
import forge.game.card.*;
......@@ -2580,13 +2581,11 @@ public class ComputerUtilCombat {
final Game game = attacker.getGame();
// first try to replace the damage
final Map<String, Object> repParams = Maps.newHashMap();
repParams.put("Affected", target);
repParams.put("DamageSource", attacker);
repParams.put("DamageAmount", damage);
repParams.put("IsCombat", true);
repParams.put("Prevention", true);
// repParams.put("PreventMap", preventMap);
final Map<AbilityKey, Object> repParams = AbilityKey.mapFromAffected(target);
repParams.put(AbilityKey.DamageSource, attacker);
repParams.put(AbilityKey.DamageAmount, damage);
repParams.put(AbilityKey.IsCombat, true);
repParams.put(AbilityKey.Prevention, true);
List<ReplacementEffect> list = game.getReplacementHandler().getReplacementList(
ReplacementType.DamageDone, repParams, ReplacementLayer.Other);
......
......@@ -13,6 +13,7 @@ import forge.card.mana.ManaCostParser;
import forge.card.mana.ManaCostShard;
import forge.game.Game;
import forge.game.GameActionUtil;
import forge.game.ability.AbilityKey;
import forge.game.ability.AbilityUtils;
import forge.game.ability.ApiType;
import forge.game.card.*;
......@@ -1408,11 +1409,11 @@ public class ComputerUtilMana {
AbilityManaPart mp = m.getManaPart();
// setup produce mana replacement effects
final Map<String, Object> repParams = new HashMap<>();
repParams.put("Mana", mp.getOrigProduced());
repParams.put("Affected", sourceCard);
repParams.put("Player", ai);
repParams.put("AbilityMana", m);
final Map<AbilityKey, Object> repParams = AbilityKey.newMap();
repParams.put(AbilityKey.Mana, mp.getOrigProduced());
repParams.put(AbilityKey.Affected, sourceCard);
repParams.put(AbilityKey.Player, ai);
repParams.put(AbilityKey.AbilityMana, m);
for (final ReplacementEffect replacementEffect : replacementEffects) {
if (replacementEffect.canReplace(repParams)) {
......
......@@ -866,8 +866,8 @@ public class PlayerControllerAi extends PlayerController {
}
@Override
public ReplacementEffect chooseSingleReplacementEffect(String prompt, List<ReplacementEffect> possibleReplacers, Map<String, Object> runParams) {
return brains.chooseSingleReplacementEffect(possibleReplacers, runParams);
public ReplacementEffect chooseSingleReplacementEffect(String prompt, List<ReplacementEffect> possibleReplacers) {
return brains.chooseSingleReplacementEffect(possibleReplacers);
}
@Override
......
......@@ -10,6 +10,7 @@ import forge.card.MagicColor;
import forge.game.Game;
import forge.game.GameObject;
import forge.game.GlobalRuleChange;
import forge.game.ability.AbilityKey;
import forge.game.ability.AbilityUtils;
import forge.game.ability.ApiType;
import forge.game.card.*;
......@@ -1789,8 +1790,8 @@ public class ChangeZoneAi extends SpellAbilityAi {
}
public boolean doReturnCommanderLogic(SpellAbility sa, Player aiPlayer) {
Map<String, Object> originalParams = (Map<String, Object>)sa.getReplacingObject("OriginalParams");
SpellAbility causeSa = (SpellAbility)originalParams.get("Cause");
Map<AbilityKey, Object> originalParams = (Map<AbilityKey, Object>)sa.getReplacingObject(AbilityKey.OriginalParams);
SpellAbility causeSa = (SpellAbility)originalParams.get(AbilityKey.Cause);
SpellAbility causeSub = null;
// Squee, the Immortal: easier to recast it (the call below has to be "contains" since SA is an intrinsic effect)
......@@ -1813,7 +1814,7 @@ public class ChangeZoneAi extends SpellAbilityAi {
// A blink effect implemented using a delayed trigger
return !"Exile".equals(exec.getParam("Origin")) || !"Battlefield".equals(exec.getParam("Destination"));
}
} else return causeSa.getHostCard() == null || !causeSa.getHostCard().equals(sa.getReplacingObject("Card"))
} else return causeSa.getHostCard() == null || !causeSa.getHostCard().equals(sa.getReplacingObject(AbilityKey.Card))
|| !causeSa.getActivatingPlayer().equals(aiPlayer);
}
......
......@@ -2,12 +2,12 @@ package forge.ai.ability;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import forge.ai.ComputerUtil;
import forge.ai.ComputerUtilCard;
import forge.ai.ComputerUtilMana;
import forge.ai.SpellAbilityAi;
import forge.game.Game;
import forge.game.ability.AbilityKey;
import forge.game.card.Card;
import forge.game.card.CardCollection;
import forge.game.card.CardCollectionView;
......@@ -97,11 +97,10 @@ public class ManifestAi extends SpellAbilityAi {
topCopy.turnFaceDownNoUpdate();
topCopy.setManifested(true);
final Map<String, Object> repParams = Maps.newHashMap();
repParams.put("Affected", topCopy);
repParams.put("Origin", card.getZone().getZoneType());
repParams.put("Destination", ZoneType.Battlefield);
repParams.put("Source", sa.getHostCard());
final Map<AbilityKey, Object> repParams = AbilityKey.mapFromAffected(topCopy);
repParams.put(AbilityKey.Origin, card.getZone().getZoneType());
repParams.put(AbilityKey.Destination, ZoneType.Battlefield);
repParams.put(AbilityKey.Source, sa.getHostCard());
List<ReplacementEffect> list = game.getReplacementHandler().getReplacementList(ReplacementType.Moved, repParams, ReplacementLayer.Other);
if (!list.isEmpty()) {
return false;
......
......@@ -55,8 +55,6 @@ import org.apache.commons.lang3.tuple.ImmutablePair;
import java.util.*;
import static forge.util.EnumMapUtil.toStringMap;
/**
* Methods for common actions performed during a game.
*
......@@ -292,8 +290,7 @@ public class GameAction {
copied.getOwner().addInboundToken(copied);
}
Map<AbilityKey, Object> repParams = AbilityKey.newMap();
repParams.put(AbilityKey.Affected, copied);
Map<AbilityKey, Object> repParams = AbilityKey.mapFromAffected(copied);
repParams.put(AbilityKey.CardLKI, lastKnownInfo);
repParams.put(AbilityKey.Cause, cause);
repParams.put(AbilityKey.Origin, zoneFrom != null ? zoneFrom.getZoneType() : null);
......@@ -303,7 +300,7 @@ public class GameAction {
repParams.putAll(params);
}
ReplacementResult repres = game.getReplacementHandler().run(ReplacementType.Moved, toStringMap(repParams));
ReplacementResult repres = game.getReplacementHandler().run(ReplacementType.Moved, repParams);
if (repres != ReplacementResult.NotReplaced) {
// reset failed manifested Cards back to original
if (c.isManifested()) {
......@@ -1389,11 +1386,10 @@ public class GameAction {
}
// Replacement effects
final Map<String, Object> repRunParams = Maps.newHashMap();
repRunParams.put("Source", sa);
repRunParams.put("Card", c);
repRunParams.put("Affected", c);
repRunParams.put("Regeneration", regenerate);
final Map<AbilityKey, Object> repRunParams = AbilityKey.mapFromCard(c);
repRunParams.put(AbilityKey.Source, sa);
repRunParams.put(AbilityKey.Affected, c);
repRunParams.put(AbilityKey.Regeneration, regenerate);
if (game.getReplacementHandler().run(ReplacementType.Destroy, repRunParams) != ReplacementResult.NotReplaced) {
return false;
......
......@@ -115,25 +115,24 @@ public abstract class GameEntity extends GameObject implements IIdentifiable {
public int replaceDamage(final int damage, final Card source, final boolean isCombat, final boolean prevention,
final CardDamageMap damageMap, final CardDamageMap preventMap, GameEntityCounterTable counterTable, final SpellAbility cause) {
// Replacement effects
final Map<String, Object> repParams = Maps.newHashMap();
repParams.put("Affected", this);
repParams.put("DamageSource", source);
repParams.put("DamageAmount", damage);
repParams.put("IsCombat", isCombat);
repParams.put("NoPreventDamage", !prevention);
repParams.put("DamageMap", damageMap);
repParams.put("PreventMap", preventMap);
repParams.put("CounterTable", counterTable);
final Map<AbilityKey, Object> repParams = AbilityKey.mapFromAffected(this);
repParams.put(AbilityKey.DamageSource, source);
repParams.put(AbilityKey.DamageAmount, damage);
repParams.put(AbilityKey.IsCombat, isCombat);
repParams.put(AbilityKey.NoPreventDamage, !prevention);
repParams.put(AbilityKey.DamageMap, damageMap);
repParams.put(AbilityKey.PreventMap, preventMap);
repParams.put(AbilityKey.CounterTable, counterTable);
if (cause != null) {
repParams.put("Cause", cause);
repParams.put(AbilityKey.Cause, cause);
}
switch (getGame().getReplacementHandler().run(ReplacementType.DamageDone, repParams)) {
case NotReplaced:
return damage;
case Updated:
int newDamage = (int) repParams.get("DamageAmount");
GameEntity newTarget = (GameEntity) repParams.get("Affected");
int newDamage = (int) repParams.get(AbilityKey.DamageAmount);
GameEntity newTarget = (GameEntity) repParams.get(AbilityKey.Affected);
// check if this is still the affected card or player
if (this.equals(newTarget)) {
return newDamage;
......@@ -169,15 +168,14 @@ public abstract class GameEntity extends GameObject implements IIdentifiable {
int restDamage = damage;
// first try to replace the damage
final Map<String, Object> repParams = Maps.newHashMap();
repParams.put("Affected", this);
repParams.put("DamageSource", source);
repParams.put("DamageAmount", damage);
repParams.put("IsCombat", isCombat);
repParams.put("Prevention", true);
repParams.put("PreventMap", preventMap);
final Map<AbilityKey, Object> repParams = AbilityKey.mapFromAffected(this);
repParams.put(AbilityKey.DamageSource, source);
repParams.put(AbilityKey.DamageAmount, damage);
repParams.put(AbilityKey.IsCombat, isCombat);
repParams.put(AbilityKey.Prevention, true);
repParams.put(AbilityKey.PreventMap, preventMap);
if (cause != null) {
repParams.put("Cause", cause);
repParams.put(AbilityKey.Cause, cause);
}
switch (getGame().getReplacementHandler().run(ReplacementType.DamageDone, repParams)) {
......@@ -185,7 +183,7 @@ public abstract class GameEntity extends GameObject implements IIdentifiable {
restDamage = damage;
break;
case Updated:
restDamage = (int) repParams.get("DamageAmount");
restDamage = (int) repParams.get(AbilityKey.DamageAmount);
break;
default:
restDamage = 0;
......
......@@ -3,6 +3,7 @@ package forge.game.ability;
import java.util.EnumMap;
import java.util.Map;
import forge.game.GameEntity;
import forge.game.card.Card;
/**
......@@ -37,12 +38,15 @@ public enum AbilityKey {
CostStack("CostStack"),
CounterAmount("CounterAmount"),
CounteredSA("CounteredSA"),
CounterNum("CounterNum"),
CounterTable("CounterTable"),
CounterType("CounterType"),
Crew("Crew"),
CumulativeUpkeepPaid("CumulativeUpkeepPaid"),
CurrentCastSpells("CurrentCastSpells"),
CurrentStormCount("CurrentStormCount"),
DamageAmount("DamageAmount"),
DamageMap("DamageMap"),
DamageSource("DamageSource"),
DamageSources("DamageSources"),
DamageTarget("DamageTarget"),
......@@ -53,18 +57,23 @@ public enum AbilityKey {
Destination("Destination"),
Devoured("Devoured"),
EchoPaid("EchoPaid"),
EffectOnly("EffectOnly"),
Exploited("Exploited"),
Explorer("Explorer"),
Event("Event"),
Fighter("Fighter"),
FirstTime("FirstTime"),
Fizzle("Fizzle"),
IsCombat("IsCombat"), // TODO confirm that this and IsCombatDamage can be merged
IsCombatDamage("IsCombatDamage"),
IndividualCostPaymentInstance("IndividualCostPaymentInstance"),
IsMadness("IsMadness"),
LifeAmount("LifeAmount"),
LifeAmount("LifeAmount"), //TODO confirm that this and LifeGained can be merged
LifeGained("LifeGained"),
Mana("Mana"),
MonstrosityAmount("MonstrosityAmount"),
NewCounterAmount("NewCounterAmount"),
NoPreventDamage("NoPreventDamage"),
Num("Num"), // TODO confirm that this and NumThisTurn can be merged
NumBlockers("NumBlockers"),
NumThisTurn("NumThisTurn"),
......@@ -76,10 +85,15 @@ public enum AbilityKey {
Origin("Origin"),
OriginalController("OriginalController"),
OriginalDefender("OriginalDefender"),
OriginalParams("OriginalParams"),
PayingMana("PayingMana"),
Phase("Phase"),
Player("Player"),
PreventMap("PreventMap"),
Prevention("Prevention"),
Produced("Produced"),
Regeneration("Regeneration"),
ReplacementResult("ReplacementResult"),
Result("Result"),
Scheme("Scheme"),
Source("Source"),
......@@ -91,8 +105,12 @@ public enum AbilityKey {
StackInstance("StackInstance"),
StackSa("StackSa"),
StackSi("StackSi"),
SurveilNum("SurveilNum"),
Target("Target"),
Targets("Targets"),
TgtSA("TgtSA"),
Token("Token"),
TokenNum("TokenNum"),
Transformer("Transformer"),
Vehicle("Vehicle"),
Won("Won");
......@@ -141,4 +159,11 @@ public enum AbilityKey {
runParams.put(Card, card);
return runParams;
}
public static Map<AbilityKey, Object> mapFromAffected(GameEntity gameEntity) {
final Map<AbilityKey, Object> runParams = newMap();
runParams.put(Affected, gameEntity);
return runParams;
}
}
......@@ -48,7 +48,7 @@ public class AbilityUtils {
public static CounterType getCounterType(String name, SpellAbility sa) throws Exception {
CounterType counterType;
if ("ReplacedCounterType".equals(name)) {
name = (String) sa.getReplacingObject("CounterType");
name = (String) sa.getReplacingObject(AbilityKey.CounterType);
}
try {
counterType = CounterType.getType(name);
......@@ -157,7 +157,9 @@ public class AbilityUtils {
}
else if (defined.startsWith("Replaced") && (sa != null)) {
final SpellAbility root = sa.getRootAbility();
final Object crd = root.getReplacingObject(defined.substring(8));
AbilityKey type = AbilityKey.fromString(defined.substring(8));
final Object crd = root.getReplacingObject(type);
if (crd instanceof Card) {
c = game.getCardState((Card) crd);
} else if (crd instanceof List<?>) {
......@@ -712,7 +714,7 @@ public class AbilityUtils {
}
else if (calcX[0].startsWith("Replaced")) {
final SpellAbility root = sa.getRootAbility();
list = new CardCollection((Card) root.getReplacingObject(calcX[0].substring(8)));
list = new CardCollection((Card) root.getReplacingObject(AbilityKey.fromString(calcX[0].substring(8))));
}
else if (calcX[0].startsWith("ReplaceCount")) {
// ReplaceCount is similar to a regular Count, but just
......@@ -720,7 +722,7 @@ public class AbilityUtils {
final SpellAbility root = sa.getRootAbility();
final String[] l = calcX[1].split("/");
final String m = CardFactoryUtil.extractOperators(calcX[1]);
final int count = (Integer) root.getReplacingObject(l[0]);
final int count = (Integer) root.getReplacingObject(AbilityKey.fromString(l[0]));
return CardFactoryUtil.doXMath(count, m, card) * multiplier;
}
......@@ -1063,7 +1065,7 @@ public class AbilityUtils {
if (defined.endsWith("Controller")) {
String replacingType = defined.substring(8);
replacingType = replacingType.substring(0, replacingType.length() - 10);
final Object c = root.getReplacingObject(replacingType);
final Object c = root.getReplacingObject(AbilityKey.fromString(replacingType));
if (c instanceof Card) {
o = ((Card) c).getController();
}
......@@ -1074,14 +1076,14 @@ public class AbilityUtils {
else if (defined.endsWith("Owner")) {
String replacingType = defined.substring(8);
replacingType = replacingType.substring(0, replacingType.length() - 5);
final Object c = root.getReplacingObject(replacingType);
final Object c = root.getReplacingObject(AbilityKey.fromString(replacingType));
if (c instanceof Card) {
o = ((Card) c).getOwner();
}
}
else {
final String replacingType = defined.substring(8);
o = root.getReplacingObject(replacingType);
o = root.getReplacingObject(AbilityKey.fromString(replacingType));
}
if (o != null) {
if (o instanceof Player) {
......
......@@ -18,7 +18,6 @@ import java.util.List;
import java.util.Map;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
public class CounterEffect extends SpellAbilityEffect {
@Override
......@@ -155,10 +154,9 @@ public class CounterEffect extends SpellAbilityEffect {
final SpellAbility srcSA, final SpellAbilityStackInstance si) {
final Game game = tgtSA.getActivatingPlayer().getGame();
// Run any applicable replacement effects.
final Map<String, Object> repParams = Maps.newHashMap();
repParams.put("TgtSA", tgtSA);
repParams.put("Affected", tgtSA.getHostCard());
repParams.put("Cause", srcSA.getHostCard());
final Map<AbilityKey, Object> repParams = AbilityKey.mapFromAffected(tgtSA.getHostCard());
repParams.put(AbilityKey.TgtSA, tgtSA);
repParams.put(AbilityKey.Cause, srcSA.getHostCard());
if (game.getReplacementHandler().run(ReplacementType.Counter, repParams) != ReplacementResult.NotReplaced) {
return;
}
......
package forge.game.ability.effects;
import forge.game.ability.AbilityKey;
import forge.game.ability.SpellAbilityEffect;
import forge.game.card.Card;
import forge.game.spellability.SpellAbility;
......@@ -11,6 +12,6 @@ import forge.game.spellability.SpellAbility;
public class ETBReplacementEffect extends SpellAbilityEffect {
@Override
public void resolve(SpellAbility sa) {
sa.getActivatingPlayer().getGame().getAction().moveToPlay(((Card) sa.getReplacingObject("Card")), sa);
sa.getActivatingPlayer().getGame().getAction().moveToPlay(((Card) sa.getReplacingObject(AbilityKey.Card)), sa);
}
}
\ No newline at end of file
......@@ -2,10 +2,9 @@ package forge.game.ability.effects;
import java.util.Map;
import forge.game.ability.AbilityKey;
import org.apache.commons.lang3.StringUtils;
import com.google.common.collect.Maps;
import forge.game.Game;
import forge.game.ability.AbilityUtils;
import forge.game.ability.SpellAbilityEffect;
......@@ -31,10 +30,10 @@ public class ReplaceDamageEffect extends SpellAbilityEffect {
String varValue = sa.getParamOrDefault("VarName", "1");
@SuppressWarnings("unchecked")
Map<String, Object> originalParams = (Map<String, Object>) sa.getReplacingObject("OriginalParams");
Map<String, Object> params = Maps.newHashMap(originalParams);
Map<AbilityKey, Object> originalParams = (Map<AbilityKey, Object>) sa.getReplacingObject(AbilityKey.OriginalParams);
Map<AbilityKey, Object> params = AbilityKey.newMap(originalParams);
Integer dmg = (Integer) sa.getReplacingObject("DamageAmount");
Integer dmg = (Integer) sa.getReplacingObject(AbilityKey.DamageAmount);
int prevent = AbilityUtils.calculateAmount(card, varValue, sa);
......@@ -54,10 +53,10 @@ public class ReplaceDamageEffect extends SpellAbilityEffect {
// no damage for original target anymore
if (dmg <= 0) {
originalParams.put("ReplacementResult", ReplacementResult.Replaced);
originalParams.put(AbilityKey.ReplacementResult, ReplacementResult.Replaced);
return;
}
params.put("DamageAmount", dmg);
params.put(AbilityKey.DamageAmount, dmg);
//try to call replacementHandler with new Params
......@@ -65,16 +64,16 @@ public class ReplaceDamageEffect extends SpellAbilityEffect {
switch (result) {
case NotReplaced:
case Updated: {
for (Map.Entry<String, Object> e : params.entrySet()) {
for (Map.Entry<AbilityKey, Object> e : params.entrySet()) {
originalParams.put(e.getKey(), e.getValue());
}
// effect was updated
originalParams.put("ReplacementResult", ReplacementResult.Updated);
originalParams.put(AbilityKey.ReplacementResult, ReplacementResult.Updated);
break;
}
default:
// effect was replaced with something else
originalParams.put("ReplacementResult", result);
originalParams.put(AbilityKey.ReplacementResult, result);
break;
}
}
......
......@@ -7,6 +7,7 @@ import com.google.common.collect.Maps;
import forge.game.Game;
import forge.game.GameObject;
import forge.game.ability.AbilityKey;
import forge.game.ability.AbilityUtils;
import forge.game.ability.SpellAbilityEffect;
import forge.game.card.Card;
......@@ -23,14 +24,14 @@ public class ReplaceEffect extends SpellAbilityEffect {
final Card card = sa.getHostCard();
final Game game = card.getGame();
final String varName = sa.getParam("VarName");
final AbilityKey varName = AbilityKey.fromString(sa.getParam("VarName"));
final String varValue = sa.getParam("VarValue");
final String type = sa.getParamOrDefault("VarType", "amount");
final ReplacementType retype = sa.getReplacementEffect().getMode();
@SuppressWarnings("unchecked")
Map<String, Object> originalParams = (Map<String, Object>) sa.getReplacingObject("OriginalParams");
Map<String, Object> params = Maps.newHashMap(originalParams);
Map<AbilityKey, Object> originalParams = (Map<AbilityKey, Object>) sa.getReplacingObject(AbilityKey.OriginalParams);
Map<AbilityKey, Object> params = Maps.newHashMap(originalParams);
if ("Card".equals(type)) {
List<Card> list = AbilityUtils.getDefinedCards(card, varValue, sa);
......@@ -56,8 +57,8 @@ public class ReplaceEffect extends SpellAbilityEffect {
params.put(varName, AbilityUtils.calculateAmount(card, varValue, sa));
}
if (params.containsKey("EffectOnly")) {
params.put("EffectOnly", true);
if (params.containsKey(AbilityKey.EffectOnly)) {
params.put(AbilityKey.EffectOnly, true);
}
//try to call replacementHandler with new Params
......@@ -65,16 +66,16 @@ public class ReplaceEffect extends SpellAbilityEffect {
switch (result) {
case NotReplaced:
case Updated: {
for (Map.Entry<String, Object> e : params.entrySet()) {
for (Map.Entry<AbilityKey, Object> e : params.entrySet()) {
originalParams.put(e.getKey(), e.getValue());
}
// effect was updated
originalParams.put("ReplacementResult", ReplacementResult.Updated);
originalParams.put(AbilityKey.ReplacementResult, ReplacementResult.Updated);
break;
}
default:
// effect was replaced with something else
originalParams.put("ReplacementResult", result);
originalParams.put(AbilityKey.ReplacementResult, result);
break;
}
}
......
......@@ -3,10 +3,9 @@ package forge.game.ability.effects;
import java.util.List;
import java.util.Map;
import forge.game.ability.AbilityKey;
import org.apache.commons.lang3.StringUtils;
import com.google.common.collect.Maps;
import forge.game.Game;
import forge.game.GameEntity;
import forge.game.GameEntityCounterTable;
......@@ -36,10 +35,10 @@ public class ReplaceSplitDamageEffect extends SpellAbilityEffect {
String varValue = sa.getParamOrDefault("VarName", "1");
@SuppressWarnings("unchecked")
Map<String, Object> originalParams = (Map<String, Object>) sa.getReplacingObject("OriginalParams");
Map<String, Object> params = Maps.newHashMap(originalParams);
Map<AbilityKey, Object> originalParams = (Map<AbilityKey , Object>) sa.getReplacingObject(AbilityKey.OriginalParams);
Map<AbilityKey, Object> params = AbilityKey.newMap(originalParams);
Integer dmg = (Integer) sa.getReplacingObject("DamageAmount");
Integer dmg = (Integer) sa.getReplacingObject(AbilityKey.DamageAmount);
int prevent = AbilityUtils.calculateAmount(card, varValue, sa);
......@@ -57,15 +56,15 @@ public class ReplaceSplitDamageEffect extends SpellAbilityEffect {
card.setSVar(varValue, "Number$" + prevent);
}
Card sourceLKI = (Card) sa.getReplacingObject("Source");
Card sourceLKI = (Card) sa.getReplacingObject(AbilityKey.Source);
CardDamageMap damageMap = (CardDamageMap) originalParams.get("DamageMap");
CardDamageMap preventMap = (CardDamageMap) originalParams.get("PreventMap");
GameEntityCounterTable counterTable = (GameEntityCounterTable) originalParams.get("CounterTable");
SpellAbility cause = (SpellAbility) originalParams.get("Cause");
CardDamageMap damageMap = (CardDamageMap) originalParams.get(AbilityKey.DamageMap);
CardDamageMap preventMap = (CardDamageMap) originalParams.get(AbilityKey.PreventMap);
GameEntityCounterTable counterTable = (GameEntityCounterTable) originalParams.get(AbilityKey.CounterTable);
SpellAbility cause = (SpellAbility) originalParams.get(AbilityKey.Cause);
boolean isCombat = (Boolean) originalParams.get("IsCombat");
boolean noPrevention = (Boolean) originalParams.get("NoPreventDamage");
boolean isCombat = (Boolean) originalParams.get(AbilityKey.IsCombat);
boolean noPrevention = (Boolean) originalParams.get(AbilityKey.NoPreventDamage);
GameEntity obj = (GameEntity) list.get(0);
......@@ -74,26 +73,26 @@ public class ReplaceSplitDamageEffect extends SpellAbilityEffect {
// no damage for original target anymore
if (dmg <= 0) {
originalParams.put("ReplacementResult", ReplacementResult.Replaced);
originalParams.put(AbilityKey.ReplacementResult, ReplacementResult.Replaced);
return;
}
params.put("DamageAmount", dmg);
params.put(AbilityKey.DamageAmount, dmg);
//try to call replacementHandler with new Params
ReplacementResult result = game.getReplacementHandler().run(event, params);
switch (result) {
case NotReplaced:
case Updated: {
for (Map.Entry<String, Object> e : params.entrySet()) {
for (Map.Entry<AbilityKey, Object> e : params.entrySet()) {
originalParams.put(e.getKey(), e.getValue());
}
// effect was updated
originalParams.put("ReplacementResult", ReplacementResult.Updated);
originalParams.put(AbilityKey.ReplacementResult, ReplacementResult.Updated);
break;
}
default:
// effect was replaced with something else
originalParams.put("ReplacementResult", result);
originalParams.put(AbilityKey.ReplacementResult, result);
break;
}
}
......
......@@ -21,6 +21,7 @@ import java.util.Arrays;
import java.util.List;
import forge.card.MagicColor;
import forge.game.ability.AbilityKey;
import forge.game.card.token.TokenInfo;
import org.apache.commons.lang3.StringUtils;
......@@ -224,8 +225,8 @@ public class TokenEffect extends SpellAbilityEffect {
// 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 = sa;
if (root.isReplacementAbility() && root.hasReplacingObject("Cause")) {
cause = (SpellAbility)root.getReplacingObject("Cause");
if (root.isReplacementAbility() && root.hasReplacingObject(AbilityKey.Cause)) {
cause = (SpellAbility) root.getReplacingObject(AbilityKey.Cause);
}
final boolean remember = sa.hasParam("RememberTokens");
......
......@@ -689,9 +689,7 @@ public class Card extends GameEntity implements Comparable<Card> {
if (result && runTriggers) {
// Run replacement effects
Map<String, Object> repParams = Maps.newHashMap();
repParams.put("Affected", this);
getGame().getReplacementHandler().run(ReplacementType.TurnFaceUp, repParams);
getGame().getReplacementHandler().run(ReplacementType.TurnFaceUp, AbilityKey.mapFromAffected(this));
// Run triggers
getGame().getTriggerHandler().registerActiveTrigger(this, false);
......@@ -1241,18 +1239,17 @@ public class Card extends GameEntity implements Comparable<Card> {
addAmount = 0; // As per rule 107.1b
return 0;
}
final Map<String, Object> repParams = Maps.newHashMap();
repParams.put("Affected", this);
repParams.put("Source", source);
repParams.put("CounterType", counterType);
repParams.put("CounterNum", addAmount);
repParams.put("EffectOnly", applyMultiplier);
final Map<AbilityKey, Object> repParams = AbilityKey.mapFromAffected(this);
repParams.put(AbilityKey.Source, source);
repParams.put(AbilityKey.CounterType, counterType);
repParams.put(AbilityKey.CounterNum, addAmount);
repParams.put(AbilityKey.EffectOnly, applyMultiplier);
switch (getGame().getReplacementHandler().run(ReplacementType.AddCounter, repParams)) {
case NotReplaced:
break;
case Updated: {
addAmount = (int) repParams.get("CounterNum");
addAmount = (int) repParams.get(AbilityKey.CounterNum);
break;
}
default:
......@@ -3611,10 +3608,7 @@ public class Card extends GameEntity implements Comparable<Card> {
if (!tapped) { return; }
// Run Replacement effects
final Map<String, Object> repRunParams = Maps.newHashMap();
repRunParams.put("Affected", this);
if (getGame().getReplacementHandler().run(ReplacementType.Untap, repRunParams) != ReplacementResult.NotReplaced) {
if (getGame().getReplacementHandler().run(ReplacementType.Untap, AbilityKey.mapFromAffected(this)) != ReplacementResult.NotReplaced) {
return;
}
......
......@@ -3,12 +3,12 @@ package forge.game.card.token;
import com.google.common.base.Joiner;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import forge.ImageKeys;
import forge.StaticData;
import forge.card.CardType;
import forge.card.MagicColor;
import forge.game.Game;
import forge.game.ability.AbilityKey;
import forge.game.ability.AbilityUtils;
import forge.game.card.Card;
import forge.game.card.CardFactory;
......@@ -166,19 +166,18 @@ public class TokenInfo {
Player player = controller;
Card proto = prototype;
final Map<String, Object> repParams = Maps.newHashMap();
repParams.put("Affected", player);
repParams.put("Token", prototype);
repParams.put("TokenNum", multiplier);
repParams.put("EffectOnly", applyMultiplier);
final Map<AbilityKey, Object> repParams = AbilityKey.mapFromAffected(player);
repParams.put(AbilityKey.Token, prototype);
repParams.put(AbilityKey.TokenNum, multiplier);
repParams.put(AbilityKey.EffectOnly, applyMultiplier);
switch (game.getReplacementHandler().run(ReplacementType.CreateToken, repParams)) {
case NotReplaced:
break;
case Updated: {
multiplier = (int) repParams.get("TokenNum");
player = (Player) repParams.get("Affected");
proto = (Card) repParams.get("Token");
multiplier = (int) repParams.get(AbilityKey.TokenNum);
player = (Player) repParams.get(AbilityKey.Affected);
proto = (Card) repParams.get(AbilityKey.Token);
break;
}
default:
......
......@@ -235,10 +235,7 @@ public class Player extends GameEntity implements Comparable<Player> {
}
// Replacement effects
final Map<String, Object> repRunParams = Maps.newHashMap();
repRunParams.put("Affected", this);
if (game.getReplacementHandler().run(ReplacementType.SetInMotion, repRunParams) != ReplacementResult.NotReplaced) {
if (game.getReplacementHandler().run(ReplacementType.SetInMotion, AbilityKey.mapFromAffected(this)) != ReplacementResult.NotReplaced) {
return;
}
......@@ -403,10 +400,9 @@ public class Player extends GameEntity implements Comparable<Player> {
public final boolean gainLife(int lifeGain, final Card source, final SpellAbility sa) {
// Run any applicable replacement effects.
final Map<String, Object> repParams = Maps.newHashMap();
repParams.put("Affected", this);
repParams.put("LifeGained", lifeGain);
repParams.put("Source", source);
final Map<AbilityKey, Object> repParams = AbilityKey.mapFromAffected(this);
repParams.put(AbilityKey.LifeGained, lifeGain);
repParams.put(AbilityKey.Source, source);
if (!canGainLife()) {
return false;
......@@ -417,8 +413,8 @@ public class Player extends GameEntity implements Comparable<Player> {
break;
case Updated:
// check if this is still the affected player
if (this.equals(repParams.get("Affected"))) {
lifeGain = (int) repParams.get("LifeGained");
if (this.equals(repParams.get(AbilityKey.Affected))) {
lifeGain = (int) repParams.get(AbilityKey.LifeGained);
// negative update means life loss
if (lifeGain < 0) {
this.loseLife(-lifeGain);
......@@ -914,18 +910,17 @@ public class Player extends GameEntity implements Comparable<Player> {
return 0;
}
final Map<String, Object> repParams = Maps.newHashMap();
repParams.put("Affected", this);
repParams.put("Source", source);
repParams.put("CounterType", counterType);
repParams.put("CounterNum", addAmount);
repParams.put("EffectOnly", applyMultiplier);
final Map<AbilityKey, Object> repParams = AbilityKey.mapFromAffected(this);
repParams.put(AbilityKey.Source, source);
repParams.put(AbilityKey.CounterType, counterType);
repParams.put(AbilityKey.CounterNum, addAmount);
repParams.put(AbilityKey.EffectOnly, applyMultiplier);
switch (getGame().getReplacementHandler().run(ReplacementType.AddCounter, repParams)) {
case NotReplaced:
break;
case Updated: {
addAmount = (int) repParams.get("CounterNum");
addAmount = (int) repParams.get(AbilityKey.CounterNum);
break;
}
default:
......@@ -1276,16 +1271,15 @@ public class Player extends GameEntity implements Comparable<Player> {
public void surveil(int num, SpellAbility cause) {
final Map<String, Object> repParams = Maps.newHashMap();
repParams.put("Affected", this);
repParams.put("Source", cause);
repParams.put("SurveilNum", num);
final Map<AbilityKey, Object> repParams = AbilityKey.mapFromAffected(this);
repParams.put(AbilityKey.Source, cause);
repParams.put(AbilityKey.SurveilNum, num);
switch (getGame().getReplacementHandler().run(ReplacementType.Surveil, repParams)) {
case NotReplaced:
break;
case Updated: {
num = (int) repParams.get("SurveilNum");
num = (int) repParams.get(AbilityKey.SurveilNum);
break;
}
default:
......@@ -1346,9 +1340,8 @@ public class Player extends GameEntity implements Comparable<Player> {
final CardCollection toReveal = new CardCollection();
// Replacement effects
final Map<String, Object> repRunParams = Maps.newHashMap();
repRunParams.put("Affected", this);
repRunParams.put("Number", n);
final Map<AbilityKey, Object> repRunParams = AbilityKey.mapFromAffected(this);
repRunParams.put(AbilityKey.Number, n);
if (game.getReplacementHandler().run(ReplacementType.DrawCards, repRunParams) != ReplacementResult.NotReplaced) {
return drawn;
......@@ -1378,10 +1371,7 @@ public class Player extends GameEntity implements Comparable<Player> {
final PlayerZone library = getZone(ZoneType.Library);
// Replacement effects
final Map<String, Object> repRunParams = Maps.newHashMap();
repRunParams.put("Affected", this);
if (game.getReplacementHandler().run(ReplacementType.Draw, repRunParams) != ReplacementResult.NotReplaced) {
if (game.getReplacementHandler().run(ReplacementType.Draw, AbilityKey.mapFromAffected(this)) != ReplacementResult.NotReplaced) {
return drawn;
}
......@@ -1556,10 +1546,9 @@ public class Player extends GameEntity implements Comparable<Player> {
// that should not trigger other Replacement again
if (!discardToTopOfLibrary && !discardMadness) {
// Replacement effects
final Map<String, Object> repRunParams = Maps.newHashMap();
repRunParams.put("Card", c);
repRunParams.put("Source", source);
repRunParams.put("Affected", this);
final Map<AbilityKey, Object> repRunParams = AbilityKey.mapFromCard(c);
repRunParams.put(AbilityKey.Source, source);
repRunParams.put(AbilityKey.Affected, this);
if (game.getReplacementHandler().run(ReplacementType.Discard, repRunParams) != ReplacementResult.NotReplaced) {
return null;
......@@ -1861,10 +1850,7 @@ public class Player extends GameEntity implements Comparable<Player> {
}
// Replacement effects
final Map<String, Object> runParams = Maps.newHashMap();
runParams.put("Affected", this);
if (game.getReplacementHandler().run(ReplacementType.GameLoss, runParams) != ReplacementResult.NotReplaced) {
if (game.getReplacementHandler().run(ReplacementType.GameLoss, AbilityKey.mapFromAffected(this)) != ReplacementResult.NotReplaced) {
return false;
}
}
......
......@@ -211,7 +211,7 @@ public abstract class PlayerController {
Map<String, Object> params);
public abstract boolean confirmPayment(CostPart costPart, String string, SpellAbility sa);
public abstract ReplacementEffect chooseSingleReplacementEffect(String prompt, List<ReplacementEffect> possibleReplacers, Map<String, Object> runParams);
public abstract ReplacementEffect chooseSingleReplacementEffect(String prompt, List<ReplacementEffect> possibleReplacers);
public abstract String chooseProtectionType(String string, SpellAbility sa, List<String> choices);
// these 4 need some refining.
......
package forge.game.replacement;
import forge.game.ability.AbilityKey;
import forge.game.card.Card;
import forge.game.card.CounterType;
import forge.game.player.Player;
......@@ -27,20 +28,20 @@ public class ReplaceAddCounter extends ReplacementEffect {
* @see forge.card.replacement.ReplacementEffect#canReplace(java.util.HashMap)
*/
@Override
public boolean canReplace(Map<String, Object> runParams) {
if (((int) runParams.get("CounterNum")) <= 0) {
public boolean canReplace(Map<AbilityKey, Object> runParams) {
if (((int) runParams.get(AbilityKey.CounterNum)) <= 0) {
return false;
}
if (hasParam("EffectOnly")) {
final Boolean effectOnly = (Boolean) runParams.get("EffectOnly");
final Boolean effectOnly = (Boolean) runParams.get(AbilityKey.EffectOnly);
if (!effectOnly) {
return false;
}
}
if (hasParam("ValidCard")) {
Object o = runParams.get("Affected");
Object o = runParams.get(AbilityKey.Affected);
if (!(o instanceof Card)) {
return false;
}
......@@ -48,7 +49,7 @@ public class ReplaceAddCounter extends ReplacementEffect {
return false;
}
} else if (hasParam("ValidPlayer")) {
Object o = runParams.get("Affected");
Object o = runParams.get(AbilityKey.Affected);
if (!(o instanceof Player)) {
return false;
}
......@@ -59,7 +60,7 @@ public class ReplaceAddCounter extends ReplacementEffect {
if (hasParam("ValidCounterType")) {
String type = getParam("ValidCounterType");
if (CounterType.getType(type) != runParams.get("CounterType")) {
if (CounterType.getType(type) != runParams.get(AbilityKey.CounterType)) {
return false;
}
}
......@@ -71,14 +72,14 @@ public class ReplaceAddCounter extends ReplacementEffect {
* @see forge.card.replacement.ReplacementEffect#setReplacingObjects(java.util.HashMap, forge.card.spellability.SpellAbility)
*/
@Override
public void setReplacingObjects(Map<String, Object> runParams, SpellAbility sa) {
sa.setReplacingObject("CounterNum", runParams.get("CounterNum"));
sa.setReplacingObject("CounterType", ((CounterType) runParams.get("CounterType")).getName());
Object o = runParams.get("Affected");
public void setReplacingObjects(Map<AbilityKey, Object> runParams, SpellAbility sa) {
sa.setReplacingObject(AbilityKey.CounterNum, runParams.get(AbilityKey.CounterNum));
sa.setReplacingObject(AbilityKey.CounterType, ((CounterType) runParams.get(AbilityKey.CounterType)).getName());
Object o = runParams.get(AbilityKey.Affected);
if (o instanceof Card) {
sa.setReplacingObject("Card", o);
sa.setReplacingObject(AbilityKey.Card, o);
} else if (o instanceof Player) {
sa.setReplacingObject("Player", o);
sa.setReplacingObject(AbilityKey.Player, o);
}
}
......
......@@ -17,6 +17,7 @@
*/
package forge.game.replacement;
import forge.game.ability.AbilityKey;
import forge.game.card.Card;
import forge.game.spellability.SpellAbility;
......@@ -42,15 +43,15 @@ public class ReplaceCounter extends ReplacementEffect {
* @see forge.card.replacement.ReplacementEffect#canReplace(java.util.HashMap)
*/
@Override
public boolean canReplace(Map<String, Object> runParams) {
final SpellAbility spellAbility = (SpellAbility) runParams.get("TgtSA");
public boolean canReplace(Map<AbilityKey, Object> runParams) {
final SpellAbility spellAbility = (SpellAbility) runParams.get(AbilityKey.TgtSA);
if (hasParam("ValidCard")) {
if (!matchesValid(runParams.get("Affected"), getParam("ValidCard").split(","), this.getHostCard())) {
if (!matchesValid(runParams.get(AbilityKey.Affected), getParam("ValidCard").split(","), this.getHostCard())) {
return false;
}
}
if (hasParam("ValidCause")) {
if (!matchesValid(runParams.get("Cause"), getParam("ValidCause").split(","), this.getHostCard())) {
if (!matchesValid(runParams.get(AbilityKey.Cause), getParam("ValidCause").split(","), this.getHostCard())) {
return false;
}
}
......@@ -67,8 +68,8 @@ public class ReplaceCounter extends ReplacementEffect {
* @see forge.card.replacement.ReplacementEffect#setReplacingObjects(java.util.HashMap, forge.card.spellability.SpellAbility)
*/
@Override
public void setReplacingObjects(Map<String, Object> runParams, SpellAbility sa) {
sa.setReplacingObject("Card", runParams.get("Affected"));
public void setReplacingObjects(Map<AbilityKey, Object> runParams, SpellAbility sa) {
sa.setReplacingObject(AbilityKey.Card, runParams.get(AbilityKey.Affected));
}
}
......@@ -17,6 +17,7 @@
*/
package forge.game.replacement;
import forge.game.ability.AbilityKey;
import forge.game.ability.AbilityUtils;
import forge.game.card.Card;
import forge.game.card.CardFactoryUtil;
......@@ -46,49 +47,49 @@ public class ReplaceDamage extends ReplacementEffect {
* @see forge.card.replacement.ReplacementEffect#canReplace(java.util.HashMap)
*/
@Override
public boolean canReplace(Map<String, Object> runParams) {
if (!(runParams.containsKey("Prevention") == (hasParam("PreventionEffect") || hasParam("Prevent")))) {
public boolean canReplace(Map<AbilityKey, Object> runParams) {
if (!(runParams.containsKey(AbilityKey.Prevention) == (hasParam("PreventionEffect") || hasParam("Prevent")))) {
return false;
}
if (((Integer) runParams.get("DamageAmount")) == 0) {
if (((Integer) runParams.get(AbilityKey.DamageAmount)) == 0) {
// If no actual damage is dealt, there is nothing to replace
return false;
}
if (hasParam("ValidSource")) {
String validSource = getParam("ValidSource");
validSource = AbilityUtils.applyAbilityTextChangeEffects(validSource, this);
if (!matchesValid(runParams.get("DamageSource"), validSource.split(","), getHostCard())) {
if (!matchesValid(runParams.get(AbilityKey.DamageSource), validSource.split(","), getHostCard())) {
return false;
}
}
if (hasParam("ValidTarget")) {
String validTarget = getParam("ValidTarget");
validTarget = AbilityUtils.applyAbilityTextChangeEffects(validTarget, this);
if (!matchesValid(runParams.get("Affected"), validTarget.split(","), getHostCard())) {
if (!matchesValid(runParams.get(AbilityKey.Affected), validTarget.split(","), getHostCard())) {
return false;
}
}
if (hasParam("ValidCause")) {
if (!runParams.containsKey("Cause")) {
if (!runParams.containsKey(AbilityKey.Cause)) {
return false;
}
SpellAbility cause = (SpellAbility) runParams.get("Cause");
SpellAbility cause = (SpellAbility) runParams.get(AbilityKey.Cause);
String validCause = getParam("ValidCause");
validCause = AbilityUtils.applyAbilityTextChangeEffects(validCause, this);
if (!matchesValid(cause, validCause.split(","), getHostCard())) {
return false;
}
if (hasParam("CauseIsSource")) {
if (!cause.getHostCard().equals(runParams.get("DamageSource"))) {
if (!cause.getHostCard().equals(runParams.get(AbilityKey.DamageSource))) {
return false;
}
}
}
if (hasParam("RelativeToSource")) {
Card source = (Card) runParams.get("DamageSource");
Card source = (Card) runParams.get(AbilityKey.DamageSource);
String validRelative = getParam("RelativeToSource");
validRelative = AbilityUtils.applyAbilityTextChangeEffects(validRelative, this);
if (!matchesValid(runParams.get("DamageTarget"), validRelative.split(","), source)) {
if (!matchesValid(runParams.get(AbilityKey.DamageTarget), validRelative.split(","), source)) {
return false;
}
}
......@@ -103,17 +104,17 @@ public class ReplaceDamage extends ReplacementEffect {
intoperand = CardFactoryUtil.xCount(getHostCard(), getHostCard().getSVar(operand));
}
if (!Expressions.compare((Integer) runParams.get("DamageAmount"), operator, intoperand)) {
if (!Expressions.compare((Integer) runParams.get(AbilityKey.DamageAmount), operator, intoperand)) {
return false;
}
}
if (hasParam("IsCombat")) {
if (getParam("IsCombat").equals("True")) {
if (!((Boolean) runParams.get("IsCombat"))) {
if (!((Boolean) runParams.get(AbilityKey.IsCombat))) {
return false;
}
} else {
if ((Boolean) runParams.get("IsCombat")) {
if ((Boolean) runParams.get(AbilityKey.IsCombat)) {
return false;
}
}
......@@ -149,10 +150,10 @@ public class ReplaceDamage extends ReplacementEffect {
* @see forge.card.replacement.ReplacementEffect#setReplacingObjects(java.util.HashMap, forge.card.spellability.SpellAbility)
*/
@Override
public void setReplacingObjects(Map<String, Object> runParams, SpellAbility sa) {
sa.setReplacingObject("DamageAmount", runParams.get("DamageAmount"));
sa.setReplacingObject("Target", runParams.get("Affected"));
sa.setReplacingObject("Source", runParams.get("DamageSource"));
public void setReplacingObjects(Map<AbilityKey, Object> runParams, SpellAbility sa) {
sa.setReplacingObject(AbilityKey.DamageAmount, runParams.get(AbilityKey.DamageAmount));
sa.setReplacingObject(AbilityKey.Target, runParams.get(AbilityKey.Affected));
sa.setReplacingObject(AbilityKey.Source, runParams.get(AbilityKey.DamageSource));
}
}
......@@ -17,6 +17,7 @@
*/
package forge.game.replacement;
import forge.game.ability.AbilityKey;
import forge.game.card.Card;
import forge.game.spellability.SpellAbility;
......@@ -42,23 +43,23 @@ public class ReplaceDestroy extends ReplacementEffect {
* @see forge.card.replacement.ReplacementEffect#canReplace(java.util.HashMap)
*/
@Override
public boolean canReplace(Map<String, Object> runParams) {
public boolean canReplace(Map<AbilityKey, Object> runParams) {
if (hasParam("ValidPlayer")) {
if (!matchesValid(runParams.get("Affected"), getParam("ValidPlayer").split(","), getHostCard())) {
if (!matchesValid(runParams.get(AbilityKey.Affected), getParam("ValidPlayer").split(","), getHostCard())) {
return false;
}
}
if (hasParam("ValidCard")) {
Card card = (Card)runParams.get("Card");
Card card = (Card)runParams.get(AbilityKey.Card);
if (!matchesValid(card, getParam("ValidCard").split(","), getHostCard())) {
return false;
}
// extra check for Regeneration
if (hasParam("Regeneration")) {
if (!runParams.containsKey("Regeneration")) {
if (!runParams.containsKey(AbilityKey.Regeneration)) {
return false;
}
if (!(Boolean)runParams.get("Regeneration")) {
if (!(Boolean)runParams.get(AbilityKey.Regeneration)) {
return false;
}
if (!card.canBeShielded()) {
......@@ -71,7 +72,7 @@ public class ReplaceDestroy extends ReplacementEffect {
}
}
if (hasParam("ValidSource")) {
if (!matchesValid(runParams.get("Source"), getParam("ValidSource").split(","), getHostCard())) {
if (!matchesValid(runParams.get(AbilityKey.Source), getParam("ValidSource").split(","), getHostCard())) {
return false;
}
}
......@@ -83,8 +84,8 @@ public class ReplaceDestroy extends ReplacementEffect {
* @see forge.card.replacement.ReplacementEffect#setReplacingObjects(java.util.HashMap, forge.card.spellability.SpellAbility)
*/
@Override
public void setReplacingObjects(Map<String, Object> runParams, SpellAbility sa) {
sa.setReplacingObject("Card", runParams.get("Card"));
public void setReplacingObjects(Map<AbilityKey, Object> runParams, SpellAbility sa) {
sa.setReplacingObject(AbilityKey.Card, runParams.get(AbilityKey.Card));
}
}
......@@ -17,6 +17,7 @@
*/
package forge.game.replacement;
import forge.game.ability.AbilityKey;
import forge.game.card.Card;
import forge.game.spellability.SpellAbility;
......@@ -42,24 +43,24 @@ public class ReplaceDiscard extends ReplacementEffect {
* @see forge.card.replacement.ReplacementEffect#canReplace(java.util.HashMap)
*/
@Override
public boolean canReplace(Map<String, Object> runParams) {
public boolean canReplace(Map<AbilityKey, Object> runParams) {
if (hasParam("ValidPlayer")) {
if (!matchesValid(runParams.get("Affected"), getParam("ValidPlayer").split(","), this.getHostCard())) {
if (!matchesValid(runParams.get(AbilityKey.Affected), getParam("ValidPlayer").split(","), this.getHostCard())) {
return false;
}
}
if (hasParam("ValidCard")) {
if (!matchesValid(runParams.get("Card"), getParam("ValidCard").split(","), this.getHostCard())) {
if (!matchesValid(runParams.get(AbilityKey.Card), getParam("ValidCard").split(","), this.getHostCard())) {
return false;
}
}
if (hasParam("ValidSource")) {
if (!matchesValid(runParams.get("Source"), getParam("ValidSource").split(","), this.getHostCard())) {
if (!matchesValid(runParams.get(AbilityKey.Source), getParam("ValidSource").split(","), this.getHostCard())) {
return false;
}
}
if (hasParam("DiscardFromEffect")) {
if (null == runParams.get("Source")) {
if (null == runParams.get(AbilityKey.Source)) {
return false;
}
}
......@@ -71,10 +72,10 @@ public class ReplaceDiscard extends ReplacementEffect {
* @see forge.card.replacement.ReplacementEffect#setReplacingObjects(java.util.HashMap, forge.card.spellability.SpellAbility)
*/
@Override
public void setReplacingObjects(Map<String, Object> runParams, SpellAbility sa) {
sa.setReplacingObject("Card", runParams.get("Card"));
sa.setReplacingObject("Player", runParams.get("Affected"));
sa.setReplacingObject("Source", runParams.get("Source"));
public void setReplacingObjects(Map<AbilityKey, Object> runParams, SpellAbility sa) {
sa.setReplacingObject(AbilityKey.Card, runParams.get(AbilityKey.Card));
sa.setReplacingObject(AbilityKey.Player, runParams.get(AbilityKey.Affected));
sa.setReplacingObject(AbilityKey.Source, runParams.get(AbilityKey.Source));
}
}
......@@ -17,6 +17,7 @@
*/
package forge.game.replacement;
import forge.game.ability.AbilityKey;
import forge.game.card.Card;
import forge.game.phase.PhaseType;
import forge.game.player.Player;
......@@ -44,14 +45,14 @@ public class ReplaceDraw extends ReplacementEffect {
* @see forge.card.replacement.ReplacementEffect#canReplace(java.util.HashMap)
*/
@Override
public boolean canReplace(Map<String, Object> runParams) {
public boolean canReplace(Map<AbilityKey, Object> runParams) {
if (hasParam("ValidPlayer")) {
if (!matchesValid(runParams.get("Affected"), getParam("ValidPlayer").split(","), this.getHostCard())) {
if (!matchesValid(runParams.get(AbilityKey.Affected), getParam("ValidPlayer").split(","), this.getHostCard())) {
return false;
}
}
if (hasParam("NotFirstCardInDrawStep")) {
final Player p = (Player)runParams.get("Affected");
final Player p = (Player)runParams.get(AbilityKey.Affected);
if (p.numDrawnThisDrawStep() == 0
&& this.getHostCard().getGame().getPhaseHandler().is(PhaseType.DRAW)