Skip to main content
The project's repository is archived as part of the GitHub Archive Program. RogueLibs' code and the documentation will no longer be updated.

Creating a Custom Effect

RogueLibs provides classes and methods to create custom effects, and an interface to make status effects updateable. Just like items and traits, custom effects derive from a hook class, CustomEffect. If you want the effect to have some kind of a passive effect, then you might need to patch that in yourself.

CustomEffect class

To make a custom effect, you need to create a class deriving from CustomEffect:

MyCustomEffect.cs
public class MyCustomEffect : CustomEffect
{
/* ... */
}

There are 5 methods that you need to implement:

MyCustomEffect.cs
public class MyCustomEffect : CustomEffect
{
public override int GetEffectTime() { /* ... */ }
public override int GetEffectHate() { /* ... */ }
public override void OnAdded() { /* ... */ }
public override void OnRemoved() { /* ... */ }
public override void OnUpdated(EffectUpdatedArgs e) { /* ... */ }
}

GetEffectTime determines the default status effect time. Traits like "Longer Status Effects", "Longer Status Effects +" and "Shorter Status Effects" are applied after calling this method.

GetEffectHate determines how much hate other characters will get towards the character who inflicted the status effect on them. Usually, it's 5 for negative effects and 0 for positive effects.

caution

GetEffectTime and GetEffectHate are called on partially initialized hooks, so the effect's owner might not actually have the effect. Do not initialize any effect-specific variables in these methods.

OnAdded is called when the effect is added to a character, and OnRemoved is called when it's removed from a character.

OnUpdated works like Unity's Update, but with a settable interval (default is 1 second):

    public override void OnUpdated(EffectUpdatedArgs e)
{
e.UpdateDelay = 0.5f; // 2 updates per second
/* ... */
CurrentTime--;
}
info

You're responsible for decrementing the effect's CurrentTime. So, don't forget to do that.

All custom effect classes should have an EffectParameters attribute. You can specify whether your effect should be removed on death, on knockout or between levels. Default is RemoveOnDeath.

[EffectParameters(EffectLimitations.RemoveOnDeath | EffectLimitations.RemoveOnKnockOut)]
public class MyCustomEffect : CustomEffect
{
/* ... */
}

Initialization

Just call the CreateCustomEffect method with your effect's type as a parameter:

MyCustomEffect.cs
public class MyCustomEffect : CustomEffect
{
[RLSetup]
public static void Setup()
{
RogueLibs.CreateCustomEffect<MyCustomEffect>();
}
}
note

See more about the RLSetup attribute here.

You can set your effect's name and description using WithName and WithDescription methods:

MyCustomEffect.cs
public class MyCustomEffect : CustomEffect
{
[RLSetup]
public static void Setup()
{
RogueLibs.CreateCustomEffect<MyCustomEffect>()
.WithName(new CustomNameInfo("My Custom Effect"))
.WithDescription(new CustomNameInfo("My Custom Effect is very cool and does a lot of great stuff"));
}
}
info

See Custom Names for more info.

Examples

A simple effect that just gives a temporary boost to some stats. You can see Adrenaline Shot's (item that gives this effect) implementation in Usable Items: Examples.

namespace RogueLibsCore.Test
{
[EffectParameters(EffectLimitations.RemoveOnDeath | EffectLimitations.RemoveOnKnockOut)]
public class Adrenaline : CustomEffect
{
[RLSetup]
public static void Setup()
{
RogueLibs.CreateCustomEffect<Adrenaline>()
.WithName(new CustomNameInfo("Adrenaline"))
.WithDescription(new CustomNameInfo("Gives you a ton of boosts for a short period of time."));
}

public override int GetEffectTime() => 15;
public override int GetEffectHate() => 0;
public override void OnAdded()
{
Owner.ChangeHealth(20);
Owner.SetStrength(Owner.strengthStatMod + 2);
Owner.SetEndurance(Owner.enduranceStatMod + 2);
Owner.SetAccuracy(Owner.accuracyStatMod - 1);
Owner.SetSpeed(Owner.speedStatMod + 2);
Owner.critChance += 30;
}
public override void OnRemoved()
{
Owner.SetStrength(Owner.strengthStatMod - 2);
Owner.SetEndurance(Owner.enduranceStatMod - 2);
Owner.SetAccuracy(Owner.accuracyStatMod + 1);
Owner.SetSpeed(Owner.speedStatMod - 2);
Owner.critChance -= 30;
}
public override void OnUpdated(EffectUpdatedArgs e)
{
e.UpdateDelay = 1f;
CurrentTime--;
}
}
}

The project's repository is archived as part of the GitHub Archive Program. RogueLibs' code and the documentation will no longer be updated.