From d818fadf52ff2e4e4df2142d0eb98a48e8cddb86 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sat, 12 Mar 2016 11:59:30 +0100 Subject: [PATCH] * Instill Energy - Fixed that the untap enchanted creature ability did not work. --- .../mage/sets/antiquities/GateToPhyrexia.java | 38 +----- .../championsofkamigawa/BrutalDeceiver.java | 57 +++++---- .../mage/sets/fifthedition/InstillEnergy.java | 110 +----------------- .../sets/masterseditionii/EbonPraetor.java | 44 ++----- .../LimitedTimesPerTurnActivatedAbility.java | 39 ++++--- 5 files changed, 67 insertions(+), 221 deletions(-) diff --git a/Mage.Sets/src/mage/sets/antiquities/GateToPhyrexia.java b/Mage.Sets/src/mage/sets/antiquities/GateToPhyrexia.java index 4d902ed4b3..889fdb890f 100644 --- a/Mage.Sets/src/mage/sets/antiquities/GateToPhyrexia.java +++ b/Mage.Sets/src/mage/sets/antiquities/GateToPhyrexia.java @@ -30,16 +30,15 @@ package mage.sets.antiquities; import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.LimitedTimesPerTurnActivatedAbility; -import mage.abilities.costs.Cost; +import mage.abilities.condition.common.IsStepCondition; import mage.abilities.costs.common.SacrificeTargetCost; -import mage.abilities.effects.Effect; import mage.abilities.effects.common.DestroyTargetEffect; import mage.cards.CardImpl; import mage.constants.CardType; import mage.constants.PhaseStep; import mage.constants.Rarity; import mage.constants.Zone; -import mage.game.Game; +import mage.filter.common.FilterControlledCreaturePermanent; import mage.target.common.TargetArtifactPermanent; import mage.target.common.TargetControlledCreaturePermanent; @@ -54,7 +53,9 @@ public class GateToPhyrexia extends CardImpl { this.expansionSetCode = "ATQ"; // Sacrifice a creature: Destroy target artifact. Activate this ability only during your upkeep and only once each turn. - Ability ability = new GateToPhyrexiaAbility(new DestroyTargetEffect(), new SacrificeTargetCost(new TargetControlledCreaturePermanent())); + Ability ability = new LimitedTimesPerTurnActivatedAbility(Zone.BATTLEFIELD, new DestroyTargetEffect(), + new SacrificeTargetCost(new TargetControlledCreaturePermanent(new FilterControlledCreaturePermanent("a creature"))), + 1, new IsStepCondition(PhaseStep.UPKEEP, true)); ability.addTarget(new TargetArtifactPermanent()); this.addAbility(ability); } @@ -68,32 +69,3 @@ public class GateToPhyrexia extends CardImpl { return new GateToPhyrexia(this); } } - -class GateToPhyrexiaAbility extends LimitedTimesPerTurnActivatedAbility { - - public GateToPhyrexiaAbility(Effect effect, Cost cost) { - super(Zone.BATTLEFIELD, effect, cost); - } - - public GateToPhyrexiaAbility(final GateToPhyrexiaAbility ability) { - super(ability); - } - - @Override - public GateToPhyrexiaAbility copy() { - return new GateToPhyrexiaAbility(this); - } - - @Override - public boolean canActivate(UUID playerId, Game game) { - if (!game.getActivePlayerId().equals(controllerId) || !PhaseStep.UPKEEP.equals(game.getStep().getType())) { - return false; - } - return super.canActivate(playerId, game); - } - - @Override - public String getRule() { - return "Sacrifice a creature: Destroy target artifact. Activate this ability only during your upkeep and only once each turn."; - } -} diff --git a/Mage.Sets/src/mage/sets/championsofkamigawa/BrutalDeceiver.java b/Mage.Sets/src/mage/sets/championsofkamigawa/BrutalDeceiver.java index 831aefa388..b767e0d80b 100644 --- a/Mage.Sets/src/mage/sets/championsofkamigawa/BrutalDeceiver.java +++ b/Mage.Sets/src/mage/sets/championsofkamigawa/BrutalDeceiver.java @@ -28,17 +28,12 @@ package mage.sets.championsofkamigawa; import java.util.UUID; - -import mage.constants.CardType; -import mage.constants.Duration; -import mage.constants.Rarity; -import mage.constants.Zone; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.LimitedTimesPerTurnActivatedAbility; -import mage.abilities.costs.mana.GenericManaCost; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.Cost; +import mage.abilities.costs.mana.GenericManaCost; import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.effects.Effect; import mage.abilities.effects.common.LookLibraryControllerEffect; @@ -49,6 +44,10 @@ import mage.cards.Card; import mage.cards.CardImpl; import mage.cards.Cards; import mage.cards.CardsImpl; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.Rarity; +import mage.constants.Zone; import mage.game.Game; import mage.players.Player; @@ -67,11 +66,11 @@ public class BrutalDeceiver extends CardImpl { this.toughness = new MageInt(2); // {1}: Look at the top card of your library. - this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new LookLibraryControllerEffect(), new GenericManaCost(1))); + this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new LookLibraryControllerEffect(), new GenericManaCost(1))); // {2}: Reveal the top card of your library. If it's a land card, {this} gets +1/+0 and gains first strike until end of turn. - Ability ability = new BrutalDeceiverAbility(Zone.BATTLEFIELD, new BoostSourceEffect(1,0,Duration.EndOfTurn), new ManaCostsImpl("{2}")); - ability.addEffect(new GainAbilitySourceEffect(FirstStrikeAbility.getInstance(),Duration.EndOfTurn)); + Ability ability = new BrutalDeceiverAbility(Zone.BATTLEFIELD, new BoostSourceEffect(1, 0, Duration.EndOfTurn), new ManaCostsImpl("{2}")); + ability.addEffect(new GainAbilitySourceEffect(FirstStrikeAbility.getInstance(), Duration.EndOfTurn)); this.addAbility(ability); } @@ -87,36 +86,36 @@ public class BrutalDeceiver extends CardImpl { class BrutalDeceiverAbility extends LimitedTimesPerTurnActivatedAbility { - public BrutalDeceiverAbility(Zone zone, Effect effect, Cost cost) { + public BrutalDeceiverAbility(Zone zone, Effect effect, Cost cost) { super(zone, effect, cost); } - public BrutalDeceiverAbility(BrutalDeceiverAbility ability) { + public BrutalDeceiverAbility(BrutalDeceiverAbility ability) { super(ability); } - @Override - public BrutalDeceiverAbility copy() { - return new BrutalDeceiverAbility(this); - } + @Override + public BrutalDeceiverAbility copy() { + return new BrutalDeceiverAbility(this); + } - @Override + @Override public boolean checkIfClause(Game game) { - Player player = game.getPlayer(this.getControllerId()); - if (player != null) { - Cards cards = new CardsImpl(); - Card card = player.getLibrary().getFromTop(game); - cards.add(card); - player.revealCards("Brutal Deceiver", cards, game); - if (card != null && card.getCardType().contains(CardType.LAND)) { - return true; - } - } - return false; + Player player = game.getPlayer(this.getControllerId()); + if (player != null) { + Cards cards = new CardsImpl(); + Card card = player.getLibrary().getFromTop(game); + cards.add(card); + player.revealCards("Brutal Deceiver", cards, game); + if (card != null && card.getCardType().contains(CardType.LAND)) { + return true; + } } + return false; + } - @Override + @Override public String getRule() { - return "{2}: Reveal the top card of your library. If it's a land card, {this} gets +1/+0 and gains first strike until end of turn. Activate this ability only once each turn."; + return "{2}: Reveal the top card of your library. If it's a land card, {this} gets +1/+0 and gains first strike until end of turn. Activate this ability only once each turn."; } } diff --git a/Mage.Sets/src/mage/sets/fifthedition/InstillEnergy.java b/Mage.Sets/src/mage/sets/fifthedition/InstillEnergy.java index 9c0b869103..835cee02a7 100644 --- a/Mage.Sets/src/mage/sets/fifthedition/InstillEnergy.java +++ b/Mage.Sets/src/mage/sets/fifthedition/InstillEnergy.java @@ -29,14 +29,11 @@ package mage.sets.fifthedition; import java.util.UUID; import mage.abilities.Ability; -import mage.abilities.common.ActivateIfConditionActivatedAbility; +import mage.abilities.common.LimitedTimesPerTurnActivatedAbility; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.condition.Condition; import mage.abilities.condition.common.MyTurnCondition; -import mage.abilities.costs.Cost; import mage.abilities.costs.mana.GenericManaCost; import mage.abilities.effects.AsThoughEffectImpl; -import mage.abilities.effects.Effect; import mage.abilities.effects.common.AttachEffect; import mage.abilities.effects.common.UntapEnchantedEffect; import mage.abilities.effects.common.continuous.GainAbilityAttachedEffect; @@ -53,7 +50,6 @@ import mage.game.Game; import mage.game.permanent.Permanent; import mage.target.TargetPermanent; import mage.target.common.TargetCreaturePermanent; -import mage.util.CardUtil; /** * @@ -77,8 +73,7 @@ public class InstillEnergy extends CardImpl { Ability haste = new SimpleStaticAbility(Zone.BATTLEFIELD, new GainAbilityAttachedEffect(asThough, AttachmentType.AURA, Duration.WhileOnBattlefield, "Enchanted creature can attack as though it had haste.")); this.addAbility(haste); // {0}: Untap enchanted creature. Activate this ability only during your turn and only once each turn. - Ability gainedAbility = new LimitedTimesIfConditionActivatedAbility(Zone.BATTLEFIELD, new UntapEnchantedEffect(), new GenericManaCost(0), MyTurnCondition.getInstance(), 1); - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new GainAbilityAttachedEffect(gainedAbility, AttachmentType.AURA, Duration.WhileOnBattlefield, "{0}: Untap enchanted creature. Activate this ability only during your turn and only once each turn."))); + this.addAbility(new LimitedTimesPerTurnActivatedAbility(Zone.BATTLEFIELD, new UntapEnchantedEffect(), new GenericManaCost(0), 1, MyTurnCondition.getInstance())); } public InstillEnergy(final InstillEnergy card) { @@ -118,104 +113,3 @@ class CanAttackAsThoughItHadHasteEnchantedEffect extends AsThoughEffectImpl { return enchantment != null && enchantment.getAttachedTo() != null && enchantment.getAttachedTo().equals(objectId); } } - -class LimitedTimesIfConditionActivatedAbility extends ActivateIfConditionActivatedAbility { - - class ActivationInfo { - - public int turnNum; - public int activationCounter; - - public ActivationInfo(int turnNum, int activationCounter) { - this.turnNum = turnNum; - this.activationCounter = activationCounter; - } - } - - private int maxActivationsPerTurn; - - public LimitedTimesIfConditionActivatedAbility(Zone zone, Effect effect, Cost cost, Condition condition) { - this(zone, effect, cost, condition, 1); - } - - public LimitedTimesIfConditionActivatedAbility(Zone zone, Effect effect, Cost cost, Condition condition, int maxActivationsPerTurn) { - super(zone, effect, cost, condition); - this.maxActivationsPerTurn = maxActivationsPerTurn; - } - - public LimitedTimesIfConditionActivatedAbility(LimitedTimesIfConditionActivatedAbility ability) { - super(ability); - this.maxActivationsPerTurn = ability.maxActivationsPerTurn; - } - - @Override - public boolean canActivate(UUID playerId, Game game) { - if (super.canActivate(playerId, game)) { - ActivationInfo activationInfo = getActivationInfo(game); - return activationInfo == null || activationInfo.turnNum != game.getTurnNum() || activationInfo.activationCounter < maxActivationsPerTurn; - } - return false; - } - - @Override - public boolean activate(Game game, boolean noMana) { - if (canActivate(this.controllerId, game)) { - if (super.activate(game, noMana)) { - ActivationInfo activationInfo = getActivationInfo(game); - if (activationInfo == null) { - activationInfo = new ActivationInfo(game.getTurnNum(), 1); - } else if (activationInfo.turnNum != game.getTurnNum()) { - activationInfo.turnNum = game.getTurnNum(); - activationInfo.activationCounter = 1; - } else { - activationInfo.activationCounter++; - } - setActivationInfo(activationInfo, game); - return true; - } - } - return false; - } - - @Override - public boolean resolve(Game game) { - return super.resolve(game); - } - - @Override - public String getRule() { - StringBuilder sb = new StringBuilder(super.getRule()); - sb.replace(sb.length() - 1, sb.length() - 1, " and "); //suppress super()'s final period - switch (maxActivationsPerTurn) { - case 1: - sb.append("only once"); - break; - case 2: - sb.append("no more than twice"); - break; - default: - sb.append("no more than ").append(CardUtil.numberToText(maxActivationsPerTurn)).append(" times"); - } - sb.append(" each turn."); - return sb.toString(); - } - - @Override - public LimitedTimesIfConditionActivatedAbility copy() { - return new LimitedTimesIfConditionActivatedAbility(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); - } -} diff --git a/Mage.Sets/src/mage/sets/masterseditionii/EbonPraetor.java b/Mage.Sets/src/mage/sets/masterseditionii/EbonPraetor.java index 9b7905996e..04ed4d15c0 100644 --- a/Mage.Sets/src/mage/sets/masterseditionii/EbonPraetor.java +++ b/Mage.Sets/src/mage/sets/masterseditionii/EbonPraetor.java @@ -32,9 +32,9 @@ import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.BeginningOfUpkeepTriggeredAbility; import mage.abilities.common.LimitedTimesPerTurnActivatedAbility; +import mage.abilities.condition.common.IsStepCondition; import mage.abilities.costs.Cost; import mage.abilities.costs.common.SacrificeTargetCost; -import mage.abilities.effects.Effect; import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.counter.AddCountersSourceEffect; import mage.abilities.effects.common.counter.RemoveCounterSourceEffect; @@ -48,6 +48,7 @@ import mage.constants.Rarity; import mage.constants.TargetController; import mage.constants.Zone; import mage.counters.CounterType; +import mage.filter.common.FilterControlledCreaturePermanent; import mage.game.Game; import mage.game.permanent.Permanent; import mage.target.common.TargetControlledCreaturePermanent; @@ -68,16 +69,16 @@ public class EbonPraetor extends CardImpl { // First strike this.addAbility(FirstStrikeAbility.getInstance()); - + // Trample this.addAbility(TrampleAbility.getInstance()); - + // At the beginning of your upkeep, put a -2/-2 counter on Ebon Praetor. this.addAbility(new BeginningOfUpkeepTriggeredAbility(new AddCountersSourceEffect(CounterType.M2M2.createInstance()), TargetController.YOU, false)); - + // Sacrifice a creature: Remove a -2/-2 counter from Ebon Praetor. If the sacrificed creature was a Thrull, put a +1/+0 counter on Ebon Praetor. Activate this ability only during your upkeep and only once each turn. - Ability ability = new EbonPraetorAbility(new RemoveCounterSourceEffect(CounterType.M2M2.createInstance()), - new SacrificeTargetCost(new TargetControlledCreaturePermanent())); + Ability ability = new LimitedTimesPerTurnActivatedAbility(Zone.BATTLEFIELD, new RemoveCounterSourceEffect(CounterType.M2M2.createInstance()), + new SacrificeTargetCost(new TargetControlledCreaturePermanent(new FilterControlledCreaturePermanent("a creature"))), 1, new IsStepCondition(PhaseStep.UPKEEP, true)); ability.addEffect(new EbonPraetorEffect()); this.addAbility(ability); } @@ -92,37 +93,6 @@ public class EbonPraetor extends CardImpl { } } -class EbonPraetorAbility extends LimitedTimesPerTurnActivatedAbility { - - public EbonPraetorAbility(Effect effect, Cost cost) { - super(Zone.BATTLEFIELD, effect, cost); - } - - public EbonPraetorAbility(final EbonPraetorAbility ability) { - super(ability); - } - - @Override - public EbonPraetorAbility copy() { - return new EbonPraetorAbility(this); - } - - @Override - public boolean canActivate(UUID playerId, Game game) { - if (!game.getActivePlayerId().equals(controllerId) || !PhaseStep.UPKEEP.equals(game.getStep().getType())) { - return false; - } - return super.canActivate(playerId, game); - } - - @Override - public String getRule() { - StringBuilder sb = new StringBuilder(""); - sb.append(super.getRule()).append(" Activate this ability only during your upkeep."); - return sb.toString(); - } -} - class EbonPraetorEffect extends OneShotEffect { public EbonPraetorEffect() { diff --git a/Mage/src/main/java/mage/abilities/common/LimitedTimesPerTurnActivatedAbility.java b/Mage/src/main/java/mage/abilities/common/LimitedTimesPerTurnActivatedAbility.java index a415bb19a1..1d11c10c13 100644 --- a/Mage/src/main/java/mage/abilities/common/LimitedTimesPerTurnActivatedAbility.java +++ b/Mage/src/main/java/mage/abilities/common/LimitedTimesPerTurnActivatedAbility.java @@ -24,12 +24,12 @@ * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of BetaSteward_at_googlemail.com. -*/ - + */ package mage.abilities.common; import java.util.UUID; import mage.abilities.ActivatedAbilityImpl; +import mage.abilities.condition.Condition; import mage.abilities.costs.Cost; import mage.abilities.effects.Effect; import mage.constants.Zone; @@ -54,24 +54,33 @@ public class LimitedTimesPerTurnActivatedAbility extends ActivatedAbilityImpl { } private int maxActivationsPerTurn; + private Condition condition; public LimitedTimesPerTurnActivatedAbility(Zone zone, Effect effect, Cost cost) { this(zone, effect, cost, 1); } public LimitedTimesPerTurnActivatedAbility(Zone zone, Effect effect, Cost cost, int maxActivationsPerTurn) { - super(zone, effect, cost); - this.maxActivationsPerTurn = maxActivationsPerTurn; + this(zone, effect, cost, maxActivationsPerTurn, null); } - public LimitedTimesPerTurnActivatedAbility(LimitedTimesPerTurnActivatedAbility ability) { + public LimitedTimesPerTurnActivatedAbility(Zone zone, Effect effect, Cost cost, int maxActivationsPerTurn, Condition condition) { + super(zone, effect, cost); + this.maxActivationsPerTurn = maxActivationsPerTurn; + this.condition = condition; + } + + public LimitedTimesPerTurnActivatedAbility(final LimitedTimesPerTurnActivatedAbility ability) { super(ability); this.maxActivationsPerTurn = ability.maxActivationsPerTurn; + this.condition = ability.condition; } @Override public boolean canActivate(UUID playerId, Game game) { - return super.canActivate(playerId, game) && hasMoreActivationsThisTurn(game); + return super.canActivate(playerId, game) + && hasMoreActivationsThisTurn(game) + && (condition == null || condition.apply(game, this)); } private boolean hasMoreActivationsThisTurn(Game game) { @@ -86,13 +95,11 @@ public class LimitedTimesPerTurnActivatedAbility extends ActivatedAbilityImpl { ActivationInfo activationInfo = getActivationInfo(game); if (activationInfo == null) { activationInfo = new ActivationInfo(game.getTurnNum(), 1); + } else if (activationInfo.turnNum != game.getTurnNum()) { + activationInfo.turnNum = game.getTurnNum(); + activationInfo.activationCounter = 1; } else { - if (activationInfo.turnNum != game.getTurnNum()) { - activationInfo.turnNum = game.getTurnNum(); - activationInfo.activationCounter = 1; - } else { - activationInfo.activationCounter++; - } + activationInfo.activationCounter++; } setActivationInfo(activationInfo, game); return true; @@ -109,7 +116,10 @@ public class LimitedTimesPerTurnActivatedAbility extends ActivatedAbilityImpl { @Override public String getRule() { StringBuilder sb = new StringBuilder(super.getRule()).append(" Activate this ability "); - switch(maxActivationsPerTurn) { + if (condition != null) { + sb.append("only ").append(condition.toString()).append(" and "); + } + switch (maxActivationsPerTurn) { case 1: sb.append("only once"); break; @@ -127,6 +137,7 @@ 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)); @@ -135,7 +146,7 @@ public class LimitedTimesPerTurnActivatedAbility extends ActivatedAbilityImpl { } 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);