--function onGetOverridePickType(self, msg)
--    msg.ePickType = 14
--	return msg
--end

function onCheckUseRequirements(self, msg)
	-- if we're in use dont let the client use this object
    if self:GetVar('bIsInUse') then 
        msg.bCanUse = false
        
        return msg
    end        
end


function onStartup(self)
	self:SetVar("switch", 0)
end

function onClientUse(self, msg)
	-- see if this object has an animation on it by getting the time
	local animTime = 2

	GAMEOBJ:GetTimer():AddTimerWithCancel( animTime, "reset", self )
	self:SetVar("bIsInUse", true)
	self:RequestPickTypeUpdate()

    if self:GetVar("switch") == 1 then
        self:StopFXEffect{name = "glowlight"}
        self:SetVar("switch", 0)

    elseif self:GetVar("switch") == 0 then
        self:PlayFXEffect{name = "glowlight", effectType = "light", effectID = 128}
        self:SetVar("switch", 1)
    end
end

function onGetPriorityPickListType(self, msg)  
    local myPriority = 0.8  

    if ( myPriority > msg.fCurrentPickTypePriority ) then    
        msg.fCurrentPickTypePriority = myPriority  
		-- if we are inuse then dont let this object be picked
        if self:GetVar('bIsInUse') then
            msg.ePickType = -1
        else
            msg.ePickType = 14    -- Interactive pick type     
        end
    end    

    return msg
end 

function onTimerDone(self, msg)
    if msg.name == "reset" then
		-- get the local player
		local player = GAMEOBJ:GetObjectByID(GAMEOBJ:GetLocalCharID())
		
		-- terminate the interaction for the player
		player:TerminateInteraction{type = 'fromInteraction', ObjIDTerminator = self}
		-- set inuse to false and update pick type
        self:SetVar('bIsInUse', false)
        self:RequestPickTypeUpdate()
    end
end 