* Wild Evocation - Fixed handling to prevent errors in some cases.

This commit is contained in:
LevelX2 2017-07-23 19:31:59 +02:00
parent ee890418c5
commit c87e992e1d

View file

@ -25,10 +25,10 @@
* authors and should not be interpreted as representing official policies, either expressed * authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.cards.w; package mage.cards.w;
import java.util.UUID; import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.BeginningOfUpkeepTriggeredAbility; import mage.abilities.common.BeginningOfUpkeepTriggeredAbility;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
@ -43,6 +43,7 @@ import mage.constants.TargetController;
import mage.constants.Zone; import mage.constants.Zone;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.util.GameLog;
/** /**
* *
@ -51,8 +52,7 @@ import mage.players.Player;
public class WildEvocation extends CardImpl { public class WildEvocation extends CardImpl {
public WildEvocation(UUID ownerId, CardSetInfo setInfo) { public WildEvocation(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{5}{R}"); super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{5}{R}");
//At the beginning of each player's upkeep, that player reveals a card at random from his or her hand. If it's a land card, the player puts it onto the battlefield. Otherwise, the player casts it without paying its mana cost if able. //At the beginning of each player's upkeep, that player reveals a card at random from his or her hand. If it's a land card, the player puts it onto the battlefield. Otherwise, the player casts it without paying its mana cost if able.
this.addAbility(new BeginningOfUpkeepTriggeredAbility(Zone.BATTLEFIELD, new WildEvocationEffect(), TargetController.ANY, false)); this.addAbility(new BeginningOfUpkeepTriggeredAbility(Zone.BATTLEFIELD, new WildEvocationEffect(), TargetController.ANY, false));
@ -73,7 +73,9 @@ class WildEvocationEffect extends OneShotEffect {
public WildEvocationEffect() { public WildEvocationEffect() {
super(Outcome.PutCardInPlay); super(Outcome.PutCardInPlay);
staticText = "that player reveals a card at random from his or her hand. If it's a land card, that player puts it onto the battlefield. Otherwise, the player casts it without paying its mana cost if able"; staticText = "that player reveals a card at random from his or her hand. "
+ "If it's a land card, that player puts it onto the battlefield. "
+ "Otherwise, the player casts it without paying its mana cost if able";
} }
public WildEvocationEffect(final WildEvocationEffect effect) { public WildEvocationEffect(final WildEvocationEffect effect) {
@ -83,16 +85,21 @@ class WildEvocationEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(targetPointer.getFirst(game, source)); Player player = game.getPlayer(targetPointer.getFirst(game, source));
if (player != null && !player.getHand().isEmpty()) { MageObject sourceObject = source.getSourceObject(game);
if (player != null && sourceObject != null) {
Card card = player.getHand().getRandom(game); Card card = player.getHand().getRandom(game);
if (card != null) {
Cards cards = new CardsImpl(); Cards cards = new CardsImpl();
cards.add(card); cards.add(card);
player.revealCards("Wild Evocation", cards, game); player.revealCards(sourceObject.getIdName() + " Turn: " + game.getTurnNum(), cards, game);
if (card.isLand()) { if (card.isLand()) {
card.putOntoBattlefield(game, Zone.HAND, source.getSourceId(), player.getId()); player.moveCards(card, Zone.BATTLEFIELD, source, game);
} } else if (card.getSpellAbility() != null
else { && card.getSpellAbility().getTargets().canChoose(player.getId(), game)) {
player.cast(card.getSpellAbility(), game, true); player.cast(card.getSpellAbility(), game, true);
} else {
game.informPlayers(GameLog.getColoredObjectName(card) + " can't be cast now by " + player.getLogName());
}
} }
return true; return true;
} }
@ -103,5 +110,4 @@ class WildEvocationEffect extends OneShotEffect {
public WildEvocationEffect copy() { public WildEvocationEffect copy() {
return new WildEvocationEffect(this); return new WildEvocationEffect(this);
} }
} }