PlayerComponent.cs 626 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. namespace ET
  4. {
  5. public class PlayerComponent : Entity
  6. {
  7. private readonly Dictionary<long, Player> idPlayers = new Dictionary<long, Player>();
  8. public void Add(Player player)
  9. {
  10. this.idPlayers.Add(player.Id, player);
  11. }
  12. public Player Get(long id)
  13. {
  14. this.idPlayers.TryGetValue(id, out Player gamer);
  15. return gamer;
  16. }
  17. public void Remove(long id)
  18. {
  19. this.idPlayers.Remove(id);
  20. }
  21. public int Count
  22. {
  23. get
  24. {
  25. return this.idPlayers.Count;
  26. }
  27. }
  28. public Player[] GetAll()
  29. {
  30. return this.idPlayers.Values.ToArray();
  31. }
  32. }
  33. }