last room and puzzle order
This commit is contained in:
@@ -37,11 +37,14 @@ namespace EscapeRoomEngine.Engine.Runtime
|
||||
public IOption<Room> CurrentRoom => NumberOfRooms > 0 ? Some<Room>.Of(_rooms[^1]) : None<Room>.New();
|
||||
|
||||
private readonly List<Room> _rooms = new();
|
||||
private List<PuzzleModuleDescription> _puzzles;
|
||||
private GameObject _playSpaceOrigin;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Measure.Clear();
|
||||
|
||||
_puzzles = new List<PuzzleModuleDescription>(theme.puzzleTypes);
|
||||
}
|
||||
|
||||
private void Start()
|
||||
@@ -79,7 +82,10 @@ namespace EscapeRoomEngine.Engine.Runtime
|
||||
var puzzlesAdded = 0;
|
||||
var tries = 0;
|
||||
Space space;
|
||||
Passage exit;
|
||||
Passage exit = null;
|
||||
|
||||
var puzzle = _puzzles[0];
|
||||
_puzzles.RemoveAt(0);
|
||||
|
||||
do
|
||||
{
|
||||
@@ -90,19 +96,20 @@ namespace EscapeRoomEngine.Engine.Runtime
|
||||
space = new Space(room, entrance);
|
||||
|
||||
// add exit
|
||||
var exitDoor = new DoorModule(space, theme.exitDoorTypes.RandomElement());
|
||||
if (!space.AddModuleWithRequirements(exitDoor))
|
||||
throw new EngineException("Could not satisfy requirements for exit door.");
|
||||
exit = new Passage(exitDoor);
|
||||
|
||||
// add puzzles
|
||||
var puzzleCount = Utilities.Utilities.RandomInclusive(theme.puzzleCount.x, theme.puzzleCount.y);
|
||||
for (var i = 0; i < puzzleCount; i++)
|
||||
if (_puzzles.Count > 0)
|
||||
{
|
||||
if (space.AddModuleWithRequirements(Module.CreateModuleByType(space, theme.puzzleTypes.RandomElement())))
|
||||
var exitDoor = new DoorModule(space, theme.exitDoorTypes.RandomElement());
|
||||
if (!space.AddModuleWithRequirements(exitDoor))
|
||||
{
|
||||
puzzlesAdded++;
|
||||
throw new EngineException("Could not satisfy requirements for exit door.");
|
||||
}
|
||||
exit = new Passage(exitDoor);
|
||||
}
|
||||
|
||||
// add puzzle
|
||||
if (space.AddModuleWithRequirements(Module.CreateModuleByType(space, puzzle)))
|
||||
{
|
||||
puzzlesAdded++;
|
||||
}
|
||||
} while (puzzlesAdded == 0 && tries < maxSpaceGenerationTries);
|
||||
|
||||
|
||||
@@ -12,6 +12,19 @@ namespace EscapeRoomEngine.Engine.Runtime
|
||||
|
||||
public class GameControl : MonoBehaviour
|
||||
{
|
||||
public static GameControl Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_foundGameControl == null)
|
||||
{
|
||||
_foundGameControl = FindObjectOfType<GameControl>();
|
||||
}
|
||||
return _foundGameControl;
|
||||
}
|
||||
}
|
||||
private static GameControl _foundGameControl;
|
||||
|
||||
[SerializeField] private Button startButton, stopButton, pauseButton, resumeButton, addMinuteButton, removeMinuteButton;
|
||||
[SerializeField] private Text timeText;
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ namespace EscapeRoomEngine.Engine.Runtime.Measurements
|
||||
};
|
||||
|
||||
Logger.Log($"Started measuring {puzzle}", LogType.Measuring);
|
||||
LogAllMeasurements();
|
||||
}
|
||||
|
||||
public static void Solve(PuzzleModuleDescription puzzle)
|
||||
@@ -40,15 +39,6 @@ namespace EscapeRoomEngine.Engine.Runtime.Measurements
|
||||
Logger.Log(PuzzleStorage.Instance.Session.ToString(), LogType.Measuring);
|
||||
}
|
||||
|
||||
public static void LogAllMeasurements()
|
||||
{
|
||||
Engine.DefaultEngine.theme.puzzleTypes.ForEach(puzzle =>
|
||||
{
|
||||
Logger.Log(PuzzleStorage.Instance.LoadOrNew(puzzle).ToString(), LogType.Measuring);
|
||||
});
|
||||
Logger.Log(PuzzleStorage.Instance.Session.ToString(), LogType.Measuring);
|
||||
}
|
||||
|
||||
public static void Clear() => _runningMeasurements = new Dictionary<int, PuzzleMeasurement>();
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,8 @@ namespace EscapeRoomEngine.Engine.Runtime
|
||||
{
|
||||
internal Passage entrance, exit;
|
||||
internal GameObject roomObject;
|
||||
|
||||
internal bool LastRoom => exit == null;
|
||||
|
||||
private readonly List<Space> _spaces = new();
|
||||
private readonly List<PuzzleModule> _puzzles = new();
|
||||
@@ -36,7 +38,7 @@ namespace EscapeRoomEngine.Engine.Runtime
|
||||
Logger.Log($"Skipping {this}...", LogType.PuzzleFlow);
|
||||
|
||||
_puzzles.ForEach(puzzle => puzzle.PuzzleState.Solve());
|
||||
if (_puzzles.Count == 0)
|
||||
if (_puzzles.Count == 0 && !LastRoom)
|
||||
{
|
||||
exit.fromOut.DoorState.Unlock();
|
||||
}
|
||||
@@ -57,7 +59,11 @@ namespace EscapeRoomEngine.Engine.Runtime
|
||||
{
|
||||
if (type == PuzzleEventType.Solved)
|
||||
{
|
||||
if (_puzzles.All(p => p.PuzzleState.Solved))
|
||||
if (LastRoom)
|
||||
{
|
||||
GameControl.Instance.StopGame();
|
||||
}
|
||||
else if (_puzzles.All(p => p.PuzzleState.Solved))
|
||||
{
|
||||
exit.fromOut.DoorState.Unlock();
|
||||
}
|
||||
@@ -73,7 +79,7 @@ namespace EscapeRoomEngine.Engine.Runtime
|
||||
switch (type)
|
||||
{
|
||||
// generate a new room as soon as the player completes all puzzles in this one
|
||||
case DoorEventType.Unlocked when door.Equals(exit.fromOut):
|
||||
case DoorEventType.Unlocked when !LastRoom && door.Equals(exit.fromOut):
|
||||
Engine.DefaultEngine.GenerateRoom();
|
||||
break;
|
||||
// start measurements on every puzzle as soon as the player enters the last room
|
||||
|
||||
Reference in New Issue
Block a user