public override bool Equals(object obj) { if (obj != null && obj is ZoneItem) { ZoneItem other = obj as ZoneItem; return((other.ID == this.ID) && (other.Name == this.Name) && (other.Type == this.Type) && (other.MapId == this.MapId) && (other.MapName == this.MapName) && (other.Level == this.Level) && (other.ContinentLocation.X == this.ContinentLocation.X) && (other.ContinentLocation.Y == this.ContinentLocation.Y) && (other.ContinentLocation.Z == this.ContinentLocation.Z) && (other.Location.X == this.Location.X) && (other.Location.Y == this.Location.Y) && (other.Location.Z == this.Location.Z)); } else { return(false); } }
/// <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].Name; 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].Name; 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].Name; 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); }
/// <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 = GW2.V2.Continents.ForCurrentUICulture().FindAll(); // Get the current map info var map = GW2.V2.Maps.ForCurrentUICulture().Find(mapId); if (map != null) { // Find the map's continent var continent = continents[map.ContinentId]; map.Continent = continent; var floorService = GW2.V1.Floors.ForCurrentUICulture(map.ContinentId); // Retrieve details of items on every floor of the map foreach (var floorId in map.Floors) { var floor = floorService.Find(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 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(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.HeroPoint; zoneItems.Add(zoneItem); } } } } } } } } catch (Exception ex) { // Don't crash if something goes wrong, but log the error logger.Error(ex); } return zoneItems; }
/// <summary> /// Default constructor /// </summary> /// <param name="zoneItem">The zone item/point's information</param> /// <param name="userData">User data</param> public ZoneItemViewModel(ZoneItem zoneItem, IPlayerService playerService, ZoneCompletionUserData userData) { this.DistanceFromPlayer = -1; this.ItemModel = zoneItem; this.playerService = playerService; this.userData = userData; this.userData.PropertyChanged += (o, e) => this.RefreshVisibility(); // Set up handling for collection changed events on the unlocked zone items collections foreach (CharacterZoneItems charItems in this.userData.UnlockedZoneItems) { charItems.ZoneItems.CollectionChanged += UnlockedZoneItems_CollectionChanged; } this.userData.UnlockedZoneItems.CollectionChanged += (o, e) => { if (e.Action == NotifyCollectionChangedAction.Add) { foreach (CharacterZoneItems itemAdded in e.NewItems) { itemAdded.ZoneItems.CollectionChanged += UnlockedZoneItems_CollectionChanged; } } }; this.userData.UnlockedZoneItems.CollectionChanged += UnlockedZoneItems_CollectionChanged; this.RefreshVisibility(); }