From 5912ed80ad3effbcac281c380ccfef8a7649bafa Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Fri, 2 Oct 2015 01:04:40 +0200 Subject: [PATCH] * Fixed some problems with undo/cancel action (fixes #1267). --- .../battleforzendikar/BeastcallerSavant.java | 43 ++----------------- .../AddConditionalManaOfAnyColorEffect.java | 9 ++-- Mage/src/mage/actions/impl/MageAction.java | 8 ++-- Mage/src/mage/game/GameImpl.java | 2 +- Mage/src/mage/players/PlayerImpl.java | 27 ++++++++---- 5 files changed, 30 insertions(+), 59 deletions(-) diff --git a/Mage.Sets/src/mage/sets/battleforzendikar/BeastcallerSavant.java b/Mage.Sets/src/mage/sets/battleforzendikar/BeastcallerSavant.java index 7a5d26bc895..70fca955764 100644 --- a/Mage.Sets/src/mage/sets/battleforzendikar/BeastcallerSavant.java +++ b/Mage.Sets/src/mage/sets/battleforzendikar/BeastcallerSavant.java @@ -28,20 +28,14 @@ package mage.sets.battleforzendikar; import java.util.UUID; -import mage.ConditionalMana; import mage.MageInt; -import mage.MageObject; -import mage.Mana; -import mage.abilities.Ability; -import mage.abilities.condition.Condition; import mage.abilities.keyword.HasteAbility; import mage.abilities.mana.ConditionalAnyColorManaAbility; -import mage.abilities.mana.builder.ConditionalManaBuilder; +import mage.abilities.mana.conditional.ConditionalSpellManaBuilder; import mage.cards.CardImpl; import mage.constants.CardType; import mage.constants.Rarity; -import mage.game.Game; -import mage.game.stack.Spell; +import mage.filter.common.FilterCreatureSpell; /** * @@ -62,7 +56,7 @@ public class BeastcallerSavant extends CardImpl { this.addAbility(HasteAbility.getInstance()); // {T}: Add one mana of any color to your mana pool. Spend this mana only to cast creature spells. - this.addAbility(new ConditionalAnyColorManaAbility(1, new BeastcallerSavantManaBuilder())); + this.addAbility(new ConditionalAnyColorManaAbility(1, new ConditionalSpellManaBuilder(new FilterCreatureSpell("creature spells")))); } public BeastcallerSavant(final BeastcallerSavant card) { @@ -74,34 +68,3 @@ public class BeastcallerSavant extends CardImpl { return new BeastcallerSavant(this); } } - -class BeastcallerSavantManaBuilder extends ConditionalManaBuilder { - - @Override - public ConditionalMana build(Object... options) { - return new BeastcallerSavantConditionalMana(this.mana); - } - - @Override - public String getRule() { - return "Spend this mana only to cast creature spells"; - } -} - -class BeastcallerSavantConditionalMana extends ConditionalMana { - - public BeastcallerSavantConditionalMana(Mana mana) { - super(mana); - this.staticText = "Spend this mana only to cast creature spells"; - addCondition(new BeastcallerSavantManaCondition()); - } -} - -class BeastcallerSavantManaCondition implements Condition { - - @Override - public boolean apply(Game game, Ability source) { - MageObject object = source.getSourceObject(game); - return object != null && (object instanceof Spell) && object.getCardType().contains(CardType.CREATURE); - } -} \ No newline at end of file diff --git a/Mage/src/mage/abilities/effects/common/AddConditionalManaOfAnyColorEffect.java b/Mage/src/mage/abilities/effects/common/AddConditionalManaOfAnyColorEffect.java index 1b37d1e395d..e0275a85c62 100644 --- a/Mage/src/mage/abilities/effects/common/AddConditionalManaOfAnyColorEffect.java +++ b/Mage/src/mage/abilities/effects/common/AddConditionalManaOfAnyColorEffect.java @@ -59,9 +59,9 @@ public class AddConditionalManaOfAnyColorEffect extends ManaEffect { this.manaBuilder = manaBuilder; this.oneChoice = oneChoice; // - staticText = "Add " + amount + " mana of " + - (oneChoice ? "any one color":"in any combination of colors") + - " to your mana pool. " + manaBuilder.getRule(); + staticText = "Add " + amount + " mana of " + + (oneChoice ? "any one color" : "in any combination of colors") + + " to your mana pool. " + manaBuilder.getRule(); } public AddConditionalManaOfAnyColorEffect(final AddConditionalManaOfAnyColorEffect effect) { @@ -85,7 +85,7 @@ public class AddConditionalManaOfAnyColorEffect extends ManaEffect { int value = amount.calculate(game, source, this); boolean result = false; - ChoiceColor choice = new ChoiceColor(); + ChoiceColor choice = new ChoiceColor(false); for (int i = 0; i < value; i++) { if (!choice.isChosen()) { if (!controller.choose(outcome, choice, game)) { @@ -115,7 +115,6 @@ public class AddConditionalManaOfAnyColorEffect extends ManaEffect { } } - return result; } diff --git a/Mage/src/mage/actions/impl/MageAction.java b/Mage/src/mage/actions/impl/MageAction.java index 4524c5c271a..2c7f74fb0db 100644 --- a/Mage/src/mage/actions/impl/MageAction.java +++ b/Mage/src/mage/actions/impl/MageAction.java @@ -24,7 +24,7 @@ public abstract class MageAction { * Set or change action score. * * @param scorePlayer Set player. - * @param score Set score value. + * @param score Set score value. */ protected void setScore(Player scorePlayer, int score) { this.scorePlayer = scorePlayer; @@ -32,9 +32,8 @@ public abstract class MageAction { } /** - * Get game score for the {@link Player}. - * Value depends on the owner of this action. - * In case player and owner differ, negative value is returned. + * Get game score for the {@link Player}. Value depends on the owner of this + * action. In case player and owner differ, negative value is returned. * * @param player * @return @@ -54,6 +53,7 @@ public abstract class MageAction { * Execute action. * * @param game Game context. + * @return */ public abstract int doAction(final Game game); diff --git a/Mage/src/mage/game/GameImpl.java b/Mage/src/mage/game/GameImpl.java index 65f39f5be52..da2c5aa8165 100644 --- a/Mage/src/mage/game/GameImpl.java +++ b/Mage/src/mage/game/GameImpl.java @@ -1176,7 +1176,7 @@ public abstract class GameImpl implements Game, Serializable { public synchronized void concede(UUID playerId) { Player player = state.getPlayer(playerId); if (player != null) { - logger.debug(new StringBuilder("Player ").append(player.getName()).append(" concedes game ").append(this.getId())); + logger.debug("Player " + player.getName() + " concedes game " + this.getId()); fireInformEvent(player.getLogName() + " has conceded."); player.concede(this); } diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java index d52568421d5..3ce3070c96e 100644 --- a/Mage/src/mage/players/PlayerImpl.java +++ b/Mage/src/mage/players/PlayerImpl.java @@ -975,7 +975,7 @@ public abstract class PlayerImpl implements Player, Serializable { resetStoredBookmark(game); return true; } - game.restoreState(bookmark, ability.getRule()); + restoreState(bookmark, ability.getRule(), game); } } return false; @@ -1029,7 +1029,7 @@ public abstract class PlayerImpl implements Player, Serializable { // putOntoBattlefield retured false if putOntoBattlefield was replaced by replacement effect (e.g. Kjeldorian Outpost). // But that would undo the effect completely, // what makes no real sense. So it makes no sense to generally do a restorState here. - // game.restoreState(bookmark); + // restoreState(bookmark, card.getName(), game); } return false; } @@ -1039,15 +1039,17 @@ public abstract class PlayerImpl implements Player, Serializable { int bookmark = game.bookmarkState(); if (ability.activate(game, false)) { if (ability.resolve(game)) { - if (ability.isUndoPossible() && (storedBookmark == -1 || storedBookmark > bookmark)) { // e.g. usefull for undo Nykthos, Shrine to Nyx - setStoredBookmark(bookmark); + if (ability.isUndoPossible()) { + if (storedBookmark == -1 || storedBookmark > bookmark) { // e.g. usefull for undo Nykthos, Shrine to Nyx + setStoredBookmark(bookmark); + } } else { resetStoredBookmark(game); } return true; } } - game.restoreState(bookmark, ability.getRule()); + restoreState(bookmark, ability.getRule(), game); } return false; } @@ -1068,7 +1070,7 @@ public abstract class PlayerImpl implements Player, Serializable { resetStoredBookmark(game); return true; } - game.restoreState(bookmark, ability.getRule()); + restoreState(bookmark, ability.getRule(), game); } } else { int bookmark = game.bookmarkState(); @@ -1078,7 +1080,7 @@ public abstract class PlayerImpl implements Player, Serializable { resetStoredBookmark(game); return true; } - game.restoreState(bookmark, ability.getRule()); + restoreState(bookmark, ability.getRule(), game); } return false; } @@ -1098,11 +1100,18 @@ public abstract class PlayerImpl implements Player, Serializable { return true; } } - game.restoreState(bookmark, action.getRule()); + restoreState(bookmark, action.getRule(), game); } return false; } + private void restoreState(int bookmark, String text, Game game) { + game.restoreState(bookmark, text); + if (storedBookmark >= bookmark) { + resetStoredBookmark(game); + } + } + @Override public boolean activateAbility(ActivatedAbility ability, Game game) { boolean result; @@ -1175,7 +1184,7 @@ public abstract class PlayerImpl implements Player, Serializable { return true; } } - game.restoreState(bookmark, source.getRule()); // why restore is needed here? + restoreState(bookmark, source.getRule(), game); // why restore is needed here? (to remove the triggered ability from the stack) return false; }