예제 #1
0
    // === PUBLIC METHODS ===

    public override CommandOutcome DoAction()
    {
        // Get the word to be said, if any
        string[] otherWord = parserState.GetOtherWordText();

        CommandOutcome outcome     = CommandOutcome.NO_COMMAND;
        bool           resetFoobar = true;

        // If there were any
        if (otherWord != null)
        {
            bool foundMagicWord = false;

            List <string> otherCommands = commandsController.FindMatch(otherWord[0]);

            foreach (string command in otherCommands)
            {
                if (magicWords.Contains(command))
                {
                    if (command == "2025FeeFieFoe")
                    {
                        resetFoobar = false;
                    }

                    foundMagicWord = true;
                    break;
                }
            }

            // If it's one of the magic words, discard the SAY verb and just continue to process the magic word
            if (foundMagicWord)
            {
                parserState.CurrentCommandState = CommandState.NO_COMMAND;
            }
            else
            {
                textDisplayController.AddTextToLog(playerMessageController.GetMessage("258SayWord", otherWord));
                parserState.CommandComplete();
                outcome = CommandOutcome.MESSAGE;
            }
        }
        else
        {
            parserState.CarryOverVerb();
            textDisplayController.AddTextToLog(playerMessageController.GetMessage("257VerbWhat", parserState.Words));
            parserState.CurrentCommandState = CommandState.NO_COMMAND; // Indicate we're done with this command
        }

        // If used with anything other than the Fee Fie Foe sequence, then reset foobar
        if (resetFoobar)
        {
            controller.ResetFoobar();
        }

        return(outcome);
    }
예제 #2
0
    // Resets the parser state with new commands. Returns true if there is processing to be done and false otherwise
    public bool ResetParserState(CommandWord[] words)
    {
        CommandsToProcess     = new CommandToProcess[2];
        CommandBeingProcessed = -1;

        // Look for a match with available commands
        for (int i = 0; i < 2; i++)
        {
            CommandToProcess commandToProcess = new CommandToProcess();

            // If no word was entered for this command...
            if (words[i].activeWord == null)
            {
                // ... discard it
                commandToProcess.commandState = CommandState.NO_COMMAND;
            }
            else
            {
                // Otherise, Store the words for this command
                commandToProcess.words = new string[2] {
                    words[i].activeWord, words[i].wordTail
                };

                // Try to find one or more matching commands for the word
                commandToProcess.commands      = commandsController.FindMatch(words[i].activeWord);
                commandToProcess.activeCommand = 0;

                // If no match was found...
                if (commandToProcess.commands.Count == 0)
                {
                    // .. discard it
                    commandToProcess.commandState = CommandState.DISCARDED;
                }
                else
                {
                    // Otherwise, mark it ready for processing
                    commandToProcess.commandState = CommandState.NOT_PROCESSED;
                }
            }

            // Add this command to the ParserState
            CommandsToProcess[i] = commandToProcess;
        }

        // Now find the first unprocessed command and mark that as the current command
        CommandBeingProcessed = FindCommandWithState(CommandState.NOT_PROCESSED);

        // If there's nothing to process
        if (CommandBeingProcessed == -1)
        {
            // If nothing's been found to process but the carried over verb was Say, construct a new say verb and process that
            if (VerbCarriedOver != null && VerbCarriedOver == "2003Say")
            {
                CommandsToProcess[1] = CommandsToProcess[0];
                CommandToProcess sayCommand = new CommandToProcess();
                sayCommand.commands = new List <String>()
                {
                    VerbCarriedOver
                };
                sayCommand.commandState = CommandState.NOT_PROCESSED;
                CommandsToProcess[0]    = sayCommand;
                VerbCarriedOver         = null;
                CommandBeingProcessed   = 0;
            }
            else
            {
                // ... otherwise tell the player they used a word not in the vocabulary
                textDisplayController.AddTextToLog(playerMessageController.GetMessage("254UnknownWord", new string[] { words[0].activeWord, words[0].wordTail }));
            }
        }

        // Return true if we found a command ready for processing and false otherwise
        return(CommandBeingProcessed != -1);
    }