--***********************************************************
--**                    ROBERT JOHNSON                     **
--***********************************************************

require "TimedActions/ISBaseTimedAction"

ISShovelAction = ISBaseTimedAction:derive("ISShovelAction");

function ISShovelAction:isValid()
	return true;
end

function ISShovelAction:update()
	self.item:setJobDelta(self:getJobDelta());
end

function ISShovelAction:start()
	self.item:setJobType(getText("ContextMenu_Remove"));
	self.item:setJobDelta(0.0);
    if self.plant:getSquare() then
        self.sound = getSoundManager():PlayWorldSound("shoveling", self.plant:getSquare(), 0, 10, 1, true);
    end
end

function ISShovelAction:stop()
    if self.sound and self.sound:isPlaying() then
        self.sound:stop();
    end
    ISBaseTimedAction.stop(self);
    self.item:setJobDelta(0.0);
end

function ISShovelAction:perform()
    if self.sound and self.sound:isPlaying() then
        self.sound:stop();
    end
	self.item:getContainer():setDrawDirty(true);
	self.item:setJobDelta(0.0);
	if isClient() then
		local sq = self.plant:getSquare()
		local args = { x = sq:getX(), y = sq:getY(), z = sq:getZ() }
		sendClientCommand(self.character, 'farming', 'removePlant', args)
	else
		basicFarming.removePlant(self.plant)
    end
	ISBaseTimedAction.perform(self);
end

function ISShovelAction:new (character, item, plant, time)
	local o = {}
	setmetatable(o, self)
	self.__index = self
	o.character = character;
	o.item = item;
    o.plant = plant;
	o.stopOnWalk = true;
	o.stopOnRun = true;
	o.maxTime = time;
    o.caloriesModifier = 4;
	return o
end
