BehaviorMove.lua 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. local Behavior = require("bt/Behavior")
  2. local BehaviorMove = class("BehaviorMove", Behavior)
  3. local facade = global.Facade
  4. local BehaviorConfig = global.BehaviorConfig
  5. local function checkAbleToWalk(nextPoint)
  6. return global.PathFindController:checkAbleToWalk(nextPoint)
  7. end
  8. local function checkOverTarget(nextPoint)
  9. local inputProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  10. -- launch only
  11. local moveType = inputProxy:GetCurrMoveType()
  12. if moveType ~= global.MMO.INPUT_MOVE_TYPE_LAUNCH then
  13. return false
  14. end
  15. -- can't find target
  16. local targetID = inputProxy:GetTargetID()
  17. local target = global.actorManager:GetActor(targetID)
  18. if not target then
  19. return false
  20. end
  21. if nextPoint.x == target:GetMapX() and nextPoint.y == target:GetMapY() then
  22. return true
  23. end
  24. return false
  25. end
  26. function BehaviorMove:ctor(data)
  27. BehaviorMove.super.ctor(self, data)
  28. end
  29. function BehaviorMove:getType()
  30. return BehaviorConfig.BehaviorType.BehaviorMove
  31. end
  32. function BehaviorMove:update(player, actCompleted)
  33. local player = global.gamePlayerController:GetMainPlayer()
  34. local inputProxy = facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  35. local autoProxy = facade:retrieveProxy(global.ProxyTable.Auto)
  36. if inputProxy:IsLaunchDirty() then
  37. return BehaviorConfig.BTSTATUS_Failure
  38. end
  39. if not inputProxy:IsMovePermission() then
  40. return BehaviorConfig.BTSTATUS_Failure
  41. end
  42. if player:IsHoreseCopilot() then
  43. return BehaviorConfig.BTSTATUS_Failure
  44. end
  45. if inputProxy:GetLaunchNoWalkPos() then
  46. inputProxy:SetLaunchNoWalkPos(nil)
  47. end
  48. local isHandMove = false
  49. local isRunOne = false
  50. -- 点地板
  51. local touchPos = inputProxy:GetMouseTouchPos()
  52. local touchWay = inputProxy:GetMouseTouchWay()
  53. if touchPos and touchPos.x ~= 0 and touchPos.y ~= 0 and touchWay and (touchPos.x ~= player:GetMapX() or touchPos.y ~= player:GetMapY()) then
  54. GUIFunction:ClickMapGroundMoveFunc(touchPos, touchWay)
  55. if CHECK_SERVER_OPTION(global.MMO.SERVER_RUN_ONE) then
  56. isRunOne = touchWay == -1
  57. end
  58. isHandMove = true
  59. end
  60. -- 摇杆
  61. if not global.isWinPlayMode and not isHandMove then
  62. GUIFunction:OnGamePadMoveFunc()
  63. local moveDir, moveStep = SL:GetMetaValue("GAMEPAD_MOVE_PARAM")
  64. isHandMove = isHandMove or moveDir ~= 0xff
  65. if CHECK_SERVER_OPTION(global.MMO.SERVER_RUN_ONE) then
  66. isRunOne = isRunOne or moveStep == 2
  67. end
  68. end
  69. local targetID = inputProxy:GetTargetID()
  70. if not isHandMove and not targetID and (autoProxy:IsAutoFightState() or autoProxy:IsAutoMoveState()) then
  71. -- 背包满等待
  72. local bagProxy = global.Facade:retrieveProxy(global.ProxyTable.Bag)
  73. if bagProxy:IsBagFullWait() then
  74. inputProxy:ClearMove()
  75. global.Facade:sendNotification(global.NoticeTable.ActorEnterIdleAction, {actor = player})
  76. return BehaviorConfig.BTSTATUS_Failure
  77. end
  78. end
  79. -- move to next point
  80. local currPathPoint = inputProxy:GetCurrPathPoint()
  81. if currPathPoint == 0 then
  82. if actCompleted == global.MMO.ACTION_WALK or actCompleted == global.MMO.ACTION_RUN or actCompleted == global.MMO.ACTION_RIDE_RUN then
  83. global.Facade:sendNotification(global.NoticeTable.ActorEnterIdleAction, {actor = player})
  84. self:onMoveFinished(player, actCompleted)
  85. end
  86. return BehaviorConfig.BTSTATUS_Failure
  87. end
  88. local pathPoints = inputProxy:GetPathFindPoints()
  89. local nextPoint, moveStep = global.PathFindController:checkNextMovePos(player, pathPoints, currPathPoint)
  90. if nextPoint then
  91. -- can launch
  92. if checkOverTarget(nextPoint) then
  93. inputProxy:ClearMove()
  94. global.Facade:sendNotification(global.NoticeTable.ActorEnterIdleAction, {actor = player})
  95. return BehaviorConfig.BTSTATUS_Failure
  96. end
  97. --判断是否在禁锢区
  98. local sceneImprisonEffectProxy = global.Facade:retrieveProxy(global.ProxyTable.SceneImprisonEffectProxy)
  99. if sceneImprisonEffectProxy:CheckImprison(nextPoint.x, nextPoint.y) then
  100. global.Facade:sendNotification(global.NoticeTable.ActorEnterIdleAction, {actor = player})
  101. return BehaviorConfig.BTSTATUS_Failure
  102. end
  103. if not isHandMove and moveStep == 1 and CHECK_SERVER_OPTION(global.MMO.SERVER_RUN_ONE) then
  104. isRunOne = true
  105. end
  106. -- walk, check next point has player/monster/npc
  107. if not isRunOne and moveStep == 1 then
  108. if not checkAbleToWalk(nextPoint) then
  109. -- record move blocked
  110. inputProxy:SetIsMoveBlocked(true)
  111. local moveType = inputProxy:GetCurrMoveType()
  112. -- move crowded
  113. if autoProxy:IsAFKState() then
  114. if moveType == global.MMO.INPUT_MOVE_TYPE_FINDITEM then
  115. -- 忽略当前拾取物
  116. local autoPickItemID = autoProxy:GetPickItemID()
  117. if autoPickItemID then
  118. local target = global.actorManager:GetActor(autoPickItemID)
  119. if target then
  120. target:IgnoreActor(true)
  121. end
  122. end
  123. autoProxy:ClearAutoPick()
  124. autoProxy:SetPickItemFlag(true)
  125. elseif moveType == global.MMO.INPUT_MOVE_TYPE_LAUNCH then
  126. -- 忽略
  127. if actCompleted == global.MMO.ACTION_WALK or actCompleted == global.MMO.ACTION_RUN or actCompleted == global.MMO.ACTION_RIDE_RUN then
  128. else
  129. local targetID = inputProxy:GetTargetID()
  130. local target = nil
  131. if targetID then
  132. target = global.actorManager:GetActor(targetID)
  133. if target then
  134. if not target:IsPauseIgnored() and not target:IsIngored() then
  135. local isPauseIgnored = false
  136. if target:IsBoss() then
  137. isPauseIgnored = true
  138. end
  139. if isPauseIgnored and autoProxy:IsAutoFightState() and global.PathFindController:checkActorLimitObstacle(cc.p(player:GetMapX(), player:GetMapY()), cc.p(target:GetMapX(), target:GetMapY())) then
  140. target:PauseIgnoredActor(true)
  141. else
  142. target:IgnoreActor(true)
  143. end
  144. end
  145. end
  146. end
  147. -- clear launch data
  148. if not target or (not target:IsPauseIgnored() and target:IsIngored()) then
  149. autoProxy:ClearAutoLock()
  150. inputProxy:ClearLaunch()
  151. inputProxy:ClearTarget()
  152. end
  153. end
  154. end
  155. inputProxy:ClearMove()
  156. global.Facade:sendNotification(global.NoticeTable.ActorEnterIdleAction, {actor = player})
  157. else
  158. inputProxy:ClearMove()
  159. global.Facade:sendNotification(global.NoticeTable.ActorEnterIdleAction, {actor = player})
  160. global.Facade:sendNotification(global.NoticeTable.ClearAllAutoState)
  161. end
  162. inputProxy:SetLaunchNoWalkPos(nextPoint)
  163. return BehaviorConfig.BTSTATUS_Failure
  164. end
  165. end
  166. local targetID = inputProxy:GetTargetID()
  167. if targetID then
  168. local target = global.actorManager:GetActor(targetID)
  169. if target and target:IsPauseIgnored() then
  170. target:PauseIgnoredActor()
  171. end
  172. end
  173. -- move
  174. player:SetKeyValue(global.MMO.IS_RUN_ONE, false)
  175. player:SetMoveTo(nextPoint)
  176. if moveStep == 3 then
  177. player:SetAction( global.MMO.ACTION_RIDE_RUN )
  178. elseif moveStep == 2 then
  179. player:SetAction( global.MMO.ACTION_RUN )
  180. else
  181. local act = global.MMO.ACTION_WALK
  182. if player:GetValueByKey(global.MMO.ACT_SNEAK) then
  183. act = global.MMO.ACTION_ASSASSIN_SNEAK
  184. elseif isRunOne then
  185. act = global.MMO.ACTION_RUN
  186. player:SetKeyValue(global.MMO.IS_RUN_ONE, true)
  187. end
  188. player:SetAction( act )
  189. end
  190. if currPathPoint - moveStep == 0 and not autoProxy:IsAFKState() then
  191. inputProxy:ClearMove()
  192. end
  193. inputProxy:SetCurrPathPoint(currPathPoint - moveStep)
  194. inputProxy:SetIsMoveBlocked(false)
  195. return BehaviorConfig.BTSTATUS_Running
  196. else
  197. -- move failed
  198. inputProxy:ClearMove()
  199. global.Facade:sendNotification(global.NoticeTable.ActorEnterIdleAction, {actor = player})
  200. --
  201. if not autoProxy:GetAutoTargetInterruptFlag() then
  202. if autoProxy:IsAutoFightState() or autoProxy:IsAutoMoveState() then
  203. autoProxy:PauseAutoTarget()
  204. autoProxy:ResumeAutoTarget()
  205. end
  206. end
  207. return BehaviorConfig.BTSTATUS_Failure
  208. end
  209. return BehaviorConfig.BTSTATUS_Failure
  210. end
  211. function BehaviorMove:onMoveFinished()
  212. local autoProxy = global.Facade:retrieveProxy(global.ProxyTable.Auto)
  213. -- auto move end
  214. if autoProxy:IsMoveCompleted() and autoProxy:IsAutoMoveState() then
  215. facade:sendNotification(global.NoticeTable.AutoMoveEnd)
  216. end
  217. end
  218. return BehaviorMove