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
+29 -16
View File
@@ -16,6 +16,12 @@ public class LootDrop
public int Quantity { get; set; }
}
public class LootRollResult
{
public List<LootDrop> Items { get; set; } = new();
public long Gold { get; set; }
}
/// <summary>
/// Service for generating loot from loot tables
/// </summary>
@@ -109,15 +115,15 @@ public class LootService
/// <summary>
/// Generate loot for a mob kill
/// </summary>
public List<LootDrop> GenerateMobLoot(int mobDefinitionId, int dungeonTier, float dropChanceMultiplier = 1.0f)
public LootRollResult GenerateMobLoot(int mobDefinitionId, int dungeonTier, float dropChanceMultiplier = 1.0f)
{
var loot = new List<LootDrop>();
var result = new LootRollResult();
if (!_mobLootTableMappings.TryGetValue(mobDefinitionId, out var mappings))
{
_log.LogWarning("No loot tables found for mob {MobId}. Available mappings: {MobIds}",
mobDefinitionId, string.Join(", ", _mobLootTableMappings.Keys));
return loot; // No loot tables for this mob
return result; // No loot tables for this mob
}
_log.LogDebug("Generating loot for mob {MobId}, found {Count} table mappings", mobDefinitionId, mappings.Count);
@@ -137,31 +143,29 @@ public class LootService
// Generate drops from this table
var drops = GenerateFromTable(table, dungeonTier, dropChanceMultiplier);
loot.AddRange(drops);
result.Items.AddRange(drops.Items);
result.Gold += drops.Gold;
}
_log.LogDebug("Generated {Count} loot drops for mob {MobId}", loot.Count, mobDefinitionId);
_log.LogDebug("Generated {Count} loot drops and {Gold} gold for mob {MobId}", result.Items.Count, result.Gold, mobDefinitionId);
return loot;
return result;
}
/// <summary>
/// Generate loot from a specific loot table
/// </summary>
public List<LootDrop> GenerateFromTable(DungeonLootTable table, int dungeonTier, float extraMultiplier = 1.0f)
public LootRollResult GenerateFromTable(DungeonLootTable table, int dungeonTier, float extraMultiplier = 1.0f)
{
var loot = new List<LootDrop>();
var result = new LootRollResult();
var entries = table.Entries.ToList();
if (entries.Count == 0)
return loot;
float totalMultiplier = table.DropChanceMultiplier * extraMultiplier;
// First, add all guaranteed drops
foreach (var entry in entries.Where(e => e.Guaranteed))
{
AddDrop(loot, entry);
AddDrop(result.Items, entry);
}
// Determine how many additional drops
@@ -181,7 +185,7 @@ public class LootService
if (_random.NextDouble() < chance)
{
AddDrop(loot, entry);
AddDrop(result.Items, entry);
dropCount--;
}
}
@@ -192,7 +196,7 @@ public class LootService
var selected = WeightedRandomSelect(nonGuaranteed);
if (selected != null)
{
AddDrop(loot, selected);
AddDrop(result.Items, selected);
dropCount--;
}
else
@@ -200,8 +204,17 @@ public class LootService
break;
}
}
return loot;
// Roll optional gold for this table
var goldChance = Math.Clamp(table.GoldDropChance, 0f, 1f) * totalMultiplier;
if (table.MaxGold > 0 && goldChance > 0f && _random.NextDouble() < goldChance)
{
var minGold = Math.Max(0, table.MinGold);
var maxGold = Math.Max(minGold, table.MaxGold);
result.Gold += _random.Next(minGold, maxGold + 1);
}
return result;
}
private void AddDrop(List<LootDrop> loot, DungeonLootTableEntry entry)