void Start() { engineScript = FindObjectOfType <AdventureEngine>(); editorScript = FindObjectOfType <AdventureEditor>(); wordScript = FindObjectOfType <EndOfWord>(); commandScript = FindObjectOfType <EndOfCommand>(); }
void Start() { engineScript = FindObjectOfType <AdventureEngine>(); editorScript = FindObjectOfType <AdventureEditor>(); dialogScript = FindObjectOfType <OutputDialog>(); }
private int displayLines = 18; //13; void Start() { playerInput = AdventureEngine.FindObjectOfType <InputField>(); // Added for mobile input //playerInput.onValueChanged.AddListener( OnChangeValue ); }
void Start() { engineScript = FindObjectOfType <AdventureEngine>(); dialogScript = FindObjectOfType <OutputDialog>(); parserScript = FindObjectOfType <CommandParser>(); }
private IOutputSpeech Do(AdventureEngine engine, AdventureCommandType command, XElement ssml = null) { ssml = ssml ?? new XElement("speak"); ProcessResponse(engine.Do(command)); return(new SsmlOutputSpeech { Ssml = ssml.ToString(SaveOptions.DisableFormatting) }); // local functions void ProcessResponse(AdventureResponse response) { switch (response) { case AdventureResponseSay say: ssml.Add(new XElement("p", new XText(say.Text))); break; case AdventureResponseDelay delay: ssml.Add(new XElement("break", new XAttribute("time", (int)delay.Delay.TotalMilliseconds + "ms"))); break; case AdventureResponsePlay play: ssml.Add(new XElement("audio", new XAttribute("src", _adventureSoundFilesPublicUrl + play.Name))); break; case AdventureResponseNotUnderstood _: ssml.Add(new XElement("p", new XText(PROMPT_MISUNDERSTOOD))); break; case AdventureResponseBye _: ssml.Add(new XElement("p", new XText(PROMPT_GOODBYE))); break; case AdventureResponseFinished _: break; case AdventureResponseMultiple multiple: foreach (var nestedResponse in multiple.Responses) { ProcessResponse(nestedResponse); } break; default: throw new AdventureException($"Unknown response type: {response?.GetType().FullName}"); } } }
//--- Class Methods --- public static void Main(string[] args) { var app = new CommandLineApplication { Name = "AdventureBot.Cli", FullName = "AdventureBot Command Line Interface", Description = "Choose-Your-Adventure CLI" }; app.HelpOption(); var filenameArg = app.Argument("<FILENAME>", "path to adventure file"); app.OnExecute(() => { if (filenameArg.Value == null) { Console.WriteLine(app.GetHelpText()); return; } if (!File.Exists(filenameArg.Value)) { app.ShowRootCommandFullNameAndVersion(); Console.WriteLine("ERROR: could not find file"); return; } // initialize the adventure from the adventure file Adventure adventure; try { adventure = Adventure.LoadFrom(filenameArg.Value); } catch (AdventureException e) { Console.WriteLine($"ERROR: {e.Message}"); return; } catch (Exception e) { Console.WriteLine($"ERROR: unable to load file"); Console.WriteLine(e); return; } // invoke adventure var state = new AdventureState("cli", Adventure.StartPlaceId); var engine = new AdventureEngine(adventure, state); AdventureLoop(engine); }); app.Execute(args); }
void Start() { engineScript = FindObjectOfType <AdventureEngine>(); conditionScript = FindObjectOfType <Conditions>(); }
void Start() { engineScript = FindObjectOfType <AdventureEngine>(); editorScript = FindObjectOfType <AdventureEditor>(); }
private static void AdventureLoop(AdventureEngine engine) { // start the adventure loop ProcessResponse(engine.Do(AdventureCommandType.Restart)); try { while (true) { // prompt user input Console.Write("> "); var commandText = Console.ReadLine().Trim().ToLower(); if (!Enum.TryParse(commandText, true, out AdventureCommandType command)) { // TODO (2017-07-21, bjorg): need a way to invoke a 'command not understood' reaction // responses = new[] { new AdventureResponseNotUnderstood() }; continue; } // process user input ProcessResponse(engine.Do(command)); } } catch (Exception e) { Console.Error.WriteLine(e); } // local functions void ProcessResponse(AAdventureResponse response) { switch (response) { case AdventureResponseSay say: TypeLine(say.Text); break; case AdventureResponseDelay delay: System.Threading.Thread.Sleep(delay.Delay); break; case AdventureResponsePlay play: Console.WriteLine($"({play.Name})"); break; case AdventureResponseNotUnderstood _: TypeLine("Sorry, I don't know what that means."); break; case AdventureResponseBye _: TypeLine("Good bye."); System.Environment.Exit(0); break; case AdventureResponseFinished _: break; case AdventureResponseMultiple multiple: foreach (var nestedResponse in multiple.Responses) { ProcessResponse(nestedResponse); } break; default: throw new AdventureException($"Unknown response type: {response?.GetType().FullName}"); } } }
public override async Task <SkillResponse> ProcessMessageAsync(SkillRequest skill, ILambdaContext context) { try { // load adventure from S3 string source; try { using (var s3Response = await _s3Client.GetObjectAsync(_adventureFileBucket, _adventureFileKey)) { var memory = new MemoryStream(); await s3Response.ResponseStream.CopyToAsync(memory); source = Encoding.UTF8.GetString(memory.ToArray()); } } catch (AmazonS3Exception e) when(e.StatusCode == HttpStatusCode.NotFound) { throw new Exception($"unable to load file from 's3://{_adventureFileBucket}/{_adventureFileKey}'"); } // process adventure file var adventure = Adventure.Parse(source, Path.GetExtension(_adventureFileKey)); // restore player object from session var state = await RestoreAdventureState(adventure, skill.Session); var engine = new AdventureEngine(adventure, state); LogInfo($"player status: {state.Status}"); // decode skill request IOutputSpeech response = null; IOutputSpeech reprompt = null; switch (skill.Request) { // skill was activated without an intent case LaunchRequest launch: LogInfo("launch"); // kick off the adventure! if (state.Status == AdventureStatus.New) { state.Status = AdventureStatus.InProgress; response = Do(engine, AdventureCommandType.Restart, new XElement("speak", new XElement("p", new XText(PROMPT_WELCOME)))); } else { response = Do(engine, AdventureCommandType.Describe, new XElement("speak", new XElement("p", new XText(PROMPT_WELCOME_BACK)))); } reprompt = Do(engine, AdventureCommandType.Help); break; // skill was activated with an intent case IntentRequest intent: var isAdventureCommand = Enum.TryParse(intent.Intent.Name, true, out AdventureCommandType command); // check if the intent is an adventure intent if (isAdventureCommand) { LogInfo($"adventure intent ({intent.Intent.Name})"); response = Do(engine, command); reprompt = Do(engine, AdventureCommandType.Help); } else { // built-in intents switch (intent.Intent.Name) { case BuiltInIntent.Help: LogInfo($"built-in help intent ({intent.Intent.Name})"); response = Do(engine, AdventureCommandType.Help); reprompt = Do(engine, AdventureCommandType.Help); break; case BuiltInIntent.Stop: case BuiltInIntent.Cancel: LogInfo($"built-in stop/cancel intent ({intent.Intent.Name})"); response = Do(engine, AdventureCommandType.Quit); break; default: // unknown & unsupported intents LogWarn("intent not recognized"); response = new PlainTextOutputSpeech { Text = PROMPT_MISUNDERSTOOD }; reprompt = Do(engine, AdventureCommandType.Help); break; } } break; // skill session ended (no response expected) case SessionEndedRequest ended: LogInfo("session ended"); return(ResponseBuilder.Empty()); // exception reported on previous response (no response expected) case SystemExceptionRequest error: LogWarn($"skill request exception: {JsonConvert.SerializeObject(skill)}"); return(ResponseBuilder.Empty()); // unknown skill received (no response expected) default: LogWarn($"unrecognized skill request: {JsonConvert.SerializeObject(skill)}"); return(ResponseBuilder.Empty()); } // check if the player reached the end var roomCompleteCounter = 0; Dictionary <string, string> result = new Dictionary <string, string>(); if (adventure.Places[state.CurrentPlaceId].Finished) { // TODO: send completion notification with player statistics state.RoomCount++; LogInfo("Current place at room end: " + state.CurrentPlaceId); LogInfo("STATUS at room end: " + state.Status); LogInfo("TIME at room complete: " + state.StartTime); LogInfo("ROOM COUNT at end: " + state.RoomCount); //if(state.CurrentPlaceId == "end-room-good"){ result.Add("rooms", roomCompleteCounter.ToString()); await _SNSClient.PublishAsync(_adventurePlayerFinishedTopic, "Rooms completed: " + result["rooms"]); //} } // create/update player record so we can continue in a future session await StoreAdventureState(state); // respond with serialized player state if (reprompt != null) { return(ResponseBuilder.Ask( response, new Reprompt { OutputSpeech = reprompt }, new Session { Attributes = new Dictionary <string, object> { [SESSION_STATE_KEY] = state } } )); } return(ResponseBuilder.Tell(response)); } catch (Exception e) { LogError(e, "exception during skill processing"); return(ResponseBuilder.Tell(new PlainTextOutputSpeech { Text = PROMPT_OOPS })); } }