using System.Collections;
using System.Collections.Generic;
using UnityEngine;
///
/// 负责工具材料包管理
///
public class PacksackBagMgr : BaseManager
{
///
/// 背包里所有东西
///
public Dictionary> toolAndMaterialDic = new Dictionary>();
///
/// 已经穿戴
///
public Dictionary wearDic = new Dictionary();
private PacksackBagMgr()
{
}
public Dictionary> GetCurrentBagData()
{
return toolAndMaterialDic;
}
///
/// 添加一个工器具或材料
///
///
public void AddOneToolOrMater(ItemInfo itemInfo)
{
if (toolAndMaterialDic.ContainsKey(itemInfo.toolName))
{
toolAndMaterialDic[itemInfo.toolName].Add(itemInfo);
}
else
{
toolAndMaterialDic.Add(itemInfo.toolName, new List() { itemInfo });
}
}
public Dictionary> GetItemsByE_TMDType(E_ToolOrDeviceOrMaterials tmdTpye)
{
Dictionary> tempNew = new Dictionary>();
D_ToolAndMaterialData dTMD = GameManager.ToolAndmaterialMgr.GetToolOrMaterialOrDeviceInfoByObjName("手机");
ItemInfo itemInfo = new ItemInfo();
if (dTMD != null)
{
itemInfo.toolId = dTMD.id;
itemInfo.triggerID = dTMD.id;
itemInfo.toolName = dTMD.objName;
itemInfo.toolOrDeviceOrMaterial = (E_ToolOrDeviceOrMaterials)dTMD.type;
itemInfo.objPrefab = Resources.Load("Prefabs/Objects/Tools/手机");
itemInfo.selfPosInToolRoom = new Vector3(0,0,0);
tempNew.Add("手机", new 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].toolName))
{
tempNew[dicTemp[item][i].toolName].Add(dicTemp[item][i]);
}
else
{
tempNew.Add(dicTemp[item][i].toolName, new List() { dicTemp[item][i] });
}
}
}
}
return tempNew;
}
///
/// 移除一个工器具或材料
///
///
public void RemoveOneToolOrMater(ItemInfo itemInfo)
{
if (toolAndMaterialDic.ContainsKey(itemInfo.toolName))
{
if (toolAndMaterialDic[itemInfo.toolName].Count > 1)
{
toolAndMaterialDic[itemInfo.toolName].Remove(itemInfo);
}
else
{
toolAndMaterialDic.Remove(itemInfo.toolName);
}
}
}
///
/// 移除多个
///
///
public void RemoveAllToolOrMater(ItemInfo itemInfo)
{
if (toolAndMaterialDic.ContainsKey(itemInfo.toolName))
{
toolAndMaterialDic.Remove(itemInfo.toolName);
}
}
///
/// 清除背包数据
///
public void ClearAllData()
{
wearDic.Clear();
toolAndMaterialDic.Clear();
}
///
/// 拿出背包所有东西
///
public void ClearAllToolAndDiveceAndMaterial()
{
ClearAllData();
}
///
/// 添加 穿戴 状态 0 去掉 1 穿上
///
///
///
public void WearItemState(ItemInfo itemInfo, bool state)
{
if (state)
{
if (!wearDic.ContainsKey(itemInfo.toolName))
wearDic.Add(itemInfo.toolName, itemInfo);
}
else
{
if (wearDic.ContainsKey(itemInfo.toolName))
wearDic.Remove(itemInfo.toolName);
}
}
///
/// 已经穿上
///
///
public bool IsWeared(HashSet wears)
{
HashSet keys = new HashSet(wearDic.Keys);
foreach (var str in keys)
{
wears.RemoveWhere(key => str.Contains(key));
}
return wears.Count == 0;
}
}