Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #3
0
        public async void ButtonSearchRouteTapped(object sender, TappedRoutedEventArgs e)
        {
            var options = new MapOptions
            {
                ShowTraffic = true,
                ViewStyle   = MapViewStyle.Aerial
            };

            await MapsHelper.SearchDirectionsAsync(new MapAddress("Montreal"), new MapAddress("Ottawa"), options);
        }
        public bool Load(string mapName)
        {
            var zoneMap = MapsHelper.GetMap(mapName);

            if (zoneMap == null)
            {
                Host.Log($"Could not load zone map: {mapName}");

                return(false);
            }


            bool success = false;

            switch (zoneMap.MapUseType)
            {
            case MapUseType.Local:
                success = LoadDataBase(zoneMap.GetMapPath());

                if (zoneMap.MeshExists())
                {
                    Host.LoadNavMesh(zoneMap.GetMeshPath(), false);
                }

                break;

            case MapUseType.Internal:
                success = LoadDataBase(zoneMap.GetByteMap());

                if (zoneMap.MeshExists())
                {
                    Host.LoadNavMesh(zoneMap.GetByteMesh(), false);
                }

                break;
            }


            if (success)
            {
                if (zoneMap.MeshExists())
                {
                    MeshEnabled = true;
                }

                IsLoaded = true;

                return(true);
            }

            return(false);
        }
Beispiel #5
0
    public bool InitWithMapIdx(int mapIdx)
    {
        m_mapIdx = mapIdx;
        var mapPaths = WorldControl.GetInstance().MapList.GetMapPaths(mapIdx);

        if (mapPaths == null)
        {
            m_textMapName.text = $"MISSING {mapIdx}";
            SetIconSprite(MapsHelper.GetDefaultIcon());
            return(false);
        }

        m_textMapName.text = mapPaths.Name;
        SetIconSprite(mapPaths.GetMapIcon());
        return(true);
    }
        private void cmbox_ZoneMaps_SelectedIndexChanged(object sender, EventArgs e)
        {
            Utils.InvokeOn(this, () =>
            {
                int index = cmbox_ZoneMaps.SelectedIndex;

                // Clear box
                lbox_GpsPoints.Items.Clear();

                if (index == 0)
                {
                    return;
                }


                var mapName = cmbox_ZoneMaps.SelectedItem.ToString();
                var map     = MapsHelper.GetMap(mapName);

                if (map == null)
                {
                    return;
                }


                var gps = new Gps(Host);

                switch (map.MapUseType)
                {
                case MapUseType.Local:
                    gps.LoadDataBase(map.GetMapPath());
                    break;

                case MapUseType.Internal:
                    gps.LoadDataBase(map.GetByteMap());
                    break;
                }


                var points = gps.GetAllGpsPoints().Where
                                 (p => p.name.Contains("Fight")).Select(p => p.name + " : " + p.radius);

                if (points.Count() > 0)
                {
                    lbox_GpsPoints.Items.AddRange(points.ToArray());
                }
            });
        }
Beispiel #7
0
        // private static void UpdateSizes(Product product)
        // {
        //     var sizesToRemove = new List<ISizeMapNode>();
        //     Log.WriteLog(
        //         $"Getting size map for: [Resource - {product.Resource}], [Brand - {product.Brand}], [Gender - {product.Gender}]");
        //
        //     var sizeMap = MapsHelper.GetSizesMap(product.Resource, product.Brand, product.Gender);
        //
        //     foreach (var size in product.ShoesSizeMap)
        //     {
        //         if (sizeMap.ContainsKey(size.ExternalSize))
        //         {
        //             size.InternalSize = size.ExternalSize;
        //
        //             var dbSizeId = MapsHelper.GetSizeDbId(size.InternalSize);
        //
        //             if (dbSizeId == default)
        //             {
        //                 throw new InnerException(product.InternalId,
        //                     $"No OptionValueId (Id in DB) found for {size.InternalSize}");
        //             }
        //
        //             size.OptionValueId = dbSizeId;
        //             continue;
        //         }
        //
        //         Log.WriteLog($"[NO SIZE NODE FOUND] No size map node found for {size.ExternalSize}");
        //         sizesToRemove.Add(size);
        //     }
        //
        //     //Remove not founded map nodes.
        //     if (sizesToRemove.Count > 0)
        //     {
        //         Log.WriteLog($"ERROR - Sizes not founded in size map: {string.Join(", ", sizesToRemove.Select(x => x.ExternalSize))}");
        //         sizesToRemove.ForEach(x => product.ShoesSizeMap.Remove(x));
        //     }
        // }

        private static void UpdateSizesWithExternal(Product product)
        {
            foreach (var size in product.ShoesSizeMap)
            {
                size.InternalSize = size.ExternalSize;

                var dbSizeId = MapsHelper.GetSizeDbId(size.InternalSize);

                if (dbSizeId == default)
                {
                    throw new InnerException(product.InternalId,
                                             $"No OptionValueId (Id in DB) found for {size.InternalSize}");
                }

                size.OptionValueId = dbSizeId;
            }
        }
        private void GetZoneMaps()
        {
            var maps = MapsHelper.GetAll().Select(m => m.Name);

            Utils.InvokeOn(this, () =>
            {
                cmbox_ZoneMaps.Items.Clear();
                cmbox_ZoneMaps.Items.Add("No map selected");

                if (maps.Count() > 0)
                {
                    cmbox_ZoneMaps.Items.AddRange(maps.ToArray());
                }

                cmbox_ZoneMaps.SelectedIndex = 0;
            });
        }
Beispiel #9
0
        private void GetMiningZones()
        {
            var zones = MapsHelper.GetAll().Select(m => m.Name).OrderBy(m => m);

            if (zones.Count() < 1)
            {
                return;
            }


            Utils.InvokeOn(this, () =>
            {
                cmbox_ZonesList.Items.Clear();
                cmbox_ZonesList.Items.AddRange(zones.ToArray());
                cmbox_ZonesList.SelectedIndex = 0;
            });
        }
Beispiel #10
0
    private void Awake()
    {
        if (m_checkpoints != null && m_checkpoints.Any())
        {
            for (int i = 0; i < m_checkpoints.Count; ++i)
            {
                m_checkpoints[i].SetIdx(i);
            }
        }

        if (m_miniImage = null)
        {
            m_miniImage = MapsHelper.GetDefaultMiniMap();
        }

        if (m_mapIcon = null)
        {
            m_mapIcon = MapsHelper.GetDefaultIcon();
        }
    }
        public bool Load(string mapName)
        {
            var zoneMap = MapsHelper.GetMap(mapName);

            if (zoneMap == null)
            {
                Host.Log("Failed to acquire zone map!");
                return(false);
            }

            if (!zoneMap.MeshExists())
            {
                Host.Log("Failed to load or missing mesh map!");
                return(false);
            }


            bool success = false;

            switch (zoneMap.MapUseType)
            {
            case MapUseType.Local:
                success = LoadDataBase(zoneMap.GetMapPath());
                Host.LoadNavMesh(zoneMap.GetMeshPath(), false);
                break;

            case MapUseType.Internal:
                success = LoadDataBase(zoneMap.GetByteMap());
                Host.LoadNavMesh(zoneMap.GetByteMesh(), false);
                break;
            }

            if (success)
            {
                MeshEnabled = true;
                return(true);
            }

            return(false);
        }
Beispiel #12
0
        private static void UpdatePrice(Product product)
        {
            var currencyValue = MapsHelper.GetCurrencyValue(product.Resource);

            Log.WriteLog(
                $"{product.Resource} currency to UAH value: {currencyValue}");

            var usdCurrencyValue = MapsHelper.GetCurrencyValue(Currency.USD);

            double commonExternalPrice;

            if (product.Resource == Resource.Goat || product.Resource == Resource.StockX)
            {
                foreach (var sizeMapNode in product.ShoesSizeMap)
                {
                    var price = GetUpdatedPrice(currencyValue, usdCurrencyValue, sizeMapNode.ExternalPrice);

                    sizeMapNode.InternalPrice = price;
                }

                var productsInBid = product.ShoesSizeMap.Where(x => x.Quantity > 0);

                if (productsInBid.Count() > 0)
                {
                    commonExternalPrice = productsInBid.Min(x => x.ExternalPrice);
                }
                else
                {
                    commonExternalPrice = product.ShoesSizeMap.Min(x => x.ExternalPrice);
                }
            }
            else
            {
                commonExternalPrice = product.ShoesSizeMap.FirstOrDefault().ExternalPrice;
            }

            UpdateCommonPrice(product, currencyValue, usdCurrencyValue, commonExternalPrice);
        }
Beispiel #13
0
        private static void StartSynchronization(IEnumerable <SyncRunner> runners)
        {
            var threads = new List <Thread>();

            MapsHelper.UpdateMaps();

            try
            {
                var sw = Stopwatch.StartNew();

                foreach (var runner in runners)
                {
                    for (var i = 0; i < ConfigHelper.Config.ThreadsPerResource; i++)
                    {
                        var thread = new Thread(() => runner.Run());
                        thread.Start();
                        threads.Add(thread);
                    }
                }

                foreach (var thread in threads)
                {
                    thread.Join();
                }
                sw.Stop();

                Log.ResultLog(sw.Elapsed.ToString(), UnsuccessfulItemsHandler.GetErrors());

                MySqlHelper.UpdateUnsuccessfulProducts(UnsuccessfulItemsHandler.GetUnsuccessfulProductIdsToUpdate());
            }
            catch
            {
                Log.WriteLog("Unknown error when running sync processes");
            }

            UnsuccessfulItemsHandler.ClearErrors();
        }
Beispiel #14
0
 public async void ButtonSearchRouteToTapped(object sender, TappedRoutedEventArgs e)
 {
     await MapsHelper.SearchDirectionsAsync(null, new MapPosition(33.943538, -118.40812), null);
 }
Beispiel #15
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);
        }
Beispiel #16
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));
        }