class 'l_07_Cantellos_shop' (PlayField)

function l_07_Cantellos_shop:__init(game_scene, name, path)
	PlayField.__init(self, game_scene, name, path)
	self.is_outdoor_scene = false

	self:linkScene('area_link_08',   'CursorUp',    '08_Lauras_room')
	self:linkScene('area_link_06',   'CursorDown',    '06_Town')

	-- Hide Layer textures 
	self:entityHide('opened_door_shadow','opened_door','area_link_08','area_BBT_Cantllo_Blocked','area_bbt_door','area_zoom_Lauras_room_door') 
	
	self:entityHide('area_apply_04_letter_to_Laura')
	self:entityHide('area_click_Cantello2')	
	-- zooms 
	self.zoom_table = self:createZoomZone('Table')
	self.zoom_Old_rock = self:createZoomZone('Old_rock')
	self.zoom_lauras_room_door = self:createZoomZone('Lauras_room_door')
	self.zoom_comics_father_1 = self:createZoomZone('Comics_Father_1', ZOOM_TYPE_VIDEO_CALL)

	self:registerBBT('area_BBT_Cantllo_Blocked', 'BBT_07_CANTELLO_BLOCKED')
	self:registerBBT('area_bbt_door', 'BBT_07_DOOR')

	do  -- find clock -----------------------------------------------------   
	    if not self:isObjectClicked('area_click_clock_5') then
	    	self:getEntityNamed('area_click_clock_5'):hide()
	        self.timer:add( function() 
                            	self:fadeGhostClock('clock_5', 'cover_clock_5', 'area_click_clock_5')
                            end, 35)   
	    end
	
        function on_click(event)
            self:entityHide('clock_5')
            self:entityHide('area_click_clock_5')
            if not event.save then  
                self:entityFadeHide('cover_clock_5') 
            else 
                self:entityHide('cover_clock_5') 
            end
	    end
	    self:registerFindClockObject('area_click_clock_5', 'fly_clock_5', 'clock_5', on_click)
	end

	 -- GrandFather -------------------------------------------------------------
    do
        -- if IsToolFound('06_skeleton_key') and not HasGameState('07_GRANDFATHER_VISION_SHOWN') then
        --     SetGameState('07_GRANDFATHER_VISION_SHOWN', 'true')

        --     self.grandFather = createVideo({video = 'GrandFather_vision', sound = 'GrandFather_vision', scale = 1.51, order = 500, x = 512, y = 384, isLooped = false, isAlpha = false})
        --     self:startCutScene(self.grandFather , nil, nil)

        --     local subtitles_1 = nil
        --     subtitles_1 = Subtitles(current_scene:getPanel())
        --     subtitles_1:pushReplic('SUB_07_GRANDFATHER_VISION_1', 0, 12, true)
            
        --     subtitles_1:play()

        --     self.grandFather.onFinish:add( function()
        --     									subtitles_1:destroy() 
        --     							   end)
        -- end
    end
    ----------------------------------------------------------------------------

	-- show areas -----------------------------------------------------
	if ( IsToolFound('06_paper_plane_letter')) then

			self:entityHide('area_BBT_Cantllo_Blocked')
			self:entityShow('area_bbt_door')

	    	if not isMiniGameCompleted('07_Jimmy') then 
			--	self:entityShow('area_zoom_Lauras_room_door')
			end

			if (not self.zoom_Old_rock:isDisabled()) then
				self:entityShow('area_zoom_Old_rock')
			end
			if (not self.zoom_table:isDisabled()) then
				self:entityShow('area_zoom_Table')
			end

			if (not IsToolApplied('10_bag_of_gold')) then
				self:entityShow('area_apply_10_bag_of_gold')
			end
			if (not IsToolApplied('06_paper_plane_letter')) then
				self:entityShow('compositionman')
			end
	else
		self:entityHide('area_zoom_Table','area_zoom_Old_rock','area_zoom_Lauras_room_door','area_apply_10_bag_of_gold')
	end	
		-- find photo ---------------------------------------------------------------
    do
        local function on_take_photo(event)    
           -- self:entityShow('')     
        end
        self:registerFindFlyPhoto('area_find_photo', '07_Cantello', on_take_photo)
    end
    -- find photo ---------------------------------------------------------------
   
    do  -- 
   		if IsToolFound ('06_skeleton_key') then
			self:entityHide('area_bbt_door')
			self:entityShow('area_zoom_Lauras_room_door')
		end
	end

	if IsToolFound('10_bag_of_gold') and not HasGameState('07_Cantello2_comics') then
		self:entityShow('compositionman')
		self:entityShow('area_click_Cantello2')	
		SetGameState('07_Cantello2_comics','true')	
	end	

	if isMiniGameCompleted('07_Jimmy') then 
		self:entityShow('opened_door','opened_door_shadow','area_link_08')
		self.zoom_lauras_room_door:closeAndDisable()
	end

	--self:entityShow('area_zoom_Lauras_room_door')
	
	if isSceneVisited('08_Lauras_room') then
		self:entityHide('opened_door','opened_door_shadow','area_link_08')
	end

	-- -- click Cantello--------------------------------------------------------------
	do
		local function click_on_click_Cantello1(event)
			self:entityHide('area_click_Cantello1','compositionman')	
			self:createComicsCantello1()
		end
		self:registerActiveObject('area_click_Cantello1', click_on_click_Cantello1, false, 'CursorGlass')
	end

		-- -- click Cantello2--------------------------------------------------------------
	do
		local function click_on_click_Cantello2(event)
			self:entityHide('compositionman')
			self:entityHide('area_click_Cantello2')	
			self:createComicsCantello2()
		end
		self:registerActiveObject('area_click_Cantello2', click_on_click_Cantello2, false, 'CursorGlass')
	end

	-- -- click Laura--------------------------------------------------------------
	do
		local function click_on_click_Laura1(event)
			self:entityHide('area_click_Laura1','compositiongirl')	

			self:createComicsLaura1()
		end
		self:registerActiveObject('area_click_Laura1', click_on_click_Laura1, false, 'CursorGlass')
	end
	
	local function on_apply_10_bag_of_gold(event)	
	    
	    self:entityHide('area_apply_10_bag_of_gold')	

	    self.timer:add( function()
					    	    completeGameTask('11')
						    end, 0)
	    
	    if not event.save then
	     	self:getEntityNamed('golden_eagle'):ChangeOpacity(1, 0, 0.5)
	    else
	        self:entityHide('golden_eagle')
	    end
	    
	    self:findTool('07_golden_eagle')
	end
	self:registerToolApplyInfo('10_bag_of_gold', 'area_apply_10_bag_of_gold', on_apply_10_bag_of_gold, 'BBT_07_NEED_BAG_OF_GOLD')

	local function on_apply_04_letter_to_Laura(event)	
	    self:entityHide('compositiongirl', 'area_apply_04_letter_to_Laura')
	    
	    if not event.save then
	     	
 		
	    else
	       
	    end

	    self:createComicsLaura2()	    
	end
	self:registerToolApplyInfo('04_letter_to_laura', 'area_apply_04_letter_to_Laura', on_apply_04_letter_to_Laura, 'BBT_07_NEED_LETTER_TO_LAURA')

end

--comics Laura----------------------------------------------------------------------
function l_07_Cantellos_shop:createComicsLaura1()	
    local comics_name = 'Laura1'
    
    local comics_finish = function(save)

    	 if not HasGameState('07_GRANDFATHER_VISION_SHOWN') then
            SetGameState('07_GRANDFATHER_VISION_SHOWN', 'true')

            self.grandFather = createVideo({video = 'GrandFather_vision', sound = 'GrandFather_vision', scale = 1.51, order = 500, x = 512, y = 384, isLooped = false, isAlpha = false})
            self:startCutScene(self.grandFather , nil, nil)

            local subtitles_1 = nil
            subtitles_1 = Subtitles(current_scene:getPanel())
            subtitles_1:pushReplic('SUB_07_GRANDFATHER_VISION_1', 0, 12, true)
            
            subtitles_1:play()

            self.grandFather.onFinish:add( function()
            									subtitles_1:destroy() 
            							   end)
        end
    			
		if save then
       
    	    self:entityShow('compositiongirl', 'area_apply_04_letter_to_Laura')
        else
		
        	self:entityShow('compositiongirl', 'area_apply_04_letter_to_Laura')
         end
    end
    
    if self:isComicsShown(comics_name, self.name) then
        comics_finish(true)
    else	
		local function on_frame_change(comics, frame_index)
			if frame_index == 1 or frame_index == 2 then
				self.timer:add( function()	
					self:playSound('07_skull_show')

					local effector = CreateAnimationEffector()
					effector:attachTo(comics:getEntityNamed('laura_dead'))
					effector:setLifeTime(0, 2)
					effector:setKey(_TRACK_O, 0, 0)
					effector:setKey(_TRACK_O, 0.15791829427083, 0.16807965000863)
					effector:setKey(_TRACK_O, 0.39473470052083, 0.03412043826209)
					effector:setKey(_TRACK_O, 0.63460286458333, 0.33438315359313)
					effector:setKey(_TRACK_O, 0.75, 0.33438315359313)
					effector:setKey(_TRACK_O, 0.94734700520833, 0.09583497528728)
					effector:setKey(_TRACK_O, 1.18424479166667, 0.23930873494992)
					effector:setKey(_TRACK_O, 1.5, 0)

					effector:play()

				end, ComicsFrame.DEFAULT_APPEARING_TIME)    
			end
		end
		local c = self:createComics(comics_name, nil, on_frame_change)   

		c.on_finish = function()
			comics_finish(false)
		end    

		c:start()
    end
end

--comics Laura 2----------------------------------------------------------------------
function l_07_Cantellos_shop:createComicsLaura2()	
    local comics_name = 'Laura2'
    
    local comics_finish = function(save)
    	
       
      	self:entityHide('compositionman')
      	self:entityShow('compositiongirl')
      	self.mouseBlocker:push()
      		 self.timer:add(function()
      		 	self.mouseBlocker:pop()
	   			self:createComicsCantello3()
 			 end, 0.1)

		if not save then
        else
		end
    end
    
    if self:isComicsShown(comics_name, self.name) then

        comics_finish(true)
    else	



		local c = self:createComics(comics_name)

		c.on_finish = function()
			comics_finish(false)
		end       

		c:start()
    end
end

--comics Cantello after Laura----------------------------------------------------------------------
function l_07_Cantellos_shop:createComicsCantello3()	
    local comics_name = 'Cantello3'
    
    	self:entityShow('area_BBT_Cantllo_Blocked')
	    if  HasGameState('Laura_goes_on_08', 'true') then
	        	self:entityHide('compositiongirl')
	    -- else
     --    	self:getEntityNamed('compositiongirl'):ChangeOpacity(1, 0, 0.5, 1)
     --    	self:entityFadeShow('opened_door','opened_door_shadow')
     --    	self:getEntityNamed('opened_door','opened_door_shadow'):ChangeOpacity(1, 0, 0.5, 2.5)
	    end
	
    local comics_finish = function(save)

    	if not save then
    		local node = path_manager:findNode(NodeType.SCENE, '06_Town')
	        if node then
	            node:setState(NodeState.ENABLED)
	        end  
    	end    	

		if (not IsToolFound ('06_paper_plane_letter')) then 
			self:entityShow('compositionman')
		else	
			self:entityHide('compositionman')
			self:entityHide('area_BBT_Cantllo_Blocked')
		end
		SetGameState('Laura_goes_on_08', 'true')
    end
    
    if self:isComicsShown(comics_name, self.name) then
        comics_finish(true)
    else	
    	local function on_frame_change(comics, frame_index)
    		if (frame_index == 2) or (frame_index == -1) then
	    		self:getEntityNamed('compositiongirl'):ChangeOpacity(1, 0, 0.5, 1)
	        	self:entityFadeShow('opened_door','opened_door_shadow')
	        	self:getEntityNamed('opened_door','opened_door_shadow'):ChangeOpacity(1, 0, 0.5, 2.5)
	        end
    	end

		local c = self:createComics(comics_name, nil, on_frame_change)

		c.on_finish = function()
			comics_finish(false)
		end       

		c:start()


    end
end

--comics Cantello ----------------------------------------------------------------------
function l_07_Cantellos_shop:createComicsCantello1()	
    local comics_name = 'Cantello1'
    
    local comics_finish = function(save)
		self:entityShow('area_click_Laura1')	
		self:entityShow('compositionman')
		addGameTask('11')
    			
		if save then
        		
        else
        	
         end
    end
    
    if self:isComicsShown(comics_name, self.name) then
        comics_finish(true)
    else
    	local function on_frame_change(comics, frame_index)
			if frame_index == 1 or frame_index == 2 then
				self.timer:add( function()	
					self:playSound('07_skull_show')

					local effector = CreateAnimationEffector()
					effector:attachTo(comics:getEntityNamed('cantello_dead'))
					effector:setLifeTime(0, 2)
					effector:setKey(_TRACK_O, 0, 0)
					effector:setKey(_TRACK_O, 0.15791829427083, 0.16807965000863)
					effector:setKey(_TRACK_O, 0.39473470052083, 0.03412043826209)
					effector:setKey(_TRACK_O, 0.63460286458333, 0.33438315359313)
					effector:setKey(_TRACK_O, 0.75, 0.33438315359313)
					effector:setKey(_TRACK_O, 0.94734700520833, 0.09583497528728)
					effector:setKey(_TRACK_O, 1.18424479166667, 0.23930873494992)
					effector:setKey(_TRACK_O, 1.5, 0)

					effector:play()

				end, ComicsFrame.DEFAULT_APPEARING_TIME)    
			end
		end
		local c = self:createComics(comics_name, nil, on_frame_change)

		c.on_finish = function()
			comics_finish(false)
		end   

		c:start()
    end
end

--comics Cantello 2  after find 10 bag----------------------------------------------------------------------
function l_07_Cantellos_shop:createComicsCantello2()	
    local comics_name = 'Cantello2'


    local comics_finish = function(save)
		    			
		if save then
        		
        else
        	
         end
    end
    
    if self:isComicsShown(comics_name, self.name) then
        comics_finish(true)
    else	
		local c = self:createComics(comics_name)

		c.on_finish = function()
			comics_finish(false)
		end       

		c:start()


    end
end

function l_07_Cantellos_shop:fadeGhostClockLoc(spriteClock, coverClock, areaClick)

            local areaClickEntity   = self:getEntityNamed(areaClick)
            local spriteClockEntity = self:getEntityNamed(spriteClock)
            local coverClockEntity  = self:getEntityNamed(coverClock)

            if not self:isObjectClicked(areaClick) then
                
                local rendTime = math.random(8,12)
                
                
                    spriteClockEntity:ChangeOpacity(0, 1, 0.8)
                    coverClockEntity:ChangeOpacity(1, 0, 0.8)
                    playCommonSound('MorphingClock')
                    self.timer:add( function() 
                                coverClockEntity:ChangeOpacity(0, 1, 0.8)  
                                spriteClockEntity:ChangeOpacity(1, 0, 0.8)
                          end, rendTime/4) 
                
                    self.timer:add( 
                        function() 
                            self:fadeGhostClockLoc(spriteClock, coverClock, areaClick)
                        end, rendTime)   
            end        
end    
--------------------------------------------------------------------------------
--                      GENERATED CONTENT. DO NOT EDIT.                       --
--------------------------------------------------------------------------------

function l_07_Cantellos_shop:CreateLoaderTable()
	local objects =
	{
		{ name = 'Bg',  entityType = 'SpriteEntity',  x = 512,  y = 384,  order = 0,  editingLocked = false,  treeItemIsExpanded = true,  texturePath = 'Data/Textures/Scenes/07_Cantellos_shop/Layers/Bg.jpg',  width = 1366,  height = 768,  },
		{ name = 'old_stone',  entityType = 'SpriteEntity',  x = 879,  y = 411,  order = 2,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/07_Cantellos_shop/Layers/old_stone.png',  width = 131,  height = 152,  },
		{ name = 'golden_eagle',  entityType = 'SpriteEntity',  x = 511,  y = 413,  order = 2,  editingLocked = false,  treeItemIsExpanded = true,  texturePath = 'Data/Textures/Scenes/07_Cantellos_shop/Layers/golden_eagle.png',  width = 106,  height = 122,  },
		{ name = 'lighter',  entityType = 'SpriteEntity',  x = 257.5,  y = 437,  order = 2,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/07_Cantellos_shop/Layers/lighter.png',  width = 49,  height = 38,  },
		{ name = '07_Cantellos_shop_Anim_Bg_Laura_figure',  entityType = 'CompositionContainer',  x = -171,  y = 0,  order = 1,  editingLocked = false,  treeItemIsExpanded = true,  path = 'Data/Scripts/Scenes/07_Cantellos_shop/Anim/07_Cantellos_shop_Anim_Bg_Laura_figure.lua',  },
		{ name = 'compositiongirl',  entityType = 'CompositionSequence',  parentName = '07_Cantellos_shop_Anim_Bg_Laura_figure',  x = 0,  y = 0,  order = 19,  editingLocked = false,  treeItemIsExpanded = false,  isCyclic = true,  speed = 1,  },
		{ name = 'opened_door_shadow',  entityType = 'SpriteEntity',  x = 705.5,  y = 110.5,  order = 2,  editingLocked = false,  treeItemIsExpanded = true,  texturePath = 'Data/Textures/Scenes/07_Cantellos_shop/Layers/opened_door_shadow.png',  width = 107,  height = 173,  },
		{ name = 'opened_door',  entityType = 'SpriteEntity',  x = 743,  y = 114,  order = 2,  editingLocked = false,  treeItemIsExpanded = true,  texturePath = 'Data/Textures/Scenes/07_Cantellos_shop/Layers/opened_door.png',  width = 68,  height = 156,  },
		{ name = 'area_apply_04_letter_to_Laura',  entityType = 'SpriteEntity',  x = 280,  y = 384,  order = 20,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = false,  width = 512,  height = 768,  },
		{ name = 'area_apply_10_bag_of_gold',  entityType = 'SpriteEntity',  x = 518,  y = 413,  order = 50,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = false,  width = 150,  height = 150,  },
		{ name = 'area_zoom_Lauras_room_door',  entityType = 'SpriteEntity',  x = 736,  y = 125,  order = 60,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 158,  height = 194,  },
		{ name = 'area_zoom_Table',  entityType = 'SpriteEntity',  x = 255,  y = 396,  order = 60,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 150,  height = 150,  },
		{ name = 'area_zoom_Old_rock',  entityType = 'SpriteEntity',  x = 862,  y = 410,  order = 60,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 150,  height = 150,  },
		{ name = 'area_click_Laura1',  entityType = 'SpriteEntity',  x = 512,  y = 334,  order = 89,  isVisible = false,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = false,  width = 1366,  height = 668,  },
		{ name = 'area_click_Cantello2',  entityType = 'SpriteEntity',  x = 512,  y = 334,  order = 89,  isVisible = false,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = false,  width = 1366,  height = 668,  },
		{ name = 'area_click_Cantello1',  entityType = 'SpriteEntity',  x = 512,  y = 334,  order = 90,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 1366,  height = 668,  },
		{ name = 'area_link_08',  entityType = 'SpriteEntity',  x = 711,  y = 124,  order = 100,  isVisible = false,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 130,  height = 200,  },
		{ name = 'area_link_06',  entityType = 'SpriteEntity',  x = 512,  y = 718,  order = 100,  scaleX = 12,  scaleY = 2,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 100,  height = 100,  },
		{ name = 'area_zoom_Comics_Father_1',  entityType = 'SpriteEntity',  x = 951,  y = 545,  order = 0,  isVisible = false,  isActive = false,  editingLocked = false,  treeItemIsExpanded = false,  width = 100,  height = 100,  },
		{ name = '07_Cantellos_shop_Anim_Bg',  entityType = 'CompositionContainer',  x = -171,  y = 0,  order = 1,  editingLocked = false,  treeItemIsExpanded = true,  path = 'Data/Scripts/Scenes/07_Cantellos_shop/Anim/07_Cantellos_shop_Anim_Bg.lua',  },
		{ name = 'composition21_ofis_manager',  entityType = 'CompositionSequence',  parentName = '07_Cantellos_shop_Anim_Bg',  x = 0,  y = 0,  order = 0,  isActive = false,  editingLocked = false,  treeItemIsExpanded = false,  speed = 1,  },
		{ name = 'compositionfon',  entityType = 'CompositionSequence',  parentName = '07_Cantellos_shop_Anim_Bg',  x = 0,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  speed = 1,  },
		{ name = '07_Cantellos_shop_Anim_Bg_Cantello_figure',  entityType = 'CompositionContainer',  x = -171,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = true,  path = 'Data/Scripts/Scenes/07_Cantellos_shop/Anim/07_Cantellos_shop_Anim_Bg_Cantello_figure.lua',  },
		{ name = 'compositionman',  entityType = 'CompositionSequence',  parentName = '07_Cantellos_shop_Anim_Bg_Cantello_figure',  x = 0,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  isCyclic = true,  speed = 1,  },
		{ name = 'area_click_clock_5',  entityType = 'SpriteEntity',  x = 255,  y = 555,  order = 10,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = false,  width = 100,  height = 120,  },
		{ name = 'area_find_photo',  entityType = 'SpriteEntity',  x = 856,  y = 159,  order = 80,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 100,  height = 100,  },
		{ name = 'clock_5',  entityType = 'SpriteEntity',  x = 256,  y = 544,  order = 4,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/07_Cantellos_shop/Layers/clock_07_loc.png',  width = 74,  height = 130,  },
		{ name = 'cover_clock_5',  entityType = 'SpriteEntity',  x = 253,  y = 540,  order = 5,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/07_Cantellos_shop/Layers/cover_clock_07_loc.png',  width = 74,  height = 132,  },
		{ name = 'fly_clock_5',  entityType = 'SpriteEntity',  x = 249.538,  y = 544.821,  order = 10,  isVisible = false,  isRespondable = false,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/07_Cantellos_shop/Layers/fly_clock_5.png',  width = 250,  height = 250,  },
		{ name = 'area_BBT_Cantllo_Blocked',  entityType = 'SpriteEntity',  x = 512,  y = 334,  order = 90,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 1366,  height = 668,  },
		{ name = 'area_bbt_door',  entityType = 'SpriteEntity',  x = 729,  y = 124,  order = 110,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  hotSpot = {x = 65, y = 100},  width = 130,  height = 200,  },
	}
	return objects
end
