It is currently 01 Nov 2025, 02:43
   
Text Size

Commands in GameActionUtil

Post MTG Forge Related Programming Questions Here

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

Commands in GameActionUtil

Postby friarsol » 28 Oct 2010, 17:24

Does anyone know anything about these Commands?

I was looking through them because their triggered abilities are causing NullPointerErrors for me, but I don't have time to go through and fix all of them right now. The gist of it is that instead of attaching the Ability to the card that triggers them, these commands just attach it to a blank card that has no meta-data.

The new Phase structure uses this information to follow the rules a bit closer, attempting to mimic Priority. I understand that Triggered Abilities shouldn't really change the Active Player, so once Triggered Abilities are working properly it should be easy enough to ignore them when determining ActivePlayer.

Here's a block of code about one of the Commands I'm talking about:
Code: Select all
// Reach of Branches
public static Command Reach_of_Branches           = new Command() {
   private static final long serialVersionUID = 9191592685635589492L;

   CardList                  oldForest        = new CardList();

   public void execute() {
      // count card "Reach of Branches" in graveyard
      final Player player = AllZone.Phase.getPlayerTurn();
      final PlayerZone grave = AllZone.getZone(
            Constant.Zone.Graveyard, player);
      CardList tempList = new CardList(grave.getCards());
      final CardList nCard = tempList.getName("Reach of Branches");

      // get all Forest that player has
      final PlayerZone play = AllZone.getZone(
            Constant.Zone.Play, player);
      CardList newForest = new CardList(play.getCards());
      newForest = newForest.getType("Forest");

      // if "Reach of Branches" is in graveyard and played a Forest
      if(0 < nCard.size()
            && newForest(oldForest, newForest) {
         [b]SpellAbility ability = new Ability(new Card(),
               "0") {[/b]
            @Override
            public void resolve() {
               // return all Reach of Branches to hand
               PlayerZone hand = AllZone.getZone(
                     Constant.Zone.Hand, player);
               for(int i = 0; i < nCard.size(); i++) {
                  grave.remove(nCard.get(i));
                  hand.add(nCard.get(i));
               }
            }// resolve()
         };// SpellAbility
         ability.setStackDescription("Reach of Branches - return card to "
               + player + "'s hand");
         AllZone.Stack.add(ability);
      }// if

      // potential problem: if a Forest is bounced to your hand
      // "Reach Branches"
      // won't trigger when you play that Forest
      oldForest.addAll(newForest.toArray());
   }// execute

   // check if newList has anything that oldList doesn't have
   boolean newForest(CardList oldList, CardList newList) {
      // check if a Forest came into play under your control
      for(int i = 0; i < newList.size(); i++)
         if(!oldList.contains(newList.get(i))) return true;

      return false;
   }// newForest()
}; // Reach of Branches
It seems like this is probably some old code some of which can be combined, or possibly converted to Whenever keyword? I think I saw three versions of Soul Warden, and it looks like we might just be able to use Auriok Champion's WheneverKeyword for those.

It seems like many of these abilities were "keeping track" of what triggered them already which could lead to general issues as noted in the comments of this block.
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times

Re: Commands in GameActionUtil

Postby Sloth » 28 Oct 2010, 18:03

friarsol wrote:Does anyone know anything about these Commands?

It seems like this is probably some old code some of which can be combined, or possibly converted to Whenever keyword? I think I saw three versions of Soul Warden, and it looks like we might just be able to use Auriok Champion's WheneverKeyword for those.
The Soul Warden cards and Reach of Branches can be converted to the whenever keyword.

In fact, this is what I will try to do now...

EDIT: Done!
Last edited by Sloth on 28 Oct 2010, 18:51, edited 1 time in total.
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times

Re: Commands in GameActionUtil

Postby DennisBergkamp » 28 Oct 2010, 18:44

Hmm, I'm not sure why they're causing NPEs... it is definitely code that's been around for quite awhile, but I'm not sure if there's actually code that's replaced it.
There's also another thing to keep in mind: the Reach of Branches / Soul Warden / Wirewood Hivemaster (+ a bunch of others) commands are commands that are executed no matter what, then there's a bunch of others that are only executed when the cards are actually in play (and are in the map of StaticEffects). The latter category accounts for most of them.
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Commands in GameActionUtil

Postby Sloth » 28 Oct 2010, 18:50

DennisBergkamp wrote:Hmm, I'm not sure why they're causing NPEs... it is definitely code that's been around for quite awhile, but I'm not sure if there's actually code that's replaced it.
There's also another thing to keep in mind: the Reach of Branches / Soul Warden / Wirewood Hivemaster (+ a bunch of others) commands are commands that are executed no matter what, then there's a bunch of others that are only executed when the cards are actually in play (and are in the map of StaticEffects). The latter category accounts for most of them.
One day most of the cards in the map of StaticEffects should be converted to the stPump keyword. Only a few special ones are not keywordable at the moment.
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times

Re: Commands in GameActionUtil

Postby friarsol » 28 Oct 2010, 18:53

Thanks Sloth. That'll ease the burden of the random issues that are popping up right now.

Dennis, the Errors are due to new code I'm writing that needs information about the SourceCard of abilities. Since some Abilities in this section just create a new Ability(new Card()) the information my new code needs isn't available and hits me with errors when they would resolve.
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 24 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 24 users online :: 0 registered, 0 hidden and 24 guests (based on users active over the past 10 minutes)
Most users ever online was 9298 on 10 Oct 2025, 12:54

Users browsing this forum: No registered users and 24 guests

Login Form