广播聊天

This commit is contained in:
bob
2025-08-07 17:51:25 +08:00
parent 70bfe43a80
commit e1a4db89ae
19 changed files with 347 additions and 21 deletions

View File

@@ -0,0 +1,75 @@
using Fantasy;
using Fantasy.Async;
using NB.Game;
namespace NB.Chat;
public static class ChatUnitManageComponentSystem
{
#region 线线
/// <summary>
/// 玩家上线
/// </summary>
/// <param name="self"></param>
/// <param name="scene"></param>
/// <param name="accountId"></param>
/// <param name="gateRouteId"></param>
public static async FTask<ChatUnit> Online(this ChatUnitManageComponent self, Scene scene, long accountId,
long gateRouteId)
{
if (!self.TryGet(accountId, out var account))
{
account = ChatUnitFactory.Create(scene, accountId);
self.Add(account);
}
account.GateRouteId = gateRouteId;
await FTask.CompletedTask;
return account;
}
public static async FTask Offline(this ChatUnitManageComponent self, Scene scene, long accountId)
{
self.Remove(accountId);
await FTask.CompletedTask;
}
#endregion
#region &
public static void Add(this ChatUnitManageComponent self, ChatUnit account)
{
self.ChatUnits.Add(account.Id, account);
}
public static ChatUnit? Get(this ChatUnitManageComponent self, long accountId)
{
return self.ChatUnits.GetValueOrDefault(accountId);
}
public static bool TryGet(this ChatUnitManageComponent self, long accountId, out ChatUnit? account)
{
return self.ChatUnits.TryGetValue(accountId, out account);
}
public static void Remove(this ChatUnitManageComponent self, long accountId, bool isDispose = true)
{
if (!self.ChatUnits.Remove(accountId, out var account))
{
return;
}
if (!isDispose)
{
return;
}
account.Dispose();
}
#endregion
}