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

232 lines
9.5 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-10-23 13:40:57 +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-10-10 11:03:42 +08:00
function Skill:Init(role, effectData, type) --type 0 异妖 1 点技 2 滑技
local isTeamSkill = type == 0
2020-04-10 14:52:41 +08:00
self.type = type
--skill = {技能ID, {目标id1, 效果时间, 效果1, 效果2, ...},{目标id2, 效果时间, 效果3, 效果4, ...}, ...}
2019-03-12 14:05:45 +08:00
--效果 = {效果类型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.isTeamSkill = isTeamSkill
self.teamSkillType = isTeamSkill and floor(effectData[1] / 100) or 0
2020-04-10 14:52:41 +08:00
self.id = effectData[1] -- 技能ID
-- self.EffectDuration = 0 -- 效果命中需要的时间
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
2020-04-10 14:52:41 +08:00
local function takeEffect(caster, target, effects, duration, skill)
2019-04-17 21:04:32 +08:00
for k=1, #effects do
local e = effects[k]
2020-04-10 14:52:41 +08:00
effect[e.type](caster, target, e.args, duration, skill)
2019-04-17 21:04:32 +08:00
if BattleLogic.IsOpenBattleRecord then
BattleLogic.RecordEffect(caster, target, e.type, e.args, duration)
2019-03-12 14:05:45 +08:00
end
end
end
2020-04-10 14:52:41 +08:00
-- 释放技能
-- func 技能释放完成回调
-- targets 指定技能释放目标
-- isAdd 是否是追加技能
function Skill:Cast(func, targets, isAdd)
self.castDoneFunc = func
self.effectTargets = {}
self.isAdd = isAdd
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
2020-04-10 14:52:41 +08:00
local arr = targets or 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-10-23 13:40:57 +08:00
local weight = floor(chooseId % 10000 / 100)
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
2020-04-10 14:52:41 +08:00
-- 全部同时生效
for j=1, count do
if arr[j] and not arr[j].isDead then
takeEffect(self.owner, arr[j], effects, duration, self)
-- 加入目标列表
table.insert(self.effectTargets, arr[j])
2019-03-12 14:05:45 +08:00
end
end
2020-04-10 14:52:41 +08:00
-- if chooseId == 100000 or chooseId == 200000 then --10000 我方aoe 20000 敌方aoe
-- local camp = chooseId == 100000 and self.owner.camp or 1 - self.owner.camp
-- self.owner.Event:DispatchEvent(BattleEventName.AOE, camp)
-- for j=1, count do
-- takeEffect(self.owner, arr[j], effects, duration, self)
-- -- 加入目标列表
-- table.insert(self.effectTargets, arr[j])
-- end
-- elseif weight == 7 then --对位相邻的目标同时触发效果
-- for j=1, count do
-- takeEffect(self.owner, arr[j], effects, duration, self)
-- -- 加入目标列表
-- table.insert(self.effectTargets, arr[j])
-- end
-- else
-- for j = 1, count do
-- local index = j
-- local r = arr[index]
-- -- if not r or r.isDead then --当被选取的目标已经死亡或者没有,则重新选取,若重新选取的目标也死亡或者没有,则从之前的目标中选取第一个不死亡的
-- -- if not targets then -- 如果是指定目标释放的则不再选取目标
-- -- arr = BattleUtil.ChooseTarget(self.owner, chooseId)
-- -- r = arr[index]
-- -- if not r then --当没有新增的被选取目标时,可能为空
-- -- for i=1, #arr do
-- -- if not arr[i].isDead then
-- -- r = arr[i]
-- -- break
-- -- end
-- -- end
-- -- end
-- -- end
-- -- end
-- --
-- if r and not r.isDead then
-- takeEffect(self.owner, r, effects, duration, self)
-- -- 加入目标列表
-- table.insert(self.effectTargets, r)
-- end
-- end
-- end
2019-03-12 14:05:45 +08:00
end)
end
end
2019-04-17 21:04:32 +08:00
2020-04-10 14:52:41 +08:00
-- 计算技能CD的没有用了
-- if not self.isTeamSkill then
-- local type = BattleLogic.Type
-- local isPVEMonster = self.owner.camp == 1 and (type == 1 or type == 2 or type == 4 or type == 5 or type == 8)
-- local time = 0
-- if isPVEMonster then
-- if self.owner.superSkill == self then
-- --怪物绝技读条时间=max10-速度/8*(等级+10,2)
-- time = max(10-self.owner:GetRoleData(RoleDataName.Speed)/(8*(self.owner:GetRoleData(RoleDataName.Level)+10)), 2)
-- else
-- --怪物普技读条时间==max9-速度/8*(等级+10,1)
-- time = max(9-self.owner:GetRoleData(RoleDataName.Speed)/(8*(self.owner:GetRoleData(RoleDataName.Level)+10)), 1)
-- end
-- else
-- if self.owner.superSkill == self then
-- --绝技读条时间=max9-速度/8*(等级+10,3)
-- time = max(9-self.owner:GetRoleData(RoleDataName.Speed)/(8*(self.owner:GetRoleData(RoleDataName.Level)+10)), 3)
-- else
-- --普技读条时间=max7-速度/8*(等级+10,1.5)
-- time = max(7-self.owner:GetRoleData(RoleDataName.Speed)/(8*(self.owner:GetRoleData(RoleDataName.Level)+10)), 1.5)
-- end
-- end
-- self.owner.sp = 0
-- self.owner.spPass = floor(BattleUtil.ErrorCorrection(time) * BattleLogic.GameFrameRate)
-- else
-- self.owner.curSkill = self
-- end
--
if self.isTeamSkill then
2019-07-11 15:18:00 +08:00
self.owner.curSkill = self
2019-04-17 21:04:32 +08:00
end
2020-04-10 14:52:41 +08:00
-- 延时一帧执行,避免战斗还没开始就释放了技能
-- BattleLogic.WaitForTrigger(BattleLogic.GameDeltaTime, function()
self.owner.Event:DispatchEvent(BattleEventName.SkillCast, self)
BattleLogic.Event:DispatchEvent(BattleEventName.SkillCast, self)
-- end)
2019-04-17 21:04:32 +08:00
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)
BattleLogic.WaitForTrigger(duration, function()
BattleLogic.SetSkillUsable(self.owner.camp, true)
2019-10-23 13:40:57 +08:00
self.owner.Event:DispatchEvent(BattleEventName.SkillCastEnd, self)
BattleLogic.Event:DispatchEvent(BattleEventName.SkillCastEnd, self)
2020-04-10 14:52:41 +08:00
for _, tr in ipairs(self.effectTargets) do
tr.Event:DispatchEvent(BattleEventName.BeSkillCastEnd, self)
end
-- 技能结束
self:EndSkill()
2019-04-17 21:04:32 +08:00
end)
2019-03-12 14:05:45 +08:00
2020-04-10 14:52:41 +08:00
end
2019-03-12 14:05:45 +08:00
2020-04-10 14:52:41 +08:00
-- 结束技能
function Skill:EndSkill()
-- 技能结束后摇后结束技能释放
-- if self.isAdd then
-- if self.castDoneFunc then self.castDoneFunc() end
-- else
-- 非追加技能加入技能后摇
BattleLogic.WaitForTrigger(0.5, function()
if self.castDoneFunc then self.castDoneFunc() end
end)
-- end
--
self.effectTargets = {}
self.isAdd = nil
end
2019-03-12 14:05:45 +08:00