miduo_server/luafight/Modules/Battle/Logic/BattleLogic.lua

781 lines
23 KiB
Lua
Raw Normal View History

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()
2019-03-21 14:33:56 +08:00
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 curUid
local curBuffId
local curFrame
2019-03-21 14:33:56 +08:00
local playerSkillUsable
local enemySkillUsable
2020-02-20 16:06:48 +08:00
local bMyAllDead
local bEnemyAllDead
2019-12-31 16:35:42 +08:00
BattleLogic.Type = 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()
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 = {}
2020-04-10 14:52:41 +08:00
local _IsDebug
2019-03-12 14:05:45 +08:00
local fightData
local record
local optionRecord
--是否开启战斗日志
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
2020-04-10 14:52:41 +08:00
local teamSkillCastRound = {2, 4, 6}
local MyTeamSkillCastIndex
local EnemyTeamSkillCastIndex
2019-10-10 11:03:42 +08:00
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)
2020-04-10 14:52:41 +08:00
function BattleLogic.Init(data, optionData)
2019-03-12 14:05:45 +08:00
if BattleLogic.IsOpenBattleRecord then
record = {}
end
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
2020-04-10 14:52:41 +08:00
CurRound = 0
2019-03-21 14:33:56 +08:00
2020-04-10 14:52:41 +08:00
_IsDebug = false
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
2020-02-20 16:06:48 +08:00
bMyAllDead = false
bEnemyAllDead = 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
end
function BattleLogic.StartOrder()
2020-04-10 14:52:41 +08:00
--
2019-03-12 14:05:45 +08:00
BattleLogic.CurOrder = BattleLogic.CurOrder + 1
if BattleLogic.CurOrder == 1 then
2020-04-10 14:52:41 +08:00
MyTeamSkillCastIndex = 1
EnemyTeamSkillCastIndex = 1
2020-04-16 15:10:04 +08:00
local playerData = fightData.playerData
local enemyData = fightData.enemyData[BattleLogic.CurOrder]
for i=1, #playerData do
BattleLogic.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
BattleLogic.AddRole(enemyData[i], enemyData[i].position)
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
2020-04-16 15:10:04 +08:00
for i=1, #playerData.teamSkill do
2019-10-21 14:25:32 +08:00
local skill = skillPool:Get()
2020-04-16 15:10:04 +08:00
skill:Init(playerTeamDummyRole, playerData.teamSkill[i], 0)
2020-04-10 14:52:41 +08:00
playerTeamSkillList[i] = skill
2019-03-21 14:33:56 +08:00
end
2020-04-16 15:10:04 +08:00
for i=1, #playerData.teamPassive do
for j=1, #playerData.teamPassive[i] do
local v = playerData.teamPassive[i][j]
2019-08-31 13:45:45 +08:00
local id = v[1]
local args = {}
for k = 2, #v do
args[k-1] = v[k]
end
2020-02-20 16:06:48 +08:00
BattleLogic.TakeTeamPassivity(playerTeamDummyRole, id, args)
2019-08-31 13:45:45 +08:00
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
2020-04-16 15:10:04 +08:00
for i=1, #enemyData.teamSkill do
2019-10-21 14:25:32 +08:00
local skill = skillPool:Get()
2020-04-16 15:10:04 +08:00
skill:Init(enemyTeamDummyRole, enemyData.teamSkill[i], 0)
2020-04-10 14:52:41 +08:00
enemyTeamSkillList[i] = skill
2019-03-21 14:33:56 +08:00
end
2020-04-16 15:10:04 +08:00
for i=1, #enemyData.teamPassive do
for j=1, #enemyData.teamPassive[i] do
local v = enemyData.teamPassive[i][j]
2019-08-31 13:45:45 +08:00
local id = v[1]
local args = {}
for k = 2, #v do
args[k-1] = v[k]
end
2020-02-20 16:06:48 +08:00
BattleLogic.TakeTeamPassivity(enemyTeamDummyRole, id, args)
2019-08-31 13:45:45 +08:00
end
end
2019-03-12 14:05:45 +08:00
else
BattleLogic.ClearOrder()
2020-04-16 15:10:04 +08:00
local orderList = fightData.enemyData[BattleLogic.CurOrder]
for i=1, #orderList do
BattleLogic.AddRole(orderList[i], orderList[i].position)
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
2020-04-16 15:10:04 +08:00
for i=1, #orderList.teamSkill do
2019-10-27 14:56:13 +08:00
local skill = skillPool:Get()
2020-04-16 15:10:04 +08:00
skill:Init(enemyTeamDummyRole, orderList.teamSkill[i], 0)
2020-04-10 14:52:41 +08:00
enemyTeamSkillList[i] = skill
2019-03-21 14:33:56 +08:00
end
2020-04-16 15:10:04 +08:00
for i=1, #orderList.teamPassive do
for j=1, #orderList.teamPassive[i] do
local v = orderList.teamPassive[i][j]
2019-08-31 13:45:45 +08:00
local id = v[1]
local args = {}
for k = 2, #v do
args[k-1] = v[k]
end
2020-02-20 16:06:48 +08:00
BattleLogic.TakeTeamPassivity(enemyTeamDummyRole, id, args)
2019-08-31 13:45:45 +08:00
end
end
2019-03-12 14:05:45 +08:00
end
2020-04-10 14:52:41 +08:00
-- 开始战斗,延时一帧执行,避免战斗还没开始就释放了技能
2020-04-21 20:51:31 +08:00
BattleLogic.TurnRoundNextFrame()
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
-- 设置是否是debug
function BattleLogic.SetIsDebug(isDebug)
_IsDebug = isDebug
end
function BattleLogic.GetIsDebug()
return _IsDebug
end
2020-04-21 20:51:31 +08:00
-- 下一帧开始下一轮
function BattleLogic.TurnRoundNextFrame()
BattleLogic.WaitForTrigger(BattleLogic.GameDeltaTime, function()
BattleLogic.TurnRound()
end)
end
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
CurRound = CurRound + 1
CurCamp = 0
CurSkillPos[0] = -1 -- 先从异妖开始检测
CurSkillPos[1] = -1
-- 轮数变化
BattleLogic.Event:DispatchEvent(BattleEventName.BattleRoundChange, CurRound)
else
-- 切换阵营
CurCamp = (CurCamp + 1) % 2
end
-- 当前阵营下一释放技能的位置
local cpos = CurSkillPos[CurCamp] + 1
if cpos == 0 then
-- 保存当前释放技能的位置
CurSkillPos[CurCamp] = cpos
2020-04-17 20:02:49 +08:00
-- 刷新异妖buff轮数暂时不用
-- BattleLogic.BuffMgr:PassUpdate()
2020-04-10 14:52:41 +08:00
-- 检测异妖技能释放
BattleLogic.CheckTeamSkillCast(CurCamp)
else
-- 找到下一个释放技能的人
local SkillRole
for p = cpos, 6 do
-- 保存当前位置
CurSkillPos[CurCamp] = p
-- 自己阵营中的位置 + 自己阵营的ID * 6 = 自己在PosList中的位置
local role = PosList[p + (CurCamp * 6)]
2020-04-21 20:51:31 +08:00
if role and not role.isDead then
2020-04-10 14:52:41 +08:00
SkillRole = role
break
end
-- 如果当前位置不能释放技能也需要走buff轮转
BattleLogic.BuffMgr:TurnUpdate(1) -- 计算恢复血量
BattleLogic.BuffMgr:TurnUpdate(2) -- 计算持续伤害(除去流血)
BattleLogic.BuffMgr:TurnUpdate(3) -- 计算持续伤害(流血)
BattleLogic.BuffMgr:TurnUpdate(4) -- 计算其他buff
2020-04-21 20:51:31 +08:00
BattleLogic.BuffMgr:PassUpdate() -- 计算buff轮数
2020-04-10 14:52:41 +08:00
end
-- 如果找不到下一个人,直接交换阵营
if not SkillRole then
2020-04-21 20:51:31 +08:00
BattleLogic.TurnRoundNextFrame()
2020-04-10 14:52:41 +08:00
return
2020-02-20 16:06:48 +08:00
end
2020-04-10 14:52:41 +08:00
2020-04-23 20:08:25 +08:00
-- 如果角色无法释放技能
if not SkillRole:IsAvailable() then
BattleLogic.BuffMgr:TurnUpdate(1) -- 计算恢复血量
BattleLogic.BuffMgr:TurnUpdate(2) -- 计算持续伤害(除去流血)
BattleLogic.BuffMgr:TurnUpdate(3) -- 计算持续伤害(流血)
BattleLogic.BuffMgr:TurnUpdate(4) -- 计算其他buff
BattleLogic.BuffMgr:PassUpdate() -- 计算buff轮数
BattleLogic.TurnRoundNextFrame() -- 下一个
return
end
-- 行动
2020-04-17 20:02:49 +08:00
SkillRole.Event:DispatchEvent(BattleEventName.RoleTurnStart) -- 开始行动
2020-04-10 14:52:41 +08:00
BattleLogic.BuffMgr:TurnUpdate(1) -- 计算恢复血量
BattleLogic.BuffMgr:TurnUpdate(2) -- 计算持续伤害(除去流血)
-- 释放技能后,递归交换阵营
SkillRole:CastSkill(function()
BattleLogic.BuffMgr:TurnUpdate(3) -- 计算持续伤害(流血)
BattleLogic.BuffMgr:TurnUpdate(4) -- 计算其他buff
2020-04-21 20:51:31 +08:00
BattleLogic.BuffMgr:PassUpdate() -- 计算buff轮数
2020-04-17 20:02:49 +08:00
SkillRole.Event:DispatchEvent(BattleEventName.RoleTurnEnd) -- 行动结束
2020-04-21 20:51:31 +08:00
BattleLogic.TurnRoundNextFrame()
2020-04-10 14:52:41 +08:00
end)
2020-02-20 16:06:48 +08:00
end
end
2020-04-10 14:52:41 +08:00
-- 触发异妖被动
function BattleLogic.TakeTeamPassivity(teamCaster, id, args)
2020-04-16 15:10:04 +08:00
for _, v in pairs(PosList) do
2020-04-10 14:52:41 +08:00
BattleUtil.Passivity[id](v, args)
2020-04-16 15:10:04 +08:00
end
-- objList:Foreach(function(k, v)
-- BattleUtil.Passivity[id](v, args)
-- end)
2020-04-10 14:52:41 +08:00
end
-- 获取当前等待释放技能的异妖的序号
function BattleLogic.GetTeamSkillCastIndex(camp)
-- body
if camp == 0 then
return MyTeamSkillCastIndex
else
return EnemyTeamSkillCastIndex
end
end
-- 获取异妖
2019-10-21 14:25:32 +08:00
function BattleLogic.GetTeamSkill(camp, pos)
2019-11-13 19:06:21 +08:00
if camp == 0 then
return playerTeamSkillList[pos]
else
return enemyTeamSkillList[pos]
end
2019-10-21 14:25:32 +08:00
end
2020-04-10 14:52:41 +08:00
-- 获取异妖技能CD
function BattleLogic.GetTeamSkillCastSlider(camp)
local teamSkillCastIndex = BattleLogic.GetTeamSkillCastIndex(camp)
if playerTeamDummyRole.isDebug or teamSkillCastIndex > #teamSkillCastRound then
2019-10-23 13:40:57 +08:00
return 0
end
2020-04-10 14:52:41 +08:00
local slider = 0
2019-10-23 13:40:57 +08:00
if teamSkillCastIndex == 1 then
2020-04-10 14:52:41 +08:00
slider = CurRound / teamSkillCastRound[teamSkillCastIndex]
else
slider = (CurRound - teamSkillCastRound[teamSkillCastIndex - 1]) / (teamSkillCastRound[teamSkillCastIndex] - teamSkillCastRound[teamSkillCastIndex - 1])
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
2020-04-10 14:52:41 +08:00
-- 检测异妖技能是否可以释放
function BattleLogic.CheckTeamSkillCast(camp)
local teamSkillCastIndex = BattleLogic.GetTeamSkillCastIndex(camp)
local teamSkillList = camp == 0 and playerTeamSkillList or enemyTeamSkillList
if teamSkillList[teamSkillCastIndex] then
if teamSkillCastIndex <= #teamSkillCastRound and CurRound >= teamSkillCastRound[teamSkillCastIndex] then
2020-04-21 20:51:31 +08:00
teamSkillList[teamSkillCastIndex]:Cast(BattleLogic.TurnRoundNextFrame)
2020-04-10 14:52:41 +08:00
if camp == 0 then
MyTeamSkillCastIndex = MyTeamSkillCastIndex + 1
else
EnemyTeamSkillCastIndex = EnemyTeamSkillCastIndex + 1
end
return
end
end
-- 没有要释放技能的异妖,切换阵营
2020-04-21 20:51:31 +08:00
BattleLogic.TurnRoundNextFrame()
2020-04-10 14:52:41 +08:00
end
2019-03-12 14:05:45 +08:00
function BattleLogic.GenerateBuffId()
2020-04-10 14:52:41 +08:00
if not curBuffId then
curBuffId = 0
end
2019-03-12 14:05:45 +08:00
curBuffId = curBuffId + 1
return curBuffId
end
2020-04-10 14:52:41 +08:00
-- 角色数据添加
2019-10-10 11:03:42 +08:00
function BattleLogic.AddRole(roleData, position)
2020-04-10 14:52:41 +08:00
if not curUid then
curUid = 0
end
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)
2020-04-16 15:10:04 +08:00
-- objList:Add(curUid, role)
2020-04-10 14:52:41 +08:00
if roleData.camp == 0 then
PosList[position] = role -- 1-6 我方英雄
else
PosList[position + 6] = role-- 7-12 敌方英雄
end
2019-06-28 11:28:45 +08:00
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
2020-04-10 14:52:41 +08:00
-- 获取角色数据
function BattleLogic.GetRole(camp, pos)
return PosList[pos + camp*6]
end
-- 获取某阵营所有角色
function BattleLogic.GetRoleByCamp(camp)
local list = {}
for i = 1, 6 do
list[i] = PosList[i + camp * 6]
end
return list
end
2019-03-12 14:05:45 +08:00
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.CurFrame()
return curFrame
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
2020-04-16 15:10:04 +08:00
for pos, v in pairs(PosList) do
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
2020-04-16 15:10:04 +08:00
end
-- objList:Foreach(function(k, v)
-- if func(v) and (inCludeDeadRole or not v.isDead) then
-- list[index] = v
-- index = index + 1
-- end
-- end)
2019-03-12 14:05:45 +08:00
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()
2020-04-16 15:10:04 +08:00
-- while objList.size > 0 do
-- objList.vList[objList.size]:Dispose()
-- removeObjList:Add(objList.vList[objList.size])
-- objList:Remove(objList.vList[objList.size].uid)
-- end
for _, obj in pairs(PosList) do
obj:Dispose()
removeObjList:Add(obj)
2019-04-17 21:04:32 +08:00
end
2020-04-16 15:10:04 +08:00
PosList = {}
2019-04-17 21:04:32 +08:00
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()
2020-04-16 15:10:04 +08:00
local removePos = {}
for pos, obj in pairs(PosList) do
if obj.camp == 1 then
removePos[pos] = 1
BattleLogic.Event:DispatchEvent(BattleEventName.RemoveRole, obj)
obj:Dispose()
removeObjList:Add(obj)
2019-03-12 14:05:45 +08:00
end
end
2020-04-16 15:10:04 +08:00
for pos, _ in pairs(removePos) do
PosList[pos] = nil
end
-- local index = 1
-- while index <= objList.size do
-- if objList.vList[index].camp == 1 then
-- BattleLogic.Event:DispatchEvent(BattleEventName.RemoveRole, objList.vList[index])
-- objList.vList[index]:Dispose()
-- removeObjList:Add(objList.vList[index])
-- objList:Remove(objList.vList[index].uid)
-- else
-- index = index + 1
-- end
-- end
2019-03-12 14:05:45 +08:00
end
function BattleLogic.Update()
curFrame = curFrame + 1
2020-04-10 14:52:41 +08:00
if bMyAllDead then
2019-10-23 13:40:57 +08:00
BattleLogic.BattleEnd(0)
return
end
2020-04-10 14:52:41 +08:00
if CurRound > 20 then
2020-02-20 16:06:48 +08:00
BattleLogic.BattleEnd(0)
return
end
if bEnemyAllDead then
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
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()
2020-02-20 16:06:48 +08:00
bMyAllDead = true
bEnemyAllDead = true
2020-04-16 15:10:04 +08:00
for _, v in pairs(PosList) do
2020-04-10 14:52:41 +08:00
if not v.isDead then
v:Update()
if v.camp == 0 then
2019-03-12 14:05:45 +08:00
bMyAllDead = false
else
bEnemyAllDead = false
end
end
2020-04-16 15:10:04 +08:00
end
-- objList:Foreach(function(k, v)
-- if not v.isDead then
-- v:Update()
-- if v.camp == 0 then
-- bMyAllDead = false
-- else
-- bEnemyAllDead = false
-- end
-- end
-- end)
2020-02-25 20:09:26 +08:00
if bEnemyAllDead then
2020-02-20 16:06:48 +08:00
BattleLogic.Event:DispatchEvent(BattleEventName.BattleOrderEnd, BattleLogic.CurOrder)
2019-03-12 14:05:45 +08:00
end
end
2019-10-10 11:03:42 +08:00
--对位规则: 1敌方相同对位 2若死亡或不存在选取相邻阵位最近且阵位索引最小的
2019-10-23 13:40:57 +08:00
function BattleLogic.GetAggro(role)
2020-04-16 15:10:04 +08:00
-- 计算开始位置
local startPos = role.position
startPos = startPos > 3 and startPos - 3 or startPos
2019-10-10 11:03:42 +08:00
local target
2019-10-23 13:40:57 +08:00
local enemyCamp = role.camp == 0 and 1 or 0
2020-04-16 15:10:04 +08:00
-- c=0 前排 c=1 后排
for c = 0, 1 do
startPos = startPos + c*3
-- 向左
for i = startPos, c*3+1, -1 do
local pos = i + enemyCamp * 6
if PosList[pos] and not PosList[pos].isDead then
target = PosList[pos]
break
2019-10-10 11:03:42 +08:00
end
end
2020-04-16 15:10:04 +08:00
if target then return target end
-- 向右
for i = startPos + 1, c*3+3 do
local pos = i + enemyCamp * 6
if PosList[pos] and not PosList[pos].isDead then
target = PosList[pos]
break
end
end
if target then return target end
end
end
--对位规则: 1敌方相同对位 2若死亡或不存在选取相邻阵位最近且阵位索引最小的
function BattleLogic.GetArrAggroList(role, arr)
-- 重构数据
local plist = {}
for _, role in ipairs(arr) do
plist[role.position] = role
end
-- 计算开始位置
local startPos = role.position
startPos = startPos > 3 and startPos - 3 or startPos
local targetList = {}
-- c=0 前排 c=1 后排
for c = 0, 1 do
startPos = startPos + c*3
-- 向左
for i = startPos, c*3+1, -1 do
local pos = i
if plist[pos] and not plist[pos].isDead then
table.insert(targetList, plist[pos])
end
end
-- 向右
for i = startPos + 1, c*3+3 do
local pos = i
if plist[pos] and not plist[pos].isDead then
table.insert(targetList, plist[pos])
end
end
end
return targetList
2019-10-10 11:03:42 +08:00
end
2019-10-30 15:59:45 +08:00
--获取对位相邻站位的人 chooseType 1 我方 2 敌方(对位的敌人受到嘲讽的影响,若对位的敌人死亡,则选取相邻最近的作为目标)
2019-10-23 13:40:57 +08:00
function BattleLogic.GetNeighbor(role, chooseType)
local posList = {}
2019-10-30 15:59:45 +08:00
local target
if chooseType == 1 then
target = role
else
if role.lockTarget and not role.lockTarget.isDead then
target = role.lockTarget
else
target = BattleLogic.GetAggro(role)
end
end
2019-10-24 15:24:18 +08:00
if target then
local list = BattleLogic.Query(function (r) return r.camp == target.camp end)
for i=1, #list do
2020-04-16 15:10:04 +08:00
if not list[i].isDead then
if list[i].position == target.position + 3 -- 后排的人
or list[i].position == target.position - 3 -- 前排的人
2020-04-21 20:51:31 +08:00
or (math.abs(target.position - list[i].position) <= 1 and floor((target.position-1)/3) == floor((list[i].position-1)/3)) then -- 旁边的人和自己
2020-04-16 15:10:04 +08:00
table.insert(posList, list[i])
end
2019-10-24 15:24:18 +08:00
end
2019-10-23 13:40:57 +08:00
end
end
return posList
end
2019-10-10 11:03:42 +08:00
2019-07-25 16:20:33 +08:00
function BattleLogic.CastTeamSkill(camp)
if camp == 0 then
2020-04-10 14:52:41 +08:00
local teamSkill = playerTeamSkillList[MyTeamSkillCastIndex]
2019-07-25 16:20:33 +08:00
if teamSkill then
teamSkill:Cast()
end
else
2020-04-10 14:52:41 +08:00
local teamSkill = enemyTeamSkillList[EnemyTeamSkillCastIndex]
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专用
2020-04-10 14:52:41 +08:00
-- function BattleLogic.SetDebug()
-- objList:Foreach(function(k, v)
-- v.IsDebug = not v.IsDebug
-- end)
-- playerTeamDummyRole.isDebug = not playerTeamDummyRole.isDebug
-- enemyTeamDummyRole.isDebug = not enemyTeamDummyRole.isDebug
-- end
2019-03-12 14:05:45 +08:00
--Debug专用
2020-04-16 15:10:04 +08:00
-- function BattleLogic.SetRoleValue(uid, name, value)
-- if objList.kvList[uid] then
-- objList.kvList[uid].data:SetValue(name, value)
-- end
-- end
2019-03-12 14:05:45 +08:00
2020-04-16 15:10:04 +08:00
-- --Debug专用
-- function BattleLogic.SetRoleDebug(uid, isDebug)
-- if objList.kvList[uid] then
-- objList.kvList[uid].IsDebug = isDebug
-- end
-- end
2019-03-12 14:05:45 +08:00
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专用
2019-11-13 19:06:21 +08:00
function BattleLogic.RecordMul(args)
2019-08-06 20:55:47 +08:00
local str = ""
for i=1, #args do
str = str..tostring(args[i]) .. (i == #args and "" or "#")
end
2019-11-13 19:06:21 +08:00
table.insert(record, string.format("frame:%d, mulArgs:%s", curFrame, str))
2019-08-06 20:55:47 +08:00
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)
2020-04-10 14:52:41 +08:00
end