// === PUBLIC METHODS ===

    public override CommandOutcome DoAction()
    {
        // If there was a second word, treat as a find command
        if (parserState.GetOtherWordText() != null)
        {
            return(controller.ExecuteAction("find"));
        }

        string inventoryText;

        int  numItemsCarried = playerController.NumberOfItemsCarried;
        bool bearFollowing   = playerController.HasItem("35Bear");

        if (numItemsCarried > 0 && !(numItemsCarried == 1 && bearFollowing))
        {
            inventoryText = playerMessageController.GetMessage("99InventoryList") + playerController.Inventory;
        }
        else
        {
            inventoryText = playerMessageController.GetMessage("98InventoryEmpty");
        }

        if (bearFollowing)
        {
            inventoryText += "\n\n" + playerMessageController.GetMessage("141TameBear");
        }

        textDisplayController.AddTextToLog(inventoryText);
        parserState.CommandComplete();
        return(CommandOutcome.MESSAGE);
    }
    // === 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);
    }
    public override CommandOutcome DoAction()
    {
        // If player tried to use a second word, force default message
        if (parserState.GetOtherWordText() != null)
        {
            parserState.CurrentCommandState = CommandState.DISCARDED;
            return(CommandOutcome.NO_COMMAND);
        }

        // Ask for confirmation before quitting
        parserState.CommandComplete();
        questionController.RequestQuestionResponse("quit");
        return(CommandOutcome.QUESTION);
    }
Beispiel #4
0
    // === PUBLIC METHODS ===

    public override CommandOutcome DoAction()
    {
        // If player tried to supply a subject, force default message
        if (parserState.GetOtherWordText() != null)
        {
            parserState.CurrentCommandState = CommandState.DISCARDED;
            return(CommandOutcome.NO_COMMAND);
        }

        // Create a new list for sounds that can be heard here
        List <string> soundTexts = new List <string>();
        LocationSound locSound   = locationController.SoundAtLocation(playerController.CurrentLocation);

        // Add the location sound if there is one
        if (locSound.soundMessage != null && locSound.soundMessage != "")
        {
            soundTexts.Add(locSound.soundMessage);
        }

        // If the location sound doesn't drown out other sounds...
        if (!locSound.drownsOutOtherSounds)
        {
            // Get all the items currently carried or at player's location
            List <string> itemsHere = playerController.PresentItems();

            // Search the items...
            foreach (string item in itemsHere)
            {
                // .. for any that can be heard
                if (itemController.ItemCanBeHeard(item))
                {
                    string soundText = itemController.ListenToItem(item);

                    // If the bird is singing about its freedom in the forest, we need to add magic word and the bird disappears forever
                    if (item == BIRD && soundText.Contains("~"))
                    {
                        soundText = playerMessageController.AssembleTextWithParams(soundText, new string[] { commandsController.MagicWordText });
                        itemController.DestroyItem(BIRD);
                    }

                    soundTexts.Add(soundText);
                }
            }
        }

        // If there were no sounds, add the silence message
        if (soundTexts.Count == 0)
        {
            soundTexts.Add(playerMessageController.GetMessage("228Silent"));
        }

        // Display all the sounds that can be heard here
        string outString = "";

        for (var i = 0; i < soundTexts.Count; i++)
        {
            if (i > 0)
            {
                outString += "\n";
            }

            outString += soundTexts[i];
        }

        textDisplayController.AddTextToLog(outString);
        parserState.CommandComplete();
        return(CommandOutcome.MESSAGE);
    }
    // Process an item word
    private CommandOutcome ProcessItem(Command itemCommand)
    {
        // Select the command to use
        ItemWord command = (ItemWord)itemCommand;

        OldItem = command.AssociatedItem;

        // Get the other word entered, if any
        string[] otherWord       = parserState.GetOtherWordText();
        string   otherWordActive = otherWord != null ? otherWord[0].ToUpper() : null;

        // Check for use of certain item words as verbs
        if ((command.CommandID == "1021Water" || command.CommandID == "1022Oil") && (otherWordActive == "PLANT" || otherWordActive == "DOOR"))
        {
            // Player is trying to water/oil the plant/door, so construct a POUR command with this item as the subject and execute that instead
            CommandWord pourCommand    = new CommandWord("POUR", null);
            CommandWord newItemCommand = new CommandWord(parserState.Words[0], parserState.Words[1]);
            parserState.ResetParserState(new CommandWord[2] {
                pourCommand, newItemCommand
            });
            return(ProcessCommand());
        }
        else if (command.CommandID == "1004Cage" && otherWordActive == "BIRD" && playerController.ItemIsPresent("4Cage") && playerController.ItemIsPresent("8Bird"))
        {
            // Player is trying to cage the bird, so construct a CATCH command with the bird as the subject and execute that instead
            CommandWord catchCommand   = new CommandWord("CATCH", null);
            CommandWord newItemCommand = new CommandWord(otherWord[0], otherWord[1]);
            parserState.ResetParserState(new CommandWord[2] {
                catchCommand, newItemCommand
            });
            return(ProcessCommand());
        }

        // Get the matching item
        string item = command.AssociatedItem;

        bool continueProcessing = true;

        // Check if item is present
        if (!playerController.ItemIsPresent(item))
        {
            // Item is not present so check for special cases
            string loc = playerController.CurrentLocation; // Make short ref to current location
            continueProcessing = false;                    // Assume we won't continue processing

            switch (command.CommandID)
            {
            case "1003Grate":

                // If GRATE used on its own, treat it like a movement word, if in an appropriate location
                if (parserState.GetOtherWordText() == null)
                {
                    if (playerController.PlayerCanBeFoundAt(new List <string> {
                        "1Road", "4Valley", "7SlitInStreambed"
                    }))
                    {
                        parserState.SubstituteCommand("63Depression");
                        continueProcessing = true;
                    }
                    else if (playerController.PlayerCanBeFoundAt(new List <string> {
                        "10CobbleCrawl", "11DebrisRoom", "12AwkwardCanyon", "13BirdChamber", "14TopOfPit"
                    }))
                    {
                        parserState.SubstituteCommand("64Entrance");
                        continueProcessing = true;
                    }
                }

                break;

            case "1017Dwarf":

                // If dwarf has been referenced, check that there is actually a dwarf here
                if (dwarfController.FirstDwarfAt(loc) != -1)
                {
                    // There is, so process next command
                    parserState.Subject             = item;
                    parserState.CurrentCommandState = CommandState.SUBJECT_IDENTIFIED;
                    continueProcessing = true;
                }

                break;

            case "1021Water":
            case "1022Oil":
                // Check to see if the bottle is present with the correct liquid, or the correct liquid is present at this location
                //Item bottle = itemController.GetItemWithID("20Bottle");
                bool       bottleHere          = playerController.ItemIsPresent("20Bottle");
                int        requiredBottleState = command.CommandID == "1021Water" ? 0 : 2;
                LiquidType requiredLiquidType  = command.CommandID == "1021Water" ? LiquidType.WATER : LiquidType.OIL;

                if ((bottleHere && itemController.GetItemState("20Bottle") == requiredBottleState) || locationController.LiquidAtLocation(loc) == requiredLiquidType)
                {
                    // There is, so process next command
                    parserState.Subject             = item;
                    parserState.CurrentCommandState = CommandState.SUBJECT_IDENTIFIED;
                    continueProcessing = true;
                }
                else
                {
                    // Otherwise check to see if the player is trying to manipulate oil and the urn is here and contains oil
                    if (command.CommandID == "1022Oil" && itemController.ItemIsAt("42Urn", loc) && itemController.GetItemState("42Urn") != 0)
                    {
                        // If so, set the subject to be the urn and continue processing
                        parserState.Subject             = "42Urn";
                        parserState.CurrentCommandState = CommandState.SUBJECT_IDENTIFIED;
                        continueProcessing = true;
                    }
                }

                break;

            case "1024Plant":
                // Check if player is trying to manipulate the plant, but is actually at a location where the phony plant is present
                if (itemController.ItemIsAt("25PhonyPlant", loc) && itemController.GetItemState("25PhonyPlant") != 0)
                {
                    // If so, set the subject to be the phony plant and continue processing
                    parserState.Subject             = "25PhonyPlant";
                    parserState.CurrentCommandState = CommandState.SUBJECT_IDENTIFIED;
                    continueProcessing = true;
                }

                break;

            case "1005Rod":
                // If the player is trying to do something with the rod, check if they are at the phony rod location
                if (playerController.ItemIsPresent("6BlackRod"))
                {
                    // If so, set the subject to be the phony rod and continue processing
                    parserState.Subject             = "6BlackRod";
                    parserState.CurrentCommandState = CommandState.SUBJECT_IDENTIFIED;
                    continueProcessing = true;
                }
                break;
            }

            // If we have a verb and it's FIND or INVENT, then it's OK that the subject is not present
            if (!continueProcessing && (parserState.VerbIs("2019Find") || parserState.VerbIs("2020Inventory")))
            {
                parserState.Subject             = item;
                parserState.CurrentCommandState = CommandState.SUBJECT_IDENTIFIED;
                continueProcessing = true;
            }

            if (!continueProcessing)
            {
                // Mark this as discarded...
                parserState.CurrentCommandState = CommandState.DISCARDED;

                // ... but check if there's still more commands to be processed
                if (parserState.ContainsState(CommandState.NOT_PROCESSED))
                {
                    // ... if so, mark this as pending and process other command
                    parserState.CurrentCommandState = CommandState.PENDING;
                    continueProcessing = true;
                }
                else
                {
                    // Object not present and isn't a special case so let player know that object is not here
                    textDisplayController.AddTextToLog(playerMessageController.GetMessage("256ISeeNo", parserState.Words));
                    return(CommandOutcome.MESSAGE);
                }
            }
        }
        else
        {
            // Special case for knife
            if (item == "18Knife")
            {
                dwarfController.KnifeMessageShown();
                textDisplayController.AddTextToLog(playerMessageController.GetMessage("116KnivesVanish"));
                parserState.CommandComplete();
                return(CommandOutcome.MESSAGE);
            }

            // The item is here, so set it as the subject
            parserState.Subject             = item;
            parserState.CurrentCommandState = CommandState.SUBJECT_IDENTIFIED;
        }

        // Now check to see if we have a verb or an unprocessed command, or a carried over verb, and if so, go back to processing
        if (parserState.ContainsState(CommandState.VERB_IDENTIFIED) || parserState.ContainsState(CommandState.NOT_PROCESSED) || parserState.SetCarriedOverCommand(false))
        {
            return(ProcessCommand());
        }

        // If we get here, the player has just given us the name of the item, so ask them what they want to do with it
        parserState.CarryOverSubject();
        textDisplayController.AddTextToLog(playerMessageController.GetMessage("255WantToDo", parserState.Words));
        return(CommandOutcome.MESSAGE);
    }
    public override CommandOutcome DoAction()
    {
        // If player tried to use a second word, force default message
        string[] otherword = parserState.GetOtherWordText();

        if (otherword != null && otherword[0].ToUpper() != "SAY")
        {
            parserState.CurrentCommandState = CommandState.DISCARDED;
            return(CommandOutcome.NO_COMMAND);
        }

        int nextWord = controller.Foobar;

        // Assume that nothing will happen
        string fooText = playerMessageController.GetMessage("42NothingHappens");

        // Player has used the next word in the sequence
        if (parserState.Words[0].ToUpper() == wordOrder[nextWord])
        {
            // Advance to the next word
            controller.IncrementFoobar();

            // If we're done...
            if (controller.Foobar == wordOrder.Length)
            {
                string eggs  = "56Eggs";
                string troll = "33Troll";

                controller.ResetFoobar();

                bool playerAtInitialEggLocation = itemController.IsInitialLocation(eggs, playerController.CurrentLocation, LOCATION_POSITION.FIRST_LOCATION);

                // If the eggs are currently in their initial location or the player is carrying them, but is currently at their initial location, then nothing happens
                if (!itemController.AtInitalLocation(eggs) && !(playerController.HasItem(eggs) && playerAtInitialEggLocation))
                {
                    // Bring back the troll if we're trying to steal back the eggs after using them to pay for a crossing
                    if (!itemController.ItemInPlay(eggs) && !itemController.ItemInPlay(troll) && itemController.GetItemState(troll) == 0)
                    {
                        itemController.SetItemState(troll, 1);
                    }

                    // Transport the eggs back to the giant room
                    int eggMsgState;

                    if (playerAtInitialEggLocation)
                    {
                        eggMsgState = 0;
                    }
                    else if (playerController.ItemIsPresent(eggs))
                    {
                        eggMsgState = 1;
                    }
                    else
                    {
                        eggMsgState = 2;
                    }

                    itemController.ResetItem(eggs);
                    itemController.SetItemState(eggs, eggMsgState);
                    fooText = itemController.DescribeItem(eggs);
                    itemController.SetItemState(eggs, 0);
                }
            }
            else
            {
                // Player has correctly said the next word in the sequence, but we're not at the end yet...
                fooText = playerMessageController.GetMessage("54OK");
            }
        }
        else
        {
            // Player has said a word out of sequence. If mid-sequence, we need to reset and should give the player a hint.
            if (controller.Foobar != 0)
            {
                fooText = playerMessageController.GetMessage("151StartOver");
                controller.ResetFoobar();
            }
        }

        textDisplayController.AddTextToLog(fooText);
        parserState.CommandComplete();
        return(CommandOutcome.MESSAGE);
    }
    // === PUBLIC METHODS ===

    public override CommandOutcome DoAction()
    {
        // Note whether it's dark
        isDark = gameController.IsDark();

        // Check whether a subject was identified
        noSubjectMsg = new NoSubjectMsg("257VerbWhat", parserState.Words);
        string itemToRead = controller.GetSubject("read");

        // If no item could be identified then we're either done with this command or we need to continue processing to find a subject
        if (itemToRead == null)
        {
            return(CommandOutcome.NO_COMMAND);
        }

        CommandOutcome outcome = CommandOutcome.MESSAGE;

        if (isDark)
        {
            // If it's dark, can't see object to read it
            textDisplayController.AddTextToLog(playerMessageController.GetMessage("256ISeeNo", parserState.GetOtherWordText()));
        }
        else
        {
            string itemText = itemController.ReadItem(itemToRead);

            if (itemText != null)
            {
                if (itemToRead != "15Oyster" || scoreController.ClosedHintShown)
                {
                    textDisplayController.AddTextToLog(itemText);
                }
                else
                {
                    // Oyster is a special case when read after cave closed before hint has been revealed
                    questionController.RequestQuestionResponse("read");
                    outcome = CommandOutcome.QUESTION;
                }
            }
            else
            {
                parserState.CurrentCommandState = CommandState.DISCARDED;
                return(CommandOutcome.NO_COMMAND);
            }
        }

        parserState.CommandComplete();
        return(outcome);
    }