LocationProxyComponentSystem.cs 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System;
  2. namespace ET.Server
  3. {
  4. public static partial class LocationProxyComponentSystem
  5. {
  6. private static ActorId GetLocationSceneId(long key)
  7. {
  8. return LocationConfigSingleton.Instance.GetLocation(key).ActorId;
  9. }
  10. public static async ETTask Add(this LocationProxyComponent self, int type, long key, ActorId actorId)
  11. {
  12. Fiber fiber = self.Fiber();
  13. Log.Info($"location proxy add {key}, {actorId} {TimeInfo.Instance.ServerNow()}");
  14. ObjectAddRequest objectAddRequest = ObjectAddRequest.Create();
  15. objectAddRequest.Type = type;
  16. objectAddRequest.Key = key;
  17. objectAddRequest.ActorId = actorId;
  18. await fiber.Root.GetComponent<MessageSender>().Call(GetLocationSceneId(key), objectAddRequest);
  19. }
  20. public static async ETTask Lock(this LocationProxyComponent self, int type, long key, ActorId actorId, int time = 60000)
  21. {
  22. Fiber fiber = self.Fiber();
  23. Log.Info($"location proxy lock {key}, {actorId} {TimeInfo.Instance.ServerNow()}");
  24. ObjectLockRequest objectLockRequest = ObjectLockRequest.Create();
  25. objectLockRequest.Type = type;
  26. objectLockRequest.Key = key;
  27. objectLockRequest.ActorId = actorId;
  28. objectLockRequest.Time = time;
  29. await fiber.Root.GetComponent<MessageSender>().Call(GetLocationSceneId(key), objectLockRequest);
  30. }
  31. public static async ETTask UnLock(this LocationProxyComponent self, int type, long key, ActorId oldActorId, ActorId newActorId)
  32. {
  33. Fiber fiber = self.Fiber();
  34. Log.Info($"location proxy unlock {key}, {newActorId} {TimeInfo.Instance.ServerNow()}");
  35. ObjectUnLockRequest objectUnLockRequest = ObjectUnLockRequest.Create();
  36. objectUnLockRequest.Type = type;
  37. objectUnLockRequest.Key = key;
  38. objectUnLockRequest.OldActorId = oldActorId;
  39. objectUnLockRequest.NewActorId = newActorId;
  40. await fiber.Root.GetComponent<MessageSender>().Call(GetLocationSceneId(key), objectUnLockRequest);
  41. }
  42. public static async ETTask Remove(this LocationProxyComponent self, int type, long key)
  43. {
  44. Fiber fiber = self.Fiber();
  45. Log.Info($"location proxy remove {key}, {TimeInfo.Instance.ServerNow()}");
  46. ObjectRemoveRequest objectRemoveRequest = ObjectRemoveRequest.Create();
  47. objectRemoveRequest.Type = type;
  48. objectRemoveRequest.Key = key;
  49. await fiber.Root.GetComponent<MessageSender>().Call(GetLocationSceneId(key), objectRemoveRequest);
  50. }
  51. public static async ETTask<ActorId> Get(this LocationProxyComponent self, int type, long key)
  52. {
  53. if (key == 0)
  54. {
  55. throw new Exception($"get location key 0");
  56. }
  57. // location server配置到共享区,一个大战区可以配置N多个location server,这里暂时为1
  58. ObjectGetRequest objectGetRequest = ObjectGetRequest.Create();
  59. objectGetRequest.Type = type;
  60. objectGetRequest.Key = key;
  61. ObjectGetResponse response =
  62. (ObjectGetResponse) await self.Root().GetComponent<MessageSender>().Call(GetLocationSceneId(key), objectGetRequest);
  63. return response.ActorId;
  64. }
  65. public static async ETTask AddLocation(this Entity self, int type)
  66. {
  67. await self.Root().GetComponent<LocationProxyComponent>().Add(type, self.Id, self.GetActorId());
  68. }
  69. public static async ETTask RemoveLocation(this Entity self, int type)
  70. {
  71. await self.Root().GetComponent<LocationProxyComponent>().Remove(type, self.Id);
  72. }
  73. }
  74. }