Files
zeling_v2/Assets/_Game/Scripts/Inventory/IInventoryService.cs
2026-06-05 18:41:33 +08:00

55 lines
2.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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;
}
}
}