ITEM.name = "Расходник"
ITEM.description = "Что-то съедобное"
ITEM.model = "models/kleiner.mdl"
ITEM.category = "Расходники"

ITEM.width = 1
ITEM.height = 1
ITEM.price = 0

ITEM.alcohol = 0
ITEM.hunger = 0
ITEM.thirst = 0
ITEM.empty = false
ITEM.quantity = 1

ITEM.weight = 0
ITEM.flatweight = 0

ITEM.consumableWeapon = "ix_consumable"
ITEM.consumableModel = ""

function ITEM:GetDescription()
	local invdesc = ""
	if self.longdesc then
		invdesc = "\n\n"..(self.longdesc)
	end

	if (self.entity) then
		return (self.description)
	else
        return (self.description..invdesc)
	end
end

ITEM.functions.use = {
    name = "Употребить",
    icon = "icon16/cup.png",

    OnCanRun = function(item)
        local client = item.player
        return (not IsValid(item.entity)) and IsValid(client) and client:GetCharacter() and item.invID != 0
    end,

    OnRun = function(item)
        local client = item.player
        if not IsValid(client) then return false end

        client._nextConsumePress = client._nextConsumePress or 0
        if CurTime() < client._nextConsumePress then
            return false
        end
        client._nextConsumePress = CurTime() + 5

        local weaponClass = item.consumableWeapon or "ix_consumable"
        client:Give(weaponClass)

        local weapon = client:GetWeapon(weaponClass)
        if IsValid(weapon) then
            local itemType = "consumable"
            if (item.thirst or 0) > 0 and (item.hunger or 0) == 0 then
                itemType = "drink"
            elseif (item.hunger or 0) > 0 and (item.thirst or 0) == 0 then
                itemType = "food"
            end

            weapon:SetItemData(
                item.hunger or 0,
                item.thirst or 0,
                item.alcohol or 0,
                item.empty or false,
                itemType,
                item.consumableModel or ""
            )

            client:SelectWeapon(weaponClass)
        end

        -- Удаляем предмет через небольшую задержку, чтобы анимация/оружие успели инициализироваться
        timer.Simple(0.15, function()
            if (item) then
                item:Remove()
            end
        end)

        return false
    end
}

function ITEM:GetWeight()
  return self.flatweight + self.weight
end

function ITEM:GetPrice()
	return self.price
end
