From 5973a764aa12f6bddcb767e2da001d19ee538d39 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Wed, 7 Jan 2015 16:43:26 +0100 Subject: [PATCH] * Wall of Root - Fixed that the mana ability could wrongly not used again after canceling a previous pay mana action. --- .../LimitedTimesPerTurnActivatedAbility.java | 20 +++++++++--- .../mana/ActivateOncePerTurnManaAbility.java | 32 +++++++++++-------- Mage/src/mage/game/GameState.java | 13 +++++--- 3 files changed, 43 insertions(+), 22 deletions(-) diff --git a/Mage/src/mage/abilities/common/LimitedTimesPerTurnActivatedAbility.java b/Mage/src/mage/abilities/common/LimitedTimesPerTurnActivatedAbility.java index cf34bf7c7d..53d4053903 100644 --- a/Mage/src/mage/abilities/common/LimitedTimesPerTurnActivatedAbility.java +++ b/Mage/src/mage/abilities/common/LimitedTimesPerTurnActivatedAbility.java @@ -72,7 +72,7 @@ public class LimitedTimesPerTurnActivatedAbility extends ActivatedAbilityImpl { @Override public boolean canActivate(UUID playerId, Game game) { if (super.canActivate(playerId, game)) { - ActivationInfo activationInfo = (ActivationInfo) game.getState().getValue(CardUtil.getCardZoneString("activations", sourceId, game)); + ActivationInfo activationInfo = getActivationInfo(game); return activationInfo == null || activationInfo.turnNum != game.getTurnNum() || activationInfo.activationCounter < maxActivationsPerTurn; } return false; @@ -82,7 +82,7 @@ public class LimitedTimesPerTurnActivatedAbility extends ActivatedAbilityImpl { public boolean activate(Game game, boolean noMana) { if (canActivate(this.controllerId, game)) { if (super.activate(game, noMana)) { - ActivationInfo activationInfo = (ActivationInfo) game.getState().getValue(CardUtil.getCardZoneString("activations", sourceId, game)); + ActivationInfo activationInfo = getActivationInfo(game); if (activationInfo == null) { activationInfo = new ActivationInfo(game.getTurnNum(), 1); } else { @@ -93,7 +93,7 @@ public class LimitedTimesPerTurnActivatedAbility extends ActivatedAbilityImpl { activationInfo.activationCounter++; } } - game.getState().setValue(CardUtil.getCardZoneString("activations", sourceId, game), activationInfo); + setActivationInfo(activationInfo, game); return true; } } @@ -126,5 +126,17 @@ public class LimitedTimesPerTurnActivatedAbility extends ActivatedAbilityImpl { public LimitedTimesPerTurnActivatedAbility copy() { return new LimitedTimesPerTurnActivatedAbility(this); } - + private ActivationInfo getActivationInfo(Game game) { + Integer turnNum = (Integer) game.getState().getValue(CardUtil.getCardZoneString("activationsTurn", sourceId, game)); + Integer activationCount = (Integer) game.getState().getValue(CardUtil.getCardZoneString("activationsCount", sourceId, game)); + if (turnNum == null || activationCount == null) { + return null; + } + return new ActivationInfo(turnNum, activationCount); + } + + private void setActivationInfo(ActivationInfo activationInfo, Game game) { + game.getState().setValue(CardUtil.getCardZoneString("activationsTurn", sourceId, game), activationInfo.turnNum); + game.getState().setValue(CardUtil.getCardZoneString("activationsCount", sourceId, game), activationInfo.activationCounter); + } } diff --git a/Mage/src/mage/abilities/mana/ActivateOncePerTurnManaAbility.java b/Mage/src/mage/abilities/mana/ActivateOncePerTurnManaAbility.java index 3b5bf16c74..d906e8fd03 100644 --- a/Mage/src/mage/abilities/mana/ActivateOncePerTurnManaAbility.java +++ b/Mage/src/mage/abilities/mana/ActivateOncePerTurnManaAbility.java @@ -44,7 +44,7 @@ import mage.util.CardUtil; public class ActivateOncePerTurnManaAbility extends ManaAbility { class ActivationInfo { - + public int turnNum; public int activationCounter; @@ -71,19 +71,19 @@ public class ActivateOncePerTurnManaAbility extends ManaAbility { @Override public boolean canActivate(UUID playerId, Game game) { if (super.canActivate(playerId, game)) { - ActivationInfo activationInfo = (ActivationInfo) game.getState().getValue(CardUtil.getCardZoneString("activations", sourceId, game)); + ActivationInfo activationInfo = getActivationInfo(game); if (activationInfo == null || activationInfo.turnNum != game.getTurnNum() || activationInfo.activationCounter < 1) { return true; } } return false; } - + @Override public boolean activate(Game game, boolean noMana) { if (canActivate(this.controllerId, game)) { if (super.activate(game, noMana)) { - ActivationInfo activationInfo = (ActivationInfo) game.getState().getValue(CardUtil.getCardZoneString("activations", sourceId, game)); + ActivationInfo activationInfo = getActivationInfo(game); if (activationInfo == null) { activationInfo = new ActivationInfo(game.getTurnNum(), 1); } else { @@ -94,21 +94,13 @@ public class ActivateOncePerTurnManaAbility extends ManaAbility { activationInfo.activationCounter++; } } - game.getState().setValue(CardUtil.getCardZoneString("activations", sourceId, game), activationInfo); + setActivationInfo(activationInfo, game); return true; } } return false; } - @Override - public boolean resolve(Game game) { - if (super.resolve(game)) { - return true; - } - return false; - } - @Override public String getRule() { return super.getRule() + " Activate this ability only once each turn."; @@ -119,4 +111,18 @@ public class ActivateOncePerTurnManaAbility extends ManaAbility { return new ActivateOncePerTurnManaAbility(this); } + private ActivationInfo getActivationInfo(Game game) { + Integer turnNum = (Integer) game.getState().getValue(CardUtil.getCardZoneString("activationsTurn", sourceId, game)); + Integer activationCount = (Integer) game.getState().getValue(CardUtil.getCardZoneString("activationsCount", sourceId, game)); + if (turnNum == null || activationCount == null) { + return null; + } + return new ActivationInfo(turnNum, activationCount); + } + + private void setActivationInfo(ActivationInfo activationInfo, Game game) { + game.getState().setValue(CardUtil.getCardZoneString("activationsTurn", sourceId, game), activationInfo.turnNum); + game.getState().setValue(CardUtil.getCardZoneString("activationsCount", sourceId, game), activationInfo.activationCounter); + } + } diff --git a/Mage/src/mage/game/GameState.java b/Mage/src/mage/game/GameState.java index 033dc6f2f0..7a7e4f8abc 100644 --- a/Mage/src/mage/game/GameState.java +++ b/Mage/src/mage/game/GameState.java @@ -152,12 +152,7 @@ public class GameState implements Serializable, Copyable { this.turnMods = state.turnMods.copy(); this.watchers = state.watchers.copy(); for (Map.Entry entry: state.values.entrySet()) { - if (entry.getValue() instanceof Boolean) { // AI changed values of Boolean for cards like Wall of Roots TODO: copy other types than Boolean - this.values.put(entry.getKey(), Boolean.valueOf(((Boolean)entry.getValue()).toString())); - } else { this.values.put(entry.getKey(), entry.getValue()); - } - } this.zones.putAll(state.zones); for (Map.Entry> entry: state.otherAbilities.entrySet()) { @@ -646,6 +641,14 @@ public class GameState implements Serializable, Copyable { return values.get(valueId); } + /** + * Best only use immutable objects, otherwise the states/values of the object may be + * changed by AI simulation, because the Value objects are not copied as the state + * class is copied. + * + * @param valueId + * @param value + */ public void setValue(String valueId, Object value) { values.put(valueId, value); }