房间创建和进入相关逻辑和协议

This commit is contained in:
2025-08-27 00:04:40 +08:00
parent 7325e268ce
commit f6d85a1e0a
45 changed files with 1246 additions and 729 deletions

View File

@@ -1,29 +0,0 @@
// using Fantasy;
// using Fantasy.Async;
// using Fantasy.Entitas;
// using Fantasy.Helper;
// using Fantasy.Network;
// using Fantasy.Network.Interface;
// using NB;
// using NB.Gate;
//
// namespace NB.Game;
//
// public class G2Game_EnterRequestHandler : RouteRPC<Scene, G2Game_EnterRequest, Game2G_EnterResponse>
// {
// protected override async FTask Run(Scene scene, G2Game_EnterRequest request, Game2G_EnterResponse response,
// Action reply)
// {
// Log.Debug("收到 G2Game_EnterRequestHandler");
//
//
// // 在缓存中检查该账号是否存在
// var gameAccountManageComponent = scene.GetComponent<PlayerManageComponent>();
//
// var account = await gameAccountManageComponent.Online(scene, request.AccountId, request.GateRouteId);
//
// response.RoleRouteId = account.RuntimeId;
// response.RoleInfo = account.GetRoleSimpleInfo();
// await FTask.CompletedTask;
// }
// }

View File

@@ -40,24 +40,22 @@ public static class PlayerManageComponentSystem
/// 玩家上线
/// </summary>
/// <param name="self"></param>
/// <param name="scene"></param>
/// <param name="accountId"></param>
/// <param name="gateRouteId"></param>
public static async FTask<Player?> Online(this PlayerManageComponent self, Scene scene, long accountId,
long gateRouteId)
public static async FTask<Player?> Online(this PlayerManageComponent self, long accountId, long gateRouteId)
{
Log.Debug("检查账号是否在缓存中");
if (!self.TryGet(accountId, out var account))
{
// 首先要先到数据库中查询是否有这个账号
account = await PlayerHelper.LoadDataBase(scene, accountId);
account = await PlayerHelper.LoadDataBase(self.Scene, accountId);
// 如果有的话,就直接加入在缓存中就可以了
if (account == null)
{
Log.Debug("检查到账号没有在数据库中,需要创建一个新的账号并且保存到数据库中");
// 如果没有,就要创建一个新的并且保存到数据库。
// 如果不存在,表示这是一个新的账号,需要创建一下这个账号。
account = PlayerFactory.Create(scene, accountId);
account = PlayerFactory.Create(self.Scene, accountId);
account.Level = 99;
@@ -111,6 +109,19 @@ public static class PlayerManageComponentSystem
return account;
}
public static async FTask Offline(this PlayerManageComponent self, long accountId, long sessionId)
{
if (self.TryGet(accountId, out var account))
{
if (account.SessionRunTimeId == sessionId)
{
//退出的是当前的
await account.Save();
self.Remove(accountId);
}
}
}
#endregion
#region &