Fix AI casting suspended spells against Drannith Magistrate (#1098)

* Cleanup cards

* Fix AI casting suspended spells against Drannith Magistrate

Co-authored-by: tool4EvEr <tool4EvEr@192.168.0.59>
This commit is contained in:
tool4ever
2022-07-10 15:51:56 +02:00
committed by GitHub
parent c40129cb43
commit ec3f7e00ca
12 changed files with 88 additions and 53 deletions

View File

@@ -34,6 +34,7 @@ import forge.game.ability.AbilityUtils;
import forge.game.ability.ApiType;
import forge.game.card.CardPlayOption.PayManaCost;
import forge.game.cost.Cost;
import forge.game.cost.CostPayment;
import forge.game.keyword.Keyword;
import forge.game.keyword.KeywordInterface;
import forge.game.player.Player;
@@ -842,4 +843,46 @@ public final class GameActionUtil {
c.getGame().getTriggerHandler().resetActiveTriggers();
}
public static void rollbackAbility(SpellAbility ability, final Zone fromZone, final int zonePosition, CostPayment payment, Card oldCard) {
// cancel ability during target choosing
final Game game = ability.getActivatingPlayer().getGame();
if (fromZone != null) { // and not a copy
oldCard.setCastSA(null);
oldCard.setCastFrom(null);
// add back to where it came from, hopefully old state
// skip GameAction
oldCard.getZone().remove(oldCard);
fromZone.add(oldCard, zonePosition >= 0 ? Integer.valueOf(zonePosition) : null);
ability.setHostCard(oldCard);
ability.setXManaCostPaid(null);
ability.setSpendPhyrexianMana(false);
if (ability.hasParam("Announce")) {
for (final String aVar : ability.getParam("Announce").split(",")) {
final String varName = aVar.trim();
if (!varName.equals("X")) {
ability.setSVar(varName, "0");
}
}
}
// better safe than sorry approach in case rolled back ability was copy (from addExtraKeywordCost)
for (SpellAbility sa : oldCard.getSpells()) {
sa.setHostCard(oldCard);
}
//for Chorus of the Conclave
ability.rollback();
oldCard.setBackSide(false);
oldCard.setState(oldCard.getFaceupCardStateName(), true);
oldCard.unanimateBestow();
}
ability.clearTargets();
ability.resetOnceResolved();
payment.refundPayment();
game.getStack().clearFrozen();
game.getTriggerHandler().clearWaitingTriggers();
}
}

View File

@@ -496,7 +496,7 @@ public class CountersPutEffect extends SpellAbilityEffect {
// need to unfreeze tracker
game.getTracker().unfreeze();
// check if it can recive the Tribute
// check if it can receive the Tribute
if (abort) {
continue;
}