CellSystem.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System.Collections.Generic;
  2. using System.Text;
  3. namespace ET.Server
  4. {
  5. [ObjectSystem]
  6. public class CellDestroySystem: DestroySystem<Cell>
  7. {
  8. public override void Destroy(Cell self)
  9. {
  10. self.AOIUnits.Clear();
  11. self.SubsEnterEntities.Clear();
  12. self.SubsLeaveEntities.Clear();
  13. }
  14. }
  15. public static class CellSystem
  16. {
  17. public static void Add(this Cell self, AOIEntity aoiEntity)
  18. {
  19. self.AOIUnits.Add(aoiEntity.Id, aoiEntity);
  20. }
  21. public static void Remove(this Cell self, AOIEntity aoiEntity)
  22. {
  23. self.AOIUnits.Remove(aoiEntity.Id);
  24. }
  25. public static string CellIdToString(this long cellId)
  26. {
  27. int y = (int) (cellId & 0xffffffff);
  28. int x = (int) ((ulong) cellId >> 32);
  29. return $"{x}:{y}";
  30. }
  31. public static string CellIdToString(this HashSet<long> cellIds)
  32. {
  33. StringBuilder sb = new StringBuilder();
  34. foreach (long cellId in cellIds)
  35. {
  36. sb.Append(cellId.CellIdToString());
  37. sb.Append(",");
  38. }
  39. return sb.ToString();
  40. }
  41. }
  42. }