C2G_EnterMapHandler.cs 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. using System;
  2. using Model;
  3. namespace Hotfix
  4. {
  5. [MessageHandler(AppType.Gate)]
  6. public class C2G_EnterMapHandler : AMRpcHandler<C2G_EnterMap, G2C_EnterMap>
  7. {
  8. protected override async void Run(Session session, C2G_EnterMap message, Action<G2C_EnterMap> reply)
  9. {
  10. G2C_EnterMap response = new G2C_EnterMap();
  11. try
  12. {
  13. Log.Debug(MongoHelper.ToJson(message));
  14. Player player = session.GetComponent<SessionPlayerComponent>().Player;
  15. // 在map服务器上创建战斗Unit
  16. string mapAddress = Game.Scene.GetComponent<StartConfigComponent>().MapConfigs[0].GetComponent<InnerConfig>().Address;
  17. Session mapSession = Game.Scene.GetComponent<NetInnerComponent>().Get(mapAddress);
  18. M2G_CreateUnit createUnit = await mapSession.Call<M2G_CreateUnit>(new G2M_CreateUnit() { PlayerId = player.Id, GateSessionId = session.Id });
  19. player.UnitId = createUnit.UnitId;
  20. response.UnitId = createUnit.UnitId;
  21. response.Count = createUnit.Count;
  22. reply(response);
  23. }
  24. catch (Exception e)
  25. {
  26. ReplyError(response, e, reply);
  27. }
  28. }
  29. }
  30. }