I'm trying to build a plugin that creates auto passive states, and am struggling to find a good way to detect that "something significant" changed. I'm only interested in "mechanical" changes, not "cosmetic" changes.
I've noticed that
Enumerating every possible case is certainly a possibility; I'd prefer to narrow it down to as few cases as possible though.
Another possibility I considered is hooking into scene update and just bulldozing through the checks on every frame. That might have been barely sufficient if I only needed to worry about the map and battle scenes, but unfortunately, there are quite a few changes that can occur in other scenes – using an item at the menu, equipping or unequipping an item, changing formation order, buying or selling at a shop, and probably more. Hooking
As an additional note, the reason I'm not just overriding
I've noticed that
Game_BattlerBase.prototype.refresh covers a great many cases. It does not, however, cover at least the following cases:- Taking a step on the map (need
Game_Actor.prototype.onPlayerWalk) - Transferring to another map (seems like I'd need
Game_Player.prototype.performTransfer) - Starting or ending battle (it would sometimes cover these, as TP or EXP is likely to change at the start or end of battle, and that calls
refresh… but that's only partial coverage) - Probably a bunch of things that events can do (some would lead to a
refresh, others might not) - Is that all? I likely missed something…
Enumerating every possible case is certainly a possibility; I'd prefer to narrow it down to as few cases as possible though.
Another possibility I considered is hooking into scene update and just bulldozing through the checks on every frame. That might have been barely sufficient if I only needed to worry about the map and battle scenes, but unfortunately, there are quite a few changes that can occur in other scenes – using an item at the menu, equipping or unequipping an item, changing formation order, buying or selling at a shop, and probably more. Hooking
Scene_Base.prototype.update also won't do – there are too many scenes where you can't rely on a map existing. In any case, running the checks on every frame seems excessive – most frames have no "mechanical" changes in them, only "cosmetic" changes.As an additional note, the reason I'm not just overriding
Game_BattlerBase.prototype.states is because I want the State Resist trait to be able to cancel out a passive trait. But if I call isStateResist from state, I get a stack overflow. The overflow can be solved relatively easily by introducing a recursion guard, but that is only a bandaid solution – for every active plugin that uses this approach in the traits system, the stack grows deeper and performance degrades a tiny bit. I ran into some quite noticeable performance drops due to having only 4 or 5 such plugins. (Admittedly, one of the 5 was worse than the others, but still.)