# Collection

### Key Features

* **Manages Player Collectors**: Provides a list of available collectors, interface for searching nearby resource nodes or resource depots.
* **World Space Resource**: Define resource nodes that produce valuable resources to players, frequent or scarce.
* **Depot Usage**: Utilise resource depots to manage and store collected resources.
* **Flexible Collecting Types**: Choose from various collection behaviours to fit your game design.
* **Event-Driven Updates**: Triggers events for UI or gameplay reactions.

***

### Structure

* **Collection Module** - Easy access to available collectors, finding nearby nodes or depots.
* **Resource Collector Capability** - Defines collectors capabilities like **supported resources**, collect **interval**, **amount** and **collect type.**
* **Collect Types:**
  * **RealtimeCollect -** Collects resources directly into the player's resource pool without requiring transport or capacity management.
  * **StackAndCollect** - Collects resources into the collector's storage until capacity is reached, then automatically adds them to the player's resource pool without requiring transport.
  * **GatherAndDeposit** - Collects resources into the collector's storage and requires transporting them to a resource depot for depositing.
* **Resource Collector** - Management of the collector's state and interactions.
* **Resource Depot Capability** - Defines depot capabilities, specifies supported resources for depositing.
* **Resource Depot** - Management of the depot's state and interactions. Can be moved on static or moving units.
* **Resource Node Capability** - Defines the resource and amount that can be collected from the node.
* **Resource Node** - Management of the node's state and interactions. When capability's amount is zero or negative, node is considered to have unlimited resource.
* **Collection Events** - Global events for tracking collector, node states.

***

### Usage Examples

**Control Collectors**

When you want to send collector to **gather** resources from a **nearby node**.

```csharp
ResourceCollector collector = // Get collector reference
ResourceSO resource = // Get desired resource that collector supports.

// There are other ways to get collection module, but this is one way
// if you have only Unit reference.
if (collector.Owner.TryGetModule(out CollectionModule collectionModule) &&
    collectionModule.FindNearbyNode(collector.Position, resource, out IResourceNode node))
{
    collector.GoCollectResource(node);
}
```

When you want to send collector to **deposit** resources to a **nearby depot**.

```csharp
if (collectionModule.FindNearestDepot(collector.Position, resourceToDeposit, out IResourceDepot depot))
{
    collector.GoDepositResource(depot)
}
```

**Display Available Collectors**

To show available collectors to player on UI, you can use module's interface.

```csharp
// Get all idle collectors, with no active tasks.
IResourceCollector[] collectors = collectionModule.GetAvailableCollectors();
```

**Deposit Resource Immediately**

To deposit resources held by the collector directly to player with no deposit process.

```csharp
collector.DepositResource()
```

**Clearing Resource**

To remove held resource by the collector.

```
collector.ClearResource()
```
