dofile("scripts/entities/entityinclude.lua")

door = 0
function init(me)
	node_setCursorActivation(me, true)
	door = node_getNearestEntity(me, "EnergyDoor")
	if door ~= 0 and isFlag(FLAG_MITHALAS_THRONEROOM,1) then
		entity_setState(door, STATE_OPENED)
	end
end

function update(me, dt)
end

function activate(me)
	n = getNaija()
	
	entity_idle(n)
	
	entity_swimToNode(n, me)
	entity_watchForPath(n)
	
	
	entity_animate(n, "sitThrone", -1)

	overrideZoom(0.5, 2)
	
	watch(2)
	
	if isFlag(FLAG_MITHALAS_THRONEROOM,0) then
		--if isFlag(FLAG_SEAL_KING,1) and isFlag(FLAG_SEAL_QUEEN,1) and isFlag(FLAG_SEAL_PRINCE,1) then
		if isFlag(FLAG_SEAL_PRINCE,1) then
			debugLog("OPENED DOOR")
			
			entity_setState(door, STATE_OPEN)
			setFlag(FLAG_MITHALAS_THRONEROOM, 1)
			cam_toEntity(door)
			watch(2)
			cam_toEntity(n)
		end
	end
	
	while (not isLeftMouse()) and (not isRightMouse()) do
		watch(FRAME_TIME)
	end
	
	entity_idle(n)
	entity_addVel(n, 0, -200)
	overrideZoom(1, 1)
	watch(1)
	overrideZoom(0)
end
