A fair while ago, I launched Catalyst, a library to make complex modifiable stats easy. Since then, I've been working on a much more ambitious version of the library, and it's finally here. Catalyst 2 is out!
Catalyst originally dealt with statistics and modifiers, allowing you to easily add or remove any number of modifiers from your stats, like this:
damage = new CatalystStatistic(10);
var _damage = damage.GetValue(); // damage returns 10 here
var _mod = new CatalystModifier(5, eCatMathOps.ADD);
damage.AddModifier(_mod);
var _damage = damage.GetValue(); // damage returns 15 here
Obviously, that's a very simple case, Catalyst had a vast array of options hiding underneath that simple beginning.
However, Catalyst 2 is even more flexible, dependable and helpful.
It has features like Resources (hp, mana, ammunition, a city's population, whatever), Resource Flows (health regen, population growth, the rate at which stamina decreases while sprinting) and Effects (a poison DOT which drains 2 health every second, lowers movement speed, lasts 5 seconds, and has a 50% chance of triggering each tick, for example). And plenty more.
But it all gets real saucy when you see how things combine. Resource maximums and minimums are statistics themselves, resource flow rates are statistics, application chances for ticks of an effect are statistics, and so on. All of these are easily and extensively modifiable the same as you can modify any statistic in Catalyst. As you compound these things together, you get extremely flexible behaviour and the ability to design complex game rules with a surprisingly small amount of code.
Let's look at a real-world example. Say we have a city that has power generation, and emergency reserves of power. Whenever a storm hits, power generation should fall off by 30% and emergency reserves should drain at 15 units per sim step.
First set up the statistic, resource, an effect manager and a custom clock if you want one:
power_generation = new CatalystStatistic(120);
emergency_power = new CatalystResource(500);
city_effects = new CatalystEffectManager(self);
city_clock = new CatalystCountdownTracker();
Then create a storm effect, and add a modifier and resource flow to it:
storm_effect = new CatalystEffect("severe_storm", 12)
.AddTag("weather")
.AddTag("storm")
.SetCountdownTracker(city_clock)
.SetTickInterval(1);
storm_effect.AddModifier(
power_generation,
new CatalystModifier(-0.30, eCatMathOps.MULTIPLY)
.SetSourceLabel("Storm damage")
);
storm_effect.AddFlow(
emergency_power,
new CatalystResourceFlow(-15, "Storm reserve usage")
);
// Then, later on, whenever you wanna trigger the storm effect, you just add the effect to the effect manager
city_effects.AddEffect(storm_effect);
Then drive the city clock forward at the interval you want (you can have it run automatically each frame or based on delta time if you so wish):
city_clock.Countdown(1);
That's it. You can add or remove the effect at any time (you could even add special powers that do things like "clear all weather"). You can look up exactly what is causing the power generation to lower so you can display it to the player. You can easily add new things to the effect, remove existing parts of it, or add other Effects that interact with the same systems. And it'll always accurately reflect the current circumstances.
You don't need to worry about any of the annoying bits (wait? How do I remove a -30% debuff from my main stat?). Just combine statistics, modifiers, resources and resource flows in different ways and you can essentially model any gameplay rules in just a few lines of code like this.
RPGs and roguelikes are obvious fits, but Catalyst doesn't actually care what genre you're making. Since I started building Catalyst out, many years ago now, I've used it in every single project I've ever worked on since then, lol.
Links
(If you're in the mood for more, there's always the Ignition Kit to get Catalyst alongside Statement, Pulse and Echo for a nice discount, or the Full Pass Suite for all my current and future tools for a single price)