Looooot!
This commit is contained in:
@@ -38,16 +38,20 @@ public sealed class DungeonHandler : IClientMessageHandler
|
||||
private Timer? _tickTimer;
|
||||
private long _currentTick = 0;
|
||||
|
||||
//LootSystem
|
||||
private LootService _lootService = null!;
|
||||
|
||||
public DungeonHandler(
|
||||
ILogger<DungeonHandler> log,
|
||||
ISessionRegistry sessions,
|
||||
IMessageSerializer ser,
|
||||
IServiceScopeFactory scopeFactory)
|
||||
IServiceScopeFactory scopeFactory, LootService lootService)
|
||||
{
|
||||
_log = log;
|
||||
_sessions = sessions;
|
||||
_ser = ser;
|
||||
_scopeFactory = scopeFactory;
|
||||
_lootService = lootService;
|
||||
}
|
||||
|
||||
public IReadOnlyCollection<int> SupportedOpCodes => new[]
|
||||
@@ -69,6 +73,7 @@ public sealed class DungeonHandler : IClientMessageHandler
|
||||
if (_initialized) return;
|
||||
|
||||
await LoadMobDefinitionsAsync();
|
||||
await _lootService.InitializeAsync();
|
||||
|
||||
// Start tick loop (20 ticks per second)
|
||||
_tickTimer = new Timer(TickAll, null, 0, 50);
|
||||
@@ -521,6 +526,19 @@ public sealed class DungeonHandler : IClientMessageHandler
|
||||
{
|
||||
var result = instance.Simulation.Tick(_currentTick);
|
||||
|
||||
// Process mob death events for loot generation
|
||||
if (result.DeathEvents != null)
|
||||
{
|
||||
foreach (var death in result.DeathEvents)
|
||||
{
|
||||
if (death.EntityType == EntityType.Mob && death.KillerType == EntityType.Player)
|
||||
{
|
||||
// Fire and forget loot generation (async in sync context)
|
||||
_ = ProcessMobDeathLootAsync(instance, death);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Send state to all players in this dungeon
|
||||
var playersInDungeon = _playerSessions.Values
|
||||
.Where(s => s.CurrentDungeonId == dungeonId && s.State == PlayerState.InDungeon)
|
||||
@@ -557,6 +575,137 @@ public sealed class DungeonHandler : IClientMessageHandler
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Process loot when a mob dies
|
||||
/// </summary>
|
||||
private async Task ProcessMobDeathLootAsync(DungeonInstance dungeon, DeathEvent death)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Find the mob that died (it's still in the dictionary but marked dead)
|
||||
if (!dungeon.Simulation.Mobs.TryGetValue(death.EntityId, out var mob))
|
||||
return;
|
||||
|
||||
// Find the player who killed it
|
||||
var killerSession = _playerSessions.Values
|
||||
.FirstOrDefault(s => s.CharacterId == (ulong)death.KillerId);
|
||||
|
||||
if (killerSession == null)
|
||||
return;
|
||||
|
||||
// Generate loot from the mob's loot tables
|
||||
var loot = _lootService.GenerateMobLoot(
|
||||
mob.DefinitionId,
|
||||
dungeon.Tier,
|
||||
1.0f // Can multiply by mob's DropChanceMultiplier if stored
|
||||
);
|
||||
|
||||
if (loot.Count == 0)
|
||||
return;
|
||||
|
||||
// Add loot to player's inventory
|
||||
await AddLootToInventoryAsync(killerSession, loot);
|
||||
|
||||
// Send loot popup to the player
|
||||
await SendLootPopupAsync(killerSession, loot);
|
||||
|
||||
_log.LogDebug("Player {Player} received {Count} items from {Mob}",
|
||||
killerSession.Character.Name, loot.Count, mob.Name);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.LogError(ex, "Error processing loot for mob death");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds loot directly to player's inventory in the database
|
||||
/// </summary>
|
||||
private async Task AddLootToInventoryAsync(DungeonPlayerSession session, List<LootDrop> loot)
|
||||
{
|
||||
using var scope = _scopeFactory.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<GameDbContext>();
|
||||
|
||||
// Get existing inventory items
|
||||
var existingItems = await db.Set<DungeonCharacterItem>()
|
||||
.Where(i => i.CharacterId == session.CharacterId)
|
||||
.ToListAsync();
|
||||
|
||||
int nextSlot = existingItems.Count > 0
|
||||
? existingItems.Max(i => i.SlotIndex) + 1
|
||||
: 0;
|
||||
|
||||
foreach (var drop in loot)
|
||||
{
|
||||
// Check if item is stackable and already exists in inventory
|
||||
var existingStack = existingItems.FirstOrDefault(i =>
|
||||
i.ItemDefinitionId == drop.ItemDefinitionId &&
|
||||
drop.Item.Stackable);
|
||||
|
||||
if (existingStack != null && drop.Item.Stackable)
|
||||
{
|
||||
// Add to existing stack
|
||||
existingStack.Quantity = Math.Min(
|
||||
existingStack.Quantity + drop.Quantity,
|
||||
drop.Item.MaxStack
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check if inventory is full (30 slots)
|
||||
if (nextSlot >= 30)
|
||||
{
|
||||
// TODO: Drop item on ground instead
|
||||
_log.LogWarning("Player {Name} inventory full, item {Item} not added",
|
||||
session.Character.Name, drop.Item.Name);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Create new inventory entry
|
||||
var newItem = new DungeonCharacterItem
|
||||
{
|
||||
CharacterId = session.CharacterId,
|
||||
ItemDefinitionId = drop.ItemDefinitionId,
|
||||
Quantity = drop.Quantity,
|
||||
SlotIndex = nextSlot++
|
||||
};
|
||||
db.Set<DungeonCharacterItem>().Add(newItem);
|
||||
existingItems.Add(newItem);
|
||||
}
|
||||
}
|
||||
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends loot popup to client showing what they received
|
||||
/// </summary>
|
||||
private async Task SendLootPopupAsync(DungeonPlayerSession session, List<LootDrop> loot)
|
||||
{
|
||||
var lootData = loot.Select(l => new
|
||||
{
|
||||
id = l.ItemDefinitionId,
|
||||
name = l.Item.Name,
|
||||
description = l.Item.Description,
|
||||
type = l.Item.Type.ToString(),
|
||||
rarity = l.Item.Rarity.ToString(),
|
||||
quantity = l.Quantity,
|
||||
spriteId = l.Item.SpriteId,
|
||||
// Include stats for display
|
||||
armor = l.Item.Armor,
|
||||
minDamage = l.Item.MinDamage,
|
||||
maxDamage = l.Item.MaxDamage,
|
||||
bonusHealth = l.Item.BonusHealth,
|
||||
bonusMana = l.Item.BonusMana,
|
||||
healAmount = l.Item.HealAmount,
|
||||
manaRestore = l.Item.ManaRestore
|
||||
});
|
||||
|
||||
await SendAsync(session.Connection, DungeonOpCodes.LOOT_RECEIVED, new
|
||||
{
|
||||
items = lootData
|
||||
}, CancellationToken.None);
|
||||
}
|
||||
|
||||
private async Task SendDungeonStateAsync(DungeonPlayerSession session, TickResult? tickResult)
|
||||
{
|
||||
@@ -799,6 +948,7 @@ public sealed class DungeonHandler : IClientMessageHandler
|
||||
_log.LogInformation("Dungeon session cleaned up for connection {Id}", connectionId);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Request/Input DTOs
|
||||
|
||||
@@ -0,0 +1,392 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Server.Data;
|
||||
using Server.Data.Entities;
|
||||
|
||||
namespace Server.Game.Dungeon;
|
||||
|
||||
/// <summary>
|
||||
/// Generated loot result - an item with quantity
|
||||
/// </summary>
|
||||
public class LootDrop
|
||||
{
|
||||
public int ItemDefinitionId { get; set; }
|
||||
public DungeonItemDefinition Item { get; set; } = null!;
|
||||
public int Quantity { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Service for generating loot from loot tables
|
||||
/// </summary>
|
||||
public class LootService
|
||||
{
|
||||
private readonly ILogger<LootService> _log;
|
||||
private readonly IServiceScopeFactory _scopeFactory;
|
||||
|
||||
// Cached data
|
||||
private Dictionary<int, DungeonLootTable> _lootTables = new();
|
||||
private Dictionary<int, List<DungeonMobLootTable>> _mobLootTableMappings = new(); // MobId -> List<MobLootTable>
|
||||
private Dictionary<int, DungeonItemDefinition> _itemDefinitions = new();
|
||||
private bool _initialized = false;
|
||||
|
||||
private readonly Random _random = new();
|
||||
|
||||
public LootService(ILogger<LootService> log, IServiceScopeFactory scopeFactory)
|
||||
{
|
||||
_log = log;
|
||||
_scopeFactory = scopeFactory;
|
||||
}
|
||||
|
||||
public async Task InitializeAsync()
|
||||
{
|
||||
if (_initialized) return;
|
||||
|
||||
using var scope = _scopeFactory.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<GameDbContext>();
|
||||
|
||||
// Load all loot tables with their entries
|
||||
var tables = await db.Set<DungeonLootTable>()
|
||||
.Include(t => t.Entries)
|
||||
.Where(t => t.IsEnabled)
|
||||
.ToListAsync();
|
||||
|
||||
// Seed defaults if empty
|
||||
if (tables.Count == 0)
|
||||
{
|
||||
tables = await SeedDefaultLootTablesAsync(db);
|
||||
}
|
||||
|
||||
_lootTables = tables.ToDictionary(t => t.Id);
|
||||
|
||||
// Load mob -> loot table mappings
|
||||
var mappings = await db.Set<DungeonMobLootTable>()
|
||||
.Include(m => m.LootTable)
|
||||
.ToListAsync();
|
||||
|
||||
_mobLootTableMappings = mappings
|
||||
.GroupBy(m => m.MobDefinitionId)
|
||||
.ToDictionary(g => g.Key, g => g.OrderBy(m => m.Priority).ToList());
|
||||
|
||||
// Load item definitions
|
||||
var items = await db.Set<DungeonItemDefinition>()
|
||||
.Where(i => i.IsEnabled)
|
||||
.ToListAsync();
|
||||
|
||||
// Seed default items if empty
|
||||
if (items.Count == 0)
|
||||
{
|
||||
items = await SeedDefaultItemsAsync(db);
|
||||
}
|
||||
|
||||
_itemDefinitions = items.ToDictionary(i => i.Id);
|
||||
|
||||
_initialized = true;
|
||||
_log.LogInformation("LootService initialized: {Tables} tables, {Items} items, {Mappings} mob mappings",
|
||||
_lootTables.Count, _itemDefinitions.Count, mappings.Count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate loot for a mob kill
|
||||
/// </summary>
|
||||
public List<LootDrop> GenerateMobLoot(int mobDefinitionId, int dungeonTier, float dropChanceMultiplier = 1.0f)
|
||||
{
|
||||
var loot = new List<LootDrop>();
|
||||
|
||||
if (!_mobLootTableMappings.TryGetValue(mobDefinitionId, out var mappings))
|
||||
{
|
||||
return loot; // No loot tables for this mob
|
||||
}
|
||||
|
||||
foreach (var mapping in mappings)
|
||||
{
|
||||
// Check if this table rolls
|
||||
if (_random.NextDouble() > mapping.RollChance)
|
||||
continue;
|
||||
|
||||
if (!_lootTables.TryGetValue(mapping.LootTableId, out var table))
|
||||
continue;
|
||||
|
||||
// Check tier requirements
|
||||
if (dungeonTier < table.MinTier || dungeonTier > table.MaxTier)
|
||||
continue;
|
||||
|
||||
// Generate drops from this table
|
||||
var drops = GenerateFromTable(table, dungeonTier, dropChanceMultiplier);
|
||||
loot.AddRange(drops);
|
||||
}
|
||||
|
||||
return loot;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate loot from a specific loot table
|
||||
/// </summary>
|
||||
public List<LootDrop> GenerateFromTable(DungeonLootTable table, int dungeonTier, float extraMultiplier = 1.0f)
|
||||
{
|
||||
var loot = new List<LootDrop>();
|
||||
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);
|
||||
}
|
||||
|
||||
// Determine how many additional drops
|
||||
int dropCount = table.GuaranteedDrop
|
||||
? _random.Next(table.MinDrops, table.MaxDrops + 1)
|
||||
: 0;
|
||||
|
||||
// Roll for each non-guaranteed entry
|
||||
var nonGuaranteed = entries.Where(e => !e.Guaranteed).ToList();
|
||||
|
||||
foreach (var entry in nonGuaranteed)
|
||||
{
|
||||
// Calculate drop chance with tier scaling
|
||||
float chance = entry.DropChance + (entry.DropChancePerTier * (dungeonTier - 1));
|
||||
chance = Math.Min(chance, entry.MaxDropChance);
|
||||
chance *= totalMultiplier;
|
||||
|
||||
if (_random.NextDouble() < chance)
|
||||
{
|
||||
AddDrop(loot, entry);
|
||||
dropCount--;
|
||||
}
|
||||
}
|
||||
|
||||
// If we need more drops to meet minimum, use weighted random selection
|
||||
while (dropCount > 0 && nonGuaranteed.Count > 0)
|
||||
{
|
||||
var selected = WeightedRandomSelect(nonGuaranteed);
|
||||
if (selected != null)
|
||||
{
|
||||
AddDrop(loot, selected);
|
||||
dropCount--;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return loot;
|
||||
}
|
||||
|
||||
private void AddDrop(List<LootDrop> loot, DungeonLootTableEntry entry)
|
||||
{
|
||||
if (!_itemDefinitions.TryGetValue(entry.ItemDefinitionId, out var item))
|
||||
return;
|
||||
|
||||
int quantity = _random.Next(entry.MinQuantity, entry.MaxQuantity + 1);
|
||||
|
||||
// Check if we already have this item in loot (stack it)
|
||||
var existing = loot.FirstOrDefault(l => l.ItemDefinitionId == entry.ItemDefinitionId);
|
||||
if (existing != null && item.Stackable)
|
||||
{
|
||||
existing.Quantity = Math.Min(existing.Quantity + quantity, item.MaxStack);
|
||||
}
|
||||
else
|
||||
{
|
||||
loot.Add(new LootDrop
|
||||
{
|
||||
ItemDefinitionId = entry.ItemDefinitionId,
|
||||
Item = item,
|
||||
Quantity = quantity
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private DungeonLootTableEntry? WeightedRandomSelect(List<DungeonLootTableEntry> entries)
|
||||
{
|
||||
int totalWeight = entries.Sum(e => e.Weight);
|
||||
if (totalWeight <= 0) return null;
|
||||
|
||||
int roll = _random.Next(totalWeight);
|
||||
int cumulative = 0;
|
||||
|
||||
foreach (var entry in entries)
|
||||
{
|
||||
cumulative += entry.Weight;
|
||||
if (roll < cumulative)
|
||||
return entry;
|
||||
}
|
||||
|
||||
return entries.LastOrDefault();
|
||||
}
|
||||
|
||||
public DungeonItemDefinition? GetItemDefinition(int itemId)
|
||||
{
|
||||
return _itemDefinitions.GetValueOrDefault(itemId);
|
||||
}
|
||||
|
||||
private async Task<List<DungeonLootTable>> SeedDefaultLootTablesAsync(GameDbContext db)
|
||||
{
|
||||
var tables = GetDefaultLootTables();
|
||||
db.Set<DungeonLootTable>().AddRange(tables);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
// Now add entries (need table IDs first)
|
||||
var entries = GetDefaultLootTableEntries(tables);
|
||||
db.Set<DungeonLootTableEntry>().AddRange(entries);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
// Add mob mappings
|
||||
var mappings = GetDefaultMobLootTableMappings(tables);
|
||||
db.Set<DungeonMobLootTable>().AddRange(mappings);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
_log.LogInformation("Seeded {Count} default loot tables", tables.Count);
|
||||
|
||||
// Reload with entries
|
||||
return await db.Set<DungeonLootTable>()
|
||||
.Include(t => t.Entries)
|
||||
.Where(t => t.IsEnabled)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
private List<DungeonLootTable> GetDefaultLootTables()
|
||||
{
|
||||
return new List<DungeonLootTable>
|
||||
{
|
||||
// Common mob loot
|
||||
new() { Id = 1, Name = "Common Mob", Description = "Basic drops from common mobs", MinDrops = 1, MaxDrops = 2, GuaranteedDrop = true },
|
||||
new() { Id = 2, Name = "Undead Mob", Description = "Drops from undead creatures", MinDrops = 1, MaxDrops = 2 },
|
||||
new() { Id = 3, Name = "Beast Mob", Description = "Drops from beasts", MinDrops = 1, MaxDrops = 2 },
|
||||
new() { Id = 4, Name = "Demon Mob", Description = "Drops from demons", MinDrops = 1, MaxDrops = 3 },
|
||||
new() { Id = 5, Name = "Elemental Mob", Description = "Drops from elementals", MinDrops = 1, MaxDrops = 2 },
|
||||
|
||||
// Boss loot
|
||||
new() { Id = 10, Name = "Boss Common", Description = "Guaranteed boss drops", MinDrops = 2, MaxDrops = 4, GuaranteedDrop = true },
|
||||
new() { Id = 11, Name = "Boss Rare", Description = "Rare boss drops", MinDrops = 1, MaxDrops = 2, DropChanceMultiplier = 2.0f },
|
||||
|
||||
// Equipment tables (rare drops)
|
||||
new() { Id = 20, Name = "Weapon Drop", Description = "Chance for weapon drop", MinDrops = 1, MaxDrops = 1, DropChanceMultiplier = 0.5f },
|
||||
new() { Id = 21, Name = "Armor Drop", Description = "Chance for armor drop", MinDrops = 1, MaxDrops = 1, DropChanceMultiplier = 0.5f },
|
||||
};
|
||||
}
|
||||
|
||||
private List<DungeonLootTableEntry> GetDefaultLootTableEntries(List<DungeonLootTable> tables)
|
||||
{
|
||||
// Item IDs from default items (we'll create these next):
|
||||
// 1-10: Materials
|
||||
// 11-20: Consumables
|
||||
// 21-30: Weapons
|
||||
// 31-40: Armor
|
||||
|
||||
return new List<DungeonLootTableEntry>
|
||||
{
|
||||
// Common Mob (Table 1) - basic materials
|
||||
new() { LootTableId = 1, ItemDefinitionId = 1, DropChance = 0.5f, MinQuantity = 1, MaxQuantity = 3, Weight = 100 }, // Bone Fragment
|
||||
new() { LootTableId = 1, ItemDefinitionId = 11, DropChance = 0.2f, MinQuantity = 1, MaxQuantity = 1, Weight = 50 }, // Minor Health Potion
|
||||
|
||||
// Undead Mob (Table 2)
|
||||
new() { LootTableId = 2, ItemDefinitionId = 1, DropChance = 0.8f, MinQuantity = 2, MaxQuantity = 5, Weight = 100 }, // Bone Fragment
|
||||
new() { LootTableId = 2, ItemDefinitionId = 2, DropChance = 0.3f, MinQuantity = 1, MaxQuantity = 2, Weight = 60 }, // Rotted Cloth
|
||||
new() { LootTableId = 2, ItemDefinitionId = 3, DropChance = 0.1f, MinQuantity = 1, MaxQuantity = 1, Weight = 20 }, // Soul Essence
|
||||
|
||||
// Beast Mob (Table 3)
|
||||
new() { LootTableId = 3, ItemDefinitionId = 4, DropChance = 0.7f, MinQuantity = 1, MaxQuantity = 3, Weight = 100 }, // Beast Hide
|
||||
new() { LootTableId = 3, ItemDefinitionId = 5, DropChance = 0.4f, MinQuantity = 1, MaxQuantity = 2, Weight = 70 }, // Beast Fang
|
||||
new() { LootTableId = 3, ItemDefinitionId = 6, DropChance = 0.2f, MinQuantity = 1, MaxQuantity = 1, Weight = 30 }, // Beast Heart
|
||||
|
||||
// Demon Mob (Table 4)
|
||||
new() { LootTableId = 4, ItemDefinitionId = 7, DropChance = 0.6f, MinQuantity = 1, MaxQuantity = 2, Weight = 100 }, // Demon Essence
|
||||
new() { LootTableId = 4, ItemDefinitionId = 8, DropChance = 0.3f, MinQuantity = 1, MaxQuantity = 1, Weight = 50 }, // Infernal Shard
|
||||
new() { LootTableId = 4, ItemDefinitionId = 12, DropChance = 0.25f, MinQuantity = 1, MaxQuantity = 1, Weight = 40 }, // Health Potion
|
||||
|
||||
// Elemental Mob (Table 5)
|
||||
new() { LootTableId = 5, ItemDefinitionId = 9, DropChance = 0.7f, MinQuantity = 1, MaxQuantity = 3, Weight = 100 }, // Elemental Core
|
||||
new() { LootTableId = 5, ItemDefinitionId = 10, DropChance = 0.2f, MinQuantity = 1, MaxQuantity = 1, Weight = 40 }, // Arcane Dust
|
||||
new() { LootTableId = 5, ItemDefinitionId = 14, DropChance = 0.2f, MinQuantity = 1, MaxQuantity = 1, Weight = 30 }, // Mana Potion
|
||||
|
||||
// Boss Common (Table 10)
|
||||
new() { LootTableId = 10, ItemDefinitionId = 12, DropChance = 1.0f, MinQuantity = 2, MaxQuantity = 3, Weight = 100, Guaranteed = true }, // Health Potion
|
||||
new() { LootTableId = 10, ItemDefinitionId = 14, DropChance = 1.0f, MinQuantity = 1, MaxQuantity = 2, Weight = 100, Guaranteed = true }, // Mana Potion
|
||||
new() { LootTableId = 10, ItemDefinitionId = 3, DropChance = 0.8f, MinQuantity = 2, MaxQuantity = 4, Weight = 80 }, // Soul Essence
|
||||
|
||||
// Boss Rare (Table 11)
|
||||
new() { LootTableId = 11, ItemDefinitionId = 21, DropChance = 0.15f, MinQuantity = 1, MaxQuantity = 1, Weight = 50, DropChancePerTier = 0.03f }, // Iron Sword
|
||||
new() { LootTableId = 11, ItemDefinitionId = 31, DropChance = 0.15f, MinQuantity = 1, MaxQuantity = 1, Weight = 50, DropChancePerTier = 0.03f }, // Leather Armor
|
||||
new() { LootTableId = 11, ItemDefinitionId = 8, DropChance = 0.5f, MinQuantity = 1, MaxQuantity = 2, Weight = 100 }, // Infernal Shard
|
||||
|
||||
// Weapon Drop (Table 20)
|
||||
new() { LootTableId = 20, ItemDefinitionId = 21, DropChance = 0.05f, MinQuantity = 1, MaxQuantity = 1, Weight = 100, DropChancePerTier = 0.01f }, // Iron Sword
|
||||
new() { LootTableId = 20, ItemDefinitionId = 22, DropChance = 0.03f, MinQuantity = 1, MaxQuantity = 1, Weight = 60, DropChancePerTier = 0.01f }, // Steel Sword
|
||||
new() { LootTableId = 20, ItemDefinitionId = 23, DropChance = 0.04f, MinQuantity = 1, MaxQuantity = 1, Weight = 80, DropChancePerTier = 0.01f }, // Wooden Staff
|
||||
|
||||
// Armor Drop (Table 21)
|
||||
new() { LootTableId = 21, ItemDefinitionId = 31, DropChance = 0.05f, MinQuantity = 1, MaxQuantity = 1, Weight = 100, DropChancePerTier = 0.01f }, // Leather Armor
|
||||
new() { LootTableId = 21, ItemDefinitionId = 32, DropChance = 0.03f, MinQuantity = 1, MaxQuantity = 1, Weight = 60, DropChancePerTier = 0.01f }, // Chainmail
|
||||
new() { LootTableId = 21, ItemDefinitionId = 33, DropChance = 0.05f, MinQuantity = 1, MaxQuantity = 1, Weight = 80, DropChancePerTier = 0.01f }, // Leather Helm
|
||||
};
|
||||
}
|
||||
|
||||
private List<DungeonMobLootTable> GetDefaultMobLootTableMappings(List<DungeonLootTable> tables)
|
||||
{
|
||||
// Mob IDs from DefaultDungeonMobs:
|
||||
// 1: Skeleton, 2: Zombie, 3: Ghost (Undead)
|
||||
// 4: Giant Spider, 5: Cave Wolf (Beast)
|
||||
// 6: Lesser Demon, 7: Imp (Demon)
|
||||
// 8: Fire Elemental, 9: Ice Elemental (Elemental)
|
||||
// 10: Skeleton Lord (Boss)
|
||||
|
||||
return new List<DungeonMobLootTable>
|
||||
{
|
||||
// Undead mobs
|
||||
new() { MobDefinitionId = 1, LootTableId = 1, Priority = 0 }, // Skeleton - Common
|
||||
new() { MobDefinitionId = 1, LootTableId = 2, Priority = 1 }, // Skeleton - Undead
|
||||
new() { MobDefinitionId = 1, LootTableId = 20, Priority = 2, RollChance = 0.3f }, // Skeleton - Weapon chance
|
||||
|
||||
new() { MobDefinitionId = 2, LootTableId = 1, Priority = 0 }, // Zombie - Common
|
||||
new() { MobDefinitionId = 2, LootTableId = 2, Priority = 1 }, // Zombie - Undead
|
||||
new() { MobDefinitionId = 2, LootTableId = 21, Priority = 2, RollChance = 0.3f }, // Zombie - Armor chance
|
||||
|
||||
new() { MobDefinitionId = 3, LootTableId = 1, Priority = 0 }, // Ghost - Common
|
||||
new() { MobDefinitionId = 3, LootTableId = 2, Priority = 1 }, // Ghost - Undead
|
||||
|
||||
// Beast mobs
|
||||
new() { MobDefinitionId = 4, LootTableId = 1, Priority = 0 }, // Giant Spider - Common
|
||||
new() { MobDefinitionId = 4, LootTableId = 3, Priority = 1 }, // Giant Spider - Beast
|
||||
|
||||
new() { MobDefinitionId = 5, LootTableId = 1, Priority = 0 }, // Cave Wolf - Common
|
||||
new() { MobDefinitionId = 5, LootTableId = 3, Priority = 1 }, // Cave Wolf - Beast
|
||||
new() { MobDefinitionId = 5, LootTableId = 20, Priority = 2, RollChance = 0.2f }, // Cave Wolf - Weapon
|
||||
|
||||
// Demon mobs
|
||||
new() { MobDefinitionId = 6, LootTableId = 1, Priority = 0 }, // Lesser Demon - Common
|
||||
new() { MobDefinitionId = 6, LootTableId = 4, Priority = 1 }, // Lesser Demon - Demon
|
||||
new() { MobDefinitionId = 6, LootTableId = 20, Priority = 2, RollChance = 0.4f }, // Lesser Demon - Weapon
|
||||
new() { MobDefinitionId = 6, LootTableId = 21, Priority = 3, RollChance = 0.4f }, // Lesser Demon - Armor
|
||||
|
||||
new() { MobDefinitionId = 7, LootTableId = 1, Priority = 0 }, // Imp - Common
|
||||
new() { MobDefinitionId = 7, LootTableId = 4, Priority = 1 }, // Imp - Demon
|
||||
|
||||
// Elemental mobs
|
||||
new() { MobDefinitionId = 8, LootTableId = 1, Priority = 0 }, // Fire Elemental - Common
|
||||
new() { MobDefinitionId = 8, LootTableId = 5, Priority = 1 }, // Fire Elemental - Elemental
|
||||
|
||||
new() { MobDefinitionId = 9, LootTableId = 1, Priority = 0 }, // Ice Elemental - Common
|
||||
new() { MobDefinitionId = 9, LootTableId = 5, Priority = 1 }, // Ice Elemental - Elemental
|
||||
|
||||
// Boss
|
||||
new() { MobDefinitionId = 10, LootTableId = 10, Priority = 0 }, // Skeleton Lord - Boss Common
|
||||
new() { MobDefinitionId = 10, LootTableId = 11, Priority = 1 }, // Skeleton Lord - Boss Rare
|
||||
new() { MobDefinitionId = 10, LootTableId = 2, Priority = 2 }, // Skeleton Lord - Undead
|
||||
};
|
||||
}
|
||||
|
||||
private async Task<List<DungeonItemDefinition>> SeedDefaultItemsAsync(GameDbContext db)
|
||||
{
|
||||
var items = DefaultDungeonItems.GetDefaultItems();
|
||||
db.Set<DungeonItemDefinition>().AddRange(items);
|
||||
await db.SaveChangesAsync();
|
||||
_log.LogInformation("Seeded {Count} default item definitions", items.Count);
|
||||
return items;
|
||||
}
|
||||
}
|
||||
@@ -23,9 +23,9 @@ public class DeathEvent
|
||||
{
|
||||
public EntityType EntityType { get; set; }
|
||||
public int EntityId { get; set; }
|
||||
public string EntityName { get; set; } = "";
|
||||
public EntityType KillerType { get; set; }
|
||||
public int KillerId { get; set; }
|
||||
public string EntityName { get; set; } = "";
|
||||
public string KillerName { get; set; } = "";
|
||||
public int XpReward { get; set; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user