// Process a new command from the player public CommandOutcome ProcessCommand() { OldItem = null; // If there's a command to process, then process it if (parserState.NextCommandForProcessing()) { List <string> currentCommands = parserState.CurrentCommands; // Prioritise the first (and possibly only) command matched Command command = GetCommandWithID(currentCommands[0]); // If there's more one match and we've already identified a verb... if (currentCommands.Count > 1 && parserState.ContainsState(CommandState.VERB_IDENTIFIED)) { for (int i = 0; i < currentCommands.Count; i++) { // ... then prioritise matches with item commands Command nextCommand = GetCommandWithID(currentCommands[i]); if (nextCommand is ItemWord) { command = nextCommand; parserState.ActiveCommandIndex = i; break; } } } // Any command other than the FEE FIE FOE sequence or SAY will break the sequence if (command.CommandID != "2025FeeFieFoe" && command.CommandID != "2003Say") { actionController.ResetFoobar(); } // Process the command based on its type if (command is MovementWord) { return(ProcessMovement(command)); } else if (command is ActionWord) { return(ProcessAction(command)); } else if (command is ItemWord) { return(ProcessItem(command)); } else if (command is SpecialWord) { return(ProcessSpecial(command)); } } return(CommandOutcome.NO_COMMAND); }
// Tries to identify a subject for the command and returns the ID of the item or null, if none could be found public string GetSubject(string actionID) { string subject = null; // If no subject has been identified and there are no further commands to be processed if (!parserState.ContainsState(CommandState.SUBJECT_IDENTIFIED) && !parserState.ContainsState(CommandState.NOT_PROCESSED) && !parserState.ContainsState(CommandState.PENDING) && !parserState.SetCarriedOverCommand(true)) { // Otherwise check to see if the command can assume a subject based on the current context subject = actions[actionID].FindSubstituteSubject(); } // If the subject has not yet been set but a subject has been identified if (subject == null && parserState.ContainsState(CommandState.SUBJECT_IDENTIFIED)) { // ... set it subject = parserState.Subject; } // If we've still not found a subject and there's nothing further to process, it is ambiguous, so ask player for clarification if (subject == null && !parserState.ContainsState(CommandState.NOT_PROCESSED) && !parserState.ContainsState(CommandState.PENDING) && !actions[actionID].SubjectOptional) { if (actions[actionID].CarryOverVerb) { parserState.CarryOverVerb(); } NoSubjectMsg noSubjectMsg = actions[actionID].NoSubjectMessage; if (noSubjectMsg.messageParams != null) { textDisplayController.AddTextToLog(playerMessageController.GetMessage(noSubjectMsg.messageID, noSubjectMsg.messageParams)); } else { textDisplayController.AddTextToLog(playerMessageController.GetMessage(noSubjectMsg.messageID)); } parserState.CurrentCommandState = CommandState.NO_COMMAND; // Indicate we're done with this command } return(subject); }
// === PUBLIC METHODS === public override CommandOutcome DoAction() { // Note whether rug is here rugHere = playerController.ItemIsPresent(RUG); // Check whether a subject was identified string itemToFly = controller.GetSubject("fly"); // If there was no subject but there's more to process, carry on processing if (itemToFly == null && (parserState.ContainsState(CommandState.NOT_PROCESSED) || parserState.ContainsState(CommandState.PENDING))) { return(CommandOutcome.NO_COMMAND); } string flyMsg; CommandOutcome outcome = CommandOutcome.MESSAGE; if (itemToFly == null) { // Trying to fly without a subject flyMsg = rugHere ? "224CantUseRug" : "225FlapArms"; } else if (itemToFly == RUG) { // If rug is hovering... if (itemController.GetItemState(RUG) == 2) { // fly across chasm on rug string rugLoc = itemController.Where(RUG, LOCATION_POSITION.FIRST_LOCATION); playerController.GoTo(playerController.CurrentLocation == rugLoc ? itemController.Where(RUG, LOCATION_POSITION.SECOND_LOCATION) : rugLoc, false); flyMsg = itemController.TreasureWasSeen("68Sapphire") ? "227RugBack" : "226BoardRug"; outcome = CommandOutcome.FULL; } else { // Rug won't fly flyMsg = "223RugUncooperative"; } } else { // Trying to fly something other than the rug, so force defult message parserState.CurrentCommandState = CommandState.DISCARDED; return(CommandOutcome.NO_COMMAND); } textDisplayController.AddTextToLog(playerMessageController.GetMessage(flyMsg)); parserState.CommandComplete(); return(outcome); }
// === PUBLIC METHODS === public override CommandOutcome DoAction() { // If there are no further commands to be processed, then force the default message if (!parserState.ContainsState(CommandState.NOT_PROCESSED)) { parserState.CurrentCommandState = CommandState.DISCARDED; } else { // Otherwise - increment the go count and if it's been used 10 times, give the player a hint about not using it if (controller.IncrementGoCount() == 10) { textDisplayController.AddTextToLog(playerMessageController.GetMessage("276NoGo")); } } return(CommandOutcome.NO_COMMAND); }