From 0a635ac3418b5a45f64d5755e8b8a0e92eb03b77 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Wed, 13 Jun 2018 20:58:31 -0400 Subject: [PATCH] fixed implementation of Tetravus to allow for multiple counters/tokens in a single turn The tokens were also incorrectly implemented --- Mage.Sets/src/mage/cards/t/Tetravus.java | 157 +++++++++++++++--- .../game/permanent/token/TetraviteToken.java | 41 +++-- 2 files changed, 157 insertions(+), 41 deletions(-) diff --git a/Mage.Sets/src/mage/cards/t/Tetravus.java b/Mage.Sets/src/mage/cards/t/Tetravus.java index 7a7820f44e..ace6165e8e 100644 --- a/Mage.Sets/src/mage/cards/t/Tetravus.java +++ b/Mage.Sets/src/mage/cards/t/Tetravus.java @@ -1,35 +1,40 @@ - package mage.cards.t; +import java.util.HashSet; +import java.util.Set; import java.util.UUID; import mage.MageInt; -import mage.MageObject; -import mage.abilities.StaticAbility; +import mage.MageObjectReference; +import mage.abilities.Ability; import mage.abilities.common.BeginningOfUpkeepTriggeredAbility; import mage.abilities.common.EntersBattlefieldAbility; -import mage.abilities.condition.common.SourceHasCounterCondition; +import mage.abilities.costs.Cost; import mage.abilities.costs.common.ExileTargetCost; import mage.abilities.costs.common.RemoveCountersSourceCost; -import mage.abilities.decorator.ConditionalTriggeredAbility; +import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.CreateTokenEffect; -import mage.abilities.effects.common.DoIfCostPaid; import mage.abilities.effects.common.counter.AddCountersSourceEffect; import mage.abilities.keyword.FlyingAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; +import mage.constants.Outcome; import mage.constants.SubType; import mage.constants.TargetController; -import mage.constants.Zone; import mage.counters.CounterType; import mage.filter.common.FilterControlledPermanent; +import mage.filter.predicate.Predicate; +import mage.filter.predicate.permanent.TokenPredicate; import mage.game.Game; +import mage.game.permanent.Permanent; import mage.game.permanent.token.TetraviteToken; +import mage.players.Player; import mage.target.common.TargetControlledPermanent; +import mage.util.CardUtil; /** * - * @author MarcoMarin + * @author TheElk801 */ public final class Tetravus extends CardImpl { @@ -41,15 +46,24 @@ public final class Tetravus extends CardImpl { // Flying this.addAbility(FlyingAbility.getInstance()); + // Tetravus enters the battlefield with three +1/+1 counters on it. - this.addAbility(new EntersBattlefieldAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance(3)), "{this} enters the battlefield with three +1/+1 counters on it")); + this.addAbility(new EntersBattlefieldAbility( + new AddCountersSourceEffect(CounterType.P1P1.createInstance(3)), + "with three +1/+1 counters on it" + )); + // At the beginning of your upkeep, you may remove any number of +1/+1 counters from Tetravus. If you do, create that many 1/1 colorless Tetravite artifact creature tokens. They each have flying and "This creature can't be enchanted." - this.addAbility(new ConditionalTriggeredAbility(new BeginningOfUpkeepTriggeredAbility(new DoIfCostPaid(new CreateTokenEffect(new TetraviteToken()), - new RemoveCountersSourceCost(CounterType.P1P1.createInstance(1))), TargetController.YOU, true), - new SourceHasCounterCondition(CounterType.P1P1, 1), "At the beginning of your upkeep, you may remove any number of +1/+1 counters from Tetravus. If you do, create that many 1/1 colorless Tetravite artifact creature tokens. They each have flying and \"This creature can't be enchanted.\"")); + this.addAbility(new BeginningOfUpkeepTriggeredAbility( + new TetravusCreateTokensEffect(), + TargetController.YOU, true + )); + // At the beginning of your upkeep, you may exile any number of tokens created with Tetravus. If you do, put that many +1/+1 counters on Tetravus. - this.addAbility(new BeginningOfUpkeepTriggeredAbility(new DoIfCostPaid(new AddCountersSourceEffect(CounterType.P1P1.createInstance(1)), - new ExileTargetCost(new TargetControlledPermanent(new FilterControlledPermanent("Tetravite")))), TargetController.YOU, true)); + this.addAbility(new BeginningOfUpkeepTriggeredAbility( + new TetravusAddCountersEffect(), + TargetController.YOU, true + )); } @@ -63,27 +77,120 @@ public final class Tetravus extends CardImpl { } } -class CantBeEnchantedAbility extends StaticAbility { +class TetravusCreateTokensEffect extends OneShotEffect { - public CantBeEnchantedAbility() { - super(Zone.BATTLEFIELD, null); + public TetravusCreateTokensEffect() { + super(Outcome.Benefit); + this.staticText = "remove any number of +1/+1 counters from {this}. " + + "If you do, create that many 1/1 colorless Tetravite artifact creature tokens. " + + "They each have flying and \"This creature can't be enchanted.\""; } - public CantBeEnchantedAbility(final CantBeEnchantedAbility ability) { - super(ability); + public TetravusCreateTokensEffect(final TetravusCreateTokensEffect effect) { + super(effect); } @Override - public CantBeEnchantedAbility copy() { - return new CantBeEnchantedAbility(this); + public TetravusCreateTokensEffect copy() { + return new TetravusCreateTokensEffect(this); } - public boolean canTarget(MageObject source, Game game) { - if (source.isEnchantment() - && source.hasSubtype(SubType.AURA, game)) { + @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; } - return true; + int countersToRemove = permanent.getCounters(game).getCount(CounterType.P1P1); + if (countersToRemove == 0) { + return false; + } + countersToRemove = player.getAmount(0, countersToRemove, "Choose an amount of counters to remove", game); + Cost cost = new RemoveCountersSourceCost(CounterType.P1P1.createInstance(countersToRemove)); + if (cost.pay(source, game, source.getSourceId(), source.getControllerId(), true)) { + CreateTokenEffect effect = new CreateTokenEffect(new TetraviteToken(), countersToRemove); + effect.apply(game, source); + Object object = game.getState().getValue(CardUtil.getObjectZoneString("_tokensCreated", permanent, game)); + Set tokensCreated; + if (object != null) { + tokensCreated = (Set) object; + } else { + tokensCreated = new HashSet<>(); + } + for (UUID tokenId : effect.getLastAddedTokenIds()) { + if (tokenId != null) { + tokensCreated.add(tokenId); + } + } + game.getState().setValue(CardUtil.getCardZoneString("_tokensCreated", source.getSourceId(), game), tokensCreated); + } + return false; + } +} + +class TetravusAddCountersEffect extends OneShotEffect { + + public TetravusAddCountersEffect() { + super(Outcome.Benefit); + this.staticText = "exile any number of tokens created with {this}. " + + "If you do, put that many +1/+1 counters on {this}"; } + public TetravusAddCountersEffect(final TetravusAddCountersEffect effect) { + super(effect); + } + + @Override + public TetravusAddCountersEffect copy() { + return new TetravusAddCountersEffect(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; + } + FilterControlledPermanent filter = new FilterControlledPermanent("tokens created with " + permanent.getName()); + filter.add(new TetravusPredicate(new MageObjectReference(permanent, game))); + filter.add(new TokenPredicate()); + ExileTargetCost cost = new ExileTargetCost(new TargetControlledPermanent(0, Integer.MAX_VALUE, filter, true)); + if (cost.pay(source, game, source.getSourceId(), player.getId(), true)) { + return new AddCountersSourceEffect(CounterType.P1P1.createInstance(cost.getPermanents().size())).apply(game, source); + } + return false; + } +} + +class TetravusPredicate implements Predicate { + + private final MageObjectReference mor; + + public TetravusPredicate(MageObjectReference mor) { + this.mor = mor; + } + + @Override + public boolean apply(Permanent input, Game game) { + if (mor == null) { + return false; + } + Permanent permanent = mor.getPermanent(game); + if (permanent == null) { + return false; + } + Object object = game.getState().getValue(CardUtil.getObjectZoneString("_tokensCreated", permanent, game)); + if (object == null) { + return false; + } + Set tokensCreated = (Set) object; + return tokensCreated.contains(input.getId()); + } + + @Override + public String toString() { + return ""; + } } diff --git a/Mage/src/main/java/mage/game/permanent/token/TetraviteToken.java b/Mage/src/main/java/mage/game/permanent/token/TetraviteToken.java index 7ff53e0f12..aef40c90d5 100644 --- a/Mage/src/main/java/mage/game/permanent/token/TetraviteToken.java +++ b/Mage/src/main/java/mage/game/permanent/token/TetraviteToken.java @@ -1,14 +1,17 @@ - - package mage.game.permanent.token; + import mage.constants.CardType; import mage.MageInt; -import mage.MageObject; -import mage.abilities.StaticAbility; +import mage.abilities.Ability; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; import mage.abilities.keyword.FlyingAbility; +import mage.constants.Duration; +import mage.constants.Outcome; import mage.constants.SubType; import mage.constants.Zone; import mage.game.Game; +import mage.game.events.GameEvent; /** * @@ -17,7 +20,7 @@ import mage.game.Game; public final class TetraviteToken extends TokenImpl { public TetraviteToken() { - super("Tetravite", "1/1 colorless Tetravite artifact creature token"); + super("Tetravite", "1/1 colorless Tetravite artifact creature token with flying and \"This creature can’t be enchanted.\""); cardType.add(CardType.CREATURE); cardType.add(CardType.ARTIFACT); subtype.add(SubType.TETRAVITE); @@ -25,7 +28,7 @@ public final class TetraviteToken extends TokenImpl { toughness = new MageInt(1); this.addAbility(FlyingAbility.getInstance()); - this.addAbility(new CantBeEnchantedAbility()); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new TetraviteTokenEffect())); } public TetraviteToken(final TetraviteToken token) { @@ -37,24 +40,30 @@ public final class TetraviteToken extends TokenImpl { } } -class CantBeEnchantedAbility extends StaticAbility { +class TetraviteTokenEffect extends ContinuousRuleModifyingEffectImpl { - public CantBeEnchantedAbility() { - super(Zone.BATTLEFIELD, null); + public TetraviteTokenEffect() { + super(Duration.WhileOnBattlefield, Outcome.Detriment); + staticText = "this creature can't be enchanted"; } - public CantBeEnchantedAbility(final CantBeEnchantedAbility ability) { - super(ability); + public TetraviteTokenEffect(final TetraviteTokenEffect effect) { + super(effect); } @Override - public CantBeEnchantedAbility copy() { - return new CantBeEnchantedAbility(this); + public TetraviteTokenEffect copy() { + return new TetraviteTokenEffect(this); } - public boolean canTarget(MageObject source, Game game) { - return !(source.isEnchantment() - && source.hasSubtype(SubType.AURA, game)); + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.ATTACH + || event.getType() == GameEvent.EventType.STAY_ATTACHED; } + @Override + public boolean applies(GameEvent event, Ability source, Game game) { + return event.getTargetId().equals(source.getSourceId()); + } }