Ejemplo n.º 1
0
        /// <summary>
        /// Returns the item information for the items with the given ID
        /// </summary>
        /// <param name="itemID">ID of the item</param>
        /// <returns>Item object containing all item information, or null if the itemName is invalid</returns>
        public GW2PAO.API.Data.Entities.Item GetItem(int itemID)
        {
            GW2PAO.API.Data.Entities.Item item = null;

            try
            {
                var itemService = LocalizationUtil.IsSupportedCulture() ? GW2.V2.Items.ForCurrentUICulture() : GW2.V2.Items.ForDefaultCulture();
                var itemDetails = itemService.Find(itemID);
                if (itemDetails != null)
                {
                    item                  = new Data.Entities.Item(itemID, itemDetails.Name);
                    item.Icon             = itemDetails.IconFileUrl;
                    item.Description      = itemDetails.Description;
                    item.Rarity           = (Data.Enums.ItemRarity)itemDetails.Rarity;
                    item.Flags            = (Data.Enums.ItemFlags)itemDetails.Flags;
                    item.GameTypes        = (Data.Enums.ItemGameTypes)itemDetails.GameTypes;
                    item.LevelRequirement = itemDetails.Level;
                    item.VenderValue      = itemDetails.VendorValue;
                    item.ChatCode         = itemDetails.GetItemChatLink().ToString();
                    item.Prices           = this.GetItemPrices(itemID);

                    // Since there is no need to use ALL details right now, we'll just get what we need...
                    // TODO: Finish this up, get all details, such as Type, SkinID
                }
            }
            catch (Exception ex)
            {
                // Don't crash, just return null
                logger.Warn("Error finding item with id {0}: {1}", itemID, ex);
            }

            return(item);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Retrieves the name of the zone using the given mapID
        /// </summary>
        /// <param name="mapId">The mapID of the zone to retrieve the name for</param>
        /// <returns>the name of the zone</returns>
        public string GetZoneName(int mapId)
        {
            if (mapId <= 0)
            {
                return("Unknown");
            }

            try
            {
                if (MapNamesCache.ContainsKey(mapId))
                {
                    return(MapNamesCache[mapId]);
                }
                else
                {
                    var map = LocalizationUtil.IsSupportedCulture() ? GW2.V2.Maps.ForCurrentUICulture().Find(mapId) : GW2.V2.Maps.ForDefaultCulture().Find(mapId);
                    if (map != null)
                    {
                        return(map.MapName);
                    }
                    else
                    {
                        return("Unknown");
                    }
                }
            }
            catch (Exception ex)
            {
                // Don't crash if something goes wrong, but log the error
                logger.Error(ex);
                return("Unknown");
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Retrieves the continent information for the given map ID
        /// </summary>
        /// <param name="mapId">The ID of a zone</param>
        /// <returns>The continent data</returns>
        public Data.Entities.Continent GetContinentByMap(int mapId)
        {
            Data.Entities.Continent result = null;

            if (this.MapContinentsCache.ContainsKey(mapId))
            {
                int continentId;
                this.MapContinentsCache.TryGetValue(mapId, out continentId);
                this.ContinentsCache.TryGetValue(continentId, out result);
            }

            if (result == null)
            {
                // If we didn't get the continent from our cache of Map ID -> Continent ID,
                // request the map info and add it our cache
                try
                {
                    var map = LocalizationUtil.IsSupportedCulture() ? GW2.V2.Maps.ForCurrentUICulture().Find(mapId) : GW2.V2.Maps.ForDefaultCulture().Find(mapId);
                    if (map != null)
                    {
                        this.MapContinentsCache.TryAdd(mapId, map.ContinentId);
                        this.ContinentsCache.TryGetValue(map.ContinentId, out result);
                    }
                }
                catch (Exception ex)
                {
                    // Don't crash if something goes wrong, but log the error
                    logger.Error(ex);
                }
            }

            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Retrieves map information using the provided continent coordinates,
        /// or null if the coordinates do not fall into any current zone
        /// </summary>
        /// <param name="continentId">ID of the continent that the coordinates are for</param>
        /// <param name="continentCoordinates">Continent coordinates to use</param>
        /// <returns>The map data, or null if not found</returns>
        public Data.Entities.Map GetMap(int continentId, Point continentCoordinates)
        {
            var continent    = this.GetContinent(continentId);
            var floorService = LocalizationUtil.IsSupportedCulture() ? GW2.V1.Floors.ForCurrentUICulture(continentId) : GW2.V1.Floors.ForDefaultCulture(continentId);

            var floor = this.GetFloor(continentId, continent.FloorIds.First());

            if (floor != null && floor.Regions != null)
            {
                foreach (var region in floor.Regions.Values)
                {
                    foreach (var map in region.Maps.Values)
                    {
                        if (continentCoordinates.X >= map.ContinentRectangle.X &&
                            continentCoordinates.X <= (map.ContinentRectangle.X + map.ContinentRectangle.Width) &&
                            continentCoordinates.Y >= map.ContinentRectangle.Y &&
                            continentCoordinates.Y <= (map.ContinentRectangle.Y + map.ContinentRectangle.Height))
                        {
                            Data.Entities.Map mapData = new Data.Entities.Map(map.MapId);

                            mapData.MaxLevel     = map.MaximumLevel;
                            mapData.MinLevel     = map.MinimumLevel;
                            mapData.DefaultFloor = map.DefaultFloor;

                            mapData.ContinentId = continent.Id;
                            mapData.RegionId    = region.RegionId;
                            mapData.RegionName  = region.Name;

                            mapData.MapRectangle.X      = map.MapRectangle.X;
                            mapData.MapRectangle.Y      = map.MapRectangle.Y;
                            mapData.MapRectangle.Height = map.MapRectangle.Height;
                            mapData.MapRectangle.Width  = map.MapRectangle.Width;

                            mapData.ContinentRectangle.X      = map.ContinentRectangle.X;
                            mapData.ContinentRectangle.Y      = map.ContinentRectangle.Y;
                            mapData.ContinentRectangle.Height = map.ContinentRectangle.Height;
                            mapData.ContinentRectangle.Width  = map.ContinentRectangle.Width;

                            // Done - return the data
                            return(mapData);
                        }
                    }
                }
            }

            // Not found
            return(null);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns the item information for the items with the given IDs
        /// </summary>
        /// <param name="itemIDs">IDs of the items to retrieve</param>
        /// <returns>Collection of Item objects containing all item information</returns>
        public IDictionary <int, GW2PAO.API.Data.Entities.Item> GetItems(ICollection <int> itemIDs)
        {
            Dictionary <int, GW2PAO.API.Data.Entities.Item> items = new Dictionary <int, GW2PAO.API.Data.Entities.Item>();

            try
            {
                // Remove all items with itemID of 0 or less
                var validIDs = itemIDs.Where(id => id > 0).ToList();

                var itemService = LocalizationUtil.IsSupportedCulture() ? GW2.V2.Items.ForCurrentUICulture() : GW2.V2.Items.ForDefaultCulture();
                var itemDetails = itemService.FindAll(validIDs);
                var prices      = this.GetItemPrices(validIDs);

                foreach (var itemDetail in itemDetails)
                {
                    GW2PAO.API.Data.Entities.Item item = new Data.Entities.Item(itemDetail.Key, itemDetail.Value.Name);
                    item.Icon             = itemDetail.Value.IconFileUrl;
                    item.Description      = itemDetail.Value.Description;
                    item.Rarity           = (Data.Enums.ItemRarity)itemDetail.Value.Rarity;
                    item.Flags            = (Data.Enums.ItemFlags)itemDetail.Value.Flags;
                    item.GameTypes        = (Data.Enums.ItemGameTypes)itemDetail.Value.GameTypes;
                    item.LevelRequirement = itemDetail.Value.Level;
                    item.VenderValue      = itemDetail.Value.VendorValue;
                    item.ChatCode         = itemDetail.Value.GetItemChatLink().ToString();
                    if (prices.ContainsKey(item.ID))
                    {
                        item.Prices = prices[item.ID];
                    }
                    else
                    {
                        item.Prices = new ItemPrices(); // empty, no prices found
                    }
                    // Since there is no need to use ALL details right now, we'll just get what we need...
                    // TODO: Finish this up, get all details, such as Type, SkinID

                    items.Add(item.ID, item);
                }
            }
            catch (Exception ex)
            {
                // Don't crash, just return null
                logger.Warn(ex, "Error finding item");
            }

            return(items);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Retrieves the map information for the given map ID
        /// </summary>
        /// <param name="mapId">The ID of a zone</param>
        /// <returns>The map data</returns>
        public Data.Entities.Map GetMap(int mapId)
        {
            try
            {
                // Get the current map info
                var map = LocalizationUtil.IsSupportedCulture() ? GW2.V2.Maps.ForCurrentUICulture().Find(mapId) : GW2.V2.Maps.ForDefaultCulture().Find(mapId);
                if (map != null)
                {
                    Data.Entities.Map m = new Data.Entities.Map(mapId);

                    m.MaxLevel     = map.MaximumLevel;
                    m.MinLevel     = map.MinimumLevel;
                    m.DefaultFloor = map.DefaultFloor;

                    m.ContinentId = map.ContinentId;
                    m.RegionId    = map.RegionId;
                    m.RegionName  = map.RegionName;

                    m.MapRectangle.X      = map.MapRectangle.X;
                    m.MapRectangle.Y      = map.MapRectangle.Y;
                    m.MapRectangle.Height = map.MapRectangle.Height;
                    m.MapRectangle.Width  = map.MapRectangle.Width;

                    m.ContinentRectangle.X      = map.ContinentRectangle.X;
                    m.ContinentRectangle.Y      = map.ContinentRectangle.Y;
                    m.ContinentRectangle.Height = map.ContinentRectangle.Height;
                    m.ContinentRectangle.Width  = map.ContinentRectangle.Width;

                    return(m);
                }
            }
            catch (Exception ex)
            {
                // Don't crash if something goes wrong, but log the error
                logger.Error(ex);
            }

            return(null);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Initializes the zone service
        /// </summary>
        public void Initialize()
        {
            if (Monitor.TryEnter(this.initLock))
            {
                try
                {
                    if (this.MapNamesCache.IsEmpty)
                    {
                        foreach (var mapName in LocalizationUtil.IsSupportedCulture() ? GW2.V2.Maps.ForCurrentUICulture().FindAll() : GW2.V2.Maps.ForDefaultCulture().FindAll())
                        {
                            this.MapNamesCache.TryAdd(mapName.Key, mapName.Value.MapName);
                        }
                    }

                    if (this.ContinentsCache.IsEmpty)
                    {
                        // Get all continents
                        var continents = LocalizationUtil.IsSupportedCulture() ? GW2.V2.Continents.ForCurrentUICulture().FindAll() : GW2.V2.Continents.ForDefaultCulture().FindAll();

                        foreach (var continent in continents.Values)
                        {
                            Data.Entities.Continent cont = new Data.Entities.Continent(continent.ContinentId);
                            cont.Name     = continent.Name;
                            cont.Height   = continent.ContinentDimensions.Height;
                            cont.Width    = continent.ContinentDimensions.Width;
                            cont.FloorIds = continent.FloorIds;
                            cont.MaxZoom  = continent.MaximumZoom;
                            cont.MinZoom  = continent.MinimumZoom;
                            this.ContinentsCache.TryAdd(cont.Id, cont);
                        }
                    }
                }
                finally
                {
                    Monitor.Exit(this.initLock);
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Retrieves the floor data for the given floor ID, using the internal cache when possible
        /// </summary>
        /// <param name="continentId">ID of the continent the floor is for</param>
        /// <param name="floorId">ID of the floor to retrieve</param>
        /// <returns>The floor data</returns>
        private GW2NET.Maps.Floor GetFloor(int continentId, int floorId)
        {
            GW2NET.Maps.Floor result = null;

            var key = new Tuple <int, int>(continentId, floorId);

            if (this.FloorCache.ContainsKey(key))
            {
                this.FloorCache.TryGetValue(key, out result);
            }
            else
            {
                var floorService = LocalizationUtil.IsSupportedCulture() ? GW2.V1.Floors.ForCurrentUICulture(continentId) : GW2.V1.Floors.ForDefaultCulture(continentId);
                var floor        = floorService.Find(floorId);
                if (floor != null)
                {
                    this.FloorCache.TryAdd(key, floor);
                    result = floor;
                }
            }

            return(result);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Loads the WvW objects  and initializes all cached information
        /// </summary>
        public void LoadData()
        {
            try
            {
                logger.Info("Loading worlds via API");
                this.Worlds = new List <World>();
                var worldRepository = LocalizationUtil.IsSupportedCulture() ? GW2.V2.Worlds.ForCurrentUICulture() : GW2.V2.Worlds.ForDefaultCulture();
                var worlds          = worldRepository.FindAll();
                foreach (var world in worlds.Values)
                {
                    this.Worlds.Add(new World()
                    {
                        ID   = world.WorldId,
                        Name = world.Name
                    });
                }
            }
            catch (Exception ex)
            {
                logger.Error("Failed to load worlds data: ");
                logger.Error(ex);
            }

            logger.Info("Loading Objectives Table");
            try
            {
                this.ObjectivesTable = WvWObjectivesTable.LoadTable();
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                logger.Info("Error loading Objectives Table, re-creating table");
                WvWObjectivesTable.CreateTable();
                this.ObjectivesTable = WvWObjectivesTable.LoadTable();
            }
        }
Ejemplo n.º 10
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.GetContinents();

                // Get the current map info
                var map = LocalizationUtil.IsSupportedCulture() ? GW2.V2.Maps.ForCurrentUICulture().Find(mapId) : GW2.V2.Maps.ForDefaultCulture().Find(mapId);
                if (map != null)
                {
                    // Retrieve details of items on every floor of the map
                    foreach (var floorId in map.Floors)
                    {
                        var floor = this.GetFloor(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];
                                    var continentRectangle = new Rectangle()
                                    {
                                        X      = regionMap.ContinentRectangle.X,
                                        Y      = regionMap.ContinentRectangle.Y,
                                        Height = regionMap.ContinentRectangle.Height,
                                        Width  = regionMap.ContinentRectangle.Width
                                    };
                                    var mapRectangle = new Rectangle()
                                    {
                                        X      = regionMap.MapRectangle.X,
                                        Y      = regionMap.MapRectangle.Y,
                                        Height = regionMap.MapRectangle.Height,
                                        Width  = regionMap.MapRectangle.Width
                                    };

                                    // 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(
                                                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             = mapId;
                                            zoneItem.MapName           = map.MapName;
                                            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;
                                            }

                                            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(
                                                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             = 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(
                                            continentRectangle,
                                            mapRectangle,
                                            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.ContinentLocation = new Point(skillChallenge.Coordinates.X, skillChallenge.Coordinates.Y);
                                            zoneItem.Location          = new Point(location.X, location.Y);
                                            zoneItem.MapId             = mapId;
                                            zoneItem.MapName           = map.MapName;
                                            zoneItem.Type = Data.Enums.ZoneItemType.HeroPoint;

                                            zoneItems.Add(zoneItem);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // Don't crash if something goes wrong, but log the error
                logger.Error(ex);
            }
            return(zoneItems);
        }