# Craft

## 🛠️ Craft Class

Functions as a blueprint for crafts.

> Namespace: `Esper.Inventool.Crafting`\
> Access: `public`\
> Type: `class`\
> Inherits: `InventoolObject`

***

### 📦 Fields

| Access    | Field             | Type              | Description                                                             |
| --------- | ----------------- | ----------------- | ----------------------------------------------------------------------- |
| `private` | `pathInResources` | `string` (const)  | The path used with `Resources.LoadAll` to find craft assets.            |
| `public`  | `searchableName`  | `string`          | The name of this craft for the purposes of searching inside the editor. |
| `public`  | `combineItems`    | `List<ItemStack>` | The items required to craft the result item.                            |
| `public`  | `resultItem`      | `ItemStack`       | The item that is created when the required items are combined.          |
| `public`  | `cost`            | `Currency`        | The amount this craft will cost.                                        |

***

### 🔍 Properties

| Access   | Property         | Type          | Description                                                                 |
| -------- | ---------------- | ------------- | --------------------------------------------------------------------------- |
| `public` | `DatabaseRecord` | `CraftRecord` | The database record of this craft.                                          |
| `public` | `CraftingCode`   | `string`      | A generated code created with crafting item combinations for craft lookups. |

***

### 🧰 Methods

| Access           | Method                            | Returns | Description                                                    |
| ---------------- | --------------------------------- | ------- | -------------------------------------------------------------- |
| `public`         | `Clean()`                         | `void`  | Cleans the object by removing deleted items.                   |
| `public`         | `override Save()`                 | `void`  | Saves the object (editor only).                                |
| `public`         | `CanCraft(List<ItemStack> items)` | `bool`  | If this craft can be crafted with the provided list of items.  |
| `public`         | `CanCraft(ItemStack[] items)`     | `bool`  | If this craft can be crafted with the provided array of items. |
| `public`         | `SetData(Craft craft)`            | `void`  | Sets the data from another craft.                              |
| `public static`  | `Create()`                        | `Craft` | Creates a new instance of a craft (editor only).               |
| `public`         | `UpdateAssetName()`               | `void`  | Updates the name of the asset (editor only).                   |
| `public static`  | `CreateCopy(Craft original)`      | `Craft` | Creates a copy of another craft.                               |
| `private static` | `GetID()`                         | `int`   | Returns an unused ID.                                          |

***

## Creating Crafts

It's not at all recommended to create crafts at runtime, but it is possible. `Craft`'s are scriptable objects which cannot be created as assets at runtime for later use.

```csharp
Craft myCraft = ScriptableObject.CreateInstance<Craft>();
```

## Getting Crafts

Crafts created through the [crafting](https://stylishesper.gitbook.io/inventool/inventool-v1/editors/inventool/crafting "mention") tab can be retrieved at runtime.

### Get a Single Craft

You can get a `Craft` by its ID, name, or code with the `Inventool.GetCraft` method.

```csharp
Craft myCraft = Inventool.GetCraft("My Craft Name");
```

### Get All Crafts

```csharp
var myCrafts = Inventool.GetAllCrafts();
```

## Requirements Checking

You can check if a list of items matches the requirement of the `Craft` to craft the result item.

```csharp
bool result = myCraft.CanCraft(myListOfItemStacks);
```
