Card: add EtbCounter functions: that does handle ETB counter effects with Replacements better

This commit is contained in:
Hanmac
2017-02-02 06:08:42 +00:00
parent e6b828af71
commit faa1e000df
3 changed files with 41 additions and 3 deletions

View File

@@ -227,7 +227,7 @@ public class GameAction {
copied.getOwner().addInboundToken(copied);
}
HashMap<String, Object> repParams = new HashMap<String, Object>();
Map<String, Object> repParams = Maps.newHashMap();
repParams.put("Event", "Moved");
repParams.put("Affected", copied);
repParams.put("CardLKI", lastKnownInfo);
@@ -252,6 +252,10 @@ public class GameAction {
lastKnownInfo = CardUtil.getLKICopy(c);
c.setUnearthed(false);
}
if (toBattlefield) {
copied.putEtbCounters();
}
}
copied.getOwner().removeInboundToken(copied);

View File

@@ -192,7 +192,11 @@ public class CountersPutEffect extends SpellAbilityEffect {
}
final Zone zone = tgtCard.getGame().getZoneOf(tgtCard);
if (zone == null || zone.is(ZoneType.Battlefield) || zone.is(ZoneType.Stack)) {
tgtCard.addCounter(counterType, counterAmount, true);
if (etbcounter) {
tgtCard.addEtbCounter(counterType, counterAmount);
} else {
tgtCard.addCounter(counterType, counterAmount, true);
}
if (remember) {
final int value = tgtCard.getTotalCountersToAdd();
tgtCard.addCountersAddedBy(card, counterType, value);
@@ -219,7 +223,11 @@ public class CountersPutEffect extends SpellAbilityEffect {
} else {
// adding counters to something like re-suspend cards
// etbcounter should apply multiplier
tgtCard.addCounter(counterType, counterAmount, etbcounter);
if (etbcounter) {
tgtCard.addEtbCounter(counterType, counterAmount);
} else {
tgtCard.addCounter(counterType, counterAmount, false);
}
}
}
} else if (obj instanceof Player) {

View File

@@ -242,6 +242,8 @@ public class Card extends GameEntity implements Comparable<Card> {
private CardRules cardRules;
private final CardView view;
private Map<CounterType, Integer> etbCounters = Maps.newEnumMap(CounterType.class);
// Enumeration for CMC request types
public enum SplitCMCMode {
CurrentSideCMC,
@@ -7126,4 +7128,28 @@ public class Card extends GameEntity implements Comparable<Card> {
public final void setLastKnownZone(Zone zone) {
this.savedLastKnownZone = zone;
}
/**
* ETBCounters are only used between replacementEffects
* and when the Card really enters the Battlefield with the counters
* @return map of counters
*/
public final Map<CounterType,Integer> getEtbCounters() {
return etbCounters;
}
public final void addEtbCounter(CounterType type, Integer val) {
int old = etbCounters.containsKey(type) ? etbCounters.get(type) : 0;
etbCounters.put(type, old + val);
}
public final void clearEtbCounters() {
etbCounters.clear();
}
public final void putEtbCounters() {
for (Map.Entry<CounterType, Integer> e : etbCounters.entrySet()) {
this.addCounter(e.getKey(), e.getValue(), true);
}
}
}