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