private void MovedOrRefresh(Player player, SeenRoom room, RoomDisplayCommand command, Direction?direction) { if (player.RoomDetectionState == RoomDetectionState.HaveMatch && command == RoomDisplayCommand.Move && direction != null) { // user is moving, verify that the new room we are in is in fact what we think it is. VerifyNewRoom(player.LastSeenRoom, direction.Value, room, player); } else { // first find a potential match for the room. FindPotentialRoomMatch(room, player); if (room.PotentialMatches.Count == 1) { // we found a definite match, simply set the current room and be done with it. SetCurrentRoom(RoomDetectionState.HaveMatch, room, player); } else if (room.PotentialMatches.Count == 0) { // found a room that we have no idea where it is, so we're officially lost. SetCurrentRoom(RoomDetectionState.NoClue, null, player); } else { if (player.RoomDetectionState == RoomDetectionState.HaveMatches && direction != null) { player.LastSeenRoom.AdjacentRooms[(int)direction] = room; SetCurrentRoom(RoomDetectionState.HaveMatches, room, player); CalculateRoomWeb(player); } else if (command == RoomDisplayCommand.Refresh && player.RoomDetectionState == RoomDetectionState.HaveMatch && room.HasMatch(player.LastSeenRoom.Match.RoomNumber)) { // player refreshed, so if we had a match don't overwrite it with an ambiguity. return; } else if (player.RoomDetectionState == RoomDetectionState.HaveMatch && command == RoomDisplayCommand.Move && direction == null) { // We couldn't tell what direction the user moved, so look at the adjacent rooms and see if there's a single match. var adjacentRooms = player.LastSeenRoom.Match.GetAdjacentRoomNumbers(); var narrowedList = room.PotentialMatches.Where(p => adjacentRooms.Any(a => p.RoomNumber == a)); if (narrowedList.Count() == 1) { room.PotentialMatches.RemoveAll(x => x.RoomNumber != narrowedList.First().RoomNumber); // found a definite match, let's assume the user moved there. SetCurrentRoom(RoomDetectionState.HaveMatch, room, player); return; } } else { SetCurrentRoom(RoomDetectionState.HaveMatches, room, player); } } } }
public static void ParseUserCommand(Player player, out RoomDisplayCommand command, out Direction?direction) { command = RoomDisplayCommand.Unknown; direction = null; if (player.LastConfirmedCommand != null) { var tokens = player.LastConfirmedCommand.ToLowerInvariant().Split(new char[0], StringSplitOptions.RemoveEmptyEntries); if (tokens.Length > 1 && player.Model.IsCommand(Command.Look, tokens[0])) { command = RoomDisplayCommand.Look; direction = player.Model.IsDirectionCommand(tokens[1]); player.Interface.DebugText("Player looking " + player.Model.PlainExitNames[(int)direction]); } else if (tokens.Length == 0 || (tokens.Length == 1 && player.Model.IsCommand(Command.Look, tokens[0]))) { command = RoomDisplayCommand.Refresh; player.Interface.DebugText("Player refreshing room view."); } else if (tokens.Length > 0) { command = RoomDisplayCommand.Move; direction = player.Model.IsDirectionCommand(tokens[0]); if (direction == null && player.RoomDetectionState == RoomDetectionState.HaveMatch) { var exits = (from e in player.LastSeenRoom.Match.GetExits() from me in player.Model.Messages from msg in me.Messages() where e.ExitType == ExitType.Text && me.Number == e.Parameter1 && msg.Equals(player.LastConfirmedCommand, StringComparison.InvariantCultureIgnoreCase) select e).ToList(); if (exits.Count == 1) { direction = exits[0].Direction; } } if (direction != null) { player.Interface.DebugText("Player moving " + player.Model.PlainExitNames[(int)direction]); } else { player.Interface.DebugText("Player moved, but I don't know what direction."); } } } }