Commit 5f3a0b3f authored by Ryan Wiedemann's avatar Ryan Wiedemann

change `replacingObjects` type

parent f6134e3c
Pipeline #1776 failed with stage
......@@ -1814,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);
}
......
......@@ -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) {
......
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
......@@ -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,11 @@ 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()) {
Object replacingObject = root.getReplacingObject(AbilityKey.Cause);
if (replacingObject != null) {
cause = (SpellAbility) replacingObject;
}
}
final boolean remember = sa.hasParam("RememberTokens");
......
......@@ -72,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);
}
}
......
......@@ -68,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));
}
}
......@@ -150,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));
}
}
......@@ -84,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));
}
}
......@@ -72,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));
}
}
......@@ -69,7 +69,7 @@ public class ReplaceDraw 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("Player", runParams.get("Affected"));
public void setReplacingObjects(Map<AbilityKey, Object> runParams, SpellAbility sa) {
sa.setReplacingObject(AbilityKey.Player, runParams.get(AbilityKey.Affected));
}
}
......@@ -69,7 +69,7 @@ public class ReplaceDrawCards 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("Player", runParams.get("Affected"));
public void setReplacingObjects(Map<AbilityKey, Object> runParams, SpellAbility sa) {
sa.setReplacingObject(AbilityKey.Player, runParams.get(AbilityKey.Affected));
}
}
......@@ -70,9 +70,9 @@ public class ReplaceGainLife 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("LifeGained", runParams.get("LifeGained"));
sa.setReplacingObject("Player", runParams.get("Affected"));
public void setReplacingObjects(Map<AbilityKey, Object> runParams, SpellAbility sa) {
sa.setReplacingObject(AbilityKey.LifeGained, runParams.get(AbilityKey.LifeGained));
sa.setReplacingObject(AbilityKey.Player, runParams.get(AbilityKey.Affected));
}
}
......@@ -117,10 +117,10 @@ public class ReplaceMoved 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"));
sa.setReplacingObject("CardLKI", runParams.get("CardLKI"));
sa.setReplacingObject("Cause", runParams.get("Cause"));
public void setReplacingObjects(Map<AbilityKey, Object> runParams, SpellAbility sa) {
sa.setReplacingObject(AbilityKey.Card, runParams.get(AbilityKey.Affected));
sa.setReplacingObject(AbilityKey.CardLKI, runParams.get(AbilityKey.CardLKI));
sa.setReplacingObject(AbilityKey.Cause, runParams.get(AbilityKey.Cause));
}
}
......@@ -44,9 +44,9 @@ public class ReplaceSurveil extends ReplacementEffect {
* @see forge.card.replacement.ReplacementEffect#setReplacingObjects(java.util.Map, forge.card.spellability.SpellAbility)
*/
@Override
public void setReplacingObjects(Map<String, Object> runParams, SpellAbility sa) {
sa.setReplacingObject("Player", runParams.get("Affected"));
sa.setReplacingObject("SurveilNum", runParams.get("SurveilNum"));
public void setReplacingObjects(Map<AbilityKey, Object> runParams, SpellAbility sa) {
sa.setReplacingObject(AbilityKey.Player, runParams.get(AbilityKey.Affected));
sa.setReplacingObject(AbilityKey.SurveilNum, runParams.get(AbilityKey.SurveilNum));
}
}
......@@ -62,9 +62,9 @@ public class ReplaceToken extends ReplacementEffect {
* @see forge.card.replacement.ReplacementEffect#setReplacingObjects(java.util.Map, forge.card.spellability.SpellAbility)
*/
@Override
public void setReplacingObjects(Map<String, Object> runParams, SpellAbility sa) {
sa.setReplacingObject("TokenNum", runParams.get("TokenNum"));
sa.setReplacingObject("Player", runParams.get("Affected"));
public void setReplacingObjects(Map<AbilityKey, Object> runParams, SpellAbility sa) {
sa.setReplacingObject(AbilityKey.TokenNum, runParams.get(AbilityKey.TokenNum));
sa.setReplacingObject(AbilityKey.Player, runParams.get(AbilityKey.Affected));
}
}
......@@ -39,8 +39,8 @@ public class ReplaceTurnFaceUp 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));
}
}
......@@ -73,8 +73,8 @@ public class ReplaceUntap 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));
}
}
......@@ -200,13 +200,11 @@ public abstract class ReplacementEffect extends TriggerReplacementBase {
/**
* Sets the replacing objects.
*
* @param runParams
* @param runParams
* the run params
* @param spellAbility
* the SpellAbility
*/
public void setReplacingObjects(final Map<String, Object> runParams, final SpellAbility spellAbility) {
public void setReplacingObjects(final Map<AbilityKey, Object> runParams, final SpellAbility spellAbility) {
// Should be overridden by replacers that need it.
}
......
......@@ -238,7 +238,7 @@ public class ReplacementHandler {
SpellAbility tailend = effectSA;
do {
replacementEffect.setReplacingObjects(toStringMap(runParams), tailend);
replacementEffect.setReplacingObjects(runParams, tailend);
//set original Params to update them later
tailend.setReplacingObject(AbilityKey.OriginalParams, runParams);
tailend = tailend.getSubAbility();
......@@ -249,7 +249,7 @@ public class ReplacementHandler {
effectSA = replacementEffect.getOverridingAbility();
SpellAbility tailend = effectSA;
do {
replacementEffect.setReplacingObjects(toStringMap(runParams), tailend);
replacementEffect.setReplacingObjects(runParams, tailend);
//set original Params to update them later
tailend.setReplacingObject(AbilityKey.OriginalParams, runParams);
tailend = tailend.getSubAbility();
......
......@@ -143,7 +143,7 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
private EnumMap<AbilityKey, Object> triggeringObjects = AbilityKey.newMap();
private HashMap<String, Object> replacingObjects = Maps.newHashMap();
private EnumMap<AbilityKey, Object> replacingObjects = AbilityKey.newMap();
private List<AbilitySub> chosenList = null;
private CardCollection tappedForConvoke = new CardCollection();
......@@ -593,29 +593,15 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
triggerRemembered = Lists.newArrayList();
}
public HashMap<String, Object> getReplacingObjects() {
public Map<AbilityKey, Object> getReplacingObjects() {
return replacingObjects;
}
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);
}
......
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