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

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;
}
}

View File

@@ -0,0 +1,33 @@
using Fantasy;
using Fantasy.Async;
using Fantasy.Network.Interface;
namespace NB.Map;
public class C2Map_EnterMapRequestHandler : RouteRPC<MapUnit, C2Map_EnterMapRequest, Map2C_EnterMapResponse>
{
protected override async FTask Run(MapUnit entity, C2Map_EnterMapRequest request, Map2C_EnterMapResponse response,
Action reply)
{
var roomManageComponent = entity.Scene.GetComponent<RoomManageComponent>();
if (roomManageComponent == null)
{
response.ErrorCode = ErrorCode.ErrServer;
return;
}
// if (entity.RoomId > 0)
// {
// response.ErrorCode = ErrorCode.MapRoomHave;
// return;
// }
//
// roomManageComponent.Enter(entity, request.RoomId);
Log.Info($"进入地图=== map:{request.MapId}");
entity.MapId = request.MapId;
response.MapId = request.MapId;
await FTask.CompletedTask;
}
}

View File

@@ -0,0 +1,27 @@
using Fantasy;
using Fantasy.Async;
using Fantasy.Network.Interface;
namespace NB.Map.Inner;
public class G2Map_EnterRequestHandler : RouteRPC<Scene, G2Map_EnterRoomRequest, Map2G_EnterRoomResponse>
{
protected override async FTask Run(Scene entity, G2Map_EnterRoomRequest request, Map2G_EnterRoomResponse response,
Action reply)
{
var roomManageComponent = entity.GetComponent<RoomManageComponent>();
if (roomManageComponent == null)
{
response.ErrorCode = ErrorCode.ErrServer;
return;
}
RoomHelper.ParseCode(request.RoomCode, out var serviceId, out var roomId);
if (serviceId < 1 || roomId < 1)
{
response.ErrorCode = ErrorCode.MapRoomIdError;
return;
}
// roomManageComponent.Enter();
}
}