进入和离开地图和房间协议合并
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
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;
|
||||
}
|
||||
|
||||
response.ErrorCode = await entity.EnterMap(request.MapId);
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,12 @@ using Fantasy.Network.Interface;
|
||||
|
||||
namespace NB.Map.Inner;
|
||||
|
||||
public class G2Map_EnterRoomRequestHandler : RouteRPC<Scene, G2Map_EnterRoomRequest, Map2G_EnterRoomResponse>
|
||||
/// <summary>
|
||||
/// 请求进入地图
|
||||
/// </summary>
|
||||
public class G2Map_EnterMapRequestHandler : RouteRPC<Scene, G2Map_EnterMapRequest, Map2G_EnterMapResponse>
|
||||
{
|
||||
protected override async FTask Run(Scene entity, G2Map_EnterRoomRequest request, Map2G_EnterRoomResponse response,
|
||||
protected override async FTask Run(Scene entity, G2Map_EnterMapRequest request, Map2G_EnterMapResponse response,
|
||||
Action reply)
|
||||
{
|
||||
var roomManageComponent = entity.GetComponent<RoomManageComponent>();
|
||||
@@ -31,32 +34,32 @@ public class G2Map_EnterRoomRequestHandler : RouteRPC<Scene, G2Map_EnterRoomRequ
|
||||
}
|
||||
|
||||
|
||||
//进入地图
|
||||
response.ErrorCode = await mapUnit.EnterMap(request.MapId);
|
||||
if (response.ErrorCode != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果没有房间代码,则只是进入地图,直接返回,不执行后续逻辑
|
||||
if (string.IsNullOrEmpty(request.RoomCode))
|
||||
{
|
||||
response.Units = [mapUnit.ToMapUnitInfo()];
|
||||
return;
|
||||
}
|
||||
|
||||
RoomHelper.ParseCode(request.RoomCode, out var serviceId, out var roomId);
|
||||
if (serviceId < 1 || roomId < 1)
|
||||
{
|
||||
response.ErrorCode = ErrorCode.MapRoomIdError;
|
||||
return;
|
||||
}
|
||||
|
||||
var room = roomManageComponent.Get(roomId);
|
||||
if (room == null)
|
||||
{
|
||||
response.ErrorCode = ErrorCode.MapRoomIdError;
|
||||
return;
|
||||
}
|
||||
|
||||
if (mapUnit.MapId != room.Map)
|
||||
{
|
||||
//切换地图
|
||||
response.ErrorCode = await mapUnit.EnterMap(mapUnit.MapId);
|
||||
if (response.ErrorCode != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
response.ErrorCode = await room.Enter(mapUnit);
|
||||
response.RoomCode = room.Code;
|
||||
if (response.ErrorCode == ErrorCode.Successful)
|
||||
@@ -64,6 +67,5 @@ public class G2Map_EnterRoomRequestHandler : RouteRPC<Scene, G2Map_EnterRoomRequ
|
||||
mapUnit.RoomId = room.Id;
|
||||
response.Units = room.ToMapUnitInfo();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user