This commit is contained in:
dingo
2025-12-17 20:18:36 -05:00
parent e446cc28b6
commit 2faf19452e
2 changed files with 19 additions and 6 deletions
+17 -6
View File
@@ -423,7 +423,7 @@ public sealed class DungeonHandler : IClientMessageHandler
seed = instance.Seed,
width = layout2.Width,
height = layout2.Height,
tiles = layout2.SerializeTiles(),
tilesRLE = layout2.SerializeTilesRLE(),
spawn = new { x = player.X, y = player.Y },
players = instance.Simulation.Players.Values.Select(p => new
{
@@ -1393,11 +1393,16 @@ public sealed class DungeonHandler : IClientMessageHandler
chest.Items.Remove(chestItem);
// Check if chest is now empty
await CheckAndRemoveEmptyChestAsync(db, dungeon, chest, ct);
await CheckAndRemoveEmptyChestAsync(db, dungeon, chest, session, ct);
// Send updated states
await HandleInventoryRequest(connection, session, ct);
await HandleLootChestOpen(connection, session, payload, ct); // Resend chest state
// Only resend chest state if it still exists
if (!chest.IsEmpty)
{
await HandleLootChestOpen(connection, session, payload, ct);
}
}
/// <summary>
@@ -1521,7 +1526,7 @@ public sealed class DungeonHandler : IClientMessageHandler
}
// Check if chest is now empty
await CheckAndRemoveEmptyChestAsync(db, dungeon, chest, ct);
await CheckAndRemoveEmptyChestAsync(db, dungeon, chest, session, ct);
// Send updated inventory
await HandleInventoryRequest(connection, session, ct);
@@ -1560,7 +1565,7 @@ public sealed class DungeonHandler : IClientMessageHandler
/// <summary>
/// Check if a chest is empty and remove it if so
/// </summary>
private async Task CheckAndRemoveEmptyChestAsync(GameDbContext db, DungeonInstance dungeon, LootChestInstance chest, CancellationToken ct)
private async Task CheckAndRemoveEmptyChestAsync(GameDbContext db, DungeonInstance dungeon, LootChestInstance chest, DungeonPlayerSession owner, CancellationToken ct)
{
if (chest.IsEmpty)
{
@@ -1573,6 +1578,12 @@ public sealed class DungeonHandler : IClientMessageHandler
await db.SaveChangesAsync(ct);
}
// Notify owner that chest is removed
await SendAsync(owner.Connection, DungeonOpCodes.LOOT_CHEST_REMOVED, new
{
chestId = chest.Id
}, ct);
// Remove from runtime
dungeon.Simulation.LootChests.TryRemove(chest.Id, out _);
@@ -1831,7 +1842,7 @@ public sealed class DungeonHandler : IClientMessageHandler
levelBracket = new { min = instance.LevelBracketMin, max = instance.LevelBracketMax },
width = layout.Width,
height = layout.Height,
tiles = layout.SerializeTiles(),
tilesRLE = layout.SerializeTilesRLE(),
spawn = new { x = player.X, y = player.Y },
players = instance.Simulation.Players.Values.Select(p => new
{
+2
View File
@@ -42,6 +42,7 @@ 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;
@@ -63,6 +64,7 @@ public static class DungeonOpCodes
public const int LOOT_CHEST_TAKE_ALL = 273;
public const int LOOT_CHEST_CLOSE = 274;
public const int LOOT_CHEST_SPAWNED = 275;
public const int LOOT_CHEST_REMOVED = 276;
// Player Death (280-289)
public const int PLAYER_DEATH_LOOT_LOST = 280; // Notifies victim what they lost