mirror of
https://github.com/correl/mage.git
synced 2025-04-02 03:18:09 -09:00
Fixed some trap cards and removed old AlternateCostImpl.
This commit is contained in:
parent
9b4ef96eb9
commit
29b37b046d
6 changed files with 271 additions and 181 deletions
Mage.Sets/src/mage/sets/zendikar
Mage.Tests/src/test/java/org/mage/test/cards/single
|
@ -27,18 +27,24 @@
|
|||
*/
|
||||
package mage.sets.zendikar;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import mage.MageObjectReference;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.costs.AlternativeCostImpl;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.abilities.costs.AlternativeCostSourceAbility;
|
||||
import mage.abilities.costs.mana.ManaCostsImpl;
|
||||
import mage.abilities.effects.common.DamageTargetEffect;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Rarity;
|
||||
import mage.constants.WatcherScope;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.target.common.TargetCreaturePermanent;
|
||||
import mage.watchers.Watcher;
|
||||
|
||||
|
@ -54,8 +60,7 @@ public class InfernoTrap extends CardImpl {
|
|||
this.subtype.add("Trap");
|
||||
|
||||
// If you've been dealt damage by two or more creatures this turn, you may pay {R} rather than pay Inferno Trap's mana cost.
|
||||
this.getSpellAbility().addAlternativeCost(new InfernoTrapAlternativeCost());
|
||||
this.getSpellAbility().addWatcher(new ControllerDamagedByCreatureWatcher());
|
||||
this.addAbility(new AlternativeCostSourceAbility(new ManaCostsImpl("{R}"), InfernoTrapCondition.getInstance()), new InfernoTrapWatcher());
|
||||
|
||||
// Inferno Trap deals 4 damage to target creature.
|
||||
this.getSpellAbility().addEffect(new DamageTargetEffect(4));
|
||||
|
@ -72,71 +77,76 @@ public class InfernoTrap extends CardImpl {
|
|||
}
|
||||
}
|
||||
|
||||
class ControllerDamagedByCreatureWatcher extends Watcher {
|
||||
class InfernoTrapCondition implements Condition {
|
||||
|
||||
int numCreaturesDamagedController;
|
||||
private static final InfernoTrapCondition fInstance = new InfernoTrapCondition();
|
||||
|
||||
public ControllerDamagedByCreatureWatcher() {
|
||||
super("ControllerDamagedByCreatureWatcher", WatcherScope.GAME);
|
||||
public static Condition getInstance() {
|
||||
return fInstance;
|
||||
}
|
||||
|
||||
public ControllerDamagedByCreatureWatcher(final ControllerDamagedByCreatureWatcher watcher) {
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
InfernoTrapWatcher watcher = (InfernoTrapWatcher) game.getState().getWatchers().get(InfernoTrapWatcher.class.getName());
|
||||
if (watcher != null) {
|
||||
Set<MageObjectReference> damagingCreatures = watcher.getDamagingCreatures(source.getControllerId());
|
||||
return !damagingCreatures.isEmpty() && damagingCreatures.size() > 1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "If you've been dealt damage by two or more creatures this turn";
|
||||
}
|
||||
}
|
||||
|
||||
class InfernoTrapWatcher extends Watcher {
|
||||
|
||||
Map<UUID, Set<MageObjectReference>> playerDamagedByCreature = new HashMap<>();
|
||||
|
||||
public InfernoTrapWatcher() {
|
||||
super(InfernoTrapWatcher.class.getName(), WatcherScope.GAME);
|
||||
}
|
||||
|
||||
public InfernoTrapWatcher(final InfernoTrapWatcher watcher) {
|
||||
super(watcher);
|
||||
playerDamagedByCreature.putAll(watcher.playerDamagedByCreature);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void watch(GameEvent event, Game game) {
|
||||
if (event.getType() == GameEvent.EventType.DAMAGED_PLAYER
|
||||
&& event.getTargetId().equals(controllerId)) {
|
||||
Card card = game.getCard(event.getSourceId());
|
||||
if (card != null && card.getCardType().contains(CardType.CREATURE)) {
|
||||
numCreaturesDamagedController += 1;
|
||||
if (numCreaturesDamagedController >= 2) {
|
||||
condition = true;
|
||||
Permanent damageBy = game.getPermanentOrLKIBattlefield(event.getSourceId());
|
||||
if (damageBy != null && damageBy.getCardType().contains(CardType.CREATURE)) {
|
||||
Set<MageObjectReference> damagingCreatures;
|
||||
if (playerDamagedByCreature.containsKey(event.getTargetId())) {
|
||||
damagingCreatures = playerDamagedByCreature.get(event.getTargetId());
|
||||
} else {
|
||||
damagingCreatures = new HashSet<>();
|
||||
playerDamagedByCreature.put(event.getTargetId(), damagingCreatures);
|
||||
}
|
||||
MageObjectReference damagingCreature = new MageObjectReference(damageBy, game);
|
||||
if (!damagingCreatures.contains(damagingCreature)) {
|
||||
damagingCreatures.add(damagingCreature);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Set<MageObjectReference> getDamagingCreatures(UUID playerId) {
|
||||
return playerDamagedByCreature.get(playerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
super.reset();
|
||||
numCreaturesDamagedController = 0;
|
||||
playerDamagedByCreature.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ControllerDamagedByCreatureWatcher copy() {
|
||||
return new ControllerDamagedByCreatureWatcher(this);
|
||||
}
|
||||
}
|
||||
|
||||
class InfernoTrapAlternativeCost extends AlternativeCostImpl {
|
||||
|
||||
public InfernoTrapAlternativeCost() {
|
||||
super("you may pay {R} rather than pay Inferno Trap's mana cost");
|
||||
this.add(new ManaCostsImpl("{R}"));
|
||||
}
|
||||
|
||||
public InfernoTrapAlternativeCost(final InfernoTrapAlternativeCost cost) {
|
||||
super(cost);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InfernoTrapAlternativeCost copy() {
|
||||
return new InfernoTrapAlternativeCost(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(Game game, Ability source) {
|
||||
ControllerDamagedByCreatureWatcher watcher = (ControllerDamagedByCreatureWatcher) game.getState().getWatchers().get("ControllerDamagedByCreatureWatcher");
|
||||
if (watcher != null && watcher.conditionMet()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText() {
|
||||
return "If you've been dealt damage by two or more creatures this turn, you may pay {R} rather than pay Inferno Trap's mana cost";
|
||||
public InfernoTrapWatcher copy() {
|
||||
return new InfernoTrapWatcher(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,12 +32,12 @@ import java.util.UUID;
|
|||
import mage.constants.CardType;
|
||||
import mage.constants.Rarity;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.costs.AlternativeCostImpl;
|
||||
import mage.abilities.costs.mana.ColoredManaCost;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.abilities.costs.AlternativeCostSourceAbility;
|
||||
import mage.abilities.costs.mana.ManaCostsImpl;
|
||||
import mage.abilities.effects.common.GainLifeEffect;
|
||||
import mage.abilities.effects.common.LoseLifeTargetEffect;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.constants.ColoredManaSymbol;
|
||||
import mage.game.Game;
|
||||
import mage.target.TargetPlayer;
|
||||
import mage.watchers.common.PlayerGainedLifeWatcher;
|
||||
|
@ -53,11 +53,8 @@ public class NeedlebiteTrap extends CardImpl {
|
|||
this.expansionSetCode = "ZEN";
|
||||
this.subtype.add("Trap");
|
||||
|
||||
|
||||
// If an opponent gained life this turn, you may pay {B} rather than pay Needlebite Trap's mana cost.
|
||||
this.getSpellAbility().addAlternativeCost(
|
||||
new NeedlebiteTrapAlternativeCost());
|
||||
this.getSpellAbility().addWatcher(new PlayerGainedLifeWatcher());
|
||||
this.addAbility(new AlternativeCostSourceAbility(new ManaCostsImpl("{B}"), NeedlebiteTrapCondition.getInstance()), new PlayerGainedLifeWatcher());
|
||||
|
||||
// Target player loses 5 life and you gain 5 life.
|
||||
this.getSpellAbility().addEffect(new LoseLifeTargetEffect(5));
|
||||
|
@ -75,37 +72,29 @@ public class NeedlebiteTrap extends CardImpl {
|
|||
}
|
||||
}
|
||||
|
||||
class NeedlebiteTrapAlternativeCost extends AlternativeCostImpl {
|
||||
class NeedlebiteTrapCondition implements Condition {
|
||||
|
||||
public NeedlebiteTrapAlternativeCost() {
|
||||
super("If an opponent gained life this turn, you may pay {B} rather than pay {this}'s mana cost");
|
||||
this.add(new ColoredManaCost(ColoredManaSymbol.B));
|
||||
}
|
||||
private static final NeedlebiteTrapCondition fInstance = new NeedlebiteTrapCondition();
|
||||
|
||||
public NeedlebiteTrapAlternativeCost(final NeedlebiteTrapAlternativeCost cost) {
|
||||
super(cost);
|
||||
public static Condition getInstance() {
|
||||
return fInstance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NeedlebiteTrapAlternativeCost copy() {
|
||||
return new NeedlebiteTrapAlternativeCost(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(Game game, Ability source) {
|
||||
public boolean apply(Game game, Ability source) {
|
||||
PlayerGainedLifeWatcher watcher = (PlayerGainedLifeWatcher) game.getState().getWatchers().get("PlayerGainedLifeWatcher");
|
||||
if (watcher != null) {
|
||||
for (UUID opponentId: game.getOpponents(source.getControllerId())) {
|
||||
for (UUID opponentId : game.getOpponents(source.getControllerId())) {
|
||||
if (watcher.getLiveGained(opponentId) > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText() {
|
||||
return "If an opponent gained life this turn, you may pay {B} rather than pay {this}'s mana cost";
|
||||
public String toString() {
|
||||
return "If an opponent gained life this turn";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,8 +29,9 @@ package mage.sets.zendikar;
|
|||
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.costs.AlternativeCostImpl;
|
||||
import mage.abilities.costs.mana.GenericManaCost;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.abilities.costs.AlternativeCostSourceAbility;
|
||||
import mage.abilities.costs.mana.ManaCostsImpl;
|
||||
import mage.abilities.effects.common.ExileGraveyardAllTargetPlayerEffect;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.constants.CardType;
|
||||
|
@ -51,9 +52,7 @@ public class RavenousTrap extends CardImpl {
|
|||
this.subtype.add("Trap");
|
||||
|
||||
// If an opponent had three or more cards put into his or her graveyard from anywhere this turn, you may pay {0} rather than pay Ravenous Trap's mana cost.
|
||||
this.getSpellAbility().addAlternativeCost(
|
||||
new RavenousTrapAlternativeCost());
|
||||
this.getSpellAbility().addWatcher(new CardsPutIntoGraveyardWatcher());
|
||||
this.addAbility(new AlternativeCostSourceAbility(new ManaCostsImpl("{0}"), RavenousTrapCondition.getInstance()), new CardsPutIntoGraveyardWatcher());
|
||||
|
||||
// Exile all cards from target player's graveyard.
|
||||
this.getSpellAbility().addEffect(new ExileGraveyardAllTargetPlayerEffect());
|
||||
|
@ -70,24 +69,16 @@ public class RavenousTrap extends CardImpl {
|
|||
}
|
||||
}
|
||||
|
||||
class RavenousTrapAlternativeCost extends AlternativeCostImpl {
|
||||
class RavenousTrapCondition implements Condition {
|
||||
|
||||
public RavenousTrapAlternativeCost() {
|
||||
super("If an opponent had three or more cards put into his or her graveyard from anywhere this turn, you may pay {0} rather than pay Ravenous Trap's mana cost");
|
||||
this.add(new GenericManaCost(0));
|
||||
}
|
||||
private static final RavenousTrapCondition fInstance = new RavenousTrapCondition();
|
||||
|
||||
public RavenousTrapAlternativeCost(final RavenousTrapAlternativeCost cost) {
|
||||
super(cost);
|
||||
public static Condition getInstance() {
|
||||
return fInstance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RavenousTrapAlternativeCost copy() {
|
||||
return new RavenousTrapAlternativeCost(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(Game game, Ability source) {
|
||||
public boolean apply(Game game, Ability source) {
|
||||
CardsPutIntoGraveyardWatcher watcher = (CardsPutIntoGraveyardWatcher) game.getState().getWatchers().get("CardsPutIntoGraveyardWatcher");
|
||||
if (watcher != null) {
|
||||
for (UUID opponentId : game.getOpponents(source.getControllerId())) {
|
||||
|
@ -100,7 +91,7 @@ class RavenousTrapAlternativeCost extends AlternativeCostImpl {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getText() {
|
||||
return "If an opponent had three or more cards put into his or her graveyard from anywhere this turn, you may pay {0} rather than pay {this}'s mana cost";
|
||||
public String toString() {
|
||||
return "If an opponent had three or more cards put into his or her graveyard from anywhere this turn";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,8 +27,12 @@
|
|||
*/
|
||||
package mage.sets.zendikar;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.costs.AlternativeCostImpl;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.abilities.costs.AlternativeCostSourceAbility;
|
||||
import mage.abilities.costs.mana.ManaCostsImpl;
|
||||
import mage.abilities.dynamicvalue.DynamicValue;
|
||||
import mage.abilities.effects.Effect;
|
||||
|
@ -43,9 +47,6 @@ import mage.players.Player;
|
|||
import mage.target.TargetPlayer;
|
||||
import mage.watchers.Watcher;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.abilities.costs.Cost;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jeffwadsworth
|
||||
|
@ -57,10 +58,8 @@ public class RuneflareTrap extends CardImpl {
|
|||
this.expansionSetCode = "ZEN";
|
||||
this.subtype.add("Trap");
|
||||
|
||||
|
||||
// If an opponent drew three or more cards this turn, you may pay {R} rather than pay Runeflare Trap's mana cost.
|
||||
this.getSpellAbility().addAlternativeCost(new RuneflareTrapAlternativeCost());
|
||||
this.getSpellAbility().addWatcher(new CardsDrawnOpponentWatcher());
|
||||
this.addAbility(new AlternativeCostSourceAbility(new ManaCostsImpl("{R}"), RavenousTrapCondition.getInstance()), new CardsDrawnWatcher());
|
||||
|
||||
// Runeflare Trap deals damage to target player equal to the number of cards in that player's hand.
|
||||
this.getSpellAbility().addEffect(new DamageTargetEffect(new TargetPlayerCardsInHandCount()));
|
||||
|
@ -106,26 +105,46 @@ class TargetPlayerCardsInHandCount implements DynamicValue {
|
|||
}
|
||||
}
|
||||
|
||||
class CardsDrawnOpponentWatcher extends Watcher {
|
||||
class RuneflareTrapCondition implements Condition {
|
||||
|
||||
int cardsDrawn;
|
||||
private static final RuneflareTrapCondition fInstance = new RuneflareTrapCondition();
|
||||
|
||||
public CardsDrawnOpponentWatcher() {
|
||||
super("CardsDrawnOpponentWatcher", WatcherScope.GAME);
|
||||
public static Condition getInstance() {
|
||||
return fInstance;
|
||||
}
|
||||
|
||||
public CardsDrawnOpponentWatcher(final CardsDrawnOpponentWatcher watcher) {
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
CardsDrawnWatcher watcher = (CardsDrawnWatcher) game.getState().getWatchers().get("CardsDrawnWatcher");
|
||||
return watcher != null && watcher.opponentDrewXOrMoreCards(source.getControllerId(), 3, game);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "If an opponent drew three or more cards this turn";
|
||||
}
|
||||
}
|
||||
|
||||
class CardsDrawnWatcher extends Watcher {
|
||||
|
||||
private final Map<UUID, Integer> playerCardsDrawn = new HashMap<>();
|
||||
|
||||
public CardsDrawnWatcher() {
|
||||
super("CardsDrawnWatcher", WatcherScope.GAME);
|
||||
}
|
||||
|
||||
public CardsDrawnWatcher(final CardsDrawnWatcher watcher) {
|
||||
super(watcher);
|
||||
this.cardsDrawn = watcher.cardsDrawn;
|
||||
playerCardsDrawn.putAll(watcher.playerCardsDrawn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void watch(GameEvent event, Game game) {
|
||||
if (event.getType() == GameEvent.EventType.DREW_CARD
|
||||
&& game.getOpponents(controllerId).contains(event.getPlayerId())) {
|
||||
cardsDrawn += 1;
|
||||
if (cardsDrawn >= 3) {
|
||||
condition = true;
|
||||
if (event.getType() == GameEvent.EventType.DREW_CARD) {
|
||||
if (playerCardsDrawn.containsKey(event.getPlayerId())) {
|
||||
playerCardsDrawn.put(event.getPlayerId(), playerCardsDrawn.get(event.getPlayerId()) + 1);
|
||||
} else {
|
||||
playerCardsDrawn.put(event.getPlayerId(), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -133,42 +152,25 @@ class CardsDrawnOpponentWatcher extends Watcher {
|
|||
@Override
|
||||
public void reset() {
|
||||
super.reset();
|
||||
cardsDrawn = 0;
|
||||
playerCardsDrawn.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CardsDrawnOpponentWatcher copy() {
|
||||
return new CardsDrawnOpponentWatcher(this);
|
||||
}
|
||||
}
|
||||
|
||||
class RuneflareTrapAlternativeCost extends AlternativeCostImpl<Cost> {
|
||||
|
||||
public RuneflareTrapAlternativeCost() {
|
||||
super("you may pay {R} rather than pay Runeflare Trap's mana cost");
|
||||
this.add(new ManaCostsImpl("{R}"));
|
||||
}
|
||||
|
||||
public RuneflareTrapAlternativeCost(final RuneflareTrapAlternativeCost cost) {
|
||||
super(cost);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RuneflareTrapAlternativeCost copy() {
|
||||
return new RuneflareTrapAlternativeCost(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(Game game, Ability source) {
|
||||
CardsDrawnOpponentWatcher watcher = (CardsDrawnOpponentWatcher) game.getState().getWatchers().get("CardsDrawnOpponentWatcher");
|
||||
if (watcher != null && watcher.conditionMet()) {
|
||||
return true;
|
||||
public boolean opponentDrewXOrMoreCards(UUID playerId, int x, Game game) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
for (Map.Entry<UUID, Integer> entry : playerCardsDrawn.entrySet()) {
|
||||
if (game.isOpponent(player, playerId)) {
|
||||
if (entry.getValue() >= x) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText() {
|
||||
return "If an opponent drew three or more cards this turn, you may pay {R} rather than pay Runeflare Trap's mana cost";
|
||||
public CardsDrawnWatcher copy() {
|
||||
return new CardsDrawnWatcher(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,11 +27,13 @@
|
|||
*/
|
||||
package mage.sets.zendikar;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.costs.AlternativeCostImpl;
|
||||
import mage.abilities.costs.Cost;
|
||||
import mage.abilities.costs.mana.GenericManaCost;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.abilities.costs.AlternativeCostSourceAbility;
|
||||
import mage.abilities.costs.mana.ManaCostsImpl;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.CardImpl;
|
||||
|
@ -64,8 +66,8 @@ public class SummoningTrap extends CardImpl {
|
|||
this.subtype.add("Trap");
|
||||
|
||||
// If a creature spell you cast this turn was countered by a spell or ability an opponent controlled, you may pay {0} rather than pay Summoning Trap's mana cost.
|
||||
this.getSpellAbility().addAlternativeCost(new SummoningTrapAlternativeCost());
|
||||
this.getSpellAbility().addWatcher(new SummoningTrapWatcher());
|
||||
this.addAbility(new AlternativeCostSourceAbility(new ManaCostsImpl("{0}"), SummoningTrapCondition.getInstance()), new SummoningTrapWatcher());
|
||||
|
||||
// Look at the top seven cards of your library. You may put a creature card from among them onto the battlefield. Put the rest on the bottom of your library in any order.
|
||||
this.getSpellAbility().addEffect(new SummoningTrapEffect());
|
||||
}
|
||||
|
@ -80,14 +82,37 @@ public class SummoningTrap extends CardImpl {
|
|||
}
|
||||
}
|
||||
|
||||
class SummoningTrapCondition implements Condition {
|
||||
|
||||
private static final SummoningTrapCondition fInstance = new SummoningTrapCondition();
|
||||
|
||||
public static Condition getInstance() {
|
||||
return fInstance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
SummoningTrapWatcher watcher = (SummoningTrapWatcher) game.getState().getWatchers().get("CardsPutIntoGraveyardWatcher");
|
||||
return watcher != null && watcher.creatureSpellOfPlayerWasCountered(source.getControllerId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "If a creature spell you cast this turn was countered by a spell or ability an opponent controlled";
|
||||
}
|
||||
}
|
||||
|
||||
class SummoningTrapWatcher extends Watcher {
|
||||
|
||||
Set<UUID> players = new HashSet<>();
|
||||
|
||||
public SummoningTrapWatcher() {
|
||||
super("CreatureSpellCountered", WatcherScope.PLAYER);
|
||||
super("CreatureSpellCountered", WatcherScope.GAME);
|
||||
}
|
||||
|
||||
public SummoningTrapWatcher(final SummoningTrapWatcher watcher) {
|
||||
super(watcher);
|
||||
this.players.addAll(watcher.players);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -97,52 +122,34 @@ class SummoningTrapWatcher extends Watcher {
|
|||
|
||||
@Override
|
||||
public void watch(GameEvent event, Game game) {
|
||||
if (condition == true) {// no need to check - condition has already occured
|
||||
return;
|
||||
}
|
||||
if (event.getType() == EventType.COUNTERED) {
|
||||
StackObject stackObject = game.getStack().getStackObject(event.getTargetId());
|
||||
if (stackObject == null) {
|
||||
stackObject = (StackObject) game.getLastKnownInformation(event.getTargetId(), Zone.STACK);
|
||||
}
|
||||
StackObject counterObject = game.getStack().getStackObject(event.getSourceId());
|
||||
if (counterObject == null) {
|
||||
counterObject = (StackObject) game.getLastKnownInformation(event.getSourceId(), Zone.STACK);
|
||||
}
|
||||
if (stackObject != null && counterObject != null
|
||||
&& stackObject.getCardType().contains(CardType.CREATURE)
|
||||
&& game.getOpponents(controllerId).contains(counterObject.getControllerId())) {
|
||||
condition = true;
|
||||
if (stackObject != null
|
||||
&& !players.contains(stackObject.getControllerId())
|
||||
&& stackObject.getCardType().contains(CardType.CREATURE)) {
|
||||
StackObject counterObject = game.getStack().getStackObject(event.getSourceId());
|
||||
if (counterObject == null) {
|
||||
counterObject = (StackObject) game.getLastKnownInformation(event.getSourceId(), Zone.STACK);
|
||||
}
|
||||
if (counterObject != null && game.getOpponents(stackObject.getControllerId()).contains(counterObject.getControllerId())) {
|
||||
players.add(stackObject.getControllerId());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SummoningTrapAlternativeCost extends AlternativeCostImpl<Cost> {
|
||||
|
||||
public SummoningTrapAlternativeCost() {
|
||||
super("you may pay {0} rather than pay Summoning Trap's mana cost");
|
||||
this.add(new GenericManaCost(0));
|
||||
}
|
||||
|
||||
public SummoningTrapAlternativeCost(final SummoningTrapAlternativeCost cost) {
|
||||
super(cost);
|
||||
public boolean creatureSpellOfPlayerWasCountered(UUID playerId) {
|
||||
return players.contains(playerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SummoningTrapAlternativeCost copy() {
|
||||
return new SummoningTrapAlternativeCost(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(Game game, Ability source) {
|
||||
Watcher watcher = game.getState().getWatchers().get("CreatureSpellCountered", source.getControllerId());
|
||||
return watcher != null && watcher.conditionMet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText() {
|
||||
return "If a creature spell you cast this turn was countered by a spell or ability an opponent controlled, you may pay {0} rather than pay Summoning Trap's mana cost";
|
||||
public void reset() {
|
||||
super.reset();
|
||||
players.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* 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 org.mage.test.cards.single;
|
||||
|
||||
import mage.constants.PhaseStep;
|
||||
import mage.constants.Zone;
|
||||
import org.junit.Test;
|
||||
import org.mage.test.serverside.base.CardTestPlayerBase;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class InfernoTrapTest extends CardTestPlayerBase {
|
||||
|
||||
@Test
|
||||
public void testTwoDamageStepsCountOnlyAsOneCreature() {
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 1);
|
||||
// If you've been dealt damage by two or more creatures this turn, you may pay {R} rather than pay Inferno Trap's mana cost.
|
||||
// Inferno Trap deals 4 damage to target creature.
|
||||
addCard(Zone.HAND, playerA, "Inferno Trap"); // Instant {3}{R}
|
||||
|
||||
// Flying, double strike
|
||||
addCard(Zone.BATTLEFIELD, playerB, "Skyhunter Skirmisher"); // 1/1
|
||||
|
||||
attack(2, playerB, "Skyhunter Skirmisher");
|
||||
|
||||
castSpell(2, PhaseStep.POSTCOMBAT_MAIN, playerA, "Inferno Trap", "Skyhunter Skirmisher");
|
||||
|
||||
setStopAt(2, PhaseStep.END_TURN);
|
||||
execute();
|
||||
|
||||
assertLife(playerA, 18);
|
||||
assertLife(playerB, 20);
|
||||
|
||||
assertGraveyardCount(playerA, "Inferno Trap", 0);
|
||||
assertGraveyardCount(playerB, "Skyhunter Skirmisher", 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlayByAlternateCost() {
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 1);
|
||||
// If you've been dealt damage by two or more creatures this turn, you may pay {R} rather than pay Inferno Trap's mana cost.
|
||||
// Inferno Trap deals 4 damage to target creature.
|
||||
addCard(Zone.HAND, playerA, "Inferno Trap"); // Instant {3}{R}
|
||||
|
||||
// Flying, double strike
|
||||
addCard(Zone.BATTLEFIELD, playerB, "Skyhunter Skirmisher"); // 1/1
|
||||
addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion"); // 2/2
|
||||
|
||||
attack(2, playerB, "Skyhunter Skirmisher");
|
||||
attack(2, playerB, "Silvercoat Lion");
|
||||
|
||||
castSpell(2, PhaseStep.POSTCOMBAT_MAIN, playerA, "Inferno Trap", "Skyhunter Skirmisher");
|
||||
|
||||
setStopAt(2, PhaseStep.END_TURN);
|
||||
execute();
|
||||
|
||||
assertLife(playerA, 16);
|
||||
assertLife(playerB, 20);
|
||||
|
||||
assertGraveyardCount(playerA, "Inferno Trap", 1);
|
||||
assertGraveyardCount(playerB, "Skyhunter Skirmisher", 1);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue