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