Menu

Submission for Iname as One

151

Config

name=Iname as One
image=http://magiccards.info/scans/en/sok/151.jpg
value=2.549
rarity=R
type=Legendary,Creature
subtype=Spirit
cost={8}{B}{B}{G}{G}
pt=8/8
timing=main
requires_groovy_code
oracle=When Iname as One enters the battlefield, if you cast it from your hand, you may search your library for a Spirit permanent card, put it onto the battlefield, then shuffle your library.\nWhen Iname as One dies, you may exile it. If you do, return target Spirit permanent card from your graveyard to the battlefield.

Script

def choice = new MagicTargetChoice("a Spirit permanent card from your library");

def SPIRIT_PERMANENT_FROM_GRAVEYARD = new MagicCardFilterImpl() {
    public boolean accept(final MagicSource source,final MagicPlayer player,final MagicCard target) {
        return target.hasSubType(MagicSubType.Spirit) && target.isPermanent();
    }
    public boolean acceptType(final MagicTargetType targetType) {
        return targetType == MagicTargetType.Graveyard;
    }
};

def TARGET_SPIRIT_PERMANENT_FROM_GRAVEYARD = new MagicTargetChoice(
    SPIRIT_PERMANENT_FROM_GRAVEYARD,  
    MagicTargetHint.None,
    "target spirit permanent card from your graveyard"
);

[
    new MagicWhenComesIntoPlayTrigger() {
        @Override
        public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicPayedCost payedCost) {
            return permanent.hasState(MagicPermanentState.CastFromHand) ? 
                new MagicEvent(
                    permanent,
                    new MagicMayChoice("Search library?"),
                    this,
                    "PN may\$ search your library for a Spirit permanent card, " +
                    "put it onto the battlefield, then shuffle your library."
                ):
                MagicEvent.NONE;
        }
        @Override
        public void executeEvent(final MagicGame game, final MagicEvent event) {
            if (event.isYes()) {
                game.addEvent(new MagicSearchOntoBattlefieldEvent(
                    event.getSource(),
                    event.getPlayer(),
                    choice
                ));
            }
        }
    },
    new MagicWhenDiesTrigger() {
        @Override
        public MagicEvent executeTrigger(final MagicGame game, final MagicPermanent permanent, final MagicPermanent died) {
            return new MagicEvent(
                permanent,
                new MagicMayChoice(TARGET_SPIRIT_PERMANENT_FROM_GRAVEYARD),
                this,
                "PN may\$ exile SN. If you do, return target Spirit permanent card\$ from your graveyard to the battlefield."
            );
        }

        @Override
        public void executeEvent(final MagicGame game, final MagicEvent event) {
            if (event.isYes()){
                event.processTargetCard(game, {
                final MagicCard card = event.getPermanent().getCard();
                    if (card.isInGraveyard()) {
                        game.doAction(new RemoveCardAction(card,MagicLocationType.Graveyard));
                        game.doAction(new MoveCardAction(card,MagicLocationType.Graveyard,MagicLocationType.Exile));
                        game.doAction(new ReanimateAction(
                            it,
                            event.getPlayer()
                        ));
                    }
                });
            }
        }
    }
]
Pushed