Refactor: Flattened Elkin Lair
@@ -35,7 +35,9 @@ public final class ElkinLair extends CardImpl {
super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{3}{R}");
addSuperType(SuperType.WORLD);
- // At the beginning of each player's upkeep, that player exiles a card at random from their hand. The player may play that card this turn. At the beginning of the next end step, if the player hasn't played the card, they put it into their graveyard.
+ // At the beginning of each player's upkeep, that player exiles a card at random from their hand.
+ // The player may play that card this turn.
+ // At the beginning of the next end step, if the player hasn't played the card, they put it into their graveyard.
this.addAbility(new BeginningOfUpkeepTriggeredAbility(new ElkinLairUpkeepEffect(), TargetController.ANY, false));
}
@@ -74,30 +76,34 @@ class ElkinLairUpkeepEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(game.getActivePlayerId());
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
- if (player != null
- && sourcePermanent != null) {
+ if (player == null || sourcePermanent == null) {
+ return false;
+ }
+
Card[] cards = player.getHand().getCards(new FilterCard(), game).toArray(new Card[0]);
- if (cards.length > 0) {
+ if (cards.length == 0) {
+ return false;
+ }
+
Card card = cards[RandomUtil.nextInt(cards.length)];
- if (card != null) {
+ if (card == null) {
+ return false;
+ }
+
String exileName = sourcePermanent.getIdName() + " <this card may be played the turn it was exiled";
player.moveCardsToExile(card, source, game, true, source.getSourceId(), exileName);
- if (game.getState().getZone(card.getId()) == Zone.EXILED) {
+ if (game.getState().getZone(card.getId()) != Zone.EXILED) {
+ return false;
+ }
+
ContinuousEffect effect = new PlayFromNotOwnHandZoneTargetEffect(Zone.EXILED, TargetController.OWNER, Duration.EndOfTurn);
effect.setTargetPointer(new FixedTarget(card, game));
game.addEffect(effect, source);
- DelayedTriggeredAbility delayed
- = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(
- new ElkinLairPutIntoGraveyardEffect());
+ DelayedTriggeredAbility delayed = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new ElkinLairPutIntoGraveyardEffect());
game.addDelayedTriggeredAbility(delayed, source);
return true;
}
}
- }
- }
- return false;
- }
-}
class ElkinLairPutIntoGraveyardEffect extends OneShotEffect {
@@ -113,15 +119,18 @@ class ElkinLairPutIntoGraveyardEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(game.getActivePlayerId());
- if (player != null) {
+ if (player == null) {
+ return false;
+ }
+
Set<Card> cardsInExile = game.getExile().getExileZone(source.getSourceId()).getCards(game);
- if (cardsInExile != null) {
+ if (cardsInExile == null) {
+ return false;
+ }
+
player.moveCardsToGraveyardWithInfo(cardsInExile, source, game, Zone.EXILED);
return true;
}
- }
- return false;
- }
@Override
public ElkinLairPutIntoGraveyardEffect copy() {
