LocationProxyComponentSystem.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System.Threading.Tasks;
  2. using ETModel;
  3. namespace ETHotfix
  4. {
  5. [ObjectSystem]
  6. public class LocationProxyComponentSystem : AwakeSystem<LocationProxyComponent>
  7. {
  8. public override void Awake(LocationProxyComponent self)
  9. {
  10. self.Awake();
  11. }
  12. }
  13. public static class LocationProxyComponentEx
  14. {
  15. public static void Awake(this LocationProxyComponent self)
  16. {
  17. StartConfigComponent startConfigComponent = Game.Scene.GetComponent<StartConfigComponent>();
  18. self.AppId = startConfigComponent.StartConfig.AppId;
  19. StartConfig startConfig = startConfigComponent.LocationConfig;
  20. self.LocationAddress = startConfig.GetComponent<InnerConfig>().IPEndPoint;
  21. }
  22. public static async Task Add(this LocationProxyComponent self, long key, long instanceId)
  23. {
  24. Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(self.LocationAddress);
  25. await session.Call(new ObjectAddRequest() { Key = key, InstanceId = instanceId });
  26. }
  27. public static async Task Lock(this LocationProxyComponent self, long key, long instanceId, int time = 1000)
  28. {
  29. Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(self.LocationAddress);
  30. await session.Call(new ObjectLockRequest() { Key = key, InstanceId = instanceId, Time = time });
  31. }
  32. public static async Task UnLock(this LocationProxyComponent self, long key, long oldInstanceId, long instanceId)
  33. {
  34. Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(self.LocationAddress);
  35. await session.Call(new ObjectUnLockRequest() { Key = key, OldInstanceId = oldInstanceId, InstanceId = instanceId});
  36. }
  37. public static async Task Remove(this LocationProxyComponent self, long key)
  38. {
  39. Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(self.LocationAddress);
  40. await session.Call(new ObjectRemoveRequest() { Key = key });
  41. }
  42. public static async Task<long> Get(this LocationProxyComponent self, long key)
  43. {
  44. Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(self.LocationAddress);
  45. ObjectGetResponse response = (ObjectGetResponse)await session.Call(new ObjectGetRequest() { Key = key });
  46. return response.InstanceId;
  47. }
  48. }
  49. }