122 lines
3.3 KiB
C#
122 lines
3.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// 负责工具材料包管理
|
|
/// </summary>
|
|
public class PacksackBagMgr : BaseManager<PacksackBagMgr>
|
|
{
|
|
private readonly Dictionary<int, List<ItemInfo>> toolAndMaterialDic = new Dictionary<int, List<ItemInfo>>();
|
|
public Dictionary<int, ItemInfo> wearDic = new Dictionary<int, ItemInfo>();
|
|
|
|
private PacksackBagMgr()
|
|
{
|
|
}
|
|
|
|
public Dictionary<int, List<ItemInfo>> GetCurrentBagData()
|
|
{
|
|
return toolAndMaterialDic;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 添加一个工器具或材料
|
|
/// </summary>
|
|
/// <param name="name"></param>
|
|
public void AddOneToolOrMater(ItemInfo itemInfo)
|
|
{
|
|
if (toolAndMaterialDic.ContainsKey(itemInfo.toolId))
|
|
{
|
|
toolAndMaterialDic[itemInfo.toolId].Add(itemInfo);
|
|
}
|
|
else
|
|
{
|
|
toolAndMaterialDic.Add(itemInfo.toolId, new List<ItemInfo>() { itemInfo });
|
|
}
|
|
}
|
|
|
|
public Dictionary<int, List<ItemInfo>> GetItemsByE_TMDType(E_ToolOrDeviceOrMaterials tmdTpye)
|
|
{
|
|
Dictionary<int, List<ItemInfo>> tempNew = new Dictionary<int, List<ItemInfo>>();
|
|
|
|
var dicTemp = toolAndMaterialDic;
|
|
foreach (var item in dicTemp.Keys)
|
|
{
|
|
for (int i = 0; i < dicTemp[item].Count; i++)
|
|
{
|
|
if (dicTemp[item][i].toolOrDeviceOrMaterial == tmdTpye)
|
|
{
|
|
|
|
if (tempNew.ContainsKey(dicTemp[item][i].toolId))
|
|
{
|
|
tempNew[dicTemp[item][i].toolId].Add(dicTemp[item][i]);
|
|
}
|
|
else
|
|
{
|
|
tempNew.Add(dicTemp[item][i].toolId, new List<ItemInfo>() { dicTemp[item][i] });
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
return tempNew;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 移除一个工器具或材料
|
|
/// </summary>
|
|
/// <param name="name"></param>
|
|
public void RemoveOneToolOrMater(ItemInfo itemInfo)
|
|
{
|
|
if (toolAndMaterialDic.ContainsKey(itemInfo.toolId))
|
|
{
|
|
if (toolAndMaterialDic[itemInfo.toolId].Count > 1)
|
|
{
|
|
toolAndMaterialDic[itemInfo.toolId].Remove(itemInfo);
|
|
}
|
|
else
|
|
{
|
|
toolAndMaterialDic.Remove(itemInfo.toolId);
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 移除多个
|
|
/// </summary>
|
|
/// <param name="itemInfo"></param>
|
|
public void RemoveAllToolOrMater(ItemInfo itemInfo)
|
|
{
|
|
if (toolAndMaterialDic.ContainsKey(itemInfo.toolId))
|
|
{
|
|
toolAndMaterialDic.Remove(itemInfo.toolId);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 移除全部工具 设备 材料
|
|
/// </summary>
|
|
public void ClearAllToolAndDiveceAndMaterial()
|
|
{
|
|
toolAndMaterialDic.Clear();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加 穿戴 状态 0 去掉 1 穿上
|
|
/// </summary>
|
|
/// <param name="itemInfo"></param>
|
|
/// <param name="state"></param>
|
|
public void WearItemState(ItemInfo itemInfo, bool state)
|
|
{
|
|
if (state)
|
|
{
|
|
if (!wearDic.ContainsKey(itemInfo.toolId))
|
|
wearDic.Add(itemInfo.toolId, itemInfo);
|
|
}
|
|
else
|
|
{
|
|
if (wearDic.ContainsKey(itemInfo.toolId))
|
|
wearDic.Remove(itemInfo.toolId);
|
|
}
|
|
}
|
|
} |