55 lines
2.1 KiB
C#
55 lines
2.1 KiB
C#
using System.Collections.Generic;
|
||
|
||
namespace BaseGames.Inventory
|
||
{
|
||
/// <summary>
|
||
/// 背包管理服务接口。UI 层(ItemInventoryPanel)通过此接口读取道具状态,
|
||
/// 与 <see cref="InventoryManager"/> 具体实现解耦,便于独立测试和跨场景复用。
|
||
/// 设计对照 <see cref="BaseGames.Equipment.IEquipmentService"/>。
|
||
/// </summary>
|
||
public interface IInventoryService
|
||
{
|
||
/// <summary>当前持有的全部道具条目(只读视图,含数量)。</summary>
|
||
IReadOnlyList<InventoryEntry> Items { get; }
|
||
|
||
/// <summary>持有道具种类数(不含数量)。</summary>
|
||
int DistinctCount { get; }
|
||
|
||
/// <summary>查询指定道具的持有数量;未持有返回 0。</summary>
|
||
int GetCount(string itemId);
|
||
|
||
/// <summary>是否持有指定道具(数量 ≥ 1)。</summary>
|
||
bool Has(string itemId);
|
||
|
||
/// <summary>
|
||
/// 增加道具。stackable 道具按 amount 叠加(受 maxStack 限制);
|
||
/// 非 stackable 恒为 1。返回实际新增数量(0 表示已满或道具无效)。
|
||
/// </summary>
|
||
int AddItem(string itemId, int amount = 1);
|
||
|
||
/// <summary>移除道具(如消耗品使用 / 剧情消耗)。返回实际移除数量。</summary>
|
||
int RemoveItem(string itemId, int amount = 1);
|
||
|
||
/// <summary>清除某道具的"新获得"未读标记(玩家查看背包后调用)。</summary>
|
||
void MarkSeen(string itemId);
|
||
|
||
/// <summary>道具集合变化(增删 / 数量变更)时触发;UI 据此刷新。</summary>
|
||
event System.Action OnInventoryChanged;
|
||
}
|
||
|
||
/// <summary>背包条目:道具数据 + 当前数量 + 未读标记。</summary>
|
||
public readonly struct InventoryEntry
|
||
{
|
||
public readonly ItemSO Item;
|
||
public readonly int Count;
|
||
public readonly bool IsNew;
|
||
|
||
public InventoryEntry(ItemSO item, int count, bool isNew)
|
||
{
|
||
Item = item;
|
||
Count = count;
|
||
IsNew = isNew;
|
||
}
|
||
}
|
||
}
|