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

require "TimedActions/ISBaseTimedAction"

ISRemoveTrapAction = ISBaseTimedAction:derive("ISRemoveTrapAction");

function ISRemoveTrapAction:isValid()
	return self.trap:getTrapObject() ~= nil
end

function ISRemoveTrapAction:update()
end

function ISRemoveTrapAction:start()
end

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

function ISRemoveTrapAction:perform()
	if isClient() then
		local sq = self.trap:getSquare()
		local args = { x = sq:getX(), y = sq:getY(), z = sq:getZ() }
		sendClientCommand(self.character, 'trapping', 'remove', args)
	else
		self.character:getInventory():AddItem(self.trap.type);
		self.trap:removeBait(self.character)
		TrapSystem.removeTrap(self.trap, true)
    end
	ISBaseTimedAction.perform(self);
end

function ISRemoveTrapAction:new(character, trap, time)
	local o = {}
	setmetatable(o, self)
	self.__index = self
	o.character = character;
	o.trap = trap;
    o.maxTime = time;
	return o;
end
