Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Latest commit

 

History

History
149 lines (133 loc) · 5.2 KB

CustomItems.md

File metadata and controls

149 lines (133 loc) · 5.2 KB
  1. Main page
  2. RogueLibs
  3. CustomMutators
  4. CustomItems
  5. CustomNames
  6. Extras
  7. RogueLibs Changelog
  8. Mod Examples

Creating CustomItems

public static CustomItem SetItem(string id, Sprite sprite, CustomNameInfo name, CustomNameInfo description, Action<InvItem> setupDetails);
// Creating a sprite from byte[] (.png image)
Sprite sprite = RogueUtilities.ConvertToSprite(Properties.Resources.MoneyContainer);

CustomItem moneyContainer = RogueLibs.SetItem("money-container", sprite,
    new CustomNameInfo("Money Container"),
    new CustomNameInfo("Gives you some money."),
    item =>
    { // See InvItem.SetupDetails() for more info
        item.itemType = "Consumable";
        item.Categories.Add("Technology");
        item.itemValue = 20;
        item.initCount = 10;
        item.rewardCount = 10;
        item.stackable = true;
        item.goesInToolbar = true;
        item.cantBeCloned = true;
        // item.LoadItemSprite("my-item"); - RogueLibs loads the sprite automatically
    });

Deleting CustomItems

public static bool DeleteItem(string id);
public static bool DeleteItem(CustomItem customItem);

You probably won't need these.

Properties

You can get your CustomItem's Id:

public string Id { get; }

You can get/set your CustomItem's SetupDetails delegate:

public Action<InvItem> SetupDetails { get; set; }

You can get/set your CustomItem's Sprite:

public Sprite Sprite { get; set; }

And your CustomItem's Name and Description:

public CustomName Name { get; set; }
public CustomName Description { get; set; }

Making Consumable Items

public Action<InvItem, Agent> UseItem { get; set; }
CustomItem moneyContainer = RogueLibs.SetItem(...);

moneyContainer.UseItem = (item, agent) =>
{
    agent.inventory.AddItem("Money", UnityEngine.Random.Range(5, 40));
    item.database.SubtractFromItemCount(item, 1);
    new ItemFunctions().UseItemAnim(item, agent);
};

Making Combinable Items

public Func<InvItem, Agent, InvItem, bool> CombineFilter { get; set; }
public Action<InvItem, Agent, InvItem, int> CombineItem { get; set; }
CustomItem repairer = RogueLibs.SetItem(...);

repairer.CombineFilter = (item, agent, otherItem) => otherItem.itemType == "WeaponMelee" && otherItem.invItemCount < otherItem.rewardCount;
// Item can be repaired only if it is a melee weapon and has less than 200 (default) durability

repairer.CombineItem = (item, agent, otherItem, slotNum) =>
{
    otherItem.invItemCount += UnityEngine.Random.Range(30, 50); // Repair by a random amount
    if (otherItem.invItemCount > otherItem.rewardCount)
        otherItem.invItemCount = otherItem.rewardCount;

    if (!item.gc.challenges.Contains("NoLimits"))
        agent.agentInvDatabase.SubtractFromItemCount(item, 1);

    item.gc.audioHandler.Play(agent, "CombineItem");

    if (item.invItemCount < 1) // Stop combining if the repairer has 0 uses left
    {
        agent.mainGUI.invInterface.HideDraggedItem();
        agent.mainGUI.invInterface.HideTarget();
    }
};

Making Targeting Items

public Func<InvItem, Agent, PlayfieldObject, bool> TargetFilter { get; set; }
public Action<InvItem, Agent, PlayfieldObject> TargetObject { get; set; }
public CustomName HoverText { get; set; }
public void SetHoverText(CustomNameInfo info);
CustomItem remoteGiantizer = RogueLibs.SetItem(...);

remoteGiantizer.TargetFilter = (item, agent, target) => target is Agent a && !a.dead;
// Object can be targeted only if it is an Agent and is not dead

remoteGiantizer.TargetObject = (item, agent, target) =>
{
    item.invInterface.HideTarget();

    Agent a = (Agent)target;
    a.statusEffects.AddStatusEffect("Giant", true, true, 999999);
    item.database.SubtractFromItemCount(item, 1);
}

remoteGiantizer.SetHoverText(new CustomNameInfo("Giantize!"));

Making Items Spawnable

public Dictionary<string, int> SpawnDictionary { get; set; }
public void AddSpawnList(string listName, int spawnChance);
CustomItem vodka = RogueLibs.SetItem(...);

vodka.AddSpawnList("Alcohol2", 3);
vodka.AddSpawnList("DefaultChallenge", 3);

// For more info, see RandomItems.fillItems()

Or, you can edit SpawnDictionary directly:

CustomItem vodka = RogueLibs.SetItem(...);

vodka.SpawnDictionary.Add("Alcohol2", 3);
vodka.SpawnDictionary.Add("DefaultChallenge", 1);

You can also use ECTD (Edit Characters Through Description) mod to quickly test your items, just type ++<Your Item ID> in your custom character's description.