Exemplo n.º 1
0
    //helper function to turn all of the requests in a given state's GameLines directory into
    //Actions that execute the interaction as a generic text interchange.
    private IEnumerable <Action> CreateTextRequestActionList(string stateName, bool randomize = true)
    {
        string requestPath = string.Format("requests/text_requests/{0}/", stateName);
        IEnumerable <GenericTextInterchange> interchanges = GameLinesTextGetter.ParseAllTextInterchangesInDir(requestPath);

        //randomize order
        if (randomize)
        {
            var rng = new System.Random();
            interchanges = interchanges.OrderBy(i => rng.Next());
        }

        //the only way to get the desired behavior is via an enumerator.
        //Each function will get the next item from the enumerator, and there
        //will be exactly as many functions as items
        IEnumerator <GenericTextInterchange> interchangesEnumerator = interchanges.GetEnumerator();

        for (int i = 0; i < interchanges.Count(); i++)
        {
            yield return(() => {
                if (interchangesEnumerator.MoveNext())
                {
                    if (interchangesEnumerator.Current == null)
                    {
                        Debug.Log("next interchange was null");
                    }
                    ExecTextInterchange(interchangesEnumerator.Current);
                }
            });
        }
    }
 public override string GetQuestionText()
 {
     //change this to be path specific
     if (isFirst)
     {
         return(GameLinesTextGetter.FirstRequest());
     }
     else
     {
         return(GameLinesTextGetter.RandomRequestIntro() + "\nTouch all 4 corners of the room before moving on.");
     }
 }
 public override string GetResponseToPlayerText(bool responseIsPositive)
 {
     //todo: change this to be path specific
     if (isFirst)
     {
         return(GameLinesTextGetter.FirstResponse(isPositive: responseIsPositive));
     }
     else
     {
         return(GameLinesTextGetter.RandomResponse(isPositive: responseIsPositive));
     }
 }
Exemplo n.º 4
0
    private void Friendly_Reaction_CreateShortcut()
    {
        MazeDirection?shortcutDir      = maze.CreateShortcutIfPossible(playerCurrentCoords);
        bool          shortcutPossible = shortcutDir != null;

        oneWayTimedComm.SetTimeToWait(5.0f);
        SendMessageToPlayer(GameLinesTextGetter.ShortcutText(shortcutPossible), oneWayTimedComm);

        if (shortcutPossible)
        {
            maze.AddSignpostToCell(playerCurrentCoords, shortcutDir.GetValueOrDefault(), player.transform.localPosition);
        }
    }
Exemplo n.º 5
0
    //TODO: Make sure this is working
    private void Hostile_Reaction_LengthenPathToExit()
    {
        MazeDirection?longcutDir      = maze.LengthenPathToExitIfPossible(playerCurrentCoords);
        bool          longcutPossible = longcutDir != null;

        oneWayTimedComm.SetTimeToWait(5.0f);
        SendMessageToPlayer(GameLinesTextGetter.LongcutText(longcutPossible), oneWayTimedComm);

        if (longcutPossible)
        {
            maze.AddSignpostToCell(playerCurrentCoords, longcutDir.GetValueOrDefault(), player.transform.localPosition);
        }
    }
Exemplo n.º 6
0
    //This region contains code for ending the game.
    //There are currently 3 types of endings the AI can initiate.
    #region

    //start off the end of the game. ending changes depending on ai state.
    private void FlyoverMonologueEnding()
    {
        Debug.LogError("about to close doors in cell monologueending");
        maze.CloseDoorsInCell(playerCurrentCoords);
        player.PermanentlyFreezePlayer();
        SendMessageToPlayer(GameLinesTextGetter.GetEndingMonologue(AIAlignmentState.Neutral), oneWayCommChannel);

        ObjectMover objMoverTwo = ObjectMover.CreateObjectMover();

        objectMover.MoveObjectStraightLine(player.gameObject, new Vector3(0, 2.0f, 0), 1f);

        Action <GameObject> setGameOverFlag = (obj => gameOver = true);

        objMoverTwo.SpinObject(player.gameObject, 600f, 30f, setGameOverFlag);

        maze.StartRandomizingMaze(2.0f);
    }
Exemplo n.º 7
0
    //helper function to turn all of the reaction text in a given state's GameLines directory
    //into actions that send the message on the one way channel. Some code duplication from above,
    //but combining these two functions would probably make them less comprehensible
    private IEnumerable <Action> CreateTextReactionActionList(string stateName, bool randomize = true)
    {
        string responsePath            = string.Format("reactions/{0}", stateName);
        IEnumerable <string> reactions = GameLinesTextGetter.GetAllTextInDir(responsePath);

        if (randomize)
        {
            var rng = new System.Random();
            reactions = reactions.OrderBy(i => rng.Next());
        }

        IEnumerator <string> reactionEnumerator = reactions.GetEnumerator();

        for (int i = 0; i < reactions.Count(); i++)
        {
            yield return(() => {
                if (reactionEnumerator.MoveNext())
                {
                    SendMessageToPlayer(reactionEnumerator.Current, oneWayCommChannel);
                }
            });
        }
    }
Exemplo n.º 8
0
    private void Update()
    {
        //if in communcation, check for response, call handler on response if there
        if (aiCommState == AICommunicationState.InCommunication)
        {
            if (currentCommChannel != null && currentCommChannel.IsResponseReceived())
            {
                playerResponse = currentCommChannel.GetResponse();

                //end communcation and reset state
                currentCommChannel.EndCommuncation();
                currentCommChannel = null;

                aiCommState = AICommunicationState.NotInCommuncation;

                //handle whatever the response was
                HandleResponse(playerResponse);
            }
        }
        else if (!openingDone)
        {
            Debug.LogError("about to close doors in cell opening");
            maze.CloseDoorsInCell(playerCurrentCoords);
            SendMessageToPlayer(GameLinesTextGetter.OpeningMonologue(), oneWayCommChannel);
        }
        else if (playerCurrentCoords != player.MazeCellCoords &&
                 DistanceBetweenPlayerAndRoom(player.MazeCellCoords) < 0.4)
        {
            //neutral ending. ends on reaching the ladder
            if (player.MazeCellCoords == maze.exitCoords && !aiAlignmentState.ToString().StartsWith("Very"))
            {
                FlyoverMonologueEnding();
            }
            //very friendly ending. end condition on the last room
            else if (aiAlignmentState == AIAlignmentState.VeryFriendly &&
                     player.MazeCellCoords.z == (maze.size.z - 1))
            {
                maze.TurnAllLightsRed();

                Debug.LogError("about to close doors in cell friendlyending");
                maze.CloseDoorsInCell(player.MazeCellCoords);
                gameOver = true;
            }
            //the standard case. do a reaction or request
            else
            {
                //for the single hallway ending. close doors behind you.
                if (aiAlignmentState == AIAlignmentState.VeryFriendly)
                {
                    Debug.LogError("about to close doors in cell friendlyending close behind");
                    maze.CloseDoorsInCell(playerCurrentCoords);
                }

                playerCurrentCoords = player.MazeCellCoords;
                if (!firstInterchangeDone)
                {
                    Neutral_Request_AskPlayerToTouchCorners();
                    firstInterchangeDone = true;
                }
                else
                {
                    if (reactToPlayer)
                    {
                        ExecuteRandomAction(perStateReactionList[aiAlignmentState]);

                        //react to player next time only if VeryHostile, VeryFriendly and there are reactions left
                        reactToPlayer = (aiAlignmentState.ToString().StartsWith("Very")) &&
                                        perStateReactionList[aiAlignmentState].Count > 0;
                    }
                    else
                    {
                        if (!roomsRequestedIn.ContainsKey(playerCurrentCoords))
                        {
                            ExecuteRandomAction(perStateRequestActionList[aiAlignmentState]);
                            roomsRequestedIn[playerCurrentCoords] = true;
                        }

                        //on occasion, prompt a reaction from the AI on the next room
                        reactToPlayer = (UnityEngine.Random.Range(0, 1f) < 0.75f);
                    }
                }
            }
        }
    }
 public override string GetResponseToPlayerText(bool responseIsPositive)
 {
     return(GameLinesTextGetter.RandomResponse(isPositive: responseIsPositive));
 }