public bool TryStartRun(string runKey, string input, bool forceStart = false)
        {
            if (RunState != null)
            {
                Log.Warning("A run is already in progress. Cannot start new run!");
                return(false);
            }

            var runCutscenes  = _runDataLoader.RunData[runKey].Cutscenes;
            var firstCutscene = runCutscenes.First();

            if (MatchesTriggerMessage(input, firstCutscene.StartTriggerRegex) || forceStart)
            {
                var cutsceneEnumerator = runCutscenes.GetEnumerator();
                cutsceneEnumerator.MoveNext();
                RunState = new RunState()
                {
                    RunName                    = runKey,
                    IsInCutscene               = true,
                    CurrentCutsceneTimeEnd     = DateTime.Now + firstCutscene.Duration,
                    LastCheckpointLabel        = firstCutscene.Label, // assume a run starts on a cutscene
                    LastCheckpointTime         = DateTime.Now,
                    RunStartTime               = DateTime.Now,
                    ExpectedCutsceneEnumerator = cutsceneEnumerator,
                };
                var log = string.Join("\n",
                                      $"Run start detected. Now running: {RunState.RunName}",
                                      $"Trigger message: {input}"
                                      );
                Log.Info(log);
                RunStateChanged?.Invoke(RunState);
                return(true);
            }
            return(false);
        }
Exemple #2
0
        private void CompileWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            currentWorker = null;
            state         = RuntimeState.Stop;
            RunStateChanged?.Invoke(state);

            BackgroundWorker runWorker = new BackgroundWorker();

            runWorker.DoWork             += RunWorker_DoWork;
            runWorker.RunWorkerCompleted += RunWorker_RunWorkerCompleted;
            runWorker.RunWorkerAsync();
            currentWorker = runWorker;
            state         = RuntimeState.Running;
            RunStateChanged?.Invoke(state);
        }
Exemple #3
0
        public bool CompileAsync(out string reason)
        {
            reason = null;
            modSDKCompileScript = mod.ModSDKPath;
            modSDKRunScript     = mod.ModSDKPath;
            OperatingSystem os = Environment.OSVersion;

            if (os.Platform == PlatformID.Win32NT)
            {
                modSDKCompileScript += "\\make.cmd";
                modSDKRunScript     += "\\launch-game.cmd";
            }
            else if (os.Platform == PlatformID.Unix || os.Platform == PlatformID.MacOSX)
            {
                modSDKCompileScript += "\\Makefile";
                modSDKRunScript     += "\\launch-game.sh";
            }

            if (File.Exists(modSDKCompileScript) && File.Exists(modSDKRunScript))
            {
                state = RuntimeState.Compiling;
                BackgroundWorker compileWorker = new BackgroundWorker();
                compileWorker.DoWork             += CompileWorker_DoWork;
                compileWorker.RunWorkerCompleted += CompileWorker_RunWorkerCompleted;
                compileWorker.RunWorkerAsync();
                currentWorker = compileWorker;
                RunStateChanged?.Invoke(state);

                return(true);
            }
            else
            {
                reason = "Mod SDK Compile or Run script missing!";
                return(false);
            }
        }
Exemple #4
0
 private void RunWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     currentWorker = null;
     state         = RuntimeState.Stop;
     RunStateChanged?.Invoke(state);
 }
        public bool TryHitCheckpoint(string input, bool forceCheckpointHit = false)
        {
            if (RunState == null)
            {
                Log.Warning("No run is in progress. Cannot try to hit a checkpoint");
                return(false);
            }

            var expectedCutscene = RunState.ExpectedCutsceneEnumerator.Current;

            if (RunState.IsInCutscene)
            {
                if (MatchesTriggerMessage(input, expectedCutscene.EndTriggerRegex) || forceCheckpointHit)
                {
                    RunState.ExpectedCutsceneEnumerator.MoveNext();

                    RunState.IsInCutscene = false;
                    RunState.FinishedCutscenesDuration += DateTime.Now - RunState.LastCheckpointTime;
                    RunState.LastCheckpointLabel        = expectedCutscene.Label + "_end";
                    RunState.LastCheckpointTime         = DateTime.Now;
                    var log = string.Join("\n",
                                          $"Cutscene end hit. Checkpoint label: {RunState.LastCheckpointLabel}",
                                          $"Trigger message: {input}"
                                          );
                    RunStateChanged?.Invoke(RunState);
                    return(true);
                }
            }
            else
            {
                if (MatchesTriggerMessage(input, expectedCutscene.StartTriggerRegex) || forceCheckpointHit)
                {
                    RunState.IsInCutscene           = true;
                    RunState.CurrentCutsceneTimeEnd = DateTime.Now + expectedCutscene.Duration;
                    RunState.LastCheckpointLabel    = expectedCutscene.Label;
                    RunState.LastCheckpointTime     = DateTime.Now;
                    RunStateChanged?.Invoke(RunState);

                    if (expectedCutscene.IsEnding)
                    {
                        var runResult = new RunResult()
                        {
                            RunName      = RunState.RunName,
                            RunDuration  = DateTime.Now - RunState.RunStartTime,
                            RunStartTime = RunState.RunStartTime,
                        };
                        runResult.RunDurationOutOfCutscenes = runResult.RunDuration - RunState.FinishedCutscenesDuration;
                        var log = string.Join("\n",
                                              $"{runResult.RunName} run finished! Stats:",
                                              $"Total run duration: {runResult.RunDuration}",
                                              $"Total run duration outside of cutscenes: {runResult.RunDurationOutOfCutscenes}"
                                              );
                        Log.Info(log);

                        OnRunEnded?.Invoke(runResult);

                        Reset();
                    }

                    return(true);
                }
            }
            return(false);
        }
 public void Reset()
 {
     Log.Info("Resetting run.");
     RunState = null;
     RunStateChanged?.Invoke(RunState);
 }