print("_LevelHub_Level_Controller load") myTime = 0 require "lua/entity.lua" require "lua/utilities.lua" require "lua/level_hub/ruinsstate.lua" require "lua/level_hub/placenpc.lua" require "lua/level_hub/_levelhub_utilities.lua" require "lua/level_hub/_levelhub_hintcontroller.lua" require "lua/level_hub/_levelhub_cavecontroller.lua" print ( RuinsState.get() ) cameras = object("_RuinsCameras") if global_variable_get_int("RuinsStateDEBUG", 0) == 0 then RuinsState.calculate() global_variable_set_int("RuinsStateDEBUG", 0) else print ("USING DEBUG STATE") local debugState = global_variable_get_int("RuinsStateDEBUG", 0) if debugState == -1 then RuinsState.set( 6 ) elseif debugState == -2 then RuinsState.set( 10 ) elseif debugState == -3 then RuinsState.set( 13 ) elseif debugState == -4 then RuinsState.set( 16 ) elseif debugState == -5 then RuinsState.set( 20 ) elseif debugState == -6 then RuinsState.set( 22 ) else RuinsState.set( global_variable_get_int("RuinsStateDEBUG", 0) ) end end --RuinsState.set(10) print ( RuinsState.get() ) nextLevel = nil artLoader = object("_Environment_Art_Selector") artToLoad = "" sc03Done = global_variable_get_bool("Ruins_sc03Done",false) -- 01 intro sc04Done = global_variable_get_bool("Ruins_sc04Done",false) -- 02 intro sc05Done = global_variable_get_bool("Ruins_sc05Done",false) -- 02 after far viewer sc07Done = global_variable_get_bool("Ruins_sc07Done",false) -- 03 intro state3UpgradeDone = global_variable_get_bool("Ruins_state3UpgradeDone",false) -- 03 after upgrade sc10Done = global_variable_get_bool("Ruins_sc10Done",false) -- 04 intro sc11Done = global_variable_get_bool("Ruins_sc11Done",false) -- 04 free gillman sc13Done = global_variable_get_bool("Ruins_sc13Done",false) -- 05 intro sc17Done = global_variable_get_bool("Ruins_sc17Done",false) -- 05 after oiling Far Viewer sc18Done = global_variable_get_bool("Ruins_sc18Done",false) -- 06 intro sc19Done = global_variable_get_bool("Ruins_sc19Done",false) -- 07 intro sc14Done = global_variable_get_bool("Ruins_sc14Done",false) -- 07 after oiling CSR sc15Done = global_variable_get_bool("Ruins_sc15Done",false) -- 07 after collecting clams sc50Done = global_variable_get_bool("Ruins_sc50Done",false) -- 07 after bombing cliffside door sc21Done = global_variable_get_bool("Ruins_sc21Done",false) -- 08 intro sc22Done = global_variable_get_bool("Ruins_sc22Done",false) -- 09 intro sc24Done = global_variable_get_bool("Ruins_sc24Done",false) -- 10 intro sc52Done = global_variable_get_bool("Ruins_sc52Done",false) -- 10 after apple game sc25Done = global_variable_get_bool("Ruins_sc25Done",false) -- 11 intro sc27Done = global_variable_get_bool("Ruins_sc27Done",false) -- 12 intro sc28Done = global_variable_get_bool("Ruins_sc28Done",false) -- 14 intro sc30Done = global_variable_get_bool("Ruins_sc30Done",false) -- 14 Mr. Bones intro sc47Done = global_variable_get_bool("Ruins_sc47Done",false) -- 14 Mr. Bones minigame complete sc32Done = global_variable_get_bool("Ruins_sc32Done",false) -- 15 intro sc33Done = global_variable_get_bool("Ruins_sc33Done",false) -- 16 intro sc34Done = global_variable_get_bool("Ruins_sc34Done",false) -- 17 intro sc63Done = global_variable_get_bool("Ruins_sc63Done",false) -- 17 after destroying mine tunnel opening sc36Done = global_variable_get_bool("Ruins_sc36Done",false) -- 18 intro sc37Done = global_variable_get_bool("Ruins_sc37Done",false) -- 19 intro sc40Done = global_variable_get_bool("Ruins_sc40Done",false) -- 20 intro sc41Done = global_variable_get_bool("Ruins_sc41Done",false) -- 21 intro sc43Done = global_variable_get_bool("Ruins_sc43Done",false) -- 22 intro fanDestroyed = global_variable_get_bool("Ruins_fanDestroyed",false) require "lua/level_hub/_levelhub_cutscenehandlers.lua" require "lua/level_hub/_levelhub_objectsandnpcs.lua" require "lua/level_hub/_levelhub_unlocks.lua" require "lua/level_hub/_levelhub_butterfly.lua" --Expansion data xp = {} xp.initialSetup = function () print("xp.initialSetup") for _ , i in pairs(xp) do --print(i,type(i)) if type(i) == "table" then print(i.name,i.isUnlocked,i.isSetup) if i.isUnlocked and not i.isSetup then print("settingup",i.name) xp.setup(i) else for _ , obj in pairs(i.obj) do print("hiding",i.name,obj) obj.setAlpha(0) if i.name == "ice" then print("skip collision disable for ice xp") else print("disable collision",i.name,obj) obj.collision.enable(false) end obj.trigger.send(4,"ActionButtonTrigger") end end end end xp.tick() end xp.tick = function () for _ , i in pairs(xp) do if type(i) == "table" then --print(i.name,i.locationTrigger) if trigger.received(1,i.locationTrigger) then print("xp.tick: received trigger",i.locationTrigger) if not i.isSetup then xp.unlock(i) end end if trigger.received(1,i.depart .. "Done") then print("xp.tick: received trigger",i.depart .. "Done") i.goToLevel() end end end end xp.unlock = function ( theXpTable ) print("unlock",theXpTable.name) if not theXpTable.isUnlocked then theXpTable.isUnlocked = true global_variable_set_bool("Ruins_xp_" .. theXpTable.name .. "_isUnlocked",true) theXpTable.intro.trigger.send() if theXpTable.movie then print( "playing xp movie " .. tostring(theXpTable.movie) ) playMovie(theXpTable.movie) end end if not theXpTable.isSetup then xp.setup( theXpTable ) end end xp.promptAccept = function ( name ) print("xp.promptAccept",name) local theDepartCS = xp[name]["depart"] print( theDepartCS,object(theDepartCS) ) if theDepartCS then print("playing theDepartCS") object(theDepartCS).trigger.send(1) end end xp.setup = function ( theXpTable ) for _ , obj in pairs(theXpTable.obj) do obj.setAlpha(1) obj.collision.enable(true) obj.trigger.send(3,"ActionButtonTrigger") end if theXpTable.setup then theXpTable.setup() end theXpTable.isSetup = true end xp.pirate = { name = "pirate", isUnlocked = global_variable_get_bool("Ruins_xp_pirate_isUnlocked",false) , intro = object() , ab = object() , goToLevel = function() level_switch("Level_008") end , locationTrigger = "PortalGotLocationPirate" , setup = function() if object("Docks_Barrier") then object("Docks_Barrier").delete() end object("PirateXPShip").scale(0.8,0.8,0.8) end , movie = "sl_sc51", depart = "Sc54_PirateTakeoff", obj = { object("Pirate_Expansion_Card_Table"), object("PirateXPShip"), object("Pirate_Expansion_Interact"), }, } xp.ice = { name = "ice", isUnlocked = global_variable_get_bool("Ruins_xp_ice_isUnlocked",false) , intro = object() , ab = object() , goToLevel = function() level_switch("Level_003") end , locationTrigger = "PortalGotLocationIce" , setup = function() if object("Docks_Barrier") then object("Docks_Barrier").delete() end end , movie = "sl_sc53", depart = "Sc53_IceTakeoff", obj = { object("Ice_Expansion_tower"), object("Ice_Expansion_tower_base"), object("Ice_Expansion_bridge_template"), object("Ice_Expansion_bridge_template_1_"), object("Ice_Expansion_bridge_template_2_"), object("Ice_Expansion_bridge_template_3_"), object("Ice_Expansion_bridge_template_4_"), object("Ice_Expansion_Interact"), }, } xp.dragon = { name = "dragon", isUnlocked = global_variable_get_bool("Ruins_xp_dragon_isUnlocked",false), intro = object(), ab = object(), goToLevel = function() level_switch("Level_046") end, locationTrigger = "PortalGotLocationDragon" , setup = function() if object("Fairy_Barrier") then object("Fairy_Barrier").delete() end end , movie = "sl_sc54", depart = "Sc56_DragonTakeoff", obj = { object("Dragon_Expansion_Horn"), }, } xp.undead = { name = "undead", isUnlocked = global_variable_get_bool("Ruins_xp_undead_isUnlocked",false), intro = object(), ab = object(), goToLevel = function() level_switch("Level_036") end, locationTrigger = "PortalGotLocationUndead" , setup = function() xp.undead.obj[1].scale(4,4,4) ; xp.undead.obj[2].scale(2,2,2) end , movie = "sl_sc52", depart = "Sc55_HauntedTakeoff", obj = { object("Undead_Expansion_Crypt"), object("Undead_Expansion_Island"), object("Undead_Expansion_Interact"), }, } npcPointers = {} OvergrowthSpawnerWaypoints = {} for i=26,44 do OvergrowthSpawnerWaypoints[i] = object("Overgrowth_Spawner_waypoint_" .. i ) --print ( OvergrowthSpawnerWaypoints[i] ) end playerSpawnPoints = {} for i=0,8 do playerSpawnPoints[i] = object("__Initialize_Level_waypoint_" .. i ) end playerSpawn = object("__Initialize_Level") function SetupRuins() local state = RuinsState.get() print("Setting up Environment") print(artToLoad) artLoader.trigger.send(1,artToLoad) print("Setting up Objects...",myTime) for k,v in pairs(RuinsObjects) do --print(k,v) if v ~= true then if object(k) ~= nil then --print("deleting " .. k) --print( object(k) ) object(k).delete() else --print(k .. " is not in level") end end end if state > 5 or sc13Done then spawnOilCan() object("Oil_Donkey").trigger.send() end if RuinsObjects["Beach_Campfire"] then object("Beach_Campfire").trigger.send(1,"fireOn") end if RuinsObjects["Gilman_Boat"] and state == 4 and not sc11Done then print("hiding boat") object("Gilman_Boat").position(0,0,-100) end if sc17Done or state > 5 then object("Far_Viewer").trigger.send(4,"oilCanTarget") end if fanDestroyed then object("fx_hole_dust_01").delete() object("HoleCover").delete() object("env_steam_1_").trigger.send(2) object("env_steam_1_").delete() end object("CaveFan").setAlpha(0) print("spawnClams",spawnClams) if spawnClams then for k,v in pairs( { "New_Clam" , "New_Clam_1_" , "New_Clam_2_" , "New_Clam_3_" , "New_Clam_4_" , "New_Clam_5_" } ) do print(v) object(v).trigger.send(1,"spawnIdle") end end if state >= 3 then print("set Far Viewer animActive") object("Far_Viewer").trigger.send(1,"animActive") print("set Far Viewer animSpin") object("Far_Viewer").trigger.send(1,"animSpin") elseif state == 2 and sc05Done then print("set Far Viewer animActive") object("Far_Viewer").trigger.send(1,"animActive") print("set Far Viewer animSpin") object("Far_Viewer").trigger.send(1,"animSpin") else print("set Far Viewer animInactive") object("Far_Viewer").trigger.send(1,"animInactive") end print("checking lockdoor") if object("lockdoor") then print("sending untrigger to lockdoorABT ActionButtonTrigger") object("lockdoorABT")trigger.send(2,"ActionButtonTrigger") end objectsSetup = true print("Setting up NPCs...",myTime) for k,v in pairs(RuinsNPCs) do --print (k,v) if v == true then if object(k) ~= nil then --print("spawning " .. k) --print( object(k) ) object(k).trigger.send(3) else print(k .. " is not in level") end end end NPCsSetup = true if state == 5 then moveToFlip( npcPointers.gillman , object("NPC_Gillman_waypoint_206") ) end print("setup butterflies") butterflySetup() end function spawnOilCan() if RuinsObjects["oilCan"] == true then object("oilCanObjectSpawner").trigger.send(1) end end brambleToWatch = {} brambleClones = {} farViewer = object("Far_Viewer") farViewerPosition = { farViewer.position() } function spawnAllBramble() for k,v in pairs(OvergrowthSpawnerWaypoints) do local newBramble = spawn("Edible_Overgrowth_1_", v.position() ) --print("spawned bramble at ") --print(v.position()) table.insert(brambleClones, newBramble) end --[[print("brambleToWatch:") for k,v in pairs(brambleToWatch) do print(k,v) end]] end function spawnBramble(i) local usedWaypoints = {} while #usedWaypoints < i do local n = math.random(26,44) if not tableContains(usedWaypoints,OvergrowthSpawnerWaypoints[n]) then usedWaypoints[#usedWaypoints+1] = OvergrowthSpawnerWaypoints[n] end end for k,v in pairs(usedWaypoints) do local newBramble = spawn("Edible_Overgrowth_1_", v.position() ) table.insert(brambleClones, newBramble) end end function clearBramble() for k,v in pairs(brambleClones) do if v.alive then v.delete() end end end --waterfallLow = object("fx_waterfall_260") --waterfallHigh = object("fx_waterfall_01") waterfallState = 0 function setupWaterfalls( waterfallType ) print("setupWaterfalls",waterfallType) if waterfallType == nil then return waterfallState end if waterfallType == 0 then -- no waterfalls setupWaterfallLow(2) setupWaterfallHigh(2) waterfallState = waterfallType elseif waterfallType == 1 then -- low waterfalls setupWaterfallLow(1) setupWaterfallHigh(2) waterfallState = waterfallType elseif waterfallType == 2 then -- high waterfalls setupWaterfallLow(2) setupWaterfallHigh(1) waterfallState = waterfallType else print("setupWaterfalls received invalid waterfallType",waterfallType) end end function setupWaterfallLow(triggerType) for i = 131,260 do thisObj = object("fx_waterfall_" .. i) if thisObj then thisObj.trigger.send(triggerType) end end end function setupWaterfallHigh(triggerType) for i = 1,130 do thisObj = object("fx_waterfall_" .. i) if thisObj then thisObj.trigger.send(triggerType) end end end function nextWaterfall() local nextState = waterfallState + 1 if nextState > 2 then nextState = 0 end setupWaterfalls(nextState) end print("RuinsState " .. RuinsState.get() ) specificUnlocks(RuinsState.get()) progressiveUnlocks(RuinsState.get()) SetupRuins() if RuinsObjects["MachPiece04_SocketRing"] then socketRing = object("MachPiece04_SocketRing") end if RuinsObjects["MachPiece07_SkullMask"] then skullMask = object("MachPiece07_SkullMask") end --outerRing defined earlier if RuinsObjects["MachPiece04_SocketOrb"] then socketOrb = object("MachPiece04_SocketOrb") end if RuinsObjects["MachinePiece19_OuterRingRunes"] then outerRingRunes = object("MachinePiece19_OuterRingRunes") end SetCamera("camera0") clams = { object("New_Clam"), object("New_Clam_1_"), object("New_Clam_2_"), object("New_Clam_3_"), object("New_Clam_4_"), object("New_Clam_5_"), } clamsForMinigame = { object("New_Clam_Minigame"), object("New_Clam_1__Minigame"), object("New_Clam_2__Minigame"), object("New_Clam_3__Minigame"), object("New_Clam_4__Minigame"), object("New_Clam_5__Minigame"), } function clamMiniGameSetup() print("set clams to minigamemode") for k,v in pairs(clams) do v.trigger.send(2,"spawnIdle") end for k,v in pairs(clamsForMinigame) do v.trigger.send(1,"spawnMinigame") end end while tick() do myTime = myTime + dt caveTick() --DEBUG if trigger.received(1,"nextWaterfall") then nextWaterfall() end if trigger.received(1,"ButterFlyPicked") then print("ButterFlyPicked") end --fx_hole_dust_01 if --[[myTime > 0.1 and]] not didXpInitialSetup then xp.initialSetup() didXpInitialSetup = true end if didXpInitialSetup then xp.tick() end if not playerPlaced and isThereAPlayer() then print(myTime) print("placing player") local x,y,z = playerSpawn.position() local rx,ry,rz = playerSpawn.rotation() if player_obj(0) then player_obj(0).position( x,y,z ) player_obj(0).rotation( rx,ry,rz ) end if player_obj(1) then player_obj(1).position( x+1 , y+1 , z+1 ) player_obj(1).rotation( rx , ry ,rz ) end local _ , firstValidPlayer = isThereAPlayer() fx,fy,fz = firstValidPlayer.position() print("setting player centroid object position") GetPlayerCentroidObj().position( fx,fy,fz ) playerPlaced = true end if trigger.received (1,"state3UpgradeDone") then placeNPCs() end if NPCsSetup and not NPCsPlaced and myTime > 0.1 then setupActionButtonObjectPointers() placeNPCs() end butterflyTick() -- state 2 bramble mini-game -- far viewer cutscene if RuinsState.get() == 2 and not sc05played and not sc05Done then brambleClear = true for k,v in pairs(brambleClones) do if v.alive and v.alive() then --v.setColor( ( math.random (0,10) * 0.1 ) + 2 , 1 , 1 ) --print(v.alive,position()) brambleClear = false end end if not sc05played and not sc05Done and brambleClear == true then print("All bramble cleared!") clearBramble() waitForBrambleClear = false sc05played = true object("Sc05_FarViewer").trigger.send() end end if trigger.received(1,"sc05Done") then print("sc05Done") placeNPCs() end if trigger.received(1,"sc17Done") then print("sc17Done") placeNPCs() end --state 4 gillman intro if RuinsState.get() == 4 and not sc44played and not sc44Done and not sc11Done then if not sc44triggerpos then sc44triggerpos = {object("IGC_713_GilmanIntro_waypoint_5").position()} end local thePlayer, _ , theDistance = getNearestPlayer(sc44triggerpos) if theDistance <= 6 then sc44played = true object("Sc44_WaterGillman").trigger.send(1) end end --state 4 lock puzzle if trigger.received(1,"jailOpen") then print("Level_Controller got jailOpen") if RuinsState.get() == 4 and not sc11Done then object("Sc11_WaterShipArrival").trigger.send(1) else local jb = object("Jail_Cell_Door") if jb then jb.trigger.send(1,"Open") end end jailOpen = true end if trigger.received(1,"sc11Done") then print("sc11Done") setCriticalNPC("NPC_Gillman") sc11Done = true global_variable_set_bool("Ruins_sc11Done",true) SaveGameProgress() end if trigger.received(1,"sc39Done") then print("sc39Done") sc39Done = true SetCamera("camera6") end if trigger.received(1,"sc44Done") then if object("lockMasterActor") then object("lockMasterActor").delete() end sc44Done = true global_variable_set_bool("Ruins_sc44done",true) SaveGameProgress() end --state 5 if trigger.received(1,"pickupOilCan") and RuinsState.get() == 5 and not sc67Played and not sc17Done then sc67Played = true object("Sc67_WaterOilCan").trigger.send() end --state 7 if trigger.received(1,"CliffsideDoorDestroyed") and RuinsState.get() == 7 then print("CliffsideDoorDestroyed") sc50Played = true object("Sc50_EarthMolekin").trigger.send(1) npcPointers.historian.trigger.send(4,"ActionButtonTrigger") setCriticalNPC("Cliffside_Gateway_Molekin") end --state 17 if trigger.received(1,"MineTrainTunnelDestroyed") and RuinsState.get() == 17 then print("MineTrainTunnelDestroyed") mineTrainTunnelOpen = true global_variable_set_bool("Ruins_mineTrainTunnelOpen",true) object("Sc63_FireMine").trigger.send() end if trigger.received(1,"sc63Done") then print("sc63Done") sc63Done = true global_variable_set_bool("Ruins_sc63Done",true) SaveGameProgress() end if trigger.received(1,"sc14Done") then print("sc14Done") sc14Done = true global_variable_set_bool("Ruins_sc14Done",true) SaveGameProgress() end if trigger.received(1,"sc15Done") then print("sc15Done") object("Clam_Processing_Machine").trigger.send(1,"makeBomb") sc15Done = true global_variable_set_bool("Ruins_sc15Done",true) SaveGameProgress() end if trigger.received(1,"sc50Done") then print("sc50Done") npcPointers.cliffsidemolekin.trigger.send(3,"ActionButtonTrigger") sc50Done = true global_variable_set_bool("Ruins_sc50Done",true) SaveGameProgress() end if trigger.received(1,"sc63Done") then print("sc63Done") sc63Done = true global_variable_set_bool("Ruins_sc63Done",true) SaveGameProgress() end --[[ if not thePlayer or not thePlayer.position then --print("updating player object") thePlayer = player_obj() end ]] --in _LevelHub_CutsceneHandlers.lua introHandlers() departHandlers() -- Misc. Trigger Handling if trigger.received(1,"ShowRock") then print("ruins controller ShowRock") object("FlippableRock").setAlpha(1) end --world machine animations if dt > 0 then if socketRing then socketRing.rotateSmoothRelative(0,1,0,0,0,0) end if skullMask then skullMaskNearestPlayer = getNearestPlayer( {skullMask.position()} ) if skullMaskNearestPlayer and skullMaskNearestPlayer.alive then skullMask.lookat( skullMaskNearestPlayer.position() ) local rx,ry,rz = skullMask.rotation() skullMask.rotation( 0, 0, rz+180 ) end end if RuinsState.get() >= 14 then outerRing.rotateSmoothRelative( 0 , 0 , -0.250 , 0 , 0 , 0 ) socketOrb.rotateSmoothRelative( 0 , 0 , 0.250 , 0 , 0 , 0 ) end if RuinsState.get() >= 20 then outerRingRunes.rotateSmoothRelative( 0 , 0 , -0.250 , 0 , 0 , 0 ) end end if trigger.received(1,"balloonRideStart") then print("balloonRideStart") npcPointers.balloonist.setAlpha(0) if object("HotairBalloon") then object("HotairBalloon").setAlpha(0) end if object("Hot_air_Balloon_Propeller") then object("Hot_air_Balloon_Propeller").setAlpha(0) end end if trigger.received(1,"balloonRideEnd") then print("balloonRideEnd") npcPointers.balloonist.setAlpha(1) if object("HotairBalloon") then object("HotairBalloon").setAlpha(1) end if object("Hot_air_Balloon_Propeller") then object("Hot_air_Balloon_Propeller").setAlpha(1) end end hintTick() -- this needs to be at the end of the tick so all the progression variable can be updated first end