C2G_EnterMapHandler.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System;
  2. namespace ET.Server
  3. {
  4. /// <summary>
  5. /// 加载100%
  6. /// </summary>
  7. [MessageHandler(SceneType.Game)]
  8. public class C2G_EnterMapHandler: AMRpcHandler<C2G_EnterMap, G2C_EnterMap>
  9. {
  10. protected override async ETTask Run(Session session, C2G_EnterMap request, G2C_EnterMap response, Action reply)
  11. {
  12. if (session.DomainScene().SceneType != SceneType.Game)
  13. {
  14. Log.Debug($"Game 请求的Scene错误...SceneType={session.DomainScene().SceneType}");
  15. session.Dispose();
  16. return;
  17. }
  18. // 移除session自动超时组件
  19. session.RemoveComponent<SessionAcceptTimeoutComponent>();
  20. WNPlayer player = session.GetComponent<SessionPlayerComponent>().GetMyPlayer();
  21. if (player == null)
  22. {
  23. Log.Debug($"操作错误, player is null");
  24. response.Error = ErrorCode.ERR_OperationError;
  25. reply();
  26. return;
  27. }
  28. Log.Info($"玩家请求进入场景: playerId={player.GetId()}, instanceId={request.InstanceId}");
  29. Map map = player.Map;
  30. // 当客户端所要进入的场景不为空且不等于当前场景,忽略掉本次请求
  31. if (request.InstanceId > 0 && map.Id != request.InstanceId)
  32. {
  33. Log.Debug(
  34. $"连续切图吗? playerId={player.GetId()}, name={player.GetName()}, mapId={map.MapId}, map.InstanceId={map.Id}, request.InstanceId={request.InstanceId}");
  35. response.Error = ErrorCode.ERR_OperationToFast;
  36. reply();
  37. return;
  38. }
  39. if (map == null)
  40. {
  41. Log.Debug($"进入场景出错, 场景不存在...playerId={player.GetId()}, instanceId={request.InstanceId}");
  42. response.Error = ErrorCode.ERR_EnterMapError;
  43. reply();
  44. return;
  45. }
  46. map.PlayerEnterRequest(player);
  47. map.OnPlayerEntered(player);
  48. response.MapInstanceId = player.Map.Id;
  49. reply();
  50. // 等待client ready消息
  51. // await session.DomainScene().GetComponent<ObjectWait>().Wait<Wait_PlayerReady>();
  52. // player.OnEndEnterScene();
  53. // 测试添加单位
  54. // Struct.MonsterUnit unit = new Struct.MonsterUnit();
  55. // unit.id = 101;
  56. // unit.force = (int)AreaForce.MONSTER;
  57. // unit.x = 5;
  58. // unit.y = 12;
  59. // unit.autoGuard = true;
  60. // await player.Map.AddUnits(unit, false);
  61. await ETTask.CompletedTask;
  62. }
  63. }
  64. }