Friday, March 7, 2008

Delaying Glorious Anthem

Glorious Anthem (GA) is a tough card to program and when I first started MTG Forge I had no idea if I could ever code it. Think for a second and tell me what is the difference between cards like Shock and GA? Hopefully most of you realize that GA’s effect stays around, while Shock is just a one-shot.

Thankfully I was able to implement GA with minimal fuss. GameAction already had a method called checkStateEffects() which sent creatures to the graveyard if they had enough damage and checked for legendary permanents, so I just added GA to the code. GA is actually implemented in GameActionUtil which also does upkeep effects like Juzam Djinn. There are only 17 cards that do state effects, cards like Soul Warden and Nightmare. I recently programmed Serra Avatar (power and toughness are each equal to your life total) which was a relatively simple.

And finally, design a flexible system but put off what you don’t know how to do. I didn’t know how to program GA but I didn’t sweat it. There were a hundred other things that I wanted to program first, like Shock and creature combat, and I couldn’t let myself be bogged down in details.

I thought about showing you the code for GA, but Serra Avatar is much easier to understand (and it won’t make your eyes glaze over). AllZone is a global variable that keeps track of all player zones and life totals.


//taken from GameActionUtil
//get all creatures
CardList list = new CardList();
list.addAll(AllZone.Human_Play.getCards());
list.addAll(AllZone.Computer_Play.getCards());
list = list.getName("Serra Avatar");

for(int i = 0; i < list.size(); i++)
{
Card card = list.get(i);
int n = AllZone.GameAction.getPlayerLife(card.getController()).getLife();
card.setAttack(n);
card.setDefense(n);
}//for

4 comments:

  1. hi, MTG forge is really great

    It would be possible to increase the width of the window (for high resolutions) to be able to see more card of the game at the same time.

    Thanks

    ReplyDelete
  2. Hi thanks for the praise. The answer is maybe. I have a version of MTG Forge that is resizable but it doesn't work when I package it up into a jar. MTG Forge works best at a resolution of 1024 by 768.

    ReplyDelete
  3. this is why MTGOnline has a lot of programmers working in it (actually, just a few, but they're very good)
    It isn't easy to program this. To make it work perfectly, use the layer system.
    glorious anthem creates a 6d layer effect when it is in play.
    it gives all creatures on your side a +1/+1 bonus, but only after each other effect has applied except for other anthem like effects or P/T switching effects.

    ReplyDelete
  4. My version of Glorious Anthem doesn't layer so Giant Growth effects don't work, the same goes for the card Nightmare. I know Magic Online has to check for a ton of things like layers, that currently I don't consider at all.

    ReplyDelete

Note: Only a member of this blog may post a comment.