117 lines
4.8 KiB
Lua
117 lines
4.8 KiB
Lua
local ____lualib = require("lualib_bundle")
|
|
local __TS__Class = ____lualib.__TS__Class
|
|
local Map = ____lualib.Map
|
|
local __TS__New = ____lualib.__TS__New
|
|
local __TS__Number = ____lualib.__TS__Number
|
|
local ____exports = {}
|
|
local ____get_true_hero_from_entity = require("utils.get_true_hero_from_entity")
|
|
local getTrueHeroFromEntity = ____get_true_hero_from_entity.getTrueHeroFromEntity
|
|
--- Единый учёт за матч: исх./вх. урон (SetDamageFilter, как defension) и лечение союзников (HealWithBattlePass).
|
|
-- Используется: экран итогов, квесты BP, отправка статистики в API (история матчей).
|
|
____exports.MatchEndCombatStats = __TS__Class()
|
|
local MatchEndCombatStats = ____exports.MatchEndCombatStats
|
|
MatchEndCombatStats.name = "MatchEndCombatStats"
|
|
MatchEndCombatStats.____file_path = "scripts/vscripts/match_end_combat_stats.lua"
|
|
function MatchEndCombatStats.prototype.____constructor(self)
|
|
self.incomingSumByPlayer = __TS__New(Map)
|
|
self.outgoingSumByPlayer = __TS__New(Map)
|
|
self.healToAlliesByPlayer = __TS__New(Map)
|
|
ListenToGameEvent(
|
|
"game_rules_state_change",
|
|
function()
|
|
if GameRules:State_Get() == DOTA_GAMERULES_STATE_GAME_IN_PROGRESS then
|
|
self:resetForNewMatch()
|
|
end
|
|
end,
|
|
nil
|
|
)
|
|
end
|
|
function MatchEndCombatStats.getInstance(self)
|
|
if not ____exports.MatchEndCombatStats.instance then
|
|
____exports.MatchEndCombatStats.instance = __TS__New(____exports.MatchEndCombatStats)
|
|
end
|
|
return ____exports.MatchEndCombatStats.instance
|
|
end
|
|
function MatchEndCombatStats.registerDamageFilter(self)
|
|
if not IsServer() or ____exports.MatchEndCombatStats.filterRegistered then
|
|
return
|
|
end
|
|
local inst = ____exports.MatchEndCombatStats:getInstance()
|
|
local mode = GameRules:GetGameModeEntity()
|
|
mode:SetDamageFilter(
|
|
function(____, event) return inst:onDamageFilter(event) end,
|
|
inst
|
|
)
|
|
____exports.MatchEndCombatStats.filterRegistered = true
|
|
end
|
|
function MatchEndCombatStats.prototype.onDamageFilter(self, event)
|
|
local dmg = __TS__Number(event.damage) or 0
|
|
if dmg <= 0 then
|
|
return true
|
|
end
|
|
local ____event_entindex_attacker_const_0 = event.entindex_attacker_const
|
|
if ____event_entindex_attacker_const_0 == nil then
|
|
____event_entindex_attacker_const_0 = event.entindex_attacker
|
|
end
|
|
local aIdx = ____event_entindex_attacker_const_0
|
|
local ____event_entindex_victim_const_1 = event.entindex_victim_const
|
|
if ____event_entindex_victim_const_1 == nil then
|
|
____event_entindex_victim_const_1 = event.entindex_victim
|
|
end
|
|
local vIdx = ____event_entindex_victim_const_1
|
|
if aIdx ~= nil and aIdx ~= nil then
|
|
local attacker = EntIndexToHScript(aIdx)
|
|
local attackerHero = getTrueHeroFromEntity(nil, attacker)
|
|
if attackerHero then
|
|
local pid = attackerHero:GetPlayerOwnerID()
|
|
if pid ~= nil and pid >= 0 then
|
|
local prev = self.outgoingSumByPlayer:get(pid) or 0
|
|
self.outgoingSumByPlayer:set(pid, prev + dmg)
|
|
end
|
|
end
|
|
end
|
|
if vIdx ~= nil and vIdx ~= nil then
|
|
local victim = EntIndexToHScript(vIdx)
|
|
if victim and IsValidEntity(victim) and victim:IsBaseNPC() then
|
|
local v = victim
|
|
if v:IsHero() then
|
|
local vpid = v:GetPlayerOwnerID()
|
|
if vpid ~= nil and vpid >= 0 then
|
|
local prev = self.incomingSumByPlayer:get(vpid) or 0
|
|
self.incomingSumByPlayer:set(vpid, prev + dmg)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
return true
|
|
end
|
|
function MatchEndCombatStats.prototype.resetForNewMatch(self)
|
|
self.incomingSumByPlayer:clear()
|
|
self.outgoingSumByPlayer:clear()
|
|
self.healToAlliesByPlayer:clear()
|
|
end
|
|
function MatchEndCombatStats.prototype.addHealToAllies(self, playerId, amount)
|
|
if amount <= 0 or playerId < 0 then
|
|
return
|
|
end
|
|
local prev = self.healToAlliesByPlayer:get(playerId) or 0
|
|
self.healToAlliesByPlayer:set(playerId, prev + amount)
|
|
end
|
|
function MatchEndCombatStats.prototype.getHealToAlliesSum(self, playerId)
|
|
return math.floor(self.healToAlliesByPlayer:get(playerId) or 0)
|
|
end
|
|
function MatchEndCombatStats.prototype.getIncomingDamageSum(self, playerId)
|
|
return math.floor(self.incomingSumByPlayer:get(playerId) or 0)
|
|
end
|
|
function MatchEndCombatStats.prototype.getOutgoingDamageSum(self, playerId)
|
|
return math.floor(self.outgoingSumByPlayer:get(playerId) or 0)
|
|
end
|
|
function MatchEndCombatStats.prototype.getIncomingHurtEventSum(self, playerId)
|
|
return self:getIncomingDamageSum(playerId)
|
|
end
|
|
MatchEndCombatStats.filterRegistered = false
|
|
if IsServer() then
|
|
____exports.MatchEndCombatStats:getInstance()
|
|
end
|
|
return ____exports
|