* Runeflare Trap - Fix alternative cost condition (fixes #1943).

This commit is contained in:
Quercitron 2016-05-20 03:25:03 +03:00
parent eea532b2a5
commit f815148424
4 changed files with 123 additions and 157 deletions

View file

@ -27,9 +27,6 @@
*/
package mage.sets.journeyintonyx;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.TriggeredAbilityImpl;
@ -47,7 +44,6 @@ import mage.cards.CardsImpl;
import mage.constants.CardType;
import mage.constants.ColoredManaSymbol;
import mage.constants.Rarity;
import mage.constants.WatcherScope;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
@ -55,7 +51,7 @@ import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.common.TargetCreatureOrPlayer;
import mage.watchers.Watcher;
import mage.watchers.common.CardsAmountDrawnThisTurnWatcher;
/**
*
@ -83,7 +79,7 @@ public class KeranosGodOfStorms extends CardImpl {
// Reveal the first card you draw on each of your turns.
// Whenever you reveal a land card this way, draw a card.
// Whenever you reveal a nonland card this way, Keranos deals 3 damage to target creature or player.
this.addAbility(new KeranosGodOfStormsTriggeredAbility(), new CardsDrawnDuringTurnWatcher());
this.addAbility(new KeranosGodOfStormsTriggeredAbility(), new CardsAmountDrawnThisTurnWatcher());
}
@ -122,7 +118,8 @@ class KeranosGodOfStormsTriggeredAbility extends TriggeredAbilityImpl {
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getPlayerId().equals(this.getControllerId())) {
if (game.getActivePlayerId().equals(this.getControllerId())) {
CardsDrawnDuringTurnWatcher watcher = (CardsDrawnDuringTurnWatcher) game.getState().getWatchers().get("CardsDrawnDuringTurn");
CardsAmountDrawnThisTurnWatcher watcher =
(CardsAmountDrawnThisTurnWatcher) game.getState().getWatchers().get(CardsAmountDrawnThisTurnWatcher.BASIC_KEY);
if (watcher != null && watcher.getAmountCardsDrawn(event.getPlayerId()) != 1) {
return false;
}
@ -148,56 +145,7 @@ class KeranosGodOfStormsTriggeredAbility extends TriggeredAbilityImpl {
@Override
public String getRule() {
return "Reveal the first card you draw on each of your turns. Whenever you reveal a land card this way, draw a card. Whenever you reveal a nonland card this way, Keranos deals 3 damage to target creature or player.";
return "Reveal the first card you draw on each of your turns. Whenever you reveal a land card this way, draw a card. " +
"Whenever you reveal a nonland card this way, Keranos deals 3 damage to target creature or player.";
}
}
class CardsDrawnDuringTurnWatcher extends Watcher {
private final Map<UUID, Integer> amountOfCardsDrawnThisTurn = new HashMap<>();
public CardsDrawnDuringTurnWatcher() {
super("CardsDrawnDuringTurn", WatcherScope.GAME);
}
public CardsDrawnDuringTurnWatcher(final CardsDrawnDuringTurnWatcher watcher) {
super(watcher);
for (Entry<UUID, Integer> entry : watcher.amountOfCardsDrawnThisTurn.entrySet()) {
amountOfCardsDrawnThisTurn.put(entry.getKey(), entry.getValue());
}
}
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.DREW_CARD) {
UUID playerId = event.getPlayerId();
if (playerId != null) {
Integer amount = amountOfCardsDrawnThisTurn.get(playerId);
if (amount == null) {
amount = 1;
} else {
amount++;
}
amountOfCardsDrawnThisTurn.put(playerId, amount);
}
}
}
public int getAmountCardsDrawn(UUID playerId) {
Integer amount = amountOfCardsDrawnThisTurn.get(playerId);
if (amount != null) {
return amount;
}
return 0;
}
@Override
public void reset() {
amountOfCardsDrawnThisTurn.clear();
}
@Override
public CardsDrawnDuringTurnWatcher copy() {
return new CardsDrawnDuringTurnWatcher(this);
}
}

View file

@ -41,7 +41,7 @@ import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.common.TargetCardInLibrary;
import mage.watchers.Watcher;
import mage.watchers.common.CardsAmountDrawnThisTurnWatcher;
import java.util.UUID;
@ -57,9 +57,10 @@ public class ArchmageAscension extends CardImpl {
// At the beginning of each end step, if you drew two or more cards this turn, you may put a quest counter on Archmage Ascension.
this.addAbility(new ArchmageAscensionTriggeredAbility(), new CardsDrawnControllerWatcher());
this.addAbility(new ArchmageAscensionTriggeredAbility(), new CardsAmountDrawnThisTurnWatcher());
// As long as Archmage Ascension has six or more quest counters on it, if you would draw a card, you may instead search your library for a card, put that card into your hand, then shuffle your library.
// As long as Archmage Ascension has six or more quest counters on it, if you would draw a card,
// you may instead search your library for a card, put that card into your hand, then shuffle your library.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new ArchmageAscensionReplacementEffect()));
}
@ -97,8 +98,9 @@ class ArchmageAscensionTriggeredAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Permanent archmage = game.getPermanent(super.getSourceId());
CardsDrawnControllerWatcher watcher = (CardsDrawnControllerWatcher) game.getState().getWatchers().get("CardsControllerDrawn");
return archmage != null && watcher != null && watcher.conditionMet();
CardsAmountDrawnThisTurnWatcher watcher =
(CardsAmountDrawnThisTurnWatcher) game.getState().getWatchers().get(CardsAmountDrawnThisTurnWatcher.BASIC_KEY);
return archmage != null && watcher != null && watcher.getAmountCardsDrawn(this.getControllerId()) >= 2;
}
@Override
@ -107,47 +109,12 @@ class ArchmageAscensionTriggeredAbility extends TriggeredAbilityImpl {
}
}
class CardsDrawnControllerWatcher extends Watcher {
int cardsDrawn;
public CardsDrawnControllerWatcher() {
super("CardsControllerDrawn", WatcherScope.GAME);
}
public CardsDrawnControllerWatcher(final CardsDrawnControllerWatcher watcher) {
super(watcher);
this.cardsDrawn = watcher.cardsDrawn;
}
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.DREW_CARD
&& event.getPlayerId().equals(controllerId)) {
cardsDrawn += 1;
if (cardsDrawn >= 2) {
condition = true;
}
}
}
@Override
public void reset() {
super.reset();
cardsDrawn = 0;
}
@Override
public CardsDrawnControllerWatcher copy() {
return new CardsDrawnControllerWatcher(this);
}
}
class ArchmageAscensionReplacementEffect extends ReplacementEffectImpl {
public ArchmageAscensionReplacementEffect() {
super(Duration.WhileOnBattlefield, Outcome.Benefit);
staticText = "As long as {this} has six or more quest counters on it, if you would draw a card, you may instead search your library for a card, put that card into your hand, then shuffle your library";
staticText = "As long as {this} has six or more quest counters on it, if you would draw a card, " +
"you may instead search your library for a card, put that card into your hand, then shuffle your library";
}
public ArchmageAscensionReplacementEffect(final ArchmageAscensionReplacementEffect effect) {

View file

@ -27,8 +27,6 @@
*/
package mage.sets.zendikar;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.condition.Condition;
@ -40,12 +38,10 @@ import mage.abilities.effects.common.DamageTargetEffect;
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.players.Player;
import mage.target.TargetPlayer;
import mage.watchers.Watcher;
import mage.watchers.common.CardsAmountDrawnThisTurnWatcher;
/**
*
@ -59,7 +55,7 @@ public class RuneflareTrap extends CardImpl {
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.addAbility(new AlternativeCostSourceAbility(new ManaCostsImpl("{R}"), RavenousTrapCondition.getInstance()), new CardsDrawnWatcher());
this.addAbility(new AlternativeCostSourceAbility(new ManaCostsImpl("{R}"), RuneflareTrapCondition.getInstance()), new CardsAmountDrawnThisTurnWatcher());
// 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()));
@ -115,7 +111,8 @@ class RuneflareTrapCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
CardsDrawnWatcher watcher = (CardsDrawnWatcher) game.getState().getWatchers().get("CardsDrawnWatcher");
CardsAmountDrawnThisTurnWatcher watcher =
(CardsAmountDrawnThisTurnWatcher) game.getState().getWatchers().get(CardsAmountDrawnThisTurnWatcher.BASIC_KEY);
return watcher != null && watcher.opponentDrewXOrMoreCards(source.getControllerId(), 3, game);
}
@ -124,53 +121,3 @@ class RuneflareTrapCondition implements Condition {
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);
playerCardsDrawn.putAll(watcher.playerCardsDrawn);
}
@Override
public void watch(GameEvent event, Game game) {
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);
}
}
}
@Override
public void reset() {
super.reset();
playerCardsDrawn.clear();
}
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 CardsDrawnWatcher copy() {
return new CardsDrawnWatcher(this);
}
}

View file

@ -0,0 +1,104 @@
/*
* 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 mage.watchers.common;
import mage.constants.WatcherScope;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.players.Player;
import mage.watchers.Watcher;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/**
*
* @author Quercitron
* @author LevelX2
* @author jeffwadsworth
*/
public class CardsAmountDrawnThisTurnWatcher extends Watcher {
public final static String BASIC_KEY = "CardsAmountDrawnThisTurnWatcher";
private final Map<UUID, Integer> amountOfCardsDrawnThisTurn = new HashMap<>();
public CardsAmountDrawnThisTurnWatcher() {
super(BASIC_KEY, WatcherScope.GAME);
}
public CardsAmountDrawnThisTurnWatcher(final CardsAmountDrawnThisTurnWatcher watcher) {
super(watcher);
amountOfCardsDrawnThisTurn.putAll(watcher.amountOfCardsDrawnThisTurn);
}
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.DREW_CARD) {
if (amountOfCardsDrawnThisTurn.containsKey(event.getPlayerId())) {
amountOfCardsDrawnThisTurn.put(event.getPlayerId(), amountOfCardsDrawnThisTurn.get(event.getPlayerId()) + 1);
} else {
amountOfCardsDrawnThisTurn.put(event.getPlayerId(), 1);
}
}
}
@Override
public void reset() {
super.reset();
amountOfCardsDrawnThisTurn.clear();
}
public boolean opponentDrewXOrMoreCards(UUID playerId, int x, Game game) {
Player player = game.getPlayer(playerId);
if (player != null) {
for (Map.Entry<UUID, Integer> entry : amountOfCardsDrawnThisTurn.entrySet()) {
if (game.isOpponent(player, entry.getKey())) {
if (entry.getValue() >= x) {
return true;
}
}
}
}
return false;
}
public int getAmountCardsDrawn(UUID playerId) {
Integer amount = amountOfCardsDrawnThisTurn.get(playerId);
if (amount != null) {
return amount;
}
return 0;
}
@Override
public CardsAmountDrawnThisTurnWatcher copy() {
return new CardsAmountDrawnThisTurnWatcher(this);
}
}