Page 1 of 1

Is it possible to re-route events flow in Forge?

PostPosted: 19 Sep 2011, 06:01
by Max mtg
I would like to talk about the way abilities are handled.
The what I see in Upkeep.java now is a bit confusing:
Code: Select all
    /**
     * <p>executeAt.</p>
     */
    public void executeAt() {
       AllZone.getStack().freezeStack();
        upkeep_Braid_Of_Fire();

        upkeep_Slowtrips();  // for "Draw a card at the beginning of the next turn's upkeep."
        upkeep_UpkeepCost(); //sacrifice unless upkeep cost is paid
        upkeep_Echo();

        upkeep_The_Abyss();
        upkeep_Yawgmoth_Demon();
        upkeep_Lord_of_the_Pit();
        upkeep_Drop_of_Honey();
        upkeep_Demonic_Hordes();
        upkeep_Carnophage();
        upkeep_Sangrophage();
        upkeep_Dega_Sanctuary();
        upkeep_Ceta_Sanctuary();
        upkeep_Tangle_Wire();


        upkeep_Shapeshifter();
        upkeep_Vesuvan_Doppelganger_Keyword();

        //Kinship cards
        upkeep_Ink_Dissolver();
        upkeep_Kithkin_Zephyrnaut();
        upkeep_Leaf_Crowned_Elder();
        upkeep_Mudbutton_Clanger();
        upkeep_Nightshade_Schemers();
        upkeep_Pyroclast_Consul();
        upkeep_Sensation_Gorger();
        upkeep_Squeaking_Pie_Grubfellows();
        upkeep_Wandering_Graybeard();
        upkeep_Waterspout_Weavers();
        upkeep_Winnower_Patrol();
        upkeep_Wolf_Skull_Shaman();

        // upkeep_Dragon_Broodmother(); //put this before bitterblossom and mycoloth, so that they will resolve FIRST

        //Win / Lose
        // Checks for can't win or can't lose happen in Player.altWinConditionMet()

        upkeep_Mortal_Combat();
        upkeep_Near_Death_Experience();
        upkeep_Test_of_Endurance();
        upkeep_Helix_Pinnacle();
        upkeep_Barren_Glory();
        upkeep_Felidar_Sovereign();

        upkeep_Karma();
        upkeep_Oath_of_Druids();
        upkeep_Oath_of_Ghouls();
        upkeep_Suspend();
        upkeep_Vanishing();
        upkeep_Fading();
        upkeep_Masticore();
        upkeep_Eldrazi_Monument();
        upkeep_Blaze_Counters();
        //upkeep_Dark_Confidant(); // keep this one semi-last
        upkeep_Power_Surge();
        upkeep_AI_Aluren();
        // experimental, AI abuse aluren

        AllZone.getStack().unfreezeStack();
    }
it looks like classes like this one will keep getting bloated by more and more cards with thier unique code. And the worst part is that all these methods are static, so every method would have some AllZone(Util) calls to get current player, permanents of battlefield and so on... I think that's a design flaw that the Upkeep has to know (hold the code) what each specific card does at that moment

I wish there were a different organization of events handling:
There should be an event bus, where all the interested executors (small classes encapsulating some mechanics or hardcoded rules for a single card) can subscribe to some events. Executors subscribe when a matching permanent appears in game, and unsubscribe when it gets exiled or dies (or maybe otherwise subscribes if that is an ability like Flashback or Bloodghast's one). But anyway presence of only actual cards would eliminate searches like this: AllZoneUtil.getCardsIn(Zone.Battlefield, "Aluren").

Changes in game state lead to events generation, be that some card etb or die or beginning of new phase or turn. So, the executors recieve a notice, check whether any extra conditions are met (according to their card rules) and change game state appropriatelly, that might include generation of some new events. Some events might also be cancelled ("whenever hydra would receive damage prevent it, remove a counter from it instead")

So, is there a chance to do something like that in Forge?

Re: Is it possible to re-route events flow in Forge?

PostPosted: 19 Sep 2011, 06:20
by Hellfish
"Many" (in quotes because I'm not actually sure *how* many) of the upkeep_<card> functions can be replaced with a CardFactory entry that uses a Trigger object with an OverridingAbility. Also, similarly "Many" of the playCard_<Card> in GameActionUtil can be converted this way.

Also also, the Mortal Combat -> Felidar Sovereign block can probably be scripted now.

Re: Is it possible to re-route events flow in Forge?

PostPosted: 19 Sep 2011, 07:22
by Sloth
Max mtg wrote:it looks like classes like this one will keep getting bloated by more and more cards with thier unique code. And the worst part is that all these methods are static, so every method would have some AllZone(Util) calls to get current player, permanents of battlefield and so on... I think that's a design flaw that the Upkeep has to know (hold the code) what each specific card does at that moment

I wish there were a different organization of events handling:
There should be an event bus, where all the interested executors (small classes encapsulating some mechanics or hardcoded rules for a single card) can subscribe to some events. Executors subscribe when a matching permanent appears in game, and unsubscribe when it gets exiled or dies (or maybe otherwise subscribes if that is an ability like Flashback or Bloodghast's one). But anyway presence of only actual cards would eliminate searches like this: AllZoneUtil.getCardsIn(Zone.Battlefield, "Aluren").

Changes in game state lead to events generation, be that some card etb or die or beginning of new phase or turn. So, the executors recieve a notice, check whether any extra conditions are met (according to their card rules) and change game state appropriatelly, that might include generation of some new events. Some events might also be cancelled ("whenever hydra would receive damage prevent it, remove a counter from it instead")

So, is there a chance to do something like that in Forge?
What Hellfish hinted at, is that we already have more or less the system you describe. All scripted Triggers of cards that are actually used in a game are registered in TriggerHandler. Before Hellfish coded the scripting for triggers we had hundreds of hardcoded entries of cards everywhere (in the damage code, in changing zones, even the stack handler) and most of them didn't even use the stack (they just did something secretly).
Actually I removed three entries from the upkeep class this weekend. It just takes time to script all of these cards.

Re: Is it possible to re-route events flow in Forge?

PostPosted: 19 Sep 2011, 08:02
by Max mtg
Thanks, Sloth, then I should not be upset about it.

Re: Is it possible to re-route events flow in Forge?

PostPosted: 19 Sep 2011, 12:02
by friarsol
Max mtg wrote:Thanks, Sloth, then I should not be upset about it.
Nope. It is much much better than it used to be, and I don't think many cards have been added into these sections in a while.