This commit is contained in:
dingo
2025-12-08 11:57:08 -05:00
parent 3755b13931
commit 17da6639cf
15 changed files with 3098 additions and 5 deletions
+151 -1
View File
@@ -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
+392
View File
@@ -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;
}
}
+1 -1
View File
@@ -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; }
}
File diff suppressed because it is too large Load Diff
+135
View File
@@ -0,0 +1,135 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace SystemRevivalServer.Migrations
{
/// <inheritdoc />
public partial class LootTables : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "dungeon_loot_tables",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Name = table.Column<string>(type: "varchar(64)", maxLength: 64, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
Description = table.Column<string>(type: "varchar(256)", maxLength: 256, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
MinTier = table.Column<int>(type: "int", nullable: false),
MaxTier = table.Column<int>(type: "int", nullable: false),
DropChanceMultiplier = table.Column<float>(type: "float", nullable: false),
MinDrops = table.Column<int>(type: "int", nullable: false),
MaxDrops = table.Column<int>(type: "int", nullable: false),
GuaranteedDrop = table.Column<bool>(type: "tinyint(1)", nullable: false),
IsEnabled = table.Column<bool>(type: "tinyint(1)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_dungeon_loot_tables", x => x.Id);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "dungeon_loot_table_entries",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
LootTableId = table.Column<int>(type: "int", nullable: false),
ItemDefinitionId = table.Column<int>(type: "int", nullable: false),
DropChance = table.Column<float>(type: "float", nullable: false),
MinQuantity = table.Column<int>(type: "int", nullable: false),
MaxQuantity = table.Column<int>(type: "int", nullable: false),
Weight = table.Column<int>(type: "int", nullable: false),
Guaranteed = table.Column<bool>(type: "tinyint(1)", nullable: false),
DropChancePerTier = table.Column<float>(type: "float", nullable: false),
MaxDropChance = table.Column<float>(type: "float", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_dungeon_loot_table_entries", x => x.Id);
table.ForeignKey(
name: "FK_dungeon_loot_table_entries_dungeon_item_definitions_ItemDefi~",
column: x => x.ItemDefinitionId,
principalTable: "dungeon_item_definitions",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_dungeon_loot_table_entries_dungeon_loot_tables_LootTableId",
column: x => x.LootTableId,
principalTable: "dungeon_loot_tables",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "dungeon_mob_loot_tables",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
MobDefinitionId = table.Column<int>(type: "int", nullable: false),
LootTableId = table.Column<int>(type: "int", nullable: false),
Priority = table.Column<int>(type: "int", nullable: false),
RollChance = table.Column<float>(type: "float", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_dungeon_mob_loot_tables", x => x.Id);
table.ForeignKey(
name: "FK_dungeon_mob_loot_tables_dungeon_loot_tables_LootTableId",
column: x => x.LootTableId,
principalTable: "dungeon_loot_tables",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_dungeon_mob_loot_tables_dungeon_mob_definitions_MobDefinitio~",
column: x => x.MobDefinitionId,
principalTable: "dungeon_mob_definitions",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateIndex(
name: "IX_dungeon_loot_table_entries_ItemDefinitionId",
table: "dungeon_loot_table_entries",
column: "ItemDefinitionId");
migrationBuilder.CreateIndex(
name: "IX_dungeon_loot_table_entries_LootTableId",
table: "dungeon_loot_table_entries",
column: "LootTableId");
migrationBuilder.CreateIndex(
name: "IX_dungeon_mob_loot_tables_LootTableId",
table: "dungeon_mob_loot_tables",
column: "LootTableId");
migrationBuilder.CreateIndex(
name: "IX_dungeon_mob_loot_tables_MobDefinitionId",
table: "dungeon_mob_loot_tables",
column: "MobDefinitionId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "dungeon_loot_table_entries");
migrationBuilder.DropTable(
name: "dungeon_mob_loot_tables");
migrationBuilder.DropTable(
name: "dungeon_loot_tables");
}
}
}
+160
View File
@@ -362,6 +362,94 @@ namespace SystemRevivalServer.Migrations
b.ToTable("dungeon_learned_spells");
});
modelBuilder.Entity("Server.Data.Entities.DungeonLootTable", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Description")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("varchar(256)");
b.Property<float>("DropChanceMultiplier")
.HasColumnType("float");
b.Property<bool>("GuaranteedDrop")
.HasColumnType("tinyint(1)");
b.Property<bool>("IsEnabled")
.HasColumnType("tinyint(1)");
b.Property<int>("MaxDrops")
.HasColumnType("int");
b.Property<int>("MaxTier")
.HasColumnType("int");
b.Property<int>("MinDrops")
.HasColumnType("int");
b.Property<int>("MinTier")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(64)
.HasColumnType("varchar(64)");
b.HasKey("Id");
b.ToTable("dungeon_loot_tables");
});
modelBuilder.Entity("Server.Data.Entities.DungeonLootTableEntry", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<float>("DropChance")
.HasColumnType("float");
b.Property<float>("DropChancePerTier")
.HasColumnType("float");
b.Property<bool>("Guaranteed")
.HasColumnType("tinyint(1)");
b.Property<int>("ItemDefinitionId")
.HasColumnType("int");
b.Property<int>("LootTableId")
.HasColumnType("int");
b.Property<float>("MaxDropChance")
.HasColumnType("float");
b.Property<int>("MaxQuantity")
.HasColumnType("int");
b.Property<int>("MinQuantity")
.HasColumnType("int");
b.Property<int>("Weight")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ItemDefinitionId");
b.HasIndex("LootTableId");
b.ToTable("dungeon_loot_table_entries");
});
modelBuilder.Entity("Server.Data.Entities.DungeonMobDefinition", b =>
{
b.Property<int>("Id")
@@ -506,6 +594,35 @@ namespace SystemRevivalServer.Migrations
b.ToTable("dungeon_mob_definitions");
});
modelBuilder.Entity("Server.Data.Entities.DungeonMobLootTable", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<int>("LootTableId")
.HasColumnType("int");
b.Property<int>("MobDefinitionId")
.HasColumnType("int");
b.Property<int>("Priority")
.HasColumnType("int");
b.Property<float>("RollChance")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("LootTableId");
b.HasIndex("MobDefinitionId");
b.ToTable("dungeon_mob_loot_tables");
});
modelBuilder.Entity("Server.Data.Entities.DungeonSpellDefinition", b =>
{
b.Property<int>("Id")
@@ -1297,6 +1414,44 @@ namespace SystemRevivalServer.Migrations
b.Navigation("Definition");
});
modelBuilder.Entity("Server.Data.Entities.DungeonLootTableEntry", b =>
{
b.HasOne("Server.Data.Entities.DungeonItemDefinition", "ItemDefinition")
.WithMany()
.HasForeignKey("ItemDefinitionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Server.Data.Entities.DungeonLootTable", "LootTable")
.WithMany("Entries")
.HasForeignKey("LootTableId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("ItemDefinition");
b.Navigation("LootTable");
});
modelBuilder.Entity("Server.Data.Entities.DungeonMobLootTable", b =>
{
b.HasOne("Server.Data.Entities.DungeonLootTable", "LootTable")
.WithMany()
.HasForeignKey("LootTableId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Server.Data.Entities.DungeonMobDefinition", "MobDefinition")
.WithMany()
.HasForeignKey("MobDefinitionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("LootTable");
b.Navigation("MobDefinition");
});
modelBuilder.Entity("Server.Data.Entities.DungeonStashItem", b =>
{
b.HasOne("Server.Data.Entities.DungeonCharacter", "Character")
@@ -1430,6 +1585,11 @@ namespace SystemRevivalServer.Migrations
b.Navigation("Stash");
});
modelBuilder.Entity("Server.Data.Entities.DungeonLootTable", b =>
{
b.Navigation("Entries");
});
#pragma warning restore 612, 618
}
}
+2
View File
@@ -32,4 +32,6 @@ public static class DungeonOpCodes
public const int EVENT_DEATH = 501;
public const int EVENT_LEVELUP = 502;
public const int EVENT_LOOT = 503;
public const int LOOT_RECEIVED = 160;
}
+1
View File
@@ -59,6 +59,7 @@ builder.Services.AddSingleton<MatchManager>();
builder.Services.AddSingleton<IClientMessageHandler, GameHandler>();
builder.Services.AddSingleton<DungeonHandler>();
builder.Services.AddSingleton<IClientMessageHandler>(sp => sp.GetRequiredService<DungeonHandler>());
builder.Services.AddSingleton<LootService>();
builder.Services.AddSingleton<MessageRouter>();
builder.Services.AddSingleton<IItemService, CachedItemService>();
+3
View File
@@ -28,6 +28,9 @@ public sealed class GameDbContext : DbContext
public DbSet<DungeonSpellDefinition> DungeonSpellDefinitions => Set<DungeonSpellDefinition>();
public DbSet<DungeonLearnedSpell> DungeonLearnedSpells => Set<DungeonLearnedSpell>();
public DbSet<DungeonMobDefinition> DungeonMobDefinitions => Set<DungeonMobDefinition>();
public DbSet<DungeonLootTable> DungeonLootTables => Set<DungeonLootTable>();
public DbSet<DungeonLootTableEntry> DungeonLootTableEntries => Set<DungeonLootTableEntry>();
public DbSet<DungeonMobLootTable> DungeonMobLootTables => Set<DungeonMobLootTable>();
protected override void OnModelCreating(ModelBuilder b)
{
b.ApplyConfigurationsFromAssembly(typeof(GameDbContext).Assembly);
+481
View File
@@ -0,0 +1,481 @@
using Server.Data.Enums;
namespace Server.Data.Entities;
/// <summary>
/// Default item definitions - seeded on first startup
/// </summary>
public static class DefaultDungeonItems
{
public static List<DungeonItemDefinition> GetDefaultItems()
{
return new List<DungeonItemDefinition>
{
// ==================== CRAFTING MATERIALS (1-10) ====================
new()
{
Id = 1,
Name = "Bone Fragment",
Description = "A fragment of bone from the undead. Used in crafting.",
Type = ItemType.Material,
Rarity = ItemRarity.Common,
Stackable = true,
MaxStack = 99,
SpriteId = 1
},
new()
{
Id = 2,
Name = "Rotted Cloth",
Description = "Decayed fabric from the walking dead.",
Type = ItemType.Material,
Rarity = ItemRarity.Common,
Stackable = true,
MaxStack = 99,
SpriteId = 2
},
new()
{
Id = 3,
Name = "Soul Essence",
Description = "The captured essence of a departed spirit. Valuable for enchanting.",
Type = ItemType.Material,
Rarity = ItemRarity.Uncommon,
Stackable = true,
MaxStack = 50,
SpriteId = 3
},
new()
{
Id = 4,
Name = "Beast Hide",
Description = "Tough hide from a dungeon beast.",
Type = ItemType.Material,
Rarity = ItemRarity.Common,
Stackable = true,
MaxStack = 99,
SpriteId = 4
},
new()
{
Id = 5,
Name = "Beast Fang",
Description = "A sharp fang from a predatory creature.",
Type = ItemType.Material,
Rarity = ItemRarity.Common,
Stackable = true,
MaxStack = 99,
SpriteId = 5
},
new()
{
Id = 6,
Name = "Beast Heart",
Description = "The still-warm heart of a powerful beast.",
Type = ItemType.Material,
Rarity = ItemRarity.Uncommon,
Stackable = true,
MaxStack = 30,
SpriteId = 6
},
new()
{
Id = 7,
Name = "Demon Essence",
Description = "Dark energy condensed from demonic creatures.",
Type = ItemType.Material,
Rarity = ItemRarity.Uncommon,
Stackable = true,
MaxStack = 50,
SpriteId = 7
},
new()
{
Id = 8,
Name = "Infernal Shard",
Description = "A crystallized fragment of hellfire.",
Type = ItemType.Material,
Rarity = ItemRarity.Rare,
Stackable = true,
MaxStack = 30,
SpriteId = 8
},
new()
{
Id = 9,
Name = "Elemental Core",
Description = "The magical core of an elemental being.",
Type = ItemType.Material,
Rarity = ItemRarity.Uncommon,
Stackable = true,
MaxStack = 50,
SpriteId = 9
},
new()
{
Id = 10,
Name = "Arcane Dust",
Description = "Fine magical particles. Essential for enchanting.",
Type = ItemType.Material,
Rarity = ItemRarity.Rare,
Stackable = true,
MaxStack = 99,
SpriteId = 10
},
// ==================== CONSUMABLES (11-20) ====================
new()
{
Id = 11,
Name = "Minor Health Potion",
Description = "Restores a small amount of health.",
Type = ItemType.Consumable,
Rarity = ItemRarity.Common,
Stackable = true,
MaxStack = 20,
HealAmount = 30,
SpriteId = 11
},
new()
{
Id = 12,
Name = "Health Potion",
Description = "Restores a moderate amount of health.",
Type = ItemType.Consumable,
Rarity = ItemRarity.Common,
Stackable = true,
MaxStack = 20,
HealAmount = 75,
SpriteId = 12
},
new()
{
Id = 13,
Name = "Greater Health Potion",
Description = "Restores a large amount of health.",
Type = ItemType.Consumable,
Rarity = ItemRarity.Uncommon,
Stackable = true,
MaxStack = 10,
HealAmount = 150,
SpriteId = 13
},
new()
{
Id = 14,
Name = "Minor Mana Potion",
Description = "Restores a small amount of mana.",
Type = ItemType.Consumable,
Rarity = ItemRarity.Common,
Stackable = true,
MaxStack = 20,
ManaRestore = 25,
SpriteId = 14
},
new()
{
Id = 15,
Name = "Mana Potion",
Description = "Restores a moderate amount of mana.",
Type = ItemType.Consumable,
Rarity = ItemRarity.Common,
Stackable = true,
MaxStack = 20,
ManaRestore = 60,
SpriteId = 15
},
new()
{
Id = 16,
Name = "Scroll of Escape",
Description = "Teleports you safely out of the dungeon.",
Type = ItemType.Consumable,
Rarity = ItemRarity.Uncommon,
Stackable = true,
MaxStack = 5,
IsTeleportScroll = true,
SpriteId = 16
},
// ==================== WEAPONS (21-30) ====================
new()
{
Id = 21,
Name = "Iron Sword",
Description = "A sturdy iron blade.",
Type = ItemType.Weapon,
Rarity = ItemRarity.Common,
EquipSlot = DungeonEquipmentSlot.MainHand,
MinDamage = 8,
MaxDamage = 14,
AttackRange = 40,
RequiredLevel = 1,
SpriteId = 21
},
new()
{
Id = 22,
Name = "Steel Sword",
Description = "A well-forged steel blade.",
Type = ItemType.Weapon,
Rarity = ItemRarity.Uncommon,
EquipSlot = DungeonEquipmentSlot.MainHand,
MinDamage = 12,
MaxDamage = 20,
AttackRange = 40,
RequiredLevel = 3,
RequiredStrength = 5,
SpriteId = 22
},
new()
{
Id = 23,
Name = "Wooden Air Staff",
Description = "A simple staff channeling magical energy.",
Type = ItemType.Weapon,
Rarity = ItemRarity.Common,
EquipSlot = DungeonEquipmentSlot.MainHand,
MinDamage = 5,
MaxDamage = 10,
AttackRange = 100,
DamageType = DamageType.Wind,
BonusMana = 10,
RequiredLevel = 1,
SpriteId = 23
},
new()
{
Id = 24,
Name = "Enchanted Fire Staff",
Description = "A staff imbued with arcane power.",
Type = ItemType.Weapon,
Rarity = ItemRarity.Uncommon,
EquipSlot = DungeonEquipmentSlot.MainHand,
MinDamage = 10,
MaxDamage = 18,
AttackRange = 120,
DamageType = DamageType.Fire,
BonusMana = 25,
BonusIntelligence = 3,
RequiredLevel = 4,
RequiredIntelligence = 6,
SpriteId = 24
},
new()
{
Id = 25,
Name = "Hunting Bow",
Description = "A reliable ranged weapon.",
Type = ItemType.Weapon,
Rarity = ItemRarity.Common,
EquipSlot = DungeonEquipmentSlot.MainHand,
MinDamage = 6,
MaxDamage = 12,
AttackRange = 180,
DamageType = DamageType.Physical,
RequiredLevel = 1,
RequiredDexterity = 3,
SpriteId = 25
},
new()
{
Id = 26,
Name = "Shadow Dagger",
Description = "A wickedly sharp blade that strikes from the shadows.",
Type = ItemType.Weapon,
Rarity = ItemRarity.Rare,
EquipSlot = DungeonEquipmentSlot.MainHand,
MinDamage = 15,
MaxDamage = 25,
AttackRange = 35,
DamageType = DamageType.Physical,
BonusDexterity = 5,
RequiredLevel = 6,
RequiredDexterity = 10,
SpriteId = 26
},
// ==================== ARMOR - CHEST (31-35) ====================
new()
{
Id = 31,
Name = "Leather Armor",
Description = "Basic leather protection.",
Type = ItemType.Armor,
Rarity = ItemRarity.Common,
EquipSlot = DungeonEquipmentSlot.Chest,
Armor = 5,
RequiredLevel = 1,
SpriteId = 31
},
new()
{
Id = 32,
Name = "Chainmail",
Description = "Interlocking metal rings provide solid defense.",
Type = ItemType.Armor,
Rarity = ItemRarity.Uncommon,
EquipSlot = DungeonEquipmentSlot.Chest,
Armor = 12,
BonusEndurance = 2,
RequiredLevel = 4,
RequiredStrength = 5,
SpriteId = 32
},
new()
{
Id = 33,
Name = "Mage Robes",
Description = "Enchanted robes that enhance magical abilities.",
Type = ItemType.Armor,
Rarity = ItemRarity.Uncommon,
EquipSlot = DungeonEquipmentSlot.Chest,
Armor = 3,
MagicResist = 10,
BonusMana = 30,
BonusIntelligence = 3,
RequiredLevel = 3,
RequiredIntelligence = 5,
SpriteId = 33
},
// ==================== ARMOR - HEAD (36-38) ====================
new()
{
Id = 36,
Name = "Leather Cap",
Description = "A simple leather head covering.",
Type = ItemType.Armor,
Rarity = ItemRarity.Common,
EquipSlot = DungeonEquipmentSlot.Head,
Armor = 2,
RequiredLevel = 1,
SpriteId = 36
},
new()
{
Id = 37,
Name = "Iron Helm",
Description = "A sturdy metal helmet.",
Type = ItemType.Armor,
Rarity = ItemRarity.Uncommon,
EquipSlot = DungeonEquipmentSlot.Head,
Armor = 6,
BonusEndurance = 1,
RequiredLevel = 3,
RequiredStrength = 3,
SpriteId = 37
},
new()
{
Id = 38,
Name = "Wizard Hat",
Description = "A pointed hat crackling with magical energy.",
Type = ItemType.Armor,
Rarity = ItemRarity.Uncommon,
EquipSlot = DungeonEquipmentSlot.Head,
Armor = 1,
MagicResist = 5,
BonusMana = 15,
BonusWisdom = 2,
RequiredLevel = 3,
RequiredIntelligence = 3,
SpriteId = 38
},
// ==================== ARMOR - OFFHAND (41-43) ====================
new()
{
Id = 41,
Name = "Wooden Shield",
Description = "A basic wooden shield.",
Type = ItemType.Armor,
Rarity = ItemRarity.Common,
EquipSlot = DungeonEquipmentSlot.OffHand,
Armor = 4,
RequiredLevel = 1,
SpriteId = 41
},
new()
{
Id = 42,
Name = "Iron Shield",
Description = "A solid iron shield.",
Type = ItemType.Armor,
Rarity = ItemRarity.Uncommon,
EquipSlot = DungeonEquipmentSlot.OffHand,
Armor = 10,
BonusEndurance = 2,
RequiredLevel = 4,
RequiredStrength = 6,
SpriteId = 42
},
new()
{
Id = 43,
Name = "Tome of Knowledge",
Description = "An ancient tome that enhances magical power.",
Type = ItemType.Armor,
Rarity = ItemRarity.Uncommon,
EquipSlot = DungeonEquipmentSlot.OffHand,
MagicResist = 5,
BonusMana = 20,
BonusIntelligence = 2,
RequiredLevel = 3,
RequiredIntelligence = 4,
SpriteId = 43
},
// ==================== ACCESSORIES (51-55) ====================
new()
{
Id = 51,
Name = "Ring of Health",
Description = "A simple ring that bolsters vitality.",
Type = ItemType.Accessory,
Rarity = ItemRarity.Common,
EquipSlot = DungeonEquipmentSlot.Accessory1,
BonusHealth = 25,
RequiredLevel = 2,
SpriteId = 51
},
new()
{
Id = 52,
Name = "Ring of Power",
Description = "A ring pulsing with physical might.",
Type = ItemType.Accessory,
Rarity = ItemRarity.Uncommon,
EquipSlot = DungeonEquipmentSlot.Accessory1,
BonusStrength = 3,
RequiredLevel = 3,
SpriteId = 52
},
new()
{
Id = 53,
Name = "Amulet of Wisdom",
Description = "An amulet that sharpens the mind.",
Type = ItemType.Accessory,
Rarity = ItemRarity.Uncommon,
EquipSlot = DungeonEquipmentSlot.Accessory2,
BonusWisdom = 3,
BonusMana = 15,
RequiredLevel = 3,
SpriteId = 53
},
new()
{
Id = 54,
Name = "Pendant of Swiftness",
Description = "A pendant that enhances agility.",
Type = ItemType.Accessory,
Rarity = ItemRarity.Uncommon,
EquipSlot = DungeonEquipmentSlot.Accessory2,
BonusDexterity = 4,
RequiredLevel = 3,
SpriteId = 54
},
};
}
}
+70
View File
@@ -0,0 +1,70 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Server.Data.Entities;
namespace Server.Data.Entities
{
/// <summary>
/// A single entry in a loot table - one possible drop
/// </summary>
[Table("dungeon_loot_table_entries")]
public class DungeonLootTableEntry
{
[Key]
public int Id { get; set; }
/// <summary>
/// The loot table this entry belongs to
/// </summary>
public int LootTableId { get; set; }
[ForeignKey(nameof(LootTableId))]
public DungeonLootTable? LootTable { get; set; }
/// <summary>
/// The item that can drop
/// </summary>
public int ItemDefinitionId { get; set; }
[ForeignKey(nameof(ItemDefinitionId))]
public DungeonItemDefinition? ItemDefinition { get; set; }
/// <summary>
/// Base drop chance (0.0 - 1.0)
/// 1.0 = 100%, 0.1 = 10%, 0.01 = 1%
/// </summary>
public float DropChance { get; set; } = 0.1f;
/// <summary>
/// Minimum quantity to drop
/// </summary>
public int MinQuantity { get; set; } = 1;
/// <summary>
/// Maximum quantity to drop
/// </summary>
public int MaxQuantity { get; set; } = 1;
/// <summary>
/// Weight for weighted random selection (higher = more likely)
/// Used when selecting which items drop
/// </summary>
public int Weight { get; set; } = 100;
/// <summary>
/// If true, this is a guaranteed drop (ignores DropChance)
/// </summary>
public bool Guaranteed { get; set; } = false;
/// <summary>
/// Additional drop chance per dungeon tier
/// Example: 0.02 means +2% chance per tier
/// </summary>
public float DropChancePerTier { get; set; } = 0.0f;
/// <summary>
/// Maximum drop chance after tier scaling
/// </summary>
public float MaxDropChance { get; set; } = 1.0f;
}
}
+37
View File
@@ -0,0 +1,37 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Server.Data.Entities;
namespace Server.Data.Entities
{
/// <summary>
/// Maps mobs to their loot tables (many-to-many)
/// A mob can have multiple loot tables, and a loot table can be used by multiple mobs
/// </summary>
[Table("dungeon_mob_loot_tables")]
public class DungeonMobLootTable
{
[Key]
public int Id { get; set; }
public int MobDefinitionId { get; set; }
[ForeignKey(nameof(MobDefinitionId))]
public DungeonMobDefinition? MobDefinition { get; set; }
public int LootTableId { get; set; }
[ForeignKey(nameof(LootTableId))]
public DungeonLootTable? LootTable { get; set; }
/// <summary>
/// Priority/order for rolling this table (lower = first)
/// </summary>
public int Priority { get; set; } = 0;
/// <summary>
/// Chance this loot table is rolled at all (0.0 - 1.0)
/// </summary>
public float RollChance { get; set; } = 1.0f;
}
}
+61
View File
@@ -0,0 +1,61 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Server.Data.Enums;
namespace Server.Data.Entities;
/// <summary>
/// A loot table defines a collection of possible item drops
/// </summary>
[Table("dungeon_loot_tables")]
public class DungeonLootTable
{
[Key]
public int Id { get; set; }
[Required]
[MaxLength(64)]
public string Name { get; set; } = "";
[MaxLength(256)]
public string Description { get; set; } = "";
/// <summary>
/// Minimum dungeon tier for this loot table to be active
/// </summary>
public int MinTier { get; set; } = 1;
/// <summary>
/// Maximum dungeon tier (99 = no limit)
/// </summary>
public int MaxTier { get; set; } = 99;
/// <summary>
/// Global drop chance multiplier for all entries in this table
/// </summary>
public float DropChanceMultiplier { get; set; } = 1.0f;
/// <summary>
/// Minimum number of items to drop from this table
/// </summary>
public int MinDrops { get; set; } = 1;
/// <summary>
/// Maximum number of items to drop from this table
/// </summary>
public int MaxDrops { get; set; } = 3;
/// <summary>
/// If true, guaranteed to drop at least MinDrops items
/// </summary>
public bool GuaranteedDrop { get; set; } = false;
public bool IsEnabled { get; set; } = true;
// Navigation
public ICollection<DungeonLootTableEntry> Entries { get; set; } = new List<DungeonLootTableEntry>();
}
+1
View File
@@ -3,6 +3,7 @@ namespace Server.Data.Enums;
public enum DamageType
{
Physical,
Wind,
Fire,
Ice,
Lightning,
+4 -3
View File
@@ -2,12 +2,13 @@ namespace Server.Data.Enums;
public enum DungeonEquipmentSlot
{
Weapon,
Offhand,
MainHand,
OffHand,
Head,
Chest,
Legs,
Boots,
Gloves,
Accessory
Accessory1,
Accessory2,
}