* Fixed some problems with undo/cancel action (fixes #1267).

This commit is contained in:
LevelX2 2015-10-02 01:04:40 +02:00
parent 63c6aa226a
commit 5912ed80ad
5 changed files with 30 additions and 59 deletions

View file

@ -28,20 +28,14 @@
package mage.sets.battleforzendikar; package mage.sets.battleforzendikar;
import java.util.UUID; import java.util.UUID;
import mage.ConditionalMana;
import mage.MageInt; 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.keyword.HasteAbility;
import mage.abilities.mana.ConditionalAnyColorManaAbility; import mage.abilities.mana.ConditionalAnyColorManaAbility;
import mage.abilities.mana.builder.ConditionalManaBuilder; import mage.abilities.mana.conditional.ConditionalSpellManaBuilder;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.game.Game; import mage.filter.common.FilterCreatureSpell;
import mage.game.stack.Spell;
/** /**
* *
@ -62,7 +56,7 @@ public class BeastcallerSavant extends CardImpl {
this.addAbility(HasteAbility.getInstance()); this.addAbility(HasteAbility.getInstance());
// {T}: Add one mana of any color to your mana pool. Spend this mana only to cast creature spells. // {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) { public BeastcallerSavant(final BeastcallerSavant card) {
@ -74,34 +68,3 @@ public class BeastcallerSavant extends CardImpl {
return new BeastcallerSavant(this); 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);
}
}

View file

@ -59,9 +59,9 @@ public class AddConditionalManaOfAnyColorEffect extends ManaEffect {
this.manaBuilder = manaBuilder; this.manaBuilder = manaBuilder;
this.oneChoice = oneChoice; this.oneChoice = oneChoice;
// //
staticText = "Add " + amount + " mana of " + staticText = "Add " + amount + " mana of "
(oneChoice ? "any one color":"in any combination of colors") + + (oneChoice ? "any one color" : "in any combination of colors")
" to your mana pool. " + manaBuilder.getRule(); + " to your mana pool. " + manaBuilder.getRule();
} }
public AddConditionalManaOfAnyColorEffect(final AddConditionalManaOfAnyColorEffect effect) { public AddConditionalManaOfAnyColorEffect(final AddConditionalManaOfAnyColorEffect effect) {
@ -85,7 +85,7 @@ public class AddConditionalManaOfAnyColorEffect extends ManaEffect {
int value = amount.calculate(game, source, this); int value = amount.calculate(game, source, this);
boolean result = false; boolean result = false;
ChoiceColor choice = new ChoiceColor(); ChoiceColor choice = new ChoiceColor(false);
for (int i = 0; i < value; i++) { for (int i = 0; i < value; i++) {
if (!choice.isChosen()) { if (!choice.isChosen()) {
if (!controller.choose(outcome, choice, game)) { if (!controller.choose(outcome, choice, game)) {
@ -115,7 +115,6 @@ public class AddConditionalManaOfAnyColorEffect extends ManaEffect {
} }
} }
return result; return result;
} }

View file

@ -32,9 +32,8 @@ public abstract class MageAction {
} }
/** /**
* Get game score for the {@link Player}. * Get game score for the {@link Player}. Value depends on the owner of this
* Value depends on the owner of this action. * action. In case player and owner differ, negative value is returned.
* In case player and owner differ, negative value is returned.
* *
* @param player * @param player
* @return * @return
@ -54,6 +53,7 @@ public abstract class MageAction {
* Execute action. * Execute action.
* *
* @param game Game context. * @param game Game context.
* @return
*/ */
public abstract int doAction(final Game game); public abstract int doAction(final Game game);

View file

@ -1176,7 +1176,7 @@ public abstract class GameImpl implements Game, Serializable {
public synchronized void concede(UUID playerId) { public synchronized void concede(UUID playerId) {
Player player = state.getPlayer(playerId); Player player = state.getPlayer(playerId);
if (player != null) { 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."); fireInformEvent(player.getLogName() + " has conceded.");
player.concede(this); player.concede(this);
} }

View file

@ -975,7 +975,7 @@ public abstract class PlayerImpl implements Player, Serializable {
resetStoredBookmark(game); resetStoredBookmark(game);
return true; return true;
} }
game.restoreState(bookmark, ability.getRule()); restoreState(bookmark, ability.getRule(), game);
} }
} }
return false; 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). // putOntoBattlefield retured false if putOntoBattlefield was replaced by replacement effect (e.g. Kjeldorian Outpost).
// But that would undo the effect completely, // But that would undo the effect completely,
// what makes no real sense. So it makes no sense to generally do a restorState here. // 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; return false;
} }
@ -1039,15 +1039,17 @@ public abstract class PlayerImpl implements Player, Serializable {
int bookmark = game.bookmarkState(); int bookmark = game.bookmarkState();
if (ability.activate(game, false)) { if (ability.activate(game, false)) {
if (ability.resolve(game)) { if (ability.resolve(game)) {
if (ability.isUndoPossible() && (storedBookmark == -1 || storedBookmark > bookmark)) { // e.g. usefull for undo Nykthos, Shrine to Nyx if (ability.isUndoPossible()) {
if (storedBookmark == -1 || storedBookmark > bookmark) { // e.g. usefull for undo Nykthos, Shrine to Nyx
setStoredBookmark(bookmark); setStoredBookmark(bookmark);
}
} else { } else {
resetStoredBookmark(game); resetStoredBookmark(game);
} }
return true; return true;
} }
} }
game.restoreState(bookmark, ability.getRule()); restoreState(bookmark, ability.getRule(), game);
} }
return false; return false;
} }
@ -1068,7 +1070,7 @@ public abstract class PlayerImpl implements Player, Serializable {
resetStoredBookmark(game); resetStoredBookmark(game);
return true; return true;
} }
game.restoreState(bookmark, ability.getRule()); restoreState(bookmark, ability.getRule(), game);
} }
} else { } else {
int bookmark = game.bookmarkState(); int bookmark = game.bookmarkState();
@ -1078,7 +1080,7 @@ public abstract class PlayerImpl implements Player, Serializable {
resetStoredBookmark(game); resetStoredBookmark(game);
return true; return true;
} }
game.restoreState(bookmark, ability.getRule()); restoreState(bookmark, ability.getRule(), game);
} }
return false; return false;
} }
@ -1098,11 +1100,18 @@ public abstract class PlayerImpl implements Player, Serializable {
return true; return true;
} }
} }
game.restoreState(bookmark, action.getRule()); restoreState(bookmark, action.getRule(), game);
} }
return false; return false;
} }
private void restoreState(int bookmark, String text, Game game) {
game.restoreState(bookmark, text);
if (storedBookmark >= bookmark) {
resetStoredBookmark(game);
}
}
@Override @Override
public boolean activateAbility(ActivatedAbility ability, Game game) { public boolean activateAbility(ActivatedAbility ability, Game game) {
boolean result; boolean result;
@ -1175,7 +1184,7 @@ public abstract class PlayerImpl implements Player, Serializable {
return true; 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; return false;
} }