AutoMoveBeginCommand.lua 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. local AutoMoveBeginCommand = class('AutoMoveBeginCommand', framework.SimpleCommand)
  2. function AutoMoveBeginCommand:ctor()
  3. end
  4. function AutoMoveBeginCommand:execute(notification)
  5. local facade = global.Facade
  6. local data = notification:getBody()
  7. print("---------------------- auto move begin")
  8. local mapProxy = facade:retrieveProxy(global.ProxyTable.Map)
  9. local autoProxy = facade:retrieveProxy(global.ProxyTable.Auto)
  10. local inputProxy = facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  11. local destMapID = data.mapID or mapProxy:GetMapID()
  12. local destX = data.x
  13. local destY = data.y
  14. local priority = data.priority or global.MMO.INPUT_PRIORITY_SYSTEM
  15. local autoMoveType = data.autoMoveType or global.MMO.AUTO_MOVE_TYPE_TARGET
  16. -- check param error
  17. if nil == destX or nil == destY then
  18. return nil
  19. end
  20. if destMapID ~= mapProxy:GetMapID() then
  21. return nil
  22. end
  23. -- clear state
  24. facade:sendNotification(global.NoticeTable.ClearAllInputState)
  25. facade:sendNotification(global.NoticeTable.ClearAllAutoState)
  26. facade:sendNotification(global.NoticeTable.InputIdle)
  27. autoProxy:ClearAutoLock()
  28. autoProxy:ClearAllState()
  29. autoProxy:ClearAFKState()
  30. autoProxy:ClearPickState()
  31. -- mark auto move state
  32. autoProxy:SetIsAutoMoveState(true)
  33. autoProxy:SetAutoInputPriority(priority)
  34. -- check auto target
  35. data.targetType = data.targetType or global.MMO.ACTOR_NONE
  36. data.targetIndex = data.targetIndex or global.MMO.AUTO_FIND_TARGET_NONE
  37. autoProxy:SetAutoTarget(data)
  38. -- check auto find target
  39. local fixRange = nil
  40. if data.targetType ~= global.MMO.ACTOR_NONE then
  41. -- fix move by target type
  42. if global.MMO.ACTOR_NPC == data.targetType then
  43. fixRange = SL:GetMetaValue("GAME_DATA","AutoMoveRange_NPC")
  44. elseif global.MMO.ACTOR_MONSTER == data.targetType then
  45. fixRange = SL:GetMetaValue("GAME_DATA","AutoMoveRange_Monster")
  46. elseif global.MMO.ACTOR_COLLECTION == data.targetType then
  47. fixRange = SL:GetMetaValue("GAME_DATA","AutoMoveRange_Collection")
  48. end
  49. end
  50. if data.autoMoveType == global.MMO.AUTO_MOVE_TYPE_CHAT then
  51. fixRange = 2
  52. end
  53. -- tips
  54. SLBridge:onLUAEvent(LUA_EVENT_AUTOMOVE_TIPS_SHOW, true)
  55. SLBridge:onLUAEvent(LUA_EVENT_AUTOMOVEBEGIN, {mapID = destMapID, x = destX, y = destY})
  56. ssr.ssrBridge:OnAutoMoveBegin({mapID = destMapID, x = destX, y = destY})
  57. -- push last
  58. autoProxy:PushMove({mapID = destMapID, x = destX, y = destY, range = fixRange})
  59. -- input front move pos
  60. local movePos = autoProxy:PopMove()
  61. facade:sendNotification(global.NoticeTable.InputMove, movePos)
  62. -- auto target state:begin
  63. autoProxy:SetTargetState(global.MMO.AUTO_TARGET_STATE_BEGIN)
  64. -- 通知服务器
  65. local autoTarget = autoProxy:GetAutoTarget()
  66. if autoTarget.autoMoveType == global.MMO.AUTO_MOVE_TYPE_MINIMAP or autoTarget.autoMoveType == global.MMO.AUTO_MOVE_TYPE_SERVER then
  67. if inputProxy:GetPathPointSize() > 0 then
  68. autoProxy:RequestAutoMoveNotify(global.MMO.AUTO_MOVE_START, destX, destY)
  69. end
  70. end
  71. end
  72. return AutoMoveBeginCommand