Is it possible to re-route events flow in Forge?
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
5 posts
• Page 1 of 1
Is it possible to re-route events flow in Forge?
by Max mtg » 19 Sep 2011, 06:01
I would like to talk about the way abilities are handled.
The what I see in Upkeep.java now is a bit confusing:
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?
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();
}
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?
Single class for single responsibility.
- Max mtg
- Programmer
- Posts: 1997
- Joined: 02 Jul 2011, 14:26
- Has thanked: 173 times
- Been thanked: 334 times
Re: Is it possible to re-route events flow in Forge?
by Hellfish » 19 Sep 2011, 06:20
"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.
Also also, the Mortal Combat -> Felidar Sovereign block can probably be scripted now.
So now you're
Screaming for the blood of the cookie monster
Evil puppet demon of obesity
Time to change the tune of his fearful ballad
C is for "Lettuce," that's good enough for me
Screaming for the blood of the cookie monster
Evil puppet demon of obesity
Time to change the tune of his fearful ballad
C is for "Lettuce," that's good enough for me
-
Hellfish - Programmer
- Posts: 1297
- Joined: 07 Jun 2009, 10:41
- Location: South of the Pumphouse
- Has thanked: 110 times
- Been thanked: 169 times
Re: Is it possible to re-route events flow in Forge?
by Sloth » 19 Sep 2011, 07:22
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).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?
Actually I removed three entries from the upkeep class this weekend. It just takes time to script all of these cards.
-
Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
Re: Is it possible to re-route events flow in Forge?
by Max mtg » 19 Sep 2011, 08:02
Thanks, Sloth, then I should not be upset about it.
Single class for single responsibility.
- Max mtg
- Programmer
- Posts: 1997
- Joined: 02 Jul 2011, 14:26
- Has thanked: 173 times
- Been thanked: 334 times
Re: Is it possible to re-route events flow in Forge?
by friarsol » 19 Sep 2011, 12:02
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.Max mtg wrote:Thanks, Sloth, then I should not be upset about it.
- friarsol
- Global Moderator
- Posts: 7593
- Joined: 15 May 2010, 04:20
- Has thanked: 243 times
- Been thanked: 965 times
5 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 53 guests