新增逻辑
This commit is contained in:
@@ -3,7 +3,6 @@ using Fantasy.Async;
|
||||
using Fantasy.Network.Interface;
|
||||
using NB.Chat;
|
||||
using NB.Game;
|
||||
using NB.Map;
|
||||
|
||||
namespace NB.Common;
|
||||
|
||||
@@ -27,11 +26,11 @@ public class G2Common_EnterRequestHandler : RouteRPC<Scene, G2Common_EnterReques
|
||||
await RunSocial(scene, request, response);
|
||||
break;
|
||||
}
|
||||
case SceneType.Map:
|
||||
{
|
||||
await RunMap(scene, request, response);
|
||||
break;
|
||||
}
|
||||
// case SceneType.Map:
|
||||
// {
|
||||
// await RunMap(scene, request, response);
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
|
||||
await FTask.CompletedTask;
|
||||
@@ -68,19 +67,19 @@ public class G2Common_EnterRequestHandler : RouteRPC<Scene, G2Common_EnterReques
|
||||
Log.Info($"登录到社交服成功,id={response.UnitRouteId}");
|
||||
}
|
||||
|
||||
private async FTask RunMap(Scene scene, G2Common_EnterRequest request, G2Common_EnterResponse response)
|
||||
{
|
||||
// 在缓存中检查该账号是否存在
|
||||
var chatUnitManageComponent = scene.GetComponent<MapUnitManageComponent>();
|
||||
var account = await chatUnitManageComponent.Online(scene, request.AccountId, request.GateRouteId);
|
||||
|
||||
if (account == null)
|
||||
{
|
||||
response.ErrorCode = ErrorCode.ErrServer;
|
||||
return;
|
||||
}
|
||||
|
||||
response.UnitRouteId = account.RuntimeId;
|
||||
Log.Info($"登录到地图服成功,id={response.UnitRouteId}");
|
||||
}
|
||||
// private async FTask RunMap(Scene scene, G2Common_EnterRequest request, G2Common_EnterResponse response)
|
||||
// {
|
||||
// // 在缓存中检查该账号是否存在
|
||||
// var chatUnitManageComponent = scene.GetComponent<MapUnitManageComponent>();
|
||||
// var account = await chatUnitManageComponent.Online(scene, request.AccountId, request.GateRouteId);
|
||||
//
|
||||
// if (account == null)
|
||||
// {
|
||||
// response.ErrorCode = ErrorCode.ErrServer;
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// response.UnitRouteId = account.RuntimeId;
|
||||
// Log.Info($"登录到地图服成功,id={response.UnitRouteId}");
|
||||
// }
|
||||
}
|
||||
@@ -3,7 +3,6 @@ using Fantasy.Async;
|
||||
using Fantasy.Network.Interface;
|
||||
using NB.Chat;
|
||||
using NB.Game;
|
||||
using NB.Map;
|
||||
|
||||
namespace NB.Common;
|
||||
|
||||
@@ -25,11 +24,11 @@ public class G2Common_ExitRequestHandler : RouteRPC<Scene, G2Common_ExitRequest,
|
||||
await RunSocial(scene, request, response);
|
||||
break;
|
||||
}
|
||||
case SceneType.Map:
|
||||
{
|
||||
await RunMap(scene, request, response);
|
||||
break;
|
||||
}
|
||||
// case SceneType.Map:
|
||||
// {
|
||||
// await RunMap(scene, request, response);
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
|
||||
await FTask.CompletedTask;
|
||||
@@ -51,9 +50,9 @@ public class G2Common_ExitRequestHandler : RouteRPC<Scene, G2Common_ExitRequest,
|
||||
Log.Info("退出聊天服成功==");
|
||||
}
|
||||
|
||||
private async FTask RunMap(Scene scene, G2Common_ExitRequest request, Common2G_ExitResponse response)
|
||||
{
|
||||
await MapHelper.Offline(scene, request.AccountId, request.GateRouteId);
|
||||
Log.Info("退出房间服成功==");
|
||||
}
|
||||
// private async FTask RunMap(Scene scene, G2Common_ExitRequest request, Common2G_ExitResponse response)
|
||||
// {
|
||||
// await MapHelper.Offline(scene, request.AccountId, request.GateRouteId);
|
||||
// Log.Info("退出房间服成功==");
|
||||
// }
|
||||
}
|
||||
@@ -16,10 +16,6 @@ public static class SceneConfigHelper
|
||||
{
|
||||
sceneType = SceneType.Social;
|
||||
}
|
||||
else if (routeType == RouteType.MapRoute)
|
||||
{
|
||||
sceneType = SceneType.Map;
|
||||
}
|
||||
else if (routeType == RouteType.GateRoute)
|
||||
{
|
||||
sceneType = SceneType.Gate;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Entitas;
|
||||
using Fantasy.Network.Interface;
|
||||
using NB.Map;
|
||||
|
||||
namespace NB.Game;
|
||||
|
||||
@@ -11,7 +10,7 @@ public class C2Game_GetRoleInfoRequestHandler : RouteRPC<Player, C2Game_GetRoleI
|
||||
protected override async FTask Run(Player entity, C2Game_GetRoleInfoRequest request,
|
||||
Game2C_GetRoleInfoResponse response, Action reply)
|
||||
{
|
||||
response.RoomCode = "13AHVL";
|
||||
response.RoomCode = "136A69";
|
||||
response.RoleInfo = entity.GetRoleInfo();
|
||||
|
||||
await FTask.CompletedTask;
|
||||
|
||||
@@ -22,6 +22,12 @@ public class C2Game_RigChangeRequestHandler : RouteRPC<Player, C2Game_RigChangeR
|
||||
return;
|
||||
}
|
||||
|
||||
if (item.InUse)
|
||||
{
|
||||
response.ErrorCode = ErrorCode.ErrArgs; //已使用的
|
||||
return;
|
||||
}
|
||||
|
||||
if (request.IsAdd)
|
||||
{
|
||||
//安装配件需要检查配件是否已被使用
|
||||
|
||||
31
Hotfix/Game/Handler/C2Game_UseItemRequestHandler.cs
Normal file
31
Hotfix/Game/Handler/C2Game_UseItemRequestHandler.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using Fantasy;
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Network.Interface;
|
||||
|
||||
namespace NB.Game;
|
||||
|
||||
public class C2Game_UseItemRequestHandler : RouteRPC<Player, C2Game_UseItemRequest, Game2C_UseItemResponse>
|
||||
{
|
||||
protected override async FTask Run(Player entity, C2Game_UseItemRequest request, Game2C_UseItemResponse response,
|
||||
Action reply)
|
||||
{
|
||||
var itemContainer = entity.GetComponent<PlayerItemContainerComponent>();
|
||||
if (itemContainer == null)
|
||||
{
|
||||
response.ErrorCode = ErrorCode.ErrArgs;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!itemContainer.Items.TryGetValue(request.ItemId, out var item))
|
||||
{
|
||||
response.ErrorCode = ErrorCode.ErrArgs;
|
||||
return;
|
||||
}
|
||||
|
||||
var itemType = ItemHelper.GetType(item.ConfigId);
|
||||
if (itemType == ItemBasicType.Rod)
|
||||
{
|
||||
//鱼竿
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using Fantasy;
|
||||
using Fantasy.Entitas;
|
||||
using NB.Map;
|
||||
|
||||
namespace NB.Game;
|
||||
|
||||
|
||||
@@ -4,17 +4,22 @@ public static class ItemHelper
|
||||
{
|
||||
public static ItemBasicType GetType(uint id)
|
||||
{
|
||||
var type = (int)(id / 10000);
|
||||
if (type == 1)
|
||||
{
|
||||
return ItemBasicType.Currency;
|
||||
}
|
||||
|
||||
if (type == 21)
|
||||
{
|
||||
return ItemBasicType.Fish;
|
||||
}
|
||||
|
||||
return ItemBasicType.Item;
|
||||
return (ItemBasicType)(id / 10000);
|
||||
}
|
||||
|
||||
// public static ItemBasicType GetType(uint id)
|
||||
// {
|
||||
// var type = (int)(id / 10000);
|
||||
// if (type == 1)
|
||||
// {
|
||||
// return ItemBasicType.Currency;
|
||||
// }
|
||||
//
|
||||
// if (type == 21)
|
||||
// {
|
||||
// return ItemBasicType.Fish;
|
||||
// }
|
||||
//
|
||||
// return ItemBasicType.Item;
|
||||
// }
|
||||
}
|
||||
@@ -18,6 +18,9 @@ public class ItemDestroySystem : DestroySystem<Item>
|
||||
|
||||
public static class ItemSystem
|
||||
{
|
||||
|
||||
|
||||
|
||||
public static ItemInfo ToItemInfo(this Item self)
|
||||
{
|
||||
return new ItemInfo()
|
||||
|
||||
@@ -3,15 +3,22 @@ using Fantasy.Async;
|
||||
using Fantasy.Entitas;
|
||||
using Fantasy.Network.Interface;
|
||||
|
||||
namespace NB.Map;
|
||||
namespace NB.Game;
|
||||
|
||||
public class C2Map_CreateRoomRequestHandler : RouteRPC<MapUnit, C2Map_CreateRoomRequest, Map2C_CreateRoomResponse>
|
||||
public class C2Map_CreateRoomRequestHandler : RouteRPC<Player, C2Map_CreateRoomRequest, Map2C_CreateRoomResponse>
|
||||
{
|
||||
protected override async FTask Run(MapUnit entity, C2Map_CreateRoomRequest request,
|
||||
protected override async FTask Run(Player entity, C2Map_CreateRoomRequest request,
|
||||
Map2C_CreateRoomResponse response,
|
||||
Action reply)
|
||||
{
|
||||
if (entity.MapId != request.MapId)
|
||||
var mapUnit = entity.GetComponent<MapUnitComponent>();
|
||||
if (mapUnit == null)
|
||||
{
|
||||
response.ErrorCode = ErrorCode.ErrServer;
|
||||
return;
|
||||
}
|
||||
|
||||
if (mapUnit.MapId != request.MapId)
|
||||
{
|
||||
response.ErrorCode = ErrorCode.MapCreateRoomNotEnter;
|
||||
return;
|
||||
@@ -31,12 +38,12 @@ public class C2Map_CreateRoomRequestHandler : RouteRPC<MapUnit, C2Map_CreateRoom
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -2,14 +2,21 @@
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Network.Interface;
|
||||
|
||||
namespace NB.Map;
|
||||
namespace NB.Game;
|
||||
|
||||
public class C2Map_LookHandler : Route<MapUnit, C2Map_Look>
|
||||
public class C2Map_LookHandler : Route<Player, C2Map_Look>
|
||||
{
|
||||
protected override async FTask Run(MapUnit entity, C2Map_Look message)
|
||||
protected override async FTask Run(Player entity, C2Map_Look message)
|
||||
{
|
||||
var mapUnit = entity.GetComponent<MapUnitComponent>();
|
||||
if (mapUnit == null)
|
||||
{
|
||||
// response.ErrorCode = ErrorCode.ErrServer;
|
||||
return;
|
||||
}
|
||||
|
||||
var roomId = mapUnit.RoomId;
|
||||
var roomManageComponent = entity.Scene.GetComponent<RoomManageComponent>();
|
||||
var roomId = entity.RoomId;
|
||||
var room = roomManageComponent.Get(roomId);
|
||||
if (room == null)
|
||||
{
|
||||
@@ -23,14 +30,14 @@ public class C2Map_LookHandler : Route<MapUnit, C2Map_Look>
|
||||
Timestamp = message.Timestamp
|
||||
};
|
||||
|
||||
entity.Rotation.x = message.Rotation.x;
|
||||
entity.Rotation.y = message.Rotation.y;
|
||||
entity.Rotation.z = message.Rotation.z;
|
||||
// entity.Rotation.x = message.Rotation.x;
|
||||
// entity.Rotation.y = message.Rotation.y;
|
||||
// entity.Rotation.z = message.Rotation.z;
|
||||
|
||||
foreach (var (_, unit) in room.Units)
|
||||
{
|
||||
// if (unit.Id == entity.Id) continue;
|
||||
entity.Scene.NetworkMessagingComponent.SendInnerRoute(unit.GateRouteId, notifyMessage);
|
||||
entity.Scene.NetworkMessagingComponent.SendInnerRoute(unit.SessionRunTimeId, notifyMessage);
|
||||
}
|
||||
|
||||
await FTask.CompletedTask;
|
||||
@@ -3,14 +3,21 @@ using Fantasy.Async;
|
||||
using Fantasy.Helper;
|
||||
using Fantasy.Network.Interface;
|
||||
|
||||
namespace NB.Map;
|
||||
namespace NB.Game;
|
||||
|
||||
public class C2Map_MoveHandler : Route<MapUnit, C2Map_Move>
|
||||
public class C2Map_MoveHandler : Route<Player, C2Map_Move>
|
||||
{
|
||||
protected override async FTask Run(MapUnit entity, C2Map_Move message)
|
||||
protected override async FTask Run(Player entity, C2Map_Move message)
|
||||
{
|
||||
var mapUnit = entity.GetComponent<MapUnitComponent>();
|
||||
if (mapUnit == null)
|
||||
{
|
||||
// response.ErrorCode = ErrorCode.ErrServer;
|
||||
return;
|
||||
}
|
||||
|
||||
var roomManageComponent = entity.Scene.GetComponent<RoomManageComponent>();
|
||||
var roomId = entity.RoomId;
|
||||
var roomId = mapUnit.RoomId;
|
||||
var room = roomManageComponent.Get(roomId);
|
||||
if (room == null)
|
||||
{
|
||||
@@ -27,18 +34,18 @@ public class C2Map_MoveHandler : Route<MapUnit, C2Map_Move>
|
||||
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;
|
||||
// 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 room.Units)
|
||||
{
|
||||
// if (unit.Id == entity.Id) continue;
|
||||
entity.Scene.NetworkMessagingComponent.SendInnerRoute(unit.GateRouteId, notifyMessage);
|
||||
entity.Scene.NetworkMessagingComponent.SendInnerRoute(unit.SessionRunTimeId, notifyMessage);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,14 +2,21 @@
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Network.Interface;
|
||||
|
||||
namespace NB.Map;
|
||||
namespace NB.Game;
|
||||
|
||||
public class C2Map_RolePropertyChangeHandler : Route<MapUnit, C2Map_RolePropertyChange>
|
||||
public class C2Map_RolePropertyChangeHandler : Route<Player, C2Map_RolePropertyChange>
|
||||
{
|
||||
protected override async FTask Run(MapUnit entity, C2Map_RolePropertyChange message)
|
||||
protected override async FTask Run(Player entity, C2Map_RolePropertyChange message)
|
||||
{
|
||||
var mapUnit = entity.GetComponent<MapUnitComponent>();
|
||||
if (mapUnit == null)
|
||||
{
|
||||
// response.ErrorCode = ErrorCode.ErrServer;
|
||||
return;
|
||||
}
|
||||
|
||||
var roomManageComponent = entity.Scene.GetComponent<RoomManageComponent>();
|
||||
var roomId = entity.RoomId;
|
||||
var roomId = mapUnit.RoomId;
|
||||
var room = roomManageComponent.Get(roomId);
|
||||
if (room == null)
|
||||
{
|
||||
@@ -26,7 +33,7 @@ public class C2Map_RolePropertyChangeHandler : Route<MapUnit, C2Map_RoleProperty
|
||||
foreach (var (_, unit) in room.Units)
|
||||
{
|
||||
if (unit.Id == entity.Id) continue;
|
||||
entity.Scene.NetworkMessagingComponent.SendInnerRoute(unit.GateRouteId, notifyMessage);
|
||||
entity.Scene.NetworkMessagingComponent.SendInnerRoute(unit.SessionRunTimeId, notifyMessage);
|
||||
}
|
||||
|
||||
await FTask.CompletedTask;
|
||||
60
Hotfix/Game/Map/Handler/C2Map_TakeItemRequestHandler.cs
Normal file
60
Hotfix/Game/Map/Handler/C2Map_TakeItemRequestHandler.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using Fantasy;
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Network.Interface;
|
||||
|
||||
namespace NB.Game;
|
||||
|
||||
public class C2Map_TakeItemRequestHandler : RouteRPC<Player, C2Map_TakeItemRequest, Map2C_TakeItemResponse>
|
||||
{
|
||||
protected override async FTask Run(Player entity, C2Map_TakeItemRequest request, Map2C_TakeItemResponse response,
|
||||
Action reply)
|
||||
{
|
||||
var itemContainer = entity.GetComponent<PlayerItemContainerComponent>();
|
||||
if (itemContainer == null)
|
||||
{
|
||||
response.ErrorCode = ErrorCode.ErrArgs;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!itemContainer.Items.TryGetValue(request.Id, out var item))
|
||||
{
|
||||
response.ErrorCode = ErrorCode.ErrArgs;
|
||||
return;
|
||||
}
|
||||
|
||||
var mapUnit = entity.GetComponent<MapUnitComponent>();
|
||||
if (mapUnit == null)
|
||||
{
|
||||
response.ErrorCode = ErrorCode.ErrArgs;
|
||||
return;
|
||||
}
|
||||
|
||||
var itemType = ItemHelper.GetType(item.ConfigId);
|
||||
if (itemType == ItemBasicType.Rod)
|
||||
{
|
||||
itemContainer.Binding.TryGetValue(item.Id, out var itemRod);
|
||||
//鱼竿
|
||||
var itemGear = mapUnit.GetOrAddItemGear(item);
|
||||
if (itemRod != null)
|
||||
{
|
||||
itemGear.Rings.AddRange(itemRod);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var roomManageComponent = entity.Scene.GetComponent<RoomManageComponent>();
|
||||
var roomId = mapUnit.RoomId;
|
||||
var room = roomManageComponent.Get(roomId);
|
||||
if (room != null)
|
||||
{
|
||||
var notifyMessage = new Map2C_RoleGearChangeNotify();
|
||||
// notifyMessage
|
||||
// return;
|
||||
foreach (var (_, unit) in room.Units)
|
||||
{
|
||||
// if (unit.Id == entity.Id) continue;
|
||||
entity.Scene.NetworkMessagingComponent.SendInnerRoute(unit.SessionRunTimeId, notifyMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
using Fantasy;
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Network.Interface;
|
||||
using NB.Game;
|
||||
|
||||
namespace NB.Map.Inner;
|
||||
namespace NB.Game.Inner;
|
||||
|
||||
/// <summary>
|
||||
/// 请求进入地图
|
||||
@@ -19,32 +20,43 @@ public class G2Map_EnterMapRequestHandler : RouteRPC<Scene, G2Map_EnterMapReques
|
||||
return;
|
||||
}
|
||||
|
||||
var mapUnitManage = entity.GetComponent<MapUnitManageComponent>();
|
||||
var mapUnitManage = entity.GetComponent<PlayerManageComponent>();
|
||||
if (mapUnitManage == null)
|
||||
{
|
||||
response.ErrorCode = ErrorCode.ErrServer;
|
||||
return;
|
||||
}
|
||||
|
||||
var mapUnit = mapUnitManage.Get(request.AccountId);
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
//进入地图
|
||||
response.ErrorCode = await mapUnit.EnterMap(request.MapId);
|
||||
if (response.ErrorCode != 0)
|
||||
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 = [mapUnit.ToMapUnitInfo()];
|
||||
response.Units = [player.ToMapUnitInfo()];
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -60,7 +72,7 @@ public class G2Map_EnterMapRequestHandler : RouteRPC<Scene, G2Map_EnterMapReques
|
||||
return;
|
||||
}
|
||||
|
||||
response.ErrorCode = await room.Enter(mapUnit);
|
||||
response.ErrorCode = await room.Enter(player);
|
||||
response.RoomCode = room.Code;
|
||||
if (response.ErrorCode == ErrorCode.Successful)
|
||||
{
|
||||
@@ -0,0 +1,51 @@
|
||||
using Fantasy;
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Network.Interface;
|
||||
|
||||
namespace NB.Game.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)
|
||||
{
|
||||
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 room = roomManageComponent.Get(mapUnit.RoomId);
|
||||
if (room == null)
|
||||
{
|
||||
response.ErrorCode = ErrorCode.ErrServer;
|
||||
return;
|
||||
}
|
||||
|
||||
player.RemoveComponent<MapUnitComponent>();
|
||||
response.ErrorCode = await room.Enter(player);
|
||||
// room.Units.Remove(mapUnit.Id);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using Fantasy;
|
||||
using Fantasy.Entitas;
|
||||
|
||||
namespace NB.Map;
|
||||
namespace NB.Game;
|
||||
|
||||
public class MapFactory
|
||||
{
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Text;
|
||||
|
||||
namespace NB.Map;
|
||||
namespace NB.Game;
|
||||
|
||||
public static class RoomHelper
|
||||
{
|
||||
@@ -65,5 +65,4 @@ public static class RoomHelper
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using Fantasy.Entitas;
|
||||
using Fantasy.Entitas.Interface;
|
||||
|
||||
namespace NB.Map;
|
||||
namespace NB.Game;
|
||||
|
||||
public class MapManageComponentDestroySystem : DestroySystem<MapManageComponent>
|
||||
{
|
||||
@@ -2,7 +2,7 @@
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Entitas.Interface;
|
||||
|
||||
namespace NB.Map;
|
||||
namespace NB.Game;
|
||||
|
||||
public class MapRoomDestroySystem : DestroySystem<MapRoom>
|
||||
{
|
||||
@@ -18,21 +18,21 @@ public class MapRoomDestroySystem : DestroySystem<MapRoom>
|
||||
|
||||
public static class MapRoomSystem
|
||||
{
|
||||
public static async FTask<uint> Enter(this MapRoom self, MapUnit unit)
|
||||
public static async FTask<uint> Enter(this MapRoom self, Player unit)
|
||||
{
|
||||
self.Units.TryAdd(unit.Id, unit);
|
||||
|
||||
var notifyMessage = new Map2C_RoleEnterRoomNotify()
|
||||
{
|
||||
Info = unit.ToMapUnitInfo(),
|
||||
};
|
||||
|
||||
foreach (var (_, roomUnit) in self.Units)
|
||||
{
|
||||
// if (roomUnit.Id == unit.Id) continue;
|
||||
// 同步其他客户端
|
||||
self.Scene.NetworkMessagingComponent.SendInnerRoute(roomUnit.GateRouteId, notifyMessage);
|
||||
}
|
||||
// var notifyMessage = new Map2C_RoleEnterRoomNotify()
|
||||
// {
|
||||
// Info = unit.ToMapUnitInfo(),
|
||||
// };
|
||||
//
|
||||
// foreach (var (_, roomUnit) in self.Units)
|
||||
// {
|
||||
// // if (roomUnit.Id == unit.Id) continue;
|
||||
// // 同步其他客户端
|
||||
// self.Scene.NetworkMessagingComponent.SendInnerRoute(roomUnit.GateRouteId, notifyMessage);
|
||||
// }
|
||||
|
||||
await FTask.CompletedTask;
|
||||
return ErrorCode.Successful;
|
||||
@@ -1,6 +1,6 @@
|
||||
using Fantasy.Entitas.Interface;
|
||||
|
||||
namespace NB.Map;
|
||||
namespace NB.Game;
|
||||
|
||||
public class MapDestroySystem : DestroySystem<Map>
|
||||
{
|
||||
31
Hotfix/Game/Map/System/MapUnitSystem.cs
Normal file
31
Hotfix/Game/Map/System/MapUnitSystem.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using Fantasy;
|
||||
using Fantasy.Async;
|
||||
|
||||
namespace NB.Game;
|
||||
|
||||
public static class MapUnitComponentSystem
|
||||
{
|
||||
public static MapUnitGear GetOrAddItemGear(this MapUnitComponent self, Item item)
|
||||
{
|
||||
var mapItem = self.Gears.Find(t => t.Item == item.Id);
|
||||
if (mapItem == null)
|
||||
{
|
||||
mapItem = new MapUnitGear();
|
||||
mapItem.Item = item.Id;
|
||||
self.Gears.Add(mapItem);
|
||||
}
|
||||
|
||||
return mapItem;
|
||||
}
|
||||
|
||||
public static List<GearInfo> ToMapUnitInfo(this MapUnitComponent self)
|
||||
{
|
||||
List<GearInfo> ret = new List<GearInfo>();
|
||||
// foreach (var (_, unit) in self.Units)
|
||||
// {
|
||||
// // ret.Add(unit.ToMapUnitInfo());
|
||||
// }
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
using Fantasy.Entitas;
|
||||
using Fantasy.Entitas.Interface;
|
||||
|
||||
namespace NB.Map;
|
||||
namespace NB.Game;
|
||||
|
||||
public class RoomManageComponentAwakeSystem : AwakeSystem<RoomManageComponent>
|
||||
{
|
||||
@@ -62,6 +62,7 @@ public static class PlayerManageComponentSystem
|
||||
await account.TryComponent<PlayerItemContainerComponent>();
|
||||
await account.TryComponent<PlayerWalletComponent>();
|
||||
await account.TryComponent<FishContainer>();
|
||||
account.GetOrAddComponent<MapUnitComponent>();
|
||||
|
||||
if (needInit)
|
||||
{
|
||||
|
||||
@@ -63,45 +63,26 @@ public static class PlayerSystem
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 测试数据
|
||||
|
||||
public static void SetTestData(this Player player)
|
||||
|
||||
public static MapUnitInfo ToMapUnitInfo(this Player self)
|
||||
{
|
||||
var ret = new MapUnitInfo()
|
||||
{
|
||||
Id = self.Id,
|
||||
Position = Vector3Info.Create(self.Scene),
|
||||
Rotation = Vector3Info.Create(self.Scene),
|
||||
};
|
||||
|
||||
// Dictionary<int, List<int>> rigDic = new Dictionary<int, List<int>>()
|
||||
// {
|
||||
// { 30001, [50001, 60001, 70002, 90001, 100001] },
|
||||
// { 30002, [40001, 50001, 60001, 70002, 00001, 100001] },
|
||||
// { 30003, [40001, 60001, 80001] }
|
||||
// };
|
||||
//
|
||||
// var itemContainer = player.GetComponent<PlayerItemContainerComponent>();
|
||||
//
|
||||
// //添加测试数据
|
||||
// if (itemContainer != null && itemContainer.FishingRig.Count < 1)
|
||||
// {
|
||||
// foreach (var (rod, list) in rigDic)
|
||||
// {
|
||||
// if (itemContainer.GetFistItemByConfigId(rod, out var item) && item != null)
|
||||
// {
|
||||
// var childs = new List<long>();
|
||||
// foreach (var i in list)
|
||||
// {
|
||||
// if (itemContainer.GetFistItemByConfigId(i, out var itemChild) && itemChild != null)
|
||||
// {
|
||||
// childs.Add(itemChild.Id);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// itemContainer.FishingRig[item.Id] = childs;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// itemContainer.Save();
|
||||
// }
|
||||
var mapUnit = self.GetComponent<MapUnitComponent>();
|
||||
|
||||
ret.Position.x = mapUnit.Position.x;
|
||||
ret.Position.y = mapUnit.Position.y;
|
||||
ret.Position.z = mapUnit.Position.z;
|
||||
|
||||
ret.Rotation.x = mapUnit.Rotation.x;
|
||||
ret.Rotation.y = mapUnit.Rotation.y;
|
||||
ret.Rotation.z = mapUnit.Rotation.z;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -3,7 +3,7 @@ using Fantasy.Async;
|
||||
using Fantasy.Network;
|
||||
using Fantasy.Network.Interface;
|
||||
using Fantasy.Platform.Net;
|
||||
using NB.Map;
|
||||
using NB.Game;
|
||||
|
||||
namespace NB.Gate;
|
||||
|
||||
@@ -55,7 +55,7 @@ public class C2G_EnterMapRequestHandler : MessageRPC<C2G_EnterMapRequest, G2C_En
|
||||
|
||||
if (serviceId == 0)
|
||||
{
|
||||
var mapScenes = SceneConfigData.Instance.GetSceneBySceneType(SceneType.Map);
|
||||
var mapScenes = SceneConfigData.Instance.GetSceneBySceneType(SceneType.Game);
|
||||
serviceId = mapScenes.First().Id;
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class C2G_EnterMapRequestHandler : MessageRPC<C2G_EnterMapRequest, G2C_En
|
||||
if (oldServerRouteId != sceneConfig.RouteId)
|
||||
{
|
||||
//先退出旧的服务
|
||||
var ret = await gateUnit.Offline(session.RuntimeId, RouteType.MapRoute);
|
||||
var ret = await gateUnit.Offline(session.RuntimeId, RouteType.GameRoute);
|
||||
if (ret != 0)
|
||||
{
|
||||
response.ErrorCode = ErrorCode.MapRoomIdError;
|
||||
@@ -79,7 +79,7 @@ public class C2G_EnterMapRequestHandler : MessageRPC<C2G_EnterMapRequest, G2C_En
|
||||
}
|
||||
|
||||
//再进入新的服务
|
||||
ret = await gateUnit.Online(RouteType.MapRoute, sceneConfig);
|
||||
ret = await gateUnit.Online(RouteType.GameRoute, sceneConfig);
|
||||
if (ret != 0)
|
||||
{
|
||||
response.ErrorCode = ErrorCode.MapRoomIdError;
|
||||
|
||||
@@ -3,7 +3,7 @@ using Fantasy.Async;
|
||||
using Fantasy.Network;
|
||||
using Fantasy.Network.Interface;
|
||||
using Fantasy.Platform.Net;
|
||||
using NB.Map;
|
||||
using NB.Game;
|
||||
|
||||
namespace NB.Gate;
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ public static class GateLoginHelper
|
||||
gateUnitSessionComponent.AccountID = gateUnit.AccountID;
|
||||
gateUnitSessionComponent.SessionId = session.RuntimeId;
|
||||
|
||||
return await gateUnit.Online(RouteType.GameRoute, RouteType.SocialRoute, RouteType.MapRoute);
|
||||
return await gateUnit.Online(RouteType.GameRoute, RouteType.SocialRoute);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -61,7 +61,7 @@ public static class GateLoginHelper
|
||||
{
|
||||
//通知服务器下线
|
||||
Log.Info($"断线的session id={sessionId}");
|
||||
var ret = await gateUnit.Offline(sessionId, RouteType.GameRoute, RouteType.SocialRoute, RouteType.MapRoute);
|
||||
var ret = await gateUnit.Offline(sessionId, RouteType.GameRoute, RouteType.SocialRoute);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
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)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
using Fantasy;
|
||||
using Fantasy.Async;
|
||||
|
||||
namespace NB.Map;
|
||||
|
||||
public static class MapHelper
|
||||
{
|
||||
public static async FTask Offline(Scene scene, long accountId, long gateRouteId)
|
||||
{
|
||||
// 在缓存中检查该账号是否存在
|
||||
var chatUnitManageComponent = scene.GetComponent<MapUnitManageComponent>();
|
||||
if (chatUnitManageComponent == null) return;
|
||||
var mapUnit = chatUnitManageComponent.Get(accountId);
|
||||
if (mapUnit == null) return;
|
||||
|
||||
var roomManageComponent = scene.GetComponent<RoomManageComponent>();
|
||||
|
||||
if (mapUnit.RoomId > 0)
|
||||
{
|
||||
var room = roomManageComponent.Get(mapUnit.RoomId);
|
||||
if (room != null)
|
||||
{
|
||||
await room.Exit(accountId);
|
||||
roomManageComponent.Check(mapUnit.RoomId);
|
||||
}
|
||||
}
|
||||
|
||||
await chatUnitManageComponent.Offline(scene, accountId, gateRouteId);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
using Fantasy;
|
||||
using Fantasy.Entitas;
|
||||
|
||||
namespace NB.Map;
|
||||
|
||||
public static class MapUnitFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// 创建一个新的Player
|
||||
/// </summary>
|
||||
/// <param name="scene"></param>
|
||||
/// <param name="aId">ToKen令牌传递过来的aId</param>
|
||||
/// <returns></returns>
|
||||
public static MapUnit Create(Scene scene, long aId)
|
||||
{
|
||||
var player = Entity.Create<MapUnit>(scene, aId, true, true);
|
||||
return player;
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
using Fantasy;
|
||||
using Fantasy.Async;
|
||||
|
||||
namespace NB.Map;
|
||||
|
||||
public static class MapUnitManageComponentSystem
|
||||
{
|
||||
#region 上线下线
|
||||
|
||||
/// <summary>
|
||||
/// 玩家上线
|
||||
/// </summary>
|
||||
/// <param name="self"></param>
|
||||
/// <param name="scene"></param>
|
||||
/// <param name="accountId"></param>
|
||||
/// <param name="gateRouteId"></param>
|
||||
public static async FTask<MapUnit?> Online(this MapUnitManageComponent self, Scene scene,
|
||||
long accountId,
|
||||
long gateRouteId)
|
||||
{
|
||||
if (!self.TryGet(accountId, out var unit))
|
||||
{
|
||||
unit = MapUnitFactory.Create(scene, accountId);
|
||||
self.Add(unit);
|
||||
}
|
||||
|
||||
if (unit != null)
|
||||
{
|
||||
unit.GateRouteId = gateRouteId;
|
||||
}
|
||||
|
||||
await FTask.CompletedTask;
|
||||
return unit;
|
||||
}
|
||||
|
||||
public static async FTask Offline(this MapUnitManageComponent self, Scene scene, long accountId, long gateRouteId)
|
||||
{
|
||||
if (self.TryGet(accountId, out var unit) && unit != null)
|
||||
{
|
||||
if (unit.GateRouteId == gateRouteId)
|
||||
{
|
||||
self.Remove(accountId); //如果当前网关和下线的网关一致
|
||||
}
|
||||
}
|
||||
|
||||
await FTask.CompletedTask;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 获取&移除
|
||||
|
||||
public static void Add(this MapUnitManageComponent self, MapUnit unit)
|
||||
{
|
||||
self.Units.Add(unit.Id, unit);
|
||||
}
|
||||
|
||||
public static MapUnit? Get(this MapUnitManageComponent self, long accountId)
|
||||
{
|
||||
return self.Units.GetValueOrDefault(accountId);
|
||||
}
|
||||
|
||||
public static bool TryGet(this MapUnitManageComponent self, long accountId, out MapUnit? unit)
|
||||
{
|
||||
return self.Units.TryGetValue(accountId, out unit);
|
||||
}
|
||||
|
||||
public static void Remove(this MapUnitManageComponent self, long accountId, bool isDispose = true)
|
||||
{
|
||||
if (!self.Units.Remove(accountId, out var account))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isDispose)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
account.Dispose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
using Fantasy;
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Entitas.Interface;
|
||||
using Unity.Mathematics;
|
||||
|
||||
namespace NB.Map;
|
||||
|
||||
public class MapUnitSystemDestroySystem : DestroySystem<MapUnit>
|
||||
{
|
||||
protected override void Destroy(MapUnit self)
|
||||
{
|
||||
self.MapId = 0;
|
||||
self.Position = float3.zero;
|
||||
self.Rotation = float3.zero;
|
||||
self.GateRouteId = 0L;
|
||||
}
|
||||
}
|
||||
|
||||
public static class MapUnitSystem
|
||||
{
|
||||
public static async FTask<uint> EnterMap(this MapUnit self, int mapId)
|
||||
{
|
||||
var mapManageComponent = self.Scene.GetComponent<MapManageComponent>();
|
||||
|
||||
var map = mapManageComponent.Get(mapId);
|
||||
if (map == null)
|
||||
{
|
||||
return ErrorCode.MapIdError;
|
||||
}
|
||||
|
||||
if (map.Units.TryAdd(self.Id, self))
|
||||
{
|
||||
// 同步客户端
|
||||
// self.Scene.NetworkMessagingComponent.SendInnerRoute(self.GateRouteId, new Map2C_ChangeMap()
|
||||
// {
|
||||
// Node = 1,
|
||||
// MapId = mapId
|
||||
// });
|
||||
}
|
||||
|
||||
self.MapId = mapId;
|
||||
|
||||
|
||||
await FTask.CompletedTask;
|
||||
|
||||
|
||||
return ErrorCode.Successful;
|
||||
}
|
||||
|
||||
|
||||
public static MapUnitInfo ToMapUnitInfo(this MapUnit self)
|
||||
{
|
||||
var ret = new MapUnitInfo()
|
||||
{
|
||||
Id = self.Id,
|
||||
Position = Vector3Info.Create(self.Scene),
|
||||
Rotation = Vector3Info.Create(self.Scene),
|
||||
};
|
||||
|
||||
ret.Position.x = self.Position.x;
|
||||
ret.Position.y = self.Position.y;
|
||||
ret.Position.z = self.Position.z;
|
||||
|
||||
ret.Rotation.x = self.Rotation.x;
|
||||
ret.Rotation.y = self.Rotation.y;
|
||||
ret.Rotation.z = self.Rotation.z;
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@ using NB.Authentication;
|
||||
using NB.Chat;
|
||||
using NB.Game;
|
||||
using NB.Gate;
|
||||
using NB.Map;
|
||||
|
||||
namespace NBF;
|
||||
|
||||
@@ -40,11 +39,11 @@ public sealed class OnCreateSceneEvent : AsyncEventSystem<OnCreateScene>
|
||||
await InitializeGateScene(scene);
|
||||
break;
|
||||
}
|
||||
case SceneType.Map:
|
||||
{
|
||||
await InitializeMapScene(scene);
|
||||
break;
|
||||
}
|
||||
// case SceneType.Map:
|
||||
// {
|
||||
// await InitializeMapScene(scene);
|
||||
// break;
|
||||
// }
|
||||
case SceneType.Social:
|
||||
{
|
||||
// Gate 场景初始化
|
||||
@@ -117,24 +116,24 @@ public sealed class OnCreateSceneEvent : AsyncEventSystem<OnCreateScene>
|
||||
// Log.Debug(instanceList[0].Dic[1]);
|
||||
}
|
||||
|
||||
private async FTask InitializeMapScene(Scene scene)
|
||||
{
|
||||
// Map 场景特定的初始化逻辑
|
||||
Log.Info($"初始化 Map 场景: {scene.Id}");
|
||||
Log.Info("创建地图场景===");
|
||||
scene.AddComponent<MapUnitManageComponent>();
|
||||
var roomManageComponent = scene.AddComponent<RoomManageComponent>();
|
||||
scene.AddComponent<MapManageComponent>();
|
||||
|
||||
var room = roomManageComponent.Create(361499030775398402);
|
||||
if (room != null)
|
||||
{
|
||||
roomManageComponent.TestRoomCode = room.Code;
|
||||
Log.Info($"测试房间代码 = {room.Code}");
|
||||
}
|
||||
|
||||
await FTask.CompletedTask;
|
||||
}
|
||||
// private async FTask InitializeMapScene(Scene scene)
|
||||
// {
|
||||
// // Map 场景特定的初始化逻辑
|
||||
// Log.Info($"初始化 Map 场景: {scene.Id}");
|
||||
// Log.Info("创建地图场景===");
|
||||
// scene.AddComponent<MapUnitManageComponent>();
|
||||
// var roomManageComponent = scene.AddComponent<RoomManageComponent>();
|
||||
// scene.AddComponent<MapManageComponent>();
|
||||
//
|
||||
// var room = roomManageComponent.Create(361499030775398402);
|
||||
// if (room != null)
|
||||
// {
|
||||
// roomManageComponent.TestRoomCode = room.Code;
|
||||
// Log.Info($"测试房间代码 = {room.Code}");
|
||||
// }
|
||||
//
|
||||
// await FTask.CompletedTask;
|
||||
// }
|
||||
|
||||
private async FTask InitializeSocialScene(Scene scene)
|
||||
{
|
||||
@@ -153,6 +152,19 @@ public sealed class OnCreateSceneEvent : AsyncEventSystem<OnCreateScene>
|
||||
//用于管理玩家的组件
|
||||
scene.AddComponent<PlayerManageComponent>();
|
||||
scene.AddComponent<PlayerBasicCacheManageComponent>();
|
||||
|
||||
|
||||
Log.Info("创建地图场景===");
|
||||
var roomManageComponent = scene.AddComponent<RoomManageComponent>();
|
||||
scene.AddComponent<MapManageComponent>();
|
||||
|
||||
var room = roomManageComponent.Create(361499030775398402);
|
||||
if (room != null)
|
||||
{
|
||||
// roomManageComponent.TestRoomCode = room.Code;
|
||||
Log.Info($"测试房间代码 = {room.Code}");
|
||||
}
|
||||
|
||||
await FTask.CompletedTask;
|
||||
|
||||
// var rod = RodConfig.Get(30001);
|
||||
|
||||
Reference in New Issue
Block a user