Banishing Knack
Post MTG Forge Related Programming Questions Here
	Moderators: timmermac, Agetian, friarsol, Blacksmith, KrazyTheFox, CCGHQ Admins
			3 posts
			 • Page 1 of 1
		
	
Banishing Knack
 by zerker2000 » 24 Jun 2009, 09:14
by 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
. 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
, so I had to look up the whole 
cards.txt, the obvious:
			 . It turns out I was calling AllZone.<Human/Computer>_Play in CardFactory, which gets called at the beggining
. 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
, 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);
cards.txt, the obvious:
- Code: Select all
- Banishing Knack
 U
 Instant
 no text
- 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;
 }
- 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.\"");
 }
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
		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
 by DennisBergkamp » 24 Jun 2009, 15:41
by DennisBergkamp » 24 Jun 2009, 15:41 
Good job! Yeah, Input_targetSpecific is a very handy thing to know about 
			
		
- 
				 
 DennisBergkamp
- AI Programmer
- Posts: 2602
- Joined: 09 Sep 2008, 15:46
- Has thanked: 0 time
- Been thanked: 0 time
Re: Banishing Knack
 by zerker2000 » 25 Jun 2009, 09:00
by zerker2000 » 25 Jun 2009, 09:00 
Oh shoot, I found a bug in it:  . How'd that slip in anyways?
. 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)
			- Code: Select all
- PlayerZone hand = AllZone.getZone(Constant.Zone.Hand, target[0].getController());
- Code: Select all
- PlayerZone hand = AllZone.getZone(Constant.Zone.Hand, target[0].getOwner());
 . How'd that slip in anyways?
. 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
		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
			3 posts
			 • Page 1 of 1
		
	
Who is online
Users browsing this forum: No registered users and 20 guests
