yyl
9 天以前 3bd7f56906e31e8fe0072108c9d4652707b51de8
Main/System/KnapSack/PackManager.cs
@@ -14,7 +14,7 @@
    public event Action<PackType, string, bool> ChangeItemEvent; // 背包类型,GUID,是否创建
    //删除物品,可能批量删除注意效率
    public event Action<PackType, string> DeleteItemEvent; // 背包类型,GUID
    public event Action<PackType, string, int, int, int> DeleteItemEvent; // 背包类型,GUID, 物品ID,索引, 删除原因
    // 单物品刷新 在得到新物品、物品数量的改变,清理该物品时均会触发 ; 但0725整个背包刷新不触发,如果有需要单独数量刷新事件另外处理
    // 触发比较频繁,界面使用时可以做个汇总后延迟刷新
@@ -24,8 +24,7 @@
    public event Action<int> refreshItemDayUseCountEvent;  //刷新物品每日使用数量
    public event Action<int> refreshItemSumUseCountEvent;  //刷新物品总使用数量
    public bool isPlayBetterEquipEffect { get; set; }  //整理背包时是否播放特效
    public event Action<PackType, string, bool> RefreshItemLockEvent; //物品锁定刷新 背包类型,guid,锁定状态
    
    private Dictionary<PackType, SinglePack> playerPackDict = new Dictionary<PackType, SinglePack>();
@@ -35,7 +34,6 @@
    //读表数据
    public Dictionary<int, int> PackMaxCountDict = new Dictionary<int, int>(); //背包类型:背包格子最大数量
    public Dictionary<int, int> PackInitCountDict = new Dictionary<int, int>(); //背包类型:初始数量
    public int initBagGridCount { get; private set; } //初始物品背包格子数
    public int[] itemPackSortTyps { get; private set; }    //背包物品的按类型排序
    public List<string> composeItemGuidList = new List<string>();  //合成列表物品guid
@@ -58,7 +56,6 @@
    public override void Init()
    {
        DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitialize;
        DTC0102_tagCDBPlayer.afterPlayerDataInitializeEvent += OnAfterPlayerDataInitialize;
        DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent += OnPlayerLoginOk;
        ParseConfig();
        //SysNotifyMgr.Instance.sysNotifyEvent += RefreshSysInfo;
@@ -90,7 +87,6 @@
    public override void Release()
    {
        DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitialize;
        DTC0102_tagCDBPlayer.afterPlayerDataInitializeEvent -= OnAfterPlayerDataInitialize;
        DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent -= OnPlayerLoginOk;
        FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChangeEvent;
        // SysNotifyMgr.Instance.sysNotifyEvent -= RefreshSysInfo;
@@ -112,13 +108,10 @@
        itemDayUseCntDict.Clear();
        itemSumUseCntDict.Clear();
        itemGUIDDict.Clear();
        isPlayBetterEquipEffect = false;
        PackGirdServerBuyCountDict.Clear();
    }
    public void OnAfterPlayerDataInitialize()
    {
    }
    public void OnPlayerLoginOk()
    {
@@ -185,10 +178,6 @@
            playerPackDict.Add(packType, new SinglePack(packType));
        }
        if (isPlayBetterEquipEffect)
        {
            ItemLogicUtility.Instance.ClearSortedBetterEquip();
        }
        for (int i = 0; i < packInfo.ItemCount; i++)
        {
@@ -196,10 +185,7 @@
            var item = playerPackDict[packType].UpdateItem(itemInfo);
            AddItemGUIDDict(item, true);
            if (isPlayBetterEquipEffect)
            {
                ItemLogicUtility.Instance.SetBagSortBetterEquipList(GetItemByGuid(itemInfo.guid));
            }
        }
        if (refrechPackEvent != null)
@@ -212,7 +198,6 @@
    public void UpdateItem(H0704_tagRolePackRefresh serverItem)
    {
        isPlayBetterEquipEffect = false;
        SetLookIndex(null);
        PackType type = (PackType)serverItem.PackType;
        if (!playerPackDict.ContainsKey(type))
@@ -258,17 +243,48 @@
    }
    public void UpdateItemLockState(H0722_tagItemDeadLockRefresh netPack)
    {
        var singlePack = GetSinglePack((PackType)netPack.PackType);
        var item = singlePack.GetItemByIndex(netPack.ItemIndex);
        if (item == null)
        {
            return;
        }
        item.itemInfo.isLock = netPack.IsLock == 1;
        RefreshItemLockEvent?.Invoke((PackType)netPack.PackType, item.guid, item.itemInfo.isLock);
    }
    public void UpdateBuyPackGirdCount(HA207_tagSCPackBuyInfo netPack)
    {
        for (int i = 0; i < netPack.BuyInfoList.Length; i++)
        {
        {
            PackGirdServerBuyCountDict[netPack.BuyInfoList[i].PackType] = netPack.BuyInfoList[i].BuyCnt;
        }
    }
    //购买所需信息 [货币类型,货币数量,购买格数]
    public int[] BuyPackGirdNeedData(PackType packType)
    {
        return null;
        var curPackGirdCnt = GetSinglePack(packType).unlockedGridCount;
        if (curPackGirdCnt >= PackMaxCountDict[(int)packType])
            return null;
        int buyTimes = 0;
        PackGirdServerBuyCountDict.TryGetValue((int)packType, out buyTimes);
        var moneyType = openGirdMoneyDict[(int)packType];
        var moneyCntList = openGirdMoneyValueDict[(int)packType];
        var money = moneyCntList[Math.Min(buyTimes, moneyCntList.Length - 1)];
        var girdCntList = openGirdCountDict[(int)packType];
        var buyGirdCnt = girdCntList[Math.Min(buyTimes, girdCntList.Length - 1)];
        return new[] {moneyType, money, buyGirdCnt};
    }
    public void BuyPackGird(PackType packType)
    {
        var netPack = new C0741_tagCOpenPackCount();
        netPack.PackType = (byte)packType;
        GameNetSystem.Instance.SendInfo(netPack);
    }
    public void UpdateUnlockedGridCount(H0724_tagRolePackCanUseCount useCount)
@@ -289,10 +305,11 @@
        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);
@@ -338,7 +355,6 @@
    public void RemoveItem(H0709_tagClearItem clearItem)
    {
        isPlayBetterEquipEffect = false;
        SetLookIndex(null);
        PackType type = (PackType)clearItem.PackType;
@@ -356,9 +372,9 @@
            guid = itemModel.guid;
            int itemId = itemModel.itemId;
            DeleteItemDictByGUID(type, itemModel.guid);
            singlePack.RemoveItem(clearItem.ItemIndex);
            DeleteItemDictByGUID(type, itemModel.guid,itemId, clearItem.ItemIndex, clearItem.ClearType);
            if (RefreshItemEvent != null)
            {
                RefreshItemEvent(type, clearItem.ItemIndex, itemId);
@@ -382,7 +398,6 @@
    public void UseItemSuccess(H0706_tagUseItemSuccess success)
    {
        isPlayBetterEquipEffect = false;
        SetLookIndex(null);
        if (success.PlayerID != PlayerDatas.Instance.baseData.PlayerID)
        {
@@ -412,15 +427,16 @@
        ChangeItemEvent?.Invoke(itemModel.packType, itemModel.guid, showNewItem);
    }
    void DeleteItemDictByGUID(PackType type, string guid)
    void DeleteItemDictByGUID(PackType type, string guid, int itemID = 0, int index = 0, int clearType = -1)
    {
        if (itemGUIDDict.ContainsKey(guid))
        {
            if (itemGUIDDict[guid].packType == type)
            {
                itemGUIDDict.Remove(guid);
                DeleteItemEvent?.Invoke(type, guid);
            }
            //只是背包转移,不删除但也要通知
            DeleteItemEvent?.Invoke(type, guid, itemID, index, clearType);
        }
    }
@@ -483,7 +499,6 @@
        autoUseItemIDs = JsonMapper.ToObject<int[]>(FuncConfigConfig.Get("AutoUseItem").Numerical1);
        var config= FuncConfigConfig.Get("InitBagCellCount");
        initBagGridCount = int.Parse(config.Numerical1);
        PackInitCountDict = ConfigParse.ParseIntDict(config.Numerical2);
        config = FuncConfigConfig.Get("PackageSortPriority");
        itemPackSortTyps = ConfigParse.GetMultipleStr<int>(config.Numerical1);
@@ -528,7 +543,8 @@
        else
#endif
        {
            path = AssetVersionUtility.GetAssetFilePath($"Config/{name}.ini");
            //从服务端拷贝是ini,打包用txt统一处理
            path = AssetVersionUtility.GetAssetFilePath($"Config/{name}.txt");
        }
        return File.ReadAllLines(path);
@@ -712,6 +728,18 @@
        }
    }
    public List<ItemModel> GetItems(PackType packType)
    {
        if (playerPackDict.ContainsKey(packType))
        {
            return playerPackDict[packType].GetItems();
        }
        else
        {
            return null;
        }
    }
    //通过id找物品,注意检查是否指定背包
    public string GetItemGUIDByID(int itemId, bool includeAuction = true, PackType packType = PackType.Item)
    {
@@ -748,14 +776,14 @@
    /// <summary>
    /// 得到ID相同的物品数量
    /// 得到ID相同的物品数量; 也可以获得部分货币和物品绑定的数量
    /// </summary>
    /// <param name="type"></param>
    /// <param name="id"></param>
    /// <returns></returns>
    public int GetItemCountByID(PackType type, int id, bool includeAuction = true)
    public long GetItemCountByID(PackType type, int id, bool includeAuction = true)
    {
        int count = 0;
        long count = 0;
        var singlePack = GetSinglePack(type);
        if (singlePack != null)
        {
@@ -896,22 +924,23 @@
    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;
        }
        return;
        // if (string.IsNullOrEmpty(guid) || guid == "")
        // {
        //     lookLineIndex = -1;
        //     lookItemGUID = "";
        // }
        // else
        // {
        //     int index = GetItemByGuid(guid).gridIndex;
        //     lookLineIndex = index / singleRowCount;
        //     lookItemGUID = guid;
        // }
        if (lookEquipEvent != null)
        {
            lookEquipEvent();
        }
        // if (lookEquipEvent != null)
        // {
        //     lookEquipEvent();
        // }
    }
    public event Action RefreshBagEvent;