Ability FSM? #2319
Replies: 1 comment
-
There's #1469 open for a revamp, but I like your view/approach with a FSM, as it includes proper stuff to complement the issue. The coder who wrote initial prototype proposed a rewrite for abilities back in the day but he was focusing on a modular approach regarding their effect, similar to a game with some game that featured 4 colored anime-ish looking color cloaked mages (but probably not Wizards of Legends¹), where you would create and evolve your magic spells using some modular as you pleased. Having interactions handled by an engine is great stuff, because eventually we'll need a MVC approach, so that we can easily decouple from current UI or graphic mode in order to have the game be able to easily embrace new hardware down the line or have different graphical modes / renderers - #1970 #2021 #249 ¹ On that note (game with modular abilities), I've acquired and played Vampire Survivors lately quite a bit, there you can upgrade various attack parameters with some objects/skills, but even so, not all of them are cross-compatible, so you either need to test and observe or constantly dig through wikis, as the UI is not very informative about what works with what (could have been an easy fix overall) except with object/skill required by for a certain attack to evolve past its ultimate level, looking way different and becoming way more powerful. |
Beta Was this translation helpful? Give feedback.
-
TL;DR
I'm considering making a few tests using a revamped ability architecture. A finite state machine (FSM) would make a suitable, flexible replacement to the current system.
I've been working on converting
ability.js
toability.ts
.The module seems to have been coded for flexibility, but the result is that it's quite difficult to know when functions are called, where their definitions come from, what and how many arguments they're called with. There's a lot of reliance on
arguments
rather than named arguments. There's also a lot of reliance on ambiguous argument objects – e.g.and
that have to be tested to see if they include a particular field.
This means that converting to TS isn't particularly useful in a lot of cases.
There's also quite a lot of indirection. Objects passed to functions extend other objects and are passed to still other functions to be extended.
Ability Finite State Machine (FSM)?
It seems to me that a lot of the indirection and ambiguity could be removed if abilities were implemented as an FSM – finite state machine. A first draft of a
State
could perhaps be implemented with an interface like this.Mouse/Pointer events:
Lifecycle events:
Properties:
An engine – perhaps in
game
– wouldThen the current state itself decides if requirements for a state transition are satisfied and what that transition should be – directly in the
src/abilities/*
file – rather than relying on a series of callbacks. If a state change is required, the current state could:Hex
and aCreature
instance, then the creator has to pass theHex
andCreature
.In addition to centralizing an ability's core in its file and typing arguments, this has a concrete advantage over the current system that an FSM can have an arbitrary number of nodes, without requiring modification of calling code. If a new ability requires the user to select 2 hexes, then a creature, that's easy to implement simply by pushing new states.
Branching is also relatively trivial – e.g., a particular ability could allow a player to either:
Thoughts welcome.
Beta Was this translation helpful? Give feedback.
All reactions