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
|
2019-03-21 14:33:56 +08:00
|
|
|
|
local objList = BattleDictionary.New()
|
2019-04-17 21:04:32 +08:00
|
|
|
|
local removeObjList = BattleList.New()
|
2019-03-21 14:33:56 +08:00
|
|
|
|
|
2019-03-12 14:05:45 +08:00
|
|
|
|
local curUid
|
|
|
|
|
local curBuffId
|
|
|
|
|
local curFrame
|
|
|
|
|
|
|
|
|
|
local playerMP
|
|
|
|
|
local enemyMP
|
|
|
|
|
|
2019-03-21 14:33:56 +08:00
|
|
|
|
local playerSkillUsable
|
|
|
|
|
local enemySkillUsable
|
|
|
|
|
|
2019-08-31 13:45:45 +08:00
|
|
|
|
BattleLogic.Type = 0 --1 故事副本 2 地图探索 3 竞技场 4 秘境boss 5 解锁秘境 6 公会战 7 血战
|
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()
|
2019-03-21 14:33:56 +08:00
|
|
|
|
|
2019-10-23 13:40:57 +08:00
|
|
|
|
local playerTeamDummyRole = {camp = 0, Event = BattleEvent.New(), isTeam = true, curSkill = nil, isDebug = false}
|
|
|
|
|
local enemyTeamDummyRole = {camp = 1, Event = BattleEvent.New(), isTeam = true, curSkill = nil, isDebug = false}
|
2019-03-21 14:33:56 +08:00
|
|
|
|
local playerTeamSkillList = {}
|
|
|
|
|
local enemyTeamSkillList = {}
|
|
|
|
|
|
2019-03-12 14:05:45 +08:00
|
|
|
|
local fightData
|
|
|
|
|
local record
|
|
|
|
|
local optionRecord
|
|
|
|
|
|
|
|
|
|
--是否开启战斗日志
|
|
|
|
|
BattleLogic.IsOpenBattleRecord = false
|
|
|
|
|
--逻辑帧频
|
|
|
|
|
BattleLogic.GameFrameRate = 30
|
|
|
|
|
BattleLogic.GameDeltaTime = 1 / BattleLogic.GameFrameRate
|
|
|
|
|
--总波次
|
|
|
|
|
BattleLogic.TotalOrder = 0
|
|
|
|
|
--当前波次
|
|
|
|
|
BattleLogic.CurOrder = 0
|
|
|
|
|
|
2019-10-10 11:03:42 +08:00
|
|
|
|
local stage --战场分割阶段
|
2019-10-23 13:40:57 +08:00
|
|
|
|
local stageFrame1 = 15 * BattleLogic.GameFrameRate --前期转中期的时间点
|
|
|
|
|
local stageFrame2 = 30 * BattleLogic.GameFrameRate --中期转后期的时间点
|
|
|
|
|
local curStageFrame
|
2019-10-10 11:03:42 +08:00
|
|
|
|
|
2019-10-23 13:40:57 +08:00
|
|
|
|
local teamSkillCastTime = {7 * BattleLogic.GameFrameRate,
|
|
|
|
|
25 * BattleLogic.GameFrameRate,
|
2019-10-10 11:03:42 +08:00
|
|
|
|
55 * BattleLogic.GameFrameRate}
|
|
|
|
|
local teamSkillCastIndex
|
|
|
|
|
|
2019-05-09 17:50:38 +08:00
|
|
|
|
local maxFrame --战斗最大用时,超时判负
|
2019-07-16 10:59:40 +08:00
|
|
|
|
|
2019-03-21 14:33:56 +08:00
|
|
|
|
local actionPool = BattleObjectPool.New(function ()
|
|
|
|
|
return { 0, 0 }
|
|
|
|
|
end)
|
|
|
|
|
local skillPool = BattleObjectPool.New(function ()
|
|
|
|
|
return Skill:New()
|
|
|
|
|
end)
|
|
|
|
|
local tbActionList = BattleList.New()
|
|
|
|
|
|
|
|
|
|
local rolePool = BattleObjectPool.New(function ()
|
|
|
|
|
return RoleLogic.New()
|
|
|
|
|
end)
|
|
|
|
|
|
2019-05-09 17:50:38 +08:00
|
|
|
|
function BattleLogic.Init(maxTime, data, optionData)
|
2019-03-12 14:05:45 +08:00
|
|
|
|
if BattleLogic.IsOpenBattleRecord then
|
|
|
|
|
record = {}
|
|
|
|
|
end
|
|
|
|
|
|
2019-05-09 17:50:38 +08:00
|
|
|
|
maxFrame = BattleLogic.GameFrameRate * maxTime
|
2019-03-12 14:05:45 +08:00
|
|
|
|
fightData = data
|
|
|
|
|
if optionData then
|
|
|
|
|
optionRecord = optionData
|
|
|
|
|
else
|
|
|
|
|
optionRecord = {}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
curUid = 0
|
|
|
|
|
curBuffId = 0
|
|
|
|
|
curFrame = 0
|
2019-03-21 14:33:56 +08:00
|
|
|
|
|
2019-10-10 11:03:42 +08:00
|
|
|
|
stage = 0
|
2019-03-21 14:33:56 +08:00
|
|
|
|
|
2019-07-25 16:20:33 +08:00
|
|
|
|
playerTeamDummyRole.isDebug = false
|
2019-10-23 13:40:57 +08:00
|
|
|
|
playerTeamDummyRole.Event:ClearEvent()
|
2019-07-25 16:20:33 +08:00
|
|
|
|
enemyTeamDummyRole.isDebug = false
|
2019-10-23 13:40:57 +08:00
|
|
|
|
enemyTeamDummyRole.Event:ClearEvent()
|
2019-07-25 16:20:33 +08:00
|
|
|
|
|
2019-03-21 14:33:56 +08:00
|
|
|
|
playerSkillUsable = true
|
|
|
|
|
enemySkillUsable = true
|
|
|
|
|
|
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
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function BattleLogic.StartOrder()
|
|
|
|
|
BattleLogic.CurOrder = BattleLogic.CurOrder + 1
|
2019-10-23 13:40:57 +08:00
|
|
|
|
stage = 0
|
|
|
|
|
curStageFrame = 0
|
2019-10-10 11:03:42 +08:00
|
|
|
|
teamSkillCastIndex = 1
|
|
|
|
|
|
2019-03-12 14:05:45 +08:00
|
|
|
|
if BattleLogic.CurOrder == 1 then
|
|
|
|
|
for i=1, #fightData.playerData do
|
2019-10-10 11:03:42 +08:00
|
|
|
|
BattleLogic.AddRole(fightData.playerData[i], i)
|
2019-03-12 14:05:45 +08:00
|
|
|
|
end
|
|
|
|
|
for i=1, #fightData.enemyData[BattleLogic.CurOrder] do
|
2019-10-10 11:03:42 +08:00
|
|
|
|
BattleLogic.AddRole(fightData.enemyData[BattleLogic.CurOrder][i], i)
|
2019-03-12 14:05:45 +08:00
|
|
|
|
end
|
2019-03-21 14:33:56 +08:00
|
|
|
|
|
2019-10-21 14:25:32 +08:00
|
|
|
|
for i=1,3 do
|
|
|
|
|
if playerTeamSkillList[i] then
|
|
|
|
|
skillPool:Put(playerTeamSkillList[i])
|
|
|
|
|
playerTeamSkillList[i]=nil
|
|
|
|
|
end
|
2019-03-21 14:33:56 +08:00
|
|
|
|
end
|
|
|
|
|
for i=1, #fightData.playerData.teamSkill do
|
2019-10-21 14:25:32 +08:00
|
|
|
|
local skill = skillPool:Get()
|
|
|
|
|
skill:Init(playerTeamDummyRole, fightData.playerData.teamSkill[i], 0)
|
|
|
|
|
playerTeamSkillList[skill.cd] = skill
|
2019-03-21 14:33:56 +08:00
|
|
|
|
end
|
2019-08-31 13:45:45 +08:00
|
|
|
|
for i=1, #fightData.playerData.teamPassive do
|
|
|
|
|
for j=1, #fightData.playerData.teamPassive[i] do
|
|
|
|
|
local v = fightData.playerData.teamPassive[i][j]
|
|
|
|
|
local id = v[1]
|
|
|
|
|
local args = {}
|
|
|
|
|
for k = 2, #v do
|
|
|
|
|
args[k-1] = v[k]
|
|
|
|
|
end
|
|
|
|
|
BattleUtil.Passivity[id](playerTeamDummyRole, args)
|
|
|
|
|
end
|
|
|
|
|
end
|
2019-03-21 14:33:56 +08:00
|
|
|
|
|
2019-10-21 14:25:32 +08:00
|
|
|
|
for i=1,3 do
|
|
|
|
|
if enemyTeamSkillList[i] then
|
|
|
|
|
skillPool:Put(enemyTeamSkillList[i])
|
|
|
|
|
enemyTeamSkillList[i]=nil
|
|
|
|
|
end
|
2019-03-21 14:33:56 +08:00
|
|
|
|
end
|
|
|
|
|
for i=1, #fightData.enemyData[BattleLogic.CurOrder].teamSkill do
|
2019-10-21 14:25:32 +08:00
|
|
|
|
local skill = skillPool:Get()
|
|
|
|
|
skill:Init(enemyTeamDummyRole, fightData.enemyData[BattleLogic.CurOrder].teamSkill[i], 0)
|
|
|
|
|
enemyTeamSkillList[skill.cd] = skill
|
2019-03-21 14:33:56 +08:00
|
|
|
|
end
|
2019-08-31 13:45:45 +08:00
|
|
|
|
for i=1, #fightData.enemyData[BattleLogic.CurOrder].teamPassive do
|
|
|
|
|
for j=1, #fightData.enemyData[BattleLogic.CurOrder].teamPassive[i] do
|
|
|
|
|
local v = fightData.enemyData[BattleLogic.CurOrder].teamPassive[i][j]
|
|
|
|
|
local id = v[1]
|
|
|
|
|
local args = {}
|
|
|
|
|
for k = 2, #v do
|
|
|
|
|
args[k-1] = v[k]
|
|
|
|
|
end
|
|
|
|
|
BattleUtil.Passivity[id](enemyTeamDummyRole, args)
|
|
|
|
|
end
|
|
|
|
|
end
|
2019-03-12 14:05:45 +08:00
|
|
|
|
else
|
|
|
|
|
BattleLogic.ClearOrder()
|
|
|
|
|
for i=1, #fightData.enemyData[BattleLogic.CurOrder] do
|
2019-10-10 11:03:42 +08:00
|
|
|
|
BattleLogic.AddRole(fightData.enemyData[BattleLogic.CurOrder][i], i)
|
2019-03-12 14:05:45 +08:00
|
|
|
|
end
|
2019-03-21 14:33:56 +08:00
|
|
|
|
|
|
|
|
|
for i=1, #enemyTeamSkillList do
|
|
|
|
|
skillPool:Put(enemyTeamSkillList[i])
|
|
|
|
|
enemyTeamSkillList[i]=nil
|
|
|
|
|
end
|
|
|
|
|
for i=1, #fightData.enemyData[BattleLogic.CurOrder].teamSkill do
|
|
|
|
|
enemyTeamSkillList[i] = skillPool:Get()
|
2019-10-10 11:03:42 +08:00
|
|
|
|
enemyTeamSkillList[i]:Init(enemyTeamDummyRole, fightData.enemyData[BattleLogic.CurOrder].teamSkill[i], 0)
|
2019-03-21 14:33:56 +08:00
|
|
|
|
end
|
2019-08-31 13:45:45 +08:00
|
|
|
|
for i=1, #fightData.enemyData[BattleLogic.CurOrder].teamPassive do
|
|
|
|
|
for j=1, #fightData.enemyData[BattleLogic.CurOrder].teamPassive[i] do
|
|
|
|
|
local v = fightData.enemyData[BattleLogic.CurOrder].teamPassive[i][j]
|
|
|
|
|
local id = v[1]
|
|
|
|
|
local args = {}
|
|
|
|
|
for k = 2, #v do
|
|
|
|
|
args[k-1] = v[k]
|
|
|
|
|
end
|
|
|
|
|
BattleUtil.Passivity[id](enemyTeamDummyRole, args)
|
|
|
|
|
end
|
|
|
|
|
end
|
2019-03-12 14:05:45 +08:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-10-21 14:25:32 +08:00
|
|
|
|
function BattleLogic.GetTeamSkill(camp, pos)
|
|
|
|
|
return camp == 0 and playerTeamSkillList[pos] or enemyTeamSkillList[pos]
|
|
|
|
|
end
|
|
|
|
|
|
2019-10-23 13:40:57 +08:00
|
|
|
|
function BattleLogic.GetTeamSkillCastSlider()
|
|
|
|
|
if playerTeamDummyRole.isDebug then
|
|
|
|
|
return 0
|
|
|
|
|
end
|
|
|
|
|
local slider = (teamSkillCastTime[teamSkillCastIndex] - curStageFrame)
|
|
|
|
|
if teamSkillCastIndex == 1 then
|
|
|
|
|
slider = slider / teamSkillCastTime[teamSkillCastIndex]
|
|
|
|
|
elseif teamSkillCastIndex == 2 then
|
|
|
|
|
slider = slider / (teamSkillCastTime[teamSkillCastIndex] - stageFrame1)
|
|
|
|
|
elseif teamSkillCastIndex == 3 then
|
|
|
|
|
slider = slider / (teamSkillCastTime[teamSkillCastIndex] - stageFrame2)
|
2019-07-25 16:20:33 +08:00
|
|
|
|
end
|
2019-10-23 13:40:57 +08:00
|
|
|
|
return slider
|
2019-04-17 21:04:32 +08:00
|
|
|
|
end
|
|
|
|
|
|
2019-03-12 14:05:45 +08:00
|
|
|
|
function BattleLogic.GenerateBuffId()
|
|
|
|
|
curBuffId = curBuffId + 1
|
|
|
|
|
return curBuffId
|
|
|
|
|
end
|
|
|
|
|
|
2019-10-10 11:03:42 +08:00
|
|
|
|
function BattleLogic.AddRole(roleData, position)
|
2019-03-12 14:05:45 +08:00
|
|
|
|
curUid = curUid + 1
|
2019-06-28 11:28:45 +08:00
|
|
|
|
local role = rolePool:Get()
|
2019-10-10 11:03:42 +08:00
|
|
|
|
role:Init(curUid, roleData, position)
|
2019-06-28 11:28:45 +08:00
|
|
|
|
objList:Add(curUid, role)
|
|
|
|
|
if not role.isDead then
|
|
|
|
|
BattleLogic.Event:DispatchEvent(BattleEventName.AddRole, role)
|
2019-03-27 15:47:27 +08:00
|
|
|
|
end
|
2019-03-12 14:05:45 +08:00
|
|
|
|
end
|
|
|
|
|
|
2019-03-21 14:33:56 +08:00
|
|
|
|
function BattleLogic.SetSkillUsable(camp, value)
|
|
|
|
|
if camp == 0 then
|
|
|
|
|
playerSkillUsable = value
|
|
|
|
|
else
|
|
|
|
|
enemySkillUsable = value
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function BattleLogic.GetSkillUsable(camp)
|
|
|
|
|
if camp == 0 then
|
|
|
|
|
return playerSkillUsable
|
|
|
|
|
else
|
|
|
|
|
return enemySkillUsable
|
|
|
|
|
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-23 13:18:16 +08:00
|
|
|
|
if BattleLogic.IsOpenBattleRecord then
|
2019-03-23 17:06:14 +08:00
|
|
|
|
BattleLogic.RecordDelayTrigger(delayTime, curFrame + delayFrame)
|
2019-03-23 13:18:16 +08:00
|
|
|
|
end
|
2019-03-12 14:05:45 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function BattleLogic.AddOption(opType, opArg)
|
|
|
|
|
table.insert(optionRecord, {curFrame + 1, opType, opArg})
|
|
|
|
|
end
|
|
|
|
|
|
2019-07-25 16:20:33 +08:00
|
|
|
|
function BattleLogic.GetTeamSkillCaster(camp)
|
|
|
|
|
return camp == 0 and playerTeamDummyRole or enemyTeamDummyRole
|
|
|
|
|
end
|
|
|
|
|
|
2019-03-12 14:05:45 +08:00
|
|
|
|
function BattleLogic.HasObj(obj)
|
2019-03-21 14:33:56 +08:00
|
|
|
|
return obj and objList.kvList[obj.uid]
|
2019-03-12 14:05:45 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function BattleLogic.CurFrame()
|
|
|
|
|
return curFrame
|
|
|
|
|
end
|
|
|
|
|
|
2019-10-10 11:03:42 +08:00
|
|
|
|
function BattleLogic.CurStage()
|
|
|
|
|
return stage
|
|
|
|
|
end
|
|
|
|
|
|
2019-10-23 13:40:57 +08:00
|
|
|
|
--表现层调用,显示每个阶段剩余时间百分比
|
|
|
|
|
function BattleLogic.CurStageSlider()
|
|
|
|
|
local slider = 0
|
|
|
|
|
if stage == 1 then
|
|
|
|
|
slider = (stageFrame1 - curStageFrame) / stageFrame1
|
|
|
|
|
elseif stage == 2 then
|
|
|
|
|
slider = (stageFrame2 - curStageFrame) / (stageFrame2 - stageFrame1)
|
|
|
|
|
elseif stage == 3 then
|
|
|
|
|
slider = (maxFrame / BattleLogic.TotalOrder - curStageFrame) / (maxFrame / BattleLogic.TotalOrder - stageFrame2)
|
|
|
|
|
end
|
|
|
|
|
return slider
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--表现层调用,显示每个阶段剩余时间
|
2019-10-10 11:03:42 +08:00
|
|
|
|
function BattleLogic.CurStageTime()
|
|
|
|
|
local time = 0
|
|
|
|
|
if stage == 1 then
|
2019-10-23 13:40:57 +08:00
|
|
|
|
time = (stageFrame1 - curStageFrame) / BattleLogic.GameFrameRate
|
2019-10-10 11:03:42 +08:00
|
|
|
|
elseif stage == 2 then
|
2019-10-23 13:40:57 +08:00
|
|
|
|
time = (stageFrame2 - curStageFrame) / BattleLogic.GameFrameRate
|
|
|
|
|
elseif stage == 3 then
|
|
|
|
|
time = (maxFrame / BattleLogic.TotalOrder - curStageFrame) / BattleLogic.GameFrameRate
|
2019-10-10 11:03:42 +08:00
|
|
|
|
end
|
|
|
|
|
return time
|
|
|
|
|
end
|
|
|
|
|
|
2019-04-20 17:21:45 +08:00
|
|
|
|
function BattleLogic.Query(func, inCludeDeadRole)
|
2019-03-22 18:36:24 +08:00
|
|
|
|
local list = {}
|
2019-03-12 14:05:45 +08:00
|
|
|
|
local index = 1
|
|
|
|
|
if func then
|
2019-03-21 14:33:56 +08:00
|
|
|
|
for i=1, objList.size do
|
|
|
|
|
local v = objList.vList[i]
|
2019-04-20 17:21:45 +08:00
|
|
|
|
if func(v) and (inCludeDeadRole or not v.isDead) then
|
2019-03-12 14:05:45 +08:00
|
|
|
|
list[index] = v
|
|
|
|
|
index = index + 1
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return list
|
|
|
|
|
end
|
|
|
|
|
|
2019-03-21 14:33:56 +08:00
|
|
|
|
function BattleLogic.BattleEnd(result)
|
|
|
|
|
BattleLogic.IsEnd = true
|
|
|
|
|
BattleLogic.Result = result
|
|
|
|
|
BattleLogic.Event:DispatchEvent(BattleEventName.BattleEnd, result)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function BattleLogic.Clear()
|
2019-03-22 11:00:12 +08:00
|
|
|
|
while objList.size > 0 do
|
2019-04-17 21:04:32 +08:00
|
|
|
|
objList.vList[objList.size]:Dispose()
|
|
|
|
|
removeObjList:Add(objList.vList[objList.size])
|
|
|
|
|
objList:Remove(objList.vList[objList.size].uid)
|
|
|
|
|
end
|
|
|
|
|
while removeObjList.size > 0 do
|
|
|
|
|
rolePool:Put(removeObjList.buffer[removeObjList.size])
|
|
|
|
|
removeObjList:Remove(removeObjList.size)
|
2019-03-21 14:33:56 +08:00
|
|
|
|
end
|
2019-03-22 11:00:12 +08:00
|
|
|
|
while tbActionList.size > 0 do
|
|
|
|
|
actionPool:Put(tbActionList.buffer[tbActionList.size])
|
|
|
|
|
tbActionList:Remove(tbActionList.size)
|
2019-03-21 14:33:56 +08:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-03-12 14:05:45 +08:00
|
|
|
|
function BattleLogic.ClearOrder()
|
|
|
|
|
local index = 1
|
2019-03-22 11:00:12 +08:00
|
|
|
|
while index <= objList.size do
|
2019-03-21 14:33:56 +08:00
|
|
|
|
if objList.vList[index].camp == 1 then
|
2019-04-17 21:04:32 +08:00
|
|
|
|
BattleLogic.Event:DispatchEvent(BattleEventName.RemoveRole, objList.vList[index])
|
|
|
|
|
objList.vList[index]:Dispose()
|
|
|
|
|
removeObjList:Add(objList.vList[index])
|
|
|
|
|
objList:Remove(objList.vList[index].uid)
|
2019-03-12 14:05:45 +08:00
|
|
|
|
else
|
|
|
|
|
index = index + 1
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function BattleLogic.Update()
|
|
|
|
|
curFrame = curFrame + 1
|
2019-10-23 13:40:57 +08:00
|
|
|
|
if curFrame > maxFrame then
|
|
|
|
|
BattleLogic.BattleEnd(0)
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
curStageFrame = curStageFrame + 1
|
|
|
|
|
|
|
|
|
|
if curStageFrame > 0 and stage == 0 then
|
|
|
|
|
stage = 1
|
|
|
|
|
BattleLogic.Event:DispatchEvent(BattleEventName.BattleStageChange, stage)
|
|
|
|
|
end
|
|
|
|
|
if curStageFrame > stageFrame1 and stage == 1 then
|
2019-10-10 11:03:42 +08:00
|
|
|
|
stage = 2
|
|
|
|
|
BattleLogic.Event:DispatchEvent(BattleEventName.BattleStageChange, stage)
|
|
|
|
|
end
|
2019-10-23 13:40:57 +08:00
|
|
|
|
if curStageFrame > stageFrame2 and stage == 2 then
|
2019-10-10 11:03:42 +08:00
|
|
|
|
stage = 3
|
|
|
|
|
BattleLogic.Event:DispatchEvent(BattleEventName.BattleStageChange, stage)
|
|
|
|
|
end
|
|
|
|
|
|
2019-10-23 13:40:57 +08:00
|
|
|
|
if teamSkillCastIndex <= #teamSkillCastTime and curStageFrame > teamSkillCastTime[teamSkillCastIndex] then
|
2019-10-21 14:25:32 +08:00
|
|
|
|
if not playerTeamDummyRole.isDebug and playerTeamSkillList[teamSkillCastIndex] then
|
|
|
|
|
playerTeamSkillList[teamSkillCastIndex]:Cast()
|
2019-03-12 14:05:45 +08:00
|
|
|
|
end
|
2019-10-21 14:25:32 +08:00
|
|
|
|
if not enemyTeamDummyRole.isDebug and enemyTeamSkillList[teamSkillCastIndex] then
|
|
|
|
|
enemyTeamSkillList[teamSkillCastIndex]:Cast()
|
2019-10-23 13:40:57 +08:00
|
|
|
|
end
|
2019-10-21 14:25:32 +08:00
|
|
|
|
teamSkillCastIndex = teamSkillCastIndex + 1
|
2019-07-15 19:25:22 +08:00
|
|
|
|
end
|
|
|
|
|
|
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
|
|
|
|
|
|
2019-04-16 14:32:11 +08:00
|
|
|
|
BattleLogic.BuffMgr:Update()
|
|
|
|
|
|
2019-04-17 21:04:32 +08:00
|
|
|
|
local bMyAllDead = true
|
|
|
|
|
local bEnemyAllDead = true
|
2019-03-21 14:33:56 +08:00
|
|
|
|
for i=1, objList.size do
|
2019-04-17 21:04:32 +08:00
|
|
|
|
local tmpObj = objList.vList[i]
|
2019-03-12 14:05:45 +08:00
|
|
|
|
if not tmpObj.isDead then
|
|
|
|
|
tmpObj:Update()
|
|
|
|
|
if tmpObj.camp == 0 then
|
|
|
|
|
bMyAllDead = false
|
|
|
|
|
else
|
|
|
|
|
bEnemyAllDead = false
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if bMyAllDead then
|
2019-03-21 14:33:56 +08:00
|
|
|
|
BattleLogic.BattleEnd(0)
|
2019-10-23 13:40:57 +08:00
|
|
|
|
return
|
2019-03-12 14:05:45 +08:00
|
|
|
|
end
|
|
|
|
|
if bEnemyAllDead then
|
|
|
|
|
if BattleLogic.CurOrder == BattleLogic.TotalOrder then
|
2019-03-21 14:33:56 +08:00
|
|
|
|
BattleLogic.BattleEnd(1)
|
2019-03-12 14:05:45 +08:00
|
|
|
|
else
|
2019-04-04 14:36:07 +08:00
|
|
|
|
BattleLogic.Event:DispatchEvent(BattleEventName.BattleOrderChange, BattleLogic.CurOrder + 1)
|
2019-03-12 14:05:45 +08:00
|
|
|
|
BattleLogic.StartOrder()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-10-10 11:03:42 +08:00
|
|
|
|
local posDic = {3,2,4,1,5}
|
|
|
|
|
--对位规则: 1敌方相同对位 2若死亡或不存在,选取相邻阵位最近且阵位索引最小的
|
2019-10-23 13:40:57 +08:00
|
|
|
|
function BattleLogic.GetAggro(role)
|
2019-10-10 11:03:42 +08:00
|
|
|
|
local minNeighbor = 100
|
|
|
|
|
local index = 100
|
|
|
|
|
local target
|
2019-10-23 13:40:57 +08:00
|
|
|
|
local enemyCamp = role.camp == 0 and 1 or 0
|
2019-10-10 11:03:42 +08:00
|
|
|
|
for i=1, objList.size do
|
|
|
|
|
if objList.vList[i].camp == enemyCamp and not objList.vList[i].isDead then
|
2019-10-23 13:40:57 +08:00
|
|
|
|
if role.position == objList.vList[i].position then
|
2019-10-10 11:03:42 +08:00
|
|
|
|
return objList.vList[i]
|
|
|
|
|
else
|
2019-10-23 13:40:57 +08:00
|
|
|
|
local neighbor = math.abs(posDic[role.position] - posDic[objList.vList[i].position])
|
2019-10-10 11:03:42 +08:00
|
|
|
|
if neighbor < minNeighbor then
|
|
|
|
|
minNeighbor = neighbor
|
|
|
|
|
index = objList.vList[i].position
|
|
|
|
|
target = objList.vList[i]
|
|
|
|
|
elseif neighbor == minNeighbor and objList.vList[i].position < index then
|
|
|
|
|
minNeighbor = neighbor
|
|
|
|
|
index = objList.vList[i].position
|
|
|
|
|
target = objList.vList[i]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return target
|
|
|
|
|
end
|
2019-10-23 13:40:57 +08:00
|
|
|
|
--获取对位相邻站位的人 chooseType 1 我方 2 敌方(若对位的敌人死亡,则选取相邻最近的作为目标)
|
|
|
|
|
function BattleLogic.GetNeighbor(role, chooseType)
|
|
|
|
|
local posList = {}
|
|
|
|
|
local target = chooseType == 1 and role or BattleLogic.GetAggro(role)
|
|
|
|
|
local list = BattleUtil.ChooseTarget(target, 10000)
|
|
|
|
|
for i=1, #list do
|
|
|
|
|
if not list[i].isDead and math.abs(posDic[target.position] - posDic[list[i].position]) <= 1 then
|
|
|
|
|
table.insert(posList, list[i])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return posList
|
|
|
|
|
end
|
2019-10-10 11:03:42 +08:00
|
|
|
|
|
2019-07-25 16:20:33 +08:00
|
|
|
|
function BattleLogic.ResetTeamSkillCD(camp)
|
|
|
|
|
local skill = camp == 0 and playerTeamDummyRole.curSkill or enemyTeamDummyRole.curSkill
|
|
|
|
|
if skill then
|
|
|
|
|
skill.spPass = floor(skill.cd % 100 * BattleLogic.GameFrameRate)
|
|
|
|
|
skill.sp = skill.spPass
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function BattleLogic.CastTeamSkill(camp)
|
|
|
|
|
if camp == 0 then
|
2019-10-21 14:25:32 +08:00
|
|
|
|
local teamSkill = playerTeamSkillList[teamSkillCastIndex]
|
2019-07-25 16:20:33 +08:00
|
|
|
|
if teamSkill then
|
|
|
|
|
teamSkill:Cast()
|
|
|
|
|
end
|
|
|
|
|
else
|
2019-10-21 14:25:32 +08:00
|
|
|
|
local teamSkill = enemyTeamSkillList[teamSkillCastIndex]
|
2019-07-25 16:20:33 +08:00
|
|
|
|
if teamSkill then
|
|
|
|
|
teamSkill:Cast()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-03-12 14:05:45 +08:00
|
|
|
|
--Debug专用
|
|
|
|
|
function BattleLogic.SetDebug()
|
2019-03-21 14:33:56 +08:00
|
|
|
|
for i=1, objList.size do
|
2019-04-17 21:04:32 +08:00
|
|
|
|
local v = objList.vList[i]
|
2019-03-12 14:05:45 +08:00
|
|
|
|
v.IsDebug = not v.IsDebug
|
|
|
|
|
end
|
2019-07-25 16:20:33 +08:00
|
|
|
|
playerTeamDummyRole.isDebug = not playerTeamDummyRole.isDebug
|
|
|
|
|
enemyTeamDummyRole.isDebug = not enemyTeamDummyRole.isDebug
|
2019-03-12 14:05:45 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--Debug专用
|
|
|
|
|
function BattleLogic.SetRoleValue(uid, name, value)
|
2019-03-21 14:33:56 +08:00
|
|
|
|
if objList.kvList[uid] then
|
|
|
|
|
objList.kvList[uid].data:SetValue(name, value)
|
2019-03-12 14:05:45 +08:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--Debug专用
|
|
|
|
|
function BattleLogic.SetRoleDebug(uid, isDebug)
|
2019-03-21 14:33:56 +08:00
|
|
|
|
if objList.kvList[uid] then
|
|
|
|
|
objList.kvList[uid].IsDebug = isDebug
|
2019-03-12 14:05:45 +08:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-03-21 17:24:21 +08:00
|
|
|
|
--Record专用
|
|
|
|
|
function BattleLogic.GetRecord()
|
|
|
|
|
return record
|
|
|
|
|
end
|
|
|
|
|
|
2019-03-12 14:05:45 +08:00
|
|
|
|
--Record专用
|
|
|
|
|
function BattleLogic.RecordSeed(seed)
|
|
|
|
|
table.insert(record, string.format("frame:%d, seed:%d", curFrame, seed))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--Record专用
|
|
|
|
|
function BattleLogic.RecordRoleProperty(uid, camp, name, value, delta)
|
|
|
|
|
table.insert(record, string.format("frame:%d, uid:%d, camp:%d, name:%s, value:%d, delta:%d", curFrame, uid, camp, name, value, delta))
|
|
|
|
|
end
|
|
|
|
|
|
2019-08-06 20:55:47 +08:00
|
|
|
|
--Record专用
|
|
|
|
|
function BattleLogic.RecordDamage(args)
|
|
|
|
|
local str = ""
|
|
|
|
|
for i=1, #args do
|
|
|
|
|
str = str..tostring(args[i]) .. (i == #args and "" or "#")
|
|
|
|
|
end
|
|
|
|
|
table.insert(record, string.format("frame:%d, damageArgs:%s", curFrame, str))
|
|
|
|
|
end
|
|
|
|
|
|
2019-03-22 18:36:24 +08:00
|
|
|
|
--Record专用
|
|
|
|
|
function BattleLogic.RecordEffect(caster, target, type, args, interval)
|
|
|
|
|
local cUid = tostring(caster.uid) or "cTeam"
|
|
|
|
|
local tUid = tostring(target.uid) or "tTeam"
|
|
|
|
|
local str = ""
|
|
|
|
|
for i=1, #args do
|
|
|
|
|
str = str..tostring(args[i]) .. (i == #args and "" or "#")
|
|
|
|
|
end
|
|
|
|
|
table.insert(record, string.format("frame:%d, caster:%s, target:%s, effectType:%d, args:%s, interval:%d", curFrame, cUid, tUid, type, str, interval))
|
|
|
|
|
end
|
|
|
|
|
|
2019-03-23 13:18:16 +08:00
|
|
|
|
--Record专用
|
|
|
|
|
function BattleLogic.RecordDelayTrigger(delayFrame, triggerFrame)
|
2019-03-23 17:06:14 +08:00
|
|
|
|
table.insert(record, string.format("frame:%d, delayTime:%f, triggerFrame:%d", curFrame, delayFrame, triggerFrame))
|
2019-03-23 13:18:16 +08:00
|
|
|
|
end
|
|
|
|
|
|
2019-03-12 14:05:45 +08:00
|
|
|
|
--Record专用
|
|
|
|
|
function BattleLogic.GenerateRecordFile()
|
|
|
|
|
local time = string.format("%d-%d-%d-%d-%d-%d",
|
|
|
|
|
os.date("%Y"),
|
|
|
|
|
os.date("%m"),
|
|
|
|
|
os.date("%d"),
|
|
|
|
|
os.date("%H"),
|
|
|
|
|
os.date("%M"),
|
|
|
|
|
os.date("%S"))
|
|
|
|
|
local file = io.open("BattleRecord/"..time..".txt", "a")
|
|
|
|
|
for i=1, #record do
|
|
|
|
|
file:write(record[i].."\n")
|
|
|
|
|
end
|
|
|
|
|
io.close(file)
|
|
|
|
|
end
|