RogueLibs' logo

Combinable Items

Custom items can be made combinable with other items by implementing the IItemCombinable interface. You can define what kind of items your item is combinable with, what happens when you combine these items, and what tooltips to display in the combinable item's cell, and when hovering over it.

Making items combinable

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

/MyAwesomeProject/MyCombinableItem.cs
public class MyCombinableItem : CustomItem, IItemCombinable{    public bool CombineFilter(InvItem other) { /* ... */ }    public bool CombineItems(InvItem other) { /* ... */ }    public CustomTooltip CombineTooltip(InvItem other) { /* ... */ }    public CustomTooltip CombineCursorText(InvItem other) { /* ... */ }}

CombineFilter determines what items will be highlighted, when combining the current item.

CombineItems combines the current item with the other one. The return value indicates whether it was a success or not. Usually you'd just play a "CantDo" sound, if the items cannot be combined. Returning true will also play an animation.

CombineTooltip determines the tooltip in the upper-left corner of the inventory slot. Text set to null will default to an empty string, and Color set to null will default to #FFED00. See the tool below.

CombineCursorText determines the cursor text when hovering over the item. Text set to null will default to "Combine", and Color set to null will default to #FFFFFF.

Inventory Slot Preview

Wanna see how your CombineTooltip will look in the game? Check out this small tool:

$123

Examples

A simple example that inverts the Syringes' effects.

/MyAwesomeProject/Centrifuge.cs
using System.Collections.Generic;using System.Linq;using RogueLibsCore;namespace MyAwesomeMod{    public class Centrifuge : CustomItem, IItemCombinable    {        [RLSetup]        public static void Setup()        {            RogueLibs.CreateCustomItem<Centrifuge>()                .WithName(new CustomNameInfo("Centrifuge"))                .WithDescription(new CustomNameInfo("Combine with a syringe to invert its effect."))                .WithSprite(Properties.Resources.Centrifuge)                .WithUnlock(new ItemUnlock                {                    UnlockCost = 10,                    LoadoutCost = 5,                    CharacterCreationCost = 3,                    Prerequisites = { VanillaItems.Antidote },                });        }        public override void SetupDetails()        {            Item.itemType = ItemTypes.Combine;            Item.itemValue = 8;            Item.initCount = 10;            Item.stackable = true;            Item.hasCharges = true;        }        private static readonly Dictionary<string, string> invertDictionary = new Dictionary<string, string>        {            [VanillaEffects.Poisoned] = VanillaEffects.RegenerateHealth,            [VanillaEffects.Slow] = VanillaEffects.Fast,            [VanillaEffects.Weak] = VanillaEffects.Strength,            [VanillaEffects.Acid] = VanillaEffects.Invincible,            [VanillaEffects.Confused] = VanillaEffects.Invisible,        };        static Centrifuge()        {            foreach (KeyValuePair<string, string> pair in invertDictionary.ToArray())                invertDictionary.Add(pair.Value, pair.Key);        }        public bool CombineFilter(InvItem other)            => other.invItemName == VanillaItems.Syringe            && other.contents.Count > 0            && invertDictionary.ContainsKey(other.contents[0]);        public bool CombineItems(InvItem other)        {            if (!CombineFilter(other)) return false;            other.contents[0] = invertDictionary[other.contents[0]];            Count--;            gc.audioHandler.Play(Owner, VanillaAudio.CombineItem);            return true;        }        public CustomTooltip CombineCursorText(InvItem other) => default;        public CustomTooltip CombineTooltip(InvItem other) => default;    }}