mirror of
https://github.com/correl/mage.git
synced 2024-12-27 03:00:13 +00:00
Fixed X costs not being properly reset with Word of Command rollback
This commit is contained in:
parent
d19ca838ca
commit
323894118b
2 changed files with 44 additions and 36 deletions
|
@ -105,43 +105,22 @@ class WordOfCommandEffect extends OneShotEffect {
|
||||||
manaPool.storeMana();
|
manaPool.storeMana();
|
||||||
int bookmark = game.bookmarkState();
|
int bookmark = game.bookmarkState();
|
||||||
|
|
||||||
// check for card playability (Word of Command allows the chosen card to be played "as if it had flash" so we need to invoke such effect to bypass the check)
|
boolean canPlay = checkPlayability(card, targetPlayer, game, source);
|
||||||
boolean canPlay = false;
|
while (canPlay
|
||||||
if (card.isLand()) { // we can't use getPlayableInHand(game) in here because it disallows playing lands outside the main step
|
&& targetPlayer.canRespond()
|
||||||
if (targetPlayer.canPlayLand()
|
&& !targetPlayer.playCard(card, game, false, true, new MageObjectReference(source.getSourceObject(game), game))) {
|
||||||
&& game.getActivePlayerId().equals(targetPlayer.getId())) {
|
SpellAbility spellAbility = card.getSpellAbility();
|
||||||
canPlay = true;
|
if (spellAbility != null) {
|
||||||
for (Ability ability : card.getAbilities(game)) {
|
spellAbility.getManaCostsToPay().clear();
|
||||||
if (!game.getContinuousEffects().preventedByRuleModification(GameEvent.getEvent(GameEvent.EventType.PLAY_LAND, ability.getSourceId(), ability.getSourceId(), targetPlayer.getId()), ability, game, true)) {
|
spellAbility.getManaCostsToPay().addAll(spellAbility.getManaCosts());
|
||||||
canPlay &= true;
|
((ManaCostsImpl) spellAbility.getManaCostsToPay()).forceManaRollback(game, manaPool); // force rollback if card was deemed playable
|
||||||
}
|
canPlay = checkPlayability(card, targetPlayer, game, source);
|
||||||
}
|
} else {
|
||||||
}
|
break;
|
||||||
} else {
|
|
||||||
AsThoughEffectImpl effect2 = new WordOfCommandTestFlashEffect();
|
|
||||||
game.addEffect(effect2, source);
|
|
||||||
if (targetPlayer.getPlayableInHand(game).contains(card.getId())) {
|
|
||||||
canPlay = true;
|
|
||||||
}
|
|
||||||
for (AsThoughEffect eff : game.getContinuousEffects().getApplicableAsThoughEffects(AsThoughEffectType.CAST_AS_INSTANT, game)) {
|
|
||||||
if (eff instanceof WordOfCommandTestFlashEffect) {
|
|
||||||
eff.discard();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!canPlay) {
|
||||||
if (canPlay) {
|
game.informPlayers(targetPlayer.getLogName() + " didn't play " + card.getLogName() + " (card can't be played)");
|
||||||
while (!targetPlayer.playCard(card, game, false, true, new MageObjectReference(source.getSourceObject(game), game))) {
|
|
||||||
SpellAbility spellAbility = card.getSpellAbility();
|
|
||||||
if (spellAbility != null) {
|
|
||||||
((ManaCostsImpl) spellAbility.getManaCosts()).forceManaRollback(game, manaPool); // force rollback if card was deemed playable
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
game.informPlayers(targetPlayer.getLogName() + " didn't play " + card.getLogName() + (canPlay ? "" : " (card can't be played)"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
manaPool.setForcedToPay(false); // duplicate in case of a new mana pool existing - probably not necessary, but just in case
|
manaPool.setForcedToPay(false); // duplicate in case of a new mana pool existing - probably not necessary, but just in case
|
||||||
|
@ -149,7 +128,6 @@ class WordOfCommandEffect extends OneShotEffect {
|
||||||
manaPool.setForcedToPay(false);
|
manaPool.setForcedToPay(false);
|
||||||
game.removeBookmark(bookmark);
|
game.removeBookmark(bookmark);
|
||||||
targetPlayer.resetStoredBookmark(game);
|
targetPlayer.resetStoredBookmark(game);
|
||||||
|
|
||||||
for (RestrictionEffect eff : game.getContinuousEffects().getRestrictionEffects()) {
|
for (RestrictionEffect eff : game.getContinuousEffects().getRestrictionEffects()) {
|
||||||
if (eff instanceof WordOfCommandCantActivateEffect) {
|
if (eff instanceof WordOfCommandCantActivateEffect) {
|
||||||
eff.discard();
|
eff.discard();
|
||||||
|
@ -174,6 +152,35 @@ class WordOfCommandEffect extends OneShotEffect {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean checkPlayability(Card card, Player targetPlayer, Game game, Ability source) {
|
||||||
|
// check for card playability
|
||||||
|
boolean canPlay = false;
|
||||||
|
if (card.isLand()) { // we can't use getPlayableInHand(game) in here because it disallows playing lands outside the main step
|
||||||
|
if (targetPlayer.canPlayLand()
|
||||||
|
&& game.getActivePlayerId().equals(targetPlayer.getId())) {
|
||||||
|
canPlay = true;
|
||||||
|
for (Ability ability : card.getAbilities(game)) {
|
||||||
|
if (!game.getContinuousEffects().preventedByRuleModification(GameEvent.getEvent(GameEvent.EventType.PLAY_LAND, ability.getSourceId(), ability.getSourceId(), targetPlayer.getId()), ability, game, true)) {
|
||||||
|
canPlay &= true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else { // Word of Command allows the chosen card to be played "as if it had flash" so we need to invoke such effect to bypass the check
|
||||||
|
AsThoughEffectImpl effect2 = new WordOfCommandTestFlashEffect();
|
||||||
|
game.addEffect(effect2, source);
|
||||||
|
if (targetPlayer.getPlayableInHand(game).contains(card.getId())) {
|
||||||
|
canPlay = true;
|
||||||
|
}
|
||||||
|
for (AsThoughEffect eff : game.getContinuousEffects().getApplicableAsThoughEffects(AsThoughEffectType.CAST_AS_INSTANT, game)) {
|
||||||
|
if (eff instanceof WordOfCommandTestFlashEffect) {
|
||||||
|
eff.discard();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return canPlay;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class WordOfCommandCantActivateEffect extends RestrictionEffect {
|
class WordOfCommandCantActivateEffect extends RestrictionEffect {
|
||||||
|
|
|
@ -339,6 +339,7 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
game.undo(playerId);
|
game.undo(playerId);
|
||||||
this.clearPaid();
|
this.clearPaid();
|
||||||
|
this.setX(0);
|
||||||
player.getManaPool().restoreMana(pool.getPoolBookmark());
|
player.getManaPool().restoreMana(pool.getPoolBookmark());
|
||||||
game.bookmarkState();
|
game.bookmarkState();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue