Example #1
0
        public void Build(bool fetchIconsOnly)
        {
            OneTimeExports.Run(_realm);

            // Miscellaneous initialization
            ItemsToImport = Sheet <Saint.Item>()
                            .Where(i => !Hacks.IsItemSkipped(i.Name, i.Key))
                            .ToArray();

            NpcsToImport = _realm.GameData.ENpcs
                           .Where(n => n.Resident != null)
                           .Where(n => !string.IsNullOrWhiteSpace(n.Singular))
                           .ToArray();

            _libraNpcIndex = _libra.Table <Libra.ENpcResident>().ToDictionary(e => e.Key);

            FileDatabase.Initialize();
            IconDatabase.Initialize();
            ItemIconDatabase.Initialize(ItemsToImport);
            PatchDatabase.Initialize();

            if (fetchIconsOnly)
            {
                new Lodestone.LodestoneIconScraper().FetchIcons();
                PrintLine("All icons fetched.  Stopping.");
                return;
            }

            var itemSourceComplexityModule = new ItemSourceComplexity();

            // All the modules.
            var modules = new Queue <Module>(new Module[]
            {
                new Indexes(),
                new Miscellaneous(),
                new Locations(),
                new Items(),
                //new ItemSets(),
                new Orchestrion(),
                new Actions(),
                new Emotes(),
                new Weather(),
                new Instances(),
                new Nodes(),
                new NPCs(),
                new SpecialShops(),
                new DisposalShops(),
                new Recipes(),
                new Specializations(),
                new Mounts(),
                new Minions(),
                new TripleTriad(),
                new Customize(),
                new Mobs(),
                new Quests(),
                new Talk(),
                new FishingSpots(),
                new Leves(),
                new Achievements(),
                new Fates(),
                new JobCategories(),
                new Ventures(),
                new Materia(),
                new WondrousTails(),
                new OtherItemSources(),
                new Relics(),
                itemSourceComplexityModule,
                new SupplyDuties(itemSourceComplexityModule),
                new Maps(),
                new EquipmentScorer(),
                new Jobs(),
                new Dyes(),
                new NpcEquipment(itemSourceComplexityModule),
                new NpcAlternates(), // Has to be the very end.
                new StatisticsModule(itemSourceComplexityModule),
            });

            itemSourceComplexityModule = null;

            var total = modules.Count;

            while (modules.Count > 0)
            {
                var module = modules.Dequeue();
                PrintLine($"* {module.Name}... {total - modules.Count}/{total}");
                module.Start();
            }
        }
Example #2
0
        public dynamic GetOrCreateNpc(Saint.ENpc sNpc)
        {
            if (_db.NpcsById.TryGetValue(sNpc.Key, out var npc))
            {
                return(npc);
            }

            if (string.IsNullOrWhiteSpace(sNpc.Singular))
            {
                return(null); // Bad or unreferenced NPC.
            }
            npc    = new JObject();
            npc.id = sNpc.Key;
            Localize.Column((JObject)npc, sNpc.Resident, "Singular", "name", Utils.CapitalizeWords);
            string name = npc.en.name;

            npc.patch = PatchDatabase.Get("npc", sNpc.Key);

            // Set base information.
            if (!_db.NpcAlternatesByName.TryGetValue(name, out var alts))
            {
                alts = new List <dynamic>();
                _db.NpcAlternatesByName[name] = alts;
            }
            alts.Add(npc);

            var title = sNpc.Title.ToString();

            if (!string.IsNullOrEmpty(title))
            {
                npc.title = title;
            }

            // Map and coordinates.
            if (LevelByNpcObjectKey.TryGetValue(sNpc.Key, out var level) && LocationInfoByMapId.TryGetValue(level.Map.Key, out var locationInfo))
            {
                npc.zoneid = locationInfo.PlaceName.Key;
                npc.coords = GetCoords(level);
                _db.AddLocationReference(locationInfo.PlaceName.Key);
            }
            else
            {
                if (_db.NpcZoneByNpcId.ContainsKey(sNpc.Key))
                {
                    var zoneid = _db.NpcZoneByNpcId[sNpc.Key];
                    npc.zoneid = zoneid;
                    _db.AddLocationReference(zoneid);
                }

                if (_libraNpcIndex.TryGetValue(sNpc.Key, out var lNpc))
                {
                    dynamic data = JsonConvert.DeserializeObject((string)lNpc.data);
                    var     zone = Utils.GetPair(data.coordinate);
                    npc.coords = Utils.GetFirst(zone.Value);
                    npc.approx = 1;
                }
            }

            // Closest map marker.
            if (level != null)
            {
                var marker = MapMarker.FindClosest(this, level.Map, level.MapX, level.MapY);
                if (marker != null)
                {
                    npc.areaid = marker.PlaceName.Key;
                    _db.AddLocationReference(marker.PlaceName.Key);
                }
            }

            _db.Npcs.Add(npc);
            _db.NpcsById[sNpc.Key] = npc;
            return(npc);
        }