yyl
9 天以前 3bd7f56906e31e8fe0072108c9d4652707b51de8
Main/System/KnapSack/PackManager.cs
@@ -8,12 +8,40 @@
public class PackManager : GameSystemManager<PackManager>
{
    public event Action<PackType> refrechPackEvent; //刷新整个背包数据
    //物品(创建)刷新,可能批量创建注意效率; bool:true代表创建 false 刷新; 注意0707物品数量刷新不包含在此事件
    public event Action<PackType, string, bool> ChangeItemEvent; // 背包类型,GUID,是否创建
    //删除物品,可能批量删除注意效率
    public event Action<PackType, string, int, int, int> DeleteItemEvent; // 背包类型,GUID, 物品ID,索引, 删除原因
    // 单物品刷新 在得到新物品、物品数量的改变,清理该物品时均会触发 ; 但0725整个背包刷新不触发,如果有需要单独数量刷新事件另外处理
    // 触发比较频繁,界面使用时可以做个汇总后延迟刷新
    public event Action<PackType, int, int> RefreshItemEvent; //背包类型,位置索引,物品id
    public event Action<PackType> gridRefreshEvent; //背包可用格子数刷新
    public event Action<int, int> useItemSuccessEvent; //物品使用成功 int 位置索引 int物品id
    public event Action<int> refreshItemDayUseCountEvent;  //刷新物品每日使用数量
    public event Action<int> refreshItemSumUseCountEvent;  //刷新物品总使用数量
    public event Action<PackType, string, bool> RefreshItemLockEvent; //物品锁定刷新 背包类型,guid,锁定状态
    private Dictionary<PackType, SinglePack> playerPackDict = new Dictionary<PackType, SinglePack>();
    private Dictionary<string, ItemModel> itemGUIDDict = new Dictionary<string, ItemModel>();
    private Dictionary<int, int> PackGirdServerBuyCountDict = new Dictionary<int, int>(); //背包类型:购买格子的次数
    //读表数据
    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
    //开格子
    public Dictionary<int, int> openGirdMoneyDict = new Dictionary<int, int>(); //背包类型:消耗货币类型
    public Dictionary<int, int[]> openGirdMoneyValueDict = new Dictionary<int, int[]>(); //背包类型:消耗货币值(按次数定价)
    public Dictionary<int, int[]> openGirdCountDict = new Dictionary<int, int[]>(); //背包类型:每次开的格子数量
    public static string StrengthAttrShift_RecordKey = "";
    public const string RecordKnapsackTitle = "RecordKnapsackTitle";
@@ -23,16 +51,11 @@
    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[] gameCashShow;  //代金券特殊显示 除以100
    public int[] autoUseItemIDs;
    public override void Init()
    {
        DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitialize;
        DTC0102_tagCDBPlayer.afterPlayerDataInitializeEvent += OnAfterPlayerDataInitialize;
        DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent += OnPlayerLoginOk;
        ParseConfig();
        //SysNotifyMgr.Instance.sysNotifyEvent += RefreshSysInfo;
@@ -56,38 +79,20 @@
        //     }
        // }
        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)
@@ -103,13 +108,10 @@
        itemDayUseCntDict.Clear();
        itemSumUseCntDict.Clear();
        itemGUIDDict.Clear();
        isPlayBetterEquipEffect = false;
        PackGirdServerBuyCountDict.Clear();
    }
    public void OnAfterPlayerDataInitialize()
    {
    }
    public void OnPlayerLoginOk()
    {
@@ -165,28 +167,7 @@
        // }
    }
    public event Action<PackType> refrechPackEvent; //刷新整个背包数据
    //物品(创建)刷新,可能批量创建注意效率; bool:true代表创建 false 刷新; 注意0707物品数量刷新不包含在此事件
    public event Action<PackType, string, bool> ChangeItemEvent; // 背包类型,GUID,是否创建
    //删除物品,可能批量删除注意效率
    public event Action<PackType, string> DeleteItemEvent; // 背包类型,GUID
    // 单物品刷新 在得到新物品、物品数量的改变,清理该物品时均会触发 ; 但0725整个背包刷新不触发,如果有需要单独数量刷新事件另外处理
    // 触发比较频繁,界面使用时可以做个汇总后延迟刷新
    public event Action<PackType, int, int> RefreshItemEvent; //背包类型,位置索引,物品id
    public event Action<PackType> gridRefreshEvent; //背包可用格子数刷新
    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)
    {
@@ -197,10 +178,6 @@
            playerPackDict.Add(packType, new SinglePack(packType));
        }
        if (isPlayBetterEquipEffect)
        {
            ItemLogicUtility.Instance.ClearSortedBetterEquip();
        }
        for (int i = 0; i < packInfo.ItemCount; i++)
        {
@@ -208,10 +185,7 @@
            var item = playerPackDict[packType].UpdateItem(itemInfo);
            AddItemGUIDDict(item, true);
            if (isPlayBetterEquipEffect)
            {
                ItemLogicUtility.Instance.SetBagSortBetterEquipList(GetItemByGuid(itemInfo.guid));
            }
        }
        if (refrechPackEvent != null)
@@ -224,7 +198,6 @@
    public void UpdateItem(H0704_tagRolePackRefresh serverItem)
    {
        isPlayBetterEquipEffect = false;
        SetLookIndex(null);
        PackType type = (PackType)serverItem.PackType;
        if (!playerPackDict.ContainsKey(type))
@@ -270,7 +243,49 @@
    }
    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)
    {
        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)
    {
@@ -290,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);
@@ -339,7 +355,6 @@
    public void RemoveItem(H0709_tagClearItem clearItem)
    {
        isPlayBetterEquipEffect = false;
        SetLookIndex(null);
        PackType type = (PackType)clearItem.PackType;
@@ -357,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);
@@ -383,7 +398,6 @@
    public void UseItemSuccess(H0706_tagUseItemSuccess success)
    {
        isPlayBetterEquipEffect = false;
        SetLookIndex(null);
        if (success.PlayerID != PlayerDatas.Instance.baseData.PlayerID)
        {
@@ -413,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);
        }
    }
@@ -475,20 +490,26 @@
    //     }
    // }
    #endregion
    #region 玩家装备特殊逻辑
    void ParseConfig()
    {
        ParsePackConfigIni();
        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);
        ParsePackConfigIni();
        config = FuncConfigConfig.Get("OpenPack");
        openGirdMoneyDict = ConfigParse.ParseIntDict(config.Numerical1);
        openGirdMoneyValueDict = ConfigParse.ParseIntArrayDict(config.Numerical2);
        openGirdCountDict = ConfigParse.ParseIntArrayDict(config.Numerical3);
        config = FuncConfigConfig.Get("ItemCountShow");
        gameCashShow = JsonMapper.ToObject<int[]>(config.Numerical1);
    }
    void ParsePackConfigIni()
@@ -522,10 +543,20 @@
        else
#endif
        {
            path = AssetVersionUtility.GetAssetFilePath($"Config/{name}.ini");
            //从服务端拷贝是ini,打包用txt统一处理
            path = AssetVersionUtility.GetAssetFilePath($"Config/{name}.txt");
        }
        return File.ReadAllLines(path);
    }
    public int GetCanBuyPackGirdCount(PackType type)
    {
        if (!PackMaxCountDict.ContainsKey((int)type))
        {
            return 0;
        }
        return PackMaxCountDict[(int)type] - GetSinglePack(type).unlockedGridCount;
    }
@@ -697,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)
    {
@@ -733,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)
        {
@@ -842,9 +885,6 @@
    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 UpdatePackRedpoint(PackType type)
    {
@@ -868,16 +908,7 @@
                }
                break;
            case PackType.Warehouse:
                if (singlePack.GetEmptyGridCount() <= 0)
                {
                    MainRedDot.Instance.redPointDepotFunc.state = RedPointState.Full;
                }
                else
                {
                    MainRedDot.Instance.redPointDepotFunc.state = RedPointState.None;
                }
                break;
        }
    }
@@ -893,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;