Refresh active triggers after statics from ETB (#5580)

* Refresh active triggers after statics from ETB

* Style change

---------

Co-authored-by: TRT <>
This commit is contained in:
tool4ever
2024-07-12 14:48:37 +02:00
committed by GitHub
parent 129cca0527
commit 6c2c8cc6e8
3 changed files with 16 additions and 23 deletions

View File

@@ -613,10 +613,6 @@ public class GameAction {
} }
game.getTriggerHandler().clearActiveTriggers(copied, null); game.getTriggerHandler().clearActiveTriggers(copied, null);
// register all LTB trigger from last state battlefield
for (Card lki : lastBattlefield) {
game.getTriggerHandler().registerActiveLTBTrigger(lki);
}
game.getTriggerHandler().registerActiveTrigger(copied, false); game.getTriggerHandler().registerActiveTrigger(copied, false);
// play the change zone sound // play the change zone sound
@@ -1438,6 +1434,8 @@ public class GameAction {
} }
setHoldCheckingStaticAbilities(false); setHoldCheckingStaticAbilities(false);
table.triggerChangesZoneAll(game, null);
// important to collect first otherwise if a static fires it will mess up registered ones from LKI // important to collect first otherwise if a static fires it will mess up registered ones from LKI
game.getTriggerHandler().collectTriggerForWaiting(); game.getTriggerHandler().collectTriggerForWaiting();
if (game.getTriggerHandler().runWaitingTriggers()) { if (game.getTriggerHandler().runWaitingTriggers()) {
@@ -1448,8 +1446,6 @@ public class GameAction {
game.getCombat().removeAbsentCombatants(); game.getCombat().removeAbsentCombatants();
} }
table.triggerChangesZoneAll(game, null);
for (final Card c : cardsToUpdateLKI) { for (final Card c : cardsToUpdateLKI) {
game.updateLastStateForCard(c); game.updateLastStateForCard(c);
} }

View File

@@ -11,7 +11,6 @@ import forge.game.ability.SpellAbilityEffect;
import forge.game.card.Card; import forge.game.card.Card;
import forge.game.card.CardZoneTable; import forge.game.card.CardZoneTable;
import forge.game.spellability.SpellAbility; import forge.game.spellability.SpellAbility;
import forge.game.zone.ZoneType;
public class PermanentEffect extends SpellAbilityEffect { public class PermanentEffect extends SpellAbilityEffect {
@@ -26,12 +25,8 @@ public class PermanentEffect extends SpellAbilityEffect {
public void resolve(SpellAbility sa) { public void resolve(SpellAbility sa) {
final Card host = sa.getHostCard(); final Card host = sa.getHostCard();
final Game game = host.getGame(); final Game game = host.getGame();
CardZoneTable table = new CardZoneTable(); final Map<AbilityKey, Object> moveParams = AbilityKey.newMap();
ZoneType previousZone = host.getZone().getZoneType(); final CardZoneTable table = AbilityKey.addCardZoneTableParams(moveParams, sa);
Map<AbilityKey, Object> moveParams = AbilityKey.newMap();
moveParams.put(AbilityKey.LastStateBattlefield, game.copyLastStateBattlefield());
moveParams.put(AbilityKey.LastStateGraveyard, game.copyLastStateGraveyard());
final Card c = game.getAction().moveToPlay(host, host.getController(), sa, moveParams); final Card c = game.getAction().moveToPlay(host, host.getController(), sa, moveParams);
sa.setHostCard(c); sa.setHostCard(c);
@@ -47,10 +42,6 @@ public class PermanentEffect extends SpellAbilityEffect {
registerDelayedTrigger(sa, "Sacrifice", Lists.newArrayList(c)); registerDelayedTrigger(sa, "Sacrifice", Lists.newArrayList(c));
} }
ZoneType newZone = c.getZone().getZoneType();
if (newZone != previousZone) {
table.put(previousZone, newZone, c);
}
table.triggerChangesZoneAll(game, sa); table.triggerChangesZoneAll(game, sa);
} }
} }

View File

@@ -5,8 +5,6 @@ package forge.game.card;
import java.util.Map; import java.util.Map;
import org.apache.commons.lang3.ObjectUtils;
import com.google.common.collect.*; import com.google.common.collect.*;
import forge.game.CardTraitBase; import forge.game.CardTraitBase;
@@ -34,8 +32,8 @@ public class CardZoneTable extends ForwardingTable<ZoneType, ZoneType, CardColle
} }
public CardZoneTable(CardCollectionView lastStateBattlefield, CardCollectionView lastStateGraveyard) { public CardZoneTable(CardCollectionView lastStateBattlefield, CardCollectionView lastStateGraveyard) {
setLastStateBattlefield(ObjectUtils.firstNonNull(lastStateBattlefield, CardCollection.EMPTY)); setLastStateBattlefield(lastStateBattlefield);
setLastStateGraveyard(ObjectUtils.firstNonNull(lastStateGraveyard, CardCollection.EMPTY)); setLastStateGraveyard(lastStateGraveyard);
} }
public CardZoneTable(CardZoneTable cardZoneTable) { public CardZoneTable(CardZoneTable cardZoneTable) {
@@ -64,10 +62,10 @@ public class CardZoneTable extends ForwardingTable<ZoneType, ZoneType, CardColle
} }
public void setLastStateBattlefield(CardCollectionView lastState) { public void setLastStateBattlefield(CardCollectionView lastState) {
// store it in a new object, it might be from Game which can also refresh itself // store it in a new object, it might be from Game which can also refresh itself
this.lastStateBattlefield = new CardCollection(lastState); lastStateBattlefield = lastState == null ? CardCollection.EMPTY : new CardCollection(lastState);
} }
public void setLastStateGraveyard(CardCollectionView lastState) { public void setLastStateGraveyard(CardCollectionView lastState) {
this.lastStateGraveyard = new CardCollection(lastState); lastStateGraveyard = lastState == null ? CardCollection.EMPTY : new CardCollection(lastState);
} }
/** /**
@@ -102,6 +100,14 @@ public class CardZoneTable extends ForwardingTable<ZoneType, ZoneType, CardColle
// will be handled by original "cause" instead // will be handled by original "cause" instead
return; return;
} }
// this should still refresh for empty battlefield
if (lastStateBattlefield != CardCollection.EMPTY) {
game.getTriggerHandler().resetActiveTriggers(false);
// register all LTB trigger from last state battlefield
for (Card lki : lastStateBattlefield) {
game.getTriggerHandler().registerActiveLTBTrigger(lki);
}
}
if (!isEmpty()) { if (!isEmpty()) {
final Map<AbilityKey, Object> runParams = AbilityKey.newMap(); final Map<AbilityKey, Object> runParams = AbilityKey.newMap();
runParams.put(AbilityKey.Cards, new CardZoneTable(this)); runParams.put(AbilityKey.Cards, new CardZoneTable(this));