| | |
| | | private Dictionary<int, BattleDrops> tempDropList = new Dictionary<int, BattleDrops>(); |
| | | private Dictionary<int, HB422_tagMCTurnFightObjDead> tempDeadPackList = new Dictionary<int, HB422_tagMCTurnFightObjDead>(); |
| | | |
| | | protected List<HB428_tagSCBuffRefresh> buffCollections = new List<HB428_tagSCBuffRefresh>(); |
| | | |
| | | |
| | | // 构造函数:初始化技能基础数据 |
| | | public SkillBase(BattleObject _caster, SkillConfig _skillCfg, HB427_tagSCUseSkill vNetData, List<GameNetPackBasic> _packList, BattleField _battleField = null) |
| | | { |
| | |
| | | // 修复:使用循环代替递归,避免栈溢出风险 |
| | | // try |
| | | // { |
| | | while (true) |
| | | while (true) |
| | | { |
| | | // 验证技能效果是否完成 |
| | | if (skillEffect != null && !skillEffect.IsFinished()) |
| | | return; |
| | | |
| | | if (skillEffect != null) |
| | | { |
| | | // 验证技能效果是否完成 |
| | | if (skillEffect != null && !skillEffect.IsFinished()) |
| | | return; |
| | | |
| | | if (skillEffect != null) |
| | | skillEffect = null; |
| | | continue; // 使用continue代替递归调用 |
| | | } |
| | | |
| | | // 验证其他技能动作是否完成 |
| | | if (otherSkillActionList.Count > 0) |
| | | { |
| | | bool hasFinishedAction = false; |
| | | for (int i = otherSkillActionList.Count - 1; i >= 0; i--) |
| | | { |
| | | skillEffect = null; |
| | | var action = otherSkillActionList[i]; |
| | | if (action.IsFinished()) |
| | | { |
| | | otherSkillActionList.RemoveAt(i); |
| | | hasFinishedAction = true; |
| | | } |
| | | } |
| | | if (hasFinishedAction) |
| | | { |
| | | continue; // 使用continue代替递归调用 |
| | | } |
| | | |
| | | // 验证其他技能动作是否完成 |
| | | if (otherSkillActionList.Count > 0) |
| | | { |
| | | bool hasFinishedAction = false; |
| | | for (int i = otherSkillActionList.Count - 1; i >= 0; i--) |
| | | { |
| | | var action = otherSkillActionList[i]; |
| | | if (action.IsFinished()) |
| | | { |
| | | otherSkillActionList.RemoveAt(i); |
| | | hasFinishedAction = true; |
| | | } |
| | | } |
| | | if (hasFinishedAction) |
| | | { |
| | | continue; // 使用continue代替递归调用 |
| | | } |
| | | return; |
| | | } |
| | | |
| | | break; // 没有更多需要处理的,退出循环 |
| | | return; |
| | | } |
| | | |
| | | // 处理剩余包 |
| | | while (packList.Count > 0) |
| | | { |
| | | var pack = packList[0]; |
| | | packList.RemoveAt(0); |
| | | break; // 没有更多需要处理的,退出循环 |
| | | } |
| | | |
| | | if (pack is CustomHB426CombinePack combinePack && combinePack.startTag.Tag.StartsWith("Skill_")) |
| | | { |
| | | BattleDebug.LogError("other skill casting " + combinePack.startTag.Tag); |
| | | var otherSkillAction = combinePack.CreateSkillAction(); |
| | | otherSkillAction.fromSkillId = skillConfig.SkillID; |
| | | otherSkillActionList.Add(otherSkillAction); |
| | | return; |
| | | } |
| | | |
| | | if (pack is CustomB421ActionPack actionPack) |
| | | { |
| | | actionPack.Distribute(); |
| | | } |
| | | else |
| | | { |
| | | PackageRegedit.Distribute(pack); |
| | | } |
| | | } |
| | | // } |
| | | // catch (Exception ex) |
| | | // { |
| | | // Debug.LogError($"OnSkillFinished异常: {ex.Message},技能ID={skillConfig.SkillID}"); |
| | | // // 确保状态一致性,即使出现异常也要标记完成 |
| | | // isFinished = true; |
| | | // throw; // 重新抛出异常供上层处理 |
| | | // } |
| | | // 处理剩余包 |
| | | if (!ResolvePackList()) |
| | | { |
| | | return; |
| | | } |
| | | // } |
| | | // catch (Exception ex) |
| | | // { |
| | | // Debug.LogError($"OnSkillFinished异常: {ex.Message},技能ID={skillConfig.SkillID}"); |
| | | // // 确保状态一致性,即使出现异常也要标记完成 |
| | | // isFinished = true; |
| | | // throw; // 重新抛出异常供上层处理 |
| | | // } |
| | | |
| | | isFinished = true; |
| | | } |
| | | |
| | | protected virtual bool ResolvePackList() |
| | | { |
| | | while (packList.Count > 0) |
| | | { |
| | | var pack = packList[0]; |
| | | packList.RemoveAt(0); |
| | | |
| | | if (pack is CustomHB426CombinePack combinePack && combinePack.startTag.Tag.StartsWith("Skill_")) |
| | | { |
| | | BattleDebug.LogError("other skill casting " + combinePack.startTag.Tag); |
| | | var otherSkillAction = combinePack.CreateSkillAction(); |
| | | otherSkillAction.fromSkillId = skillConfig.SkillID; |
| | | otherSkillActionList.Add(otherSkillAction); |
| | | return false; |
| | | } |
| | | else if (pack is HB428_tagSCBuffRefresh buffRefresh) |
| | | { |
| | | // 从找到第一个HB428开始 找出连续的HB428_tagSCBuffRefresh包 如果找到一个B428后 之后碰到非HB428包就停止 |
| | | buffCollections.Add(buffRefresh); |
| | | while (packList.Count > 0) |
| | | { |
| | | var nextPack = packList[0]; |
| | | if (nextPack is HB428_tagSCBuffRefresh nextBuffRefresh) |
| | | { |
| | | buffCollections.Add(nextBuffRefresh); |
| | | packList.RemoveAt(0); |
| | | } |
| | | else |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | |
| | | // 同时刷新所有对象的buff,不分组 |
| | | foreach (var buff in buffCollections) |
| | | { |
| | | BattleObject battleObj = battleField.battleObjMgr.GetBattleObject((int)buff.ObjID); |
| | | if (battleObj != null) |
| | | { |
| | | battleObj.buffMgr.RefreshBuff(buff, true); |
| | | } |
| | | } |
| | | |
| | | // 清空已处理的buff集合 |
| | | buffCollections.Clear(); |
| | | continue; |
| | | } |
| | | |
| | | if (pack is CustomB421ActionPack actionPack) |
| | | { |
| | | actionPack.Distribute(); |
| | | } |
| | | else |
| | | { |
| | | PackageRegedit.Distribute(pack); |
| | | } |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | // 添加清理方法:防止内存泄漏 |
| | | public virtual void Cleanup() |