local ____lualib = require("lualib_bundle") local __TS__Class = ____lualib.__TS__Class local __TS__ClassExtends = ____lualib.__TS__ClassExtends local __TS__Decorate = ____lualib.__TS__Decorate local ____exports = {} local ____CardSystem = require("cards.CardSystem") local CardBase = ____CardSystem.CardBase local RegisterCard = ____CardSystem.RegisterCard local ____CardBaseModifier = require("cards.CardBaseModifier") local CardBaseModifier = ____CardBaseModifier.CardBaseModifier local ____dota_ts_adapter = require("lib.dota_ts_adapter") local registerModifier = ____dota_ts_adapter.registerModifier local ____crystal_currency = require("crystal_currency") local GetCrystalCurrency = ____crystal_currency.GetCrystalCurrency local CARD_ID = 36 ____exports.card_36 = __TS__Class() local card_36 = ____exports.card_36 card_36.name = "card_36" card_36.____file_path = "scripts/vscripts/cards/examples/card_36.lua" __TS__ClassExtends(card_36, CardBase) function card_36.prototype.GetModifierName(self) return "modifier_card_36" end card_36 = __TS__Decorate(card_36, card_36, {RegisterCard}, {kind = "class", name = "card_36"}) ____exports.card_36 = card_36 ____exports.modifier_card_36 = __TS__Class() local modifier_card_36 = ____exports.modifier_card_36 modifier_card_36.name = "modifier_card_36" modifier_card_36.____file_path = "scripts/vscripts/cards/examples/card_36.lua" __TS__ClassExtends(modifier_card_36, CardBaseModifier) function modifier_card_36.prototype.____constructor(self, ...) CardBaseModifier.prototype.____constructor(self, ...) self.spentCrystalsTracked = 0 self.spendListenerId = nil self.outgoingBonusStacks = 0 end function modifier_card_36.prototype.DeclareFunctions(self) return {MODIFIER_PROPERTY_DAMAGEOUTGOING_PERCENTAGE, MODIFIER_PROPERTY_TOOLTIP} end function modifier_card_36.prototype.getValue(self, key, fallback) return self:getCardValue(key, fallback, CARD_ID) end function modifier_card_36.prototype.getOwnerPlayerId(self) local hero = self:GetParent() if not hero or not IsValidEntity(hero) or not hero:IsRealHero() then return nil end local playerId = hero:GetPlayerOwnerID() if playerId == nil or playerId == nil or playerId < 0 then return nil end return playerId end function modifier_card_36.prototype.OnCustomCreated(self, params) if not IsServer() then return end local playerId = self:getOwnerPlayerId() if playerId == nil then print("[CARD_36] OnCustomCreated: playerId undefined") return end local currency = GetCrystalCurrency(nil) self.spentCrystalsTracked = currency:getTotalSpentCrystals(playerId) print((((("[CARD_36] OnCustomCreated: player=" .. tostring(playerId)) .. ", trackedSpent=") .. tostring(self.spentCrystalsTracked)) .. ", currentStacks=") .. tostring(self:GetStackCount())) self:recalculateStacks() self.spendListenerId = currency:addSpendListener(function(____, eventPlayerId, spentAmount, _newTotal, totalSpent) if eventPlayerId ~= playerId then return end if spentAmount <= 0 then return end self.spentCrystalsTracked = totalSpent print((((((("[CARD_36] SpendEvent: player=" .. tostring(playerId)) .. ", delta=") .. tostring(spentAmount)) .. ", trackedSpent=") .. tostring(self.spentCrystalsTracked)) .. ", stacksBefore=") .. tostring(self:GetStackCount())) self:recalculateStacks() end) print((("[CARD_36] ListenerRegistered: player=" .. tostring(playerId)) .. ", listenerId=") .. tostring(self.spendListenerId)) end function modifier_card_36.prototype.OnDestroy(self) if not IsServer() then return end if self.spendListenerId ~= nil then print("[CARD_36] OnDestroy: remove listenerId=" .. tostring(self.spendListenerId)) GetCrystalCurrency(nil):removeSpendListener(self.spendListenerId) self.spendListenerId = nil end end function modifier_card_36.prototype.recalculateStacks(self) local crystalsPerStep = math.max( 1, self:getValue("crystals_per_step", 2) ) local damagePctPerStep = self:getValue("damage_pct_per_step", 1) local maxBonusPct = math.max( 0, self:getValue("max_bonus_pct", 40) ) if damagePctPerStep <= 0 then self.outgoingBonusStacks = 0 print("[CARD_36] Recalc: damagePctPerStep<=0 -> stacks=0") return end local rawStacks = math.floor(self.spentCrystalsTracked / crystalsPerStep) local maxStacks = math.floor(maxBonusPct / damagePctPerStep) self.outgoingBonusStacks = math.min(rawStacks, maxStacks) print((((((((("[CARD_36] Recalc: trackedSpent=" .. tostring(self.spentCrystalsTracked)) .. ", step=") .. tostring(crystalsPerStep)) .. ", raw=") .. tostring(rawStacks)) .. ", maxStacks=") .. tostring(maxStacks)) .. ", finalStacks=") .. tostring(self.outgoingBonusStacks)) end function modifier_card_36.prototype.GetModifierDamageOutgoing_Percentage(self, _event) local damagePctPerStep = self:getValue("damage_pct_per_step", 1) return self.outgoingBonusStacks * damagePctPerStep * self:getCardCopies() end modifier_card_36 = __TS__Decorate( modifier_card_36, modifier_card_36, {registerModifier(nil)}, {kind = "class", name = "modifier_card_36"} ) ____exports.modifier_card_36 = modifier_card_36 return ____exports