Example #1
0
        // unused - using ProcessMovementReceived instead
        private async Task FindFoundRoomId(Room room)
        {
            var possibleRooms = PossibleRoomMatcher.FindPossibleRooms(room);

            room.PossibleRoomIds = possibleRooms.Select(r => r.RoomData.ObjID.Value).ToList();

            if (possibleRooms.Any())
            {
                _foundRoomId = possibleRooms.First().RoomData.ObjID.Value;

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

                    MapData.RoomsById.TryGetValue(MapData.CurrentRoomId, out var previousRoom);
                    if (previousRoom != null)
                    {
                        // if there are multiple rooms try to pick a match in the same ZoneId
                        var matchesZone = possibleRooms.Where(r => r.RoomData.ZoneID.Value == previousRoom.ZoneID.Value).ToList();

                        // todo: if there is more than one match then prefer matching rooms close to the previous room
                        if (matchesZone.Any())
                        {
                            _foundRoomId = matchesZone.First().RoomData.ObjID.Value;
                        }
                    }
                }
            }
            else
            {
                await Store.ClientInfo.SendAsync("Map: No matching rooms found.");
            }
        }
Example #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.");
            }
        }