yuanshen/Yuanshen.Gameserver/Game/MonsterSpawnTable.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

59 lines
2 KiB
C#

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<SpawnNode> Nodes { get; }
public MonsterSpawnTable()
{
Nodes = Load("scene3_spawns.json");
}
private static List<SpawnNode> Load(string fileName)
{
List<SpawnNode> 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;
}
}