--------------------------------------------------------------------------------
--  File     : Tavern_ext_Doghouse
--  Author(s): Prokopovich Larisa
--
--  Summary  : Скрипт управления локацией.
--
--  Copyright © 2012 Floodlight Games.  All rights reserved.
--------------------------------------------------------------------------------
time_rope = 0.5
--------------------------------------------------------------------------------
function OnSerialize(system)
	ropeEffect = system:Serialize(ropeEffect)
	EndOffRopeEffect()
end
--------------------------------------------------------------------------------
function OnFirstEntry()
	ropeEffect = 0
	room:GetItem("ROPE"):Disable()
	stars:Show("M_CUT_PLACE", "4")
end
--------------------------------------------------------------------------------
function OnMouseClickOnBack()
	chapter:ExitCloseup()
	return true
end
--------------------------------------------------------------------------------
function OnMouseClickOnItem(item)
	local itemName = item:GetName()
	
	if (itemName == "ROPE") or (itemName == "M_CUT_PLACE") then		--веревка
		if room:GetItem("N_ROPE"):IsVisible() then
			comment:Add("CMT_Rope1_Player")
		else
			cstore:SetKey("Close_up_DogHouse", true)
			pick_panel:AddItems(itemName, true)
			room:MarkCompleted()
		end
		return true
	end
end
--------------------------------------------------------------------------------
function OnClickItemOnItem(item)									
	local itemName = item:GetName()

	if cursor:IsItemNameEqual("KNIFE_Q") then		--нож на крепление веревки
		if itemName == "M_CUT_PLACE" then
			inventory.alt:AddItemFromCursor()
			item:Hide()
			
			local videoKnife = room:GetItem("DOGHOUSE_KNIFE")
			videoKnife:Show()
			videoKnife:PlayAnimation()
			room:AddCtrlAnimation("DOGHOUSE_KNIFE", -1)
			room.sfx:Play("cut_rope")				--звук "перерезаем веревку, которой привязана собака"
			return true
		
		elseif itemName == "ROPE" then
			comment:Add("CMT_Rope2_Player")
			return true
		end
	end
end
--------------------------------------------------------------------------------
function OnUpdate (elapsedTime)
	local n_rope = room:GetItem("N_ROPE")
	
	if not(n_rope.effects:IsPlayingColor()) and (ropeEffect == 1) then
		n_rope:Hide()
		room:GetItem("ROPE"):Enable()
		ropeEffect = 2
	end
end
--------------------------------------------------------------------------------
function OnExit()
	EndOffRopeEffect()
end
--------------------------------------------------------------------------------
-- Окончание анимации отрезания веревки
function OnAnimationComplete_DOGHOUSE_KNIFE(forced)
	room:GetItem("DOGHOUSE_KNIFE"):Hide()
	inventory:AddInventoryItem(inventory.alt:GetItem("KNIFE_Q"))
	inventory.alt:EraseOneItemFromCell("KNIFE_Q")
	stars:Show("ROPE", "4")
	
	local n_rope = room:GetItem("N_ROPE")
		
	if forced == true then
		n_rope:Hide()
		room:GetItem("ROPE"):Enable()
	else
		local color = n_rope:GetColor()
		color:SetNormalAlpha(0)
		n_rope.effects:PlayColor(color, time_rope)
		ropeEffect = 1
	end
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function EndOffRopeEffect()
	if ropeEffect == 1 then
		room:GetItem("N_ROPE"):Hide()
		room:GetItem("ROPE"):Enable()
		ropeEffect = 2
	end
end