It is currently 12 Sep 2025, 22:45
   
Text Size

Programming a card

Post MTG Forge Related Programming Questions Here

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

Re: Programming a card

Postby DennisBergkamp » 01 Oct 2009, 16:37

Ah true, this is trickier. I've done something similar with the card Squirrel Nest... I remember it took me hours to fix all the little bugs :(

Cyclope, the rest looks great :) I've added all of them, except for Spirit Loop (I can see this card being used as more of a defensive card, as opposed to Armadillo Cloak), I will add that one as soon as I've coded the way they should actually work.
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Programming a card

Postby cyclope » 01 Oct 2009, 19:12

Good , i'm happy that some of my codes can be used...
Here there are some more codes for various enchants:

For Flight:
Code: Select all
//*************** START *********** START **************************
if(cardName.equals("Flight"))
{
  final SpellAbility spell = new Spell(card)
  {

   public boolean canPlayAI()
    {
      CardList list = new CardList(AllZone.Computer_Play.getCards());
      list = list.getType("Creature");

      if(list.isEmpty())
       return false;

      //else
      CardListUtil.sortAttack(list);
      CardListUtil.sortFlying(list);

      setTargetCard(list.get(0));
      return true;
    }//canPlayAI()
    public void resolve()
    {
      PlayerZone play = AllZone.getZone(Constant.Zone.Play, card.getController());
      play.add(card);
     
      Card c = getTargetCard();
     
      if(AllZone.GameAction.isCardInPlay(c)  && CardFactoryUtil.canTarget(card, c) )
      {
         card.enchantCard(c);
         System.out.println("Enchanted: " +getTargetCard());
      }
    }//resolve()
  };//SpellAbility
  card.clearSpellAbility();
  card.addSpellAbility(spell);
 
  Command onEnchant = new Command()
  {   

   public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
            crd.addExtrinsicKeyword("Flying");
                     } 
      }//execute()
  };//Command
 

  Command onUnEnchant = new Command()
  {   
   

      public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
            crd.removeExtrinsicKeyword("Flying");
            
         }
      
      }//execute()
   };//Command
   
   Command onLeavesPlay = new Command()
   {
   
   public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
            card.unEnchantCard(crd);
         }
      }
   };
 
  card.setEnchant(onEnchant);
  card.setUnEnchant(onUnEnchant);
  card.setLeavesPlay(onLeavesPlay);
 
  spell.setBeforePayMana(CardFactoryUtil.input_targetCreature(spell));
}//*************** END ************ END **************************
For Spirit Link:
Code: Select all
//*************** START *********** START **************************
if(cardName.equals("Spirit Link"))
{
  final SpellAbility spell = new Spell(card)
  {

   public boolean canPlayAI()
    {
      CardList list = new CardList(AllZone.Computer_Play.getCards());
      list = list.getType("Creature");

      if(list.isEmpty())
       return false;

      //else
      CardListUtil.sortAttack(list);
      CardListUtil.sortFlying(list);

      setTargetCard(list.get(0));
      return true;
    }//canPlayAI()
    public void resolve()
    {
      PlayerZone play = AllZone.getZone(Constant.Zone.Play, card.getController());
      play.add(card);
     
      Card c = getTargetCard();
     
      if(AllZone.GameAction.isCardInPlay(c)  && CardFactoryUtil.canTarget(card, c) )
      {
         card.enchantCard(c);
         System.out.println("Enchanted: " +getTargetCard());
      }
    }//resolve()
  };//SpellAbility
  card.clearSpellAbility();
  card.addSpellAbility(spell);
 
  Command onEnchant = new Command()
  {   

   public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
            crd.addExtrinsicKeyword("Lifelink");
                     } 
      }//execute()
  };//Command
 

  Command onUnEnchant = new Command()
  {   
   

      public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
            crd.removeExtrinsicKeyword("Lifelink");
            
         }
      
      }//execute()
   };//Command
   
   Command onLeavesPlay = new Command()
   {
   
   public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
            card.unEnchantCard(crd);
         }
      }
   };
 
  card.setEnchant(onEnchant);
  card.setUnEnchant(onUnEnchant);
  card.setLeavesPlay(onLeavesPlay);
 
  spell.setBeforePayMana(CardFactoryUtil.input_targetCreature(spell));
}//*************** END ************ END **************************
For Wings of Hope:
Code: Select all
//*************** START *********** START **************************
if(cardName.equals("Wings of Hope"))
{
  final SpellAbility spell = new Spell(card)
  {

   public boolean canPlayAI()
    {
      CardList list = new CardList(AllZone.Computer_Play.getCards());
      list = list.getType("Creature");

      if(list.isEmpty())
       return false;

      //else
      CardListUtil.sortAttack(list);
      CardListUtil.sortFlying(list);

      setTargetCard(list.get(0));
      return true;
    }//canPlayAI()
    public void resolve()
    {
      PlayerZone play = AllZone.getZone(Constant.Zone.Play, card.getController());
      play.add(card);
     
      Card c = getTargetCard();
     
      if(AllZone.GameAction.isCardInPlay(c)  && CardFactoryUtil.canTarget(card, c) )
      {
         card.enchantCard(c);
         System.out.println("Enchanted: " +getTargetCard());
      }
    }//resolve()
  };//SpellAbility
  card.clearSpellAbility();
  card.addSpellAbility(spell);
 
  Command onEnchant = new Command()
  {   

   public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
            crd.addExtrinsicKeyword("Flying");
            crd.addSemiPermanentAttackBoost(1);
            crd.addSemiPermanentDefenseBoost(3);
         } 
      }//execute()
  };//Command
 

  Command onUnEnchant = new Command()
  {   
   

      public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
            crd.removeExtrinsicKeyword("Flying");
            crd.addSemiPermanentAttackBoost(-1);               
            crd.addSemiPermanentDefenseBoost(-3);
         }
      
      }//execute()
   };//Command
   
   Command onLeavesPlay = new Command()
   {
   
   public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
            card.unEnchantCard(crd);
         }
      }
   };
 
  card.setEnchant(onEnchant);
  card.setUnEnchant(onUnEnchant);
  card.setLeavesPlay(onLeavesPlay);
 
  spell.setBeforePayMana(CardFactoryUtil.input_targetCreature(spell));
}//*************** END ************ END **************************
For Serra's Embrace:
Code: Select all
//*************** START *********** START **************************
if(cardName.equals("Serra's Embrace"))
{
  final SpellAbility spell = new Spell(card)
  {

   public boolean canPlayAI()
    {
      CardList list = new CardList(AllZone.Computer_Play.getCards());
      list = list.getType("Creature");

      if(list.isEmpty())
       return false;

      //else
      CardListUtil.sortAttack(list);
      CardListUtil.sortFlying(list);

      setTargetCard(list.get(0));
      return true;
    }//canPlayAI()
    public void resolve()
    {
      PlayerZone play = AllZone.getZone(Constant.Zone.Play, card.getController());
      play.add(card);
     
      Card c = getTargetCard();
     
      if(AllZone.GameAction.isCardInPlay(c)  && CardFactoryUtil.canTarget(card, c) )
      {
         card.enchantCard(c);
         System.out.println("Enchanted: " +getTargetCard());
      }
    }//resolve()
  };//SpellAbility
  card.clearSpellAbility();
  card.addSpellAbility(spell);
 
  Command onEnchant = new Command()
  {   

   public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
            crd.addExtrinsicKeyword("Flying");
            crd.addExtrinsicKeyword("Vigilance");
            crd.addSemiPermanentAttackBoost(2);
            crd.addSemiPermanentDefenseBoost(2);
         } 
      }//execute()
  };//Command
 

  Command onUnEnchant = new Command()
  {   
   

      public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
            crd.removeExtrinsicKeyword("Flying");
            crd.removeExtrinsicKeyword("Vigilance");
            crd.addSemiPermanentAttackBoost(-2);               
            crd.addSemiPermanentDefenseBoost(-2);
         }
      
      }//execute()
   };//Command
   
   Command onLeavesPlay = new Command()
   {
   
   public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
            card.unEnchantCard(crd);
         }
      }
   };
 
  card.setEnchant(onEnchant);
  card.setUnEnchant(onUnEnchant);
  card.setLeavesPlay(onLeavesPlay);
 
  spell.setBeforePayMana(CardFactoryUtil.input_targetCreature(spell));
}//*************** END ************ END **************************
I hope these are correct ...
cyclope
 
Posts: 69
Joined: 28 Sep 2009, 18:08
Has thanked: 0 time
Been thanked: 0 time

Re: Programming a card

Postby cyclope » 01 Oct 2009, 19:34

Oh , i forgot this: i think to implement the sorcery Recover , we can do:

Code: Select all
add: ||cardName.equals("Recover"), in cardfactory where it is :
 if(cardName.equals("Raise Dead") || cardName.equals("Disentomb"))
and add in cards.txt:
Code: Select all
Recover
2 B
Sorcery
Return target creature card from your graveyard to your hand.
Draw a card.
Cantrip
cyclope
 
Posts: 69
Joined: 28 Sep 2009, 18:08
Has thanked: 0 time
Been thanked: 0 time

Re: Programming a card

Postby silly freak » 01 Oct 2009, 19:54

i don't know if "draw a card" is necessary with cantrip, but i'm not the expert ;)

i'm glad you enjoy what you do, and it seems you are pretty successful with it. Programming can be very interesting and even fun when you enjoy those logical things. keep your enthusiasm, it's the most helpful thing for learning you can get!
___

where's the "trust me, that will work!" switch for the compiler?
Laterna Magica - blog, forum, project, 2010/09/06 release!
silly freak
DEVELOPER
 
Posts: 598
Joined: 26 Mar 2009, 07:18
Location: Vienna, Austria
Has thanked: 93 times
Been thanked: 25 times

Re: Programming a card

Postby DennisBergkamp » 01 Oct 2009, 19:57

Ah yes, silly freak is right. It should look like this:

Code: Select all
Recover
2 B
Sorcery
Return target creature card from your graveyard to your hand. Draw a card.
Cantrip
But thanks, I see over 2000 cards in my local version now :)
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Programming a card

Postby cyclope » 01 Oct 2009, 20:03

Thanks for your words , Silly Freak...
In fact, i'll try to code some cards because I appreciate playing Magic the Gathering and I want MTG Forge to have more and more cards...
But I'm not a programmer , I'm just a french Mathematics teacher...and I love playing with logical...

Here is an another code, for the instant Sprout
Code: Select all
 //*************** START *********** START **************************
    if(cardName.equals("Sprout"))
    {
      SpellAbility spell = new Spell(card)
      {

      public void resolve()
        {   
         makeToken();
        }
      public void makeToken()
      {
          PlayerZone play = AllZone.getZone(Constant.Zone.Play, card.getController());
          Card c = new Card();

          c.setOwner(card.getController());
          c.setController(card.getController());

          c.setName("G 1 1 Saproling");
          c.setManaCost("G");
          c.setToken(true);

          c.addType("Creature");
          c.addType("Saproling");
          c.setBaseAttack(1);
          c.setBaseDefense(1);

          play.add(c);

        }//resolve()
      };
     
      spell.setDescription("Put a 1/1 green Saproling creature token into play.");
      spell.setStackDescription(card.getController() + " put a 1/1 green Saproling creature token into play.");
     
      card.clearSpellAbility();
      card.addSpellAbility(spell);
          }//*************** END ************ END **************************
Tell me if there are some errors...
And again, thanks for your advice...
cyclope
 
Posts: 69
Joined: 28 Sep 2009, 18:08
Has thanked: 0 time
Been thanked: 0 time

Re: Programming a card

Postby cyclope » 03 Oct 2009, 12:58

Hi , here is two new cards:

Nourish:
Code: Select all
//*************** START *********** START **************************
    if(cardName.equals("Nourish") )
    {
      SpellAbility spell = new Spell(card)
      {

      public boolean canPlay()
        {
          setStackDescription(card.getName() +" - " +card.getController() +" gains 6 life.");
          return super.canPlay();
        }

        public void resolve()
        {
          PlayerLife life = AllZone.GameAction.getPlayerLife(card.getController());
          life.addLife(6);
        }
      };
      spell.setDescription("You gain 6 life.");

      card.clearSpellAbility();
      card.addSpellAbility(spell);
  }//*************** END ************ END **************************
and Cloak of Mists
Code: Select all
//*************** START *********** START **************************
if(cardName.equals("Cloak of Mists"))
{
  final SpellAbility spell = new Spell(card)
  {

   public boolean canPlayAI()
    {
      CardList list = new CardList(AllZone.Computer_Play.getCards());
      list = list.getType("Creature");

      if(list.isEmpty())
       return false;

      //else
      CardListUtil.sortAttack(list);
      CardListUtil.sortFlying(list);

      setTargetCard(list.get(0));
      return true;
    }//canPlayAI()
    public void resolve()
    {
      PlayerZone play = AllZone.getZone(Constant.Zone.Play, card.getController());
      play.add(card);
     
      Card c = getTargetCard();
     
      if(AllZone.GameAction.isCardInPlay(c)  && CardFactoryUtil.canTarget(card, c) )
      {
         card.enchantCard(c);
         System.out.println("Enchanted: " +getTargetCard());
      }
    }//resolve()
  };//SpellAbility
  card.clearSpellAbility();
  card.addSpellAbility(spell);
 
  Command onEnchant = new Command()
  {   

   public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
            crd.addExtrinsicKeyword("Unblockable");
         }
      }//execute()
  };//Command
 

  Command onUnEnchant = new Command()
  {   

   public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
            crd.removeExtrinsicKeyword("Unblockable");
         }
     
      }//execute()
   };//Command
   
   Command onLeavesPlay = new Command()
   {


   public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
            card.unEnchantCard(crd);
         }
      }
   };
 
  card.setEnchant(onEnchant);
  card.setUnEnchant(onUnEnchant);
  card.setLeavesPlay(onLeavesPlay);
 
  spell.setBeforePayMana(CardFactoryUtil.input_targetCreature(spell));
}//*************** END ************ END **************************
If there are some errors , could someone tells me...
And i have a question : How Mass Hysteria is coded ?
I can't find it in cardfactory...
I think that Absolute Law could be similary coded.
cyclope
 
Posts: 69
Joined: 28 Sep 2009, 18:08
Has thanked: 0 time
Been thanked: 0 time

Re: Programming a card

Postby cyclope » 03 Oct 2009, 13:22

An another one: Soulscour:
Code: Select all
//*************** START *********** START **************************
   if (cardName.equals("Soulscour") )
   {
      SpellAbility spell = new Spell(card)
      {

         public void resolve()
         {
            CardList all = new CardList();
            all.addAll(AllZone.Human_Play.getCards());
            all.addAll(AllZone.Computer_Play.getCards());

            for (int i = 0; i < all.size(); i++)
            {
               Card c = all.get(i);
               if (c.isPermanent() && !c.isArtifact())
                  AllZone.GameAction.destroy(c);
            }
         }// resolve()

         public boolean canPlayAI()
         {
            CardList human = new CardList(AllZone.Human_Play.getCards());
            CardList computer = new CardList(AllZone.Computer_Play.getCards());

            human = human.getType("Creature");
            computer = computer.getType("Creature");

            // the computer will at least destroy 2 more human creatures
            return computer.size() < human.size() - 1 ||
            (AllZone.Computer_Life.getLife() < 7 && !human.isEmpty());
         }
      };// SpellAbility
      card.clearSpellAbility();
      card.addSpellAbility(spell);
   }// *************** END ************ END **************************
and other: Cleanfall
Code: Select all
//*************** START *********** START **************************
    if(cardName.equals("Cleanfall") )
    {
      final SpellAbility spell = new Spell(card)
      {
     
      public void resolve()
        {
          CardList all = new CardList();
          all.addAll(AllZone.Human_Play.getCards());
          all.addAll(AllZone.Computer_Play.getCards());

          for(int i = 0; i < all.size(); i++)
          {
            Card c = all.get(i);
           if (c.isEnchantment())
      AllZone.GameAction.destroy(c);
         
          }
        }//resolve()
      };//SpellAbility

      card.clearSpellAbility();
      card.addSpellAbility(spell);
    }//*************** END ************ END **************************
Rep me if the code is wrong.
cyclope
 
Posts: 69
Joined: 28 Sep 2009, 18:08
Has thanked: 0 time
Been thanked: 0 time

Re: Programming a card

Postby cyclope » 03 Oct 2009, 15:07

I code this other one: Indomitable Will

Code: Select all
in cardfactory.java:
//*************** START *********** START **************************
if(cardName.equals("Indomitable Will"))
{
  final SpellAbility spell = new Spell(card)
  {
      
   public boolean canPlay()
   {
      return true; // for flash, which is not working through the keyword for some reason
   }
   
   public boolean canPlayAI()
    {
      CardList list = new CardList(AllZone.Computer_Play.getCards());
      list = list.getType("Creature");

      if(list.isEmpty())
       return false;

      //else
      CardListUtil.sortAttack(list);
      CardListUtil.sortFlying(list);

      setTargetCard(list.get(0));
      return true;
    }//canPlayAI()
    public void resolve()
    {
      PlayerZone play = AllZone.getZone(Constant.Zone.Play, card.getController());
      play.add(card);
     
      Card c = getTargetCard();
     
      if(AllZone.GameAction.isCardInPlay(c)  && CardFactoryUtil.canTarget(card, c) )
      {
         card.enchantCard(c);
         System.out.println("Enchanted: " +getTargetCard());
      }
    }//resolve()
  };//SpellAbility
  card.clearSpellAbility();
  card.addSpellAbility(spell);
 
  Command onEnchant = new Command()
  {   
   

   public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
            crd.addSemiPermanentAttackBoost(1);
            crd.addSemiPermanentDefenseBoost(2);
         } 
      }//execute()
  };//Command
 

  Command onUnEnchant = new Command()
  {   
      
   
      public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
            
            crd.addSemiPermanentAttackBoost(-1);               
            crd.addSemiPermanentDefenseBoost(-2);
         }
      
      }//execute()
   };//Command
   
   Command onLeavesPlay = new Command()
   {
   

   public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
            card.unEnchantCard(crd);
         }
      }
   };
 
  card.setEnchant(onEnchant);
  card.setUnEnchant(onUnEnchant);
  card.setLeavesPlay(onLeavesPlay);
 
  spell.setBeforePayMana(CardFactoryUtil.input_targetCreature(spell));
}//*************** END ************ END **************************

in cards.txt:
Indomitable Will
1 W
Enchantment
Enchant creature. Enchanted creature gets +1/+2.
Flash
Is it good or not ?
cyclope
 
Posts: 69
Joined: 28 Sep 2009, 18:08
Has thanked: 0 time
Been thanked: 0 time

Re: Programming a card

Postby DennisBergkamp » 03 Oct 2009, 15:12

They all look good to me, except (this is something I forgot to mention) on the canPlayAI() code for the auras:

Code: Select all
 public boolean canPlayAI()
    {
      CardList list = new CardList(AllZone.Computer_Play.getCards());
      list = list.getType("Creature");

      if(list.isEmpty())
       return false;

      //else
      CardListUtil.sortAttack(list);
      CardListUtil.sortFlying(list);

      setTargetCard(list.get(0));
      return true;
    }//canPlayAI()
Should actually look like this:

Code: Select all
public boolean canPlayAI()
    {
      CardList list = new CardList(AllZone.Computer_Play.getCards());
      list = list.getType("Creature");

      if(list.isEmpty())
       return false;

      //else
      CardListUtil.sortAttack(list);
      CardListUtil.sortFlying(list);

      for (int i=0;i<list.size();i++) {
         if (CardFactoryUtil.canTarget(card, list.get(i)))
         {
            setTargetCard(list.get(i));
            return true;
         }
      }
      return false;
    }//canPlayAI()
This is to ensure that the AI won't try to target creatures that can't be targeted (protection from x, shroud, etc.).
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Programming a card

Postby zerker2000 » 03 Oct 2009, 17:42

cyclope wrote:Nourish:
Am I missing something?
Code: Select all
Nourish
G G
Instant
You gain 6 life.
spGainLife:6
I think that Absolute Law could be similary coded
Then be sure to include Absolute Grace.
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: Programming a card

Postby cyclope » 04 Oct 2009, 13:33

I tried today to code the card Filigree Angel...
Code: Select all
in cardfactory.java:

//*************** START *********** START **************************
    if(cardName.equals("Filigree Angel"))
    {
      final SpellAbility ability = new Ability(card, "0")
      {
        public void resolve()
        {
          int n = countArtifacts();

          PlayerLife life = AllZone.GameAction.getPlayerLife(card.getController());
            life.addLife(3*n);

        }
   int countArtifacts()
        {
          PlayerZone play = AllZone.getZone(Constant.Zone.Play, card.getController());
          CardList list = new CardList(play.getCards());
          list = list.getType("Artifact");
          return list.size();
        }

      };
      Command intoPlay = new Command()
      {

      public void execute()
        {
          ability.setStackDescription(card.getName() + " - " +card.getController() +" gains 3 life for each artifact he controls");
          AllZone.Stack.add(ability);
        }
      };
      card.setComesIntoPlay(intoPlay);
    }//*************** END ************ END **************************

in cards.txt:
Filigranee Angel
5 W W U
Artifact Creature Angel
Flying. When Filigree Angel enters the battlefield, you gain 3 life for each artifact you control.
4/4
Flying

I'm not sure this will work...Could anybody help me please ?

And I'm searching how to code cards with "each (color) creatures you control gains X/x or "keyword" " ...I think its in a .java file but which java file ? Combat.Java ? CombatUtil.java ?
cyclope
 
Posts: 69
Joined: 28 Sep 2009, 18:08
Has thanked: 0 time
Been thanked: 0 time

Re: Programming a card

Postby cyclope » 04 Oct 2009, 19:05

What about these new codes:

For Robe of Mirrors:
Code: Select all
//*************** START *********** START **************************
if(cardName.equals("Robe of Mirrors"))
{
  final SpellAbility spell = new Spell(card)
  {

   public boolean canPlayAI()
    {
      CardList list = new CardList(AllZone.Computer_Play.getCards());
      list = list.getType("Creature");

      if(list.isEmpty())
       return false;

      //else
      CardListUtil.sortAttack(list);
      CardListUtil.sortFlying(list);

      for (int i=0;i<list.size();i++) {
         if (CardFactoryUtil.canTarget(card, list.get(i)))
         {
            setTargetCard(list.get(i));
            return true;
         }
      }
      return false;
    }//canPlayAI()
    public void resolve()
    {
      PlayerZone play = AllZone.getZone(Constant.Zone.Play, card.getController());
      play.add(card);
     
      Card c = getTargetCard();
     
      if(AllZone.GameAction.isCardInPlay(c)  && CardFactoryUtil.canTarget(card, c) )
      {
         card.enchantCard(c);
         System.out.println("Enchanted: " +getTargetCard());
      }
    }//resolve()
  };//SpellAbility
  card.clearSpellAbility();
  card.addSpellAbility(spell);

  Command onEnchant = new Command()
  {   

   public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
            crd.addExtrinsicKeyword("Shroud");
         }
      }//execute()
  };//Command


  Command onUnEnchant = new Command()
  {   

   public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
            crd.removeExtrinsicKeyword("Shroud");
         }
     
      }//execute()
   };//Command
   
   Command onLeavesPlay = new Command()
   {


   public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
            card.unEnchantCard(crd);
         }
      }
   };

  card.setEnchant(onEnchant);
  card.setUnEnchant(onUnEnchant);
  card.setLeavesPlay(onLeavesPlay);

  spell.setBeforePayMana(CardFactoryUtil.input_targetCreature(spell));
}//*************** END ************ END **************************
For Fear:
Code: Select all
//*************** START *********** START **************************
if(cardName.equals("Fear"))
{
  final SpellAbility spell = new Spell(card)
  {

   public boolean canPlayAI()
    {
      CardList list = new CardList(AllZone.Computer_Play.getCards());
      list = list.getType("Creature");

      if(list.isEmpty())
       return false;

      //else
      CardListUtil.sortAttack(list);
      CardListUtil.sortFlying(list);

      for (int i=0;i<list.size();i++) {
         if (CardFactoryUtil.canTarget(card, list.get(i)))
         {
            setTargetCard(list.get(i));
            return true;
         }
      }
      return false;
    }//canPlayAI()
    public void resolve()
    {
      PlayerZone play = AllZone.getZone(Constant.Zone.Play, card.getController());
      play.add(card);
     
      Card c = getTargetCard();
     
      if(AllZone.GameAction.isCardInPlay(c)  && CardFactoryUtil.canTarget(card, c) )
      {
         card.enchantCard(c);
         System.out.println("Enchanted: " +getTargetCard());
      }
    }//resolve()
  };//SpellAbility
  card.clearSpellAbility();
  card.addSpellAbility(spell);

  Command onEnchant = new Command()
  {   

   public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
            crd.addExtrinsicKeyword("Fear");
         }
      }//execute()
  };//Command


  Command onUnEnchant = new Command()
  {   

   public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
            crd.removeExtrinsicKeyword("Fear");
         }
     
      }//execute()
   };//Command
   
   Command onLeavesPlay = new Command()
   {


   public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
            card.unEnchantCard(crd);
         }
      }
   };

  card.setEnchant(onEnchant);
  card.setUnEnchant(onUnEnchant);
  card.setLeavesPlay(onLeavesPlay);

  spell.setBeforePayMana(CardFactoryUtil.input_targetCreature(spell));
}//*************** END ************ END **************************
For Battle Mastery:
Code: Select all
//*************** START *********** START **************************
if(cardName.equals("Battle Mastery"))
{
  final SpellAbility spell = new Spell(card)
  {

   public boolean canPlayAI()
    {
      CardList list = new CardList(AllZone.Computer_Play.getCards());
      list = list.getType("Creature");

      if(list.isEmpty())
       return false;

      //else
      CardListUtil.sortAttack(list);
      CardListUtil.sortFlying(list);

      for (int i=0;i<list.size();i++) {
         if (CardFactoryUtil.canTarget(card, list.get(i)))
         {
            setTargetCard(list.get(i));
            return true;
         }
      }
      return false;
    }//canPlayAI()
    public void resolve()
    {
      PlayerZone play = AllZone.getZone(Constant.Zone.Play, card.getController());
      play.add(card);
     
      Card c = getTargetCard();
     
      if(AllZone.GameAction.isCardInPlay(c)  && CardFactoryUtil.canTarget(card, c) )
      {
         card.enchantCard(c);
         System.out.println("Enchanted: " +getTargetCard());
      }
    }//resolve()
  };//SpellAbility
  card.clearSpellAbility();
  card.addSpellAbility(spell);

  Command onEnchant = new Command()
  {   

   public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
            crd.addExtrinsicKeyword("Double Strike");
         }
      }//execute()
  };//Command


  Command onUnEnchant = new Command()
  {   

   public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
            crd.removeExtrinsicKeyword("Double Strike");
         }
     
      }//execute()
   };//Command
   
   Command onLeavesPlay = new Command()
   {


   public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
            card.unEnchantCard(crd);
         }
      }
   };

  card.setEnchant(onEnchant);
  card.setUnEnchant(onUnEnchant);
  card.setLeavesPlay(onLeavesPlay);

  spell.setBeforePayMana(CardFactoryUtil.input_targetCreature(spell));
}//*************** END ************ END **************************
For Protective Bubble:
Code: Select all
//*************** START *********** START **************************
if(cardName.equals("Protective Bubble"))
{
  final SpellAbility spell = new Spell(card)
  {

   public boolean canPlayAI()
    {
      CardList list = new CardList(AllZone.Computer_Play.getCards());
      list = list.getType("Creature");

      if(list.isEmpty())
       return false;

      //else
      CardListUtil.sortAttack(list);
      CardListUtil.sortFlying(list);

      for (int i=0;i<list.size();i++) {
         if (CardFactoryUtil.canTarget(card, list.get(i)))
         {
            setTargetCard(list.get(i));
            return true;
         }
      }
      return false;
    }//canPlayAI()
    public void resolve()
    {
      PlayerZone play = AllZone.getZone(Constant.Zone.Play, card.getController());
      play.add(card);
     
      Card c = getTargetCard();
     
      if(AllZone.GameAction.isCardInPlay(c)  && CardFactoryUtil.canTarget(card, c) )
      {
         card.enchantCard(c);
         System.out.println("Enchanted: " +getTargetCard());
      }
    }//resolve()
  };//SpellAbility
  card.clearSpellAbility();
  card.addSpellAbility(spell);

  Command onEnchant = new Command()
  {   

   public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
            crd.addExtrinsicKeyword("Shroud");
       crd.addExtrinsicKeyword("Unblockable");
         }
      }//execute()
  };//Command


  Command onUnEnchant = new Command()
  {   

   public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
            crd.removeExtrinsicKeyword("Shroud");
      crd.removeExtrinsicKeyword("Unblockable");
         }
     
      }//execute()
   };//Command
   
   Command onLeavesPlay = new Command()
   {


   public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
            card.unEnchantCard(crd);
         }
      }
   };

  card.setEnchant(onEnchant);
  card.setUnEnchant(onUnEnchant);
  card.setLeavesPlay(onLeavesPlay);

  spell.setBeforePayMana(CardFactoryUtil.input_targetCreature(spell));
}//*************** END ************ END **************************
For Zephyr Net
Code: Select all
//*************** START *********** START **************************
if(cardName.equals("Zephyr Net"))
{
  final SpellAbility spell = new Spell(card)
  {

   public boolean canPlayAI()
    {
      CardList list = new CardList(AllZone.Computer_Play.getCards());
      list = list.getType("Creature");

      if(list.isEmpty())
       return false;

      //else
      CardListUtil.sortAttack(list);
      CardListUtil.sortFlying(list);

      for (int i=0;i<list.size();i++) {
         if (CardFactoryUtil.canTarget(card, list.get(i)))
         {
            setTargetCard(list.get(i));
            return true;
         }
      }
      return false;
    }//canPlayAI()
    public void resolve()
    {
      PlayerZone play = AllZone.getZone(Constant.Zone.Play, card.getController());
      play.add(card);
     
      Card c = getTargetCard();
     
      if(AllZone.GameAction.isCardInPlay(c)  && CardFactoryUtil.canTarget(card, c) )
      {
         card.enchantCard(c);
         System.out.println("Enchanted: " +getTargetCard());
      }
    }//resolve()
  };//SpellAbility
  card.clearSpellAbility();
  card.addSpellAbility(spell);

  Command onEnchant = new Command()
  {   

   public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
            crd.addExtrinsicKeyword("Flying");
       crd.addExtrinsicKeyword("Defender");
         }
      }//execute()
  };//Command


  Command onUnEnchant = new Command()
  {   

   public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
            crd.removeExtrinsicKeyword("Flying");
      crd.removeExtrinsicKeyword("Defender");
         }
     
      }//execute()
   };//Command
   
   Command onLeavesPlay = new Command()
   {


   public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
            card.unEnchantCard(crd);
         }
      }
   };

  card.setEnchant(onEnchant);
  card.setUnEnchant(onUnEnchant);
  card.setLeavesPlay(onLeavesPlay);

  spell.setBeforePayMana(CardFactoryUtil.input_targetCreature(spell));
}//*************** END ************ END **************************
and for Uncontrollable Anger :
Code: Select all
//*************** START *********** START **************************
if(cardName.equals("Uncontrollable Anger"))
{
  final SpellAbility spell = new Spell(card)
  {

   public boolean canPlayAI()
    {
      CardList list = new CardList(AllZone.Computer_Play.getCards());
      list = list.getType("Creature");

      if(list.isEmpty())
       return false;

      //else
      CardListUtil.sortAttack(list);
      CardListUtil.sortFlying(list);

      for (int i=0;i<list.size();i++) {
         if (CardFactoryUtil.canTarget(card, list.get(i)))
         {
            setTargetCard(list.get(i));
            return true;
         }
      }
      return false;
    }//canPlayAI()
    public void resolve()
    {
      PlayerZone play = AllZone.getZone(Constant.Zone.Play, card.getController());
      play.add(card);
     
      Card c = getTargetCard();
     
      if(AllZone.GameAction.isCardInPlay(c)  && CardFactoryUtil.canTarget(card, c) )
      {
         card.enchantCard(c);
         System.out.println("Enchanted: " +getTargetCard());
      }
    }//resolve()
  };//SpellAbility
  card.clearSpellAbility();
  card.addSpellAbility(spell);

  Command onEnchant = new Command()
  {   

   public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
            crd.addSemiPermanentAttackBoost(2);
            crd.addSemiPermanentDefenseBoost(2);
       crd.addExtrinsicKeyword("This card attacks each turn if able");
         }
      }//execute()
  };//Command


  Command onUnEnchant = new Command()
  {   

   public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
            crd.addSemiPermanentAttackBoost(-2);               
            crd.addSemiPermanentDefenseBoost(-2);
      crd.removeExtrinsicKeyword("This card attacks each turn if able");
         }
     
      }//execute()
   };//Command
   
   Command onLeavesPlay = new Command()
   {


   public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
            card.unEnchantCard(crd);
         }
      }
   };

  card.setEnchant(onEnchant);
  card.setUnEnchant(onUnEnchant);
  card.setLeavesPlay(onLeavesPlay);

  spell.setBeforePayMana(CardFactoryUtil.input_targetCreature(spell));
}//*************** END ************ END **************************


Don't hesitate to tell me if it contains errors...

Can anybody tell me how to use Eclipse to compile and use the cards I code in order to test them?
cyclope
 
Posts: 69
Joined: 28 Sep 2009, 18:08
Has thanked: 0 time
Been thanked: 0 time

Re: Programming a card

Postby DennisBergkamp » 04 Oct 2009, 19:40

It looks like these should all work...

check here for some pointers on how to create a project in eclipse:
viewtopic.php?f=52&t=1093&hilit=eclipse+project
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Programming a card

Postby zerker2000 » 05 Oct 2009, 06:57

cyclope wrote:And I'm searching how to code cards with "each (color) creatures you control gains X/x or "keyword" " ...I think its in a .java file but which java file ? Combat.Java ? CombatUtil.java ?
Not too hard to make:
Code: Select all
CardList targets = new CardList(AllZone.getZone(Constant.Zone.Play, card.getController()).getCards());
targets = targets.getColor(/* i.e. */"W");
for (Card c : targets)
{
//spPumpTgt.resolve code copied,
//uses attack[0], defence[0] and keyword[0]
//for "X/x or keyword"

final Card[] target = {c};
             
             final Command untilEOT = new Command()
             {
                private static final long serialVersionUID = -42244224L;
               
                public void execute()
                {
                   if (AllZone.GameAction.isCardInPlay(target[0]))
                   {
                      target[0].addTempAttackBoost(-attack[0]);
                      target[0].addTempDefenseBoost(-defense[0]);
                     
                      if (!keyword[0].equals("none"))
                         target[0].removeExtrinsicKeyword(keyword[0]);
                   }
                }
             };
             
             target[0] = getTargetCard();
             if (AllZone.GameAction.isCardInPlay(target[0]) && CardFactoryUtil.canTarget(card, target[0]))
                {
                   target[0].addTempAttackBoost(attack[0]);
                   target[0].addTempDefenseBoost(defense[0]);
                   if (!keyword[0].equals("none"))
                      target[0].addExtrinsicKeyword(keyword[0]);
                   
                   AllZone.EndOfTurn.addUntil(untilEOT);
                }

//end copy
}
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

PreviousNext

Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 82 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 82 users online :: 0 registered, 0 hidden and 82 guests (based on users active over the past 10 minutes)
Most users ever online was 7967 on 09 Sep 2025, 23:08

Users browsing this forum: No registered users and 82 guests

Login Form