---
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by Robotex140.
--- DateTime: 28-Jan-22 04:27
---

require "TimedActions/ISBaseTimedAction"

ISHarvestHoneyAction = ISBaseTimedAction:derive("ISHarvestHoneyAction");

function ISHarvestHoneyAction:isValid()
    -- check for items
    return true
    --  return self.beehive:canHarvest()
end

function ISHarvestHoneyAction:waitToStart()
    -- self.character:faceThisObject(self.beehive:getObject())
    self.character:faceLocation(self.beehive.globalObject:getX(), self.beehive.globalObject:getY())
    return self.character:shouldBeTurning()
end

function ISHarvestHoneyAction:update()
    -- self.character:faceThisObject(self.beehive:getObject())
    self.character:faceLocation(self.beehive.globalObject:getX(), self.beehive.globalObject:getY())
    self.character:setMetabolicTarget(Metabolics.HeavyDomestic);
end

function ISHarvestHoneyAction:start()
    self:setActionAnim("Loot")
    self.character:SetVariable("LootPosition", "Low")

    -- used to send loot position
    self.character:reportEvent("EventLootItem");

    self.sound = self.character:playSound("SowSeeds");
end

function ISHarvestHoneyAction:stop()
    ISBaseTimedAction.stop(self);
end

function ISHarvestHoneyAction:perform()


    local n_combs = math.floor(self.beehive.honeyAmount/Beehive.week_unit)

    local inv = self.character:getInventory()
    local smokers = inv:getItemsFromFullType("Hydrocraft.HCBeesmokerfull")
    smokers:get(0):Use()

    for x=1, n_combs do
        inv:AddItem("Hydrocraft.HCHoneycomb");
    end

    local args = { x = self.beehive.x, y = self.beehive.y, z = self.beehive.z}
    sendClientCommand(self.character, 'Beehive','harvest', args)
    -- needed to remove from queue / start next.
    ISBaseTimedAction.perform(self);
end

function ISHarvestHoneyAction:new(character, beehive, time)
    local o = {}
    setmetatable(o, self)
    self.__index = self
    o.character = character;
    o.beehive = beehive;
    o.stopOnWalk = true;
    o.stopOnRun = true;
    o.maxTime = time;
    if character:isTimedActionInstant() then
        o.maxTime = 1;
    end
    return o;
end
