* Wall of Root - Fixed that the mana ability could wrongly not used again after canceling a previous pay mana action.

This commit is contained in:
LevelX2 2015-01-07 16:43:26 +01:00
parent 96aafcd475
commit 5973a764aa
3 changed files with 43 additions and 22 deletions

View file

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

View file

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

View file

@ -152,12 +152,7 @@ public class GameState implements Serializable, Copyable<GameState> {
this.turnMods = state.turnMods.copy();
this.watchers = state.watchers.copy();
for (Map.Entry<String, Object> 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<UUID, Abilities<Ability>> entry: state.otherAbilities.entrySet()) {
@ -646,6 +641,14 @@ public class GameState implements Serializable, Copyable<GameState> {
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);
}