Skip to content

Commit

Permalink
Use fresh LastState for costs
Browse files Browse the repository at this point in the history
  • Loading branch information
TRT committed Jan 18, 2024
1 parent d2174f6 commit 9dfc64e
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ public void resolve(SpellAbility sa) {

list = GameActionUtil.orderCardsByTheirOwners(game, list, ZoneType.Graveyard, sa);

CardCollectionView lastStateBattlefield = game.copyLastStateBattlefield();
Map<AbilityKey, Object> params = AbilityKey.newMap();
params.put(AbilityKey.LastStateBattlefield, game.copyLastStateBattlefield());
CardZoneTable table = new CardZoneTable(game.getLastStateBattlefield(), game.getLastStateGraveyard());
params.put(AbilityKey.LastStateBattlefield, lastStateBattlefield);
CardZoneTable table = new CardZoneTable(lastStateBattlefield, game.getLastStateGraveyard());
params.put(AbilityKey.InternalTriggerTable, table);

Map<Integer, Card> cachedMap = Maps.newHashMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ public void resolve(SpellAbility sa) {

tgtCards = GameActionUtil.orderCardsByTheirOwners(game, tgtCards, ZoneType.Graveyard, sa);

CardCollectionView lastStateBattlefield = game.copyLastStateBattlefield();
Map<AbilityKey, Object> params = AbilityKey.newMap();
params.put(AbilityKey.LastStateBattlefield, game.copyLastStateBattlefield());
CardZoneTable table = getChangeZoneTable(sa, game.getLastStateBattlefield(), CardCollection.EMPTY);
params.put(AbilityKey.LastStateBattlefield, lastStateBattlefield);
CardZoneTable table = getChangeZoneTable(sa, lastStateBattlefield, CardCollection.EMPTY);
params.put(AbilityKey.InternalTriggerTable, table);

Map<Integer, Card> cachedMap = Maps.newHashMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@ public void resolve(SpellAbility sa) {

list = GameActionUtil.orderCardsByTheirOwners(game, list, ZoneType.Graveyard, sa);

CardCollectionView lastStateBattlefield = game.copyLastStateBattlefield();
Map<Integer, Card> cachedMap = Maps.newHashMap();
Map<AbilityKey, Object> params = AbilityKey.newMap();
params.put(AbilityKey.LastStateBattlefield, game.copyLastStateBattlefield());
CardZoneTable table = new CardZoneTable(game.getLastStateBattlefield(), CardCollection.EMPTY);
params.put(AbilityKey.LastStateBattlefield, lastStateBattlefield);
CardZoneTable table = new CardZoneTable(lastStateBattlefield, CardCollection.EMPTY);
params.put(AbilityKey.InternalTriggerTable, table);

for (Card sac : list) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@ public void resolve(SpellAbility sa) {
final boolean destroy = sa.hasParam("Destroy");
final boolean remSacrificed = sa.hasParam("RememberSacrificed");
final boolean optional = sa.hasParam("Optional");
CardCollectionView lastStateBattlefield = game.copyLastStateBattlefield();
Map<AbilityKey, Object> params = AbilityKey.newMap();
params.put(AbilityKey.LastStateBattlefield, game.copyLastStateBattlefield());
CardZoneTable table = new CardZoneTable(game.getLastStateBattlefield(), CardCollection.EMPTY);
params.put(AbilityKey.LastStateBattlefield, lastStateBattlefield);
CardZoneTable table = new CardZoneTable(lastStateBattlefield, CardCollection.EMPTY);
params.put(AbilityKey.InternalTriggerTable, table);

if (valid.equals("Self") && game.getZoneOf(card) != null) {
Expand Down
9 changes: 5 additions & 4 deletions forge-game/src/main/java/forge/game/card/CardZoneTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public CardZoneTable() {
}

public CardZoneTable(CardCollectionView lastStateBattlefield, CardCollectionView lastStateGraveyard) {
this.lastStateBattlefield = ObjectUtils.firstNonNull(lastStateBattlefield, CardCollection.EMPTY);
this.lastStateGraveyard = ObjectUtils.firstNonNull(lastStateGraveyard, CardCollection.EMPTY);
setLastStateBattlefield(ObjectUtils.firstNonNull(lastStateBattlefield, CardCollection.EMPTY));
setLastStateGraveyard(ObjectUtils.firstNonNull(lastStateGraveyard, CardCollection.EMPTY));
}

public CardCollectionView getLastStateBattlefield() {
Expand All @@ -50,10 +50,11 @@ public CardCollectionView getLastStateGraveyard() {
return lastStateGraveyard;
}
public void setLastStateBattlefield(CardCollectionView lastState) {
this.lastStateBattlefield = lastState;
// store it in a new object, it might be from Game which can also refresh itself
this.lastStateBattlefield = new CardCollection(lastState);
}
public void setLastStateGraveyard(CardCollectionView lastState) {
this.lastStateGraveyard = lastState;
this.lastStateGraveyard = new CardCollection(lastState);
}

/**
Expand Down
7 changes: 3 additions & 4 deletions forge-game/src/main/java/forge/game/cost/CostExile.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,11 @@ else if (type.contains("FromTopGrave")) {

@Override
protected Card doPayment(Player payer, SpellAbility ability, Card targetCard, final boolean effect) {
final Game game = targetCard.getGame();
Map<AbilityKey, Object> moveParams = AbilityKey.newMap();
moveParams.put(AbilityKey.LastStateBattlefield, game.getLastStateBattlefield());
moveParams.put(AbilityKey.LastStateGraveyard, game.getLastStateGraveyard());
moveParams.put(AbilityKey.LastStateBattlefield, table.getLastStateBattlefield());
moveParams.put(AbilityKey.LastStateGraveyard, table.getLastStateGraveyard());
moveParams.put(AbilityKey.InternalTriggerTable, table);
Card newCard = game.getAction().exile(targetCard, null, moveParams);
Card newCard = targetCard.getGame().getAction().exile(targetCard, null, moveParams);
SpellAbilityEffect.handleExiledWith(newCard, ability);
return newCard;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ public final boolean executePayment(Player payer, SpellAbility ability, Card tar

// always returns true, made this to inline with return
protected boolean executePayment(Player payer, SpellAbility ability, CardCollectionView targetCards, final boolean effect) {
table.setLastStateBattlefield(payer.getGame().getLastStateBattlefield());
table.setLastStateGraveyard(payer.getGame().getLastStateGraveyard());
table.setLastStateBattlefield(payer.getGame().copyLastStateBattlefield());
table.setLastStateGraveyard(payer.getGame().copyLastStateGraveyard());

handleBeforePayment(payer, ability, targetCards);
if (canPayListAtOnce()) { // This is used by reveal. Without it when opponent would reveal hand, you'll get N message boxes.
Expand Down
4 changes: 2 additions & 2 deletions forge-game/src/main/java/forge/game/cost/CostSacrifice.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ protected Card doPayment(Player payer, SpellAbility ability, Card targetCard, fi
final Game game = targetCard.getGame();
// no table there, it is already handled by CostPartWithList
Map<AbilityKey, Object> moveParams = AbilityKey.newMap();
moveParams.put(AbilityKey.LastStateBattlefield, game.getLastStateBattlefield());
moveParams.put(AbilityKey.LastStateGraveyard, game.getLastStateGraveyard());
moveParams.put(AbilityKey.LastStateBattlefield, table.getLastStateBattlefield());
moveParams.put(AbilityKey.LastStateGraveyard, table.getLastStateGraveyard());
moveParams.put(AbilityKey.InternalTriggerTable, table);
return game.getAction().sacrifice(targetCard, ability, effect, moveParams);
}
Expand Down
4 changes: 0 additions & 4 deletions forge-game/src/main/java/forge/game/zone/MagicStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -591,13 +591,9 @@ private final void finishResolving(final SpellAbility sa, final boolean fizzle)
unfreezeStack();
sa.resetOnceResolved();

//game.getAction().checkStaticAbilities();
game.getPhaseHandler().onStackResolved();

curResolvingCard = null;

// xManaCostPaid will reset when cast the spell, comment out to fix Venarian Gold
// sa.getHostCard().setXManaCostPaid(0);
}

private final void removeCardFromStack(final SpellAbility sa, final SpellAbilityStackInstance si, final boolean fizzle) {
Expand Down

0 comments on commit 9dfc64e

Please sign in to comment.