Enchanter
✨ Enchanter Class
A merchant that enchants items.
Namespace:
Esper.Inventool.Merchants
Access:public
Type:class
Inherits:Merchant
📦 Fields
public
enchantTargets
EnchantTargets
The types of items this enchanter can enchant.
public
supportedItemTypes
List<ItemType>
A list of item types this enchanter can enchant.
public
supportedItems
List<Item>
A list of specific items this enchanter can enchant.
🧰 Methods
public
CanEnchant(ItemStack itemStack, ItemStack enchanter, bool invokeFailureReason)
bool
Checks if the given item stack can be enchanted with the provided enchanter.
public
TryEnchant(ItemStack itemStack, ItemStack enchanter, bool applyCost = true)
bool
Attempts to enchant an item stack. Returns true if successful.
public
Enchant(ItemStack itemStack, ItemStack enchanter, bool applyCost = true)
void
Enchants an item stack directly.
public
Clean()
void
Cleans the object by removing deleted items and item types.
public
Save()
(Editor only)
void
Saves the object.
🧩 Nested Types
public enum EnchantTargets
public enum EnchantTargets
Defines what this enchanter can enchant.
Everything
Can enchant any item.
SpecificItemTypes
Can only enchant items of the item types listed in supportedItemTypes
.
SpecificItems
Can only enchant items listed in supportedItems
.
Creating Enchanters
It's not recommended to create enchanters at runtime, but it is possible. Enchanter
is a scriptable object which cannot be created as an asset at runtime for later use.
Enchanter myEnchanter = ScriptableObject.CreateInstance<Enchanter>();
Enchanting
An Enchanter
requires a reference to an Enchantable and Enchanter item.
You can check if it's possible to enchant an item with the CanEnchant
method. The first parameter is the enchantable item, the second is the enchanter item, and the third is abool
that determines if the failure reason should be invoked. This method will return true
if the enchanter can enchant the enchantable item. Otherwise, false will be returned.
bool result = myEnchanter.CanEnchant(myEnchantableItem, myEnchanterItem, true);
To officially enchant an item, use the TryEnchant
method. This is similar to the CanEnchant
method, except it will enchant the item if successful.
bool result = myEnchanter.TryEnchant(myEnchantableItem, myEnchanterItem);
Last updated