2021-05-13 14:39:44 +08:00
|
|
|
|
require("Modules.Battle.Logic.HardStageCondition")
|
|
|
|
|
require("Modules.Battle.Logic.HardStageEventManager")
|
2019-03-12 14:05:45 +08:00
|
|
|
|
BattleLogic = {}
|
|
|
|
|
local floor = math.floor
|
2019-03-22 15:00:06 +08:00
|
|
|
|
local min = math.min
|
2020-04-16 15:10:04 +08:00
|
|
|
|
-- local objList = BattleDictionary.New()
|
2019-04-17 21:04:32 +08:00
|
|
|
|
local removeObjList = BattleList.New()
|
2020-04-10 14:52:41 +08:00
|
|
|
|
local MaxRound = 20
|
|
|
|
|
local CurRound = 0
|
|
|
|
|
local CurCamp = 0
|
|
|
|
|
local CurSkillPos = {}
|
|
|
|
|
local PosList = {}
|
2019-03-12 14:05:45 +08:00
|
|
|
|
local curFrame
|
2020-10-16 11:39:44 +08:00
|
|
|
|
BattleLogic.Type = -1 -- 0 切磋 1 故事副本 2 地图探索 3 竞技场 4 秘境boss 5 解锁秘境 6 公会战 7 血战 8 兽潮 9巅峰战
|
2019-03-21 14:33:56 +08:00
|
|
|
|
BattleLogic.IsEnd = false
|
|
|
|
|
BattleLogic.Result = -1
|
|
|
|
|
BattleLogic.Event = BattleEvent.New()
|
2019-04-16 14:32:11 +08:00
|
|
|
|
BattleLogic.BuffMgr = BuffManager.New()
|
2020-04-10 14:52:41 +08:00
|
|
|
|
local _IsDebug
|
2019-03-12 14:05:45 +08:00
|
|
|
|
local fightData
|
|
|
|
|
local record
|
2020-08-16 17:49:57 +08:00
|
|
|
|
local userData
|
2020-10-16 11:39:44 +08:00
|
|
|
|
--所有英雄伤害和治疗
|
|
|
|
|
local allHeroDamage=0
|
|
|
|
|
--所有怪的伤害和治疗
|
|
|
|
|
local allEnemyDamage=0
|
2021-05-13 14:39:44 +08:00
|
|
|
|
--关卡星级记录
|
|
|
|
|
local levelStarRecord
|
|
|
|
|
local hardStageId =0
|
2021-08-03 17:27:36 +08:00
|
|
|
|
local insertSkillRole=nil
|
2019-03-12 14:05:45 +08:00
|
|
|
|
--是否开启战斗日志
|
2019-10-31 14:49:48 +08:00
|
|
|
|
BattleLogic.IsOpenBattleRecord = false
|
2019-03-12 14:05:45 +08:00
|
|
|
|
--逻辑帧频
|
|
|
|
|
BattleLogic.GameFrameRate = 30
|
|
|
|
|
BattleLogic.GameDeltaTime = 1 / BattleLogic.GameFrameRate
|
|
|
|
|
--总波次
|
|
|
|
|
BattleLogic.TotalOrder = 0
|
|
|
|
|
--当前波次
|
|
|
|
|
BattleLogic.CurOrder = 0
|
2023-04-07 16:43:05 +08:00
|
|
|
|
--当前回合触发总次数(添加buff,伤害,治疗)
|
|
|
|
|
local curRoundTriggerTime=0
|
2019-03-21 14:33:56 +08:00
|
|
|
|
local actionPool = BattleObjectPool.New(function ()
|
|
|
|
|
return { 0, 0 }
|
|
|
|
|
end)
|
|
|
|
|
local tbActionList = BattleList.New()
|
|
|
|
|
|
|
|
|
|
local rolePool = BattleObjectPool.New(function ()
|
|
|
|
|
return RoleLogic.New()
|
|
|
|
|
end)
|
|
|
|
|
|
2023-04-07 16:43:05 +08:00
|
|
|
|
function BattleLogic.AddRoundTriggerTime()
|
|
|
|
|
curRoundTriggerTime=curRoundTriggerTime+1
|
|
|
|
|
end
|
2020-08-16 17:49:57 +08:00
|
|
|
|
function BattleLogic.Init(data, _userData, maxRound)
|
2019-03-12 14:05:45 +08:00
|
|
|
|
if BattleLogic.IsOpenBattleRecord then
|
|
|
|
|
record = {}
|
|
|
|
|
end
|
2021-05-13 14:39:44 +08:00
|
|
|
|
levelStarRecord={}
|
2019-03-12 14:05:45 +08:00
|
|
|
|
fightData = data
|
2020-08-16 17:49:57 +08:00
|
|
|
|
userData = _userData
|
2021-05-13 14:39:44 +08:00
|
|
|
|
hardStageId=data.nodeId
|
2021-08-03 17:27:36 +08:00
|
|
|
|
insertSkillRole=nil
|
2019-03-12 14:05:45 +08:00
|
|
|
|
BattleLogic.CurOrder = 0
|
|
|
|
|
BattleLogic.TotalOrder = #data.enemyData
|
2019-03-21 14:33:56 +08:00
|
|
|
|
BattleLogic.Clear()
|
2019-03-12 14:05:45 +08:00
|
|
|
|
curFrame = 0
|
2020-04-10 14:52:41 +08:00
|
|
|
|
CurRound = 0
|
2020-05-07 15:53:26 +08:00
|
|
|
|
MaxRound = maxRound or 20
|
2020-10-16 11:39:44 +08:00
|
|
|
|
allHeroDamage= 0
|
|
|
|
|
allEnemyDamage= 0
|
2020-04-10 14:52:41 +08:00
|
|
|
|
_IsDebug = false
|
2019-03-12 14:05:45 +08:00
|
|
|
|
BattleLogic.Event:ClearEvent()
|
2019-04-16 14:32:11 +08:00
|
|
|
|
BattleLogic.BuffMgr:Init()
|
2019-03-12 14:05:45 +08:00
|
|
|
|
BattleLogic.IsEnd = false
|
|
|
|
|
BattleLogic.Result = -1
|
2020-11-27 16:52:55 +08:00
|
|
|
|
-- 日志管理放到前面初始化
|
2021-01-22 18:11:30 +08:00
|
|
|
|
BattleLogManager.Init(fightData, userData, maxRound)
|
2020-05-06 16:49:24 +08:00
|
|
|
|
RoleManager.Init()
|
2023-04-07 16:43:05 +08:00
|
|
|
|
MonsterManager.Init()
|
|
|
|
|
FightWeaponManager.Init()
|
2020-05-02 05:12:07 +08:00
|
|
|
|
SkillManager.Init()
|
2020-05-24 00:04:06 +08:00
|
|
|
|
OutDataManager.Init(fightData)
|
|
|
|
|
PassiveManager.Init()
|
2021-05-13 14:39:44 +08:00
|
|
|
|
HardStageEventManager.Init()
|
2020-10-29 16:36:10 +08:00
|
|
|
|
-- 监听英雄受到治疗
|
|
|
|
|
BattleLogic.Event:AddEvent(BattleEventName.RoleBeTreated,function (castRole, realTreat, treat)
|
2020-12-28 10:34:53 +08:00
|
|
|
|
--巅峰争霸赛和切磋超时改为只判断总伤害,不再判断总治疗
|
|
|
|
|
-- if castRole.camp==0 then
|
|
|
|
|
-- allHeroDamage=allHeroDamage+treat
|
|
|
|
|
-- else
|
|
|
|
|
-- allEnemyDamage=allEnemyDamage+treat
|
|
|
|
|
-- end
|
2020-10-29 16:36:10 +08:00
|
|
|
|
end)
|
2020-10-16 11:39:44 +08:00
|
|
|
|
--监听英雄受到攻击
|
|
|
|
|
BattleLogic.Event:AddEvent(BattleEventName.RoleBeDamaged,function (defRole, atkRole, damage, bCrit, finalDmg, damageType, dotType)
|
2020-10-29 16:36:10 +08:00
|
|
|
|
--我方阵营总攻击
|
|
|
|
|
if atkRole.camp==0 then
|
|
|
|
|
allHeroDamage=allHeroDamage+damage
|
|
|
|
|
--敌方阵营
|
|
|
|
|
else
|
|
|
|
|
allEnemyDamage=allEnemyDamage+damage
|
|
|
|
|
end
|
|
|
|
|
end)
|
2023-04-07 16:43:05 +08:00
|
|
|
|
BattleLogic.Event:AddEvent(BattleEventName.BattleRoundChange,function()
|
|
|
|
|
curRoundTriggerTime=0
|
|
|
|
|
end)
|
2020-10-16 11:39:44 +08:00
|
|
|
|
|
|
|
|
|
end
|
2021-01-22 18:11:30 +08:00
|
|
|
|
|
2021-10-26 10:25:51 +08:00
|
|
|
|
--获取是否为pvp战斗
|
|
|
|
|
function BattleLogic.GetIsPvP()
|
|
|
|
|
if BattleLogic.Type== BATTLE_SERVER_TYPE.TOPFight or
|
|
|
|
|
BattleLogic.Type== BATTLE_SERVER_TYPE.Firend or
|
|
|
|
|
BattleLogic.Type== BATTLE_SERVER_TYPE.ArenaFight or
|
|
|
|
|
BattleLogic.Type== BATTLE_SERVER_TYPE.CarPersonFight or
|
|
|
|
|
BattleLogic.Type== BATTLE_SERVER_TYPE.CrossYuxuLunDaoFight or
|
2021-11-23 14:17:57 +08:00
|
|
|
|
BattleLogic.Type== BATTLE_SERVER_TYPE.NewArenaFight or
|
|
|
|
|
BattleLogic.Type== BATTLE_SERVER_TYPE.LINGMAIMIJING then
|
2021-10-26 10:25:51 +08:00
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
2021-01-22 18:11:30 +08:00
|
|
|
|
-- 获取双方所有血量
|
|
|
|
|
function BattleLogic.GetAllDamage()
|
|
|
|
|
return allHeroDamage, allEnemyDamage
|
|
|
|
|
end
|
|
|
|
|
|
2021-05-13 14:39:44 +08:00
|
|
|
|
--获取我方灵兽数据
|
|
|
|
|
function BattleLogic.GetPlayerMonsterData()
|
|
|
|
|
return fightData.playerData.monsterList
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--获取精英副本星级记录
|
|
|
|
|
function BattleLogic.GetHardLevelStarRecord()
|
|
|
|
|
return levelStarRecord
|
|
|
|
|
end
|
2021-01-22 18:11:30 +08:00
|
|
|
|
|
2020-08-11 09:12:09 +08:00
|
|
|
|
-- 检测先手阵营
|
|
|
|
|
function BattleLogic.CheckFirstCamp()
|
|
|
|
|
-- 默认我方先手
|
|
|
|
|
BattleLogic.FirstCamp = 0
|
|
|
|
|
-- 数据不存在时,兼容老战斗数据
|
|
|
|
|
if not fightData.playerData.firstCamp and not fightData.enemyData[BattleLogic.CurOrder].firstCamp then
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
-- 敌方先手
|
|
|
|
|
if fightData.playerData.firstCamp == 0 and fightData.enemyData[BattleLogic.CurOrder].firstCamp == 1 then
|
|
|
|
|
BattleLogic.FirstCamp = 1
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2021-03-16 14:15:18 +08:00
|
|
|
|
function BattleLogic.InitOrder()
|
2019-03-12 14:05:45 +08:00
|
|
|
|
BattleLogic.CurOrder = BattleLogic.CurOrder + 1
|
|
|
|
|
if BattleLogic.CurOrder == 1 then
|
2020-04-16 15:10:04 +08:00
|
|
|
|
local playerData = fightData.playerData
|
|
|
|
|
local enemyData = fightData.enemyData[BattleLogic.CurOrder]
|
|
|
|
|
for i=1, #playerData do
|
2020-05-06 16:49:24 +08:00
|
|
|
|
RoleManager.AddRole(playerData[i], playerData[i].position)
|
2019-03-12 14:05:45 +08:00
|
|
|
|
end
|
2020-04-16 15:10:04 +08:00
|
|
|
|
for i=1, #enemyData do
|
2020-05-06 16:49:24 +08:00
|
|
|
|
RoleManager.AddRole(enemyData[i], enemyData[i].position)
|
2019-08-31 13:45:45 +08:00
|
|
|
|
end
|
2019-03-21 14:33:56 +08:00
|
|
|
|
|
2020-10-29 16:36:10 +08:00
|
|
|
|
|
|
|
|
|
local playerMonsterList = fightData.playerData.monsterList
|
|
|
|
|
if playerMonsterList then
|
|
|
|
|
for i=1, #playerMonsterList do
|
|
|
|
|
MonsterManager.AddMonster(playerMonsterList[i])
|
|
|
|
|
end
|
|
|
|
|
end
|
2023-04-07 16:43:05 +08:00
|
|
|
|
|
|
|
|
|
local playerWeaPonList = fightData.playerData.weaponList
|
|
|
|
|
if playerWeaPonList then
|
|
|
|
|
for i=1, #playerWeaPonList do
|
|
|
|
|
--LogError("创建一个神兵")
|
|
|
|
|
FightWeaponManager.AddWeapon(playerWeaPonList[i])
|
|
|
|
|
end
|
|
|
|
|
end
|
2020-10-29 16:36:10 +08:00
|
|
|
|
|
|
|
|
|
local enemyMonsterList = fightData.enemyData[1].monsterList
|
|
|
|
|
if enemyMonsterList then
|
|
|
|
|
for i=1, #enemyMonsterList do
|
|
|
|
|
MonsterManager.AddMonster(enemyMonsterList[i])
|
|
|
|
|
end
|
|
|
|
|
end
|
2023-04-07 16:43:05 +08:00
|
|
|
|
local enemyWeaponList = fightData.enemyData[1].weaponList
|
|
|
|
|
if enemyWeaponList then
|
|
|
|
|
for i=1, #enemyWeaponList do
|
2023-04-14 14:46:17 +08:00
|
|
|
|
--LogError("创建一个神兵")
|
2023-04-07 16:43:05 +08:00
|
|
|
|
FightWeaponManager.AddWeapon(enemyWeaponList[i])
|
|
|
|
|
end
|
|
|
|
|
end
|
2020-10-29 16:36:10 +08:00
|
|
|
|
|
2019-03-12 14:05:45 +08:00
|
|
|
|
else
|
2020-05-06 16:49:24 +08:00
|
|
|
|
RoleManager.ClearEnemy()
|
2020-04-16 15:10:04 +08:00
|
|
|
|
local orderList = fightData.enemyData[BattleLogic.CurOrder]
|
|
|
|
|
for i=1, #orderList do
|
2020-05-06 16:49:24 +08:00
|
|
|
|
RoleManager.AddRole(orderList[i], orderList[i].position)
|
2019-08-31 13:45:45 +08:00
|
|
|
|
end
|
2020-10-29 16:36:10 +08:00
|
|
|
|
|
|
|
|
|
MonsterManager.ClearEnemy()
|
|
|
|
|
local enemyMonsterList = orderList.monsterList
|
|
|
|
|
if enemyMonsterList then
|
|
|
|
|
for i=1, #enemyMonsterList do
|
2023-04-07 16:43:05 +08:00
|
|
|
|
MonsterManager.AddMonster(enemyMonsterList[i])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
FightWeaponManager.ClearEnemy()
|
|
|
|
|
local enemyWeaponList = orderList.weaponList
|
|
|
|
|
if enemyWeaponList then
|
|
|
|
|
for i=1, #enemyWeaponList do
|
|
|
|
|
--LogError("创建一个神兵")
|
|
|
|
|
FightWeaponManager.AddWeapon(enemyWeaponList[i])
|
2020-10-29 16:36:10 +08:00
|
|
|
|
end
|
|
|
|
|
end
|
2019-03-12 14:05:45 +08:00
|
|
|
|
end
|
2021-03-16 14:15:18 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function BattleLogic.StartTurnRound()
|
|
|
|
|
BattleLogic.CheckFirstCamp()-- 检测先后手
|
|
|
|
|
BattleLogic.TurnRoundNextFrame()-- 开始战斗,延时一帧执行,避免战斗还没开始就释放了技能
|
|
|
|
|
BattleLogic.Event:DispatchEvent(BattleEventName.BattleStart)-- 战斗开始
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function BattleLogic.StartOrder()
|
|
|
|
|
BattleLogic.InitOrder()
|
|
|
|
|
BattleLogic.StartTurnRound()
|
2019-03-12 14:05:45 +08:00
|
|
|
|
end
|
|
|
|
|
|
2020-04-10 14:52:41 +08:00
|
|
|
|
-- 获取当前轮数
|
|
|
|
|
function BattleLogic.GetCurRound()
|
|
|
|
|
-- body
|
|
|
|
|
return CurRound, MaxRound
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 获取当前轮次信息
|
|
|
|
|
function BattleLogic.GetCurTurn()
|
|
|
|
|
-- body
|
|
|
|
|
return CurCamp, CurSkillPos[CurCamp]
|
|
|
|
|
end
|
|
|
|
|
|
2021-08-03 17:27:36 +08:00
|
|
|
|
|
|
|
|
|
|
2020-04-10 14:52:41 +08:00
|
|
|
|
-- 设置是否是debug
|
|
|
|
|
function BattleLogic.SetIsDebug(isDebug)
|
|
|
|
|
_IsDebug = isDebug
|
|
|
|
|
end
|
|
|
|
|
function BattleLogic.GetIsDebug()
|
|
|
|
|
return _IsDebug
|
|
|
|
|
end
|
|
|
|
|
|
2020-04-21 20:51:31 +08:00
|
|
|
|
-- 下一帧开始下一轮
|
2020-05-06 16:49:24 +08:00
|
|
|
|
local _TurnRoundFlag = 0
|
2020-04-21 20:51:31 +08:00
|
|
|
|
function BattleLogic.TurnRoundNextFrame()
|
2020-05-06 16:49:24 +08:00
|
|
|
|
_TurnRoundFlag = 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 检测是否要轮转
|
|
|
|
|
function BattleLogic.CheckTurnRound()
|
|
|
|
|
if _TurnRoundFlag == 2 then
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
_TurnRoundFlag = _TurnRoundFlag + 1
|
|
|
|
|
if _TurnRoundFlag == 2 then
|
2020-04-21 20:51:31 +08:00
|
|
|
|
BattleLogic.TurnRound()
|
2020-05-06 16:49:24 +08:00
|
|
|
|
end
|
2020-04-21 20:51:31 +08:00
|
|
|
|
end
|
2020-05-06 16:49:24 +08:00
|
|
|
|
|
2020-04-10 14:52:41 +08:00
|
|
|
|
-- 开始轮转
|
|
|
|
|
-- debugTurn 用于判断是否是debug轮转的参数
|
|
|
|
|
function BattleLogic.TurnRound(debugTurn)
|
|
|
|
|
if BattleLogic.GetIsDebug() and not debugTurn then
|
|
|
|
|
BattleLogic.Event:DispatchEvent(BattleEventName.DebugStop)
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
-- 第一次进入 或者 本轮结束 初始化流程状态
|
|
|
|
|
if CurRound == 0 or (CurSkillPos[0] == 6 and CurSkillPos[1] == 6) then
|
2020-10-29 16:36:10 +08:00
|
|
|
|
if CurRound ~= 0 then
|
2021-10-22 16:59:08 +08:00
|
|
|
|
if BattleLogic.CheckHaveInsertRole() then
|
|
|
|
|
return
|
|
|
|
|
else
|
|
|
|
|
-- 上一轮结束
|
|
|
|
|
BattleLogic.Event:DispatchEvent(BattleEventName.BattleRoundEnd, CurRound)
|
|
|
|
|
end
|
2020-10-29 16:36:10 +08:00
|
|
|
|
end
|
2020-11-04 14:38:54 +08:00
|
|
|
|
-- 检测一次灵兽技能
|
|
|
|
|
SkillManager.CheckMonsterSkill(function()
|
|
|
|
|
CurRound = CurRound + 1
|
|
|
|
|
CurCamp = BattleLogic.FirstCamp -- 判断先手阵营
|
|
|
|
|
CurSkillPos[0] = 0
|
|
|
|
|
CurSkillPos[1] = 0
|
|
|
|
|
--
|
|
|
|
|
BattleLogManager.Log(
|
|
|
|
|
"Round Change",
|
|
|
|
|
"round", CurRound
|
|
|
|
|
)
|
|
|
|
|
-- 轮数变化
|
|
|
|
|
BattleLogic.Event:DispatchEvent(BattleEventName.BattleRoundChange, CurRound)
|
2020-12-10 16:32:17 +08:00
|
|
|
|
--刷新灵兽buff,回合开始前刷新,如果灵兽技能是在回合后释放,持续1回合,配置的回合数要+1 2020/12/05 by:王振兴
|
|
|
|
|
BattleLogic.BuffMgr:PassMonsterUpdate()
|
2020-11-04 14:38:54 +08:00
|
|
|
|
-- 开始
|
|
|
|
|
BattleLogic.Event:DispatchEvent(BattleEventName.BattleRoundStart, CurRound)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- 检测一次灵兽技能
|
|
|
|
|
SkillManager.CheckMonsterSkill(function()
|
|
|
|
|
--轮数变化后延时0.2秒用于初始化监听回合数被动的初始化
|
2021-12-07 18:37:27 +08:00
|
|
|
|
BattleLogic.WaitForTrigger(0.5,function()
|
2020-11-04 14:38:54 +08:00
|
|
|
|
-- 进入新轮
|
|
|
|
|
BattleLogic.CheckBattleLogic()
|
|
|
|
|
end)
|
|
|
|
|
end)
|
2020-10-29 15:36:43 +08:00
|
|
|
|
end)
|
2020-04-10 14:52:41 +08:00
|
|
|
|
else
|
2020-11-04 14:38:54 +08:00
|
|
|
|
-- 检测一次灵兽技能
|
|
|
|
|
SkillManager.CheckMonsterSkill(function()
|
|
|
|
|
--轮数变化后延时0.2秒用于初始化监听回合数被动的初始化
|
2021-12-07 18:37:27 +08:00
|
|
|
|
BattleLogic.WaitForTrigger(0.5,function()
|
2020-11-04 14:38:54 +08:00
|
|
|
|
-- 切换阵营
|
2021-08-03 17:27:36 +08:00
|
|
|
|
if not insertSkillRole then
|
|
|
|
|
CurCamp = (CurCamp + 1) % 2
|
|
|
|
|
end
|
2020-11-04 14:38:54 +08:00
|
|
|
|
BattleLogic.CheckBattleLogic()
|
|
|
|
|
end)
|
|
|
|
|
end)
|
2020-04-10 14:52:41 +08:00
|
|
|
|
end
|
2020-10-29 15:36:43 +08:00
|
|
|
|
end
|
2020-04-10 14:52:41 +08:00
|
|
|
|
|
2020-10-29 15:36:43 +08:00
|
|
|
|
--检测战斗逻辑
|
|
|
|
|
function BattleLogic.CheckBattleLogic()
|
2020-10-16 11:39:44 +08:00
|
|
|
|
-- 这里再检测一次战斗结束
|
|
|
|
|
if CurRound > MaxRound then
|
|
|
|
|
return
|
|
|
|
|
end
|
2020-10-29 16:36:10 +08:00
|
|
|
|
BattleLogManager.Log(
|
2020-06-26 00:42:16 +08:00
|
|
|
|
"Camp Change",
|
|
|
|
|
"camp", CurCamp
|
|
|
|
|
)
|
2021-08-03 17:27:36 +08:00
|
|
|
|
|
2020-05-06 16:49:24 +08:00
|
|
|
|
-- 找到下一个释放技能的人
|
|
|
|
|
local SkillRole
|
2021-08-03 17:27:36 +08:00
|
|
|
|
local lastPos
|
|
|
|
|
--如果有插入行动的英雄,就先让插入的英雄行动
|
|
|
|
|
if insertSkillRole then
|
|
|
|
|
SkillRole =insertSkillRole
|
|
|
|
|
insertSkillRole=nil
|
|
|
|
|
--记录下正常执行行动的英雄的位置,插入英雄行动完,再按照正常顺序执行
|
|
|
|
|
lastPos=CurSkillPos[CurCamp]
|
|
|
|
|
CurSkillPos[CurCamp]=SkillRole.position
|
|
|
|
|
-- 如果当前位置不能释放技能也需要走buff轮转
|
|
|
|
|
BattleLogic.BuffMgr:TurnUpdate(1) -- 计算恢复血量
|
|
|
|
|
BattleLogic.BuffMgr:TurnUpdate(2) -- 计算持续伤害(除去流血)
|
|
|
|
|
BattleLogic.BuffMgr:TurnUpdate(3) -- 计算持续伤害(流血)
|
|
|
|
|
BattleLogic.BuffMgr:TurnUpdate(4) -- 计算其他buff
|
|
|
|
|
BattleLogic.BuffMgr:PassUpdate() -- 计算buff轮数
|
|
|
|
|
BattleLogic.BuffMgr:PassUpdateNoDead() -- 计算buff不灭
|
|
|
|
|
CurSkillPos[CurCamp]=lastPos
|
|
|
|
|
end
|
|
|
|
|
if not SkillRole then
|
|
|
|
|
-- 当前阵营下一释放技能的位置
|
|
|
|
|
local cpos = CurSkillPos[CurCamp] + 1
|
|
|
|
|
for p = cpos, 6 do
|
|
|
|
|
-- 保存当前位置
|
|
|
|
|
CurSkillPos[CurCamp] = p
|
|
|
|
|
-- 自己阵营中的位置 + 自己阵营的ID * 6 = 自己在PosList中的位置
|
|
|
|
|
local role = RoleManager.GetRole(CurCamp, p) --PosList[p + (CurCamp * 6)]
|
|
|
|
|
|
|
|
|
|
--角色如果被放逐不能行动 by:wangzhenxing 2020/12/23 11:35
|
|
|
|
|
if role and not role:IsRealDead() and not role.isExile then
|
|
|
|
|
SkillRole = role
|
|
|
|
|
break
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 如果当前位置不能释放技能也需要走buff轮转
|
|
|
|
|
BattleLogic.BuffMgr:TurnUpdate(1) -- 计算恢复血量
|
|
|
|
|
BattleLogic.BuffMgr:TurnUpdate(2) -- 计算持续伤害(除去流血)
|
|
|
|
|
BattleLogic.BuffMgr:TurnUpdate(3) -- 计算持续伤害(流血)
|
|
|
|
|
BattleLogic.BuffMgr:TurnUpdate(4) -- 计算其他buff
|
|
|
|
|
BattleLogic.BuffMgr:PassUpdate() -- 计算buff轮数
|
|
|
|
|
BattleLogic.BuffMgr:PassUpdateNoDead() -- 计算buff不灭
|
2020-04-23 20:08:25 +08:00
|
|
|
|
end
|
2020-02-20 16:06:48 +08:00
|
|
|
|
end
|
2021-08-03 17:27:36 +08:00
|
|
|
|
|
2020-05-06 16:49:24 +08:00
|
|
|
|
-- 如果找不到下一个人,直接交换阵营
|
|
|
|
|
if not SkillRole then
|
2020-06-26 00:42:16 +08:00
|
|
|
|
BattleLogManager.Log( "No Skill Position" )
|
2020-05-06 16:49:24 +08:00
|
|
|
|
BattleLogic.TurnRoundNextFrame()
|
|
|
|
|
return
|
2019-11-13 19:06:21 +08:00
|
|
|
|
end
|
2020-06-26 00:42:16 +08:00
|
|
|
|
--
|
|
|
|
|
BattleLogManager.Log(
|
|
|
|
|
"Position Change",
|
|
|
|
|
"position", CurSkillPos[CurCamp]
|
|
|
|
|
)
|
2019-04-17 21:04:32 +08:00
|
|
|
|
|
2020-11-27 16:52:55 +08:00
|
|
|
|
-- 行动
|
|
|
|
|
SkillRole.Event:DispatchEvent(BattleEventName.RoleTurnStart, SkillRole) -- 开始行动
|
|
|
|
|
BattleLogic.Event:DispatchEvent(BattleEventName.RoleTurnStart, SkillRole) -- 开始行动
|
2020-07-18 21:06:17 +08:00
|
|
|
|
-- buff计算
|
|
|
|
|
BattleLogic.BuffMgr:TurnUpdate(1) -- 计算恢复血量
|
|
|
|
|
BattleLogic.BuffMgr:TurnUpdate(2) -- 计算持续伤害(除去流血)
|
2020-11-27 16:52:55 +08:00
|
|
|
|
-- 设置行动完成回调
|
|
|
|
|
SkillManager.SetTurnRoundFunc(function()
|
|
|
|
|
BattleLogic.BuffMgr:TurnUpdate(3) -- 计算持续伤害(流血)
|
|
|
|
|
BattleLogic.BuffMgr:TurnUpdate(4) -- 计算其他buff
|
|
|
|
|
BattleLogic.BuffMgr:PassUpdate() -- 计算buff轮数
|
2020-12-28 10:34:53 +08:00
|
|
|
|
BattleLogic.BuffMgr:PassUpdateNoDead() -- 计算buff不灭
|
2020-11-27 16:52:55 +08:00
|
|
|
|
SkillRole.Event:DispatchEvent(BattleEventName.RoleTurnEnd, SkillRole) -- 行动结束
|
|
|
|
|
BattleLogic.Event:DispatchEvent(BattleEventName.RoleTurnEnd, SkillRole) -- 开始行动
|
|
|
|
|
BattleLogic.TurnRoundNextFrame()
|
|
|
|
|
end)
|
2020-08-02 23:44:02 +08:00
|
|
|
|
|
2020-05-06 16:49:24 +08:00
|
|
|
|
-- 如果角色无法释放技能
|
2020-08-02 23:44:02 +08:00
|
|
|
|
if not SkillRole:IsAvailable() -- 角色不能释放技能
|
2020-11-27 16:52:55 +08:00
|
|
|
|
or (SkillRole:IsDead() -- 将死状态
|
|
|
|
|
and not BattleLogic.BuffMgr:HasBuff(SkillRole,BuffName.NoDead) --将死但没有不死buff
|
2021-03-10 11:22:03 +08:00
|
|
|
|
and not SkillManager.HaveMySkill(SkillRole)) -- 也没有要释放的技能
|
2020-08-02 23:44:02 +08:00
|
|
|
|
then
|
2020-11-27 16:52:55 +08:00
|
|
|
|
SkillManager.CheckTurnRound()
|
2020-05-06 16:49:24 +08:00
|
|
|
|
return
|
2020-04-10 14:52:41 +08:00
|
|
|
|
end
|
|
|
|
|
|
2020-05-06 16:49:24 +08:00
|
|
|
|
-- 释放技能后,递归交换阵营
|
2020-11-27 16:52:55 +08:00
|
|
|
|
SkillRole:CastSkill()
|
2019-03-21 14:33:56 +08:00
|
|
|
|
end
|
|
|
|
|
|
2021-10-22 16:59:08 +08:00
|
|
|
|
--检测是否有插入得英雄
|
|
|
|
|
function BattleLogic.CheckHaveInsertRole()
|
|
|
|
|
if insertSkillRole then
|
|
|
|
|
local SkillRole=insertSkillRole
|
|
|
|
|
insertSkillRole=nil
|
|
|
|
|
-- 如果找不到下一个人,直接交换阵营
|
|
|
|
|
if not SkillRole then
|
|
|
|
|
BattleLogManager.Log( "No Skill Position" )
|
|
|
|
|
BattleLogic.TurnRoundNextFrame()
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
--
|
|
|
|
|
BattleLogManager.Log(
|
|
|
|
|
"Position Change",
|
|
|
|
|
"position", CurSkillPos[CurCamp]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
-- 行动
|
|
|
|
|
SkillRole.Event:DispatchEvent(BattleEventName.RoleTurnStart, SkillRole) -- 开始行动
|
|
|
|
|
BattleLogic.Event:DispatchEvent(BattleEventName.RoleTurnStart, SkillRole) -- 开始行动
|
|
|
|
|
-- buff计算
|
|
|
|
|
BattleLogic.BuffMgr:TurnUpdate(1) -- 计算恢复血量
|
|
|
|
|
BattleLogic.BuffMgr:TurnUpdate(2) -- 计算持续伤害(除去流血)
|
|
|
|
|
-- 设置行动完成回调
|
|
|
|
|
SkillManager.SetTurnRoundFunc(function()
|
|
|
|
|
BattleLogic.BuffMgr:TurnUpdate(3) -- 计算持续伤害(流血)
|
|
|
|
|
BattleLogic.BuffMgr:TurnUpdate(4) -- 计算其他buff
|
|
|
|
|
BattleLogic.BuffMgr:PassUpdate() -- 计算buff轮数
|
|
|
|
|
BattleLogic.BuffMgr:PassUpdateNoDead() -- 计算buff不灭
|
|
|
|
|
SkillRole.Event:DispatchEvent(BattleEventName.RoleTurnEnd, SkillRole) -- 行动结束
|
|
|
|
|
BattleLogic.Event:DispatchEvent(BattleEventName.RoleTurnEnd, SkillRole) -- 开始行动
|
|
|
|
|
BattleLogic.TurnRoundNextFrame()
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
-- 如果角色无法释放技能
|
|
|
|
|
if not SkillRole:IsAvailable() -- 角色不能释放技能
|
|
|
|
|
or (SkillRole:IsDead() -- 将死状态
|
|
|
|
|
and not BattleLogic.BuffMgr:HasBuff(SkillRole,BuffName.NoDead) --将死但没有不死buff
|
|
|
|
|
and not SkillManager.HaveMySkill(SkillRole)) -- 也没有要释放的技能
|
|
|
|
|
then
|
|
|
|
|
SkillManager.CheckTurnRound()
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 释放技能后,递归交换阵营
|
|
|
|
|
SkillRole:CastSkill()
|
|
|
|
|
return true
|
|
|
|
|
else
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-03-12 14:05:45 +08:00
|
|
|
|
function BattleLogic.WaitForTrigger(delayTime, action)
|
2019-08-06 20:55:47 +08:00
|
|
|
|
delayTime = BattleUtil.ErrorCorrection(delayTime)
|
2019-03-23 17:06:14 +08:00
|
|
|
|
local delayFrame = floor(delayTime * BattleLogic.GameFrameRate + 0.5)
|
2019-04-18 13:25:01 +08:00
|
|
|
|
if delayFrame == 0 then --0延迟的回调直接调用
|
|
|
|
|
action()
|
|
|
|
|
return
|
|
|
|
|
end
|
2019-03-21 14:33:56 +08:00
|
|
|
|
local item = actionPool:Get()
|
2019-03-23 17:06:14 +08:00
|
|
|
|
item[1] = curFrame + delayFrame
|
2019-03-21 14:33:56 +08:00
|
|
|
|
item[2] = action
|
|
|
|
|
tbActionList:Add(item)
|
2019-03-12 14:05:45 +08:00
|
|
|
|
end
|
|
|
|
|
|
2021-08-03 17:27:36 +08:00
|
|
|
|
function BattleLogic.InsertSkillRole(role)
|
|
|
|
|
insertSkillRole=role
|
|
|
|
|
end
|
2019-07-25 16:20:33 +08:00
|
|
|
|
|
2019-03-12 14:05:45 +08:00
|
|
|
|
function BattleLogic.CurFrame()
|
|
|
|
|
return curFrame
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function BattleLogic.Update()
|
|
|
|
|
curFrame = curFrame + 1
|
2020-11-27 16:52:55 +08:00
|
|
|
|
-- 强制退出
|
|
|
|
|
if curFrame > BattleMaxFrame then
|
|
|
|
|
assert(false, "Battle Time Out !!!")
|
|
|
|
|
BattleLogic.BattleEnd(-1)
|
|
|
|
|
return
|
|
|
|
|
end
|
2023-04-07 16:43:05 +08:00
|
|
|
|
if curRoundTriggerTime>2000 then
|
|
|
|
|
--assert(false, "Battle Round Time Out !!!")
|
|
|
|
|
BattleLogic.BattleEnd(-2)
|
|
|
|
|
return
|
|
|
|
|
end
|
2020-05-06 16:49:24 +08:00
|
|
|
|
local roleResult = RoleManager.GetResult()
|
|
|
|
|
if roleResult == 0 then
|
2019-10-23 13:40:57 +08:00
|
|
|
|
BattleLogic.BattleEnd(0)
|
|
|
|
|
return
|
|
|
|
|
end
|
2020-05-07 15:53:26 +08:00
|
|
|
|
if CurRound > MaxRound then
|
2021-01-14 17:18:41 +08:00
|
|
|
|
if BattleLogic.Type == BATTLE_SERVER_TYPE.TOPFight -- 巅峰赛
|
2022-03-11 17:13:54 +08:00
|
|
|
|
or BattleLogic.Type == BATTLE_SERVER_TYPE.ArenaFight
|
2021-11-23 14:17:57 +08:00
|
|
|
|
or BattleLogic.Type == BATTLE_SERVER_TYPE.Firend
|
|
|
|
|
or BattleLogic.Type == BATTLE_SERVER_TYPE.CrossYuxuLunDaoFight
|
|
|
|
|
or BattleLogic.Type == BATTLE_SERVER_TYPE.LINGMAIMIJING
|
|
|
|
|
or BattleLogic.Type == BATTLE_SERVER_TYPE.CarPersonFight
|
|
|
|
|
or BattleLogic.Type == BATTLE_SERVER_TYPE.NewArenaFight then -- 好友切磋
|
2021-01-14 17:18:41 +08:00
|
|
|
|
if allHeroDamage>allEnemyDamage then
|
|
|
|
|
BattleLogic.BattleEnd(1)
|
|
|
|
|
else
|
|
|
|
|
BattleLogic.BattleEnd(0)
|
|
|
|
|
end
|
2020-10-16 11:39:44 +08:00
|
|
|
|
else
|
|
|
|
|
BattleLogic.BattleEnd(0)
|
|
|
|
|
end
|
2020-02-20 16:06:48 +08:00
|
|
|
|
return
|
|
|
|
|
end
|
2020-05-06 16:49:24 +08:00
|
|
|
|
if roleResult == 1 then
|
2020-02-20 16:06:48 +08:00
|
|
|
|
if BattleLogic.CurOrder == BattleLogic.TotalOrder then
|
|
|
|
|
BattleLogic.BattleEnd(1)
|
|
|
|
|
else
|
|
|
|
|
BattleLogic.Event:DispatchEvent(BattleEventName.BattleOrderChange, BattleLogic.CurOrder + 1)
|
|
|
|
|
BattleLogic.StartOrder()
|
|
|
|
|
end
|
|
|
|
|
end
|
2019-10-23 13:40:57 +08:00
|
|
|
|
|
2020-05-06 16:49:24 +08:00
|
|
|
|
-- 检测帧事件(技能命中,伤害计算,buff生成)
|
2019-04-17 21:04:32 +08:00
|
|
|
|
local index = 1
|
2019-03-21 14:33:56 +08:00
|
|
|
|
while index <= tbActionList.size do
|
2019-04-17 21:04:32 +08:00
|
|
|
|
local action = tbActionList.buffer[index]
|
|
|
|
|
if action[1] <= curFrame then
|
|
|
|
|
action[2]()
|
|
|
|
|
actionPool:Put(action)
|
2019-03-21 14:33:56 +08:00
|
|
|
|
tbActionList:Remove(index)
|
2019-03-12 14:05:45 +08:00
|
|
|
|
else
|
|
|
|
|
index = index + 1
|
|
|
|
|
end
|
|
|
|
|
end
|
2020-05-06 16:49:24 +08:00
|
|
|
|
-- 检测buff
|
2019-04-16 14:32:11 +08:00
|
|
|
|
BattleLogic.BuffMgr:Update()
|
2020-05-06 16:49:24 +08:00
|
|
|
|
---
|
|
|
|
|
-- 检测死亡
|
|
|
|
|
if RoleManager.CheckDead() then -- 单独用一帧执行死亡
|
|
|
|
|
return
|
2020-04-16 15:10:04 +08:00
|
|
|
|
end
|
2020-05-06 16:49:24 +08:00
|
|
|
|
-- 检测复活
|
|
|
|
|
if RoleManager.CheckRelive() then -- 单独用一帧执行复活
|
|
|
|
|
return
|
2019-03-12 14:05:45 +08:00
|
|
|
|
end
|
|
|
|
|
|
2021-03-10 11:22:03 +08:00
|
|
|
|
-- 没有技能释放时再检测轮转
|
|
|
|
|
if SkillManager.IsSkillEmpty() then
|
|
|
|
|
-- 检测轮转
|
|
|
|
|
BattleLogic.CheckTurnRound()
|
|
|
|
|
end
|
2020-05-06 16:49:24 +08:00
|
|
|
|
-- 技能
|
|
|
|
|
SkillManager.Update()
|
2020-10-16 11:39:44 +08:00
|
|
|
|
--如果有英雄有可以复活的技能,先执行技能逻辑,最后判断死亡人数 by:王振兴
|
|
|
|
|
-- 检测角色状态
|
|
|
|
|
RoleManager.Update()
|
2020-10-29 16:36:10 +08:00
|
|
|
|
|
|
|
|
|
-- 检测灵兽状态
|
|
|
|
|
MonsterManager.Update()
|
2020-04-16 15:10:04 +08:00
|
|
|
|
end
|
2020-05-06 16:49:24 +08:00
|
|
|
|
|
|
|
|
|
-- 战斗结束
|
|
|
|
|
function BattleLogic.BattleEnd(result)
|
2020-05-24 00:04:06 +08:00
|
|
|
|
--
|
|
|
|
|
BattleLogic.Event:DispatchEvent(BattleEventName.BeforeBattleEnd, result)
|
|
|
|
|
--
|
2020-05-06 16:49:24 +08:00
|
|
|
|
BattleLogic.IsEnd = true
|
|
|
|
|
BattleLogic.Result = result
|
|
|
|
|
BattleLogic.Event:DispatchEvent(BattleEventName.BattleEnd, result)
|
2021-05-13 14:39:44 +08:00
|
|
|
|
if hardStageId and hardStageId~=0 then
|
|
|
|
|
--获取精英副本 星级信息
|
2021-08-03 17:27:36 +08:00
|
|
|
|
local hardStageConfig=ConfigManager.GetConfigData(ConfigName.HardStage,hardStageId)
|
|
|
|
|
if hardStageConfig then
|
|
|
|
|
if hardStageConfig.ConditionValue then
|
|
|
|
|
for i = 1, #hardStageConfig.ConditionValue do
|
|
|
|
|
local harConfig = ConfigManager.GetConfigData(ConfigName.HardStageCondition,hardStageConfig.ConditionValue[i])
|
|
|
|
|
local v1 = HardStageCondition.CheckCondition(harConfig.ConditionType,harConfig.ConditionValue)
|
|
|
|
|
table.insert(levelStarRecord,hardStageConfig.ConditionValue[i])
|
|
|
|
|
table.insert(levelStarRecord,v1)
|
2023-04-21 14:45:13 +08:00
|
|
|
|
print("k=="..hardStageConfig.ConditionValue[i].." v=="..v1)
|
2021-08-03 17:27:36 +08:00
|
|
|
|
end
|
|
|
|
|
end
|
2021-05-13 14:39:44 +08:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2021-01-22 18:11:30 +08:00
|
|
|
|
-- 打印结果
|
|
|
|
|
BattleLogic.LogResult(result)
|
2020-06-26 00:42:16 +08:00
|
|
|
|
-- 战斗日志写入
|
|
|
|
|
if not BattleLogic.GetIsDebug() then
|
2020-10-16 11:39:44 +08:00
|
|
|
|
BattleLogManager.WriteLogToFile()
|
2020-06-26 00:42:16 +08:00
|
|
|
|
end
|
2021-05-13 14:39:44 +08:00
|
|
|
|
HardStageEventManager.ClearEvent()
|
2019-10-10 11:03:42 +08:00
|
|
|
|
end
|
2021-01-22 18:11:30 +08:00
|
|
|
|
|
|
|
|
|
-- 打印战斗结果
|
|
|
|
|
function BattleLogic.LogResult(result)
|
|
|
|
|
local allHeroDamage, allEnemyDamage = BattleLogic.GetAllDamage()
|
|
|
|
|
|
|
|
|
|
local heroHP = {0, 0, 0, 0, 0, 0}
|
|
|
|
|
local arr = RoleManager.Query(function (r) return r.camp == 0 end, true)
|
|
|
|
|
for i=1, #arr do
|
|
|
|
|
local pos = arr[i].position
|
|
|
|
|
heroHP[pos] = arr[i]:GetRoleData(RoleDataName.Hp)
|
|
|
|
|
end
|
|
|
|
|
local enemyHP = {0, 0, 0, 0, 0, 0}
|
|
|
|
|
local arr = RoleManager.Query(function (r) return r.camp == 1 end, true)
|
|
|
|
|
for i=1, #arr do
|
|
|
|
|
local pos = arr[i].position
|
|
|
|
|
enemyHP[pos] = arr[i]:GetRoleData(RoleDataName.Hp)
|
|
|
|
|
end
|
|
|
|
|
BattleLogManager.Log(
|
|
|
|
|
"Battle Over!!!!!!!",
|
|
|
|
|
"result", result,
|
|
|
|
|
"allHeroDamage", allHeroDamage,
|
|
|
|
|
"allEnemyDamage", allEnemyDamage,
|
|
|
|
|
"duration", BattleLogic.CurFrame() / BattleLogic.GameFrameRate,
|
|
|
|
|
"heroHP", BattleLogManager.PrintBattleTable(heroHP),
|
|
|
|
|
"enemyHP", BattleLogManager.PrintBattleTable(enemyHP)
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
2020-05-06 16:49:24 +08:00
|
|
|
|
--
|
|
|
|
|
function BattleLogic.Clear()
|
|
|
|
|
-- 清空角色
|
|
|
|
|
RoleManager.Clear()
|
2023-04-07 16:43:05 +08:00
|
|
|
|
MSkillManager.Clear()
|
2020-05-06 16:49:24 +08:00
|
|
|
|
-- 清空事件
|
|
|
|
|
while tbActionList.size > 0 do
|
|
|
|
|
actionPool:Put(tbActionList.buffer[tbActionList.size])
|
|
|
|
|
tbActionList:Remove(tbActionList.size)
|
2019-10-23 13:40:57 +08:00
|
|
|
|
end
|
|
|
|
|
end
|