From e446cc28b6635bcd41957673a1c3c63a80ac59e6 Mon Sep 17 00:00:00 2001 From: dingo Date: Wed, 17 Dec 2025 15:12:56 -0500 Subject: [PATCH] Dungeon Browser --- Game/Dungeon/DungeonHandler.cs | 490 ++++- Game/Dungeon/DungeonInstance.cs | 41 + Game/Dungeon/DungeonSimulation.cs | 7 +- .../20251217201208_DungeonBrowser.Designer.cs | 1836 +++++++++++++++++ Migrations/20251217201208_DungeonBrowser.cs | 64 + Migrations/GameDbContextModelSnapshot.cs | 71 + Networking/Messages/DungeonOpCodes.cs | 8 +- data/GameDbContext.cs | 4 +- data/entities/DungeonMobDefinition.cs | 27 +- data/entities/DungeonPersistence.cs | 78 + 10 files changed, 2611 insertions(+), 15 deletions(-) create mode 100644 Migrations/20251217201208_DungeonBrowser.Designer.cs create mode 100644 Migrations/20251217201208_DungeonBrowser.cs create mode 100644 data/entities/DungeonPersistence.cs diff --git a/Game/Dungeon/DungeonHandler.cs b/Game/Dungeon/DungeonHandler.cs index d875b35..8990b6f 100644 --- a/Game/Dungeon/DungeonHandler.cs +++ b/Game/Dungeon/DungeonHandler.cs @@ -76,7 +76,11 @@ public sealed class DungeonHandler : IClientMessageHandler DungeonOpCodes.LOOT_CHEST_OPEN, DungeonOpCodes.LOOT_CHEST_TAKE_ITEM, DungeonOpCodes.LOOT_CHEST_TAKE_ALL, - DungeonOpCodes.LOOT_CHEST_CLOSE + DungeonOpCodes.LOOT_CHEST_CLOSE, + // Dungeon browser + DungeonOpCodes.DUNGEON_LIST_REQUEST, + DungeonOpCodes.DUNGEON_CREATE, + DungeonOpCodes.DUNGEON_JOIN }; public async Task InitializeAsync() @@ -213,6 +217,17 @@ public sealed class DungeonHandler : IClientMessageHandler case DungeonOpCodes.LOOT_CHEST_CLOSE: await HandleLootChestClose(connection, session, payload, ct); break; + + // Dungeon browser + case DungeonOpCodes.DUNGEON_LIST_REQUEST: + await HandleDungeonListRequest(connection, session, ct); + break; + case DungeonOpCodes.DUNGEON_CREATE: + await HandleDungeonCreate(connection, session, payload, ct); + break; + case DungeonOpCodes.DUNGEON_JOIN: + await HandleDungeonJoin(connection, session, payload, ct); + break; } } catch (Exception ex) @@ -683,6 +698,16 @@ public sealed class DungeonHandler : IClientMessageHandler { // Fire and forget loot generation (async in sync context) _ = ProcessMobDeathLootAsync(instance, death); + + // Check if this was a boss kill + if (instance.Simulation.Mobs.TryGetValue(death.EntityId, out var killedMob)) + { + if (killedMob.Type == MobType.Boss) + { + instance.BossKilled = true; + _log.LogInformation("Boss killed in dungeon {Id}! Dungeon is now cleared.", dungeonId); + } + } } else if (death.EntityType == EntityType.Player) { @@ -727,10 +752,30 @@ public sealed class DungeonHandler : IClientMessageHandler _ = SendDungeonStateAsync(session, result); } - // Cleanup empty dungeons - if (playersInDungeon.Count == 0 && (DateTime.UtcNow - instance.CreatedAt).TotalMinutes > 5) + // Update last activity if players present + if (playersInDungeon.Count > 0) { - _dungeons.TryRemove(dungeonId, out _); + instance.LastPlayerActivity = DateTime.UtcNow; + } + + // Handle empty dungeon logic + if (playersInDungeon.Count == 0) + { + var emptyTime = DateTime.UtcNow - instance.LastPlayerActivity; + + // If boss not killed and empty for 10+ minutes, persist to database + if (!instance.BossKilled && !instance.IsPersisted && emptyTime.TotalMinutes >= 10) + { + _ = PersistDungeonAsync(instance, CancellationToken.None); + _dungeons.TryRemove(dungeonId, out _); + _log.LogInformation("Dungeon {Id} persisted after 10 minutes empty", dungeonId); + } + // If boss killed and empty for 5+ minutes, just remove (cleared) + else if (instance.BossKilled && emptyTime.TotalMinutes >= 5) + { + _dungeons.TryRemove(dungeonId, out _); + _log.LogInformation("Cleared dungeon {Id} removed after 5 minutes empty", dungeonId); + } } } catch (Exception ex) @@ -1537,6 +1582,433 @@ public sealed class DungeonHandler : IClientMessageHandler #endregion + #region Dungeon Browser Handlers + + /// + /// Handle request for list of available dungeons + /// + private async Task HandleDungeonListRequest(IConnection connection, DungeonPlayerSession session, CancellationToken ct) + { + var playerLevel = session.Character.Level; + var (bracketMin, bracketMax) = DungeonInstance.GetLevelBracket(playerLevel); + + // Get active dungeons in player's bracket + var availableDungeons = _dungeons.Values + .Where(d => d.IsLevelInBracket(playerLevel) && + d.Simulation.Phase == DungeonPhase.Active && + !d.BossKilled) + .Select(d => new + { + id = d.Id.ToString(), + tier = d.Tier, + levelBracket = $"{d.LevelBracketMin}-{d.LevelBracketMax}", + creatorName = d.CreatorName, + creatorLevel = d.CreatorLevel, + playerCount = d.Simulation.Players.Count, + maxPlayers = 20, + isJoinWindowOpen = d.IsJoinWindowOpen, + createdAt = d.CreatedAt, + secondsRemaining = d.IsJoinWindowOpen ? (int)(d.JoinWindowEnd - DateTime.UtcNow).TotalSeconds : 0 + }) + .OrderByDescending(d => d.isJoinWindowOpen) + .ThenByDescending(d => d.createdAt) + .ToList(); + + // Also load persisted dungeons from database + using var scope = _scopeFactory.CreateScope(); + var db = scope.ServiceProvider.GetRequiredService(); + + var persistedDungeons = await db.Set() + .Where(d => d.LevelBracketMin == bracketMin && + d.LevelBracketMax == bracketMax && + !d.IsCleared) + .Select(d => new + { + id = d.Id.ToString(), + tier = d.Tier, + levelBracket = $"{d.LevelBracketMin}-{d.LevelBracketMax}", + creatorName = d.CreatorName, + creatorLevel = d.CreatorLevel, + playerCount = 0, + maxPlayers = 20, + isJoinWindowOpen = false, + isPersisted = true, + createdAt = d.CreatedAt + }) + .ToListAsync(ct); + + await SendAsync(connection, DungeonOpCodes.DUNGEON_LIST_RESPONSE, new + { + playerLevel = playerLevel, + bracket = new { min = bracketMin, max = bracketMax }, + activeDungeons = availableDungeons, + persistedDungeons = persistedDungeons + }, ct); + } + + /// + /// Handle creating a new dungeon + /// + private async Task HandleDungeonCreate(IConnection connection, DungeonPlayerSession session, ReadOnlyMemory payload, CancellationToken ct) + { + if (session.State == PlayerState.InDungeon) + { + await SendAsync(connection, DungeonOpCodes.DUNGEON_ENTER_RESULT, new { ok = false, error = "already_in_dungeon" }, ct); + return; + } + + var request = _ser.Deserialize(payload); + int tier = Math.Clamp(request.Tier, 1, 10); + int playerLevel = session.Character.Level; + var (bracketMin, bracketMax) = DungeonInstance.GetLevelBracket(playerLevel); + + var dungeonId = Guid.NewGuid(); + int seed = Random.Shared.Next(); + + var layout = DungeonGenerator.Generate(seed, tier); + var simulation = new DungeonSimulation(layout, tier, _mobDefinitions, bracketMin); + + var instance = new DungeonInstance + { + Id = dungeonId, + Tier = tier, + Seed = seed, + Simulation = simulation, + CreatedAt = DateTime.UtcNow, + LevelBracketMin = bracketMin, + LevelBracketMax = bracketMax, + CreatorLevel = playerLevel, + CreatorCharacterId = session.CharacterId, + CreatorName = session.Character.Name + }; + + _dungeons[dungeonId] = instance; + _log.LogInformation("Player {Name} (Level {Level}) created dungeon {Id} (tier {Tier}, bracket {Min}-{Max})", + session.Character.Name, playerLevel, dungeonId, tier, bracketMin, bracketMax); + + // Add player to dungeon + await AddPlayerToDungeonAsync(connection, session, instance, ct); + } + + /// + /// Handle joining an existing dungeon + /// + private async Task HandleDungeonJoin(IConnection connection, DungeonPlayerSession session, ReadOnlyMemory payload, CancellationToken ct) + { + if (session.State == PlayerState.InDungeon) + { + await SendAsync(connection, DungeonOpCodes.DUNGEON_ENTER_RESULT, new { ok = false, error = "already_in_dungeon" }, ct); + return; + } + + var request = _ser.Deserialize(payload); + if (!Guid.TryParse(request.DungeonId, out var dungeonId)) + { + await SendAsync(connection, DungeonOpCodes.DUNGEON_ENTER_RESULT, new { ok = false, error = "invalid_dungeon_id" }, ct); + return; + } + + int playerLevel = session.Character.Level; + + // Check if dungeon is in memory + if (_dungeons.TryGetValue(dungeonId, out var instance)) + { + // Validate level bracket + if (!instance.IsLevelInBracket(playerLevel)) + { + await SendAsync(connection, DungeonOpCodes.DUNGEON_ENTER_RESULT, new + { + ok = false, + error = "level_out_of_range", + message = $"Your level ({playerLevel}) is outside the dungeon's level bracket ({instance.LevelBracketMin}-{instance.LevelBracketMax})" + }, ct); + return; + } + + // Check if full + if (instance.Simulation.Players.Count >= 20) + { + await SendAsync(connection, DungeonOpCodes.DUNGEON_ENTER_RESULT, new { ok = false, error = "dungeon_full" }, ct); + return; + } + + // Check if boss killed + if (instance.BossKilled) + { + await SendAsync(connection, DungeonOpCodes.DUNGEON_ENTER_RESULT, new { ok = false, error = "dungeon_cleared" }, ct); + return; + } + + await AddPlayerToDungeonAsync(connection, session, instance, ct); + return; + } + + // Try to restore from persistence + using var scope = _scopeFactory.CreateScope(); + var db = scope.ServiceProvider.GetRequiredService(); + + var persisted = await db.Set().FindAsync(new object[] { dungeonId }, ct); + if (persisted == null) + { + await SendAsync(connection, DungeonOpCodes.DUNGEON_ENTER_RESULT, new { ok = false, error = "dungeon_not_found" }, ct); + return; + } + + if (persisted.IsCleared) + { + await SendAsync(connection, DungeonOpCodes.DUNGEON_ENTER_RESULT, new { ok = false, error = "dungeon_cleared" }, ct); + return; + } + + // Validate level bracket + if (playerLevel < persisted.LevelBracketMin || playerLevel > persisted.LevelBracketMax) + { + await SendAsync(connection, DungeonOpCodes.DUNGEON_ENTER_RESULT, new + { + ok = false, + error = "level_out_of_range", + message = $"Your level ({playerLevel}) is outside the dungeon's level bracket ({persisted.LevelBracketMin}-{persisted.LevelBracketMax})" + }, ct); + return; + } + + // Restore dungeon from persistence + instance = await RestoreDungeonFromPersistenceAsync(persisted, ct); + if (instance == null) + { + await SendAsync(connection, DungeonOpCodes.DUNGEON_ENTER_RESULT, new { ok = false, error = "restore_failed" }, ct); + return; + } + + _dungeons[dungeonId] = instance; + + // Remove from persistence table (it's active now) + db.Set().Remove(persisted); + await db.SaveChangesAsync(ct); + + await AddPlayerToDungeonAsync(connection, session, instance, ct); + } + + /// + /// Add a player to a dungeon and send the result + /// + private async Task AddPlayerToDungeonAsync(IConnection connection, DungeonPlayerSession session, DungeonInstance instance, CancellationToken ct) + { + var layout = instance.Simulation.Layout; + var spawnPos = layout.Rooms[0]; // Entrance room + + var player = new PlayerInstance + { + CharacterId = session.CharacterId, + CharacterName = session.Character.Name, + X = spawnPos.CenterX * 32 + Random.Shared.Next(-20, 20), + Y = spawnPos.CenterY * 32 + Random.Shared.Next(-20, 20), + Health = session.Character.CurrentHealth, + MaxHealth = DungeonCharacterStats.GetMaxHealth(session.Character), + Mana = session.Character.CurrentMana, + MaxMana = DungeonCharacterStats.GetMaxMana(session.Character), + Stamina = DungeonCharacterStats.GetMaxStamina(session.Character), + MaxStamina = DungeonCharacterStats.GetMaxStamina(session.Character), + MoveSpeed = DungeonCharacterStats.GetMoveSpeed(session.Character), + AttackSpeed = DungeonCharacterStats.GetAttackSpeed(session.Character), + Strength = session.Character.Strength, + Intelligence = session.Character.Intelligence + }; + + instance.Simulation.Players[session.CharacterId] = player; + instance.LastPlayerActivity = DateTime.UtcNow; + + session.State = PlayerState.InDungeon; + session.CurrentDungeonId = instance.Id; + session.PlayerInstance = player; + + await SendAsync(connection, DungeonOpCodes.DUNGEON_ENTER_RESULT, new + { + ok = true, + dungeonId = instance.Id.ToString(), + tier = instance.Tier, + seed = instance.Seed, + levelBracket = new { min = instance.LevelBracketMin, max = instance.LevelBracketMax }, + width = layout.Width, + height = layout.Height, + tiles = layout.SerializeTiles(), + spawn = new { x = player.X, y = player.Y }, + players = instance.Simulation.Players.Values.Select(p => new + { + id = p.CharacterId, + name = p.CharacterName, + x = p.X, + y = p.Y + }), + mobs = instance.Simulation.Mobs.Values.Where(m => m.IsAlive).Select(m => new + { + id = m.Id, + name = m.Name, + x = m.X, + y = m.Y, + health = m.Health, + maxHealth = m.MaxHealth, + spriteSheet = m.SpriteSheet, + spriteWidth = m.SpriteWidth, + spriteHeight = m.SpriteHeight, + tintColor = m.TintColor + }), + chests = instance.Simulation.Chests.Values.Select(c => new + { + id = c.Id, + x = c.X, + y = c.Y, + type = c.Type.ToString().ToLower(), + opened = c.IsOpened + }), + portals = instance.Simulation.Portals.Values.Where(p => p.IsActive).Select(p => new + { + id = p.Id, + x = p.X, + y = p.Y, + type = p.Type.ToString().ToLower() + }) + }, ct); + + _log.LogInformation("Player {Name} (Level {Level}) joined dungeon {Id}", + session.Character.Name, session.Character.Level, instance.Id); + } + + /// + /// Restore a dungeon from persistence + /// + private async Task RestoreDungeonFromPersistenceAsync(DungeonPersistence persisted, CancellationToken ct) + { + try + { + var layout = DungeonGenerator.Generate(persisted.Seed, persisted.Tier); + var simulation = new DungeonSimulation(layout, persisted.Tier, _mobDefinitions, persisted.LevelBracketMin); + + // Restore mob state if available + if (!string.IsNullOrEmpty(persisted.MobStateJson)) + { + var mobStates = System.Text.Json.JsonSerializer.Deserialize>(persisted.MobStateJson); + if (mobStates != null) + { + foreach (var mobState in mobStates) + { + if (simulation.Mobs.TryGetValue(mobState.Id, out var mob)) + { + mob.X = mobState.X; + mob.Y = mobState.Y; + mob.Health = mobState.Health; + mob.IsAlive = mobState.IsAlive; + if (!mob.IsAlive) mob.State = MobState.Dead; + } + } + } + } + + // Restore chest state if available + if (!string.IsNullOrEmpty(persisted.ChestStateJson)) + { + var chestStates = System.Text.Json.JsonSerializer.Deserialize>(persisted.ChestStateJson); + if (chestStates != null) + { + foreach (var chestState in chestStates) + { + if (simulation.Chests.TryGetValue(chestState.Id, out var chest)) + { + chest.IsOpened = chestState.IsOpened; + } + } + } + } + + var instance = new DungeonInstance + { + Id = persisted.Id, + Tier = persisted.Tier, + Seed = persisted.Seed, + Simulation = simulation, + CreatedAt = persisted.CreatedAt, + LevelBracketMin = persisted.LevelBracketMin, + LevelBracketMax = persisted.LevelBracketMax, + CreatorLevel = persisted.CreatorLevel, + CreatorCharacterId = persisted.CreatorCharacterId, + CreatorName = persisted.CreatorName, + BossKilled = persisted.BossKilled, + IsPersisted = false, + LastPlayerActivity = DateTime.UtcNow + }; + + _log.LogInformation("Restored dungeon {Id} from persistence", persisted.Id); + return instance; + } + catch (Exception ex) + { + _log.LogError(ex, "Failed to restore dungeon {Id} from persistence", persisted.Id); + return null; + } + } + + /// + /// Persist a dungeon to SQL (called when empty for 10 minutes) + /// + private async Task PersistDungeonAsync(DungeonInstance instance, CancellationToken ct) + { + if (instance.IsPersisted || instance.BossKilled) return; + + try + { + using var scope = _scopeFactory.CreateScope(); + var db = scope.ServiceProvider.GetRequiredService(); + + // Serialize mob state + var mobStates = instance.Simulation.Mobs.Values.Select(m => new PersistedMobState + { + Id = m.Id, + DefinitionId = m.DefinitionId, + X = m.X, + Y = m.Y, + Health = m.Health, + IsAlive = m.IsAlive + }).ToList(); + + // Serialize chest state + var chestStates = instance.Simulation.Chests.Values.Select(c => new PersistedChestState + { + Id = c.Id, + IsOpened = c.IsOpened + }).ToList(); + + var persisted = new DungeonPersistence + { + Id = instance.Id, + Tier = instance.Tier, + Seed = instance.Seed, + LevelBracketMin = instance.LevelBracketMin, + LevelBracketMax = instance.LevelBracketMax, + CreatorCharacterId = instance.CreatorCharacterId, + CreatorName = instance.CreatorName, + CreatorLevel = instance.CreatorLevel, + CreatedAt = instance.CreatedAt, + LastActivity = instance.LastPlayerActivity, + PersistedAt = DateTime.UtcNow, + BossKilled = instance.BossKilled, + MobStateJson = System.Text.Json.JsonSerializer.Serialize(mobStates), + ChestStateJson = System.Text.Json.JsonSerializer.Serialize(chestStates) + }; + + db.Set().Add(persisted); + await db.SaveChangesAsync(ct); + + instance.IsPersisted = true; + _log.LogInformation("Persisted dungeon {Id} to database", instance.Id); + } + catch (Exception ex) + { + _log.LogError(ex, "Failed to persist dungeon {Id}", instance.Id); + } + } + + #endregion + /// /// Sends loot popup to client showing what they received /// @@ -2299,3 +2771,13 @@ public class LootChestCloseRequest { public int ChestId { get; set; } } + +public class DungeonCreateRequest +{ + public int Tier { get; set; } +} + +public class DungeonJoinRequest +{ + public string DungeonId { get; set; } = ""; +} diff --git a/Game/Dungeon/DungeonInstance.cs b/Game/Dungeon/DungeonInstance.cs index 570c47c..9d61227 100644 --- a/Game/Dungeon/DungeonInstance.cs +++ b/Game/Dungeon/DungeonInstance.cs @@ -11,4 +11,45 @@ public class DungeonInstance public DungeonSimulation Simulation { get; set; } = null!; public DateTime CreatedAt { get; set; } = DateTime.UtcNow; public bool ClearedHandled { get; set; } = false; + + // Level bracket system + public int LevelBracketMin { get; set; } + public int LevelBracketMax { get; set; } + public int CreatorLevel { get; set; } + public ulong CreatorCharacterId { get; set; } + public string CreatorName { get; set; } = ""; + + // Auto-join window (5 minutes) + public DateTime JoinWindowEnd => CreatedAt.AddMinutes(5); + public bool IsJoinWindowOpen => DateTime.UtcNow < JoinWindowEnd; + + // Persistence + public DateTime LastPlayerActivity { get; set; } = DateTime.UtcNow; + public bool IsPersisted { get; set; } = false; + public bool BossKilled { get; set; } = false; + + /// + /// Check if a player level is within the bracket range + /// + public bool IsLevelInBracket(int playerLevel) + { + return playerLevel >= LevelBracketMin && playerLevel <= LevelBracketMax; + } + + /// + /// Calculate level bracket from a player's level (brackets of 10: 1-10, 11-20, 21-30, etc.) + /// + public static (int min, int max) GetLevelBracket(int level) + { + // Bracket 1: 1-10, Bracket 2: 11-20, etc. + int bracketIndex = (level - 1) / 10; + int min = bracketIndex * 10 + 1; + int max = min + 9; + return (min, max); + } + + /// + /// Get the bracket number (1, 2, 3, etc.) + /// + public int BracketNumber => (LevelBracketMin - 1) / 10 + 1; } diff --git a/Game/Dungeon/DungeonSimulation.cs b/Game/Dungeon/DungeonSimulation.cs index 9940b9c..ed84b6e 100644 --- a/Game/Dungeon/DungeonSimulation.cs +++ b/Game/Dungeon/DungeonSimulation.cs @@ -11,6 +11,7 @@ public class DungeonSimulation { public DungeonLayout Layout { get; } public int Tier { get; } + public int BracketMin { get; } // Tick rate public const int TicksPerSecond = 20; @@ -38,10 +39,11 @@ public class DungeonSimulation private int _nextDroppedItemId = 1; private readonly Dictionary _mobDefinitions; - public DungeonSimulation(DungeonLayout layout, int tier, Dictionary mobDefinitions) + public DungeonSimulation(DungeonLayout layout, int tier, Dictionary mobDefinitions, int bracketMin = 1) { Layout = layout; Tier = tier; + BracketMin = bracketMin; _mobDefinitions = mobDefinitions; SpawnMobs(); @@ -105,7 +107,8 @@ public class DungeonSimulation var mobDef = SelectMobDefinition(mobSpawn.MobType, rng); if (mobDef == null) continue; - var stats = mobDef.GetStatsForTier(Tier); + // Use bracket-aware stat scaling + var stats = mobDef.GetStatsForTierAndBracket(Tier, BracketMin); Mobs[mobSpawn.Id] = new MobInstance { diff --git a/Migrations/20251217201208_DungeonBrowser.Designer.cs b/Migrations/20251217201208_DungeonBrowser.Designer.cs new file mode 100644 index 0000000..a8f4521 --- /dev/null +++ b/Migrations/20251217201208_DungeonBrowser.Designer.cs @@ -0,0 +1,1836 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Server.Data; + +#nullable disable + +namespace SystemRevivalServer.Migrations +{ + [DbContext(typeof(GameDbContext))] + [Migration("20251217201208_DungeonBrowser")] + partial class DungeonBrowser + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder); + + modelBuilder.Entity("Server.Data.Account", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("BannedUntil") + .HasColumnType("datetime(6)"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("datetime(6)") + .HasDefaultValueSql("CURRENT_TIMESTAMP(6)"); + + b.Property("Email") + .HasMaxLength(255) + .HasColumnType("varchar(255)"); + + b.Property("IsBanned") + .HasColumnType("tinyint(1)"); + + b.Property("PasswordHash") + .IsRequired() + .HasColumnType("varbinary(64)"); + + b.Property("PasswordSalt") + .IsRequired() + .HasColumnType("varbinary(32)"); + + b.Property("Role") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasDefaultValue(0); + + b.Property("UpdatedAt") + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("datetime(6)") + .HasDefaultValueSql("CURRENT_TIMESTAMP(6)"); + + MySqlPropertyBuilderExtensions.UseMySqlComputedColumn(b.Property("UpdatedAt")); + + b.Property("Username") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("varchar(32)"); + + b.HasKey("Id"); + + b.HasIndex("Email") + .IsUnique(); + + b.HasIndex("Username") + .IsUnique(); + + b.ToTable("accounts", (string)null); + }); + + modelBuilder.Entity("Server.Data.Entities.DeathChest", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("DungeonInstanceId") + .HasColumnType("char(36)"); + + b.Property("EmptiedAt") + .HasColumnType("datetime(6)"); + + b.Property("GoldAmount") + .HasColumnType("bigint"); + + b.Property("IsEmpty") + .HasColumnType("tinyint(1)"); + + b.Property("OwnerCharacterId") + .HasColumnType("bigint unsigned"); + + b.Property("VictimCharacterId") + .HasColumnType("bigint unsigned"); + + b.Property("VictimMobDefinitionId") + .HasColumnType("int"); + + b.Property("X") + .HasColumnType("float"); + + b.Property("Y") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("OwnerCharacterId"); + + b.HasIndex("VictimCharacterId"); + + b.ToTable("dungeon_death_chests"); + }); + + modelBuilder.Entity("Server.Data.Entities.DeathChestItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("DeathChestId") + .HasColumnType("bigint unsigned"); + + b.Property("IsTaken") + .HasColumnType("tinyint(1)"); + + b.Property("ItemDefinitionId") + .HasColumnType("int"); + + b.Property("Quantity") + .HasColumnType("int"); + + b.Property("SlotIndex") + .HasColumnType("int"); + + b.Property("TakenAt") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.HasIndex("DeathChestId"); + + b.HasIndex("ItemDefinitionId"); + + b.ToTable("dungeon_death_chest_items"); + }); + + modelBuilder.Entity("Server.Data.Entities.DungeonBeltItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("CharacterId") + .HasColumnType("bigint unsigned"); + + b.Property("InventorySlotIndex") + .HasColumnType("int"); + + b.Property("SlotIndex") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CharacterId"); + + b.ToTable("dungeon_belt_items"); + }); + + modelBuilder.Entity("Server.Data.Entities.DungeonCharacter", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("AccountId") + .HasColumnType("bigint unsigned"); + + b.Property("BossesKilled") + .HasColumnType("int"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("CurrentHealth") + .HasColumnType("int"); + + b.Property("CurrentMana") + .HasColumnType("int"); + + b.Property("Dexterity") + .HasColumnType("int"); + + b.Property("DungeonsCompleted") + .HasColumnType("int"); + + b.Property("Endurance") + .HasColumnType("int"); + + b.Property("EquippedAccessory") + .HasColumnType("bigint unsigned"); + + b.Property("EquippedBoots") + .HasColumnType("bigint unsigned"); + + b.Property("EquippedChest") + .HasColumnType("bigint unsigned"); + + b.Property("EquippedGloves") + .HasColumnType("bigint unsigned"); + + b.Property("EquippedHead") + .HasColumnType("bigint unsigned"); + + b.Property("EquippedLegs") + .HasColumnType("bigint unsigned"); + + b.Property("EquippedOffhand") + .HasColumnType("bigint unsigned"); + + b.Property("EquippedWeapon") + .HasColumnType("bigint unsigned"); + + b.Property("Experience") + .HasColumnType("bigint"); + + b.Property("Gold") + .HasColumnType("bigint"); + + b.Property("Intelligence") + .HasColumnType("int"); + + b.Property("IsDeleted") + .HasColumnType("tinyint(1)"); + + b.Property("LastPlayedAt") + .HasColumnType("datetime(6)"); + + b.Property("Level") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("varchar(32)"); + + b.Property("PlayersKilled") + .HasColumnType("int"); + + b.Property("Strength") + .HasColumnType("int"); + + b.Property("TotalDeaths") + .HasColumnType("int"); + + b.Property("TotalKills") + .HasColumnType("int"); + + b.Property("UnspentStatPoints") + .HasColumnType("int"); + + b.Property("Wisdom") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("AccountId"); + + b.ToTable("dungeon_characters"); + }); + + modelBuilder.Entity("Server.Data.Entities.DungeonCharacterItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("AcquiredAt") + .HasColumnType("datetime(6)"); + + b.Property("CharacterId") + .HasColumnType("bigint unsigned"); + + b.Property("EquipSlot") + .HasColumnType("int"); + + b.Property("IsEquipped") + .HasColumnType("tinyint(1)"); + + b.Property("ItemDefinitionId") + .HasColumnType("int"); + + b.Property("Quantity") + .HasColumnType("int"); + + b.Property("SlotIndex") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CharacterId"); + + b.HasIndex("ItemDefinitionId"); + + b.ToTable("dungeon_character_items"); + }); + + modelBuilder.Entity("Server.Data.Entities.DungeonItemDefinition", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("Armor") + .HasColumnType("int"); + + b.Property("AttackRange") + .HasColumnType("float"); + + b.Property("BonusDexterity") + .HasColumnType("int"); + + b.Property("BonusEndurance") + .HasColumnType("int"); + + b.Property("BonusHealth") + .HasColumnType("int"); + + b.Property("BonusIntelligence") + .HasColumnType("int"); + + b.Property("BonusMana") + .HasColumnType("int"); + + b.Property("BonusStrength") + .HasColumnType("int"); + + b.Property("BonusWisdom") + .HasColumnType("int"); + + b.Property("DamageType") + .HasColumnType("int"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.Property("EquipSlot") + .HasColumnType("int"); + + b.Property("HealAmount") + .HasColumnType("int"); + + b.Property("IsEnabled") + .HasColumnType("tinyint(1)"); + + b.Property("IsTeleportScroll") + .HasColumnType("tinyint(1)"); + + b.Property("MagicResist") + .HasColumnType("int"); + + b.Property("ManaRestore") + .HasColumnType("int"); + + b.Property("MaxDamage") + .HasColumnType("int"); + + b.Property("MaxStack") + .HasColumnType("int"); + + b.Property("MinDamage") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("varchar(64)"); + + b.Property("Rarity") + .HasColumnType("int"); + + b.Property("RequiredDexterity") + .HasColumnType("int"); + + b.Property("RequiredIntelligence") + .HasColumnType("int"); + + b.Property("RequiredLevel") + .HasColumnType("int"); + + b.Property("RequiredStrength") + .HasColumnType("int"); + + b.Property("RequiredWisdom") + .HasColumnType("int"); + + b.Property("SpriteId") + .HasColumnType("int"); + + b.Property("Stackable") + .HasColumnType("tinyint(1)"); + + b.Property("StaminaRestore") + .HasColumnType("int"); + + b.Property("TeachesSpellId") + .HasColumnType("int"); + + b.Property("Type") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("dungeon_item_definitions"); + }); + + modelBuilder.Entity("Server.Data.Entities.DungeonLearnedSpell", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("CharacterId") + .HasColumnType("bigint unsigned"); + + b.Property("DefinitionId") + .HasColumnType("int"); + + b.Property("LearnedAt") + .HasColumnType("datetime(6)"); + + b.Property("SpellDefinitionId") + .HasColumnType("int"); + + b.Property("SpellLevel") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CharacterId"); + + b.HasIndex("DefinitionId"); + + b.ToTable("dungeon_learned_spells"); + }); + + modelBuilder.Entity("Server.Data.Entities.DungeonLootTable", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("Description") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.Property("DropChanceMultiplier") + .HasColumnType("float"); + + b.Property("GuaranteedDrop") + .HasColumnType("tinyint(1)"); + + b.Property("IsEnabled") + .HasColumnType("tinyint(1)"); + + b.Property("MaxDrops") + .HasColumnType("int"); + + b.Property("MaxTier") + .HasColumnType("int"); + + b.Property("MinDrops") + .HasColumnType("int"); + + b.Property("MinTier") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("varchar(64)"); + + b.HasKey("Id"); + + b.ToTable("dungeon_loot_tables"); + }); + + modelBuilder.Entity("Server.Data.Entities.DungeonLootTableEntry", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("DropChance") + .HasColumnType("float"); + + b.Property("DropChancePerTier") + .HasColumnType("float"); + + b.Property("Guaranteed") + .HasColumnType("tinyint(1)"); + + b.Property("ItemDefinitionId") + .HasColumnType("int"); + + b.Property("LootTableId") + .HasColumnType("int"); + + b.Property("MaxDropChance") + .HasColumnType("float"); + + b.Property("MaxQuantity") + .HasColumnType("int"); + + b.Property("MinQuantity") + .HasColumnType("int"); + + b.Property("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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("AbilitiesJson") + .IsRequired() + .HasMaxLength(1024) + .HasColumnType("varchar(1024)"); + + b.Property("AggroRange") + .HasColumnType("float"); + + b.Property("AnimationSpeed") + .HasColumnType("float"); + + b.Property("ArmorPerTier") + .HasColumnType("float"); + + b.Property("AttackFrames") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.Property("AttackRange") + .HasColumnType("float"); + + b.Property("AttackSpeed") + .HasColumnType("float"); + + b.Property("BaseArmor") + .HasColumnType("int"); + + b.Property("BaseHealth") + .HasColumnType("int"); + + b.Property("BaseMagicDamage") + .HasColumnType("int"); + + b.Property("BaseMagicResist") + .HasColumnType("int"); + + b.Property("BaseMana") + .HasColumnType("int"); + + b.Property("BasePhysicalDamage") + .HasColumnType("int"); + + b.Property("BaseXp") + .HasColumnType("int"); + + b.Property("Category") + .HasColumnType("int"); + + b.Property("DamagePerTier") + .HasColumnType("float"); + + b.Property("DeathFrames") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.Property("DropChanceMultiplier") + .HasColumnType("float"); + + b.Property("HealthPerTier") + .HasColumnType("float"); + + b.Property("IdleFrames") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.Property("IsEnabled") + .HasColumnType("tinyint(1)"); + + b.Property("LeashRange") + .HasColumnType("float"); + + b.Property("LootTableId") + .HasColumnType("int"); + + b.Property("MaxTier") + .HasColumnType("int"); + + b.Property("MinTier") + .HasColumnType("int"); + + b.Property("MoveSpeed") + .HasColumnType("float"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("varchar(64)"); + + b.Property("ResistancesJson") + .IsRequired() + .HasMaxLength(1024) + .HasColumnType("varchar(1024)"); + + b.Property("SpriteHeight") + .HasColumnType("int"); + + b.Property("SpriteIndex") + .HasColumnType("int"); + + b.Property("SpriteSheet") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("varchar(128)"); + + b.Property("SpriteWidth") + .HasColumnType("int"); + + b.Property("TintColor") + .IsRequired() + .HasMaxLength(16) + .HasColumnType("varchar(16)"); + + b.Property("Type") + .HasColumnType("int"); + + b.Property("WalkFrames") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.Property("XpPerTier") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("dungeon_mob_definitions"); + }); + + modelBuilder.Entity("Server.Data.Entities.DungeonMobLootTable", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("LootTableId") + .HasColumnType("int"); + + b.Property("MobDefinitionId") + .HasColumnType("int"); + + b.Property("Priority") + .HasColumnType("int"); + + b.Property("RollChance") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("LootTableId"); + + b.HasIndex("MobDefinitionId"); + + b.ToTable("dungeon_mob_loot_tables"); + }); + + modelBuilder.Entity("Server.Data.Entities.DungeonPersistence", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)"); + + b.Property("BossKilled") + .HasColumnType("tinyint(1)"); + + b.Property("ChestStateJson") + .HasColumnType("json"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("CreatorCharacterId") + .HasColumnType("bigint unsigned"); + + b.Property("CreatorId") + .HasColumnType("bigint unsigned"); + + b.Property("CreatorLevel") + .HasColumnType("int"); + + b.Property("CreatorName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("IsCleared") + .HasColumnType("tinyint(1)"); + + b.Property("LastActivity") + .HasColumnType("datetime(6)"); + + b.Property("LevelBracketMax") + .HasColumnType("int"); + + b.Property("LevelBracketMin") + .HasColumnType("int"); + + b.Property("LootChestStateJson") + .HasColumnType("json"); + + b.Property("MobStateJson") + .HasColumnType("json"); + + b.Property("PersistedAt") + .HasColumnType("datetime(6)"); + + b.Property("Seed") + .HasColumnType("int"); + + b.Property("Tier") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.ToTable("dungeon_instances"); + }); + + modelBuilder.Entity("Server.Data.Entities.DungeonSpellDefinition", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("AreaOfEffect") + .HasColumnType("float"); + + b.Property("BaseDamage") + .HasColumnType("int"); + + b.Property("BaseHealing") + .HasColumnType("int"); + + b.Property("Cooldown") + .HasColumnType("float"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.Property("EffectColor") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("IsEnabled") + .HasColumnType("tinyint(1)"); + + b.Property("IsShield") + .HasColumnType("tinyint(1)"); + + b.Property("IsTeleport") + .HasColumnType("tinyint(1)"); + + b.Property("ManaCost") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("varchar(64)"); + + b.Property("Range") + .HasColumnType("float"); + + b.Property("RequiredIntelligence") + .HasColumnType("int"); + + b.Property("RequiredLevel") + .HasColumnType("int"); + + b.Property("RequiredWisdom") + .HasColumnType("int"); + + b.Property("ShieldAmount") + .HasColumnType("int"); + + b.Property("SpriteId") + .HasColumnType("int"); + + b.Property("Type") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("dungeon_spell_definitions"); + }); + + modelBuilder.Entity("Server.Data.Entities.DungeonStashItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("CharacterId") + .HasColumnType("bigint unsigned"); + + b.Property("DefinitionId") + .HasColumnType("int"); + + b.Property("ItemDefinitionId") + .HasColumnType("int"); + + b.Property("Quantity") + .HasColumnType("int"); + + b.Property("SlotIndex") + .HasColumnType("int"); + + b.Property("StoredAt") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.HasIndex("CharacterId"); + + b.HasIndex("DefinitionId"); + + b.ToTable("dungeon_stash_items"); + }); + + modelBuilder.Entity("Server.Data.EquipmentSlot", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("CharacterId") + .HasColumnType("bigint unsigned"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("datetime(6)") + .HasDefaultValueSql("CURRENT_TIMESTAMP(6)"); + + b.Property("ItemTemplateId") + .HasColumnType("bigint unsigned"); + + b.Property("SlotCode") + .HasColumnType("tinyint unsigned"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("datetime(6)") + .HasDefaultValueSql("CURRENT_TIMESTAMP(6)"); + + MySqlPropertyBuilderExtensions.UseMySqlComputedColumn(b.Property("UpdatedAt")); + + b.HasKey("Id"); + + b.HasIndex("ItemTemplateId"); + + b.HasIndex("CharacterId", "SlotCode") + .IsUnique(); + + b.ToTable("equipment", (string)null); + }); + + modelBuilder.Entity("Server.Data.GameItem", b => + { + b.Property("Id") + .HasColumnType("int"); + + b.Property("AmmoType") + .HasColumnType("int"); + + b.Property("Category") + .HasColumnType("int"); + + b.Property("CraftCost") + .HasColumnType("int"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("datetime(6)") + .HasDefaultValueSql("CURRENT_TIMESTAMP(6)"); + + b.Property("Damage") + .HasColumnType("int"); + + b.Property("DamageReduction") + .HasColumnType("float"); + + b.Property("DashCooldown") + .HasColumnType("float"); + + b.Property("DashDistance") + .HasColumnType("float"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.Property("ExplosionRadius") + .HasColumnType("float"); + + b.Property("FireRate") + .HasColumnType("float"); + + b.Property("HarvestMultiplier") + .HasColumnType("float"); + + b.Property("HealAmount") + .HasColumnType("int"); + + b.Property("HealthBonus") + .HasColumnType("int"); + + b.Property("IsEnabled") + .ValueGeneratedOnAdd() + .HasColumnType("tinyint(1)") + .HasDefaultValue(true); + + b.Property("LootValue") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("varchar(64)"); + + b.Property("PelletCount") + .HasColumnType("int"); + + b.Property("ProjectileSpeed") + .HasColumnType("float"); + + b.Property("Range") + .HasColumnType("float"); + + b.Property("ScanCooldown") + .HasColumnType("float"); + + b.Property("ScanRadius") + .HasColumnType("float"); + + b.Property("ShieldBoostDuration") + .HasColumnType("float"); + + b.Property("ShieldDuration") + .HasColumnType("float"); + + b.Property("ShieldHealth") + .HasColumnType("int"); + + b.Property("SpeedBoostDuration") + .HasColumnType("float"); + + b.Property("SpeedMultiplier") + .HasColumnType("float"); + + b.Property("SpeedPenalty") + .HasColumnType("float"); + + b.Property("Spread") + .HasColumnType("float"); + + b.Property("Stackable") + .HasColumnType("tinyint(1)"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("datetime(6)") + .HasDefaultValueSql("CURRENT_TIMESTAMP(6)"); + + MySqlPropertyBuilderExtensions.UseMySqlComputedColumn(b.Property("UpdatedAt")); + + b.HasKey("Id"); + + b.HasIndex("Category"); + + b.HasIndex("IsEnabled"); + + b.ToTable("game_items", (string)null); + }); + + modelBuilder.Entity("Server.Data.GameRecipe", b => + { + b.Property("Id") + .HasColumnType("int"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("datetime(6)") + .HasDefaultValueSql("CURRENT_TIMESTAMP(6)"); + + b.Property("EnergyCost") + .HasColumnType("int"); + + b.Property("IsEnabled") + .ValueGeneratedOnAdd() + .HasColumnType("tinyint(1)") + .HasDefaultValue(true); + + b.Property("RareCost") + .HasColumnType("int"); + + b.Property("ResultItemId") + .HasColumnType("int"); + + b.Property("ScrapCost") + .HasColumnType("int"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("datetime(6)") + .HasDefaultValueSql("CURRENT_TIMESTAMP(6)"); + + MySqlPropertyBuilderExtensions.UseMySqlComputedColumn(b.Property("UpdatedAt")); + + b.HasKey("Id"); + + b.HasIndex("IsEnabled"); + + b.HasIndex("ResultItemId"); + + b.ToTable("game_recipes", (string)null); + }); + + modelBuilder.Entity("Server.Data.InventoryItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("CharacterId") + .HasColumnType("bigint unsigned"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("datetime(6)") + .HasDefaultValueSql("CURRENT_TIMESTAMP(6)"); + + b.Property("ItemTemplateId") + .HasColumnType("bigint unsigned"); + + b.Property("Quantity") + .HasColumnType("int unsigned"); + + b.Property("SlotIndex") + .HasColumnType("int unsigned"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("datetime(6)") + .HasDefaultValueSql("CURRENT_TIMESTAMP(6)"); + + MySqlPropertyBuilderExtensions.UseMySqlComputedColumn(b.Property("UpdatedAt")); + + b.HasKey("Id"); + + b.HasIndex("CharacterId"); + + b.HasIndex("ItemTemplateId"); + + b.HasIndex("CharacterId", "SlotIndex") + .IsUnique(); + + b.ToTable("inventories", (string)null); + }); + + modelBuilder.Entity("Server.Data.ItemTemplate", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("datetime(6)") + .HasDefaultValueSql("CURRENT_TIMESTAMP(6)"); + + b.Property("ItemType") + .HasColumnType("tinyint unsigned"); + + b.Property("MaxStack") + .HasColumnType("int unsigned"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("varchar(64)"); + + b.Property("Rarity") + .HasColumnType("tinyint unsigned"); + + b.Property("StatsJson") + .HasColumnType("json"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("datetime(6)") + .HasDefaultValueSql("CURRENT_TIMESTAMP(6)"); + + MySqlPropertyBuilderExtensions.UseMySqlComputedColumn(b.Property("UpdatedAt")); + + b.Property("Weight") + .HasColumnType("int unsigned"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("item_templates", (string)null); + }); + + modelBuilder.Entity("Server.Data.MatchHistory", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("AccountId") + .HasColumnType("bigint unsigned"); + + b.Property("DamageDealt") + .HasColumnType("int"); + + b.Property("DamageTaken") + .HasColumnType("int"); + + b.Property("Deaths") + .HasColumnType("int"); + + b.Property("EloAfter") + .HasColumnType("int"); + + b.Property("EloChange") + .HasColumnType("int"); + + b.Property("EnergyCollected") + .HasColumnType("int"); + + b.Property("ItemsCrafted") + .HasColumnType("int"); + + b.Property("Kills") + .HasColumnType("int"); + + b.Property("MatchDurationSeconds") + .HasColumnType("int"); + + b.Property("MatchId") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("varchar(32)"); + + b.Property("Placement") + .HasColumnType("int"); + + b.Property("PlayedAt") + .ValueGeneratedOnAdd() + .HasColumnType("datetime(6)") + .HasDefaultValueSql("CURRENT_TIMESTAMP(6)"); + + b.Property("RareCollected") + .HasColumnType("int"); + + b.Property("Result") + .HasColumnType("int"); + + b.Property("ScrapCollected") + .HasColumnType("int"); + + b.Property("SurvivalTimeSeconds") + .HasColumnType("int"); + + b.Property("TotalPlayers") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("AccountId"); + + b.HasIndex("MatchId"); + + b.HasIndex("PlayedAt"); + + b.ToTable("match_history", (string)null); + }); + + modelBuilder.Entity("Server.Data.Old_Character", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("AccountId") + .HasColumnType("bigint unsigned"); + + b.Property("AppearanceJson") + .HasColumnType("json"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("datetime(6)") + .HasDefaultValueSql("CURRENT_TIMESTAMP(6)"); + + b.Property("FacingDeg") + .HasColumnType("float"); + + b.Property("HpCurrent") + .HasColumnType("int unsigned"); + + b.Property("HpMax") + .HasColumnType("int unsigned"); + + b.Property("Level") + .HasColumnType("int unsigned"); + + b.Property("MpCurrent") + .HasColumnType("int unsigned"); + + b.Property("MpMax") + .HasColumnType("int unsigned"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("varchar(32)"); + + b.Property("PosX") + .HasColumnType("double"); + + b.Property("PosY") + .HasColumnType("double"); + + b.Property("PosZ") + .HasColumnType("double"); + + b.Property("StaminaCurrent") + .HasColumnType("int unsigned"); + + b.Property("StaminaMax") + .HasColumnType("int unsigned"); + + b.Property("StatDexterity") + .HasColumnType("int unsigned"); + + b.Property("StatEndurance") + .HasColumnType("int unsigned"); + + b.Property("StatIntelligence") + .HasColumnType("int unsigned"); + + b.Property("StatStrength") + .HasColumnType("int unsigned"); + + b.Property("StatWisdom") + .HasColumnType("int unsigned"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("datetime(6)") + .HasDefaultValueSql("CURRENT_TIMESTAMP(6)"); + + MySqlPropertyBuilderExtensions.UseMySqlComputedColumn(b.Property("UpdatedAt")); + + b.Property("Xp") + .HasColumnType("bigint unsigned"); + + b.Property("ZoneId") + .HasColumnType("bigint unsigned"); + + b.HasKey("Id"); + + b.HasIndex("AccountId") + .IsUnique(); + + b.HasIndex("ZoneId"); + + b.ToTable("characters", (string)null); + }); + + modelBuilder.Entity("Server.Data.PlayerStats", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("AccountId") + .HasColumnType("bigint unsigned"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("datetime(6)") + .HasDefaultValueSql("CURRENT_TIMESTAMP(6)"); + + b.Property("Deaths") + .HasColumnType("int"); + + b.Property("Elo") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasDefaultValue(1000); + + b.Property("Extractions") + .HasColumnType("int"); + + b.Property("ItemsCrafted") + .HasColumnType("int"); + + b.Property("Kills") + .HasColumnType("int"); + + b.Property("LongestSurvivalSeconds") + .HasColumnType("int"); + + b.Property("Losses") + .HasColumnType("int"); + + b.Property("MatchesPlayed") + .HasColumnType("int"); + + b.Property("TotalDamageDealt") + .HasColumnType("bigint"); + + b.Property("TotalDamageTaken") + .HasColumnType("bigint"); + + b.Property("TotalEnergyCollected") + .HasColumnType("bigint"); + + b.Property("TotalPlayTimeSeconds") + .HasColumnType("bigint"); + + b.Property("TotalRareCollected") + .HasColumnType("bigint"); + + b.Property("TotalScrapCollected") + .HasColumnType("bigint"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("datetime(6)") + .HasDefaultValueSql("CURRENT_TIMESTAMP(6)"); + + MySqlPropertyBuilderExtensions.UseMySqlComputedColumn(b.Property("UpdatedAt")); + + b.Property("Wins") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("AccountId") + .IsUnique(); + + b.ToTable("player_stats", (string)null); + }); + + modelBuilder.Entity("Server.Data.Session", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("AccountId") + .HasColumnType("bigint unsigned"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("datetime(6)") + .HasDefaultValueSql("CURRENT_TIMESTAMP(6)"); + + b.Property("CreatedIp") + .HasMaxLength(64) + .HasColumnType("varchar(64)"); + + b.Property("ExpiresAt") + .HasColumnType("datetime(6)"); + + b.Property("RevokedAt") + .HasColumnType("datetime(6)"); + + b.Property("TokenHash") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("varchar(128)"); + + b.Property("UserAgent") + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("AccountId"); + + b.HasIndex("TokenHash") + .IsUnique(); + + b.ToTable("sessions", (string)null); + }); + + modelBuilder.Entity("Server.Data.Zone", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("datetime(6)") + .HasDefaultValueSql("CURRENT_TIMESTAMP(6)"); + + b.Property("MaxX") + .HasColumnType("double"); + + b.Property("MaxY") + .HasColumnType("double"); + + b.Property("MaxZ") + .HasColumnType("double"); + + b.Property("MinX") + .HasColumnType("double"); + + b.Property("MinY") + .HasColumnType("double"); + + b.Property("MinZ") + .HasColumnType("double"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("varchar(64)"); + + b.Property("UpdatedAt") + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("datetime(6)") + .HasDefaultValueSql("CURRENT_TIMESTAMP(6)"); + + MySqlPropertyBuilderExtensions.UseMySqlComputedColumn(b.Property("UpdatedAt")); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("zones", (string)null); + }); + + modelBuilder.Entity("Server.Data.Entities.DeathChest", b => + { + b.HasOne("Server.Data.Entities.DungeonCharacter", "OwnerCharacter") + .WithMany() + .HasForeignKey("OwnerCharacterId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Server.Data.Entities.DungeonCharacter", "VictimCharacter") + .WithMany() + .HasForeignKey("VictimCharacterId"); + + b.Navigation("OwnerCharacter"); + + b.Navigation("VictimCharacter"); + }); + + modelBuilder.Entity("Server.Data.Entities.DeathChestItem", b => + { + b.HasOne("Server.Data.Entities.DeathChest", "DeathChest") + .WithMany("Items") + .HasForeignKey("DeathChestId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Server.Data.Entities.DungeonItemDefinition", "ItemDefinition") + .WithMany() + .HasForeignKey("ItemDefinitionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("DeathChest"); + + b.Navigation("ItemDefinition"); + }); + + modelBuilder.Entity("Server.Data.Entities.DungeonBeltItem", b => + { + b.HasOne("Server.Data.Entities.DungeonCharacter", "Character") + .WithMany() + .HasForeignKey("CharacterId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Character"); + }); + + modelBuilder.Entity("Server.Data.Entities.DungeonCharacter", b => + { + b.HasOne("Server.Data.Account", "Account") + .WithMany() + .HasForeignKey("AccountId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Account"); + }); + + modelBuilder.Entity("Server.Data.Entities.DungeonCharacterItem", b => + { + b.HasOne("Server.Data.Entities.DungeonCharacter", "Character") + .WithMany("Inventory") + .HasForeignKey("CharacterId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Server.Data.Entities.DungeonItemDefinition", "ItemDefinition") + .WithMany() + .HasForeignKey("ItemDefinitionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Character"); + + b.Navigation("ItemDefinition"); + }); + + modelBuilder.Entity("Server.Data.Entities.DungeonLearnedSpell", b => + { + b.HasOne("Server.Data.Entities.DungeonCharacter", "Character") + .WithMany("LearnedSpells") + .HasForeignKey("CharacterId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Server.Data.Entities.DungeonSpellDefinition", "Definition") + .WithMany() + .HasForeignKey("DefinitionId"); + + b.Navigation("Character"); + + 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.DungeonPersistence", b => + { + b.HasOne("Server.Data.Entities.DungeonCharacter", "Creator") + .WithMany() + .HasForeignKey("CreatorId"); + + b.Navigation("Creator"); + }); + + modelBuilder.Entity("Server.Data.Entities.DungeonStashItem", b => + { + b.HasOne("Server.Data.Entities.DungeonCharacter", "Character") + .WithMany("Stash") + .HasForeignKey("CharacterId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Server.Data.Entities.DungeonItemDefinition", "Definition") + .WithMany() + .HasForeignKey("DefinitionId"); + + b.Navigation("Character"); + + b.Navigation("Definition"); + }); + + modelBuilder.Entity("Server.Data.EquipmentSlot", b => + { + b.HasOne("Server.Data.Old_Character", "Old_Character") + .WithMany() + .HasForeignKey("CharacterId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Server.Data.ItemTemplate", "ItemTemplate") + .WithMany() + .HasForeignKey("ItemTemplateId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("ItemTemplate"); + + b.Navigation("Old_Character"); + }); + + modelBuilder.Entity("Server.Data.GameRecipe", b => + { + b.HasOne("Server.Data.GameItem", "ResultItem") + .WithMany() + .HasForeignKey("ResultItemId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ResultItem"); + }); + + modelBuilder.Entity("Server.Data.InventoryItem", b => + { + b.HasOne("Server.Data.Old_Character", "Old_Character") + .WithMany() + .HasForeignKey("CharacterId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Server.Data.ItemTemplate", "ItemTemplate") + .WithMany() + .HasForeignKey("ItemTemplateId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("ItemTemplate"); + + b.Navigation("Old_Character"); + }); + + modelBuilder.Entity("Server.Data.MatchHistory", b => + { + b.HasOne("Server.Data.Account", "Account") + .WithMany() + .HasForeignKey("AccountId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Account"); + }); + + modelBuilder.Entity("Server.Data.Old_Character", b => + { + b.HasOne("Server.Data.Account", "Account") + .WithMany("Characters") + .HasForeignKey("AccountId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Server.Data.Zone", "Zone") + .WithMany() + .HasForeignKey("ZoneId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Account"); + + b.Navigation("Zone"); + }); + + modelBuilder.Entity("Server.Data.PlayerStats", b => + { + b.HasOne("Server.Data.Account", "Account") + .WithOne() + .HasForeignKey("Server.Data.PlayerStats", "AccountId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Account"); + }); + + modelBuilder.Entity("Server.Data.Session", b => + { + b.HasOne("Server.Data.Account", "Account") + .WithMany("Sessions") + .HasForeignKey("AccountId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Account"); + }); + + modelBuilder.Entity("Server.Data.Account", b => + { + b.Navigation("Characters"); + + b.Navigation("Sessions"); + }); + + modelBuilder.Entity("Server.Data.Entities.DeathChest", b => + { + b.Navigation("Items"); + }); + + modelBuilder.Entity("Server.Data.Entities.DungeonCharacter", b => + { + b.Navigation("Inventory"); + + b.Navigation("LearnedSpells"); + + b.Navigation("Stash"); + }); + + modelBuilder.Entity("Server.Data.Entities.DungeonLootTable", b => + { + b.Navigation("Entries"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Migrations/20251217201208_DungeonBrowser.cs b/Migrations/20251217201208_DungeonBrowser.cs new file mode 100644 index 0000000..1f22c11 --- /dev/null +++ b/Migrations/20251217201208_DungeonBrowser.cs @@ -0,0 +1,64 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace SystemRevivalServer.Migrations +{ + /// + public partial class DungeonBrowser : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "dungeon_instances", + columns: table => new + { + Id = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + Tier = table.Column(type: "int", nullable: false), + Seed = table.Column(type: "int", nullable: false), + LevelBracketMin = table.Column(type: "int", nullable: false), + LevelBracketMax = table.Column(type: "int", nullable: false), + CreatorCharacterId = table.Column(type: "bigint unsigned", nullable: false), + CreatorName = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + CreatorLevel = table.Column(type: "int", nullable: false), + CreatedAt = table.Column(type: "datetime(6)", nullable: false), + LastActivity = table.Column(type: "datetime(6)", nullable: false), + PersistedAt = table.Column(type: "datetime(6)", nullable: true), + BossKilled = table.Column(type: "tinyint(1)", nullable: false), + IsCleared = table.Column(type: "tinyint(1)", nullable: false), + MobStateJson = table.Column(type: "json", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + ChestStateJson = table.Column(type: "json", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + LootChestStateJson = table.Column(type: "json", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + CreatorId = table.Column(type: "bigint unsigned", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_dungeon_instances", x => x.Id); + table.ForeignKey( + name: "FK_dungeon_instances_dungeon_characters_CreatorId", + column: x => x.CreatorId, + principalTable: "dungeon_characters", + principalColumn: "Id"); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateIndex( + name: "IX_dungeon_instances_CreatorId", + table: "dungeon_instances", + column: "CreatorId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "dungeon_instances"); + } + } +} diff --git a/Migrations/GameDbContextModelSnapshot.cs b/Migrations/GameDbContextModelSnapshot.cs index 3c2b954..eff0600 100644 --- a/Migrations/GameDbContextModelSnapshot.cs +++ b/Migrations/GameDbContextModelSnapshot.cs @@ -735,6 +735,68 @@ namespace SystemRevivalServer.Migrations b.ToTable("dungeon_mob_loot_tables"); }); + modelBuilder.Entity("Server.Data.Entities.DungeonPersistence", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)"); + + b.Property("BossKilled") + .HasColumnType("tinyint(1)"); + + b.Property("ChestStateJson") + .HasColumnType("json"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("CreatorCharacterId") + .HasColumnType("bigint unsigned"); + + b.Property("CreatorId") + .HasColumnType("bigint unsigned"); + + b.Property("CreatorLevel") + .HasColumnType("int"); + + b.Property("CreatorName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("IsCleared") + .HasColumnType("tinyint(1)"); + + b.Property("LastActivity") + .HasColumnType("datetime(6)"); + + b.Property("LevelBracketMax") + .HasColumnType("int"); + + b.Property("LevelBracketMin") + .HasColumnType("int"); + + b.Property("LootChestStateJson") + .HasColumnType("json"); + + b.Property("MobStateJson") + .HasColumnType("json"); + + b.Property("PersistedAt") + .HasColumnType("datetime(6)"); + + b.Property("Seed") + .HasColumnType("int"); + + b.Property("Tier") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.ToTable("dungeon_instances"); + }); + modelBuilder.Entity("Server.Data.Entities.DungeonSpellDefinition", b => { b.Property("Id") @@ -1613,6 +1675,15 @@ namespace SystemRevivalServer.Migrations b.Navigation("MobDefinition"); }); + modelBuilder.Entity("Server.Data.Entities.DungeonPersistence", b => + { + b.HasOne("Server.Data.Entities.DungeonCharacter", "Creator") + .WithMany() + .HasForeignKey("CreatorId"); + + b.Navigation("Creator"); + }); + modelBuilder.Entity("Server.Data.Entities.DungeonStashItem", b => { b.HasOne("Server.Data.Entities.DungeonCharacter", "Character") diff --git a/Networking/Messages/DungeonOpCodes.cs b/Networking/Messages/DungeonOpCodes.cs index e38387e..f728752 100644 --- a/Networking/Messages/DungeonOpCodes.cs +++ b/Networking/Messages/DungeonOpCodes.cs @@ -14,6 +14,13 @@ public static class DungeonOpCodes public const int DUNGEON_ENTER_RESULT = 301; public const int DUNGEON_STATE = 302; public const int DUNGEON_LEAVE = 303; + public const int DUNGEON_CLEARED = 304; + + // Dungeon Browser (310-319) + public const int DUNGEON_LIST_REQUEST = 310; + public const int DUNGEON_LIST_RESPONSE = 311; + public const int DUNGEON_CREATE = 312; + public const int DUNGEON_JOIN = 313; // Input (400-449) public const int DUNGEON_INPUT_MOVE = 400; @@ -35,7 +42,6 @@ public static class DungeonOpCodes public const int EVENT_LEVELUP = 502; public const int EVENT_LOOT = 503; public const int LOOT_RECEIVED = 160; - public const int DUNGEON_CLEARED = 304; // Inventory (250-259) public const int INVENTORY_REQUEST = 250; diff --git a/data/GameDbContext.cs b/data/GameDbContext.cs index 67e79ff..01a9726 100644 --- a/data/GameDbContext.cs +++ b/data/GameDbContext.cs @@ -1,8 +1,7 @@ using System.Security.Principal; using Microsoft.EntityFrameworkCore; using Server.Data.Entities; -using Server.Data.Entities; -using Server.Data.Enums; + namespace Server.Data; @@ -34,6 +33,7 @@ public sealed class GameDbContext : DbContext public DbSet DungeonBeltItems => Set(); public DbSet DeathChests => Set(); public DbSet DeathChestItems => Set(); + public DbSet DungeonInstances => Set(); protected override void OnModelCreating(ModelBuilder b) { b.ApplyConfigurationsFromAssembly(typeof(GameDbContext).Assembly); diff --git a/data/entities/DungeonMobDefinition.cs b/data/entities/DungeonMobDefinition.cs index fac4025..0f83dd0 100644 --- a/data/entities/DungeonMobDefinition.cs +++ b/data/entities/DungeonMobDefinition.cs @@ -120,19 +120,34 @@ public class DungeonMobDefinition /// public DungeonMobCombatStats GetStatsForTier(int tier) { + return GetStatsForTierAndBracket(tier, 1); // Default to bracket 1 for backwards compatibility + } + + /// + /// Calculate scaled stats for a specific dungeon tier and level bracket + /// Level bracket scaling: each bracket adds 15% to base stats + /// + public DungeonMobCombatStats GetStatsForTierAndBracket(int tier, int bracketMin) + { + // Calculate bracket number (1-10 = bracket 1, 11-20 = bracket 2, etc.) + int bracketNumber = Math.Max(1, (bracketMin - 1) / 10 + 1); + + // Bracket scaling: each bracket adds 15% to base stats (compound) + double bracketMultiplier = Math.Pow(1.15, bracketNumber - 1); + return new DungeonMobCombatStats { - MaxHealth = (int)(BaseHealth * Math.Pow(HealthPerTier, tier - 1)), - PhysicalDamage = (int)(BasePhysicalDamage * Math.Pow(DamagePerTier, tier - 1)), - MagicDamage = (int)(BaseMagicDamage * Math.Pow(DamagePerTier, tier - 1)), - Armor = (int)(BaseArmor * Math.Pow(ArmorPerTier, tier - 1)), - MagicResist = (int)(BaseMagicResist * Math.Pow(ArmorPerTier, tier - 1)), + MaxHealth = (int)(BaseHealth * Math.Pow(HealthPerTier, tier - 1) * bracketMultiplier), + PhysicalDamage = (int)(BasePhysicalDamage * Math.Pow(DamagePerTier, tier - 1) * bracketMultiplier), + MagicDamage = (int)(BaseMagicDamage * Math.Pow(DamagePerTier, tier - 1) * bracketMultiplier), + Armor = (int)(BaseArmor * Math.Pow(ArmorPerTier, tier - 1) * bracketMultiplier), + MagicResist = (int)(BaseMagicResist * Math.Pow(ArmorPerTier, tier - 1) * bracketMultiplier), MoveSpeed = MoveSpeed, AttackRange = AttackRange, AttackSpeed = AttackSpeed, AggroRange = AggroRange, LeashRange = LeashRange, - XpReward = (int)(BaseXp * Math.Pow(XpPerTier, tier - 1)), + XpReward = (int)(BaseXp * Math.Pow(XpPerTier, tier - 1) * bracketMultiplier), Resistances = Resistances }; } diff --git a/data/entities/DungeonPersistence.cs b/data/entities/DungeonPersistence.cs new file mode 100644 index 0000000..7b81816 --- /dev/null +++ b/data/entities/DungeonPersistence.cs @@ -0,0 +1,78 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace Server.Data.Entities; + +/// +/// Persisted dungeon data for dungeons that become inactive but remain "open" +/// +[Table("dungeon_instances")] +public class DungeonPersistence +{ + [Key] + public Guid Id { get; set; } + + public int Tier { get; set; } + public int Seed { get; set; } + + // Level bracket + public int LevelBracketMin { get; set; } + public int LevelBracketMax { get; set; } + + // Creator info + public ulong CreatorCharacterId { get; set; } + public string CreatorName { get; set; } = ""; + public int CreatorLevel { get; set; } + + // Timestamps + public DateTime CreatedAt { get; set; } + public DateTime LastActivity { get; set; } + public DateTime? PersistedAt { get; set; } + + // State + public bool BossKilled { get; set; } = false; + public bool IsCleared { get; set; } = false; + + /// + /// Serialized mob state (JSON) - only alive mobs with their positions/health + /// + [Column(TypeName = "json")] + public string? MobStateJson { get; set; } + + /// + /// Serialized chest state (JSON) - which chests are opened + /// + [Column(TypeName = "json")] + public string? ChestStateJson { get; set; } + + /// + /// Serialized loot chest state (JSON) - personal loot chests + /// + [Column(TypeName = "json")] + public string? LootChestStateJson { get; set; } + + // Navigation + public virtual DungeonCharacter? Creator { get; set; } +} + +/// +/// Serializable mob state for persistence +/// +public class PersistedMobState +{ + public int Id { get; set; } + public int DefinitionId { get; set; } + public float X { get; set; } + public float Y { get; set; } + public int Health { get; set; } + public bool IsAlive { get; set; } +} + +/// +/// Serializable chest state for persistence +/// +public class PersistedChestState +{ + public int Id { get; set; } + public bool IsOpened { get; set; } +}