Buffs

Buffs (both positive and negative) are temporary changes to an entity's attributes. They are applied in response to a situation or event. For example, sleeping on the ground may add the groggy buff to a hearthling, causing them to be slower for a few hours after waking up.

The buffs component is used to add, remove and keep track of all the buffs/debuffs that a hearthling currently has. The buff data that we declare in a JSON file is then managed by the stonehearth/components/buffs/buff.lua controller.

The existing buffs can be found inside stonehearth/data/buffs. There might be some more in subfolders of stonehearth/jobs.

Creating buffs

We can easily create buffs that modify some attributes from the hearthlings with just JSON, or do some more complex things with a small Lua script. Don't forget to add an alias for your buff in your manifest!

These are the properties that we can find in the buff's JSON file:

You might see a "tags" property in some of the existing buffs. It's no longer in use, so you can omit it.

Applying and removing buffs

There are several ways to apply buffs to entities:

Buffs are removed when:

Testing buffs

We can easily add buffs to check that they're working as intended, even before hooking them to an equipment piece or in a script.

Once we add an alias for our buff in our manifest, we can select a hearthling in the game, open the default console and type:

  add_buff my_mod:buffs:my_buff

and press Enter. We should be able to see the icon of the buff next to the unit frame of the hearthling. If the buff is invisible to players, we can open the Object browser, click on the value for the buffs component, and check that it's listed there.

We can also remove a buff in the same way, using the remove_buff command.