private void Update() { if (readInitialState) { room.Physical.ForcePipesUpdate(); int psi = 0; foreach (PipeSystem ps in pipes.PipeSystems()) { int i = 0; foreach (Valve v in ps.Valves()) { initialValveStates[psi][i] = room.Physical.GetValveState(v.Row, v.PositionInRow); i++; } psi++; } room.Physical.ForceDynamiteUpdate(); for (int i = 0; i < DynamiteGame.HoleCount; i++) { initialHoleStates[i] = room.Physical.GetHoleState(i); } readInitialState = false; } else { updateRecord(room.Physical); checkRecord(record); } }
public override void OnGameStateChanged(Game <IEtsInterface> sender, GameStateChangedEventArgs e) { // this method is registered with the pipes game's OnGameStateChanged event. if (sender != game) { return; } // stop all coroutines to prevent timing errors and stop sound playback to avoid overlapping audio StopAllCoroutines(); audio.StopAllVoice(); audio.StopAllSounds(); switch (e.NewState) { case GameState.Initialized: // if the game has been initialized, reset what we know about the subsystems from the last playthrough solvedSubsystems = new Dictionary <int, bool>(); foreach (PipeSystem ps in game.PipeSystems()) { solvedSubsystems[ps.Index] = false; } StartCoroutine(GameInitialized()); // then explain the rules break; case GameState.Running: // if the game has been started, start the coroutine that keeps track of the player's progress StartCoroutine(GameRunning(game)); break; case GameState.Completed: // if the game has been completed, handle the players' success StartCoroutine(GameCompleted()); break; case GameState.Aborted: // if the game has been aborted (due to timeout), handle the player's failure or partial success StartCoroutine(GameAborted()); break; case GameState.Uninitialized: case GameState.Error: break; default: throw new NotImplementedException("GameState not handled: " + e.NewState); } }
public override void OnGameStateChanged(Game <IEtsInterface> sender, GameStateChangedEventArgs e) { if (e.NewState == GameState.Error) { audio.StopAllSounds(); audio.StopAllVoice(); audio.PlaySound(ErrorSound); } if (sender is DynamiteGame && e.NewState == GameState.Completed) { audio.PlaySound(33); } if (sender is PipesGame) { switch (e.NewState) { case GameState.Initialized: int pipeSystemCount = 0; foreach (PipeSystem ps in pipes.PipeSystems()) { pipeSystemCount++; } solvedPipeSystems = new bool[pipeSystemCount]; drillVolume = 0f; break; case GameState.Running: drillVolume = DrillVolumeStep; audio.PlaySound(02, true, drillVolume); break; case GameState.Completed: case GameState.Aborted: audio.StopSound(11); audio.StopSound(02); break; case GameState.Uninitialized: case GameState.Error: break; default: throw new NotImplementedException("Unhandled game state: " + e.NewState); } } }
public override void OnRoomStateChanged(EscapeRoom <IEtsInterface> sender, RoomStateChangedEventArgs e) { if (e.NewState == RoomState.Uninitialized) { // start a new record Statistics = new Statistics(); PipesGame pipes = sender.GetGame <PipesGame>(); foreach (PipeSystem ps in pipes.PipeSystems()) { Statistics.valvesTurnedPerSubsystem[ps.Index] = 0; Statistics.runningFansPerSubsystem[ps.Index] = 0; } } if (e.NewState == RoomState.Completed || e.NewState == RoomState.Aborted) { // write active record to file Statistics.WriteCSV(Ets.AnalyticsPath + filename); } }
private void OnEnable() { Log.Verbose("Starting maintenance mode..."); room = Ets.Room; pipes = room.GetGame <PipesGame>(); lighting.SwitchAllLights(LightSetting.On); success = false; readInitialState = true; record = new MaintenanceRecord(); // pipes List <int> valvesPerPipeSystem = new List <int>(); List <int> fansPerPipeSystem = new List <int>(); foreach (PipeSystem ps in pipes.PipeSystems()) { valvesPerPipeSystem.Add(ps.ValveCount); fansPerPipeSystem.Add(ps.FanCount); } initialValveStates = new bool[valvesPerPipeSystem.Count][]; record.valvesPerPipeSystem_Rotating = new bool[valvesPerPipeSystem.Count][]; record.valvesPerPipeSystem_StateChanges = new bool[valvesPerPipeSystem.Count][]; for (int i = 0; i < valvesPerPipeSystem.Count; i++) { initialValveStates[i] = new bool[valvesPerPipeSystem[i]]; record.valvesPerPipeSystem_Rotating[i] = new bool[valvesPerPipeSystem[i]]; record.valvesPerPipeSystem_StateChanges[i] = new bool[valvesPerPipeSystem[i]]; } record.fansPerPipeSystem = new bool[fansPerPipeSystem.Count][]; for (int i = 0; i < fansPerPipeSystem.Count; i++) { record.fansPerPipeSystem[i] = new bool[fansPerPipeSystem[i]]; } foreach (Fan f in pipes.Fans()) { room.Physical.SetFanState(f.Row, f.PositionInRow, true); } // crane record.craneButtons = new bool[CratesGame.ButtonCount]; // dynamite initialHoleStates = new int[DynamiteGame.HoleCount]; record.holes = new bool[DynamiteGame.HoleCount]; // trigger record.triggerButtons = new bool[TriggersGame.ButtonCount]; Color[] colors = new Color[TriggersGame.LedCount]; for (int i = 0; i < colors.Length; i++) { colors[i] = Color.blue; } room.Physical.SetLEDColors(colors); Log.Verbose("Maintenance mode started. Waiting for input..."); }