--------------------------------------------------------------------------------
--  File     : Witch's_house_int
--  Author(s): Prokopovich Larisa
--
--  Summary  : Скрипт управления локацией.
--
--  Copyright © 2012 Floodlight Games.  All rights reserved.
--------------------------------------------------------------------------------
function OnFirstEntry()
	secret = room:GetItem("WITCH_SECRET")
	secret:PlayAnimation()
	secret:SetAnimPause(true)	
	
	horn = room:GetItem("WITCH_HORN_TWITCHES")
	horn:PlayAnimation()
	horn:SetAnimPause(true)

	music:Stop(true)
--	music:Play("reprise_1", false)
	
	room.sfx:Play ("jingle_10_boom")	--звук джингла при первом входе

	stars:Show("M_SCULL_H", "2")
	stars:Show("M_WITCH_BOOK", "2")
	stars:Show("M_FURNACE", "4")
	stars:Show("M_SHELF", "4")
	stars:Show("M_SKULL_A", "4")
	stars:Show("FUNGUS", "4")
	stars:Show("WITCH_HORN_TWITCHES", "4")
	stars:Show("WITCH_HORN", "4")
	stars:Show("PESTLE", "4")
	stars:Show("PICK", "4")
end
--------------------------------------------------------------------------------
function OnEntry()
	music:PlayLoopWithDelay(20, "horror_6")
	ambient:Play("Witch's_house_int")
end
--------------------------------------------------------------------------------
function OnMouseClickOnItem(item)
	local itemName = item:GetName()
	
	if itemName == "M_TO_EXIT" then
		chapter:JumpRoom("Witch's_house_ext")					--выход из домика
		return true
		
	elseif itemName == "M_WITCH_BOOK" then
		chapter:JumpCloseup("Witch's_house_int_Witch_book_MG")	--переход в close-up с книгой
		return true
	elseif itemName == "M_SCULL_H" then
		chapter:JumpCloseup("Witch's_house_int_Scull_h")		--переход в close-up с черепом
		return true
	elseif (itemName == "WITCH_SECRET") and not(item:IsEnabled()) then
		chapter:JumpCloseup("Witch's_house_int_Cache")			--переход в close-up с тайником
		return true
	end
	
	
	if itemName == "M_SKULL_A" then					--череп животного	
		comment:Add("CMT_Scull_Player")
		return true
	
	elseif itemName == "M_FURNACE" then				--топка печи	
		comment:Add("CMT_Furnace1_Player")
		return true
	
	elseif itemName == "M_SHELF" then				--шкафчик	
		comment:Add("CMT_Shelf_Player")
		room.sfx:Play ("open_door_fail")	--звук "пробуем открыть шкафчик - без ключа не открывается"
		return true
	
	elseif itemName == "WITCH_HORN_TWITCHES" then	--рог на черепе животного (глаз не вставлен) 
		item:SetAnimPause(false)
		room:AddCtrlAnimation("WITCH_HORN_TWITCHES", -1)
		comment:Add("CMT_Rog_Player")
		room.sfx:Play ("not_turn_horn")
		return true
		
	elseif itemName == "WITCH_HORN" then			--рог на черепе животного (глаз вставлен)
		if not(item:IsEnabled()) then
			item:SetAnimPause(false)
			room:AddCtrlAnimation("WITCH_HORN", -1)
			room.sfx:Play ("turn_horn")		--звук "поворачиваем рог, выдвигается кирпич из стены"
			return true
		end
			
	elseif itemName == "PESTLE" then				--пестик	
		pick_panel:AddItems(itemName, false)
		return true	
	
	elseif itemName == "PICK" then					--кайло	
		pick_panel:AddItems(itemName, false)
		return true	
	
	elseif itemName == "FUNGUS" then				--гриб	
		pick_panel:AddItems(itemName, false)
		journal:CompleteTask("p2_fungus")
		return true	
	end
end
--------------------------------------------------------------------------------
function OnClickItemOnItem(item)
	local itemName = item:GetName()
	
	if itemName == "M_WITCH_BOOK" then
		chapter:JumpCloseup("Witch's_house_int_Witch_book_MG")	--переход в close-up с книгой
		return true
	elseif itemName == "M_SCULL_H" then
		chapter:JumpCloseup("Witch's_house_int_Scull_h")		--переход в close-up с черепом
		return true
	elseif (itemName == "WITCH_SECRET") and not(item:IsEnabled()) then
		chapter:JumpCloseup("Witch's_house_int_Cache")			--переход в close-up с тайником
		return true
	end
	
	if itemName == "M_SKULL_A" then				--каменный глаз на череп
		if cursor:IsItemNameEqual("EYESTONE") then
			cursor:RemoveItem()
			room:GetItem("M_SKULL_A"):Hide()
			room:GetItem("EYESTONE_ON_SCULL"):Show()
			room:GetItem("WITCH_HORN_TWITCHES"):Hide()
			
			horn = room:GetItem("WITCH_HORN")
			horn:Show()
			horn:Disable()
			horn:PlayAnimation()
			horn:SetAnimPause(true)
			
			room.sfx:Play ("insert_eye")		--звук "вставляем глаз в череп на стене"
			return true
		end
	end
	
	if itemName == "M_SHELF" then				--ключ от шкафчика на шкафчик
		if cursor:IsItemNameEqual("WITCH_SHELF_KEY") then
			cursor:RemoveItem()
			room:GetItem("M_SHELF"):Hide()
			room:GetItem("SHELF_DOOR_OPEN"):Show()
			room:GetItem("FUNGUS"):Show()
			room:GetItem("N_NAKL_TOADSTOOL"):Show()
			room.sfx:Play ("open_lock")		--звук "открываем шкафчик ключом"
			return true
		end
	end
	
	if itemName == "M_FURNACE" then				--кочергу на топку печи
		if cursor:IsItemNameEqual("POKER") then
			cursor:RemoveItem()
			room:GetItem("M_FURNACE"):Hide()
			pick_panel:AddItems("WITCH_SHELF_KEY", false)
			room.sfx:Play ("get_chicken_arm")	--звук "кочергой достается куриная лапка из очага"
			return true
		
		elseif cursor:IsItemNameEqual("SPADE_Q") then
			comment:Add("CMT_Furnace2_Player")
			return true
		end
	end
end
--------------------------------------------------------------------------------
-- Окончание анимации поворачивания рога (глаз не вставлен)
function OnAnimationComplete_WITCH_HORN_TWITCHES(forced)
	horn = room:GetItem("WITCH_HORN_TWITCHES")
	horn:PlayAnimation()
	horn:SetAnimPause(true)
end
--------------------------------------------------------------------------------
-- Окончание анимации поворачивания рога (глаз вставлен)
function OnAnimationComplete_WITCH_HORN(forced)
	room:GetItem("WITCH_SECRET"):SetAnimPause(false)
	room:AddCtrlAnimation("WITCH_SECRET", -1)
	
	local witch_horn = room:GetItem("WITCH_HORN")
	witch_horn:Enable()
	stars:Hide("WITCH_HORN")
			
	if forced == true then
		room:VideoSeekToEnd(witch_horn)
	end
end
--------------------------------------------------------------------------------
-- Окончание анимации выдвигания тайника
function OnAnimationComplete_WITCH_SECRET(forced)
	witch_secret = room:GetItem("WITCH_SECRET")
	witch_secret:Disable()
	stars:Show("WITCH_SECRET", "2")
	
	if forced == true then
		room:VideoSeekToEnd(witch_secret)
	end
end
--------------------------------------------------------------------------------
function OnChapterStoreEvent_Hollow_HO(value)					--открыть книгу
	if value == 2 then
		room:GetItem("BOOK_CLOSED"):Hide()
		room:GetItem("BOOK_OPENED"):Show()
	end
end
--------------------------------------------------------------------------------
function OnChapterStoreEvent_Close_up_Scull_h(value)			--закрыть close-up с черепом
	if value == 1 then
		room:GetItem("SCULL_H_CLOSED"):Hide()
		room:GetItem("SCULL_H_OPENED"):Show()
		
	elseif value == 2 then
		room:GetItem("M_SCULL_H"):Hide()
	end
end
--------------------------------------------------------------------------------
function OnChapterStoreEvent_Close_up_Cache(value)				--закрыть close-up с тайником
	room:GetItem("WITCH_SECRET"):Enable()
	stars:Hide("WITCH_SECRET")
end
--------------------------------------------------------------------------------
function OnChapterStoreEvent_Cheat_WitchHouseInt1(value)		--выполнить все в локации  !!!
	room:GetItem("PESTLE"):Hide()
	room:GetItem("PICK"):Hide()
	room:GetItem("EYESTONE_ON_SCULL"):Show()
	room:GetItem("M_SKULL_A"):Hide()
	
	room:GetItem("WITCH_HORN_TWITCHES"):Hide()
	
	witch_horn = room:GetItem("WITCH_HORN")
	witch_horn:Show()
	witch_horn:PlayAnimation()
	room:VideoSeekToEnd(witch_horn)
	witch_horn:Enable()
	stars:Hide("WITCH_HORN")
	
	witch_secret = room:GetItem("WITCH_SECRET")
	witch_secret:Show()
	witch_secret:PlayAnimation()
	room:VideoSeekToEnd(witch_secret)
	witch_secret:Enable()
	stars:Hide("WITCH_SECRET")
end
function OnChapterStoreEvent_Cheat_WitchHouseInt2(value)							
	cstore:SetKey("Close_up_Scull_h", 1)
	cstore:SetKey("Close_up_Scull_h", 2)
	room:GetItem("M_FURNACE"):Hide()
	room:GetItem("M_SHELF"):Hide()
	room:GetItem("SHELF_DOOR_OPEN"):Show()
	room:GetItem("FUNGUS"):Hide()
	room:GetItem("BOOK_CLOSED"):Hide()
	room:GetItem("BOOK_OPENED"):Show()
end