Files
Fishing2Server/Hotfix/Outer/Gate/System/GameAccountManageComponentSystem.cs
2025-07-16 17:47:53 +08:00

50 lines
1.3 KiB
C#

using Fantasy.Entitas.Interface;
using Fantasy.Gate;
namespace System.Gate.System;
public sealed class GameAccountManageComponentDestroySystem : DestroySystem<GameAccountManageComponent>
{
protected override void Destroy(GameAccountManageComponent self)
{
foreach (var (_, gameAccount) in self.Accounts)
{
gameAccount.Dispose();
}
self.Accounts.Clear();
}
}
public static class GameAccountManageComponentSystem
{
public static void Add(this GameAccountManageComponent self, GameAccount account)
{
self.Accounts.Add(account.Id, account);
}
public static GameAccount? Get(this GameAccountManageComponent self, long accountId)
{
return self.Accounts.GetValueOrDefault(accountId);
}
public static bool TryGet(this GameAccountManageComponent self, long accountId, out GameAccount? account)
{
return self.Accounts.TryGetValue(accountId, out account);
}
public static void Remove(this GameAccountManageComponent self, long accountId, bool isDispose = true)
{
if (!self.Accounts.Remove(accountId, out var account))
{
return;
}
if (!isDispose)
{
return;
}
account.Dispose();
}
}