private AdventureNode GetSearchHedgeNode()
        {
            AdventureNode outNode = new AdventureNode();

            outNode.Name         = SEARCHHEDGE_NAME;
            outNode.OutputSpeech = new List <SpeechFragement>();
            outNode.OutputSpeech.Add(SpeechFragement.CreateTextFragment("It's a rabid possum!"));

            //  outNode.OutputSpeech.Add(SpeechFragement.CreateAudioLibraryFragment(Whetstone.Alexa.Audio.AmazonSoundLibrary.Animals.CAT_ANGRY_SCREECH_1X_01))

            outNode.OutputSpeech.Add(SpeechFragement.CreateTextFragment("It bites you! Better have that looked at. Maybe you should walk it off. To walk it off, say walk it off."));

            outNode.Reprompt = new List <SpeechFragement>();
            outNode.Reprompt.Add(SpeechFragement.CreateTextFragment("To walk it off, say walk it off."));

            outNode.Card = new CardInfo()
            {
                Title = "Rabid Possum",
                Text  = "It's a rabid possum. It bites you! Better have that looked at. Maybe you should walk it off."
            };


            outNode.NodeRoutes = new List <NodeRoute>();
            outNode.NodeRoutes.Add(new NodeRoute
            {
                IntentName   = "WalkIntent",
                NextNodeName = OUTOFWOODS_NAME
            });

            return(outNode);
        }
        private AdventureNode GetTrollTalksNode()
        {
            AdventureNode outNode = new AdventureNode();

            outNode.Name         = TROLLTALKS_NAME;
            outNode.OutputSpeech = new List <SpeechFragement>();
            outNode.OutputSpeech.Add(SpeechFragement.CreateTextFragment("The troll shares his opinion of earl grey tea, Darjeeling and green tea. He drones on and on. Maybe you should just keep walking."));

            outNode.Reprompt = new List <SpeechFragement>();

            outNode.Reprompt.Add(SpeechFragement.CreateTextFragment("To keep walking, say keep walking."));

            outNode.Card = new CardInfo()
            {
                Title = "Talkative Troll",
                Text  = "The troll shares his opinion of earl grey tea, Darjeeling and green tea. He drones on and on. Maybe you should just keep walking."
            };


            outNode.NodeRoutes = new List <NodeRoute>();

            outNode.NodeRoutes.Add(
                new NodeRoute()
            {
                IntentName   = "WalkIntent",
                NextNodeName = OUTOFWOODS_NAME
            });

            return(outNode);
        }
Example #3
0
        private AlexaResponse MergeNodeResponses(AdventureNode parentNode, AdventureNode subNode, string voiceId)
        {
            AlexaResponse resp = new AlexaResponse();

            resp.Version  = "1.0";
            resp.Response = new AlexaResponseAttributes();

            List <SpeechFragement> outFragments = new List <SpeechFragement>();

            outFragments.AddRange(parentNode.OutputSpeech);

            if (subNode != null)
            {
                outFragments.AddRange(subNode.Reprompt);
            }

            resp.Response.OutputSpeech = OutputSpeechBuilder.GetSsmlSpeech(
                AdventureNode.GetSpeechText(outFragments, _linkProcessor, voiceId));


            if ((subNode?.Reprompt?.Any()).GetValueOrDefault(false))
            {
                resp.Response.Reprompt = new RepromptAttributes();
                resp.Response.Reprompt.OutputSpeech = OutputSpeechBuilder.GetSsmlSpeech(
                    AdventureNode.GetSpeechText(subNode.Reprompt, _linkProcessor, voiceId));
            }

            return(resp);
        }
Example #4
0
    // Update is called once per frame
    void Update()
    {
        if (startGameTimer.Finished == true && gameStarted == false)
        {
            gameStarted = true;

            Vector3 encounterPosition = Camera.main.transform.position;
            encounterPosition.x += 820;
            encounterPosition.y -= 50;
            encounterPosition.z  = 0;
            encounterCount       = Random.Range(0, encounterPool1.Count);
            prevEncounterCount   = encounterCount;
            GameObject encounter = Instantiate(encounterPool1[encounterCount], encounterPosition, Quaternion.identity);
            currentEncounter = encounter.GetComponent <AdventureNode>();
            roverMoveEvent.Invoke(currentEncounter.gameObject);
        }

        if (Input.GetMouseButtonUp(0))
        {
            PlayerTappedOnScreen();
        }

        if (resourceChangeVisible && showResourceChangeTimer.Finished)
        {
            fuelReadout.transform.GetChild(0).gameObject.SetActive(false);
            durabilityReadout.transform.GetChild(0).gameObject.SetActive(false);
            scrapReadout.transform.GetChild(0).gameObject.SetActive(false);
            researchReadout.transform.GetChild(0).gameObject.SetActive(false);
            Object.Destroy(showResourceChangeTimer);
            showResourceChangeTimer          = gameObject.AddComponent <Timer>();
            showResourceChangeTimer.Duration = SHOW_RESOURCE_CHANGE_DURATION;
            resourceChangeVisible            = false;
        }
    }
Example #5
0
        private async Task <AlexaResponse> GetLaunchResponseAsync(AlexaRequest request)
        {
            Adventure adv = await _adventureRep.GetAdventureAsync();

            AdventureNode curNode = await _curNodeRep.GetCurrentNodeAsync(request, adv.Nodes);

            // If there is a current node that has choices, then let the user resume.
            bool nodeHasChoices = (curNode?.NodeRoutes?.Any()).GetValueOrDefault(false);

            AlexaResponse resp;

            if (!nodeHasChoices)
            {
                string welcomeText = "Welcome to the Adventure Sample. When you are ready to start the adventure, say begin";

                resp = new AlexaResponse
                {
                    Version = "1.0",

                    Response = new AlexaResponseAttributes
                    {
                        OutputSpeech =
                            OutputSpeechBuilder.GetPlainTextSpeech(welcomeText),
                        Card     = CardBuilder.GetSimpleCardResponse("Welcome to the Adventure", welcomeText),
                        Reprompt = new RepromptAttributes
                        {
                            OutputSpeech = OutputSpeechBuilder.GetPlainTextSpeech("Say begin when you're ready to begin")
                        }
                    }
                };
            }
            else
            {
                string resumeText = "Welcome back! You have an adventure in progress. Would you like to resume or restart?";


                resp = new AlexaResponse
                {
                    Version = "1.0",

                    Response = new AlexaResponseAttributes
                    {
                        OutputSpeech =
                            OutputSpeechBuilder.GetPlainTextSpeech(resumeText),
                        Card     = CardBuilder.GetSimpleCardResponse("Welcome Back to the Adventure", resumeText),
                        Reprompt = new RepromptAttributes
                        {
                            OutputSpeech = OutputSpeechBuilder.GetPlainTextSpeech("You can resume or restart.")
                        }
                    }
                };
            }


            return(resp);
        }
        private AdventureNode GetStopNode()
        {
            AdventureNode outNode = new AdventureNode();

            outNode.Name         = "StopNode";
            outNode.OutputSpeech = new List <SpeechFragement>();
            outNode.OutputSpeech.Add(SpeechFragement.CreateTextFragment("Thanks for playing!"));

            return(outNode);
        }
        private AdventureNode GetHelpNode()
        {
            AdventureNode outNode = new AdventureNode();

            outNode.Name         = "HelpNode";
            outNode.OutputSpeech = new List <SpeechFragement>();
            outNode.OutputSpeech.Add(SpeechFragement.CreateTextFragment("You're playing the Sample Adventure. "));

            return(outNode);
        }
        private AdventureNode GetUnknownNode()
        {
            AdventureNode outNode = new AdventureNode();

            outNode.Name         = "UnknownNode";
            outNode.OutputSpeech = new List <SpeechFragement>();
            outNode.OutputSpeech.Add(SpeechFragement.CreateTextFragment("I'm sorry. I didn't get that. "));

            return(outNode);
        }
Example #9
0
        public async Task <AdventureNode> GetCurrentNodeAsync(AlexaRequest req, IEnumerable <AdventureNode> nodes)
        {
            string curNodeName = await GetCurrentNodeNameAsync(req);

            AdventureNode curNode = null;

            if (!string.IsNullOrWhiteSpace(curNodeName))
            {
                curNode = nodes.FirstOrDefault(x => x.Name.Equals(curNodeName));
            }

            return(curNode);
        }
Example #10
0
        private AlexaResponse GenerateFallbackResponse(Adventure adventure, AdventureNode curNode)
        {
            AdventureNode fallbackNode = adventure.GetUnknownNode();

            if (fallbackNode == null)
            {
                throw new Exception($"Help node {fallbackNode.Name} not found");
            }

            AlexaResponse resp = MergeNodeResponses(fallbackNode, curNode, adventure.VoiceId);

            return(resp);
        }
        private AdventureNode GetOutOfWoodsNode()
        {
            AdventureNode outNode = new AdventureNode();

            outNode.Name         = OUTOFWOODS_NAME;
            outNode.OutputSpeech = new List <SpeechFragement>();
            outNode.OutputSpeech.Add(SpeechFragement.CreateTextFragment("The sun is shining. "));
            outNode.OutputSpeech.Add(SpeechFragement.CreateAudioLibraryFragment(Whetstone.Alexa.Audio.AmazonSoundLibrary.Animals.BIRD_FOREST_02));
            outNode.OutputSpeech.Add(SpeechFragement.CreateTextFragment("The birds are chirping and you're out of the woods. Hurray! You won!"));


            outNode.Card = new CardInfo()
            {
                Title = "Out of the Woods",
                Text  = "The sun is shining. The birds are chirping and you're out of the woods. Hurray! You won!"
            };

            return(outNode);
        }
        private AdventureNode GetTrollLaughsNode()
        {
            AdventureNode outNode = new AdventureNode();

            outNode.Name         = TROLLLAUNGHS_NAME;
            outNode.OutputSpeech = new List <SpeechFragement>();

            outNode.OutputSpeech.Add(SpeechFragement.CreateAudioLibraryFragment(Whetstone.Alexa.Audio.AmazonSoundLibrary.Impact.PUNCH_01));

            //outNode.OutputSpeech.Add(SpeechFragement.CreateAudioLibraryFragment(Whetstone.Alexa.Audio.AmazonSoundLibrary.Battle.BATTLE_MAN_GRUNTS_01));

            outNode.OutputSpeech.Add(SpeechFragement.CreateTextFragment("His skin is too tough. You scrape your knuckles and the troll just laughs at you."));

            outNode.OutputSpeech.Add(SpeechFragement.CreateTextFragment("Ha! Ha! ", "Joey"));

            outNode.OutputSpeech.Add(SpeechFragement.CreateTextFragment("Perhaps you should try giving him some tea instead. To serve tea, say serve tea."));

            outNode.Reprompt = new List <SpeechFragement>();

            outNode.Reprompt.Add(SpeechFragement.CreateTextFragment("To serve tea, say serve tea."));

            outNode.Card = new CardInfo()
            {
                Title = "The Troll Laughs",
                Text  = "His skin is too tough. You scrape your knuckles and the troll just laughs at you. Perhaps you should try giving him some tea instead.",
            };



            outNode.NodeRoutes = new List <NodeRoute>();

            outNode.NodeRoutes.Add(
                new NodeRoute()
            {
                IntentName   = "TeaIntent",
                NextNodeName = GOODTEA_NAME
            });

            return(outNode);
        }
        private AdventureNode GetGoodTeaNode()
        {
            AdventureNode outNode = new AdventureNode();

            outNode.Name         = GOODTEA_NAME;
            outNode.OutputSpeech = new List <SpeechFragement>();
            outNode.OutputSpeech.Add(SpeechFragement.CreateTextFragment("He takes a sip and seems happy with the tea. He smiles. He looks like he would enjoy a conversation. Would you like to talk to him or keep walking?"));

            outNode.Reprompt = new List <SpeechFragement>();

            outNode.Reprompt.Add(SpeechFragement.CreateTextFragment("Would you like to talk to him or keep walking?"));

            outNode.Card = new CardInfo()
            {
                Title = "Good Tea",
                Text  = "He takes a sip and seems happy with the tea. He smiles. He looks like he would enjoy a conversation.",
            };


            outNode.NodeRoutes = new List <NodeRoute>();

            outNode.NodeRoutes.Add(
                new NodeRoute()
            {
                IntentName   = "WalkIntent",
                NextNodeName = OUTOFWOODS_NAME
            });

            outNode.NodeRoutes.Add(
                new NodeRoute()
            {
                IntentName   = "TalkIntent",
                NextNodeName = TROLLTALKS_NAME
            });

            return(outNode);
        }
        public void BuildStoryNode()
        {
            Adventure adv = new Adventure();

            adv.VoiceId = Amazon.Polly.VoiceId.Joey.Value;

            adv.VoiceId = Amazon.Polly.VoiceId.Emma;

            AdventureNode startNode = new AdventureNode();

            startNode.Name         = "PathStart";
            startNode.OutputSpeech = new List <SpeechFragement>();


            string fullIntro = "You stand on a mountain side overlooking a slope that descends into a valley that disappears into forest. Miles away, it ends in a beach where land yields to sea in a crumble of sand. You are at a fork in the road. Would you like to go left or right?";

            startNode.OutputSpeech.Add(
                SpeechFragement.CreateTextFragment(fullIntro));

            startNode.Card = new CardInfo()
            {
                Title = "A Fork in the Road",
                Text  = fullIntro
            };


            adv.StartNodeName = "PathStart";


            startNode.Reprompt = new List <SpeechFragement>();

            startNode.Reprompt.Add(SpeechFragement.CreateTextFragment("Left or right?"));

            adv.Nodes = new List <AdventureNode>();

            adv.Nodes.Add(startNode);

            AdventureNode trollinPath = new AdventureNode();

            trollinPath.Name         = "TrollInPath";
            trollinPath.OutputSpeech = new List <SpeechFragement>();

            trollinPath.OutputSpeech.Add(SpeechFragement.CreateAudioFragment("trollgrowl.mp3"));
            trollinPath.OutputSpeech.Add(SpeechFragement.CreateTextFragment("There's a troll in your way."));
            trollinPath.OutputSpeech.Add(SpeechFragement.CreateAudioFragment("trollsniff.mp3"));
            trollinPath.OutputSpeech.Add(SpeechFragement.CreateTextFragment("Would you like to punch him or serve him tea?"));

            trollinPath.Card = new CardInfo()
            {
                Title      = "Rabid Possum",
                Text       = "There's a troll in your way. You can punch him or serve him tea.",
                LargeImage = "troll_lg.jpg",
                SmallImage = "troll_sm.jpg"
            };


            trollinPath.Reprompt = new List <SpeechFragement>();

            trollinPath.Reprompt.Add(SpeechFragement.CreateTextFragment("Punch him or serve him tea?"));

            trollinPath.NodeRoutes = new List <NodeRoute>();

            trollinPath.NodeRoutes.Add(
                new NodeRoute
            {
                IntentName   = "PunchIntent",
                NextNodeName = TROLLLAUNGHS_NAME
            });

            trollinPath.NodeRoutes.Add(
                new NodeRoute
            {
                IntentName   = "TeaIntent",
                NextNodeName = GOODTEA_NAME
            });



            adv.Nodes.Add(trollinPath);

            AdventureNode animalInBush = new AdventureNode();

            animalInBush.Name         = "HedgeNode";
            animalInBush.OutputSpeech = new List <SpeechFragement>();

            animalInBush.OutputSpeech.Add(SpeechFragement.CreateAudioLibraryFragment(Whetstone.Alexa.Audio.AmazonSoundLibrary.Foley.SWOOSH_FAST_1X_01));

            animalInBush.OutputSpeech.Add(SpeechFragement.CreateTextFragment("You see a small animal dart into a bush. Would you like to look in the bush or keep walking?"));

            animalInBush.Reprompt = new List <SpeechFragement>();
            animalInBush.Reprompt.Add(SpeechFragement.CreateTextFragment("Look in bush or keep walking?"));

            animalInBush.NodeRoutes = new List <NodeRoute>();
            animalInBush.NodeRoutes.Add(new NodeRoute
            {
                IntentName   = "WalkIntent",
                NextNodeName = OUTOFWOODS_NAME
            });

            animalInBush.NodeRoutes.Add(new NodeRoute
            {
                IntentName   = "SearchHedgeIntent",
                NextNodeName = SEARCHHEDGE_NAME
            });



            adv.Nodes.Add(animalInBush);

            startNode.NodeRoutes = new List <NodeRoute>();
            NodeRoute leftRoute = new NodeRoute();

            leftRoute.IntentName   = "LeftIntent";
            leftRoute.NextNodeName = trollinPath.Name;

            startNode.NodeRoutes.Add(leftRoute);


            NodeRoute rightRoute = new NodeRoute();

            rightRoute.IntentName   = "RightIntent";
            rightRoute.NextNodeName = animalInBush.Name;

            startNode.NodeRoutes.Add(rightRoute);

            AdventureNode stopNode = GetStopNode();

            adv.StopNodeName = stopNode.Name;
            adv.Nodes.Add(stopNode);

            adv.Nodes.Add(GetSearchHedgeNode());

            adv.Nodes.Add(GetOutOfWoodsNode());
            adv.Nodes.Add(GetTrollLaughsNode());
            adv.Nodes.Add(GetGoodTeaNode());
            adv.Nodes.Add(GetTrollTalksNode());


            AdventureNode helpNode = GetHelpNode();

            adv.Nodes.Add(helpNode);
            adv.HelpNodeName = helpNode.Name;

            AdventureNode unknownNode = GetUnknownNode();

            adv.Nodes.Add(unknownNode);
            adv.UnknownNodeName = unknownNode.Name;

            var serializer = new Serializer();

            string        yamlOut;
            StringBuilder builder = new StringBuilder();

            using (StringWriter writer = new StringWriter(builder))
            {
                serializer.Serialize(writer, adv);
                yamlOut = builder.ToString();
            }
        }
Example #15
0
        private async Task <AlexaResponse> GetIntentResponseAsync(AlexaRequest request)
        {
            string intentName = request?.Request?.Intent?.Name;

            if (string.IsNullOrWhiteSpace(intentName))
            {
                throw new Exception("No intent name found");
            }



            Adventure adv = await _adventureRep.GetAdventureAsync();

            AdventureNode curNode = await _curNodeRep.GetCurrentNodeAsync(request, adv.Nodes);

            string        nextNodeName = null;
            AlexaResponse resp         = null;

            if (intentName.Equals("BeginIntent", StringComparison.OrdinalIgnoreCase) || intentName.Equals(BuiltInIntents.StartOverIntent))
            {
                AdventureNode startNode = adv.GetStartNode();

                if (startNode == null)
                {
                    throw new Exception($"Start node {adv.StartNodeName} not found");
                }

                nextNodeName = startNode.Name;
                resp         = startNode.ToAlexaResponse(_linkProcessor, adv.VoiceId);
            }
            else if (intentName.Equals(BuiltInIntents.CancelIntent) || intentName.Equals(BuiltInIntents.StopIntent))
            {
                AdventureNode stopNode = adv.GetStopNode();

                if (stopNode == null)
                {
                    throw new Exception($"Start node {adv.StopNodeName} not found");
                }

                resp = stopNode.ToAlexaResponse(_linkProcessor, adv.VoiceId);
            }
            else if (intentName.Equals("ResumeIntent", StringComparison.OrdinalIgnoreCase))
            {
                resp = curNode.ToAlexaResponse(_linkProcessor, adv.VoiceId);
            }
            else if (intentName.Equals(BuiltInIntents.HelpIntent))
            {
                AdventureNode helpNode = adv.GetHelpNode();

                if (helpNode == null)
                {
                    throw new Exception($"Help node {helpNode.Name} not found");
                }

                resp = MergeNodeResponses(helpNode, curNode, adv.VoiceId);
            }
            else if (intentName.Equals(BuiltInIntents.FallbackIntent))
            {
                resp = GenerateFallbackResponse(adv, curNode);
            }
            else
            {
                if (curNode != null)
                {
                    // Process the route

                    NodeRoute selectedRoute = curNode.NodeRoutes.FirstOrDefault(x => x.IntentName.Equals(intentName, StringComparison.OrdinalIgnoreCase));

                    if (selectedRoute != null)
                    {
                        nextNodeName = selectedRoute.NextNodeName;

                        if (!string.IsNullOrWhiteSpace(nextNodeName))
                        {
                            AdventureNode nextNode = adv.GetNode(nextNodeName);

                            if (nextNode != null)
                            {
                                resp = nextNode.ToAlexaResponse(_linkProcessor, adv.VoiceId);
                            }
                            else
                            {
                                _logger.LogWarning($"Next node {nextNodeName} on node {curNode} not found for intent {intentName}");
                            }
                        }
                        else
                        {
                            _logger.LogWarning($"Node name missing for node route for {intentName} provided on node {curNode.Name}");
                        }
                    }
                    else
                    {
                        resp = GenerateFallbackResponse(adv, curNode);
                        // unsupported intent. Send reprompt.
                        _logger.LogWarning($"Node route not found for {intentName} provided on node {curNode.Name}");
                    }
                }
                else
                {
                    resp = GenerateFallbackResponse(adv, null);
                    // unsupported intent. Send reprompt.
                    _logger.LogWarning($"Node {curNode.Name} on session attribute {AdventureNode.CURNODE_ATTRIB} not found");
                }
            }

            // If the next node is known, then set it. Otherwise, keep the user on the current node.
            if (string.IsNullOrWhiteSpace(nextNodeName))
            {
                if (curNode != null)
                {
                    await _curNodeRep.SetCurrentNodeAsync(request, resp, curNode.Name);
                }
            }
            else
            {
                await _curNodeRep.SetCurrentNodeAsync(request, resp, nextNodeName);
            }

            return(resp);
        }
Example #16
0
    public void PlayerTappedOnScreen()
    {
        // Start a new encounter
        if (waitingForResolution && resolutionTapTimer.Finished)
        {
            //if the player isn't dead
            if (playerFuel <= 0 || playerDurability <= 0)
            {
                GameObject tempManager = GameObject.FindGameObjectWithTag("GameController");
                if (tempManager != null)
                {
                    tempManager.GetComponent <GameManager>().AlterResearchPoints(playerResearch);
                    tempManager.GetComponent <GameManager>().LoadMainMenu();
                }
                else
                {
                    Debug.Log("There is no GameManager in this scene. Please add one.");
                }
            }
            else
            {
                AudioManager.Instance.Play2DSound("ButtonPress");
                dialogBox.SetActive(false);
                if (previousEncounter != null)
                {
                    Object.Destroy(previousEncounter.gameObject);
                }
                previousEncounter = currentEncounter;
                //TODO RANDOMIZE THE ENCOUNTER INSTEAD OF JUST GOING THRU
                Vector3 encounterPosition = Camera.main.transform.position;
                encounterPosition.x += 850;
                encounterPosition.y -= 50;
                encounterPosition.z  = 0;
                encounterCount       = Random.Range(0, encounterPool1.Count);

                //check for dupe encounters
                if (encounterCount == prevEncounterCount && encounterCount != encounterPool1.Count - 1)
                {
                    if (encounterCount != encounterPool1.Count - 1)
                    {
                        encounterCount += 1;
                    }
                    else
                    {
                        encounterCount = 0;
                    }
                }

                GameObject encounter = Instantiate(encounterPool1[encounterCount], encounterPosition, Quaternion.identity);
                currentEncounter = encounter.GetComponent <AdventureNode>();
                roverMoveEvent.Invoke(currentEncounter.gameObject);
                prevEncounterCount = encounterCount;
                // Every event costs 1 fuel
                ChangeFuel(-1);
                UpdateReadouts();

                if (toggleSpawnMoreGround)
                {
                    Vector3 groundPosition = Camera.main.transform.position;
                    groundPosition.x += 936;
                    groundPosition.z  = 0;
                    Instantiate(groundPrefab, groundPosition, Quaternion.identity);
                }
                toggleSpawnMoreGround = !toggleSpawnMoreGround;

                Object.Destroy(resolutionTapTimer);
                resolutionTapTimer          = gameObject.AddComponent <Timer>();
                resolutionTapTimer.Duration = 1;
                waitingForResolution        = false;
            }
        }
    }