GameScreen.inv_fun = {}
GameScreen.inv_fun["bomb_006"] = function()
    clApplication.ignore_lock_obj = "professor_hand";
end

GameScreen.textures_path = "graphics/screens/06_basement/location/"

GameScreen.hint_table = {
    {obj = {"prison_hint", -3043, -358}, fun = function() if(Inventory:IsFound("oil_can_006") and CurrentScreen.zoom) then return true end end, tool = "oil_can_006"}, 
    {obj = {"prison_hint", 256, 331}, fun = function() if GetState(CURRENT_SCREEN, "state") == "" then return true end end},
    {obj = {"prison_hint", 256, 331}, fun = function() if GetState(CURRENT_SCREEN, "state") == "prison" then return true end end},
    {obj = {"professor_hint", 1025, 259}, fun = function() if GetState(CURRENT_SCREEN, "state") == "bomb" then return true end end, tool = "bomb_006"},
    {obj = {"storeroom_door_hint", 262, 955}, fun = function() if GetState(CURRENT_SCREEN, "state") == "storeroom1" then return true end end},
    {obj = {"storeroom_door_hint", 262, 955}, fun = function() if GetState(CURRENT_SCREEN, "state") == "storeroom2" then return true end end},
    {obj = {"professor_hint", 1025, 259}, fun = function() if GetState(CURRENT_SCREEN, "state") == "finish" then return true end end},
}

function GameScreen:RestoreScene()
    self:SetItemCursor("prison_eye", "eye")
    
    if(pc_sound) then
        StopSound(pc_sound)
        pc_sound = nil;
    end
    
    if(GetState(CURRENT_SCREEN, "state") == "") then
        
    elseif(GetState(CURRENT_SCREEN, "state") == "comics") then   
        local comics_finish = function()
            DelayedExec(1.0, function()
                SetState(CURRENT_SCREEN, "state", "ho")
                self:StartHO();
            end, 113)
        end
        
        local comics = clScreenManager:add_screen("006_basement_dlg1") 	
        comics.on_finish = comics_finish;
    elseif(GetState(CURRENT_SCREEN, "state") == "ho")then
        self:StartHO();
        if(GetState(CURRENT_SCREEN, "bomb") == "activation") then
            SetState("screen_006_basement", "bomb", "activated")
            self:RemoveItem("bomb_fake")
            DelayedExec(0.1, function()
                self:OnClick("bomb")
            end, 113)
        end
    elseif(GetState(CURRENT_SCREEN, "state") == "prison")then
        self:SetItemCursor("storeroom_door_hand", "hand")
    elseif(GetState(CURRENT_SCREEN, "state") == "storeroom1")then
        self:SetItemCursor("storeroom_door_hand", "hand")
    elseif(GetState(CURRENT_SCREEN, "state") == "storeroom2")then
        ItemSetOpacity("07_door_hand", 1.0)
        ItemRemove(self.name, "lock_zoom")
        self:CreateLocationPortal("storeroom_door_hand", "007_storeroom", "hand");
    elseif(GetState(CURRENT_SCREEN, "state") == "store_room_finish")then
        ItemRemove(self.name, "lock_zoom")
        ItemSetOpacity("07_door_hand", 1.0)
        HUDScreen:ShowTips({path = self.textures_path.."text_06a", x = 323, y = 1112})
        SetState(CURRENT_SCREEN, "state", "bomb") 
        self:BombInit()
        self:CreateLocationPortal("storeroom_door_hand", "007_storeroom", "hand");
    elseif(GetState(CURRENT_SCREEN, "state") == "bomb")then
        ItemRemove(self.name, "lock_zoom")
        ItemSetOpacity("07_door_hand", 1.0)
        self:BombInit()
        self:CreateLocationPortal("storeroom_door_hand", "007_storeroom", "hand");
    elseif(GetState(CURRENT_SCREEN, "state") == "finish")then
        ItemRemove(self.name, "lock_zoom")
        ItemSetOpacity("07_door_hand", 1.0)
        self:CreateObj(OBJ_TYPE.NO_ACTIVE, "door_broken", "graphics/screens/06_basement/location/door_broken", 911, 361);
        self:CreateObj(OBJ_TYPE.TRIGGER, "portal", "graphics/trigger", 1050, 300, 250, 650);
        self:CreateLocationPortal("portal", "008_portal", "hand");
        self:CreateLocationPortal("storeroom_door_hand", "007_storeroom", "hand");
        --clApplication:LoadLocation("008_portal")
    end
    
    if(GetState(CURRENT_SCREEN, "bomb") == "activated") then
        self:RemoveItem("bomb_fake")
    end
    
    
    
    for found_item in string.gmatch(GetState(CURRENT_SCREEN, "found_obj"), "[_%a%d]+") do
		ItemRemove(self.name, found_item)
		ItemRemove(self.name, found_item.."_shadow")
    end 
end

function GameScreen:InitScreen()
    self:LoadScreen()
    
    if(pc_sound) then
        StopSound(pc_sound)
        pc_sound = nil;
    end
    
    self:CreateWallpaperPortal("note_06_part", "note_06_full", 430, 18)
    self:SetItemCursor("note_06_part", "eye")
    self:AddHiddenCrystal("crystal_06_part")
    
    self:SetItemSound("bottle_01", "sound/plastic_bottle_01.ogg");
    self:SetItemSound("bottle_02", "sound/plastic_bottle_02.ogg");
    self:SetItemSound("fridge", "sound/fridge.ogg");
    self:SetItemSound("pail_01", "sound/pail_01.ogg");
    self:SetItemSound("pail_02", "sound/pail_02.ogg");
    self:SetItemSound("pail_03", "sound/pail_03.ogg");
    self:SetItemSound("valve", "sound/valve.ogg");
    self:SetItemSound("pressure_01", "sound/pressure_01.ogg");
    self:SetItemSound("pressure_02", "sound/pressure_02.ogg");
    
    MusicPlay({"sound/music/basement.ogg", "sound/ambient/20_ambient.ogg"}, 6) 
    
    self:ZoomZoneLink("lock_zoom", "006_basement_zoom1");
    
    self:RestoreScene();
end

function GameScreen:BombInit()
    self:SetItemCursor("professor_hand", "hand")
    
    local bomb_apply = function()
        Inventory:ActiveToolApply()
        SetState(CURRENT_SCREEN, "state", "finish") 
        self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "bomb_trigger", "graphics/trigger", 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
        ItemSetOpacity("bomb_trigger", 0.0)
        ItemChangeOpacity("bomb_trigger", 1.0, 0.5, 0.8)
        
        DelayedExec(0.5, function()
            SoundPlay("sound/bomb.ogg")
            CreateZoneParticles(self, "06_basement", "gfx/expl.lua");
        end, 113)
        DelayedExec(3.0, function()
            
            clApplication:LoadLocation("008_portal")
        end, 113)
    end
    self:AddToolApplyZone("professor_hand", "bomb_006", bomb_apply, true);
end

function GameScreen:StartHO()
    local hole_found = function(this1, end_fun) 
        ItemMove("hole", 0.0, 300, 2.4)
        SoundPlay("sound/stone_trap.ogg")
        DelayedExec(0.8, function()
            end_fun();
        end, 113)
    end
    
    self.item_list = {
        {obj = {"bomb", {x = 238, y = 609}, color = true}, inv = "bomb_006"},
        {obj = {"detector", {x = 978, y = 273}}, tool_found_win = {"detector_full", 463, 328}},
        {obj = {"grenade", {x = 825, y = 873}}, tool_found_win = {"grenade_full", 463, 328}},
        {obj = {"mat", {x = 943, y = 943}}, tool_found_win = {"mat_full", 463, 328}},
        {obj = {"revolver", {x = 140, y = 567}}, tool_found_win = {"revolver_full", 463, 328}},
        {obj = {"laser", {x = 237, y = 879}}, tool_found_win = {"laser_full", 463, 328}},
        {obj = {"trap", {x = 770, y = 956}}, tool_found_win = {"trap_full", 463, 328}},
        {obj = {"snake", {x = 664, y = 163}}, tool_found_win = {"snake_full", 463, 328}},
        {obj = {"camera", {x = 156, y = 48}}, tool_found_win = {"camera_full", 463, 328}},
        {obj = {"scorpio", {x = 359, y = 226}}, tool_found_win = {"scorpio_full", 463, 328}},
        {obj = {"spider", {x = 716, y = 741}}, tool_found_win = {"spider_full", 463, 328}},
        {obj = {"hole", {x = 286, y = 1076}}, finding_fun = hole_found},
    }

    local end_fun = function()  
        clApplication.curret_win = clScreenManager:add_screen("tool_found_screen") 
        clApplication.curret_win._resource = "graphics/screens/06_basement/location/object_found_06"
        clApplication.curret_win.end_fun = function()
            Inventory:ToolFound("bomb_006", 800, 600)
            HUDScreen:ShowTips({path = self.textures_path.."text_06", x = 311, y = 1111})
            self.mini_game = nil;
            SetState(CURRENT_SCREEN, "state", "prison")
            self:SetItemCursor("storeroom_door_hand", "hand")
        end 
    end
    
    self:SetMiniGame(mgt_hidden_object)   
    self.mini_game:Init(self.item_list, end_fun, true);
end

function GameScreen:onObjectClick(item_name)
    if(item_name == "bomb_fake" and GetState(CURRENT_SCREEN, "state") == "ho") then
        clApplication:LoadLocation("mg_006_bomb")
    end
    
    if(item_name == "prison_eye" and GetState(CURRENT_SCREEN, "state") == "") then
        SetState(CURRENT_SCREEN, "state", "comics")
        local comics_finish = function()
            self.comics = nil;
            DelayedExec(1.0, function()
                SetState(CURRENT_SCREEN, "state", "ho")
                HUDScreen:ShowHintText({path = "graphics/screens/06_basement/location/Hint_06", x = 313, y = 1110})
                self:StartHO();
            end, 113)
        end
        
        self.comics = clScreenManager:add_screen("006_basement_dlg1") 	
        self.comics.on_finish = comics_finish;
    elseif(item_name == "prison_eye" and (GetState(CURRENT_SCREEN, "state") == "ho" or GetState(CURRENT_SCREEN, "state") == "comics"))then
        HUDScreen:ShowTips({path = self.textures_path.."Text_06c", x = 312, y = 1128})
    elseif(item_name == "prison_eye")then
        clApplication:LoadLocation("006_prison")
    end
    if(item_name == "professor_hand" and not Inventory:GetActiveObj()) then
        SoundPlay("sound/security_door.ogg")
    end
    
    --[[if("storeroom_door_hand" == item_name and GetState(CURRENT_SCREEN, "state") == "storeroom1")then
        SoundPlay("sound/switchboard_door.ogg")
        SetState(CURRENT_SCREEN, "state", "storeroom2")
        DelayedExec(0.1, function()
            self:CreateLocationPortal("storeroom_door_hand", "007_storeroom", "hand");
        end, 113)
        ItemChangeOpacity("07_door_hand", 1.0, 0.3)
    end--]]
end

function GameScreen:OpenDoor007()
    SoundPlay("sound/switchboard_door.ogg")
    SetState(CURRENT_SCREEN, "state", "storeroom2")
    DelayedExec(0.1, function()
        self:CreateLocationPortal("storeroom_door_hand", "007_storeroom", "hand");
    end, 113)
    ItemChangeOpacity("07_door_hand", 1.0, 0.3)
    ItemRemove(self.name, "lock_zoom")
end
------------------------------------------------------------------------------------------------------
-------------------------------------------Mouse functions--------------------------------------------
------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------
function GameScreen:LoadScreen()
	--[[---Background---]]--
	self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "06_basement", "graphics/screens/06_basement/location/06_basement", 0, 0);
	
	self:CreateObj(OBJ_TYPE.TRIGGER, "pressure_02", "graphics/screens/06_basement/location/pressure_02", 1478, 423);
	self:CreateObj(OBJ_TYPE.TRIGGER, "pressure_01", "graphics/screens/06_basement/location/pressure_01", 1478, 338);
	self:CreateObj(OBJ_TYPE.TRIGGER, "fridge", "graphics/screens/06_basement/location/fridge", 0, 501);
    self:CreateObj(OBJ_TYPE.TRIGGER, "bottle_02", "graphics/screens/06_basement/location/bottle_02", 693, 844);
    self:CreateObj(OBJ_TYPE.TRIGGER, "bottle_01", "graphics/screens/06_basement/location/bottle_01", 213, 768);    
    self:CreateObj(OBJ_TYPE.TRIGGER, "prison_eye", "graphics/screens/06_basement/location/prison_eye", 271, 345);
    self:CreateObj(OBJ_TYPE.TRIGGER, "pail_01", "graphics/screens/06_basement/location/pail_01", 924, 862);
	self:CreateObj(OBJ_TYPE.TRIGGER, "pail_02", "graphics/screens/06_basement/location/pail_02", 895, 813);
	self:CreateObj(OBJ_TYPE.TRIGGER, "pail_03", "graphics/screens/06_basement/location/pail_03", 896, 783);
    self:CreateObj(OBJ_TYPE.TRIGGER, "valve", "graphics/screens/06_basement/location/valve", 1384, 621);
   
    self:CreateObj(OBJ_TYPE.TRIGGER, "professor_hand", "graphics/screens/06_basement/location/professor_hand", 1040, 273);
    self:CreateObj(OBJ_TYPE.TRIGGER, "storeroom_door_hand", "graphics/screens/06_basement/location/storeroom_door_hand", 367, 969);
    
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "camera", "graphics/screens/06_basement/location/camera_part", 184, 74);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "hole", "graphics/screens/06_basement/location/hole_part", 289, 1090);    
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "hole_cover", "graphics/screens/06_basement/location/hole_cover", 282, 1145);
	self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "trap_shadow", "graphics/screens/06_basement/location/trap_shadow", 651, 908);
	self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "trap", "graphics/screens/06_basement/location/trap_part", 882, 977);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "detector_shadow", "graphics/screens/06_basement/location/detector_shadow", 990, 262);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "detector", "graphics/screens/06_basement/location/detector_part", 990, 284);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "scorpio", "graphics/screens/06_basement/location/scorpio_part", 354, 227);
    	self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "laser_shadow", "graphics/screens/06_basement/location/laser_shadow", 279, 912);
	self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "laser", "graphics/screens/06_basement/location/laser_part", 366, 912);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "revolver_shadow", "graphics/screens/06_basement/location/revolver_shadow", 264, 888);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "revolver", "graphics/screens/06_basement/location/revolver_part", 368, 574);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "spider", "graphics/screens/06_basement/location/spider_part", 720, 749);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "snake_shadow", "graphics/screens/06_basement/location/snake_shadow", 643, 90);    
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "snake", "graphics/screens/06_basement/location/snake_part", 677, 174);
	self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "mat", "graphics/screens/06_basement/location/mat_part", 945, 934);
	self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "grenade", "graphics/screens/06_basement/location/grenade_part", 982, 902);
	    
	self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "crystal_06_part", "graphics/screens/06_basement/location/crystal_06_part", 761, 485);
	self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "bomb", "graphics/screens/06_basement/location/bomb_part", 278, 649);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "bomb_fake", "graphics/screens/06_basement/location/bomb_part", 278, 649);
    
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "note_06_part", "graphics/screens/06_basement/location/note_06_part", 832, 848);
    
    self:CreateObj(OBJ_TYPE.NO_ACTIVE, "07_door_hand", "graphics/screens/06_basement/location/07_door_hand", 278, 774);
    
    self:CreateObj(OBJ_TYPE.TRIGGER, "lock_zoom", "graphics/screens/06_basement/location/storeroom_door_hand", 367, 969);
    
    ItemSetOpacity("07_door_hand", 0.0)
    
    clScreenManager:add_screen("hud") 
end