tweaks
This commit is contained in:
@@ -71,7 +71,8 @@ public sealed class DungeonHandler : IClientMessageHandler
|
|||||||
DungeonOpCodes.UNEQUIP_ITEM,
|
DungeonOpCodes.UNEQUIP_ITEM,
|
||||||
DungeonOpCodes.USE_ITEM,
|
DungeonOpCodes.USE_ITEM,
|
||||||
DungeonOpCodes.DROP_ITEM,
|
DungeonOpCodes.DROP_ITEM,
|
||||||
DungeonOpCodes.CHAT_SEND
|
DungeonOpCodes.CHAT_SEND,
|
||||||
|
DungeonOpCodes.HOTBAR_ASSIGN
|
||||||
};
|
};
|
||||||
|
|
||||||
public async Task InitializeAsync()
|
public async Task InitializeAsync()
|
||||||
@@ -195,6 +196,9 @@ public sealed class DungeonHandler : IClientMessageHandler
|
|||||||
case DungeonOpCodes.CHAT_SEND:
|
case DungeonOpCodes.CHAT_SEND:
|
||||||
await HandleChatSend(connection, session, payload, ct);
|
await HandleChatSend(connection, session, payload, ct);
|
||||||
break;
|
break;
|
||||||
|
case DungeonOpCodes.HOTBAR_ASSIGN:
|
||||||
|
await HandleHotbarAssign(connection, session, payload, ct);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -545,6 +549,71 @@ public sealed class DungeonHandler : IClientMessageHandler
|
|||||||
{
|
{
|
||||||
session.IsEscaping = false;
|
session.IsEscaping = false;
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Handle hotbar slot assignment - links a hotbar slot to an inventory slot
|
||||||
|
/// </summary>
|
||||||
|
private async Task HandleHotbarAssign(IConnection connection, DungeonPlayerSession session, ReadOnlyMemory<byte> payload, CancellationToken ct)
|
||||||
|
{
|
||||||
|
var json = System.Text.Encoding.UTF8.GetString(payload.Span);
|
||||||
|
var request = System.Text.Json.JsonSerializer.Deserialize<HotbarAssignRequest>(json);
|
||||||
|
if (request == null) return;
|
||||||
|
|
||||||
|
// Validate slots
|
||||||
|
if (request.HotbarSlot < 0 || request.HotbarSlot >= 8) return;
|
||||||
|
if (request.InventorySlot < 0 || request.InventorySlot >= 30) return;
|
||||||
|
|
||||||
|
using var scope = _scopeFactory.CreateScope();
|
||||||
|
var db = scope.ServiceProvider.GetRequiredService<GameDbContext>();
|
||||||
|
|
||||||
|
// Check if the inventory slot has a consumable item
|
||||||
|
var invItem = await db.Set<DungeonCharacterItem>()
|
||||||
|
.FirstOrDefaultAsync(i => i.CharacterId == session.CharacterId &&
|
||||||
|
i.SlotIndex == request.InventorySlot &&
|
||||||
|
!i.IsEquipped, ct);
|
||||||
|
|
||||||
|
if (invItem != null)
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
_log.LogDebug("Cannot assign non-consumable item to hotbar");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find existing hotbar entry for this slot
|
||||||
|
var existingEntry = await db.Set<DungeonBeltItem>()
|
||||||
|
.FirstOrDefaultAsync(b => b.CharacterId == session.CharacterId &&
|
||||||
|
b.SlotIndex == request.HotbarSlot, ct);
|
||||||
|
|
||||||
|
if (existingEntry != null)
|
||||||
|
{
|
||||||
|
// Update existing
|
||||||
|
existingEntry.InventorySlotIndex = request.InventorySlot;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Create new
|
||||||
|
var newEntry = new DungeonBeltItem
|
||||||
|
{
|
||||||
|
CharacterId = session.CharacterId,
|
||||||
|
SlotIndex = request.HotbarSlot,
|
||||||
|
InventorySlotIndex = request.InventorySlot
|
||||||
|
};
|
||||||
|
db.Set<DungeonBeltItem>().Add(newEntry);
|
||||||
|
}
|
||||||
|
|
||||||
|
await db.SaveChangesAsync(ct);
|
||||||
|
|
||||||
|
// Send updated inventory state (includes hotbar)
|
||||||
|
await HandleInventoryRequest(connection, session, ct);
|
||||||
|
|
||||||
|
_log.LogDebug("Player {Name} assigned inventory slot {InvSlot} to hotbar slot {HotbarSlot}",
|
||||||
|
session.Character.Name, request.InventorySlot, request.HotbarSlot);
|
||||||
|
}
|
||||||
|
|
||||||
private void TickAll(object? state)
|
private void TickAll(object? state)
|
||||||
{
|
{
|
||||||
@@ -782,7 +851,23 @@ public sealed class DungeonHandler : IClientMessageHandler
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Load hotbar assignments
|
||||||
|
var hotbarItems = await db.Set<DungeonBeltItem>()
|
||||||
|
.Where(b => b.CharacterId == session.CharacterId)
|
||||||
|
.OrderBy(b => b.SlotIndex)
|
||||||
|
.ToListAsync(ct);
|
||||||
|
|
||||||
|
var hotbar = new object?[8];
|
||||||
|
foreach (var belt in hotbarItems)
|
||||||
|
{
|
||||||
|
if (belt.SlotIndex >= 0 && belt.SlotIndex < 8)
|
||||||
|
{
|
||||||
|
hotbar[belt.SlotIndex] = new
|
||||||
|
{
|
||||||
|
inventory_slot = belt.InventorySlotIndex
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
// Build equipment map - using your actual enum names
|
// Build equipment map - using your actual enum names
|
||||||
var equipment = new Dictionary<string, object?>();
|
var equipment = new Dictionary<string, object?>();
|
||||||
foreach (var equippedItem in inventoryItems.Where(i => i.IsEquipped))
|
foreach (var equippedItem in inventoryItems.Where(i => i.IsEquipped))
|
||||||
@@ -824,7 +909,8 @@ public sealed class DungeonHandler : IClientMessageHandler
|
|||||||
await SendAsync(connection, DungeonOpCodes.INVENTORY_STATE, new
|
await SendAsync(connection, DungeonOpCodes.INVENTORY_STATE, new
|
||||||
{
|
{
|
||||||
items,
|
items,
|
||||||
equipment
|
equipment,
|
||||||
|
hotbar,
|
||||||
}, ct);
|
}, ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1639
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,49 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace SystemRevivalServer.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddDungeonBeltItems : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "dungeon_belt_items",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<ulong>(type: "bigint unsigned", nullable: false)
|
||||||
|
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||||
|
CharacterId = table.Column<ulong>(type: "bigint unsigned", nullable: false),
|
||||||
|
SlotIndex = table.Column<int>(type: "int", nullable: false),
|
||||||
|
InventorySlotIndex = table.Column<int>(type: "int", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_dungeon_belt_items", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_dungeon_belt_items_dungeon_characters_CharacterId",
|
||||||
|
column: x => x.CharacterId,
|
||||||
|
principalTable: "dungeon_characters",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
})
|
||||||
|
.Annotation("MySql:CharSet", "utf8mb4");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_dungeon_belt_items_CharacterId",
|
||||||
|
table: "dungeon_belt_items",
|
||||||
|
column: "CharacterId");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "dungeon_belt_items");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -81,6 +81,30 @@ namespace SystemRevivalServer.Migrations
|
|||||||
b.ToTable("accounts", (string)null);
|
b.ToTable("accounts", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Server.Data.Entities.DungeonBeltItem", b =>
|
||||||
|
{
|
||||||
|
b.Property<ulong>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("bigint unsigned");
|
||||||
|
|
||||||
|
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<ulong>("Id"));
|
||||||
|
|
||||||
|
b.Property<ulong>("CharacterId")
|
||||||
|
.HasColumnType("bigint unsigned");
|
||||||
|
|
||||||
|
b.Property<int>("InventorySlotIndex")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("SlotIndex")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("CharacterId");
|
||||||
|
|
||||||
|
b.ToTable("dungeon_belt_items");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Server.Data.Entities.DungeonCharacter", b =>
|
modelBuilder.Entity("Server.Data.Entities.DungeonCharacter", b =>
|
||||||
{
|
{
|
||||||
b.Property<ulong>("Id")
|
b.Property<ulong>("Id")
|
||||||
@@ -1372,6 +1396,17 @@ namespace SystemRevivalServer.Migrations
|
|||||||
b.ToTable("zones", (string)null);
|
b.ToTable("zones", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Server.Data.Entities.DungeonBeltItem", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Server.Data.Entities.DungeonCharacter", "Character")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("CharacterId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Character");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Server.Data.Entities.DungeonCharacter", b =>
|
modelBuilder.Entity("Server.Data.Entities.DungeonCharacter", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("Server.Data.Account", "Account")
|
b.HasOne("Server.Data.Account", "Account")
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ public static class DungeonOpCodes
|
|||||||
public const int UNEQUIP_ITEM = 253;
|
public const int UNEQUIP_ITEM = 253;
|
||||||
public const int USE_ITEM = 254;
|
public const int USE_ITEM = 254;
|
||||||
public const int DROP_ITEM = 255;
|
public const int DROP_ITEM = 255;
|
||||||
|
public const int HOTBAR_ASSIGN = 256;
|
||||||
|
|
||||||
// Chat (260-269)
|
// Chat (260-269)
|
||||||
public const int CHAT_SEND = 260;
|
public const int CHAT_SEND = 260;
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
public class HotbarAssignRequest
|
||||||
|
{
|
||||||
|
public int HotbarSlot { get; set; }
|
||||||
|
public int InventorySlot { get; set; }
|
||||||
|
}
|
||||||
@@ -31,6 +31,7 @@ public sealed class GameDbContext : DbContext
|
|||||||
public DbSet<DungeonLootTable> DungeonLootTables => Set<DungeonLootTable>();
|
public DbSet<DungeonLootTable> DungeonLootTables => Set<DungeonLootTable>();
|
||||||
public DbSet<DungeonLootTableEntry> DungeonLootTableEntries => Set<DungeonLootTableEntry>();
|
public DbSet<DungeonLootTableEntry> DungeonLootTableEntries => Set<DungeonLootTableEntry>();
|
||||||
public DbSet<DungeonMobLootTable> DungeonMobLootTables => Set<DungeonMobLootTable>();
|
public DbSet<DungeonMobLootTable> DungeonMobLootTables => Set<DungeonMobLootTable>();
|
||||||
|
public DbSet<DungeonBeltItem> DungeonBeltItems => Set<DungeonBeltItem>();
|
||||||
protected override void OnModelCreating(ModelBuilder b)
|
protected override void OnModelCreating(ModelBuilder b)
|
||||||
{
|
{
|
||||||
b.ApplyConfigurationsFromAssembly(typeof(GameDbContext).Assembly);
|
b.ApplyConfigurationsFromAssembly(typeof(GameDbContext).Assembly);
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace Server.Data.Entities;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Hotbar/belt item slot assignment for quick item access
|
||||||
|
/// </summary>
|
||||||
|
[Table("dungeon_belt_items")]
|
||||||
|
public class DungeonBeltItem
|
||||||
|
{
|
||||||
|
[Key]
|
||||||
|
public ulong Id { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public ulong CharacterId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Hotbar slot (0-7)
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
public int SlotIndex { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reference to inventory slot index (not item ID, since items can stack/move)
|
||||||
|
/// </summary>
|
||||||
|
public int InventorySlotIndex { get; set; }
|
||||||
|
|
||||||
|
// Navigation
|
||||||
|
[ForeignKey("CharacterId")]
|
||||||
|
public virtual DungeonCharacter? Character { get; set; }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user