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.

Rechargeable Abilities

Custom abilities can be made rechargeable by implementing the IAbilityRechargeable interface. Ability's Count here works as a cooldown and usually represents the amount of time to wait until full recharge. This interface makes use of some of the game's recharging mechanics, but it doesn't completely rely on it. I'd recommend taking a look at Recharging Items, if you need finer control.

Making abilities rechargeable

Just implement the IAbilityRechargeable interface in your ability's class:

MyRechargeableAbility.cs
public class MyRechargeableAbility : CustomAbility, IAbilityRechargeable
{
public void OnRecharging(AbilityRechargingArgs e) { /* ... */ }
}
Pro-tip

You can just set it to 0 when it's fully recharged and to 1 when it's recharging (you can override the displayed count if you want), and use your own cooldown mechanism instead. See Recharging Items for more info.

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

    public void OnRecharging(AbilityRechargingArgs e)
{
e.UpdateDelay = 2f; // 1 update every 2 seconds
Count--;
}
info

You're responsible for decrementing the ability's Count. So, don't forget to do that.
Ability will stop recharging when Count reaches 0. To start recharging again, just set Count to any other value.

Examples

namespace RogueLibsCore.Test
{
public class Titan : CustomAbility, IAbilityRechargeable
{
[RLSetup]
public static void Setup()
{
RogueLibs.CreateCustomAbility<Titan>()
.WithName(new CustomNameInfo("Titan"))
.WithDescription(new CustomNameInfo("Willpower alone isn't enough in battle."))
.WithSprite(Properties.Resources.Titan)
.WithUnlock(new AbilityUnlock
{
UnlockCost = 10,
CharacterCreationCost = 10,
Prerequisites = { VanillaItems.Giantizer },
});
}

public override void OnAdded() { }
public override void OnPressed()
{
if (Count != 0)
{
gc.audioHandler.Play(Owner, VanillaAudio.CantDo);
return;
}
Owner!.statusEffects.AddStatusEffect(VanillaEffects.Giant, 15);
Count = 30;
}
public void OnRecharging(AbilityRechargingArgs e)
{
e.UpdateDelay = 1f;
Count--;
}
}
}

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