Added and used ExileCardYouChooseTargetOpponentEffect.

This commit is contained in:
LevelX2 2013-07-09 14:30:47 +02:00
parent 1932f49969
commit 18221a6513
3 changed files with 104 additions and 110 deletions

View file

@ -28,20 +28,13 @@
package mage.sets.avacynrestored;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.abilities.effects.common.ExileCardYouChooseTargetOpponentEffect;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.filter.Filter;
import mage.filter.FilterCard;
import mage.filter.common.FilterCreatureCard;
import mage.filter.predicate.mageobject.ConvertedManaCostPredicate;
import mage.game.Game;
import mage.players.Player;
import mage.target.TargetCard;
import mage.target.common.TargetOpponent;
/**
@ -50,6 +43,11 @@ import mage.target.common.TargetOpponent;
*/
public class AppetiteForBrains extends CardImpl<AppetiteForBrains> {
private static final FilterCreatureCard filter = new FilterCreatureCard("a card from it with converted mana cost 4 or greater");
static {
filter.add(new ConvertedManaCostPredicate(Filter.ComparisonType.GreaterThan, 3));
}
public AppetiteForBrains(UUID ownerId) {
super(ownerId, 84, "Appetite for Brains", Rarity.UNCOMMON, new CardType[]{CardType.SORCERY}, "{B}");
this.expansionSetCode = "AVR";
@ -57,7 +55,7 @@ public class AppetiteForBrains extends CardImpl<AppetiteForBrains> {
this.color.setBlack(true);
// Target opponent reveals his or her hand. You choose a card from it with converted mana cost 4 or greater and exile that card.
this.getSpellAbility().addEffect(new AppetiteForBrainsEffect());
this.getSpellAbility().addEffect(new ExileCardYouChooseTargetOpponentEffect(filter));
this.getSpellAbility().addTarget(new TargetOpponent());
}
@ -70,42 +68,3 @@ public class AppetiteForBrains extends CardImpl<AppetiteForBrains> {
return new AppetiteForBrains(this);
}
}
class AppetiteForBrainsEffect extends OneShotEffect<AppetiteForBrainsEffect> {
public AppetiteForBrainsEffect() {
super(Outcome.Exile);
this.staticText = "Target opponent reveals his or her hand. You choose a card from it with converted mana cost 4 or greater and exile that card";
}
public AppetiteForBrainsEffect(final AppetiteForBrainsEffect effect) {
super(effect);
}
@Override
public AppetiteForBrainsEffect copy() {
return new AppetiteForBrainsEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(source.getFirstTarget());
if (player != null && targetPlayer != null) {
FilterCard filter = new FilterCard("with converted mana cost 4 or greater");
filter.add(new ConvertedManaCostPredicate(Filter.ComparisonType.GreaterThan, 3));
targetPlayer.revealCards("Appetite for Brains", targetPlayer.getHand(), game);
TargetCard target = new TargetCard(Zone.PICK, filter);
target.setRequired(true);
if (targetPlayer.getHand().count(filter, game) > 0
&& player.choose(Outcome.Exile, targetPlayer.getHand(), target, game)) {
Card card = targetPlayer.getHand().get(target.getFirstTarget(), game);
if (card != null) {
return card.moveToExile(null, "", source.getId(), game);
}
}
}
return false;
}
}

View file

@ -29,22 +29,14 @@
package mage.sets.dragonsmaze;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.abilities.effects.common.ExileCardYouChooseTargetOpponentEffect;
import mage.cards.CardImpl;
import mage.filter.FilterCard;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.CardTypePredicate;
import mage.game.Game;
import mage.players.Player;
import mage.target.TargetCard;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.filter.common.FilterInstantOrSorceryCard;
import mage.target.common.TargetOpponent;
/**
@ -67,7 +59,7 @@ public class SinCollector extends CardImpl<SinCollector> {
this.color.setWhite(true);
// When Sin Collector enters the battlefield, target opponent reveals his or her hand. You choose an instant or sorcery card from it and exile that card.
Ability ability = new EntersBattlefieldTriggeredAbility(new SinCollectorEffect());
Ability ability = new EntersBattlefieldTriggeredAbility(new ExileCardYouChooseTargetOpponentEffect(new FilterInstantOrSorceryCard("an instant or sorcery card")));
ability.addTarget(new TargetOpponent());
this.addAbility(ability);
}
@ -81,49 +73,3 @@ public class SinCollector extends CardImpl<SinCollector> {
return new SinCollector(this);
}
}
class SinCollectorEffect extends OneShotEffect<SinCollectorEffect> {
private static final FilterCard filter = new FilterCard("instant or sorcery card");
static {
filter.add(Predicates.or(
new CardTypePredicate(CardType.INSTANT),
new CardTypePredicate(CardType.SORCERY)));
}
public SinCollectorEffect() {
super(Outcome.Exile);
staticText = "target opponent reveals his or her hand. You choose an instant or sorcery card from it and exile that card";
}
public SinCollectorEffect(final SinCollectorEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getFirstTarget());
if (player != null) {
player.revealCards("Sin Collector", player.getHand(), game);
Player you = game.getPlayer(source.getControllerId());
if (you != null) {
TargetCard target = new TargetCard(Zone.PICK, filter);
target.setRequired(true);
if (you.choose(Outcome.Benefit, player.getHand(), target, game)) {
Card card = player.getHand().get(target.getFirstTarget(), game);
if (card != null) {
card.moveToExile(null, null , source.getSourceId(), game);
}
}
}
}
return false;
}
@Override
public SinCollectorEffect copy() {
return new SinCollectorEffect(this);
}
}

View file

@ -0,0 +1,89 @@
/*
* 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.abilities.effects.common;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.FilterCard;
import mage.game.Game;
import mage.players.Player;
import mage.target.TargetCard;
/**
*
* @author LevelX2
*/
public class ExileCardYouChooseTargetOpponentEffect extends OneShotEffect<ExileCardYouChooseTargetOpponentEffect> {
private FilterCard filter;
public ExileCardYouChooseTargetOpponentEffect() {
this(new FilterCard("a card"));
}
public ExileCardYouChooseTargetOpponentEffect(FilterCard filter) {
super(Outcome.Discard);
staticText = new StringBuilder("Target opponent reveals his or her hand. You choose ")
.append(filter.getMessage()).append(" from it and exile that card").toString();
this.filter = filter;
}
public ExileCardYouChooseTargetOpponentEffect(final ExileCardYouChooseTargetOpponentEffect effect) {
super(effect);
this.filter = effect.filter;
}
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getFirstTarget());
if (player != null) {
player.revealCards("Exile " + filter.getMessage(), player.getHand(), game);
Player you = game.getPlayer(source.getControllerId());
if (you != null) {
TargetCard target = new TargetCard(Zone.PICK, filter);
target.setRequired(true);
if (you.choose(Outcome.Benefit, player.getHand(), target, game)) {
Card card = player.getHand().get(target.getFirstTarget(), game);
if (card != null) {
card.moveToExile(null, null , source.getSourceId(), game);
}
}
}
}
return false;
}
@Override
public ExileCardYouChooseTargetOpponentEffect copy() {
return new ExileCardYouChooseTargetOpponentEffect(this);
}
}