修改协议工具
This commit is contained in:
49
Hotfix/Gate/System/PlayerManageComponentSystem.cs
Normal file
49
Hotfix/Gate/System/PlayerManageComponentSystem.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using Fantasy.Entitas.Interface;
|
||||
|
||||
namespace NB.Gate.System;
|
||||
|
||||
public sealed class PlayerManageComponentDestroySystem : DestroySystem<PlayerManageComponent>
|
||||
{
|
||||
protected override void Destroy(PlayerManageComponent self)
|
||||
{
|
||||
foreach (var (_, gameAccount) in self.Players)
|
||||
{
|
||||
gameAccount.Dispose();
|
||||
}
|
||||
|
||||
self.Players.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public static class PlayerManageComponentSystem
|
||||
{
|
||||
public static void Add(this PlayerManageComponent self, Player account)
|
||||
{
|
||||
self.Players.Add(account.Id, account);
|
||||
}
|
||||
|
||||
public static Player Get(this PlayerManageComponent self, long accountId)
|
||||
{
|
||||
return self.Players.GetValueOrDefault(accountId);
|
||||
}
|
||||
|
||||
public static bool TryGet(this PlayerManageComponent self, long accountId, out Player? account)
|
||||
{
|
||||
return self.Players.TryGetValue(accountId, out account);
|
||||
}
|
||||
|
||||
public static void Remove(this PlayerManageComponent self, long accountId, bool isDispose = true)
|
||||
{
|
||||
if (!self.Players.Remove(accountId, out var account))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isDispose)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
account.Dispose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user