
The very short list
- Refer to the mod DLL.
- Create and register an
IBuffsingleton instance. - Create one (or more)
BuffInstance. - Create
IBuffTargetandIBuffEffectfor theBuffInstance. - Process the applied
BuffInstancein 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 BuffDebuffas this will be the namespace for all Buff & Debuff System classes.
- Optionally add
- Create a singleton Buff class similar to
BuffDebuffDemo.Buffs.PositiveBuffthat 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,SimpleValueBufforSimpleFloatBuff. The latter two are for buffs that create instances with a simple value. - If you use
SimpleValueBuffor 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
BuffInstancefor aBuff. You can create any number ofBuffInstanceof any type(s) you want.
- You can create a class from scratch or inherit from
[!TIP]
BuffInstance,IBuffTarget, andIBuffEffectall haveInit(),Update...()andCleanUp()methods. You can override them to add your custom logic.
- Create a BuffInstance class similar to
BuffDebuffDemo.Buffs.PositiveBuffInstancethat inheritBuffInstance. This class will declare the targets and effects of the Buff.- You can inherit your class directly from
BuffInstanceor use some provided classes that support common use cases, such asBuffInstance<TValue, TBuff>orTimedBuffInstance. - BuffInstance must have a
new()(parameterless) constructor. You then useInjectAttributeto 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>.BuffandIValuedBuffInstance<TValue>.Valueavailable 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 itsActiveisfalse. If you setActivetofalse, theTargetswon’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
GlobalBuffTargetand its subclasses (GlobalBeaverBuffTarget,GlobalAdultBeaverBuffTarget,GlobalChildBeaverBuffTarget,GlobalBotBuffTarget), orIdsBuffTarget. - Each tick,
UpdateTargets()is called. If theTargetsChangedproperty istrue, the game will useTargetsas 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
IBuffServiceto 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
BaseComponentto 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