It is currently 27 Apr 2024, 06:34
   
Text Size

sneak attack

Post MTG Forge Related Programming Questions Here

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

sneak attack

Postby zen » 20 Feb 2010, 12:53

here's some working sneak code. is this the proper place to post card code? or should i just submit it via svn in the future?

cards.txt
Code: Select all
Sneak Attack
3 R
Enchantment
R: Put a creature from your into play. It has haste. Sacrafice it at the end of turn.
CardFactory.java
Code: Select all
//******************START SNEAK ATTACK**************************888
    else if (cardName.equals("Sneak Attack"))
    {
       final CardList SneakCards = new CardList();
       final Command sneak = new Command()
        {
          private static final long serialVersionUID = 4511445425867383367L;

        public void execute()
          {
            if(AllZone.GameAction.isCardInPlay(card))
            {
              //put cards removed by Necropotence into player's hand
              if(SneakCards.size() > 0){
               GameAction ga = new GameAction();
                for(int i = 0;i<SneakCards.size();i++){
                  Card c = SneakCards.get(i);
                  if (ga.isCardInPlay(c)){
                     ga.sacrifice(c); // change to AllZone.GameAction.sacrifice(c); ??
                  }
                }
                SneakCards.clear();
              }
            }
          }
        };
       
       final SpellAbility ability = new Ability(card, "R")
       {
         private static final long serialVersionUID = 4414609319033894302L;
         
          public void resolve()
          {
             Card c = getTargetCard();
                  PlayerZone hand = AllZone.getZone(Constant.Zone.Hand, card.getController());
                  PlayerZone play = AllZone.getZone(Constant.Zone.Play, card.getController());

                  if(AllZone.GameAction.isCardInZone(c, hand))
                  {
                     hand.remove(c);
                     play.add(c);
                     SneakCards.add(c);
                     c.addIntrinsicKeyword("Haste");               //give c haste
                     AllZone.EndOfTurn.addAt(sneak);
                  }
          }
       };
      
       ability.setBeforePayMana(new Input()
       {
           private static final long serialVersionUID = -1647181037510967127L;

         public void showMessage()
          {
                  String controller = card.getController();
               CardList creats = new CardList(AllZone.getZone(Constant.Zone.Hand, controller).getCards());
               creats = creats.filter(new CardListFilter()
               {
               public boolean addCard(Card c)
               {
                  PlayerZone zone = AllZone.getZone(c);
                  return c.isCreature() && zone.is(Constant.Zone.Hand);
               }
                  
               });
               stopSetNext(CardFactoryUtil.input_targetSpecific(ability, creats, "Select a creature", false, false));
             }
         });
         card.addSpellAbility(ability);
    }//*************** END ************ END **************************SNEAK ATTACK
   
zen
 
Posts: 27
Joined: 13 Feb 2010, 19:21
Has thanked: 0 time
Been thanked: 0 time

Re: sneak attack

Postby DennisBergkamp » 20 Feb 2010, 19:11

It looks good to me (haven't tested it yet but if you say it works then things should be alright) ! There's a few few small things though:

1. "sacrifice" instead of "sacrafice", also try to use the latest Oracle text (I always use http://magiccards.info) :mrgreen:
2. The way we usually represent text for abilities, is to specify them in a "ability.setDescription(text);" statement. This is to make sure the ability's text will show up correctly in the selection dialog box if the card has multiple abilities. Check out the Planeswalkers for instance, they have "no text" defined in cards.txt, but all of their respective abilities are defined in CardFactory_Planeswalkers.java with setDescription() methods. In the case of Sneak Attack, your cards.txt would look like this:
Code: Select all
Sneak Attack
3 R
Enchantment
no text
and in the code block CardFactory.java:
Code: Select all
     //command and ability code above
     ....
     ability.setDescription("R: You may put a creature card from your hand onto the battlefield. That creature gains haste. Sacrifice the creature at the beginning of the next end       step.");
     card.addSpellAbility(ability);
    }//*************** END ************ END **************************SNEAK ATTACK
3. Yes, use AllZone.GameAction.sacrifice() instead of ga = new GameAction...
4. Use addExtrinsicKeyword("Haste") instead of addIntrinsicKeyword("Haste")
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 97 guests


Who is online

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

Login Form