Files
Dota-Zombie-Invasion/scripts/vscripts/items/util_items/item_energy_drink.lua
T
2026-05-29 15:11:31 +07:00

195 lines
7.3 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 ____modifier_general_hunger = require("abilities.modifiers.modifier_general_hunger")
local modifier_buff_food_slot = ____modifier_general_hunger.modifier_buff_food_slot
local modifier_general_hunger = ____modifier_general_hunger.modifier_general_hunger
local BUFF_FOOD_MAX_SLOTS = ____modifier_general_hunger.BUFF_FOOD_MAX_SLOTS
local getBuffFoodSlotCount = ____modifier_general_hunger.getBuffFoodSlotCount
local ____dota_ts_adapter = require("lib.dota_ts_adapter")
local BaseItem = ____dota_ts_adapter.BaseItem
local BaseModifier = ____dota_ts_adapter.BaseModifier
local registerAbility = ____dota_ts_adapter.registerAbility
local registerModifier = ____dota_ts_adapter.registerModifier
local ____heal_tracker = require("utils.heal_tracker")
local HealWithBattlePass = ____heal_tracker.HealWithBattlePass
--- Энергетический напиток — еда: лечение, мана, голод + бафф скорости и регенерации на время
____exports.item_energy_drink = __TS__Class()
local item_energy_drink = ____exports.item_energy_drink
item_energy_drink.name = "item_energy_drink"
item_energy_drink.____file_path = "scripts/vscripts/items/util_items/item_energy_drink.lua"
__TS__ClassExtends(item_energy_drink, BaseItem)
function item_energy_drink.prototype.CastFilterResultTarget(self, target)
if IsServer() then
if not target:IsRealHero() then
return UF_FAIL_CUSTOM
end
if getBuffFoodSlotCount(nil, target) >= BUFF_FOOD_MAX_SLOTS then
return UF_FAIL_CUSTOM
end
if self:GetCurrentCharges() < self:GetInitialCharges() then
return UF_FAIL_CUSTOM
end
return UF_SUCCESS
end
return UF_SUCCESS
end
function item_energy_drink.prototype.GetCustomCastErrorTarget(self, target)
if IsServer() then
if not target:IsRealHero() then
return "#dota_hud_error_cheese_bad_target"
end
if getBuffFoodSlotCount(nil, target) >= BUFF_FOOD_MAX_SLOTS then
return "#dota_hud_error_ability_not_ready"
end
if self:GetCurrentCharges() < self:GetInitialCharges() then
return "#dota_hud_error_havent_charges"
end
end
return ""
end
function item_energy_drink.prototype.OnSpellStart(self)
local target = self:GetCursorTarget()
local item = self
if not target then
return
end
local healAmount = self:GetSpecialValueFor("heal")
local manaAmount = self:GetSpecialValueFor("mana")
target:EmitSound("DOTA_Item.Cheese.Activate")
HealWithBattlePass(
nil,
target,
healAmount,
self,
self:GetCaster(),
true
)
if healAmount > 0 then
SendOverheadEventMessage(
nil,
OVERHEAD_ALERT_HEAL,
target,
healAmount,
target:GetPlayerOwner()
)
end
if manaAmount > 0 then
target:GiveMana(manaAmount)
SendOverheadEventMessage(
nil,
OVERHEAD_ALERT_MANA_ADD,
target,
manaAmount,
target:GetPlayerOwner()
)
end
if target:IsRealHero() then
local buffDuration = self:GetSpecialValueFor("buff_duration")
local buffMoveSpeedPct = self:GetSpecialValueFor("buff_move_speed_pct")
local buffAttackSpeed = self:GetSpecialValueFor("buff_attack_speed")
local modifier = target:AddNewModifier(
self:GetCaster(),
self,
modifier_general_hunger.name,
{}
)
target:AddNewModifier(
self:GetCaster(),
self,
modifier_buff_food_slot.name,
{duration = buffDuration}
)
target:AddNewModifier(
self:GetCaster(),
self,
____exports.modifier_energy_drink_buff.name,
{duration = buffDuration, buff_move_speed_pct = buffMoveSpeedPct, buff_attack_speed = buffAttackSpeed}
)
if modifier then
local hunger_bonus = self:GetSpecialValueFor("hunger_bonus")
do
local i = 0
while i < hunger_bonus do
modifier:IncrementStackCount()
i = i + 1
end
end
end
if item:GetCurrentCharges() <= item:GetInitialCharges() then
UTIL_Remove(item)
return
end
item:SetCurrentCharges(item:GetCurrentCharges() - item:GetInitialCharges())
end
end
item_energy_drink = __TS__Decorate(
item_energy_drink,
item_energy_drink,
{registerAbility(nil)},
{kind = "class", name = "item_energy_drink"}
)
____exports.item_energy_drink = item_energy_drink
--- Бафф от энергетического напитка: скорость передвижения и атаки
____exports.modifier_energy_drink_buff = __TS__Class()
local modifier_energy_drink_buff = ____exports.modifier_energy_drink_buff
modifier_energy_drink_buff.name = "modifier_energy_drink_buff"
modifier_energy_drink_buff.____file_path = "scripts/vscripts/items/util_items/item_energy_drink.lua"
__TS__ClassExtends(modifier_energy_drink_buff, BaseModifier)
function modifier_energy_drink_buff.prototype.____constructor(self, ...)
BaseModifier.prototype.____constructor(self, ...)
self.buffMoveSpeedPct = 0
self.buffAttackSpeed = 0
end
function modifier_energy_drink_buff.prototype.IsHidden(self)
return false
end
function modifier_energy_drink_buff.prototype.IsPurgable(self)
return true
end
function modifier_energy_drink_buff.prototype.IsDebuff(self)
return false
end
function modifier_energy_drink_buff.prototype.GetAttributes(self)
return MODIFIER_ATTRIBUTE_MULTIPLE
end
function modifier_energy_drink_buff.prototype.OnCreated(self, params)
if params and params.buff_move_speed_pct ~= nil then
self.buffMoveSpeedPct = params.buff_move_speed_pct
end
if params and params.buff_attack_speed ~= nil then
self.buffAttackSpeed = params.buff_attack_speed
end
local ability = self:GetAbility()
if ability then
if self.buffMoveSpeedPct == 0 then
self.buffMoveSpeedPct = ability:GetSpecialValueFor("buff_move_speed_pct")
end
if self.buffAttackSpeed == 0 then
self.buffAttackSpeed = ability:GetSpecialValueFor("buff_attack_speed")
end
end
end
function modifier_energy_drink_buff.prototype.DeclareFunctions(self)
return {MODIFIER_PROPERTY_MOVESPEED_BONUS_PERCENTAGE, MODIFIER_PROPERTY_ATTACKSPEED_PERCENTAGE}
end
function modifier_energy_drink_buff.prototype.GetModifierMoveSpeedBonus_Percentage(self)
return self.buffMoveSpeedPct
end
function modifier_energy_drink_buff.prototype.GetModifierAttackSpeedPercentage(self)
return self.buffAttackSpeed
end
function modifier_energy_drink_buff.prototype.GetTexture(self)
return "../items/utils/energetic"
end
modifier_energy_drink_buff = __TS__Decorate(
modifier_energy_drink_buff,
modifier_energy_drink_buff,
{registerModifier(nil)},
{kind = "class", name = "modifier_energy_drink_buff"}
)
____exports.modifier_energy_drink_buff = modifier_energy_drink_buff
return ____exports