miduo_server/luafight/Modules/Battle/Logic/RoleLogic.lua

152 lines
4.5 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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 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(),
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普通 2Boss 3召唤物
self.shield:Clear() --护盾列表
self.exCalDmgList:Clear() --额外计算伤害列表
self.buffFilter:Clear() --buff屏蔽列表
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
for i = 1, #data.passivity do
local v = data.passivity[i]
local id = v[1]
local args = v[2]
Passivity[id](self, args)
end
self.isDead = self:GetRoleData(RoleDataName.Hp) <= 0
self.Auto = true
self.IsDebug = false
self.enable = true
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:GetRoleData(property)
return self.data:GetData(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
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