using System.Text.Json; using Yuanshen.Protocol; namespace Yuanshen.Gameserver.Game; internal readonly record struct SpawnNode(uint NodeId, uint ConfigId, uint GroupId, uint MonsterId, uint Level, Vector Pos, float Hp, float Attack, float Defense) { public bool IsWildlife => MonsterId is >= 28000000 and < 29000000; } internal sealed class MonsterSpawnTable { public IReadOnlyList Nodes { get; } public MonsterSpawnTable() { Nodes = Load("scene3_spawns.json"); } private static List Load(string fileName) { List nodes = new(); string path = Path.Combine(AppContext.BaseDirectory, "assets", "scene", fileName); if (!File.Exists(path)) return nodes; using JsonDocument document = JsonDocument.Parse(File.ReadAllText(path)); foreach (JsonElement entry in document.RootElement.EnumerateArray()) { uint configId = entry.GetProperty("c").GetUInt32(); if (configId == 0) continue; if (entry.TryGetProperty("a", out JsonElement active) && active.GetUInt32() != 1) continue; uint nodeId = entry.TryGetProperty("n", out JsonElement node) ? node.GetUInt32() : configId; uint groupId = entry.TryGetProperty("g", out JsonElement group) ? group.GetUInt32() : 0; nodes.Add(new SpawnNode( nodeId, configId, groupId, entry.GetProperty("m").GetUInt32(), entry.GetProperty("l").GetUInt32(), new Vector { X = entry.GetProperty("x").GetSingle(), Y = entry.GetProperty("y").GetSingle(), Z = entry.GetProperty("z").GetSingle() }, entry.GetProperty("hp").GetSingle(), entry.GetProperty("atk").GetSingle(), entry.GetProperty("def").GetSingle())); } return nodes; } }