require "TimedActions/ISBaseTimedAction"

ISAddBarricadeAction = ISBaseTimedAction:derive("ISAddBarricadeAction");

function ISAddBarricadeAction:isValid()
	return true;
end

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

function ISAddBarricadeAction:start()
	self.item:setJobType("placeBarricade");
	self.item:setJobDelta(0.0);
end

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

function ISAddBarricadeAction:perform()
	self.item:getContainer():setDrawDirty(true);
	self.item:setJobDelta(0.0);
	self.character:getInventory():Remove("HCLogbarrier");
	if isClient() then
		local args = {x = self.sq:getX(), y = self.sq.getY(), z = self.sq.getZ(), sprite = self.sprite};
		sendClientCommand(self.character, 'Hydrocraft', 'placeBarricade', args);
	else
		HCPlaceItem.placeBarricade(self.sq, self.sprite);
	end
	ISBaseTimedAction.perform(self);
end

function ISAddBarricadeAction:new(character, sq, item, sprite, time)
	local o = {};
	setmetatable(o, self);
	self.__index = self;
	o.character = character;
	o.item = item;
	o.stopOnWalk = true;
	o.stopOnRun = true;
	o.maxTime = time;
	o.sprite = sprite;
	o.sq = sq;
	return o;
end