Refactor - SkywardEyeProphetsEffect is shared so moved to new RevealTopLandToBattlefieldElseHandEffect

This commit is contained in:
JOAC69 2016-09-24 18:19:10 -05:00
parent 1005fd65f9
commit 8206e29493
3 changed files with 57 additions and 52 deletions

View file

@ -29,21 +29,14 @@ package mage.sets.conflux;
import java.util.UUID; import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.RevealTopLandToBattlefieldElseHandEffect;
import mage.abilities.keyword.VigilanceAbility; import mage.abilities.keyword.VigilanceAbility;
import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardsImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.constants.Zone; import mage.constants.Zone;
import mage.game.Game;
import mage.players.Player;
/** /**
* @author North * @author North
@ -62,7 +55,7 @@ public class SkywardEyeProphets extends CardImpl {
// Vigilance // Vigilance
this.addAbility(VigilanceAbility.getInstance()); this.addAbility(VigilanceAbility.getInstance());
// {tap}: Reveal the top card of your library. If it's a land card, put it onto the battlefield. Otherwise, put it into your hand. // {tap}: Reveal the top card of your library. If it's a land card, put it onto the battlefield. Otherwise, put it into your hand.
this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new SkywardEyeProphetsEffect(), new TapSourceCost())); this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new RevealTopLandToBattlefieldElseHandEffect(), new TapSourceCost()));
} }
public SkywardEyeProphets(final SkywardEyeProphets card) { public SkywardEyeProphets(final SkywardEyeProphets card) {
@ -73,45 +66,4 @@ public class SkywardEyeProphets extends CardImpl {
public SkywardEyeProphets copy() { public SkywardEyeProphets copy() {
return new SkywardEyeProphets(this); return new SkywardEyeProphets(this);
} }
public static class SkywardEyeProphetsEffect extends OneShotEffect {
public SkywardEyeProphetsEffect() {
super(Outcome.DrawCard);
this.staticText = "Reveal the top card of your library. If it's a land card, put it onto the battlefield. Otherwise, put it into your hand";
}
public SkywardEyeProphetsEffect(final SkywardEyeProphetsEffect effect) {
super(effect);
}
@Override
public SkywardEyeProphetsEffect copy() {
return new SkywardEyeProphetsEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (sourceObject == null || controller == null) {
return false;
}
if (controller.getLibrary().size() > 0) {
CardsImpl cards = new CardsImpl();
Card card = controller.getLibrary().getFromTop(game);
if (card == null) {
return false;
}
cards.add(card);
controller.revealCards(sourceObject.getName(), cards, game);
if (card.getCardType().contains(CardType.LAND)) {
return controller.moveCards(card, Zone.BATTLEFIELD, source, game);
} else {
controller.moveCards(card, Zone.HAND, source, game);
}
}
return true;
}
}
} }

View file

@ -30,10 +30,10 @@ package mage.sets.dissension;
import java.util.UUID; import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.EntersBattlefieldTriggeredAbility;
import mage.abilities.effects.common.RevealTopLandToBattlefieldElseHandEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.sets.conflux.SkywardEyeProphets.SkywardEyeProphetsEffect;
/** /**
* @author mluds * @author mluds
@ -51,7 +51,7 @@ public class CoilingOracle extends CardImpl {
this.toughness = new MageInt(1); this.toughness = new MageInt(1);
// When Coiling Oracle enters the battlefield, reveal the top card of your library. If it's a land card, put it onto the battlefield. Otherwise, put that card into your hand. // When Coiling Oracle enters the battlefield, reveal the top card of your library. If it's a land card, put it onto the battlefield. Otherwise, put that card into your hand.
this.addAbility(new EntersBattlefieldTriggeredAbility(new SkywardEyeProphetsEffect())); this.addAbility(new EntersBattlefieldTriggeredAbility(new RevealTopLandToBattlefieldElseHandEffect()));
} }
public CoilingOracle(final CoilingOracle card) { public CoilingOracle(final CoilingOracle card) {

View file

@ -0,0 +1,53 @@
package mage.abilities.effects.common;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.cards.CardsImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.Game;
import mage.players.Player;
public class RevealTopLandToBattlefieldElseHandEffect extends OneShotEffect {
public RevealTopLandToBattlefieldElseHandEffect() {
super(Outcome.DrawCard);
this.staticText = "Reveal the top card of your library. If it's a land card, put it onto the battlefield. Otherwise, put it into your hand";
}
public RevealTopLandToBattlefieldElseHandEffect(final RevealTopLandToBattlefieldElseHandEffect effect) {
super(effect);
}
@Override
public RevealTopLandToBattlefieldElseHandEffect copy() {
return new RevealTopLandToBattlefieldElseHandEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (sourceObject == null || controller == null) {
return false;
}
if (controller.getLibrary().size() > 0) {
CardsImpl cards = new CardsImpl();
Card card = controller.getLibrary().getFromTop(game);
if (card == null) {
return false;
}
cards.add(card);
controller.revealCards(sourceObject.getName(), cards, game);
if (card.getCardType().contains(CardType.LAND)) {
return controller.moveCards(card, Zone.BATTLEFIELD, source, game);
} else {
controller.moveCards(card, Zone.HAND, source, game);
}
}
return true;
}
}