private void MergeNullPlaces(IEnumerable <GatheringPoint> gatheringPoints)
        {
            foreach (GatheringPoint gatheringPoint in gatheringPoints)
            {
                GatheringPoint[] nullPoints = gatheringPoint.children.Where(child => child.placeKey == null).ToArray();

                foreach (GatheringPoint nullPoint in nullPoints)
                {
                    nullPoint.placeNameKo = "???";
                    nullPoint.placeNameEn = "???";
                }

                if (nullPoints.Length > 1)
                {
                    GatheringPoint nullPoint = nullPoints[0];

                    for (int i = 1; i < nullPoints.Length; i++)
                    {
                        nullPoint.level    = Math.Min((long)nullPoint.level, (long)nullPoints[i].level);
                        nullPoint.children = nullPoint.children.Concat(nullPoints[i].children).ToArray();
                    }

                    List <GatheringPoint> newList = gatheringPoint.children.Where(child => child.placeKey != null).ToList();
                    newList.Add(nullPoint);
                    gatheringPoint.children = newList.ToArray();
                }

                MergeNullPlaces(gatheringPoint.children);
            }
        }
        private GatheringPoint FindGatheringPointRecursively(IEnumerable <GatheringPoint> gatheringPoints, long?placeKey)
        {
            if (placeKey == null)
            {
                return(null);
            }

            foreach (GatheringPoint gatheringPoint in gatheringPoints)
            {
                if (gatheringPoint.children.Length > 0)
                {
                    GatheringPoint candidate = FindGatheringPointRecursively(gatheringPoint.children, placeKey);

                    if (candidate != null)
                    {
                        return(candidate);
                    }
                }

                if (gatheringPoint.placeKey == placeKey)
                {
                    return(gatheringPoint);
                }
            }

            return(null);
        }
        private Item GetItem(long key, int requiredAmount)
        {
            Item item = _context.Items
                        .Where(_item => key == _item.Key)
                        .Select(_item => new Item
            {
                key            = _item.Key,
                nameKo         = _item.UINameKo,
                nameEn         = _item.UINameEn,
                iconPath       = _item.IconPath,
                requiredAmount = requiredAmount,
                recipes        = _item.CraftRecipes.Select(recipe => new Recipe
                {
                    key           = recipe.Key,
                    level         = recipe.LevelView,
                    totalCrafted  = recipe.CraftNum,
                    numStarsArray = new int[(int)recipe.LevelDiff],
                    craftingJob   = new Job
                    {
                        key      = recipe.CraftJob.Key,
                        nameKo   = recipe.CraftJob.NameKo,
                        nameEn   = recipe.CraftJob.NameEn,
                        iconPath = "/assets/ui/icon/062000/" + ((long)((recipe.CraftJob.Key) + 62100L)).ToString("D6") + ".tex.png"
                    }
                }).ToArray(),
                gatherings = _item.Gatherings.Select(gathering => new Gathering
                {
                    key          = gathering.Key,
                    gatheringJob = new Job
                    {
                        key      = gathering.GatheringJob.Key,
                        nameKo   = gathering.GatheringJob.NameKo,
                        nameEn   = gathering.GatheringJob.NameEn,
                        iconPath = "/assets/ui/icon/062000/" + ((long)(gathering.GatheringJob.Key + 62100L)).ToString("D6") + ".tex.png"
                    },
                    numStarsArray        = new int[(int)gathering.LevelDiff],
                    isHidden             = gathering.IsHidden,
                    gatheringSubCategory =
                        gathering.GatheringSubCategory != null ?
                        new GatheringSubCategory
                    {
                        key    = gathering.GatheringSubCategory.Key,
                        nameKo = gathering.GatheringSubCategory.NameKo,
                        nameEn = gathering.GatheringSubCategory.NameEn
                    } : null,
                    gatheringPoints = gathering.GatheringPoints
                                      .Where(gatheringPoint => gatheringPoint.Level != null)
                                      .Select(gatheringPoint => new GatheringPoint
                    {
                        key         = gatheringPoint.Key,
                        level       = gatheringPoint.Level,
                        placeKey    = gatheringPoint.PlaceName.Key,
                        placeNameKo = gatheringPoint.PlaceName.SGLKo,
                        placeNameEn = gatheringPoint.PlaceName.SGLEn,
                        children    = new GatheringPoint[0]
                    }).ToArray()
                }).ToArray(),
                shops = _item.ItemShops.Select(itemShop => itemShop.Shop)
                        .Select(shop => new Shop
                {
                    key        = shop.Key,
                    nameKo     = shop.NameKo,
                    nameEn     = shop.NameEn,
                    beastTribe = shop.BeastTribe != null ? new BeastTribe
                    {
                        key    = shop.BeastTribe.Key,
                        nameKo = shop.BeastTribe.SGLKo,
                        nameEn = shop.BeastTribe.SGLEn
                    } : null,
                    quest = shop.Quest != null ? new Quest
                    {
                        key    = shop.Quest.Key,
                        nameKo = shop.Quest.NameKo,
                        nameEn = shop.Quest.NameEn
                    } : null,
                    npcs = shop.ENpcShops.Select(eNpcShop => eNpcShop.ENpc)
                           .Select(eNpc => new Npc
                    {
                        key    = eNpc.Key,
                        nameKo = eNpc.SGLKo,
                        nameEn = eNpc.SGLEn
                    }).ToArray()
                }).ToArray()
            }).FirstOrDefault();

            if (item != null)
            {
                List <Gathering> gatherings = new List <Gathering>();

                foreach (Gathering gathering in item.gatherings)
                {
                    Gathering candidate = gatherings.Where(_gathering =>
                                                           _gathering.gatheringJob.key == gathering.gatheringJob.key &&
                                                           _gathering.numStarsArray.Length == gathering.numStarsArray.Length &&
                                                           _gathering.isHidden == gathering.isHidden &&
                                                           (_gathering.gatheringSubCategory == null ?
                                                            gathering.gatheringSubCategory == null :
                                                            _gathering.gatheringSubCategory.key == gathering.gatheringSubCategory.key)).FirstOrDefault();

                    if (candidate != null)
                    {
                        candidate.gatheringPoints = candidate.gatheringPoints.Concat(gathering.gatheringPoints).ToArray();
                    }
                    else
                    {
                        gatherings.Add(gathering);
                    }
                }

                item.gatherings = gatherings.ToArray();

                foreach (Gathering gathering in item.gatherings)
                {
                    while (gathering.gatheringPoints.Any(gatheringPoint => _context.GatheringPoints.Any(_gatheringPoint => _gatheringPoint.Key == gatheringPoint.key && _gatheringPoint.Parent != null)))
                    {
                        List <GatheringPoint> newGatheringPoints = new List <GatheringPoint>();

                        foreach (GatheringPoint gatheringPoint in gathering.gatheringPoints)
                        {
                            GatheringPoint existingGatheringPoint = FindGatheringPointRecursively(newGatheringPoints, gatheringPoint.placeKey);

                            if (existingGatheringPoint != null)
                            {
                                if (existingGatheringPoint.level != null && gatheringPoint.level != null)
                                {
                                    existingGatheringPoint.level = Math.Min((long)existingGatheringPoint.level, (long)gatheringPoint.level);
                                }

                                existingGatheringPoint.children = existingGatheringPoint.children.Concat(gatheringPoint.children).ToArray();

                                continue;
                            }

                            FFXIVTranslator.PorierFFXIV.GatheringPoint parentGatheringPoint = _context.GatheringPoints.Where(_gatheringPoint => _gatheringPoint.Key == gatheringPoint.key)
                                                                                              .Select(_gatheringPoint => _gatheringPoint.Parent)
                                                                                              .FirstOrDefault();

                            if (parentGatheringPoint == null)
                            {
                                newGatheringPoints.Add(gatheringPoint);
                            }
                            else
                            {
                                GatheringPoint newGatheringPoint = new GatheringPoint
                                {
                                    key      = parentGatheringPoint.Key,
                                    level    = parentGatheringPoint.Level,
                                    children = new GatheringPoint[1]
                                    {
                                        gatheringPoint
                                    }
                                };

                                PlaceName placeName = _context.GatheringPoints.Where(_gatheringPoint => _gatheringPoint.Key == parentGatheringPoint.Key)
                                                      .Select(_gatheringPoint => _gatheringPoint.PlaceName)
                                                      .FirstOrDefault();

                                if (placeName != null)
                                {
                                    newGatheringPoint.placeKey    = placeName.Key;
                                    newGatheringPoint.placeNameKo = placeName.SGLKo;
                                    newGatheringPoint.placeNameEn = placeName.SGLEn;
                                }

                                GatheringPoint candidate = FindGatheringPointRecursively(newGatheringPoints, newGatheringPoint.placeKey);

                                if (candidate != null)
                                {
                                    if (candidate.level != null && newGatheringPoint.level != null)
                                    {
                                        candidate.level = Math.Min((long)candidate.level, (long)newGatheringPoint.level);
                                    }

                                    candidate.children = candidate.children.Concat(newGatheringPoint.children).ToArray();
                                }
                                else
                                {
                                    newGatheringPoints.Add(newGatheringPoint);
                                }
                            }
                        }

                        gathering.gatheringPoints = newGatheringPoints.ToArray();
                    }
                }

                foreach (Gathering gathering in item.gatherings)
                {
                    MergeNullPlaces(gathering.gatheringPoints);
                }

                foreach (Shop shop in item.shops)
                {
                    foreach (Npc npc in shop.npcs)
                    {
                        ENpcPlaceName eNpcPlaceName = _context.ENpcs
                                                      .Where(eNpc => eNpc.Key == npc.key)
                                                      .SelectMany(eNpc => eNpc.ENpcPlaceNames)
                                                      .Where(_eNpcPlaceName => _eNpcPlaceName.PlaceName != null)
                                                      .FirstOrDefault();

                        if (eNpcPlaceName != null)
                        {
                            npc.x     = eNpcPlaceName.X;
                            npc.y     = eNpcPlaceName.Y;
                            npc.place = _context.ENpcPlaceNames
                                        .Where(_eNpcPlaceName => _eNpcPlaceName.Key == eNpcPlaceName.Key)
                                        .Select(_eNpcPlaceName => _eNpcPlaceName.PlaceName)
                                        .Select(placeName => new Place
                            {
                                key    = placeName.Key,
                                nameKo = placeName.SGLKo,
                                nameEn = placeName.SGLEn
                            })
                                        .FirstOrDefault();

                            Place currentPlace = npc.place;

                            while (true)
                            {
                                PlaceName region = _context.PlaceNames.Where(placeName => placeName.Key == currentPlace.key).Select(placeName => placeName.Region).FirstOrDefault();

                                if (region == null)
                                {
                                    break;
                                }

                                currentPlace.parent = new Place
                                {
                                    key    = region.Key,
                                    nameKo = region.SGLKo,
                                    nameEn = region.SGLEn
                                };

                                currentPlace = currentPlace.parent;
                            }
                        }
                    }
                }
            }

            return(item);
        }
Exemplo n.º 4
0
        private void ParseGather(GatheringPoint g, IEnumerable <MapMarker> maps)
        {
            //Beast Tribe and Leve Quests get Territory type 1 most of the time....
            if (g.Base.Key == 0 || g.TerritoryType.Key == 1 || g.Base.GatheringLevel == 0 || !g.Base.Items.Any() || g.Base.Items.All(i => i.Item.Key >= 2000000 && i.Item.Key < 3000000))
            {
                return;
            }
            var ng = new GatheringData();

            ng.NodeId = Convert.ToUInt32(g.Key);

            if (g.GatheringPointBonus.Length >= 1)
            {
                ng.Bonus = Convert.ToUInt32(g.GatheringPointBonus[0].Key);
            }


            ng.Level = Convert.ToUInt32(g.TerritoryType.Key);

            ng.Position = LevelBuilder.Level(_Realm.GameData.GetSheet <SaintCoinach.Xiv.Level>().FirstOrDefault(i => i.Object == g));



            /// <summary>
            /// 0 -> Mining
            /// 1 -> Quarrying
            /// 2 -> Logging
            /// 3 -> Harrvesting
            /// 4 -> SpearFishing
            /// </summary>

            var type = Convert.ToByte(g.Base.Type.Key); //

            if (type < 2)
            {
                ng.Job = 16; //miner
            }
            else if (type < 4)
            {
                ng.Job = 17; //bot
            }
            else
            {
                ng.Job = 18; //fisher
            }
            if (g.GatheringSubCategory == null)
            {
                ng.RequiredBook = 0;
            }
            else
            {
                ng.RequiredBook = Convert.ToUInt32(g.GatheringSubCategory.Item.Key);
            }



            ng.Territory = Convert.ToUInt32(g.TerritoryType.Key);

            ng.TerritoryName = g.TerritoryType.Name.ToString();


            if (g.PlaceName.Key != 0)
            {
                ng.Place = Convert.ToUInt32(g.PlaceName.Key);

                ng.PlaceName = g.PlaceName.Name.ToString();

                var map = g.TerritoryType.Map;
                var X   = maps.Where(i => i.Place.Key == g.PlaceName.Key);
                //hard coded fix for hell's lid
                if (g.PlaceName.Key == 2762)
                {
                    X = X.Where(i => i.Key == 17);
                }
                if (X.Count() == 0)
                {
                    var Y = _Realm.GameData.GetSheet <SpearfishingNotebook>().Where(t => t.PlaceName.Key == g.PlaceName.Key);
                    if (Y.Count() == 0 || Y.Count() > 1)
                    {
                        Debugger.Break();
                    }

                    ng.PlaceX = (float)map.ToMapCoordinate3d(Y.First().X, map.OffsetX);
                    ng.PlaceY = (float)map.ToMapCoordinate3d(Y.First().Y, map.OffsetY);
                }
                else if (X.Count() > 1)
                {
                    Debugger.Break();
                }
                else
                {
                    ng.PlaceX = (float)map.ToMapCoordinate3d(X.First().X, map.OffsetX);
                    ng.PlaceY = (float)map.ToMapCoordinate3d(X.First().Y, map.OffsetY);
                }
            }
            ng.Timed = g.Base.IsLimited;
            var bg = g.Base.Key;

            MappyNPC npc = mappyDataResult.First(i => i.ENpcResidentID == ng.NodeId);

            //OutputInformation($"{g.Base.Key} count - {mappyDataResult.Count(i => i.ENpcResidentID == ng.NodeId)} ");
            if (ng.Timed)
            {
                var garland = GarlandBellGathering.First(i => i.Id == bg);
                ng.Timer    = new List <uint>(garland.Time);
                ng.Duration = garland.Uptime;
            }
            if (ng.Position != null)
            {
                OutputInformation($"{ng.NodeId} {g.Base.Key}  {ng.Position.ZoneId} {ng.NodeId} {ng.Position.ToVec3<Vector3>()}");
            }
            else
            {
                OutputInformation($"{ng.NodeId} {g.Base.Items.FirstOrDefault().Item.Name} ({npc.CoordinateX}, {npc.CoordinateZ}, {npc.CoordinateY})");
            }
            GatherData.Add(ng.NodeId, ng);
        }
Exemplo n.º 5
0
 public void AddToGatheringPointsList(GatheringPoint point)
 {
     _gatheringPoints.Add(point);
 }