--***********************************************************
--**                    THE INDIE STONE                    **
--***********************************************************

require "TimedActions/ISBaseTimedAction"

ISBBQRemovePropaneTank = ISBaseTimedAction:derive("ISBBQRemovePropaneTank");

function ISBBQRemovePropaneTank:isValid()
	return self.bbq:getObjectIndex() ~= -1 and self.bbq:hasPropaneTank()
end

function ISBBQRemovePropaneTank:update()
	self.character:faceThisObject(self.bbq)
end

function ISBBQRemovePropaneTank:start()
end

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

function ISBBQRemovePropaneTank:perform()
	if isClient() then
		local bbq = self.bbq
		local args = { x = bbq:getX(), y = bbq:getY(), z = bbq:getZ() }
		sendClientCommand(self.character, 'bbq', 'removePropaneTank', args)
	else
		local tank = self.bbq:removePropaneTank()
		if tank then
			self.character:getSquare():AddWorldInventoryItem(tank, 0.5, 0.5, 0)
		end
	end
	-- needed to remove from queue / start next.
	ISBaseTimedAction.perform(self)
end

function ISBBQRemovePropaneTank:new (character, bbq, time)
	local o = {}
	setmetatable(o, self)
	self.__index = self
	o.character = character
	o.stopOnWalk = true
	o.stopOnRun = true
	o.maxTime = time
	-- custom fields
	o.bbq = bbq
	return o
end
