Files
Dota-Zombie-Invasion/scripts/vscripts/abilities/modifiers/modifier_equipment_stats.lua
T
2026-05-29 15:11:31 +07:00

165 lines
5.6 KiB
Lua

local ____lualib = require("lualib_bundle")
local __TS__Class = ____lualib.__TS__Class
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
local __TS__Number = ____lualib.__TS__Number
local __TS__NumberIsFinite = ____lualib.__TS__NumberIsFinite
local __TS__Decorate = ____lualib.__TS__Decorate
local ____exports = {}
local ____dota_ts_adapter = require("lib.dota_ts_adapter")
local BaseModifier = ____dota_ts_adapter.BaseModifier
local registerModifier = ____dota_ts_adapter.registerModifier
local ____luck = require("utils.luck")
local addLuck = ____luck.addLuck
local reduceLuck = ____luck.reduceLuck
____exports.modifier_equipment_stats = __TS__Class()
local modifier_equipment_stats = ____exports.modifier_equipment_stats
modifier_equipment_stats.name = "modifier_equipment_stats"
modifier_equipment_stats.____file_path = "scripts/vscripts/abilities/modifiers/modifier_equipment_stats.lua"
__TS__ClassExtends(modifier_equipment_stats, BaseModifier)
function modifier_equipment_stats.prototype.____constructor(self, ...)
BaseModifier.prototype.____constructor(self, ...)
self.appliedLuck = 0
self.strengthPct = 0
self.intellectPct = 0
self.damagePct = 0
self.damageReductionPct = 0
self.spellAmpPct = 0
self.strengthBonus = 0
self.intellectBonus = 0
end
function modifier_equipment_stats.prototype.IsHidden(self)
return true
end
function modifier_equipment_stats.prototype.IsPurgable(self)
return false
end
function modifier_equipment_stats.prototype.RemoveOnDeath(self)
return false
end
function modifier_equipment_stats.prototype.OnCreated(self, params)
if not IsServer() then
return
end
self:readParams(params)
self:applyLuck()
self:StartIntervalThink(1)
self:updateDerivedAttributeBonuses()
end
function modifier_equipment_stats.prototype.OnRefresh(self, params)
if not IsServer() then
return
end
self:clearLuck()
self:readParams(params)
self:applyLuck()
self:updateDerivedAttributeBonuses()
end
function modifier_equipment_stats.prototype.OnDestroy(self)
if not IsServer() then
return
end
self:clearLuck()
end
function modifier_equipment_stats.prototype.OnIntervalThink(self)
if not IsServer() then
return
end
self:updateDerivedAttributeBonuses()
end
function modifier_equipment_stats.prototype.DeclareFunctions(self)
return {
MODIFIER_PROPERTY_STATS_STRENGTH_BONUS,
MODIFIER_PROPERTY_STATS_INTELLECT_BONUS,
MODIFIER_PROPERTY_TOTALDAMAGEOUTGOING_PERCENTAGE,
MODIFIER_PROPERTY_INCOMING_DAMAGE_PERCENTAGE,
MODIFIER_PROPERTY_SPELL_AMPLIFY_PERCENTAGE
}
end
function modifier_equipment_stats.prototype.GetModifierBonusStats_Strength(self)
return self.strengthBonus
end
function modifier_equipment_stats.prototype.GetModifierBonusStats_Intellect(self)
return self.intellectBonus
end
function modifier_equipment_stats.prototype.GetModifierTotalDamageOutgoing_Percentage(self)
return self.damagePct
end
function modifier_equipment_stats.prototype.GetModifierIncomingDamage_Percentage(self)
return -self.damageReductionPct
end
function modifier_equipment_stats.prototype.GetModifierSpellAmplify_Percentage(self)
return self.spellAmpPct
end
function modifier_equipment_stats.prototype.readParams(self, params)
self.appliedLuck = 0
self.strengthPct = __TS__Number(params.strengthPct or "0")
self.intellectPct = __TS__Number(params.intellectPct or "0")
self.damagePct = __TS__Number(params.damagePct or "0")
self.damageReductionPct = __TS__Number(params.damageReductionPct or "0")
self.spellAmpPct = __TS__Number(params.spellAmpPct or "0")
self.appliedLuck = __TS__Number(params.luckPct or "0")
if not __TS__NumberIsFinite(self.appliedLuck) then
self.appliedLuck = 0
end
if not __TS__NumberIsFinite(self.strengthPct) then
self.strengthPct = 0
end
if not __TS__NumberIsFinite(self.intellectPct) then
self.intellectPct = 0
end
if not __TS__NumberIsFinite(self.damagePct) then
self.damagePct = 0
end
if not __TS__NumberIsFinite(self.damageReductionPct) then
self.damageReductionPct = 0
end
if not __TS__NumberIsFinite(self.spellAmpPct) then
self.spellAmpPct = 0
end
end
function modifier_equipment_stats.prototype.updateDerivedAttributeBonuses(self)
local hero = self:GetParent()
if not hero or not hero:IsRealHero() then
self.strengthBonus = 0
self.intellectBonus = 0
return
end
local baseStrength = math.max(
0,
hero:GetStrength() - self.strengthBonus
)
local baseIntellect = math.max(
0,
hero:GetIntellect(false) - self.intellectBonus
)
self.strengthBonus = math.floor(baseStrength * (self.strengthPct / 100))
self.intellectBonus = math.floor(baseIntellect * (self.intellectPct / 100))
self:ForceRefresh()
end
function modifier_equipment_stats.prototype.applyLuck(self)
local hero = self:GetParent()
if not hero or not hero:IsRealHero() then
return
end
if self.appliedLuck ~= 0 then
addLuck(nil, hero, self.appliedLuck)
end
end
function modifier_equipment_stats.prototype.clearLuck(self)
local hero = self:GetParent()
if not hero or not hero:IsRealHero() then
return
end
if self.appliedLuck ~= 0 then
reduceLuck(nil, hero, self.appliedLuck)
end
end
modifier_equipment_stats = __TS__Decorate(
modifier_equipment_stats,
modifier_equipment_stats,
{registerModifier(nil)},
{kind = "class", name = "modifier_equipment_stats"}
)
____exports.modifier_equipment_stats = modifier_equipment_stats
return ____exports