It is currently 14 Sep 2025, 20:06
   
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 cyclope » 09 Oct 2009, 16:06

Here is enchant from Zendikar Goblin War-Paint:
Code: Select all
//*************** START *********** START **************************
if(cardName.equals("Goblin War-Paint"))
{
  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("Haste");
         }
      }//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("Haste");
         }
     
      }//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 I have a question: Will the keyword "RegenerateMe" function with the programmation of auras like Savage Silhouette ?
Code: Select all
//*************** START *********** START **************************
if(cardName.equals("Savage Silhouette"))
{
  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("RegenerateMe:1 G");
         }
      }//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("RegenerateMe:1 G");
         }
     
      }//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 **************************

.
cyclope
 
Posts: 69
Joined: 28 Sep 2009, 18:08
Has thanked: 0 time
Been thanked: 0 time

Re: Programming a card

Postby DennisBergkamp » 09 Oct 2009, 16:30

Yes, both Paralyzing Grasp and Savage Silhouette should work.
However, the AI targeting code for Paralyzing Grasp should be changed (it won't help the AI if he casts it on his own creatures, now would it :) ) ?
Look at the code for Weakness, there it should be correct.
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 Rob Cashwalker » 09 Oct 2009, 17:14

You can't just add "RegenerateMe" to a card's extrinsic keyword list and expect it to work. The script keywords only work when the card is created.
The Force will be with you, Always.
User avatar
Rob Cashwalker
Programmer
 
Posts: 2167
Joined: 09 Sep 2008, 15:09
Location: New York
Has thanked: 5 times
Been thanked: 40 times

Re: Programming a card

Postby DennisBergkamp » 09 Oct 2009, 17:19

Oh, you're right. Just like Fiery Mantle, it won't 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 » 11 Oct 2009, 18:44

Thanks for your answers... I have effectively some doubts on the keyword RegenerateMe in extrinsic...

I think you can add this two creatures Loxodon Mystic and Master Decoy which are similar to Goldmeadow Harrier:

Code: Select all
in CardFactory.java :

//*************** START *********** START **************************
    if (cardName.equals("Loxodon Mystic")|| cardName.equals("Master Decoy"))
    {
       final SpellAbility ability = new Ability_Tap(card, "W")
        {

         public void resolve()
           {
             Card c = getTargetCard();
             c.tap();
           }
           public boolean canPlayAI() {return false;}
        };//SpellAbility
        card.addSpellAbility(ability);
        ability.setDescription("W, tap: Tap target creature.");
        ability.setBeforePayMana(CardFactoryUtil.input_targetCreature(ability));

     }//*************** END ************ END **************************
   
in Cards.txt:

Master Decoy
1 W
Creature Human Soldier
W, Tap : Tap traget creature.
1/2

Loxodon Mystic
3 W W
Creature Elephant Cleric
W, Tap:Tap target creature.
3/3
And you could add the enchant Giant Strength:
Code: Select all
//*************** START *********** START **************************
if(cardName.equals("Giant Strength"))
{
  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);
           
         }
      }//execute()
  };//Command


  Command onUnEnchant = new Command()
  {   

   public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
        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 **************************

and in cards.txt:

Giant Strength
R R
Enchantment Aura
Enchanted Creature gets +2/+2.
cyclope
 
Posts: 69
Joined: 28 Sep 2009, 18:08
Has thanked: 0 time
Been thanked: 0 time

Re: Programming a card

Postby cyclope » 14 Oct 2009, 16:24

Hello , this time i have tried to code lands from zendikar: Akoum Refuge , Graypelt Refuge, Jwar Isle Refuge, Kazandu refuge, Seijiri Refuge and Kabira Crossroads.

Here are my codes :
Code: Select all
 in cardfactory.java
//*************** START *********** START **************************
    if(cardName.equals("Graypelt Refuge")|| cardName.equals("Seijiri Refuge")|| cardName.equals("Jwar Isle Refuge")|| cardName.equals("Akoum Refuge")|| cardName.equals("Kazandu Refuge"))
    {
      final SpellAbility ability = new Ability(card, "0")
      {
        public void resolve()
        {
          Card c = card;
          PlayerLife life = AllZone.GameAction.getPlayerLife(c.getController());
          life.addLife(1);
        }
      };
      Command intoPlay = new Command()
      {
      

      public void execute()
        {
          ability.setStackDescription(card.getName() + " - " +card.getController() +" gains 1 life");
          AllZone.Stack.add(ability);
        }
      };
      card.setComesIntoPlay(intoPlay);
    }//*************** END ************ END **************************

and in cards.txt:

Akoum Refuge
no cost
Land
Akoum Refuge comes into play tapped. When Akoum Refuge enters the battlefield, you gain 1 life.
tap: add B
tap: add R

Graypelt Refuge
no cost
Land
Graypelt Refuge comes into play tapped. When Graypelt Refuge enters the battlefield, you gain 1 life.
tap: add G
tap: add W

Jwar Isle Refuge
no cost
Land
Jwar Isle Refuge comes into play tapped. When Jwar Isle Refuge enters the battlefield, you gain 1 life.
tap: add U
tap: add B

Seijiri Refuge
no cost
Land
Seijiri Refuge comes into play tapped. When Seijiri Refuge enters the battlefield, you gain 1 life.
tap: add W
tap: add U

Kazandu Refuge
no cost
Land
Kazandu Refuge comes into play tapped. When Kazandu Refuge enters the battlefield, you gain 1 life.
tap: add R
tap: add G

 in cardfactory.java
//*************** START *********** START **************************
    if(cardName.equals("Kabira Crossroads"))
    {
      final SpellAbility ability = new Ability(card, "0")
      {
        public void resolve()
        {
          Card c = card;
          PlayerLife life = AllZone.GameAction.getPlayerLife(c.getController());
          life.addLife(2);
        }
      };
      Command intoPlay = new Command()
      {
      

      public void execute()
        {
          ability.setStackDescription(card.getName() + " - " +card.getController() +" gains 2 life");
          AllZone.Stack.add(ability);
        }
      };
      card.setComesIntoPlay(intoPlay);
    }//*************** END ************ END **************************

and in cards.txt:

Kabira Crossroads
no cost
Land
Kabira Crossroads comes into play tapped. When Kabira Crossroads enters the battlefield, you gain 2 life.
tap: add W

and i code the Spidersilk Net equipement, but I think the AI must be change but i don't know how to...
could somebody help me and tell me if my codes should work ? Thanks.

Code: Select all
 //*************** START *********** START **************************
    if (cardName.equals("Spidersilk Net"))
    {
       final Ability equip = new Ability(card, "2")
       {
          public void resolve()
          {
             if (AllZone.GameAction.isCardInPlay(getTargetCard()) && CardFactoryUtil.canTarget(card, getTargetCard()) )
             {
                if (card.isEquipping())
                {
                   Card crd = card.getEquipping().get(0);
                   if (crd.equals(getTargetCard()) )
                      return;
                   
                   card.unEquipCard(crd);
                }   
                card.equipCard(getTargetCard());
             }
          }
          
          public boolean canPlay()
          {
             return AllZone.getZone(card).is(Constant.Zone.Play) &&           
                      AllZone.Phase.getActivePlayer().equals(card.getController()) &&
                      (AllZone.Phase.getPhase().equals("Main1") || AllZone.Phase.getPhase().equals("Main2") );
          }
          
          public boolean canPlayAI()
            {
              return getCreature().size() != 0 && !card.isEquipping();
            }
         
          
          public void chooseTargetAI()
            {
              Card target = CardFactoryUtil.AI_getBestCreature(getCreature());
              setTargetCard(target);
            }
            CardList getCreature()
            {
              CardList list = new CardList(AllZone.Computer_Play.getCards());
              list = list.filter(new CardListFilter()
              {
                public boolean addCard(Card c)
                {
                  return c.isCreature() && (!CardFactoryUtil.AI_doesCreatureAttack(c)) && CardFactoryUtil.canTarget(card, c) &&
                         (! c.getKeyword().contains("Defender"));
                }
              });
              // list.remove(card);      // if mana-only cost, allow self-target
              return list;
            }//getCreature()
          
       };//equip ability
       

       Command onEquip = new Command()
       {   

         

         public void execute()
           {
            if (card.isEquipping())
             {
                Card crd = card.getEquipping().get(0);
                crd.addExtrinsicKeyword("Reach");
                crd.addSemiPermanentDefenseBoost(2);
             } 
           }//execute()
       };//Command
      

       Command onUnEquip = new Command()
       {   


         public void execute()
           {
            if (card.isEquipping())
             {
                Card crd = card.getEquipping().get(0);
                crd.removeExtrinsicKeyword("Reach");
                crd.addSemiPermanentDefenseBoost(-2);
                   
             }
            
           }//execute()
       };//Command
      
       
       Input runtime = new Input()
       {
         

         public void showMessage()
             {
               //get all creatures you control
               CardList list = new CardList();
               list.addAll(AllZone.Human_Play.getCards());
               list = list.getType("Creature");
              
               stopSetNext(CardFactoryUtil.input_targetSpecific(equip, list, "Select target creature to equip", true));
             }
        };//Input
      
       equip.setBeforePayMana(runtime);
       
       equip.setDescription("Equip: 2");
       card.addSpellAbility(equip);
       
       card.setEquip(onEquip);
       card.setUnEquip(onUnEquip);

    } //*************** END ************ END **************************
cyclope
 
Posts: 69
Joined: 28 Sep 2009, 18:08
Has thanked: 0 time
Been thanked: 0 time

Re: Programming a card

Postby DennisBergkamp » 14 Oct 2009, 17:05

Cool, yes these should all work. Except in cards.txt, make sure the "Comes into play tapped." keyword is set. For instance, Akoum Refuge should probably look like this:

Akoum Refuge
no cost
Land
When Akoum Refuge enters the battlefield, you gain 1 life.
tap: add B
tap: add R
Comes into play tapped.
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 » 14 Oct 2009, 17:21

Thanks Dennis...

Here is a code for Eviscerator:( i copy the code from Foul Imp)
Code: Select all
in cardfactory.java:
//*************** START *********** START **************************
    if(cardName.equals("Eviscerator"))
    {
      final SpellAbility ability = new Ability(card, "0")
      {
        public void resolve()
        {
          AllZone.GameAction.getPlayerLife(card.getController()).subtractLife(5);
        }
        public boolean canPlayAI()
        {
          return 4 < AllZone.Computer_Life.getLife();
        }
      };
      Command intoPlay = new Command()
      {
      

      public void execute()
        {
          ability.setStackDescription("Eviscerator - " +card.getController() +" loses 5 life");
          AllZone.Stack.add(ability);
        }
      };
      card.setComesIntoPlay(intoPlay);
    }//*************** END ************ END **************************

in cards.txt

Eviscerator
3 B B
Creature Horror
When Eviscerator comes into play you lose 5 life.
5/5
Protection from white
But i think i should change the line "return 4 < AllZone.Computer_Life.getLife();" into this "return 7 < AllZone.Computer_Life.getLife();"
Am I right ?
cyclope
 
Posts: 69
Joined: 28 Sep 2009, 18:08
Has thanked: 0 time
Been thanked: 0 time

Re: Programming a card

Postby DennisBergkamp » 14 Oct 2009, 17:27

Yes, or maybe even 8.
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 » 15 Oct 2009, 18:37

I don't know if many people read my codes but i hope they are usefull...

Here there are two artefact - equipement: No-Dachi et Shuko

Code: Select all

 //*************** START *********** START **************************
    if (cardName.equals("No-Dachi"))
    {
       final Ability equip = new Ability(card, "3")
       {
          public void resolve()
          {
             if (AllZone.GameAction.isCardInPlay(getTargetCard()) && CardFactoryUtil.canTarget(card, getTargetCard()) )
             {
                if (card.isEquipping())
                {
                   Card crd = card.getEquipping().get(0);
                   if (crd.equals(getTargetCard()) )
                      return;
                   
                   card.unEquipCard(crd);
                }   
                card.equipCard(getTargetCard());
             }
          }
          
          public boolean canPlay()
          {
             return AllZone.getZone(card).is(Constant.Zone.Play) &&           
                      AllZone.Phase.getActivePlayer().equals(card.getController()) &&
                      (AllZone.Phase.getPhase().equals("Main1") || AllZone.Phase.getPhase().equals("Main2") );
          }
          
          public boolean canPlayAI()
            {
              return getCreature().size() != 0 && !card.isEquipping();
            }
         
          
          public void chooseTargetAI()
            {
              Card target = CardFactoryUtil.AI_getBestCreature(getCreature());
              setTargetCard(target);
            }
            CardList getCreature()
            {
              CardList list = new CardList(AllZone.Computer_Play.getCards());
              list = list.filter(new CardListFilter()
              {
                public boolean addCard(Card c)
                {
                  return c.isCreature() && (!CardFactoryUtil.AI_doesCreatureAttack(c)) && CardFactoryUtil.canTarget(card, c) &&
                         (! c.getKeyword().contains("Defender"));
                }
              });
              // list.remove(card);      // if mana-only cost, allow self-target
              return list;
            }//getCreature()
          
       };//equip ability
       

       Command onEquip = new Command()
       {   

         

         public void execute()
           {
            if (card.isEquipping())
             {
                Card crd = card.getEquipping().get(0);
                crd.addExtrinsicKeyword("First Strike");
                crd.addSemiPermanentAttackBoost(2);
             } 
           }//execute()
       };//Command
      

       Command onUnEquip = new Command()
       {   


         public void execute()
           {
            if (card.isEquipping())
             {
                Card crd = card.getEquipping().get(0);
                crd.removeExtrinsicKeyword("First Strike");
                crd.addSemiPermanentAttackBoost(-2);
                   
             }
            
           }//execute()
       };//Command
      
       
       Input runtime = new Input()
       {
         

         public void showMessage()
             {
               //get all creatures you control
               CardList list = new CardList();
               list.addAll(AllZone.Human_Play.getCards());
               list = list.getType("Creature");
              
               stopSetNext(CardFactoryUtil.input_targetSpecific(equip, list, "Select target creature to equip", true));
             }
        };//Input
      
       equip.setBeforePayMana(runtime);
       
       equip.setDescription("Equip: 3");
       card.addSpellAbility(equip);
       
       card.setEquip(onEquip);
       card.setUnEquip(onUnEquip);

    } //*************** END ************ END **************************



 //*************** START *********** START **************************
    if (cardName.equals("Shuko"))
    {
       final Ability equip = new Ability(card, "0")
       {
          public void resolve()
          {
             if (AllZone.GameAction.isCardInPlay(getTargetCard()) && CardFactoryUtil.canTarget(card, getTargetCard()) )
             {
                if (card.isEquipping())
                {
                   Card crd = card.getEquipping().get(0);
                   if (crd.equals(getTargetCard()) )
                      return;
                   
                   card.unEquipCard(crd);
                }   
                card.equipCard(getTargetCard());
             }
          }
          
          public boolean canPlay()
          {
             return AllZone.getZone(card).is(Constant.Zone.Play) &&           
                      AllZone.Phase.getActivePlayer().equals(card.getController()) &&
                      (AllZone.Phase.getPhase().equals("Main1") || AllZone.Phase.getPhase().equals("Main2") );
          }
          
          public boolean canPlayAI()
            {
              return getCreature().size() != 0 && !card.isEquipping();
            }
         
          
          public void chooseTargetAI()
            {
              Card target = CardFactoryUtil.AI_getBestCreature(getCreature());
              setTargetCard(target);
            }
            CardList getCreature()
            {
              CardList list = new CardList(AllZone.Computer_Play.getCards());
              list = list.filter(new CardListFilter()
              {
                public boolean addCard(Card c)
                {
                  return c.isCreature() && (!CardFactoryUtil.AI_doesCreatureAttack(c)) && CardFactoryUtil.canTarget(card, c) &&
                         (! c.getKeyword().contains("Defender"));
                }
              });
              // list.remove(card);      // if mana-only cost, allow self-target
              return list;
            }//getCreature()
          
       };//equip ability
       

       Command onEquip = new Command()
       {   

         

         public void execute()
           {
            if (card.isEquipping())
             {
                Card crd = card.getEquipping().get(0);
                
                crd.addSemiPermanentDefenseBoost(1);
             } 
           }//execute()
       };//Command
      

       Command onUnEquip = new Command()
       {   


         public void execute()
           {
            if (card.isEquipping())
             {
                Card crd = card.getEquipping().get(0);
                
                crd.addSemiPermanentDefenseBoost(-1);
                   
             }
            
           }//execute()
       };//Command
      
       
       Input runtime = new Input()
       {
         

         public void showMessage()
             {
               //get all creatures you control
               CardList list = new CardList();
               list.addAll(AllZone.Human_Play.getCards());
               list = list.getType("Creature");
              
               stopSetNext(CardFactoryUtil.input_targetSpecific(equip, list, "Select target creature to equip", true));
             }
        };//Input
      
       equip.setBeforePayMana(runtime);
       
       equip.setDescription("Equip: 0");
       card.addSpellAbility(equip);
       
       card.setEquip(onEquip);
       card.setUnEquip(onUnEquip);

    } //*************** END ************ END **************************

And some enchants: Vigilance , Mageta's Boon, Tiger Claws, Buoyancy, Feast of the Unicorn and Mask of Law and Grace:
Code: Select all
//*************** START *********** START **************************
if(cardName.equals("Vigilance"))
{
  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("Vigilance");
         }
      }//execute()
  };//Command


  Command onUnEnchant = new Command()
  {   

   public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
           
      crd.removeExtrinsicKeyword("Vigilance");
         }
     
      }//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 **************************



//*************** START *********** START **************************
if(cardName.equals("Mageta's Boon"))
{
  final SpellAbility spell = new Spell(card)
  {

   
   
   //for flash, keyword somehow doesn't work
   public boolean canPlay()
   {
      return true;
   }
   
   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(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 **************************


//*************** START *********** START **************************
if(cardName.equals("Tiger Claws"))
{
  final SpellAbility spell = new Spell(card)
  {

   
   
   //for flash, keyword somehow doesn't work
   public boolean canPlay()
   {
      return true;
   }
   
   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(1);
            crd.addSemiPermanentDefenseBoost(1);
       crd.addExtrinsicKeyword("Trample");
         }
      }//execute()
  };//Command


  Command onUnEnchant = new Command()
  {   

   
   public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
            crd.addSemiPermanentAttackBoost(-1);               
            crd.addSemiPermanentDefenseBoost(-1);
      crd.removeExtrinsicKeyword("Trample");
         }
     
      }//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 **************************



//*************** START *********** START **************************
if(cardName.equals("Feast of the Unicorn"))
{
  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(4);
            
           
         }
      }//execute()
  };//Command


  Command onUnEnchant = new Command()
  {   

   public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
        crd.addSemiPermanentAttackBoost(-4);
          
           
         }
     
      }//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 **************************


//*************** START *********** START **************************
if(cardName.equals("Buoyancy"))
{
  final SpellAbility spell = new Spell(card)
  {

   
   
   //for flash, keyword somehow doesn't work
   public boolean canPlay()
   {
      return true;
   }
   
   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");
           
       
         }
      }//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 **************************


//*************** START *********** START **************************
if(cardName.equals("Mask of Law and Grace"))
{
  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("Protection from black");
      crd.addExtrinsicKeyword("Protection from red");
         }
      }//execute()
  };//Command


  Command onUnEnchant = new Command()
  {   

   public void execute()
      {
         if (card.isEnchanting())
         {
            Card crd = card.getEnchanting().get(0);
           
      crd.removeExtrinsicKeyword("Protection from black");
      crd.removeExtrinsicKeyword("Protection from red");
         }
     
      }//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 **************************

cyclope
 
Posts: 69
Joined: 28 Sep 2009, 18:08
Has thanked: 0 time
Been thanked: 0 time

Re: Programming a card

Postby cyclope » 18 Oct 2009, 13:32

Can anybody tells me if this code for Benalish Heralds is correct please ?

Code: Select all
//*************** START *********** START **************************
    if (cardName.equals("Benalish Heralds"))
    {
       final SpellAbility ability = new Ability_Tap(card, "3 U")
        {
      public boolean canPlayAI() {return false;}
       
         public void resolve()
           {
            AllZone.GameAction.drawCard(card.getController());
           }
           
        };//SpellAbility
        card.addSpellAbility(ability);
        ability.setDescription("3 U, tap: Draw a card.");
        ability.setBeforePayMana(runtime);

     }//*************** END ************ END **************************
I'm not sure for the last line "ability.setBeforePayMana...)

I think we could also add Benalish Trapper to the cards ( it is the same as Goldmeadow Harrier...)
cyclope
 
Posts: 69
Joined: 28 Sep 2009, 18:08
Has thanked: 0 time
Been thanked: 0 time

Re: Programming a card

Postby cyclope » 18 Oct 2009, 18:11

I hope that somebody will read this... I need help... I want to code the card Nightscape Master...

Here is my code:
Code: Select all
//*************** START *********** START **************************
    if (cardName.equals("Nightscape Master"))
    {
       final SpellAbility ability = new Ability_Tap(card, "U U")
        {
      public boolean canPlayAI()
        {
          CardList human = CardFactoryUtil.AI_getHumanCreature(card, true);
          return 3 < AllZone.Phase.getTurn() && 0 < human.size();
        }
        public void chooseTargetAI()
        {
          CardList human = CardFactoryUtil.AI_getHumanCreature(card, true);
          setTargetCard(CardFactoryUtil.AI_getBestCreature(human));
        }

        public void resolve()
        {
          if(AllZone.GameAction.isCardInPlay(getTargetCard()) && CardFactoryUtil.canTarget(card, getTargetCard()) )
          {
            if(getTargetCard().isToken())
              AllZone.getZone(getTargetCard()).remove(getTargetCard());
            else
            {
              PlayerZone hand = AllZone.getZone(Constant.Zone.Hand, getTargetCard().getOwner());
              @SuppressWarnings("unused") // play
           PlayerZone play = AllZone.getZone(Constant.Zone.Play, getTargetCard().getOwner());
              AllZone.GameAction.moveTo(hand, getTargetCard());
             
              //play.remove(getTargetCard());
              //hand.add(getTargetCard());
            }
          }//if
        }//resolve()
     
 final SpellAbility ability2 = new Ability_Tap(card,"R R")
       {
      

      public boolean canPlayAI()
        {
          CardList c = getCreature();
          if(c.isEmpty())
            return false;
          else
          {
            setTargetCard(c.get(0));
            return true;
          }
        }//canPlayAI()
        CardList getCreature()
        {
          CardList out = new CardList();
          CardList list = CardFactoryUtil.AI_getHumanCreature("Flying", card, true);
          list.shuffle();

          for(int i = 0; i < list.size(); i++)
            if((list.get(i).getNetAttack() >= 2) && (list.get(i).getNetDefense() <= 2))
              out.add(list.get(i));

          //in case human player only has a few creatures in play, target anything
          if(out.isEmpty() &&
              0 < CardFactoryUtil.AI_getHumanCreature(2, card, true).size() &&
             3 > CardFactoryUtil.AI_getHumanCreature(card, true).size())
          {
            out.addAll(CardFactoryUtil.AI_getHumanCreature(2, card, true).toArray());
            CardListUtil.sortFlying(out);
          }
          return out;
        }//getCreature()


        public void resolve()
        {
          if(AllZone.GameAction.isCardInPlay(getTargetCard()) && CardFactoryUtil.canTarget(card, getTargetCard()) )
          {
            getTargetCard().addDamage(2);
           
          }
        }//resolve()

         }; //ability2
      
       card.addSpellAbility(ability);
   ability.setBeforePayMana(CardFactoryUtil.input_targetCreature(ability));    ability.setDescription("U U, tap: Return target creature to its owner's hand.")
      
      
       card.addSpellAbility(ability2);
   ability2.setDescription("R R,Tap : Nightscape Master deals 2 damage to target creature");
       ability2.setBeforePayMana(CardFactoryUtil.input_targetCreature(ability));
      
  }//*************** END ************ END **************************
I'm not sure for the ending lines ...

Can anyone explain me where in the code must i have to add "private static final long serialVersionUID" in Eclipse ...

I know how to open the source as a new project from source, i know how to make a executable jar file and now and want to know how to do to make a "beta" of mtgforge in order to test my future codes...
cyclope
 
Posts: 69
Joined: 28 Sep 2009, 18:08
Has thanked: 0 time
Been thanked: 0 time

Re: Programming a card

Postby zerker2000 » 18 Oct 2009, 18:22

cyclope wrote:Can anybody tells me if this code for Benalish Heralds is correct please ?

Code: Select all
//*************** START *********** START **************************
    if (cardName.equals("Benalish Heralds"))
    {
       final SpellAbility ability = new Ability_Tap(card, "3 U")
        {
      public boolean canPlayAI() {return false;}
       
         public void resolve()
           {
            AllZone.GameAction.drawCard(card.getController());
           }
           
        };//SpellAbility
        card.addSpellAbility(ability);
        ability.setDescription("3 U, tap: Draw a card.");
        ability.setBeforePayMana(runtime);

     }//*************** END ************ END **************************
I'm not sure for the last line "ability.setBeforePayMana...)
Yes, there isn't a BeforePayMana input to set, so that line shouldn't be there. Other than that, and the fact that classically descriptions are set before the ability is added to the card, it looks like it should work.
I think we could also add Benalish Trapper to the cards ( it is the same as Goldmeadow Harrier...)
Yes, that should be inserted into that card's if block.

EDIT:Nightscape Commander's first ability looks like it should work, I think the second should be keyworded using abDamage though.
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 » 18 Oct 2009, 18:33

Thanks Zerker

I thought the "abDamage" keyword enables to target creature or player but i only want to traget creature ...
cyclope
 
Posts: 69
Joined: 28 Sep 2009, 18:08
Has thanked: 0 time
Been thanked: 0 time

Re: Programming a card

Postby Chris H. » 18 Oct 2009, 20:15

Can anyone explain me where in the code must i have to add "private static final long serialVersionUID" in Eclipse ...
`
It comes after the final SpellAbility ability = new Ability_Tap(card, "3 U"). It would look like this:

Code: Select all
       final SpellAbility ability = new Ability_Tap(card, "3 U")
        {
              private static final long serialVersionUID =

`
I know how to open the source as a new project from source, i know how to make a executable jar file and now and want to know how to do to make a "beta" of mtgforge in order to test my future codes...
`
Add your code to the appropriate java file and save this file. Build the project with the project menu.

Look at the problems listed to see if there are any problems and fix them.

Then run the project that you just built. Select the Run -> Run As -> Java Application option and select the file listed named Gui_NewGame.

And before you run the build you want to place a copy of the "forge.properties" file and the "res" folder into the root level of your forge project. You should add the cards.txt information for the card that you are coding to the cards.txt file that is located in the "res" folder located in your project.
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

PreviousNext

Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 45 guests

Main Menu

User Menu

Our Partners


Who is online

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

Login Form