Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
55ba2b7
chore: add inventory runtime folder
pes7 Jul 27, 2026
764e7a8
feat: add inventory runtime assembly
pes7 Jul 27, 2026
39d552a
chore: add inventory assembly metadata
pes7 Jul 27, 2026
7354dc1
feat: add item definitions
pes7 Jul 27, 2026
a542b6c
chore: add item definition metadata
pes7 Jul 27, 2026
870fc1f
feat: add item catalog
pes7 Jul 27, 2026
1c9bab1
chore: add item catalog metadata
pes7 Jul 27, 2026
e0417a7
feat: add deterministic inventory state
pes7 Jul 27, 2026
104acc5
chore: add inventory state metadata
pes7 Jul 27, 2026
cdca4f5
feat: add construction definitions
pes7 Jul 27, 2026
a6a7af1
chore: add construction definition metadata
pes7 Jul 27, 2026
419d872
feat: add deterministic construction state
pes7 Jul 27, 2026
d1c4c53
chore: add construction state metadata
pes7 Jul 27, 2026
f6bda85
feat: add inventory component
pes7 Jul 27, 2026
7f3a8ca
chore: add inventory component metadata
pes7 Jul 27, 2026
5323f2d
feat: persist inventory contents
pes7 Jul 27, 2026
25672f5
chore: add inventory save participant metadata
pes7 Jul 27, 2026
c552755
feat: add persistent world item pickup
pes7 Jul 27, 2026
caf15ed
chore: add world item pickup metadata
pes7 Jul 27, 2026
3bc9fa1
feat: add persistent construction site
pes7 Jul 27, 2026
fabec1b
chore: add construction site metadata
pes7 Jul 27, 2026
95a75aa
chore: reference inventory from editor validation
pes7 Jul 27, 2026
1797c2b
chore: reference inventory from edit mode tests
pes7 Jul 27, 2026
19fdcab
test: cover inventory and construction state
pes7 Jul 27, 2026
3d05825
chore: add inventory construction test metadata
pes7 Jul 27, 2026
0e35475
feat: validate inventory and construction content
pes7 Jul 27, 2026
0725686
chore: add inventory validator metadata
pes7 Jul 27, 2026
6dc2902
feat: add persistent world prefab id to items
pes7 Jul 27, 2026
f8f083a
feat: persist dropped world item amounts
pes7 Jul 27, 2026
9d78aab
feat: add inventory item dropping
pes7 Jul 27, 2026
871ae80
chore: add inventory dropper metadata
pes7 Jul 27, 2026
7b9fe40
docs: add inventory items construction guide
pes7 Jul 27, 2026
04c16c1
chore: add inventory documentation metadata
pes7 Jul 27, 2026
159693c
refactor: remove out-of-scope construction gameplay
pes7 Jul 27, 2026
b1fb268
refactor: remove construction script metadata
pes7 Jul 27, 2026
2d8c477
refactor: remove construction definitions from RPG inventory module
pes7 Jul 27, 2026
6ed26cd
refactor: remove construction definition metadata
pes7 Jul 27, 2026
a151ed9
refactor: remove construction state from loot module
pes7 Jul 27, 2026
05c5579
refactor: remove construction state metadata
pes7 Jul 27, 2026
ab06699
feat: add atomic inventory transfer support
pes7 Jul 27, 2026
c7da67c
feat: add RPG loot valuation metadata
pes7 Jul 27, 2026
3e80ab9
feat: add loot source contracts and state
pes7 Jul 27, 2026
18a1656
chore: add loot contracts metadata
pes7 Jul 27, 2026
8ca1b61
feat: add runtime loot reservation registry
pes7 Jul 27, 2026
da71550
chore: add loot reservation metadata
pes7 Jul 27, 2026
5443ff2
feat: add persistent searchable loot containers
pes7 Jul 27, 2026
68848e1
feat: expose inventory transfer notifications
pes7 Jul 27, 2026
74f6c57
chore: add loot container metadata
pes7 Jul 27, 2026
3d07d75
feat: add corpse inventory snapshots
pes7 Jul 27, 2026
d08cde1
chore: add corpse loot metadata
pes7 Jul 27, 2026
abf8c48
feat: expose world items through loot source contract
pes7 Jul 27, 2026
fa377bb
refactor: validate RPG inventory and loot sources
pes7 Jul 27, 2026
42ddc95
test: replace construction coverage with loot transfer tests
pes7 Jul 27, 2026
fa435c0
docs: add RPG inventory and loot guide
pes7 Jul 27, 2026
9146ba8
chore: add RPG inventory loot documentation metadata
pes7 Jul 27, 2026
ecc1d6e
docs: remove construction-oriented inventory guide
pes7 Jul 27, 2026
b3397b8
docs: remove obsolete construction guide metadata
pes7 Jul 27, 2026
d34565d
test: rename inventory loot test file
pes7 Jul 27, 2026
92a5a01
test: preserve inventory loot test metadata
pes7 Jul 27, 2026
4fe7c91
test: remove obsolete construction test filename
pes7 Jul 27, 2026
51630a8
test: remove obsolete construction test metadata
pes7 Jul 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Assets/Script/CorpseLootContainer.cs
Original file line number Diff line number Diff line change
@@ -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<InventoryComponent>();
lootContainer = GetComponent<LootContainer>();
}

public bool InitialiseFrom(InventoryComponent sourceInventory)
{
if (IsInitialised || sourceInventory == null || sourceInventory == corpseInventory) return false;

List<InventoryEntry> snapshot = new List<InventoryEntry>(sourceInventory.Entries);
corpseInventory.ReplaceContents(snapshot);
if (clearSourceInventory) sourceInventory.ReplaceContents(System.Array.Empty<InventoryEntry>());

lootContainer.MarkSearched();
IsInitialised = true;
return true;
}
}
11 changes: 11 additions & 0 deletions Assets/Script/CorpseLootContainer.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 70 additions & 0 deletions Assets/Script/InventoryComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
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<InventoryEntry> initialItems = new List<InventoryEntry>();

private InventoryState state;

public event Action InventoryChanged;
public InventoryState State => state ??= CreateState();
public IReadOnlyList<InventoryEntry> 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;
NotifyExternalChange();
return true;
}

public bool Remove(string itemId, int amount)
{
if (!State.Remove(itemId, amount)) return false;
NotifyExternalChange();
return true;
}

public bool TryConsume(IEnumerable<InventoryEntry> costs)
{
if (!State.TryConsume(costs)) return false;
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<InventoryEntry> entries)
{
State.Replace(entries);
NotifyExternalChange();
}

public void NotifyExternalChange() => InventoryChanged?.Invoke();

private InventoryState CreateState()
{
var result = new InventoryState(capacity);
result.Replace(initialItems);
return result;
}

private void OnValidate() => capacity = Mathf.Max(0, capacity);
}
11 changes: 11 additions & 0 deletions Assets/Script/InventoryComponent.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions Assets/Script/InventoryDropper.cs
Original file line number Diff line number Diff line change
@@ -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<InventoryComponent>();
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<InventoryComponent>();
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<PersistentIdentity>() ?? instance.AddComponent<PersistentIdentity>();
identity.AssignRuntimeId(Guid.NewGuid().ToString("N"), item.PersistentWorldPrefabId);
WorldItemPickup pickup = instance.GetComponent<WorldItemPickup>() ?? instance.AddComponent<WorldItemPickup>();
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);
}
11 changes: 11 additions & 0 deletions Assets/Script/InventoryDropper.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions Assets/Script/InventorySaveParticipant.cs
Original file line number Diff line number Diff line change
@@ -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<InventoryEntry> entries = new List<InventoryEntry>();
}

private InventoryComponent inventory;

public string ParticipantKey => "inventory";
public int ParticipantVersion => 1;

private void Awake() => inventory = GetComponent<InventoryComponent>();

public string CaptureState()
{
inventory ??= GetComponent<InventoryComponent>();
return JsonUtility.ToJson(new Payload { entries = new List<InventoryEntry>(inventory.Entries) });
}

public void RestoreState(string payload, int version)
{
inventory ??= GetComponent<InventoryComponent>();
Payload state = string.IsNullOrWhiteSpace(payload) ? new Payload() : JsonUtility.FromJson<Payload>(payload);
inventory.ReplaceContents(state?.entries ?? new List<InventoryEntry>());
}
}
11 changes: 11 additions & 0 deletions Assets/Script/InventorySaveParticipant.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

96 changes: 96 additions & 0 deletions Assets/Script/LootContainer.cs
Original file line number Diff line number Diff line change
@@ -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<LootSearchState> 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<InventoryEntry> Entries => inventory != null ? inventory.Entries : Array.Empty<InventoryEntry>();
public float SearchDurationSeconds => Mathf.Max(0f, searchDurationSeconds);
public string ParticipantKey => "loot-source";
public int ParticipantVersion => 1;

private void Awake()
{
identity = GetComponent<PersistentIdentity>();
inventory = GetComponent<InventoryComponent>();
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>(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);
}
11 changes: 11 additions & 0 deletions Assets/Script/LootContainer.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading