using System.Text.Json; using Yuanshen.Protocol; namespace Yuanshen.Gameserver.Game; internal sealed class ScenePointTable { private readonly Dictionary> _points = new(); public ScenePointTable() { Load(3, "scene3_points.json"); } public bool TryGet(uint sceneId, uint pointId, out Vector position) { position = new Vector(); return _points.TryGetValue(sceneId, out Dictionary? points) && points.TryGetValue(pointId, out position!); } private void Load(uint sceneId, string fileName) { string path = Path.Combine(AppContext.BaseDirectory, "assets", "scene", fileName); if (!File.Exists(path)) return; using JsonDocument document = JsonDocument.Parse(File.ReadAllText(path)); Dictionary points = new(); foreach (JsonProperty property in document.RootElement.EnumerateObject()) { if (!uint.TryParse(property.Name, out uint pointId)) continue; JsonElement value = property.Value; points[pointId] = new Vector { X = value.GetProperty("x").GetSingle(), Y = value.GetProperty("y").GetSingle(), Z = value.GetProperty("z").GetSingle() }; } _points[sceneId] = points; } }