The very short list
- Refer to the mod DLL.
- Create and register an
IBuff
singleton instance. - Create one (or more)
BuffInstance
. - Create
IBuffTarget
andIBuffEffect
for theBuffInstance
. - Process the applied
BuffInstance
in your mod using Singleton, BaseComponent or Harmony patch.
A bit more detailed
- Add the mod reference to your project. The file should be at
"SteamLibrary\steamapps\workshop\content\1062090\3433810580\version-0.7\BuffDebuff.dll"
.- Optionally add
global using BuffDebuff
as this will be the namespace for all Buff & Debuff System classes.
- Optionally add
- Create a singleton Buff class similar to
BuffDebuffDemo.Buffs.PositiveBuff
that implementsIBuff
. This class will declare general information about the buff, such as its name, description. It will also act as a manager and factory for the BuffInstance.- You can create a class from scratch or inherit from
SimpleBuff
,SimpleValueBuff
orSimpleFloatBuff
. The latter two are for buffs that create instances with a simple value. - If you use
SimpleValueBuff
or similar, you do not have enough class (BuffInstance
) to provide for the generic parameters yet. Just ignore and go ahead to the next step. - You are not limited to one type of
BuffInstance
for aBuff
. You can create any number ofBuffInstance
of any type(s) you want.
- You can create a class from scratch or inherit from
[!TIP]
BuffInstance
,IBuffTarget
, andIBuffEffect
all haveInit()
,Update...()
andCleanUp()
methods. You can override them to add your custom logic.
- Create a BuffInstance class similar to
BuffDebuffDemo.Buffs.PositiveBuffInstance
that inheritBuffInstance
. This class will declare the targets and effects of the Buff.- You can inherit your class directly from
BuffInstance
or use some provided classes that support common use cases, such asBuffInstance<TValue, TBuff>
orTimedBuffInstance
. - BuffInstance must have a
new()
(parameterless) constructor. You then useInjectAttribute
to inject necessary services into the instance similar to how you code aBaseComponent
. - Use
Init()
to setup your instance. This method is called after the instance is created and injected. You would have yourIBuffInstance<TBuff>.Buff
andIValuedBuffInstance<TValue>.Value
available at this point as well if your instance is of those types. - Use
Update()
if you need to update your instance every tick even when itsActive
isfalse
. If you setActive
tofalse
, theTargets
won’t be called right in that tick.
- You can inherit your class directly from
- Create
IBuffTarget
(s) for your buff instance to target. This interface will define the target(s) of the buff instance.- You can create a class from scratch or inherit from
GlobalBuffTarget
and its subclasses (GlobalBeaverBuffTarget
,GlobalAdultBeaverBuffTarget
,GlobalChildBeaverBuffTarget
,GlobalBotBuffTarget
), orIdsBuffTarget
. - Each tick,
UpdateTargets()
is called. If theTargetsChanged
property istrue
, the game will useTargets
as new targets and remove the buff instance from the old targets.
- You can create a class from scratch or inherit from
-
Create
IBuffEffect
(s) for your buff instance to apply. There isUpdateEffect()
method that is called every tick if you need to. - Create another class (it can be a game’s singleton or a Harmony patch) that uses
IBuffService
to scan for yourBuffInstance
. Then decide what to do with theIBuffEffect
(s) that they have.- Another way (recommended in the Step-by-step guide) is to add another
BaseComponent
to the entities that the buff can apply to (likeBeaverSpec
) and listen to the events.
- Another way (recommended in the Step-by-step guide) is to add another