using UnityEngine;
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
///
/// 玩家物品
///
public class GameCollectItem
{
///
/// 物品
///
public Dictionary collectItemDic = new Dictionary();
///
/// 新道具记录
///
public List itemRecord = new List();
#region 七宗罪元素
///
/// 七宗罪元素,这个不占背包格子,也不在背包里显示
///
private Dictionary collectElementDic = new Dictionary();
///
/// 刷新背包七宗罪元素数据
///
///
public void RefreshElement(JObject data)
{
if (data != null)
{
collectElementDic.Clear();
LogHelper.Log(data);
foreach (JProperty temp in data.Properties())
{
var itemtemp = new ItemVo();
itemtemp.typeId = temp.Name;
itemtemp.count = temp.Value.ToObject();
collectElementDic.Add(itemtemp.typeId, itemtemp);
}
}
}
///
/// 获取七宗罪元素的数据
///
///
public Dictionary GetElementDic()
{
Dictionary temp = new Dictionary();
foreach (string key in collectElementDic.Keys)
{
ItemVo vo = collectElementDic[key];
temp.Add(vo.typeId, vo);
}
return temp;
}
#endregion
///
/// 初始化已经拥有的物品数据
///
///
public void InitItemData(JObject data)
{
if (data["items"] != null)
{
collectItemDic.Clear();
JObject items = (JObject)data["items"];
foreach (JProperty temp in items.Properties())
{
// 普通道具只有id 和数量 -- gwang 2019年11月14日10:25:27
var itemtemp = new ItemVo();
itemtemp.typeId = temp.Name;
itemtemp.count = temp.Value.ToObject();
if (itemtemp.count > 0)
{
collectItemDic.Add(itemtemp.typeId, itemtemp);
}
}
}
//if (data["segement"] != null) // 碎片模块单独出去了 --gwang 2019年11月14日10:25:19
//{
//}
if (data["itemRecord"] != null)
{
this.itemRecord.Clear();
JArray arr = JArray.Parse(data["itemRecord"].ToString());
foreach (JToken id in arr)
{
this.itemRecord.Add(id.ToString());
}
}
if (data["element"] != null)
{
collectElementDic.Clear();
JObject items = (JObject)data["element"];
foreach (JProperty temp in items.Properties())
{
// 七宗罪元素也只有id和数量 --gwang 2019年11月14日10:25:10
var itemtemp = new ItemVo();
itemtemp.typeId = temp.Name;
itemtemp.count = temp.Value.ToObject();
collectElementDic.Add(itemtemp.typeId, itemtemp);
}
}
#region 注释
//if (data["equipment"] != null)
//{
// JObject equipment = (JObject)data["equipment"]; // {uid:{typeId:"",level:x,...},uid:{...},...}
// foreach (JProperty temp in equipment.Properties())
// {
// #region 旧代码
// //var itemtemp = new ItemVo();
// //itemtemp.typeId = temp.Value["typeId"].ToObject(); // typeId
// //// 装备类道具, 额外存储了level、melt_level和吃的经验数据(未升级或强化过的不存储此字段). --gwang 2019年11月14日10:25:01
// //if (temp.Value["level"] != null)
// //{
// // itemtemp.level = temp.Value["level"].ToObject();
// //}
// //if (temp.Value["melt_level"] != null)
// //{
// // itemtemp.melt_level = temp.Value["melt_level"].ToObject();
// //}
// //if (temp.Value["self_exp"] != null)
// //{
// // itemtemp.self_exp = temp.Value["self_exp"].ToObject();
// //}
// //else
// //{
// // itemtemp.self_exp = 0;
// //}
// #endregion
// var itemtemp = new EquipeMentVo();
// itemtemp.typeId = temp.Value["typeId"].ToObject(); // typeId
// { // 武器专属字段,不升级之前没有初始化 (不好,要改-wg)
// if (temp.Value["isLocked"] != null)
// {
// itemtemp.isLocked = temp.Value["isLocked"].ToObject();
// }
// if (temp.Value["isUsing"] != null)
// {
// itemtemp.WhoIsUsing = temp.Value["isUsing"].ToObject();
// }
// if (temp.Value["level"] != null)
// {
// itemtemp.level = temp.Value["level"].ToObject();
// }
// if (temp.Value["maxStar"] != null)
// {
// itemtemp.maxStar = temp.Value["maxStar"].ToObject();
// }
// if (temp.Value["starLevel"] != null)
// {
// itemtemp.starLevel = temp.Value["starLevel"].ToObject();
// }
// }
// itemtemp.uid = temp.Name; // uid
// collectItemDic.Add(itemtemp.uid, itemtemp); // 这里, 装备index从1开始,其他道具按照6位的编号作为索引,应该不至于冲突 --王刚 2019年11月14日10:31:19
// // 另外一个存在uid的就是英雄了, 从10001开始,5位编码,整个10001到99999段都没有别人用,应该也不至于不够用或者冲突了
// }
//}
#endregion
}
///
/// 根据typeID来查询物品的数据信息
///
/// 类型或者uid
///
internal ItemVo GetRealItemInfoByType(string type)
{
if (collectItemDic.ContainsKey(type))
{
return collectItemDic[type];
}
return null;
}
///
/// 按子类型查询物品
///
/// 子类型为None时返回全部道具
///
public List GetItemList(EItemSubType _type = EItemSubType.None)
{
if (_type == EItemSubType.None) { // 限定种类
return collectItemDic.Values.ToList();
}
return collectItemDic.Values.Where(item => item.nMo.subType == (int)_type).ToList();
}
///
/// 取所有武器
///
///
public List GetWeaponList()
{
return UserProxy.Instance.player.collectEquip.equipments.Values.ToList();
}
///
/// 添加物品
///
///
///
public void AddItems(string ItemId, int num) {
if (collectItemDic.ContainsKey(ItemId))
{
collectItemDic[ItemId].count += num;
}
else {
collectElementDic.Add(ItemId, new ItemVo() { typeId = ItemId, count = num });
}
}
///
/// 检测是否有足够的道具
///
///
///
///
public bool CheckHasEngoughItem(string type, int num)
{
if (collectItemDic.ContainsKey(type))
{
if (collectItemDic[type].count >= num)
{
return true;
}
}
return false;
}
///
/// 返回指定物品的数量
///
/// typeid
///
public int GetItemCount(string type)
{
if (collectItemDic.ContainsKey(type))
{
return collectItemDic[type].count;
}
return 0;
}
///
/// 消耗背包中的道具
///
///
///
public void ConsumePacketItem(string itemid, int num)
{
if (collectItemDic.ContainsKey(itemid))
{
int curNum = collectItemDic[itemid].count;
collectItemDic[itemid].count = curNum - num;
if (collectItemDic[itemid].count <= 0)
{
collectItemDic.Remove(itemid);
}
}
}
public List GetStoreData(EItemSubType _type = EItemSubType.None)
{
if (_type == EItemSubType.None)
{ // 限定种类
return collectItemDic.Values.ToList();
}
List list = new List();
List tempList = new List();
foreach (KeyValuePair kv in this.collectItemDic)
{
if (kv.Value.nMo.subType != (int)_type)
{
continue;
}
if (kv.Value.count > 99999)
{
int n = kv.Value.count - 99999;
kv.Value.count = 99999;
list.Add(kv.Value);
ItemVo vo = new ItemVo();
vo.typeId = kv.Key;
vo.count = n;
list.Add(vo);
}
else
{
list.Add(kv.Value);
}
}
return list;
}
#region
///
/// 物品的相关数据发生变化
/// 通知UI层,重新刷新显示的事件触发
///
public System.EventHandler RefreshPacketUIDataViewEvent;
public System.EventHandler RefreshPropertyUIDataViewEvent;
public void RefreshUI(string even)
{
//---------------Event触发通知---------------------
if (RefreshPacketUIDataViewEvent != null)
{
RefreshPacketUIDataViewEvent.Invoke(even, EventArgs.Empty);
}
}
public void RefreshPropertyUI(string even = null)
{
//---------------Event触发通知---------------------
if (RefreshPropertyUIDataViewEvent != null)
{
RefreshPropertyUIDataViewEvent.Invoke(even, EventArgs.Empty);
}
}
#endregion
}