Commit df4b0b03 authored by Ryan Wiedemann's avatar Ryan Wiedemann

remove `runOld` and `getReplacementListOld`

parent a3b0d8ac
......@@ -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);
......
......@@ -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)
......
......@@ -85,6 +85,7 @@ public enum AbilityKey {
Origin("Origin"),
OriginalController("OriginalController"),
OriginalDefender("OriginalDefender"),
OriginalParams("OriginalParams"),
PayingMana("PayingMana"),
Phase("Phase"),
Player("Player"),
......@@ -92,6 +93,7 @@ public enum AbilityKey {
Prevention("Prevention"),
Produced("Produced"),
Regeneration("Regeneration"),
ReplacementResult("ReplacementResult"),
Result("Result"),
Scheme("Scheme"),
Source("Source"),
......
......@@ -2,6 +2,7 @@ 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;
......@@ -31,10 +32,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,27 +55,27 @@ 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
ReplacementResult result = game.getReplacementHandler().runOld(event, 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;
}
}
......
......@@ -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,25 +57,25 @@ 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
ReplacementResult result = game.getReplacementHandler().runOld(retype, params);
ReplacementResult result = game.getReplacementHandler().run(retype, 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;
}
}
......
......@@ -3,6 +3,7 @@ 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;
......@@ -36,10 +37,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 +58,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 +75,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().runOld(event, 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;
}
}
......
......@@ -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.
......
......@@ -599,10 +599,22 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
public boolean hasReplacingObject(final String type) {
return replacingObjects.containsKey(type);
}
public Object getReplacingObject(final AbilityKey type) {
return getReplacingObject(type.toString());
}
// Eventually we want to switch the internal map to be a `Map<AbilityKey, Object>` instead of a
// `Map<String, Object>`.
@Deprecated
public Object getReplacingObject(final String type) {
final Object res = replacingObjects.get(type);
return res;
}
public void setReplacingObject(final AbilityKey type, final Object o) {
setReplacingObject(type.toString(), o);
}
// Eventually we want to switch the internal map to be a `Map<AbilityKey, Object>` instead of a
// `Map<String, Object>`.
@Deprecated
public void setReplacingObject(final String type, final Object o) {
replacingObjects.put(type, o);
}
......
......@@ -506,7 +506,7 @@ public class PlayerControllerForTests extends PlayerController {
}
@Override
public ReplacementEffect chooseSingleReplacementEffect(String prompt, List<ReplacementEffect> possibleReplacers, Map<String, Object> runParams) {
public ReplacementEffect chooseSingleReplacementEffect(String prompt, List<ReplacementEffect> possibleReplacers) {
// TODO Auto-generated method stub
return Iterables.getFirst(possibleReplacers, null);
}
......
......@@ -1587,7 +1587,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
@Override
public ReplacementEffect chooseSingleReplacementEffect(final String prompt,
final List<ReplacementEffect> possibleReplacers, final Map<String, Object> runParams) {
final List<ReplacementEffect> possibleReplacers) {
final ReplacementEffect first = possibleReplacers.get(0);
if (possibleReplacers.size() == 1) {
return first;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment