miduo_client/Assets/ManagedResources/~Lua/Modules/Battle/BattleAnalysisManager.lua

171 lines
5.5 KiB
Lua

BattleAnalysisManager = {}
function BattleAnalysisManager:Init()
self.data = {}
self.mdata = {}
BattleLogic.Event:AddEvent(BattleEventName.RecordDamage, self.OnRecordDamage, self)
BattleLogic.Event:AddEvent(BattleEventName.RecordTreat, self.OnRecordTreat, self)
BattleLogic.Event:AddEvent(BattleEventName.RecordRage, self.OnRecordRage, self)
BattleLogic.Event:AddEvent(BattleEventName.RecordTransRage, self.OnRecordTransRage, self)
BattleLogic.Event:AddEvent(BattleEventName.RecordBuff, self.OnRecordBuff, self)
BattleLogic.Event:AddEvent(BattleEventName.RecordSecKill, self.OnRecordSecKill, self)
BattleLogic.Event:AddEvent(BattleEventName.AddRole, self.OnAddRole, self)
BattleLogic.Event:AddEvent(BattleEventName.AddMonster, self.OnAddMonster, self)
end
-- 获取分析后的数据
function BattleAnalysisManager:GetAnalysisData()
-- for pos, role in pairs(self.data) do
-- print("角色:", pos)
-- for pro, data in pairs(role) do
-- if pro == "buff" then
-- for id, count in pairs(data) do
-- print("buff", id, count)
-- end
-- else
-- print(pro, data)
-- end
-- end
-- end
-- for pos, role in pairs(self.mdata) do
-- print("角色:", pos)
-- for pro, data in pairs(role) do
-- if pro == "buff" then
-- for id, count in pairs(data) do
-- print("buff", id, count)
-- end
-- else
-- print(pro, data)
-- end
-- end
-- end
return self.data, self.mdata
end
-- 获取要记录的数据
function BattleAnalysisManager:GetRecordData(role)
local data = {}
if role.type == BattleUnitType.Role then
data = self.data
elseif role.type == BattleUnitType.Monster then
data = self.mdata
end
local pos = role.position
local camp = role.camp
local index = role.camp * 6 + pos
if not data[index] then
data[index] = {damage = 0, treat = 0}
end
return data[index]
end
function BattleAnalysisManager:OnAddRole(role)
local data = self:GetRecordData(role)
data.info = role
end
function BattleAnalysisManager:OnAddMonster(monster)
if monster.position==100 or monster.uid==20100 then
--monster.type=1
end
local data = self:GetRecordData(monster)
data.info = monster
end
-- 伤害计算
function BattleAnalysisManager:OnRecordDamage(castRole, targetRole, damage)
local data = self:GetRecordData(castRole)
if not data.damage then
data.damage = 0
end
data.damage = data.damage + damage
end
-- 治疗量
function BattleAnalysisManager:OnRecordTreat(castRole, targetRole, treat)
local data = self:GetRecordData(castRole)
if not data.treat then
data.treat = 0
end
data.treat = data.treat + treat
end
-- 怒气改变
function BattleAnalysisManager:OnRecordRage(castRole, targetRole, delta)
local data = self:GetRecordData(castRole)
if delta > 0 then -- 加怒
if not data.addRage then
data.addRage = 0
end
data.addRage = data.addRage + delta
elseif delta < 0 then -- 减怒
if not data.subRage then
data.subRage = 0
end
data.subRage = data.subRage + math.abs(delta)
end
end
-- 转移怒气(精卫借怒)
function BattleAnalysisManager:OnRecordTransRage(castRole, targetRole, delta)
local data = self:GetRecordData(castRole)
if not data.transRage then
data.transRage = 0
end
data.transRage = data.transRage + delta
end
-- buff计算
function BattleAnalysisManager:OnRecordBuff(castRole, targetRole, buff)
local data = self:GetRecordData(castRole)
local id
if buff.type == BuffName.Control then -- 控制类
id = buff.type * 100 + buff.ctrlType
elseif buff.type == BuffName.Shield then -- 盾
id = buff.type * 100 + buff.shieldType
--特殊处理 坐骑老虎加无敌盾显示 2021/12/27
if buff.shieldType==ShieldTypeName.AllReduce and castRole:IsDead() and buff.shieldValue==0 then
return
end
elseif buff.type == BuffName.Curse then -- 连接符
id = buff.type * 100 + 1
end
if not id then
return
end
if not data.buff then
data.buff = {}
end
if not data.buff[id] then
data.buff[id] = 0
end
data.buff[id] = data.buff[id] + 1
end
-- 斩杀次数计算
function BattleAnalysisManager:OnRecordSecKill(castRole, targetRole)
local data = self:GetRecordData(castRole)
if not data.secKill then
data.secKill = 0
end
data.secKill = data.secKill + 1
end
function BattleAnalysisManager:Clear()
BattleLogic.Event:RemoveEvent(BattleEventName.RecordDamage, self.OnRecordDamage, self)
BattleLogic.Event:RemoveEvent(BattleEventName.RecordTreat, self.OnRecordTreat, self)
BattleLogic.Event:RemoveEvent(BattleEventName.RecordRage, self.OnRecordRage, self)
BattleLogic.Event:RemoveEvent(BattleEventName.RecordTransRage, self.OnRecordTransRage, self)
BattleLogic.Event:RemoveEvent(BattleEventName.RecordBuff, self.OnRecordBuff, self)
BattleLogic.Event:RemoveEvent(BattleEventName.RecordSecKill, self.OnRecordSecKill, self)
BattleLogic.Event:RemoveEvent(BattleEventName.AddRole, self.OnAddRole, self)
BattleLogic.Event:RemoveEvent(BattleEventName.AddMonster, self.OnAddMonster, self)
end
return BattleAnalysisManager