Actor_TransferHandler.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Threading.Tasks;
  3. using Model;
  4. namespace Hotfix
  5. {
  6. [ActorMessageHandler(AppType.Map)]
  7. public class Actor_TransferHandler : AMActorRpcHandler<Unit, Actor_TransferRequest, Actor_TransferResponse>
  8. {
  9. protected override async Task Run(Unit unit, Actor_TransferRequest message, Action<Actor_TransferResponse> reply)
  10. {
  11. Actor_TransferResponse response = new Actor_TransferResponse();
  12. try
  13. {
  14. long unitId = unit.Id;
  15. // 先在location锁住unit的地址
  16. await Game.Scene.GetComponent<LocationProxyComponent>().Lock(unitId);
  17. int mapIndex = message.MapIndex;
  18. StartConfigComponent startConfigComponent = Game.Scene.GetComponent<StartConfigComponent>();
  19. // 考虑AllServer情况
  20. if (startConfigComponent.Count == 1)
  21. {
  22. mapIndex = 0;
  23. }
  24. // 传送到map
  25. StartConfig mapConfig = startConfigComponent.MapConfigs[mapIndex];
  26. string address = mapConfig.GetComponent<InnerConfig>().Address;
  27. Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(address);
  28. await session.Call<M2M_TrasferUnitResponse>(new M2M_TrasferUnitRequest() { Unit = unit });
  29. Game.Scene.GetComponent<UnitComponent>().Remove(unitId);
  30. // 解锁unit的地址,并且更新unit的地址
  31. await Game.Scene.GetComponent<LocationProxyComponent>().UnLock(unitId, mapConfig.AppId);
  32. reply(response);
  33. }
  34. catch (Exception e)
  35. {
  36. ReplyError(response, e, reply);
  37. }
  38. }
  39. }
  40. }