139 lines
4.9 KiB
Lua
139 lines
4.9 KiB
Lua
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 ____modifier_card_greed = require("cards.modifier_card_greed")
|
|
local updateGreedForHero = ____modifier_card_greed.updateGreedForHero
|
|
local ____WaveManager = require("WaveManager")
|
|
local WaveManager = ____WaveManager.WaveManager
|
|
local CARD_ID = 23
|
|
local function isCard23GoldTickBlocked(self)
|
|
if WaveManager:getInstance():isEndingCutsceneReadyVoteOpen() then
|
|
return true
|
|
end
|
|
local cutscene = GameRules.CutsceneManager
|
|
if cutscene ~= nil and cutscene:isCutsceneActive() then
|
|
return true
|
|
end
|
|
return false
|
|
end
|
|
____exports.card_23 = __TS__Class()
|
|
local card_23 = ____exports.card_23
|
|
card_23.name = "card_23"
|
|
card_23.____file_path = "scripts/vscripts/cards/examples/card_23.lua"
|
|
__TS__ClassExtends(card_23, CardBase)
|
|
function card_23.prototype.GetModifierName(self)
|
|
return "modifier_card_23"
|
|
end
|
|
card_23 = __TS__Decorate(card_23, card_23, {RegisterCard}, {kind = "class", name = "card_23"})
|
|
____exports.card_23 = card_23
|
|
____exports.modifier_card_23 = __TS__Class()
|
|
local modifier_card_23 = ____exports.modifier_card_23
|
|
modifier_card_23.name = "modifier_card_23"
|
|
modifier_card_23.____file_path = "scripts/vscripts/cards/examples/card_23.lua"
|
|
__TS__ClassExtends(modifier_card_23, CardBaseModifier)
|
|
function modifier_card_23.prototype.____constructor(self, ...)
|
|
CardBaseModifier.prototype.____constructor(self, ...)
|
|
self.lastGoldSnapshot = 0
|
|
end
|
|
function modifier_card_23.prototype.getValue(self, key, fallback)
|
|
return self:getCardValue(key, fallback, CARD_ID)
|
|
end
|
|
function modifier_card_23.prototype.OnCustomCreated(self, params)
|
|
if not IsServer() then
|
|
return
|
|
end
|
|
self.lastGoldSnapshot = self:getCurrentPlayerGold()
|
|
self:startGoldTick()
|
|
end
|
|
function modifier_card_23.prototype.OnCustomRefresh(self, params)
|
|
if not IsServer() then
|
|
return
|
|
end
|
|
self.lastGoldSnapshot = self:getCurrentPlayerGold()
|
|
self:startGoldTick()
|
|
end
|
|
function modifier_card_23.prototype.startGoldTick(self)
|
|
local tickSeconds = math.max(
|
|
1,
|
|
self:getValue("gold_tick_interval_sec", 60)
|
|
)
|
|
self:StartIntervalThink(tickSeconds)
|
|
end
|
|
function modifier_card_23.prototype.getCurrentPlayerGold(self)
|
|
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 math.max(
|
|
0,
|
|
PlayerResource:GetGold(playerId)
|
|
)
|
|
end
|
|
function modifier_card_23.prototype.OnIntervalThink(self)
|
|
if not IsServer() then
|
|
return
|
|
end
|
|
if isCard23GoldTickBlocked(nil) then
|
|
self.lastGoldSnapshot = self:getCurrentPlayerGold()
|
|
return
|
|
end
|
|
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 currentGold = PlayerResource:GetGold(playerId)
|
|
if currentGold <= 0 then
|
|
self.lastGoldSnapshot = 0
|
|
return
|
|
end
|
|
local percentPerMinute = self:getScaledCardValue("gold_income_pct_per_minute", 15)
|
|
local bonusGold = math.floor(currentGold * (percentPerMinute / 100))
|
|
if bonusGold <= 0 then
|
|
self.lastGoldSnapshot = currentGold
|
|
return
|
|
end
|
|
local earnedGoldForTick = math.max(0, currentGold - self.lastGoldSnapshot)
|
|
local minEarnedPct = math.max(
|
|
0,
|
|
self:getScaledCardValue("min_earned_gold_pct_of_dividend_required", 25)
|
|
)
|
|
local minEarnedGoldRequired = math.ceil(bonusGold * (minEarnedPct / 100))
|
|
if earnedGoldForTick < minEarnedGoldRequired then
|
|
self.lastGoldSnapshot = currentGold
|
|
return
|
|
end
|
|
PlayerResource:ModifyGold(playerId, bonusGold, true, DOTA_ModifyGold_Unspecified)
|
|
self.lastGoldSnapshot = math.max(
|
|
0,
|
|
PlayerResource:GetGold(playerId)
|
|
)
|
|
local ____updateGreedForHero_2 = updateGreedForHero
|
|
local ____opt_0 = PlayerResource:GetPlayer(playerId)
|
|
____updateGreedForHero_2(nil, hero, ____opt_0 and ____opt_0.cardSystem)
|
|
end
|
|
modifier_card_23 = __TS__Decorate(
|
|
modifier_card_23,
|
|
modifier_card_23,
|
|
{registerModifier(nil)},
|
|
{kind = "class", name = "modifier_card_23"}
|
|
)
|
|
____exports.modifier_card_23 = modifier_card_23
|
|
return ____exports
|