LocationProxyComponentSystem.cs 4.0 KB

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