diff --git a/Game/Dungeon/DungeonHandler.cs b/Game/Dungeon/DungeonHandler.cs index 567221b..ca83926 100644 --- a/Game/Dungeon/DungeonHandler.cs +++ b/Game/Dungeon/DungeonHandler.cs @@ -1432,7 +1432,7 @@ public sealed partial class DungeonHandler : IClientMessageHandler using var scope = _scopeFactory.CreateScope(); var db = scope.ServiceProvider.GetRequiredService(); - // Check if the inventory slot has a consumable item + // Check if the inventory slot has a valid item (consumable or equipment) var invItem = await db.Set() .FirstOrDefaultAsync(i => i.CharacterId == session.CharacterId && i.SlotIndex == request.InventorySlot && @@ -1443,14 +1443,29 @@ public sealed partial class DungeonHandler : IClientMessageHandler var itemDef = await db.Set() .FirstOrDefaultAsync(d => d.Id == invItem.ItemDefinitionId, ct); - // Only allow consumables in hotbar - if (itemDef == null || itemDef.Type != ItemType.Consumable) + // Only allow consumables and equipment in hotbar + if (itemDef == null || (itemDef.Type != ItemType.Consumable && + itemDef.Type != ItemType.Weapon && + itemDef.Type != ItemType.Armor && + itemDef.Type != ItemType.Accessory)) { - _log.LogDebug("Cannot assign non-consumable item to hotbar"); + _log.LogDebug("Cannot assign item type {Type} to hotbar", itemDef?.Type); return; } } + // Remove the same inventory slot from any other hotbar slot (prevent duplicates) + var duplicateEntries = await db.Set() + .Where(b => b.CharacterId == session.CharacterId && + b.InventorySlotIndex == request.InventorySlot && + b.SlotIndex != request.HotbarSlot) + .ToListAsync(ct); + + if (duplicateEntries.Any()) + { + db.Set().RemoveRange(duplicateEntries); + } + // Find existing hotbar entry for this slot var existingEntry = await db.Set() .FirstOrDefaultAsync(b => b.CharacterId == session.CharacterId && @@ -3582,7 +3597,7 @@ public sealed partial class DungeonHandler : IClientMessageHandler } /// - /// Handle use item request (consumables) + /// Handle use item request (consumables get used, equipment gets equipped) /// private async Task HandleUseItem(IConnection connection, DungeonPlayerSession session, ReadOnlyMemory payload, CancellationToken ct) { @@ -3599,7 +3614,16 @@ public sealed partial class DungeonHandler : IClientMessageHandler if (item?.ItemDefinition == null) return; - // Only consumables can be used + // If it's equipment, delegate to equip handler instead + if (item.ItemDefinition.Type == ItemType.Weapon || + item.ItemDefinition.Type == ItemType.Armor || + item.ItemDefinition.Type == ItemType.Accessory) + { + await HandleEquipItem(connection, session, payload, ct); + return; + } + + // Only consumables can be used directly if (item.ItemDefinition.Type != ItemType.Consumable) return; // Apply effects