It is currently 30 Oct 2025, 13:07
   
Text Size

Buyback spells

Post MTG Forge Related Programming Questions Here

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

Buyback spells

Postby Chris H. » 27 Oct 2009, 02:20

While working on the spRaiseDead keyword I realized that I would not be able to use this keyword to implement Disturbed Burial. I looked at the code for other buyback spells to get an idea on how to code Disturbed Burial.

Currently this spell like the other buyback spells create a difficult AI decision, as such, buyback spells are set to force the computer to only use the more expensive buyback SpellAbility.

I used zerker's Raise Dead code and I play tested this card and it works for both the computer and for us humans. Thank you, zerker.

Code: Select all
Disturbed Burial
1 B
Sorcery
no text
`
Code: Select all
   //*************** START *********** START **************************
   if (cardName.equals("Disturbed Burial"))
   {
      final int numCreatures = 1;
       final SpellAbility spell_one = new Spell(card)
       {
         private static final long serialVersionUID = -5603148360641550138L;
         public boolean canPlayAI() {return false;}   //comp can only play spell_two, not spell_one
         CardList targets;

         public void resolve()
         {
            {
               CardList grave = getGraveCreatures();
               targets = new CardList();
               if (grave.size() > numCreatures)
                  for (int i=0; i<numCreatures ; i++)
                  {
                     Card c = AllZone.Display.getChoice("Select card", grave.toArray());
                     targets.add(c);
                     grave.remove(c);
                  }
               else targets = grave;
            }
            PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, card.getController());
            PlayerZone hand = AllZone.getZone(Constant.Zone.Hand, card.getController());
            for (Card c : targets)
               if (AllZone.GameAction.isCardInZone(c, grave))
                  AllZone.GameAction.moveTo(hand, c);
         }//resolve()

         public boolean canPlay()
         {
            return getGraveCreatures().size() >= numCreatures;
         }

         CardList getGraveCreatures()
         {
            PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, card.getController());
            CardList list = new CardList(grave.getCards());
            list = list.getType("Creature");
            return list;
         }
      };//SpellAbility

       
       final SpellAbility spell_two = new Spell(card)
       {
         private static final long serialVersionUID = 4315092314767982320L;
         public boolean canPlayAI() {return getGraveCreatures().size() >= numCreatures;}
         CardList targets;

         public void chooseTargetAI()
         {
            CardList grave = getGraveCreatures();
            targets = new CardList();
            for (int i=0; i<numCreatures; i++)
            {
               Card c = CardFactoryUtil.AI_getBestCreature(grave);
               targets.add(c);
               grave.remove(c);
            }
         }

         public void resolve()
         {
            if (card.getController().equals(Constant.Player.Human))
            {
               CardList grave = getGraveCreatures();
               targets = new CardList();
               if (grave.size() > numCreatures)
                  for (int i=0; i<numCreatures ; i++)
                  {
                     Card c = AllZone.Display.getChoice("Select card", grave.toArray());
                     targets.add(c);
                     grave.remove(c);
                  }
               else targets = grave;
            }
            PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, card.getController());
            PlayerZone hand = AllZone.getZone(Constant.Zone.Hand, card.getController());
            for (Card c : targets)
               if (AllZone.GameAction.isCardInZone(c, grave))
                  AllZone.GameAction.moveTo(hand, c);
         }//resolve()

         public boolean canPlay()
         {
            return getGraveCreatures().size() >= numCreatures;
         }

         CardList getGraveCreatures()
         {
            PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, card.getController());
            CardList list = new CardList(grave.getCards());
            list = list.getType("Creature");
            return list;
         }
      };//SpellAbility
       
       spell_two.setManaCost("4 B");
       spell_one.setDescription("Return target creature card from your graveyard to your hand.");
       spell_one.setStackDescription(cardName + " - returns target card from " + card.getController() + "'s graveyard to " + card.getController() + "'s hand.");
       spell_two.setDescription("Buyback 3 - Pay 4 B , put this card into your hand as it resolves.");
       spell_two.setStackDescription(cardName + " - (Buyback) returns target card from " + card.getController() + "'s graveyard to " + card.getController() + "'s hand.");
       spell_two.setIsBuyBackAbility(true);
       
       card.clearSpellAbility();
       card.addSpellAbility(spell_one);
       card.addSpellAbility(spell_two);
   }//*************** END ************ END ****************************
`
`
Attachments
Disturbed Burial pic url.zip
(687 Bytes) Downloaded 226 times
Last edited by Chris H. on 27 Oct 2009, 10:10, edited 1 time in total.
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

Re: Buyback spells

Postby zerker2000 » 27 Oct 2009, 04:46

Pardon the intrusion, but my name has two e's :"Zerker" 8).
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: Buyback spells

Postby Chris H. » 27 Oct 2009, 10:13

zerker2000 wrote:Pardon the intrusion, but my name has two e's :"Zerker" 8).
Oh my, It was fairly late last night when I posted that message. :oops: Nonetheless, the thank you is still in effect, and a little humor helps to pass the day. :mrgreen:
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: No registered users and 23 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 23 users online :: 0 registered, 0 hidden and 23 guests (based on users active over the past 10 minutes)
Most users ever online was 9298 on 10 Oct 2025, 12:54

Users browsing this forum: No registered users and 23 guests

Login Form