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.

Usable Items

Custom items can be made usable by implementing the IItemUsable interface, that defines a single method, UseItem. Usable items can be used by right-clicking them in the inventory, or using them from the toolbar (1-5 keys).

Making items usable

Just implement the IItemUsable interface in your item's class:

MyUsableItem.cs
public class MyUsableItem : CustomItem, IItemUsable
{
public bool UseItem() { /* ... */ }
}

UseItem's return value indicates whether the item was successfully used. Returning true will also play an animation. When returning false, you can play a "CantDo" sound, and optionally make the current owner say why the item cannot be used:

        if (cantUse)
{
gc.audioHandler.Play(Owner, "CantDo");
Owner.SayDialogue("CantUseItemBecause...");
// don't forget to create a dialogue with that id
return false;
}
info

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

Examples

A simple usable item that allows the player to use the Joke ability.

namespace RogueLibsCore.Test
{
[ItemCategories(RogueCategories.Usable, RogueCategories.Social)]
public class JokeBook : CustomItem, IItemUsable
{
[RLSetup]
public static void Setup()
{
RogueLibs.CreateCustomItem<JokeBook>()
.WithName(new CustomNameInfo("Joke Book"))
.WithDescription(new CustomNameInfo("Always wanted to be a Comedian? Now you can! (kind of)"))
.WithSprite(Properties.Resources.JokeBook)
.WithUnlock(new ItemUnlock
{
UnlockCost = 10,
LoadoutCost = 5,
CharacterCreationCost = 3,
Prerequisites = { VanillaAgents.Comedian + "_BQ" },
});
}

public override void SetupDetails()
{
Item.itemType = ItemTypes.Tool;
Item.itemValue = 15;
Item.initCount = 10;
Item.rewardCount = 10;
Item.stackable = true;
Item.hasCharges = true;
Item.goesInToolbar = true;
}
public bool UseItem()
{
if (Owner!.statusEffects.makingJoke) return false;

string prev = Owner.specialAbility;
Owner.specialAbility = VanillaAbilities.Joke;
Owner.statusEffects.PressedSpecialAbility();
Owner.specialAbility = prev;

Count--;
return true;
}
}
}

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