fix end space

This commit is contained in:
2022-12-15 23:40:55 +01:00
parent 4f57b57a00
commit 80435ff696
3 changed files with 25 additions and 34 deletions

View File

@@ -63,7 +63,15 @@ namespace EscapeRoomEngine.Engine.Runtime
var room = new Room(entrance); var room = new Room(entrance);
_rooms.Add(room); _rooms.Add(room);
GenerateSpace(room, entrance); if (_plannedPuzzles.Count > 0)
{
GeneratePuzzleSpace(room, entrance);
}
else
{
GenerateEndSpace(room, entrance);
GameControl.Instance.StopGame();
}
var roomId = _rooms.Count - 1; var roomId = _rooms.Count - 1;
room.InstantiateRoom(_playSpaceOrigin.transform, roomId * roomOffset, roomId.ToString()); room.InstantiateRoom(_playSpaceOrigin.transform, roomId * roomOffset, roomId.ToString());
@@ -77,15 +85,14 @@ namespace EscapeRoomEngine.Engine.Runtime
UpdateUI(); UpdateUI();
} }
private void GenerateSpace(Room room, Passage entrance) private void GeneratePuzzleSpace(Room room, Passage entrance)
{ {
var puzzlesAdded = 0; var puzzlesAdded = 0;
var tries = 0; var tries = 0;
Space space; Space space;
Passage exit = null; Passage exit;
// choose the next puzzle // choose the next puzzle
// PlanPuzzles();
var puzzle = ChoosePuzzle(); var puzzle = ChoosePuzzle();
GameControl.Instance.CurrentPuzzle = puzzle; GameControl.Instance.CurrentPuzzle = puzzle;
@@ -98,17 +105,14 @@ namespace EscapeRoomEngine.Engine.Runtime
space = new Space(room, entrance); space = new Space(room, entrance);
// add exit // add exit
if (_plannedPuzzles.Count > 0) var exitDoor = new DoorModule(space, theme.exitDoorTypes.RandomElement());
if (!space.AddModuleWithRequirements(exitDoor))
{ {
var exitDoor = new DoorModule(space, theme.exitDoorTypes.RandomElement()); throw new EngineException("Could not satisfy requirements for exit door.");
if (!space.AddModuleWithRequirements(exitDoor))
{
throw new EngineException("Could not satisfy requirements for exit door.");
}
exit = new Passage(exitDoor);
} }
exit = new Passage(exitDoor);
// add puzzle // add puzzle
if (space.AddModuleWithRequirements(Module.CreateModuleByType(space, puzzle))) if (space.AddModuleWithRequirements(Module.CreateModuleByType(space, puzzle)))
{ {
puzzlesAdded++; puzzlesAdded++;
@@ -123,6 +127,13 @@ namespace EscapeRoomEngine.Engine.Runtime
room.AddSpace(space, exit); room.AddSpace(space, exit);
} }
private void GenerateEndSpace(Room room, Passage entrance)
{
Logger.Log($"Generating end space...", LogType.RoomGeneration);
room.AddSpace(new Space(room, entrance), null);
}
private PuzzleModuleDescription ChoosePuzzle() private PuzzleModuleDescription ChoosePuzzle()
{ {
// choose a puzzle from the plan and remove it from both the plan and later available puzzles (so it is only chosen once) // choose a puzzle from the plan and remove it from both the plan and later available puzzles (so it is only chosen once)

View File

@@ -2,7 +2,6 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using EscapeRoomEngine.Engine.Runtime.Measurements; using EscapeRoomEngine.Engine.Runtime.Measurements;
using EscapeRoomEngine.Engine.Runtime.Modules; using EscapeRoomEngine.Engine.Runtime.Modules;
using EscapeRoomEngine.Engine.Runtime.UI;
using UnityEngine; using UnityEngine;
using Logger = EscapeRoomEngine.Engine.Runtime.Utilities.Logger; using Logger = EscapeRoomEngine.Engine.Runtime.Utilities.Logger;
using LogType = EscapeRoomEngine.Engine.Runtime.Utilities.LogType; using LogType = EscapeRoomEngine.Engine.Runtime.Utilities.LogType;
@@ -62,11 +61,7 @@ namespace EscapeRoomEngine.Engine.Runtime
{ {
Measure.Solve((PuzzleModuleDescription)puzzle.description); Measure.Solve((PuzzleModuleDescription)puzzle.description);
if (LastRoom) if (puzzles.All(p => p.PuzzleState.Solved))
{
GameControl.Instance.StopGame();
}
else if (puzzles.All(p => p.PuzzleState.Solved))
{ {
exit.fromOut.DoorState.Unlock(); exit.fromOut.DoorState.Unlock();
} }

View File

@@ -547,7 +547,6 @@ GameObject:
- component: {fileID: 1568048334} - component: {fileID: 1568048334}
- component: {fileID: 1568048339} - component: {fileID: 1568048339}
- component: {fileID: 1568048336} - component: {fileID: 1568048336}
- component: {fileID: 1568048340}
m_Layer: 0 m_Layer: 0
m_Name: Engine m_Name: Engine
m_TagString: Untagged m_TagString: Untagged
@@ -599,7 +598,7 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
loggingEnabled: 1 loggingEnabled: 1
typeFilter: 0000000009000000 typeFilter: 00000000
--- !u!114 &1568048339 --- !u!114 &1568048339
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -613,17 +612,3 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
databasePath: measurements.realm databasePath: measurements.realm
--- !u!114 &1568048340
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1568048333}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 599a288d4210437698dc391e5cc84a8a, type: 3}
m_Name:
m_EditorClassIdentifier:
values: a3000000110100007c0000002801000029000000
target: 600