--------------------------------------------------------------------------------
--  File     : Tavern_int_Witch_box_MG
--  Author(s): Prokopovich Larisa
--
--  Summary  : Скрипт управления локацией.
--
--  Copyright © 2012 Floodlight Games.  All rights reserved.
--------------------------------------------------------------------------------
function OnFirstEntry()
	stars:Show("BRIDGE_POTION_UN", "4")
	stars:Show("THREAD_NEEDLE", "4")
	cstore:SetKey("Close_Witch_Box", 0)
end
--------------------------------------------------------------------------------
function OnEntry()
	if cstore:GetKey("Hollow_HO") >= 3 then
		solve:Enable(true)
		--вызов функции из кода
		room:Start()
		room:GetItem("M_COVER"):Hide()
	end
end
--------------------------------------------------------------------------------
function OnMouseClickOnItem(item)
	local itemName = item:GetName()
	
	if itemName == "GOBACK" then
		chapter:JumpRoom("Tavern_int")
		return true
	end
	
	if itemName == "M_COVER" then   				--крышка шкатулки
		comment:Add("CMT_Box_Player")
		return true
		
	elseif itemName == "BRIDGE_POTION_UN" then   	--настой Драконовой травы
		EndCloseup("THREAD_NEEDLE", "BRIDGE_POTION_UN")
		journal:CompleteTask("p2_potion")
		return true
		
	elseif itemName == "THREAD_NEEDLE" then   		--нитки с иголкой
		EndCloseup("BRIDGE_POTION_UN", "THREAD_NEEDLE")
		return true
	end
end
--------------------------------------------------------------------------------
function OnPuzzleWin()
	solve:Enable(false)
	room:GetItem("COVER"):Hide()
	room:GetItem("N_REEL"):Hide()
	room:GetItem("BRIDGE_POTION_UN"):Show()
	room:GetItem("THREAD_NEEDLE"):Show()
	cstore:SetKey("Close_Witch_Box", 1)
	room.sfx:Play ("puzzle_done")			--звук "пазл пройден - открывается шкатулка"
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function EndCloseup(check_name, pick_name)
	if room:GetItem(check_name):IsVisible() then
		pick_panel:AddItems(pick_name, false)
	else
		cstore:SetKey("Close_Witch_Box", 2)
		pick_panel:AddItems(pick_name, true)
		room:MarkCompleted()
	end
end
