miduo_server/luafight/Modules/Battle/Logic/Base/Skill.lua

207 lines
8.3 KiB
Lua
Raw Normal View History

2019-03-12 14:05:45 +08:00
local effect = require("Modules/Battle/Logic/Base/Effect")
local floor = math.floor
local max = math.max
2019-03-21 14:33:56 +08:00
local min = math.min
2019-03-12 14:05:45 +08:00
--local BattleConst = BattleConst
--local RoleDataName = RoleDataName
--local BattleEventName = BattleEventName
2019-03-25 10:58:38 +08:00
local effectPool = BattleObjectPool.New(function ()
2019-04-17 21:04:32 +08:00
return { type = 0, args = {}} -- type, {args, ...}
2019-03-25 10:58:38 +08:00
end)
local effectGroupPool = BattleObjectPool.New(function ()
2019-04-17 21:04:32 +08:00
return { chooseId = 0, duration = 0, effects = {}} -- chooseId, duration, {effect1, effect2, ...}
2019-03-25 10:58:38 +08:00
end)
2019-03-12 14:05:45 +08:00
Skill = {}
2019-03-21 14:33:56 +08:00
function Skill:New()
2019-07-25 16:20:33 +08:00
local o = {cd=0,effectList = BattleList.New(),owner=0,sp=0,spPass = 0,isTeamSkill=false,teamSkillType=0 }
2019-03-21 14:33:56 +08:00
setmetatable(o, self)
self.__index = self
return o
end
2019-07-25 16:20:33 +08:00
function Skill:Init(role, effectData, isTeamSkill)
self.cd = isTeamSkill and effectData[1] % 100 or effectData[1] --异妖技能的cd数据为类型*100 + cd
2019-03-12 14:05:45 +08:00
--skill = {cd, {目标id1, 效果时间, 效果1, 效果2, ...},{目标id2, 效果时间, 效果3, 效果4, ...}, ...}
--效果 = {效果类型id, 效果参数1, 效果参数2, ...}
2019-03-21 14:33:56 +08:00
self.effectList:Clear()
self.owner = role
2019-07-25 16:20:33 +08:00
self.sp = isTeamSkill and floor(self.cd * BattleLogic.GameFrameRate) or 0
self.spPass = self.sp
self.isTeamSkill = isTeamSkill
self.teamSkillType = isTeamSkill and floor(effectData[1] / 100) or 0
2019-07-15 19:25:22 +08:00
self.isManual = false
2019-03-12 14:05:45 +08:00
for i=2, #effectData do
2019-04-17 21:04:32 +08:00
local v = effectData[i]
2019-03-25 10:58:38 +08:00
local effectGroup = effectGroupPool:Get() -- chooseId, duration, {effect1, effect2, ...}
2019-04-17 21:04:32 +08:00
effectGroup.chooseId = v[1] --chooseId
effectGroup.duration = v[2] --duration
2019-03-12 14:05:45 +08:00
for j=3, #v do --effectList
2019-03-25 10:58:38 +08:00
local effect = effectPool:Get() -- type, {args, ...}
2019-04-17 21:04:32 +08:00
effect.type = v[j][1]
2019-03-12 14:05:45 +08:00
for k=2, #v[j] do
2019-04-17 21:04:32 +08:00
effect.args[k-1] = v[j][k]
2019-03-12 14:05:45 +08:00
end
2019-04-17 21:04:32 +08:00
effectGroup.effects[j-2] = effect
2019-03-12 14:05:45 +08:00
end
2019-03-21 14:33:56 +08:00
self.effectList:Add(effectGroup)
2019-03-12 14:05:45 +08:00
end
2019-03-21 14:33:56 +08:00
end
2019-03-12 14:05:45 +08:00
2019-03-25 10:58:38 +08:00
function Skill:Dispose()
while self.effectList.size > 0 do
2019-04-17 21:04:32 +08:00
local effectGroup = self.effectList.buffer[self.effectList.size]
for k=1, #effectGroup.effects do
local effect = effectGroup.effects[k]
for j=1, #effect.args do
effect.args[j] = nil
2019-03-25 19:41:30 +08:00
end
effectPool:Put(effect)
2019-04-17 21:04:32 +08:00
effectGroup.effects[k] = nil
2019-03-25 10:58:38 +08:00
end
effectGroupPool:Put(effectGroup)
self.effectList:Remove(self.effectList.size)
end
end
2019-04-17 21:04:32 +08:00
local function takeEffect(caster, target, effects, duration)
for k=1, #effects do
local e = effects[k]
effect[e.type](caster, target, e.args, duration)
if BattleLogic.IsOpenBattleRecord then
BattleLogic.RecordEffect(caster, target, e.type, e.args, duration)
2019-03-12 14:05:45 +08:00
end
end
end
function Skill:Cast()
2019-03-21 14:33:56 +08:00
for i=1, self.effectList.size do
local effectGroup = self.effectList.buffer[i]
2019-04-17 21:04:32 +08:00
local chooseId = effectGroup.chooseId
2019-06-05 11:29:24 +08:00
local arr = BattleUtil.ChooseTarget(self.owner, chooseId)
2019-03-12 14:05:45 +08:00
if #arr > 0 then
2019-04-17 21:04:32 +08:00
--效果延迟1帧生效
BattleLogic.WaitForTrigger(BattleLogic.GameDeltaTime, function()
local duration = effectGroup.duration
local effects = effectGroup.effects
2019-03-12 14:05:45 +08:00
local nn = floor(chooseId / 10000) % 10
2019-05-10 19:31:20 +08:00
local count = min(chooseId % 10, #arr)
2019-05-07 20:01:07 +08:00
if count == 0 then
count = #arr
end
2019-03-12 14:05:45 +08:00
if self.owner.camp == 0 and nn == 2 then --我方释放效果开始切镜头
BattleLogic.Event:DispatchEvent(BattleEventName.ZoomIn, 0.3)
BattleLogic.WaitForTrigger(duration, function()
BattleLogic.Event:DispatchEvent(BattleEventName.ZoomOut, 0.3)
end)
end
2019-04-20 13:02:14 +08:00
if chooseId == 10000 or chooseId == 20000 then --10000 我方aoe 20000 敌方aoe
local camp = chooseId == 10000 and self.owner.camp or 1 - self.owner.camp
self.owner.Event:DispatchEvent(BattleEventName.AOE, camp)
2019-05-07 20:01:07 +08:00
for j=1, count do
2019-04-17 21:04:32 +08:00
takeEffect(self.owner, arr[j], effects, duration)
2019-03-12 14:05:45 +08:00
end
2019-03-21 14:33:56 +08:00
elseif nn == 1 or nn == 3 then
2019-05-07 20:01:07 +08:00
for j=1, count do
2019-04-17 21:04:32 +08:00
takeEffect(self.owner, arr[j], effects, duration)
2019-03-12 14:05:45 +08:00
end
else
2019-03-21 14:33:56 +08:00
local d = duration / (count + 1) --分割多人目标施加效果的时间按照1+1+..+2的时间权重占比分配
for j=1, count do
2019-03-12 14:05:45 +08:00
local index = j
2019-03-21 14:33:56 +08:00
local cd = j == count and d * 2 or d
2019-03-12 14:05:45 +08:00
BattleLogic.WaitForTrigger(d * (j-1), function()
local r = arr[index]
2019-03-21 14:33:56 +08:00
if not r or r.isDead then --当被选取的目标已经死亡或者没有,则重新选取,若重新选取的目标也死亡或者没有,则从之前的目标中选取第一个不死亡的
2019-06-05 11:29:24 +08:00
arr = BattleUtil.ChooseTarget(self.owner, chooseId)
2019-03-12 14:05:45 +08:00
r = arr[index]
if not r then --当没有新增的被选取目标时,可能为空
for i=1, #arr do
if not arr[i].isDead then
2019-04-17 21:04:32 +08:00
takeEffect(self.owner, arr[i], effects, cd)
2019-03-12 14:05:45 +08:00
return
end
end
if not r then
return
end
end
end
2019-04-17 21:04:32 +08:00
takeEffect(self.owner, r, effects, cd)
2019-03-12 14:05:45 +08:00
end)
end
end
end)
end
end
2019-04-17 21:04:32 +08:00
BattleLogic.SetAggro(self.owner)
if not self.isTeamSkill then
2019-06-05 15:25:06 +08:00
local time = max(8-self.owner:GetRoleData(RoleDataName.Speed)/(8*(self.owner:GetRoleData(RoleDataName.Level)+10)), 1.5)
2019-08-06 20:55:47 +08:00
time = BattleUtil.ErrorCorrection(time)
2019-04-17 21:04:32 +08:00
if self.owner.superSkill == self then
self.sp = 0
self.spPass = floor(self.cd * BattleLogic.GameFrameRate)
BattleLogic.AddMP(self.owner.camp, 10)
if self.owner.skill then
local skill = self.owner.skill
skill.sp = 0
skill.spPass = floor(time * BattleLogic.GameFrameRate)
end
else
self.sp = 0
self.spPass = floor(time * BattleLogic.GameFrameRate)
2019-07-08 10:25:43 +08:00
BattleLogic.AddMP(self.owner.camp, 5)
2019-04-17 21:04:32 +08:00
end
self.owner.Event:DispatchEvent(BattleEventName.SkillCast, self)
else
2019-07-25 16:20:33 +08:00
self.sp = 0
2019-07-11 15:18:00 +08:00
self.owner.curSkill = self
2019-07-25 16:20:33 +08:00
BattleLogic.Event:DispatchEvent(BattleEventName.SkillCast, self)
2019-04-17 21:04:32 +08:00
end
2019-05-07 20:01:07 +08:00
--技能的施法时间计算根据当前目标id关联的持续时间取其中时间最长的一个
2019-04-17 21:04:32 +08:00
local duration = 0
for i=1, self.effectList.size do
duration = max(duration, self.effectList.buffer[i].duration)
end
BattleLogic.SetSkillUsable(self.owner.camp, false)
2019-07-15 19:25:22 +08:00
self.isManual = false
2019-04-17 21:04:32 +08:00
BattleLogic.WaitForTrigger(duration, function()
BattleLogic.SetSkillUsable(self.owner.camp, true)
2019-05-07 20:01:07 +08:00
if not self.isTeamSkill then
self.owner.Event:DispatchEvent(BattleEventName.SkillCastEnd, self)
else
BattleLogic.Event:DispatchEvent(BattleEventName.SkillCastEnd, self.cd)
end
2019-04-17 21:04:32 +08:00
end)
2019-03-12 14:05:45 +08:00
end
--表现层调用
function Skill:CanManualCast()
2019-07-15 19:25:22 +08:00
return not self.isManual and self.owner.enable and not self.owner.ctrl_slient and
self.owner.camp == 0 and not self.owner.Auto and self.sp >= self.spPass
2019-03-12 14:05:45 +08:00
end
--表现层调用
function Skill:ManualCast()
--非调试模式下,只有我方阵营角色,且处在非自动状态下可手动释放技能
local b = self:CanManualCast()
--调试模式下,可无条件手动释放技能
local b2 = self.owner.IsDebug
if b or b2 then
if self.owner.skill == self then
BattleLogic.AddOption(2, self.owner.uid)
else
BattleLogic.AddOption(3, self.owner.uid)
end
2019-07-15 19:25:22 +08:00
self.isManual = true
2019-03-12 14:05:45 +08:00
end
end