--------------------------------------------------------------------------------
--  File     : Village_street_Smithy_door
--  Author(s): Prokopovich Larisa
--
--  Summary  : Скрипт управления локацией.
--
--  Copyright © 2012 Floodlight Games.  All rights reserved.
--------------------------------------------------------------------------------
function OnSerialize(system)
	commentDoor = system:Serialize(commentDoor)
end
--------------------------------------------------------------------------------
function OnFirstEntry()
	commentDoor = 0
	cstore:SetKey("Close_up_SmithyDoor", 0)
	stars:Show("LOCK", "4")
end
--------------------------------------------------------------------------------
function OnMouseClickOnBack()
	chapter:ExitCloseup()
	return true
end
--------------------------------------------------------------------------------
function OnMouseClickOnItem(item)
	local itemName = item:GetName()
	
	if itemName == "M_LATTICE" then						--решетка
		if cstore:GetKey("Tools_HO") == 2 then
			if commentDoor == 0 then
				commentDoor = 1
				comment:Add("CMT_Smithy2_Player")
			else
				comment:Add("CMT_Smithy1_Player")
			end
			return true
		else
			comment:Add("CMT_Smithy1_Player")
			return true
		end
	end
end
--------------------------------------------------------------------------------
function OnClickItemOnItem(item)					
	local itemName = item:GetName()

	if itemName == "M_LATTICE" then						--пилу на дверь
		if cursor:IsItemNameEqual("METAL_SAW") then	
			cursor:RemoveItem()
			item:Hide()
			cstore:SetKey("Close_up_SmithyDoor", 1)
			
			local saw_lock = room:GetItem("SAW_LOCK")
			saw_lock:Show()
			saw_lock:PlayAnimation()
			room:AddCtrlAnimation("SAW_LOCK", -1)
				
			room.sfx:Play ("cut_padlock")	--звук "отпиливаем замок ножовкой" 
			return true
		end
	end
end
--------------------------------------------------------------------------------
function OnUpdate (elapsedTime)
	if cstore:GetKey("Close_up_SmithyDoor") == 1 then
		if not(room:GetItem("SAW_LOCK"):IsVisible()) then
			cstore:SetKey("Close_up_SmithyDoor", 2)
			chapter:ExitCloseup()
		end
	end
end
--------------------------------------------------------------------------------
-- Окончание анимации выпиливания замка
function OnAnimationComplete_SAW_LOCK(forced)
	room:GetItem("SAW_LOCK"):Hide()
	room:GetItem("LOCK"):Hide()
	room:MarkCompleted()
	
	if forced == true then
		cstore:SetKey("Close_up_SmithyDoor", 2)
	end
end