提交进入地图和创建房间相关逻辑和协议

This commit is contained in:
2025-08-27 18:05:55 +08:00
parent f6d85a1e0a
commit 94af0e5ddb
31 changed files with 562 additions and 68 deletions

View File

@@ -2,6 +2,7 @@
using Fantasy.Async;
using Fantasy.Entitas.Interface;
using Fantasy.Network;
using Fantasy.Platform.Net;
using NB.Common;
// ReSharper disable ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
@@ -13,7 +14,9 @@ public class GateUnitDestroySystem : DestroySystem<GateUnit>
protected override void Destroy(GateUnit self)
{
self.AccountID = 0;
self.Kick = false;
self.Region = 0;
self.SceneRoutes.Clear();
self.RoomCode = string.Empty;
}
}
@@ -21,15 +24,9 @@ public static class GateUnitSystem
{
#region Address
public static void RemoveAddress(this GateUnit self, int routType, long routeId)
public static void RemoveAddress(this GateUnit self, int routType)
{
if (self.SceneRoutes.TryGetValue(routType, out var route))
{
if (route == routeId)
{
self.SceneRoutes.Remove(routType);
}
}
self.SceneRoutes.Remove(routType);
}
public static void AddAddress(this GateUnit self, int routType, long routeId)
@@ -61,7 +58,7 @@ public static class GateUnitSystem
return ErrorCode.Successful;
}
public static async FTask<uint> Online(this GateUnit self, int routeType)
public static async FTask<uint> Online(this GateUnit self, int routeType, SceneConfig? sceneConfig = null)
{
Session session = self.Session;
var routeComponent = session.GetComponent<RouteComponent>();
@@ -69,9 +66,13 @@ public static class GateUnitSystem
{
routeComponent = session.AddComponent<RouteComponent>();
}
var gameSceneConfig = SceneConfigHelper.GetConfigByRouteType(routeType);
var gameRouteId = gameSceneConfig.RouteId;
if (sceneConfig == null)
{
sceneConfig = SceneConfigHelper.GetConfigByRouteType(routeType);
}
var gameRouteId = sceneConfig.RouteId;
var gameResponse = (G2Common_EnterResponse)await self.Scene.NetworkMessagingComponent.CallInnerRoute(
gameRouteId, new G2Common_EnterRequest()
@@ -85,8 +86,10 @@ public static class GateUnitSystem
return gameResponse.ErrorCode;
}
routeComponent.RemoveAddress(routeType);
routeComponent.AddAddress(routeType, gameResponse.UnitRouteId);
self.AddAddress(routeType, gameResponse.UnitRouteId);
self.AddAddress(sceneConfig.SceneType, gameRouteId);
return ErrorCode.Successful;
}
@@ -111,7 +114,8 @@ public static class GateUnitSystem
public static async FTask<uint> Offline(this GateUnit self, long sessionId, int routeType)
{
var sceneRouteId = self.GetAddress(routeType);
var sceneConfig = SceneConfigHelper.GetConfigByRouteType(routeType);
var sceneRouteId = sceneConfig.RouteId;
if (sceneRouteId < 1) return ErrorCode.Successful;
for (int i = 0; i < 10; i++)
{
@@ -123,7 +127,9 @@ public static class GateUnitSystem
});
if (gameResponse.ErrorCode == 0)
{
self.RemoveAddress(routeType, sceneRouteId);
//TODO:这里需要清理掉记录的数据
self.RemoveAddress(routeType);
self.RemoveAddress(sceneConfig.SceneType);
return ErrorCode.Successful;
}
}