lcy
7 天以前 3b2a6bb9047cfce9f501593b3669a9c1af6c5df4
Main/System/Battle/BattleManager.cs
@@ -10,10 +10,29 @@
    //  同时只能有一场战斗在进行 guid, battlefield
    protected Dictionary<string, BattleField> battleFields = new Dictionary<string, BattleField>();
    public float[] speedGear; //战斗倍数对应的实际速率
    public int speedIndex
    {
        get
        {
            return QuickSetting.Instance.GetQuickSettingValue<int>(QuickSettingType.BattleSpeed, 0);
        }
        set
        {
            QuickSetting.Instance.SetQuickSetting(QuickSettingType.BattleSpeed, value);
            QuickSetting.Instance.SendPackage();
        }
    }
    public readonly int[] speedIndexfuncIdArr = new int[] { 34, 35, 36 };  // 战斗倍数对应的功能ID
    public readonly int passFuncId = 33;    // 跳过战斗对应的功能ID
    public int passRound;   // 超过X回合可跳过
    public int fightGuideID;
    public int fightGuideMainLevelLimit;
    public int fightGuideNoClickSeconds;
    public Action<string, BattleField> onBattleFieldCreate;
    public Action<string, BattleField> onBattleFieldDestroy;
    public Action onBattleFieldDestroy;
    public bool isWaitServerStory = false;  //主线等服务端回报 0425
@@ -24,8 +43,24 @@
        LogicEngine.Instance.OnUpdate += Run;
        DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent += OnPlayerLoginOk;
        DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += BeforePlayerInit;
        ParseConfig();
        
    }
    void ParseConfig()
    {
        var config = FuncConfigConfig.Get("AutoGuaji");
        speedGear = JsonMapper.ToObject<float[]>(config.Numerical4);
        config = FuncConfigConfig.Get("FightGuide");
        fightGuideID = int.Parse(config.Numerical1);
        fightGuideMainLevelLimit = int.Parse(config.Numerical2);
        fightGuideNoClickSeconds = int.Parse(config.Numerical3);
        config = FuncConfigConfig.Get("BattleButton");
        passRound= int.Parse(config.Numerical1);
    }
    public override void Release()
    {
@@ -37,8 +72,8 @@
    protected void OnPlayerLoginOk()
    {
        long exAttr1 = PlayerDatas.Instance.GetPlayerDataByType(PlayerDataType.ExAttr1);
        long exAttr2 = PlayerDatas.Instance.GetPlayerDataByType(PlayerDataType.ExAttr2);
        long exAttr1 = PlayerDatas.Instance.baseData.ExAttr1;
        long exAttr2 = PlayerDatas.Instance.baseData.ExAttr2;
        int MapID = 1;
        int FuncLineID = (int)exAttr2;
@@ -63,7 +98,11 @@
            redTeamList.Add(storyTeam);
            CreateBattleField(string.Empty, MapID, FuncLineID, extendData, redTeamList, blueTeamList);
            HB424_tagSCTurnFightInit vNetData = new HB424_tagSCTurnFightInit();
            vNetData.MapID = (uint)MapID;
            vNetData.FuncLineID = (uint)FuncLineID;
            CreateBattleField(string.Empty, vNetData, extendData, redTeamList, blueTeamList);
        }
        else
        {
@@ -126,6 +165,30 @@
        List<GameNetPackBasic> packQueueSnapshot = new List<GameNetPackBasic>(packQueue);
        List<GameNetPackBasic> newPackList = ParseBattlePackList(string.Empty, packQueueSnapshot);
        Action printNewPack = () =>
        {
            string temp = "After AnalysisPackQueueAndDistribute newPackList count: " + newPackList.Count + "\n";
            foreach (var pack in newPackList)
            {
                if (pack is CustomHB426CombinePack b426Pack)
                {
                    temp += "  pack type is " + pack.GetType().Name + " tag is " + (b426Pack.startTag != null ? b426Pack.startTag.Tag : "null") + "\n";
                }
                else if (pack is CustomB421ActionPack b421Pack)
                {
                    temp += "  pack type is " + pack.GetType().Name + " guid is " + b421Pack.guid + "\n";
                }
                else
                {
                    temp += "  pack type is " + pack.GetType().Name + "\n";
                }
            }
            Debug.LogWarning(temp);
        };
        printNewPack();
        // HashSet<int> skipIndexes = new HashSet<int>();
        // // 这里已经是按照Dequeue的顺序了
@@ -210,127 +273,15 @@
    public static List<GameNetPackBasic> ParseBattlePackList(string guid, List<GameNetPackBasic> packQueueSnapshot)
    {
        bool wrong = false;
        List<GameNetPackBasic> newPackList = new List<GameNetPackBasic>();
        HB421_tagMCTurnFightObjAction b421Pack = null;
        for (int i = 0; i < packQueueSnapshot.Count; i++)
        var list = CustomHB426CombinePack.CombineToSkillPackFromList(guid, packQueueSnapshot);
        string str = "ParseBattlePackList \n";
        for (int i = 0; i < list.Count; i++)
        {
           GameNetPackBasic pack = packQueueSnapshot[i];
            if (null == b421Pack)
            {
                if (pack is HB421_tagMCTurnFightObjAction _b421)
                {
                    b421Pack = _b421;
                }
                else
                {
                    newPackList.Add(pack);
                }
                continue;
            }
            else
            {
                List<GameNetPackBasic> b421List = new List<GameNetPackBasic>();
                bool find = false;
                for (int k = i; k < packQueueSnapshot.Count; k++/*, Debug.LogError(k + " : is plusing")*/)
                {
                    GameNetPackBasic maybeB426Pack = packQueueSnapshot[k];
                    if (maybeB426Pack is HB426_tagSCTurnFightTag b426Pack)
                    {
                        // Debug.LogError(k + " : find b426 " + maybeB426Pack.packUID + " sign " + b426Pack.Sign + " tag " + b426Pack.Tag);
                        if (b426Pack.Sign == 0)
                        {
                            find = true;
                            List<GameNetPackBasic> b426List = new List<GameNetPackBasic>();
                            b426List.Add(b426Pack);
                            for (int j = k + 1; j < packQueueSnapshot.Count; j++)
                            {
                                GameNetPackBasic maybeB426EndPack = packQueueSnapshot[j];
                                if (maybeB426EndPack is HB426_tagSCTurnFightTag b426EndPack)
                                {
                                    // Debug.LogError(j + " : find b426 end pack : " + b426EndPack.packUID + " sign " + b426EndPack.Sign + " tag " + b426EndPack.Tag);
                                    if (b426EndPack.Tag == b426Pack.Tag)
                                    {
                                        if (b426EndPack.Sign == 1)
                                        {
                                            b426List.Add(maybeB426EndPack);
                                            k = j;
                                            i = k;
                                            break;
                                        }
                                        else
                                        {
                                            Debug.LogError("错误的Sign == 1");
                                            continue;
                                        }
                                    }
                                    else
                                    {
                                        //  新的一对
                                    }
                                }
                                else
                                {
                                    b426List.Add(maybeB426EndPack);
                                    k = j;
                                    i = k;
                                }
                            }
                            //   这里面的b421还没处理
                            List<GameNetPackBasic> combinedList = CustomHB426CombinePack.CombineToSkillPackFromList(guid, b426List);
                            b421List.AddRange(combinedList);
                        }
                        else
                        {
                            wrong = true;
                            Debug.LogError("错误的b426 分析有问题 " + b426Pack.packUID);
                        }
                    }
                    else
                    {
                        if (!find)
                        {
                            newPackList.Add(maybeB426Pack);
                            i = k;
                        }
                        else
                        {
                            if (maybeB426Pack is HB421_tagMCTurnFightObjAction _b421)
                            {
                                i = k - 1;
                                break;
                            }
                            b421List.Add(maybeB426Pack);
                            i = k;
                        }
                    }
                }
                CustomB421ActionPack actionPack = CustomB421ActionPack.CreateB421ActionPack(guid, b421List);
                newPackList.Add(actionPack);
                b421Pack = null;
           }
            str += "  " + list[i].GetType().Name + "\n";
        }
        // BattleDebug.LogError(str);
        return list;
        if (wrong)
        {
            string output = string.Empty;
            for (int f = 0; f < packQueueSnapshot.Count; f++)
            {
                output += (packQueueSnapshot[f].packUID  + "&" + packQueueSnapshot[f].GetType().ToString() + "|");
            }
            Debug.LogError(output);
        }
        return newPackList;
    }
    //  专属于主线战斗的派发
@@ -447,11 +398,18 @@
        {
            uidList.Add(packUID);
        }
    }
    public BattleField GetBattleField(ulong packUID)
    {
        return GetBattleField(GetGUID(packUID));
        string guid = GetGUID(packUID);
        BattleField battleField = GetBattleField(GetGUID(packUID));
        if (battleField == null || battleField.rejectNewPackage)
        {
            return null;
        }
        return battleField;
    }
    public BattleField GetBattleField(string guid)
@@ -484,6 +442,11 @@
            return;
        }
        if (queue.Count <= 0)
        {
            return;
        }
        var pack = queue.Dequeue();
        // Debug.LogError("DistributeNextReportPackage for guid : " + guid + " pack type : " + pack.GetType());
@@ -506,25 +469,16 @@
        catch (Exception ex)
        {
            Debug.LogError("DistributeNextPackage: 分发包异常 " + ex);
            // 出错时主动移除当前包,防止死循环
            if (packQueue.Count > 0)
            {
                packQueue.Dequeue();
            }
        }
        if (queue.Count <= 0)
        {
            battleReportDict.Remove(guid);
            battlePackRelationList.Remove(guid);
        }
    }
    #endregion
    public BattleField CreateBattleField(string guid, int MapID, int FuncLineID, JsonData extendData, List<TeamBase> redTeamList, List<TeamBase> blueTeamList)
    public BattleField CreateBattleField(string guid, HB424_tagSCTurnFightInit vNetData, JsonData extendData, List<TeamBase> redTeamList, List<TeamBase> blueTeamList)
    {
        BattleField battleField = null;
        int MapID = (int)vNetData.MapID;
        int FuncLineID = (int)vNetData.FuncLineID;
        bool isCreate = true;
        if (battleFields.TryGetValue(guid, out battleField))
@@ -542,7 +496,7 @@
        }
        if (isCreate)
        {
        {
            battleField = BattleFieldFactory.CreateBattleField(guid, MapID, FuncLineID, extendData, redTeamList, blueTeamList);
            if (string.IsNullOrEmpty(guid))
@@ -555,7 +509,7 @@
        battleField.Init(MapID, FuncLineID, extendData, redTeamList, blueTeamList);
        battleField.Init(MapID, FuncLineID, extendData, redTeamList, blueTeamList, vNetData.TurnMax);
        return battleField;
    }
@@ -583,7 +537,7 @@
        GameObject.DestroyImmediate(battleField.battleRootNode.gameObject);
        onBattleFieldDestroy?.Invoke(battleField.guid, battleField);
        onBattleFieldDestroy?.Invoke();
    }
@@ -596,6 +550,7 @@
    // 4-继续战斗          -   玩家主线战斗中(包含主线小怪、主线boss),前端表现完后端同步的战斗片段后,可再回复该值,后端会根据战斗逻辑及流程自动回复下一段的战斗片段封包,一直循环
    public void MainFightRequest(byte reqType, uint reqValue = 0)
    {
        // Debug.LogError("MainFightRequest reqType " + reqType + " reqValue " + reqValue);
        CB413_tagCSMainFightReq req = new CB413_tagCSMainFightReq();
        req.ReqType = reqType;
        req.ReqValue = reqValue;
@@ -635,4 +590,64 @@
        return null;
    }
    //发进入战斗包
    private float lastTime = 0f;
    private float turnCoolDown = 0.5f; // 冷却时间
    public void SendTurnFight(uint mapID, uint funcLineID = 0, byte tagType = 0, uint tagID = 0, uint[] valueList = null)
    {
        // 连续频繁发包,触发提示
        float currentTime = Time.time;
        if (currentTime - lastTime < turnCoolDown)
        {
            SysNotifyMgr.Instance.ShowTip("BattleCoolDown");
            return;
        }
        lastTime = currentTime;
        CB410_tagCMTurnFight pack = new CB410_tagCMTurnFight();
        pack.MapID = mapID;
        pack.FuncLineID = funcLineID;
        pack.TagType = tagType;
        pack.TagID = tagID;
        if (!valueList.IsNullOrEmpty())
        {
            pack.ValueList = valueList;
            pack.ValueCount = (byte)valueList.Length;
        }
        GameNetSystem.Instance.SendInfo(pack);
    }
    // 获取当前正在显示的战斗场景名称,如果没有则返回空字符串
    public string GetActiveBattleName()
    {
        foreach (var kvp in battleFields)
        {
            BattleField battleField = kvp.Value;
            if (battleField == null)
                continue;
            var battleName = battleField.ToString();
            if (BattleConst.battleNameToWinName.ContainsKey(battleName)
            && UIManager.Instance.IsOpened(BattleConst.battleNameToWinName[battleName]))
                return battleName;
        }
        return "";
    }
    // 获取当前正在显示的战斗场景,如果没有则返回null
    public BattleField GetActiveBattleFieldByName(string battleName)
    {
        foreach (var kvp in battleFields)
        {
            BattleField battleField = kvp.Value;
            if (battleField == null)
                continue;
            var name = battleField.ToString();
            if (name == battleName)
                return battleField;
        }
        return null;
    }
}