Refactored restore state code, added additional error check for mana undo param;

This commit is contained in:
Oleg Agafonov 2020-08-06 22:17:37 +04:00
parent 2eeefd91ef
commit 83f7ae377a
12 changed files with 64 additions and 40 deletions

View file

@ -150,13 +150,16 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
*/
@Override
public boolean payOrRollback(Ability ability, Game game, UUID sourceId, UUID payingPlayerId) {
int bookmark = game.bookmarkState();
handlePhyrexianManaCosts(payingPlayerId, ability, game);
if (pay(ability, game, sourceId, payingPlayerId, false, null)) {
game.removeBookmark(bookmark);
return true;
Player player = game.getPlayer(payingPlayerId);
if (player != null) {
int bookmark = game.bookmarkState();
handlePhyrexianManaCosts(payingPlayerId, ability, game);
if (pay(ability, game, sourceId, payingPlayerId, false, null)) {
game.removeBookmark(bookmark);
return true;
}
player.restoreState(bookmark, ability.getRule(), game);
}
game.restoreState(bookmark, ability.getRule());
return false;
}

View file

@ -108,7 +108,7 @@ public class DoIfCostPaid extends OneShotEffect {
player.resetStoredBookmark(game); // otherwise you can e.g. undo card drawn with Mentor of the Meek
} else {
// Paying cost was cancels so try to undo payment so far
game.restoreState(bookmark, DoIfCostPaid.class.getName());
player.restoreState(bookmark, DoIfCostPaid.class.getName(), game);
if (!otherwiseEffects.isEmpty()) {
for (Effect effect : otherwiseEffects) {
effect.setTargetPointer(this.targetPointer);

View file

@ -60,7 +60,7 @@ public class DoWhenCostPaid extends OneShotEffect {
player.resetStoredBookmark(game);
return true;
}
game.restoreState(bookmark, DoWhenCostPaid.class.getName());
player.restoreState(bookmark, DoWhenCostPaid.class.getName(), game);
return true;
}

View file

@ -103,7 +103,7 @@ class CumulativeUpkeepEffect extends OneShotEffect {
game.fireEvent(new GameEvent(EventType.PAID_CUMULATIVE_UPKEEP, permanent.getId(), permanent.getId(), player.getId(), ageCounter, false));
return true;
} else {
game.restoreState(bookmark, source.getRule());
player.restoreState(bookmark, source.getRule(), game);
}
}
game.fireEvent(new GameEvent(EventType.DIDNT_PAY_CUMULATIVE_UPKEEP, permanent.getId(), permanent.getId(), player.getId(), ageCounter, false));

View file

@ -1,25 +1,17 @@
package mage.abilities.mana;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import mage.Mana;
import mage.abilities.Ability;
import mage.abilities.ActivatedAbilityImpl;
import mage.abilities.costs.Cost;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.ManaEffect;
import mage.constants.AbilityType;
import mage.constants.AsThoughEffectType;
import mage.constants.ManaType;
import mage.constants.TimingRule;
import mage.constants.Zone;
import mage.constants.*;
import mage.game.Game;
import mage.game.stack.Spell;
import mage.game.stack.StackObject;
import java.util.*;
/**
* @author BetaSteward_at_googlemail.com
*/
@ -134,6 +126,9 @@ public abstract class ActivatedManaAbilityImpl extends ActivatedAbilityImpl impl
* Is it allowed to undo the mana creation. It's e.g. not allowed if some
* game revealing information is related (like reveal the top card of the
* library)
* <p>
* TODO: it helps with single mana activate for mana pool, but will not work while activates on paying for casting
* (e.g. user can cheats to see next draw card)
*
* @return
*/