using System.Collections; using System.Collections.Generic; using System; using UnityEngine; namespace GFGGame { public enum DressFilterType { None, Search, Filter } public class DressUpMenuItemDataManager { public static string dressSearchTxt = ""; public static DressFilterType dressFilterType = DressFilterType.None; public static List selectRarityList = new List(); public static List selectScoreList = new List(); public static List selectTagList = new List(); private static List _itemDatas = new List(); private static Dictionary> _itemDatasBySubTypeDic = new Dictionary>(); public static Dictionary> ItemDatasBySubTypeDic { get { return _itemDatasBySubTypeDic; } } private static Dictionary> _newItemdata = new Dictionary>(); private static List _newSuitData = new List(); public static void InitData() { _itemDatas.Clear(); _newItemdata.Clear(); _itemDatasBySubTypeDic.Clear(); } public static void Clear() { DressUpMenuItemDataManager.dressFilterType = DressFilterType.None; selectRarityList.Clear(); selectScoreList.Clear(); selectTagList.Clear(); dressSearchTxt = ""; } public static void Add(int value) { ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(value); if (itemCfg == null) { Debug.LogError("添加了一个不存在的物品" + value); } else { if (!_itemDatas.Contains(value)) { _itemDatas.Add(value); int subType = ItemUtilCS.GetItemSubType(value); subType = subType >= (int)ConstDressUpItemType.TE_SHU ? (int)ConstDressUpItemType.TE_SHU : subType; if (!_itemDatasBySubTypeDic.ContainsKey(subType)) { _itemDatasBySubTypeDic.Add(subType, new List()); } _itemDatasBySubTypeDic[subType].Add(value); if (GameGlobal.DataInited) { AddNewDressItem(value); } DressUpMenuSuitDataManager.CheckItemInSuit(value); } } } public static bool CheckHasItem(int itemID) { return _itemDatas.Contains(itemID); } public static void Remove(int value) { if (_itemDatas == null) { return; } if (_itemDatas.Contains(value)) { _itemDatas.Remove(value); } int subType = ItemUtilCS.GetItemSubType(value); subType = subType >= (int)ConstDressUpItemType.TE_SHU ? (int)ConstDressUpItemType.TE_SHU : subType; if (_itemDatasBySubTypeDic.ContainsKey(subType) && _itemDatasBySubTypeDic[subType].IndexOf(value) >= 0) { _itemDatasBySubTypeDic[subType].Remove(value); } } public static List getItemDatasByType(int type) { List arrayList = new List(); if (_itemDatasBySubTypeDic.ContainsKey(type)) { arrayList.AddRange(_itemDatasBySubTypeDic[type]); } // for (int i = 0; i < _itemDatas.Count; i++) // { // int itemID = (int)_itemDatas[i]; // int subType = ItemUtilCS.GetItemSubType(itemID); // if (type == (int)ConstDressUpItemType.TE_SHU && subType > type) // { // arrayList.Add(itemID); // } // else if (subType == type) // { // arrayList.Add(itemID); // } // } return arrayList; } public static List SortItemListByHighScore(List arrayList) { arrayList.Sort((int a, int b) => { bool isNewA = CheckIsDressUpItemNew(a); bool isNewB = CheckIsDressUpItemNew(b); if (isNewA != isNewB) { if (isNewA) return -1; if (isNewB) return 1; } int scoreA = ItemDataManager.GetItemAdditionScore(a, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ; int scoreB = ItemDataManager.GetItemAdditionScore(b, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ; if (scoreB > scoreA) { return 1; } else if (scoreB < scoreA) { return -1; } return 0; }); return arrayList; } public static List SortItemListByLowScore(List arrayList) { arrayList.Sort((int a, int b) => { bool isNewA = CheckIsDressUpItemNew(a); bool isNewB = CheckIsDressUpItemNew(b); if (isNewA != isNewB) { if (isNewA) return -1; if (isNewB) return 1; } int scoreA = ItemDataManager.GetItemAdditionScore(a, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ; int scoreB = ItemDataManager.GetItemAdditionScore(b, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ; if (scoreB < scoreA) { return 1; } else if (scoreB > scoreA) { return -1; } return 0; }); return arrayList; } private static List SortItemListByScoreByType(List arrayList) { arrayList.Sort((int a, int b) => { int typeA = ItemUtilCS.GetItemSubType(a); int typeB = ItemUtilCS.GetItemSubType(b); int scoreA = ItemDataManager.GetItemAdditionScore(a, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ; int scoreB = ItemDataManager.GetItemAdditionScore(b, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags); ; if (typeB < typeA) { return -1; } else if (typeB > typeA) { return 1; } else if (scoreB > scoreA) { return 1; } else if (scoreB < scoreA) { return -1; } return 0; }); return arrayList; } public static List SortItemListByHighRarity(List arrayList) { arrayList.Sort((int a, int b) => { ItemCfg itemCfgA = ItemCfgArray.Instance.GetCfg(a); ItemCfg itemCfgB = ItemCfgArray.Instance.GetCfg(b); bool isNewA = CheckIsDressUpItemNew(a); bool isNewB = CheckIsDressUpItemNew(b); if (isNewA != isNewB) { if (isNewA) return -1; if (isNewB) return 1; } if (itemCfgB.rarity > itemCfgA.rarity) { return 1; } else if (itemCfgB.rarity < itemCfgA.rarity) { return -1; } return 0; }); return arrayList; } public static List SortItemListByLowRarity(List arrayList) { arrayList.Sort((int a, int b) => { ItemCfg itemCfgA = ItemCfgArray.Instance.GetCfg(a); ItemCfg itemCfgB = ItemCfgArray.Instance.GetCfg(b); bool isNewA = CheckIsDressUpItemNew(a); bool isNewB = CheckIsDressUpItemNew(b); if (isNewA != isNewB) { if (isNewA) return -1; if (isNewB) return 1; } if (itemCfgB.rarity < itemCfgA.rarity) { return 1; } else if (itemCfgB.rarity > itemCfgA.rarity) { return -1; } return 0; }); return arrayList; } public static List GetRecommendItemList(bool toSort = true) { StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(InstanceZonesDataManager.currentLevelCfgId); StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID); List recommendTypeList = new List(); List recommendList = new List(); List recommendSpecialList = new List(); List tempAllList = _itemDatas.GetRange(0, _itemDatas.Count); if (toSort) { SortItemListByScoreByType(tempAllList); } foreach (int itemID in tempAllList) { int subType = ItemUtilCS.GetItemSubType(itemID); if (!DressUpMenuItemCfg1Array.Instance.CheckIsSceneType(itemID) && subType != ConstDressUpItemType.BEI_JING) { if (!recommendTypeList.Contains(subType)) { bool isNeed = fightCfg.needItemId > 0 && (ItemUtilCS.GetItemSubType(fightCfg.needItemId) != subType || ItemUtilCS.GetItemSubType(fightCfg.needItemId) == subType && fightCfg.needItemId == itemID); if (isNeed || fightCfg.needItemId <= 0) { if (subType < ConstDressUpItemType.TE_SHU) { recommendList.Add(itemID); } recommendTypeList.Add(subType); } } } } recommendSpecialList = DressUpMenuItemDataManager.getItemDatasByType(ConstDressUpItemType.TE_SHU); recommendSpecialList = DressUpMenuItemDataManager.SortItemListByHighScore(recommendSpecialList); List specialSubList = new List(); List specialIdList = new List(); foreach (int itemID in recommendSpecialList) { int subType = ItemUtilCS.GetItemSubType(itemID); if (subType > ConstDressUpItemType.TE_SHU) { if (specialSubList.Count >= 3) continue; if (specialSubList.IndexOf(subType) < 0) { specialSubList.Add(subType); specialIdList.Add(itemID); } } } recommendList.AddRange(specialIdList); return recommendList; } // public static int GetRecommendCount() // { // List recommendTypeList = GetRecommendItemList(false); // return recommendTypeList.Count; // } // public static int GetItemScore(int itemId) // { // return ItemDataManager.GetItemAdditionScore(itemId, InstanceZonesDataManager.currentScoreType); // } public static List DressSearch(List list) { List searchList = new List(); for (int i = 0; i < list.Count; i++) { bool isSearch = true; ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(list[i]); SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(list[i]); string name = itemCfg != null ? itemCfg.name : suitCfg.name; for (int j = 0; j < dressSearchTxt.Length; j++) { if (name.IndexOf(dressSearchTxt[j]) < 0) { isSearch = false; break; } } if (isSearch) { searchList.Add(list[i]); } } return searchList; } public static List DressFilter(List list) { List filterList = new List(); for (int i = 0; i < list.Count; i++) { ItemCfg cfg = ItemCfgArray.Instance.GetCfg(list[i]); SuitCfg tzCfg = SuitCfgArray.Instance.GetCfg(list[i]); bool isRarity = cfg == null ? FilterRarity(tzCfg) : FilterRarity(cfg); bool isScore = cfg == null ? true : FilterScore(cfg); bool isTag = cfg == null ? true : FilterTag(cfg); if (isRarity && isScore && isTag) { filterList.Add(list[i]); } } if (filterList.Count == 0) { PromptController.Instance.ShowFloatTextPrompt("无满足条件物品"); } return filterList; } private static bool FilterRarity(ItemCfg cfg) { bool isRarity = false; if (selectRarityList.Count > 0) { for (int j = 0; j < selectRarityList.Count; j++) { if (cfg != null && cfg.rarity == selectRarityList[j]) { isRarity = true; break; } } } else { isRarity = true; } return isRarity; } private static bool FilterRarity(SuitCfg cfg) { bool isRarity = false; if (selectRarityList.Count > 0) { for (int j = 0; j < selectRarityList.Count; j++) { if (cfg != null && cfg.rarity == selectRarityList[j]) { isRarity = true; break; } } } else { isRarity = true; } return isRarity; } private static bool FilterScore(ItemCfg cfg) { bool isScore = false; if (selectScoreList.Count > 0) { if (cfg != null) { for (int j = 0; j < selectScoreList.Count; j++) { if (cfg.mainScore == selectScoreList[j]) { isScore = true; break; } } } } else { isScore = true; } return isScore; } private static bool FilterTag(ItemCfg cfg) { bool isTag = false; if (selectTagList.Count > 0) { if (cfg != null) { for (int j = 0; j < selectTagList.Count; j++) { if (isTag == true) { break; } for (int k = 0; k < cfg.tagsArr.Length; k++) { if (cfg.tagsArr[k][0] == selectTagList[j]) { isTag = true; break; } } } } } else { isTag = true; } return isTag; } public static void AddNewDressItem(int value) { int subType = ItemUtilCS.GetItemSubType(value); if (!_newItemdata.ContainsKey(subType)) { _newItemdata.Add(subType, new List()); } _newItemdata[subType].Add(value); // ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(value); // if (itemCfg.suitId > 0 && DressUpMenuSuitDataManager.CheckHaveSuit(itemCfg.suitId)) // { // SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(itemCfg.suitId); // } } public static void RemoveNewDressItem(int itemId) { int subType = ItemCfgArray.Instance.GetCfg(itemId).subType; if (_newItemdata.ContainsKey(subType) && _newItemdata[subType].IndexOf(itemId) >= 0) { _newItemdata[subType].Remove(itemId); } } //检测一级菜单是否有展示新增 public static bool CheckIsFirstMenuNew(int menuId) { if (_newItemdata.Count == 0) return false; DressUpMenuItemCfg1 cfg1 = DressUpMenuItemCfg1Array.Instance.GetCfg(menuId); if (cfg1.subMenusArr.Length > 0)//有二级菜单 { foreach (int id2 in cfg1.subMenusArr) { if (CheckIsSecondMenuNew(id2)) return true; } } else { if (_newItemdata.ContainsKey(cfg1.type) && _newItemdata[cfg1.type].Count > 0) return true; } return false; } //检测二级菜单是否有展示新增 public static bool CheckIsSecondMenuNew(int subMenuId) { if (_newItemdata.Count == 0) return false; DressUpMenuItemCfg2 cfg2 = DressUpMenuItemCfg2Array.Instance.GetCfg(subMenuId); if (_newItemdata.ContainsKey(cfg2.type) && _newItemdata[cfg2.type].Count > 0) { return true; } return false; } //检测服装部件是否为新增 public static bool CheckIsDressUpItemNew(int itemId) { if (_newItemdata.Count == 0) return false; int subType = ItemUtilCS.GetItemSubType(itemId); return _newItemdata.ContainsKey(subType) && _newItemdata[subType].IndexOf(itemId) >= 0; } } }