refactor duplicate code for playing lands from grave

This commit is contained in:
igoudt 2017-06-24 00:28:34 +02:00
parent 940b44ef81
commit ae640ee0b7
4 changed files with 68 additions and 105 deletions

View file

@ -27,16 +27,12 @@
*/
package mage.cards.c;
import mage.abilities.Ability;
import mage.abilities.PlayLandAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.cards.Card;
import mage.abilities.effects.common.ruleModifying.PlayLandsFromGraveyardEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.*;
import mage.game.Game;
import mage.players.Player;
import mage.constants.CardType;
import mage.constants.Zone;
import java.util.UUID;
@ -50,7 +46,7 @@ public class CrucibleOfWorlds extends CardImpl {
super(ownerId,setInfo,new CardType[]{CardType.ARTIFACT},"{3}");
// You may play land cards from your graveyard.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new CrucibleOfWorldsEffect()));
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new PlayLandsFromGraveyardEffect()));
}
public CrucibleOfWorlds(final CrucibleOfWorlds card) {
@ -62,45 +58,3 @@ public class CrucibleOfWorlds extends CardImpl {
return new CrucibleOfWorlds(this);
}
}
class CrucibleOfWorldsEffect extends ContinuousEffectImpl {
public CrucibleOfWorldsEffect() {
super(Duration.WhileOnBattlefield, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility);
this.staticText = "You may play land cards from your graveyard";
}
public CrucibleOfWorldsEffect(final CrucibleOfWorldsEffect effect) {
super(effect);
}
@Override
public CrucibleOfWorldsEffect copy() {
return new CrucibleOfWorldsEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
for (UUID cardId: player.getGraveyard()) {
Card card = game.getCard(cardId);
if(card != null && card.isLand()){
PlayLandFromGraveyardAbility ability = new PlayLandFromGraveyardAbility(card.getName());
ability.setSourceId(cardId);
ability.setControllerId(card.getOwnerId());
game.getState().addOtherAbility(card, ability);
}
}
return true;
}
return false;
}
}
class PlayLandFromGraveyardAbility extends PlayLandAbility{
PlayLandFromGraveyardAbility(String name){
super(name);
zone = Zone.GRAVEYARD;
}
}

View file

@ -27,26 +27,17 @@
*/
package mage.cards.r;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.PlayLandAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.cards.Card;
import mage.abilities.effects.common.ruleModifying.PlayLandsFromGraveyardEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Layer;
import mage.constants.Outcome;
import mage.constants.SubLayer;
import mage.constants.Zone;
import mage.game.Game;
import mage.players.Player;
import java.util.UUID;
/**
*
* @author fireshoes
*/
public class RamunapExcavator extends CardImpl {
@ -60,7 +51,7 @@ public class RamunapExcavator extends CardImpl {
this.toughness = new MageInt(3);
// You may play land cards from your graveyard.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new RamunapExcavatorEffect()));
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new PlayLandsFromGraveyardEffect()));
}
public RamunapExcavator(final RamunapExcavator card) {
@ -71,46 +62,4 @@ public class RamunapExcavator extends CardImpl {
public RamunapExcavator copy() {
return new RamunapExcavator(this);
}
}
class RamunapExcavatorEffect extends ContinuousEffectImpl {
public RamunapExcavatorEffect() {
super(Duration.WhileOnBattlefield, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility);
this.staticText = "You may play land cards from your graveyard";
}
public RamunapExcavatorEffect(final RamunapExcavatorEffect effect) {
super(effect);
}
@Override
public RamunapExcavatorEffect copy() {
return new RamunapExcavatorEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
for (UUID cardId: player.getGraveyard()) {
Card card = game.getCard(cardId);
if(card != null && card.isLand()){
PlayLandFromGraveyardAbility ability = new PlayLandFromGraveyardAbility(card.getName());
ability.setSourceId(cardId);
ability.setControllerId(card.getOwnerId());
game.getState().addOtherAbility(card, ability);
}
}
return true;
}
return false;
}
}
class PlayLandFromGraveyardAbility extends PlayLandAbility{
PlayLandFromGraveyardAbility(String name){
super(name);
zone = Zone.GRAVEYARD;
}
}

View file

@ -0,0 +1,11 @@
package mage.abilities.common;
import mage.abilities.PlayLandAbility;
import mage.constants.Zone;
public class PlayLandFromGraveyardAbility extends PlayLandAbility {
public PlayLandFromGraveyardAbility(String name){
super(name);
zone = Zone.GRAVEYARD;
}
}

View file

@ -0,0 +1,49 @@
package mage.abilities.effects.common.ruleModifying;
import mage.abilities.Ability;
import mage.abilities.common.PlayLandFromGraveyardAbility;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.cards.Card;
import mage.constants.Duration;
import mage.constants.Layer;
import mage.constants.Outcome;
import mage.constants.SubLayer;
import mage.game.Game;
import mage.players.Player;
import java.util.UUID;
public class PlayLandsFromGraveyardEffect extends ContinuousEffectImpl {
public PlayLandsFromGraveyardEffect() {
super(Duration.WhileOnBattlefield, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility);
this.staticText = "You may play land cards from your graveyard";
}
public PlayLandsFromGraveyardEffect(final PlayLandsFromGraveyardEffect effect) {
super(effect);
}
@Override
public PlayLandsFromGraveyardEffect copy() {
return new PlayLandsFromGraveyardEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
for (UUID cardId: player.getGraveyard()) {
Card card = game.getCard(cardId);
if(card != null && card.isLand()){
PlayLandFromGraveyardAbility ability = new PlayLandFromGraveyardAbility(card.getName());
ability.setSourceId(cardId);
ability.setControllerId(card.getOwnerId());
game.getState().addOtherAbility(card, ability);
}
}
return true;
}
return false;
}
}