mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 02:08:00 +00:00
Effects: add gameCardState check with equalWithTimestamp
This commit is contained in:
@@ -100,6 +100,7 @@ public class CountersMoveEffect extends SpellAbilityEffect {
|
||||
// Test to see if the card we're trying to add is in the expected state
|
||||
return;
|
||||
}
|
||||
dest = cur;
|
||||
|
||||
int csum = 0;
|
||||
|
||||
@@ -194,15 +195,15 @@ public class CountersMoveEffect extends SpellAbilityEffect {
|
||||
Map<String, Object> params = Maps.newHashMap();
|
||||
params.put("CounterType", cType);
|
||||
params.put("Source", source);
|
||||
params.put("Target", dest);
|
||||
params.put("Target", cur);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Put how many ").append(cType.getName()).append(" counters on ").append(dest).append("?");
|
||||
sb.append("Put how many ").append(cType.getName()).append(" counters on ").append(cur).append("?");
|
||||
int cnum = player.getController().chooseNumber(sa, sb.toString(), 0, source.getCounters(cType), params);
|
||||
|
||||
if (cnum > 0) {
|
||||
source.subtractCounter(cType, cnum);
|
||||
dest.addCounter(cType, cnum, player, true);
|
||||
game.updateLastStateForCard(dest);
|
||||
cur.addCounter(cType, cnum, player, true);
|
||||
game.updateLastStateForCard(cur);
|
||||
updateSource = true;
|
||||
}
|
||||
}
|
||||
@@ -245,7 +246,7 @@ public class CountersMoveEffect extends SpellAbilityEffect {
|
||||
}
|
||||
|
||||
if (!"Any".matches(counterName)) {
|
||||
if (!dest.canReceiveCounters(cType)) {
|
||||
if (!cur.canReceiveCounters(cType)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -253,7 +254,7 @@ public class CountersMoveEffect extends SpellAbilityEffect {
|
||||
Map<String, Object> params = Maps.newHashMap();
|
||||
params.put("CounterType", cType);
|
||||
params.put("Source", source);
|
||||
params.put("Target", dest);
|
||||
params.put("Target", cur);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Take how many ").append(cType.getName());
|
||||
sb.append(" counters from ").append(source).append("?");
|
||||
@@ -262,8 +263,8 @@ public class CountersMoveEffect extends SpellAbilityEffect {
|
||||
|
||||
if (source.getCounters(cType) >= cntToMove) {
|
||||
source.subtractCounter(cType, cntToMove);
|
||||
dest.addCounter(cType, cntToMove, player, true);
|
||||
game.updateLastStateForCard(dest);
|
||||
cur.addCounter(cType, cntToMove, player, true);
|
||||
game.updateLastStateForCard(cur);
|
||||
}
|
||||
} else {
|
||||
// any counterType currently only Leech Bonder
|
||||
|
||||
@@ -135,9 +135,10 @@ public class CountersPutEffect extends SpellAbilityEffect {
|
||||
|
||||
for (final GameObject obj : tgtObjects) {
|
||||
// check if the object is still in game or if it was moved
|
||||
Card gameCard = null;
|
||||
if (obj instanceof Card) {
|
||||
Card tgtCard = (Card) obj;
|
||||
Card gameCard = game.getCardState(tgtCard, null);
|
||||
gameCard = game.getCardState(tgtCard, null);
|
||||
// gameCard is LKI in that case, the card is not in game anymore
|
||||
// or the timestamp did change
|
||||
// this should check Self too
|
||||
@@ -164,7 +165,7 @@ public class CountersPutEffect extends SpellAbilityEffect {
|
||||
((Player) obj).addCounter(ct, counterAmount, placer, true);
|
||||
}
|
||||
if (obj instanceof Card) {
|
||||
((Card) obj).addCounter(ct, counterAmount, placer, true);
|
||||
gameCard.addCounter(ct, counterAmount, placer, true);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
@@ -185,7 +186,7 @@ public class CountersPutEffect extends SpellAbilityEffect {
|
||||
}
|
||||
|
||||
if (obj instanceof Card) {
|
||||
Card tgtCard = (Card) obj;
|
||||
Card tgtCard = gameCard;
|
||||
counterAmount = sa.usesTargeting() && sa.hasParam("DividedAsYouChoose") ? sa.getTargetRestrictions().getDividedValue(tgtCard) : counterAmount;
|
||||
if (!sa.usesTargeting() || tgtCard.canBeTargetedBy(sa)) {
|
||||
if (max != -1) {
|
||||
|
||||
@@ -65,16 +65,16 @@ public class CountersPutOrRemoveEffect extends SpellAbilityEffect {
|
||||
if (gameCard == null || !tgtCard.equalsWithTimestamp(gameCard)) {
|
||||
continue;
|
||||
}
|
||||
if (!sa.usesTargeting() || tgtCard.canBeTargetedBy(sa)) {
|
||||
if (tgtCard.hasCounters()) {
|
||||
if (!sa.usesTargeting() || gameCard.canBeTargetedBy(sa)) {
|
||||
if (gameCard.hasCounters()) {
|
||||
if (sa.hasParam("EachExistingCounter")) {
|
||||
for (CounterType listType : Lists.newArrayList(tgtCard.getCounters().keySet())) {
|
||||
addOrRemoveCounter(sa, tgtCard, listType, counterAmount);
|
||||
for (CounterType listType : Lists.newArrayList(gameCard.getCounters().keySet())) {
|
||||
addOrRemoveCounter(sa, gameCard, listType, counterAmount);
|
||||
}
|
||||
} else {
|
||||
addOrRemoveCounter(sa, tgtCard, ctype, counterAmount);
|
||||
addOrRemoveCounter(sa, gameCard, ctype, counterAmount);
|
||||
}
|
||||
game.updateLastStateForCard(tgtCard);
|
||||
game.updateLastStateForCard(gameCard);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,27 +115,27 @@ public class CountersRemoveEffect extends SpellAbilityEffect {
|
||||
if (gameCard == null || !tgtCard.equalsWithTimestamp(gameCard)) {
|
||||
continue;
|
||||
}
|
||||
if (!sa.usesTargeting() || tgtCard.canBeTargetedBy(sa)) {
|
||||
if (!sa.usesTargeting() || gameCard.canBeTargetedBy(sa)) {
|
||||
final Zone zone = game.getZoneOf(gameCard);
|
||||
if (type.equals("All")) {
|
||||
for (Map.Entry<CounterType, Integer> e : tgtCard.getCounters().entrySet()) {
|
||||
tgtCard.subtractCounter(e.getKey(), e.getValue());
|
||||
for (Map.Entry<CounterType, Integer> e : gameCard.getCounters().entrySet()) {
|
||||
gameCard.subtractCounter(e.getKey(), e.getValue());
|
||||
}
|
||||
game.updateLastStateForCard(tgtCard);
|
||||
game.updateLastStateForCard(gameCard);
|
||||
continue;
|
||||
} else if (num.equals("All")) {
|
||||
cntToRemove = tgtCard.getCounters(counterType);
|
||||
cntToRemove = gameCard.getCounters(counterType);
|
||||
} else if (sa.getParam("CounterNum").equals("Remembered")) {
|
||||
cntToRemove = tgtCard.getCountersAddedBy(card, counterType);
|
||||
cntToRemove = gameCard.getCountersAddedBy(card, counterType);
|
||||
}
|
||||
|
||||
PlayerController pc = sa.getActivatingPlayer().getController();
|
||||
|
||||
if (type.equals("Any")) {
|
||||
while (cntToRemove > 0 && tgtCard.hasCounters()) {
|
||||
final Map<CounterType, Integer> tgtCounters = tgtCard.getCounters();
|
||||
while (cntToRemove > 0 && gameCard.hasCounters()) {
|
||||
final Map<CounterType, Integer> tgtCounters = gameCard.getCounters();
|
||||
Map<String, Object> params = Maps.newHashMap();
|
||||
params.put("Target", tgtCard);
|
||||
params.put("Target", gameCard);
|
||||
|
||||
String prompt = "Select type of counters to remove";
|
||||
CounterType chosenType = pc.chooseCounterType(
|
||||
@@ -143,13 +143,13 @@ public class CountersRemoveEffect extends SpellAbilityEffect {
|
||||
prompt = "Select the number of " + chosenType.getName() + " counters to remove";
|
||||
int max = Math.min(cntToRemove, tgtCounters.get(chosenType));
|
||||
params = Maps.newHashMap();
|
||||
params.put("Target", tgtCard);
|
||||
params.put("Target", gameCard);
|
||||
params.put("CounterType", chosenType);
|
||||
int chosenAmount = pc.chooseNumber(sa, prompt, 1, max, params);
|
||||
|
||||
if (chosenAmount > 0) {
|
||||
tgtCard.subtractCounter(chosenType, chosenAmount);
|
||||
game.updateLastStateForCard(tgtCard);
|
||||
gameCard.subtractCounter(chosenType, chosenAmount);
|
||||
game.updateLastStateForCard(gameCard);
|
||||
if (rememberRemoved) {
|
||||
for (int i = 0; i < chosenAmount; i++) {
|
||||
card.addRemembered(Pair.of(chosenType, i));
|
||||
@@ -159,12 +159,12 @@ public class CountersRemoveEffect extends SpellAbilityEffect {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cntToRemove = Math.min(cntToRemove, tgtCard.getCounters(counterType));
|
||||
cntToRemove = Math.min(cntToRemove, gameCard.getCounters(counterType));
|
||||
|
||||
if (zone.is(ZoneType.Battlefield) || zone.is(ZoneType.Exile)) {
|
||||
if (sa.hasParam("UpTo")) {
|
||||
Map<String, Object> params = Maps.newHashMap();
|
||||
params.put("Target", tgtCard);
|
||||
params.put("Target", gameCard);
|
||||
params.put("CounterType", type);
|
||||
String title = "Select the number of " + type + " counters to remove";
|
||||
cntToRemove = pc.chooseNumber(sa, title, 0, cntToRemove, params);
|
||||
@@ -172,13 +172,13 @@ public class CountersRemoveEffect extends SpellAbilityEffect {
|
||||
|
||||
}
|
||||
if (cntToRemove > 0) {
|
||||
tgtCard.subtractCounter(counterType, cntToRemove);
|
||||
gameCard.subtractCounter(counterType, cntToRemove);
|
||||
if (rememberRemoved) {
|
||||
for (int i = 0; i < cntToRemove; i++) {
|
||||
card.addRemembered(Pair.of(counterType, i));
|
||||
}
|
||||
}
|
||||
game.updateLastStateForCard(tgtCard);
|
||||
game.updateLastStateForCard(gameCard);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package forge.game.ability.effects;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import forge.game.Game;
|
||||
import forge.game.GameObject;
|
||||
import forge.game.ability.AbilityUtils;
|
||||
import forge.game.card.Card;
|
||||
@@ -68,6 +70,7 @@ public class DamageDealEffect extends DamageBaseEffect {
|
||||
@Override
|
||||
public void resolve(SpellAbility sa) {
|
||||
final Card hostCard = sa.getHostCard();
|
||||
final Game game = hostCard.getGame();
|
||||
|
||||
final String damage = sa.getParam("NumDmg");
|
||||
int dmg = AbilityUtils.calculateAmount(hostCard, damage, sa);
|
||||
@@ -176,7 +179,12 @@ public class DamageDealEffect extends DamageBaseEffect {
|
||||
dmg = (sa.usesTargeting() && sa.hasParam("DividedAsYouChoose")) ? sa.getTargetRestrictions().getDividedValue(o) : dmg;
|
||||
if (o instanceof Card) {
|
||||
final Card c = (Card) o;
|
||||
if (c.isInPlay() && (!targeted || c.canBeTargetedBy(sa))) {
|
||||
final Card gc = game.getCardState(c, null);
|
||||
if (gc == null || !c.equalsWithTimestamp(gc) || !gc.isInPlay()) {
|
||||
// timestamp different or not in play
|
||||
continue;
|
||||
}
|
||||
if (!targeted || c.canBeTargetedBy(sa)) {
|
||||
if (removeDamage) {
|
||||
c.setDamage(0);
|
||||
c.setHasBeenDealtDeathtouchDamage(false);
|
||||
|
||||
@@ -86,7 +86,7 @@ public class FightEffect extends DamageBaseEffect {
|
||||
defined.addAll(AbilityUtils.getDefinedCards(host, sa.getParam("ExtraDefined"), sa));
|
||||
}
|
||||
|
||||
List<Card> remove = Lists.newArrayList();
|
||||
List<Card> newDefined = Lists.newArrayList();
|
||||
for (final Card d : defined) {
|
||||
final Card g = game.getCardState(d, null);
|
||||
// 701.12b If a creature instructed to fight is no longer on the battlefield or is no longer a creature,
|
||||
@@ -94,10 +94,12 @@ public class FightEffect extends DamageBaseEffect {
|
||||
// for a resolving spell or ability that instructs it to fight, no damage is dealt.
|
||||
if (g == null || !g.equalsWithTimestamp(d) || !d.isInPlay() || !d.isCreature()) {
|
||||
// Test to see if the card we're trying to add is in the expected state
|
||||
remove.add(d);
|
||||
continue;
|
||||
}
|
||||
newDefined.add(g);
|
||||
}
|
||||
defined.removeAll(remove);
|
||||
// replace with new List using CardState
|
||||
defined = newDefined;
|
||||
|
||||
if (!defined.isEmpty()) {
|
||||
if (defined.size() > 1 && fighter1 == null) {
|
||||
|
||||
@@ -31,32 +31,40 @@ public class PumpEffect extends SpellAbilityEffect {
|
||||
final int a, final int d, final List<String> keywords,
|
||||
final long timestamp) {
|
||||
final Card host = sa.getHostCard();
|
||||
final Game game = host.getGame();
|
||||
//if host is not on the battlefield don't apply
|
||||
// Suspend should does Affect the Stack
|
||||
if (sa.hasParam("UntilLoseControlOfHost")
|
||||
&& !(host.isInPlay() || host.isInZone(ZoneType.Stack))) {
|
||||
return;
|
||||
}
|
||||
final Game game = sa.getActivatingPlayer().getGame();
|
||||
|
||||
// do Game Check there in case of LKI
|
||||
final Card gameCard = game.getCardState(applyTo, null);
|
||||
if (gameCard == null || !applyTo.equalsWithTimestamp(gameCard)) {
|
||||
return;
|
||||
}
|
||||
final List<String> kws = Lists.newArrayList();
|
||||
|
||||
boolean redrawPT = false;
|
||||
for (String kw : keywords) {
|
||||
if (kw.startsWith("HIDDEN")) {
|
||||
applyTo.addHiddenExtrinsicKeyword(kw);
|
||||
gameCard.addHiddenExtrinsicKeyword(kw);
|
||||
redrawPT |= kw.contains("CARDNAME's power and toughness are switched");
|
||||
} else {
|
||||
kws.add(kw);
|
||||
}
|
||||
}
|
||||
|
||||
applyTo.addTempPowerBoost(a);
|
||||
applyTo.addTempToughnessBoost(d);
|
||||
applyTo.addChangedCardKeywords(kws, Lists.<String>newArrayList(), false, false, timestamp);
|
||||
if (redrawPT) { applyTo.updatePowerToughnessForView(); }
|
||||
gameCard.addTempPowerBoost(a);
|
||||
gameCard.addTempToughnessBoost(d);
|
||||
gameCard.addChangedCardKeywords(kws, Lists.<String>newArrayList(), false, false, timestamp);
|
||||
if (redrawPT) {
|
||||
gameCard.updatePowerToughnessForView();
|
||||
}
|
||||
|
||||
if (sa.hasParam("LeaveBattlefield")) {
|
||||
addLeaveBattlefieldReplacement(applyTo, sa, sa.getParam("LeaveBattlefield"));
|
||||
addLeaveBattlefieldReplacement(gameCard, sa, sa.getParam("LeaveBattlefield"));
|
||||
}
|
||||
|
||||
if (!sa.hasParam("Permanent")) {
|
||||
@@ -66,8 +74,8 @@ public class PumpEffect extends SpellAbilityEffect {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
applyTo.addTempPowerBoost(-1 * a);
|
||||
applyTo.addTempToughnessBoost(-1 * d);
|
||||
gameCard.addTempPowerBoost(-1 * a);
|
||||
gameCard.addTempToughnessBoost(-1 * d);
|
||||
|
||||
if (keywords.size() > 0) {
|
||||
boolean redrawPT = false;
|
||||
@@ -75,16 +83,16 @@ public class PumpEffect extends SpellAbilityEffect {
|
||||
for (String kw : keywords) {
|
||||
redrawPT |= kw.contains("CARDNAME's power and toughness are switched");
|
||||
if (kw.startsWith("HIDDEN")) {
|
||||
applyTo.removeHiddenExtrinsicKeyword(kw);
|
||||
gameCard.removeHiddenExtrinsicKeyword(kw);
|
||||
if (redrawPT) {
|
||||
applyTo.updatePowerToughnessForView();
|
||||
gameCard.updatePowerToughnessForView();
|
||||
}
|
||||
}
|
||||
}
|
||||
applyTo.removeChangedCardKeywords(timestamp);
|
||||
gameCard.removeChangedCardKeywords(timestamp);
|
||||
}
|
||||
|
||||
game.fireEvent(new GameEventCardStatsChanged(applyTo));
|
||||
game.fireEvent(new GameEventCardStatsChanged(gameCard));
|
||||
}
|
||||
};
|
||||
if (sa.hasParam("UntilEndOfCombat")) {
|
||||
@@ -107,7 +115,7 @@ public class PumpEffect extends SpellAbilityEffect {
|
||||
game.getEndOfTurn().addUntil(untilEOT);
|
||||
}
|
||||
}
|
||||
game.fireEvent(new GameEventCardStatsChanged(applyTo));
|
||||
game.fireEvent(new GameEventCardStatsChanged(gameCard));
|
||||
}
|
||||
|
||||
private static void applyPump(final SpellAbility sa, final Player p,
|
||||
@@ -218,7 +226,6 @@ public class PumpEffect extends SpellAbilityEffect {
|
||||
public void resolve(final SpellAbility sa) {
|
||||
|
||||
final List<Card> untargetedCards = Lists.newArrayList();
|
||||
final TargetRestrictions tgt = sa.getTargetRestrictions();
|
||||
final Game game = sa.getActivatingPlayer().getGame();
|
||||
final Card host = sa.getHostCard();
|
||||
final long timestamp = game.getNextTimestamp();
|
||||
@@ -350,7 +357,7 @@ public class PumpEffect extends SpellAbilityEffect {
|
||||
}
|
||||
|
||||
// if pump is a target, make sure we can still target now
|
||||
if ((tgt != null) && !tgtC.canBeTargetedBy(sa)) {
|
||||
if (sa.usesTargeting() && !tgtC.canBeTargetedBy(sa)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user