144 lines
4.9 KiB
Lua
144 lines
4.9 KiB
Lua
local ____lualib = require("lualib_bundle")
|
|
local __TS__Class = ____lualib.__TS__Class
|
|
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
|
|
local __TS__StringStartsWith = ____lualib.__TS__StringStartsWith
|
|
local __TS__StringSubstring = ____lualib.__TS__StringSubstring
|
|
local __TS__Number = ____lualib.__TS__Number
|
|
local __TS__NumberIsFinite = ____lualib.__TS__NumberIsFinite
|
|
local __TS__StringReplace = ____lualib.__TS__StringReplace
|
|
local ____exports = {}
|
|
local ____dota_ts_adapter = require("lib.dota_ts_adapter")
|
|
local BaseModifier = ____dota_ts_adapter.BaseModifier
|
|
local ____card_value_resolver = require("cards.card_value_resolver")
|
|
local getCardValueByLevel = ____card_value_resolver.getCardValueByLevel
|
|
--- Базовый модификатор для всех карт
|
|
____exports.CardBaseModifier = __TS__Class()
|
|
local CardBaseModifier = ____exports.CardBaseModifier
|
|
CardBaseModifier.name = "CardBaseModifier"
|
|
CardBaseModifier.____file_path = "scripts/vscripts/cards/CardBaseModifier.lua"
|
|
__TS__ClassExtends(CardBaseModifier, BaseModifier)
|
|
function CardBaseModifier.prototype.getCardValue(self, key, fallback, cardId)
|
|
local resolvedCardId = cardId or self:getCardIdFromModifierName()
|
|
if not resolvedCardId or resolvedCardId <= 0 then
|
|
return fallback
|
|
end
|
|
local parent = self:GetParent()
|
|
local hero = parent and IsValidEntity(parent) and parent:IsRealHero() and parent or nil
|
|
return getCardValueByLevel(
|
|
nil,
|
|
resolvedCardId,
|
|
hero,
|
|
key,
|
|
fallback,
|
|
self.cardLevelSnapshot
|
|
)
|
|
end
|
|
function CardBaseModifier.prototype.getCardCopies(self)
|
|
return math.max(
|
|
1,
|
|
math.floor(self:GetStackCount() or 0)
|
|
)
|
|
end
|
|
function CardBaseModifier.prototype.getScaledCardValue(self, key, fallback, cardId)
|
|
return self:getCardValue(key, fallback, cardId) * self:getCardCopies()
|
|
end
|
|
function CardBaseModifier.prototype.getCardIdFromModifierName(self)
|
|
local name = self:GetName()
|
|
local prefix = "modifier_card_"
|
|
if not __TS__StringStartsWith(name, prefix) then
|
|
return 0
|
|
end
|
|
local idRaw = __TS__StringSubstring(name, #prefix)
|
|
if #idRaw <= 0 then
|
|
return 0
|
|
end
|
|
local value = __TS__Number(idRaw)
|
|
return __TS__NumberIsFinite(value) and math.floor(value) or 0
|
|
end
|
|
function CardBaseModifier.prototype.OnCreated(self, params)
|
|
local ____opt_result_2
|
|
if params ~= nil then
|
|
____opt_result_2 = params.card_level
|
|
end
|
|
local levelRaw = __TS__Number(____opt_result_2)
|
|
if __TS__NumberIsFinite(levelRaw) and levelRaw > 0 then
|
|
self.cardLevelSnapshot = math.floor(levelRaw)
|
|
else
|
|
self.cardLevelSnapshot = nil
|
|
end
|
|
if IsClient() then
|
|
self:OnCustomCreated(params)
|
|
return
|
|
end
|
|
if not IsServer() then
|
|
return
|
|
end
|
|
if self:GetStackCount() <= 0 then
|
|
self:SetStackCount(1)
|
|
end
|
|
self:SetHasCustomTransmitterData(true)
|
|
self:SendBuffRefreshToClients()
|
|
self:OnCustomCreated(params)
|
|
end
|
|
function CardBaseModifier.prototype.OnRefresh(self)
|
|
if not IsServer() then
|
|
return
|
|
end
|
|
self:OnCustomRefresh({})
|
|
self:SendBuffRefreshToClients()
|
|
local parent = self:GetParent()
|
|
if parent and IsValidEntity(parent) and parent:IsRealHero() then
|
|
parent:CalculateStatBonus(true)
|
|
end
|
|
end
|
|
function CardBaseModifier.prototype.OnCustomRefresh(self, _params)
|
|
end
|
|
function CardBaseModifier.prototype.IsPermanent(self)
|
|
return true
|
|
end
|
|
function CardBaseModifier.prototype.IsHidden(self)
|
|
return false
|
|
end
|
|
function CardBaseModifier.prototype.IsDebuff(self)
|
|
return false
|
|
end
|
|
function CardBaseModifier.prototype.RemoveOnDeath(self)
|
|
return false
|
|
end
|
|
function CardBaseModifier.prototype.IsPurgable(self)
|
|
return false
|
|
end
|
|
function CardBaseModifier.prototype.GetAttributes(self)
|
|
return MODIFIER_ATTRIBUTE_MULTIPLE
|
|
end
|
|
function CardBaseModifier.prototype.OnCustomCreated(self, params)
|
|
end
|
|
function CardBaseModifier.prototype.HandleCustomTransmitterData(self, data)
|
|
local ____opt_result_5
|
|
if data ~= nil then
|
|
____opt_result_5 = data.card_level_snapshot
|
|
end
|
|
local levelRaw = __TS__Number(____opt_result_5)
|
|
if __TS__NumberIsFinite(levelRaw) and levelRaw > 0 then
|
|
self.cardLevelSnapshot = math.floor(levelRaw)
|
|
end
|
|
end
|
|
function CardBaseModifier.prototype.AddCustomTransmitterData(self)
|
|
return {card_level_snapshot = self.cardLevelSnapshot or 1}
|
|
end
|
|
function CardBaseModifier.prototype.GetTexture(self)
|
|
local modifierName = self:GetName()
|
|
local cardId = __TS__StringReplace(modifierName, "modifier_card_", "")
|
|
return "cards/card_" .. cardId
|
|
end
|
|
function CardBaseModifier.prototype.GetTooltip(self)
|
|
return ("dota_tooltip_modifier_" .. self:GetName()) .. "_Description"
|
|
end
|
|
function CardBaseModifier.prototype.DeclareFunctions(self)
|
|
return {MODIFIER_PROPERTY_TOOLTIP}
|
|
end
|
|
function CardBaseModifier.prototype.OnTooltip(self)
|
|
return self:GetStackCount()
|
|
end
|
|
return ____exports
|