Loot fix
This commit is contained in:
@@ -423,7 +423,7 @@ public sealed class DungeonHandler : IClientMessageHandler
|
|||||||
seed = instance.Seed,
|
seed = instance.Seed,
|
||||||
width = layout2.Width,
|
width = layout2.Width,
|
||||||
height = layout2.Height,
|
height = layout2.Height,
|
||||||
tiles = layout2.SerializeTiles(),
|
tilesRLE = layout2.SerializeTilesRLE(),
|
||||||
spawn = new { x = player.X, y = player.Y },
|
spawn = new { x = player.X, y = player.Y },
|
||||||
players = instance.Simulation.Players.Values.Select(p => new
|
players = instance.Simulation.Players.Values.Select(p => new
|
||||||
{
|
{
|
||||||
@@ -1393,11 +1393,16 @@ public sealed class DungeonHandler : IClientMessageHandler
|
|||||||
chest.Items.Remove(chestItem);
|
chest.Items.Remove(chestItem);
|
||||||
|
|
||||||
// Check if chest is now empty
|
// Check if chest is now empty
|
||||||
await CheckAndRemoveEmptyChestAsync(db, dungeon, chest, ct);
|
await CheckAndRemoveEmptyChestAsync(db, dungeon, chest, session, ct);
|
||||||
|
|
||||||
// Send updated states
|
// Send updated states
|
||||||
await HandleInventoryRequest(connection, session, ct);
|
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>
|
/// <summary>
|
||||||
@@ -1521,7 +1526,7 @@ public sealed class DungeonHandler : IClientMessageHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if chest is now empty
|
// Check if chest is now empty
|
||||||
await CheckAndRemoveEmptyChestAsync(db, dungeon, chest, ct);
|
await CheckAndRemoveEmptyChestAsync(db, dungeon, chest, session, ct);
|
||||||
|
|
||||||
// Send updated inventory
|
// Send updated inventory
|
||||||
await HandleInventoryRequest(connection, session, ct);
|
await HandleInventoryRequest(connection, session, ct);
|
||||||
@@ -1560,7 +1565,7 @@ public sealed class DungeonHandler : IClientMessageHandler
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Check if a chest is empty and remove it if so
|
/// Check if a chest is empty and remove it if so
|
||||||
/// </summary>
|
/// </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)
|
if (chest.IsEmpty)
|
||||||
{
|
{
|
||||||
@@ -1573,6 +1578,12 @@ public sealed class DungeonHandler : IClientMessageHandler
|
|||||||
await db.SaveChangesAsync(ct);
|
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
|
// Remove from runtime
|
||||||
dungeon.Simulation.LootChests.TryRemove(chest.Id, out _);
|
dungeon.Simulation.LootChests.TryRemove(chest.Id, out _);
|
||||||
|
|
||||||
@@ -1831,7 +1842,7 @@ public sealed class DungeonHandler : IClientMessageHandler
|
|||||||
levelBracket = new { min = instance.LevelBracketMin, max = instance.LevelBracketMax },
|
levelBracket = new { min = instance.LevelBracketMin, max = instance.LevelBracketMax },
|
||||||
width = layout.Width,
|
width = layout.Width,
|
||||||
height = layout.Height,
|
height = layout.Height,
|
||||||
tiles = layout.SerializeTiles(),
|
tilesRLE = layout.SerializeTilesRLE(),
|
||||||
spawn = new { x = player.X, y = player.Y },
|
spawn = new { x = player.X, y = player.Y },
|
||||||
players = instance.Simulation.Players.Values.Select(p => new
|
players = instance.Simulation.Players.Values.Select(p => new
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ public static class DungeonOpCodes
|
|||||||
public const int EVENT_LEVELUP = 502;
|
public const int EVENT_LEVELUP = 502;
|
||||||
public const int EVENT_LOOT = 503;
|
public const int EVENT_LOOT = 503;
|
||||||
public const int LOOT_RECEIVED = 160;
|
public const int LOOT_RECEIVED = 160;
|
||||||
|
public const int DUNGEON_CLEARED = 304;
|
||||||
|
|
||||||
// Inventory (250-259)
|
// Inventory (250-259)
|
||||||
public const int INVENTORY_REQUEST = 250;
|
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_TAKE_ALL = 273;
|
||||||
public const int LOOT_CHEST_CLOSE = 274;
|
public const int LOOT_CHEST_CLOSE = 274;
|
||||||
public const int LOOT_CHEST_SPAWNED = 275;
|
public const int LOOT_CHEST_SPAWNED = 275;
|
||||||
|
public const int LOOT_CHEST_REMOVED = 276;
|
||||||
|
|
||||||
// Player Death (280-289)
|
// Player Death (280-289)
|
||||||
public const int PLAYER_DEATH_LOOT_LOST = 280; // Notifies victim what they lost
|
public const int PLAYER_DEATH_LOOT_LOST = 280; // Notifies victim what they lost
|
||||||
|
|||||||
Reference in New Issue
Block a user