Actor_TransferHandler.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using System.Net;
  3. using ETModel;
  4. namespace ETHotfix
  5. {
  6. [ActorMessageHandler(AppType.Map)]
  7. public class Actor_TransferHandler : AMActorRpcHandler<Unit, Actor_TransferRequest, Actor_TransferResponse>
  8. {
  9. protected override async ETTask Run(Unit unit, Actor_TransferRequest request, Actor_TransferResponse response, Action reply)
  10. {
  11. long unitId = unit.Id;
  12. // 先在location锁住unit的地址
  13. await Game.Scene.GetComponent<LocationProxyComponent>().Lock(unitId, unit.InstanceId);
  14. // 删除unit,让其它进程发送过来的消息找不到actor,重发
  15. Game.EventSystem.Remove(unitId);
  16. long instanceId = unit.InstanceId;
  17. int mapIndex = request.MapIndex;
  18. StartConfigComponent startConfigComponent = StartConfigComponent.Instance;
  19. // 考虑AllServer情况
  20. if (startConfigComponent.Count == 1)
  21. {
  22. mapIndex = 0;
  23. }
  24. // 传送到map
  25. StartConfig mapConfig = startConfigComponent.MapConfigs[mapIndex];
  26. IPEndPoint address = mapConfig.GetComponent<InnerConfig>().IPEndPoint;
  27. Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(address);
  28. // 只删除不disponse否则M2M_TrasferUnitRequest无法序列化Unit
  29. Game.Scene.GetComponent<UnitComponent>().RemoveNoDispose(unitId);
  30. M2M_TrasferUnitResponse m2m_TrasferUnitResponse = (M2M_TrasferUnitResponse)await session.Call(new M2M_TrasferUnitRequest() { Unit = unit });
  31. unit.Dispose();
  32. // 解锁unit的地址,并且更新unit的instanceId
  33. await Game.Scene.GetComponent<LocationProxyComponent>().UnLock(unitId, instanceId, m2m_TrasferUnitResponse.InstanceId);
  34. reply();
  35. }
  36. }
  37. }