It is currently 25 Apr 2024, 00:27
   
Text Size

Zur the Enchanter

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

Zur the Enchanter

Postby DennisBergkamp » 03 Oct 2008, 05:31

I've been looking at some of the code for Combat.java and CombatUtil.java. I decided to add Zur the Enchanter, and here it is! Very strong card, and fun to play with, would probably go well with Bitterblossom, Glorious Anthem or the recently added Megrim just to name a few enchantments in MTGForge.

In CombatUtil.java, I'm not sure if this is the ideal place to stuff the code into, but it seemed to made sense to me. I put it way at the end, after getPlanesWalkerBlockers():

Code: Select all
 //.... above here is all the getPlaneswalkerBlockers() code
}//getPlaneswalkerBlockers()
 
private static void checkDeclareAttackers(Card c) //this method checks triggered effects of attacking creatures, right before defending player declares blockers
  {
     if (AllZone.Phase.getPhase().equals("Declare Attackers"))
     {
        if(c.getName().equals("Zur the Enchanter"))
        {
           PlayerZone library = AllZone.getZone(Constant.Zone.Library, c.getController());
           PlayerZone play = AllZone.getZone(Constant.Zone.Play, c.getController());
          
             CardList enchantments = new CardList(library.getCards());
             enchantments = enchantments.getType("Enchantment");         
            
             if (enchantments.size() > 0) {
                for(int i=0;i < enchantments.size();i++)
                {
                   Card c1 = enchantments.get(i);
                   if (CardUtil.getConvertedManaCost(c1.getManaCost()) > 3)
                      enchantments.remove(c1); // get rid of all enchantments with a converted manacost higher than 3
                  
                }
            
               
                if (c.getController().equals("Human"))
                {
                   Object o = AllZone.Display.getChoiceOptional("Pick an enchantment to put into play", enchantments.toArray());
                   if(o != null)
                   {
                      library.remove(o);
                      play.add((Card)o);
                      AllZone.GameAction.shuffle(c.getController());
                   }
                }
                else if (c.getController().equals("Computer"))
                {
                   Card card = enchantments.get(0);
                   library.remove(card);
                   play.add(card);
                   AllZone.GameAction.shuffle(c.getController());
                }
             }
               
        }//zur the enchanter
       
     }
  }//checkDeclareAttackers
Then, call this method (also in CombatUtil.java) in showCombat(), right at the beginning of the for-loop:

Code: Select all
   // ....   
   //loop through attackers
    for(int i = 0; i < attack.length; i++)
    {
      checkDeclareAttackers(attack[i]);
      display += attack[i].getName() +" (" +attack[i].getUniqueNumber() +") "  +attack[i].getAttack() +"/" +attack[i].getDefense()   +" is attacking \n";
      //... etc
Then in cards.txt:


Code: Select all
Zur the Enchanter
1 W U B
Legendary Creature Human Wizard
Whenever Zur the Enchanter attacks, you may search your library for an enchantment card with converted mana cost 3 or less and put it into play. If you do, shuffle your library.
1/4
Flying
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Zur the Enchanter

Postby jpb » 03 Oct 2008, 16:17

Very nice! Now we should be able to add some creatures with some pretty cool abilities triggered by declaring them attackers.
jpb
 
Posts: 132
Joined: 05 Sep 2008, 13:12
Has thanked: 0 time
Been thanked: 0 time

Re: Zur the Enchanter

Postby mtgrares » 03 Oct 2008, 16:59

(I guess people know who I am, but I'll tell you just in case you don't.) As the author of MTG Forge I have to say, very nice code.
mtgrares
DEVELOPER
 
Posts: 1352
Joined: 08 Sep 2008, 22:10
Has thanked: 3 times
Been thanked: 12 times

Re: Zur the Enchanter

Postby DennisBergkamp » 03 Oct 2008, 17:29

Thanks guys!
However, it's not perfect. I just realized, I'm not putting any of these triggered abilities on the stack :(
This became a little more clear after I just implemented a few cards with a slightly different triggered ability, namely "Whenever creature deals combat damage to a player".
I made Hypnotic Specter, Shadowmage Infiltrator and Thieving Magpie just to test things out.... they work perfectly fine, except stuff does not get added to the stack, unfortunately. This would be nice for rules-sake, but also just to see what's going on exactly.

I have to turn these triggered abilities into SpellAbilities I suppose, so I can do setStackDescriptions, but I'm not exactly sure how #-o

EDIT: I guess the stack display won't matter too much in case of Zur the Enchanter and other cards that trigger right away as one is attacking, but it's necessary for creatures that trigger when combat damage is dealt to a player. Even though I got the actual cards to work (I attacked with my Shadowmage Infiltrator, Thieving Magpie and Hypnotic Specter and I ended up with 2 extra cards in my hand and my opponent ended up discarding a card at random), it seemed too sudden, and didn't notify me of anything. The code for triggering on "deals combat damage to a player" I put in Combat.java:

Code: Select all
private static void checkCombatDamageTriggers(Card c) //not sure if trample gets factored in...
  {
   if (c.getName().equals("Hypnotic Specter") && (c.getAttack() > 0))
   {
      String opponent = AllZone.GameAction.getOpponent(c.getController());
      AllZone.GameAction.discardRandom(opponent);         
   
   }//Hypnotic Specter
   
   else if ( (c.getName().equals("Shadowmage Infiltrator")) || (c.getName().equals("Thieving Magpie")) && (c.getAttack() > 0))
   {
      AllZone.GameAction.drawCard(c.getController());      
   }
   
  } //checkCombatDamageTriggers
Very simple, and probably not nearly finished. Then I call this method in the setDefendingDamage() method (this seems to deal with unblocked damage) :

Code: Select all
public void setDefendingDamage()
  {
    defendingDamage = 0;
    CardList att = new CardList(getAttackers());
    //sum unblocked attackers' power
    for(int i = 0; i < att.size(); i++)
      if(! isBlocked(att.get(i))) {
        defendingDamage += att.get(i).getAttack();
        checkCombatDamageTriggers(att.get(i)); //<==== here
       
      }
  }
Does anyone know if there's an easy way of adding in a stack trace for those abilities ?
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time


Return to Forge

Who is online

Users browsing this forum: No registered users and 158 guests

cron

Who is online

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

Login Form