* ForcastAbility - Fixed that forecast ability wrongly did only work one time from hand for a card.

This commit is contained in:
LevelX2 2014-08-01 00:25:21 +02:00
parent 16b58a337d
commit 11cf5ab4fe
2 changed files with 24 additions and 13 deletions

View file

@ -42,6 +42,17 @@ import mage.util.CardUtil;
*/
public class LimitedTimesPerTurnActivatedAbility extends ActivatedAbilityImpl {
class ActivationInfo {
public int turnNum;
public int activationCounter;
public ActivationInfo(int turnNum, int activationCounter) {
this.turnNum = turnNum;
this.activationCounter = activationCounter;
}
}
private int maxActivationsPerTurn;
public LimitedTimesPerTurnActivatedAbility(Zone zone, Effect effect, Cost cost) {
@ -61,8 +72,8 @@ public class LimitedTimesPerTurnActivatedAbility extends ActivatedAbilityImpl {
@Override
public boolean canActivate(UUID playerId, Game game) {
if (super.canActivate(playerId, game)) {
Integer activations = (Integer) game.getState().getValue(CardUtil.getCardZoneString("activations", sourceId, game));
return activations == null || activations < maxActivationsPerTurn;
ActivationInfo activationInfo = (ActivationInfo) game.getState().getValue(CardUtil.getCardZoneString("activations", sourceId, game));
return activationInfo == null || activationInfo.turnNum != game.getTurnNum() || activationInfo.activationCounter < maxActivationsPerTurn;
}
return false;
}
@ -71,24 +82,24 @@ public class LimitedTimesPerTurnActivatedAbility extends ActivatedAbilityImpl {
public boolean activate(Game game, boolean noMana) {
if (canActivate(this.controllerId, game)) {
if (super.activate(game, noMana)) {
Integer activations = (Integer) game.getState().getValue(CardUtil.getCardZoneString("activations", sourceId, game));
if (activations == null) {
activations = new Integer(1);
ActivationInfo activationInfo = (ActivationInfo) game.getState().getValue(CardUtil.getCardZoneString("activations", sourceId, game));
if (activationInfo == null) {
activationInfo = new ActivationInfo(game.getTurnNum(), 1);
} else {
activations++;
if (activationInfo.turnNum != game.getTurnNum()) {
activationInfo.turnNum = game.getTurnNum();
activationInfo.activationCounter = 1;
} else {
activationInfo.activationCounter++;
}
}
game.getState().setValue(CardUtil.getCardZoneString("activations", sourceId, game), activations);
game.getState().setValue(CardUtil.getCardZoneString("activations", sourceId, game), activationInfo);
return true;
}
}
return false;
}
@Override
public void reset(Game game) {
game.getState().setValue(CardUtil.getCardZoneString("activations", sourceId, game), new Integer(0));
}
@Override
public boolean resolve(Game game) {
return super.resolve(game);

View file

@ -70,7 +70,7 @@ public class ForecastAbility extends LimitedTimesPerTurnActivatedAbility {
@Override
public boolean canActivate(UUID playerId, Game game) {
// May be activated only during the upkeep step of the card's owner
if (!game.getActivePlayerId().equals(controllerId) || !game.getStep().getType().equals(PhaseStep.UPKEEP)) {
if (!game.getActivePlayerId().equals(controllerId) || !PhaseStep.UPKEEP.equals(game.getStep().getType())) {
return false;
}
return super.canActivate(playerId, game);