房间创建和进入相关逻辑和协议

This commit is contained in:
2025-08-27 00:04:40 +08:00
parent 7325e268ce
commit f6d85a1e0a
45 changed files with 1246 additions and 729 deletions

View File

@@ -1,15 +1,44 @@
// using Fantasy;
// using Fantasy.Async;
// using Fantasy.Network.Interface;
//
// namespace NB.Map;
//
// public class C2Map_CreateRoomRequestHandler : RouteRPC<Scene, C2Map_CreateRoomRequest, Map2C_CreateRoomResponse>
// {
// protected override async FTask Run(Scene entity, C2Map_CreateRoomRequest request, Map2C_CreateRoomResponse response,
// Action reply)
// {
// Log.Info($"创建房间=== map:{request.MapId} pass:{request.Password}");
// await FTask.CompletedTask;
// }
// }
using Fantasy;
using Fantasy.Async;
using Fantasy.Entitas;
using Fantasy.Network.Interface;
namespace NB.Map;
public class C2Map_CreateRoomRequestHandler : RouteRPC<MapUnit, C2Map_CreateRoomRequest, Map2C_CreateRoomResponse>
{
protected override async FTask Run(MapUnit entity, C2Map_CreateRoomRequest request,
Map2C_CreateRoomResponse response,
Action reply)
{
if (entity.MapId != request.MapId)
{
response.ErrorCode = ErrorCode.MapCreateRoomNotEnter;
return;
}
var roomManageComponent = entity.Scene.GetComponent<RoomManageComponent>();
if (roomManageComponent == null)
{
response.ErrorCode = ErrorCode.ErrServer;
return;
}
var roomId = roomManageComponent.AllocateId();
if (roomId < 1)
{
response.ErrorCode = ErrorCode.MapCreateRoomMax;
return;
}
// roomManageComponent.on
var room = Entity.Create<MapRoom>(entity.Scene, true, true);
room.Owner = entity.Id;
room.RoomId = roomId;
room.Code = RoomHelper.GenerateCode(entity.Scene.SceneConfigId, roomId);
roomManageComponent.Add(room);
Log.Info(
$"创建房间=== sId={entity.Scene.SceneConfigId} map:{request.MapId} id={room.RoomId} code={room.Code}");
await FTask.CompletedTask;
}
}