2019-03-12 14:05:45 +08:00
|
|
|
|
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")
|
|
|
|
|
|
2019-03-21 14:33:56 +08:00
|
|
|
|
local skillPool = BattleObjectPool.New(function ()
|
|
|
|
|
return Skill:New()
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
function RoleLogic.New()
|
2019-03-26 15:11:47 +08:00
|
|
|
|
local instance = {uid=0,roleData=0,data=RoleData.New(),camp=0,name=0,roleType=0,
|
|
|
|
|
shield=BattleList.New(),
|
|
|
|
|
exCalDmgList=BattleList.New(),
|
2019-05-07 20:01:07 +08:00
|
|
|
|
proTranList=BattleList.New(),
|
2019-03-26 15:11:47 +08:00
|
|
|
|
buffFilter=BattleList.New(),
|
2019-04-16 14:32:11 +08:00
|
|
|
|
Event=BattleEvent:New(),passiveList=0,isDead=false,Auto=false,IsDebug=false,enable=false}
|
2019-03-12 14:05:45 +08:00
|
|
|
|
setmetatable(instance, RoleLogic)
|
2019-03-21 14:33:56 +08:00
|
|
|
|
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:召唤物
|
2019-03-12 14:05:45 +08:00
|
|
|
|
|
2019-03-21 14:33:56 +08:00
|
|
|
|
self.shield:Clear() --护盾列表
|
|
|
|
|
self.exCalDmgList:Clear() --额外计算伤害列表
|
2019-03-26 15:11:47 +08:00
|
|
|
|
self.buffFilter:Clear() --buff屏蔽列表
|
2019-05-07 20:01:07 +08:00
|
|
|
|
self.proTranList:Clear() --属性转换列表
|
2019-03-12 14:05:45 +08:00
|
|
|
|
|
2019-03-21 14:33:56 +08:00
|
|
|
|
self.Event:ClearEvent()
|
2019-03-12 14:05:45 +08:00
|
|
|
|
|
2019-03-21 14:33:56 +08:00
|
|
|
|
self.passiveList = {}
|
2019-03-12 14:05:45 +08:00
|
|
|
|
if data.skill and #data.skill > 0 then
|
2019-03-21 14:33:56 +08:00
|
|
|
|
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)
|
2019-03-12 14:05:45 +08:00
|
|
|
|
end
|
|
|
|
|
if data.superSkill and #data.superSkill > 0 then
|
2019-03-21 14:33:56 +08:00
|
|
|
|
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
|
2019-03-12 14:05:45 +08:00
|
|
|
|
end
|
2019-05-09 17:50:38 +08:00
|
|
|
|
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
|
2019-03-12 14:05:45 +08:00
|
|
|
|
end
|
|
|
|
|
|
2019-04-20 17:56:19 +08:00
|
|
|
|
self.isDead = self:GetRoleData(RoleDataName.Hp) <= 0
|
2019-03-21 14:33:56 +08:00
|
|
|
|
self.Auto = true
|
|
|
|
|
self.IsDebug = false
|
|
|
|
|
self.enable = true
|
2019-04-17 21:04:32 +08:00
|
|
|
|
|
|
|
|
|
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)
|
2019-03-12 14:05:45 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function RoleLogic:GetRoleData(property)
|
2019-05-07 20:01:07 +08:00
|
|
|
|
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)
|
2019-03-12 14:05:45 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function RoleLogic:AddBuff(buff)
|
2019-04-16 14:32:11 +08:00
|
|
|
|
if self.isDead then
|
|
|
|
|
return
|
|
|
|
|
end
|
2019-03-26 15:11:47 +08:00
|
|
|
|
for i=1, self.buffFilter.size do
|
|
|
|
|
if self.buffFilter.buffer[i](buff) then
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
end
|
2019-04-16 14:32:11 +08:00
|
|
|
|
BattleLogic.BuffMgr:AddBuff(self, buff)
|
2019-03-12 14:05:45 +08:00
|
|
|
|
end
|
|
|
|
|
|
2019-03-21 14:33:56 +08:00
|
|
|
|
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
|
|
|
|
|
|
2019-03-12 14:05:45 +08:00
|
|
|
|
function RoleLogic:Update()
|
|
|
|
|
if not self.enable then
|
|
|
|
|
return
|
|
|
|
|
end
|
2019-04-17 21:04:32 +08:00
|
|
|
|
self.updateFunc()
|
2019-03-12 14:05:45 +08:00
|
|
|
|
end
|