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

329 lines
11 KiB
Lua
Raw Normal View History

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
2019-06-06 17:23:18 +08:00
local min = math.min
2019-03-12 14:05:45 +08:00
2019-08-05 15:58:48 +08:00
local aiList = {
[0] = function(skill, superSkill) --默认75%释放点击技、25%释放上滑技
2019-10-10 11:03:42 +08:00
local stage = BattleLogic.CurStage()
if stage == 1 then
return true
elseif stage == 2 then
return Random.Range01() > superSkill.randomInStage2
elseif stage == 3 then
return false
end
2019-08-05 15:58:48 +08:00
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,
}
2019-03-21 14:33:56 +08:00
local skillPool = BattleObjectPool.New(function ()
return Skill:New()
end)
function RoleLogic.New()
2019-10-10 11:03:42 +08:00
local instance = {uid=0,roleData=0,data=RoleData.New(),camp=0,name=0,roleType=0,aiIndex=1,position=0,
2019-03-26 15:11:47 +08:00
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
2019-10-10 11:03:42 +08:00
function RoleLogic:Init(uid, data, position)
2019-03-21 14:33:56 +08:00
self.uid = uid
2019-10-10 11:03:42 +08:00
self.position = position
2019-03-21 14:33:56 +08:00
self.roleData = data
self.data:Init(self, data.property)
2019-08-06 14:37:17 +08:00
self.isDead = self:GetRoleData(RoleDataName.Hp) <= 0
2019-03-21 14:33:56 +08:00
self.camp = data.camp --阵营 0我方 1敌方
self.name = data.name
self.roleType = 1 --阵营 1普通 2Boss 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()
2019-10-10 11:03:42 +08:00
self.skill:Init(self, data.skill, 1)
2019-03-21 14:33:56 +08:00
self.skill.sp = 0
2019-08-06 20:55:47 +08:00
local time = max(8-self:GetRoleData(RoleDataName.Speed)/(8*(self:GetRoleData(RoleDataName.Level)+10)), 1.5)
self.skill.spPass = floor( BattleUtil.ErrorCorrection(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()
2019-10-10 11:03:42 +08:00
self.superSkill:Init(self, data.superSkill, 2)
2019-03-21 14:33:56 +08:00
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
2019-09-02 16:32:32 +08:00
BattleUtil.Passivity[id](self, args)
2019-05-09 17:50:38 +08:00
end
2019-03-12 14:05:45 +08:00
end
2019-08-05 15:58:48 +08:00
self.aiOrder = data.ai
self.aiIndex = 1
self.aiTempCount = 0
2019-03-21 14:33:56 +08:00
self.Auto = true
self.IsDebug = false
2019-06-28 11:28:45 +08:00
self.enable = true --眩晕
self.ctrl_slient = false --沉默
self.lockTarget = nil --嘲讽
self.ctrl_noheal = false --禁疗
self.ctrl_blind = false --致盲
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
2019-09-02 13:16:49 +08:00
if self.Auto and self:CanCastSkill() and not self.ctrl_slient then
2019-04-17 21:04:32 +08:00
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
2019-08-05 15:58:48 +08:00
self:ExecuteAI(skill, superSkill)
2019-04-17 21:04:32 +08:00
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()
2019-09-02 13:16:49 +08:00
return self.enable and not self.IsDebug and BattleLogic.GetSkillUsable(self.camp)
2019-03-12 14:05:45 +08:00
end
2019-06-05 15:25:06 +08:00
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
2019-06-06 17:23:18 +08:00
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
2019-03-12 14:05:45 +08:00
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
2019-09-01 12:11:18 +08:00
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
2019-05-07 20:01:07 +08:00
end
end
return tarPro
end
--proA替换的属性factor系数proB被替换的属性, duration持续时间
--读取proB属性时得到的值为proB + proA * factor
2019-09-01 12:11:18 +08:00
function RoleLogic:AddPropertyTransfer(proA, factor, proB, ct, duration)
local proTran = {proName = proB, tranProName = proA, tranFactor = factor, changeType = ct}
2019-05-07 20:01:07 +08:00
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-08-05 15:58:48 +08:00
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
2019-09-02 13:16:49 +08:00
if self.ctrl_slient then --沉默不能放上滑技
2019-08-05 15:58:48 +08:00
skill:Cast()
else
2019-09-02 13:16:49 +08:00
if ai(skill, superSkill) then
skill:Cast()
else
superSkill:Cast()
end
2019-08-05 15:58:48 +08:00
end
if self.aiOrder then
if self.aiIndex == #self.aiOrder then
self.aiIndex = 1
else
self.aiIndex = self.aiIndex + 1
end
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