Files
Fishing2Server/Hotfix/Game/Map/Handler/C2Map_CreateRoomRequestHandler.cs
2026-03-11 10:15:34 +08:00

50 lines
1.3 KiB
C#

using System;
using Fantasy;
using Fantasy.Async;
using Fantasy.Entitas;
using Fantasy.Network.Interface;
namespace NB.Game;
public class C2Map_CreateRoomRequestHandler : AddressRPC<Player, C2Game_CreateRoomRequest, Game2C_CreateRoomResponse>
{
protected override async FTask Run(Player entity, C2Game_CreateRoomRequest request,
Game2C_CreateRoomResponse response,
Action reply)
{
var mapUnit = entity.GetComponent<MapUnitComponent>();
if (mapUnit == null)
{
response.ErrorCode = ErrorCode.ErrServer;
return;
}
if (mapUnit.MapId != request.MapId)
{
response.ErrorCode = ErrorCode.MapCreateRoomNotEnter;
return;
}
var roomManageComponent = entity.Scene.GetComponent<RoomManageComponent>();
if (roomManageComponent == null)
{
response.ErrorCode = ErrorCode.ErrServer;
return;
}
var room = roomManageComponent.Create(entity.Id);
if (room == null)
{
response.ErrorCode = ErrorCode.MapCreateRoomMax;
return;
}
Log.Info(
$"创建房间=== sId={entity.Scene.SceneConfigId} map:{request.MapId} id={room.RoomId} code={room.Code}");
response.RoomCode = room.Code;
await FTask.CompletedTask;
}
}