using Fantasy; using Fantasy.Async; using Fantasy.Entitas.Interface; using Hotfix.Helper; namespace Hotfix; public static class GameAccountManageComponentSystem { public static void Add(this GameAccountManageComponent self,long accountId, GameAccount gameAccount) { if (!self.Accounts.ContainsKey(accountId)) { self.Accounts.Add(accountId, gameAccount); } else { self.Accounts[accountId] = gameAccount; } } public static GameAccount? Get(this GameAccountManageComponent self,long accountId) { return self.Accounts.GetValueOrDefault(accountId); } public static GameAccount? TryGet(this GameAccountManageComponent self,long accountId) { self.Accounts.TryGetValue(accountId,out var gameAccount); return gameAccount; } public static bool Remove(this GameAccountManageComponent self, long accountId, bool isDispose = true) { if (!self.Accounts.Remove(accountId,out var gameAccount)) { return false; } if (isDispose) { gameAccount.Dispose(); } return true; } public static async FTask<(uint error,GameAccount gameAccount)> GetAccountGame(this GameAccountManageComponent self, long accountId) { var scene = self.Scene; GameAccount gameAccount = null; using (await scene.CoroutineLockComponent.Wait((int)ELockType.GateGetGameAccount,accountId)) { gameAccount = self.Get(accountId); if (gameAccount != null) return (GameErrorCode.GateLoginSuccess,gameAccount);; gameAccount = await GameAccountHelper.LoadGameAccountFromDatabase(scene,accountId); if (gameAccount != null) { gameAccount = await GameAccountFactory.Create(scene, accountId); } self.Add(accountId, gameAccount); return (GameErrorCode.GateLoginSuccess,gameAccount); } } } public class GameAccountManageComponentDestroySystem : DestroySystem { protected override void Destroy(GameAccountManageComponent self) { foreach (var (_,account) in self.Accounts.ToArray()) { account.Dispose(); } self.Accounts.Clear(); } }