Logic Constructor
Logic Constructor lets you move combat and ability logic out of code and into HOCON config. Designers tweak damage, healing, and targeting in a text file; the engine parses it into typed actions and runs them against your entities — no recompile, no glue code per ability.
Example
This is a simplified example which uses data from tests/fixture.rs.
Configuration & Boilerplate
- Define entities which would qualify for running logic constructor actions on.
- Define logic constructor actions.
Defining entities
Configuration
First we are going to define our entities structures.
// ... and more
Second we should define an enum which acts as a "registry" for all possible entities
we will be using for logic constructor (it's best practice to call it LcGameEntity).
Boilerplate
Now we have to tie it down to the logic constructor engine.
We have to implement LcEntityType for our game entities enum (also make sure that
LcEntityTypeId would be a unique value per entity type).
Define helper From implementations for every type, so it would be easier to pass
in entities into run_lca function.
// ... and more
Additionally for ease of use we can define helper methods on our LcGameEntity,
so it would be easier to implement logic constructor actions, like so.
Defining actions
Boilerplate
Before configuring our actions, first we will define some boilerplate so it would be easier later on to define our actions.
First we will define our Action trait which combines with our LcGameEntity.
Then since we will always need to implement LcAction<LcGameEntity> per action, we can write
simple macro to help use out reduce boilerplate per action definition.
Configuration
Now when we have our boilerplate in place, we can define our actions, we will define a struct which will hold information for a specific action and implement a trait, which we will tell how to apply an action from source to target.
// Define action and it's data.
// Define how it applies from source onto target.
impl_lc_game_action!;
impl_lc_game_action!;
// ... and more
Parsing
We of course also need to parse the data from hocon configuration, since we are defining which actions are available inside the config.
The parsers can be defined in many ways, but it's goal is to take hoccon Value type and parse
it into our LcGameAction. Later on when parsing from hocon config we will be injecting this
parser function into run_lca.
Roadmap
This is only scrathing the surface of what is the real potential of logic constructor in time will be adding way more features as I'll be using this library to develop my own games.
Features
- Buffs - have actions performed when applied or removed. Another action would be to apply a buff.
- Stats & Math - inside configs instead of typing out raw number for damage you will be able to write
10 * STRor something similar. - Periodic Actions - an action which is applied every x times, or per custom rules. For example while player has slow buff it ticks damage every 2 seconds.
- Effects - They will be able to last over time like a moment speed reduction while buff is applied.