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
+52 -8
View File
@@ -43,6 +43,7 @@ public sealed partial class DungeonHandler : IClientMessageHandler
private Dictionary<int, MobAbilityDefinition> _abilityDefinitions = new();
private Dictionary<int, MobAbilityAnimationMapping> _abilityAnimationMappings = new();
private Dictionary<int, string?> _mobSpriteConfigs = new(); // MobDefinitionId -> SpriteConfig JSON
private Dictionary<int, DungeonNpcDefinition> _npcDefinitions = new();
private bool _initialized = false;
private volatile bool _spatialStateFilterEnabled = true;
private volatile float _spatialStateRadiusPx = 32f * 28f; // 28 tiles
@@ -163,6 +164,9 @@ public sealed partial class DungeonHandler : IClientMessageHandler
DungeonOpCodes.DUNGEON_INPUT_CHEST,
DungeonOpCodes.DUNGEON_INPUT_PORTAL,
DungeonOpCodes.DUNGEON_INPUT_FIRE_PROJECTILE,
DungeonOpCodes.DUNGEON_INPUT_NPC_INTERACT,
DungeonOpCodes.DUNGEON_INPUT_NPC_DIALOG_SELECT,
DungeonOpCodes.DUNGEON_INPUT_NPC_SHOP_ACTION,
DungeonOpCodes.INVENTORY_REQUEST,
DungeonOpCodes.EQUIP_ITEM,
DungeonOpCodes.UNEQUIP_ITEM,
@@ -189,7 +193,7 @@ public sealed partial class DungeonHandler : IClientMessageHandler
DungeonOpCodes.CRAFTING_SKILLS_REQUEST,
DungeonOpCodes.CRAFTING_RECIPES_REQUEST,
DungeonOpCodes.CRAFTING_ATTEMPT,
// Stash (VIP)
// Stash
DungeonOpCodes.STASH_REQUEST,
DungeonOpCodes.STASH_DEPOSIT,
DungeonOpCodes.STASH_WITHDRAW,
@@ -234,7 +238,7 @@ public sealed partial class DungeonHandler : IClientMessageHandler
if (!_sessions.TryGet(connection.Id, out var accountId, out _))
{
// Ignore stray input before auth to avoid booting the client during connect
if (opCode is >= DungeonOpCodes.DUNGEON_INPUT_MOVE and <= DungeonOpCodes.DUNGEON_INPUT_FIRE_PROJECTILE)
if (opCode is >= DungeonOpCodes.DUNGEON_INPUT_MOVE and <= DungeonOpCodes.DUNGEON_INPUT_NPC_SHOP_ACTION)
return;
await SendErrorAsync(connection, $"auth_required for packet: {opCode}", ct);
@@ -297,6 +301,15 @@ public sealed partial class DungeonHandler : IClientMessageHandler
case DungeonOpCodes.DUNGEON_INPUT_FIRE_PROJECTILE:
await HandleFireProjectile(connection, session, payload, ct);
break;
case DungeonOpCodes.DUNGEON_INPUT_NPC_INTERACT:
await HandleNpcInteract(connection, session, payload, ct);
break;
case DungeonOpCodes.DUNGEON_INPUT_NPC_DIALOG_SELECT:
await HandleNpcDialogSelect(connection, session, payload, ct);
break;
case DungeonOpCodes.DUNGEON_INPUT_NPC_SHOP_ACTION:
await HandleNpcShopAction(connection, session, payload, ct);
break;
case DungeonOpCodes.INVENTORY_REQUEST:
await HandleInventoryRequest(connection, session, ct);
@@ -379,7 +392,7 @@ public sealed partial class DungeonHandler : IClientMessageHandler
await HandleCraftingAttempt(connection, session, payload, ct);
break;
// Stash (VIP Feature)
// Stash
case DungeonOpCodes.STASH_REQUEST:
await HandleStashRequest(connection, session, ct);
break;
@@ -708,7 +721,7 @@ public sealed partial class DungeonHandler : IClientMessageHandler
var (layout, layoutV2) = await GenerateDungeonLayoutWithFallbackAsync(seed, tier, ct);
var simulation = new DungeonSimulation(layout, tier, _mobDefinitions, bracketMin, _abilityDefinitions, _mobSpriteConfigs, _abilityAnimationMappings);
var simulation = new DungeonSimulation(layout, tier, _mobDefinitions, bracketMin, _abilityDefinitions, _mobSpriteConfigs, _abilityAnimationMappings, _npcDefinitions);
instance = new DungeonInstance
{
@@ -1683,15 +1696,15 @@ public sealed partial class DungeonHandler : IClientMessageHandler
return;
// Generate loot from the mob's loot tables
var loot = _lootService.GenerateMobLoot(
var lootResult = _lootService.GenerateMobLoot(
mob.DefinitionId,
dungeon.Tier,
1.0f
);
// Collect all items (normal loot + carried player loot)
var allItems = new List<LootDrop>(loot);
long totalGold = 0;
var allItems = new List<LootDrop>(lootResult.Items);
long totalGold = lootResult.Gold;
// Add any carried player loot from player kills
if (mob.HasCarriedLoot)
@@ -2862,6 +2875,11 @@ public sealed partial class DungeonHandler : IClientMessageHandler
? nearbyOrRelevantMobs
: nearbyOrRelevantMobs.Where(m => !m.IsAlive || m.TargetId == session.CharacterId).ToList();
var visibleMobIds = visibleMobs.Select(m => m.Id).ToHashSet();
var visibleNpcs = (sendSpatialThisTick
? sim.Npcs.Values.Where(n => !spatialFiltering || IsNearby(n.X, n.Y))
: Enumerable.Empty<NpcInstance>())
.ToList();
var visibleNpcIds = visibleNpcs.Select(n => n.Id).ToHashSet();
bool sendMobCatalog = session.CurrentDungeonId.HasValue &&
session.InitialMobCatalogDungeonId != session.CurrentDungeonId;
@@ -2922,6 +2940,28 @@ public sealed partial class DungeonHandler : IClientMessageHandler
tintColor = m.TintColor,
scale = m.Scale
}),
npcs = visibleNpcs.Select(n => new
{
id = n.Id,
definitionId = n.DefinitionId,
name = n.Name,
x = n.X,
y = n.Y,
rotation = n.Rotation,
level = n.Level,
health = n.Health,
maxHealth = n.MaxHealth,
isAlive = n.IsAlive,
isKillable = n.IsKillable,
canShop = n.CanShop,
hasDialog = n.HasDialog,
behavior = n.BehaviorMode.ToString().ToLower(),
onAttackBehavior = n.OnAttackBehavior.ToString().ToLower(),
currentAnimation = n.CurrentAnimation,
spriteConfig = DeserializeSpriteConfigSafe(n.SpriteConfigJson),
tintColor = n.TintColor,
scale = n.Scale
}),
mobCatalog = sendMobCatalog ? sim.Mobs.Values.Select(m => new
{
id = m.Id,
@@ -3095,7 +3135,11 @@ public sealed partial class DungeonHandler : IClientMessageHandler
targetX = e.TargetX,
targetY = e.TargetY,
targetId = e.TargetId
})
}),
npcInteraction = new
{
visibleNpcIds
}
},
exitPosition = sim.Layout.ExitPosition != null ? new