Commit d11bafd2 authored by Hans Mackowiak's avatar Hans Mackowiak

GameAction: fixed putEtbCounters with Arixmethes

parent 3d85051f
Pipeline #171 passed with stage
......@@ -252,11 +252,24 @@ public class GameAction {
Card noLandLKI = CardUtil.getLKICopy(c);
// this check needs to check if this card would be on the battlefield
noLandLKI.setLastKnownZone(zoneTo);
CardCollection preList = new CardCollection(noLandLKI);
checkStaticAbilities(false, Sets.newHashSet(noLandLKI), preList);
// fake etb counters thing, then if something changed,
// need to apply checkStaticAbilities again
if(!noLandLKI.isLand()) {
if (noLandLKI.putEtbCounters()) {
// counters are added need to check again
checkStaticAbilities(false, Sets.newHashSet(noLandLKI), preList);
}
}
if(noLandLKI.isLand()) {
// if it isn't on the Stack, it stays in that Zone
if (!c.getZone().is(ZoneType.Stack)) {
return c;
}
// if something would only be a land when entering the battlefield and not before
// put it into the graveyard instead
zoneTo = c.getOwner().getZone(ZoneType.Graveyard);
......@@ -264,6 +277,9 @@ public class GameAction {
copied.setState(CardStateName.Original, false);
copied.setManifested(false);
copied.updateStateForView();
// not to battlefield anymore!
toBattlefield = false;
}
}
......@@ -359,7 +375,10 @@ public class GameAction {
// do ETB counters after StaticAbilities check
if (!suppress) {
if (toBattlefield) {
copied.putEtbCounters();
if (copied.putEtbCounters()) {
// if counter where put of card, call checkStaticAbilities again
checkStaticAbilities();
}
}
copied.clearEtbCounters();
}
......
......@@ -366,7 +366,7 @@ public abstract class GameEntity extends GameObject implements IIdentifiable {
abstract public void setCounters(final Map<CounterType, Integer> allCounters);
abstract public boolean canReceiveCounters(final CounterType type);
abstract public void addCounter(final CounterType counterType, final int n, final Player source, final boolean applyMultiplier, final boolean fireEvents);
abstract public int addCounter(final CounterType counterType, final int n, final Player source, final boolean applyMultiplier, final boolean fireEvents);
abstract public void subtractCounter(final CounterType counterName, final int n);
abstract public void clearCounters();
......
......@@ -1082,18 +1082,19 @@ public class Card extends GameEntity implements Comparable<Card> {
countersAdded = value;
}
public final void addCounter(final CounterType counterType, final int n, final Player source, final boolean applyMultiplier) {
addCounter(counterType, n, source, applyMultiplier, true);
public final int addCounter(final CounterType counterType, final int n, final Player source, final boolean applyMultiplier) {
return addCounter(counterType, n, source, applyMultiplier, true);
}
public final void addCounterFireNoEvents(final CounterType counterType, final int n, final Player source, final boolean applyMultiplier) {
addCounter(counterType, n, source, applyMultiplier, false);
public final int addCounterFireNoEvents(final CounterType counterType, final int n, final Player source, final boolean applyMultiplier) {
return addCounter(counterType, n, source, applyMultiplier, false);
}
@Override
public void addCounter(final CounterType counterType, final int n, final Player source, final boolean applyMultiplier, final boolean fireEvents) {
public int addCounter(final CounterType counterType, final int n, final Player source, final boolean applyMultiplier, final boolean fireEvents) {
int addAmount = n;
if(addAmount < 0) {
addAmount = 0; // As per rule 107.1b
return 0;
}
final Map<String, Object> repParams = Maps.newHashMap();
repParams.put("Event", "AddCounter");
......@@ -1111,7 +1112,7 @@ public class Card extends GameEntity implements Comparable<Card> {
break;
}
default:
return;
return 0;
}
if (canReceiveCounters(counterType)) {
......@@ -1124,7 +1125,7 @@ public class Card extends GameEntity implements Comparable<Card> {
}
if (addAmount <= 0) {
return;
return 0;
}
setTotalCountersToAdd(addAmount);
......@@ -1170,6 +1171,7 @@ public class Card extends GameEntity implements Comparable<Card> {
getController().addCounterToPermThisTurn(counterType, addAmount);
view.updateCounters(this);
}
return addAmount;
}
/**
......@@ -5091,7 +5093,7 @@ public class Card extends GameEntity implements Comparable<Card> {
}
public boolean isInZone(final ZoneType zone) {
Zone z = getZone();
Zone z = this.getLastKnownZone();
return z != null && z.is(zone);
}
......@@ -5791,10 +5793,24 @@ public class Card extends GameEntity implements Comparable<Card> {
etbCounters.clear();
}
public final void putEtbCounters() {
public final Set<Table.Cell<Player, CounterType, Integer>> getEtbCounters() {
return etbCounters.cellSet();
}
public final boolean putEtbCounters() {
boolean changed = false;
for (Table.Cell<Player, CounterType, Integer> e : etbCounters.cellSet()) {
this.addCounter(e.getColumnKey(), e.getValue(), e.getRowKey(), true);
CounterType ct = e.getColumnKey();
if (this.isLKI()) {
if (canReceiveCounters(ct)) {
setCounters(ct, getCounters(ct) + e.getValue());
changed = true;
}
} else {
changed |= addCounter(ct, e.getValue(), e.getRowKey(), true) > 0;
}
}
return changed;
}
public final void clearTemporaryVars() {
......
......@@ -24,6 +24,7 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.common.collect.Table;
import forge.ImageKeys;
import forge.card.CardStateName;
......@@ -270,6 +271,10 @@ public final class CardUtil {
newCopy.addImprintedCard(o);
}
for(Table.Cell<Player, CounterType, Integer> cl : in.getEtbCounters()) {
newCopy.addEtbCounter(cl.getColumnKey(), cl.getValue(), cl.getRowKey());
}
newCopy.setUnearthed(in.isUnearthed());
newCopy.setChangedCardColors(in.getChangedCardColors());
......
......@@ -876,20 +876,20 @@ public class Player extends GameEntity implements Comparable<Player> {
return true;
}
public final void addCounter(final CounterType counterType, final int n, final Player source, final boolean applyMultiplier) {
addCounter(counterType, n, source, applyMultiplier, true);
public final int addCounter(final CounterType counterType, final int n, final Player source, final boolean applyMultiplier) {
return addCounter(counterType, n, source, applyMultiplier, true);
}
@Override
public void addCounter(CounterType counterType, int n, final Player source, boolean applyMultiplier, boolean fireEvents) {
public int addCounter(CounterType counterType, int n, final Player source, boolean applyMultiplier, boolean fireEvents) {
if (!canReceiveCounters(counterType)) {
return;
return 0;
}
int addAmount = n;
if(addAmount <= 0) {
// Can't add negative or 0 counters, bail out now
return;
return 0;
}
final Map<String, Object> repParams = Maps.newHashMap();
......@@ -908,7 +908,7 @@ public class Player extends GameEntity implements Comparable<Player> {
break;
}
default:
return;
return 0;
}
final int oldValue = getCounters(counterType);
......@@ -925,6 +925,7 @@ public class Player extends GameEntity implements Comparable<Player> {
if (addAmount > 0) {
getGame().getTriggerHandler().runTrigger(TriggerType.CounterAddedOnce, runParams, false);
}
return addAmount;
}
@Override
......
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