From 55ba2b791d7c2636c2331a9d3d4b44e39bcbcf8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 21:35:49 +0300 Subject: [PATCH 01/61] chore: add inventory runtime folder --- Assets/_ZoneUA/Runtime/Inventory.meta | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Assets/_ZoneUA/Runtime/Inventory.meta diff --git a/Assets/_ZoneUA/Runtime/Inventory.meta b/Assets/_ZoneUA/Runtime/Inventory.meta new file mode 100644 index 0000000..c9b0811 --- /dev/null +++ b/Assets/_ZoneUA/Runtime/Inventory.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 8b8fb47518984642af6048d0c3c94127 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: From 764e7a8571f024150756a2fb51371a718434dde9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 21:35:59 +0300 Subject: [PATCH 02/61] feat: add inventory runtime assembly --- .../Runtime/Inventory/ZoneUA.Inventory.asmdef | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Assets/_ZoneUA/Runtime/Inventory/ZoneUA.Inventory.asmdef diff --git a/Assets/_ZoneUA/Runtime/Inventory/ZoneUA.Inventory.asmdef b/Assets/_ZoneUA/Runtime/Inventory/ZoneUA.Inventory.asmdef new file mode 100644 index 0000000..bc4b95c --- /dev/null +++ b/Assets/_ZoneUA/Runtime/Inventory/ZoneUA.Inventory.asmdef @@ -0,0 +1,14 @@ +{ + "name": "ZoneUA.Inventory", + "rootNamespace": "ZoneUA.Inventory", + "references": [], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} From 39d552a5725d804d628c10d42e9a2c2f74eab5d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 21:36:07 +0300 Subject: [PATCH 03/61] chore: add inventory assembly metadata --- .../_ZoneUA/Runtime/Inventory/ZoneUA.Inventory.asmdef.meta | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Assets/_ZoneUA/Runtime/Inventory/ZoneUA.Inventory.asmdef.meta diff --git a/Assets/_ZoneUA/Runtime/Inventory/ZoneUA.Inventory.asmdef.meta b/Assets/_ZoneUA/Runtime/Inventory/ZoneUA.Inventory.asmdef.meta new file mode 100644 index 0000000..14d93b6 --- /dev/null +++ b/Assets/_ZoneUA/Runtime/Inventory/ZoneUA.Inventory.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 6ccd2d06ac9543d99329469715866adb +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: From 7354dc1c812f4e6ade271a09450dbf449b1f5d89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 21:36:23 +0300 Subject: [PATCH 04/61] feat: add item definitions --- .../Runtime/Inventory/ItemDefinition.cs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Assets/_ZoneUA/Runtime/Inventory/ItemDefinition.cs diff --git a/Assets/_ZoneUA/Runtime/Inventory/ItemDefinition.cs b/Assets/_ZoneUA/Runtime/Inventory/ItemDefinition.cs new file mode 100644 index 0000000..8af6c1d --- /dev/null +++ b/Assets/_ZoneUA/Runtime/Inventory/ItemDefinition.cs @@ -0,0 +1,28 @@ +using UnityEngine; + +namespace ZoneUA.Inventory +{ + [CreateAssetMenu(menuName = "Zone UA/Inventory/Item Definition", fileName = "ItemDefinition")] + public sealed class ItemDefinition : ScriptableObject + { + [SerializeField] private string itemId = string.Empty; + [SerializeField] private string displayName = string.Empty; + [SerializeField, TextArea] private string description = string.Empty; + [SerializeField] private Sprite icon; + [SerializeField, Min(1)] private int maximumStack = 1; + [SerializeField] private GameObject worldPrefab; + + public string ItemId => itemId; + public string DisplayName => string.IsNullOrWhiteSpace(displayName) ? name : displayName; + public string Description => description; + public Sprite Icon => icon; + public int MaximumStack => Mathf.Max(1, maximumStack); + public GameObject WorldPrefab => worldPrefab; + + private void OnValidate() + { + itemId = itemId?.Trim() ?? string.Empty; + maximumStack = Mathf.Max(1, maximumStack); + } + } +} From a542b6c0d6269a24e01a0bf3b64cbd4e97588320 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 21:36:32 +0300 Subject: [PATCH 05/61] chore: add item definition metadata --- .../_ZoneUA/Runtime/Inventory/ItemDefinition.cs.meta | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Assets/_ZoneUA/Runtime/Inventory/ItemDefinition.cs.meta diff --git a/Assets/_ZoneUA/Runtime/Inventory/ItemDefinition.cs.meta b/Assets/_ZoneUA/Runtime/Inventory/ItemDefinition.cs.meta new file mode 100644 index 0000000..f80baf4 --- /dev/null +++ b/Assets/_ZoneUA/Runtime/Inventory/ItemDefinition.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 252b69fc6d624fd5abce1b3b04aec077 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 870fc1f00f9b302b0f20a1c7d93d8644dae207f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 21:36:42 +0300 Subject: [PATCH 06/61] feat: add item catalog --- .../_ZoneUA/Runtime/Inventory/ItemCatalog.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Assets/_ZoneUA/Runtime/Inventory/ItemCatalog.cs diff --git a/Assets/_ZoneUA/Runtime/Inventory/ItemCatalog.cs b/Assets/_ZoneUA/Runtime/Inventory/ItemCatalog.cs new file mode 100644 index 0000000..3b2b523 --- /dev/null +++ b/Assets/_ZoneUA/Runtime/Inventory/ItemCatalog.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +namespace ZoneUA.Inventory +{ + [CreateAssetMenu(menuName = "Zone UA/Inventory/Item Catalog", fileName = "ItemCatalog")] + public sealed class ItemCatalog : ScriptableObject + { + [SerializeField] private List items = new List(); + + public IReadOnlyList Items => items; + + public bool TryGet(string itemId, out ItemDefinition definition) + { + definition = null; + if (string.IsNullOrWhiteSpace(itemId)) return false; + foreach (ItemDefinition item in items) + { + if (item != null && string.Equals(item.ItemId, itemId.Trim(), StringComparison.Ordinal)) + { + definition = item; + return true; + } + } + return false; + } + } +} From 1c9bab125fe00ed3596239d1889da34eac1abc90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 21:36:53 +0300 Subject: [PATCH 07/61] chore: add item catalog metadata --- Assets/_ZoneUA/Runtime/Inventory/ItemCatalog.cs.meta | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Assets/_ZoneUA/Runtime/Inventory/ItemCatalog.cs.meta diff --git a/Assets/_ZoneUA/Runtime/Inventory/ItemCatalog.cs.meta b/Assets/_ZoneUA/Runtime/Inventory/ItemCatalog.cs.meta new file mode 100644 index 0000000..354aed8 --- /dev/null +++ b/Assets/_ZoneUA/Runtime/Inventory/ItemCatalog.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0b8abd425ddc480684bae4fc0a66a6d1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From e0417a735a3cc2da6627b0eaff17cc8eb8021b11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 21:37:11 +0300 Subject: [PATCH 08/61] feat: add deterministic inventory state --- .../Runtime/Inventory/InventoryState.cs | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 Assets/_ZoneUA/Runtime/Inventory/InventoryState.cs diff --git a/Assets/_ZoneUA/Runtime/Inventory/InventoryState.cs b/Assets/_ZoneUA/Runtime/Inventory/InventoryState.cs new file mode 100644 index 0000000..8686322 --- /dev/null +++ b/Assets/_ZoneUA/Runtime/Inventory/InventoryState.cs @@ -0,0 +1,90 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace ZoneUA.Inventory +{ + [Serializable] + public sealed class InventoryEntry + { + public string itemId = string.Empty; + public int amount; + + public InventoryEntry() { } + public InventoryEntry(string itemId, int amount) + { + this.itemId = itemId ?? string.Empty; + this.amount = Math.Max(0, amount); + } + } + + public sealed class InventoryState + { + private readonly Dictionary amounts = new Dictionary(StringComparer.Ordinal); + private readonly int capacity; + + public InventoryState(int capacity = 0) => this.capacity = Math.Max(0, capacity); + public int Capacity => capacity; + public int DistinctItemCount => amounts.Count; + public int TotalItemCount => amounts.Values.Sum(); + public IReadOnlyList Entries => amounts.OrderBy(pair => pair.Key, StringComparer.Ordinal).Select(pair => new InventoryEntry(pair.Key, pair.Value)).ToList(); + + public int GetAmount(string itemId) => Normalize(itemId) is string id && amounts.TryGetValue(id, out int value) ? value : 0; + + public bool CanAdd(string itemId, int amount) + { + string id = Normalize(itemId); + if (string.IsNullOrEmpty(id) || amount <= 0) return false; + return capacity <= 0 || TotalItemCount + amount <= capacity; + } + + public bool Add(string itemId, int amount) + { + string id = Normalize(itemId); + if (!CanAdd(id, amount)) return false; + amounts[id] = GetAmount(id) + amount; + return true; + } + + public bool Has(string itemId, int amount = 1) => amount > 0 && GetAmount(itemId) >= amount; + + public bool Remove(string itemId, int amount) + { + string id = Normalize(itemId); + if (string.IsNullOrEmpty(id) || amount <= 0 || !amounts.TryGetValue(id, out int current) || current < amount) return false; + int remaining = current - amount; + if (remaining == 0) amounts.Remove(id); else amounts[id] = remaining; + return true; + } + + public bool TryConsume(IEnumerable costs) + { + List normalized = NormalizeEntries(costs); + if (normalized.Any(entry => !Has(entry.itemId, entry.amount))) return false; + foreach (InventoryEntry entry in normalized) Remove(entry.itemId, entry.amount); + return true; + } + + public void Replace(IEnumerable entries) + { + amounts.Clear(); + foreach (InventoryEntry entry in NormalizeEntries(entries)) + { + if (capacity > 0 && TotalItemCount + entry.amount > capacity) break; + amounts[entry.itemId] = GetAmount(entry.itemId) + entry.amount; + } + } + + private static List NormalizeEntries(IEnumerable entries) + { + return (entries ?? Array.Empty()) + .Where(entry => entry != null && entry.amount > 0 && !string.IsNullOrWhiteSpace(entry.itemId)) + .GroupBy(entry => entry.itemId.Trim(), StringComparer.Ordinal) + .Select(group => new InventoryEntry(group.Key, group.Sum(entry => entry.amount))) + .OrderBy(entry => entry.itemId, StringComparer.Ordinal) + .ToList(); + } + + private static string Normalize(string value) => string.IsNullOrWhiteSpace(value) ? string.Empty : value.Trim(); + } +} From 104acc5f4c9ffdabe3cade8dc8f6eaa9034dc32c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 21:37:22 +0300 Subject: [PATCH 09/61] chore: add inventory state metadata --- .../_ZoneUA/Runtime/Inventory/InventoryState.cs.meta | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Assets/_ZoneUA/Runtime/Inventory/InventoryState.cs.meta diff --git a/Assets/_ZoneUA/Runtime/Inventory/InventoryState.cs.meta b/Assets/_ZoneUA/Runtime/Inventory/InventoryState.cs.meta new file mode 100644 index 0000000..e76be8b --- /dev/null +++ b/Assets/_ZoneUA/Runtime/Inventory/InventoryState.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c9312ca7bc66476ea4ed928ec1dd61df +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From cdca4f527df02e033d08eb73a36098bfd1258f44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 21:37:34 +0300 Subject: [PATCH 10/61] feat: add construction definitions --- .../Inventory/ConstructionDefinition.cs | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Assets/_ZoneUA/Runtime/Inventory/ConstructionDefinition.cs diff --git a/Assets/_ZoneUA/Runtime/Inventory/ConstructionDefinition.cs b/Assets/_ZoneUA/Runtime/Inventory/ConstructionDefinition.cs new file mode 100644 index 0000000..6120ac7 --- /dev/null +++ b/Assets/_ZoneUA/Runtime/Inventory/ConstructionDefinition.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +namespace ZoneUA.Inventory +{ + [Serializable] + public sealed class ConstructionCost + { + public ItemDefinition item; + [Min(1)] public int amount = 1; + } + + [CreateAssetMenu(menuName = "Zone UA/Construction/Definition", fileName = "ConstructionDefinition")] + public sealed class ConstructionDefinition : ScriptableObject + { + [SerializeField] private string constructionId = string.Empty; + [SerializeField] private GameObject completedPrefab; + [SerializeField, Min(0.01f)] private float requiredWork = 1f; + [SerializeField] private List costs = new List(); + + public string ConstructionId => constructionId; + public GameObject CompletedPrefab => completedPrefab; + public float RequiredWork => Mathf.Max(0.01f, requiredWork); + public IReadOnlyList Costs => costs; + + public List BuildCostEntries() + { + var result = new List(); + foreach (ConstructionCost cost in costs) + { + if (cost?.item == null || string.IsNullOrWhiteSpace(cost.item.ItemId) || cost.amount <= 0) continue; + result.Add(new InventoryEntry(cost.item.ItemId, cost.amount)); + } + return result; + } + + private void OnValidate() + { + constructionId = constructionId?.Trim() ?? string.Empty; + requiredWork = Mathf.Max(0.01f, requiredWork); + } + } +} From a6a7af1c7ddb54d9b78563a0ddeb6b770823e5ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 21:37:43 +0300 Subject: [PATCH 11/61] chore: add construction definition metadata --- .../Runtime/Inventory/ConstructionDefinition.cs.meta | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Assets/_ZoneUA/Runtime/Inventory/ConstructionDefinition.cs.meta diff --git a/Assets/_ZoneUA/Runtime/Inventory/ConstructionDefinition.cs.meta b/Assets/_ZoneUA/Runtime/Inventory/ConstructionDefinition.cs.meta new file mode 100644 index 0000000..1bfaf89 --- /dev/null +++ b/Assets/_ZoneUA/Runtime/Inventory/ConstructionDefinition.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e0c623291b4745b3ba278849d48f41f1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 419d87234b6c585ab2fbe3840f2470c513340f2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 21:37:55 +0300 Subject: [PATCH 12/61] feat: add deterministic construction state --- .../Runtime/Inventory/ConstructionState.cs | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Assets/_ZoneUA/Runtime/Inventory/ConstructionState.cs diff --git a/Assets/_ZoneUA/Runtime/Inventory/ConstructionState.cs b/Assets/_ZoneUA/Runtime/Inventory/ConstructionState.cs new file mode 100644 index 0000000..5ba8698 --- /dev/null +++ b/Assets/_ZoneUA/Runtime/Inventory/ConstructionState.cs @@ -0,0 +1,47 @@ +using System; + +namespace ZoneUA.Inventory +{ + [Serializable] + public sealed class ConstructionState + { + private float requiredWork; + private float appliedWork; + private bool resourcesCommitted; + + public ConstructionState(float requiredWork, float appliedWork = 0f, bool resourcesCommitted = false) + { + this.requiredWork = Math.Max(0.01f, requiredWork); + this.appliedWork = Math.Clamp(appliedWork, 0f, this.requiredWork); + this.resourcesCommitted = resourcesCommitted; + } + + public float RequiredWork => requiredWork; + public float AppliedWork => appliedWork; + public bool ResourcesCommitted => resourcesCommitted; + public bool IsComplete => appliedWork >= requiredWork; + public float Progress01 => requiredWork <= 0f ? 1f : appliedWork / requiredWork; + + public bool CommitResources() + { + if (resourcesCommitted) return false; + resourcesCommitted = true; + return true; + } + + public float ApplyWork(float amount) + { + if (!resourcesCommitted || IsComplete || amount <= 0f) return 0f; + float previous = appliedWork; + appliedWork = Math.Min(requiredWork, appliedWork + amount); + return appliedWork - previous; + } + + public void Restore(float newRequiredWork, float newAppliedWork, bool committed) + { + requiredWork = Math.Max(0.01f, newRequiredWork); + appliedWork = Math.Clamp(newAppliedWork, 0f, requiredWork); + resourcesCommitted = committed; + } + } +} From d1c4c536d50fbc92667538636c618a43c49ab76d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 21:38:07 +0300 Subject: [PATCH 13/61] chore: add construction state metadata --- .../Runtime/Inventory/ConstructionState.cs.meta | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Assets/_ZoneUA/Runtime/Inventory/ConstructionState.cs.meta diff --git a/Assets/_ZoneUA/Runtime/Inventory/ConstructionState.cs.meta b/Assets/_ZoneUA/Runtime/Inventory/ConstructionState.cs.meta new file mode 100644 index 0000000..75fa2d5 --- /dev/null +++ b/Assets/_ZoneUA/Runtime/Inventory/ConstructionState.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a8dac1bc1f7d497e8a051ed1c4fe68fd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From f6bda851945ea3944b15b885e6949c23a79b5f02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 21:38:21 +0300 Subject: [PATCH 14/61] feat: add inventory component --- Assets/Script/InventoryComponent.cs | 60 +++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 Assets/Script/InventoryComponent.cs diff --git a/Assets/Script/InventoryComponent.cs b/Assets/Script/InventoryComponent.cs new file mode 100644 index 0000000..9380455 --- /dev/null +++ b/Assets/Script/InventoryComponent.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using UnityEngine; +using ZoneUA.Inventory; + +[DisallowMultipleComponent] +public sealed class InventoryComponent : MonoBehaviour +{ + [SerializeField, Min(0)] private int capacity; + [SerializeField] private List initialItems = new List(); + + private InventoryState state; + + public event Action InventoryChanged; + public InventoryState State => state ??= CreateState(); + public IReadOnlyList Entries => State.Entries; + public int Capacity => State.Capacity; + public int TotalItemCount => State.TotalItemCount; + + private void Awake() => state = CreateState(); + + public int GetAmount(string itemId) => State.GetAmount(itemId); + public bool Has(string itemId, int amount = 1) => State.Has(itemId, amount); + + public bool Add(string itemId, int amount) + { + if (!State.Add(itemId, amount)) return false; + InventoryChanged?.Invoke(); + return true; + } + + public bool Remove(string itemId, int amount) + { + if (!State.Remove(itemId, amount)) return false; + InventoryChanged?.Invoke(); + return true; + } + + public bool TryConsume(IEnumerable costs) + { + if (!State.TryConsume(costs)) return false; + InventoryChanged?.Invoke(); + return true; + } + + public void ReplaceContents(IEnumerable entries) + { + State.Replace(entries); + InventoryChanged?.Invoke(); + } + + private InventoryState CreateState() + { + var result = new InventoryState(capacity); + result.Replace(initialItems); + return result; + } + + private void OnValidate() => capacity = Mathf.Max(0, capacity); +} From 7f3a8ca90a27f8efa9c07ddd4f076ef04d57a9b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 21:38:31 +0300 Subject: [PATCH 15/61] chore: add inventory component metadata --- Assets/Script/InventoryComponent.cs.meta | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Assets/Script/InventoryComponent.cs.meta diff --git a/Assets/Script/InventoryComponent.cs.meta b/Assets/Script/InventoryComponent.cs.meta new file mode 100644 index 0000000..dd34850 --- /dev/null +++ b/Assets/Script/InventoryComponent.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 47aa3cb45f4644839c3ca8fb52b1e987 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 5323f2d6b1f3a6633dff66f6381d3dba6b8f058f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 21:38:43 +0300 Subject: [PATCH 16/61] feat: persist inventory contents --- Assets/Script/InventorySaveParticipant.cs | 35 +++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Assets/Script/InventorySaveParticipant.cs diff --git a/Assets/Script/InventorySaveParticipant.cs b/Assets/Script/InventorySaveParticipant.cs new file mode 100644 index 0000000..34d1b5c --- /dev/null +++ b/Assets/Script/InventorySaveParticipant.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using UnityEngine; +using ZoneUA.Inventory; +using ZoneUA.Persistence; + +[RequireComponent(typeof(InventoryComponent))] +public sealed class InventorySaveParticipant : MonoBehaviour, IPersistentSaveParticipant +{ + [Serializable] + private sealed class Payload + { + public List entries = new List(); + } + + private InventoryComponent inventory; + + public string ParticipantKey => "inventory"; + public int ParticipantVersion => 1; + + private void Awake() => inventory = GetComponent(); + + public string CaptureState() + { + inventory ??= GetComponent(); + return JsonUtility.ToJson(new Payload { entries = new List(inventory.Entries) }); + } + + public void RestoreState(string payload, int version) + { + inventory ??= GetComponent(); + Payload state = string.IsNullOrWhiteSpace(payload) ? new Payload() : JsonUtility.FromJson(payload); + inventory.ReplaceContents(state?.entries ?? new List()); + } +} From 25672f5e779a4087e7d235cd529af982da8c581d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 21:38:51 +0300 Subject: [PATCH 17/61] chore: add inventory save participant metadata --- Assets/Script/InventorySaveParticipant.cs.meta | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Assets/Script/InventorySaveParticipant.cs.meta diff --git a/Assets/Script/InventorySaveParticipant.cs.meta b/Assets/Script/InventorySaveParticipant.cs.meta new file mode 100644 index 0000000..e755419 --- /dev/null +++ b/Assets/Script/InventorySaveParticipant.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 38801d9187684c1388fa6e57b5d3c2be +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From c55275566f7b9071aa434a897a09987501831d19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 21:39:06 +0300 Subject: [PATCH 18/61] feat: add persistent world item pickup --- Assets/Script/WorldItemPickup.cs | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Assets/Script/WorldItemPickup.cs diff --git a/Assets/Script/WorldItemPickup.cs b/Assets/Script/WorldItemPickup.cs new file mode 100644 index 0000000..e7c3ca9 --- /dev/null +++ b/Assets/Script/WorldItemPickup.cs @@ -0,0 +1,39 @@ +using UnityEngine; +using ZoneUA.Inventory; +using ZoneUA.Persistence; + +[RequireComponent(typeof(PersistentIdentity))] +public sealed class WorldItemPickup : MonoBehaviour +{ + [SerializeField] private ItemDefinition item; + [SerializeField, Min(1)] private int amount = 1; + [SerializeField] private bool pickupOnTrigger = true; + + private PersistentIdentity identity; + private bool consumed; + + public ItemDefinition Item => item; + public int Amount => Mathf.Max(1, amount); + + private void Awake() => identity = GetComponent(); + + public bool TryPickup(InventoryComponent inventory) + { + if (consumed || inventory == null || item == null || string.IsNullOrWhiteSpace(item.ItemId)) return false; + if (!inventory.Add(item.ItemId, Amount)) return false; + + consumed = true; + identity ??= GetComponent(); + identity.MarkDestroyed(); + return true; + } + + private void OnTriggerEnter2D(Collider2D other) + { + if (!pickupOnTrigger || other == null) return; + InventoryComponent inventory = other.GetComponentInParent(); + if (inventory != null) TryPickup(inventory); + } + + private void OnValidate() => amount = Mathf.Max(1, amount); +} From caf15ed7546366c84322a8e8feecff556b785af6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 21:39:15 +0300 Subject: [PATCH 19/61] chore: add world item pickup metadata --- Assets/Script/WorldItemPickup.cs.meta | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Assets/Script/WorldItemPickup.cs.meta diff --git a/Assets/Script/WorldItemPickup.cs.meta b/Assets/Script/WorldItemPickup.cs.meta new file mode 100644 index 0000000..4a5616d --- /dev/null +++ b/Assets/Script/WorldItemPickup.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ba80c6a69ed146f995653ee5233bd072 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 3bc9fa1a8a2266aab5e14e894bb38cdb2d8149d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 21:39:35 +0300 Subject: [PATCH 20/61] feat: add persistent construction site --- Assets/Script/ConstructionSite.cs | 91 +++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 Assets/Script/ConstructionSite.cs diff --git a/Assets/Script/ConstructionSite.cs b/Assets/Script/ConstructionSite.cs new file mode 100644 index 0000000..4eeb619 --- /dev/null +++ b/Assets/Script/ConstructionSite.cs @@ -0,0 +1,91 @@ +using System; +using UnityEngine; +using ZoneUA.Inventory; +using ZoneUA.Persistence; + +[RequireComponent(typeof(PersistentIdentity))] +public sealed class ConstructionSite : MonoBehaviour, IPersistentSaveParticipant +{ + [Serializable] + private sealed class Payload + { + public string constructionId = string.Empty; + public float requiredWork; + public float appliedWork; + public bool resourcesCommitted; + } + + [SerializeField] private ConstructionDefinition definition; + [SerializeField] private GameObject incompleteRoot; + [SerializeField] private GameObject completedRoot; + + private ConstructionState state; + + public event Action ProgressChanged; + public event Action Completed; + + public ConstructionDefinition Definition => definition; + public bool IsComplete => State.IsComplete; + public float Progress01 => State.Progress01; + public string ParticipantKey => "construction"; + public int ParticipantVersion => 1; + private ConstructionState State => state ??= new ConstructionState(definition != null ? definition.RequiredWork : 1f); + + private void Awake() + { + state = new ConstructionState(definition != null ? definition.RequiredWork : 1f); + RefreshVisuals(); + } + + public bool CommitResources(InventoryComponent inventory) + { + if (definition == null || inventory == null || State.ResourcesCommitted) return false; + if (!inventory.TryConsume(definition.BuildCostEntries())) return false; + State.CommitResources(); + ProgressChanged?.Invoke(State.Progress01); + return true; + } + + public float ApplyWork(float amount) + { + bool wasComplete = State.IsComplete; + float applied = State.ApplyWork(amount); + if (applied <= 0f) return 0f; + ProgressChanged?.Invoke(State.Progress01); + if (!wasComplete && State.IsComplete) + { + RefreshVisuals(); + Completed?.Invoke(); + } + return applied; + } + + public string CaptureState() + { + var payload = new Payload + { + constructionId = definition != null ? definition.ConstructionId : string.Empty, + requiredWork = State.RequiredWork, + appliedWork = State.AppliedWork, + resourcesCommitted = State.ResourcesCommitted + }; + return JsonUtility.ToJson(payload); + } + + public void RestoreState(string payload, int version) + { + Payload restored = string.IsNullOrWhiteSpace(payload) ? new Payload() : JsonUtility.FromJson(payload); + float required = restored != null && restored.requiredWork > 0f + ? restored.requiredWork + : definition != null ? definition.RequiredWork : 1f; + State.Restore(required, restored?.appliedWork ?? 0f, restored?.resourcesCommitted ?? false); + RefreshVisuals(); + ProgressChanged?.Invoke(State.Progress01); + } + + private void RefreshVisuals() + { + if (incompleteRoot != null) incompleteRoot.SetActive(!State.IsComplete); + if (completedRoot != null) completedRoot.SetActive(State.IsComplete); + } +} From fabec1b9b709529904a3da450ce39df51ece3f5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 21:39:45 +0300 Subject: [PATCH 21/61] chore: add construction site metadata --- Assets/Script/ConstructionSite.cs.meta | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Assets/Script/ConstructionSite.cs.meta diff --git a/Assets/Script/ConstructionSite.cs.meta b/Assets/Script/ConstructionSite.cs.meta new file mode 100644 index 0000000..28269b1 --- /dev/null +++ b/Assets/Script/ConstructionSite.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f4dc0cc5f2044d7f876ea0ee4ad588f1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 95a75aa99ab7f1c395ea1c2e18e9522d7254291f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 21:40:14 +0300 Subject: [PATCH 22/61] chore: reference inventory from editor validation --- Assets/_ZoneUA/Editor/ZoneUA.EditorValidation.asmdef | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Assets/_ZoneUA/Editor/ZoneUA.EditorValidation.asmdef b/Assets/_ZoneUA/Editor/ZoneUA.EditorValidation.asmdef index d01e07b..f27f7bf 100644 --- a/Assets/_ZoneUA/Editor/ZoneUA.EditorValidation.asmdef +++ b/Assets/_ZoneUA/Editor/ZoneUA.EditorValidation.asmdef @@ -3,7 +3,8 @@ "rootNamespace": "ZoneUA.EditorValidation", "references": [ "ZoneUA.SceneManagement", - "ZoneUA.Persistence" + "ZoneUA.Persistence", + "ZoneUA.Inventory" ], "includePlatforms": [ "Editor" @@ -16,4 +17,4 @@ "defineConstraints": [], "versionDefines": [], "noEngineReferences": false -} \ No newline at end of file +} From 1797c2b7460050e5f3a18a5802263a7d65f00f2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 21:40:27 +0300 Subject: [PATCH 23/61] chore: reference inventory from edit mode tests --- .../_ZoneUA/Tests/EditMode/ZoneUA.Combat.EditModeTests.asmdef | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Assets/_ZoneUA/Tests/EditMode/ZoneUA.Combat.EditModeTests.asmdef b/Assets/_ZoneUA/Tests/EditMode/ZoneUA.Combat.EditModeTests.asmdef index 7999c47..2c525a5 100644 --- a/Assets/_ZoneUA/Tests/EditMode/ZoneUA.Combat.EditModeTests.asmdef +++ b/Assets/_ZoneUA/Tests/EditMode/ZoneUA.Combat.EditModeTests.asmdef @@ -11,7 +11,8 @@ "ZoneUA.Input", "ZoneUA.Performance", "ZoneUA.SceneManagement", - "ZoneUA.Persistence" + "ZoneUA.Persistence", + "ZoneUA.Inventory" ], "includePlatforms": [ "Editor" From 19fdcabaa42c4f93e0c5673fdda4e63ab509f081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 21:40:46 +0300 Subject: [PATCH 24/61] test: cover inventory and construction state --- .../EditMode/InventoryConstructionTests.cs | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 Assets/_ZoneUA/Tests/EditMode/InventoryConstructionTests.cs diff --git a/Assets/_ZoneUA/Tests/EditMode/InventoryConstructionTests.cs b/Assets/_ZoneUA/Tests/EditMode/InventoryConstructionTests.cs new file mode 100644 index 0000000..f4fd3b1 --- /dev/null +++ b/Assets/_ZoneUA/Tests/EditMode/InventoryConstructionTests.cs @@ -0,0 +1,84 @@ +using System.Collections.Generic; +using NUnit.Framework; +using ZoneUA.Inventory; + +namespace ZoneUA.Combat.Tests +{ + public sealed class InventoryConstructionTests + { + [Test] + public void Inventory_AddRemoveAndCapacity_AreDeterministic() + { + var state = new InventoryState(5); + Assert.That(state.Add("wood", 3), Is.True); + Assert.That(state.Add("stone", 2), Is.True); + Assert.That(state.Add("metal", 1), Is.False); + Assert.That(state.Remove("wood", 2), Is.True); + Assert.That(state.GetAmount("wood"), Is.EqualTo(1)); + Assert.That(state.TotalItemCount, Is.EqualTo(3)); + } + + [Test] + public void Inventory_TryConsume_IsAtomic() + { + var state = new InventoryState(); + state.Add("wood", 3); + state.Add("stone", 1); + + bool failed = state.TryConsume(new[] + { + new InventoryEntry("wood", 2), + new InventoryEntry("stone", 2) + }); + + Assert.That(failed, Is.False); + Assert.That(state.GetAmount("wood"), Is.EqualTo(3)); + Assert.That(state.GetAmount("stone"), Is.EqualTo(1)); + + Assert.That(state.TryConsume(new[] + { + new InventoryEntry("wood", 2), + new InventoryEntry("stone", 1) + }), Is.True); + Assert.That(state.GetAmount("wood"), Is.EqualTo(1)); + Assert.That(state.GetAmount("stone"), Is.Zero); + } + + [Test] + public void Inventory_Replace_MergesDuplicateIds() + { + var state = new InventoryState(); + state.Replace(new List + { + new InventoryEntry("wood", 2), + new InventoryEntry("wood", 3), + new InventoryEntry("stone", 1) + }); + + Assert.That(state.GetAmount("wood"), Is.EqualTo(5)); + Assert.That(state.DistinctItemCount, Is.EqualTo(2)); + } + + [Test] + public void Construction_RequiresCommittedResourcesBeforeWork() + { + var state = new ConstructionState(10f); + Assert.That(state.ApplyWork(5f), Is.Zero); + Assert.That(state.CommitResources(), Is.True); + Assert.That(state.ApplyWork(5f), Is.EqualTo(5f)); + Assert.That(state.Progress01, Is.EqualTo(0.5f)); + Assert.That(state.ApplyWork(20f), Is.EqualTo(5f)); + Assert.That(state.IsComplete, Is.True); + } + + [Test] + public void Construction_Restore_ClampsProgress() + { + var state = new ConstructionState(1f); + state.Restore(8f, 50f, true); + Assert.That(state.RequiredWork, Is.EqualTo(8f)); + Assert.That(state.AppliedWork, Is.EqualTo(8f)); + Assert.That(state.IsComplete, Is.True); + } + } +} From 3d0582531be15d93d04858e87a223d0f4d37a7a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 21:41:01 +0300 Subject: [PATCH 25/61] chore: add inventory construction test metadata --- .../Tests/EditMode/InventoryConstructionTests.cs.meta | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Assets/_ZoneUA/Tests/EditMode/InventoryConstructionTests.cs.meta diff --git a/Assets/_ZoneUA/Tests/EditMode/InventoryConstructionTests.cs.meta b/Assets/_ZoneUA/Tests/EditMode/InventoryConstructionTests.cs.meta new file mode 100644 index 0000000..b3d319e --- /dev/null +++ b/Assets/_ZoneUA/Tests/EditMode/InventoryConstructionTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4979ae9e54a447db978c84b7ff36a793 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 0e354753f51ed8e9ac36b5e1641ea4c6d821e621 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 21:41:31 +0300 Subject: [PATCH 26/61] feat: validate inventory and construction content --- .../Editor/ZoneUAInventoryContentValidator.cs | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 Assets/_ZoneUA/Editor/ZoneUAInventoryContentValidator.cs diff --git a/Assets/_ZoneUA/Editor/ZoneUAInventoryContentValidator.cs b/Assets/_ZoneUA/Editor/ZoneUAInventoryContentValidator.cs new file mode 100644 index 0000000..ee63689 --- /dev/null +++ b/Assets/_ZoneUA/Editor/ZoneUAInventoryContentValidator.cs @@ -0,0 +1,100 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEditor; +using UnityEditor.Build; +using UnityEditor.Build.Reporting; +using UnityEngine; +using ZoneUA.Inventory; + +namespace ZoneUA.EditorValidation +{ + public static class ZoneUAInventoryContentValidator + { + [MenuItem("Zone UA/Validation/Validate Inventory and Construction", priority = 45)] + public static void ValidateMenu() + { + bool valid = Validate(logResults: true); + EditorUtility.DisplayDialog("Inventory and construction validation", valid ? "Validation passed." : "Validation failed. See Console.", "OK"); + } + + public static bool Validate(bool logResults) + { + var errors = new List(); + var warnings = new List(); + ValidateItems(errors, warnings); + ValidateConstruction(errors, warnings); + ValidateLoadedObjects(errors, warnings); + + if (logResults) + { + foreach (string warning in warnings) Debug.LogWarning("[Inventory Validation] " + warning); + foreach (string error in errors) Debug.LogError("[Inventory Validation] " + error); + if (errors.Count == 0) Debug.Log($"Inventory validation passed with {warnings.Count} warning(s)."); + } + return errors.Count == 0; + } + + private static void ValidateItems(ICollection errors, ICollection warnings) + { + var seen = new Dictionary(StringComparer.Ordinal); + foreach (string guid in AssetDatabase.FindAssets("t:ItemDefinition")) + { + string path = AssetDatabase.GUIDToAssetPath(guid); + ItemDefinition item = AssetDatabase.LoadAssetAtPath(path); + if (item == null) continue; + if (string.IsNullOrWhiteSpace(item.ItemId)) errors.Add($"ItemDefinition has an empty item ID: {path}"); + else if (seen.TryGetValue(item.ItemId, out string other)) errors.Add($"Duplicate item ID '{item.ItemId}': {other} and {path}"); + else seen[item.ItemId] = path; + if (item.WorldPrefab == null) warnings.Add($"Item '{item.ItemId}' has no world prefab: {path}"); + } + } + + private static void ValidateConstruction(ICollection errors, ICollection warnings) + { + var seen = new Dictionary(StringComparer.Ordinal); + foreach (string guid in AssetDatabase.FindAssets("t:ConstructionDefinition")) + { + string path = AssetDatabase.GUIDToAssetPath(guid); + ConstructionDefinition definition = AssetDatabase.LoadAssetAtPath(path); + if (definition == null) continue; + if (string.IsNullOrWhiteSpace(definition.ConstructionId)) errors.Add($"ConstructionDefinition has an empty ID: {path}"); + else if (seen.TryGetValue(definition.ConstructionId, out string other)) errors.Add($"Duplicate construction ID '{definition.ConstructionId}': {other} and {path}"); + else seen[definition.ConstructionId] = path; + if (definition.CompletedPrefab == null) warnings.Add($"Construction '{definition.ConstructionId}' has no completed prefab: {path}"); + foreach (ConstructionCost cost in definition.Costs) + if (cost == null || cost.item == null || cost.amount <= 0) errors.Add($"Construction '{definition.ConstructionId}' has an invalid cost entry: {path}"); + } + } + + private static void ValidateLoadedObjects(ICollection errors, ICollection warnings) + { + ValidateTypeComposition("InventoryComponent", "InventorySaveParticipant", warnings); + ValidateTypeComposition("WorldItemPickup", "PersistentIdentity", errors); + ValidateTypeComposition("ConstructionSite", "PersistentIdentity", errors); + } + + private static void ValidateTypeComposition(string ownerTypeName, string requiredTypeName, ICollection issues) + { + Type ownerType = RuntimeTypeResolver.Resolve(ownerTypeName); + Type requiredType = RuntimeTypeResolver.Resolve(requiredTypeName); + if (ownerType == null || requiredType == null) return; + foreach (UnityEngine.Object item in Resources.FindObjectsOfTypeAll(ownerType)) + { + if (item is not Component component || EditorUtility.IsPersistent(component)) continue; + if (component.GetComponent(requiredType) == null) + issues.Add($"'{component.name}' contains {ownerTypeName} but is missing {requiredTypeName}."); + } + } + } + + public sealed class ZoneUAInventoryContentBuildValidator : IPreprocessBuildWithReport + { + public int callbackOrder => 90; + public void OnPreprocessBuild(BuildReport report) + { + if (!ZoneUAInventoryContentValidator.Validate(logResults: true)) + throw new BuildFailedException("Inventory or construction content validation failed."); + } + } +} From 0725686bb52bf5ab6813e07835ee47a829358355 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 21:41:45 +0300 Subject: [PATCH 27/61] chore: add inventory validator metadata --- .../Editor/ZoneUAInventoryContentValidator.cs.meta | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Assets/_ZoneUA/Editor/ZoneUAInventoryContentValidator.cs.meta diff --git a/Assets/_ZoneUA/Editor/ZoneUAInventoryContentValidator.cs.meta b/Assets/_ZoneUA/Editor/ZoneUAInventoryContentValidator.cs.meta new file mode 100644 index 0000000..b9a89e3 --- /dev/null +++ b/Assets/_ZoneUA/Editor/ZoneUAInventoryContentValidator.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d575120c9db64612bfaa86337e1d9dba +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 6dc2902c30dcf96caee100f4401a443a41950304 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 21:42:17 +0300 Subject: [PATCH 28/61] feat: add persistent world prefab id to items --- Assets/_ZoneUA/Runtime/Inventory/ItemDefinition.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Assets/_ZoneUA/Runtime/Inventory/ItemDefinition.cs b/Assets/_ZoneUA/Runtime/Inventory/ItemDefinition.cs index 8af6c1d..89438bc 100644 --- a/Assets/_ZoneUA/Runtime/Inventory/ItemDefinition.cs +++ b/Assets/_ZoneUA/Runtime/Inventory/ItemDefinition.cs @@ -11,6 +11,8 @@ public sealed class ItemDefinition : ScriptableObject [SerializeField] private Sprite icon; [SerializeField, Min(1)] private int maximumStack = 1; [SerializeField] private GameObject worldPrefab; + [SerializeField, Tooltip("Prefab catalog ID used when a dropped item must be recreated from a save.")] + private string persistentWorldPrefabId = string.Empty; public string ItemId => itemId; public string DisplayName => string.IsNullOrWhiteSpace(displayName) ? name : displayName; @@ -18,10 +20,12 @@ public sealed class ItemDefinition : ScriptableObject public Sprite Icon => icon; public int MaximumStack => Mathf.Max(1, maximumStack); public GameObject WorldPrefab => worldPrefab; + public string PersistentWorldPrefabId => string.IsNullOrWhiteSpace(persistentWorldPrefabId) ? itemId : persistentWorldPrefabId; private void OnValidate() { itemId = itemId?.Trim() ?? string.Empty; + persistentWorldPrefabId = persistentWorldPrefabId?.Trim() ?? string.Empty; maximumStack = Mathf.Max(1, maximumStack); } } From f8f083a77a24ca4edc95a0200243f8418fc1ca8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 21:42:44 +0300 Subject: [PATCH 29/61] feat: persist dropped world item amounts --- Assets/Script/WorldItemPickup.cs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/Assets/Script/WorldItemPickup.cs b/Assets/Script/WorldItemPickup.cs index e7c3ca9..7644f55 100644 --- a/Assets/Script/WorldItemPickup.cs +++ b/Assets/Script/WorldItemPickup.cs @@ -1,10 +1,17 @@ +using System; using UnityEngine; using ZoneUA.Inventory; using ZoneUA.Persistence; [RequireComponent(typeof(PersistentIdentity))] -public sealed class WorldItemPickup : MonoBehaviour +public sealed class WorldItemPickup : MonoBehaviour, IPersistentSaveParticipant { + [Serializable] + private sealed class Payload + { + public int amount = 1; + } + [SerializeField] private ItemDefinition item; [SerializeField, Min(1)] private int amount = 1; [SerializeField] private bool pickupOnTrigger = true; @@ -14,9 +21,18 @@ public sealed class WorldItemPickup : MonoBehaviour public ItemDefinition Item => item; public int Amount => Mathf.Max(1, amount); + public string ParticipantKey => "world-item"; + public int ParticipantVersion => 1; private void Awake() => identity = GetComponent(); + public void Configure(ItemDefinition definition, int itemAmount) + { + item = definition; + amount = Mathf.Max(1, itemAmount); + consumed = false; + } + public bool TryPickup(InventoryComponent inventory) { if (consumed || inventory == null || item == null || string.IsNullOrWhiteSpace(item.ItemId)) return false; @@ -28,6 +44,15 @@ public bool TryPickup(InventoryComponent inventory) return true; } + public string CaptureState() => JsonUtility.ToJson(new Payload { amount = Amount }); + + public void RestoreState(string payload, int version) + { + Payload restored = string.IsNullOrWhiteSpace(payload) ? new Payload() : JsonUtility.FromJson(payload); + amount = Mathf.Max(1, restored?.amount ?? 1); + consumed = false; + } + private void OnTriggerEnter2D(Collider2D other) { if (!pickupOnTrigger || other == null) return; From 9d78aab8ecec5c800c4905780d182944f4822fda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 21:43:00 +0300 Subject: [PATCH 30/61] feat: add inventory item dropping --- Assets/Script/InventoryDropper.cs | 54 +++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Assets/Script/InventoryDropper.cs diff --git a/Assets/Script/InventoryDropper.cs b/Assets/Script/InventoryDropper.cs new file mode 100644 index 0000000..f94b00c --- /dev/null +++ b/Assets/Script/InventoryDropper.cs @@ -0,0 +1,54 @@ +using System; +using UnityEngine; +using ZoneUA.Inventory; +using ZoneUA.Persistence; + +[RequireComponent(typeof(InventoryComponent))] +public sealed class InventoryDropper : MonoBehaviour +{ + [SerializeField] private ItemCatalog itemCatalog; + [SerializeField] private Transform dropOrigin; + [SerializeField] private Transform droppedItemsRoot; + [SerializeField, Min(0f)] private float forwardOffset = 0.75f; + + private InventoryComponent inventory; + + private void Awake() + { + inventory = GetComponent(); + dropOrigin ??= transform; + } + + public bool Drop(string itemId, int amount = 1) + { + Vector3 position = (dropOrigin != null ? dropOrigin.position : transform.position) + transform.right * forwardOffset; + return DropAt(itemId, amount, position); + } + + public bool DropAt(string itemId, int amount, Vector3 position) + { + inventory ??= GetComponent(); + if (amount <= 0 || itemCatalog == null || !itemCatalog.TryGet(itemId, out ItemDefinition item)) return false; + if (item.WorldPrefab == null || !inventory.Remove(item.ItemId, amount)) return false; + + GameObject instance = null; + try + { + instance = Instantiate(item.WorldPrefab, position, Quaternion.identity, droppedItemsRoot); + PersistentIdentity identity = instance.GetComponent() ?? instance.AddComponent(); + identity.AssignRuntimeId(Guid.NewGuid().ToString("N"), item.PersistentWorldPrefabId); + WorldItemPickup pickup = instance.GetComponent() ?? instance.AddComponent(); + pickup.Configure(item, amount); + return true; + } + catch (Exception exception) + { + inventory.Add(item.ItemId, amount); + if (instance != null) Destroy(instance); + Debug.LogException(exception, this); + return false; + } + } + + private void OnValidate() => forwardOffset = Mathf.Max(0f, forwardOffset); +} From 871ae80513525b65c7ac477e01b03279e40a7f28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 21:43:11 +0300 Subject: [PATCH 31/61] chore: add inventory dropper metadata --- Assets/Script/InventoryDropper.cs.meta | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Assets/Script/InventoryDropper.cs.meta diff --git a/Assets/Script/InventoryDropper.cs.meta b/Assets/Script/InventoryDropper.cs.meta new file mode 100644 index 0000000..e799c01 --- /dev/null +++ b/Assets/Script/InventoryDropper.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 354b3a2f6ac344db94fbec506f61429f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 7b9fe408e03acb411e237fa5e88da970b13fb808 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 21:43:33 +0300 Subject: [PATCH 32/61] docs: add inventory items construction guide --- Docs/INVENTORY_ITEMS_CONSTRUCTION.md | 94 ++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 Docs/INVENTORY_ITEMS_CONSTRUCTION.md diff --git a/Docs/INVENTORY_ITEMS_CONSTRUCTION.md b/Docs/INVENTORY_ITEMS_CONSTRUCTION.md new file mode 100644 index 0000000..70814f8 --- /dev/null +++ b/Docs/INVENTORY_ITEMS_CONSTRUCTION.md @@ -0,0 +1,94 @@ +# Inventory, Items and Construction + +This module adds definition-driven items, deterministic inventory state, persistent pickup/drop objects and persistent construction progress. + +## Assets + +Create item assets with: + +`Create -> Zone UA -> Inventory -> Item Definition` + +Each item requires a unique `Item Id`. `World Prefab` is used when dropping the item. `Persistent World Prefab Id` must match an entry in `PersistentPrefabCatalog`; when empty it falls back to the item ID. + +Create a catalog with: + +`Create -> Zone UA -> Inventory -> Item Catalog` + +Create buildable definitions with: + +`Create -> Zone UA -> Construction -> Definition` + +A construction definition contains a stable ID, required work, material costs and the completed prefab reference. + +## Player composition + +Add these components to the persistent player root: + +- `PersistentIdentity` +- `InventoryComponent` +- `InventorySaveParticipant` +- `InventoryDropper` + +Assign the `ItemCatalog` to `InventoryDropper`. Capacity `0` means unlimited capacity. + +## World pickup prefab + +A dropped or authored pickup should contain: + +- `PersistentIdentity` +- `TransformSaveParticipant` +- `WorldItemPickup` +- a trigger collider + +Register runtime pickup prefabs in `PersistentPrefabCatalog`. `InventoryDropper` assigns a new logical object ID and configures the dropped stack amount. `WorldItemPickup` persists its amount through participant key `world-item`. + +When a pickup succeeds it calls `PersistentIdentity.MarkDestroyed()`, creating a tombstone. The item therefore does not reappear after save/load. + +## Construction composition + +A persistent construction object should contain: + +- `PersistentIdentity` +- `TransformSaveParticipant` +- `ConstructionSite` + +`ConstructionSite` is itself a save participant with key `construction`. It stores required work, applied work and whether resources were committed. + +Typical flow: + +1. Place the construction-site prefab. +2. Call `CommitResources(playerInventory)` once. +3. Call `ApplyWork(amount)` from worker or interaction logic. +4. Swap `Incomplete Root` and `Completed Root` when progress reaches 100%. +5. Save/load restores the exact construction progress. + +Resource consumption is atomic. If any required material is missing, no material is removed. + +## Validation + +Run: + +`Zone UA -> Validation -> Validate Inventory and Construction` + +The validator reports: + +- empty or duplicate item IDs; +- empty or duplicate construction IDs; +- invalid construction costs; +- item definitions without world prefabs; +- loaded inventories without `InventorySaveParticipant`; +- pickups or construction sites without `PersistentIdentity`. + +Errors block Unity builds. Missing optional presentation references remain warnings. + +## Required Play Mode checks + +- collect a world pickup and confirm inventory count changes; +- save, reload and confirm the collected object remains absent; +- drop a stack and confirm a new stable object ID is assigned; +- save, reload and confirm the dropped stack and amount restore once; +- verify full inventory prevents pickup without creating a tombstone; +- commit construction resources and verify exact atomic deduction; +- partially build, save and reload; +- complete construction and verify the completed visual persists; +- validate duplicate item/construction IDs are blocked. From 04c16c12599c2ebd2ced7fd2b997da96d5940b45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 21:43:47 +0300 Subject: [PATCH 33/61] chore: add inventory documentation metadata --- Docs/INVENTORY_ITEMS_CONSTRUCTION.md.meta | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Docs/INVENTORY_ITEMS_CONSTRUCTION.md.meta diff --git a/Docs/INVENTORY_ITEMS_CONSTRUCTION.md.meta b/Docs/INVENTORY_ITEMS_CONSTRUCTION.md.meta new file mode 100644 index 0000000..cfb7c72 --- /dev/null +++ b/Docs/INVENTORY_ITEMS_CONSTRUCTION.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: b969208f41294ce1b278928de7d29094 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: From 159693ce29b9a24167e8608f345b445ceef71ba4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 22:15:54 +0300 Subject: [PATCH 34/61] refactor: remove out-of-scope construction gameplay --- Assets/Script/ConstructionSite.cs | 91 ------------------------------- 1 file changed, 91 deletions(-) delete mode 100644 Assets/Script/ConstructionSite.cs diff --git a/Assets/Script/ConstructionSite.cs b/Assets/Script/ConstructionSite.cs deleted file mode 100644 index 4eeb619..0000000 --- a/Assets/Script/ConstructionSite.cs +++ /dev/null @@ -1,91 +0,0 @@ -using System; -using UnityEngine; -using ZoneUA.Inventory; -using ZoneUA.Persistence; - -[RequireComponent(typeof(PersistentIdentity))] -public sealed class ConstructionSite : MonoBehaviour, IPersistentSaveParticipant -{ - [Serializable] - private sealed class Payload - { - public string constructionId = string.Empty; - public float requiredWork; - public float appliedWork; - public bool resourcesCommitted; - } - - [SerializeField] private ConstructionDefinition definition; - [SerializeField] private GameObject incompleteRoot; - [SerializeField] private GameObject completedRoot; - - private ConstructionState state; - - public event Action ProgressChanged; - public event Action Completed; - - public ConstructionDefinition Definition => definition; - public bool IsComplete => State.IsComplete; - public float Progress01 => State.Progress01; - public string ParticipantKey => "construction"; - public int ParticipantVersion => 1; - private ConstructionState State => state ??= new ConstructionState(definition != null ? definition.RequiredWork : 1f); - - private void Awake() - { - state = new ConstructionState(definition != null ? definition.RequiredWork : 1f); - RefreshVisuals(); - } - - public bool CommitResources(InventoryComponent inventory) - { - if (definition == null || inventory == null || State.ResourcesCommitted) return false; - if (!inventory.TryConsume(definition.BuildCostEntries())) return false; - State.CommitResources(); - ProgressChanged?.Invoke(State.Progress01); - return true; - } - - public float ApplyWork(float amount) - { - bool wasComplete = State.IsComplete; - float applied = State.ApplyWork(amount); - if (applied <= 0f) return 0f; - ProgressChanged?.Invoke(State.Progress01); - if (!wasComplete && State.IsComplete) - { - RefreshVisuals(); - Completed?.Invoke(); - } - return applied; - } - - public string CaptureState() - { - var payload = new Payload - { - constructionId = definition != null ? definition.ConstructionId : string.Empty, - requiredWork = State.RequiredWork, - appliedWork = State.AppliedWork, - resourcesCommitted = State.ResourcesCommitted - }; - return JsonUtility.ToJson(payload); - } - - public void RestoreState(string payload, int version) - { - Payload restored = string.IsNullOrWhiteSpace(payload) ? new Payload() : JsonUtility.FromJson(payload); - float required = restored != null && restored.requiredWork > 0f - ? restored.requiredWork - : definition != null ? definition.RequiredWork : 1f; - State.Restore(required, restored?.appliedWork ?? 0f, restored?.resourcesCommitted ?? false); - RefreshVisuals(); - ProgressChanged?.Invoke(State.Progress01); - } - - private void RefreshVisuals() - { - if (incompleteRoot != null) incompleteRoot.SetActive(!State.IsComplete); - if (completedRoot != null) completedRoot.SetActive(State.IsComplete); - } -} From b1fb26886a3e5b4c069a30bb1df66d75a67126c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 22:16:05 +0300 Subject: [PATCH 35/61] refactor: remove construction script metadata --- Assets/Script/ConstructionSite.cs.meta | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 Assets/Script/ConstructionSite.cs.meta diff --git a/Assets/Script/ConstructionSite.cs.meta b/Assets/Script/ConstructionSite.cs.meta deleted file mode 100644 index 28269b1..0000000 --- a/Assets/Script/ConstructionSite.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: f4dc0cc5f2044d7f876ea0ee4ad588f1 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: From 2d8c47735b681b6c9447ab8b74576689f930480a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 22:16:17 +0300 Subject: [PATCH 36/61] refactor: remove construction definitions from RPG inventory module --- .../Inventory/ConstructionDefinition.cs | 44 ------------------- 1 file changed, 44 deletions(-) delete mode 100644 Assets/_ZoneUA/Runtime/Inventory/ConstructionDefinition.cs diff --git a/Assets/_ZoneUA/Runtime/Inventory/ConstructionDefinition.cs b/Assets/_ZoneUA/Runtime/Inventory/ConstructionDefinition.cs deleted file mode 100644 index 6120ac7..0000000 --- a/Assets/_ZoneUA/Runtime/Inventory/ConstructionDefinition.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System; -using System.Collections.Generic; -using UnityEngine; - -namespace ZoneUA.Inventory -{ - [Serializable] - public sealed class ConstructionCost - { - public ItemDefinition item; - [Min(1)] public int amount = 1; - } - - [CreateAssetMenu(menuName = "Zone UA/Construction/Definition", fileName = "ConstructionDefinition")] - public sealed class ConstructionDefinition : ScriptableObject - { - [SerializeField] private string constructionId = string.Empty; - [SerializeField] private GameObject completedPrefab; - [SerializeField, Min(0.01f)] private float requiredWork = 1f; - [SerializeField] private List costs = new List(); - - public string ConstructionId => constructionId; - public GameObject CompletedPrefab => completedPrefab; - public float RequiredWork => Mathf.Max(0.01f, requiredWork); - public IReadOnlyList Costs => costs; - - public List BuildCostEntries() - { - var result = new List(); - foreach (ConstructionCost cost in costs) - { - if (cost?.item == null || string.IsNullOrWhiteSpace(cost.item.ItemId) || cost.amount <= 0) continue; - result.Add(new InventoryEntry(cost.item.ItemId, cost.amount)); - } - return result; - } - - private void OnValidate() - { - constructionId = constructionId?.Trim() ?? string.Empty; - requiredWork = Mathf.Max(0.01f, requiredWork); - } - } -} From 6ed26cdaac67d5f8704ffefd0a19fb012cfa8568 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 22:16:28 +0300 Subject: [PATCH 37/61] refactor: remove construction definition metadata --- .../Runtime/Inventory/ConstructionDefinition.cs.meta | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 Assets/_ZoneUA/Runtime/Inventory/ConstructionDefinition.cs.meta diff --git a/Assets/_ZoneUA/Runtime/Inventory/ConstructionDefinition.cs.meta b/Assets/_ZoneUA/Runtime/Inventory/ConstructionDefinition.cs.meta deleted file mode 100644 index 1bfaf89..0000000 --- a/Assets/_ZoneUA/Runtime/Inventory/ConstructionDefinition.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: e0c623291b4745b3ba278849d48f41f1 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: From a151ed948646f7347163aa3749aed703b71ce128 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 22:16:37 +0300 Subject: [PATCH 38/61] refactor: remove construction state from loot module --- .../Runtime/Inventory/ConstructionState.cs | 47 ------------------- 1 file changed, 47 deletions(-) delete mode 100644 Assets/_ZoneUA/Runtime/Inventory/ConstructionState.cs diff --git a/Assets/_ZoneUA/Runtime/Inventory/ConstructionState.cs b/Assets/_ZoneUA/Runtime/Inventory/ConstructionState.cs deleted file mode 100644 index 5ba8698..0000000 --- a/Assets/_ZoneUA/Runtime/Inventory/ConstructionState.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; - -namespace ZoneUA.Inventory -{ - [Serializable] - public sealed class ConstructionState - { - private float requiredWork; - private float appliedWork; - private bool resourcesCommitted; - - public ConstructionState(float requiredWork, float appliedWork = 0f, bool resourcesCommitted = false) - { - this.requiredWork = Math.Max(0.01f, requiredWork); - this.appliedWork = Math.Clamp(appliedWork, 0f, this.requiredWork); - this.resourcesCommitted = resourcesCommitted; - } - - public float RequiredWork => requiredWork; - public float AppliedWork => appliedWork; - public bool ResourcesCommitted => resourcesCommitted; - public bool IsComplete => appliedWork >= requiredWork; - public float Progress01 => requiredWork <= 0f ? 1f : appliedWork / requiredWork; - - public bool CommitResources() - { - if (resourcesCommitted) return false; - resourcesCommitted = true; - return true; - } - - public float ApplyWork(float amount) - { - if (!resourcesCommitted || IsComplete || amount <= 0f) return 0f; - float previous = appliedWork; - appliedWork = Math.Min(requiredWork, appliedWork + amount); - return appliedWork - previous; - } - - public void Restore(float newRequiredWork, float newAppliedWork, bool committed) - { - requiredWork = Math.Max(0.01f, newRequiredWork); - appliedWork = Math.Clamp(newAppliedWork, 0f, requiredWork); - resourcesCommitted = committed; - } - } -} From 05c55794dfda5596c48b97bd24729ded57d993ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 22:17:00 +0300 Subject: [PATCH 39/61] refactor: remove construction state metadata --- .../Runtime/Inventory/ConstructionState.cs.meta | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 Assets/_ZoneUA/Runtime/Inventory/ConstructionState.cs.meta diff --git a/Assets/_ZoneUA/Runtime/Inventory/ConstructionState.cs.meta b/Assets/_ZoneUA/Runtime/Inventory/ConstructionState.cs.meta deleted file mode 100644 index 75fa2d5..0000000 --- a/Assets/_ZoneUA/Runtime/Inventory/ConstructionState.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: a8dac1bc1f7d497e8a051ed1c4fe68fd -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: From ab066998c81fd66507f11ebe20b5f55055a2d490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 22:17:20 +0300 Subject: [PATCH 40/61] feat: add atomic inventory transfer support --- Assets/_ZoneUA/Runtime/Inventory/InventoryState.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Assets/_ZoneUA/Runtime/Inventory/InventoryState.cs b/Assets/_ZoneUA/Runtime/Inventory/InventoryState.cs index 8686322..782a1a9 100644 --- a/Assets/_ZoneUA/Runtime/Inventory/InventoryState.cs +++ b/Assets/_ZoneUA/Runtime/Inventory/InventoryState.cs @@ -27,6 +27,7 @@ public sealed class InventoryState public int Capacity => capacity; public int DistinctItemCount => amounts.Count; public int TotalItemCount => amounts.Values.Sum(); + public int FreeCapacity => capacity <= 0 ? int.MaxValue : Math.Max(0, capacity - TotalItemCount); public IReadOnlyList Entries => amounts.OrderBy(pair => pair.Key, StringComparer.Ordinal).Select(pair => new InventoryEntry(pair.Key, pair.Value)).ToList(); public int GetAmount(string itemId) => Normalize(itemId) is string id && amounts.TryGetValue(id, out int value) ? value : 0; @@ -65,6 +66,17 @@ public bool TryConsume(IEnumerable costs) return true; } + public bool TryTransferTo(InventoryState destination, string itemId, int amount) + { + if (destination == null || ReferenceEquals(destination, this) || amount <= 0) return false; + string id = Normalize(itemId); + if (string.IsNullOrEmpty(id) || !Has(id, amount) || !destination.CanAdd(id, amount)) return false; + if (!Remove(id, amount)) return false; + if (destination.Add(id, amount)) return true; + Add(id, amount); + return false; + } + public void Replace(IEnumerable entries) { amounts.Clear(); @@ -75,7 +87,7 @@ public void Replace(IEnumerable entries) } } - private static List NormalizeEntries(IEnumerable entries) + public static List NormalizeEntries(IEnumerable entries) { return (entries ?? Array.Empty()) .Where(entry => entry != null && entry.amount > 0 && !string.IsNullOrWhiteSpace(entry.itemId)) From c7da67c60e9eda7b656675c9cb766684cda00488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 22:17:35 +0300 Subject: [PATCH 41/61] feat: add RPG loot valuation metadata --- .../Runtime/Inventory/ItemDefinition.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Assets/_ZoneUA/Runtime/Inventory/ItemDefinition.cs b/Assets/_ZoneUA/Runtime/Inventory/ItemDefinition.cs index 89438bc..19b0833 100644 --- a/Assets/_ZoneUA/Runtime/Inventory/ItemDefinition.cs +++ b/Assets/_ZoneUA/Runtime/Inventory/ItemDefinition.cs @@ -2,12 +2,27 @@ namespace ZoneUA.Inventory { + public enum ItemCategory + { + Miscellaneous = 0, + Weapon = 1, + Ammunition = 2, + Medical = 3, + Armour = 4, + Consumable = 5, + Quest = 6, + Valuable = 7 + } + [CreateAssetMenu(menuName = "Zone UA/Inventory/Item Definition", fileName = "ItemDefinition")] public sealed class ItemDefinition : ScriptableObject { [SerializeField] private string itemId = string.Empty; [SerializeField] private string displayName = string.Empty; [SerializeField, TextArea] private string description = string.Empty; + [SerializeField] private ItemCategory category; + [SerializeField, Min(0)] private int baseValue; + [SerializeField, Min(0f)] private float weight; [SerializeField] private Sprite icon; [SerializeField, Min(1)] private int maximumStack = 1; [SerializeField] private GameObject worldPrefab; @@ -17,6 +32,9 @@ public sealed class ItemDefinition : ScriptableObject public string ItemId => itemId; public string DisplayName => string.IsNullOrWhiteSpace(displayName) ? name : displayName; public string Description => description; + public ItemCategory Category => category; + public int BaseValue => Mathf.Max(0, baseValue); + public float Weight => Mathf.Max(0f, weight); public Sprite Icon => icon; public int MaximumStack => Mathf.Max(1, maximumStack); public GameObject WorldPrefab => worldPrefab; @@ -26,6 +44,8 @@ private void OnValidate() { itemId = itemId?.Trim() ?? string.Empty; persistentWorldPrefabId = persistentWorldPrefabId?.Trim() ?? string.Empty; + baseValue = Mathf.Max(0, baseValue); + weight = Mathf.Max(0f, weight); maximumStack = Mathf.Max(1, maximumStack); } } From 3e80ab9fa4bae4ea31e828e6224b4104197ec35c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 22:17:49 +0300 Subject: [PATCH 42/61] feat: add loot source contracts and state --- .../Runtime/Inventory/LootContracts.cs | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Assets/_ZoneUA/Runtime/Inventory/LootContracts.cs diff --git a/Assets/_ZoneUA/Runtime/Inventory/LootContracts.cs b/Assets/_ZoneUA/Runtime/Inventory/LootContracts.cs new file mode 100644 index 0000000..d5206b7 --- /dev/null +++ b/Assets/_ZoneUA/Runtime/Inventory/LootContracts.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; + +namespace ZoneUA.Inventory +{ + public enum LootSourceKind + { + WorldItem = 0, + Container = 1, + Corpse = 2 + } + + public enum LootSearchState + { + Unsearched = 0, + Searched = 1, + Empty = 2 + } + + public interface ILootSource + { + string LootSourceId { get; } + LootSourceKind Kind { get; } + LootSearchState SearchState { get; } + bool IsAvailable { get; } + IReadOnlyList Entries { get; } + void MarkSearched(); + bool TryTake(InventoryState destination, string itemId, int amount); + } + + [Serializable] + public sealed class LootContainerState + { + private readonly InventoryState inventory; + private LootSearchState searchState; + + public LootContainerState(int capacity = 0, IEnumerable initialItems = null, bool startsSearched = false) + { + inventory = new InventoryState(capacity); + inventory.Replace(initialItems); + searchState = startsSearched ? ResolveVisibleState() : LootSearchState.Unsearched; + } + + public InventoryState Inventory => inventory; + public LootSearchState SearchState => searchState; + public bool IsAvailable => inventory.TotalItemCount > 0; + public IReadOnlyList Entries => inventory.Entries; + + public void MarkSearched() => searchState = ResolveVisibleState(); + + public bool TryTake(InventoryState destination, string itemId, int amount) + { + if (searchState == LootSearchState.Unsearched || destination == null) return false; + bool transferred = inventory.TryTransferTo(destination, itemId, amount); + if (transferred) searchState = ResolveVisibleState(); + return transferred; + } + + public void Restore(IEnumerable entries, LootSearchState restoredState) + { + inventory.Replace(entries); + searchState = inventory.TotalItemCount == 0 + ? LootSearchState.Empty + : restoredState == LootSearchState.Unsearched ? LootSearchState.Unsearched : LootSearchState.Searched; + } + + private LootSearchState ResolveVisibleState() => inventory.TotalItemCount == 0 ? LootSearchState.Empty : LootSearchState.Searched; + } +} From 18a16569d2a2548ec1b127a2a1623d4442e003f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 22:17:59 +0300 Subject: [PATCH 43/61] chore: add loot contracts metadata --- .../_ZoneUA/Runtime/Inventory/LootContracts.cs.meta | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Assets/_ZoneUA/Runtime/Inventory/LootContracts.cs.meta diff --git a/Assets/_ZoneUA/Runtime/Inventory/LootContracts.cs.meta b/Assets/_ZoneUA/Runtime/Inventory/LootContracts.cs.meta new file mode 100644 index 0000000..1e742c6 --- /dev/null +++ b/Assets/_ZoneUA/Runtime/Inventory/LootContracts.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4e4f9dc4dbeb4ce5a1cff5d71ae8d7a1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 8ca1b610b90cedd61ddacf0adc699fca8a474488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 22:18:17 +0300 Subject: [PATCH 44/61] feat: add runtime loot reservation registry --- .../Inventory/LootReservationRegistry.cs | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 Assets/_ZoneUA/Runtime/Inventory/LootReservationRegistry.cs diff --git a/Assets/_ZoneUA/Runtime/Inventory/LootReservationRegistry.cs b/Assets/_ZoneUA/Runtime/Inventory/LootReservationRegistry.cs new file mode 100644 index 0000000..8ec2c6d --- /dev/null +++ b/Assets/_ZoneUA/Runtime/Inventory/LootReservationRegistry.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; + +namespace ZoneUA.Inventory +{ + public sealed class LootReservationRegistry + { + private sealed class Reservation + { + public string ownerId; + public double expiresAt; + } + + private readonly Dictionary reservations = new Dictionary(StringComparer.Ordinal); + + public bool TryReserve(string sourceId, string ownerId, double now, double durationSeconds) + { + sourceId = Normalize(sourceId); + ownerId = Normalize(ownerId); + if (string.IsNullOrEmpty(sourceId) || string.IsNullOrEmpty(ownerId) || durationSeconds <= 0d) return false; + PruneExpired(now); + if (reservations.TryGetValue(sourceId, out Reservation existing) && !string.Equals(existing.ownerId, ownerId, StringComparison.Ordinal)) return false; + reservations[sourceId] = new Reservation { ownerId = ownerId, expiresAt = now + durationSeconds }; + return true; + } + + public bool IsReservedByOther(string sourceId, string ownerId, double now) + { + PruneExpired(now); + sourceId = Normalize(sourceId); + ownerId = Normalize(ownerId); + return reservations.TryGetValue(sourceId, out Reservation existing) + && !string.Equals(existing.ownerId, ownerId, StringComparison.Ordinal); + } + + public void Release(string sourceId, string ownerId) + { + sourceId = Normalize(sourceId); + ownerId = Normalize(ownerId); + if (!reservations.TryGetValue(sourceId, out Reservation existing)) return; + if (string.IsNullOrEmpty(ownerId) || string.Equals(existing.ownerId, ownerId, StringComparison.Ordinal)) reservations.Remove(sourceId); + } + + public void ReleaseAll(string ownerId) + { + ownerId = Normalize(ownerId); + if (string.IsNullOrEmpty(ownerId)) return; + var keys = new List(); + foreach (KeyValuePair pair in reservations) + if (string.Equals(pair.Value.ownerId, ownerId, StringComparison.Ordinal)) keys.Add(pair.Key); + foreach (string key in keys) reservations.Remove(key); + } + + public void PruneExpired(double now) + { + var keys = new List(); + foreach (KeyValuePair pair in reservations) + if (pair.Value.expiresAt <= now) keys.Add(pair.Key); + foreach (string key in keys) reservations.Remove(key); + } + + private static string Normalize(string value) => string.IsNullOrWhiteSpace(value) ? string.Empty : value.Trim(); + } +} From da715501e19a804094d43e42cd81dbfd26034c5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 22:18:31 +0300 Subject: [PATCH 45/61] chore: add loot reservation metadata --- .../Runtime/Inventory/LootReservationRegistry.cs.meta | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Assets/_ZoneUA/Runtime/Inventory/LootReservationRegistry.cs.meta diff --git a/Assets/_ZoneUA/Runtime/Inventory/LootReservationRegistry.cs.meta b/Assets/_ZoneUA/Runtime/Inventory/LootReservationRegistry.cs.meta new file mode 100644 index 0000000..b089b3a --- /dev/null +++ b/Assets/_ZoneUA/Runtime/Inventory/LootReservationRegistry.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 91e41e8c598b451fb1f0d3b7cf0a2c2b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 5443ff2f33b2514ca6b8456a4fe3013b6279be47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 22:18:55 +0300 Subject: [PATCH 46/61] feat: add persistent searchable loot containers --- Assets/Script/LootContainer.cs | 96 ++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 Assets/Script/LootContainer.cs diff --git a/Assets/Script/LootContainer.cs b/Assets/Script/LootContainer.cs new file mode 100644 index 0000000..c337029 --- /dev/null +++ b/Assets/Script/LootContainer.cs @@ -0,0 +1,96 @@ +using System; +using System.Collections.Generic; +using UnityEngine; +using ZoneUA.Inventory; +using ZoneUA.Persistence; + +[RequireComponent(typeof(PersistentIdentity), typeof(InventoryComponent), typeof(InventorySaveParticipant))] +public sealed class LootContainer : MonoBehaviour, ILootSource, IPersistentSaveParticipant +{ + [Serializable] + private sealed class Payload + { + public LootSearchState searchState; + } + + [SerializeField] private LootSourceKind kind = LootSourceKind.Container; + [SerializeField, Min(0f)] private float searchDurationSeconds = 1f; + [SerializeField] private bool startsSearched; + + private PersistentIdentity identity; + private InventoryComponent inventory; + private LootSearchState searchState; + + public event Action SearchStateChanged; + public event Action ContentsChanged; + + public string LootSourceId => identity != null ? identity.ObjectId : string.Empty; + public LootSourceKind Kind => kind; + public LootSearchState SearchState => searchState; + public bool IsAvailable => inventory != null && inventory.TotalItemCount > 0; + public IReadOnlyList Entries => inventory != null ? inventory.Entries : Array.Empty(); + public float SearchDurationSeconds => Mathf.Max(0f, searchDurationSeconds); + public string ParticipantKey => "loot-source"; + public int ParticipantVersion => 1; + + private void Awake() + { + identity = GetComponent(); + inventory = GetComponent(); + searchState = startsSearched ? ResolveVisibleState() : LootSearchState.Unsearched; + inventory.InventoryChanged += HandleContentsChanged; + } + + private void OnDestroy() + { + if (inventory != null) inventory.InventoryChanged -= HandleContentsChanged; + } + + public void MarkSearched() + { + LootSearchState next = ResolveVisibleState(); + if (searchState == next) return; + searchState = next; + SearchStateChanged?.Invoke(searchState); + } + + public bool TryTake(InventoryState destination, string itemId, int amount) + { + if (searchState == LootSearchState.Unsearched || inventory == null || destination == null) return false; + bool transferred = inventory.State.TryTransferTo(destination, itemId, amount); + if (transferred) HandleContentsChanged(); + return transferred; + } + + public bool TryTake(InventoryComponent destination, string itemId, int amount) + { + if (destination == null) return false; + bool transferred = TryTake(destination.State, itemId, amount); + if (transferred) destination.NotifyExternalChange(); + return transferred; + } + + public string CaptureState() => JsonUtility.ToJson(new Payload { searchState = searchState }); + + public void RestoreState(string payload, int version) + { + Payload restored = string.IsNullOrWhiteSpace(payload) ? null : JsonUtility.FromJson(payload); + searchState = restored != null ? restored.searchState : startsSearched ? ResolveVisibleState() : LootSearchState.Unsearched; + if (!IsAvailable) searchState = LootSearchState.Empty; + SearchStateChanged?.Invoke(searchState); + } + + private void HandleContentsChanged() + { + if (!IsAvailable && searchState != LootSearchState.Empty) + { + searchState = LootSearchState.Empty; + SearchStateChanged?.Invoke(searchState); + } + ContentsChanged?.Invoke(); + } + + private LootSearchState ResolveVisibleState() => IsAvailable ? LootSearchState.Searched : LootSearchState.Empty; + + private void OnValidate() => searchDurationSeconds = Mathf.Max(0f, searchDurationSeconds); +} From 68848e1b48812074bc9e5687e9b5b93ccb305290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 22:19:14 +0300 Subject: [PATCH 47/61] feat: expose inventory transfer notifications --- Assets/Script/InventoryComponent.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Assets/Script/InventoryComponent.cs b/Assets/Script/InventoryComponent.cs index 9380455..e9017ca 100644 --- a/Assets/Script/InventoryComponent.cs +++ b/Assets/Script/InventoryComponent.cs @@ -25,30 +25,40 @@ public sealed class InventoryComponent : MonoBehaviour public bool Add(string itemId, int amount) { if (!State.Add(itemId, amount)) return false; - InventoryChanged?.Invoke(); + NotifyExternalChange(); return true; } public bool Remove(string itemId, int amount) { if (!State.Remove(itemId, amount)) return false; - InventoryChanged?.Invoke(); + NotifyExternalChange(); return true; } public bool TryConsume(IEnumerable costs) { if (!State.TryConsume(costs)) return false; - InventoryChanged?.Invoke(); + NotifyExternalChange(); + return true; + } + + public bool TryTransferTo(InventoryComponent destination, string itemId, int amount) + { + if (destination == null || !State.TryTransferTo(destination.State, itemId, amount)) return false; + NotifyExternalChange(); + destination.NotifyExternalChange(); return true; } public void ReplaceContents(IEnumerable entries) { State.Replace(entries); - InventoryChanged?.Invoke(); + NotifyExternalChange(); } + public void NotifyExternalChange() => InventoryChanged?.Invoke(); + private InventoryState CreateState() { var result = new InventoryState(capacity); From 74f6c57da01a6d5dec19bae1b3c41b759c49a757 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 22:19:23 +0300 Subject: [PATCH 48/61] chore: add loot container metadata --- Assets/Script/LootContainer.cs.meta | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Assets/Script/LootContainer.cs.meta diff --git a/Assets/Script/LootContainer.cs.meta b/Assets/Script/LootContainer.cs.meta new file mode 100644 index 0000000..e84d227 --- /dev/null +++ b/Assets/Script/LootContainer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6b7dd22bb0d74aeca348e26af07d6f38 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 3d07d75ac0d1a9e4063b6a8a909283811f3db5de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 22:19:36 +0300 Subject: [PATCH 49/61] feat: add corpse inventory snapshots --- Assets/Script/CorpseLootContainer.cs | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Assets/Script/CorpseLootContainer.cs diff --git a/Assets/Script/CorpseLootContainer.cs b/Assets/Script/CorpseLootContainer.cs new file mode 100644 index 0000000..42ee668 --- /dev/null +++ b/Assets/Script/CorpseLootContainer.cs @@ -0,0 +1,33 @@ +using System.Collections.Generic; +using UnityEngine; +using ZoneUA.Inventory; + +[RequireComponent(typeof(LootContainer), typeof(InventoryComponent))] +public sealed class CorpseLootContainer : MonoBehaviour +{ + [SerializeField] private bool clearSourceInventory = true; + + private InventoryComponent corpseInventory; + private LootContainer lootContainer; + + public bool IsInitialised { get; private set; } + + private void Awake() + { + corpseInventory = GetComponent(); + lootContainer = GetComponent(); + } + + public bool InitialiseFrom(InventoryComponent sourceInventory) + { + if (IsInitialised || sourceInventory == null || sourceInventory == corpseInventory) return false; + + List snapshot = new List(sourceInventory.Entries); + corpseInventory.ReplaceContents(snapshot); + if (clearSourceInventory) sourceInventory.ReplaceContents(System.Array.Empty()); + + lootContainer.MarkSearched(); + IsInitialised = true; + return true; + } +} From d08cde1f2b428da437ef22cefa1b893056d5bd44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 22:19:47 +0300 Subject: [PATCH 50/61] chore: add corpse loot metadata --- Assets/Script/CorpseLootContainer.cs.meta | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Assets/Script/CorpseLootContainer.cs.meta diff --git a/Assets/Script/CorpseLootContainer.cs.meta b/Assets/Script/CorpseLootContainer.cs.meta new file mode 100644 index 0000000..952ef95 --- /dev/null +++ b/Assets/Script/CorpseLootContainer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4a5a67ee4bb7410fb69a0dbdd5503ec1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From abf8c4880565dad047386cd0d269aefed7842613 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 22:20:14 +0300 Subject: [PATCH 51/61] feat: expose world items through loot source contract --- Assets/Script/WorldItemPickup.cs | 35 +++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/Assets/Script/WorldItemPickup.cs b/Assets/Script/WorldItemPickup.cs index 7644f55..535f984 100644 --- a/Assets/Script/WorldItemPickup.cs +++ b/Assets/Script/WorldItemPickup.cs @@ -1,10 +1,11 @@ using System; +using System.Collections.Generic; using UnityEngine; using ZoneUA.Inventory; using ZoneUA.Persistence; [RequireComponent(typeof(PersistentIdentity))] -public sealed class WorldItemPickup : MonoBehaviour, IPersistentSaveParticipant +public sealed class WorldItemPickup : MonoBehaviour, ILootSource, IPersistentSaveParticipant { [Serializable] private sealed class Payload @@ -21,6 +22,13 @@ private sealed class Payload public ItemDefinition Item => item; public int Amount => Mathf.Max(1, amount); + public string LootSourceId => identity != null ? identity.ObjectId : string.Empty; + public LootSourceKind Kind => LootSourceKind.WorldItem; + public LootSearchState SearchState => consumed ? LootSearchState.Empty : LootSearchState.Searched; + public bool IsAvailable => !consumed && item != null && !string.IsNullOrWhiteSpace(item.ItemId); + public IReadOnlyList Entries => IsAvailable + ? new[] { new InventoryEntry(item.ItemId, Amount) } + : Array.Empty(); public string ParticipantKey => "world-item"; public int ParticipantVersion => 1; @@ -33,14 +41,20 @@ public void Configure(ItemDefinition definition, int itemAmount) consumed = false; } - public bool TryPickup(InventoryComponent inventory) + public void MarkSearched() { } + + public bool TryTake(InventoryState destination, string itemId, int requestedAmount) { - if (consumed || inventory == null || item == null || string.IsNullOrWhiteSpace(item.ItemId)) return false; - if (!inventory.Add(item.ItemId, Amount)) return false; + if (!IsAvailable || destination == null || requestedAmount != Amount || !string.Equals(item.ItemId, itemId, StringComparison.Ordinal)) return false; + if (!destination.Add(item.ItemId, Amount)) return false; + Consume(); + return true; + } - consumed = true; - identity ??= GetComponent(); - identity.MarkDestroyed(); + public bool TryPickup(InventoryComponent inventory) + { + if (inventory == null || !TryTake(inventory.State, item != null ? item.ItemId : string.Empty, Amount)) return false; + inventory.NotifyExternalChange(); return true; } @@ -53,6 +67,13 @@ public void RestoreState(string payload, int version) consumed = false; } + private void Consume() + { + consumed = true; + identity ??= GetComponent(); + identity.MarkDestroyed(); + } + private void OnTriggerEnter2D(Collider2D other) { if (!pickupOnTrigger || other == null) return; From fa377bbfb88185dfbc24c3024affef65eeeddc4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 22:20:35 +0300 Subject: [PATCH 52/61] refactor: validate RPG inventory and loot sources --- .../Editor/ZoneUAInventoryContentValidator.cs | 33 +++++-------------- 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/Assets/_ZoneUA/Editor/ZoneUAInventoryContentValidator.cs b/Assets/_ZoneUA/Editor/ZoneUAInventoryContentValidator.cs index ee63689..4db1be2 100644 --- a/Assets/_ZoneUA/Editor/ZoneUAInventoryContentValidator.cs +++ b/Assets/_ZoneUA/Editor/ZoneUAInventoryContentValidator.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using UnityEditor; using UnityEditor.Build; using UnityEditor.Build.Reporting; @@ -11,11 +10,11 @@ namespace ZoneUA.EditorValidation { public static class ZoneUAInventoryContentValidator { - [MenuItem("Zone UA/Validation/Validate Inventory and Construction", priority = 45)] + [MenuItem("Zone UA/Validation/Validate Inventory and Loot", priority = 45)] public static void ValidateMenu() { bool valid = Validate(logResults: true); - EditorUtility.DisplayDialog("Inventory and construction validation", valid ? "Validation passed." : "Validation failed. See Console.", "OK"); + EditorUtility.DisplayDialog("Inventory and loot validation", valid ? "Validation passed." : "Validation failed. See Console.", "OK"); } public static bool Validate(bool logResults) @@ -23,14 +22,13 @@ public static bool Validate(bool logResults) var errors = new List(); var warnings = new List(); ValidateItems(errors, warnings); - ValidateConstruction(errors, warnings); ValidateLoadedObjects(errors, warnings); if (logResults) { foreach (string warning in warnings) Debug.LogWarning("[Inventory Validation] " + warning); foreach (string error in errors) Debug.LogError("[Inventory Validation] " + error); - if (errors.Count == 0) Debug.Log($"Inventory validation passed with {warnings.Count} warning(s)."); + if (errors.Count == 0) Debug.Log($"Inventory and loot validation passed with {warnings.Count} warning(s)."); } return errors.Count == 0; } @@ -47,23 +45,7 @@ private static void ValidateItems(ICollection errors, ICollection errors, ICollection warnings) - { - var seen = new Dictionary(StringComparer.Ordinal); - foreach (string guid in AssetDatabase.FindAssets("t:ConstructionDefinition")) - { - string path = AssetDatabase.GUIDToAssetPath(guid); - ConstructionDefinition definition = AssetDatabase.LoadAssetAtPath(path); - if (definition == null) continue; - if (string.IsNullOrWhiteSpace(definition.ConstructionId)) errors.Add($"ConstructionDefinition has an empty ID: {path}"); - else if (seen.TryGetValue(definition.ConstructionId, out string other)) errors.Add($"Duplicate construction ID '{definition.ConstructionId}': {other} and {path}"); - else seen[definition.ConstructionId] = path; - if (definition.CompletedPrefab == null) warnings.Add($"Construction '{definition.ConstructionId}' has no completed prefab: {path}"); - foreach (ConstructionCost cost in definition.Costs) - if (cost == null || cost.item == null || cost.amount <= 0) errors.Add($"Construction '{definition.ConstructionId}' has an invalid cost entry: {path}"); + if (item.BaseValue == 0) warnings.Add($"Item '{item.ItemId}' has zero base loot value: {path}"); } } @@ -71,7 +53,10 @@ private static void ValidateLoadedObjects(ICollection errors, ICollectio { ValidateTypeComposition("InventoryComponent", "InventorySaveParticipant", warnings); ValidateTypeComposition("WorldItemPickup", "PersistentIdentity", errors); - ValidateTypeComposition("ConstructionSite", "PersistentIdentity", errors); + ValidateTypeComposition("LootContainer", "PersistentIdentity", errors); + ValidateTypeComposition("LootContainer", "InventoryComponent", errors); + ValidateTypeComposition("LootContainer", "InventorySaveParticipant", errors); + ValidateTypeComposition("CorpseLootContainer", "LootContainer", errors); } private static void ValidateTypeComposition(string ownerTypeName, string requiredTypeName, ICollection issues) @@ -94,7 +79,7 @@ public sealed class ZoneUAInventoryContentBuildValidator : IPreprocessBuildWithR public void OnPreprocessBuild(BuildReport report) { if (!ZoneUAInventoryContentValidator.Validate(logResults: true)) - throw new BuildFailedException("Inventory or construction content validation failed."); + throw new BuildFailedException("Inventory or loot content validation failed."); } } } From 42ddc95f314092c86a2e42da76d8042ff9586587 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 22:20:54 +0300 Subject: [PATCH 53/61] test: replace construction coverage with loot transfer tests --- .../EditMode/InventoryConstructionTests.cs | 92 ++++++++++--------- 1 file changed, 49 insertions(+), 43 deletions(-) diff --git a/Assets/_ZoneUA/Tests/EditMode/InventoryConstructionTests.cs b/Assets/_ZoneUA/Tests/EditMode/InventoryConstructionTests.cs index f4fd3b1..5df715c 100644 --- a/Assets/_ZoneUA/Tests/EditMode/InventoryConstructionTests.cs +++ b/Assets/_ZoneUA/Tests/EditMode/InventoryConstructionTests.cs @@ -4,17 +4,17 @@ namespace ZoneUA.Combat.Tests { - public sealed class InventoryConstructionTests + public sealed class InventoryLootTests { [Test] public void Inventory_AddRemoveAndCapacity_AreDeterministic() { var state = new InventoryState(5); - Assert.That(state.Add("wood", 3), Is.True); - Assert.That(state.Add("stone", 2), Is.True); - Assert.That(state.Add("metal", 1), Is.False); - Assert.That(state.Remove("wood", 2), Is.True); - Assert.That(state.GetAmount("wood"), Is.EqualTo(1)); + Assert.That(state.Add("ammo-9x19", 3), Is.True); + Assert.That(state.Add("medkit", 2), Is.True); + Assert.That(state.Add("food", 1), Is.False); + Assert.That(state.Remove("ammo-9x19", 2), Is.True); + Assert.That(state.GetAmount("ammo-9x19"), Is.EqualTo(1)); Assert.That(state.TotalItemCount, Is.EqualTo(3)); } @@ -22,63 +22,69 @@ public void Inventory_AddRemoveAndCapacity_AreDeterministic() public void Inventory_TryConsume_IsAtomic() { var state = new InventoryState(); - state.Add("wood", 3); - state.Add("stone", 1); + state.Add("ammo-9x19", 3); + state.Add("medkit", 1); bool failed = state.TryConsume(new[] { - new InventoryEntry("wood", 2), - new InventoryEntry("stone", 2) + new InventoryEntry("ammo-9x19", 2), + new InventoryEntry("medkit", 2) }); Assert.That(failed, Is.False); - Assert.That(state.GetAmount("wood"), Is.EqualTo(3)); - Assert.That(state.GetAmount("stone"), Is.EqualTo(1)); + Assert.That(state.GetAmount("ammo-9x19"), Is.EqualTo(3)); + Assert.That(state.GetAmount("medkit"), Is.EqualTo(1)); + } - Assert.That(state.TryConsume(new[] - { - new InventoryEntry("wood", 2), - new InventoryEntry("stone", 1) - }), Is.True); - Assert.That(state.GetAmount("wood"), Is.EqualTo(1)); - Assert.That(state.GetAmount("stone"), Is.Zero); + [Test] + public void Inventory_Transfer_IsAtomicWhenDestinationIsFull() + { + var source = new InventoryState(); + var destination = new InventoryState(1); + source.Add("medkit", 2); + destination.Add("ammo-9x19", 1); + + Assert.That(source.TryTransferTo(destination, "medkit", 1), Is.False); + Assert.That(source.GetAmount("medkit"), Is.EqualTo(2)); + Assert.That(destination.GetAmount("medkit"), Is.Zero); } [Test] - public void Inventory_Replace_MergesDuplicateIds() + public void LootContainer_MustBeSearchedBeforeTransfer() { - var state = new InventoryState(); - state.Replace(new List - { - new InventoryEntry("wood", 2), - new InventoryEntry("wood", 3), - new InventoryEntry("stone", 1) - }); + var loot = new LootContainerState(initialItems: new[] { new InventoryEntry("medkit", 1) }); + var destination = new InventoryState(); - Assert.That(state.GetAmount("wood"), Is.EqualTo(5)); - Assert.That(state.DistinctItemCount, Is.EqualTo(2)); + Assert.That(loot.TryTake(destination, "medkit", 1), Is.False); + loot.MarkSearched(); + Assert.That(loot.TryTake(destination, "medkit", 1), Is.True); + Assert.That(loot.SearchState, Is.EqualTo(LootSearchState.Empty)); + Assert.That(destination.GetAmount("medkit"), Is.EqualTo(1)); } [Test] - public void Construction_RequiresCommittedResourcesBeforeWork() + public void Reservation_RejectsOtherNpcUntilExpiry() { - var state = new ConstructionState(10f); - Assert.That(state.ApplyWork(5f), Is.Zero); - Assert.That(state.CommitResources(), Is.True); - Assert.That(state.ApplyWork(5f), Is.EqualTo(5f)); - Assert.That(state.Progress01, Is.EqualTo(0.5f)); - Assert.That(state.ApplyWork(20f), Is.EqualTo(5f)); - Assert.That(state.IsComplete, Is.True); + var registry = new LootReservationRegistry(); + Assert.That(registry.TryReserve("corpse-1", "npc-a", 10d, 5d), Is.True); + Assert.That(registry.TryReserve("corpse-1", "npc-b", 11d, 5d), Is.False); + Assert.That(registry.IsReservedByOther("corpse-1", "npc-b", 11d), Is.True); + Assert.That(registry.TryReserve("corpse-1", "npc-b", 16d, 5d), Is.True); } [Test] - public void Construction_Restore_ClampsProgress() + public void Inventory_Replace_MergesDuplicateIds() { - var state = new ConstructionState(1f); - state.Restore(8f, 50f, true); - Assert.That(state.RequiredWork, Is.EqualTo(8f)); - Assert.That(state.AppliedWork, Is.EqualTo(8f)); - Assert.That(state.IsComplete, Is.True); + var state = new InventoryState(); + state.Replace(new List + { + new InventoryEntry("ammo-9x19", 2), + new InventoryEntry("ammo-9x19", 3), + new InventoryEntry("medkit", 1) + }); + + Assert.That(state.GetAmount("ammo-9x19"), Is.EqualTo(5)); + Assert.That(state.DistinctItemCount, Is.EqualTo(2)); } } } From fa435c0ce77944760845c34a25bb4a5f428e6e42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 22:21:36 +0300 Subject: [PATCH 54/61] docs: add RPG inventory and loot guide --- Docs/RPG_INVENTORY_LOOT.md | 100 +++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 Docs/RPG_INVENTORY_LOOT.md diff --git a/Docs/RPG_INVENTORY_LOOT.md b/Docs/RPG_INVENTORY_LOOT.md new file mode 100644 index 0000000..9611dbb --- /dev/null +++ b/Docs/RPG_INVENTORY_LOOT.md @@ -0,0 +1,100 @@ +# RPG Inventory and Persistent Loot + +This module provides definition-driven items, deterministic inventories, persistent world pickups, searchable containers and corpse loot for the Zone UA top-down shooter RPG. + +## Item assets + +Create items with: + +`Create -> Zone UA -> Inventory -> Item Definition` + +Each item requires a unique `Item Id`. Configure category, base loot value, weight, stack size, world prefab and persistent world prefab ID. The value/category fields are intended for future NPC loot evaluation. + +Create an `ItemCatalog` and assign it to systems that need to resolve item IDs into definitions or world prefabs. + +## Player and NPC inventories + +A persistent actor should contain: + +- `PersistentIdentity` +- `InventoryComponent` +- `InventorySaveParticipant` + +Both players and raid NPCs use the same inventory state. Initial spawn equipment can be configured through `InventoryComponent.initialItems`; acquired loot is added through normal transfer operations. + +Inventory transfer is atomic. A failed transfer caused by missing source items or destination capacity leaves both inventories unchanged. + +## World pickups + +A persistent world item should contain: + +- `PersistentIdentity` +- `TransformSaveParticipant` +- `WorldItemPickup` +- an interaction or trigger collider + +`WorldItemPickup` implements `ILootSource`, so the player and AI can use the same loot contract. A successful pickup creates a tombstone through `PersistentIdentity.MarkDestroyed()`, preventing the authored or runtime item from reappearing after save/load. + +Dropped item prefabs must be registered in `PersistentPrefabCatalog` using the item's persistent world prefab ID. + +## Searchable containers + +A crate, stash or other searchable container should contain: + +- `PersistentIdentity` +- `TransformSaveParticipant` +- `InventoryComponent` +- `InventorySaveParticipant` +- `LootContainer` + +`LootContainer` stores whether the source is unsearched, searched or empty. Container contents are persisted by `InventorySaveParticipant`; search state is persisted through participant key `loot-source`. + +The configured search duration is presentation/gameplay data for the interaction and future raid-NPC task executor. The container does not own movement or UI. + +## Corpse loot + +A corpse prefab should contain the normal loot-container composition plus `CorpseLootContainer`. + +On death, initialise it from the dead actor's inventory: + +`corpseLootContainer.InitialiseFrom(deadActorInventory)` + +The corpse receives an inventory snapshot containing both spawn equipment and all acquired loot. By default the source inventory is cleared so pooled or disabled actors cannot expose the same items twice. + +## Loot reservations + +`LootReservationRegistry` prevents multiple raid NPCs from selecting the same world item, crate or corpse. Reservations contain a source ID, owner NPC ID and expiry time. + +Reservations are runtime coordination state and should normally not be written into save files. After loading, NPCs re-evaluate available loot and reserve targets again. + +Release reservations when an NPC dies, changes goal, cannot reach the target, completes looting or exceeds the reservation timeout. + +## Validation + +Run: + +`Zone UA -> Validation -> Validate Inventory and Loot` + +The validator checks: + +- empty or duplicate item IDs; +- missing world prefabs and zero-value item warnings; +- inventories without `InventorySaveParticipant`; +- world pickups without `PersistentIdentity`; +- loot containers without identity, inventory or inventory persistence; +- corpse containers without `LootContainer`. + +Errors block Unity builds. + +## Required Play Mode checks + +- collect a world pickup and confirm inventory count changes; +- confirm a full inventory does not consume or tombstone the item; +- drop a stack and confirm a new stable object ID is assigned; +- save/load a dropped stack exactly once; +- search a crate and transfer selected items; +- verify destination capacity cannot delete source loot; +- kill an NPC and initialise a corpse from its complete inventory; +- save/load corpse contents and search state; +- reserve one loot source from two NPCs and verify only one succeeds; +- expire or release a reservation and verify another NPC can claim it. From 9146ba8a3e0f7ad21720462ce8cff3b3aa477ebd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 22:21:50 +0300 Subject: [PATCH 55/61] chore: add RPG inventory loot documentation metadata --- Docs/RPG_INVENTORY_LOOT.md.meta | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Docs/RPG_INVENTORY_LOOT.md.meta diff --git a/Docs/RPG_INVENTORY_LOOT.md.meta b/Docs/RPG_INVENTORY_LOOT.md.meta new file mode 100644 index 0000000..1745ffa --- /dev/null +++ b/Docs/RPG_INVENTORY_LOOT.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 2661e97e92124af690302dd2c9098f09 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: From ecc1d6ea438043b55ccc7ce509ad7cb9b0189316 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 22:22:00 +0300 Subject: [PATCH 56/61] docs: remove construction-oriented inventory guide --- Docs/INVENTORY_ITEMS_CONSTRUCTION.md | 94 ---------------------------- 1 file changed, 94 deletions(-) delete mode 100644 Docs/INVENTORY_ITEMS_CONSTRUCTION.md diff --git a/Docs/INVENTORY_ITEMS_CONSTRUCTION.md b/Docs/INVENTORY_ITEMS_CONSTRUCTION.md deleted file mode 100644 index 70814f8..0000000 --- a/Docs/INVENTORY_ITEMS_CONSTRUCTION.md +++ /dev/null @@ -1,94 +0,0 @@ -# Inventory, Items and Construction - -This module adds definition-driven items, deterministic inventory state, persistent pickup/drop objects and persistent construction progress. - -## Assets - -Create item assets with: - -`Create -> Zone UA -> Inventory -> Item Definition` - -Each item requires a unique `Item Id`. `World Prefab` is used when dropping the item. `Persistent World Prefab Id` must match an entry in `PersistentPrefabCatalog`; when empty it falls back to the item ID. - -Create a catalog with: - -`Create -> Zone UA -> Inventory -> Item Catalog` - -Create buildable definitions with: - -`Create -> Zone UA -> Construction -> Definition` - -A construction definition contains a stable ID, required work, material costs and the completed prefab reference. - -## Player composition - -Add these components to the persistent player root: - -- `PersistentIdentity` -- `InventoryComponent` -- `InventorySaveParticipant` -- `InventoryDropper` - -Assign the `ItemCatalog` to `InventoryDropper`. Capacity `0` means unlimited capacity. - -## World pickup prefab - -A dropped or authored pickup should contain: - -- `PersistentIdentity` -- `TransformSaveParticipant` -- `WorldItemPickup` -- a trigger collider - -Register runtime pickup prefabs in `PersistentPrefabCatalog`. `InventoryDropper` assigns a new logical object ID and configures the dropped stack amount. `WorldItemPickup` persists its amount through participant key `world-item`. - -When a pickup succeeds it calls `PersistentIdentity.MarkDestroyed()`, creating a tombstone. The item therefore does not reappear after save/load. - -## Construction composition - -A persistent construction object should contain: - -- `PersistentIdentity` -- `TransformSaveParticipant` -- `ConstructionSite` - -`ConstructionSite` is itself a save participant with key `construction`. It stores required work, applied work and whether resources were committed. - -Typical flow: - -1. Place the construction-site prefab. -2. Call `CommitResources(playerInventory)` once. -3. Call `ApplyWork(amount)` from worker or interaction logic. -4. Swap `Incomplete Root` and `Completed Root` when progress reaches 100%. -5. Save/load restores the exact construction progress. - -Resource consumption is atomic. If any required material is missing, no material is removed. - -## Validation - -Run: - -`Zone UA -> Validation -> Validate Inventory and Construction` - -The validator reports: - -- empty or duplicate item IDs; -- empty or duplicate construction IDs; -- invalid construction costs; -- item definitions without world prefabs; -- loaded inventories without `InventorySaveParticipant`; -- pickups or construction sites without `PersistentIdentity`. - -Errors block Unity builds. Missing optional presentation references remain warnings. - -## Required Play Mode checks - -- collect a world pickup and confirm inventory count changes; -- save, reload and confirm the collected object remains absent; -- drop a stack and confirm a new stable object ID is assigned; -- save, reload and confirm the dropped stack and amount restore once; -- verify full inventory prevents pickup without creating a tombstone; -- commit construction resources and verify exact atomic deduction; -- partially build, save and reload; -- complete construction and verify the completed visual persists; -- validate duplicate item/construction IDs are blocked. From b3397b889c16d4f49354bee7295efd80962c44ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 22:22:14 +0300 Subject: [PATCH 57/61] docs: remove obsolete construction guide metadata --- Docs/INVENTORY_ITEMS_CONSTRUCTION.md.meta | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 Docs/INVENTORY_ITEMS_CONSTRUCTION.md.meta diff --git a/Docs/INVENTORY_ITEMS_CONSTRUCTION.md.meta b/Docs/INVENTORY_ITEMS_CONSTRUCTION.md.meta deleted file mode 100644 index cfb7c72..0000000 --- a/Docs/INVENTORY_ITEMS_CONSTRUCTION.md.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: b969208f41294ce1b278928de7d29094 -TextScriptImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: From d34565d719831afbb2af9ff15a6f87afe570803e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 22:23:17 +0300 Subject: [PATCH 58/61] test: rename inventory loot test file --- .../Tests/EditMode/InventoryLootTests.cs | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 Assets/_ZoneUA/Tests/EditMode/InventoryLootTests.cs diff --git a/Assets/_ZoneUA/Tests/EditMode/InventoryLootTests.cs b/Assets/_ZoneUA/Tests/EditMode/InventoryLootTests.cs new file mode 100644 index 0000000..5df715c --- /dev/null +++ b/Assets/_ZoneUA/Tests/EditMode/InventoryLootTests.cs @@ -0,0 +1,90 @@ +using System.Collections.Generic; +using NUnit.Framework; +using ZoneUA.Inventory; + +namespace ZoneUA.Combat.Tests +{ + public sealed class InventoryLootTests + { + [Test] + public void Inventory_AddRemoveAndCapacity_AreDeterministic() + { + var state = new InventoryState(5); + Assert.That(state.Add("ammo-9x19", 3), Is.True); + Assert.That(state.Add("medkit", 2), Is.True); + Assert.That(state.Add("food", 1), Is.False); + Assert.That(state.Remove("ammo-9x19", 2), Is.True); + Assert.That(state.GetAmount("ammo-9x19"), Is.EqualTo(1)); + Assert.That(state.TotalItemCount, Is.EqualTo(3)); + } + + [Test] + public void Inventory_TryConsume_IsAtomic() + { + var state = new InventoryState(); + state.Add("ammo-9x19", 3); + state.Add("medkit", 1); + + bool failed = state.TryConsume(new[] + { + new InventoryEntry("ammo-9x19", 2), + new InventoryEntry("medkit", 2) + }); + + Assert.That(failed, Is.False); + Assert.That(state.GetAmount("ammo-9x19"), Is.EqualTo(3)); + Assert.That(state.GetAmount("medkit"), Is.EqualTo(1)); + } + + [Test] + public void Inventory_Transfer_IsAtomicWhenDestinationIsFull() + { + var source = new InventoryState(); + var destination = new InventoryState(1); + source.Add("medkit", 2); + destination.Add("ammo-9x19", 1); + + Assert.That(source.TryTransferTo(destination, "medkit", 1), Is.False); + Assert.That(source.GetAmount("medkit"), Is.EqualTo(2)); + Assert.That(destination.GetAmount("medkit"), Is.Zero); + } + + [Test] + public void LootContainer_MustBeSearchedBeforeTransfer() + { + var loot = new LootContainerState(initialItems: new[] { new InventoryEntry("medkit", 1) }); + var destination = new InventoryState(); + + Assert.That(loot.TryTake(destination, "medkit", 1), Is.False); + loot.MarkSearched(); + Assert.That(loot.TryTake(destination, "medkit", 1), Is.True); + Assert.That(loot.SearchState, Is.EqualTo(LootSearchState.Empty)); + Assert.That(destination.GetAmount("medkit"), Is.EqualTo(1)); + } + + [Test] + public void Reservation_RejectsOtherNpcUntilExpiry() + { + var registry = new LootReservationRegistry(); + Assert.That(registry.TryReserve("corpse-1", "npc-a", 10d, 5d), Is.True); + Assert.That(registry.TryReserve("corpse-1", "npc-b", 11d, 5d), Is.False); + Assert.That(registry.IsReservedByOther("corpse-1", "npc-b", 11d), Is.True); + Assert.That(registry.TryReserve("corpse-1", "npc-b", 16d, 5d), Is.True); + } + + [Test] + public void Inventory_Replace_MergesDuplicateIds() + { + var state = new InventoryState(); + state.Replace(new List + { + new InventoryEntry("ammo-9x19", 2), + new InventoryEntry("ammo-9x19", 3), + new InventoryEntry("medkit", 1) + }); + + Assert.That(state.GetAmount("ammo-9x19"), Is.EqualTo(5)); + Assert.That(state.DistinctItemCount, Is.EqualTo(2)); + } + } +} From 92a5a01022e8abe2422e5924ea49fba496d0d1f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 22:23:32 +0300 Subject: [PATCH 59/61] test: preserve inventory loot test metadata --- .../_ZoneUA/Tests/EditMode/InventoryLootTests.cs.meta | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Assets/_ZoneUA/Tests/EditMode/InventoryLootTests.cs.meta diff --git a/Assets/_ZoneUA/Tests/EditMode/InventoryLootTests.cs.meta b/Assets/_ZoneUA/Tests/EditMode/InventoryLootTests.cs.meta new file mode 100644 index 0000000..b3d319e --- /dev/null +++ b/Assets/_ZoneUA/Tests/EditMode/InventoryLootTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4979ae9e54a447db978c84b7ff36a793 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 4fe7c91f92cc8c712f0902499e8f7770a0c7c2df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 22:23:44 +0300 Subject: [PATCH 60/61] test: remove obsolete construction test filename --- .../EditMode/InventoryConstructionTests.cs | 90 ------------------- 1 file changed, 90 deletions(-) delete mode 100644 Assets/_ZoneUA/Tests/EditMode/InventoryConstructionTests.cs diff --git a/Assets/_ZoneUA/Tests/EditMode/InventoryConstructionTests.cs b/Assets/_ZoneUA/Tests/EditMode/InventoryConstructionTests.cs deleted file mode 100644 index 5df715c..0000000 --- a/Assets/_ZoneUA/Tests/EditMode/InventoryConstructionTests.cs +++ /dev/null @@ -1,90 +0,0 @@ -using System.Collections.Generic; -using NUnit.Framework; -using ZoneUA.Inventory; - -namespace ZoneUA.Combat.Tests -{ - public sealed class InventoryLootTests - { - [Test] - public void Inventory_AddRemoveAndCapacity_AreDeterministic() - { - var state = new InventoryState(5); - Assert.That(state.Add("ammo-9x19", 3), Is.True); - Assert.That(state.Add("medkit", 2), Is.True); - Assert.That(state.Add("food", 1), Is.False); - Assert.That(state.Remove("ammo-9x19", 2), Is.True); - Assert.That(state.GetAmount("ammo-9x19"), Is.EqualTo(1)); - Assert.That(state.TotalItemCount, Is.EqualTo(3)); - } - - [Test] - public void Inventory_TryConsume_IsAtomic() - { - var state = new InventoryState(); - state.Add("ammo-9x19", 3); - state.Add("medkit", 1); - - bool failed = state.TryConsume(new[] - { - new InventoryEntry("ammo-9x19", 2), - new InventoryEntry("medkit", 2) - }); - - Assert.That(failed, Is.False); - Assert.That(state.GetAmount("ammo-9x19"), Is.EqualTo(3)); - Assert.That(state.GetAmount("medkit"), Is.EqualTo(1)); - } - - [Test] - public void Inventory_Transfer_IsAtomicWhenDestinationIsFull() - { - var source = new InventoryState(); - var destination = new InventoryState(1); - source.Add("medkit", 2); - destination.Add("ammo-9x19", 1); - - Assert.That(source.TryTransferTo(destination, "medkit", 1), Is.False); - Assert.That(source.GetAmount("medkit"), Is.EqualTo(2)); - Assert.That(destination.GetAmount("medkit"), Is.Zero); - } - - [Test] - public void LootContainer_MustBeSearchedBeforeTransfer() - { - var loot = new LootContainerState(initialItems: new[] { new InventoryEntry("medkit", 1) }); - var destination = new InventoryState(); - - Assert.That(loot.TryTake(destination, "medkit", 1), Is.False); - loot.MarkSearched(); - Assert.That(loot.TryTake(destination, "medkit", 1), Is.True); - Assert.That(loot.SearchState, Is.EqualTo(LootSearchState.Empty)); - Assert.That(destination.GetAmount("medkit"), Is.EqualTo(1)); - } - - [Test] - public void Reservation_RejectsOtherNpcUntilExpiry() - { - var registry = new LootReservationRegistry(); - Assert.That(registry.TryReserve("corpse-1", "npc-a", 10d, 5d), Is.True); - Assert.That(registry.TryReserve("corpse-1", "npc-b", 11d, 5d), Is.False); - Assert.That(registry.IsReservedByOther("corpse-1", "npc-b", 11d), Is.True); - Assert.That(registry.TryReserve("corpse-1", "npc-b", 16d, 5d), Is.True); - } - - [Test] - public void Inventory_Replace_MergesDuplicateIds() - { - var state = new InventoryState(); - state.Replace(new List - { - new InventoryEntry("ammo-9x19", 2), - new InventoryEntry("ammo-9x19", 3), - new InventoryEntry("medkit", 1) - }); - - Assert.That(state.GetAmount("ammo-9x19"), Is.EqualTo(5)); - Assert.That(state.DistinctItemCount, Is.EqualTo(2)); - } - } -} From 51630a8d60d5203c32e88a9f24722f1cd1189953 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 22:23:56 +0300 Subject: [PATCH 61/61] test: remove obsolete construction test metadata --- .../Tests/EditMode/InventoryConstructionTests.cs.meta | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 Assets/_ZoneUA/Tests/EditMode/InventoryConstructionTests.cs.meta diff --git a/Assets/_ZoneUA/Tests/EditMode/InventoryConstructionTests.cs.meta b/Assets/_ZoneUA/Tests/EditMode/InventoryConstructionTests.cs.meta deleted file mode 100644 index b3d319e..0000000 --- a/Assets/_ZoneUA/Tests/EditMode/InventoryConstructionTests.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 4979ae9e54a447db978c84b7ff36a793 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: