Craftsman

Scripting with the Craftsman class.

A Craftsman is a merchant that crafts items.

Fields & Properties

Name
Description
Type
Access

craftTargets

The types of items this craftsman can craft.

Craftsman.CraftTargets

public

supportedItemTypes

A list of item types this craftsman can craft.

List<ItemType>

public

supportedItems

A list of items that this craftsman can craft.

List<Item>

public

Craft Targets

Craftsman.CraftTargets is an enum that helps define the items a craftsman can craft.

Name
Description

Everything

Can craft any item.

SpecificItemTypes

Can only craft items of the item types listed in the supportedItemTypes field.

SpecificItems

Can only craft items listed in the supportedItems field.

Creating Craftsmen

It's not recommended to create craftsmen at runtime, but it is possible. Craftsman is a scriptable object which cannot be created as an asset at runtime for later use.

Craftsman myCraftsman = ScriptableObject.CreateInstance<Craftsman>();

Crafting

A Craftsman requires a reference to a Crafter to help craft items.

You can check if it's possible to craft an item with the CanCraft method. The first parameter is the Crafter and the second is a bool that determines if the failure reason should be invoked. This method will return true if the item in the Crafter can be crafted by the Craftsman and if the Crafter's CanCraft method returns true. Otherwise, false will be returned.

bool result = myCraftsman.CanCraft(myCrafter, true);

To officially craft an item, use the TryCraft method. This is similar to the CanCraft method, except it will add the item to the player's inventory if successful.

bool result = myCraftsman.TryCraft(myCrafter);

Last updated