using System; using System.Collections.Generic; using XGame.Framework.Data; namespace FL.Data { /// /// 背包格子数据 /// public class BagItemData { public int tableId; public int num; } public class ItemData : DataSingleton, IDisposable { private Dictionary _bagItemDataDic = new Dictionary(); // 背包中的道具数据 /// /// 添加一个物品道具数据 /// /// /// public void AddItemData(int tableId, int count) { if (_bagItemDataDic.ContainsKey(tableId)) { _bagItemDataDic[tableId].num = count; if (_bagItemDataDic[tableId].num == 0) { // 移除 _bagItemDataDic.Remove(tableId); } return; } _bagItemDataDic.Add(tableId, new BagItemData() { tableId = tableId, num = count, }); } /// /// 拥有的道具数量 /// /// /// public int GetItemNum(int tableId) { return _bagItemDataDic.ContainsKey(tableId) ? _bagItemDataDic[tableId].num : 0; } /// /// 获取礼包|红包类型道具(道具页签),常规道具类型(材料页签)用来在背包界面显示 /// /// public Dictionary GetBackpackData() { return _bagItemDataDic; } void IDisposable.Dispose() { if (_bagItemDataDic?.Count > 0) { _bagItemDataDic.Clear(); } } } }