264 lines
8.9 KiB
Lua
264 lines
8.9 KiB
Lua
RoleLogic = {}
|
||
RoleLogic.__index = RoleLogic
|
||
--local RoleLogic = RoleLogic
|
||
--local RoleDataName = RoleDataName
|
||
--local BattleLogic = BattleLogic
|
||
local Random = Random
|
||
local floor = math.floor
|
||
local max = math.max
|
||
local min = math.min
|
||
local Passivity = require("Modules/Battle/Logic/Base/Passivity")
|
||
|
||
local skillPool = BattleObjectPool.New(function ()
|
||
return Skill:New()
|
||
end)
|
||
|
||
function RoleLogic.New()
|
||
local instance = {uid=0,roleData=0,data=RoleData.New(),camp=0,name=0,roleType=0,
|
||
shield=BattleList.New(),
|
||
exCalDmgList=BattleList.New(),
|
||
proTranList=BattleList.New(),
|
||
buffFilter=BattleList.New(),
|
||
Event=BattleEvent:New(),passiveList=0,isDead=false,Auto=false,IsDebug=false,enable=false}
|
||
setmetatable(instance, RoleLogic)
|
||
return instance
|
||
end
|
||
|
||
function RoleLogic:Init(uid, data)
|
||
self.uid = uid
|
||
self.roleData = data
|
||
|
||
self.data:Init(self, data.property)
|
||
|
||
self.camp = data.camp --阵营 0:我方 1:敌方
|
||
self.name = data.name
|
||
self.roleType = 1 --阵营 1:普通 2:Boss 3:召唤物
|
||
|
||
self.shield:Clear() --护盾列表
|
||
self.exCalDmgList:Clear() --额外计算伤害列表
|
||
self.buffFilter:Clear() --buff屏蔽列表
|
||
self.proTranList:Clear() --属性转换列表
|
||
|
||
self.Event:ClearEvent()
|
||
|
||
self.passiveList = {}
|
||
if data.skill and #data.skill > 0 then
|
||
self.skill = skillPool:Get()
|
||
self.skill:Init(self, data.skill)
|
||
self.skill.sp = 0
|
||
local time = max(6-self:GetRoleData(RoleDataName.Speed)/(8*(self:GetRoleData(RoleDataName.Level)+10)), 1.5)
|
||
self.skill.spPass = floor( time * BattleLogic.GameFrameRate)
|
||
end
|
||
if data.superSkill and #data.superSkill > 0 then
|
||
self.superSkill = skillPool:Get()
|
||
self.superSkill:Init(self, data.superSkill)
|
||
self.superSkill.spPass = floor(self.superSkill.cd * BattleLogic.GameFrameRate)
|
||
self.superSkill.sp = self.superSkill.spPass
|
||
end
|
||
if data.passivity and #data.passivity > 0 then
|
||
for i = 1, #data.passivity do
|
||
local v = data.passivity[i]
|
||
local id = v[1]
|
||
local args = {}
|
||
for j = 2, #v do
|
||
args[j-1] = v[j]
|
||
end
|
||
Passivity[id](self, args)
|
||
end
|
||
end
|
||
|
||
self.isDead = self:GetRoleData(RoleDataName.Hp) <= 0
|
||
self.Auto = true
|
||
self.IsDebug = false
|
||
|
||
self.enable = true --眩晕
|
||
self.ctrl_slient = false --沉默
|
||
self.lockTarget = nil --嘲讽
|
||
self.ctrl_noheal = false --禁疗
|
||
self.ctrl_blind = false --致盲
|
||
|
||
if self.skill and not self.superSkill then
|
||
self.updateFunc = function()
|
||
local skill = self.skill
|
||
if skill.sp >= skill.spPass then
|
||
if self.Auto and self:CanCastSkill() then
|
||
skill:Cast()
|
||
end
|
||
else
|
||
skill.sp = skill.sp + 1
|
||
end
|
||
end
|
||
elseif not self.skill and self.superSkill then
|
||
self.updateFunc = function()
|
||
local superSkill = self.superSkill
|
||
if superSkill.sp >= superSkill.spPass then
|
||
if self.Auto and self:CanCastSkill() then
|
||
superSkill:Cast()
|
||
end
|
||
else
|
||
superSkill.sp = superSkill.sp + 1
|
||
end
|
||
end
|
||
elseif self.skill and self.superSkill then
|
||
self.updateFunc = function()
|
||
local superSkill = self.superSkill
|
||
local skill = self.skill
|
||
if superSkill.sp >= superSkill.spPass then
|
||
if skill.sp >= skill.spPass then
|
||
if self.Auto and self:CanCastSkill() then
|
||
if Random.Range01() <= 0.75 then
|
||
skill:Cast()
|
||
else
|
||
superSkill:Cast()
|
||
end
|
||
end
|
||
else
|
||
skill.sp = skill.sp + 1
|
||
end
|
||
else
|
||
superSkill.sp = superSkill.sp + 1
|
||
end
|
||
end
|
||
else
|
||
self.updateFunc = function() end
|
||
end
|
||
end
|
||
|
||
function RoleLogic:CanCastSkill()
|
||
return self.enable and not self.ctrl_slient and not self.IsDebug and BattleLogic.GetSkillUsable(self.camp)
|
||
end
|
||
|
||
function RoleLogic:GetSkillCD()
|
||
local cd = 0
|
||
if self.skill and not self.superSkill then
|
||
cd = max(self.skill.spPass - self.skill.sp, 0)
|
||
elseif not self.skill and self.superSkill then
|
||
cd = max(self.superSkill.spPass - self.superSkill.sp, 0)
|
||
elseif self.skill and self.superSkill then
|
||
cd = max(self.skill.spPass - self.skill.sp, 0) + max(self.superSkill.spPass - self.superSkill.sp, 0)
|
||
end
|
||
return cd
|
||
end
|
||
|
||
function RoleLogic:AddSkillCD(value, type)
|
||
self.Event:DispatchEvent(BattleEventName.RoleCDChanged)
|
||
if value == 0 then --为0直接清CD
|
||
if self.skill and not self.superSkill then
|
||
self.skill.sp = self.skill.spPass
|
||
elseif not self.skill and self.superSkill then
|
||
self.superSkill.sp = self.superSkill.spPass
|
||
elseif self.skill and self.superSkill then
|
||
self.skill.sp = self.skill.spPass
|
||
self.superSkill.sp = self.superSkill.spPass
|
||
end
|
||
return
|
||
end
|
||
|
||
local cdTotal = 0
|
||
if self.skill and not self.superSkill then
|
||
cdTotal = self.skill.spPass
|
||
elseif not self.skill and self.superSkill then
|
||
cdTotal = self.superSkill.spPass
|
||
elseif self.skill and self.superSkill then
|
||
if self.superSkill.sp >= self.superSkill.spPass then --滑技cd生效,加点技cd,否则加滑技cd+点技cd
|
||
cdTotal = self.skill.spPass
|
||
else
|
||
cdTotal = self.superSkill.spPass + self.skill.spPass
|
||
end
|
||
end
|
||
|
||
local delta = 0
|
||
if type == 1 then --加算
|
||
delta = floor(value * BattleLogic.GameFrameRate)
|
||
elseif type == 2 then --乘加算(百分比属性加算)
|
||
delta = floor(value * cdTotal)
|
||
elseif type == 3 then --减算
|
||
delta = -floor(value * BattleLogic.GameFrameRate)
|
||
elseif type == 4 then --乘减算(百分比属性减算)
|
||
delta = -floor(value * cdTotal)
|
||
end
|
||
|
||
if delta > 0 then --加cd加cd最大值
|
||
if self.skill and not self.superSkill then
|
||
self.skill.spPass = self.skill.spPass + delta
|
||
elseif not self.skill and self.superSkill then
|
||
self.superSkill.spPass = self.superSkill.spPass + delta
|
||
elseif self.skill and self.superSkill then
|
||
if self.superSkill.sp < self.superSkill.spPass then --滑技cd没好,加滑技cd,否则加点技cd
|
||
self.superSkill.spPass = self.superSkill.spPass + delta
|
||
else
|
||
self.skill.spPass = self.skill.spPass + delta
|
||
end
|
||
end
|
||
else --减cd减cd当前值
|
||
delta = -delta
|
||
if self.skill and not self.superSkill then
|
||
self.skill.sp = min(self.skill.sp + delta, self.skill.spPass)
|
||
elseif not self.skill and self.superSkill then
|
||
self.superSkill.sp = min(self.superSkill.sp + delta, self.superSkill.spPass)
|
||
elseif self.skill and self.superSkill then
|
||
if delta <= self.superSkill.spPass - self.superSkill.sp then
|
||
self.superSkill.sp = self.superSkill.sp + delta
|
||
else
|
||
delta = delta - self.superSkill.spPass + self.superSkill.sp --滑技cd不够减,继续减点技cd
|
||
self.superSkill.sp = self.superSkill.spPass
|
||
self.skill.sp = self.skill.sp + delta
|
||
end
|
||
end
|
||
end
|
||
end
|
||
|
||
function RoleLogic:GetRoleData(property)
|
||
local tarPro = self.data:GetData(property)
|
||
local item
|
||
for i=1, self.proTranList.size do
|
||
item = self.proTranList.buffer[i]
|
||
if item.proName == property then
|
||
tarPro = tarPro + self.data:GetData(item.tranProName) * item.tranFactor
|
||
end
|
||
end
|
||
return tarPro
|
||
end
|
||
|
||
--proA替换的属性,factor系数,proB被替换的属性, duration持续时间
|
||
--读取proB属性时,得到的值为proB + proA * factor
|
||
function RoleLogic:AddPropertyTransfer(proA, factor, proB, duration)
|
||
local proTran = {proName = proB, tranProName = proA, tranFactor = factor}
|
||
self.proTranList:Add(proTran)
|
||
local index = self.proTranList.size
|
||
BattleLogic.WaitForTrigger(duration, function ()
|
||
self.proTranList:Remove(index)
|
||
end)
|
||
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
|
||
BattleLogic.BuffMgr:AddBuff(self, buff)
|
||
end
|
||
|
||
function RoleLogic:Dispose()
|
||
if self.skill then
|
||
self.skill:Dispose()
|
||
skillPool:Put(self.skill)
|
||
self.skill = nil
|
||
end
|
||
if self.superSkill then
|
||
self.superSkill:Dispose()
|
||
skillPool:Put(self.superSkill)
|
||
self.superSkill = nil
|
||
end
|
||
end
|
||
|
||
function RoleLogic:Update()
|
||
if not self.enable then
|
||
return
|
||
end
|
||
self.updateFunc()
|
||
end |