# Resource

### Key Features

* **Manages Player Resources:** Tracks, updates, and modifies resource quantities for player-controlled entities.
* **Supports Multiple Resource Types:** Works with `ResourceSO` to define different resources like food, wood, gold, etc.
* **Resource Calculation:** Uses `ResourceQuantity` to compute costs and manage transactions efficiently.
* **Automatic or Manual Resource Updates:** Can handle real-time updates or allow manual adjustments for turn-based systems.
* **Integration with Other Modules:** Works alongside `ProductionModule` to ensure resource availability for unit production.

***

### Structure

* **Resource Module** – Manages resources, including adding, removing, and checking availability.
* **ResourceSO** – Defines resource types as ScriptableObjects, allowing flexible creation of new resources.
* **ResourceQuantity** – Represents specific amounts of resources and handles cost calculations.
* **Resource Events** – Provides global events for UI updates and resource-related triggers.

***

### Usage Examples

#### Adding Resources Manually

```csharp
ResourceModule resourceModule = player.GetModule<ResourceModule>();
ResourceSO goldResource = ... // Reference to the gold resource scriptable object
resourceModule.AddResource(goldResource, 500); // Adds 500 gold to the player
```

#### Checking Resource Availability

```csharp
ResourceQuantity requiredWood = new ResourceQuantity(woodResource, 200);
bool hasEnough = resourceModule.HasResources(new ResourceQuantity[] { requiredWood });
if (hasEnough)
{
    Debug.Log("Player has enough wood.");
}
```

#### Deducting Resources for Production

```csharp
ResourceQuantity[] cost = unitBlueprint.GetProductionCost();
if (resourceModule.TryConsumeResources(cost))
{
    Debug.Log("Resources consumed, production can proceed.");
}
else
{
    Debug.Log("Not enough resources available.");
}
```
