diff --git a/Mage.Sets/src/mage/cards/c/ClockworkAvian.java b/Mage.Sets/src/mage/cards/c/ClockworkAvian.java index ca67107e04..1b7c5f3ea5 100644 --- a/Mage.Sets/src/mage/cards/c/ClockworkAvian.java +++ b/Mage.Sets/src/mage/cards/c/ClockworkAvian.java @@ -1,7 +1,5 @@ - package mage.cards.c; -import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.EndOfCombatTriggeredAbility; @@ -12,26 +10,23 @@ import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.decorator.ConditionalActivatedAbility; import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility; -import mage.abilities.dynamicvalue.DynamicValue; -import mage.abilities.dynamicvalue.common.ManacostVariableValue; +import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.counter.AddCountersSourceEffect; import mage.abilities.effects.common.counter.RemoveCounterSourceEffect; import mage.abilities.keyword.FlyingAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.CardType; -import mage.constants.SubType; -import mage.constants.PhaseStep; -import mage.constants.Zone; -import mage.counters.Counter; +import mage.constants.*; import mage.counters.CounterType; -import mage.counters.Counters; import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; import mage.watchers.common.AttackedOrBlockedThisCombatWatcher; +import java.util.UUID; + /** - * - * @author MarcoMarin + * @author TheElk801 */ public final class ClockworkAvian extends CardImpl { @@ -52,23 +47,16 @@ public final class ClockworkAvian extends CardImpl { // At end of combat, if Clockwork Avian attacked or blocked this combat, remove a +1/+0 counter from it. this.addAbility(new ConditionalInterveningIfTriggeredAbility( - new EndOfCombatTriggeredAbility(new RemoveCounterSourceEffect(CounterType.P1P0.createInstance()), false), - AttackedOrBlockedThisCombatSourceCondition.instance, - "At end of combat, if {this} attacked or blocked this combat, remove a +1/+0 counter from it."), - new AttackedOrBlockedThisCombatWatcher() - ); + new EndOfCombatTriggeredAbility( + new RemoveCounterSourceEffect(CounterType.P1P0.createInstance()), false + ), AttackedOrBlockedThisCombatSourceCondition.instance, "At end of combat, " + + "if {this} attacked or blocked this combat, remove a +1/+0 counter from it." + ), new AttackedOrBlockedThisCombatWatcher()); // {X}, {tap}: Put up to X +1/+0 counters on Clockwork Avian. This ability can't cause the total number of +1/+0 counters on Clockwork Avian to be greater than four. Activate this ability only during your upkeep. Ability ability = new ConditionalActivatedAbility( - Zone.BATTLEFIELD, - new AvianAddCountersSourceEffect( - CounterType.P1P0.createInstance(), - ManacostVariableValue.REGULAR, - true, true - ), - new ManaCostsImpl("{X}"), - new IsStepCondition(PhaseStep.UPKEEP), - null + Zone.BATTLEFIELD, new ClockworkAvianEffect(), + new ManaCostsImpl<>("{X}"), new IsStepCondition(PhaseStep.UPKEEP) ); ability.addCost(new TapSourceCost()); this.addAbility(ability); @@ -84,24 +72,42 @@ public final class ClockworkAvian extends CardImpl { } } -class AvianAddCountersSourceEffect extends AddCountersSourceEffect { +class ClockworkAvianEffect extends OneShotEffect { - public AvianAddCountersSourceEffect(Counter counter, DynamicValue amount, boolean informPlayers, boolean putOnCard) { - super(counter, amount, informPlayers, putOnCard); - staticText = "Put up to X +1/+0 counters on {this}. This ability can't cause the total number of +1/+0 counters on {this} to be greater than four."; + ClockworkAvianEffect() { + super(Outcome.Benefit); + staticText = "put up to X +1/+0 counters on {this}. This ability can't cause " + + "the total number of +1/+0 counters on {this} to be greater than four"; + } + + private ClockworkAvianEffect(final ClockworkAvianEffect effect) { + super(effect); + } + + @Override + public ClockworkAvianEffect copy() { + return new ClockworkAvianEffect(this); } @Override public boolean apply(Game game, Ability source) { - //record how many counters - Counters permCounters = game.getPermanent(source.getSourceId()).getCounters(game); - int countersWas = permCounters.getCount(CounterType.P1P0); - if (countersWas < 4) { - super.apply(game, source); - if (permCounters.getCount(CounterType.P1P0) > 4) { - permCounters.removeCounter(CounterType.P1P0, permCounters.getCount(CounterType.P1P0) - 4); - }//if countersWas < 4 then counter is min(current,4); there is no setCounters function tho - }//else this is a rare case of an Avian getting boosted by outside sources :) Which is the sole purpose of this if, for the benefit of this rare but not impossible case :p - return true; + Player player = game.getPlayer(source.getControllerId()); + Permanent permanent = source.getSourcePermanentIfItStillExists(game); + if (player == null || permanent == null) { + return false; + } + int maxCounters = Integer.min( + 4 - permanent.getCounters(game).getCount(CounterType.P1P0), source.getManaCostsToPay().getX() + ); + if (maxCounters < 1) { + return false; + } + int toAdd = player.getAmount( + 0, maxCounters, "Choose how many +1/+0 counters to put on " + permanent.getName(), game + ); + return toAdd > 0 && permanent.addCounters( + CounterType.P1P0.createInstance(toAdd), source.getControllerId(), + source, game, null, true, 4 + ); } } diff --git a/Mage.Sets/src/mage/cards/c/ClockworkBeast.java b/Mage.Sets/src/mage/cards/c/ClockworkBeast.java index 48e257ada3..4d0c2b8bdf 100644 --- a/Mage.Sets/src/mage/cards/c/ClockworkBeast.java +++ b/Mage.Sets/src/mage/cards/c/ClockworkBeast.java @@ -1,7 +1,6 @@ package mage.cards.c; -import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.EndOfCombatTriggeredAbility; @@ -12,25 +11,22 @@ import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.decorator.ConditionalActivatedAbility; import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility; -import mage.abilities.dynamicvalue.DynamicValue; -import mage.abilities.dynamicvalue.common.ManacostVariableValue; +import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.counter.AddCountersSourceEffect; import mage.abilities.effects.common.counter.RemoveCounterSourceEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.CardType; -import mage.constants.SubType; -import mage.constants.PhaseStep; -import mage.constants.Zone; -import mage.counters.Counter; +import mage.constants.*; import mage.counters.CounterType; -import mage.counters.Counters; import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; import mage.watchers.common.AttackedOrBlockedThisCombatWatcher; +import java.util.UUID; + /** - * - * @author escplan9 (Derek Monturo - dmontur1 at gmail dot com) + * @author TheElk801 */ public final class ClockworkBeast extends CardImpl { @@ -48,23 +44,16 @@ public final class ClockworkBeast extends CardImpl { // At end of combat, if Clockwork Beast attacked or blocked this combat, remove a +1/+0 counter from it. this.addAbility(new ConditionalInterveningIfTriggeredAbility( - new EndOfCombatTriggeredAbility(new RemoveCounterSourceEffect(CounterType.P1P0.createInstance()), false), - AttackedOrBlockedThisCombatSourceCondition.instance, - "At end of combat, if {this} attacked or blocked this combat, remove a +1/+0 counter from it."), - new AttackedOrBlockedThisCombatWatcher() - ); + new EndOfCombatTriggeredAbility( + new RemoveCounterSourceEffect(CounterType.P1P0.createInstance()), false + ), AttackedOrBlockedThisCombatSourceCondition.instance, "At end of combat, " + + "if {this} attacked or blocked this combat, remove a +1/+0 counter from it." + ), new AttackedOrBlockedThisCombatWatcher()); // {X}, {tap}: Put up to X +1/+0 counters on Clockwork Beast. This ability can't cause the total number of +1/+0 counters on Clockwork Beast to be greater than seven. Activate this ability only during your upkeep. Ability ability = new ConditionalActivatedAbility( - Zone.BATTLEFIELD, - new BeastAddCountersSourceEffect( - CounterType.P1P0.createInstance(), - ManacostVariableValue.REGULAR, - true, true - ), - new ManaCostsImpl("{X}"), - new IsStepCondition(PhaseStep.UPKEEP), - null + Zone.BATTLEFIELD, new ClockworkBeastEffect(), + new ManaCostsImpl<>("{X}"), new IsStepCondition(PhaseStep.UPKEEP) ); ability.addCost(new TapSourceCost()); this.addAbility(ability); @@ -80,32 +69,42 @@ public final class ClockworkBeast extends CardImpl { } } -class BeastAddCountersSourceEffect extends AddCountersSourceEffect { +class ClockworkBeastEffect extends OneShotEffect { - public BeastAddCountersSourceEffect(Counter counter, DynamicValue amount, boolean informPlayers, boolean putOnCard) { - super(counter, amount, informPlayers, putOnCard); - staticText = "Put up to X +1/+0 counters on {this}. This ability can't cause the total number of +1/+0 counters on {this} to be greater than seven."; + ClockworkBeastEffect() { + super(Outcome.Benefit); + staticText = "put up to X +1/+0 counters on {this}. This ability can't cause " + + "the total number of +1/+0 counters on {this} to be greater than seven"; } - @Override - public boolean apply(Game game, Ability source) { - Counters permCounters = game.getPermanent(source.getSourceId()).getCounters(game); - int countersWas = permCounters.getCount(CounterType.P1P0); - if (countersWas < 7) { - super.apply(game, source); - if (permCounters.getCount(CounterType.P1P0) > 7) { - permCounters.removeCounter(CounterType.P1P0, permCounters.getCount(CounterType.P1P0) - 7); - }//if countersWas < 7 then counter is min(current,7); there is no setCounters function though - }//else this is a rare case of a Beast getting boosted by outside sources. Which is the sole purpose of this if, for the benefit of this rare but not impossible case - return true; - } - - public BeastAddCountersSourceEffect(final BeastAddCountersSourceEffect effect) { + private ClockworkBeastEffect(final ClockworkBeastEffect effect) { super(effect); } @Override - public BeastAddCountersSourceEffect copy() { - return new BeastAddCountersSourceEffect(this); + public ClockworkBeastEffect copy() { + return new ClockworkBeastEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player player = game.getPlayer(source.getControllerId()); + Permanent permanent = source.getSourcePermanentIfItStillExists(game); + if (player == null || permanent == null) { + return false; + } + int maxCounters = Integer.min( + 7 - permanent.getCounters(game).getCount(CounterType.P1P0), source.getManaCostsToPay().getX() + ); + if (maxCounters < 1) { + return false; + } + int toAdd = player.getAmount( + 0, maxCounters, "Choose how many +1/+0 counters to put on " + permanent.getName(), game + ); + return toAdd > 0 && permanent.addCounters( + CounterType.P1P0.createInstance(toAdd), source.getControllerId(), + source, game, null, true, 7 + ); } } diff --git a/Mage.Sets/src/mage/cards/c/ClockworkSteed.java b/Mage.Sets/src/mage/cards/c/ClockworkSteed.java index dac9760b5e..7ab435ef58 100644 --- a/Mage.Sets/src/mage/cards/c/ClockworkSteed.java +++ b/Mage.Sets/src/mage/cards/c/ClockworkSteed.java @@ -1,7 +1,5 @@ - package mage.cards.c; -import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.EndOfCombatTriggeredAbility; @@ -13,28 +11,24 @@ import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.decorator.ConditionalActivatedAbility; import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility; -import mage.abilities.dynamicvalue.DynamicValue; -import mage.abilities.dynamicvalue.common.ManacostVariableValue; +import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.combat.CantBeBlockedByCreaturesSourceEffect; import mage.abilities.effects.common.counter.AddCountersSourceEffect; import mage.abilities.effects.common.counter.RemoveCounterSourceEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.CardType; -import mage.constants.SubType; -import mage.constants.Duration; -import mage.constants.PhaseStep; -import mage.constants.Zone; -import mage.counters.Counter; +import mage.constants.*; import mage.counters.CounterType; -import mage.counters.Counters; import mage.filter.common.FilterCreaturePermanent; import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; import mage.watchers.common.AttackedOrBlockedThisCombatWatcher; +import java.util.UUID; + /** - * - * @author escplan9, MarcoMarin & L_J + * @author TheElk801 */ public final class ClockworkSteed extends CardImpl { @@ -58,23 +52,16 @@ public final class ClockworkSteed extends CardImpl { // At end of combat, if Clockwork Steed attacked or blocked this combat, remove a +1/+0 counter from it. this.addAbility(new ConditionalInterveningIfTriggeredAbility( - new EndOfCombatTriggeredAbility(new RemoveCounterSourceEffect(CounterType.P1P0.createInstance()), false), - AttackedOrBlockedThisCombatSourceCondition.instance, - "At end of combat, if {this} attacked or blocked this combat, remove a +1/+0 counter from it."), - new AttackedOrBlockedThisCombatWatcher() - ); + new EndOfCombatTriggeredAbility( + new RemoveCounterSourceEffect(CounterType.P1P0.createInstance()), false + ), AttackedOrBlockedThisCombatSourceCondition.instance, "At end of combat, " + + "if {this} attacked or blocked this combat, remove a +1/+0 counter from it." + ), new AttackedOrBlockedThisCombatWatcher()); // {X}, {tap}: Put up to X +1/+0 counters on Clockwork Steed. This ability can't cause the total number of +1/+0 counters on Clockwork Steed to be greater than four. Activate this ability only during your upkeep. Ability ability = new ConditionalActivatedAbility( - Zone.BATTLEFIELD, - new ClockworkSteedAddCountersSourceEffect( - CounterType.P1P0.createInstance(), - ManacostVariableValue.REGULAR, - true, true - ), - new ManaCostsImpl("{X}"), - new IsStepCondition(PhaseStep.UPKEEP), - null + Zone.BATTLEFIELD, new ClockworkSteedEffect(), + new ManaCostsImpl<>("{X}"), new IsStepCondition(PhaseStep.UPKEEP) ); ability.addCost(new TapSourceCost()); this.addAbility(ability); @@ -90,24 +77,42 @@ public final class ClockworkSteed extends CardImpl { } } -class ClockworkSteedAddCountersSourceEffect extends AddCountersSourceEffect { +class ClockworkSteedEffect extends OneShotEffect { - public ClockworkSteedAddCountersSourceEffect(Counter counter, DynamicValue amount, boolean informPlayers, boolean putOnCard) { - super(counter, amount, informPlayers, putOnCard); - staticText = "Put up to X +1/+0 counters on {this}. This ability can't cause the total number of +1/+0 counters on {this} to be greater than four."; + ClockworkSteedEffect() { + super(Outcome.Benefit); + staticText = "put up to X +1/+0 counters on {this}. This ability can't cause " + + "the total number of +1/+0 counters on {this} to be greater than four"; + } + + private ClockworkSteedEffect(final ClockworkSteedEffect effect) { + super(effect); + } + + @Override + public ClockworkSteedEffect copy() { + return new ClockworkSteedEffect(this); } @Override public boolean apply(Game game, Ability source) { - //record how many counters - Counters permCounters = game.getPermanent(source.getSourceId()).getCounters(game); - int countersWas = permCounters.getCount(CounterType.P1P0); - if (countersWas < 4) { - super.apply(game, source); - if (permCounters.getCount(CounterType.P1P0) > 4) { - permCounters.removeCounter(CounterType.P1P0, permCounters.getCount(CounterType.P1P0) - 4); - }//if countersWas < 4 then counter is min(current,4); there is no setCounters function tho - }//else this is a rare case of a Steed getting boosted by outside sources :) Which is the sole purpose of this if, for the benefit of this rare but not impossible case :p - return true; + Player player = game.getPlayer(source.getControllerId()); + Permanent permanent = source.getSourcePermanentIfItStillExists(game); + if (player == null || permanent == null) { + return false; + } + int maxCounters = Integer.min( + 4 - permanent.getCounters(game).getCount(CounterType.P1P0), source.getManaCostsToPay().getX() + ); + if (maxCounters < 1) { + return false; + } + int toAdd = player.getAmount( + 0, maxCounters, "Choose how many +1/+0 counters to put on " + permanent.getName(), game + ); + return toAdd > 0 && permanent.addCounters( + CounterType.P1P0.createInstance(toAdd), source.getControllerId(), + source, game, null, true, 4 + ); } } diff --git a/Mage.Sets/src/mage/cards/c/ClockworkSwarm.java b/Mage.Sets/src/mage/cards/c/ClockworkSwarm.java index 02e88b6d08..2e8c15776d 100644 --- a/Mage.Sets/src/mage/cards/c/ClockworkSwarm.java +++ b/Mage.Sets/src/mage/cards/c/ClockworkSwarm.java @@ -1,7 +1,5 @@ - package mage.cards.c; -import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.EndOfCombatTriggeredAbility; @@ -13,27 +11,23 @@ import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.decorator.ConditionalActivatedAbility; import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility; -import mage.abilities.dynamicvalue.DynamicValue; -import mage.abilities.dynamicvalue.common.ManacostVariableValue; +import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.combat.CantBeBlockedByCreaturesSourceEffect; import mage.abilities.effects.common.counter.AddCountersSourceEffect; import mage.abilities.effects.common.counter.RemoveCounterSourceEffect; -import mage.constants.SubType; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.CardType; -import mage.constants.Duration; -import mage.constants.PhaseStep; -import mage.constants.Zone; -import mage.counters.Counter; +import mage.constants.*; import mage.counters.CounterType; -import mage.counters.Counters; import mage.filter.common.FilterCreaturePermanent; import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; import mage.watchers.common.AttackedOrBlockedThisCombatWatcher; +import java.util.UUID; + /** - * * @author TheElk801 */ public final class ClockworkSwarm extends CardImpl { @@ -62,22 +56,16 @@ public final class ClockworkSwarm extends CardImpl { // At end of combat, if Clockwork Swarm attacked or blocked this combat, remove a +1/+0 counter from it. this.addAbility(new ConditionalInterveningIfTriggeredAbility( - new EndOfCombatTriggeredAbility(new RemoveCounterSourceEffect(CounterType.P1P0.createInstance()), false), - AttackedOrBlockedThisCombatSourceCondition.instance, - "At end of combat, if {this} attacked or blocked this combat, remove a +1/+0 counter from it."), - new AttackedOrBlockedThisCombatWatcher()); + new EndOfCombatTriggeredAbility( + new RemoveCounterSourceEffect(CounterType.P1P0.createInstance()), false + ), AttackedOrBlockedThisCombatSourceCondition.instance, "At end of combat, " + + "if {this} attacked or blocked this combat, remove a +1/+0 counter from it." + ), new AttackedOrBlockedThisCombatWatcher()); // {X}, {tap}: Put up to X +1/+0 counters on Clockwork Swarm. This ability can't cause the total number of +1/+0 counters on Clockwork Swarm to be greater than four. Activate this ability only during your upkeep. Ability ability = new ConditionalActivatedAbility( - Zone.BATTLEFIELD, - new SwarmAddCountersSourceEffect( - CounterType.P1P0.createInstance(), - ManacostVariableValue.REGULAR, - true, true - ), - new ManaCostsImpl("{X}"), - new IsStepCondition(PhaseStep.UPKEEP), - null + Zone.BATTLEFIELD, new ClockworkSwarmEffect(), + new ManaCostsImpl<>("{X}"), new IsStepCondition(PhaseStep.UPKEEP) ); ability.addCost(new TapSourceCost()); this.addAbility(ability); @@ -93,32 +81,42 @@ public final class ClockworkSwarm extends CardImpl { } } -class SwarmAddCountersSourceEffect extends AddCountersSourceEffect { +class ClockworkSwarmEffect extends OneShotEffect { - public SwarmAddCountersSourceEffect(Counter counter, DynamicValue amount, boolean informPlayers, boolean putOnCard) { - super(counter, amount, informPlayers, putOnCard); - staticText = "Put up to X +1/+0 counters on {this}. This ability can't cause the total number of +1/+0 counters on {this} to be greater than four."; + ClockworkSwarmEffect() { + super(Outcome.Benefit); + staticText = "put up to X +1/+0 counters on {this}. This ability can't cause " + + "the total number of +1/+0 counters on {this} to be greater than four"; } - @Override - public boolean apply(Game game, Ability source) { - Counters permCounters = game.getPermanent(source.getSourceId()).getCounters(game); - int countersWas = permCounters.getCount(CounterType.P1P0); - if (countersWas < 4) { - super.apply(game, source); - if (permCounters.getCount(CounterType.P1P0) > 4) { - permCounters.removeCounter(CounterType.P1P0, permCounters.getCount(CounterType.P1P0) - 4); - }//if countersWas < 4 then counter is min(current,4); there is no setCounters function though - }//else this is a rare case of a Beast getting boosted by outside sources. Which is the sole purpose of this if, for the benefit of this rare but not impossible case - return true; - } - - public SwarmAddCountersSourceEffect(final SwarmAddCountersSourceEffect effect) { + private ClockworkSwarmEffect(final ClockworkSwarmEffect effect) { super(effect); } @Override - public SwarmAddCountersSourceEffect copy() { - return new SwarmAddCountersSourceEffect(this); + public ClockworkSwarmEffect copy() { + return new ClockworkSwarmEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player player = game.getPlayer(source.getControllerId()); + Permanent permanent = source.getSourcePermanentIfItStillExists(game); + if (player == null || permanent == null) { + return false; + } + int maxCounters = Integer.min( + 4 - permanent.getCounters(game).getCount(CounterType.P1P0), source.getManaCostsToPay().getX() + ); + if (maxCounters < 1) { + return false; + } + int toAdd = player.getAmount( + 0, maxCounters, "Choose how many +1/+0 counters to put on " + permanent.getName(), game + ); + return toAdd > 0 && permanent.addCounters( + CounterType.P1P0.createInstance(toAdd), source.getControllerId(), + source, game, null, true, 4 + ); } } diff --git a/Mage/src/main/java/mage/cards/Card.java b/Mage/src/main/java/mage/cards/Card.java index 5b99d66e85..d3b27fa068 100644 --- a/Mage/src/main/java/mage/cards/Card.java +++ b/Mage/src/main/java/mage/cards/Card.java @@ -152,6 +152,8 @@ public interface Card extends MageObject { boolean addCounters(Counter counter, UUID playerAddingCounters, Ability source, Game game, List appliedEffects, boolean isEffect); + boolean addCounters(Counter counter, UUID playerAddingCounters, Ability source, Game game, List appliedEffects, boolean isEffect, int maxCounters); + void removeCounters(String name, int amount, Ability source, Game game); void removeCounters(Counter counter, Ability source, Game game); diff --git a/Mage/src/main/java/mage/cards/CardImpl.java b/Mage/src/main/java/mage/cards/CardImpl.java index 014c740079..946710f81a 100644 --- a/Mage/src/main/java/mage/cards/CardImpl.java +++ b/Mage/src/main/java/mage/cards/CardImpl.java @@ -704,12 +704,21 @@ public abstract class CardImpl extends MageObjectImpl implements Card { @Override public boolean addCounters(Counter counter, UUID playerAddingCounters, Ability source, Game game, List appliedEffects, boolean isEffect) { + return addCounters(counter, playerAddingCounters, source, game, appliedEffects, isEffect, Integer.MAX_VALUE); + } + + public boolean addCounters(Counter counter, UUID playerAddingCounters, Ability source, Game game, List appliedEffects, boolean isEffect, int maxCounters) { boolean returnCode = true; GameEvent addingAllEvent = GameEvent.getEvent(GameEvent.EventType.ADD_COUNTERS, objectId, source, playerAddingCounters, counter.getName(), counter.getCount()); addingAllEvent.setAppliedEffects(appliedEffects); addingAllEvent.setFlag(isEffect); if (!game.replaceEvent(addingAllEvent)) { - int amount = addingAllEvent.getAmount(); + int amount; + if (maxCounters < Integer.MAX_VALUE) { + amount = Integer.min(addingAllEvent.getAmount(), maxCounters - this.getCounters(game).getCount(counter.getName())); + } else { + amount = addingAllEvent.getAmount(); + } boolean isEffectFlag = addingAllEvent.getFlag(); int finalAmount = amount; for (int i = 0; i < amount; i++) { diff --git a/Mage/src/main/java/mage/cards/ModalDoubleFacesCard.java b/Mage/src/main/java/mage/cards/ModalDoubleFacesCard.java index 1680c05f06..db7062b931 100644 --- a/Mage/src/main/java/mage/cards/ModalDoubleFacesCard.java +++ b/Mage/src/main/java/mage/cards/ModalDoubleFacesCard.java @@ -132,8 +132,8 @@ public abstract class ModalDoubleFacesCard extends CardImpl { } @Override - public boolean addCounters(Counter counter, UUID playerAddingCounters, Ability source, Game game, List appliedEffects, boolean isEffect) { - return leftHalfCard.addCounters(counter, playerAddingCounters, source, game, appliedEffects, isEffect); + public boolean addCounters(Counter counter, UUID playerAddingCounters, Ability source, Game game, List appliedEffects, boolean isEffect, int maxCounters) { + return leftHalfCard.addCounters(counter, playerAddingCounters, source, game, appliedEffects, isEffect, maxCounters); } @Override diff --git a/Mage/src/main/java/mage/game/stack/Spell.java b/Mage/src/main/java/mage/game/stack/Spell.java index 82ea3710ea..910e19e5f2 100644 --- a/Mage/src/main/java/mage/game/stack/Spell.java +++ b/Mage/src/main/java/mage/game/stack/Spell.java @@ -1009,6 +1009,11 @@ public class Spell extends StackObjectImpl implements Card { return card.addCounters(counter, playerAddingCounters, source, game, appliedEffects, isEffect); } + @Override + public boolean addCounters(Counter counter, UUID playerAddingCounters, Ability source, Game game, List appliedEffects, boolean isEffect, int maxCounters) { + return card.addCounters(counter, playerAddingCounters, source, game, appliedEffects, isEffect, maxCounters); + } + @Override public void removeCounters(String name, int amount, Ability source, Game game) { card.removeCounters(name, amount, source, game); diff --git a/Mage/src/main/java/mage/watchers/common/AttackedOrBlockedThisCombatWatcher.java b/Mage/src/main/java/mage/watchers/common/AttackedOrBlockedThisCombatWatcher.java index 5f5410fca3..271c2c2d8a 100644 --- a/Mage/src/main/java/mage/watchers/common/AttackedOrBlockedThisCombatWatcher.java +++ b/Mage/src/main/java/mage/watchers/common/AttackedOrBlockedThisCombatWatcher.java @@ -1,15 +1,15 @@ package mage.watchers.common; -import java.util.HashSet; -import java.util.Set; import mage.MageObjectReference; import mage.constants.WatcherScope; import mage.game.Game; import mage.game.events.GameEvent; import mage.watchers.Watcher; +import java.util.HashSet; +import java.util.Set; + /** - * * @author LevelX2 */ public class AttackedOrBlockedThisCombatWatcher extends Watcher { @@ -23,14 +23,16 @@ public class AttackedOrBlockedThisCombatWatcher extends Watcher { @Override public void watch(GameEvent event, Game game) { - if (event.getType() == GameEvent.EventType.BEGIN_COMBAT_STEP_PRE) { - this.getAttackedThisTurnCreatures().clear(); - } - if (event.getType() == GameEvent.EventType.ATTACKER_DECLARED) { - this.getAttackedThisTurnCreatures().add(new MageObjectReference(event.getSourceId(), game)); - } - if (event.getType() == GameEvent.EventType.BLOCKER_DECLARED) { - this.getBlockedThisTurnCreatures().add(new MageObjectReference(event.getSourceId(), game)); + switch (event.getType()) { + case BEGIN_COMBAT_STEP_PRE: + this.attackedThisTurnCreatures.clear(); + this.blockedThisTurnCreatures.clear(); + return; + case ATTACKER_DECLARED: + this.attackedThisTurnCreatures.add(new MageObjectReference(event.getSourceId(), game)); + return; + case BLOCKER_DECLARED: + this.blockedThisTurnCreatures.add(new MageObjectReference(event.getSourceId(), game)); } }