[REFACTOR] Removed duplicate code and an unused effect

This commit is contained in:
Styxo 2017-01-04 09:58:10 +01:00
parent ffca57e41c
commit 3c67e51db0
5 changed files with 27 additions and 281 deletions

View file

@ -29,23 +29,14 @@ package mage.cards.a;
import java.util.UUID;
import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.DiesTriggeredAbility;
import mage.abilities.costs.common.ExileSourceFromGraveCost;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.DoIfCostPaid;
import mage.abilities.effects.common.ExileSourceEffect;
import mage.cards.Card;
import mage.abilities.effects.common.search.SearchLibraryPutInPlayEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.FilterCard;
import mage.filter.predicate.mageobject.CardTypePredicate;
import mage.game.Game;
import mage.players.Player;
import mage.filter.common.FilterEnchantmentCard;
import mage.target.common.TargetCardInLibrary;
/**
@ -55,7 +46,7 @@ import mage.target.common.TargetCardInLibrary;
public class AcademyRector extends CardImpl {
public AcademyRector(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{3}{W}");
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{3}{W}");
this.subtype.add("Human");
this.subtype.add("Cleric");
@ -63,8 +54,12 @@ public class AcademyRector extends CardImpl {
this.toughness = new MageInt(2);
// When Academy Rector dies, you may exile it. If you do, search your library for an enchantment card, put that card onto the battlefield, then shuffle your library.
Ability ability = new DiesTriggeredAbility(new DoIfCostPaid(new AcademyRectorEffect(), new ExileSourceFromGraveCost(), "Exile to search enchantment?"), false);
this.addAbility(ability);
this.addAbility(new DiesTriggeredAbility(new DoIfCostPaid(
new SearchLibraryPutInPlayEffect(new TargetCardInLibrary(new FilterEnchantmentCard())),
new ExileSourceFromGraveCost(),
"Exile to search enchantment?"),
false
));
}
public AcademyRector(final AcademyRector card) {
@ -76,45 +71,3 @@ public class AcademyRector extends CardImpl {
return new AcademyRector(this);
}
}
class AcademyRectorEffect extends OneShotEffect {
private static final FilterCard filter = new FilterCard();
static {
filter.add(new CardTypePredicate(CardType.ENCHANTMENT));
}
public AcademyRectorEffect() {
super(Outcome.Benefit);
staticText = "you may exile it. If you do, search your library for an enchantment card and put it onto the battlefield. Then shuffle your library";
}
public AcademyRectorEffect(final AcademyRectorEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (controller != null && sourceObject != null) {
new ExileSourceEffect().apply(game, source);
TargetCardInLibrary target = new TargetCardInLibrary(filter);
target.setNotTarget(true);
controller.searchLibrary(target, game);
Card targetCard = game.getCard(target.getFirstTarget());
if (targetCard != null) {
controller.moveCards(targetCard, Zone.BATTLEFIELD, source, game);
}
controller.shuffleLibrary(source, game);
return true;
}
return false;
}
@Override
public AcademyRectorEffect copy() {
return new AcademyRectorEffect(this);
}
}

View file

@ -33,17 +33,12 @@ import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.common.SacrificeSourceCost;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.abilities.effects.common.PutPermanentOnBattlefieldEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.common.FilterArtifactCard;
import mage.game.Game;
import mage.players.Player;
import mage.target.common.TargetCardInHand;
/**
*
@ -52,13 +47,13 @@ import mage.target.common.TargetCardInHand;
public class CopperGnomes extends CardImpl {
public CopperGnomes(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.ARTIFACT,CardType.CREATURE},"{2}");
super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT, CardType.CREATURE}, "{2}");
this.subtype.add("Gnome");
this.power = new MageInt(1);
this.toughness = new MageInt(1);
// {4}, Sacrifice Copper Gnomes: You may put an artifact card from your hand onto the battlefield.
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new PutArtifactOnBattlefieldEffect(), new ManaCostsImpl("{4}"));
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new PutPermanentOnBattlefieldEffect(new FilterArtifactCard()), new ManaCostsImpl("{4}"));
ability.addCost(new SacrificeSourceCost());
this.addAbility(ability);
}
@ -72,39 +67,3 @@ public class CopperGnomes extends CardImpl {
return new CopperGnomes(this);
}
}
class PutArtifactOnBattlefieldEffect extends OneShotEffect {
private static final String choiceText = "Put an artifact card from your hand onto the battlefield?";
public PutArtifactOnBattlefieldEffect() {
super(Outcome.PutCardInPlay);
this.staticText = "You may put an artifact card from your hand onto the battlefield";
}
public PutArtifactOnBattlefieldEffect(final PutArtifactOnBattlefieldEffect effect) {
super(effect);
}
@Override
public PutArtifactOnBattlefieldEffect copy() {
return new PutArtifactOnBattlefieldEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null || !controller.chooseUse(Outcome.PutCardInPlay, choiceText, source, game)) {
return false;
}
TargetCardInHand target = new TargetCardInHand(new FilterArtifactCard());
if (controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
return controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
}
return false;
}
}

View file

@ -30,22 +30,16 @@ package mage.cards.n;
import java.util.UUID;
import mage.MageInt;
import mage.ObjectColor;
import mage.abilities.Ability;
import mage.abilities.common.ActivateIfConditionActivatedAbility;
import mage.abilities.condition.common.MyTurnBeforeAttackersDeclaredCondition;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.abilities.effects.common.PutPermanentOnBattlefieldEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
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.common.TargetCardInHand;
/**
*
@ -53,17 +47,26 @@ import mage.target.common.TargetCardInHand;
*/
public class NorwoodPriestess extends CardImpl {
private static final FilterCreatureCard filter = new FilterCreatureCard("a green creature card");
static {
filter.add(new ColorPredicate(ObjectColor.GREEN));
}
public NorwoodPriestess(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{2}{G}{G}");
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{G}{G}");
this.subtype.add("Elf");
this.subtype.add("Druid");
this.power = new MageInt(1);
this.toughness = new MageInt(1);
// {tap}: You may put a green creature card from your hand onto the battlefield. Activate this ability only during your turn, before attackers are declared.
Ability ability = new ActivateIfConditionActivatedAbility(Zone.BATTLEFIELD,
new NorwoodPriestessEffect(), new TapSourceCost(), MyTurnBeforeAttackersDeclaredCondition.getInstance());
this.addAbility(ability);
this.addAbility(new ActivateIfConditionActivatedAbility(
Zone.BATTLEFIELD,
new PutPermanentOnBattlefieldEffect(filter),
new TapSourceCost(),
MyTurnBeforeAttackersDeclaredCondition.getInstance()
));
}
public NorwoodPriestess(final NorwoodPriestess card) {
@ -75,45 +78,3 @@ public class NorwoodPriestess extends CardImpl {
return new NorwoodPriestess(this);
}
}
class NorwoodPriestessEffect extends OneShotEffect {
private static final String choiceText = "Put a green creature card from your hand onto the battlefield?";
private static final FilterCreatureCard filter = new FilterCreatureCard("a green creature card");
static {
filter.add(new ColorPredicate(ObjectColor.GREEN));
}
public NorwoodPriestessEffect() {
super(Outcome.PutCreatureInPlay);
this.staticText = "You may put a green creature card from your hand onto the battlefield";
}
public NorwoodPriestessEffect(final NorwoodPriestessEffect effect) {
super(effect);
}
@Override
public NorwoodPriestessEffect copy() {
return new NorwoodPriestessEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null || !controller.chooseUse(Outcome.PutCreatureInPlay, choiceText, source, game)) {
return false;
}
TargetCardInHand target = new TargetCardInHand(filter);
if (controller.choose(Outcome.PutCreatureInPlay, target, source.getSourceId(), game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
return controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
}
return false;
}
}

View file

@ -1,126 +0,0 @@
/*
* 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.constants.Outcome;
import mage.constants.Zone;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.game.Game;
import mage.players.Player;
import java.util.UUID;
/**
* @author LevelX
*/
public class PutOntoBattlefieldTargetEffect extends OneShotEffect {
boolean tapped;
boolean optional;
public PutOntoBattlefieldTargetEffect(boolean tapped) {
this(tapped, false);
}
public PutOntoBattlefieldTargetEffect(boolean tapped, boolean optional) {
super(Outcome.PutCreatureInPlay);
this.tapped = tapped;
this.optional = optional;
}
public PutOntoBattlefieldTargetEffect(final PutOntoBattlefieldTargetEffect effect) {
super(effect);
this.tapped = effect.tapped;
this.optional = effect.optional;
}
@Override
public PutOntoBattlefieldTargetEffect copy() {
return new PutOntoBattlefieldTargetEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
boolean result = false;
if (optional) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null || !controller.chooseUse(Outcome.PutCreatureInPlay,
new StringBuilder("Put ")
.append(source.getTargets() != null ? source.getTargets().get(0).getTargetName() : "target")
.append(" onto the battlefield?").toString(), source, game)) {
return false;
}
}
for (UUID targetId : targetPointer.getTargets(game, source)) {
Card card = game.getCard(targetId);
if (card != null) {
switch (game.getState().getZone(targetId)) {
case GRAVEYARD:
for (Player player : game.getPlayers().values()) {
if (player.getGraveyard().contains(card.getId())) {
player.getGraveyard().remove(card);
result |= card.moveToZone(Zone.BATTLEFIELD, source.getSourceId(), game, tapped);
}
}
case HAND:
for (Player player : game.getPlayers().values()) {
if (player.getHand().contains(card.getId())) {
player.getHand().remove(card);
result |= card.moveToZone(Zone.BATTLEFIELD, source.getSourceId(), game, tapped);
}
}
}
}
}
return result;
}
@Override
public String getText(Mode mode) {
// You may put an artifact card from your hand onto the battlefield.
StringBuilder sb = new StringBuilder();
if (optional) {
sb.append("You may put ");
} else {
sb.append("Put ");
}
if (mode.getTargets().get(0).getMaxNumberOfTargets() == 0) {
sb.append("any number of ");
}
if (mode.getTargets() != null) {
sb.append(mode.getTargets().get(0).getTargetName());
}
sb.append(tapped ? "tapped" : "").append(" onto the battlefield");
return sb.toString();
}
}

View file

@ -25,7 +25,6 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.filter.common;
import mage.constants.CardType;
@ -39,7 +38,7 @@ import mage.filter.predicate.mageobject.CardTypePredicate;
public class FilterEnchantmentCard extends FilterCard {
public FilterEnchantmentCard() {
this("enchantment");
this("enchantment card");
}
public FilterEnchantmentCard(String name) {