It is currently 20 Apr 2024, 00:54
   
Text Size

Banishing Knack

Post MTG Forge Related Programming Questions Here

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

Banishing Knack

Postby zerker2000 » 24 Jun 2009, 09:14

Finally got Banishing Knack coded. That took way longer than it should have. I spent half the time hunting for a bug that disabled the ability, and gave a NullPointerError when I made a test card that had the ability directly :(. It turns out I was calling AllZone.<Human/Computer>_Play in CardFactory, which gets called at the beggining :?, so I had to look up the whole
Code: Select all
Input runtime = new Input()
      {

        private static final long serialVersionUID =<serial #>;

        public void showMessage()
            {
              CardList all = new CardList();
              all.addAll(AllZone.Human_Play.getCards());
              all.addAll(AllZone.Computer_Play.getCards());
              all = all.filter(new CardListFilter()
              {
                public boolean addCard(Card c) {
                   return (<c meets requirements> && CardFactoryUtil.canTarget(card, c));
                }
              });

              stopSetNext(CardFactoryUtil.input_targetSpecific(ability, all, <Str>, true));
            }
      };
      ability.setBeforePayMana(runtime);
concept in other cards. So anyways, here's the actual code:
cards.txt, the obvious:
Code: Select all
Banishing Knack
U
Instant
no text
Card.java, this was missing for some reason:
Code: Select all
  public void clearSpellAbility()               {spellAbility.clear();}
  public void addSpellAbility(SpellAbility a) {spellAbility.add(a);}
> public void removeSpellAbility(SpellAbility a) {spellAbility.remove(a);}
  public SpellAbility[] getSpellAbility()
  {
    SpellAbility[] s = new SpellAbility[spellAbility.size()];
    spellAbility.toArray(s);
    return s;
  }
...and CardFactory:
Code: Select all
    if(cardName.equals("Banishing Knack"))
    {
       SpellAbility spell = new Spell(card)
       {
          
          public boolean canPlayAI(){return false;}
          public void resolve()
          {
             final Card creature = getTargetCard();
             final Ability_Tap tBanish = new Ability_Tap(creature)
             {
                

                public boolean canPlayAI() {return false;}

                public void resolve()
                {
                   setStackDescription(creature+" - Return"+getTargetCard()+"to its owner's hand");
                   final Card[] target = new Card[1];
                   target[0] = getTargetCard();
                   PlayerZone hand = AllZone.getZone(Constant.Zone.Hand, target[0].getController());

                   if(AllZone.GameAction.isCardInPlay(target[0])  && CardFactoryUtil.canTarget(creature, target[0]) )
                   {
                      AllZone.GameAction.moveTo(hand ,target[0]);
                   }
                }//resolve()
             };//tBanish;
             tBanish.setDescription("T: Return target nonland permanent to its owner's hand.");
             creature.addSpellAbility(tBanish);
             CardList all = new CardList();
             all.addAll(AllZone.Human_Play.getCards());
             all.addAll(AllZone.Computer_Play.getCards());
             all = all.filter(new CardListFilter()
             {
                public boolean addCard(Card c) {
                   return (!c.isLand() && CardFactoryUtil.canTarget(creature, c));
                }
             });
             tBanish.setBeforePayMana(CardFactoryUtil.input_targetSpecific(tBanish, all, "Return target nonland permanent to its owner's hand.", true));
             AllZone.EndOfTurn.addUntil(new Command(){
                public void execute(){
                   creature.removeSpellAbility(tBanish);
                }
             });
          }
       };//SpellAbility
       spell.setBeforePayMana(CardFactoryUtil.input_targetCreature(spell));
       card.clearSpellAbility();
       card.addSpellAbility(spell);
       spell.setDescription("Until end of turn, target creature gains \"T: Return target nonland permanent to its owner's hand.\"");
       spell.setStackDescription("Target creature gains \"T: Return target nonland permanent to its owner's hand.\"");
    }
Ok, looks like that's all, if something doesn't / looks like it shouldn't work, post the problem here(, and I'll probably post the piece of code I missed).
O forest, hold thy wand'ring son
Though fears assail the door.
O foliage, cloak thy ravaged one
In vestments cut for war.


--Eladamri, the Seed of Freyalise
zerker2000
Programmer
 
Posts: 569
Joined: 09 May 2009, 21:40
Location: South Pasadena, CA
Has thanked: 0 time
Been thanked: 0 time

Re: Banishing Knack

Postby DennisBergkamp » 24 Jun 2009, 15:41

Good job! Yeah, Input_targetSpecific is a very handy thing to know about :)
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Banishing Knack

Postby zerker2000 » 25 Jun 2009, 09:00

Oh shoot, I found a bug in it:
Code: Select all
                   PlayerZone hand = AllZone.getZone(Constant.Zone.Hand, target[0].getController());
should obviously be
Code: Select all
                   PlayerZone hand = AllZone.getZone(Constant.Zone.Hand, target[0].getOwner());
:P. How'd that slip in anyways?
EDIT: traced it back, it turns out my aether spellbomb also has it, which was copied off capsize... all three have the bug.(Also, I think the capsize one just got noticed in the buglist)
O forest, hold thy wand'ring son
Though fears assail the door.
O foliage, cloak thy ravaged one
In vestments cut for war.


--Eladamri, the Seed of Freyalise
zerker2000
Programmer
 
Posts: 569
Joined: 09 May 2009, 21:40
Location: South Pasadena, CA
Has thanked: 0 time
Been thanked: 0 time


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 90 guests


Who is online

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

Login Form