Beispiel #1
0
    private void Start()
    {
        //init communcation channels
        textCommChannel     = CommunicationChannelFactory.Make2WayTextChannel() as TextCommunicationChannel;
        oneWayCommChannel   = CommunicationChannelFactory.MakeOneWayTextChannel() as OneWayTextCommunication;
        roomExitCommChannel = CommunicationChannelFactory.MakeRoomExitPathChannel() as RoomExitPathCommChannel;
        oneWayTimedComm     = CommunicationChannelFactory.MakeOneWayTimedChannel() as OneWayTimedCommChannel;
        stillnessTimedComm  = CommunicationChannelFactory.MakeTimedStillnessChannel() as StillnessTimedCommChannel;

        //init object mover
        objectMover = ObjectMover.CreateObjectMover();

        playerCurrentCoords = player.MazeCellCoords;

        //start out not in communcation
        aiCommState      = AICommunicationState.NotInCommuncation;
        aiAlignmentState = AIAlignmentState.Neutral;

        //initialize list of possible actions (for each state)
        InitializeActionLists();

        roomsRequestedIn = new Dictionary <IntVector2, bool>();

        rng = new System.Random();
    }
    private void Start() {

        //init communcation channels 
        textCommChannel = CommunicationChannelFactory.Make2WayTextChannel() as TextCommunicationChannel;
        oneWayCommChannel = CommunicationChannelFactory.MakeOneWayTextChannel() as OneWayTextCommunication;
        roomExitCommChannel = CommunicationChannelFactory.MakeRoomExitPathChannel() as RoomExitPathCommChannel;
        oneWayTimedComm = CommunicationChannelFactory.MakeOneWayTimedChannel() as OneWayTimedCommChannel;
        stillnessTimedComm = CommunicationChannelFactory.MakeTimedStillnessChannel() as StillnessTimedCommChannel;

        //init object mover
        objectMover = ObjectMover.CreateObjectMover();

        playerCurrentCoords = player.MazeCellCoords;

        //start out not in communcation
        aiCommState = AICommunicationState.NotInCommuncation;
        aiAlignmentState = AIAlignmentState.Neutral;

        //initialize list of possible actions (for each state)
        InitializeActionLists();

        roomsRequestedIn = new Dictionary<IntVector2, bool>();

        rng = new System.Random();
    }
Beispiel #3
0
 /// <summary>
 /// sends the given string message to the player via the given channel.
 /// Also sets current channel to be given channel.
 /// </summary>
 /// <param name="message"></
 /// <param name="channel"></param>
 private void SendMessageToPlayer(string message, CommunicationChannel channel)
 {
     if (channel == null)
     {
         throw new Exception("channel was null");
     }
     aiCommState        = AICommunicationState.InCommunication;
     currentCommChannel = channel;
     channel.StartCommunicationWithPlayer(player, this, message);
 }
Beispiel #4
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);
                    }
                }
            }
        }
    }
 /// <summary>
 /// sends the given string message to the player via the given channel. 
 /// Also sets current channel to be given channel.
 /// </summary>
 /// <param name="message"></
 /// <param name="channel"></param>
 private void SendMessageToPlayer(string message, CommunicationChannel channel) {
     if (channel == null) {
         throw new Exception("channel was null");
     }
     aiCommState = AICommunicationState.InCommunication;
     currentCommChannel = channel;
     channel.StartCommunicationWithPlayer(player, this, message);
 }
    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);
                    }
                }
            }            
        }
    }