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

require "TimedActions/ISBaseTimedAction"

ISTakeFuel = ISBaseTimedAction:derive("ISTakeFuel");

function ISTakeFuel:isValid()
	return true;
end

function ISTakeFuel:update()
	self.character:faceLocation(self.square:getX(), self.square:getY())
end

function ISTakeFuel:start()
end

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

function ISTakeFuel:perform()
    while self.petrolCan:getUsedDelta() < 1 and tonumber(self.square:getProperties():Val("fuelAmount")) > 0 do
        self.petrolCan:setUsedDelta(self.petrolCan:getUsedDelta() + self.petrolCan:getUseDelta());
        -- FIXME: sync in multiplayer
        self.square:getProperties():Set("fuelAmount", (tonumber(self.square:getProperties():Val("fuelAmount")) - 1) .. "");
    end

    -- needed to remove from queue / start next.
	ISBaseTimedAction.perform(self);
end

function ISTakeFuel:new(character, square, petrolCan, time)
	local o = {}
	setmetatable(o, self)
	self.__index = self
	o.character = character;
    o.square = square;
	o.petrolCan = petrolCan;
	o.stopOnWalk = true;
	o.stopOnRun = true;
	o.maxTime = time;
	return o;
end
