289 lines
9.5 KiB
Lua
289 lines
9.5 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 __TS__ArraySplice = ____lualib.__TS__ArraySplice
|
|
local __TS__Number = ____lualib.__TS__Number
|
|
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_cursed = require("cards.modifier_card_cursed")
|
|
local addCursedStack = ____modifier_card_cursed.addCursedStack
|
|
local removeCursedStack = ____modifier_card_cursed.removeCursedStack
|
|
local ____modifier_card_greed = require("cards.modifier_card_greed")
|
|
local updateGreedForHero = ____modifier_card_greed.updateGreedForHero
|
|
local MAIN_INVENTORY_SLOT_COUNT = 6
|
|
____exports.card_9 = __TS__Class()
|
|
local card_9 = ____exports.card_9
|
|
card_9.name = "card_9"
|
|
card_9.____file_path = "scripts/vscripts/cards/examples/card_9.lua"
|
|
__TS__ClassExtends(card_9, CardBase)
|
|
function card_9.prototype.GetModifierName(self)
|
|
return "modifier_card_9"
|
|
end
|
|
card_9 = __TS__Decorate(card_9, card_9, {RegisterCard}, {kind = "class", name = "card_9"})
|
|
____exports.card_9 = card_9
|
|
____exports.modifier_card_9 = __TS__Class()
|
|
local modifier_card_9 = ____exports.modifier_card_9
|
|
modifier_card_9.name = "modifier_card_9"
|
|
modifier_card_9.____file_path = "scripts/vscripts/cards/examples/card_9.lua"
|
|
__TS__ClassExtends(modifier_card_9, CardBaseModifier)
|
|
function modifier_card_9.prototype.____constructor(self, ...)
|
|
CardBaseModifier.prototype.____constructor(self, ...)
|
|
self.appliedCursedStacks = 0
|
|
end
|
|
function modifier_card_9.prototype.IsHidden(self)
|
|
return false
|
|
end
|
|
function modifier_card_9.prototype.IsDebuff(self)
|
|
return true
|
|
end
|
|
function modifier_card_9.prototype.OnCustomCreated(self, params)
|
|
if not IsServer() then
|
|
return
|
|
end
|
|
local hero = self:GetParent()
|
|
if not hero or not IsValidEntity(hero) or not hero:IsRealHero() then
|
|
return
|
|
end
|
|
self:syncCursedStacks(hero)
|
|
local ____temp_0
|
|
if hero:GetPlayerOwnerID() >= 0 then
|
|
____temp_0 = PlayerResource:GetPlayer(hero:GetPlayerOwnerID())
|
|
else
|
|
____temp_0 = nil
|
|
end
|
|
local player = ____temp_0
|
|
updateGreedForHero(nil, hero, player and player.cardSystem)
|
|
end
|
|
function modifier_card_9.prototype.OnCustomRefresh(self, _params)
|
|
if not IsServer() then
|
|
return
|
|
end
|
|
local hero = self:GetParent()
|
|
if not hero or not IsValidEntity(hero) or not hero:IsRealHero() then
|
|
return
|
|
end
|
|
self:syncCursedStacks(hero)
|
|
local ____temp_3
|
|
if hero:GetPlayerOwnerID() >= 0 then
|
|
____temp_3 = PlayerResource:GetPlayer(hero:GetPlayerOwnerID())
|
|
else
|
|
____temp_3 = nil
|
|
end
|
|
local player = ____temp_3
|
|
updateGreedForHero(nil, hero, player and player.cardSystem)
|
|
end
|
|
function modifier_card_9.prototype.OnDestroy(self)
|
|
if not IsServer() then
|
|
return
|
|
end
|
|
local hero = self:GetParent()
|
|
if hero and IsValidEntity(hero) and hero:IsRealHero() then
|
|
local ____temp_6
|
|
if hero:GetPlayerOwnerID() >= 0 then
|
|
____temp_6 = PlayerResource:GetPlayer(hero:GetPlayerOwnerID())
|
|
else
|
|
____temp_6 = nil
|
|
end
|
|
local player = ____temp_6
|
|
updateGreedForHero(nil, hero, player and player.cardSystem)
|
|
end
|
|
if not hero or not IsValidEntity(hero) then
|
|
return
|
|
end
|
|
while self.appliedCursedStacks > 0 do
|
|
removeCursedStack(nil, hero)
|
|
self.appliedCursedStacks = self.appliedCursedStacks - 1
|
|
end
|
|
end
|
|
function modifier_card_9.prototype.DeclareFunctions(self)
|
|
return {MODIFIER_EVENT_ON_DEATH}
|
|
end
|
|
function modifier_card_9.prototype.OnDeath(self, event)
|
|
if not IsServer() then
|
|
return
|
|
end
|
|
local hero = self:GetParent()
|
|
if not hero or not IsValidEntity(hero) or not hero:IsRealHero() then
|
|
return
|
|
end
|
|
if event.attacker == hero and event.unit ~= hero then
|
|
local bonusGold = self:getKillGoldBonus(event)
|
|
if bonusGold > 0 then
|
|
local playerId = hero:GetPlayerOwnerID()
|
|
if playerId ~= nil and playerId ~= nil and playerId >= 0 then
|
|
PlayerResource:ModifyGold(playerId, bonusGold, true, DOTA_ModifyGold_Unspecified)
|
|
self:sendGoldOverheadInThreeBursts(hero, bonusGold)
|
|
end
|
|
end
|
|
return
|
|
end
|
|
if event.unit ~= hero then
|
|
return
|
|
end
|
|
self:stripAllGold(hero)
|
|
self:removeRandomMainInventoryItems(
|
|
hero,
|
|
self:getCardCopies()
|
|
)
|
|
local ____temp_9
|
|
if hero:GetPlayerOwnerID() >= 0 then
|
|
____temp_9 = PlayerResource:GetPlayer(hero:GetPlayerOwnerID())
|
|
else
|
|
____temp_9 = nil
|
|
end
|
|
local player = ____temp_9
|
|
updateGreedForHero(nil, hero, player and player.cardSystem)
|
|
end
|
|
function modifier_card_9.prototype.stripAllGold(self, hero)
|
|
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
|
|
return
|
|
end
|
|
PlayerResource:ModifyGold(playerId, -currentGold, false, DOTA_ModifyGold_Death)
|
|
end
|
|
function modifier_card_9.prototype.removeRandomMainInventoryItems(self, hero, count)
|
|
local items = {}
|
|
do
|
|
local slot = 0
|
|
while slot < MAIN_INVENTORY_SLOT_COUNT do
|
|
local item = hero:GetItemInSlot(slot)
|
|
if item and IsValidEntity(item) and not item:IsNull() then
|
|
items[#items + 1] = item
|
|
end
|
|
slot = slot + 1
|
|
end
|
|
end
|
|
if #items == 0 then
|
|
return
|
|
end
|
|
local toRemove = math.min(
|
|
#items,
|
|
math.max(
|
|
1,
|
|
math.floor(count)
|
|
)
|
|
)
|
|
do
|
|
local i = 0
|
|
while i < toRemove do
|
|
if #items <= 0 then
|
|
break
|
|
end
|
|
local idx = RandomInt(0, #items - 1)
|
|
local item = unpack(__TS__ArraySplice(items, idx, 1))
|
|
if item and IsValidEntity(item) and not item:IsNull() then
|
|
hero:RemoveItem(item)
|
|
end
|
|
i = i + 1
|
|
end
|
|
end
|
|
end
|
|
function modifier_card_9.prototype.getKillGoldBonus(self, event)
|
|
local victim = event.unit
|
|
local baseGold = 0
|
|
if victim and IsValidEntity(victim) and victim ~= self:GetParent() then
|
|
local ____math_max_15 = math.max
|
|
local ____math_floor_14 = math.floor
|
|
local ____opt_12 = victim.GetGoldBounty
|
|
baseGold = ____math_max_15(
|
|
0,
|
|
____math_floor_14(____opt_12 and ____opt_12(victim) or 0)
|
|
)
|
|
end
|
|
if baseGold <= 0 then
|
|
local ____math_floor_18 = math.floor
|
|
local ____event_gold_bounty_16 = event.gold_bounty
|
|
if ____event_gold_bounty_16 == nil then
|
|
____event_gold_bounty_16 = event.gold
|
|
end
|
|
local ____event_gold_bounty_16_17 = ____event_gold_bounty_16
|
|
if ____event_gold_bounty_16_17 == nil then
|
|
____event_gold_bounty_16_17 = 0
|
|
end
|
|
local eventGold = ____math_floor_18(__TS__Number(____event_gold_bounty_16_17))
|
|
baseGold = math.max(0, eventGold)
|
|
end
|
|
if baseGold <= 0 then
|
|
return 0
|
|
end
|
|
local bonusPct = self:getScaledCardValue("kill_gold_bonus_pct", 100, 9)
|
|
return math.max(
|
|
0,
|
|
math.floor(baseGold * bonusPct / 100)
|
|
)
|
|
end
|
|
function modifier_card_9.prototype.syncCursedStacks(self, hero)
|
|
local desiredStacks = self:getCardCopies()
|
|
while self.appliedCursedStacks < desiredStacks do
|
|
addCursedStack(nil, hero)
|
|
self.appliedCursedStacks = self.appliedCursedStacks + 1
|
|
end
|
|
while self.appliedCursedStacks > desiredStacks do
|
|
removeCursedStack(nil, hero)
|
|
self.appliedCursedStacks = self.appliedCursedStacks - 1
|
|
end
|
|
end
|
|
function modifier_card_9.prototype.sendGoldOverheadInThreeBursts(self, hero, totalGold)
|
|
local total = math.max(
|
|
0,
|
|
math.floor(totalGold)
|
|
)
|
|
if total <= 0 then
|
|
return
|
|
end
|
|
local chunkA = math.floor(total / 3)
|
|
local chunkB = math.floor(total / 3)
|
|
local chunkC = total - chunkA - chunkB
|
|
local chunks = {chunkA, chunkB, chunkC}
|
|
local delays = {0, 0.1, 0.2}
|
|
local owner = hero:GetPlayerOwner()
|
|
do
|
|
local i = 0
|
|
while i < #chunks do
|
|
do
|
|
local chunkGold = chunks[i + 1]
|
|
if chunkGold <= 0 then
|
|
goto __continue43
|
|
end
|
|
Timers:CreateTimer(
|
|
delays[i + 1],
|
|
function()
|
|
if not hero or not IsValidEntity(hero) or hero:IsNull() then
|
|
return nil
|
|
end
|
|
SendOverheadEventMessage(
|
|
nil,
|
|
OVERHEAD_ALERT_GOLD,
|
|
hero,
|
|
chunkGold,
|
|
owner
|
|
)
|
|
return nil
|
|
end
|
|
)
|
|
end
|
|
::__continue43::
|
|
i = i + 1
|
|
end
|
|
end
|
|
end
|
|
modifier_card_9 = __TS__Decorate(
|
|
modifier_card_9,
|
|
modifier_card_9,
|
|
{registerModifier(nil)},
|
|
{kind = "class", name = "modifier_card_9"}
|
|
)
|
|
____exports.modifier_card_9 = modifier_card_9
|
|
return ____exports
|