(Feat) Add build cost

This commit is contained in:
2026-07-14 14:25:02 +02:00
parent c9e923975d
commit 3657b870d8
27 changed files with 1270 additions and 990 deletions
@@ -1,4 +1,5 @@
using UnityEngine;
using Ashwild.Inventory;
namespace Ashwild.Building
{
@@ -30,6 +31,10 @@ namespace Ashwild.Building
[Tooltip("The real structure spawned once the placement is confirmed.")]
[SerializeField] private GameObject builtPrefab;
[Header("Cost")]
[Tooltip("Resources consumed from the builder's inventory on each placement. Leave empty for a free build.")]
[SerializeField] private BuildCost[] cost;
#endregion
#region Public API
@@ -39,6 +44,24 @@ namespace Ashwild.Building
public string Description => description;
public GameObject GhostPrefab => ghostPrefab;
public GameObject BuiltPrefab => builtPrefab;
public BuildCost[] Cost => cost;
/// <summary>
/// Whether the given inventory holds enough of every cost line to place this structure once.
/// A null inventory or an empty cost list counts as affordable (free build).
/// </summary>
public bool CanAfford(PlayerInventory inventory)
{
if (cost == null || cost.Length == 0) return true;
if (inventory == null) return false;
for (int i = 0; i < cost.Length; i++)
{
if (cost[i].item == null) continue;
if (!inventory.HasItem(cost[i].item, cost[i].quantity)) return false;
}
return true;
}
#endregion
}