back_recharge
gaojie 2019-04-16 17:34:41 +08:00
commit 39bff04d03
8 changed files with 122 additions and 76 deletions

View File

@ -10,14 +10,14 @@ require("Modules.Battle.Logic.Misc.BattleObjectPool")
require("Modules.Battle.Logic.Base.BattleEvent")
require("Modules.Battle.Logic.Base.Random")
require("Modules.Battle.Logic.BattleLogic")
require("Modules.Battle.Logic.RoleLogic")
require("Modules.Battle.Logic.Base.RoleData")
require("Modules.Battle.Logic.Base.Buff")
require("Modules.Battle.Logic.Base.Skill")
require("Modules.Battle.Logic.Base.Passivity")
require("Modules.Battle.Logic.BattleLogic")
require("Modules.Battle.Logic.RoleLogic")
local BattleMain = {}
local BattleLogic = BattleLogic
local Random = Random
@ -123,7 +123,7 @@ function BattleMain.Execute(seed, fightData, optionData)
_fightData = fightData
_optionData = optionData
print(PrintTable(fightData))
--print(PrintTable(fightData))
--该开关用于输出战斗过程中的日志,用于验证前后端是否出现战斗不同步
BattleLogic.IsOpenBattleRecord = false

View File

@ -18,6 +18,10 @@ local putBuff = function(buff)
end
end
local buffListPool = BattleObjectPool.New(function ()
return BattleList.New()
end)
function Buff:New()
local o = {}
setmetatable(o, self)
@ -51,13 +55,24 @@ function BuffManager.New()
return instance
end
function BuffManager:Init(owner)
self.buffQueue:Clear()
function BuffManager:Init()
for i=1, self.buffQueue.size do
buffListPool:Put(self.buffQueue:Dequeue())
end
local list
for i = 1, self.buffList.size do
list = self.buffList.vList[i]
for j=1, list.size do
putBuff(list.buffer[j])
end
list:Clear()
buffListPool:Put(list)
end
self.buffList:Clear()
self.owner = owner
end
function BuffManager:AddBuff(buff)
function BuffManager:AddBuff(target, buff)
buff.target = target
self.buffQueue:Enqueue(buff)
if not buff.exCtrlTime then
buff.exCtrlTime = 0
@ -76,12 +91,13 @@ function BuffManager:AddBuff(buff)
buff.frameInterval = floor(buff.interval * BattleLogic.GameFrameRate)
end
function BuffManager:HasBuff(type, checkFunc)
local v
function BuffManager:HasBuff(target, type, checkFunc)
local v, buff
for i=1, self.buffList:Count() do
v = self.buffList.vList[i]
if v.size > 0 then
if v.buffer[1].type == type and (not checkFunc or (checkFunc and checkFunc(v.buffer[1]))) then
buff = v.buffer[1]
if buff.target == target and buff.type == type and (not checkFunc or (checkFunc and checkFunc(buff))) then
return true
end
end
@ -89,25 +105,23 @@ function BuffManager:HasBuff(type, checkFunc)
return false
end
function BuffManager:ClearBuff(func)
function BuffManager:ClearBuff(target, func)
local list, buff, idx
for i = 1, self.buffList.size do
local k = self.buffList.kList[i]
local v = self.buffList.vList[i]
if v.size > 0 then
local removeCount = 0
local idx = 1
while idx <= v.size do
if func(v.buffer[idx]) then
putBuff:Put(v.buffer[idx])
v:Remove(idx)
removeCount = removeCount + 1
list = self.buffList.vList[i]
if list.size > 0 then
idx = 1
while idx <= list.size do
buff = list.buffer[idx]
if buff.target == target and (not func or (func and func(buff))) then
buff:OnEnd()
buff.target.Event:DispatchEvent(BattleEventName.BuffEnd, buff)
putBuff(buff)
list:Remove(idx)
else
idx = idx + 1
end
end
if removeCount > 0 then
self.owner.Event:DispatchEvent(BattleEventName.BuffCountChange, k, v.size)
end
end
end
end
@ -122,42 +136,34 @@ end
function BuffManager:Update()
for i=1, self.buffQueue.size do
local buff = self.buffQueue:Dequeue()
if not buff.caster then
--logErrorTrace("buff's caster can't be nil!")
return
end
local buffList
if not self.buffList.kvList[buff.id] then
buffList = BattleList.New()
buffList = buffListPool:Get()
self.buffList:Add(buff.id, buffList)
else
buffList = self.buffList.kvList[buff.id]
end
if buff.cover and buffList.size > 0 then
if buffList.buffer[1]:OnCover(buff) then --判定该效果能否被覆盖
buffList.buffer[1]:OnEnd(self.owner)
self.owner.Event:DispatchEvent(BattleEventName.BuffEnd, buffList.buffer[1])
buffList.buffer[1]:OnEnd()
buff.target.Event:DispatchEvent(BattleEventName.BuffEnd, buffList.buffer[1])
buffList.buffer[1] = buff
buff.target = self.owner
buff:OnStart()
self.owner.Event:DispatchEvent(BattleEventName.BuffStart, buff)
self.owner.Event:DispatchEvent(BattleEventName.BuffCover, buff)
buff.target.Event:DispatchEvent(BattleEventName.BuffStart, buff)
buff.target.Event:DispatchEvent(BattleEventName.BuffCover, buff)
end
else
if buff.maxCount == 0 or buffList.size < buff.maxCount then --限制相同效果的数量为0则不限制
buffList:Add(buff)
buff.target = self.owner
buff:OnStart()
self.owner.Event:DispatchEvent(BattleEventName.BuffStart, buff)
self.owner.Event:DispatchEvent(BattleEventName.BuffCountChange, buff.id, buffList.size)
buff.target.Event:DispatchEvent(BattleEventName.BuffStart, buff)
end
end
end
local v
for i = 1, self.buffList.size do
local k = self.buffList.kList[i]
local v = self.buffList.vList[i]
v = self.buffList.vList[i]
if v.size > 0 then
local removeCount = 0
local idx = 1
local buff
while idx <= v.size do
@ -193,16 +199,12 @@ function BuffManager:Update()
if buff.disperse then
buff:OnEnd()
buff.target.Event:DispatchEvent(BattleEventName.BuffEnd, buff)
putBuff(v.buffer[idx])
putBuff(buff)
v:Remove(idx)
removeCount = removeCount + 1
else
idx = idx + 1
end
end
if removeCount > 0 then
self.owner.Event:DispatchEvent(BattleEventName.BuffCountChange, k, v.size)
end
end
end
end

View File

@ -1,4 +1,6 @@
local floor = math.floor
local min = math.min
local max = math.max
--local RoleDataName = RoleDataName
--local BattleLogic = BattleLogic
--local BattleUtil = BattleUtil
@ -119,7 +121,7 @@ local effectList = {
end
end,
--[b]%改变[c]下次重击技能CD[a]秒
--a[float],b[float]
--a[float],b[float],c[改变类型]
[8] = function(caster, target, args, interval)
local f1 = args[1]
local f2 = args[2] * (1 + caster:GetRoleData(RoleDataName.Hit) / (1 + target:GetRoleData(RoleDataName.Dodge)))
@ -131,13 +133,13 @@ local effectList = {
target.skill.sp = target.skill.spPass
else
if ct == 1 then --加算
target.skill.sp = target.skill.sp - floor(f1 * BattleLogic.GameFrameRate)
target.skill.sp = max(target.skill.sp - floor(f1 * BattleLogic.GameFrameRate), 0)
elseif ct == 2 then --乘加算(百分比属性加算)
target.skill.sp = floor(target.skill.sp * (1 - f1))
target.skill.sp = max(target.skill.sp - floor(target.skill.spPass * f1),0)
elseif ct == 3 then --减算
target.skill.sp = target.skill.sp + floor(f1 * BattleLogic.GameFrameRate)
target.skill.sp = min(target.skill.sp + floor(f1 * BattleLogic.GameFrameRate), target.skill.spPass)
elseif ct == 4 then --乘减算(百分比属性减算)
target.skill.sp = floor(target.skill.sp * (1 + f1))
target.skill.sp = min(target.skill.sp + floor(target.skill.spPass * f1), target.skill.spPass)
end
end
end
@ -198,8 +200,8 @@ local effectList = {
target:AddBuff(Buff.Create(caster, BuffName.DOT, f2, 1, 0, dt, f1))
end)
end,
--造成[c],每秒造成[d]的[e]的伤害,持续[f]秒
--c[持续伤害状态].d[float],e[伤害类型],f[int]
--造成[a],每秒造成[b]的[c]的伤害,持续[d]秒
--a[持续伤害状态].b[float],c[伤害类型],d[int]
[13] = function(caster, target, args, interval)
local d1 = args[1]
local f1 = args[2]
@ -223,7 +225,7 @@ local effectList = {
end
BattleLogic.WaitForTrigger(interval, function ()
local layer
if target.BuffMgr:HasBuff(BuffName.Brand, function (buff)
if BattleLogic.BuffMgr:HasBuff(target, BuffName.Brand, function (buff)
local b = buff.flag == rid
if b then
layer = buff.layer
@ -354,7 +356,7 @@ local effectList = {
BattleLogic.Event:DispatchEvent(BattleEventName.ZoomChange, target, interval)
end
BattleLogic.WaitForTrigger(interval, function ()
if target.BuffMgr:HasBuff(BuffName.Control, function (buff) return i1 == 0 or buff.ctrlType == i1 end) then
if BattleLogic.BuffMgr:HasBuff(target, BuffName.Control, function (buff) return i1 == 0 or buff.ctrlType == i1 end) then
f1 = f1 + f2
end
BattleUtil.CalDamage(caster, target, dt, f1)
@ -371,7 +373,7 @@ local effectList = {
local f3 = args[6]
BattleLogic.WaitForTrigger(interval, function ()
BattleUtil.CalDamage(caster, target, dt, f1)
if target.BuffMgr:HasBuff(BuffName.DOT, function (buff) return dot == 0 or buff.damageType == dot end) then
if BattleLogic.BuffMgr:HasBuff(target, BuffName.DOT, function (buff) return dot == 0 or buff.damageType == dot end) then
BattleUtil.RandomAction(f2, function ()
target:AddBuff(Buff.Create(caster, BuffName.Control, f3, ct))
end)
@ -386,7 +388,7 @@ local effectList = {
local dot = args[3]
local f2 = args[4]
BattleLogic.WaitForTrigger(interval, function ()
if target.BuffMgr:HasBuff(BuffName.DOT, function (buff) return dot == 0 or buff.damageType == dot end) then
if BattleLogic.BuffMgr:HasBuff(target, BuffName.DOT, function (buff) return dot == 0 or buff.damageType == dot end) then
f1 = f1 + f2
end
BattleUtil.CalDamage(caster, target, dt, f1)
@ -404,7 +406,7 @@ local effectList = {
BattleLogic.Event:DispatchEvent(BattleEventName.ZoomChange, target, interval)
end
BattleLogic.WaitForTrigger(interval, function ()
if target.BuffMgr:HasBuff(BuffName.HOT, function (buff) return true end) then
if BattleLogic.BuffMgr:HasBuff(target, BuffName.HOT, function (buff) return true end) then
f1 = f1 + f2
end
BattleUtil.CalDamage(caster, target, dt, f1)
@ -430,7 +432,7 @@ local effectList = {
BattleLogic.WaitForTrigger(interval, function ()
local func = function(damage)
if target.BuffMgr:HasBuff(BuffName.DOT, function (buff) return dot == 0 or buff.damageType == dot end) then
if BattleLogic.BuffMgr:HasBuff(target, BuffName.DOT, function (buff) return dot == 0 or buff.damageType == dot end) then
damage = damage + floor(damage * f1)
end
return damage
@ -479,7 +481,7 @@ local effectList = {
BattleLogic.Event:DispatchEvent(BattleEventName.ZoomChange, target, interval)
end
BattleLogic.WaitForTrigger(interval, function ()
if target.BuffMgr:HasBuff(BuffName.DOT, function (buff) return dot == 0 or buff.damageType == dot end) then
if BattleLogic.BuffMgr:HasBuff(target, BuffName.DOT, function (buff) return dot == 0 or buff.damageType == dot end) then
f1 = f1 + f2
end
BattleUtil.CalDamage(caster, target, dt, f1)
@ -524,7 +526,7 @@ local effectList = {
BattleLogic.Event:DispatchEvent(BattleEventName.ZoomChange, target, interval)
end
BattleLogic.WaitForTrigger(interval, function ()
if target.BuffMgr:HasBuff(BuffName.Control, function (buff) return ct == 0 or buff.ctrlType == ct end) then
if BattleLogic.BuffMgr:HasBuff(target, BuffName.Control, function (buff) return ct == 0 or buff.ctrlType == ct end) then
BattleUtil.CalDamage(caster, target, dt, f1, f2)
else
BattleUtil.CalDamage(caster, target, dt, f1)
@ -543,6 +545,18 @@ local effectList = {
end)
end)
end,
--[b]%改变[d]重击技能CD[a]秒 ,持续[c]秒 0代表清除所有
--a[float],b[float],c[改变类型]
[32] = function(caster, target, args, interval)
local f1 = args[1] * (1 + caster:GetRoleData(RoleDataName.Hit) / (1 + target:GetRoleData(RoleDataName.Dodge)))
local ib1 = args[2]
local f2 = args[3]
BattleLogic.WaitForTrigger(interval, function ()
BattleUtil.RandomAction(f1, function ()
target:AddBuff(Buff.Create(caster, BuffName.Immune, f2, ib1))
end)
end)
end,
}
return effectList

View File

@ -200,12 +200,6 @@ function Skill:ResetCD()
BattleLogic.SetAggro(self.owner, 0)
end
local function takeEffect(type, caster, target, args, interval)
effect[type](caster, target, args, interval)
if BattleLogic.IsOpenBattleRecord then
BattleLogic.RecordEffect(caster, target, type, args, interval)
end
end
function Skill:Cast()
for i=1, self.effectList.size do
local effectGroup = self.effectList.buffer[i]
@ -227,7 +221,10 @@ function Skill:Cast()
for j=1, #arr do
for k=1, #effectGroup[3] do
local v = effectGroup[3][k]
takeEffect(v[1], self.owner, arr[j], v[2], duration)
effect[v[1]](self.owner, arr[j], v[2], duration)
--if BattleLogic.IsOpenBattleRecord then
-- BattleLogic.RecordEffect(v[1], self.owner, arr[j], v[2], duration)
--end
end
end
elseif chooseId == 20000 then --敌方aoe
@ -235,14 +232,20 @@ function Skill:Cast()
for j=1, #arr do
for k=1, #effectGroup[3] do
local v = effectGroup[3][k]
takeEffect(v[1], self.owner, arr[j], v[2], duration)
effect[v[1]](self.owner, arr[j], v[2], duration)
--if BattleLogic.IsOpenBattleRecord then
-- BattleLogic.RecordEffect(v[1], self.owner, arr[j], v[2], duration)
--end
end
end
elseif nn == 1 or nn == 3 then
for j=1, #arr do
for k=1, #effectGroup[3] do
local v = effectGroup[3][k]
takeEffect(v[1], self.owner, arr[j], v[2], duration)
effect[v[1]](self.owner, arr[j], v[2], duration)
--if BattleLogic.IsOpenBattleRecord then
-- BattleLogic.RecordEffect(v[1], self.owner, arr[j], v[2], duration)
--end
end
end
else
@ -262,7 +265,10 @@ function Skill:Cast()
r = arr[i]
for k=1, #effectGroup[3] do
local v = effectGroup[3][k]
takeEffect(v[1], self.owner, r, v[2], cd)
effect[v[1]](self.owner, r, v[2], cd)
--if BattleLogic.IsOpenBattleRecord then
-- BattleLogic.RecordEffect(v[1], self.owner, r, v[2], cd)
--end
end
return
end
@ -275,7 +281,10 @@ function Skill:Cast()
self.choosedList:Add(r)
for k=1, #effectGroup[3] do
local v = effectGroup[3][k]
takeEffect(v[1], self.owner, r, v[2], cd)
effect[v[1]](self.owner, r, v[2], cd)
--if BattleLogic.IsOpenBattleRecord then
-- BattleLogic.RecordEffect(v[1], self.owner, r, v[2], cd)
--end
end
end)
end

View File

@ -21,6 +21,7 @@ local enemySkillUsable
BattleLogic.IsEnd = false
BattleLogic.Result = -1
BattleLogic.Event = BattleEvent.New()
BattleLogic.BuffMgr = BuffManager.New()
local playerTeamDummyRole = {camp = 0, Event = BattleLogic.Event, isTeam = true}
local enemyTeamDummyRole = {camp = 0, Event = BattleLogic.Event, isTeam = true}
@ -88,6 +89,7 @@ function BattleLogic.Init(data, optionData)
enemySkillUsable = true
BattleLogic.Event:ClearEvent()
BattleLogic.BuffMgr:Init()
BattleLogic.IsEnd = false
BattleLogic.Result = -1
end
@ -383,6 +385,8 @@ function BattleLogic.Update()
enemyMP = 0
end
BattleLogic.BuffMgr:Update()
bMyAllDead = true
bEnemyAllDead = true
for i=1, objList.size do

View File

@ -9,6 +9,14 @@ function DOT:SetData(...)
self.damagePro, --1 物理 2 魔法
self.damageFactor = ... --伤害系数
self.isDeBuff = true
--if self.damageType == 2 then
-- self.cover = true
-- self.layer = 1
--else
-- self.cover = false
-- self.layer = nil
--end
end
--初始化后调用一次
@ -31,6 +39,10 @@ end
--只有当cover字段为true时触发返回true则被新效果覆盖
function DOT:OnCover(newBuff)
--log("DOT:OnCover")
--if self.damageType == 2 then
-- newBuff.layer = self.layer + 1
-- newBuff.damageFactor =
--end
return true
end

View File

@ -82,8 +82,12 @@ function BattleUtil.ApplyDamage(atkRole, defRole, damage, bCrit)
if defRole:GetRoleData(RoleDataName.Hp) <= 0 then
defRole.isDead = true
BattleLogic.BuffMgr:ClearBuff(defRole)
defRole.Event:DispatchEvent(BattleEventName.RoleDead)
BattleLogic.Event:DispatchEvent(BattleEventName.BattleRoleDead, defRole)
if defRole.camp == 1 then
BattleLogic.Event:DispatchEvent(BattleEventName.ZoomChange, BattleLogic.GetAggro(0), 0.3)
end
end
end
return finalDmg

View File

@ -17,7 +17,7 @@ function RoleLogic.New()
shield=BattleList.New(),
exCalDmgList=BattleList.New(),
buffFilter=BattleList.New(),
BuffMgr=BuffManager.New(),Event=BattleEvent:New(),passiveList=0,isDead=false,Auto=false,IsDebug=false,enable=false}
Event=BattleEvent:New(),passiveList=0,isDead=false,Auto=false,IsDebug=false,enable=false}
setmetatable(instance, RoleLogic)
return instance
end
@ -36,7 +36,6 @@ function RoleLogic:Init(uid, data)
self.exCalDmgList:Clear() --额外计算伤害列表
self.buffFilter:Clear() --buff屏蔽列表
self.BuffMgr:Init(self)
self.Event:ClearEvent()
self.passiveList = {}
@ -71,12 +70,15 @@ function RoleLogic:GetRoleData(property)
end
function RoleLogic:AddBuff(buff)
if self.isDead then
return
end
for i=1, self.buffFilter.size do
if self.buffFilter.buffer[i](buff) then
return
end
end
self.BuffMgr:AddBuff(buff)
BattleLogic.BuffMgr:AddBuff(self, buff)
end
function RoleLogic:Dispose()
@ -93,7 +95,6 @@ function RoleLogic:Dispose()
end
function RoleLogic:Update()
self.BuffMgr:Update()
if not self.enable then
return
end