--------------------------------------------------------------------------------
--  File     : Bridge_Garbage_HO
--  Author(s): Prokopovich Larisa
--
--  Summary  : Скрипт управления локацией.
--
--  Copyright © 2012 Floodlight Games.  All rights reserved.
--------------------------------------------------------------------------------
KEY_CSTORE		= "Garbage_HO"
ROOM_NAME		= "Bridge"
--------------------------------------------------------------------------------
function OnFirstEntry()
	room.ispy:ExcludeFromRandom("SCULL_H_JAW")
	room.ispy:ExcludeFromRandom("LAMP")
end
--------------------------------------------------------------------------------
function OnEntry()
	if room.tasks:GetCount() == 0 then
		if cstore:GetKey(KEY_CSTORE) == 0 then
			room.ispy:AddTaskForRequiredItem("SCULL_H_JAW")
			room.ispy:AddTasksWithDefaultCount(1)
			room.tasks:Shuffle();
		elseif cstore:GetKey(KEY_CSTORE) == 2 then
			room.tasks:ClearAll()
			room.ispy:AddTaskForRequiredItem("LAMP")
			room.ispy:AddTasksWithDefaultCount(1)
			room.tasks:Shuffle();
		end
	end
	game_panel:ShowTask()
end
--------------------------------------------------------------------------------
function OnEndPickedItemAnim(item)
	if room.tasks:IsAllCompleted() then
		if (cstore:GetKey(KEY_CSTORE) == 0) then
			cstore:SetKey(KEY_CSTORE, 1)
			pick_panel:AddItems("SCULL_H_JAW", true)
			room:SafeDelete()
			return true
		elseif (cstore:GetKey(KEY_CSTORE) == 2) then
			cstore:SetKey(KEY_CSTORE, 3)
			pick_panel:AddItems("LAMP", true)
			room:MarkCompleted()
			return true
		end
	end
	return false
end
--------------------------------------------------------------------------------
function OnExit()
	if room.tasks:GetCount() > 0 then
		local cs_state = cstore:GetKey(KEY_CSTORE)
		if cs_state == 1 or cs_state == 3 then
			room.tasks:ClearAll()
		end
	end
	game_panel:ShowInventory()
end
--------------------------------------------------------------------------------
function OnClickOnCentralPanel()
	if (OnEndPickedItemAnim(nil) == false) then
		chapter:JumpRoom(ROOM_NAME)
	end
end
--------------------------------------------------------------------------------