Fixing Hotbar
This commit is contained in:
@@ -1432,7 +1432,7 @@ public sealed partial class DungeonHandler : IClientMessageHandler
|
||||
using var scope = _scopeFactory.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<GameDbContext>();
|
||||
|
||||
// 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<DungeonCharacterItem>()
|
||||
.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<DungeonItemDefinition>()
|
||||
.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<DungeonBeltItem>()
|
||||
.Where(b => b.CharacterId == session.CharacterId &&
|
||||
b.InventorySlotIndex == request.InventorySlot &&
|
||||
b.SlotIndex != request.HotbarSlot)
|
||||
.ToListAsync(ct);
|
||||
|
||||
if (duplicateEntries.Any())
|
||||
{
|
||||
db.Set<DungeonBeltItem>().RemoveRange(duplicateEntries);
|
||||
}
|
||||
|
||||
// Find existing hotbar entry for this slot
|
||||
var existingEntry = await db.Set<DungeonBeltItem>()
|
||||
.FirstOrDefaultAsync(b => b.CharacterId == session.CharacterId &&
|
||||
@@ -3582,7 +3597,7 @@ public sealed partial class DungeonHandler : IClientMessageHandler
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle use item request (consumables)
|
||||
/// Handle use item request (consumables get used, equipment gets equipped)
|
||||
/// </summary>
|
||||
private async Task HandleUseItem(IConnection connection, DungeonPlayerSession session, ReadOnlyMemory<byte> 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
|
||||
|
||||
Reference in New Issue
Block a user