Replace more custom effects with PutPermanentOnBattlefieldEffect

This commit is contained in:
LoneFox 2015-08-05 11:51:56 +03:00
parent 94b9790bb0
commit 56ee85e11f
3 changed files with 24 additions and 189 deletions

View file

@ -34,12 +34,11 @@ import mage.abilities.LoyaltyAbility;
import mage.abilities.common.EntersBattlefieldAbility;
import mage.abilities.common.SpellCastControllerTriggeredAbility;
import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.GetEmblemEffect;
import mage.abilities.effects.common.PutPermanentOnBattlefieldEffect;
import mage.abilities.effects.common.RevealLibraryPutIntoHandEffect;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.abilities.effects.common.search.SearchLibraryPutInPlayEffect;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
@ -50,11 +49,7 @@ import mage.filter.FilterSpell;
import mage.filter.common.FilterCreatureCard;
import mage.filter.predicate.mageobject.CardTypePredicate;
import mage.filter.predicate.mageobject.ColorPredicate;
import mage.game.Game;
import mage.game.command.Emblem;
import mage.players.Player;
import mage.target.Target;
import mage.target.common.TargetCardInHand;
import mage.target.common.TargetCardInLibrary;
/**
@ -63,7 +58,8 @@ import mage.target.common.TargetCardInLibrary;
*/
public class GarrukCallerOfBeasts extends CardImpl {
private static final FilterCreatureCard filterGreenCreature = new FilterCreatureCard("a green creature card from your hand");
private static final FilterCreatureCard filterGreenCreature = new FilterCreatureCard("a green creature card");
static {
filterGreenCreature.add(new ColorPredicate(ObjectColor.GREEN));
}
@ -80,7 +76,7 @@ public class GarrukCallerOfBeasts extends CardImpl {
this.addAbility(new LoyaltyAbility(new RevealLibraryPutIntoHandEffect(5, new FilterCreatureCard("all creature cards"),true), 1));
// -3: You may put a green creature card from your hand onto the battlefield.
this.addAbility(new LoyaltyAbility(new GarrukCallerOfBeastsPutOntoBattlefieldEffect(), -3));
this.addAbility(new LoyaltyAbility(new PutPermanentOnBattlefieldEffect(filterGreenCreature), -3));
// -7: You get an emblem with "Whenever you cast a creature spell, you may search your library for a creature card, put it onto the battlefield, then shuffle your library.");
this.addAbility(new LoyaltyAbility(new GetEmblemEffect(new GarrukCallerOfBeastsEmblem()), -7));
@ -96,6 +92,7 @@ public class GarrukCallerOfBeasts extends CardImpl {
return new GarrukCallerOfBeasts(this);
}
}
/**
* Emblem: "Whenever you cast a creature spell, you may search your library for a creature card, put it onto the battlefield, then shuffle your library."
*/
@ -113,48 +110,3 @@ class GarrukCallerOfBeastsEmblem extends Emblem {
this.getAbilities().add(ability);
}
}
class GarrukCallerOfBeastsPutOntoBattlefieldEffect extends OneShotEffect {
private static final FilterCreatureCard filterGreenCreature = new FilterCreatureCard("a green creature card from your hand");
static {
filterGreenCreature.add(new ColorPredicate(ObjectColor.GREEN));
}
public GarrukCallerOfBeastsPutOntoBattlefieldEffect() {
super(Outcome.PutCreatureInPlay);
this.staticText = "You may put a green creature card from your hand onto the battlefield";
}
public GarrukCallerOfBeastsPutOntoBattlefieldEffect(final GarrukCallerOfBeastsPutOntoBattlefieldEffect effect) {
super(effect);
}
@Override
public GarrukCallerOfBeastsPutOntoBattlefieldEffect copy() {
return new GarrukCallerOfBeastsPutOntoBattlefieldEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
if (controller.getHand().count(filterGreenCreature, game) > 0) {
if (controller.chooseUse(Outcome.PutCreatureInPlay,
"Put a green creature card onto the battlefield?", source, game)) {
Target target = new TargetCardInHand(filterGreenCreature);
if (controller.chooseTarget(outcome, target, source, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
controller.putOntoBattlefieldWithInfo(card, game, Zone.HAND, source.getSourceId());
}
}
}
}
return true;
}
return false;
}
}

View file

@ -29,20 +29,12 @@ package mage.sets.shadowmoor;
import java.util.UUID;
import mage.ObjectColor;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.abilities.effects.common.PutPermanentOnBattlefieldEffect;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.filter.common.FilterCreatureCard;
import mage.filter.predicate.mageobject.ColorPredicate;
import mage.game.Game;
import mage.players.Player;
import mage.target.Target;
import mage.target.common.TargetCardInHand;
/**
*
@ -50,13 +42,18 @@ import mage.target.common.TargetCardInHand;
*/
public class DramaticEntrance extends CardImpl {
private static final FilterCreatureCard filter = new FilterCreatureCard("a green creature card");
static {
filter.add(new ColorPredicate(ObjectColor.GREEN));
}
public DramaticEntrance(UUID ownerId) {
super(ownerId, 111, "Dramatic Entrance", Rarity.RARE, new CardType[]{CardType.INSTANT}, "{3}{G}{G}");
this.expansionSetCode = "SHM";
// You may put a green creature card from your hand onto the battlefield.
this.getSpellAbility().addEffect(new DramaticEntranceEffect());
this.getSpellAbility().addEffect(new PutPermanentOnBattlefieldEffect(filter));
}
@ -69,47 +66,3 @@ public class DramaticEntrance extends CardImpl {
return new DramaticEntrance(this);
}
}
class DramaticEntranceEffect extends OneShotEffect {
private static final FilterCreatureCard filter = new FilterCreatureCard("a green creature card from your hand");
static {
filter.add(new ColorPredicate(ObjectColor.GREEN));
}
public DramaticEntranceEffect() {
super(Outcome.PutCreatureInPlay);
this.staticText = "You may put a green creature card from your hand onto the battlefield";
}
public DramaticEntranceEffect(final DramaticEntranceEffect effect) {
super(effect);
}
@Override
public DramaticEntranceEffect copy() {
return new DramaticEntranceEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
if (controller.getHand().count(filter, game) > 0) {
if (controller.chooseUse(Outcome.PutCreatureInPlay,
"Put a green creature card onto the battlefield?", source, game)) {
Target target = new TargetCardInHand(filter);
if (controller.chooseTarget(outcome, target, source, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
controller.putOntoBattlefieldWithInfo(card, game, Zone.HAND, source.getSourceId());
}
}
}
}
return true;
}
return false;
}
}

View file

@ -29,23 +29,14 @@ package mage.sets.zendikar;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.common.DealsDamageToOpponentTriggeredAbility;
import mage.abilities.effects.common.PutPermanentOnBattlefieldEffect;
import mage.abilities.keyword.DoubleStrikeAbility;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.filter.common.FilterCreatureCard;
import mage.filter.predicate.mageobject.SubtypePredicate;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.players.Player;
import mage.target.common.TargetCardInHand;
/**
*
@ -53,6 +44,12 @@ import mage.target.common.TargetCardInHand;
*/
public class WarrenInstigator extends CardImpl {
private static final FilterCreatureCard filter = new FilterCreatureCard("a Goblin creature card");
static {
filter.add(new SubtypePredicate("Goblin"));
}
public WarrenInstigator(UUID ownerId) {
super(ownerId, 154, "Warren Instigator", Rarity.MYTHIC, new CardType[]{CardType.CREATURE}, "{R}{R}");
this.expansionSetCode = "ZEN";
@ -63,7 +60,9 @@ public class WarrenInstigator extends CardImpl {
this.toughness = new MageInt(1);
this.addAbility(DoubleStrikeAbility.getInstance());
this.addAbility(new WarrenInstigatorTriggeredAbility());
// Whenever Warren Instigator deals damage to an opponent, you may put a Goblin creature card from your hand onto the battlefield.
this.addAbility(new DealsDamageToOpponentTriggeredAbility(new PutPermanentOnBattlefieldEffect(filter), false));
}
public WarrenInstigator(final WarrenInstigator card) {
@ -75,72 +74,3 @@ public class WarrenInstigator extends CardImpl {
return new WarrenInstigator(this);
}
}
class WarrenInstigatorTriggeredAbility extends TriggeredAbilityImpl {
public WarrenInstigatorTriggeredAbility() {
super(Zone.BATTLEFIELD, new WarrenInstigatorEffect(), true);
}
public WarrenInstigatorTriggeredAbility(final WarrenInstigatorTriggeredAbility ability) {
super(ability);
}
@Override
public WarrenInstigatorTriggeredAbility copy() {
return new WarrenInstigatorTriggeredAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == EventType.DAMAGED_PLAYER;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
return event.getSourceId().equals(this.sourceId)
&& game.getOpponents(this.getControllerId()).contains(event.getTargetId());
}
@Override
public String getRule() {
return "Whenever {this} deals damage to an opponent, you may put a Goblin creature card from your hand onto the battlefield.";
}
}
class WarrenInstigatorEffect extends OneShotEffect {
public WarrenInstigatorEffect() {
super(Outcome.PutCreatureInPlay);
this.staticText = "you may put a Goblin creature card from your hand onto the battlefield";
}
public WarrenInstigatorEffect(final WarrenInstigatorEffect effect) {
super(effect);
}
@Override
public WarrenInstigatorEffect copy() {
return new WarrenInstigatorEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
FilterCreatureCard filter = new FilterCreatureCard("Goblin creature card from your hand");
filter.add(new SubtypePredicate("Goblin"));
TargetCardInHand target = new TargetCardInHand(filter);
if (player.choose(Outcome.PutCreatureInPlay, target, source.getSourceId(), game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
card.putOntoBattlefield(game, Zone.HAND, source.getSourceId(), source.getControllerId());
return true;
}
}
return false;
}
}