// === 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); }
// Begin a new turn public bool ProcessTurn(CommandOutcome turnType) { bool hintOrDeathQuestion = false; bool forced = true; // This loop is repeated while the player is alive until the player reaches a location where movement isn't forced while (playerController.IsAlive && forced) { forced = false; // Ensure we break out of the loop, unless the current location is forced if (turnType == CommandOutcome.FULL) { // If the player has left the cave during closing ... if (playerController.IsOutside && CurrentCaveStatus == CaveStatus.CLOSING) { // ... force them back inside and give them warning about cave closing playerController.RevokeMovement(); textDisplayController.AddTextToLog(playerMessageController.GetMessage("130ClosedAnnounce")); // Start the panic clock, if it hasn't already started StartPanic(); } // CHeck if player's path is blocked by a dwarf before moving player to new location if (dwarfController.Blocked()) { // Passage was blocked, so tell player textDisplayController.AddTextToLog(playerMessageController.GetMessage("2DwarfBlock")); playerController.RevokeMovement(); } else { playerController.CommitMovement(); } // Now process the dwarves if (dwarfController.DoDwarfActions()) { // The dwarves killed the player avatar playerController.KillPlayer(); } } // If player is still alive after any dwarf encounters... if (playerController.IsAlive) { // If the location is to be shown or reshown, show it now if (turnType != CommandOutcome.MESSAGE) { // Now show the current location DisplayLocation(); } // Show useful info in the debug panel (only visible if debug mode is on) debugPanelScript.UpdateDebugPanel(); // Check to see if movement from this location is forced and move if so forced = playerController.CheckForcedMove(); // Forced locations can't have items left there and don't have hints, so if movement was forced, we can skip this section if (!forced) { // Don't show item descriptions again if the command outcome was just a message if (turnType != CommandOutcome.MESSAGE) { // If at Y2 before closing, there's a 25% chance the player hears someone say "PLUGH" if (playerController.CurrentLocation == "33Y2" && CurrentCaveStatus != CaveStatus.CLOSING && Random.value < .25) { textDisplayController.AddTextToLog(playerMessageController.GetMessage("7Plugh")); } DisplayItems(); } // If cave is closed, adjust state of any carried items so they will be described again after they are put down if (CurrentCaveStatus == CaveStatus.CLOSED) { AdjustCarriedItemsAfterClosing(); } // Get rid of the knife if it exists itemController.CleanUpKnife(); } else { // Ensure we process a full turn for any forced movement turnType = CommandOutcome.FULL; } } } // If the player has died if (!playerController.IsAlive) { PlayerDeath(); hintOrDeathQuestion = true; } else { // Show any hints for the current location hintOrDeathQuestion = hintController.CheckForHints(playerController.CurrentLocation); } // Check to see if a continuation save is due persistenceController.CheckContinuationSave(); return(hintOrDeathQuestion); }
// === PUBLIC METHODS === public override CommandOutcome DoAction() { location = playerController.CurrentLocation; noSubjectMsg = new NoSubjectMsg("44NoAttack", null); carryOverVerb = false; // Check whether a subject was identified, or could be identified and return if not itemToAttack = controller.GetSubject("attack"); // 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 (itemToAttack == null) { return(CommandOutcome.NO_COMMAND); } attackText = null; CommandOutcome outcome = CommandOutcome.MESSAGE; switch (itemToAttack) { case BIRD: outcome = AttackBird(); break; case VENDING: outcome = AttackVendingMachine(); break; case CLAM: case OYSTER: attackText = playerMessageController.GetMessage("150StrongShell"); break; case SNAKE: attackText = playerMessageController.GetMessage("46AttackSnake"); break; case DWARF: outcome = AttackDwarf(); break; case DRAGON: outcome = AttackDragon(); break; case TROLL: attackText = playerMessageController.GetMessage("157TrollDefence"); break; case OGRE: outcome = AttackOgre(); break; case BEAR: outcome = AttackBear(); break; default: // The identified object cannot be attacked, so display default message parserState.CurrentCommandState = CommandState.DISCARDED; return(CommandOutcome.NO_COMMAND); } if (attackText != null) { textDisplayController.AddTextToLog(attackText); } parserState.CommandComplete(); return(outcome); }
public List <CommandOutcome> ValidatePlacement(string socketId, int posX, int posY, int arenaId) { ShipSelection selection = GetSelection(socketId); ShipType type = GetShipType(socketId); Cell cell = ReturnCell(posX, posY, arenaId); List <CommandOutcome> commands = new List <CommandOutcome>(); if (cell == null) { if (NoCellsNearby(posX, posY, arenaId, type)) { List <Ship> ships = GetShipsByType(type.ShipTypeId, socketId); int shipId = 0; Console.WriteLine("!!!!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!!!!!!!!!!!!!!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!!!!!!!!!!~~~~~~~~~~~~~ + COUNT[" + selection.Count + "] SIZE[" + selection.Size + "]"); if (ships.Count < type.Count - selection.Count + 1) { if (NoShipNearby(posX, posY, arenaId, new Ship(), true)) { shipId = AddShip(arenaId, type.ShipTypeId, type.Type, type.Size, socketId, posX, posY); //cell was created when adding a new ship cell = ReturnCell(posX, posY, arenaId); cell.ShipId = shipId; SaveCommand(cell, selection, socketId); if (PlaceShip(socketId)) { commands.Add(new CommandOutcome(PlacementOutcome.Ship, posX, posY)); } else { string id = GetButtonId(socketId); CommandOutcome outcome = new CommandOutcome(PlacementOutcome.LastShip, posX, posY); outcome.idToRemove = id; commands.Add(outcome); } _context.SaveChanges(); } else { commands.Add(new CommandOutcome(PlacementOutcome.Invalid)); } } else { shipId = ships[ships.Count - 1].ShipId; if (!CorrectPlacement(type, selection, ships[ships.Count - 1], arenaId, posX, posY)) { commands.Add(new CommandOutcome(PlacementOutcome.Invalid)); } else { cell = CreateCell(posX, posY, arenaId); cell.ShipId = shipId; if (PlaceShip(socketId)) { commands.Add(new CommandOutcome(PlacementOutcome.Ship, posX, posY)); } else { string id = GetButtonId(socketId); CommandOutcome outcome = new CommandOutcome(PlacementOutcome.LastShip, posX, posY); outcome.idToRemove = id; commands.Add(outcome); } _context.SaveChanges(); Ship ship = GetShip(shipId); Cell preCell = GetCell(ship.CellId); if (preCell.PosX < posX) { //RIGHT for (int i = 1; i < ship.RemainingTiles - 1; i++) { cell = CreateCell(posX + i, posY, arenaId); cell.ShipId = shipId; if (PlaceShip(socketId)) { commands.Add(new CommandOutcome(PlacementOutcome.Ship, posX + i, posY)); } else { string id = GetButtonId(socketId); CommandOutcome outcome = new CommandOutcome(PlacementOutcome.LastShip, posX + i, posY); outcome.idToRemove = id; commands.Add(outcome); } _context.SaveChanges(); } } else if (preCell.PosX > posX) { //LEFT for (int i = 1; i < ship.RemainingTiles - 1; i++) { cell = CreateCell(posX - i, posY, arenaId); cell.ShipId = shipId; if (PlaceShip(socketId)) { commands.Add(new CommandOutcome(PlacementOutcome.Ship, posX - i, posY)); } else { string id = GetButtonId(socketId); CommandOutcome outcome = new CommandOutcome(PlacementOutcome.LastShip, posX - i, posY); outcome.idToRemove = id; commands.Add(outcome); } _context.SaveChanges(); } } else if (preCell.PosY < posY) { //UP for (int i = 1; i < ship.RemainingTiles - 1; i++) { cell = CreateCell(posX, posY + i, arenaId); cell.ShipId = shipId; if (PlaceShip(socketId)) { commands.Add(new CommandOutcome(PlacementOutcome.Ship, posX, posY + i)); } else { string id = GetButtonId(socketId); CommandOutcome outcome = new CommandOutcome(PlacementOutcome.LastShip, posX, posY + i); outcome.idToRemove = id; commands.Add(outcome); } _context.SaveChanges(); } } else { //DOWN for (int i = 1; i < ship.RemainingTiles - 1; i++) { cell = CreateCell(posX, posY - i, arenaId); cell.ShipId = shipId; if (PlaceShip(socketId)) { commands.Add(new CommandOutcome(PlacementOutcome.Ship, posX, posY - i)); } else { string id = GetButtonId(socketId); CommandOutcome outcome = new CommandOutcome(PlacementOutcome.LastShip, posX, posY - i); outcome.idToRemove = id; commands.Add(outcome); } _context.SaveChanges(); } } } } } else { commands.Add(new CommandOutcome(PlacementOutcome.Invalid)); } } else { commands.Add(new CommandOutcome(PlacementOutcome.Invalid)); } return(commands); }
public CommandResult(CommandOutcome outcome, List <ValidationResult> validationErrors = null) { ValidationErrors = validationErrors ?? new List <ValidationResult>(); Outcome = outcome; }
// === PUBLIC METHODS === public override CommandOutcome DoAction() { location = playerController.CurrentLocation; // Check whether a subject was identified, or could be identified noSubjectMsg = new NoSubjectMsg("257VerbWhat", parserState.Words); itemToWave = controller.GetSubject("wave"); // 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 (itemToWave == null) { return(CommandOutcome.NO_COMMAND); } List <string> waveMsg = new List <string>(); bool hasItem = playerController.HasItem(itemToWave); bool isRod = itemToWave == "5BlackRod"; bool birdHere = playerController.ItemIsPresent("8Bird"); bool atFissure = location == "17EastFissure" || location == "27WestFissure"; bool closing = gameController.CurrentCaveStatus == CaveStatus.CLOSING; if (!hasItem && (!isRod || !playerController.HasItem("6BlackRod"))) { textDisplayController.AddTextToLog(playerMessageController.GetMessage("29DontHaveIt")); parserState.CommandComplete(); return(CommandOutcome.MESSAGE); } // Wave will have no effect in these circumstances if (!isRod || !hasItem || (!birdHere && (closing || !atFissure))) { parserState.CurrentCommandState = CommandState.DISCARDED; return(CommandOutcome.NO_COMMAND); } CommandOutcome outcome = CommandOutcome.MESSAGE; // If the bird is here... if (birdHere) { switch (itemController.GetItemState("8Bird") % 2) { // ... and bird is uncaged... case 0: // ... if at steps and jade necklace not yet found... if (location == "14TopOfPit" && !itemController.ItemInPlay("66Necklace")) { // ... bird retrieves jade necklace... itemController.DropItemAt("66Necklace", location); // Tally a treasure itemController.TallyTreasure("66Necklace"); waveMsg.Add(playerMessageController.GetMessage("208BirdRetrieveNecklace")); } else { // ... otherwise bird just got agitated waveMsg.Add(playerMessageController.GetMessage("206BirdAgitated")); } break; case 1: // ... bird got agitated in cage waveMsg.Add(playerMessageController.GetMessage("207BirdAgitatedCage")); break; } // If cave is closed, this action will wake the dwarves if (gameController.CurrentCaveStatus == CaveStatus.CLOSED) { outcome = CommandOutcome.DISTURBED; } } // If we're at the fissure and it's not closing if (atFissure && !closing) { //Toggle crystal bridge state and show appropriate message int fissureState = itemController.GetItemState("12Fissure"); itemController.SetItemState("12Fissure", fissureState + 1); waveMsg.Add(itemController.DescribeItem("12Fissure")); itemController.SetItemState("12Fissure", 1 - fissureState); } // Show any messages generated and end this command for (int i = 0; i < waveMsg.Count; i++) { if (waveMsg[i] != null) { textDisplayController.AddTextToLog(waveMsg[i]); } } parserState.CommandComplete(); return(outcome); }
// === 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); }