InputMoveCommand.lua 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. local InputMoveCommand = class('InputMoveCommand', framework.SimpleCommand)
  2. function InputMoveCommand:ctor()
  3. end
  4. function InputMoveCommand:execute(note)
  5. local data = note:getBody()
  6. local facade = global.Facade
  7. local inputProxy = facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  8. local mapProxy = facade:retrieveProxy(global.ProxyTable.Map)
  9. local autoProxy = facade:retrieveProxy(global.ProxyTable.Auto)
  10. local mainPlayer = global.gamePlayerController:GetMainPlayer()
  11. if not mainPlayer then
  12. return nil
  13. end
  14. if mainPlayer:IsHoreseCopilot() then
  15. return nil
  16. end
  17. --
  18. inputProxy:ClearMove()
  19. -- clear mouse input move
  20. inputProxy:ClearMouseTouch()
  21. --
  22. local moveType = data.type and data.type or global.MMO.INPUT_MOVE_TYPE_OTHER
  23. local destPos = cc.p(data.x, data.y)
  24. -- 摇杆/点地板
  25. if moveType == global.MMO.INPUT_MOVE_TYPE_JOYSTICK or moveType == global.MMO.INPUT_MOVE_TYPE_GRID then
  26. -- find pos
  27. local moveDir = data.moveDir
  28. local moveStep = data.moveStep
  29. ----------------------------------------
  30. -- open door
  31. local openDoorPos = cc.p(destPos.x, destPos.y)
  32. if moveType == global.MMO.INPUT_MOVE_TYPE_JOYSTICK then
  33. local normal = inputProxy:DirToNormalizeVec2(data.moveDir)
  34. local move = cc.pMul(normal, 1)
  35. openDoorPos.x = mainPlayer:GetMapX() + move.x * moveStep
  36. openDoorPos.y = mainPlayer:GetMapY() + move.y * moveStep
  37. end
  38. if global.sceneManager:canOpenDoor(openDoorPos.x, openDoorPos.y) then
  39. local mapProxy = facade:retrieveProxy(global.ProxyTable.Map)
  40. mapProxy:RequestOpenDoor(openDoorPos.x, openDoorPos.y)
  41. return nil
  42. end
  43. ----------------------------------------
  44. -- calc dest pos
  45. local srcPos = cc.p(mainPlayer:GetMapX(), mainPlayer:GetMapY())
  46. destPos = global.PathFindController:FindDestPosJoystick(srcPos, moveDir, moveStep)
  47. end
  48. --
  49. if nil == destPos then
  50. return nil
  51. end
  52. -- fix move pos by range
  53. local posX = destPos.x
  54. local posY = destPos.y
  55. if data.range and data.range > 0 then
  56. posX, posY = inputProxy:FindBestMovePos(mainPlayer:GetMapX(), mainPlayer:GetMapY(), data.x, data.y,data.range)
  57. end
  58. -- check move pos enable
  59. if mainPlayer:GetMapX() == posX and mainPlayer:GetMapY() == posY then
  60. if autoProxy:IsAutoMoveState() then
  61. facade:sendNotification(global.NoticeTable.AutoMoveEnd)
  62. end
  63. return nil
  64. end
  65. -- check mapID
  66. local mapID = data.mapID
  67. if not mapID then
  68. local mapProxy = facade:retrieveProxy(global.ProxyTable.Map)
  69. mapID = mapProxy:GetMapID()
  70. end
  71. -- push last move pos
  72. local targetID = data.targetID
  73. local skillID = data.skillID
  74. inputProxy:SetCurrMoveType(moveType)
  75. inputProxy:SetCurrMovePos({mapID = mapID, x = posX, y = posY, targetID = targetID, skillID = skillID})
  76. -- path find
  77. local moveTo = inputProxy:GetCurrMovePos()
  78. if moveType == global.MMO.INPUT_MOVE_TYPE_LAUNCH then
  79. local findPoints = global.PathFindController:FindPathAStarLimits(cc.p(mainPlayer:GetMapX(), mainPlayer:GetMapY()), cc.p(moveTo.x, moveTo.y))
  80. inputProxy:SetPathFindPoints(findPoints)
  81. else
  82. local findPoints = global.PathFindController:FindPathAStar(cc.p(mainPlayer:GetMapX(), mainPlayer:GetMapY()), cc.p(moveTo.x, moveTo.y))
  83. inputProxy:SetPathFindPoints(findPoints)
  84. end
  85. -- can't find path
  86. local pathPoints = inputProxy:GetCurrPathPoint()
  87. if pathPoints == 0 then
  88. -- record move blocked
  89. inputProxy:SetIsMoveBlocked(true)
  90. if autoProxy:IsAFKState() then
  91. if moveType == global.MMO.INPUT_MOVE_TYPE_FINDITEM then
  92. -- 忽略当前拾取物
  93. local autoPickItemID = autoProxy:GetPickItemID()
  94. if autoPickItemID then
  95. local target = global.actorManager:GetActor(autoPickItemID)
  96. if target then
  97. target:IgnoreActor(true)
  98. end
  99. end
  100. autoProxy:ClearAutoPick()
  101. autoProxy:SetPickItemFlag(true)
  102. elseif moveType == global.MMO.INPUT_MOVE_TYPE_LAUNCH then
  103. -- 忽略当前目标
  104. local targetID = inputProxy:GetTargetID()
  105. local target = nil
  106. if targetID then
  107. target = global.actorManager:GetActor(targetID)
  108. if target then
  109. if not target:IsPauseIgnored() and not target:IsIngored() then
  110. local isPauseIgnored = false
  111. if target:IsBoss() then
  112. isPauseIgnored = true
  113. end
  114. if isPauseIgnored and autoProxy:IsAutoFightState() and global.PathFindController:checkActorLimitObstacle(cc.p(mainPlayer:GetMapX(), mainPlayer:GetMapY()), cc.p(target:GetMapX(), target:GetMapY())) then
  115. target:PauseIgnoredActor(true)
  116. else
  117. target:IgnoreActor(true)
  118. end
  119. end
  120. end
  121. end
  122. -- clear launch data
  123. if not target or (not target:IsPauseIgnored() and target:IsIngored()) then
  124. autoProxy:ClearAutoLock()
  125. inputProxy:ClearLaunch()
  126. inputProxy:ClearTarget()
  127. end
  128. end
  129. end
  130. -- auto move end
  131. if autoProxy:IsAutoMoveState() then
  132. facade:sendNotification(global.NoticeTable.AutoMoveEnd)
  133. end
  134. return nil
  135. end
  136. local targetID = inputProxy:GetTargetID()
  137. if targetID then
  138. local target = global.actorManager:GetActor(targetID)
  139. if target and target:IsPauseIgnored() then
  140. target:PauseIgnoredActor()
  141. end
  142. end
  143. end
  144. return InputMoveCommand