public static void UpdateArea(DatabaseBuilder builder, dynamic npc, Saint.Map sMap, double mapX, double mapY) { var marker = MapMarker.FindClosest(builder, sMap, mapX, mapY); if (marker != null) { npc.areaid = marker.PlaceName.Key; builder.Db.AddLocationReference(marker.PlaceName.Key); } }
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); }