99 lines
3.6 KiB
Lua
99 lines
3.6 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 GetPlayerCardsTaken = ____CardSystem.GetPlayerCardsTaken
|
|
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 ____luck = require("utils.luck")
|
|
local addLuck = ____luck.addLuck
|
|
local reduceLuck = ____luck.reduceLuck
|
|
local CARD_ID = 18
|
|
____exports.card_18 = __TS__Class()
|
|
local card_18 = ____exports.card_18
|
|
card_18.name = "card_18"
|
|
card_18.____file_path = "scripts/vscripts/cards/examples/card_18.lua"
|
|
__TS__ClassExtends(card_18, CardBase)
|
|
function card_18.prototype.GetModifierName(self)
|
|
return "modifier_card_18"
|
|
end
|
|
card_18 = __TS__Decorate(card_18, card_18, {RegisterCard}, {kind = "class", name = "card_18"})
|
|
____exports.card_18 = card_18
|
|
____exports.modifier_card_18 = __TS__Class()
|
|
local modifier_card_18 = ____exports.modifier_card_18
|
|
modifier_card_18.name = "modifier_card_18"
|
|
modifier_card_18.____file_path = "scripts/vscripts/cards/examples/card_18.lua"
|
|
__TS__ClassExtends(modifier_card_18, CardBaseModifier)
|
|
function modifier_card_18.prototype.____constructor(self, ...)
|
|
CardBaseModifier.prototype.____constructor(self, ...)
|
|
self.appliedLuckBonus = 0
|
|
end
|
|
function modifier_card_18.prototype.getValue(self, key, fallback)
|
|
return self:getCardValue(key, fallback, CARD_ID)
|
|
end
|
|
function modifier_card_18.prototype.OnCustomCreated(self, params)
|
|
if not IsServer() then
|
|
return
|
|
end
|
|
self:updateLuckBonus()
|
|
self:StartIntervalThink(1)
|
|
end
|
|
function modifier_card_18.prototype.OnCustomRefresh(self, params)
|
|
if not IsServer() then
|
|
return
|
|
end
|
|
self:updateLuckBonus()
|
|
end
|
|
function modifier_card_18.prototype.OnIntervalThink(self)
|
|
if not IsServer() then
|
|
return
|
|
end
|
|
self:updateLuckBonus()
|
|
end
|
|
function modifier_card_18.prototype.OnDestroy(self)
|
|
if not IsServer() then
|
|
return
|
|
end
|
|
local parent = self:GetParent()
|
|
if not parent or not IsValidEntity(parent) or not parent:IsRealHero() then
|
|
return
|
|
end
|
|
if self.appliedLuckBonus > 0 then
|
|
reduceLuck(nil, parent, self.appliedLuckBonus)
|
|
self.appliedLuckBonus = 0
|
|
end
|
|
end
|
|
function modifier_card_18.prototype.updateLuckBonus(self)
|
|
local parent = self:GetParent()
|
|
if not parent or not IsValidEntity(parent) or not parent:IsRealHero() then
|
|
return
|
|
end
|
|
local copies = self:getCardCopies()
|
|
local baseLuckBonus = self:getValue("base_luck_bonus", 10) * copies
|
|
local luckPerCardTaken = self:getValue("luck_per_card_taken", 1) * copies
|
|
local playerId = parent:GetPlayerOwnerID()
|
|
local cardsTaken = playerId >= 0 and GetPlayerCardsTaken(nil, playerId) or 0
|
|
local desiredLuckBonus = math.max(0, baseLuckBonus + cardsTaken * luckPerCardTaken)
|
|
local delta = desiredLuckBonus - self.appliedLuckBonus
|
|
if delta > 0 then
|
|
addLuck(nil, parent, delta)
|
|
elseif delta < 0 then
|
|
reduceLuck(nil, parent, -delta)
|
|
end
|
|
self.appliedLuckBonus = desiredLuckBonus
|
|
end
|
|
modifier_card_18 = __TS__Decorate(
|
|
modifier_card_18,
|
|
modifier_card_18,
|
|
{registerModifier(nil)},
|
|
{kind = "class", name = "modifier_card_18"}
|
|
)
|
|
____exports.modifier_card_18 = modifier_card_18
|
|
return ____exports
|