It is currently 07 Sep 2025, 23:43
   
Text Size

etbBounceTgt keyword

Post MTG Forge Related Programming Questions Here

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

etbBounceTgt keyword

Postby Rob Cashwalker » 22 Sep 2010, 11:57

Just added etbBounceTgt.

Pretty standard syntax, based on spBounceTgt:

K:etbBounceTgt:{ValidTgts}:{Destination}:{Drawback}

At the moment, it relies on the text field to provide the targeting prompt.

Test Card:
man_o_war.txt
Code: Select all

Name:Man-o'-War
ManaCost:2 U
Types:Creature Jellyfish
Text:When Man-o'-War enters the battlefield, return target creature to its owner's hand.
PT:2/2
K:etbBounceTgt:Creature:Hand
SVar:Rarity:Common
SVar:Picture:http://resources.wizards.com/magic/cards/po/en-us/card4266.jpg
End
Other cards I intended to support: (needs to be fixed for new card format)
Code: Select all

AEther Adept
1 U U
Creature Human Wizard
When AEther Adept enters the battlefield, return target creature to its owner's hand.
2/2
etbBounceTgt:Creature:Hand

AEthersnipe
5 U
Creature Elemental
When Æthersnipe enters the battlefield, return target nonland permanent to its owner's hand.
4/4
etbBounceTgt:nonLand:Hand
SVar:Evoke:1 U U

Aven Fogbringer
3 U
Creature Bird Wizard
When Aven Fogbringer enters the battlefield, return target land to its owner's hand.
2/1
Flying
etbBounceTgt:Land:Hand

Devout Lightcaster
W W W
Creature Kor Cleric
When Devout Lightcaster enters the battlefield, exile target black permanent.
2/2
Protection from black
etbBounceTgt:Permanent.Black:Exile

Glowing Anemone
3 U
Creature Jellyfish Beast
When Glowing Anemone enters the battlefield, you may return target land to its owner's hand.
1/3
etbBounceTgtMay:Land:Hand

Hunting Drake
4 U
Creature Drake
When Hunting Drake enters the battlefield, put target red or green creature on top of its owner's library.
2/2
Flying
etbBounceTgt:Creature.Red,Creature.Green:TopofLibrary

Looming Hoverguard
4 U U
Creature Drone
When Looming Hoverguard enters the battlefield, put target artifact on top of its owner's library.
3/3
Flying
etbBounceTgt:Artifact:TopofLibrary

Man-o'-War
2 U
Creature Jellyfish
When Man-o'-War enters the battlefield, return target creature to its owner's hand.
2/2
etbBounceTgt:Creature:Hand

Stern Proctor
U U
Creature Human Wizard
When Stern Proctor enters the battlefield, return target artifact or enchantment to its owner's hand.
1/2
etbBounceTgt:Artifact,Enchantment:Hand

Sun Ce, Young Conquerer
3 U U
Legendary Creature Human Soldier
When Sun Ce, Young Conquerer enters the battlefield, you may return target creature to its owner's hand.
3/3
Horsemanship
etbBounceTgtMay:Creature:Hand

Surrakar Banisher
4 U
Creature Surrakar
When Surrakar Banisher enters the battlefield, you may return target tapped creature to its owner's hand.
3/3
etbBounceTgtMay:Creature.Tapped:Hand

Vedalken AEthermage
1 U
Creature Vedalken Wizard
When Vedalken Æthermage enters the battlefield, return target Sliver to its owner's hand.
1/2
Flash
TypeCycling:3
etbBounceTgt:Sliver:Hand

Vedalken Dismisser
5 U
Creature Vedlaken Wizard
When Vedalken Dismisser enters the battlefield, put target creature on top of its owner's library.
2/2
etbBounceTgt:Creature:TopofLibrary
Code: Select all
        // Generic bounce when enters the battlefield
        if (hasKeyword(card, "etbBounceTgt") != -1)
        {
           int n = hasKeyword(card, "etbBounceTgt");
           
           String parse = card.getKeyword().get(n).toString();
           card.removeIntrinsicKeyword(parse);
           
           String k[] = parse.split(":");
           
           final boolean May[] = {false};
           if (k[0].contains("May"))
              May[0] = true;
           
           final String Tgts[] = k[1].split(",");
           
           final String Destination = k[2];
           
           final String Selec[] = {"Select a target "};
           String tgtType = card.getSpellText();
           int i = 0;
           if (Destination.equals("Hand"))
           {
              i = tgtType.indexOf("return target ");
              tgtType = tgtType.substring(i + "return target ".length());
              i = tgtType.indexOf(" to its owner's hand.");
              tgtType = tgtType.substring(0, i);
              Selec[0] += tgtType + " to return.";
           }
           else if (Destination.equals("Exile"))
           {
              i = tgtType.indexOf("exile target ");
              tgtType = tgtType.substring(i + "exile target ".length());
              i = tgtType.indexOf(".");
              tgtType = tgtType.substring(0, i);
              Selec[0] += tgtType + " to exile.";
           }
           else if (Destination.equals("TopofLibrary"))
           {
              i = tgtType.indexOf("put target ".length());
              tgtType = tgtType.substring(i + "put target ".length());
              i = tgtType.indexOf(" on top of its owner's library.");
              tgtType = tgtType.substring(0, i);
              Selec[0] += tgtType + " to put on top of the library.";
           }
           else
           {
              Selec[0] = card.getSpellText();
           }
           
           final String Drawback[] = {"none"};
           if (k.length > 3)
           {
              if (k[3].startsWith("Drawback"))
                 Drawback[0] = k[3].substring("Drawback$".length());
           }
           
           final boolean Evoke[] = {false};
           if (card.getSVar("Evoke").length() > 0)
              Evoke[0] = true;
           
           card.setSVar("PlayMain1", "TRUE");
           card.clearSpellAbility();
           
           // over-rides the default Spell_Permanent
           // enables the AI to play the card when appropriate
           SpellAbility spETBBounceTgt = new Spell_Permanent(card)
           {
                private static final long serialVersionUID = -1548526222769333358L;
               
                @Override
                public boolean canPlayAI()
                {
                    Random r = new Random();
                                      
                    CardList hCards = new CardList(AllZone.getZone(Constant.Zone.Play, Constant.Player.Human).getCards());
                    hCards = hCards.getValidCards(Tgts);
                    if (hCards.size() > 0)
                       return true;
                   
                    CardList cCards = new CardList(AllZone.getZone(Constant.Zone.Play, Constant.Player.Computer).getCards());
                    cCards = cCards.getValidCards(Tgts);
                    if (cCards.size() == 0)
                       return true;
                    else
                    {
                       if (r.nextInt(100) > 67)
                          return true;
                    }
                   
                   return false;
                }
           };
           card.addSpellAbility(spETBBounceTgt);
           
           // performs the bounce
           final SpellAbility saBounceTgt = new Ability(card, "0")
           {
              @Override
              public void resolve()
              {
                 Card tgtC = getTargetCard();
                 if (tgtC == null)
                    return;
                 
                 if (AllZone.GameAction.isCardInPlay(tgtC) && CardFactoryUtil.canTarget(card, tgtC))
                 {
                    if (tgtC.isToken())
                       AllZone.getZone(tgtC).remove(tgtC);
                    else
                    {
                       if (Destination.equals("TopofLibrary"))
                          AllZone.GameAction.moveToTopOfLibrary(tgtC);
                       else if (Destination.equals("ShuffleIntoLibrary"))
                       {
                          AllZone.GameAction.moveToTopOfLibrary(tgtC);
                          AllZone.GameAction.shuffle(tgtC.getOwner());
                       }
                       else if (Destination.equals("Exile"))
                          AllZone.GameAction.removeFromGame(tgtC);
                       else if (Destination.equals("Hand"))
                          AllZone.GameAction.moveToHand(tgtC);
                    }
                    
                    if (!Drawback[0].equals("none"))
                       CardFactoryUtil.doDrawBack(Drawback[0], 0, card.getController(), AllZone.GameAction.getOpponent(card.getController()), tgtC.getController(), card, tgtC, this);
                 }
              }
           }; //saBounceTgt
           saBounceTgt.setStackDescription(card.getName() + " - bounce target.");
           
           // when the card enters the battlefield, enable the human to target
           // or the AI decides on a target
           Command etbBounceTgt = new Command()
           {
              private static final long serialVersionUID = 829702746298938287L;
              
              public void execute()
              {
                 CardList hCards = new CardList(AllZone.Human_Play.getCards());
                 CardList cCards = new CardList(AllZone.Computer_Play.getCards());
                 
                 hCards = hCards.getValidCards(Tgts);
                 cCards = cCards.getValidCards(Tgts);
                 
                 if (hCards.size() > 0 || cCards.size() > 0)
                 {
                    if (card.getController().equals(Constant.Player.Human))
                    {
                       Input inDT = CardFactoryUtil.input_targetValid(saBounceTgt, Tgts, Selec[0]);
                       
                       AllZone.InputControl.setInput(inDT);
                       
                       if (May[0] == true)
                          ButtonUtil.enableOnlyCancel();
                       else
                          ButtonUtil.disableAll();
                    }
                    else
                    {
                       Card c = new Card();
                       CardList dChoices = new CardList();
                       if (hCards.size() > 0)
                       {
                          for (int i=0; i<Tgts.length; i++)
                          {
                             if (Tgts[i].startsWith("Creature"))
                             {
                                c = CardFactoryUtil.AI_getBestCreature(hCards);
                                if (c != null)
                                   dChoices.add(c);
                             }
                             
                             CardListUtil.sortByTextLen(hCards);
                             dChoices.add(hCards.get(0));
                             
                             CardListUtil.sortCMC(hCards);
                             dChoices.add(hCards.get(0));
                          }
                          
                          c = dChoices.get(CardUtil.getRandomIndex(dChoices));
                          saBounceTgt.setTargetCard(c);
                          AllZone.Stack.add(saBounceTgt);
                       }
                       else if (cCards.size() > 0 && May[0] == false)
                       {
                          for (int i=0; i<Tgts.length; i++)
                          {
                             if (Tgts[i].startsWith("Creature"))
                             {
                                c = CardFactoryUtil.AI_getWorstCreature(cCards);
                                if (c != null)
                                   dChoices.add(c);
                             }
                             
                             CardListUtil.sortByTextLen(cCards);
                             dChoices.add(cCards.get(cCards.size() - 1));
                             
                             CardListUtil.sortCMC(cCards);
                             dChoices.add(cCards.get(cCards.size() - 1));
                          }
                          
                          c = dChoices.get(CardUtil.getRandomIndex(dChoices));
                          saBounceTgt.setTargetCard(c);
                          AllZone.Stack.add(saBounceTgt);
                       }
                    }
                 }
              }
           }; // etbBounceTgt
           card.addComesIntoPlayCommand(etbBounceTgt);
           
           // handle SVar:Evoke:{cost}
           if (Evoke[0] == true)
           {
              String EvCost = card.getSVar("Evoke");
              
              SpellAbility evBounceTgt = new Spell_Evoke(card, EvCost)
              {
                 private static final long serialVersionUID = 865327909209183746L;
                 
                 @Override
                 public boolean canPlayAI() {
                    return false;
                 }
              };
              card.addSpellAbility(evBounceTgt);
           }
        } // etbBounceTgt
The Force will be with you, Always.
User avatar
Rob Cashwalker
Programmer
 
Posts: 2167
Joined: 09 Sep 2008, 15:09
Location: New York
Has thanked: 5 times
Been thanked: 40 times

Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 55 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 55 users online :: 0 registered, 0 hidden and 55 guests (based on users active over the past 10 minutes)
Most users ever online was 7303 on 15 Jul 2025, 20:46

Users browsing this forum: No registered users and 55 guests

Login Form