264 lines
8.2 KiB
Lua
264 lines
8.2 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 aiList = {
|
||
[0] = function(skill, superSkill)
|
||
local stage = BattleLogic.CurStage()
|
||
if stage == 1 then
|
||
return true
|
||
elseif stage == 2 then --中期绝技释放率=技能基础概率+施法率+后期施法率-1
|
||
return Random.Range01() > superSkill.randomInStage2 + superSkill.owner:GetRoleData(RoleDataName.Hit) + superSkill.owner:GetRoleData(RoleDataName.Dodge) - 1
|
||
elseif stage == 3 then--后期绝技释放率=后期施法率+施法率
|
||
return Random.Range01() > superSkill.owner:GetRoleData(RoleDataName.Hit) + superSkill.owner:GetRoleData(RoleDataName.Dodge)
|
||
end
|
||
end,
|
||
[1] = function(skill, superSkill) --只放点技
|
||
return true
|
||
end,
|
||
[2] = function(skill, superSkill) --只放滑技
|
||
return false
|
||
end,
|
||
[3] = function(skill, superSkill) --上滑技初始概率为5%,每次释放点击技后,增加上滑技释放概率20%,释放上滑技后,上滑技释放概率回到5%。
|
||
local b = Random.Range01() > (0.05 + 0.2 * skill.owner.aiTempCount)
|
||
if b then
|
||
skill.owner.aiTempCount = skill.owner.aiTempCount + 1
|
||
else
|
||
skill.owner.aiTempCount = 0
|
||
end
|
||
return b
|
||
end,
|
||
}
|
||
|
||
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,aiIndex=1,position=0,sp=0,spPass=0,
|
||
shield=BattleList.New(),
|
||
exCalDmgList=BattleList.New(),
|
||
proTranList=BattleList.New(),
|
||
buffFilter=BattleList.New(),
|
||
Event=BattleEvent:New(),passiveList=0,isDead=false,IsDebug=false,enable=false}
|
||
setmetatable(instance, RoleLogic)
|
||
return instance
|
||
end
|
||
|
||
function RoleLogic:Init(uid, data, position)
|
||
self.uid = uid
|
||
self.position = position
|
||
self.roleData = data
|
||
|
||
self.data:Init(self, data.property)
|
||
self.isDead = self:GetRoleData(RoleDataName.Hp) <= 0
|
||
|
||
self.camp = data.camp --阵营 0:我方 1:敌方
|
||
self.name = data.name
|
||
|
||
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, 1)
|
||
end
|
||
if data.superSkill and #data.superSkill > 0 then
|
||
self.superSkill = skillPool:Get()
|
||
self.superSkill:Init(self, data.superSkill, 2)
|
||
end
|
||
--首次读条时间=速度/(20*(等级+10)
|
||
self.sp = 0
|
||
local time = self:GetRoleData(RoleDataName.Speed)/(20*(self:GetRoleData(RoleDataName.Level)+10))
|
||
self.spPass = floor( BattleUtil.ErrorCorrection(time) * BattleLogic.GameFrameRate)
|
||
|
||
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
|
||
BattleUtil.Passivity[id](self, args)
|
||
end
|
||
end
|
||
|
||
self.aiOrder = data.ai
|
||
self.aiIndex = 1
|
||
self.aiTempCount = 0
|
||
|
||
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()
|
||
if self:CanCastSkill() then
|
||
self.skill:Cast()
|
||
else
|
||
self.sp = self.sp + 1
|
||
end
|
||
end
|
||
elseif not self.skill and self.superSkill then
|
||
self.updateFunc = function()
|
||
if self:CanCastSkill() and not self.ctrl_slient then
|
||
self.superSkill:Cast()
|
||
else
|
||
self.sp = self.sp + 1
|
||
end
|
||
end
|
||
elseif self.skill and self.superSkill then
|
||
self.updateFunc = function()
|
||
if self:CanCastSkill() then
|
||
self:ExecuteAI(self.skill, self.superSkill)
|
||
else
|
||
self.sp = self.sp + 1
|
||
end
|
||
end
|
||
else
|
||
self.updateFunc = function() end
|
||
end
|
||
end
|
||
|
||
function RoleLogic:CanCastSkill()
|
||
return self.sp >= self.spPass and not self.IsDebug and BattleLogic.GetSkillUsable(self.camp)
|
||
end
|
||
|
||
function RoleLogic:GetSkillCD()
|
||
return max(self.spPass - self.sp, 0)
|
||
end
|
||
|
||
function RoleLogic:AddSkillCD(value, type)
|
||
self.Event:DispatchEvent(BattleEventName.RoleCDChanged)
|
||
if value == 0 then --为0直接清CD
|
||
self.sp = self.spPass
|
||
return
|
||
end
|
||
|
||
local cdTotal = self.spPass
|
||
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最大值
|
||
self.spPass = self.spPass + delta
|
||
else --减cd减cd当前值
|
||
delta = -delta
|
||
self.sp = min(self.sp + delta, self.spPass)
|
||
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
|
||
local value
|
||
if item.changeType == 1 then --加算
|
||
value = item.tranFactor
|
||
elseif item.changeType == 2 then --乘加算(百分比属性加算)
|
||
value = BattleUtil.ErrorCorrection(self.data:GetData(item.tranProName) * item.tranFactor)
|
||
elseif item.changeType == 3 then --减算
|
||
value = -item.tranFactor
|
||
elseif item.changeType == 4 then --乘减算(百分比属性减算)
|
||
value = -BattleUtil.ErrorCorrection(self.data:GetData(item.tranProName) * item.tranFactor)
|
||
end
|
||
tarPro = tarPro + value
|
||
end
|
||
end
|
||
return tarPro
|
||
end
|
||
|
||
--proA替换的属性,factor系数,proB被替换的属性, duration持续时间
|
||
--读取proB属性时,得到的值为proB + proA * factor
|
||
function RoleLogic:AddPropertyTransfer(proA, factor, proB, ct, duration)
|
||
local proTran = {proName = proB, tranProName = proA, tranFactor = factor, changeType = ct}
|
||
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:ExecuteAI(skill, superSkill)
|
||
local ai
|
||
if self.aiOrder and self.aiOrder[self.aiIndex] then
|
||
ai = aiList[self.aiOrder[self.aiIndex]]
|
||
else
|
||
ai = aiList[0]
|
||
end
|
||
|
||
if self.ctrl_slient then --沉默不能放上滑技
|
||
skill:Cast()
|
||
else
|
||
if ai(skill, superSkill) then
|
||
skill:Cast()
|
||
else
|
||
superSkill:Cast()
|
||
end
|
||
end
|
||
|
||
if self.aiOrder then
|
||
if self.aiIndex == #self.aiOrder then
|
||
self.aiIndex = 1
|
||
else
|
||
self.aiIndex = self.aiIndex + 1
|
||
end
|
||
end
|
||
end
|
||
|
||
function RoleLogic:Update()
|
||
if not self.enable then
|
||
return
|
||
end
|
||
self.updateFunc()
|
||
end |