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.

Chargeable Abilities

Custom abilities can be made chargeable by implementing the IAbilityChargeable interface. Ability's Count here works as the amount of stored up energy/charges. This interface makes use of some of the game's charging 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 chargeable

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

MyChargeableAbility.cs
public class MyChargeableAbility : CustomAbility, IAbilityChargeable
{
public void OnHeld(AbilityHeldArgs e) { /* ... */ }
public void OnReleased(AbilityReleasedArgs e) { /* ... */ }
}

OnHeld is called every frame (I think?) that the special ability button is held. OnReleased is called on the frame that the special ability button is released. Use these in tandem with OnPressed to charge your ability and stuff.

caution

AbilityHeldArgs.Interrupt() method is still work-in-progress.

Examples

using UnityEngine;

namespace RogueLibsCore.Test
{
public class Kamikaze : CustomAbility, IAbilityChargeable, IDoUpdate
{
[RLSetup]
public static void Setup()
{
RogueLibs.CreateCustomAbility<Kamikaze>()
.WithName(new CustomNameInfo("Kamikaze"))
.WithDescription(new CustomNameInfo("Charge up and explode everything around you."))
.WithSprite(Properties.Resources.Kamikaze)
.WithUnlock(new AbilityUnlock { UnlockCost = 20, CharacterCreationCost = 20 });
}

public float Charge { get; private set; }
public bool IsCharging { get; private set; }

public override void OnAdded() { }
public override void OnPressed()
{
IsCharging = true;
gc.audioHandler.Play(Owner, VanillaAudio.GeneratorHiss);
Owner!.objectMult.chargingSpecialLunge = true;
}
public override CustomTooltip GetCountString()
{
if (Charge is 0) return default;
string text = $"{Charge:#.#}s";
Color color = Color.Lerp(Color.white, Color.red, Charge / 10f);
if (Charge > 10f)
{
text = "BOOM!";
color = Color.Lerp(Color.white, Color.red, Mathf.PingPong(Time.time * 5, 1f));
}
return new CustomTooltip(text, color);
}
public void OnHeld(AbilityHeldArgs e)
{
Charge += Time.deltaTime;
e.HeldTime = Charge;
if (Charge > 10f)
{
Owner!.objectMult.chargingSpecialLunge = true;
}
}
public void OnReleased(AbilityReleasedArgs e)
{
IsCharging = false;
Owner!.objectMult.chargingSpecialLunge = false;
if (e.HeldTime > 10f)
{
Owner.AddEffect(VanillaEffects.Resurrection, new CreateEffectInfo(1) { DontShowText = true, IgnoreElectronic = true });
gc.spawnerMain.SpawnExplosion(Owner, Owner.tr.position, "Huge", false, -1, false, true).noOwnCheck = true;
Charge = 0f;
}
gc.audioHandler.Stop(Owner, VanillaAudio.GeneratorHiss);
}
public void Update()
{
if (!IsCharging) Charge = Mathf.Max(Charge - Time.deltaTime * 5f, 0f);
}
}
}

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