--***********************************************************
--**                    TIM BAKER                          **
--***********************************************************

require "TimedActions/ISBaseTimedAction"

ISAddFuelAction = ISBaseTimedAction:derive("ISAddFuelAction");

function ISAddFuelAction:isValid()
	camping.updateClientCampfire(self.campfire)
	return self.campfire:getObject() and
		self.character:getInventory():contains(self.item)
end

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

function ISAddFuelAction:start()
	self.item:setJobType(campingText.addFuel);
	self.item:setJobDelta(0.0);
end

function ISAddFuelAction:stop()
	ISBaseTimedAction.stop(self);
    self.item:setJobDelta(0.0);
end

function ISAddFuelAction:perform()
	self.character:getInventory():Remove(self.item)
--	self.item:getContainer():setDrawDirty(true);
    self.item:setJobDelta(0.0);
    if isClient() then
		local cf = self.campfire
		local args = { x = cf.x, y = cf.y, z = cf.z, fuelAmt = self.fuelAmt }
		sendClientCommand(self.character, 'camping', 'addFuel', args)
	else
		camping.addFuel(self.campfire, self.fuelAmt)
	end
    -- needed to remove from queue / start next.
	ISBaseTimedAction.perform(self);
end

function ISAddFuelAction:new(character, campfire, item, fuelAmt, time)
	local o = {}
	setmetatable(o, self)
	self.__index = self
	o.character = character;
	o.stopOnWalk = true;
	o.stopOnRun = true;
	o.maxTime = time;
	-- custom fields
	o.campfire = campfire
	o.fuelAmt = fuelAmt
	o.item = item;
	return o;
end
