角色控制和房间进入推送

This commit is contained in:
2025-09-07 23:51:17 +08:00
parent 61d20b5729
commit 7dad49bf5f
28 changed files with 432 additions and 221 deletions

View File

@@ -24,19 +24,14 @@ public class C2Map_CreateRoomRequestHandler : RouteRPC<MapUnit, C2Map_CreateRoom
return;
}
var roomId = roomManageComponent.AllocateId();
if (roomId < 1)
var room = roomManageComponent.Create(entity.Id);
if (room == null)
{
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}");

View File

@@ -0,0 +1,33 @@
using Fantasy;
using Fantasy.Async;
using Fantasy.Network.Interface;
namespace NB.Map;
public class C2Map_LookHandler : Route<MapUnit, C2Map_Look>
{
protected override async FTask Run(MapUnit entity, C2Map_Look message)
{
var roomManageComponent = entity.Scene.GetComponent<RoomManageComponent>();
var notifyMessage = new Map2C_LookeNotify()
{
Id = entity.Id,
Rotation = message.Rotation,
Timestamp = message.Timestamp
};
entity.Rotation.x = message.Rotation.x;
entity.Rotation.y = message.Rotation.y;
entity.Rotation.z = message.Rotation.z;
var room = roomManageComponent.Get(entity.MapId);
// foreach (var (_, unit) in mapUnitManageComponent.Units)
// {
// entity.Scene.NetworkMessagingComponent.SendInnerRoute(unit.GateRouteId, notifyMessage);
// }
await FTask.CompletedTask;
}
}

View File

@@ -0,0 +1,38 @@
using Fantasy;
using Fantasy.Async;
using Fantasy.Helper;
using Fantasy.Network.Interface;
namespace NB.Map;
public class C2Map_MoveHandler : Route<MapUnit, C2Map_Move>
{
protected override async FTask Run(MapUnit entity, C2Map_Move message)
{
var mapUnitManageComponent = entity.Scene.GetComponent<MapUnitManageComponent>();
var notifyMessage = new Map2C_MoveNotify()
{
Id = entity.Id,
Position = message.Position,
Rotation = message.Rotation,
IsStop = message.IsStop,
Direction = message.Direction,
Timestamp = TimeHelper.Now
};
entity.Position.x = message.Position.x;
entity.Position.y = message.Position.y;
entity.Position.z = message.Position.z;
entity.Rotation.x = message.Rotation.x;
entity.Rotation.y = message.Rotation.y;
entity.Rotation.z = message.Rotation.z;
foreach (var (_, unit) in mapUnitManageComponent.Units)
{
entity.Scene.NetworkMessagingComponent.SendInnerRoute(unit.GateRouteId, notifyMessage);
}
await FTask.CompletedTask;
}
}

View File

@@ -4,7 +4,7 @@ using Fantasy.Network.Interface;
namespace NB.Map.Inner;
public class G2Map_EnterRequestHandler : RouteRPC<Scene, G2Map_EnterRoomRequest, Map2G_EnterRoomResponse>
public class G2Map_EnterRoomRequestHandler : RouteRPC<Scene, G2Map_EnterRoomRequest, Map2G_EnterRoomResponse>
{
protected override async FTask Run(Scene entity, G2Map_EnterRoomRequest request, Map2G_EnterRoomResponse response,
Action reply)
@@ -54,9 +54,16 @@ public class G2Map_EnterRequestHandler : RouteRPC<Scene, G2Map_EnterRoomRequest,
return;
}
}
response.ErrorCode = await room.Enter(request.AccountId);
response.ErrorCode = await room.Enter(mapUnit);
response.RoomCode = room.Code;
if (response.ErrorCode == ErrorCode.Successful)
{
mapUnit.RoomId = room.Id;
response.Units = room.ToMapUnitInfo();
}
}
}

View File

@@ -0,0 +1,13 @@
using Fantasy;
using Fantasy.Async;
using Fantasy.Network.Interface;
namespace NB.Map.Inner;
public class G2Map_ExitRoomRequestHandler : RouteRPC<Scene, G2Map_ExitRoomRequest, Map2G_ExiRoomResponse>
{
protected override async FTask Run(Scene entity, G2Map_ExitRoomRequest request, Map2G_ExiRoomResponse response,
Action reply)
{
}
}