Dungeon Changes

This commit is contained in:
dingo
2026-01-25 15:36:54 -05:00
parent cd40e28f72
commit 9a5e45c35b
2 changed files with 69 additions and 14 deletions
+68 -14
View File
@@ -357,6 +357,9 @@ public sealed partial class DungeonHandler : IClientMessageHandler
case DungeonOpCodes.MOVE_ITEM:
await HandleMoveItem(connection, session, payload, ct);
break;
case DungeonOpCodes.AUTO_STACK_INVENTORY:
await HandleAutoStackInventory(connection, session, ct);
break;
case DungeonOpCodes.CHAT_SEND:
await HandleChatSend(connection, session, payload, ct);
break;
@@ -3643,9 +3646,9 @@ public sealed partial class DungeonHandler : IClientMessageHandler
if (sourceItem?.ItemDefinition == null || targetItem?.ItemDefinition == null) return;
// Can only stack consumables with the same name
if (sourceItem.ItemDefinition.Type != ItemType.Consumable || targetItem.ItemDefinition.Type != ItemType.Consumable) return;
if (sourceItem.ItemDefinition.Name != targetItem.ItemDefinition.Name) return;
// Can only stack items with the same ID and that are stackable
if (sourceItem.ItemDefinitionId != targetItem.ItemDefinitionId) return;
if (!sourceItem.ItemDefinition.Stackable || !targetItem.ItemDefinition.Stackable) return;
// Check max stack
var maxStack = targetItem.ItemDefinition.MaxStack;
@@ -3702,6 +3705,64 @@ public sealed partial class DungeonHandler : IClientMessageHandler
await HandleInventoryRequest(connection, session, ct);
}
private async Task HandleAutoStackInventory(IConnection connection, DungeonPlayerSession session, CancellationToken ct)
{
using var scope = _scopeFactory.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<GameDbContext>();
// Get all inventory items
var items = await db.Set<DungeonCharacterItem>()
.Include(i => i.ItemDefinition)
.Where(i => i.CharacterId == session.CharacterId && !i.IsEquipped)
.OrderBy(i => i.SlotIndex)
.ToListAsync(ct);
// Group stackable items by ItemDefinitionId
var stackableGroups = items
.Where(i => i.ItemDefinition.Stackable)
.GroupBy(i => i.ItemDefinitionId)
.Where(g => g.Count() > 1) // Only process if there are multiple stacks
.ToList();
foreach (var group in stackableGroups)
{
var maxStack = group.First().ItemDefinition.MaxStack;
var stacks = group.OrderBy(i => i.Quantity).ToList();
// Consolidate into as few stacks as possible
for (int i = 0; i < stacks.Count; i++)
{
if (stacks[i].Quantity >= maxStack) continue;
for (int j = i + 1; j < stacks.Count; j++)
{
if (stacks[j].Quantity == 0) continue;
var spaceAvailable = maxStack - stacks[i].Quantity;
var amountToMove = Math.Min(stacks[j].Quantity, spaceAvailable);
if (amountToMove > 0)
{
stacks[i].Quantity += amountToMove;
stacks[j].Quantity -= amountToMove;
if (stacks[j].Quantity <= 0)
{
db.Set<DungeonCharacterItem>().Remove(stacks[j]);
}
}
if (stacks[i].Quantity >= maxStack) break;
}
}
}
await db.SaveChangesAsync(ct);
// Send updated inventory
await HandleInventoryRequest(connection, session, ct);
}
private DungeonEquipmentSlot? GetEquipSlotForItem(DungeonItemDefinition item)
{
return item.Type switch
@@ -3868,23 +3929,16 @@ public sealed partial class DungeonHandler : IClientMessageHandler
/// </summary>
private async Task HandleDungeonClearedAsync(DungeonPlayerSession session)
{
_log.LogInformation("Dungeon cleared! Returning player {Name} to hub", session.Character.Name);
_log.LogInformation("Dungeon cleared! Player {Name} can now exit via portal", session.Character.Name);
// Send dungeon cleared notification
// Send dungeon cleared notification (but don't force exit)
await SendAsync(session.Connection, DungeonOpCodes.DUNGEON_STATE, new
{
phase = "cleared",
message = "Dungeon cleared! All enemies defeated."
message = "Dungeon cleared! Use the portal to exit."
}, CancellationToken.None);
// Small delay to let client see the message
await Task.Delay(2000);
// Remove from dungeon (extracted = true, so they keep XP and loot)
await RemoveFromDungeonAsync(session, true, CancellationToken.None);
// Send hub state
await SendAsync(session.Connection, DungeonOpCodes.HUB_STATE, GetHubState(session.Character), CancellationToken.None);
// Don't automatically remove from dungeon - let them use the portal
}
private async Task HandlePlayerDeathAsync(DungeonPlayerSession session)
+1
View File
@@ -63,6 +63,7 @@ public static class DungeonOpCodes
public const int HOTBAR_ASSIGN = 256;
public const int STACK_ITEMS = 257; // Stack consumables from source to target slot
public const int MOVE_ITEM = 258; // Move/swap item between inventory slots
public const int AUTO_STACK_INVENTORY = 259; // Auto-stack all stackable items in inventory
// Chat (260-269)
public const int CHAT_SEND = 260;