yyl
2025-06-04 a7f4c5ecc5268c49f6a6caf769b3ebee6f237662
Main/System/KnapSack/PackManager.cs
File was renamed from Main/Manager/GameSystemManager/PackManager.cs
@@ -1,1902 +1,1902 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using LitJson;
using System.Text.RegularExpressions;
using System.Collections;
    public class PackManager : GameSystemManager<PackManager>
    //public class PackModel : Model, IBeforePlayerDataInitialize, IAfterPlayerDataInitialize, IPlayerLoginOk
    {
        public static string StrengthAttrShift_RecordKey = "";
        public const string RecordKnapsackTitle = "RecordKnapsackTitle";
        Dictionary<int, int> DrugToDungeonDict { get; set; }   //key 丹药ID,value副本ID
        Dictionary<int, int[]> DungeonToDrugDict { get; set; }  //key 副本ID,value丹药ID列表
        //public List<AttrFruitConfig> makeDruglist { get; private set; }
        Dictionary<int, Dictionary<int, int>> decomposeAttrDict = new Dictionary<int, Dictionary<int, int>>();
        string RoleEquipLocalSave = "";
        List<int> LocalSavePlaceArray { get; set; }
        Dictionary<int, List<int>> sharedUseCountItemDict { get; set; }
        bool isUpdatePlayerLv = false;
        //AlchemyModel alchemyModel { get { return ModelCenter.Instance.GetModel<AlchemyModel>(); } }
        //ItemTipsModel itemTipsModel { get { return ModelCenter.Instance.GetModel<ItemTipsModel>(); } }
        public int lsItemID = 150; //可兑换的灵石物品ID
        int lsItemCnt = 0;
        List<string> commonShowAwardEvents = new List<string>();
        public int[] autoUseItemIDs;
        UIEffect lingshiEffect;  //灵石特效
        public override void Init()
        {
            DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitialize;
            DTC0102_tagCDBPlayer.afterPlayerDataInitializeEvent += OnAfterPlayerDataInitialize;
            DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent += OnPlayerLoginOk;
            ParseConfig();
            //SysNotifyMgr.Instance.sysNotifyEvent += RefreshSysInfo;
            // List<DungeonOpenTimeConfig> dungeonlist = DungeonOpenTimeConfig.GetValues();
            // if (dungeonlist != null)
            // {
            //     //DrugToDungeonDict = new Dictionary<int, int>();
            //     DungeonToDrugDict = new Dictionary<int, int[]>();
            //     for (int i = 0; i < dungeonlist.Count; i++)
            //     {
            //         int[] drugIdlist = dungeonlist[i].ElixirHint;
            //         if (drugIdlist != null && drugIdlist.Length > 0)
            //         {
            //             DungeonToDrugDict.Add(dungeonlist[i].DataMapID, drugIdlist);
            //             //for (int j = 0; j < drugIdlist.Length; j++)
            //             //{
            //             //    DrugToDungeonDict.Add(drugIdlist[j], dungeonlist[i].DataMapID);
            //             //}
            //         }
            //     }
            // }
            // makeDruglist = new List<AttrFruitConfig>();
            // List<AttrFruitConfig> fruitlist = AttrFruitConfig.GetValues();
            // for (int i = 0; i < fruitlist.Count; i++)
            // {
            //     if (fruitlist[i].FuncID == 2)
            //     {
            //         makeDruglist.Add(fruitlist[i]);
            //     }
            // }
            // StageLoad.Instance.onStageLoadFinish += OnStageLoadFinish;
            SetDevourEquipPlace();
            // decomposeAttrDict.Clear();
            // List<EquipDeComposeConfig> decomlist = EquipDeComposeConfig.GetValues();
            // for (int i = 0; i < decomlist.Count; i++)
            // {
            //     JsonData attrData = JsonMapper.ToObject(decomlist[i].Attr);
            //     Dictionary<int, int> attrDict = new Dictionary<int, int>();
            //     decomposeAttrDict.Add(decomlist[i].LV, attrDict);
            //     foreach (var id in attrData.Keys)
            //     {
            //         attrDict.Add(int.Parse(id), int.Parse(attrData[id].ToString()));
            //     }
            // }
            FuncConfigConfig equipDecompose = FuncConfigConfig.Get("EquipDevourCount");
            minDecomposeNum = int.Parse(equipDecompose.Numerical1);
            defaultUnSelectlist = ConfigParse.GetMultipleStr<int>(equipDecompose.Numerical2);
            FuncConfigConfig ShareUseCntItem = FuncConfigConfig.Get("ShareUseCntItem");
            sharedUseCountItemDict = new Dictionary<int, List<int>>();
            JsonData shareUseJson = JsonMapper.ToObject(ShareUseCntItem.Numerical1);
            if (shareUseJson.IsArray)
            {
                for (int i = 0; i < shareUseJson.Count; i++)
                {
                    var idListJson = shareUseJson[i];
                    var idlist = new List<int>();
                    sharedUseCountItemDict.Add(i, idlist);
                    foreach (var id in idListJson)
                    {
                        idlist.Add(int.Parse(id.ToString()));
                    }
                }
            }
            ParseItemCount();
            autoUseItemIDs = JsonMapper.ToObject<int[]>(FuncConfigConfig.Get("ItemTipsNum").Numerical2);
        }
        public override void Release()
        {
            DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitialize;
            DTC0102_tagCDBPlayer.afterPlayerDataInitializeEvent -= OnAfterPlayerDataInitialize;
            DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent -= OnPlayerLoginOk;
FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChangeEvent;
           // SysNotifyMgr.Instance.sysNotifyEvent -= RefreshSysInfo;
        }
        public Dictionary<int, string> textCountShow = new Dictionary<int, string>();
        public int[] textCountShow2;
        public List<int> gameCashShow = new List<int>();
        public void ParseItemCount()
        {
            var textConfig = FuncConfigConfig.Get("ItemCountShow");
            var json = JsonMapper.ToObject(textConfig.Numerical1);
            foreach (var key in json.Keys)
            {
                var itemID = int.Parse(key);
                textCountShow[itemID] = json[key].ToString();
            }
            textCountShow2 = JsonMapper.ToObject<int[]>(textConfig.Numerical2);
            gameCashShow = JsonMapper.ToObject<List<int>>(textConfig.Numerical3);
        }
        private void OnFuncStateChangeEvent(int id)
        {
            if (id == (int)FuncOpenEnum.EquipDecompose)
            {
                EquipDecomRedCtrl();
            }
        }
        public void OnBeforePlayerDataInitialize()
        {
            GlobalTimeEvent.Instance.secondEvent -= UpdateSecond;
            PlayerDatas.Instance.playerDataRefreshEvent -= UpdatePlayerLv;
            LocalSave.DeleteKey(RecordKnapsackTitle);
            cacheMapId = 0;
            playerPackDict.Clear();
            itemDayUseCntDict.Clear();
            itemSumUseCntDict.Clear();
            itemGUIDDict.Clear();
            isPlayBetterEquipEffect = false;
            colorType = EquipColorType.Orange;
            decomposeLv = 1;
            decomposeExp = 0;
            decomposeProgress = 0;
            isAutoDecompose = false;
        }
        public void OnAfterPlayerDataInitialize()
        {
        }
        public void OnPlayerLoginOk()
        {
            //ItemOperateUtility.Instance.RequestWarehouseData();
            EquipDecomRedCtrl();
            RoleEquipLocalSave = StringUtility.Contact("RoleEquipLocalSave", PlayerDatas.Instance.baseData.PlayerID);
            StrengthAttrShift_RecordKey = StringUtility.Contact(PlayerDatas.Instance.baseData.PlayerID, "StrengthAttrShift");
            if (LocalSave.GetIntArray(RoleEquipLocalSave) != null)
            {
                LocalSavePlaceArray = LocalSave.GetIntArray(RoleEquipLocalSave).ToList();
            }
            else
            {
                LocalSavePlaceArray = null;
            }
            GlobalTimeEvent.Instance.secondEvent += UpdateSecond;
            PlayerDatas.Instance.playerDataRefreshEvent += UpdatePlayerLv;
            isUpdatePlayerLv = true;
            FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent;
        }
        private void RefreshSysInfo(string key, ArrayList infolist)
        {
            // if (key != "GetMoney") return;
            // if (ItemLogicUtility.Instance.hidePickItem)
            //     return;
            // if (PlayerDatas.Instance.baseData.LV < 3)
            //     return;
            // var type = 0;
            // int.TryParse(infolist[0].ToString(), out type);
            // if (type == 1)
            // {
            //     Vector3 pos = new Vector3(-100, 0, 0);
            //     Vector3 rot = new Vector3(0, 0, 0);
            //     if (!WindowCenter.Instance.IsOpen<MainInterfaceWin>())
            //     {
            //         pos = new Vector3(0, 50, 0);
            //         rot = new Vector3(180, 180, 0);
            //     }
            //     EffectMgr.Instance.PlayUIEffect(1204, 3000, WindowCenter.Instance.uiRoot.tipsCanvas, pos, rot, false);
            // }
            // else if (type == 2)
            // {
            //     Vector3 pos = new Vector3(-100, 0, 0);
            //     Vector3 rot = new Vector3(0, 0, 0);
            //     if (!WindowCenter.Instance.IsOpen<MainInterfaceWin>())
            //     {
            //         pos = new Vector3(150, 50, 0);
            //         rot = new Vector3(180, 180, 0);
            //     }
            //     lingshiEffect = EffectMgr.Instance.PlayUIEffect(1158, 3000, WindowCenter.Instance.uiRoot.tipsCanvas, pos, rot, false);
            // }
        }
        public event Action<PackType> refrechPackEvent; //刷新整个背包数据
        public event Action<PackType, int, int> refreshItemCountEvent; // 慎用会卡(单个)最新物品数量刷新(旧的弃用)在得到新物品、物品数量的改变,清理该物品时均会触发 int 位置索引 int物品id
        public event Action<PackType> gridRefreshEvent; //背包空格刷新
        public event Action<PackType, int, int> itemCntAddEvent; //物品数量增加 int 位置索引 int物品id
        public event Action<PackType, int, int> itemCntReduceEvent; //物品数量减少的改变 int 位置索引 int物品id
        public event Action<int, int> useItemSuccessEvent; //物品使用成功 int 位置索引 int物品id
        public event Action<int> refreshItemDayUseCountEvent;  //刷新物品每日使用数量
        public event Action<int> refreshItemSumUseCountEvent;  //刷新物品总使用数量
        public bool isPlayBetterEquipEffect { get; set; }  //整理背包时是否播放特效
        #region 接收服务端数据
        private Dictionary<PackType, SinglePack> playerPackDict = new Dictionary<PackType, SinglePack>();
        private Dictionary<string, ItemModel> itemGUIDDict = new Dictionary<string, ItemModel>();
        public void UpdatePack(H0725_tagRolePackRefreshEx packInfo)
        {
            SetLookIndex(null);
            var packType = (PackType)packInfo.PackType;
            if (!playerPackDict.ContainsKey(packType))
            {
                playerPackDict.Add(packType, new SinglePack(packType));
            }
            if (isPlayBetterEquipEffect)
            {
                ItemLogicUtility.Instance.ClearSortedBetterEquip();
            }
            for (int i = 0; i < packInfo.ItemCount; i++)
            {
                var itemInfo = new ItemInfo(packInfo.ItemInfo[i]);
                var item = playerPackDict[packType].UpdateItem(itemInfo);
                AddItemGUIDDict(item, false);
                if (isPlayBetterEquipEffect)
                {
                    ItemLogicUtility.Instance.SetBagSortBetterEquipList(GetItemByGuid(itemInfo.guid));
                }
            }
            if (refrechPackEvent != null)
            {
                refrechPackEvent(packType);
            }
            UpdatePackRedpoint(packType);
        }
        public void UpdateItem(H0704_tagRolePackRefresh serverItem)
        {
            isPlayBetterEquipEffect = false;
            SetLookIndex(null);
            PackType type = (PackType)serverItem.PackType;
            if (!playerPackDict.ContainsKey(type))
            {
                playerPackDict.Add(type, new SinglePack(type));
            }
            var showNewItem = false;
            if (itemGUIDDict.ContainsKey(serverItem.ItemGUID))
            {
                var prePack = itemGUIDDict[serverItem.ItemGUID].packType;
                var preAuction = itemGUIDDict[serverItem.ItemGUID].isAuction;
                var nowPackType = type;
                var nowAcution = serverItem.IsBind == 1;
                showNewItem = preAuction != nowAcution || prePack != nowPackType;
            }
            else
            {
                showNewItem = true;
            }
            var itemInfo = new ItemInfo(serverItem);
            var item = playerPackDict[type].UpdateItem(itemInfo);
            AddItemGUIDDict(item, showNewItem);
            if (refreshItemCountEvent != null)
            {
                refreshItemCountEvent(type, itemInfo.index, itemInfo.itemId);
            }
            if (itemCntAddEvent != null)
            {
                itemCntAddEvent(type, itemInfo.index, itemInfo.itemId);
            }
            // if (type == PackType.Equip)
            // {
            //     if (ItemLogicUtility.Instance.IsRealmEquip(itemInfo.itemId))
            //     {
            //         ItemOperateUtility.Instance.ShowPutOnNewEquipRemind(itemInfo.itemId);
            //     }
            // }
            UpdatePackRedpoint(type);
            //EquipDecomRedCtrl();
            m_CheckEquipDecomRedCtrl = true;
            AutoUseItem(itemInfo.itemId, serverItem.ItemGUID);
        }
        bool m_CheckEquipDecomRedCtrl = false;
        void CheckEquipDecomRedCtrl()
        {
            if (m_CheckEquipDecomRedCtrl)
            {
                EquipDecomRedCtrl();
                m_CheckEquipDecomRedCtrl = false;
            }
        }
        public void UpdateUnlockedGridCount(H0724_tagRolePackCanUseCount useCount)
        {
            PackType type = (PackType)useCount.PackType;
            if (!playerPackDict.ContainsKey(type))
            {
                playerPackDict.Add(type, new SinglePack(type));
            }
            playerPackDict[type].SetOpenGridCount(useCount.CanUseCount);
            if (gridRefreshEvent != null)
            {
                gridRefreshEvent(type);
            }
            UpdatePackRedpoint(type);
        }
        public void RefreshItemCount(H0707_tagItemCountRefresh refresh)
        {
            SetLookIndex(null);
            isPlayBetterEquipEffect = false;
            PackType type = (PackType)refresh.PackType;
            SinglePack singlePack = null;
            playerPackDict.TryGetValue(type, out singlePack);
            if (singlePack != null)
            {
                ItemModel itemModel = singlePack.GetItemByIndex(refresh.ItemIndex);
                if (itemModel != null)
                {
                    bool isAddItemCount = false;
                    if (refresh.ItemCount > itemModel.count)
                    {
                        isAddItemCount = true;
                    }
                    itemModel.RefreshCount(refresh.ItemCount);
                    if (isAddItemCount)
                    {
                        if (itemCntAddEvent != null)
                        {
                            itemCntAddEvent(type, itemModel.gridIndex, itemModel.itemId);
                        }
                        ItemLogicUtility.Instance.RecommendItem(itemModel);
                        ItemLogicUtility.Instance.RefreshPickItem(type, itemModel.itemId.ToString());
                    }
                    else
                    {
                        if (itemCntReduceEvent != null)
                        {
                            itemCntReduceEvent(type, itemModel.gridIndex, itemModel.itemId);
                        }
                    }
                    if (refreshItemCountEvent != null)
                    {
                        refreshItemCountEvent(type, itemModel.gridIndex, itemModel.itemId);
                    }
                    UpdateLSRedpoint(type, itemModel.itemId);
                }
            }
        }
        public void ClearPack(H0711_tagClearItemPack clearPack)
        {
            PackType type = (PackType)clearPack.PackIndex;
            SinglePack singlePack = null;
            playerPackDict.TryGetValue(type, out singlePack);
            if (singlePack != null)
            {
                singlePack.Clear();
            }
        }
        public void RemoveItem(H0709_tagClearItem clearItem)
        {
            isPlayBetterEquipEffect = false;
            SetLookIndex(null);
            PackType type = (PackType)clearItem.PackType;
            SinglePack singlePack = null;
            playerPackDict.TryGetValue(type, out singlePack);
            string guid = "";
            if (singlePack != null)
            {
                ItemModel itemModel = singlePack.GetItemByIndex(clearItem.ItemIndex);
                guid = itemModel.guid;
                int itemId = itemModel.itemId;
                DeleteItemDictByGUID(type, itemModel.guid);
                singlePack.RemoveItem(clearItem.ItemIndex);
                if (refreshItemCountEvent != null)
                {
                    refreshItemCountEvent(type, clearItem.ItemIndex, itemId);
                }
                if (itemCntReduceEvent != null)
                {
                    itemCntReduceEvent(type, clearItem.ItemIndex, itemId);
                }
            }
            UpdatePackRedpoint(type);
            m_CheckEquipDecomRedCtrl = true;
            //EquipDecomRedCtrl();
            if (GetItemByGuid(guid) == null)
            {
                KnapsackTimeCDMgr.Instance.UnRegister(guid);
            }
        }
        public void PackResetOk(H0316_tagPackResetOK packreset)
        {
            ItemLogicUtility.Instance.isPackResetOk = true;
        }
        public void UseItemSuccess(H0706_tagUseItemSuccess success)
        {
            isPlayBetterEquipEffect = false;
            SetLookIndex(null);
            if (success.PlayerID != PlayerDatas.Instance.baseData.PlayerID)
            {
                return;
            }
            MakeUseItemSuccess(success.ItemIndex, (int)success.ItemID);
            switch (success.ItemID)
            {
                // case 221:
                //     if (WindowCenter.Instance.IsOpen<KnapSackWin>())
                //     {
                //         WindowCenter.Instance.Close<KnapSackWin>();
                //     }
                //     break;
            }
            if (useItemSuccessEvent != null)
            {
                useItemSuccessEvent(success.ItemIndex, (int)success.ItemID);
            }
        }
        void AutoUseItem(int itemID, string guid)
        {
            // if (autoUseItemIDs.Contains(itemID))
            // {
            //     ItemOperateUtility.Instance.GotoUseItem(guid);
            // }
        }
        private void MakeUseItemSuccess(int index, int id)
        {
            ItemConfig itemConfig = ItemConfig.Get(id);
            if (itemConfig.CDType != 0)
            {
                var items = GetItems(PackType.Item, new SinglePack.FilterParams()
                {
                    itemTypes = new List<int>() { (int)ItemType.Buff }
                });
                for (int i = 0; i < items.Count; i++)
                {
                    if (ItemLogicUtility.Instance.drugIDs.Contains(items[i].itemId))
                    {
                        itemConfig = ItemConfig.Get(items[i].itemId);
                        float configCdTime = (float)Math.Round((double)itemConfig.CDTime / 1000, 1);
                        KnapsackTimeCDMgr.Instance.Register(items[i].guid, items[i].itemId, configCdTime);
                    }
                }
            }
        }
        void AddItemGUIDDict(ItemModel itemModel, bool showNewItem)
        {
            itemGUIDDict[itemModel.guid] = itemModel;
            GetItemEventCtrl(itemModel, showNewItem);
        }
        void DeleteItemDictByGUID(PackType type, string guid)
        {
            if (itemGUIDDict.ContainsKey(guid))
            {
                if (itemGUIDDict[guid].packType == type)
                {
                    itemGUIDDict.Remove(guid);
                }
            }
        }
        /// <summary>
        /// 物品每日使用的次数
        /// </summary>
        private Dictionary<int, int> itemDayUseCntDict = new Dictionary<int, int>();
        public void UpdateItemUseCnt(HA809_tagMCItemDayUseCntInfo useCntInfo)
        {
            for (int i = 0; i < useCntInfo.Count; i++)
            {
                int itemId = (int)useCntInfo.ItemUseCntList[i].ItemID;
                int cnt = useCntInfo.ItemUseCntList[i].UseCnt;
                if (!itemDayUseCntDict.ContainsKey(itemId))
                {
                    itemDayUseCntDict.Add(itemId, cnt);
                }
                else
                {
                    itemDayUseCntDict[itemId] = cnt;
                }
                if (refreshItemDayUseCountEvent != null)
                {
                    refreshItemDayUseCountEvent(itemId);
                }
            }
        }
        private Dictionary<int, int> itemSumUseCntDict = new Dictionary<int, int>();
        // public void UpdateItemSumUseCnt(HA339_tagMCAttrFruitEatCntList useCntInfo)
        // {
        //     for (int i = 0; i < useCntInfo.count; i++)
        //     {
        //         int itemId = (int)useCntInfo.EatCntList[i].ItemID;
        //         int cnt = (int)useCntInfo.EatCntList[i].EatCnt;
        //         if (!itemSumUseCntDict.ContainsKey(itemId))
        //         {
        //             itemSumUseCntDict.Add(itemId, cnt);
        //         }
        //         else
        //         {
        //             itemSumUseCntDict[itemId] = cnt;
        //         }
        //         if (refreshItemSumUseCountEvent != null)
        //         {
        //             refreshItemSumUseCountEvent(itemId);
        //         }
        //     }
        // }
        #endregion
        #region 玩家装备特殊逻辑
        public Dictionary<int, Dictionary<int, int>> spiritWeaponPathIds { get; private set; }
        public Dictionary<int, int> wingsGetPathIdDict { get; private set; }
        public Dictionary<int, List<int>> dungeonUseDict { get; private set; }
        void ParseConfig()
        {
            FuncConfigConfig funcConfig = FuncConfigConfig.Get("WingYuPeiHQTJ");
            spiritWeaponPathIds = new Dictionary<int, Dictionary<int, int>>();
            var splits = funcConfig.Numerical3.Split('|');
            for (int i = 0; i < splits.Length; i++)
            {
                var tempString = splits[i];
                var matches = Regex.Matches(tempString.Trim(), "\\d+");
                var equipPlace = int.Parse(matches[0].Value);
                var job = int.Parse(matches[1].Value);
                var itemId = int.Parse(matches[2].Value);
                if (!spiritWeaponPathIds.ContainsKey(equipPlace))
                {
                    spiritWeaponPathIds[equipPlace] = new Dictionary<int, int>();
                }
                spiritWeaponPathIds[equipPlace][job] = itemId;
            }
            FuncConfigConfig copyItemBulletWindow = FuncConfigConfig.Get("CopyItemBulletWindow");
            JsonData copyWinData = JsonMapper.ToObject(copyItemBulletWindow.Numerical1);
            dungeonUseDict = new Dictionary<int, List<int>>();
            foreach (var dungeonId in copyWinData.Keys)
            {
                List<int> idlist = new List<int>();
                dungeonUseDict.Add(int.Parse(dungeonId), idlist);
                if (copyWinData[dungeonId].IsArray)
                {
                    JsonData useData = copyWinData[dungeonId];
                    for (int i = 0; i < useData.Count; i++)
                    {
                        idlist.Add(int.Parse(useData[i].ToString()));
                    }
                }
            }
            lsItemCnt = int.Parse(FuncConfigConfig.Get("LingshiShowCount").Numerical1);
            var config = FuncConfigConfig.Get("CommonShowAwards");
            commonShowAwardEvents = JsonMapper.ToObject<List<string>>(config.Numerical1);
        }
        public int GetRoleEquipPathId(int equipPlace)
        {
            int playerJob = PlayerDatas.Instance.baseData.Job;
            switch ((RoleEquipType)equipPlace)
            {
                case RoleEquipType.Guard:
                case RoleEquipType.PeerlessWeapon1:
                case RoleEquipType.PeerlessWeapon2:
                case RoleEquipType.Wing:
                    return spiritWeaponPathIds[equipPlace][playerJob];
                default:
                    return 0;
            }
        }
        private void UpdateSecond()
        {
            if (isUpdatePlayerLv)
            {
                isUpdatePlayerLv = false;
            }
            CheckEquipDecomRedCtrl();
        }
        private void UpdatePlayerLv(PlayerDataType type)
        {
            if (type != PlayerDataType.LV) return;
            isUpdatePlayerLv = true;
        }
        #endregion
        private void GetItemEventCtrl(ItemModel itemModel, bool showNewItem)
        {
            // if (showNewItem)
            // {
            //     bool isOverdue = false;
            //     if (itemModel.config.ExpireTime > 0)
            //     {
            //         ItemCDCool cool = KnapsackTimeCDMgr.Instance.GetItemCoolById(itemModel.guid);
            //         switch ((ItemTimeType)itemModel.config.EndureReduceType)
            //         {
            //             case ItemTimeType.EquipedTime:
            //                 List<int> itemEffectTime = itemModel.GetUseData((int)ItemUseDataKey.createTime);
            //                 if (itemEffectTime != null && itemEffectTime[0] != 0)
            //                 {
            //                     if (cool == null || cool.GetRemainTime() <= 0)
            //                     {
            //                         isOverdue = true;
            //                     }
            //                 }
            //                 break;
            //             case ItemTimeType.RealityTime:
            //                 if (cool == null || cool.GetRemainTime() <= 0)
            //                 {
            //                     isOverdue = true;
            //                 }
            //                 break;
            //         }
            //     }
            //     if (!isOverdue)
            //     {
            //         ItemLogicUtility.Instance.RecommendItem(itemModel);
            //         ItemLogicUtility.Instance.OnGetEquip(itemModel);
            //         ItemLogicUtility.Instance.RefreshPickItem(itemModel.packType, itemModel.itemId.ToString());
            //     }
            // }
        }
        /// <summary>
        /// 得到某个包裹的所有数据
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public SinglePack GetSinglePack(PackType type)
        {
            SinglePack singlePack = null;
            playerPackDict.TryGetValue(type, out singlePack);
            return singlePack;
        }
        public void UnLockPackGrid(int chooseGridCount, PackType type)
        {
            // var singlePack = GetSinglePack(type);
            // int openCount = chooseGridCount - singlePack.unlockedGridCount;
            // int index = 0;
            // switch (type)
            // {
            //     case PackType.Item:
            //         index = chooseGridCount - GeneralDefine.initBagGridCount;
            //         break;
            //     case PackType.Warehouse:
            //         index = chooseGridCount - GeneralDefine.initDepotGridCount;
            //         break;
            // }
            // itemTipsModel.SetExtendGirdModel(openCount, index, type);
            // WindowCenter.Instance.Open<ExtendWin>();
        }
        public ItemModel GetItemByGuid(string guid)
        {
            if (string.IsNullOrEmpty(guid))
            {
                return null;
            }
            ItemModel itemModel = null;
            itemGUIDDict.TryGetValue(guid, out itemModel);
            return itemModel;
        }
        public ItemModel GetItemByIndex(PackType type, int index)
        {
            ItemModel itemModel = null;
            if (playerPackDict.ContainsKey(type))
            {
                itemModel = playerPackDict[type].GetItemByIndex(index);
            }
            return itemModel;
        }
        /// <summary>
        /// 获取指定背包内 指定ID的所有物品
        /// </summary>
        /// <param name="type"></param>
        /// <param name="id"></param>
        /// <param name="includeAuction"></param>
        /// <returns></returns>
        public List<ItemModel> GetItemsById(PackType type, int id, bool includeAuction = true)
        {
            if (playerPackDict.ContainsKey(type))
            {
                var singlePack = playerPackDict[type];
                return singlePack.GetItemsById(id, includeAuction);
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 获取指定背包内指定ID的一个物品
        /// </summary>
        /// <param name="type"></param>
        /// <param name="id"></param>
        /// <param name="includeAuction"></param>
        /// <returns></returns>
        public ItemModel GetItemByID(PackType type, int id, bool includeAuction = true)
        {
            if (playerPackDict.ContainsKey(type))
            {
                var singlePack = playerPackDict[type];
                return singlePack.GetItemByID(id, includeAuction);
            }
            else
            {
                return null;
            }
        }
        public List<ItemModel> GetItems(PackType packType, SinglePack.FilterParams param)
        {
            if (playerPackDict.ContainsKey(packType))
            {
                return playerPackDict[packType].GetItems(param);
            }
            else
            {
                return null;
            }
        }
        //通过id找物品,注意检查是否指定背包
        public string GetItemGUIDByID(int itemId, bool includeAuction = true, PackType packType = PackType.Item)
        {
            string guid = string.Empty;
            foreach (var key in itemGUIDDict.Keys)
            {
                if (!includeAuction && itemGUIDDict[key].isAuction)
                {
                    continue;
                }
                if (itemGUIDDict[key].itemId == itemId && packType == itemGUIDDict[key].packType)
                {
                    guid = key;
                    return guid;
                }
            }
            return guid;
        }
        /// <summary>
        /// 得到ID相同的物品数量
        /// </summary>
        /// <param name="type"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public int GetItemCountByID(PackType type, int id, bool includeAuction = true)
        {
            int count = 0;
            var singlePack = GetSinglePack(type);
            if (singlePack != null)
            {
                count = singlePack.GetCountById(id, includeAuction);
            }
            return count;
        }
        public int GetEmptyGridCount(PackType type)
        {
            int count = 0;
            SinglePack singlePack = GetSinglePack(type);
            if (singlePack != null)
            {
                count = singlePack.GetEmptyGridCount();
            }
            return count;
        }
        public bool TryGetShareNumItem(int itemId, out List<int> idlist)
        {
            idlist = new List<int>();
            foreach (var list in sharedUseCountItemDict.Values)
            {
                if (list.Contains(itemId))
                {
                    idlist = list;
                    return true;
                }
            }
            return false;
        }
        /// <summary>
        /// 得到物品今日使用次数
        /// </summary>
        /// <param name="itemId"></param>
        /// <returns></returns>
        public int GetItemUsedTimesToday(int itemId)
        {
            int useCnt = 0;
            List<int> shareIdlist = null;
            bool isShare = TryGetShareNumItem(itemId, out shareIdlist);
            if (isShare)
            {
                foreach (var id in shareIdlist)
                {
                    int singleUseCnt = 0;
                    itemDayUseCntDict.TryGetValue(id, out singleUseCnt);
                    useCnt += singleUseCnt;
                }
            }
            else
            {
                itemDayUseCntDict.TryGetValue(itemId, out useCnt);
            }
            return useCnt;
        }
        /// <summary>
        /// 得到物品总使用次数
        /// </summary>
        /// <param name="itemId"></param>
        /// <returns></returns>
        public int GetItemTotalUsedTimes(int itemId)
        {
            int useCnt = 0;
            List<int> shareIdlist = null;
            bool isShare = TryGetShareNumItem(itemId, out shareIdlist);
            if (isShare)
            {
                foreach (var id in shareIdlist)
                {
                    int singleUseCnt = 0;
                    itemDayUseCntDict.TryGetValue(id, out singleUseCnt);
                    useCnt += singleUseCnt;
                }
            }
            else
            {
                itemSumUseCntDict.TryGetValue(itemId, out useCnt);
            }
            return useCnt;
        }
        public void GotoWashAttributePoint(string guid)
        {
            // ItemModel itemModel = GetItemByGuid(guid);
            // if (itemModel == null) return;
            // WashAttrPointWin.itemModel = itemModel;
            // WindowCenter.Instance.Open<WashAttrPointWin>();
        }
        #region 红点逻辑判断
        const int ITEMPACK_REDKEY = 102011003;
        Redpoint redpointItemPack = new Redpoint(MainRedDot.RedPoint_BagFuncKey, ITEMPACK_REDKEY);
        const int LS_REDKEY = 102011015;
        Redpoint redpointLS = new Redpoint(MainRedDot.RedPoint_BagFuncKey, LS_REDKEY);
        private void UpdateLSRedpoint(PackType type, int itemID)
        {
            var singlePack = GetSinglePack(type);
            if (singlePack == null)
            {
                return;
            }
            if (type != PackType.Item) return;
            if (itemID != lsItemID) return;
            if (GetItemCountByID(PackType.Item, lsItemID) < lsItemCnt)
            {
                redpointLS.state = RedPointState.None;
            }
            else
            {
                redpointLS.state = RedPointState.Simple;
            }
        }
        private void UpdatePackRedpoint(PackType type)
        {
            var singlePack = GetSinglePack(type);
            if (singlePack == null)
            {
                return;
            }
            switch (type)
            {
                case PackType.Item:
                    if (singlePack.GetEmptyGridCount() <= 0)
                    {
                        redpointItemPack.state = RedPointState.Full;
                        //SysNotifyMgr.Instance.ShowTip("BagFull");
                    }
                    else
                    {
                        redpointItemPack.state = RedPointState.None;
                    }
                    if (GetItemCountByID(PackType.Item, lsItemID) < lsItemCnt)
                    {
                        redpointLS.state = RedPointState.None;
                    }
                    else
                    {
                        redpointLS.state = RedPointState.Simple;
                    }
                    break;
                case PackType.Warehouse:
                    if (singlePack.GetEmptyGridCount() <= 0)
                    {
                        MainRedDot.Instance.redPointDepotFunc.state = RedPointState.Full;
                    }
                    else
                    {
                        MainRedDot.Instance.redPointDepotFunc.state = RedPointState.None;
                    }
                    break;
            }
        }
        const int PLAYERSUMSTAR_REDKEY = 102011002;
        Redpoint redpointSTAR = new Redpoint(MainRedDot.RedPoint_BagFuncKey, PLAYERSUMSTAR_REDKEY);
        public const int EquipDecompose_RedKey = 10205;
        public Redpoint redpointEquipDecom = new Redpoint(MainRedDot.RedPoint_MainPackKey, EquipDecompose_RedKey);
        public void EquipDecomRedCtrl()
        {
            if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.EquipDecompose))
            {
                return;
            }
            if (PlayerDatas.Instance.baseData.LV < devourRedpointLevel)
            {
                redpointEquipDecom.state = RedPointState.None;
                return;
            }
            var canDevourItems = GetCanDevourModellist();
            if (canDevourItems != null && canDevourItems.Count >= minDevourEquipNum)
            {
                redpointEquipDecom.state = RedPointState.Simple;
            }
            else
            {
                redpointEquipDecom.state = RedPointState.None;
            }
        }
        #endregion
        #region 查看某个位置的物品
        public event Action lookEquipEvent;
        private int _lookLineIndex = -1;
        public int lookLineIndex { get { return _lookLineIndex; } private set { _lookLineIndex = value; } }
        public string lookItemGUID { get; private set; }
        public void SetLookIndex(string guid, int singleRowCount = 5)
        {
            if (string.IsNullOrEmpty(guid) || guid == "")
            {
                lookLineIndex = -1;
                lookItemGUID = "";
            }
            else
            {
                int index = GetItemByGuid(guid).gridIndex;
                lookLineIndex = index / singleRowCount;
                lookItemGUID = guid;
            }
            if (lookEquipEvent != null)
            {
                lookEquipEvent();
            }
        }
        public event Action RefreshBagEvent;
        public void RefreshBagInfo()
        {
            if (RefreshBagEvent != null)
            {
                RefreshBagEvent();
            }
        }
        #endregion
        public void SetJumpToOneKeySell(Transform parent)
        {
            // var goEffect = AchievementGuideEffectPool.Require(1);
            // goEffect.transform.SetParentEx(parent, Vector3.zero, Quaternion.identity, Vector3.one);
            // AchievementGoto.guideAchievementId = 0;
        }
        #region 物品使用快捷提示
        private int cacheMapId = 0;
        public event Action<PackType, string> itemUseAct;
        private Dictionary<int, int> itemUseTypeDict = new Dictionary<int, int>(); //key SkillTypeID,value 使用物品的ID
        private void OnStageLoadFinish()
        {
            // itemUseTypeDict.Clear();
            // if (PlayerDatas.Instance.baseData.MapID == cacheMapId)
            // {
            //     return;
            // }
            // cacheMapId = PlayerDatas.Instance.baseData.MapID;
            // UpdateDungeonDanUse();
            // UpdateDungeonUse();
            // SinglePack singlePack = GetSinglePack(PackType.Item);
            // foreach (int itemId in itemUseTypeDict.Values)
            // {
            //     var modellist = singlePack.GetItemsById(itemId);
            //     if (modellist.Count > 0)
            //     {
            //         ItemModel itemModel = modellist[0];
            //         bool isExist = StatusMgr.Instance.IsExist(PlayerDatas.Instance.hero.ServerInstID, itemModel.config.AddSkill1);
            //         Debug.Log("Buff是否存在" + isExist);
            //         if (itemUseAct != null && !isExist)
            //         {
            //             itemUseAct(PackType.Item, itemModel.guid);
            //         }
            //     }
            // }
        }
        private void AddItemUseTypeDict(int id)
        {
            SkillConfig skillConfig = GetSkillConfig(id);
            int itemCount = GetItemCountByID(PackType.Item, id);
            if (skillConfig != null && itemCount > 0)
            {
                if (!itemUseTypeDict.ContainsKey(skillConfig.SkillTypeID))
                {
                    itemUseTypeDict.Add(skillConfig.SkillTypeID, id);
                }
                else
                {
                    SkillConfig preSkillConfig = GetSkillConfig(itemUseTypeDict[skillConfig.SkillTypeID]);
                    if (skillConfig.SkillLV > preSkillConfig.SkillLV)
                    {
                        itemUseTypeDict[skillConfig.SkillTypeID] = id;
                    }
                }
            }
        }
        private void UpdateDungeonDanUse()
        {
            int mapId = PlayerDatas.Instance.baseData.MapID;
            int[] useDrugs = GetDrugIDListByDungeonID(mapId);
            if (useDrugs == null) return;
            for (int i = 0; i < useDrugs.Length; i++)
            {
                int id = useDrugs[i];
                AddItemUseTypeDict(id);
            }
        }
        private void UpdateDungeonUse()
        {
            int mapId = PlayerDatas.Instance.baseData.MapID;
            if (!dungeonUseDict.ContainsKey(mapId)) return;
            List<int> useIdlist = dungeonUseDict[mapId];
            for (int i = 0; i < useIdlist.Count; i++)
            {
                int id = useIdlist[i];
                AddItemUseTypeDict(id);
            }
        }
        public SkillConfig GetSkillConfig(int itemId)
        {
            ItemConfig itemConfig = ItemConfig.Get(itemId);
            SkillConfig skillConfig = SkillConfig.Get(itemConfig.AddSkill1);
            return skillConfig;
        }
        public int GetDungeonIDByDrugID(int drugID)
        {
            int dungeonID = 0;
            //DrugToDungeonDict.TryGetValue(drugID, out dungeonID);
            return dungeonID;
        }
        public int[] GetDrugIDListByDungeonID(int dungeonID)
        {
            int[] drugIDlist = null;
            DungeonToDrugDict.TryGetValue(dungeonID, out drugIDlist);
            return drugIDlist;
        }
        #endregion
        #region 判断物品是否达到使用上限
        // public bool IsReachUseLimit(string guid, out ulong count)
        // {
        //     count = 0;
        //     ItemModel itemModel = GetItemByGuid(guid);
        //     if (itemModel == null) return false;
        //     AttrFruitConfig fruitConfig = AttrFruitConfig.Get(itemModel.itemId);
        //     int haveUseCnt = GetItemUsedTimesToday(itemModel.itemId);
        //     int sumHaveUseCnt = GetItemTotalUsedTimes(itemModel.itemId);
        //     count = (ulong)itemModel.count;
        //     bool isReach = false;
        //     int remainDayCnt = 0;
        //     if (itemModel.config.MaxSkillCnt > 0)
        //     {
        //         remainDayCnt = itemModel.config.MaxSkillCnt - haveUseCnt;
        //         if (itemModel.count > remainDayCnt)
        //         {
        //             count = (ulong)remainDayCnt;
        //         }
        //     }
        //     int remainSumCnt = 0;
        //     if (fruitConfig != null)
        //     {
        //         remainSumCnt = fruitConfig.basicUseLimit - sumHaveUseCnt;
        //         if (remainSumCnt <= remainDayCnt && itemModel.count > remainSumCnt)
        //         {
        //             count = (ulong)remainSumCnt;
        //         }
        //     }
        //     if (count < (ulong)itemModel.count)
        //     {
        //         isReach = true;
        //     }
        //     return isReach;
        // }
        #endregion
        #region 物品吞噬逻辑处理
        public EquipColorType colorType { get; private set; }
        public event Action<EquipColorType> RefreshColorSelectAct;
        public event Action RefreshEquipDecomNumAct;
        public int[] defaultUnSelectlist { get; private set; }
        public int GetBetterEquipCount(List<ItemModel> itemModels)
        {
            if (itemModels.IsNullOrEmpty())
            {
                return 0;
            }
            var count = 0;
            foreach (var item in itemModels)
            {
                if (ItemLogicUtility.Instance.IsFightUp(item.itemId, item.score) == 1)
                {
                    count += item.count;
                }
            }
            return count;
        }
        public void SetColorSelect(EquipColorType type)
        {
            colorType = type;
            if (RefreshColorSelectAct != null)
            {
                RefreshColorSelectAct(type);
            }
            SendEquipDevourRecordQuest();
            EquipDecomRedCtrl();
        }
        public List<int> devourPlacelist { get; private set; }
        public int devourRedpointLevel { get; private set; }
        public int minDevourEquipNum { get; private set; }
        public void SetDevourEquipPlace()
        {
            devourPlacelist = new List<int>();
            FuncConfigConfig funcConfig = FuncConfigConfig.Get("PetAbsorbType");
            int[] placeArray = ConfigParse.GetMultipleStr<int>(funcConfig.Numerical1);
            for (int i = 0; i < placeArray.Length; i++)
            {
                devourPlacelist.Add(placeArray[i]);
            }
            devourRedpointLevel = int.Parse(funcConfig.Numerical2);
            minDevourEquipNum = int.Parse(funcConfig.Numerical3);
        }
        List<ItemModel> devourModellist = new List<ItemModel>();
        List<ItemModel> orderDevourModellist = new List<ItemModel>();
        public List<ItemModel> GetDevourModellist()
        {
            SinglePack singlePack = GetSinglePack(PackType.Item);
            if (singlePack == null) return null;
            devourModellist.Clear();
            orderDevourModellist.Clear();
            foreach (var model in singlePack.GetAllItems().Values)
            {
                if (model.config.Type == 29)
                {
                    devourModellist.Add(model);
                }
                else
                {
                    if (devourPlacelist.Contains(model.config.EquipPlace))
                    {
                        if (GeneralDefine.equipDecomposeScreen.Contains(model.config.ItemColor))
                        {
                            devourModellist.Add(model);
                        }
                    }
                }
            }
            orderDevourModellist.AddRange(devourModellist);
            orderDevourModellist.Sort(CompareByColor);
            return orderDevourModellist;
        }
        public int CompareByColor(ItemModel start, ItemModel next)
        {
            bool typeX = start.config.Type == 29 ? true : false;
            bool typeY = next.config.Type == 29 ? true : false;
            if (typeX.CompareTo(typeY) != 0) return -typeX.CompareTo(typeY);
            int colorX = start.config.ItemColor;
            int colorY = next.config.ItemColor;
            if (colorX.CompareTo(colorY) != 0) return colorX.CompareTo(colorY);
            int startIndex = devourModellist.IndexOf(start);
            int nextIndex = devourModellist.IndexOf(next);
            if (startIndex.CompareTo(nextIndex) != 0) return startIndex.CompareTo(nextIndex);
            return 0;
        }
        public List<ItemModel> GetCanDevourModellist()
        {
            List<ItemModel> canDevourModellist = new List<ItemModel>();
            SinglePack singlePack = GetSinglePack(PackType.Item);
            if (singlePack == null || colorType == EquipColorType.None)
            {
                if (RefreshEquipDecomNumAct != null)
                {
                    RefreshEquipDecomNumAct();
                }
                return null;
            }
            foreach (var model in singlePack.GetAllItems().Values)
            {
                if (model.config.Type == 29)
                {
                    if (!defaultUnSelectlist.Contains(model.itemId))
                    {
                        canDevourModellist.Add(model);
                    }
                }
                else
                {
                    if (IsCanDevour(model))
                    {
                        canDevourModellist.Add(model);
                    }
                }
            }
            if (RefreshEquipDecomNumAct != null)
            {
                RefreshEquipDecomNumAct();
            }
            return canDevourModellist;
        }
        public bool IsCanDevour(ItemModel model)
        {
            // if (devourPlacelist.Contains(model.config.EquipPlace))
            // {
            //     if (GeneralDefine.equipDecomposeScreen.Contains(model.config.ItemColor))
            //     {
            //         var eatEquipConfig = PetEatEquipConfig.GetEquipColorAndEquipClass(model.config.ItemColor, model.config.LV);
            //         if (eatEquipConfig == null) return false;
            //         if (EquipControlConfig.Get(model.config.LV, 1).realm > PlayerDatas.Instance.baseData.realmLevel)
            //         {
            //             //bug:玩家挂机会打高境界怪,导致装备无法分解背包太满的情况
            //             //境界大于玩家境界,且在指定颜色品质下的直接分解紫色以下装备
            //             if (model.config.ItemColor <= (int)colorType && model.config.ItemColor <= 3)
            //             {
            //                 return true;
            //             }
            //         }
            //         //1. 非拍卖装备
            //         //2. 装备品质小于等于当前选择的品质
            //         //3. 非本职业的套装装备
            //         //4. 非战斗力提升的装备
            //         if (!model.isAuction && model.config.ItemColor <= (int)colorType
            //             && !(ItemLogicUtility.Instance.IsJobCompatibleItem(model.itemId)
            //                     && model.config.ItemColor == 4 && model.config.SuiteiD != 0)
            //             && ItemLogicUtility.Instance.IsFightUp(model.itemId, model.score) != 1)
            //         {
            //             return true;
            //         }
            //     }
            // }
            return false;
        }
        public bool IsMaxDecomLv(int decomLv, out int realLv)
        {
            realLv = decomLv;
            // var decomlist = EquipDeComposeConfig.GetValues();
            // if (decomLv > decomlist[decomlist.Count - 1].LV)
            // {
            //     realLv = decomlist[decomlist.Count - 1].LV;
            //     return true;
            // }
            return false;
        }
        public List<ItemModel> selectDevourlist = new List<ItemModel>();
        public void GetSelectDevourList()
        {
            selectDevourlist.Clear();
            List<ItemModel> itemModels = GetCanDevourModellist();
            if (itemModels != null)
            {
                selectDevourlist.AddRange(itemModels);
            }
        }
        public void RefreshGetNewItem(ItemModel model)
        {
            if (model == null) return;
            if (CheckIsReachDevourCondi(model))
            {
                selectDevourlist.Add(model);
                if (RefreshEquipDecomNumAct != null)
                {
                    RefreshEquipDecomNumAct();
                }
            }
        }
        public void AddSelectDevourModellist(ItemModel model)
        {
            selectDevourlist.Add(model);
            if (RefreshEquipDecomNumAct != null)
            {
                RefreshEquipDecomNumAct();
            }
        }
        public bool CheckIsReachDevourCondi(ItemModel model)
        {
            if (model.config.Type == 29)
            {
                if (!defaultUnSelectlist.Contains(model.itemId))
                {
                    return true;
                }
                return false;
            }
            else
            {
                if (IsCanDevour(model))
                {
                    return true;
                }
            }
            return false;
        }
        public void RemoveSelectDevourModellist(ItemModel model)
        {
            if (selectDevourlist.Contains(model))
            {
                selectDevourlist.Remove(model);
            }
            if (RefreshEquipDecomNumAct != null)
            {
                RefreshEquipDecomNumAct();
            }
        }
        public Dictionary<int, int> GetDecomAttrDictByLv(int decomLv)
        {
            if (decomposeAttrDict.ContainsKey(decomLv))
            {
                return decomposeAttrDict[decomLv];
            }
            return null;
        }
        public bool IsReachMinDecomposeNum()
        {
            List<ItemModel> itemModels = GetCanDevourModellist();
            if (itemModels != null && itemModels.Count >= minDecomposeNum)
            {
                return true;
            }
            return false;
        }
        public void SendEquipdevourQuest(bool auto)
        {
            List<ItemModel> items = null;
            if (auto)
            {
                items = GetCanDevourModellist();
            }
            else
            {
                items = selectDevourlist;
            }
            // if (items == null || items.Count < minDecomposeNum || !ItemLogicUtility.Instance.isPackResetOk || SettingEffectMgr.Instance.isStartDecompose) return;
            // SettingEffectMgr.Instance.isStartDecompose = true;
            // isAutoDecompose = auto;
            // recordAutoDecomNum = Math.Min(items.Count, 100);    //单次最多100件分解
            // var package = new CA32C_tagCMEquipDecompose();
            // var indexLists = new ushort[recordAutoDecomNum];
            // var idlist = new uint[recordAutoDecomNum];
            // for (int i = 0; i < recordAutoDecomNum; i++)
            // {
            //     indexLists[i] = (ushort)items[i].gridIndex;
            //     idlist[i] = (uint)items[i].itemId;
            //     if ((items[i].config.EquipPlace == 0 && items[i].config.Type != 29))
            //     {
            //         return;
            //     }
            // }
            // package.Count = (byte)indexLists.Length;
            // package.IndexList = indexLists;
            // package.ItemIDList = idlist;
            // package.IsAuto = (byte)(auto ? 1 : 0);
            // GameNetSystem.Instance.SendInfo(package);
        }
        public void SendEquipDevourRecordQuest()
        {
            var record = StringUtility.Contact((int)colorType + 1, 1, 1);
            var decomSet = new CA32D_tagCMDecomposeSeting();
            decomSet.Seting = uint.Parse(record);
            GameNetSystem.Instance.SendInfo(decomSet);
        }
        public int decomposeLv { get; private set; }
        public int decomposeExp { get; private set; }
        public int decomposeProgress { get; private set; }
        public int addDecomposeExp { get; private set; }
        public int minDecomposeNum { get; private set; }
        public bool isAutoDecompose { get; set; }
        public int recordAutoDecomNum { get; private set; }
        public DecomposeGetMatInfo[] getItems { get; private set; }
        public event Action RefreshDecomAttrAct;
        // public void GetServerDecomposeSet(HA31C_tagMCEquipDecomposeInfo info)
        // {
        //     addDecomposeExp = 0;
        //     int realLv = info.LV + 1;
        //     bool isMax = IsMaxDecomLv(realLv, out realLv);
        //     if (realLv == decomposeLv)
        //     {
        //         addDecomposeExp = (int)info.Exp - decomposeExp;
        //     }
        //     else
        //     {
        //         for (int i = decomposeLv; i <= realLv; i++)
        //         {
        //             var deComposeConfig = EquipDeComposeConfig.Get(i);
        //             if (i == decomposeLv)
        //             {
        //                 addDecomposeExp = deComposeConfig.UpNeedExp - decomposeExp;
        //             }
        //             else if (i == realLv)
        //             {
        //                 addDecomposeExp += (int)info.Exp;
        //             }
        //             else
        //             {
        //                 addDecomposeExp += deComposeConfig.UpNeedExp;
        //             }
        //         }
        //     }
        //     decomposeLv = realLv;
        //     decomposeExp = (int)info.Exp;
        //     decomposeProgress = info.DecomposeCnt;
        //     getItems = JsonMapper.ToObject<DecomposeGetMatInfo[]>(info.GetItemData);
        //     if (info.Seting != 0)
        //     {
        //         string decomSetStr = info.Seting.ToString();
        //         string colorStr = decomSetStr.Substring(0, 1);
        //         colorType = (EquipColorType)(int.Parse(colorStr) - 1);
        //         string lvStr = decomSetStr.Substring(1, decomSetStr.Length - 2);
        //     }
        //     if (RefreshDecomAttrAct != null)
        //     {
        //         RefreshDecomAttrAct();
        //     }
        // }
        /// <summary>
        /// 设置获得炼丹材料的展示数据
        /// </summary>
        /// <param name="getMatInfos"></param>
        /// <returns></returns>
        private List<DecomposeGetMatInfo> getMatInfos = new List<DecomposeGetMatInfo>();
        public List<DecomposeGetMatInfo> SetShowMatInfo()
        {
            getMatInfos.Clear();
            int sumMatCnt = 0;
            if (getItems != null)
            {
                for (int i = 0; i < getItems.Length; i++)
                {
                    if (getItems[i].Count > 0)
                    {
                        sumMatCnt += getItems[i].Count;
                    }
                    else
                    {
                        sumMatCnt += 1;
                    }
                }
            }
            if (sumMatCnt > 5)
            {
                for (int i = 0; i < getItems.Length; i++)
                {
                    getMatInfos.Add(getItems[i]);
                }
            }
            else
            {
                if (getItems != null)
                {
                    for (int i = 0; i < getItems.Length; i++)
                    {
                        //if (getItems[i].Count > 0)
                        //{
                        //    for (int j = 0; j < getItems[i].Count; j++)
                        //    {
                        //        DecomposeGetMatInfo matInfo = new DecomposeGetMatInfo();
                        //        matInfo.ItemID = getItems[i].ItemID;
                        //        matInfo.Count = 1;
                        //        matInfo.IsSuite = getItems[i].IsSuite;
                        //        matInfo.UserData = getItems[i].UserData;
                        //        getMatInfos.Add(matInfo);
                        //    }
                        //}
                        //else
                        {
                            getMatInfos.Add(getItems[i]);
                        }
                    }
                }
            }
            return getMatInfos;
        }
        public enum EquipColorType
        {
            None = 0,
            White = 1,
            Blue = 2,
            Purple = 3,
            Orange = 4,
            Red = 5,
            //后续IL开发添加预设
            default1,
            default2,
            default3,
            default4,
            All = 10,
        }
        public class DecomposeGetMatInfo
        {
            public int ItemID;
            public int Count;
            public int IsSuite;
            public string UserData;
        }
        #endregion
        #region 丹药逻辑处理
        // private int CompareMakeDrug(AttrFruitConfig start, AttrFruitConfig end)
        // {
        //     ItemConfig configS = ItemConfig.Get(start.ID);
        //     ItemConfig configE = ItemConfig.Get(end.ID);
        //     if (configS.RealmLimit.CompareTo(configE.RealmLimit) != 0)
        //     {
        //         return configS.RealmLimit.CompareTo(configE.RealmLimit);
        //     }
        //     if (configS.LV.CompareTo(configE.LV) != 0)
        //     {
        //         return configS.LV.CompareTo(configE.LV);
        //     }
        //     int x = makeDruglist.IndexOf(start);
        //     int y = makeDruglist.IndexOf(end);
        //     if (x.CompareTo(y) != 0) x.CompareTo(y);
        //     return 0;
        // }
        // List<AttrFruitConfig> drugOrderlist = new List<AttrFruitConfig>();
        // List<AttrFruitConfig> haveDruglist = new List<AttrFruitConfig>();
        // public List<AttrFruitConfig> GetDrugOrderByCnt()
        // {
        //     drugOrderlist.Clear();
        //     haveDruglist.Clear();
        //     drugOrderlist.AddRange(makeDruglist);
        //     drugOrderlist.Sort(CompareByIsHave);
        //     for (int i = 0; i < drugOrderlist.Count; i++)
        //     {
        //         if (IsHaveDrugUse(drugOrderlist[i]))
        //         {
        //             haveDruglist.Add(drugOrderlist[i]);
        //         }
        //     }
        //     haveDruglist.Sort(CompareMakeDrug);
        //     for (int i = 0; i < haveDruglist.Count; i++)
        //     {
        //         drugOrderlist[i] = haveDruglist[i];
        //     }
        //     return drugOrderlist;
        // }
        public bool CheckIsDrugById(int itemId)
        {
            // for (int i = 0; i < makeDruglist.Count; i++)
            // {
            //     if (makeDruglist[i].ID == itemId)
            //     {
            //         return true;
            //     }
            // }
            return false;
        }
        // public int CompareByIsHave(AttrFruitConfig start, AttrFruitConfig end)
        // {
        //     bool isHaveStart = IsHaveDrugUse(start);
        //     bool isHaveEnd = IsHaveDrugUse(end);
        //     if (isHaveStart.CompareTo(isHaveEnd) != 0) return -isHaveStart.CompareTo(isHaveEnd);
        //     //isHaveStart = IsHaveDrugRecycle(start);
        //     //isHaveEnd = IsHaveDrugRecycle(end);
        //     //if (isHaveStart.CompareTo(isHaveEnd) != 0) return -isHaveStart.CompareTo(isHaveEnd);
        //     isHaveStart = GetItemCountByID(PackType.Item, start.ID) > 0 ? true : false;
        //     isHaveEnd = GetItemCountByID(PackType.Item, end.ID) > 0 ? true : false;
        //     if (isHaveStart.CompareTo(isHaveEnd) != 0) return isHaveStart.CompareTo(isHaveEnd);
        //     isHaveStart = IsReachMaxUseDrug(start);
        //     isHaveEnd = IsReachMaxUseDrug(end);
        //     if (isHaveStart.CompareTo(isHaveEnd) != 0) return isHaveStart.CompareTo(isHaveEnd);
        //     int x = makeDruglist.IndexOf(start);
        //     int y = makeDruglist.IndexOf(end);
        //     if (x.CompareTo(y) != 0) return x.CompareTo(y);
        //     return 0;
        // }
        // public bool IsHaveDrugUse(AttrFruitConfig fruitConfig)
        // {
        //     if (!IsReachMaxUseDrug(fruitConfig))
        //     {
        //         return GetItemCountByID(PackType.Item, fruitConfig.ID) > 0 ? true : false;
        //     }
        //     return false;
        // }
        // public bool IsHaveDrugRecycle(AttrFruitConfig fruitConfig)
        // {
        //     if (IsReachMaxUseDrug(fruitConfig))
        //     {
        //         return GetItemCountByID(PackType.Item, fruitConfig.ID) > 0 ? true : false;
        //     }
        //     return false;
        // }
        // public bool IsReachMaxUseDrug(AttrFruitConfig fruitConfig)
        // {
        //     if (fruitConfig == null)
        //     {
        //         return false;
        //     }
        //     if (fruitConfig.FuncID == 2)
        //     {
        //         AlchemyDrugUseLimit drugUseLimit;
        //         if (alchemyModel.TryGetAlchemyUseLimit(fruitConfig.ID, out drugUseLimit))
        //         {
        //             return drugUseLimit.IsReachLimit();
        //         }
        //     }
        //     int useNum = GetItemTotalUsedTimes(fruitConfig.ID);
        //     if (useNum >= fruitConfig.basicUseLimit)
        //     {
        //         return true;
        //     }
        //     return false;
        // }
        #endregion
        //获取背包中的一件可拍卖物品 优先其他职业
        public string GetAuctionEquip()
        {
            var itemPackage = GetSinglePack(PackType.Item);
            var allItems = itemPackage.GetAllItems();
            var guid = string.Empty;
            List<string> guidList = new List<string>();
            foreach (var item in allItems.Values)
            {
                var isAuction = item.isAuction;
                if (isAuction && ItemLogicUtility.Instance.IsRealmEquip(item.itemId))
                {
                    if (!ItemLogicUtility.Instance.IsJobCompatibleItem(item.itemId))
                    {
                        return item.guid;
                    }
                    else
                    {
                        if (guid != string.Empty)
                            continue;
                        guid = item.guid;
                    }
                }
            }
            return guid;
        }
        public void ReceiveAwardNotify(HA801_tagMCGiveAwardInfo netPack)
        {
            var eventName = UIHelper.ServerStringTrim(netPack.EventName);
            if (eventName == "BuyItem")
                return;
            // 仙盟攻城战
            // if (eventName == "FamilyGCZSQGrid" || eventName == "FamilyGCZSQPass" || eventName == "FamilyGCZSQPassAll" ||
            //     eventName == "FamilyGCZContiribution" || eventName == "FamilyGCZAtk")
            // {
            //     ModelCenter.Instance.GetModel<FairySiegeActModel>()?.OnUpdateAwardInfoAction(netPack);
            //     return;
            // }
            if (!commonShowAwardEvents.Contains(eventName))
                return;
            List<Item> showItems = new List<Item>();
            if (netPack.Exp != 0 || netPack.ExpPoint != 0)
            {
                ulong expValue = netPack.Exp + netPack.ExpPoint * (ulong)Constants.ExpPointValue;
                showItems.Add(new Item(GeneralDefine.expDisplayId, expValue));
            }
            if (netPack.MoneyList.Length != 0)
            {
                for (int i = 0; i < netPack.MoneyLen; i++)
                {
                    var moneyType = netPack.MoneyList[i].MoneyType;
                    if (GeneralDefine.moneyDisplayIds.ContainsKey(moneyType) && netPack.MoneyList[i].MoneyValue != 0)
                    {
                        showItems.Add(new Item(GeneralDefine.moneyDisplayIds[moneyType], netPack.MoneyList[i].MoneyValue));
                    }
                }
            }
            if (netPack.ItemList.Length != 0)
            {
                for (int i = 0; i < netPack.ItemLen; i++)
                {
                    showItems.Add(new Item((int)netPack.ItemList[i].ItemID, netPack.ItemList[i].Count, netPack.ItemList[i].IsBind));
                }
            }
            string info = string.Empty;
            if (LanguageConfig.HasKey("commonShowAwardEvents_" + eventName))
                info = Language.Get("commonShowAwardEvents_" + eventName);
            if (showItems.Count == 0)
                return;
            ItemLogicUtility.Instance.ShowGetItem(showItems, info, 0, eventName: eventName);
        }
    }
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using LitJson;
using System.Text.RegularExpressions;
using System.Collections;
    public class PackManager : GameSystemManager<PackManager>
    //public class PackModel : Model, IBeforePlayerDataInitialize, IAfterPlayerDataInitialize, IPlayerLoginOk
    {
        public static string StrengthAttrShift_RecordKey = "";
        public const string RecordKnapsackTitle = "RecordKnapsackTitle";
        Dictionary<int, int> DrugToDungeonDict { get; set; }   //key 丹药ID,value副本ID
        Dictionary<int, int[]> DungeonToDrugDict { get; set; }  //key 副本ID,value丹药ID列表
        //public List<AttrFruitConfig> makeDruglist { get; private set; }
        Dictionary<int, Dictionary<int, int>> decomposeAttrDict = new Dictionary<int, Dictionary<int, int>>();
        string RoleEquipLocalSave = "";
        List<int> LocalSavePlaceArray { get; set; }
        Dictionary<int, List<int>> sharedUseCountItemDict { get; set; }
        bool isUpdatePlayerLv = false;
        //AlchemyModel alchemyModel { get { return ModelCenter.Instance.GetModel<AlchemyModel>(); } }
        //ItemTipsModel itemTipsModel { get { return ModelCenter.Instance.GetModel<ItemTipsModel>(); } }
        public int lsItemID = 150; //可兑换的灵石物品ID
        int lsItemCnt = 0;
        List<string> commonShowAwardEvents = new List<string>();
        public int[] autoUseItemIDs;
        UIEffect lingshiEffect;  //灵石特效
        public override void Init()
        {
            DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitialize;
            DTC0102_tagCDBPlayer.afterPlayerDataInitializeEvent += OnAfterPlayerDataInitialize;
            DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent += OnPlayerLoginOk;
            ParseConfig();
            //SysNotifyMgr.Instance.sysNotifyEvent += RefreshSysInfo;
            // List<DungeonOpenTimeConfig> dungeonlist = DungeonOpenTimeConfig.GetValues();
            // if (dungeonlist != null)
            // {
            //     //DrugToDungeonDict = new Dictionary<int, int>();
            //     DungeonToDrugDict = new Dictionary<int, int[]>();
            //     for (int i = 0; i < dungeonlist.Count; i++)
            //     {
            //         int[] drugIdlist = dungeonlist[i].ElixirHint;
            //         if (drugIdlist != null && drugIdlist.Length > 0)
            //         {
            //             DungeonToDrugDict.Add(dungeonlist[i].DataMapID, drugIdlist);
            //             //for (int j = 0; j < drugIdlist.Length; j++)
            //             //{
            //             //    DrugToDungeonDict.Add(drugIdlist[j], dungeonlist[i].DataMapID);
            //             //}
            //         }
            //     }
            // }
            // makeDruglist = new List<AttrFruitConfig>();
            // List<AttrFruitConfig> fruitlist = AttrFruitConfig.GetValues();
            // for (int i = 0; i < fruitlist.Count; i++)
            // {
            //     if (fruitlist[i].FuncID == 2)
            //     {
            //         makeDruglist.Add(fruitlist[i]);
            //     }
            // }
            // StageLoad.Instance.onStageLoadFinish += OnStageLoadFinish;
            SetDevourEquipPlace();
            // decomposeAttrDict.Clear();
            // List<EquipDeComposeConfig> decomlist = EquipDeComposeConfig.GetValues();
            // for (int i = 0; i < decomlist.Count; i++)
            // {
            //     JsonData attrData = JsonMapper.ToObject(decomlist[i].Attr);
            //     Dictionary<int, int> attrDict = new Dictionary<int, int>();
            //     decomposeAttrDict.Add(decomlist[i].LV, attrDict);
            //     foreach (var id in attrData.Keys)
            //     {
            //         attrDict.Add(int.Parse(id), int.Parse(attrData[id].ToString()));
            //     }
            // }
            FuncConfigConfig equipDecompose = FuncConfigConfig.Get("EquipDevourCount");
            minDecomposeNum = int.Parse(equipDecompose.Numerical1);
            defaultUnSelectlist = ConfigParse.GetMultipleStr<int>(equipDecompose.Numerical2);
            FuncConfigConfig ShareUseCntItem = FuncConfigConfig.Get("ShareUseCntItem");
            sharedUseCountItemDict = new Dictionary<int, List<int>>();
            JsonData shareUseJson = JsonMapper.ToObject(ShareUseCntItem.Numerical1);
            if (shareUseJson.IsArray)
            {
                for (int i = 0; i < shareUseJson.Count; i++)
                {
                    var idListJson = shareUseJson[i];
                    var idlist = new List<int>();
                    sharedUseCountItemDict.Add(i, idlist);
                    foreach (var id in idListJson)
                    {
                        idlist.Add(int.Parse(id.ToString()));
                    }
                }
            }
            ParseItemCount();
            autoUseItemIDs = JsonMapper.ToObject<int[]>(FuncConfigConfig.Get("ItemTipsNum").Numerical2);
        }
        public override void Release()
        {
            DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitialize;
            DTC0102_tagCDBPlayer.afterPlayerDataInitializeEvent -= OnAfterPlayerDataInitialize;
            DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent -= OnPlayerLoginOk;
FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChangeEvent;
           // SysNotifyMgr.Instance.sysNotifyEvent -= RefreshSysInfo;
        }
        public Dictionary<int, string> textCountShow = new Dictionary<int, string>();
        public int[] textCountShow2;
        public List<int> gameCashShow = new List<int>();
        public void ParseItemCount()
        {
            var textConfig = FuncConfigConfig.Get("ItemCountShow");
            var json = JsonMapper.ToObject(textConfig.Numerical1);
            foreach (var key in json.Keys)
            {
                var itemID = int.Parse(key);
                textCountShow[itemID] = json[key].ToString();
            }
            textCountShow2 = JsonMapper.ToObject<int[]>(textConfig.Numerical2);
            gameCashShow = JsonMapper.ToObject<List<int>>(textConfig.Numerical3);
        }
        private void OnFuncStateChangeEvent(int id)
        {
            if (id == (int)FuncOpenEnum.EquipDecompose)
            {
                EquipDecomRedCtrl();
            }
        }
        public void OnBeforePlayerDataInitialize()
        {
            GlobalTimeEvent.Instance.secondEvent -= UpdateSecond;
            PlayerDatas.Instance.playerDataRefreshEvent -= UpdatePlayerLv;
            LocalSave.DeleteKey(RecordKnapsackTitle);
            cacheMapId = 0;
            playerPackDict.Clear();
            itemDayUseCntDict.Clear();
            itemSumUseCntDict.Clear();
            itemGUIDDict.Clear();
            isPlayBetterEquipEffect = false;
            colorType = EquipColorType.Orange;
            decomposeLv = 1;
            decomposeExp = 0;
            decomposeProgress = 0;
            isAutoDecompose = false;
        }
        public void OnAfterPlayerDataInitialize()
        {
        }
        public void OnPlayerLoginOk()
        {
            //ItemOperateUtility.Instance.RequestWarehouseData();
            EquipDecomRedCtrl();
            RoleEquipLocalSave = StringUtility.Contact("RoleEquipLocalSave", PlayerDatas.Instance.baseData.PlayerID);
            StrengthAttrShift_RecordKey = StringUtility.Contact(PlayerDatas.Instance.baseData.PlayerID, "StrengthAttrShift");
            if (LocalSave.GetIntArray(RoleEquipLocalSave) != null)
            {
                LocalSavePlaceArray = LocalSave.GetIntArray(RoleEquipLocalSave).ToList();
            }
            else
            {
                LocalSavePlaceArray = null;
            }
            GlobalTimeEvent.Instance.secondEvent += UpdateSecond;
            PlayerDatas.Instance.playerDataRefreshEvent += UpdatePlayerLv;
            isUpdatePlayerLv = true;
            FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent;
        }
        private void RefreshSysInfo(string key, ArrayList infolist)
        {
            // if (key != "GetMoney") return;
            // if (ItemLogicUtility.Instance.hidePickItem)
            //     return;
            // if (PlayerDatas.Instance.baseData.LV < 3)
            //     return;
            // var type = 0;
            // int.TryParse(infolist[0].ToString(), out type);
            // if (type == 1)
            // {
            //     Vector3 pos = new Vector3(-100, 0, 0);
            //     Vector3 rot = new Vector3(0, 0, 0);
            //     if (!WindowCenter.Instance.IsOpen<MainInterfaceWin>())
            //     {
            //         pos = new Vector3(0, 50, 0);
            //         rot = new Vector3(180, 180, 0);
            //     }
            //     EffectMgr.Instance.PlayUIEffect(1204, 3000, WindowCenter.Instance.uiRoot.tipsCanvas, pos, rot, false);
            // }
            // else if (type == 2)
            // {
            //     Vector3 pos = new Vector3(-100, 0, 0);
            //     Vector3 rot = new Vector3(0, 0, 0);
            //     if (!WindowCenter.Instance.IsOpen<MainInterfaceWin>())
            //     {
            //         pos = new Vector3(150, 50, 0);
            //         rot = new Vector3(180, 180, 0);
            //     }
            //     lingshiEffect = EffectMgr.Instance.PlayUIEffect(1158, 3000, WindowCenter.Instance.uiRoot.tipsCanvas, pos, rot, false);
            // }
        }
        public event Action<PackType> refrechPackEvent; //刷新整个背包数据
        public event Action<PackType, int, int> refreshItemCountEvent; // 慎用会卡(单个)最新物品数量刷新(旧的弃用)在得到新物品、物品数量的改变,清理该物品时均会触发 int 位置索引 int物品id
        public event Action<PackType> gridRefreshEvent; //背包空格刷新
        public event Action<PackType, int, int> itemCntAddEvent; //物品数量增加 int 位置索引 int物品id
        public event Action<PackType, int, int> itemCntReduceEvent; //物品数量减少的改变 int 位置索引 int物品id
        public event Action<int, int> useItemSuccessEvent; //物品使用成功 int 位置索引 int物品id
        public event Action<int> refreshItemDayUseCountEvent;  //刷新物品每日使用数量
        public event Action<int> refreshItemSumUseCountEvent;  //刷新物品总使用数量
        public bool isPlayBetterEquipEffect { get; set; }  //整理背包时是否播放特效
        #region 接收服务端数据
        private Dictionary<PackType, SinglePack> playerPackDict = new Dictionary<PackType, SinglePack>();
        private Dictionary<string, ItemModel> itemGUIDDict = new Dictionary<string, ItemModel>();
        public void UpdatePack(H0725_tagRolePackRefreshEx packInfo)
        {
            SetLookIndex(null);
            var packType = (PackType)packInfo.PackType;
            if (!playerPackDict.ContainsKey(packType))
            {
                playerPackDict.Add(packType, new SinglePack(packType));
            }
            if (isPlayBetterEquipEffect)
            {
                ItemLogicUtility.Instance.ClearSortedBetterEquip();
            }
            for (int i = 0; i < packInfo.ItemCount; i++)
            {
                var itemInfo = new ItemInfo(packInfo.ItemInfo[i]);
                var item = playerPackDict[packType].UpdateItem(itemInfo);
                AddItemGUIDDict(item, false);
                if (isPlayBetterEquipEffect)
                {
                    ItemLogicUtility.Instance.SetBagSortBetterEquipList(GetItemByGuid(itemInfo.guid));
                }
            }
            if (refrechPackEvent != null)
            {
                refrechPackEvent(packType);
            }
            UpdatePackRedpoint(packType);
        }
        public void UpdateItem(H0704_tagRolePackRefresh serverItem)
        {
            isPlayBetterEquipEffect = false;
            SetLookIndex(null);
            PackType type = (PackType)serverItem.PackType;
            if (!playerPackDict.ContainsKey(type))
            {
                playerPackDict.Add(type, new SinglePack(type));
            }
            var showNewItem = false;
            if (itemGUIDDict.ContainsKey(serverItem.ItemGUID))
            {
                var prePack = itemGUIDDict[serverItem.ItemGUID].packType;
                var preAuction = itemGUIDDict[serverItem.ItemGUID].isAuction;
                var nowPackType = type;
                var nowAcution = serverItem.IsBind == 1;
                showNewItem = preAuction != nowAcution || prePack != nowPackType;
            }
            else
            {
                showNewItem = true;
            }
            var itemInfo = new ItemInfo(serverItem);
            var item = playerPackDict[type].UpdateItem(itemInfo);
            AddItemGUIDDict(item, showNewItem);
            if (refreshItemCountEvent != null)
            {
                refreshItemCountEvent(type, itemInfo.index, itemInfo.itemId);
            }
            if (itemCntAddEvent != null)
            {
                itemCntAddEvent(type, itemInfo.index, itemInfo.itemId);
            }
            // if (type == PackType.Equip)
            // {
            //     if (ItemLogicUtility.Instance.IsRealmEquip(itemInfo.itemId))
            //     {
            //         ItemOperateUtility.Instance.ShowPutOnNewEquipRemind(itemInfo.itemId);
            //     }
            // }
            UpdatePackRedpoint(type);
            //EquipDecomRedCtrl();
            m_CheckEquipDecomRedCtrl = true;
            AutoUseItem(itemInfo.itemId, serverItem.ItemGUID);
        }
        bool m_CheckEquipDecomRedCtrl = false;
        void CheckEquipDecomRedCtrl()
        {
            if (m_CheckEquipDecomRedCtrl)
            {
                EquipDecomRedCtrl();
                m_CheckEquipDecomRedCtrl = false;
            }
        }
        public void UpdateUnlockedGridCount(H0724_tagRolePackCanUseCount useCount)
        {
            PackType type = (PackType)useCount.PackType;
            if (!playerPackDict.ContainsKey(type))
            {
                playerPackDict.Add(type, new SinglePack(type));
            }
            playerPackDict[type].SetOpenGridCount(useCount.CanUseCount);
            if (gridRefreshEvent != null)
            {
                gridRefreshEvent(type);
            }
            UpdatePackRedpoint(type);
        }
        public void RefreshItemCount(H0707_tagItemCountRefresh refresh)
        {
            SetLookIndex(null);
            isPlayBetterEquipEffect = false;
            PackType type = (PackType)refresh.PackType;
            SinglePack singlePack = null;
            playerPackDict.TryGetValue(type, out singlePack);
            if (singlePack != null)
            {
                ItemModel itemModel = singlePack.GetItemByIndex(refresh.ItemIndex);
                if (itemModel != null)
                {
                    bool isAddItemCount = false;
                    if (refresh.ItemCount > itemModel.count)
                    {
                        isAddItemCount = true;
                    }
                    itemModel.RefreshCount(refresh.ItemCount);
                    if (isAddItemCount)
                    {
                        if (itemCntAddEvent != null)
                        {
                            itemCntAddEvent(type, itemModel.gridIndex, itemModel.itemId);
                        }
                        ItemLogicUtility.Instance.RecommendItem(itemModel);
                        ItemLogicUtility.Instance.RefreshPickItem(type, itemModel.itemId.ToString());
                    }
                    else
                    {
                        if (itemCntReduceEvent != null)
                        {
                            itemCntReduceEvent(type, itemModel.gridIndex, itemModel.itemId);
                        }
                    }
                    if (refreshItemCountEvent != null)
                    {
                        refreshItemCountEvent(type, itemModel.gridIndex, itemModel.itemId);
                    }
                    UpdateLSRedpoint(type, itemModel.itemId);
                }
            }
        }
        public void ClearPack(H0711_tagClearItemPack clearPack)
        {
            PackType type = (PackType)clearPack.PackIndex;
            SinglePack singlePack = null;
            playerPackDict.TryGetValue(type, out singlePack);
            if (singlePack != null)
            {
                singlePack.Clear();
            }
        }
        public void RemoveItem(H0709_tagClearItem clearItem)
        {
            isPlayBetterEquipEffect = false;
            SetLookIndex(null);
            PackType type = (PackType)clearItem.PackType;
            SinglePack singlePack = null;
            playerPackDict.TryGetValue(type, out singlePack);
            string guid = "";
            if (singlePack != null)
            {
                ItemModel itemModel = singlePack.GetItemByIndex(clearItem.ItemIndex);
                guid = itemModel.guid;
                int itemId = itemModel.itemId;
                DeleteItemDictByGUID(type, itemModel.guid);
                singlePack.RemoveItem(clearItem.ItemIndex);
                if (refreshItemCountEvent != null)
                {
                    refreshItemCountEvent(type, clearItem.ItemIndex, itemId);
                }
                if (itemCntReduceEvent != null)
                {
                    itemCntReduceEvent(type, clearItem.ItemIndex, itemId);
                }
            }
            UpdatePackRedpoint(type);
            m_CheckEquipDecomRedCtrl = true;
            //EquipDecomRedCtrl();
            if (GetItemByGuid(guid) == null)
            {
                KnapsackTimeCDMgr.Instance.UnRegister(guid);
            }
        }
        public void PackResetOk(H0316_tagPackResetOK packreset)
        {
            ItemLogicUtility.Instance.isPackResetOk = true;
        }
        public void UseItemSuccess(H0706_tagUseItemSuccess success)
        {
            isPlayBetterEquipEffect = false;
            SetLookIndex(null);
            if (success.PlayerID != PlayerDatas.Instance.baseData.PlayerID)
            {
                return;
            }
            MakeUseItemSuccess(success.ItemIndex, (int)success.ItemID);
            switch (success.ItemID)
            {
                // case 221:
                //     if (WindowCenter.Instance.IsOpen<KnapSackWin>())
                //     {
                //         WindowCenter.Instance.Close<KnapSackWin>();
                //     }
                //     break;
            }
            if (useItemSuccessEvent != null)
            {
                useItemSuccessEvent(success.ItemIndex, (int)success.ItemID);
            }
        }
        void AutoUseItem(int itemID, string guid)
        {
            // if (autoUseItemIDs.Contains(itemID))
            // {
            //     ItemOperateUtility.Instance.GotoUseItem(guid);
            // }
        }
        private void MakeUseItemSuccess(int index, int id)
        {
            ItemConfig itemConfig = ItemConfig.Get(id);
            if (itemConfig.CDType != 0)
            {
                var items = GetItems(PackType.Item, new SinglePack.FilterParams()
                {
                    itemTypes = new List<int>() { (int)ItemType.Buff }
                });
                for (int i = 0; i < items.Count; i++)
                {
                    if (ItemLogicUtility.Instance.drugIDs.Contains(items[i].itemId))
                    {
                        itemConfig = ItemConfig.Get(items[i].itemId);
                        float configCdTime = (float)Math.Round((double)itemConfig.CDTime / 1000, 1);
                        KnapsackTimeCDMgr.Instance.Register(items[i].guid, items[i].itemId, configCdTime);
                    }
                }
            }
        }
        void AddItemGUIDDict(ItemModel itemModel, bool showNewItem)
        {
            itemGUIDDict[itemModel.guid] = itemModel;
            GetItemEventCtrl(itemModel, showNewItem);
        }
        void DeleteItemDictByGUID(PackType type, string guid)
        {
            if (itemGUIDDict.ContainsKey(guid))
            {
                if (itemGUIDDict[guid].packType == type)
                {
                    itemGUIDDict.Remove(guid);
                }
            }
        }
        /// <summary>
        /// 物品每日使用的次数
        /// </summary>
        private Dictionary<int, int> itemDayUseCntDict = new Dictionary<int, int>();
        public void UpdateItemUseCnt(HA809_tagMCItemDayUseCntInfo useCntInfo)
        {
            for (int i = 0; i < useCntInfo.Count; i++)
            {
                int itemId = (int)useCntInfo.ItemUseCntList[i].ItemID;
                int cnt = useCntInfo.ItemUseCntList[i].UseCnt;
                if (!itemDayUseCntDict.ContainsKey(itemId))
                {
                    itemDayUseCntDict.Add(itemId, cnt);
                }
                else
                {
                    itemDayUseCntDict[itemId] = cnt;
                }
                if (refreshItemDayUseCountEvent != null)
                {
                    refreshItemDayUseCountEvent(itemId);
                }
            }
        }
        private Dictionary<int, int> itemSumUseCntDict = new Dictionary<int, int>();
        // public void UpdateItemSumUseCnt(HA339_tagMCAttrFruitEatCntList useCntInfo)
        // {
        //     for (int i = 0; i < useCntInfo.count; i++)
        //     {
        //         int itemId = (int)useCntInfo.EatCntList[i].ItemID;
        //         int cnt = (int)useCntInfo.EatCntList[i].EatCnt;
        //         if (!itemSumUseCntDict.ContainsKey(itemId))
        //         {
        //             itemSumUseCntDict.Add(itemId, cnt);
        //         }
        //         else
        //         {
        //             itemSumUseCntDict[itemId] = cnt;
        //         }
        //         if (refreshItemSumUseCountEvent != null)
        //         {
        //             refreshItemSumUseCountEvent(itemId);
        //         }
        //     }
        // }
        #endregion
        #region 玩家装备特殊逻辑
        public Dictionary<int, Dictionary<int, int>> spiritWeaponPathIds { get; private set; }
        public Dictionary<int, int> wingsGetPathIdDict { get; private set; }
        public Dictionary<int, List<int>> dungeonUseDict { get; private set; }
        void ParseConfig()
        {
            FuncConfigConfig funcConfig = FuncConfigConfig.Get("WingYuPeiHQTJ");
            spiritWeaponPathIds = new Dictionary<int, Dictionary<int, int>>();
            var splits = funcConfig.Numerical3.Split('|');
            for (int i = 0; i < splits.Length; i++)
            {
                var tempString = splits[i];
                var matches = Regex.Matches(tempString.Trim(), "\\d+");
                var equipPlace = int.Parse(matches[0].Value);
                var job = int.Parse(matches[1].Value);
                var itemId = int.Parse(matches[2].Value);
                if (!spiritWeaponPathIds.ContainsKey(equipPlace))
                {
                    spiritWeaponPathIds[equipPlace] = new Dictionary<int, int>();
                }
                spiritWeaponPathIds[equipPlace][job] = itemId;
            }
            FuncConfigConfig copyItemBulletWindow = FuncConfigConfig.Get("CopyItemBulletWindow");
            JsonData copyWinData = JsonMapper.ToObject(copyItemBulletWindow.Numerical1);
            dungeonUseDict = new Dictionary<int, List<int>>();
            foreach (var dungeonId in copyWinData.Keys)
            {
                List<int> idlist = new List<int>();
                dungeonUseDict.Add(int.Parse(dungeonId), idlist);
                if (copyWinData[dungeonId].IsArray)
                {
                    JsonData useData = copyWinData[dungeonId];
                    for (int i = 0; i < useData.Count; i++)
                    {
                        idlist.Add(int.Parse(useData[i].ToString()));
                    }
                }
            }
            lsItemCnt = int.Parse(FuncConfigConfig.Get("LingshiShowCount").Numerical1);
            var config = FuncConfigConfig.Get("CommonShowAwards");
            commonShowAwardEvents = JsonMapper.ToObject<List<string>>(config.Numerical1);
        }
        public int GetRoleEquipPathId(int equipPlace)
        {
            int playerJob = PlayerDatas.Instance.baseData.Job;
            switch ((RoleEquipType)equipPlace)
            {
                case RoleEquipType.Guard:
                case RoleEquipType.PeerlessWeapon1:
                case RoleEquipType.PeerlessWeapon2:
                case RoleEquipType.Wing:
                    return spiritWeaponPathIds[equipPlace][playerJob];
                default:
                    return 0;
            }
        }
        private void UpdateSecond()
        {
            if (isUpdatePlayerLv)
            {
                isUpdatePlayerLv = false;
            }
            CheckEquipDecomRedCtrl();
        }
        private void UpdatePlayerLv(PlayerDataType type)
        {
            if (type != PlayerDataType.LV) return;
            isUpdatePlayerLv = true;
        }
        #endregion
        private void GetItemEventCtrl(ItemModel itemModel, bool showNewItem)
        {
            // if (showNewItem)
            // {
            //     bool isOverdue = false;
            //     if (itemModel.config.ExpireTime > 0)
            //     {
            //         ItemCDCool cool = KnapsackTimeCDMgr.Instance.GetItemCoolById(itemModel.guid);
            //         switch ((ItemTimeType)itemModel.config.EndureReduceType)
            //         {
            //             case ItemTimeType.EquipedTime:
            //                 List<int> itemEffectTime = itemModel.GetUseData((int)ItemUseDataKey.createTime);
            //                 if (itemEffectTime != null && itemEffectTime[0] != 0)
            //                 {
            //                     if (cool == null || cool.GetRemainTime() <= 0)
            //                     {
            //                         isOverdue = true;
            //                     }
            //                 }
            //                 break;
            //             case ItemTimeType.RealityTime:
            //                 if (cool == null || cool.GetRemainTime() <= 0)
            //                 {
            //                     isOverdue = true;
            //                 }
            //                 break;
            //         }
            //     }
            //     if (!isOverdue)
            //     {
            //         ItemLogicUtility.Instance.RecommendItem(itemModel);
            //         ItemLogicUtility.Instance.OnGetEquip(itemModel);
            //         ItemLogicUtility.Instance.RefreshPickItem(itemModel.packType, itemModel.itemId.ToString());
            //     }
            // }
        }
        /// <summary>
        /// 得到某个包裹的所有数据
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public SinglePack GetSinglePack(PackType type)
        {
            SinglePack singlePack = null;
            playerPackDict.TryGetValue(type, out singlePack);
            return singlePack;
        }
        public void UnLockPackGrid(int chooseGridCount, PackType type)
        {
            // var singlePack = GetSinglePack(type);
            // int openCount = chooseGridCount - singlePack.unlockedGridCount;
            // int index = 0;
            // switch (type)
            // {
            //     case PackType.Item:
            //         index = chooseGridCount - GeneralDefine.initBagGridCount;
            //         break;
            //     case PackType.Warehouse:
            //         index = chooseGridCount - GeneralDefine.initDepotGridCount;
            //         break;
            // }
            // itemTipsModel.SetExtendGirdModel(openCount, index, type);
            // WindowCenter.Instance.Open<ExtendWin>();
        }
        public ItemModel GetItemByGuid(string guid)
        {
            if (string.IsNullOrEmpty(guid))
            {
                return null;
            }
            ItemModel itemModel = null;
            itemGUIDDict.TryGetValue(guid, out itemModel);
            return itemModel;
        }
        public ItemModel GetItemByIndex(PackType type, int index)
        {
            ItemModel itemModel = null;
            if (playerPackDict.ContainsKey(type))
            {
                itemModel = playerPackDict[type].GetItemByIndex(index);
            }
            return itemModel;
        }
        /// <summary>
        /// 获取指定背包内 指定ID的所有物品
        /// </summary>
        /// <param name="type"></param>
        /// <param name="id"></param>
        /// <param name="includeAuction"></param>
        /// <returns></returns>
        public List<ItemModel> GetItemsById(PackType type, int id, bool includeAuction = true)
        {
            if (playerPackDict.ContainsKey(type))
            {
                var singlePack = playerPackDict[type];
                return singlePack.GetItemsById(id, includeAuction);
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 获取指定背包内指定ID的一个物品
        /// </summary>
        /// <param name="type"></param>
        /// <param name="id"></param>
        /// <param name="includeAuction"></param>
        /// <returns></returns>
        public ItemModel GetItemByID(PackType type, int id, bool includeAuction = true)
        {
            if (playerPackDict.ContainsKey(type))
            {
                var singlePack = playerPackDict[type];
                return singlePack.GetItemByID(id, includeAuction);
            }
            else
            {
                return null;
            }
        }
        public List<ItemModel> GetItems(PackType packType, SinglePack.FilterParams param)
        {
            if (playerPackDict.ContainsKey(packType))
            {
                return playerPackDict[packType].GetItems(param);
            }
            else
            {
                return null;
            }
        }
        //通过id找物品,注意检查是否指定背包
        public string GetItemGUIDByID(int itemId, bool includeAuction = true, PackType packType = PackType.Item)
        {
            string guid = string.Empty;
            foreach (var key in itemGUIDDict.Keys)
            {
                if (!includeAuction && itemGUIDDict[key].isAuction)
                {
                    continue;
                }
                if (itemGUIDDict[key].itemId == itemId && packType == itemGUIDDict[key].packType)
                {
                    guid = key;
                    return guid;
                }
            }
            return guid;
        }
        /// <summary>
        /// 得到ID相同的物品数量
        /// </summary>
        /// <param name="type"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public int GetItemCountByID(PackType type, int id, bool includeAuction = true)
        {
            int count = 0;
            var singlePack = GetSinglePack(type);
            if (singlePack != null)
            {
                count = singlePack.GetCountById(id, includeAuction);
            }
            return count;
        }
        public int GetEmptyGridCount(PackType type)
        {
            int count = 0;
            SinglePack singlePack = GetSinglePack(type);
            if (singlePack != null)
            {
                count = singlePack.GetEmptyGridCount();
            }
            return count;
        }
        public bool TryGetShareNumItem(int itemId, out List<int> idlist)
        {
            idlist = new List<int>();
            foreach (var list in sharedUseCountItemDict.Values)
            {
                if (list.Contains(itemId))
                {
                    idlist = list;
                    return true;
                }
            }
            return false;
        }
        /// <summary>
        /// 得到物品今日使用次数
        /// </summary>
        /// <param name="itemId"></param>
        /// <returns></returns>
        public int GetItemUsedTimesToday(int itemId)
        {
            int useCnt = 0;
            List<int> shareIdlist = null;
            bool isShare = TryGetShareNumItem(itemId, out shareIdlist);
            if (isShare)
            {
                foreach (var id in shareIdlist)
                {
                    int singleUseCnt = 0;
                    itemDayUseCntDict.TryGetValue(id, out singleUseCnt);
                    useCnt += singleUseCnt;
                }
            }
            else
            {
                itemDayUseCntDict.TryGetValue(itemId, out useCnt);
            }
            return useCnt;
        }
        /// <summary>
        /// 得到物品总使用次数
        /// </summary>
        /// <param name="itemId"></param>
        /// <returns></returns>
        public int GetItemTotalUsedTimes(int itemId)
        {
            int useCnt = 0;
            List<int> shareIdlist = null;
            bool isShare = TryGetShareNumItem(itemId, out shareIdlist);
            if (isShare)
            {
                foreach (var id in shareIdlist)
                {
                    int singleUseCnt = 0;
                    itemDayUseCntDict.TryGetValue(id, out singleUseCnt);
                    useCnt += singleUseCnt;
                }
            }
            else
            {
                itemSumUseCntDict.TryGetValue(itemId, out useCnt);
            }
            return useCnt;
        }
        public void GotoWashAttributePoint(string guid)
        {
            // ItemModel itemModel = GetItemByGuid(guid);
            // if (itemModel == null) return;
            // WashAttrPointWin.itemModel = itemModel;
            // WindowCenter.Instance.Open<WashAttrPointWin>();
        }
        #region 红点逻辑判断
        const int ITEMPACK_REDKEY = 102011003;
        Redpoint redpointItemPack = new Redpoint(MainRedDot.RedPoint_BagFuncKey, ITEMPACK_REDKEY);
        const int LS_REDKEY = 102011015;
        Redpoint redpointLS = new Redpoint(MainRedDot.RedPoint_BagFuncKey, LS_REDKEY);
        private void UpdateLSRedpoint(PackType type, int itemID)
        {
            var singlePack = GetSinglePack(type);
            if (singlePack == null)
            {
                return;
            }
            if (type != PackType.Item) return;
            if (itemID != lsItemID) return;
            if (GetItemCountByID(PackType.Item, lsItemID) < lsItemCnt)
            {
                redpointLS.state = RedPointState.None;
            }
            else
            {
                redpointLS.state = RedPointState.Simple;
            }
        }
        private void UpdatePackRedpoint(PackType type)
        {
            var singlePack = GetSinglePack(type);
            if (singlePack == null)
            {
                return;
            }
            switch (type)
            {
                case PackType.Item:
                    if (singlePack.GetEmptyGridCount() <= 0)
                    {
                        redpointItemPack.state = RedPointState.Full;
                        //SysNotifyMgr.Instance.ShowTip("BagFull");
                    }
                    else
                    {
                        redpointItemPack.state = RedPointState.None;
                    }
                    if (GetItemCountByID(PackType.Item, lsItemID) < lsItemCnt)
                    {
                        redpointLS.state = RedPointState.None;
                    }
                    else
                    {
                        redpointLS.state = RedPointState.Simple;
                    }
                    break;
                case PackType.Warehouse:
                    if (singlePack.GetEmptyGridCount() <= 0)
                    {
                        MainRedDot.Instance.redPointDepotFunc.state = RedPointState.Full;
                    }
                    else
                    {
                        MainRedDot.Instance.redPointDepotFunc.state = RedPointState.None;
                    }
                    break;
            }
        }
        const int PLAYERSUMSTAR_REDKEY = 102011002;
        Redpoint redpointSTAR = new Redpoint(MainRedDot.RedPoint_BagFuncKey, PLAYERSUMSTAR_REDKEY);
        public const int EquipDecompose_RedKey = 10205;
        public Redpoint redpointEquipDecom = new Redpoint(MainRedDot.RedPoint_MainPackKey, EquipDecompose_RedKey);
        public void EquipDecomRedCtrl()
        {
            if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.EquipDecompose))
            {
                return;
            }
            if (PlayerDatas.Instance.baseData.LV < devourRedpointLevel)
            {
                redpointEquipDecom.state = RedPointState.None;
                return;
            }
            var canDevourItems = GetCanDevourModellist();
            if (canDevourItems != null && canDevourItems.Count >= minDevourEquipNum)
            {
                redpointEquipDecom.state = RedPointState.Simple;
            }
            else
            {
                redpointEquipDecom.state = RedPointState.None;
            }
        }
        #endregion
        #region 查看某个位置的物品
        public event Action lookEquipEvent;
        private int _lookLineIndex = -1;
        public int lookLineIndex { get { return _lookLineIndex; } private set { _lookLineIndex = value; } }
        public string lookItemGUID { get; private set; }
        public void SetLookIndex(string guid, int singleRowCount = 5)
        {
            if (string.IsNullOrEmpty(guid) || guid == "")
            {
                lookLineIndex = -1;
                lookItemGUID = "";
            }
            else
            {
                int index = GetItemByGuid(guid).gridIndex;
                lookLineIndex = index / singleRowCount;
                lookItemGUID = guid;
            }
            if (lookEquipEvent != null)
            {
                lookEquipEvent();
            }
        }
        public event Action RefreshBagEvent;
        public void RefreshBagInfo()
        {
            if (RefreshBagEvent != null)
            {
                RefreshBagEvent();
            }
        }
        #endregion
        public void SetJumpToOneKeySell(Transform parent)
        {
            // var goEffect = AchievementGuideEffectPool.Require(1);
            // goEffect.transform.SetParentEx(parent, Vector3.zero, Quaternion.identity, Vector3.one);
            // AchievementGoto.guideAchievementId = 0;
        }
        #region 物品使用快捷提示
        private int cacheMapId = 0;
        public event Action<PackType, string> itemUseAct;
        private Dictionary<int, int> itemUseTypeDict = new Dictionary<int, int>(); //key SkillTypeID,value 使用物品的ID
        private void OnStageLoadFinish()
        {
            // itemUseTypeDict.Clear();
            // if (PlayerDatas.Instance.baseData.MapID == cacheMapId)
            // {
            //     return;
            // }
            // cacheMapId = PlayerDatas.Instance.baseData.MapID;
            // UpdateDungeonDanUse();
            // UpdateDungeonUse();
            // SinglePack singlePack = GetSinglePack(PackType.Item);
            // foreach (int itemId in itemUseTypeDict.Values)
            // {
            //     var modellist = singlePack.GetItemsById(itemId);
            //     if (modellist.Count > 0)
            //     {
            //         ItemModel itemModel = modellist[0];
            //         bool isExist = StatusMgr.Instance.IsExist(PlayerDatas.Instance.hero.ServerInstID, itemModel.config.AddSkill1);
            //         Debug.Log("Buff是否存在" + isExist);
            //         if (itemUseAct != null && !isExist)
            //         {
            //             itemUseAct(PackType.Item, itemModel.guid);
            //         }
            //     }
            // }
        }
        private void AddItemUseTypeDict(int id)
        {
            SkillConfig skillConfig = GetSkillConfig(id);
            int itemCount = GetItemCountByID(PackType.Item, id);
            if (skillConfig != null && itemCount > 0)
            {
                if (!itemUseTypeDict.ContainsKey(skillConfig.SkillTypeID))
                {
                    itemUseTypeDict.Add(skillConfig.SkillTypeID, id);
                }
                else
                {
                    SkillConfig preSkillConfig = GetSkillConfig(itemUseTypeDict[skillConfig.SkillTypeID]);
                    if (skillConfig.SkillLV > preSkillConfig.SkillLV)
                    {
                        itemUseTypeDict[skillConfig.SkillTypeID] = id;
                    }
                }
            }
        }
        private void UpdateDungeonDanUse()
        {
            int mapId = PlayerDatas.Instance.baseData.MapID;
            int[] useDrugs = GetDrugIDListByDungeonID(mapId);
            if (useDrugs == null) return;
            for (int i = 0; i < useDrugs.Length; i++)
            {
                int id = useDrugs[i];
                AddItemUseTypeDict(id);
            }
        }
        private void UpdateDungeonUse()
        {
            int mapId = PlayerDatas.Instance.baseData.MapID;
            if (!dungeonUseDict.ContainsKey(mapId)) return;
            List<int> useIdlist = dungeonUseDict[mapId];
            for (int i = 0; i < useIdlist.Count; i++)
            {
                int id = useIdlist[i];
                AddItemUseTypeDict(id);
            }
        }
        public SkillConfig GetSkillConfig(int itemId)
        {
            ItemConfig itemConfig = ItemConfig.Get(itemId);
            SkillConfig skillConfig = SkillConfig.Get(itemConfig.AddSkill1);
            return skillConfig;
        }
        public int GetDungeonIDByDrugID(int drugID)
        {
            int dungeonID = 0;
            //DrugToDungeonDict.TryGetValue(drugID, out dungeonID);
            return dungeonID;
        }
        public int[] GetDrugIDListByDungeonID(int dungeonID)
        {
            int[] drugIDlist = null;
            DungeonToDrugDict.TryGetValue(dungeonID, out drugIDlist);
            return drugIDlist;
        }
        #endregion
        #region 判断物品是否达到使用上限
        // public bool IsReachUseLimit(string guid, out ulong count)
        // {
        //     count = 0;
        //     ItemModel itemModel = GetItemByGuid(guid);
        //     if (itemModel == null) return false;
        //     AttrFruitConfig fruitConfig = AttrFruitConfig.Get(itemModel.itemId);
        //     int haveUseCnt = GetItemUsedTimesToday(itemModel.itemId);
        //     int sumHaveUseCnt = GetItemTotalUsedTimes(itemModel.itemId);
        //     count = (ulong)itemModel.count;
        //     bool isReach = false;
        //     int remainDayCnt = 0;
        //     if (itemModel.config.MaxSkillCnt > 0)
        //     {
        //         remainDayCnt = itemModel.config.MaxSkillCnt - haveUseCnt;
        //         if (itemModel.count > remainDayCnt)
        //         {
        //             count = (ulong)remainDayCnt;
        //         }
        //     }
        //     int remainSumCnt = 0;
        //     if (fruitConfig != null)
        //     {
        //         remainSumCnt = fruitConfig.basicUseLimit - sumHaveUseCnt;
        //         if (remainSumCnt <= remainDayCnt && itemModel.count > remainSumCnt)
        //         {
        //             count = (ulong)remainSumCnt;
        //         }
        //     }
        //     if (count < (ulong)itemModel.count)
        //     {
        //         isReach = true;
        //     }
        //     return isReach;
        // }
        #endregion
        #region 物品吞噬逻辑处理
        public EquipColorType colorType { get; private set; }
        public event Action<EquipColorType> RefreshColorSelectAct;
        public event Action RefreshEquipDecomNumAct;
        public int[] defaultUnSelectlist { get; private set; }
        public int GetBetterEquipCount(List<ItemModel> itemModels)
        {
            if (itemModels.IsNullOrEmpty())
            {
                return 0;
            }
            var count = 0;
            foreach (var item in itemModels)
            {
                if (ItemLogicUtility.Instance.IsFightUp(item.itemId, item.score) == 1)
                {
                    count += item.count;
                }
            }
            return count;
        }
        public void SetColorSelect(EquipColorType type)
        {
            colorType = type;
            if (RefreshColorSelectAct != null)
            {
                RefreshColorSelectAct(type);
            }
            SendEquipDevourRecordQuest();
            EquipDecomRedCtrl();
        }
        public List<int> devourPlacelist { get; private set; }
        public int devourRedpointLevel { get; private set; }
        public int minDevourEquipNum { get; private set; }
        public void SetDevourEquipPlace()
        {
            devourPlacelist = new List<int>();
            FuncConfigConfig funcConfig = FuncConfigConfig.Get("PetAbsorbType");
            int[] placeArray = ConfigParse.GetMultipleStr<int>(funcConfig.Numerical1);
            for (int i = 0; i < placeArray.Length; i++)
            {
                devourPlacelist.Add(placeArray[i]);
            }
            devourRedpointLevel = int.Parse(funcConfig.Numerical2);
            minDevourEquipNum = int.Parse(funcConfig.Numerical3);
        }
        List<ItemModel> devourModellist = new List<ItemModel>();
        List<ItemModel> orderDevourModellist = new List<ItemModel>();
        public List<ItemModel> GetDevourModellist()
        {
            SinglePack singlePack = GetSinglePack(PackType.Item);
            if (singlePack == null) return null;
            devourModellist.Clear();
            orderDevourModellist.Clear();
            foreach (var model in singlePack.GetAllItems().Values)
            {
                if (model.config.Type == 29)
                {
                    devourModellist.Add(model);
                }
                else
                {
                    if (devourPlacelist.Contains(model.config.EquipPlace))
                    {
                        if (GeneralDefine.equipDecomposeScreen.Contains(model.config.ItemColor))
                        {
                            devourModellist.Add(model);
                        }
                    }
                }
            }
            orderDevourModellist.AddRange(devourModellist);
            orderDevourModellist.Sort(CompareByColor);
            return orderDevourModellist;
        }
        public int CompareByColor(ItemModel start, ItemModel next)
        {
            bool typeX = start.config.Type == 29 ? true : false;
            bool typeY = next.config.Type == 29 ? true : false;
            if (typeX.CompareTo(typeY) != 0) return -typeX.CompareTo(typeY);
            int colorX = start.config.ItemColor;
            int colorY = next.config.ItemColor;
            if (colorX.CompareTo(colorY) != 0) return colorX.CompareTo(colorY);
            int startIndex = devourModellist.IndexOf(start);
            int nextIndex = devourModellist.IndexOf(next);
            if (startIndex.CompareTo(nextIndex) != 0) return startIndex.CompareTo(nextIndex);
            return 0;
        }
        public List<ItemModel> GetCanDevourModellist()
        {
            List<ItemModel> canDevourModellist = new List<ItemModel>();
            SinglePack singlePack = GetSinglePack(PackType.Item);
            if (singlePack == null || colorType == EquipColorType.None)
            {
                if (RefreshEquipDecomNumAct != null)
                {
                    RefreshEquipDecomNumAct();
                }
                return null;
            }
            foreach (var model in singlePack.GetAllItems().Values)
            {
                if (model.config.Type == 29)
                {
                    if (!defaultUnSelectlist.Contains(model.itemId))
                    {
                        canDevourModellist.Add(model);
                    }
                }
                else
                {
                    if (IsCanDevour(model))
                    {
                        canDevourModellist.Add(model);
                    }
                }
            }
            if (RefreshEquipDecomNumAct != null)
            {
                RefreshEquipDecomNumAct();
            }
            return canDevourModellist;
        }
        public bool IsCanDevour(ItemModel model)
        {
            // if (devourPlacelist.Contains(model.config.EquipPlace))
            // {
            //     if (GeneralDefine.equipDecomposeScreen.Contains(model.config.ItemColor))
            //     {
            //         var eatEquipConfig = PetEatEquipConfig.GetEquipColorAndEquipClass(model.config.ItemColor, model.config.LV);
            //         if (eatEquipConfig == null) return false;
            //         if (EquipControlConfig.Get(model.config.LV, 1).realm > PlayerDatas.Instance.baseData.realmLevel)
            //         {
            //             //bug:玩家挂机会打高境界怪,导致装备无法分解背包太满的情况
            //             //境界大于玩家境界,且在指定颜色品质下的直接分解紫色以下装备
            //             if (model.config.ItemColor <= (int)colorType && model.config.ItemColor <= 3)
            //             {
            //                 return true;
            //             }
            //         }
            //         //1. 非拍卖装备
            //         //2. 装备品质小于等于当前选择的品质
            //         //3. 非本职业的套装装备
            //         //4. 非战斗力提升的装备
            //         if (!model.isAuction && model.config.ItemColor <= (int)colorType
            //             && !(ItemLogicUtility.Instance.IsJobCompatibleItem(model.itemId)
            //                     && model.config.ItemColor == 4 && model.config.SuiteiD != 0)
            //             && ItemLogicUtility.Instance.IsFightUp(model.itemId, model.score) != 1)
            //         {
            //             return true;
            //         }
            //     }
            // }
            return false;
        }
        public bool IsMaxDecomLv(int decomLv, out int realLv)
        {
            realLv = decomLv;
            // var decomlist = EquipDeComposeConfig.GetValues();
            // if (decomLv > decomlist[decomlist.Count - 1].LV)
            // {
            //     realLv = decomlist[decomlist.Count - 1].LV;
            //     return true;
            // }
            return false;
        }
        public List<ItemModel> selectDevourlist = new List<ItemModel>();
        public void GetSelectDevourList()
        {
            selectDevourlist.Clear();
            List<ItemModel> itemModels = GetCanDevourModellist();
            if (itemModels != null)
            {
                selectDevourlist.AddRange(itemModels);
            }
        }
        public void RefreshGetNewItem(ItemModel model)
        {
            if (model == null) return;
            if (CheckIsReachDevourCondi(model))
            {
                selectDevourlist.Add(model);
                if (RefreshEquipDecomNumAct != null)
                {
                    RefreshEquipDecomNumAct();
                }
            }
        }
        public void AddSelectDevourModellist(ItemModel model)
        {
            selectDevourlist.Add(model);
            if (RefreshEquipDecomNumAct != null)
            {
                RefreshEquipDecomNumAct();
            }
        }
        public bool CheckIsReachDevourCondi(ItemModel model)
        {
            if (model.config.Type == 29)
            {
                if (!defaultUnSelectlist.Contains(model.itemId))
                {
                    return true;
                }
                return false;
            }
            else
            {
                if (IsCanDevour(model))
                {
                    return true;
                }
            }
            return false;
        }
        public void RemoveSelectDevourModellist(ItemModel model)
        {
            if (selectDevourlist.Contains(model))
            {
                selectDevourlist.Remove(model);
            }
            if (RefreshEquipDecomNumAct != null)
            {
                RefreshEquipDecomNumAct();
            }
        }
        public Dictionary<int, int> GetDecomAttrDictByLv(int decomLv)
        {
            if (decomposeAttrDict.ContainsKey(decomLv))
            {
                return decomposeAttrDict[decomLv];
            }
            return null;
        }
        public bool IsReachMinDecomposeNum()
        {
            List<ItemModel> itemModels = GetCanDevourModellist();
            if (itemModels != null && itemModels.Count >= minDecomposeNum)
            {
                return true;
            }
            return false;
        }
        public void SendEquipdevourQuest(bool auto)
        {
            List<ItemModel> items = null;
            if (auto)
            {
                items = GetCanDevourModellist();
            }
            else
            {
                items = selectDevourlist;
            }
            // if (items == null || items.Count < minDecomposeNum || !ItemLogicUtility.Instance.isPackResetOk || SettingEffectMgr.Instance.isStartDecompose) return;
            // SettingEffectMgr.Instance.isStartDecompose = true;
            // isAutoDecompose = auto;
            // recordAutoDecomNum = Math.Min(items.Count, 100);    //单次最多100件分解
            // var package = new CA32C_tagCMEquipDecompose();
            // var indexLists = new ushort[recordAutoDecomNum];
            // var idlist = new uint[recordAutoDecomNum];
            // for (int i = 0; i < recordAutoDecomNum; i++)
            // {
            //     indexLists[i] = (ushort)items[i].gridIndex;
            //     idlist[i] = (uint)items[i].itemId;
            //     if ((items[i].config.EquipPlace == 0 && items[i].config.Type != 29))
            //     {
            //         return;
            //     }
            // }
            // package.Count = (byte)indexLists.Length;
            // package.IndexList = indexLists;
            // package.ItemIDList = idlist;
            // package.IsAuto = (byte)(auto ? 1 : 0);
            // GameNetSystem.Instance.SendInfo(package);
        }
        public void SendEquipDevourRecordQuest()
        {
            var record = StringUtility.Contact((int)colorType + 1, 1, 1);
            var decomSet = new CA32D_tagCMDecomposeSeting();
            decomSet.Seting = uint.Parse(record);
            GameNetSystem.Instance.SendInfo(decomSet);
        }
        public int decomposeLv { get; private set; }
        public int decomposeExp { get; private set; }
        public int decomposeProgress { get; private set; }
        public int addDecomposeExp { get; private set; }
        public int minDecomposeNum { get; private set; }
        public bool isAutoDecompose { get; set; }
        public int recordAutoDecomNum { get; private set; }
        public DecomposeGetMatInfo[] getItems { get; private set; }
        public event Action RefreshDecomAttrAct;
        // public void GetServerDecomposeSet(HA31C_tagMCEquipDecomposeInfo info)
        // {
        //     addDecomposeExp = 0;
        //     int realLv = info.LV + 1;
        //     bool isMax = IsMaxDecomLv(realLv, out realLv);
        //     if (realLv == decomposeLv)
        //     {
        //         addDecomposeExp = (int)info.Exp - decomposeExp;
        //     }
        //     else
        //     {
        //         for (int i = decomposeLv; i <= realLv; i++)
        //         {
        //             var deComposeConfig = EquipDeComposeConfig.Get(i);
        //             if (i == decomposeLv)
        //             {
        //                 addDecomposeExp = deComposeConfig.UpNeedExp - decomposeExp;
        //             }
        //             else if (i == realLv)
        //             {
        //                 addDecomposeExp += (int)info.Exp;
        //             }
        //             else
        //             {
        //                 addDecomposeExp += deComposeConfig.UpNeedExp;
        //             }
        //         }
        //     }
        //     decomposeLv = realLv;
        //     decomposeExp = (int)info.Exp;
        //     decomposeProgress = info.DecomposeCnt;
        //     getItems = JsonMapper.ToObject<DecomposeGetMatInfo[]>(info.GetItemData);
        //     if (info.Seting != 0)
        //     {
        //         string decomSetStr = info.Seting.ToString();
        //         string colorStr = decomSetStr.Substring(0, 1);
        //         colorType = (EquipColorType)(int.Parse(colorStr) - 1);
        //         string lvStr = decomSetStr.Substring(1, decomSetStr.Length - 2);
        //     }
        //     if (RefreshDecomAttrAct != null)
        //     {
        //         RefreshDecomAttrAct();
        //     }
        // }
        /// <summary>
        /// 设置获得炼丹材料的展示数据
        /// </summary>
        /// <param name="getMatInfos"></param>
        /// <returns></returns>
        private List<DecomposeGetMatInfo> getMatInfos = new List<DecomposeGetMatInfo>();
        public List<DecomposeGetMatInfo> SetShowMatInfo()
        {
            getMatInfos.Clear();
            int sumMatCnt = 0;
            if (getItems != null)
            {
                for (int i = 0; i < getItems.Length; i++)
                {
                    if (getItems[i].Count > 0)
                    {
                        sumMatCnt += getItems[i].Count;
                    }
                    else
                    {
                        sumMatCnt += 1;
                    }
                }
            }
            if (sumMatCnt > 5)
            {
                for (int i = 0; i < getItems.Length; i++)
                {
                    getMatInfos.Add(getItems[i]);
                }
            }
            else
            {
                if (getItems != null)
                {
                    for (int i = 0; i < getItems.Length; i++)
                    {
                        //if (getItems[i].Count > 0)
                        //{
                        //    for (int j = 0; j < getItems[i].Count; j++)
                        //    {
                        //        DecomposeGetMatInfo matInfo = new DecomposeGetMatInfo();
                        //        matInfo.ItemID = getItems[i].ItemID;
                        //        matInfo.Count = 1;
                        //        matInfo.IsSuite = getItems[i].IsSuite;
                        //        matInfo.UserData = getItems[i].UserData;
                        //        getMatInfos.Add(matInfo);
                        //    }
                        //}
                        //else
                        {
                            getMatInfos.Add(getItems[i]);
                        }
                    }
                }
            }
            return getMatInfos;
        }
        public enum EquipColorType
        {
            None = 0,
            White = 1,
            Blue = 2,
            Purple = 3,
            Orange = 4,
            Red = 5,
            //后续IL开发添加预设
            default1,
            default2,
            default3,
            default4,
            All = 10,
        }
        public class DecomposeGetMatInfo
        {
            public int ItemID;
            public int Count;
            public int IsSuite;
            public string UserData;
        }
        #endregion
        #region 丹药逻辑处理
        // private int CompareMakeDrug(AttrFruitConfig start, AttrFruitConfig end)
        // {
        //     ItemConfig configS = ItemConfig.Get(start.ID);
        //     ItemConfig configE = ItemConfig.Get(end.ID);
        //     if (configS.RealmLimit.CompareTo(configE.RealmLimit) != 0)
        //     {
        //         return configS.RealmLimit.CompareTo(configE.RealmLimit);
        //     }
        //     if (configS.LV.CompareTo(configE.LV) != 0)
        //     {
        //         return configS.LV.CompareTo(configE.LV);
        //     }
        //     int x = makeDruglist.IndexOf(start);
        //     int y = makeDruglist.IndexOf(end);
        //     if (x.CompareTo(y) != 0) x.CompareTo(y);
        //     return 0;
        // }
        // List<AttrFruitConfig> drugOrderlist = new List<AttrFruitConfig>();
        // List<AttrFruitConfig> haveDruglist = new List<AttrFruitConfig>();
        // public List<AttrFruitConfig> GetDrugOrderByCnt()
        // {
        //     drugOrderlist.Clear();
        //     haveDruglist.Clear();
        //     drugOrderlist.AddRange(makeDruglist);
        //     drugOrderlist.Sort(CompareByIsHave);
        //     for (int i = 0; i < drugOrderlist.Count; i++)
        //     {
        //         if (IsHaveDrugUse(drugOrderlist[i]))
        //         {
        //             haveDruglist.Add(drugOrderlist[i]);
        //         }
        //     }
        //     haveDruglist.Sort(CompareMakeDrug);
        //     for (int i = 0; i < haveDruglist.Count; i++)
        //     {
        //         drugOrderlist[i] = haveDruglist[i];
        //     }
        //     return drugOrderlist;
        // }
        public bool CheckIsDrugById(int itemId)
        {
            // for (int i = 0; i < makeDruglist.Count; i++)
            // {
            //     if (makeDruglist[i].ID == itemId)
            //     {
            //         return true;
            //     }
            // }
            return false;
        }
        // public int CompareByIsHave(AttrFruitConfig start, AttrFruitConfig end)
        // {
        //     bool isHaveStart = IsHaveDrugUse(start);
        //     bool isHaveEnd = IsHaveDrugUse(end);
        //     if (isHaveStart.CompareTo(isHaveEnd) != 0) return -isHaveStart.CompareTo(isHaveEnd);
        //     //isHaveStart = IsHaveDrugRecycle(start);
        //     //isHaveEnd = IsHaveDrugRecycle(end);
        //     //if (isHaveStart.CompareTo(isHaveEnd) != 0) return -isHaveStart.CompareTo(isHaveEnd);
        //     isHaveStart = GetItemCountByID(PackType.Item, start.ID) > 0 ? true : false;
        //     isHaveEnd = GetItemCountByID(PackType.Item, end.ID) > 0 ? true : false;
        //     if (isHaveStart.CompareTo(isHaveEnd) != 0) return isHaveStart.CompareTo(isHaveEnd);
        //     isHaveStart = IsReachMaxUseDrug(start);
        //     isHaveEnd = IsReachMaxUseDrug(end);
        //     if (isHaveStart.CompareTo(isHaveEnd) != 0) return isHaveStart.CompareTo(isHaveEnd);
        //     int x = makeDruglist.IndexOf(start);
        //     int y = makeDruglist.IndexOf(end);
        //     if (x.CompareTo(y) != 0) return x.CompareTo(y);
        //     return 0;
        // }
        // public bool IsHaveDrugUse(AttrFruitConfig fruitConfig)
        // {
        //     if (!IsReachMaxUseDrug(fruitConfig))
        //     {
        //         return GetItemCountByID(PackType.Item, fruitConfig.ID) > 0 ? true : false;
        //     }
        //     return false;
        // }
        // public bool IsHaveDrugRecycle(AttrFruitConfig fruitConfig)
        // {
        //     if (IsReachMaxUseDrug(fruitConfig))
        //     {
        //         return GetItemCountByID(PackType.Item, fruitConfig.ID) > 0 ? true : false;
        //     }
        //     return false;
        // }
        // public bool IsReachMaxUseDrug(AttrFruitConfig fruitConfig)
        // {
        //     if (fruitConfig == null)
        //     {
        //         return false;
        //     }
        //     if (fruitConfig.FuncID == 2)
        //     {
        //         AlchemyDrugUseLimit drugUseLimit;
        //         if (alchemyModel.TryGetAlchemyUseLimit(fruitConfig.ID, out drugUseLimit))
        //         {
        //             return drugUseLimit.IsReachLimit();
        //         }
        //     }
        //     int useNum = GetItemTotalUsedTimes(fruitConfig.ID);
        //     if (useNum >= fruitConfig.basicUseLimit)
        //     {
        //         return true;
        //     }
        //     return false;
        // }
        #endregion
        //获取背包中的一件可拍卖物品 优先其他职业
        public string GetAuctionEquip()
        {
            var itemPackage = GetSinglePack(PackType.Item);
            var allItems = itemPackage.GetAllItems();
            var guid = string.Empty;
            List<string> guidList = new List<string>();
            foreach (var item in allItems.Values)
            {
                var isAuction = item.isAuction;
                if (isAuction && ItemLogicUtility.Instance.IsRealmEquip(item.itemId))
                {
                    if (!ItemLogicUtility.Instance.IsJobCompatibleItem(item.itemId))
                    {
                        return item.guid;
                    }
                    else
                    {
                        if (guid != string.Empty)
                            continue;
                        guid = item.guid;
                    }
                }
            }
            return guid;
        }
        public void ReceiveAwardNotify(HA801_tagMCGiveAwardInfo netPack)
        {
            var eventName = UIHelper.ServerStringTrim(netPack.EventName);
            if (eventName == "BuyItem")
                return;
            // 仙盟攻城战
            // if (eventName == "FamilyGCZSQGrid" || eventName == "FamilyGCZSQPass" || eventName == "FamilyGCZSQPassAll" ||
            //     eventName == "FamilyGCZContiribution" || eventName == "FamilyGCZAtk")
            // {
            //     ModelCenter.Instance.GetModel<FairySiegeActModel>()?.OnUpdateAwardInfoAction(netPack);
            //     return;
            // }
            if (!commonShowAwardEvents.Contains(eventName))
                return;
            List<Item> showItems = new List<Item>();
            if (netPack.Exp != 0 || netPack.ExpPoint != 0)
            {
                ulong expValue = netPack.Exp + netPack.ExpPoint * (ulong)Constants.ExpPointValue;
                showItems.Add(new Item(GeneralDefine.expDisplayId, expValue));
            }
            if (netPack.MoneyList.Length != 0)
            {
                for (int i = 0; i < netPack.MoneyLen; i++)
                {
                    var moneyType = netPack.MoneyList[i].MoneyType;
                    if (GeneralDefine.moneyDisplayIds.ContainsKey(moneyType) && netPack.MoneyList[i].MoneyValue != 0)
                    {
                        showItems.Add(new Item(GeneralDefine.moneyDisplayIds[moneyType], netPack.MoneyList[i].MoneyValue));
                    }
                }
            }
            if (netPack.ItemList.Length != 0)
            {
                for (int i = 0; i < netPack.ItemLen; i++)
                {
                    showItems.Add(new Item((int)netPack.ItemList[i].ItemID, netPack.ItemList[i].Count, netPack.ItemList[i].IsBind));
                }
            }
            string info = string.Empty;
            if (LanguageConfig.HasKey("commonShowAwardEvents_" + eventName))
                info = Language.Get("commonShowAwardEvents_" + eventName);
            if (showItems.Count == 0)
                return;
            ItemLogicUtility.Instance.ShowGetItem(showItems, info, 0, eventName: eventName);
        }
    }