Exemplo n.º 1
0
        public void ConvertToMapPos_ConvertToWorldPos_Equals_OriginalInput_WithZoom()
        {
            int x            = random.Next();
            int y            = random.Next();
            var mapRectangle = new Data.Entities.Rectangle()
            {
                X = x, Y = y, Width = 100, Height = 100
            };

            x = random.Next();
            y = random.Next();
            var continentRectangle = new Data.Entities.Rectangle()
            {
                X = x, Y = y, Width = 100, Height = 100
            };

            int maxZoom = random.Next();

            Point inputPoint = new Point(
                random.Next((int)continentRectangle.X, (int)(continentRectangle.X + continentRectangle.Width)),
                random.Next((int)continentRectangle.Y, (int)(continentRectangle.Y + continentRectangle.Height)));

            Point mapPos   = MapsHelper.ConvertToMapPos(continentRectangle, mapRectangle, inputPoint, maxZoom / 2, maxZoom);
            Point worldPos = MapsHelper.ConvertToWorldPos(continentRectangle, mapRectangle, mapPos, maxZoom / 2, maxZoom);

            Assert.AreEqual(inputPoint.X, worldPos.X, 0.5);
            Assert.AreEqual(inputPoint.Y, worldPos.Y, 0.5);
            Assert.AreEqual(inputPoint.Z, worldPos.Z, 0.5);
        }
Exemplo n.º 2
0
        public void ConvertToMapPos_ConvertToWorldPos_Equals_OriginalInput_WithZoom()
        {
            Map testMap = new Map();
            int x       = random.Next();
            int y       = random.Next();

            testMap.MapRectangle = new Rectangle(new Vector2D(x, y), new Vector2D(random.Next(x, int.MaxValue), random.Next(y, int.MaxValue)));
            x = random.Next();
            y = random.Next();
            testMap.ContinentRectangle = new Rectangle(new Vector2D(x, y), new Vector2D(random.Next(x, int.MaxValue), random.Next(y, int.MaxValue)));
            testMap.Continent          = new Continent();

            testMap.MaximumLevel = random.Next();

            Point inputPoint = new Point(
                random.Next((int)testMap.ContinentRectangle.X, (int)(testMap.ContinentRectangle.X + testMap.ContinentRectangle.Width)),
                random.Next((int)testMap.ContinentRectangle.Y, (int)(testMap.ContinentRectangle.Y + testMap.ContinentRectangle.Height)));

            Point mapPos   = MapsHelper.ConvertToMapPos(testMap, inputPoint, testMap.MaximumLevel / 2);
            Point worldPos = MapsHelper.ConvertToWorldPos(testMap, mapPos, testMap.MaximumLevel / 2);

            Assert.AreEqual(inputPoint.X, worldPos.X, 0.5);
            Assert.AreEqual(inputPoint.Y, worldPos.Y, 0.5);
            Assert.AreEqual(inputPoint.Z, worldPos.Z, 0.5);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Retrieves a collection of ZoneItems located in the zone with the given mapID
        /// </summary>
        /// <param name="mapId">The mapID of the zone to retrieve zone items for</param>
        /// <returns>a collection of ZoneItems located in the zone with the given mapID</returns>
        public IEnumerable <ZoneItem> GetZoneItems(int mapId)
        {
            List <ZoneItem> zoneItems = new List <ZoneItem>();

            try
            {
                // Get the continents (used later in determining the location of items)
                var continents = this.service.GetContinents();

                // Get the current map info
                var map = this.service.GetMap(mapId);
                if (map != null)
                {
                    // Find the map's continent
                    var continent = continents[map.ContinentId];
                    map.Continent = continent;

                    // Retrieve details of items on every floor of the map
                    foreach (var floorId in map.Floors)
                    {
                        var floor = this.service.GetMapFloor(map.ContinentId, floorId);
                        if (floor != null && floor.Regions != null)
                        {
                            // Find the region that this map is located in
                            var region = floor.Regions.Values.FirstOrDefault(r => r.Maps.ContainsKey(mapId));
                            if (region != null)
                            {
                                if (region.Maps.ContainsKey(mapId))
                                {
                                    var regionMap = region.Maps[mapId];

                                    // Points of Interest
                                    foreach (var item in regionMap.PointsOfInterest)
                                    {
                                        // If we haven't already added the item, get it's info and add it
                                        if (!zoneItems.Any(zi => zi.ID == item.PointOfInterestId))
                                        {
                                            // Determine the location
                                            var location = MapsHelper.ConvertToMapPos(map, new Point(item.Coordinates.X, item.Coordinates.Y));

                                            ZoneItem zoneItem = new ZoneItem();
                                            zoneItem.ID       = item.PointOfInterestId;
                                            zoneItem.Name     = item.Name;
                                            zoneItem.Location = new Point(location.X, location.Y);
                                            zoneItem.MapId    = mapId;
                                            zoneItem.MapName  = map.MapName;
                                            var mapChatLink = item.GetMapChatLink();
                                            if (mapChatLink != null)
                                            {
                                                zoneItem.ChatCode = mapChatLink.ToString();
                                            }

                                            // Translate the item's type
                                            if (item is GW2DotNET.Entities.Maps.Vista)
                                            {
                                                zoneItem.Type = ZoneItemType.Vista;
                                            }
                                            else if (item is GW2DotNET.Entities.Maps.Waypoint)
                                            {
                                                zoneItem.Type = ZoneItemType.Waypoint;
                                            }
                                            else if (item is GW2DotNET.Entities.Maps.Dungeon)
                                            {
                                                zoneItem.Type = ZoneItemType.Dungeon;
                                            }
                                            else
                                            {
                                                zoneItem.Type = ZoneItemType.PointOfInterest;
                                            }

                                            zoneItems.Add(zoneItem);
                                        }
                                    }

                                    // Iterate over every Task in the map (Tasks are the same as HeartQuests)
                                    foreach (var task in regionMap.Tasks)
                                    {
                                        // If we haven't already added the item, get it's info and add it
                                        if (!zoneItems.Any(zi => zi.ID == task.TaskId))
                                        {
                                            // Determine the location
                                            var location = MapsHelper.ConvertToMapPos(map, new Point(task.Coordinates.X, task.Coordinates.Y));

                                            ZoneItem zoneItem = new ZoneItem();
                                            zoneItem.ID       = task.TaskId;
                                            zoneItem.Name     = task.Objective;
                                            zoneItem.Level    = task.Level;
                                            zoneItem.Location = new Point(location.X, location.Y);
                                            zoneItem.MapId    = mapId;
                                            zoneItem.MapName  = map.MapName;
                                            zoneItem.Type     = ZoneItemType.HeartQuest;

                                            zoneItems.Add(zoneItem);
                                        }
                                    }

                                    // Iterate over every skill challenge in the map
                                    foreach (var skillChallenge in regionMap.SkillChallenges)
                                    {
                                        // Determine the location, this serves an internally-used ID for skill challenges
                                        var location = MapsHelper.ConvertToMapPos(map, new Point(skillChallenge.Coordinates.X, skillChallenge.Coordinates.Y));

                                        // Use a custom-generated ID
                                        int id = (int)(mapId + location.X + location.Y);

                                        // If we havn't already added the item, get it's info and add it
                                        if (!zoneItems.Any(zi => zi.ID == id))
                                        {
                                            ZoneItem zoneItem = new ZoneItem();
                                            zoneItem.ID       = id;
                                            zoneItem.Location = new Point(location.X, location.Y);
                                            zoneItem.MapId    = mapId;
                                            zoneItem.MapName  = map.MapName;
                                            zoneItem.Type     = Data.Enums.ZoneItemType.SkillChallenge;

                                            zoneItems.Add(zoneItem);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // Don't crash if something goes wrong, but log the error
                logger.Error(ex);
            }
            return(zoneItems);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Retrieves a collection of zone items located in the given continent
        /// </summary>
        /// <param name="continentId">ID of the continent</param>
        /// <returns></returns>
        public IEnumerable <ZoneItem> GetZoneItemsByContinent(int continentId)
        {
            ConcurrentDictionary <int, ZoneItem> pointsOfInterest = new ConcurrentDictionary <int, ZoneItem>();
            ConcurrentDictionary <int, ZoneItem> tasks            = new ConcurrentDictionary <int, ZoneItem>();
            ConcurrentDictionary <int, ZoneItem> heroPoints       = new ConcurrentDictionary <int, ZoneItem>();

            try
            {
                // Get the continents (used later in determining the location of items)
                var continent = this.GetContinent(continentId);

                Parallel.ForEach(continent.FloorIds, floorId =>
                {
                    var floor = this.GetFloor(continentId, floorId);
                    if (floor != null && floor.Regions != null)
                    {
                        foreach (var region in floor.Regions)
                        {
                            foreach (var subRegion in region.Value.Maps)
                            {
                                var continentRectangle = new Rectangle()
                                {
                                    X      = subRegion.Value.ContinentRectangle.X,
                                    Y      = subRegion.Value.ContinentRectangle.Y,
                                    Height = subRegion.Value.ContinentRectangle.Height,
                                    Width  = subRegion.Value.ContinentRectangle.Width
                                };
                                var mapRectangle = new Rectangle()
                                {
                                    X      = subRegion.Value.MapRectangle.X,
                                    Y      = subRegion.Value.MapRectangle.Y,
                                    Height = subRegion.Value.MapRectangle.Height,
                                    Width  = subRegion.Value.MapRectangle.Width
                                };

                                // Points of Interest
                                foreach (var item in subRegion.Value.PointsOfInterest)
                                {
                                    // If we haven't already added the item, get it's info and add it
                                    if (!pointsOfInterest.ContainsKey(item.PointOfInterestId))
                                    {
                                        // Determine the location
                                        var location = MapsHelper.ConvertToMapPos(
                                            continentRectangle,
                                            mapRectangle,
                                            new Point(item.Coordinates.X, item.Coordinates.Y));

                                        ZoneItem zoneItem          = new ZoneItem();
                                        zoneItem.ID                = item.PointOfInterestId;
                                        zoneItem.Name              = item.Name;
                                        zoneItem.ContinentLocation = new Point(item.Coordinates.X, item.Coordinates.Y);
                                        zoneItem.Location          = new Point(location.X, location.Y);
                                        zoneItem.MapId             = subRegion.Value.MapId;
                                        zoneItem.MapName           = this.MapNamesCache[subRegion.Value.MapId];
                                        var mapChatLink            = item.GetMapChatLink();
                                        if (mapChatLink != null)
                                        {
                                            zoneItem.ChatCode = mapChatLink.ToString();
                                        }

                                        // Translate the item's type
                                        if (item is GW2NET.Maps.Vista)
                                        {
                                            zoneItem.Type = ZoneItemType.Vista;
                                        }
                                        else if (item is GW2NET.Maps.Waypoint)
                                        {
                                            zoneItem.Type = ZoneItemType.Waypoint;
                                        }
                                        else if (item is GW2NET.Maps.Dungeon)
                                        {
                                            zoneItem.Type = ZoneItemType.Dungeon;
                                        }
                                        else
                                        {
                                            zoneItem.Type = ZoneItemType.PointOfInterest;
                                        }

                                        if (!pointsOfInterest.TryAdd(zoneItem.ID, zoneItem))
                                        {
                                            logger.Warn("Failed to add {0} to PointsOfInterest collection", zoneItem);
                                        }
                                    }
                                }

                                // Iterate over every Task in the map (Tasks are the same as HeartQuests)
                                foreach (var task in subRegion.Value.Tasks)
                                {
                                    // If we haven't already added the item, get it's info and add it
                                    if (!tasks.ContainsKey(task.TaskId))
                                    {
                                        // Determine the location
                                        var location = MapsHelper.ConvertToMapPos(
                                            continentRectangle,
                                            mapRectangle,
                                            new Point(task.Coordinates.X, task.Coordinates.Y));

                                        ZoneItem zoneItem          = new ZoneItem();
                                        zoneItem.ID                = task.TaskId;
                                        zoneItem.Name              = task.Objective;
                                        zoneItem.Level             = task.Level;
                                        zoneItem.ContinentLocation = new Point(task.Coordinates.X, task.Coordinates.Y);
                                        zoneItem.Location          = new Point(location.X, location.Y);
                                        zoneItem.MapId             = subRegion.Value.MapId;
                                        zoneItem.MapName           = this.MapNamesCache[subRegion.Value.MapId];
                                        zoneItem.Type              = ZoneItemType.HeartQuest;

                                        if (!tasks.TryAdd(zoneItem.ID, zoneItem))
                                        {
                                            logger.Warn("Failed to add {0} to Tasks collection", zoneItem);
                                        }
                                    }
                                }

                                // Iterate over every skill challenge in the map
                                foreach (var skillChallenge in subRegion.Value.SkillChallenges)
                                {
                                    // Determine the location, this serves an internally-used ID for skill challenges
                                    var location = MapsHelper.ConvertToMapPos(
                                        continentRectangle,
                                        mapRectangle,
                                        new Point(skillChallenge.Coordinates.X, skillChallenge.Coordinates.Y));

                                    // Use a custom-generated ID
                                    int id = (int)(subRegion.Value.MapId + location.X + location.Y);

                                    // If we havn't already added the item, get it's info and add it
                                    if (!heroPoints.ContainsKey(id))
                                    {
                                        ZoneItem zoneItem          = new ZoneItem();
                                        zoneItem.ID                = id;
                                        zoneItem.ContinentLocation = new Point(skillChallenge.Coordinates.X, skillChallenge.Coordinates.Y);
                                        zoneItem.Location          = new Point(location.X, location.Y);
                                        zoneItem.MapId             = subRegion.Value.MapId;
                                        zoneItem.MapName           = this.MapNamesCache[subRegion.Value.MapId];
                                        zoneItem.Type              = Data.Enums.ZoneItemType.HeroPoint;

                                        if (!heroPoints.TryAdd(zoneItem.ID, zoneItem))
                                        {
                                            logger.Warn("Failed to add {0} to HeroPoints collection", zoneItem);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    logger.Debug("{0}-{1} done", continentId, floorId);
                });
            }
            catch (Exception ex)
            {
                // Don't crash if something goes wrong, but log the error
                logger.Error(ex);
            }
            return(pointsOfInterest.Values.Concat(tasks.Values).Concat(heroPoints.Values));
        }