Example #1
0
        void IndexLibraData()
        {
            var sTerritoryTypes = _builder.Sheet <Saint.TerritoryType>();

            foreach (var lBNpcName in _builder.Libra.Table <Libra.BNpcName>())
            {
                if (!_bnpcDataByFullKey.TryGetValue(lBNpcName.Key, out var bnpcData))
                {
                    bnpcData             = new BNpcData();
                    bnpcData.FullKey     = lBNpcName.Key;
                    bnpcData.BNpcBaseKey = (int)(lBNpcName.Key / 10000000000);
                    bnpcData.BNpcNameKey = (int)(lBNpcName.Key % 10000000000);
                    bnpcData.DebugName   = lBNpcName.Index_en;
                    _bnpcDataByFullKey[lBNpcName.Key] = bnpcData;
                }

                dynamic data = JsonConvert.DeserializeObject((string)lBNpcName.data);
                if (data.nonpop != null)
                {
                    bnpcData.HasSpecialSpawnRules = true;
                }

                if (data.region != null)
                {
                    var area       = Utils.GetPair(data.region);
                    var zone       = Utils.GetPair(area.Value);
                    var levelRange = (JArray)zone.Value;

                    var location = new BNpcLocation();
                    location.PlaceNameKey = int.Parse(zone.Key);
                    location.LevelRange   = string.Join(" - ", levelRange.Select(v => (string)v));
                    bnpcData.Locations.Add(location);
                }
            }
        }
Example #2
0
        void IndexSapphireDataCore(MySql.Data.MySqlClient.MySqlDataReader reader, Saint.IXivSheet <Saint.TerritoryType> sTerritoryTypes)
        {
            BNpcData bnpcData = null;

            while (reader.Read())
            {
                var nameKey = reader.GetInt32("bNPCNameId");
                var baseKey = reader.GetInt32("bNPCBaseId");
                if (bnpcData == null || nameKey != bnpcData.BNpcNameKey || baseKey != bnpcData.BNpcBaseKey)
                {
                    var fullKey = nameKey + baseKey * 10000000000;
                    if (!_bnpcDataByFullKey.TryGetValue(fullKey, out bnpcData))
                    {
                        bnpcData             = new BNpcData();
                        bnpcData.BNpcNameKey = nameKey;
                        bnpcData.BNpcBaseKey = baseKey;
                        bnpcData.FullKey     = fullKey;
                        bnpcData.DebugName   = reader.GetString("name");
                    }
                }

                // Incomplete location data may already exist from Libra.  Fill in.
                var territoryTypeId = reader.GetInt32("territoryTypeId");
                var sTerritoryType  = sTerritoryTypes[territoryTypeId];
                var sMap            = sTerritoryType.Map;

                var bnpcLocation = bnpcData.Locations.FirstOrDefault(l => l.X == 0 && l.PlaceNameKey == sTerritoryType.PlaceName.Key);
                if (bnpcLocation == null)
                {
                    bnpcLocation = new BNpcLocation();
                    bnpcLocation.PlaceNameKey = sTerritoryType.PlaceName.Key;
                    bnpcData.Locations.Add(bnpcLocation);
                }

                bnpcLocation.Radius = reader.GetFloat("r");
                bnpcLocation.X      = sMap.ToMapCoordinate3d(reader.GetDouble("x"), sMap.OffsetX);
                // Z is intentionally used for Y here.
                bnpcLocation.Y = sMap.ToMapCoordinate3d(reader.GetDouble("z"), sMap.OffsetY);
                bnpcLocation.Z = sMap.ToMapCoordinate3d(reader.GetDouble("y"), 0);

                if (bnpcLocation.LevelRange == null)
                {
                    var level = reader.GetInt32("level");
                    bnpcLocation.LevelRange = level.ToString();
                }
            }
        }