| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390 | 
							- using System;
 
- using System.Collections.Generic;
 
- using System.Linq;
 
- using ET;
 
- using UnityEngine;
 
- namespace GFGGame
 
- {
 
-     public class ItemDataManager
 
-     {
 
-         private static Dictionary<int, ItemData> _dataDic = new Dictionary<int, ItemData>();
 
-         private static Dictionary<int, int> _itemExchangeDic = new Dictionary<int, int>();
 
-         delegate object MemberGetDelegate(ItemCfg p);
 
-         public static void Clear()
 
-         {
 
-             _itemExchangeDic.Clear();
 
-         }
 
-         public static void Add(ItemInfoProto itemInfoProto)
 
-         {
 
-             //初始化时禁止使用物品配置,会造成卡顿!!!
 
-             var itemID = itemInfoProto.ConfigId;
 
-             ItemData itemData = null;
 
-             if (_dataDic.ContainsKey(itemID))
 
-             {
 
-                 itemData = _dataDic[itemID];
 
-             }
 
-             else
 
-             {
 
-                 itemData = ItemDataPool.GetItemData(itemID);
 
-                 itemData.itemType = itemInfoProto.Type;
 
-                 itemData.subType = itemInfoProto.SubType;
 
-                 itemData.rarity = itemInfoProto.Rarity;
 
-                 _dataDic.Add(itemID, itemData);
 
-             }
 
-             itemData.num = itemInfoProto.Count;
 
-             if (itemInfoProto.Type == ConstItemType.DRESS_UP && itemID % GameConst.MAX_COUNT_EVERY_TYPE_ITEM > 0)
 
-             {
 
-                 DressUpMenuItemDataManager.Add(itemInfoProto);
 
-                 if (!DressUpMenuItemCfg1Array.Instance.CheckIsBackGroundType(itemInfoProto))
 
-                 {
 
-                     DecomposeDataManager.Instance.Add(itemID);
 
-                 }
 
-                 //游戏角色初始数据完成后才执行
 
-                 if (GameGlobal.DataInited)
 
-                 {
 
-                     ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemID);
 
-                     FunctionOpenCfg functionOpenCfg = FunctionOpenCfgArray.Instance.GetCfg(typeof(ClothingListView).Name);
 
-                     if (itemCfg.rarity == ConstDressRarity.Rarity_TIANYI
 
-                     && StorageDataManager.Instance.GetStorageValue(ConstStorageId.FUNCTION_OPEN +
 
-                                                                    functionOpenCfg.index) == 0)
 
-                     {
 
-                         FunctionOpenDataManager.Instance.CheckHasSpecialFunOpen();
 
-                     }
 
-                 }
 
-                     
 
-             }
 
-             if ((itemInfoProto.Type == ConstItemType.ITEM || itemInfoProto.Type == ConstItemType.USEABLE) &&
 
-                 itemData.num > 0)
 
-             {
 
-                 BagDataManager.Instance.Add(itemData);
 
-                 if (itemInfoProto.Type == ConstItemType.ITEM && itemInfoProto.SubType == ConstItemSubType.MATERIAL_SKILL_BOOK)
 
-                 {
 
-                     DecomposeDataManager.Instance.AddMaterial(itemID);
 
-                 }
 
-             }
 
-             if (itemInfoProto.Type == ConstItemType.HEAD)
 
-             {
 
-                 RoleInfoManager.Instance.Add(itemInfoProto);
 
-                 if (GameGlobal.DataInited)
 
-                 {
 
-                     RoleInfoManager.Instance.AddNew(itemID);
 
-                     EventAgent.DispatchEvent(ConstMessage.RED_CHANGE);
 
-                 }
 
-             }
 
-             PhotographDataManager.Instance.Add(itemInfoProto);
 
-             if(GameGlobal.DataInited)
 
-             {
 
-                 EventAgent.DispatchEvent(ConstMessage.ITEM_CHANGED, itemID);
 
-             }
 
-         }
 
-         public static void Remove(int itemID, long itemNum)
 
-         {
 
-             if (_dataDic.ContainsKey(itemID))
 
-             {
 
-                 ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemID);
 
-                 ItemData itemData = _dataDic[itemID];
 
-                 itemData.num -= itemNum;
 
-                 if (itemData.num <= 0)
 
-                 {
 
-                     itemData.num = 0;
 
-                     _dataDic.Remove(itemID);
 
-                     if (ItemUtilCS.IsDressUpItem(itemID))
 
-                     {
 
-                         DressUpMenuItemDataManager.Remove(itemID);
 
-                     }
 
-                     if (itemCfg.itemType == ConstItemType.ITEM)
 
-                     {
 
-                         BagDataManager.Instance.Remove(itemID);
 
-                         if(itemCfg.subType == ConstItemSubType.MATERIAL_SKILL_BOOK)
 
-                             DecomposeDataManager.Instance.RemoveMaterial(itemID);
 
-                     }
 
-                     if (itemCfg.itemType == ConstItemType.USEABLE)
 
-                     {
 
-                         BagDataManager.Instance.Remove(itemID);
 
-                     }
 
-                     if (itemCfg.itemType == ConstItemType.HEAD)
 
-                     {
 
-                         RoleInfoManager.Instance.Remove(itemID);
 
-                     }
 
-                 }
 
-                 if (itemCfg.itemType == ConstItemType.DRESS_UP)//&& !DressUpMenuItemCfg1Array.Instance.CheckIsSceneType(itemID)
 
-                 {
 
-                     DecomposeDataManager.Instance.Remove(itemID);
 
-                 }
 
-                 EventAgent.DispatchEvent(ConstMessage.ITEM_CHANGED, itemID);
 
-             }
 
-         }
 
-         public static long GetItemNum(int itemId)
 
-         {
 
-             int numericType = NumericUtil.GetNumericTypeByItemId(itemId);
 
-             if (numericType != 0)
 
-             {
 
-                 return GameGlobal.myNumericComponent.GetAsInt(numericType);
 
-             }
 
-             int leagueType = NumericUtil.GetLeagueNumericTypeByItemId(itemId);
 
-             if (leagueType != 0)
 
-             {
 
-                 return LeagueDataManager.Instance.GetNumeriValue(leagueType);
 
-             }
 
-             if (_dataDic.TryGetValue(itemId, out var itemData))
 
-             {
 
-                 return itemData.num;
 
-             }
 
-             return 0;
 
-         }
 
-         public static int GetItemType(int itemId)
 
-         {
 
-             _dataDic.TryGetValue(itemId, out var value);
 
-             if(value != null)
 
-             {
 
-                 return value.itemType;
 
-             }
 
-             ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId);
 
-             return itemCfg.itemType;
 
-         }
 
-         public static int[][] GetItemSyntheticSuitArr(int itemId)
 
-         {
 
-             _dataDic.TryGetValue(itemId, out var value);
 
-             if (value != null && value.syntheticMateriarsArr != null && value.syntheticMateriarsArr.Length > 0)
 
-             {
 
-                 return value.syntheticMateriarsArr;
 
-             }
 
-             ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId);
 
-             return itemCfg.syntheticMateriarsArr;
 
-         }
 
-         public static int GetItemSubType(int itemId)
 
-         {
 
-             _dataDic.TryGetValue(itemId, out var value);
 
-             if (value != null)
 
-             {
 
-                 return value.subType;
 
-             }
 
-             ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId);
 
-             return itemCfg.subType;
 
-         }
 
-         public static int GetItemRarity(int itemId)
 
-         {
 
-             _dataDic.TryGetValue(itemId, out var value);
 
-             if (value != null)
 
-             {
 
-                 return value.rarity;
 
-             }
 
-             ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId);
 
-             return itemCfg.rarity;
 
-         }
 
-         public static int GetItemSkillId(int itemId)
 
-         {
 
-             _dataDic.TryGetValue(itemId, out var value);
 
-             if (value != null && value.param2Arr != null)
 
-             {
 
-                 return value.param2Arr[0];
 
-             }
 
-             ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId);
 
-             return itemCfg.param2Arr[0];
 
-         }
 
-         public static void InitServerData(List<ItemInfoProto> items)
 
-         {
 
-             _dataDic.Clear();
 
-             foreach (ItemInfoProto roleItem in items)
 
-             {
 
-                 Add(roleItem);
 
-             }
 
-             DressUpMenuItemDataManager.StartPreLoadItemCfg();
 
-             _ = DressUpMenuItemDataManager.GetAllDressUpGuideIdListBySubTypeAsync();
 
-         }
 
-         public static void InitServerDataItemAttribute(List<ItemAttributeProto> infos)
 
-         {
 
-             foreach (var info in infos)
 
-             {
 
-                 if (_dataDic.TryGetValue(info.ConfigId, out var itemData))
 
-                 {
 
-                     itemData.SetAttributes(info.Ks, info.Vs);
 
-                 }
 
-             }
 
-         }
 
-         public static void InitItemExchange(int itemId, int exchangTimes)
 
-         {
 
-             if (_itemExchangeDic.ContainsKey(itemId))
 
-             {
 
-                 _itemExchangeDic[itemId] = exchangTimes;
 
-             }
 
-             else
 
-             {
 
-                 _itemExchangeDic.Add(itemId, exchangTimes);
 
-             }
 
-         }
 
-         //获取物品已兑换次数
 
-         public static int GetItemExchangeTimes(int itemId)
 
-         {
 
-             if (_itemExchangeDic.ContainsKey(itemId) == false)
 
-             {
 
-                 InitItemExchange(itemId, 0);
 
-             }
 
-             return _itemExchangeDic[itemId];
 
-         }
 
-         public static void SetAttribute(int itemId, int key, int value)
 
-         {
 
-             if (_dataDic.TryGetValue(itemId, out var itemData))
 
-             {
 
-                 itemData.SetAttribute(key, value);
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 获取表格配置的基础属性
 
-         /// </summary>
 
-         /// <param name="itemId"></param>
 
-         /// <param name="scoreType"></param>
 
-         /// <returns></returns>
 
-         public static int GetItemBaseScoreValue(int itemId, int scoreType)
 
-         {
 
-             ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId);
 
-             if (scoreType == 1)
 
-             {
 
-                 return itemCfg.score1;
 
-             }
 
-             else if (scoreType == 2)
 
-             {
 
-                 return itemCfg.score2;
 
-             }
 
-             else if (scoreType == 3)
 
-             {
 
-                 return itemCfg.score3;
 
-             }
 
-             else if (scoreType == 4)
 
-             {
 
-                 return itemCfg.score4;
 
-             }
 
-             return 0;
 
-         }
 
-         /// <summary>
 
-         /// 获取当前(养护/升级/升星...后)的属性
 
-         /// </summary>
 
-         /// <param name="itemId"></param>
 
-         /// <param name="scoreType"></param>
 
-         /// <returns></returns>
 
-         public static int GetItemAdditionScore(int itemId, int scoreType, string[] tags = null)
 
-         {
 
-             if (_dataDic.TryGetValue(itemId, out var itemData))
 
-             {
 
-                 int scroe = 0;
 
-                 if (tags != null)
 
-                 {
 
-                     scroe += GetItemTagScore(itemId, tags);
 
-                 }
 
-                 scroe += itemData.GetScore(scoreType);
 
-                 return scroe;
 
-             }
 
-             return 0;
 
-         }
 
-         /// <summary>
 
-         /// 获取茶话会item物品的属性
 
-         /// </summary>
 
-         /// <param name="itemId"></param>
 
-         /// <param name="scoreType"></param>
 
-         /// <returns></returns>
 
-         public static int GetItemAddTeaPartyTagsScore(int itemId)//, int scoreType, string[] tags = null)
 
-         {
 
-             if (_dataDic.TryGetValue(itemId, out var itemData))
 
-             {
 
-                 int scroe = 0;
 
-                 ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId);
 
-                 if (itemCfg.tagsArr != null)
 
-                 {
 
-                     foreach (var info in itemCfg.tagsArr)
 
-                     {
 
-                         scroe += Convert.ToInt32(info[1]);
 
-                     }
 
-                 }
 
-                 return scroe;
 
-             }
 
-             return 0;
 
-         }
 
-         /// <summary>
 
-         /// 获取一个换装部件对应的标签分数
 
-         /// </summary>
 
-         /// <param name="itemId"></param>
 
-         /// <param name="tags"></param>
 
-         /// <returns></returns>
 
-         public static int GetItemTagScore(int itemId, string[] tags)
 
-         {
 
-             int score = 0;
 
-             ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId);
 
-             if (itemCfg == null)
 
-             {
 
-                 ET.Log.Error("物品:" + itemId + "不存在");
 
-                 return score;
 
-             }
 
-             for (int i = 0; i < itemCfg.tagsArr.Length; i++)
 
-             {
 
-                 for (int j = 0; j < tags.Length; j++)
 
-                 {
 
-                     if (itemCfg.tagsArr[i][0] == tags[j])
 
-                     {
 
-                         score += int.Parse(itemCfg.tagsArr[i][1]);
 
-                     }
 
-                 }
 
-             }
 
-             return score;
 
-         }
 
-         /// <summary>
 
-         /// 检测一件服装是否包含要求的标签
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         public static bool CheckItemTagsRight(int itemId, string[] tags)
 
-         {
 
-             ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId);
 
-             for (int i = 0; i < itemCfg.tagsArr.Length; i++)
 
-             {
 
-                 for (int j = 0; j < tags.Length; j++)
 
-                 {
 
-                     if (itemCfg.tagsArr[i][0] == tags[j]) return true;
 
-                 }
 
-             }
 
-             return false;
 
-         }
 
-         /// <summary>
 
-         /// 检测背包中是否存在礼包
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         public static bool BagIsExistGiftBag()
 
-         {
 
-             var isExistGiftBag = _dataDic.Values.Any(a =>
 
-                 ((a.itemType == ConstItemType.USEABLE && a.subType == ConstItemSubType.USEABLE_GIFT_BAG_SELECTABLE) ||
 
-                 (a.itemType == ConstItemType.USEABLE && a.subType == ConstItemSubType.USEABLE_GIFT_BAG_RANDOM)) 
 
-                 && a.id != 6003001 && a.id != 6003002);
 
-             return isExistGiftBag;
 
-         }
 
-     }
 
- }
 
 
  |