84 lines
2.3 KiB
C#
84 lines
2.3 KiB
C#
using System;
|
|
using Fantasy;
|
|
using Fantasy.Async;
|
|
using Fantasy.Network.Interface;
|
|
using NB.Game;
|
|
|
|
namespace NB.Game.Inner;
|
|
|
|
/// <summary>
|
|
/// 请求进入地图
|
|
/// </summary>
|
|
public class G2Map_EnterMapRequestHandler : AddressRPC<Scene, G2Map_EnterMapRequest, Map2G_EnterMapResponse>
|
|
{
|
|
protected override async FTask Run(Scene entity, G2Map_EnterMapRequest request, Map2G_EnterMapResponse response,
|
|
Action reply)
|
|
{
|
|
var roomManageComponent = entity.GetComponent<RoomManageComponent>();
|
|
if (roomManageComponent == null)
|
|
{
|
|
response.ErrorCode = ErrorCode.ErrServer;
|
|
return;
|
|
}
|
|
|
|
var mapUnitManage = entity.GetComponent<PlayerManageComponent>();
|
|
if (mapUnitManage == null)
|
|
{
|
|
response.ErrorCode = ErrorCode.ErrServer;
|
|
return;
|
|
}
|
|
|
|
var player = mapUnitManage.Get(request.AccountId);
|
|
if (player == null)
|
|
{
|
|
response.ErrorCode = ErrorCode.ErrServer;
|
|
return;
|
|
}
|
|
|
|
var mapUnit = player.GetComponent<MapUnitComponent>();
|
|
if (mapUnit == null)
|
|
{
|
|
response.ErrorCode = ErrorCode.ErrServer;
|
|
return;
|
|
}
|
|
|
|
//进入地图
|
|
var mapManageComponent = entity.GetComponent<MapManageComponent>();
|
|
var map = mapManageComponent.Get(request.MapId);
|
|
if (map == null)
|
|
{
|
|
response.ErrorCode = ErrorCode.MapIdError;
|
|
return;
|
|
}
|
|
|
|
mapUnit.MapId = request.MapId;
|
|
|
|
|
|
// 如果没有房间代码,则只是进入地图,直接返回,不执行后续逻辑
|
|
if (string.IsNullOrEmpty(request.RoomCode))
|
|
{
|
|
response.Units = [player.ToMapUnitInfo()];
|
|
return;
|
|
}
|
|
|
|
RoomHelper.ParseCode(request.RoomCode, out var serviceId, out var roomId);
|
|
if (serviceId < 1 || roomId < 1)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var room = roomManageComponent.Get(roomId);
|
|
if (room == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
response.ErrorCode = await room.Enter(player);
|
|
response.RoomCode = room.Code;
|
|
if (response.ErrorCode == ErrorCode.Successful)
|
|
{
|
|
mapUnit.RoomId = room.RoomId;
|
|
response.Units = room.ToMapUnitInfo();
|
|
}
|
|
}
|
|
} |