Add NPC system scaffold, loot-table gold drops, and remove stash VIP gate

This commit is contained in:
dingo
2026-02-14 00:37:56 -05:00
parent d4f467656d
commit b4affac203
19 changed files with 1448 additions and 89 deletions
+79 -1
View File
@@ -29,14 +29,17 @@ public partial class DungeonSimulation
public ConcurrentDictionary<int, LootChestInstance> LootChests { get; } = new();
public ConcurrentDictionary<int, ProjectileInstance> Projectiles { get; } = new();
public ConcurrentDictionary<int, HazardZone> HazardZones { get; } = new();
public ConcurrentDictionary<int, NpcInstance> Npcs { get; } = new();
// ID generators
private int _nextLootChestId = 1;
private int _nextProjectileId = 1;
private int _nextHazardId = 1;
private int _nextNpcId = 1;
public int GetNextLootChestId() => _nextLootChestId++;
public int GetNextProjectileId() => _nextProjectileId++;
public int GetNextHazardId() => _nextHazardId++;
public int GetNextNpcId() => _nextNpcId++;
// Combat tracking
private readonly List<DamageEvent> _pendingDamageEvents = new();
@@ -54,7 +57,9 @@ public partial class DungeonSimulation
private readonly Dictionary<int, MobAbilityDefinition>? _abilityDefinitions;
private readonly Dictionary<int, string?>? _spriteConfigs;
private readonly Dictionary<int, MobAbilityAnimationMapping>? _abilityAnimationMappings;
private readonly Dictionary<int, DungeonNpcDefinition>? _npcDefinitions;
private readonly List<(int MobDefinitionId, float X, float Y, int Tier)> _pendingSummons = new();
private readonly Random _npcWanderRandom = new();
public DungeonSimulation(
DungeonLayout layout,
@@ -63,7 +68,8 @@ public partial class DungeonSimulation
int bracketMin = 1,
Dictionary<int, MobAbilityDefinition>? abilityDefinitions = null,
Dictionary<int, string?>? spriteConfigs = null,
Dictionary<int, MobAbilityAnimationMapping>? abilityAnimationMappings = null)
Dictionary<int, MobAbilityAnimationMapping>? abilityAnimationMappings = null,
Dictionary<int, DungeonNpcDefinition>? npcDefinitions = null)
{
Layout = layout;
Tier = tier;
@@ -72,11 +78,44 @@ public partial class DungeonSimulation
_abilityDefinitions = abilityDefinitions;
_spriteConfigs = spriteConfigs;
_abilityAnimationMappings = abilityAnimationMappings;
_npcDefinitions = npcDefinitions;
SpawnMobs();
SpawnNpcs();
InitializeChests();
SpawnExitPortal();
}
private void SpawnNpcs()
{
if (_npcDefinitions == null || _npcDefinitions.Count == 0 || Layout.NpcSpawns.Count == 0)
return;
foreach (var spawn in Layout.NpcSpawns.Where(s => s.IsAlive))
{
DungeonNpcDefinition? def = null;
if (spawn.NpcDefinitionId.HasValue)
{
_npcDefinitions.TryGetValue(spawn.NpcDefinitionId.Value, out def);
}
if (def == null || !def.IsEnabled)
continue;
var npc = NpcInstance.FromDefinition(
def,
GetNextNpcId(),
spawn.X * 32 + 16,
spawn.Y * 32 + 16);
if (!string.IsNullOrWhiteSpace(spawn.NpcName))
{
npc.Name = spawn.NpcName!;
}
Npcs[npc.Id] = npc;
}
}
private void SpawnExitPortal()
{
@@ -390,6 +429,8 @@ public partial class DungeonSimulation
UpdatePlayer(player);
}
UpdateNpcs();
// Keep corpses in the world after death (even after loot is emptied).
// We still stamp when loot becomes empty so UI/inspection logic can reference it.
foreach (var mob in Mobs.Values.Where(m => !m.IsAlive))
@@ -429,6 +470,43 @@ public partial class DungeonSimulation
Phase = Phase
};
}
private void UpdateNpcs()
{
foreach (var npc in Npcs.Values)
{
if (!npc.IsAlive || !npc.CanWander || npc.BehaviorMode != DataServer.Data.Enums.NpcBehaviorMode.Wander)
continue;
npc.NextWanderIn -= TickDelta;
if (npc.NextWanderIn > 0f)
continue;
npc.NextWanderIn = Math.Max(0.25f, npc.WanderIntervalSeconds);
// Random short-step wander constrained by radius around spawn.
var step = 12f;
var dx = (float)(_npcWanderRandom.NextDouble() * 2.0 - 1.0) * step;
var dy = (float)(_npcWanderRandom.NextDouble() * 2.0 - 1.0) * step;
var nx = npc.X + dx;
var ny = npc.Y + dy;
var distX = nx - npc.SpawnX;
var distY = ny - npc.SpawnY;
var maxDistSq = npc.WanderRadiusPx * npc.WanderRadiusPx;
if ((distX * distX) + (distY * distY) > maxDistSq)
continue;
var tileX = (int)MathF.Floor(nx / 32f);
var tileY = (int)MathF.Floor(ny / 32f);
if (!Layout.IsWalkable(tileX, tileY))
continue;
npc.X = nx;
npc.Y = ny;
npc.Rotation = MathF.Atan2(dy, dx);
}
}
/// <summary>
/// Process a mob's ability/attack against a target