LocationProxyComponentSystem.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System;
  2. namespace ET.Server
  3. {
  4. [ObjectSystem]
  5. public class LocationProxyComponentAwakeSystem: AwakeSystem<LocationProxyComponent>
  6. {
  7. protected override void Awake(LocationProxyComponent self)
  8. {
  9. LocationProxyComponent.Instance = self;
  10. }
  11. }
  12. [ObjectSystem]
  13. public class LocationProxyComponentDestroySystem: DestroySystem<LocationProxyComponent>
  14. {
  15. protected override void Destroy(LocationProxyComponent self)
  16. {
  17. LocationProxyComponent.Instance = null;
  18. }
  19. }
  20. public static class LocationProxyComponentSystem
  21. {
  22. private static long GetLocationSceneId(long key)
  23. {
  24. return StartSceneConfigCategory.Instance.LocationConfig.InstanceId;
  25. }
  26. public static async ETTask Add(this LocationProxyComponent self, long key, long instanceId)
  27. {
  28. Log.Info($"location proxy add {key}, {instanceId} {TimeHelper.ServerNow()}");
  29. await ActorMessageSenderComponent.Instance.Call(GetLocationSceneId(key),
  30. new ObjectAddRequest() { Key = key, InstanceId = instanceId });
  31. }
  32. public static async ETTask Lock(this LocationProxyComponent self, long key, long instanceId, int time = 60000)
  33. {
  34. Log.Info($"location proxy lock {key}, {instanceId} {TimeHelper.ServerNow()}");
  35. await ActorMessageSenderComponent.Instance.Call(GetLocationSceneId(key),
  36. new ObjectLockRequest() { Key = key, InstanceId = instanceId, Time = time });
  37. }
  38. public static async ETTask UnLock(this LocationProxyComponent self, long key, long oldInstanceId, long instanceId)
  39. {
  40. Log.Info($"location proxy unlock {key}, {instanceId} {TimeHelper.ServerNow()}");
  41. await ActorMessageSenderComponent.Instance.Call(GetLocationSceneId(key),
  42. new ObjectUnLockRequest() { Key = key, OldInstanceId = oldInstanceId, InstanceId = instanceId });
  43. }
  44. public static async ETTask Remove(this LocationProxyComponent self, long key)
  45. {
  46. Log.Info($"location proxy add {key}, {TimeHelper.ServerNow()}");
  47. await ActorMessageSenderComponent.Instance.Call(GetLocationSceneId(key),
  48. new ObjectRemoveRequest() { Key = key });
  49. }
  50. public static async ETTask<long> Get(this LocationProxyComponent self, long key)
  51. {
  52. if (key == 0)
  53. {
  54. throw new Exception($"get location key 0");
  55. }
  56. // location server配置到共享区,一个大战区可以配置N多个location server,这里暂时为1
  57. ObjectGetResponse response =
  58. (ObjectGetResponse) await ActorMessageSenderComponent.Instance.Call(GetLocationSceneId(key),
  59. new ObjectGetRequest() { Key = key });
  60. return response.InstanceId;
  61. }
  62. public static async ETTask AddLocation(this Entity self)
  63. {
  64. await LocationProxyComponent.Instance.Add(self.Id, self.InstanceId);
  65. }
  66. public static async ETTask RemoveLocation(this Entity self)
  67. {
  68. await LocationProxyComponent.Instance.Remove(self.Id);
  69. }
  70. }
  71. }