119 lines
4.1 KiB
Lua
119 lines
4.1 KiB
Lua
local ____lualib = require("lualib_bundle")
|
|
local __TS__Class = ____lualib.__TS__Class
|
|
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
|
|
local __TS__ArraySplice = ____lualib.__TS__ArraySplice
|
|
local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
|
|
local __TS__Decorate = ____lualib.__TS__Decorate
|
|
local ____exports = {}
|
|
local ____dota_ts_adapter = require("lib.dota_ts_adapter")
|
|
local BaseModifier = ____dota_ts_adapter.BaseModifier
|
|
local registerModifier = ____dota_ts_adapter.registerModifier
|
|
____exports.modifier_campfire_cooking = __TS__Class()
|
|
local modifier_campfire_cooking = ____exports.modifier_campfire_cooking
|
|
modifier_campfire_cooking.name = "modifier_campfire_cooking"
|
|
modifier_campfire_cooking.____file_path = "scripts/vscripts/cooking/modifier_campfire_cooking.lua"
|
|
__TS__ClassExtends(modifier_campfire_cooking, BaseModifier)
|
|
function modifier_campfire_cooking.prototype.____constructor(self, ...)
|
|
BaseModifier.prototype.____constructor(self, ...)
|
|
self.cookingOrders = {}
|
|
self.readyDishes = {}
|
|
end
|
|
function modifier_campfire_cooking.prototype.IsHidden(self)
|
|
return true
|
|
end
|
|
function modifier_campfire_cooking.prototype.IsPurgable(self)
|
|
return false
|
|
end
|
|
function modifier_campfire_cooking.prototype.IsPermanent(self)
|
|
return true
|
|
end
|
|
function modifier_campfire_cooking.prototype.OnCreated(self, params)
|
|
if IsServer() then
|
|
self.cookingOrders = {}
|
|
self.readyDishes = {}
|
|
local parent = self:GetParent()
|
|
if parent and IsValidEntity(parent) then
|
|
parent:SetThink(
|
|
function()
|
|
self:CheckCookingTimers()
|
|
return 0.1
|
|
end,
|
|
"CampfireCookingThink",
|
|
"0",
|
|
nil
|
|
)
|
|
end
|
|
end
|
|
end
|
|
function modifier_campfire_cooking.prototype.CheckCookingTimers(self)
|
|
if not IsServer() then
|
|
return
|
|
end
|
|
local currentTime = GameRules:GetGameTime()
|
|
local ordersToComplete = {}
|
|
do
|
|
local i = #self.cookingOrders - 1
|
|
while i >= 0 do
|
|
local order = self.cookingOrders[i + 1]
|
|
local elapsed = currentTime - order.startTime
|
|
if elapsed >= order.duration then
|
|
self:AddReadyDish({recipeIndex = order.recipeIndex, playerID = order.playerID, result = order.result, charges = 1})
|
|
ordersToComplete[#ordersToComplete + 1] = i
|
|
end
|
|
i = i - 1
|
|
end
|
|
end
|
|
for ____, index in ipairs(ordersToComplete) do
|
|
self:RemoveCookingOrder(index)
|
|
end
|
|
end
|
|
function modifier_campfire_cooking.prototype.AddCookingOrder(self, order)
|
|
if not IsServer() then
|
|
return
|
|
end
|
|
local ____self_cookingOrders_0 = self.cookingOrders
|
|
____self_cookingOrders_0[#____self_cookingOrders_0 + 1] = order
|
|
end
|
|
function modifier_campfire_cooking.prototype.GetCookingOrders(self)
|
|
return self.cookingOrders
|
|
end
|
|
function modifier_campfire_cooking.prototype.RemoveCookingOrder(self, orderIndex)
|
|
if not IsServer() then
|
|
return
|
|
end
|
|
__TS__ArraySplice(self.cookingOrders, orderIndex, 1)
|
|
end
|
|
function modifier_campfire_cooking.prototype.AddReadyDish(self, dish)
|
|
if not IsServer() then
|
|
return
|
|
end
|
|
local ____self_readyDishes_1 = self.readyDishes
|
|
____self_readyDishes_1[#____self_readyDishes_1 + 1] = dish
|
|
end
|
|
function modifier_campfire_cooking.prototype.GetReadyDishes(self)
|
|
return self.readyDishes
|
|
end
|
|
function modifier_campfire_cooking.prototype.RemoveReadyDish(self, dishIndex)
|
|
if not IsServer() then
|
|
return
|
|
end
|
|
__TS__ArraySplice(self.readyDishes, dishIndex, 1)
|
|
end
|
|
function modifier_campfire_cooking.prototype.GetReadyDishesForPlayer(self, playerID)
|
|
return __TS__ArrayFilter(
|
|
self.readyDishes,
|
|
function(____, dish) return dish.playerID == playerID end
|
|
)
|
|
end
|
|
function modifier_campfire_cooking.prototype.DeclareFunctions(self)
|
|
return {}
|
|
end
|
|
modifier_campfire_cooking = __TS__Decorate(
|
|
modifier_campfire_cooking,
|
|
modifier_campfire_cooking,
|
|
{registerModifier(nil)},
|
|
{kind = "class", name = "modifier_campfire_cooking"}
|
|
)
|
|
____exports.modifier_campfire_cooking = modifier_campfire_cooking
|
|
return ____exports
|