コード例 #1
0
        private async Task ProcessDoorCommands(string output)
        {
            // process the command the player entered
            var splitOutput = output.Split(' ');

            if (splitOutput.Length != 1)
            {
                if (splitOutput[0] == "o")
                {
                    if (new[] { "n", "e", "s", "w" }.Contains(splitOutput[1]))
                    {
                        splitOutput = new[] { "o" + splitOutput[2] };
                    }
                    else
                    {
                        await Store.TcpSend.SendAsync($"open {string.Join(" ", splitOutput.Skip(1))}");

                        return;
                    }
                }
                else if (splitOutput[0] == "c")
                {
                    if (new[] { "n", "e", "s", "w" }.Contains(splitOutput[1]))
                    {
                        splitOutput = new[] { "s" + splitOutput[1] };
                    }
                    else
                    {
                        await Store.TcpSend.SendAsync($"close {string.Join(" ", splitOutput.Skip(1))}");

                        return;
                    }
                }
            }
            string command = splitOutput.First().ToLower();

            var commands = new HashSet <string> {
                "o", "c", "cll", "opp", "unl", "loc", "pic",
                "on", "oe", "os", "ow", "ou", "od",
                "sn", "se", "ss", "sw", "su", "sd",
                "locn", "loce", "locs", "locw", "locu", "locd",
                "unln", "unle", "unls", "unlw", "unlu", "unld",
                "picn", "pice", "pics", "pic", "picu", "picd",
            };

            if (!commands.Contains(command))
            {
                return;
            }


            // need a map window command to get all doors, and also to get doors in a direction

            // todo: this probably shouldn't be accessed from here
            var currentRoomExits = new ZmudDbExitTblRow[0];

            MapData.ExitsByFromRoom.TryGetValue(MapData.CurrentVirtualRoomId, out currentRoomExits);

            var exitsWithDoors = currentRoomExits.Where(exit => !string.IsNullOrEmpty(exit.Param)).ToArray();

            if (exitsWithDoors.Length == 0)
            {
                await Store.ClientInfo.SendAsync($"DOOR NOT FOUND FOR: {output}");
            }


            (string commandType, DirectionType direction, bool all) = ParseCommand(command);

            if (direction == DirectionType.Other)
            {
                if (all)
                {
                    foreach (var exit in exitsWithDoors)
                    {
                        await Store.TcpSend.SendAsync($"{commandType} {exit.Param}");
                    }
                }
                else
                {
                    // open the one door in the room
                    if (exitsWithDoors.Length == 1)
                    {
                        await Store.TcpSend.SendAsync($"{commandType} {exitsWithDoors[0].Param}");
                    }
                    else
                    {
                        await Store.ClientInfo.SendAsync($"MULTIPLE DOORS: {string.Join("|", exitsWithDoors.Select(e => e.Param))}");
                    }
                }
            }
            else
            {
                // open the door in the direction specified
                var exitsWithDoor = exitsWithDoors.Where(exit => exit.DirType == (int)direction).ToArray();
                if (exitsWithDoor.Length == 1)
                {
                    await Store.TcpSend.SendAsync($"{commandType} {exitsWithDoor[0].Param}");
                }
                else
                {
                    await Store.ClientInfo.SendAsync($"DOOR NOT FOUND FOR: {output}");
                }
            }
        }
コード例 #2
0
        private async Task MoveCurrentRoom(Room newRoom, Movement movement)
        {
            MapData.RoomsById.TryGetValue(MapData.CurrentRoomId, out var previousRoom);

            List <PossibleRoom> matchedRooms = new List <PossibleRoom>();

            if (newRoom != null)
            {
                matchedRooms            = PossibleRoomMatcher.FindPossibleRooms(newRoom);
                newRoom.PossibleRoomIds = matchedRooms.Select(r => r.RoomData.ObjID.Value).ToList();
            }

            if (!matchedRooms.Any())
            {
                await Store.ClientInfo.SendAsync("Map: No matching rooms found.");
            }
            if (matchedRooms.Count > 1)
            {
                await Store.ClientInfo.SendAsync("Map: Multiple matching rooms found.");
            }

            if (previousRoom != null && movement != null)
            {
                MapData.ExitsByFromRoom.TryGetValue(MapData.CurrentRoomId, out var previousRoomExits);


                ZmudDbExitTblRow exit = null;
                if (previousRoomExits != null)
                {
                    exit = previousRoomExits.FirstOrDefault(e => e.DirType.Value == (int)movement.DirectionType);
                }

                if (exit != null)
                {
                    int newRoomId = exit.ToID.Value;

                    if (matchedRooms.Any() && !matchedRooms.Any(mr => mr.RoomData.ObjID.Value == newRoomId))
                    {
                        await Store.ClientInfo.SendAsync("Map: Moved to new room but didn't match an expected found room");
                    }

                    // currently trust the map find more than the movement direction code
                    if (matchedRooms.Count == 1)
                    {
                        MapData.CurrentRoomId = matchedRooms[0].RoomData.ObjID.Value;
                    }
                    else
                    {
                        MapData.CurrentRoomId = newRoomId;
                    }

                    _map.Invalidate();
                    return;
                }
            }

            // didn't receive a direction - rely purely on map find

            if (matchedRooms.Any())
            {
                var previousRoomId = MapData.CurrentRoomId;
                MapData.CurrentRoomId = matchedRooms.First().RoomData.ObjID.Value;

                if (matchedRooms.Count > 1)
                {
                    await Store.ClientInfo.SendAsync("Map: Multiple matching rooms found.");

                    if (previousRoom != null)
                    {
                        var matchedAdjacentRooms = new List <int>();
                        MapData.ExitsByFromRoom.TryGetValue(previousRoom.ObjID.Value, out var previousRoomExits);
                        if (previousRoomExits != null)
                        {
                            var adjacentRoomIds = previousRoomExits.Select(previousExit => previousExit.ToID.Value);
                            matchedAdjacentRooms = matchedRooms.Select(r => r.RoomData.ObjID.Value).Intersect(adjacentRoomIds).ToList();
                        }

                        var matchesZone = matchedRooms.Where(r => r.RoomData.ZoneID.Value == previousRoom.ZoneID.Value).ToList();

                        if (matchedAdjacentRooms.Any())
                        {
                            MapData.CurrentRoomId = matchedAdjacentRooms.First();
                        }
                        else if (matchesZone.Any())
                        {
                            MapData.CurrentRoomId = matchesZone.First().RoomData.ObjID.Value;
                        }
                    }
                }

                // didn't recieve a direction so we should make the virtual room following the current room if we can
                if (previousRoomId == MapData.CurrentVirtualRoomId)
                {
                    MapData.CurrentVirtualRoomId = MapData.CurrentRoomId;
                }
            }
            else
            {
                await Store.ClientInfo.SendAsync("Map: No matching rooms found.");
            }
        }