It is currently 24 Apr 2024, 09:36
   
Text Size

Defense of the Heart

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

Defense of the Heart

Postby jpb » 24 Sep 2008, 00:38

I recently completed a set of Urza's Legacy, and to celebrate here is the code for Defense of the Heart. Currently creatures you select do not have their come into play effects honored. This is because of a limitation in MTG Forge which would require quite a bit of work to get right.

Add this before Black Vise's entry in GameActionUtil.java's executeUpkeepEffects()
Code: Select all
upkeep_Defense_of_the_Heart();
Add this after GameActionUril.java's executeUpkeepEffects()

Code: Select all
  private static void upkeep_Defense_of_the_Heart()
  {
    final String player = AllZone.Phase.getActivePlayer();
    final String opponent = AllZone.GameAction.getOpponent(player);
   
    PlayerZone playZone =  AllZone.getZone(Constant.Zone.Play, player);
   
    //check if opponent has 3 or more creatures in play
    PlayerZone opponentZone = AllZone.getZone(Constant.Zone.Play,opponent);
    CardList opponentList = new CardList(opponentZone.getCards());
    opponentList = opponentList.getType("Creature");
    System.out.println("opponent has "+opponentList.size()+" creatures");
    for(int i=0;i<opponentList.size();i++){
       Card tmpCard = opponentList.get(i);
       System.out.println("opponent has: "+tmpCard);
    }
   
    if(3 > opponentList.size()){
       //they do not have 3 or more creatures in play, so Defense of the Heart would not be able to be sacrificed.
       return;
    }
   
    //opponent has more than 3 creatures in play, so check if Defense of the Heart is in play and sacrifice it for the effect.
    CardList list = new CardList(playZone.getCards());
    list = list.getName("Defense of the Heart");

    if(0 < list.size())
    {
     //loop through the number of Defense of the Heart's that player controls. They could control 1, 2, 3, or 4 of them.
     for(int i=0;i<list.size();i++){
        final Card card = list.get(i);
        Ability ability = new Ability(list.get(0), "0")
         {
           public void resolve()
           {
            PlayerZone library = AllZone.getZone(Constant.Zone.Library, card.getController());
             PlayerZone play    = AllZone.getZone(Constant.Zone.Play   , card.getController());
               
             //sacrifice Defense of the Heart
            AllZone.GameAction.sacrifice(card);
             //search library for a creature, put it into play
            Card creature1 = getCreatureFromLibrary();
            if(creature1 == null){
              return; //if they didn't select 2 creatures the effect fizzles.
            }
           
            //temporarily remove creature1 from the library. need to put it back if this spell fizzles.
            library.remove(creature1);
            AllZone.GameAction.shuffle(card.getController());
           
             //search library for a second creature, put it into play
            Card creature2 = getCreatureFromLibrary();
            if(creature2 == null){
               //they didn't select the second creature, so the effect fizzles.
               //need to back out the removal of creature1 from the library and shuffle
               library.add(creature1);
               AllZone.GameAction.shuffle(card.getController());
               return;
            }
           
            //if we got this far the effect was good
            library.remove(creature2);
            AllZone.GameAction.shuffle(card.getController());
           
            play.add(creature1);
            play.add(creature2);   
           }
           public Card getCreatureFromLibrary(){
               PlayerZone library = AllZone.getZone(Constant.Zone.Library, card.getController());

               CardList creatureList = new CardList(library.getCards());
               creatureList = creatureList.getType("Creature");

               Object o = AllZone.Display.getChoiceOptional("Choose a creature card", creatureList.toArray());
               if(o != null)
               {
                 Card creature = (Card)o;
                 return creature;
               }
               else{
                  return null;
               }
           }
         };//Ability

         ability.setStackDescription("Defense of the Heart - " +player +" sacrifices Defense of the Heart to search their library for up to two creature cards and put those creatures into play. Then shuffle's their library.");
         AllZone.Stack.add(ability);
        card.addSpellAbility(ability);
       
     }
    }//if
  }//upkeep_Defense_of_the_Heart
Add this to cards.txt
Code: Select all
Defense of the Heart
3 G
Enchantment
At the beginning of your upkeep, if an opponent controls three or more creatures, sacrifice Defense of the Heart to search your library for up to two creature cards and put those creatures into play. Then shuffle your library.
I did not test this well at all. I also didn't add AI since I haven't looked into adding AI for cards not in CardFactory.java. AI wouldn't be too hard for this card. Just need to have the AI select the 2 highest costing creatures in it's library. Other than that it is the same code as what is there.
jpb
 
Posts: 132
Joined: 05 Sep 2008, 13:12
Has thanked: 0 time
Been thanked: 0 time

Re: Defense of the Heart

Postby GandoTheBard » 24 Sep 2008, 00:48

This card is very situational and it seems like the AI would be hard put to make GOOD use of it. Finding the highest casting cost creatures doesnt necessarily sound like good plays...as I said its highly situational. But good work on coding this. Now to get all your codes into a compiled version for the rest of us to use :)
visit my personal homepage here: http://outofthebrokensky.com

Listen to my podcast with famed AJ_Impy "Freed from the Real" on http://puremtgo.com
User avatar
GandoTheBard
Tester
 
Posts: 1043
Joined: 06 Sep 2008, 18:43
Has thanked: 0 time
Been thanked: 0 time

Re: Defense of the Heart

Postby jpb » 24 Sep 2008, 01:51

The AI of MTG Forge is not the best. Everyone admits that. In most of the cases dealing with creatures it values them based on their cost or power and if it has flying. This is the most bang for the buck in terms of programming. It take about 1 minute to code something to determine the best creature based on cost, power, and flying. It would take a whole new AI approach or many hours of programming to determine the best creature for the situation.

I am not going to compile or distribute MTG Forge. Things will get messy if the code forks. I will leave that up to forge himself to put the code in and release a version. He has been pretty good at getting my changes in quickly.
jpb
 
Posts: 132
Joined: 05 Sep 2008, 13:12
Has thanked: 0 time
Been thanked: 0 time

Re: Defense of the Heart

Postby DennisBergkamp » 24 Sep 2008, 03:52

Great job, looks like a fun card to play! I'll test it out myself.

I looked through your code as well, I think there might be one mistake (easy to fix though), because you have it fizzle whenever you only search for one creature. It says "up to two creatures", so I think you should be able to only fetch one creature and put it into play.
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Defense of the Heart

Postby jpb » 24 Sep 2008, 07:57

You are right. So this should not fizzle if you select 0 or 1 creatures. I will change the code tomorrow and repost it. Nice catch!
jpb
 
Posts: 132
Joined: 05 Sep 2008, 13:12
Has thanked: 0 time
Been thanked: 0 time


Return to Forge

Who is online

Users browsing this forum: No registered users and 75 guests


Who is online

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

Login Form