It is currently 08 Sep 2025, 17:03
   
Text Size

New Keyword: abTapDestroyTgt

Post MTG Forge Related Programming Questions Here

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

New Keyword: abTapDestroyTgt

Postby slapshot5 » 13 Sep 2010, 17:11

I've added a new keyword: abTapDestroyTgt

It takes all the same options as spDestroyTgt minus the Buyback stuff. (Code was copied from spDestroyTgt and modified.)

Here is the code in CardFactory.java:
Code: Select all
// Generic destroy target card ability
        // can probably be adapted for tap and non-tap abilities
        if(hasKeyword(card, "abTapDestroyTgt") != -1) {
            int n = hasKeyword(card, "abTapDestroyTgt");
           
            String parse = card.getKeyword().get(n).toString();
            card.removeIntrinsicKeyword(parse);
           
            String k[] = parse.split(":");
            String Targets = k[1]; // Artifact, Creature, Enchantment, Land, Permanent, 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
            final String Tgts[] = Targets.split(",");
            String tmpDesc = card.getText().substring(20);
            int i = tmpDesc.indexOf(".");
            tmpDesc = tmpDesc.substring(0, i);
            final String Selec = "Select target " + tmpDesc + " to destroy.";
           
            final boolean NoRegen[] = {false};
            final String Drawback[] = {"none"};
           
            if (k.length > 2)
            {
                if (k[2].equals("NoRegen"))
                    NoRegen[0] = true;
               
                else if (k[2].startsWith("Drawback$"))
                    Drawback[0] = k[2];
                               
                if (k.length > 3)
                {
                    if (k[3].startsWith("Drawback$"))
                        Drawback[0] = k[3];
                }
               
                if (!Drawback[0].equals("none"))
                {
                    String kk[] = Drawback[0].split("\\$");
                    Drawback[0] = kk[1];
                }
            }
           
            final Ability abDstryTgt = new Ability(card, "0") {
                private static final long serialVersionUID = -4414033187065934909L;

                @Override
                public boolean canPlayAI() {
                    CardList results = new CardList();
                    CardList choices = getTargets();
                   
                    choices = choices.filter(new CardListFilter(){
                        public boolean addCard(Card c)
                        {
                            return !c.getKeyword().contains("Indestructible");
                        }
                    });
                   
                   
                    if(choices.size() > 0) {
                        for(int i = 0; i < Tgts.length; i++) {
                            if(Tgts[i].startsWith("Artifact")) {
                                if(CardFactoryUtil.AI_getBestArtifact(choices) != null) results.add(CardFactoryUtil.AI_getBestArtifact(choices));
                            } else if(Tgts[i].startsWith("Creature")) {
                                if(CardFactoryUtil.AI_getBestCreature(choices) != null) results.add(CardFactoryUtil.AI_getBestCreature(choices));
                            } else if(Tgts[i].startsWith("Enchantment")) {
                                if(CardFactoryUtil.AI_getBestEnchantment(choices, card, true) != null) results.add(CardFactoryUtil.AI_getBestEnchantment(
                                        choices, card, true));
                            } else if(Tgts[i].startsWith("Land")) {
                                if(CardFactoryUtil.AI_getBestLand(choices) != null) results.add(CardFactoryUtil.AI_getBestLand(choices));
                            } else if(Tgts[i].startsWith("Permanent")) {
                                if(CardFactoryUtil.AI_getMostExpensivePermanent(choices, card, true) != null) results.add(CardFactoryUtil.AI_getMostExpensivePermanent(
                                        choices, card, true));
                            }
                        }
                    }
                   
                    if(results.size() > 0) {
                        results.shuffle();
                        setTargetCard(results.get(0));
                        return true;
                    }
                    return false;
                }
               
                CardList getTargets() {
                    CardList tmpList = new CardList();
                    tmpList.addAll(AllZone.Human_Play.getCards());
                    tmpList = tmpList.filter(new CardListFilter() {
                        public boolean addCard(Card c) {
                            return (CardFactoryUtil.canTarget(card, c));
                        }
                    });
                   
                    return tmpList.getValidCards(Tgts);
                }
               
                @Override
                public void resolve()
                {
                    card.tap();
                    Card tgtC = getTargetCard();
                    if(AllZone.GameAction.isCardInPlay(tgtC) && CardFactoryUtil.canTarget(card, tgtC))
                    {
                        if(NoRegen[0])
                            AllZone.GameAction.destroyNoRegeneration(tgtC);
                        else
                            AllZone.GameAction.destroy(tgtC);
                       
                        if (!Drawback[0].equals("none"))
                            CardFactoryUtil.doDrawBack(Drawback[0], 0, card.getController(), AllZone.GameAction.getOpponent(card.getController()), tgtC.getController(), card, tgtC, this);
                    }
                }
            }; //AbDstryTgt
           
            Input InGetTarget = CardFactoryUtil.input_targetValid(abDstryTgt, Tgts, Selec);
           
            abDstryTgt.setBeforePayMana(InGetTarget);
           
            abDstryTgt.setDescription(card.getSpellText());
            card.setText("");
           
            card.setSVar("PlayMain1", "TRUE");
           
            card.addSpellAbility(abDstryTgt);
         }//abTapDestroyTgt
and an Example:
Code: Select all
King Suleiman
1 W
Creature Human
tap: Destroy target Djinn or Efreet.
1/1
abTapDestroyTgt:Creature.Djinn,Creature.Efreet
SVars:Rarity:Rare
SVars:Picture:http://www.wizards.com/global/images/magic/general/king_suleiman.jpg
-slapshot5
slapshot5
Programmer
 
Posts: 1391
Joined: 03 Jan 2010, 17:47
Location: Mac OS X
Has thanked: 25 times
Been thanked: 68 times

Re: New Keyword: abTapDestroyTgt

Postby Rob Cashwalker » 13 Sep 2010, 18:12

I have already done this keyword, and it takes any cost provided by Ability_Cost. It hasn't been committed yet, as I was waiting for friarsol to revise the Ability_Cost taking-over the targeting of the ability itself.
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

Re: New Keyword: abTapDestroyTgt

Postby Sloth » 14 Sep 2010, 07:28

Rob Cashwalker wrote:I have already done this keyword, and it takes any cost provided by Ability_Cost. It hasn't been committed yet, as I was waiting for friarsol to revise the Ability_Cost taking-over the targeting of the ability itself.
I'm sure slapshot5 won't mind you updating this keyword once Ability_Cost has been revised, Rob.

I would also remove the "Tap" from the keyword name, since there are some cards that can destroy permanents without tapping.

abTapDestroyTgt => abDestroyTgt T

This should be future compatible with Ability_Cost.
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times

Re: New Keyword: abTapDestroyTgt

Postby slapshot5 » 16 Sep 2010, 18:48

Sounds good. Thanks guys.

-slapshot5
slapshot5
Programmer
 
Posts: 1391
Joined: 03 Jan 2010, 17:47
Location: Mac OS X
Has thanked: 25 times
Been thanked: 68 times


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 48 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 48 users online :: 0 registered, 0 hidden and 48 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 48 guests

Login Form