340 lines
12 KiB
Lua
340 lines
12 KiB
Lua
local ____lualib = require("lualib_bundle")
|
|
local __TS__Number = ____lualib.__TS__Number
|
|
local __TS__Class = ____lualib.__TS__Class
|
|
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
|
|
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
|
|
____exports.GREED_MODIFIER_NAME = "modifier_card_greed"
|
|
--- Нетворса за +1 к каждому атрибуту (умножается на стаки алчности — число карт с алчностью на иконке).
|
|
____exports.GREED_NET_WORTH_PER_STACK = 250
|
|
--- Карты с общей алчностью (включая card_9 — проклятие алчного мидаса).
|
|
____exports.GREED_POOL_CARD_IDS = {
|
|
9,
|
|
20,
|
|
23,
|
|
24,
|
|
51
|
|
}
|
|
local HIDDEN_GREED_CARD_IDS = {}
|
|
local hiddenGreedCardsTaken = {}
|
|
function ____exports.isGreedPoolCardId(self, cardId)
|
|
local normalized = math.floor(__TS__Number(cardId))
|
|
for ____, poolId in ipairs(____exports.GREED_POOL_CARD_IDS) do
|
|
if poolId == normalized then
|
|
return true
|
|
end
|
|
end
|
|
return false
|
|
end
|
|
local function isHiddenGreedCardId(self, cardId)
|
|
local normalized = math.floor(__TS__Number(cardId))
|
|
for ____, hiddenId in ipairs(HIDDEN_GREED_CARD_IDS) do
|
|
if hiddenId == normalized then
|
|
return true
|
|
end
|
|
end
|
|
return false
|
|
end
|
|
local function resolveCardSystem(self, playerId, cardSystemRef)
|
|
local ____cardSystemRef_2 = cardSystemRef
|
|
if ____cardSystemRef_2 == nil then
|
|
local ____opt_0 = PlayerResource:GetPlayer(playerId)
|
|
____cardSystemRef_2 = ____opt_0 and ____opt_0.cardSystem
|
|
end
|
|
return ____cardSystemRef_2
|
|
end
|
|
--- Сколько карт с алчностью активно — число на иконке баффа (1, 2, 3…).
|
|
local function countActiveGreedCards(self, playerId, hero, cardSystemRef)
|
|
local total = math.max(
|
|
0,
|
|
math.floor(hiddenGreedCardsTaken[playerId] or 0)
|
|
)
|
|
local cardSystem = resolveCardSystem(nil, playerId, cardSystemRef)
|
|
if cardSystem then
|
|
for ____, cardId in ipairs(____exports.GREED_POOL_CARD_IDS) do
|
|
do
|
|
if isHiddenGreedCardId(nil, cardId) then
|
|
goto __continue13
|
|
end
|
|
total = total + cardSystem:GetActiveCardCopies(cardId)
|
|
end
|
|
::__continue13::
|
|
end
|
|
return total
|
|
end
|
|
for ____, cardId in ipairs(____exports.GREED_POOL_CARD_IDS) do
|
|
do
|
|
if isHiddenGreedCardId(nil, cardId) then
|
|
goto __continue16
|
|
end
|
|
local modName = "modifier_card_" .. tostring(cardId)
|
|
do
|
|
local i = 0
|
|
while i < hero:GetModifierCount() do
|
|
if hero:GetModifierNameByIndex(i) == modName then
|
|
total = total + 1
|
|
end
|
|
i = i + 1
|
|
end
|
|
end
|
|
end
|
|
::__continue16::
|
|
end
|
|
return total
|
|
end
|
|
--- Золото + предметы (для бонуса к атрибуту).
|
|
function ____exports.getHeroNetWorthForGreed(self, hero, playerId)
|
|
local playerGold = math.max(
|
|
0,
|
|
PlayerResource:GetGold(playerId)
|
|
)
|
|
local heroGold = math.max(
|
|
0,
|
|
hero:GetGold()
|
|
)
|
|
local worth = math.max(playerGold, heroGold)
|
|
do
|
|
local slot = 0
|
|
while slot < 16 do
|
|
local item = hero:GetItemInSlot(slot)
|
|
if item and not item:IsNull() then
|
|
worth = worth + math.max(
|
|
0,
|
|
item:GetCost()
|
|
)
|
|
end
|
|
slot = slot + 1
|
|
end
|
|
end
|
|
return worth
|
|
end
|
|
--- Бонус ко всем атрибутам от нетворса (+1 за каждые GREED_NET_WORTH_PER_STACK).
|
|
function ____exports.computeGreedStatBonus(self, hero, playerId, netWorthPerStack)
|
|
if netWorthPerStack == nil then
|
|
netWorthPerStack = ____exports.GREED_NET_WORTH_PER_STACK
|
|
end
|
|
local perStack = math.max(
|
|
1,
|
|
math.floor(netWorthPerStack)
|
|
)
|
|
return math.max(
|
|
0,
|
|
math.floor(____exports.getHeroNetWorthForGreed(nil, hero, playerId) / perStack)
|
|
)
|
|
end
|
|
---
|
|
-- @deprecated Используй computeGreedStatBonus
|
|
function ____exports.computeGreedStacks(self, hero, playerId, netWorthPerStack)
|
|
if netWorthPerStack == nil then
|
|
netWorthPerStack = ____exports.GREED_NET_WORTH_PER_STACK
|
|
end
|
|
return ____exports.computeGreedStatBonus(nil, hero, playerId, netWorthPerStack)
|
|
end
|
|
local function removeGreedModifier(self, hero)
|
|
local existing = hero:FindModifierByName(____exports.GREED_MODIFIER_NAME)
|
|
if existing and not existing:IsNull() then
|
|
existing:Destroy()
|
|
end
|
|
end
|
|
function ____exports.updateGreedForHero(self, hero, cardSystemRef)
|
|
if not IsServer() or not hero or not IsValidEntity(hero) or not hero:IsRealHero() then
|
|
return
|
|
end
|
|
local playerId = hero:GetPlayerOwnerID()
|
|
if playerId == nil or playerId == nil or playerId < 0 then
|
|
return
|
|
end
|
|
local cardStacks = countActiveGreedCards(nil, playerId, hero, cardSystemRef)
|
|
if cardStacks <= 0 then
|
|
removeGreedModifier(nil, hero)
|
|
return
|
|
end
|
|
local modifier = hero:FindModifierByName(____exports.GREED_MODIFIER_NAME)
|
|
if not modifier then
|
|
modifier = hero:AddNewModifier(
|
|
hero,
|
|
getModifierSourceAbility(nil, hero),
|
|
____exports.GREED_MODIFIER_NAME,
|
|
{}
|
|
)
|
|
end
|
|
if not modifier then
|
|
print("[modifier_card_greed] AddNewModifier failed — проверь LinkLuaModifier / cards_init")
|
|
return
|
|
end
|
|
modifier:refresh(cardStacks, hero, playerId)
|
|
end
|
|
function ____exports.registerHiddenGreedCard(self, hero, cardId)
|
|
if not IsServer() or not hero or not IsValidEntity(hero) or not hero:IsRealHero() then
|
|
return
|
|
end
|
|
local normalized = math.floor(__TS__Number(cardId))
|
|
if not isHiddenGreedCardId(nil, normalized) then
|
|
return
|
|
end
|
|
local playerId = hero:GetPlayerOwnerID()
|
|
if playerId == nil or playerId == nil or playerId < 0 then
|
|
return
|
|
end
|
|
hiddenGreedCardsTaken[playerId] = math.max(
|
|
0,
|
|
math.floor(hiddenGreedCardsTaken[playerId] or 0)
|
|
) + 1
|
|
end
|
|
____exports.modifier_card_greed = __TS__Class()
|
|
local modifier_card_greed = ____exports.modifier_card_greed
|
|
modifier_card_greed.name = "modifier_card_greed"
|
|
modifier_card_greed.____file_path = "scripts/vscripts/cards/modifier_card_greed.lua"
|
|
__TS__ClassExtends(modifier_card_greed, BaseModifier)
|
|
function modifier_card_greed.prototype.____constructor(self, ...)
|
|
BaseModifier.prototype.____constructor(self, ...)
|
|
self.cardStacks = 0
|
|
self.statBonus = 0
|
|
end
|
|
function modifier_card_greed.prototype.OnCreated(self)
|
|
if not IsServer() then
|
|
return
|
|
end
|
|
self.cardStacks = 0
|
|
self.statBonus = 0
|
|
self:SetHasCustomTransmitterData(true)
|
|
self:StartIntervalThink(0.25)
|
|
local hero = self:GetParent()
|
|
if hero and IsValidEntity(hero) and hero:IsRealHero() then
|
|
local playerId = hero:GetPlayerOwnerID()
|
|
if playerId ~= nil and playerId ~= nil and playerId >= 0 then
|
|
local ____opt_3 = PlayerResource:GetPlayer(playerId)
|
|
local cardSystem = ____opt_3 and ____opt_3.cardSystem
|
|
local cardStacks = countActiveGreedCards(nil, playerId, hero, cardSystem)
|
|
if cardStacks > 0 then
|
|
self:refresh(cardStacks, hero, playerId)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
function modifier_card_greed.prototype.IsHidden(self)
|
|
return false
|
|
end
|
|
function modifier_card_greed.prototype.IsDebuff(self)
|
|
return false
|
|
end
|
|
function modifier_card_greed.prototype.IsPurgable(self)
|
|
return false
|
|
end
|
|
function modifier_card_greed.prototype.RemoveOnDeath(self)
|
|
return false
|
|
end
|
|
function modifier_card_greed.prototype.IsPermanent(self)
|
|
return true
|
|
end
|
|
function modifier_card_greed.prototype.GetTexture(self)
|
|
return "alchemist_goblins_greed"
|
|
end
|
|
function modifier_card_greed.prototype.GetTooltip(self)
|
|
return "dota_tooltip_modifier_modifier_card_greed_Description"
|
|
end
|
|
function modifier_card_greed.prototype.OnTooltip(self)
|
|
return self.statBonus * self:GetStackCount()
|
|
end
|
|
function modifier_card_greed.prototype.HandleCustomTransmitterData(self, data)
|
|
local ____opt_result_7
|
|
if data ~= nil then
|
|
____opt_result_7 = data.card_stacks
|
|
end
|
|
local cardStacksRaw = __TS__Number(____opt_result_7)
|
|
if __TS__NumberIsFinite(cardStacksRaw) then
|
|
self.cardStacks = math.max(
|
|
0,
|
|
math.floor(cardStacksRaw)
|
|
)
|
|
end
|
|
local ____opt_result_10
|
|
if data ~= nil then
|
|
____opt_result_10 = data.stat_bonus
|
|
end
|
|
local statBonusRaw = __TS__Number(____opt_result_10)
|
|
if __TS__NumberIsFinite(statBonusRaw) then
|
|
self.statBonus = math.max(
|
|
0,
|
|
math.floor(statBonusRaw)
|
|
)
|
|
end
|
|
end
|
|
function modifier_card_greed.prototype.AddCustomTransmitterData(self)
|
|
return {card_stacks = self.cardStacks, stat_bonus = self.statBonus}
|
|
end
|
|
function modifier_card_greed.prototype.OnIntervalThink(self)
|
|
local hero = self:GetParent()
|
|
if not hero or not IsValidEntity(hero) or not hero:IsRealHero() then
|
|
return
|
|
end
|
|
local playerId = hero:GetPlayerOwnerID()
|
|
if playerId == nil or playerId == nil or playerId < 0 then
|
|
return
|
|
end
|
|
local ____opt_11 = PlayerResource:GetPlayer(playerId)
|
|
local cardSystem = ____opt_11 and ____opt_11.cardSystem
|
|
local cardStacks = countActiveGreedCards(nil, playerId, hero, cardSystem)
|
|
if cardStacks <= 0 then
|
|
self:Destroy()
|
|
return
|
|
end
|
|
self:refresh(cardStacks, hero, playerId)
|
|
end
|
|
function modifier_card_greed.prototype.refresh(self, cardStacks, hero, playerId)
|
|
local nextCardStacks = math.max(
|
|
0,
|
|
math.floor(cardStacks)
|
|
)
|
|
local nextStatBonus = ____exports.computeGreedStatBonus(nil, hero, playerId)
|
|
local cardChanged = self.cardStacks ~= nextCardStacks
|
|
local statChanged = self.statBonus ~= nextStatBonus
|
|
if not cardChanged and not statChanged then
|
|
return
|
|
end
|
|
self.cardStacks = nextCardStacks
|
|
self.statBonus = nextStatBonus
|
|
self:SetStackCount(nextCardStacks)
|
|
self:SendBuffRefreshToClients()
|
|
self:ForceRefresh()
|
|
hero:CalculateStatBonus(true)
|
|
end
|
|
function modifier_card_greed.prototype.getLiveStatBonus(self)
|
|
if not IsServer() then
|
|
return self.statBonus
|
|
end
|
|
local hero = self:GetParent()
|
|
if not hero or not IsValidEntity(hero) or not hero:IsRealHero() then
|
|
return 0
|
|
end
|
|
local playerId = hero:GetPlayerOwnerID()
|
|
if playerId == nil or playerId == nil or playerId < 0 then
|
|
return 0
|
|
end
|
|
return ____exports.computeGreedStatBonus(nil, hero, playerId)
|
|
end
|
|
function modifier_card_greed.prototype.DeclareFunctions(self)
|
|
return {MODIFIER_PROPERTY_STATS_STRENGTH_BONUS, MODIFIER_PROPERTY_STATS_AGILITY_BONUS, MODIFIER_PROPERTY_STATS_INTELLECT_BONUS, MODIFIER_PROPERTY_TOOLTIP}
|
|
end
|
|
function modifier_card_greed.prototype.GetModifierBonusStats_Strength(self)
|
|
return self:getLiveStatBonus() * self:GetStackCount()
|
|
end
|
|
function modifier_card_greed.prototype.GetModifierBonusStats_Agility(self)
|
|
return self:getLiveStatBonus() * self:GetStackCount()
|
|
end
|
|
function modifier_card_greed.prototype.GetModifierBonusStats_Intellect(self)
|
|
return self:getLiveStatBonus() * self:GetStackCount()
|
|
end
|
|
modifier_card_greed = __TS__Decorate(
|
|
modifier_card_greed,
|
|
modifier_card_greed,
|
|
{registerModifier(nil)},
|
|
{kind = "class", name = "modifier_card_greed"}
|
|
)
|
|
____exports.modifier_card_greed = modifier_card_greed
|
|
return ____exports
|