It is currently 02 May 2024, 14:24
   
Text Size

etbReturnTgt

Post MTG Forge Related Programming Questions Here

Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins

etbReturnTgt

Postby Chris H. » 24 Oct 2010, 00:27

This is the "Enters the Battlefield" version of the spReturnTgt keyword. etbReturnTgt and spReturnTgt share a similar code base and have similar params. The etbReturnTgt keyword also uses the getTargetList() and setTargetList() methods.

Syntax:

Code: Select all
etbReturnTgt:{Num Cards/Parameters}:{Type}:{To Zone}:{DrawBack}:{Spell Desc}
`
Examples:

Code: Select all
Name:Corpse Cur
ManaCost:4
Types:Artifact Creature Hound
Text:When Corpse Cur enters the battlefield, you may return target creature card with infect from your graveyard to your hand.
PT:2/2
K:Infect
K:etbReturnTgt:1/MayReturn:Creature.withInfect:Hand
SVar:Rarity:Common
SVar:Picture:http://www.wizards.com/global/images/magic/general/corpse_cur.jpg
End


Name:Mnemonic Wall
ManaCost:4 U
Types:Creature Wall
Text:When Mnemonic Wall enters the battlefield, you may return target instant or sorcery card from your graveyard to your hand.
PT:0/4
K:Defender
K:etbReturnTgt:1/MayReturn:Instant,Sorcery:Hand
SVar:Rarity:Common
SVar:Picture:http://www.wizards.com/global/images/magic/general/mnemonic_wall.jpg
End


Name:Nucklavee
ManaCost:4 UR UR
Types:Creature Beast
Text:When Nucklavee enters the battlefield, you may return target red sorcery card from your graveyard to your hand.\r\nWhen Nucklavee enters the battlefield, you may return target blue instant card from your graveyard to your hand.
PT:4/4
K:etbReturnTgt:1/MayReturn:Sorcery.Red:Hand
K:etbReturnTgt:1/MayReturn:Instant.Blue:Hand
SVar:Rarity:Uncommon
SVar:Picture:http://www.wizards.com/global/images/magic/general/nucklavee.jpg
End



Name:Sharuum the Hegemon
ManaCost:3 W U B
Types:Legendary Artifact Creature Sphinx
Text:When Sharuum the Hegemon enters the battlefield, you may return target artifact card from your graveyard to the battlefield.
PT:5/5
K:Flying
K:etbReturnTgt:1/MayReturn:Artifact:Battlefield
SVar:Rarity:Mythic
SVar:Picture:http://www.wizards.com/global/images/magic/general/sharuum_the_hegemon.jpg
End
`
Keyword code:

Code: Select all
        /**
         *  Generic return target card(s) from graveyard to Hand, Battlefield or Top of Library.
         *  This version handles abilities that activate when card enters the battlefield.
         *  spReturnTgt:{Num Cards/Parameters}:{Type}:{To Zone}:{DrawBack}:{Spell Desc}
         * 
         *  Buyback and X Count/Costs are not yet implemented.
         */
        while (hasKeyword(card, "etbReturnTgt") != -1) {
            int n = hasKeyword(card, "etbReturnTgt");
           
            String parse = card.getKeyword().get(n).toString();
            card.removeIntrinsicKeyword(parse);
            String k[] = parse.split(":");
            final boolean returnUpTo[] = {false};
            final boolean mayReturn[] = {false};
            final int numCardsToReturn;
           
            String np[] = k[1].split("/");
            numCardsToReturn = Integer.parseInt(np[0]);
           
            if (np.length > 1) {
                if (np[1].equals("UpTo")) {
                    returnUpTo[0] = true;
                } else if (np[1].equals("MayReturn")) {
                    mayReturn[0] = true;
                }
            }
           
            //  Artifact, Creature, Enchantment, Land, Permanent, Instant, Sorcery, Card
            //  White, Blue, Black, Red, Green, Colorless, MultiColor
            //  non-Artifact, non-Creature, non-Enchantment, non-Land, non-Permanent,
            //  non-White, non-Blue, non-Black, non-Red, non-Green, non-Colorless, non-MultiColor
           
            String Targets = k[2];
            final String Tgts[] = Targets.split(",");
           
            final String Destination = k[3];
           
            String desc = "";
            final String Drawback[] = {"none"};
           
            if (k.length > 4) {
               
                if (k[4].contains("Drawback$")){
                    String kk[] = k[4].split("\\$");
                    Drawback[0] = kk[1];
                } else {
                    desc = k[4];
                }
            }
            if (k.length > 5) {
                desc = k[5];
            }
           
            final SpellAbility etbRtrnTgt = new Ability(card, "0") {

                @Override
                public void resolve() {
                   
                    CardList targets = getTargetList();
                    PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, card.getController());
                    Player player = card.getController();
                   
                    for (Card c:targets) {
                       
                        if (AllZone.GameAction.isCardInZone(c, grave)) {
                           
                            if (Destination.equals("Hand")) {
                                PlayerZone zone = AllZone.getZone(Constant.Zone.Hand, player);
                                AllZone.GameAction.moveTo(zone, c);
                            }
                            else if (Destination.equals("Battlefield")) {
                                PlayerZone zone = AllZone.getZone(Constant.Zone.Play, player);
                                AllZone.GameAction.moveTo(zone, c);
                            }
                            else if (Destination.equals("TopofLibrary")) {
                                // PlayerZone zone = AllZone.getZone(Constant.Zone.Play, player);
                                AllZone.GameAction.moveToTopOfLibrary(c);
                            }
                        }
                    }// for
                   
                    if (!Drawback[0].equals("none")) {
                        CardFactoryUtil.doDrawBack(Drawback[0], 0, card.getController(),
                                card.getController().getOpponent(), card.getController(), card, card, this);
                    }
                }//resolve()
            };// etbRtrnTgt
           
            Command intoPlay = new Command() {
                private static final long serialVersionUID = -8592314045228582326L;

                public void execute() {
                   
                    Player player = card.getController();
                    PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, player);
                    CardList results = new CardList();
                    CardList choices = new CardList(grave.getCards());
                    choices = choices.getValidCards(Tgts);
                   
                    // AI will not use an Eternal Witness to return an Eternal Witness.
                   
                    if (card.getController().equals(AllZone.ComputerPlayer)) {
                        choices = choices.getNotName(card.getName());
                        if (Destination.equals("Battlefield")
                                && !AllZone.Phase.getPhase().equals(Constant.Phase.Main1)) {
                            choices = choices.getNotKeyword("At the beginning of the end step, destroy CARDNAME.");
                            choices = choices.getNotKeyword("At the beginning of the end step, exile CARDNAME.");
                            choices = choices.getNotKeyword("At the beginning of the end step, sacrifice CARDNAME.");
                        }
                    }
                   
                    if (choices.isEmpty()) return;
                   
                    if (card.getController().equals(AllZone.HumanPlayer)) {
                       
                        CardList targets = new CardList();
                       
                        for (int i = 0; i < numCardsToReturn; i++) {
                            if (grave.size() > 0) {
                                Object o;
                                if (mayReturn[0] || returnUpTo[0]) {
                                    o = AllZone.Display.getChoiceOptional("Select a card", choices.toArray());
                                } else {
                                    o = AllZone.Display.getChoice("Select a card", choices.toArray());
                                }
                                if (o == null) break;
                                Card c = (Card) o;
                                targets.add(c);
                                choices.remove(c);
                            }
                        }
                        if (targets.size() > 0) {
                            etbRtrnTgt.setTargetList(targets);
                            AllZone.Stack.add(etbRtrnTgt);
                        }
                    }// if HumanPlayer
                   
                    else { // ComputerPlayer
                       
                        for (int nctr = 0; nctr < numCardsToReturn; nctr ++) {
                            for (int i = 0; i < Tgts.length; i++) {
                           
                                if (Tgts[i].startsWith("Artifact")) {
                                    if (CardFactoryUtil.AI_getBestArtifact(choices) != null) {
                                        Card c = CardFactoryUtil.AI_getBestArtifact(choices);
                                        results.add(c);
                                        choices.remove(c);
                                    }
                                } else if (Tgts[i].startsWith("Creature")) {
                                    if (CardFactoryUtil.AI_getBestCreature(choices) != null) {
                                        Card c = CardFactoryUtil.AI_getBestCreature(choices);
                                        results.add(c);
                                        choices.remove(c);
                                    }
                                } else if (Tgts[i].startsWith("Enchantment")) {
                                    if (CardFactoryUtil.AI_getBestEnchantment(choices, card, true) != null) {
                                        Card c = CardFactoryUtil.AI_getBestEnchantment(choices, card, true);
                                        results.add(c);
                                        choices.remove(c);
                                    }
                                } else if (Tgts[i].startsWith("Land")) {
                                    if (CardFactoryUtil.AI_getBestLand(choices) != null) {
                                        Card c = CardFactoryUtil.AI_getBestLand(choices);
                                        results.add(c);
                                        choices.remove(c);
                                    }
                                } else if (Tgts[i].startsWith("Permanent")) {
                                    if (CardFactoryUtil.AI_getMostExpensivePermanent(choices, card, true) != null) {
                                        Card c = CardFactoryUtil.AI_getMostExpensivePermanent(choices, card, true);
                                        results.add(c);
                                        choices.remove(c);
                                    }
                                } else if (Tgts[i].startsWith("Instant")) {
                                    if (CardFactoryUtil.AI_getMostExpensivePermanent(choices, card, true) != null) {
                                        // Card c = CardFactoryUtil.AI_getMostExpensivePermanent(choices, card, true);
                                        Card c = CardFactoryUtil.getRandomCard(choices);
                                        results.add(c);
                                        choices.remove(c);
                                    }
                                } else if (Tgts[i].startsWith("Sorcery")) {
                                    if (CardFactoryUtil.AI_getMostExpensivePermanent(choices, card, true) != null) {
                                        // Card c = CardFactoryUtil.AI_getMostExpensivePermanent(choices, card, true);
                                        Card c = CardFactoryUtil.getRandomCard(choices);
                                        results.add(c);
                                        choices.remove(c);
                                    }
                                } else {
                                    if (CardFactoryUtil.AI_getMostExpensivePermanent(choices, card, true) != null) {
                                        // Card c = CardFactoryUtil.AI_getMostExpensivePermanent(choices, card, true);
                                        Card c = CardFactoryUtil.getRandomCard(choices);
                                        results.add(c);
                                        choices.remove(c);
                                    }
                                }
                            }// for i
                        }// for nctr
                        if (results.size() > 0) {
                            etbRtrnTgt.setTargetList(results);
                            AllZone.Stack.add(etbRtrnTgt);
                        }
                    }// ComputerPlayer
                   
                }// execute()
            };// Command()
            card.addComesIntoPlayCommand(intoPlay);
           
            if (desc.length() > 0) {
                etbRtrnTgt.setDescription(desc);
            }
        }// etbReturnTgt
`

EDIT:

Added MayReturn as a parameter.
User avatar
Chris H.
Forge Moderator
 
Posts: 6320
Joined: 04 Nov 2008, 12:11
Location: Mac OS X Yosemite
Has thanked: 644 times
Been thanked: 643 times

Return to Developer's Corner

Who is online

Users browsing this forum: Google [Bot] and 22 guests


Who is online

In total there are 23 users online :: 1 registered, 0 hidden and 22 guests (based on users active over the past 10 minutes)
Most users ever online was 4143 on 23 Jan 2024, 08:21

Users browsing this forum: Google [Bot] and 22 guests

Login Form