124 lines
3.8 KiB
Lua
124 lines
3.8 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 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(),
|
||
BuffMgr=BuffManager.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.BuffMgr:Init(self)
|
||
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 = false
|
||
self.Auto = true
|
||
self.IsDebug = false
|
||
self.enable = true
|
||
end
|
||
|
||
function RoleLogic:GetRoleData(property)
|
||
return self.data:GetData(property)
|
||
end
|
||
|
||
function RoleLogic:AddBuff(buff)
|
||
self.BuffMgr:AddBuff(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()
|
||
self.BuffMgr:Update()
|
||
if not self.enable then
|
||
return
|
||
end
|
||
if self.superSkill then
|
||
if self.superSkill.sp >= self.superSkill.spPass then
|
||
if self.skill then
|
||
if self.skill.sp >= self.skill.spPass then
|
||
if self.Auto and not self.IsDebug and BattleLogic.GetSkillUsable(self.camp) then
|
||
if Random.Range01() <= 0.75 then
|
||
self.skill:Cast()
|
||
else
|
||
self.superSkill:Cast()
|
||
end
|
||
end
|
||
else
|
||
self.skill.sp = self.skill.sp + 1
|
||
end
|
||
else
|
||
if self.Auto and not self.IsDebug and BattleLogic.GetSkillUsable(self.camp) then
|
||
self.superSkill:Cast()
|
||
end
|
||
end
|
||
else
|
||
self.superSkill.sp = self.superSkill.sp + 1
|
||
end
|
||
else
|
||
if self.skill then
|
||
if self.skill.sp >= self.skill.spPass then
|
||
if self.Auto and not self.IsDebug and BattleLogic.GetSkillUsable(self.camp) then
|
||
self.skill:Cast()
|
||
end
|
||
else
|
||
self.skill.sp = self.skill.sp + 1
|
||
end
|
||
end
|
||
end
|
||
end |