AutoFindActorBehavior.lua 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. local AutoFindBehavior = require("auto_behavior/AutoFindBehavior")
  2. local AutoFindActorBehavior = class("AutoFindActorBehavior", AutoFindBehavior)
  3. local proxyUtils = requireProxy("proxyUtils")
  4. function AutoFindActorBehavior:ctor()
  5. AutoFindActorBehavior.super.ctor(self)
  6. end
  7. function AutoFindActorBehavior:update(player, actCompleted)
  8. -- body
  9. if self:checkAutoPick() then
  10. return true
  11. end
  12. if self:checkAutoFindDropItem() then
  13. return true
  14. end
  15. if self:checkAutoFindTarget(player, actCompleted) then
  16. return true
  17. end
  18. return false
  19. end
  20. -- 检测拾取
  21. function AutoFindActorBehavior:isCanPick()
  22. -- 背包满等待
  23. local bagProxy = global.Facade:retrieveProxy(global.ProxyTable.Bag)
  24. if bagProxy:IsBagFullWait() then
  25. return false
  26. end
  27. local inputProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  28. local autoProxy = global.Facade:retrieveProxy(global.ProxyTable.Auto)
  29. if not inputProxy:IsMoving() then
  30. if autoProxy:GetPickItemID() then
  31. autoProxy:CheckPickTimeout()
  32. return true
  33. end
  34. end
  35. if nil == autoProxy:GetPickItemID() then
  36. global.Facade:sendNotification(global.NoticeTable.AutoFindDropItem)
  37. end
  38. if -1 == global.PathFindController:CheckNextMovePosAble() then
  39. autoProxy:SetPickItemID(nil)
  40. return false
  41. end
  42. if autoProxy:GetPickItemID() then
  43. return true
  44. end
  45. return false
  46. end
  47. -- 是否在自动拾取ing
  48. function AutoFindActorBehavior:checkAutoPick()
  49. local autoProxy = global.Facade:retrieveProxy(global.ProxyTable.Auto)
  50. if not autoProxy:IsPickState() then
  51. return false
  52. end
  53. return self:isCanPick()
  54. end
  55. -- 查找掉落物
  56. function AutoFindActorBehavior:checkAutoFindDropItem()
  57. local autoProxy = global.Facade:retrieveProxy(global.ProxyTable.Auto)
  58. if not autoProxy:IsAFKState() and not autoProxy:IsAutoFightState() then
  59. return false
  60. end
  61. if not autoProxy:IsCanAutoPick() then
  62. return false
  63. end
  64. -- 内挂 范围内是否有足够怪物
  65. if proxyUtils:checkIsEnoughMonster() then
  66. return false
  67. end
  68. -- 小精灵 如果是一个个拾取模式 需要放弃去拾取
  69. if proxyUtils:checkIsPlayerAbandonPickup() then
  70. return false
  71. end
  72. return self:isCanPick()
  73. end
  74. function AutoFindActorBehavior:checkAutoFindTarget(player, actCompleted)
  75. if actCompleted ~= global.MMO.ACTION_IDLE then
  76. return false
  77. end
  78. local autoProxy = global.Facade:retrieveProxy(global.ProxyTable.Auto)
  79. if not autoProxy:IsAFKState() and not autoProxy:IsAutoFightState() then
  80. return false
  81. end
  82. if autoProxy:GetAutoTargetInterruptFlag() then
  83. return false
  84. end
  85. local inputProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  86. if inputProxy:GetTargetID() then
  87. return false
  88. end
  89. -- 1.find current target
  90. local needTerminate = false
  91. local targetType = autoProxy:GetTargetType()
  92. if global.MMO.ACTOR_NPC == targetType then
  93. global.Facade:sendNotification(global.NoticeTable.AutoFindNPC)
  94. if inputProxy:GetTargetID() then
  95. needTerminate = true
  96. end
  97. elseif global.MMO.ACTOR_MONSTER == targetType or global.MMO.ACTOR_PLAYER == targetType or attackF1 then
  98. global.Facade:sendNotification(global.NoticeTable.AutoFindPlayer)
  99. elseif global.MMO.ACTOR_COLLECTION == targetType then
  100. global.Facade:sendNotification(global.NoticeTable.AutoFindCollection)
  101. if inputProxy:GetTargetID() then
  102. needTerminate = true
  103. end
  104. end
  105. return needTerminate
  106. end
  107. return AutoFindActorBehavior