yuanshen/Yuanshen.Gameserver/Game/ScenePointTable.cs
wisedev 61cc2055cf First working version of the server
KCP gameserver with packet dispatch, scene streaming, combat, gacha and the
shop, plus a small HTTP server for the login flow and the wish history page.

Game data under assets is pulled out of the client instead of being typed by
hand. The excel tables come from the packed bin container and the spawn points
from the compiled scene scripts.
2026-09-04 02:06:53 +03:00

47 lines
1.4 KiB
C#

using System.Text.Json;
using Yuanshen.Protocol;
namespace Yuanshen.Gameserver.Game;
internal sealed class ScenePointTable
{
private readonly Dictionary<uint, Dictionary<uint, Vector>> _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<uint, Vector>? 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<uint, Vector> 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;
}
}