战斗逻辑
parent
c7e7ef4f3d
commit
754bdf965b
|
@ -1,5 +1,6 @@
|
|||
package.path = package.path ..';luafight/?.lua';
|
||||
-- linux
|
||||
package.path = package.path ..';../luafight/?.lua';
|
||||
-- package.path = package.path ..';../luafight/?.lua';
|
||||
|
||||
require("Modules.Battle.Logic.Misc.BattleDefine")
|
||||
require("Modules.Battle.Logic.Misc.BattleUtil")
|
||||
|
@ -228,7 +229,7 @@ function BattleMain.Execute(args, fightData, optionData)
|
|||
end) then
|
||||
local resultList = {}
|
||||
if BattleLogic.Result == 1 then --胜利记录我方剩余血量
|
||||
local arr = BattleLogic.Query(function (r) return r.camp == 0 end, true)
|
||||
local arr = RoleManager.Query(function (r) return r.camp == 0 end, true)
|
||||
for i=1, #arr do
|
||||
resultList[i] = arr[i]:GetRoleData(RoleDataName.Hp)
|
||||
end
|
||||
|
@ -304,4 +305,5 @@ function BattleMain.Execute(args, fightData, optionData)
|
|||
end
|
||||
return { result = -1 }
|
||||
end
|
||||
|
||||
return BattleMain
|
|
@ -229,7 +229,7 @@ function BattleMain.Execute(args, fightData, optionData)
|
|||
end) then
|
||||
local resultList = {}
|
||||
if BattleLogic.Result == 1 then --胜利记录我方剩余血量
|
||||
local arr = BattleLogic.Query(function (r) return r.camp == 0 end, true)
|
||||
local arr = RoleManager.Query(function (r) return r.camp == 0 end, true)
|
||||
for i=1, #arr do
|
||||
resultList[i] = arr[i]:GetRoleData(RoleDataName.Hp)
|
||||
end
|
||||
|
@ -305,4 +305,5 @@ function BattleMain.Execute(args, fightData, optionData)
|
|||
end
|
||||
return { result = -1 }
|
||||
end
|
||||
|
||||
return BattleMain
|
|
@ -31,7 +31,7 @@ end
|
|||
function Buff.Create(caster, type, duration, ...)
|
||||
local buff = getBuff(type)
|
||||
buff.type = type
|
||||
buff.id = BattleLogic.GenerateBuffId()
|
||||
buff.id = BuffManager.GenerateBuffId()
|
||||
buff.caster = caster
|
||||
buff.disperse = false --该值为true时,buff在下一帧被清除
|
||||
buff.cover = false --该值为true时,同类型新buff会覆盖旧buff
|
||||
|
@ -88,6 +88,8 @@ end
|
|||
BuffManager = {}
|
||||
BuffManager.__index = BuffManager
|
||||
|
||||
local curBuffId
|
||||
|
||||
function BuffManager.New()
|
||||
local instance = {owner=0, buffQueue = BattleQueue.New(), buffDic = BattleDictionary.New()}
|
||||
setmetatable(instance, BuffManager)
|
||||
|
@ -102,6 +104,7 @@ function BuffManager.GetLevelByType(type)
|
|||
|
||||
end
|
||||
|
||||
|
||||
function BuffManager:Init()
|
||||
while self.buffQueue.size > 0 do
|
||||
putBuff(self.buffQueue:Dequeue())
|
||||
|
@ -115,8 +118,17 @@ function BuffManager:Init()
|
|||
buffListPool:Put(list)
|
||||
end
|
||||
self.buffDic:Clear()
|
||||
|
||||
curBuffId = 0
|
||||
end
|
||||
|
||||
function BuffManager.GenerateBuffId()
|
||||
if not curBuffId then
|
||||
curBuffId = 0
|
||||
end
|
||||
curBuffId = curBuffId + 1
|
||||
return curBuffId
|
||||
end
|
||||
function BuffManager:AddBuff(target, buff)
|
||||
buff.target = target
|
||||
self.buffQueue:Enqueue(buff)
|
||||
|
|
|
@ -101,7 +101,7 @@ local effectList = {
|
|||
local cb1 = args[2]
|
||||
local f2 = args[3]
|
||||
BattleLogic.WaitForTrigger(interval, function ()
|
||||
buffRandomAction(f1, target, Buff.Create(caster, BuffName.Control, f2, cb1))
|
||||
BattleUtil.RandomControl(f1, cb1, caster, target, f2)
|
||||
end)
|
||||
end,
|
||||
--[d]改变[a]属性[b]%,持续[c]秒
|
||||
|
@ -277,8 +277,8 @@ local effectList = {
|
|||
caster.Event:DispatchEvent(BattleEventName.RoleViewBullet, skill, target)
|
||||
BattleLogic.WaitForTrigger(interval, function ()
|
||||
local dmg, crit = BattleUtil.CalDamage(skill, caster, target, dt, f1)
|
||||
if target.isDead then
|
||||
local arr = BattleLogic.Query(function (r) return r.camp ~= caster.camp and r.uid ~= target.uid end)
|
||||
if target:IsDead() then
|
||||
local arr = RoleManager.Query(function (r) return r.camp ~= caster.camp and r.uid ~= target.uid end)
|
||||
for i=1, #arr do
|
||||
BattleUtil.ApplyDamage(skill, caster, arr[i], floor(dmg * f2))
|
||||
end
|
||||
|
@ -392,7 +392,7 @@ local effectList = {
|
|||
BattleLogic.WaitForTrigger(interval, function ()
|
||||
BattleUtil.CalDamage(skill, caster, target, dt, f1)
|
||||
if BattleLogic.BuffMgr:HasBuff(target, BuffName.DOT, function (buff) return dot == 0 or buff.damageType == dot end) then
|
||||
buffRandomAction(f2, target, Buff.Create(caster, BuffName.Control, f3, ct))
|
||||
BattleUtil.RandomControl(f1, ct, caster, target, f3)
|
||||
end
|
||||
end)
|
||||
end,
|
||||
|
@ -463,7 +463,7 @@ local effectList = {
|
|||
[26] = function(caster, target, args, interval, skill)
|
||||
local d = args[1]
|
||||
BattleLogic.WaitForTrigger(interval, function ()
|
||||
if not target.isDead then
|
||||
if not target:IsRealDead() then
|
||||
BattleUtil.ApplyDamage(skill, caster, target, d)
|
||||
end
|
||||
end)
|
||||
|
@ -664,7 +664,7 @@ local effectList = {
|
|||
local d = args[1]
|
||||
caster.Event:DispatchEvent(BattleEventName.RoleViewBullet, skill, target)
|
||||
BattleLogic.WaitForTrigger(interval, function ()
|
||||
if not target.isDead then
|
||||
if not target:IsRealDead() then
|
||||
BattleUtil.ApplyDamage(skill, caster, target, d)
|
||||
end
|
||||
end)
|
||||
|
@ -705,7 +705,7 @@ local effectList = {
|
|||
f1 = f1 + f3
|
||||
end)
|
||||
BattleUtil.CalDamage(skill, caster, target, dt, f1)
|
||||
if target.isDead then
|
||||
if target:IsDead() then
|
||||
BattleUtil.RandomAction(f4, function ()
|
||||
caster:AddSkillCD(0)
|
||||
end)
|
||||
|
@ -725,12 +725,12 @@ local effectList = {
|
|||
brand.exDmg = brand.exDmg + (oldBuff.exDmg or 0)
|
||||
end
|
||||
local trigger = function(atkRole, damagingFunc, damageType)
|
||||
BattleUtil.RandomAction(f1, function ()
|
||||
BattleUtil.RandomAction(f1, function()
|
||||
damagingFunc(brand.exDmg)
|
||||
end)
|
||||
end
|
||||
target.Event:AddEvent(BattleEventName.RoleBeDamagedBefore, trigger)
|
||||
brand.endFunc = function ()
|
||||
brand.endFunc = function()
|
||||
brand.exDmg = nil
|
||||
target.Event:RemoveEvent(BattleEventName.RoleBeDamagedBefore, trigger)
|
||||
end
|
||||
|
@ -791,7 +791,7 @@ local effectList = {
|
|||
caster.Event:DispatchEvent(BattleEventName.RoleViewBullet, skill, target)
|
||||
BattleLogic.WaitForTrigger(interval, function ()
|
||||
local dmg, crit = BattleUtil.CalDamage(skill, caster, target, dt, f1)
|
||||
if target.isDead then
|
||||
if target:IsDead() then
|
||||
local buff = Buff.Create(caster, BuffName.PropertyChange, 0, BattlePropList[pro1], f2, 2)
|
||||
buff.cover = true
|
||||
buff.maxLayer = i1
|
||||
|
@ -953,7 +953,7 @@ local effectList = {
|
|||
local f3 = args[4]
|
||||
BattleLogic.WaitForTrigger(interval, function ()
|
||||
if BattleUtil.GetHPPencent(target) < f1 then
|
||||
buffRandomAction(f2, target, Buff.Create(caster, BuffName.Control, f3, ct))
|
||||
BattleUtil.RandomControl(f2, ct, caster, target, f3)
|
||||
end
|
||||
end)
|
||||
end,
|
||||
|
@ -1095,7 +1095,7 @@ local effectList = {
|
|||
local delayDmgTrigger
|
||||
delayDmgTrigger = function(less, d)
|
||||
if less > 0 then
|
||||
local role = target.isDead and BattleUtil.ChooseTarget(caster, 20110)[1] or target
|
||||
local role = target:IsRealDead() and BattleUtil.ChooseTarget(caster, 20110)[1] or target
|
||||
if role then
|
||||
caster.Event:DispatchEvent(BattleEventName.RoleViewBullet, skill, role, d)
|
||||
BattleLogic.WaitForTrigger(d, function ()
|
||||
|
@ -1116,12 +1116,12 @@ local effectList = {
|
|||
caster.Event:DispatchEvent(BattleEventName.RoleViewBullet, skill, target)
|
||||
BattleLogic.WaitForTrigger(interval, function ()
|
||||
BattleUtil.CalDamage(skill, caster, target, dt, f1)
|
||||
if target.isDead then
|
||||
BattleUtil.RandomAction(f2, function ()
|
||||
if caster.superSkill then
|
||||
caster.superSkill:Cast()
|
||||
end
|
||||
end)
|
||||
if target:IsDead() then
|
||||
-- BattleUtil.RandomAction(f2, function ()
|
||||
-- if caster.superSkill then
|
||||
-- caster.superSkill:Cast()
|
||||
-- end
|
||||
-- end)
|
||||
end
|
||||
end)
|
||||
end,
|
||||
|
@ -1164,7 +1164,7 @@ local effectList = {
|
|||
-- 伤害
|
||||
BattleUtil.CalDamage(skill, caster, target, dt, f1)
|
||||
-- 控制未命中则施加增伤印记
|
||||
if not buffRandomAction(f2, target, Buff.Create(caster, BuffName.Control, f3, 1)) then
|
||||
if not BattleUtil.RandomControl(f2, 1, caster, target, f3) then
|
||||
local brand = Buff.Create(caster, BuffName.Brand, 0, "zengshang")
|
||||
brand.maxLayer = i1
|
||||
brand.clear = false
|
||||
|
@ -1308,7 +1308,7 @@ local effectList = {
|
|||
else
|
||||
BattleUtil.CalDamage(skill, caster, target, dt, f1)
|
||||
end
|
||||
buffRandomAction(f2, target, Buff.Create(caster, BuffName.Control, f4, c1))
|
||||
BattleUtil.RandomControl(f2, c1, caster, target, f4)
|
||||
end)
|
||||
end)
|
||||
end
|
||||
|
@ -1340,7 +1340,7 @@ local effectList = {
|
|||
if buff.caster and not buff.caster.isTeam then
|
||||
local trigger = function(defRole, damageFunc, damage) damageFunc(damage * remainCount) end
|
||||
buff.caster.Event:AddEvent(BattleEventName.RoleDamageAfter, trigger)
|
||||
BattleUtil.CalDamage(skill, buff.caster, buff.target, buff.damagePro, buff.damageFactor,0, true)
|
||||
BattleUtil.CalDamage(skill, buff.caster, buff.target, buff.damagePro, buff.damageFactor,0, buff.damageType)
|
||||
buff.caster.Event:RemoveEvent(BattleEventName.RoleDamageAfter, trigger)
|
||||
end
|
||||
end
|
||||
|
@ -1376,7 +1376,7 @@ local effectList = {
|
|||
caster.proTranList:Add(proTran)
|
||||
BattleUtil.CalDamage(skill, caster, target, dt, f1)
|
||||
caster.proTranList:Remove(caster.proTranList.size)
|
||||
if target.isDead then
|
||||
if target:IsDead() then
|
||||
BattleUtil.RandomAction(f3, function ()
|
||||
caster:AddSkillCD(0)
|
||||
end)
|
||||
|
@ -1408,9 +1408,9 @@ local effectList = {
|
|||
local arr = BattleUtil.ChooseTarget(caster, 20000)
|
||||
for i=1, #arr do
|
||||
if arr[i] == target then
|
||||
buffRandomAction(f1+f3, arr[i], Buff.Create(caster, BuffName.Control, f2, cb1))
|
||||
BattleUtil.RandomControl(f1+f3, cb1, caster, arr[i], f2)
|
||||
else
|
||||
buffRandomAction(f1, arr[i], Buff.Create(caster, BuffName.Control, f2, cb1))
|
||||
BattleUtil.RandomControl(f1, cb1, caster, arr[i], f2)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
@ -1464,7 +1464,7 @@ local effectList = {
|
|||
end
|
||||
return b
|
||||
end)
|
||||
buffRandomAction(f1+f3*layer, target, Buff.Create(caster, BuffName.Control, f2, ct))
|
||||
BattleUtil.RandomControl(f1+f3*layer, ct, caster, target, f2)
|
||||
end)
|
||||
end,
|
||||
--添加[a]的[b]%护盾,持续[c]秒。为自身挂护盾印记,每层额外增加护盾值[d]%,印记最多[e]层。印记不显示。(增益印记,不可驱散)
|
||||
|
@ -1533,13 +1533,13 @@ local effectList = {
|
|||
if lastTrigger > 1 then --加入限定避免循环触发
|
||||
return
|
||||
end
|
||||
if not target.isDead then
|
||||
if not target:IsDead() then
|
||||
damagingFunc(floor(damage * f1))
|
||||
BattleUtil.ApplyDamage(skill, atkRole, target, BattleUtil.CalShield(atkRole, target, floor(damage * f1)))
|
||||
end
|
||||
lastTrigger = 0
|
||||
end
|
||||
local list = BattleLogic.GetNeighbor(target, 1)
|
||||
local list = RoleManager.GetNeighbor(target, 1)
|
||||
for i=1, #list do
|
||||
if list[i] ~= target then
|
||||
list[i].Event:AddEvent(BattleEventName.PassiveBeDamaging, OnPassiveDamaging)
|
||||
|
@ -1675,7 +1675,7 @@ local effectList = {
|
|||
end
|
||||
end)
|
||||
if hasBuff then
|
||||
buffRandomAction(f2, target, Buff.Create(caster, BuffName.Control, f3, ct))
|
||||
BattleUtil.RandomControl(f2, ct, caster, target, f3)
|
||||
end
|
||||
end)
|
||||
end,
|
||||
|
@ -1697,7 +1697,7 @@ local effectList = {
|
|||
end
|
||||
end)
|
||||
if hasBuff then
|
||||
buffRandomAction(f2, target, Buff.Create(caster, BuffName.Control, f3, ct))
|
||||
BattleUtil.RandomControl(f2, ct, caster, target, f3)
|
||||
end
|
||||
end)
|
||||
end,
|
||||
|
@ -1723,8 +1723,8 @@ local effectList = {
|
|||
caster.Event:DispatchEvent(BattleEventName.RoleViewBullet, skill, target)
|
||||
BattleLogic.WaitForTrigger(interval, function ()
|
||||
local OnBeHit = function(atkRole, damage, bCrit, finalDmg, damageType)
|
||||
if target.isDead then
|
||||
local arr = BattleLogic.Query(function (r) return r.camp == target.camp and r.uid ~= target.uid end)
|
||||
if target:IsDead() then
|
||||
local arr = RoleManager.Query(function (r) return r.camp == target.camp and r.uid ~= target.uid end)
|
||||
for i=1, #arr do
|
||||
BattleUtil.ApplyDamage(skill, caster, arr[i], floor((damage-finalDmg)*f2))
|
||||
end
|
||||
|
@ -1891,7 +1891,7 @@ local effectList = {
|
|||
else
|
||||
BattleUtil.CalDamage(skill, caster, target, dt, f1)
|
||||
end
|
||||
buffRandomAction(f2, target, Buff.Create(caster, BuffName.Control, f4, c1))
|
||||
BattleUtil.RandomControl(f2, c1, caster, target, f4)
|
||||
end)
|
||||
end)
|
||||
end
|
||||
|
@ -1975,8 +1975,10 @@ local effectList = {
|
|||
caster.Event:DispatchEvent(BattleEventName.RoleViewBullet, skill, target)
|
||||
BattleLogic.WaitForTrigger(interval, function ()
|
||||
local OnBeHit = function(atkRole, damage, bCrit, finalDmg, damageType)
|
||||
local arr = BattleLogic.Query(function (r) return r.camp == caster.camp end)
|
||||
local arr = RoleManager.Query(function (r) return r.camp == caster.camp end)
|
||||
BattleUtil.SortByHpFactor(arr, 1)
|
||||
-- 检测技能伤害治疗加成
|
||||
f2 = BattleUtil.CheckSkillDamageHeal(f2, caster, arr[1])
|
||||
-- 治疗血量最低队友实际伤害的f2%
|
||||
BattleUtil.ApplyTreat(caster, arr[1], floor(finalDmg*f2))
|
||||
end
|
||||
|
@ -1993,6 +1995,18 @@ local effectList = {
|
|||
local i1 = args[2]
|
||||
caster.Event:DispatchEvent(BattleEventName.RoleViewBullet, skill, target)
|
||||
BattleLogic.WaitForTrigger(interval, function ()
|
||||
|
||||
|
||||
local cl = {}
|
||||
local function _CallBack(v, ct)
|
||||
if v then
|
||||
table.insert(cl, {v, ct})
|
||||
end
|
||||
end
|
||||
caster.Event:DispatchEvent(BattleEventName.PassiveShield, _CallBack, ShieldTypeName.RateReduce)
|
||||
target.Event:DispatchEvent(BattleEventName.PassiveBeShield, _CallBack, ShieldTypeName.RateReduce)
|
||||
f1 = BattleUtil.CountChangeList(f1, cl)
|
||||
|
||||
target:AddBuff(Buff.Create(caster, BuffName.Shield, i1, ShieldTypeName.RateReduce, f1, 0))
|
||||
end)
|
||||
end,
|
||||
|
@ -2053,7 +2067,7 @@ local effectList = {
|
|||
BattleLogic.WaitForTrigger(interval, function ()
|
||||
|
||||
local OnBeHit = function()
|
||||
if not target.isDead and BattleLogic.BuffMgr:HasBuff(target, BuffName.DOT, function (buff) return dot == 0 or buff.damageType == dot end) then
|
||||
if not target:IsDead() and BattleLogic.BuffMgr:HasBuff(target, BuffName.DOT, function (buff) return dot == 0 or buff.damageType == dot end) then
|
||||
local ft = target:GetRoleData(RoleDataName.Hp)/target:GetRoleData(RoleDataName.MaxHp)
|
||||
if ft < f2 then
|
||||
BattleUtil.RandomAction(f3, function()
|
||||
|
@ -2083,7 +2097,7 @@ local effectList = {
|
|||
caster.Event:DispatchEvent(BattleEventName.RoleViewBullet, skill, target)
|
||||
BattleLogic.WaitForTrigger(interval, function ()
|
||||
local OnBeHit = function(atkRole, damage, bCrit, finalDmg, damageType)
|
||||
if target.isDead then
|
||||
if target:IsDead() then
|
||||
caster:AddBuff(Buff.Create(caster, BuffName.PropertyChange, 0, BattlePropList[pro1], f2, ct))
|
||||
end
|
||||
end
|
||||
|
@ -2106,10 +2120,7 @@ local effectList = {
|
|||
caster.Event:DispatchEvent(BattleEventName.RoleViewBullet, skill, target)
|
||||
BattleLogic.WaitForTrigger(interval, function ()
|
||||
local damage = BattleUtil.ErrorCorrection(f2 * caster:GetRoleData(BattlePropList[pro]))
|
||||
|
||||
local buff = Buff.Create(caster, BuffName.DOT, i1, 1, dot, damage)
|
||||
buff.isRealDamage = true
|
||||
buffRandomAction(f1, target, buff)
|
||||
BattleUtil.RandomDot(f1, dot, caster, target, i1, 1, damage)
|
||||
end)
|
||||
end,
|
||||
|
||||
|
@ -2136,11 +2147,11 @@ local effectList = {
|
|||
local f2 = args[4]
|
||||
local ct = args[5]
|
||||
local f3 = args[6]
|
||||
caster.Event:DispatchEvent(BattleEventName.RoleViewBullet, skill, target)
|
||||
-- caster.Event:DispatchEvent(BattleEventName.RoleViewBullet, skill, target)
|
||||
BattleLogic.WaitForTrigger(interval, function ()
|
||||
BattleUtil.CalDamage(skill, caster, target, dt, f1)
|
||||
if BattleLogic.BuffMgr:HasBuff(target, BuffName.DOT, function (buff) return dot == 0 or buff.damageType == dot end) then
|
||||
buffRandomAction(f2, target, Buff.Create(caster, BuffName.Control, f3, ct))
|
||||
BattleUtil.RandomControl(f2, ct, caster, target, f3)
|
||||
end
|
||||
end)
|
||||
end,
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -89,9 +89,11 @@ local function takeEffect(caster, target, effects, duration, skill)
|
|||
target.Event:DispatchEvent(BattleEventName.BeSkillEffectBefore, skill, e, _PassiveCheck)
|
||||
|
||||
--
|
||||
effect[e.type](caster, target, e.args, duration, skill)
|
||||
if BattleLogic.IsOpenBattleRecord then
|
||||
BattleLogic.RecordEffect(caster, target, e.type, e.args, duration)
|
||||
if effect[e.type] then
|
||||
effect[e.type](caster, target, e.args, duration, skill)
|
||||
if BattleLogic.IsOpenBattleRecord then
|
||||
BattleLogic.RecordEffect(caster, target, e.type, e.args, duration)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -110,7 +112,7 @@ function Skill:Cast(func)
|
|||
self.effectTargets[i] = self.targets[i]
|
||||
-- 判断是否有有效目标
|
||||
for _, role in ipairs(self.effectTargets[i]) do
|
||||
if not role.isDead then
|
||||
if not role:IsRealDead() then
|
||||
isReTarget = false
|
||||
end
|
||||
end
|
||||
|
@ -140,7 +142,7 @@ function Skill:Cast(func)
|
|||
end
|
||||
-- 全部同时生效
|
||||
for j=1, count do
|
||||
if arr[j] and not arr[j].isDead then
|
||||
if arr[j] and not arr[j]:IsRealDead() then
|
||||
takeEffect(self.owner, arr[j], effects, duration, self)
|
||||
end
|
||||
end
|
||||
|
@ -159,8 +161,6 @@ function Skill:Cast(func)
|
|||
for _, tr in ipairs(self.effectTargets[1]) do
|
||||
tr.Event:DispatchEvent(BattleEventName.BeSkillCast, self)
|
||||
end
|
||||
|
||||
BattleLogic.SetSkillUsable(self.owner.camp, false)
|
||||
--技能的施法时间计算,根据当前目标id关联的持续时间,取其中时间最长的一个
|
||||
local duration = 0
|
||||
for i=1, self.effectList.size do
|
||||
|
@ -168,7 +168,6 @@ function Skill:Cast(func)
|
|||
end
|
||||
-- 结算时间向后延长0.2秒,避免在效果结算完成前就结束了技能释放
|
||||
BattleLogic.WaitForTrigger(duration + 0.2, function()
|
||||
BattleLogic.SetSkillUsable(self.owner.camp, true)
|
||||
self.owner.Event:DispatchEvent(BattleEventName.SkillCastEnd, self)
|
||||
BattleLogic.Event:DispatchEvent(BattleEventName.SkillCastEnd, self)
|
||||
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
|
||||
require("Modules.Battle.Logic.SkillManager")
|
||||
require("Modules.Battle.Logic.RoleManager")
|
||||
|
||||
|
||||
|
||||
BattleLogic = {}
|
||||
|
||||
local floor = math.floor
|
||||
|
@ -11,30 +17,16 @@ local CurCamp = 0
|
|||
local CurSkillPos = {}
|
||||
local PosList = {}
|
||||
|
||||
local curUid
|
||||
local curBuffId
|
||||
local curFrame
|
||||
|
||||
local playerSkillUsable
|
||||
local enemySkillUsable
|
||||
|
||||
local bMyAllDead
|
||||
local bEnemyAllDead
|
||||
|
||||
BattleLogic.Type = 0 --1 故事副本 2 地图探索 3 竞技场 4 秘境boss 5 解锁秘境 6 公会战 7 血战 8 兽潮 9巅峰战
|
||||
BattleLogic.IsEnd = false
|
||||
BattleLogic.Result = -1
|
||||
BattleLogic.Event = BattleEvent.New()
|
||||
BattleLogic.BuffMgr = BuffManager.New()
|
||||
|
||||
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}
|
||||
local playerTeamSkillList = {}
|
||||
local enemyTeamSkillList = {}
|
||||
|
||||
local _IsDebug
|
||||
|
||||
|
||||
local fightData
|
||||
local record
|
||||
local optionRecord
|
||||
|
@ -49,11 +41,6 @@ BattleLogic.TotalOrder = 0
|
|||
--当前波次
|
||||
BattleLogic.CurOrder = 0
|
||||
|
||||
local teamSkillCastRound = {2, 4, 6}
|
||||
local MyTeamSkillCastIndex
|
||||
local EnemyTeamSkillCastIndex
|
||||
|
||||
|
||||
|
||||
local actionPool = BattleObjectPool.New(function ()
|
||||
return { 0, 0 }
|
||||
|
@ -84,29 +71,18 @@ function BattleLogic.Init(data, optionData)
|
|||
|
||||
BattleLogic.Clear()
|
||||
|
||||
curUid = 0
|
||||
curBuffId = 0
|
||||
curFrame = 0
|
||||
|
||||
CurRound = 0
|
||||
|
||||
_IsDebug = false
|
||||
playerTeamDummyRole.isDebug = false
|
||||
playerTeamDummyRole.Event:ClearEvent()
|
||||
enemyTeamDummyRole.isDebug = false
|
||||
enemyTeamDummyRole.Event:ClearEvent()
|
||||
|
||||
playerSkillUsable = true
|
||||
enemySkillUsable = true
|
||||
|
||||
bMyAllDead = false
|
||||
bEnemyAllDead = false
|
||||
|
||||
BattleLogic.Event:ClearEvent()
|
||||
BattleLogic.BuffMgr:Init()
|
||||
BattleLogic.IsEnd = false
|
||||
BattleLogic.Result = -1
|
||||
|
||||
RoleManager.Init()
|
||||
SkillManager.Init()
|
||||
end
|
||||
|
||||
|
@ -114,89 +90,20 @@ function BattleLogic.StartOrder()
|
|||
--
|
||||
BattleLogic.CurOrder = BattleLogic.CurOrder + 1
|
||||
if BattleLogic.CurOrder == 1 then
|
||||
MyTeamSkillCastIndex = 1
|
||||
EnemyTeamSkillCastIndex = 1
|
||||
|
||||
local playerData = fightData.playerData
|
||||
local enemyData = fightData.enemyData[BattleLogic.CurOrder]
|
||||
for i=1, #playerData do
|
||||
BattleLogic.AddRole(playerData[i], playerData[i].position)
|
||||
RoleManager.AddRole(playerData[i], playerData[i].position)
|
||||
end
|
||||
for i=1, #enemyData do
|
||||
BattleLogic.AddRole(enemyData[i], enemyData[i].position)
|
||||
RoleManager.AddRole(enemyData[i], enemyData[i].position)
|
||||
end
|
||||
|
||||
for i=1,3 do
|
||||
if playerTeamSkillList[i] then
|
||||
skillPool:Put(playerTeamSkillList[i])
|
||||
playerTeamSkillList[i]=nil
|
||||
end
|
||||
end
|
||||
for i=1, #playerData.teamSkill do
|
||||
local skill = skillPool:Get()
|
||||
skill:Init(playerTeamDummyRole, playerData.teamSkill[i], 0)
|
||||
playerTeamSkillList[i] = skill
|
||||
end
|
||||
for i=1, #playerData.teamPassive do
|
||||
for j=1, #playerData.teamPassive[i] do
|
||||
local v = playerData.teamPassive[i][j]
|
||||
local id = v[1]
|
||||
local args = {}
|
||||
for k = 2, #v do
|
||||
args[k-1] = v[k]
|
||||
end
|
||||
BattleLogic.TakeTeamPassivity(playerTeamDummyRole, id, args)
|
||||
end
|
||||
end
|
||||
|
||||
for i=1,3 do
|
||||
if enemyTeamSkillList[i] then
|
||||
skillPool:Put(enemyTeamSkillList[i])
|
||||
enemyTeamSkillList[i]=nil
|
||||
end
|
||||
end
|
||||
for i=1, #enemyData.teamSkill do
|
||||
local skill = skillPool:Get()
|
||||
skill:Init(enemyTeamDummyRole, enemyData.teamSkill[i], 0)
|
||||
enemyTeamSkillList[i] = skill
|
||||
end
|
||||
for i=1, #enemyData.teamPassive do
|
||||
for j=1, #enemyData.teamPassive[i] do
|
||||
local v = enemyData.teamPassive[i][j]
|
||||
local id = v[1]
|
||||
local args = {}
|
||||
for k = 2, #v do
|
||||
args[k-1] = v[k]
|
||||
end
|
||||
BattleLogic.TakeTeamPassivity(enemyTeamDummyRole, id, args)
|
||||
end
|
||||
end
|
||||
else
|
||||
BattleLogic.ClearOrder()
|
||||
RoleManager.ClearEnemy()
|
||||
local orderList = fightData.enemyData[BattleLogic.CurOrder]
|
||||
for i=1, #orderList do
|
||||
BattleLogic.AddRole(orderList[i], orderList[i].position)
|
||||
end
|
||||
|
||||
for i=1, #enemyTeamSkillList do
|
||||
skillPool:Put(enemyTeamSkillList[i])
|
||||
enemyTeamSkillList[i]=nil
|
||||
end
|
||||
for i=1, #orderList.teamSkill do
|
||||
local skill = skillPool:Get()
|
||||
skill:Init(enemyTeamDummyRole, orderList.teamSkill[i], 0)
|
||||
enemyTeamSkillList[i] = skill
|
||||
end
|
||||
for i=1, #orderList.teamPassive do
|
||||
for j=1, #orderList.teamPassive[i] do
|
||||
local v = orderList.teamPassive[i][j]
|
||||
local id = v[1]
|
||||
local args = {}
|
||||
for k = 2, #v do
|
||||
args[k-1] = v[k]
|
||||
end
|
||||
BattleLogic.TakeTeamPassivity(enemyTeamDummyRole, id, args)
|
||||
end
|
||||
RoleManager.AddRole(orderList[i], orderList[i].position)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -224,13 +131,23 @@ function BattleLogic.GetIsDebug()
|
|||
return _IsDebug
|
||||
end
|
||||
|
||||
|
||||
-- 下一帧开始下一轮
|
||||
local _TurnRoundFlag = 0
|
||||
function BattleLogic.TurnRoundNextFrame()
|
||||
BattleLogic.WaitForTrigger(BattleLogic.GameDeltaTime, function()
|
||||
BattleLogic.TurnRound()
|
||||
end)
|
||||
_TurnRoundFlag = 0
|
||||
end
|
||||
|
||||
-- 检测是否要轮转
|
||||
function BattleLogic.CheckTurnRound()
|
||||
if _TurnRoundFlag == 2 then
|
||||
return
|
||||
end
|
||||
_TurnRoundFlag = _TurnRoundFlag + 1
|
||||
if _TurnRoundFlag == 2 then
|
||||
BattleLogic.TurnRound()
|
||||
end
|
||||
end
|
||||
|
||||
-- 开始轮转
|
||||
-- debugTurn 用于判断是否是debug轮转的参数
|
||||
function BattleLogic.TurnRound(debugTurn)
|
||||
|
@ -242,8 +159,8 @@ function BattleLogic.TurnRound(debugTurn)
|
|||
if CurRound == 0 or (CurSkillPos[0] == 6 and CurSkillPos[1] == 6) then
|
||||
CurRound = CurRound + 1
|
||||
CurCamp = 0
|
||||
CurSkillPos[0] = -1 -- 先从异妖开始检测
|
||||
CurSkillPos[1] = -1
|
||||
CurSkillPos[0] = 0
|
||||
CurSkillPos[1] = 0
|
||||
-- 轮数变化
|
||||
BattleLogic.Event:DispatchEvent(BattleEventName.BattleRoundChange, CurRound)
|
||||
else
|
||||
|
@ -253,188 +170,58 @@ function BattleLogic.TurnRound(debugTurn)
|
|||
|
||||
-- 当前阵营下一释放技能的位置
|
||||
local cpos = CurSkillPos[CurCamp] + 1
|
||||
if cpos == 0 then
|
||||
-- 保存当前释放技能的位置
|
||||
CurSkillPos[CurCamp] = cpos
|
||||
-- 刷新异妖buff轮数(暂时不用)
|
||||
-- BattleLogic.BuffMgr:PassUpdate()
|
||||
-- 检测异妖技能释放
|
||||
BattleLogic.CheckTeamSkillCast(CurCamp)
|
||||
else
|
||||
-- 找到下一个释放技能的人
|
||||
local SkillRole
|
||||
for p = cpos, 6 do
|
||||
-- 保存当前位置
|
||||
CurSkillPos[CurCamp] = p
|
||||
-- 自己阵营中的位置 + 自己阵营的ID * 6 = 自己在PosList中的位置
|
||||
local role = PosList[p + (CurCamp * 6)]
|
||||
if role and not role.isDead 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轮数
|
||||
end
|
||||
-- 如果找不到下一个人,直接交换阵营
|
||||
if not SkillRole then
|
||||
BattleLogic.TurnRoundNextFrame()
|
||||
return
|
||||
-- 找到下一个释放技能的人
|
||||
local SkillRole
|
||||
for p = cpos, 6 do
|
||||
-- 保存当前位置
|
||||
CurSkillPos[CurCamp] = p
|
||||
-- 自己阵营中的位置 + 自己阵营的ID * 6 = 自己在PosList中的位置
|
||||
local role = RoleManager.GetRole(CurCamp, p) --PosList[p + (CurCamp * 6)]
|
||||
if role and not role:IsRealDead() then
|
||||
SkillRole = role
|
||||
break
|
||||
end
|
||||
|
||||
|
||||
-- 如果角色无法释放技能
|
||||
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
|
||||
|
||||
-- 行动
|
||||
SkillRole.Event:DispatchEvent(BattleEventName.RoleTurnStart) -- 开始行动
|
||||
-- 如果当前位置不能释放技能也需要走buff轮转
|
||||
BattleLogic.BuffMgr:TurnUpdate(1) -- 计算恢复血量
|
||||
BattleLogic.BuffMgr:TurnUpdate(2) -- 计算持续伤害(除去流血)
|
||||
-- 释放技能后,递归交换阵营
|
||||
SkillRole:CastSkill(function()
|
||||
BattleLogic.BuffMgr:TurnUpdate(3) -- 计算持续伤害(流血)
|
||||
BattleLogic.BuffMgr:TurnUpdate(4) -- 计算其他buff
|
||||
BattleLogic.BuffMgr:PassUpdate() -- 计算buff轮数
|
||||
SkillRole.Event:DispatchEvent(BattleEventName.RoleTurnEnd) -- 行动结束
|
||||
BattleLogic.TurnRoundNextFrame()
|
||||
end)
|
||||
BattleLogic.BuffMgr:TurnUpdate(3) -- 计算持续伤害(流血)
|
||||
BattleLogic.BuffMgr:TurnUpdate(4) -- 计算其他buff
|
||||
BattleLogic.BuffMgr:PassUpdate() -- 计算buff轮数
|
||||
end
|
||||
-- 如果找不到下一个人,直接交换阵营
|
||||
if not SkillRole then
|
||||
BattleLogic.TurnRoundNextFrame()
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
-- 如果角色无法释放技能
|
||||
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
|
||||
|
||||
-- 行动
|
||||
SkillRole.Event:DispatchEvent(BattleEventName.RoleTurnStart) -- 开始行动
|
||||
BattleLogic.BuffMgr:TurnUpdate(1) -- 计算恢复血量
|
||||
BattleLogic.BuffMgr:TurnUpdate(2) -- 计算持续伤害(除去流血)
|
||||
-- 释放技能后,递归交换阵营
|
||||
SkillRole:CastSkill(function()
|
||||
BattleLogic.BuffMgr:TurnUpdate(3) -- 计算持续伤害(流血)
|
||||
BattleLogic.BuffMgr:TurnUpdate(4) -- 计算其他buff
|
||||
BattleLogic.BuffMgr:PassUpdate() -- 计算buff轮数
|
||||
SkillRole.Event:DispatchEvent(BattleEventName.RoleTurnEnd) -- 行动结束
|
||||
BattleLogic.TurnRoundNextFrame()
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- 触发异妖被动
|
||||
function BattleLogic.TakeTeamPassivity(teamCaster, id, args)
|
||||
for _, v in pairs(PosList) do
|
||||
BattleUtil.Passivity[id](v, args)
|
||||
end
|
||||
-- objList:Foreach(function(k, v)
|
||||
-- BattleUtil.Passivity[id](v, args)
|
||||
-- end)
|
||||
end
|
||||
|
||||
-- 获取当前等待释放技能的异妖的序号
|
||||
function BattleLogic.GetTeamSkillCastIndex(camp)
|
||||
-- body
|
||||
if camp == 0 then
|
||||
return MyTeamSkillCastIndex
|
||||
else
|
||||
return EnemyTeamSkillCastIndex
|
||||
end
|
||||
end
|
||||
|
||||
-- 获取异妖
|
||||
function BattleLogic.GetTeamSkill(camp, pos)
|
||||
if camp == 0 then
|
||||
return playerTeamSkillList[pos]
|
||||
else
|
||||
return enemyTeamSkillList[pos]
|
||||
end
|
||||
end
|
||||
|
||||
-- 获取异妖技能CD
|
||||
function BattleLogic.GetTeamSkillCastSlider(camp)
|
||||
local teamSkillCastIndex = BattleLogic.GetTeamSkillCastIndex(camp)
|
||||
if playerTeamDummyRole.isDebug or teamSkillCastIndex > #teamSkillCastRound then
|
||||
return 0
|
||||
end
|
||||
local slider = 0
|
||||
if teamSkillCastIndex == 1 then
|
||||
slider = CurRound / teamSkillCastRound[teamSkillCastIndex]
|
||||
else
|
||||
slider = (CurRound - teamSkillCastRound[teamSkillCastIndex - 1]) / (teamSkillCastRound[teamSkillCastIndex] - teamSkillCastRound[teamSkillCastIndex - 1])
|
||||
end
|
||||
return slider
|
||||
end
|
||||
|
||||
-- 检测异妖技能是否可以释放
|
||||
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
|
||||
teamSkillList[teamSkillCastIndex]:Cast(BattleLogic.TurnRoundNextFrame)
|
||||
if camp == 0 then
|
||||
MyTeamSkillCastIndex = MyTeamSkillCastIndex + 1
|
||||
else
|
||||
EnemyTeamSkillCastIndex = EnemyTeamSkillCastIndex + 1
|
||||
end
|
||||
return
|
||||
end
|
||||
end
|
||||
-- 没有要释放技能的异妖,切换阵营
|
||||
BattleLogic.TurnRoundNextFrame()
|
||||
end
|
||||
|
||||
|
||||
function BattleLogic.GenerateBuffId()
|
||||
if not curBuffId then
|
||||
curBuffId = 0
|
||||
end
|
||||
curBuffId = curBuffId + 1
|
||||
return curBuffId
|
||||
end
|
||||
|
||||
-- 角色数据添加
|
||||
function BattleLogic.AddRole(roleData, position)
|
||||
if not curUid then
|
||||
curUid = 0
|
||||
end
|
||||
curUid = curUid + 1
|
||||
local role = rolePool:Get()
|
||||
role:Init(curUid, roleData, position)
|
||||
-- objList:Add(curUid, role)
|
||||
if roleData.camp == 0 then
|
||||
PosList[position] = role -- 1-6 我方英雄
|
||||
else
|
||||
PosList[position + 6] = role-- 7-12 敌方英雄
|
||||
end
|
||||
if not role.isDead then
|
||||
BattleLogic.Event:DispatchEvent(BattleEventName.AddRole, role)
|
||||
end
|
||||
end
|
||||
-- 获取角色数据
|
||||
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
|
||||
|
||||
|
||||
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
|
||||
|
||||
function BattleLogic.WaitForTrigger(delayTime, action)
|
||||
delayTime = BattleUtil.ErrorCorrection(delayTime)
|
||||
local delayFrame = floor(delayTime * BattleLogic.GameFrameRate + 0.5)
|
||||
|
@ -451,96 +238,15 @@ function BattleLogic.WaitForTrigger(delayTime, action)
|
|||
end
|
||||
end
|
||||
|
||||
function BattleLogic.AddOption(opType, opArg)
|
||||
table.insert(optionRecord, {curFrame + 1, opType, opArg})
|
||||
end
|
||||
|
||||
function BattleLogic.GetTeamSkillCaster(camp)
|
||||
return camp == 0 and playerTeamDummyRole or enemyTeamDummyRole
|
||||
end
|
||||
|
||||
function BattleLogic.CurFrame()
|
||||
return curFrame
|
||||
end
|
||||
|
||||
function BattleLogic.Query(func, inCludeDeadRole)
|
||||
local list = {}
|
||||
local index = 1
|
||||
if func then
|
||||
for pos, v in pairs(PosList) do
|
||||
if func(v) and (inCludeDeadRole or not v.isDead) then
|
||||
list[index] = v
|
||||
index = index + 1
|
||||
end
|
||||
end
|
||||
-- objList:Foreach(function(k, v)
|
||||
-- if func(v) and (inCludeDeadRole or not v.isDead) then
|
||||
-- list[index] = v
|
||||
-- index = index + 1
|
||||
-- end
|
||||
-- end)
|
||||
end
|
||||
return list
|
||||
end
|
||||
|
||||
function BattleLogic.BattleEnd(result)
|
||||
BattleLogic.IsEnd = true
|
||||
BattleLogic.Result = result
|
||||
BattleLogic.Event:DispatchEvent(BattleEventName.BattleEnd, result)
|
||||
end
|
||||
|
||||
function BattleLogic.Clear()
|
||||
-- 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)
|
||||
end
|
||||
PosList = {}
|
||||
|
||||
while removeObjList.size > 0 do
|
||||
rolePool:Put(removeObjList.buffer[removeObjList.size])
|
||||
removeObjList:Remove(removeObjList.size)
|
||||
end
|
||||
while tbActionList.size > 0 do
|
||||
actionPool:Put(tbActionList.buffer[tbActionList.size])
|
||||
tbActionList:Remove(tbActionList.size)
|
||||
end
|
||||
end
|
||||
|
||||
function BattleLogic.ClearOrder()
|
||||
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)
|
||||
end
|
||||
end
|
||||
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
|
||||
end
|
||||
|
||||
function BattleLogic.Update()
|
||||
curFrame = curFrame + 1
|
||||
if bMyAllDead then
|
||||
local roleResult = RoleManager.GetResult()
|
||||
if roleResult == 0 then
|
||||
BattleLogic.BattleEnd(0)
|
||||
return
|
||||
end
|
||||
|
@ -548,7 +254,7 @@ function BattleLogic.Update()
|
|||
BattleLogic.BattleEnd(0)
|
||||
return
|
||||
end
|
||||
if bEnemyAllDead then
|
||||
if roleResult == 1 then
|
||||
if BattleLogic.CurOrder == BattleLogic.TotalOrder then
|
||||
BattleLogic.BattleEnd(1)
|
||||
else
|
||||
|
@ -557,6 +263,7 @@ function BattleLogic.Update()
|
|||
end
|
||||
end
|
||||
|
||||
-- 检测帧事件(技能命中,伤害计算,buff生成)
|
||||
local index = 1
|
||||
while index <= tbActionList.size do
|
||||
local action = tbActionList.buffer[index]
|
||||
|
@ -568,164 +275,62 @@ function BattleLogic.Update()
|
|||
index = index + 1
|
||||
end
|
||||
end
|
||||
|
||||
-- 检测buff
|
||||
BattleLogic.BuffMgr:Update()
|
||||
---
|
||||
-- 检测角色状态
|
||||
RoleManager.Update()
|
||||
|
||||
-- 检测死亡
|
||||
if RoleManager.CheckDead() then -- 单独用一帧执行死亡
|
||||
return
|
||||
end
|
||||
-- 检测复活
|
||||
if RoleManager.CheckRelive() then -- 单独用一帧执行复活
|
||||
return
|
||||
end
|
||||
|
||||
-- 检测技能释放
|
||||
-- 检测轮转
|
||||
BattleLogic.CheckTurnRound()
|
||||
-- 技能
|
||||
SkillManager.Update()
|
||||
|
||||
bMyAllDead = true
|
||||
bEnemyAllDead = true
|
||||
for _, v in pairs(PosList) do
|
||||
if not v.isDead then
|
||||
v:Update()
|
||||
if v.camp == 0 then
|
||||
bMyAllDead = false
|
||||
else
|
||||
bEnemyAllDead = false
|
||||
end
|
||||
end
|
||||
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)
|
||||
if bEnemyAllDead then
|
||||
BattleLogic.Event:DispatchEvent(BattleEventName.BattleOrderEnd, BattleLogic.CurOrder)
|
||||
end
|
||||
|
||||
-- 战斗结束
|
||||
function BattleLogic.BattleEnd(result)
|
||||
BattleLogic.IsEnd = true
|
||||
BattleLogic.Result = result
|
||||
BattleLogic.Event:DispatchEvent(BattleEventName.BattleEnd, result)
|
||||
end
|
||||
--
|
||||
function BattleLogic.Clear()
|
||||
-- 清空角色
|
||||
RoleManager.Clear()
|
||||
-- 清空事件
|
||||
while tbActionList.size > 0 do
|
||||
actionPool:Put(tbActionList.buffer[tbActionList.size])
|
||||
tbActionList:Remove(tbActionList.size)
|
||||
end
|
||||
end
|
||||
|
||||
--对位规则: 1敌方相同对位 2若死亡或不存在,选取相邻阵位最近且阵位索引最小的
|
||||
function BattleLogic.GetAggro(role)
|
||||
-- 计算开始位置
|
||||
local startPos = role.position
|
||||
startPos = startPos > 3 and startPos - 3 or startPos
|
||||
local target
|
||||
local enemyCamp = role.camp == 0 and 1 or 0
|
||||
|
||||
-- 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
|
||||
end
|
||||
end
|
||||
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
|
||||
end
|
||||
--获取对位相邻站位的人 chooseType 1 我方 2 敌方(对位的敌人受到嘲讽的影响,若对位的敌人死亡,则选取相邻最近的作为目标)
|
||||
function BattleLogic.GetNeighbor(role, chooseType)
|
||||
local posList = {}
|
||||
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
|
||||
if target then
|
||||
local list = BattleLogic.Query(function (r) return r.camp == target.camp end)
|
||||
for i=1, #list do
|
||||
if not list[i].isDead then
|
||||
if list[i].position == target.position + 3 -- 后排的人
|
||||
or list[i].position == target.position - 3 -- 前排的人
|
||||
or (math.abs(target.position - list[i].position) <= 1 and floor((target.position-1)/3) == floor((list[i].position-1)/3)) then -- 旁边的人和自己
|
||||
table.insert(posList, list[i])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return posList
|
||||
end
|
||||
|
||||
function BattleLogic.CastTeamSkill(camp)
|
||||
if camp == 0 then
|
||||
local teamSkill = playerTeamSkillList[MyTeamSkillCastIndex]
|
||||
if teamSkill then
|
||||
teamSkill:Cast()
|
||||
end
|
||||
else
|
||||
local teamSkill = enemyTeamSkillList[EnemyTeamSkillCastIndex]
|
||||
if teamSkill then
|
||||
teamSkill:Cast()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--Debug专用
|
||||
-- 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
|
||||
|
||||
--Debug专用
|
||||
-- function BattleLogic.SetRoleValue(uid, name, value)
|
||||
-- if objList.kvList[uid] then
|
||||
-- objList.kvList[uid].data:SetValue(name, value)
|
||||
-- end
|
||||
-- end
|
||||
|
||||
-- --Debug专用
|
||||
-- function BattleLogic.SetRoleDebug(uid, isDebug)
|
||||
-- if objList.kvList[uid] then
|
||||
-- objList.kvList[uid].IsDebug = isDebug
|
||||
-- end
|
||||
-- end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-------++++++++++++++++++++++++++++ 战斗记录相关
|
||||
--Record专用
|
||||
function BattleLogic.GetRecord()
|
||||
return record
|
||||
|
|
|
@ -34,9 +34,9 @@ end
|
|||
function DOT:OnTrigger()
|
||||
|
||||
if self.isRealDamage then
|
||||
BattleUtil.ApplyDamage(nil, self.caster, self.target, self.damagePro)
|
||||
BattleUtil.ApplyDamage(nil, self.caster, self.target, self.damagePro, nil, nil, self.damageType)
|
||||
else
|
||||
BattleUtil.CalDamage(nil, self.caster, self.target, self.damagePro, self.damageFactor,0, true)
|
||||
BattleUtil.CalDamage(nil, self.caster, self.target, self.damagePro, self.damageFactor, 0, self.damageType)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
|
|
@ -19,7 +19,7 @@ end
|
|||
--间隔N帧触发,返回true时表示继续触发,返回false立刻触发OnEnd
|
||||
function HOT:OnTrigger()
|
||||
|
||||
if not self.target.ctrl_noheal or self.target.isDead then --禁疗和死亡无法加血
|
||||
if not self.target.ctrl_noheal or self.target:IsDead() then --禁疗和死亡无法加血
|
||||
BattleUtil.ApplyTreat(self.caster, self.target, self.healValue)
|
||||
end
|
||||
return true
|
||||
|
|
|
@ -10,6 +10,9 @@ end
|
|||
local immune2 = function(buff)
|
||||
return buff.type == BuffName.DOT
|
||||
end
|
||||
local immune3 = function(buff)
|
||||
return buff.type == BuffName.Shield and buff.shieldType == ShieldTypeName.AllReduce
|
||||
end
|
||||
|
||||
--初始化Buff,通过传入一些自定义参数控制成长相关的数值
|
||||
function Immune:SetData(...)
|
||||
|
@ -30,6 +33,8 @@ function Immune:OnStart()
|
|||
self.target.buffFilter:Add(immune1)
|
||||
elseif self.immuneType == 2 then --免疫dot
|
||||
self.target.buffFilter:Add(immune2)
|
||||
elseif self.immuneType == 3 then --免疫无敌盾
|
||||
self.target.buffFilter:Add(immune3)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -49,6 +54,8 @@ function Immune:OnEnd()
|
|||
immune = immune1
|
||||
elseif self.immuneType == 2 then --免疫dot
|
||||
immune = immune2
|
||||
elseif self.immuneType == 3 then --免疫无敌盾
|
||||
immune = immune3
|
||||
end
|
||||
for i = 1, self.target.buffFilter.size do
|
||||
if self.target.buffFilter.buffer[i] == immune then
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
NoDead = Buff:New()
|
||||
|
||||
--初始化Buff,通过传入一些自定义参数控制成长相关的数值
|
||||
function NoDead:SetData(...)
|
||||
self.damageFactor,
|
||||
self.factorCT,
|
||||
self.isCanRelive = ... -- buff期间的增伤系数
|
||||
self.cover = true --控制效果可被覆盖
|
||||
-- 刷新排序等级
|
||||
self.sort = 4
|
||||
end
|
||||
|
||||
-- 伤害降低
|
||||
function NoDead:onPassiveDamaging(func, target, damage, skill)
|
||||
if skill and skill.type == BattleSkillType.Special then
|
||||
local dd = BattleUtil.CountValue(damage, self.damageFactor, self.factorCT) - damage
|
||||
if func then func(-math.floor(BattleUtil.ErrorCorrection(dd))) end
|
||||
end
|
||||
end
|
||||
|
||||
--初始化后调用一次
|
||||
function NoDead:OnStart()
|
||||
--
|
||||
self.target.Event:AddEvent(BattleEventName.PassiveDamaging, self.onPassiveDamaging, self)
|
||||
self.target:SetDeadFilter(false)
|
||||
|
||||
self.target:SetReliveFilter(self.isCanRelive)
|
||||
end
|
||||
|
||||
--间隔N帧触发,返回true时表示继续触发,返回false立刻触发OnEnd
|
||||
function NoDead:OnTrigger()
|
||||
return true
|
||||
end
|
||||
|
||||
--效果结束时调用一次
|
||||
function NoDead:OnEnd()
|
||||
self.target.Event:AddEvent(BattleEventName.PassiveDamaging, self.onPassiveDamaging, self)
|
||||
self.target:SetDeadFilter(true)
|
||||
end
|
||||
|
||||
--只有当cover字段为true时触发,返回true则被新效果覆盖
|
||||
function NoDead:OnCover(newBuff)
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
-- 比较buff
|
||||
function NoDead:OnCompare(buff)
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
return NoDead
|
|
@ -24,6 +24,10 @@ function Shield:OnStart()
|
|||
self.target.shield:Add(self)
|
||||
if self.shieldType == ShieldTypeName.AllReduce then
|
||||
self.target.buffFilter:Add(immune0)
|
||||
-- 清除所有负面buff
|
||||
BattleLogic.BuffMgr:ClearBuff(self.target, function (buff)
|
||||
return buff.type == BuffName.Control or buff.type == BuffName.Dot
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -82,7 +86,7 @@ function Shield:OnEnd()
|
|||
if self.shieldType == ShieldTypeName.NormalReduce then
|
||||
for i = 1, self.target.shield.size do
|
||||
if self.target.shield.buffer[i] == self then
|
||||
local arr = BattleLogic.Query(function (r) return r.camp ~= self.target.camp end)
|
||||
local arr = RoleManager.Query(function (r) return r.camp ~= self.target.camp end)
|
||||
for j = 1, #arr do
|
||||
BattleUtil.ApplyDamage(nil, self.target, arr[j], math.floor(self.dmgReboundFactor * self.damageSum))
|
||||
end
|
||||
|
|
|
@ -44,6 +44,10 @@ BattleEventName = {
|
|||
RoleRageChange = indexAdd(), -- 角色怒气变化
|
||||
RoleControl = indexAdd(), -- 角色释放控制技能
|
||||
RoleBeControl = indexAdd(), -- 角色被控制
|
||||
RoleRealDead = indexAdd(), -- 角色真死了
|
||||
RoleRelive = indexAdd(), -- 角色复活了
|
||||
FinalDamage = indexAdd(),
|
||||
FinalBeDamage = indexAdd(),
|
||||
|
||||
SkillCast = indexAdd(), -- 技能攻击前
|
||||
SkillCastEnd = indexAdd(), -- 技能攻击结束
|
||||
|
@ -60,6 +64,22 @@ BattleEventName = {
|
|||
PassiveCriting = indexAdd(),
|
||||
PassiveTreatingFactor = indexAdd(),
|
||||
PassiveBeTreatedFactor = indexAdd(),
|
||||
PassiveRandomControl = indexAdd(),
|
||||
PassiveBeRandomControl = indexAdd(),
|
||||
PassiveRandomDot = indexAdd(),
|
||||
PassiveBeRandomDot = indexAdd(),
|
||||
|
||||
PassiveRebackDamage = indexAdd(),
|
||||
|
||||
PassiveSkillDamageHeal = indexAdd(),
|
||||
PassiveBeSkillDamageHeal = indexAdd(),
|
||||
|
||||
PassiveDamageShare = indexAdd(),
|
||||
PassiveDamageBeShare = indexAdd(),
|
||||
|
||||
PassiveShield = indexAdd(),
|
||||
PassiveBeShield = indexAdd(),
|
||||
|
||||
|
||||
AOE = indexAdd(),
|
||||
|
||||
|
@ -121,6 +141,7 @@ BuffName = {
|
|||
Brand = "Brand",
|
||||
Shield = "Shield",
|
||||
Immune = "Immune",
|
||||
NoDead = "NoDead",
|
||||
}
|
||||
|
||||
DotType = {
|
||||
|
@ -130,6 +151,16 @@ DotType = {
|
|||
Blooding = 3,
|
||||
}
|
||||
|
||||
ControlType = {
|
||||
Dizzy = 1,
|
||||
Slient = 2,
|
||||
LockTarget = 3,
|
||||
NoHeal = 4,
|
||||
Blind = 5,
|
||||
|
||||
Palsy = 7,
|
||||
}
|
||||
|
||||
BattleSkillType = {
|
||||
Monster = 0,
|
||||
Normal = 1,
|
||||
|
|
|
@ -37,7 +37,7 @@ end
|
|||
function BattleUtil.ChooseFRow(arr)
|
||||
local tempArr = {}
|
||||
for _, r in ipairs(arr) do
|
||||
if r.position <= 3 and not r.isDead then
|
||||
if r.position <= 3 and not r:IsRealDead() then
|
||||
table.insert(tempArr, r)
|
||||
end
|
||||
end
|
||||
|
@ -50,7 +50,7 @@ end
|
|||
function BattleUtil.ChooseBRow(arr)
|
||||
local tempArr = {}
|
||||
for _, r in ipairs(arr) do
|
||||
if r.position > 3 and not r.isDead then
|
||||
if r.position > 3 and not r:IsRealDead() then
|
||||
table.insert(tempArr, r)
|
||||
end
|
||||
end
|
||||
|
@ -133,31 +133,31 @@ function BattleUtil.ChooseTarget(role, chooseId)
|
|||
local arr
|
||||
-- 选择类型
|
||||
if chooseType == 1 then
|
||||
arr = BattleLogic.Query(function (r) return r.camp == role.camp end)
|
||||
arr = RoleManager.Query(function (r) return r.camp == role.camp end)
|
||||
elseif chooseType == 2 then
|
||||
if role.lockTarget and not role.lockTarget.isDead and num == 1 then --嘲讽时对单个敌军生效
|
||||
if role.lockTarget and not role.lockTarget:IsRealDead() and num == 1 then --嘲讽时对单个敌军生效
|
||||
return {role.lockTarget}
|
||||
end
|
||||
arr = BattleLogic.Query(function (r) return r.camp ~= role.camp end)
|
||||
arr = RoleManager.Query(function (r) return r.camp ~= role.camp end)
|
||||
elseif chooseType == 3 then
|
||||
if role.ctrl_blind then --致盲时自身变随机友军
|
||||
arr = BattleLogic.Query(function (r) return r.camp == role.camp end)
|
||||
arr = RoleManager.Query(function (r) return r.camp == role.camp end)
|
||||
BattleUtil.RandomList(arr)
|
||||
return {arr[1]}
|
||||
end
|
||||
return {role}
|
||||
elseif chooseType == 4 then
|
||||
if role.lockTarget and not role.lockTarget.isDead then --嘲讽时对仇恨目标生效
|
||||
if role.lockTarget and not role.lockTarget:IsRealDead() then --嘲讽时对仇恨目标生效
|
||||
return {role.lockTarget}
|
||||
end
|
||||
if role.ctrl_blind then --致盲时仇恨目标变随机
|
||||
arr = BattleLogic.Query(function (r) return r.camp ~= role.camp end)
|
||||
arr = RoleManager.Query(function (r) return r.camp ~= role.camp end)
|
||||
BattleUtil.RandomList(arr)
|
||||
return {arr[1]}
|
||||
end
|
||||
return {BattleLogic.GetAggro(role)}
|
||||
return {RoleManager.GetAggro(role)}
|
||||
else
|
||||
arr = BattleLogic.Query()
|
||||
arr = RoleManager.Query()
|
||||
end
|
||||
|
||||
--选择范围
|
||||
|
@ -206,9 +206,9 @@ function BattleUtil.ChooseTarget(role, chooseId)
|
|||
elseif chooseWeight == 6 then -- 魔抗
|
||||
BattleUtil.SortByProp(arr, RoleDataName.MagicDefence, sort)
|
||||
elseif chooseWeight == 7 then -- 对位及其相邻目标
|
||||
arr = BattleLogic.GetNeighbor(role, chooseType)
|
||||
arr = RoleManager.GetNeighbor(role, chooseType)
|
||||
elseif chooseWeight == 8 then -- 对位
|
||||
arr = BattleLogic.GetArrAggroList(role, arr)
|
||||
arr = RoleManager.GetArrAggroList(role, arr)
|
||||
-- elseif chooseWeight == 9 then -- 展位距离
|
||||
-- BattleUtil.Sort(arr, function(a, b)
|
||||
-- local r1 = math.abs(role.position - a.position) * 10 + a.position
|
||||
|
@ -283,9 +283,8 @@ function BattleUtil.Seckill(skill, atkRole, defRole)
|
|||
local damage = defRole:GetRoleData(RoleDataName.Hp)
|
||||
local finalDmg = defRole.data:SubValue(RoleDataName.Hp, damage)
|
||||
if finalDmg >= 0 then
|
||||
if defRole:GetRoleData(RoleDataName.Hp) <= 0 then
|
||||
defRole.isDead = true
|
||||
BattleLogic.BuffMgr:ClearBuff(defRole)
|
||||
if defRole:GetRoleData(RoleDataName.Hp) <= 0 and not defRole:IsDead() then
|
||||
defRole:SetDead()
|
||||
defRole.Event:DispatchEvent(BattleEventName.RoleDead, atkRole)
|
||||
atkRole.Event:DispatchEvent(BattleEventName.RoleKill, defRole)
|
||||
BattleLogic.Event:DispatchEvent(BattleEventName.BattleRoleDead, defRole, atkRole)
|
||||
|
@ -298,14 +297,13 @@ function BattleUtil.Seckill(skill, atkRole, defRole)
|
|||
end
|
||||
|
||||
-- 计算真实伤害
|
||||
function BattleUtil.ApplyDamage(skill, atkRole, defRole, damage, bCrit, damageType, isDot)
|
||||
function BattleUtil.ApplyDamage(skill, atkRole, defRole, damage, bCrit, damageType, dotType)
|
||||
bCrit = bCrit or false
|
||||
damageType = damageType or 0
|
||||
isDot = isDot or false
|
||||
|
||||
-- if atkRole.isTeam then
|
||||
-- --max(技能基础伤害*(1+已方异妖伤害加成-目标异妖伤害减免),30%×技能基础伤害)
|
||||
-- local arr = BattleLogic.Query(function (r) return r.camp == atkRole.camp end)
|
||||
-- local arr = RoleManager.Query(function (r) return r.camp == atkRole.camp end)
|
||||
-- local n = 0
|
||||
-- for i=1, #arr do
|
||||
-- n = n + arr[i]:GetRoleData(RoleDataName.TeamDamageBocusFactor)
|
||||
|
@ -314,33 +312,47 @@ function BattleUtil.ApplyDamage(skill, atkRole, defRole, damage, bCrit, damageTy
|
|||
-- end
|
||||
|
||||
--加入被动效果
|
||||
local damagingFunc = function(dmgDeduction) damage = damage - dmgDeduction end
|
||||
atkRole.Event:DispatchEvent(BattleEventName.PassiveDamaging, damagingFunc, defRole, damage, skill)
|
||||
defRole.Event:DispatchEvent(BattleEventName.PassiveBeDamaging, damagingFunc, atkRole, damage, skill)
|
||||
local damagingFunc = function(dmgDeduction)
|
||||
damage = damage - dmgDeduction
|
||||
end
|
||||
atkRole.Event:DispatchEvent(BattleEventName.PassiveDamaging, damagingFunc, defRole, damage, skill, dotType)
|
||||
defRole.Event:DispatchEvent(BattleEventName.PassiveBeDamaging, damagingFunc, atkRole, damage, skill, dotType)
|
||||
|
||||
-- 计算护盾减伤
|
||||
damage = BattleUtil.CalShield(atkRole, defRole, damage)
|
||||
|
||||
|
||||
-- 造成的最终伤害
|
||||
local damagingFunc = function(dmgDeduction)
|
||||
damage = damage - dmgDeduction
|
||||
end
|
||||
atkRole.Event:DispatchEvent(BattleEventName.FinalDamage, damagingFunc, defRole, damage, skill, dotType, bCrit, damageType)
|
||||
defRole.Event:DispatchEvent(BattleEventName.FinalBeDamage, damagingFunc, atkRole, damage, skill, dotType, bCrit, damageType)
|
||||
|
||||
--
|
||||
return BattleUtil.FinalDamage(skill, atkRole, defRole, damage, bCrit, damageType, dotType)
|
||||
end
|
||||
|
||||
function BattleUtil.FinalDamage(skill, atkRole, defRole, damage, bCrit, damageType, dotType)
|
||||
if damage >= 0 then
|
||||
local finalDmg = defRole.data:SubValue(RoleDataName.Hp, damage)
|
||||
if finalDmg >= 0 then
|
||||
if defRole:GetRoleData(RoleDataName.Hp) <= 0 then
|
||||
defRole.isDead = true
|
||||
BattleLogic.BuffMgr:ClearBuff(defRole)
|
||||
if defRole:GetRoleData(RoleDataName.Hp) <= 0 and not defRole:IsDead() then
|
||||
defRole:SetDead()
|
||||
defRole.Event:DispatchEvent(BattleEventName.RoleDead, atkRole)
|
||||
atkRole.Event:DispatchEvent(BattleEventName.RoleKill, defRole)
|
||||
BattleLogic.Event:DispatchEvent(BattleEventName.BattleRoleDead, defRole, atkRole)
|
||||
end
|
||||
|
||||
atkRole.Event:DispatchEvent(BattleEventName.RoleDamage, defRole, damage, bCrit, finalDmg, damageType, isDot, skill)
|
||||
defRole.Event:DispatchEvent(BattleEventName.RoleBeDamaged, atkRole, damage, bCrit, finalDmg, damageType, isDot, skill)
|
||||
BattleLogic.Event:DispatchEvent(BattleEventName.RoleDamage, atkRole, defRole, damage, bCrit, finalDmg, damageType, isDot, skill)
|
||||
BattleLogic.Event:DispatchEvent(BattleEventName.RoleBeDamaged, defRole, atkRole, damage, bCrit, finalDmg, damageType, isDot, skill)
|
||||
atkRole.Event:DispatchEvent(BattleEventName.RoleDamage, defRole, damage, bCrit, finalDmg, damageType, dotType, skill)
|
||||
defRole.Event:DispatchEvent(BattleEventName.RoleBeDamaged, atkRole, damage, bCrit, finalDmg, damageType, dotType, skill)
|
||||
BattleLogic.Event:DispatchEvent(BattleEventName.RoleDamage, atkRole, defRole, damage, bCrit, finalDmg, damageType, dotType, skill)
|
||||
BattleLogic.Event:DispatchEvent(BattleEventName.RoleBeDamaged, defRole, atkRole, damage, bCrit, finalDmg, damageType, dotType, skill)
|
||||
if bCrit then
|
||||
atkRole.Event:DispatchEvent(BattleEventName.RoleCrit, defRole, damage, bCrit, finalDmg, damageType, skill)
|
||||
defRole.Event:DispatchEvent(BattleEventName.RoleBeCrit, atkRole, damage, bCrit, finalDmg, damageType, skill)
|
||||
end
|
||||
if not isDot then
|
||||
if not dotType then
|
||||
atkRole.Event:DispatchEvent(BattleEventName.RoleHit, defRole, damage, bCrit, finalDmg, damageType, skill)
|
||||
defRole.Event:DispatchEvent(BattleEventName.RoleBeHit, atkRole, damage, bCrit, finalDmg, damageType, skill)
|
||||
end
|
||||
|
@ -352,9 +364,9 @@ function BattleUtil.ApplyDamage(skill, atkRole, defRole, damage, bCrit, damageTy
|
|||
end
|
||||
|
||||
--执行完整的命中,伤害,暴击计算,返回命中,暴击
|
||||
--skill造成伤害的技能 atkRole攻击者 defRole受击者 damageType伤害类型 baseFactor伤害系数 ignoreDef无视防御参数 isDot是否是dot
|
||||
function BattleUtil.CalDamage(skill, atkRole, defRole, damageType, baseFactor, ignoreDef, isDot)
|
||||
if atkRole.isTeam and not defRole.isDead then --如果是队伍技能,计算真实伤害,则damageType为伤害值
|
||||
--skill造成伤害的技能 atkRole攻击者 defRole受击者 damageType伤害类型 baseFactor伤害系数 ignoreDef无视防御参数 dotType是持续伤害类型
|
||||
function BattleUtil.CalDamage(skill, atkRole, defRole, damageType, baseFactor, ignoreDef, dotType)
|
||||
if atkRole.isTeam and not defRole:IsDead() then --如果是队伍技能,计算真实伤害,则damageType为伤害值
|
||||
return BattleUtil.ApplyDamage(skill, atkRole, defRole, damageType), false
|
||||
end
|
||||
|
||||
|
@ -443,14 +455,14 @@ function BattleUtil.CalDamage(skill, atkRole, defRole, damageType, baseFactor, i
|
|||
defRole.Event:DispatchEvent(BattleEventName.RoleBeDamagedAfter, atkRole, damageFunc, baseDamage)
|
||||
|
||||
local finalDmg = 0 --计算实际造成的扣血
|
||||
if not defRole.isDead then
|
||||
finalDmg = BattleUtil.ApplyDamage(skill, atkRole, defRole, baseDamage, bCrit, damageType, isDot)
|
||||
if not defRole:IsRealDead() then
|
||||
finalDmg = BattleUtil.ApplyDamage(skill, atkRole, defRole, baseDamage, bCrit, damageType, dotType)
|
||||
end
|
||||
return finalDmg, bCrit
|
||||
end
|
||||
|
||||
function BattleUtil.CalTreat(castRole, targetRole, value, baseFactor)
|
||||
if targetRole.ctrl_noheal or targetRole.isDead then --禁疗和死亡无法加血
|
||||
if targetRole.ctrl_noheal or targetRole:IsDead() then --禁疗和死亡无法加血
|
||||
return
|
||||
end
|
||||
targetRole.Event:DispatchEvent(BattleEventName.RoleBeHealed, castRole)
|
||||
|
@ -458,6 +470,9 @@ function BattleUtil.CalTreat(castRole, targetRole, value, baseFactor)
|
|||
end
|
||||
|
||||
function BattleUtil.ApplyTreat(castRole, targetRole, value, baseFactor)
|
||||
if targetRole.ctrl_noheal or targetRole:IsDead() then --禁疗和死亡无法加血
|
||||
return
|
||||
end
|
||||
baseFactor = baseFactor or 1
|
||||
local maxHp = targetRole:GetRoleData(RoleDataName.MaxHp)
|
||||
local hp = targetRole:GetRoleData(RoleDataName.Hp)
|
||||
|
@ -474,9 +489,20 @@ function BattleUtil.ApplyTreat(castRole, targetRole, value, baseFactor)
|
|||
local baseTreat = floor(BattleUtil.FP_Mul(value, baseFactor, factor, factor2) + 0.5)
|
||||
|
||||
--加入被动效果
|
||||
local treatingFunc = function(exFactor) baseTreat = floor(baseTreat * (exFactor + 1) + 0.5) end
|
||||
local cl = {}
|
||||
local function treatingFunc(v, ct)
|
||||
if v then
|
||||
table.insert(cl, {v, ct})
|
||||
end
|
||||
end
|
||||
-- local treatingFunc = function(exFactor) baseTreat = floor(baseTreat * (exFactor + 1) + 0.5) end
|
||||
castRole.Event:DispatchEvent(BattleEventName.PassiveTreating, treatingFunc, targetRole)
|
||||
targetRole.Event:DispatchEvent(BattleEventName.PassiveBeTreated, treatingFunc, castRole)
|
||||
baseTreat = BattleUtil.CountChangeList(baseTreat, cl)
|
||||
|
||||
|
||||
|
||||
|
||||
local treat = min(baseTreat, maxHp - hp)
|
||||
if treat > 0 then
|
||||
targetRole.data:AddValue(RoleDataName.Hp, treat)
|
||||
|
@ -485,12 +511,62 @@ function BattleUtil.ApplyTreat(castRole, targetRole, value, baseFactor)
|
|||
targetRole.Event:DispatchEvent(BattleEventName.RoleBeTreated, castRole, treat, baseTreat)
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
function BattleUtil.RandomAction(rand, action)
|
||||
if Random.Range01() <= rand and action then
|
||||
action()
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
--
|
||||
function BattleUtil.RandomControl(rand, ctrl, caster, target, round)
|
||||
|
||||
local cl = {}
|
||||
local function _CallBack(v, ct)
|
||||
if v then
|
||||
table.insert(cl, {v, ct})
|
||||
end
|
||||
end
|
||||
caster.Event:DispatchEvent(BattleEventName.PassiveRandomControl, _CallBack, ctrl, target)
|
||||
target.Event:DispatchEvent(BattleEventName.PassiveBeRandomControl, _CallBack, ctrl, target)
|
||||
rand = BattleUtil.CountChangeList(rand, cl)
|
||||
|
||||
return BattleUtil.RandomAction(rand, function()
|
||||
local buff = Buff.Create(caster, BuffName.Control, round, ctrl)
|
||||
target:AddBuff(buff)
|
||||
end)
|
||||
end
|
||||
|
||||
--
|
||||
function BattleUtil.RandomDot(rand, dot, caster, target, round, interval, damage)
|
||||
|
||||
local cl = {}
|
||||
local dcl = {}
|
||||
local function _CallBack(v, ct, dv, dct)
|
||||
if v then
|
||||
table.insert(cl, {v, ct})
|
||||
end
|
||||
if dv then
|
||||
table.insert(dcl, {dv, dct})
|
||||
end
|
||||
end
|
||||
caster.Event:DispatchEvent(BattleEventName.PassiveRandomDot, _CallBack, dot)
|
||||
target.Event:DispatchEvent(BattleEventName.PassiveBeRandomDot, _CallBack, dot)
|
||||
rand = BattleUtil.CountChangeList(rand, cl)
|
||||
damage = BattleUtil.CountChangeList(damage, dcl)
|
||||
|
||||
return BattleUtil.RandomAction(rand, function()
|
||||
local buff = Buff.Create(caster, BuffName.DOT, round, interval, dot, damage)
|
||||
buff.isRealDamage = true
|
||||
target:AddBuff(buff)
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
function BattleUtil.RandomList(arr)
|
||||
if #arr <= 1 then return end
|
||||
local index
|
||||
|
@ -553,4 +629,55 @@ function BattleUtil.CountValue(v1, v2, ct)
|
|||
-- 做一个正确性检测
|
||||
-- v = BattleUtil.ErrorCorrection(v)
|
||||
return v
|
||||
end
|
||||
end
|
||||
|
||||
-- 计算数值改变
|
||||
function BattleUtil.CountChangeList(v, changeList)
|
||||
local aplist = {}
|
||||
local splist = {}
|
||||
local fv = v
|
||||
-- 先算绝对值
|
||||
for _, change in ipairs(changeList) do
|
||||
local cv = change[1]
|
||||
local ct = change[2]
|
||||
if ct then
|
||||
if ct == 1 or ct == 3 then
|
||||
fv = BattleUtil.CountValue(fv, cv, ct)
|
||||
elseif ct == 2 then
|
||||
table.insert(aplist, change)
|
||||
elseif ct == 4 then
|
||||
table.insert(splist, change)
|
||||
end
|
||||
end
|
||||
end
|
||||
-- 加乘(对基数进行加乘)
|
||||
for _, change in ipairs(aplist) do
|
||||
local cv = change[1]
|
||||
local ct = change[2]
|
||||
fv = fv + (BattleUtil.CountValue(v, cv, ct) - v)
|
||||
end
|
||||
-- 减乘(对最终数值进行减乘算)
|
||||
for _, change in ipairs(splist) do
|
||||
local cv = change[1]
|
||||
local ct = change[2]
|
||||
fv = BattleUtil.CountValue(fv, cv, ct)
|
||||
end
|
||||
|
||||
return fv
|
||||
end
|
||||
|
||||
-- 检测技能伤害治疗加乘
|
||||
function BattleUtil.CheckSkillDamageHeal(f, caster, target)
|
||||
|
||||
local cl = {}
|
||||
local function _CallBack(v, ct)
|
||||
if v then
|
||||
table.insert(cl, {v, ct})
|
||||
end
|
||||
end
|
||||
caster.Event:DispatchEvent(BattleEventName.PassiveSkillDamageHeal, _CallBack)
|
||||
target.Event:DispatchEvent(BattleEventName.PassiveBeSkillDamageHeal, _CallBack)
|
||||
f = BattleUtil.CountChangeList(f, cl)
|
||||
|
||||
return f
|
||||
end
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
|
||||
require("Modules.Battle.Logic.SkillManager")
|
||||
|
||||
RoleLogic = {}
|
||||
RoleLogic.__index = RoleLogic
|
||||
--local RoleLogic = RoleLogic
|
||||
|
@ -33,6 +31,7 @@ function RoleLogic:Init(uid, data, position)
|
|||
|
||||
self.data:Init(self, data.property)
|
||||
self.isDead = self:GetRoleData(RoleDataName.Hp) <= 0
|
||||
self.isRealDead = self.isDead
|
||||
|
||||
self.camp = data.camp --阵营 0:我方 1:敌方
|
||||
self.name = data.name
|
||||
|
@ -53,6 +52,13 @@ function RoleLogic:Init(uid, data, position)
|
|||
local time = self:GetRoleData(RoleDataName.Speed)/(20*(self:GetRoleData(RoleDataName.Level)+10))
|
||||
self.spPass = floor( BattleUtil.ErrorCorrection(time) * BattleLogic.GameFrameRate)
|
||||
|
||||
|
||||
-- 初始化怒气值(默认2)
|
||||
self.Rage = 2 + self:GetRoleData(RoleDataName.InitRage)-- 当前怒气值
|
||||
self.RageGrow = 2 -- 普通技能怒气成长
|
||||
self.SuperSkillRage = 4 -- 技能需要释放的怒气值,默认为4
|
||||
self.NoRageRate = 0 -- 不消耗怒气值的概率
|
||||
|
||||
--
|
||||
self.passiveList = {}
|
||||
if data.passivity and #data.passivity > 0 then
|
||||
|
@ -68,18 +74,11 @@ function RoleLogic:Init(uid, data, position)
|
|||
-- 加入被动列表
|
||||
table.insert(self.passiveList, {id, args})
|
||||
else
|
||||
print("被动技能"..id.."不存在")
|
||||
--print("被动技能"..id.."不存在")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- 初始化怒气值(默认2)
|
||||
self.Rage = 2 + self:GetRoleData(RoleDataName.InitRage)-- 当前怒气值
|
||||
self.RageGrow = 2 -- 普通技能怒气成长
|
||||
self.SuperSkillRage = 4 -- 技能需要释放的怒气值
|
||||
self.NoRageRate = 0 -- 不消耗怒气值的概率
|
||||
|
||||
|
||||
self.aiOrder = data.ai
|
||||
self.aiIndex = 1
|
||||
self.aiTempCount = 0
|
||||
|
@ -92,6 +91,11 @@ function RoleLogic:Init(uid, data, position)
|
|||
self.ctrl_palsy = false --麻痹 只能2技能
|
||||
self.ctrl_noheal = false --禁疗
|
||||
self.ctrl_blind = false --致盲
|
||||
|
||||
self.deadFilter = true -- 控制死亡,置为false则角色暂时无法死亡
|
||||
|
||||
self.reliveFilter = true -- 控制复活的标志位,置为false角色将不再享受复活效果
|
||||
self.reliveHPF = 1
|
||||
end
|
||||
|
||||
-- 添加一个被动技能
|
||||
|
@ -112,7 +116,7 @@ function RoleLogic:AddPassive(id, args, isRepeat)
|
|||
end
|
||||
--
|
||||
function RoleLogic:CanCastSkill()
|
||||
return self.sp >= self.spPass and not self.IsDebug and BattleLogic.GetSkillUsable(self.camp)
|
||||
return self.sp >= self.spPass and not self.IsDebug
|
||||
end
|
||||
|
||||
-- 废弃的方法
|
||||
|
@ -213,7 +217,7 @@ end
|
|||
|
||||
|
||||
function RoleLogic:AddBuff(buff)
|
||||
if self.isDead then
|
||||
if self:IsRealDead() then
|
||||
BattleLogic.BuffMgr:PutBuff(buff)
|
||||
return
|
||||
end
|
||||
|
@ -234,7 +238,7 @@ end
|
|||
-- 判断角色是否可以释放技能
|
||||
function RoleLogic:IsAvailable()
|
||||
-- 眩晕 -- 死亡
|
||||
if self.ctrl_dizzy or self.isDead then
|
||||
if self.ctrl_dizzy or self:IsRealDead() then
|
||||
return false
|
||||
end
|
||||
-- 沉默麻痹同时存在
|
||||
|
@ -327,15 +331,14 @@ end
|
|||
-- isAdd 是否是追加技能
|
||||
-- isRage 是否正常操作怒气值
|
||||
function RoleLogic:AddSkill(type, isRage, isAdd, targets)
|
||||
if not self.SkillNum then
|
||||
self.SkillNum = 0
|
||||
end
|
||||
self.SkillNum = self.SkillNum + 1
|
||||
|
||||
local effectData = type == BattleSkillType.Normal and self.skill or self.superSkill
|
||||
SkillManager.AddSkill(self, effectData, type, targets, isAdd, isRage)
|
||||
end
|
||||
|
||||
-- 插入一个技能
|
||||
function RoleLogic:InsertSkill(type, isRage, isAdd, targets)
|
||||
local effectData = type == BattleSkillType.Normal and self.skill or self.superSkill
|
||||
SkillManager.InsertSkill(self, effectData, type, targets, isAdd, isRage)
|
||||
end
|
||||
|
||||
|
||||
-- 正常触发技能
|
||||
|
@ -381,21 +384,89 @@ function RoleLogic:ForceCastSkill(type, targets, func)
|
|||
end
|
||||
|
||||
|
||||
-- 设置我被杀死时的信息
|
||||
function RoleLogic:SetkillMeInfo(caster, skill)
|
||||
self.killCaster = caster
|
||||
self.killSkill = skill
|
||||
-- 判断是否可以去死了
|
||||
function RoleLogic:IsCanDead()
|
||||
-- 暂时不能死
|
||||
if not self.deadFilter then
|
||||
return false
|
||||
end
|
||||
-- 还有我的技能没有释放,不能死啊
|
||||
if SkillManager.HaveMySkill(self) then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
-- 真的去死
|
||||
function RoleLogic:GoDead()
|
||||
if self:IsCanDead() then
|
||||
self.isRealDead = true
|
||||
self.Event:DispatchEvent(BattleEventName.RoleRealDead, self)
|
||||
BattleLogic.Event:DispatchEvent(BattleEventName.RoleRealDead, self)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
-- 设置是否可以死亡
|
||||
function RoleLogic:SetDeadFilter(filter)
|
||||
self.deadFilter = filter
|
||||
end
|
||||
-- 要死了
|
||||
function RoleLogic:SetDead()
|
||||
self.isDead = true
|
||||
BattleLogic.BuffMgr:ClearBuff(self)
|
||||
RoleManager.AddDeadRole(self)
|
||||
end
|
||||
-- 判断是否死亡
|
||||
function RoleLogic:IsDead()
|
||||
return self.isDead
|
||||
end
|
||||
function RoleLogic:IsRealDead()
|
||||
return self.isRealDead
|
||||
end
|
||||
|
||||
|
||||
-- 是否可以复活
|
||||
function RoleLogic:IsCanRelive()
|
||||
if not self.reliveFilter then
|
||||
return false
|
||||
end
|
||||
if not self.isRealDead then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
-- 复活吧, 真的去世后才能复活
|
||||
function RoleLogic:Relive()
|
||||
if self:IsCanRelive() then
|
||||
-- 没有指定血量则满血
|
||||
self.isDead = false
|
||||
self.isRealDead = false
|
||||
local maxHp = self.data:GetData(RoleDataName.MaxHp)
|
||||
self.data:SetValue(RoleDataName.Hp, floor(self.reliveHPF * maxHp))
|
||||
-- 发送复活事件
|
||||
self.Event:DispatchEvent(BattleEventName.RoleRelive, self)
|
||||
BattleLogic.Event:DispatchEvent(BattleEventName.RoleRelive, self)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
-- 设置是否可以死亡
|
||||
function RoleLogic:SetReliveFilter(filter)
|
||||
self.reliveFilter = filter
|
||||
end
|
||||
--,hpf 复活时拥有的血量的百分比
|
||||
function RoleLogic:SetRelive(hpf)
|
||||
-- 判断是否可以复活
|
||||
if self:IsCanRelive() then
|
||||
self.reliveHPF = hpf or 1
|
||||
RoleManager.AddReliveRole(self)
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
function RoleLogic:Update()
|
||||
|
||||
|
||||
if self:GetRoleData(RoleDataName.Hp) <= 0 then
|
||||
self.isDead = true
|
||||
BattleLogic.BuffMgr:ClearBuff(self)
|
||||
self.Event:DispatchEvent(BattleEventName.RoleDead, self.killCaster)
|
||||
self.killCaster.Event:DispatchEvent(BattleEventName.RoleKill, self)
|
||||
BattleLogic.Event:DispatchEvent(BattleEventName.BattleRoleDead, self, self.killCaster)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -0,0 +1,279 @@
|
|||
RoleManager = {}
|
||||
local this = RoleManager
|
||||
|
||||
-- 将死之人
|
||||
local _DeadRoleList = {}
|
||||
-- 重生之人
|
||||
local _ReliveRoleList = {}
|
||||
-- 所有角色
|
||||
local PosList = {}
|
||||
-- 删除节点
|
||||
local removeObjList = BattleList.New()
|
||||
-- 角色对象池
|
||||
local rolePool = BattleObjectPool.New(function ()
|
||||
return RoleLogic.New()
|
||||
end)
|
||||
|
||||
|
||||
local bMyAllDead
|
||||
local bEnemyAllDead
|
||||
|
||||
-- 初始化
|
||||
function this.Init()
|
||||
|
||||
bMyAllDead = false
|
||||
bEnemyAllDead = false
|
||||
|
||||
this.Clear()
|
||||
end
|
||||
|
||||
|
||||
-- 角色数据添加
|
||||
local curUid
|
||||
function this.AddRole(roleData, position)
|
||||
if not curUid then
|
||||
curUid = 0
|
||||
end
|
||||
curUid = curUid + 1
|
||||
local role = rolePool:Get()
|
||||
role:Init(curUid, roleData, position)
|
||||
-- objList:Add(curUid, role)
|
||||
if roleData.camp == 0 then
|
||||
PosList[position] = role -- 1-6 我方英雄
|
||||
else
|
||||
PosList[position + 6] = role-- 7-12 敌方英雄
|
||||
end
|
||||
if not role:IsRealDead() then
|
||||
BattleLogic.Event:DispatchEvent(BattleEventName.AddRole, role)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
function this.Update()
|
||||
|
||||
bMyAllDead = true
|
||||
bEnemyAllDead = true
|
||||
for _, v in pairs(PosList) do
|
||||
if not v:IsRealDead() then
|
||||
v:Update()
|
||||
if v.camp == 0 then
|
||||
bMyAllDead = false
|
||||
else
|
||||
bEnemyAllDead = false
|
||||
end
|
||||
end
|
||||
end
|
||||
if bEnemyAllDead then
|
||||
BattleLogic.Event:DispatchEvent(BattleEventName.BattleOrderEnd, BattleLogic.CurOrder)
|
||||
end
|
||||
end
|
||||
|
||||
-- 获取结果
|
||||
function this.GetResult()
|
||||
if bMyAllDead then
|
||||
return 0
|
||||
end
|
||||
if bEnemyAllDead then
|
||||
return 1
|
||||
end
|
||||
end
|
||||
|
||||
-- 加入将死的人
|
||||
function this.AddDeadRole(role)
|
||||
_DeadRoleList[role.position + role.camp * 6] = role
|
||||
end
|
||||
-- 检测是有人将死
|
||||
function this.CheckDead()
|
||||
local isDeadFrame = false
|
||||
local removePos = {}
|
||||
for pos, role in pairs(_DeadRoleList) do
|
||||
if role:GoDead() then
|
||||
isDeadFrame = true
|
||||
table.insert(removePos, pos)
|
||||
end
|
||||
end
|
||||
for _, pos in ipairs(removePos) do
|
||||
_DeadRoleList[pos] = nil
|
||||
end
|
||||
return isDeadFrame
|
||||
end
|
||||
|
||||
-- 加入复活之人
|
||||
function this.AddReliveRole(role)
|
||||
_ReliveRoleList[role.position + role.camp * 6] = role
|
||||
end
|
||||
-- 检测是否有人复活
|
||||
function this.CheckRelive()
|
||||
local isReliveFrame = false
|
||||
local removePos = {}
|
||||
for pos, role in pairs(_ReliveRoleList) do
|
||||
if role:Relive() then
|
||||
isReliveFrame = true
|
||||
table.insert(removePos, pos)
|
||||
end
|
||||
end
|
||||
for _, pos in ipairs(removePos) do
|
||||
_ReliveRoleList[pos] = nil
|
||||
end
|
||||
return isReliveFrame
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- 获取角色数据
|
||||
function this.GetRole(camp, pos)
|
||||
return PosList[pos + camp*6]
|
||||
end
|
||||
|
||||
-- 获取某阵营所有角色
|
||||
function this.GetRoleByCamp(camp)
|
||||
local list = {}
|
||||
for i = 1, 6 do
|
||||
list[i] = PosList[i + camp * 6]
|
||||
end
|
||||
return list
|
||||
end
|
||||
|
||||
-- 查找角色
|
||||
function RoleManager.Query(func, inCludeDeadRole)
|
||||
local list = {}
|
||||
local index = 1
|
||||
if func then
|
||||
for pos, v in pairs(PosList) do
|
||||
if func(v) and (inCludeDeadRole or not v:IsRealDead()) then
|
||||
list[index] = v
|
||||
index = index + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
return list
|
||||
end
|
||||
|
||||
|
||||
--对位规则: 1敌方相同对位 2若死亡或不存在,选取相邻阵位最近且阵位索引最小的
|
||||
function this.GetAggro(role)
|
||||
-- 计算开始位置
|
||||
local startPos = role.position
|
||||
startPos = startPos > 3 and startPos - 3 or startPos
|
||||
local target
|
||||
local enemyCamp = role.camp == 0 and 1 or 0
|
||||
|
||||
-- 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]:IsRealDead() then
|
||||
target = PosList[pos]
|
||||
break
|
||||
end
|
||||
end
|
||||
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]:IsRealDead() then
|
||||
target = PosList[pos]
|
||||
break
|
||||
end
|
||||
end
|
||||
if target then return target end
|
||||
end
|
||||
end
|
||||
--对位规则: 1敌方相同对位 2若死亡或不存在,选取相邻阵位最近且阵位索引最小的
|
||||
function this.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]:IsRealDead() 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]:IsRealDead() then
|
||||
table.insert(targetList, plist[pos])
|
||||
end
|
||||
end
|
||||
end
|
||||
return targetList
|
||||
end
|
||||
--获取对位相邻站位的人 chooseType 1 我方 2 敌方(对位的敌人受到嘲讽的影响,若对位的敌人死亡,则选取相邻最近的作为目标)
|
||||
function this.GetNeighbor(role, chooseType)
|
||||
local posList = {}
|
||||
local target
|
||||
if chooseType == 1 then
|
||||
target = role
|
||||
else
|
||||
if role.lockTarget and not role.lockTarget:IsRealDead() then
|
||||
target = role.lockTarget
|
||||
else
|
||||
target = this.GetAggro(role)
|
||||
end
|
||||
end
|
||||
if target then
|
||||
local list = this.Query(function (r) return r.camp == target.camp end)
|
||||
for i=1, #list do
|
||||
if not list[i]:IsRealDead() then
|
||||
if list[i].position == target.position + 3 -- 后排的人
|
||||
or list[i].position == target.position - 3 -- 前排的人
|
||||
or (math.abs(target.position - list[i].position) <= 1 and floor((target.position-1)/3) == floor((list[i].position-1)/3)) then -- 旁边的人和自己
|
||||
table.insert(posList, list[i])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return posList
|
||||
end
|
||||
|
||||
|
||||
function this.Clear()
|
||||
|
||||
for _, obj in pairs(PosList) do
|
||||
obj:Dispose()
|
||||
removeObjList:Add(obj)
|
||||
end
|
||||
PosList = {}
|
||||
|
||||
while removeObjList.size > 0 do
|
||||
rolePool:Put(removeObjList.buffer[removeObjList.size])
|
||||
removeObjList:Remove(removeObjList.size)
|
||||
end
|
||||
|
||||
_DeadRoleList = {}
|
||||
_ReliveRoleList = {}
|
||||
end
|
||||
|
||||
-- 多波
|
||||
function this.ClearEnemy()
|
||||
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)
|
||||
end
|
||||
end
|
||||
for pos, _ in pairs(removePos) do
|
||||
PosList[pos] = nil
|
||||
end
|
||||
end
|
||||
return this
|
|
@ -24,10 +24,18 @@ end
|
|||
function this.InsertSkill(caster, effectData, type, targets, isAdd, isRage)
|
||||
local skill = skillPool:Get()
|
||||
skill:Init(caster, effectData, type, targets, isAdd, isRage)
|
||||
table.insert(this.SkillList, skill, 1)
|
||||
table.insert(this.SkillList, 1, skill)
|
||||
return skill
|
||||
end
|
||||
|
||||
-- 获取是否拥有我的技能未释放
|
||||
function this.HaveMySkill(role)
|
||||
for _, skill in ipairs(this.SkillList) do
|
||||
if skill.owner == role then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
-- 设置用于轮转的方法
|
||||
|
@ -43,7 +51,7 @@ function this.CheckTurnRound()
|
|||
end
|
||||
-- 没有技能释放的时候才轮转
|
||||
if this.TurnRoundFunc then
|
||||
BattleLogic.WaitForTrigger(1, function()
|
||||
BattleLogic.WaitForTrigger(0.3, function()
|
||||
this.TurnRoundFunc()
|
||||
this.TurnRoundFunc = nil
|
||||
end)
|
||||
|
|
Loading…
Reference in New Issue