* 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;
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);
}
}

View file

@ -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;
}

View file

@ -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);

View file

@ -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);
}

View file

@ -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;
}