Fix bugs with dies triggers due to short living LKI reset (#12438)

* replace applyEffects() with processAction() for card usages

* update Goblin Welder and test

* add test for Historian's Wisdom

* enable other related tests

* only reset short living LKI for process action, not all apply effects

* update docs

* remove applyEffects from condition in Historian's Wisdom

* add another test case
This commit is contained in:
xenohedron 2024-06-09 18:56:19 -04:00 committed by GitHub
parent be8a52fe60
commit aeaeccb63b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 103 additions and 49 deletions

View file

@ -436,10 +436,7 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
if (game.getState().getZone(source.getSourceId()) == Zone.BATTLEFIELD) {
sourceObject = game.getPermanent(source.getSourceId());
} else {
// TODO: multiple calls of ApplyEffects all around the code are breaking a short living lki idea
// (PlayerImpl's call to move to battlefield do the worse thing)
// -
// Original idea: short living LKI must help to find a moment in the inner of resolve
// The idea: short living LKI must help to find a moment in the inner of resolve
// -
// Example:
// --!---------------!-------------!-----!-----------!
@ -455,15 +452,6 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
// - ! empty stack ! graveyard ! no ! no ! no more to resolve
// --!---------------!-------------!-----!-----------!
// -
// - Problem 1: move code (well, not only move) calls ApplyEffects in the middle of the resolve
// - and reset short LKI (after short LKI reset dies trigger will not work)
// - Example: Goblin Welder calls sacrifice and card move in the same effect - but move call do
// - a reset and dies trigger ignored (trigger thinks that permanent already dies)
// -
// - Possible fix:
// - replace ApplyEffects in the move code by game.getState().processAction(game);
// - check and fix many broken (is it was a false positive test or something broken)
//sourceObject = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
if (game.getShortLivingLKI(source.getSourceId(), Zone.BATTLEFIELD)) {
sourceObject = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
}

View file

@ -1929,7 +1929,6 @@ public abstract class GameImpl implements Game {
@Override
public synchronized void applyEffects() {
resetShortLivingLKI();
state.applyEffects(this);
}

View file

@ -677,11 +677,12 @@ public class GameState implements Serializable, Copyable<GameState> {
*/
public void processAction(Game game) {
game.getState().handleSimultaneousEvent(game);
game.resetShortLivingLKI();
game.applyEffects();
game.getState().getTriggers().checkStateTriggers(game);
}
public void applyEffects(Game game) {
void applyEffects(Game game) {
applyEffectsCounter++;
for (Player player : players.values()) {
player.reset();

View file

@ -691,7 +691,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
+ CardUtil.getSourceLogName(game, source, this.getId()));
this.setTransformed(!this.transformed);
this.transformCount++;
game.applyEffects();
game.applyEffects(); // not process action - no firing of simultaneous events yet
this.replaceEvent(EventType.TRANSFORMING, game);
game.addSimultaneousEvent(GameEvent.getEvent(EventType.TRANSFORMED, this.getId(), this.getControllerId()));
return true;

View file

@ -454,7 +454,7 @@ public abstract class TokenImpl extends MageObjectImpl implements Token {
}
CreatedTokensEvent.addEvents(allAddedTokens, source, game);
game.getState().applyEffects(game); // Needed to do it here without LKIReset i.e. do get SwordOfTheMeekTest running correctly.
game.applyEffects(); // without LKI reset
}
@Override

View file

@ -4779,10 +4779,7 @@ public abstract class PlayerImpl implements Player, Serializable {
}
}
}
// TODO: must be replaced by game.getState().processAction(game), see isInUseableZoneDiesTrigger comments
// about short living LKI problem
//game.getState().processAction(game);
game.applyEffects();
game.applyEffects(); // without LKI reset
break;
case HAND:
for (Card card : cards) {