mirror of
https://github.com/correl/mage.git
synced 2025-03-16 17:00:13 -09:00
* 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:
parent
96aafcd475
commit
5973a764aa
3 changed files with 43 additions and 22 deletions
|
@ -72,7 +72,7 @@ public class LimitedTimesPerTurnActivatedAbility extends ActivatedAbilityImpl {
|
||||||
@Override
|
@Override
|
||||||
public boolean canActivate(UUID playerId, Game game) {
|
public boolean canActivate(UUID playerId, Game game) {
|
||||||
if (super.canActivate(playerId, 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 activationInfo == null || activationInfo.turnNum != game.getTurnNum() || activationInfo.activationCounter < maxActivationsPerTurn;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -82,7 +82,7 @@ public class LimitedTimesPerTurnActivatedAbility extends ActivatedAbilityImpl {
|
||||||
public boolean activate(Game game, boolean noMana) {
|
public boolean activate(Game game, boolean noMana) {
|
||||||
if (canActivate(this.controllerId, game)) {
|
if (canActivate(this.controllerId, game)) {
|
||||||
if (super.activate(game, noMana)) {
|
if (super.activate(game, noMana)) {
|
||||||
ActivationInfo activationInfo = (ActivationInfo) game.getState().getValue(CardUtil.getCardZoneString("activations", sourceId, game));
|
ActivationInfo activationInfo = getActivationInfo(game);
|
||||||
if (activationInfo == null) {
|
if (activationInfo == null) {
|
||||||
activationInfo = new ActivationInfo(game.getTurnNum(), 1);
|
activationInfo = new ActivationInfo(game.getTurnNum(), 1);
|
||||||
} else {
|
} else {
|
||||||
|
@ -93,7 +93,7 @@ public class LimitedTimesPerTurnActivatedAbility extends ActivatedAbilityImpl {
|
||||||
activationInfo.activationCounter++;
|
activationInfo.activationCounter++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
game.getState().setValue(CardUtil.getCardZoneString("activations", sourceId, game), activationInfo);
|
setActivationInfo(activationInfo, game);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,5 +126,17 @@ public class LimitedTimesPerTurnActivatedAbility extends ActivatedAbilityImpl {
|
||||||
public LimitedTimesPerTurnActivatedAbility copy() {
|
public LimitedTimesPerTurnActivatedAbility copy() {
|
||||||
return new LimitedTimesPerTurnActivatedAbility(this);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ import mage.util.CardUtil;
|
||||||
public class ActivateOncePerTurnManaAbility extends ManaAbility {
|
public class ActivateOncePerTurnManaAbility extends ManaAbility {
|
||||||
|
|
||||||
class ActivationInfo {
|
class ActivationInfo {
|
||||||
|
|
||||||
public int turnNum;
|
public int turnNum;
|
||||||
public int activationCounter;
|
public int activationCounter;
|
||||||
|
|
||||||
|
@ -71,19 +71,19 @@ public class ActivateOncePerTurnManaAbility extends ManaAbility {
|
||||||
@Override
|
@Override
|
||||||
public boolean canActivate(UUID playerId, Game game) {
|
public boolean canActivate(UUID playerId, Game game) {
|
||||||
if (super.canActivate(playerId, 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) {
|
if (activationInfo == null || activationInfo.turnNum != game.getTurnNum() || activationInfo.activationCounter < 1) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean activate(Game game, boolean noMana) {
|
public boolean activate(Game game, boolean noMana) {
|
||||||
if (canActivate(this.controllerId, game)) {
|
if (canActivate(this.controllerId, game)) {
|
||||||
if (super.activate(game, noMana)) {
|
if (super.activate(game, noMana)) {
|
||||||
ActivationInfo activationInfo = (ActivationInfo) game.getState().getValue(CardUtil.getCardZoneString("activations", sourceId, game));
|
ActivationInfo activationInfo = getActivationInfo(game);
|
||||||
if (activationInfo == null) {
|
if (activationInfo == null) {
|
||||||
activationInfo = new ActivationInfo(game.getTurnNum(), 1);
|
activationInfo = new ActivationInfo(game.getTurnNum(), 1);
|
||||||
} else {
|
} else {
|
||||||
|
@ -94,21 +94,13 @@ public class ActivateOncePerTurnManaAbility extends ManaAbility {
|
||||||
activationInfo.activationCounter++;
|
activationInfo.activationCounter++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
game.getState().setValue(CardUtil.getCardZoneString("activations", sourceId, game), activationInfo);
|
setActivationInfo(activationInfo, game);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean resolve(Game game) {
|
|
||||||
if (super.resolve(game)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getRule() {
|
public String getRule() {
|
||||||
return super.getRule() + " Activate this ability only once each turn.";
|
return super.getRule() + " Activate this ability only once each turn.";
|
||||||
|
@ -119,4 +111,18 @@ public class ActivateOncePerTurnManaAbility extends ManaAbility {
|
||||||
return new ActivateOncePerTurnManaAbility(this);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,12 +152,7 @@ public class GameState implements Serializable, Copyable<GameState> {
|
||||||
this.turnMods = state.turnMods.copy();
|
this.turnMods = state.turnMods.copy();
|
||||||
this.watchers = state.watchers.copy();
|
this.watchers = state.watchers.copy();
|
||||||
for (Map.Entry<String, Object> entry: state.values.entrySet()) {
|
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.values.put(entry.getKey(), entry.getValue());
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
this.zones.putAll(state.zones);
|
this.zones.putAll(state.zones);
|
||||||
for (Map.Entry<UUID, Abilities<Ability>> entry: state.otherAbilities.entrySet()) {
|
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);
|
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) {
|
public void setValue(String valueId, Object value) {
|
||||||
values.put(valueId, value);
|
values.put(valueId, value);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue