public void InvokeCommand(CommandWord commandWord, params object[] parameter) { ICalculatorCommand command = this.commandList.FirstOrDefault(c => c.ShouldExecute(commandWord)); if (command == null) { return; } command.PreviousCommandWord = this.commandJournal.LastOrDefault(); try { command.Execute(parameter); // REMARK: This might be an issue as soon as I want to implement undo operations... // Maybe an can-undo flag is required then but a command shouldn't have a status... this.CommandExecuted?.Invoke(this, command.CommandWord); this.AddCommandToJournal(commandWord); } catch (Exception ex) { this.CommandFailed?.Invoke(this, ex); } }
public RtpMidiInvitation(CommandWord commandWord, int protocolVersion, int initiatorToken, int ssrc, string name) : base(commandWord, ssrc) { ProtocolVersion = protocolVersion; InitiatorToken = initiatorToken; Name = name; }
// TODO: MAKE PRIVATE public void AddCommandToJournal(CommandWord commandWord) { if (this.commandJournal.Count >= 20) { this.commandJournal.RemoveAt(0); } this.commandJournal.Add(commandWord); }
// Processes commands to a usable format (upper case and first five letters only) private CommandWord formatCommandWord(string rawCommandWord) { string formattedWord = rawCommandWord; string wordTail = null; if (formattedWord.Length > 5) { formattedWord = formattedWord.Substring(0, 5); wordTail = rawCommandWord.Substring(5); } CommandWord commandWord = new CommandWord(formattedWord, wordTail); return(commandWord); }
// Checks to see if player is carrying a valid liquid item and returns true if processing can continue and false otherwise private bool ValidLiquidItem() { // Check if the player is trying to get oil or water if (itemToCarry == "21Water" || itemToCarry == "22Oil") { // Make a copy of the liquid item we're atfer and set the item to carry as the bottle string liquidItem = itemToCarry; itemToCarry = "20Bottle"; // Check for cases where the bottle is not at this location with the correct liquid if (!(playerController.ItemIsPresent(itemToCarry) && itemController.GetItemState(itemToCarry) == (liquidItem == "21Water" ? 0 : 2))) { // Check if the player is carrying the bottle if (playerController.HasItem(itemToCarry)) { // Check if the bottle is empty if (itemController.GetItemState(itemToCarry) == 1) { // If so, change the command to "fill bottle" and process that instead CommandWord fillCommand = new CommandWord("FILL", null); CommandWord bottleCommand = new CommandWord("BOTTL", null); parserState.ResetParserState(new CommandWord[2] { fillCommand, bottleCommand }); outcome = CommandOutcome.NO_COMMAND; } else { // The bottle is not empty so let the player know textDisplayController.AddTextToLog(playerMessageController.GetMessage("105BottleFull")); parserState.CommandComplete(); } } else { // The player is not carrying the bottle, so let them know they don't have a suitable container textDisplayController.AddTextToLog(playerMessageController.GetMessage("104NoContainer")); parserState.CommandComplete(); } return(false); } } return(true); }
public byte[] ToByteArray() { MemoryStream outputStream = new MemoryStream(); DataOutputStream dataOutputStream = new DataOutputStream(outputStream); dataOutputStream.Write(MIDI_COMMAND_HEADER1); dataOutputStream.Write(MIDI_COMMAND_HEADER2); dataOutputStream.Write(System.Text.Encoding.UTF8.GetBytes(CommandWord.ToString())); dataOutputStream.WriteInt(Ssrc); dataOutputStream.WriteByte(Count); dataOutputStream.Write(new byte[3]); dataOutputStream.WriteLong(Timestamp1); dataOutputStream.WriteLong(Timestamp2); dataOutputStream.WriteLong(Timestamp3); dataOutputStream.Flush(); return(outputStream.ToArray()); }
public override byte[] ToByteArray() { try { MemoryStream outputStream = new MemoryStream(); DataOutputStream dataOutputStream = new DataOutputStream(outputStream); dataOutputStream.Write(MIDI_COMMAND_HEADER1); dataOutputStream.Write(MIDI_COMMAND_HEADER2); dataOutputStream.Write(System.Text.Encoding.UTF8.GetBytes(CommandWord.ToString())); dataOutputStream.WriteInt(ProtocolVersion); dataOutputStream.WriteInt(InitiatorToken); dataOutputStream.WriteInt(Ssrc); dataOutputStream.Flush(); return(outputStream.ToArray()); } catch (Exception e) { throw new System.IO.IOException(e.Message); } }
public static bool IsSpecialCommandWord(this CommandWord commandWord) => commandWord == CommandWord.SetYears || commandWord == CommandWord.GetYears || commandWord == CommandWord.CalculateYears || commandWord == CommandWord.GetEffectiveInterest || commandWord == CommandWord.SetEffectiveInterest || commandWord == CommandWord.CalculateEffectiveInterest || commandWord == CommandWord.GetNominalInterestRate || commandWord == CommandWord.SetNominalInterestRate || commandWord == CommandWord.GetStart || commandWord == CommandWord.SetStart || commandWord == CommandWord.CalculateStart || commandWord == CommandWord.SetAdvance || commandWord == CommandWord.GetRate || commandWord == CommandWord.SetRate || commandWord == CommandWord.GetRepaymentRate || commandWord == CommandWord.SetRepaymentRate || commandWord == CommandWord.CalculateRate || commandWord == CommandWord.GetEnd || commandWord == CommandWord.SetEnd || commandWord == CommandWord.CalculateEnd || commandWord == CommandWord.SetRatesPerAnnum || commandWord == CommandWord.GetRatesPerAnnum;
public RtpMidiCommand(CommandWord commandWord, int ssrc) { CommandWord = commandWord; Ssrc = ssrc; }
// === PUBLIC METHODS === public override CommandOutcome DoAction() { location = playerController.CurrentLocation; // Determine the liquid in the botttle, if any liquidInBottle = null; switch (itemController.GetItemState(BOTTLE)) { case 0: liquidInBottle = WATER; break; case 2: liquidInBottle = OIL; break; } // Check whether a subject was identified, or could be identified noSubjectMsg = new NoSubjectMsg("257VerbWhat", parserState.Words); itemToPour = controller.GetSubject("pour"); // 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 (itemToPour == null) { return(CommandOutcome.NO_COMMAND); } // If the item to pour is the bottle, substitute the liquid, if any if (itemToPour == BOTTLE && liquidInBottle != null) { itemToPour = liquidInBottle; } // If player doesn't have the object, show the default message if (!playerController.HasItem(itemToPour)) { parserState.CurrentCommandState = CommandState.DISCARDED; return(CommandOutcome.NO_COMMAND); } string pourMsg = null; CommandOutcome outcome = CommandOutcome.MESSAGE; // If the item being poured is not oil or water, object if (itemToPour != WATER && itemToPour != OIL) { pourMsg = "78NoPour"; } else { // If the urn is here and empty - create a new command to fill the urn and execute that instead if (itemController.ItemIsAt("42Urn", location)) { CommandWord fillCommand = new CommandWord("FILL", null); CommandWord urnCommand = new CommandWord("URN", null); parserState.ResetParserState(new CommandWord[2] { fillCommand, urnCommand }); return(CommandOutcome.NO_COMMAND); } else { // Set the bottle to empty and destroy the liquid itemController.SetItemState(BOTTLE, 1); itemController.DestroyItem(itemToPour); // Check for special actions at the rusty door if (itemController.ItemIsAt(DOOR, location)) { if (itemToPour == OIL) { // If oil used, hinges are lubricated itemController.SetItemState(DOOR, 1); pourMsg = "114OiledHinges"; } else { // Water is used, so hinges are rusted up itemController.SetItemState(DOOR, 0); pourMsg = "113RustyHinges"; } } // Check for special actions at plant else if (itemController.ItemIsAt(PLANT, location)) { if (itemToPour == WATER) { int plantState = itemController.GetItemState(PLANT); // Describe what happens to plant itemController.SetItemState(PLANT, plantState + 3); textDisplayController.AddTextToLog(itemController.DescribeItem(PLANT)); // Set a new stable state for the plant and the phony plant plantState = (plantState + 1) % 3; itemController.SetItemState(PLANT, plantState); itemController.SetItemState("25PhonyPlant", plantState); // Force location to be redescribed outcome = CommandOutcome.FULL; } else { // Player has watered plant with oil pourMsg = "112PlantOil"; } } else { // The player has emptied the bottle onto the ground pourMsg = "77PourGround"; } } } if (pourMsg != null) { textDisplayController.AddTextToLog(playerMessageController.GetMessage(pourMsg)); } parserState.CommandComplete(); return(outcome); }
// 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 bool ShouldExecute(CommandWord commandWord) => this.CommandWord == commandWord;
// === PUBLIC METHODS === public override CommandOutcome DoAction() { location = playerController.CurrentLocation; // Get player's current location // Attempt to get an item to throw noSubjectMsg = new NoSubjectMsg("257VerbWhat", parserState.Words); itemToThrow = controller.GetSubject("throw"); // 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 (itemToThrow == null) { return(CommandOutcome.NO_COMMAND); } // If subject is real rod, but player only carrying phony rod, then set phony rod as subject if (itemToThrow == "5BlackRod" && !playerController.HasItem("5BlackRod") && playerController.HasItem("6BlackRod")) { itemToThrow = "6BlackRod"; } // If player is not holding the object, show default message if (!playerController.HasItem(itemToThrow)) { parserState.CurrentCommandState = CommandState.DISCARDED; return(CommandOutcome.NO_COMMAND); } string throwMsg = null; // Will hold the message to be shown to the player as a result of the command outcome = CommandOutcome.MESSAGE; // In most cases, outcome will be message (will be updated if not) // If at troll bridge and throwing a treasure, it is assumed to be a toll to cross if (itemController.IsTreasure(itemToThrow) && itemController.ItemIsAt("33Troll", location)) { throwMsg = ThrowTreasureToTroll(); } // If throwing food in the presence of the bear... else if (itemToThrow == "19Food" && itemController.ItemIsAt("35Bear", location)) { // ... construct a feed command with the bear as subject and execute that instead CommandWord feedCommand = new CommandWord("FEED", null); CommandWord itemCommand = new CommandWord("BEAR", null); parserState.ResetParserState(new CommandWord[2] { feedCommand, itemCommand }); return(CommandOutcome.NO_COMMAND); } // Throwing the axe else if (itemToThrow == "28Axe") { throwMsg = ThrowAxe(); } // In all other circumstances... else { // ...execute a drop command instead return(controller.ExecuteAction("drop")); } if (throwMsg != null) { textDisplayController.AddTextToLog(playerMessageController.GetMessage(throwMsg)); } parserState.CommandComplete(); return(outcome); }