mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 21:12:04 -08:00
refactor duplicate code for playing lands from grave
This commit is contained in:
parent
940b44ef81
commit
ae640ee0b7
4 changed files with 68 additions and 105 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue