AutoFindSkillBehavior.lua 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. local AutoFindBehavior = require("auto_behavior/AutoFindBehavior")
  2. local AutoFindSkillBehavior = class("AutoFindSkillBehavior", AutoFindBehavior)
  3. local skillUtils = requireProxy("skillUtils")
  4. local proxyUtils = requireProxy("proxyUtils")
  5. function AutoFindSkillBehavior:ctor()
  6. AutoFindSkillBehavior.super.ctor(self)
  7. end
  8. function AutoFindSkillBehavior:update(player, actCompleted)
  9. if self:checkLaunchFirstSkill() then
  10. return true
  11. end
  12. if self:checkLaunchComboSkill() then
  13. return true
  14. end
  15. if self:checkLaunchAutoSkill() then
  16. return true
  17. end
  18. if self:checkLaunchSimpleSkill() then
  19. return true
  20. end
  21. if self:checkLaunchLockSkill() then
  22. return true
  23. end
  24. if self:checkAutoMining(player) then
  25. return true
  26. end
  27. return false
  28. end
  29. function AutoFindSkillBehavior:checkLaunchFirstSkill()
  30. local inputProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  31. if not inputProxy:GetTargetID() then
  32. return false
  33. end
  34. if inputProxy:GetLaunchSkillID() then
  35. return false
  36. end
  37. local autoProxy = global.Facade:retrieveProxy(global.ProxyTable.Auto)
  38. if not inputProxy:IsAttackState() and not autoProxy:IsAutoLockState() and not autoProxy:IsAFKState() and
  39. not autoProxy:IsAutoFightState() then
  40. return false
  41. end
  42. local skillID, destPos = skillUtils.findFirstLaunchSkill()
  43. if not skillID then
  44. return false
  45. end
  46. local actorPickerProxy = global.Facade:retrieveProxy(global.ProxyTable.ActorPicker)
  47. local lastMouseInsideActor = actorPickerProxy:GetLastMouseInsideActor()
  48. local launchData = {
  49. skillID = skillID,
  50. destPos = destPos,
  51. priority = inputProxy:GetLaunchPriority(),
  52. launchType = inputProxy:GetLaunchType(),
  53. targetID = lastMouseInsideActor or inputProxy:GetTargetID()
  54. }
  55. global.Facade:sendNotification(global.NoticeTable.InputLaunch, launchData)
  56. return true
  57. end
  58. function AutoFindSkillBehavior:checkLaunchAutoSkill()
  59. local autoProxy = global.Facade:retrieveProxy(global.ProxyTable.Auto)
  60. if not autoProxy:IsAFKState() and not autoProxy:IsAutoFightState() then
  61. return false
  62. end
  63. local inputProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  64. if inputProxy:GetLaunchSkillID() then
  65. return false
  66. end
  67. local targetID = inputProxy:GetTargetID()
  68. if not targetID then
  69. return false
  70. end
  71. if not proxyUtils.checkLaunchTargetByID(targetID) then
  72. inputProxy:ClearTarget()
  73. return false
  74. end
  75. -- 挂机目标死亡,原地等待一段时间
  76. if autoProxy:GetAFKTargetDeath() then
  77. return true
  78. end
  79. local targetActor = global.actorManager:GetActor(targetID)
  80. if not targetActor then
  81. inputProxy:ClearTarget()
  82. return true
  83. end
  84. -- 闪避技能
  85. local skillID, destPos = skillUtils.findAvoidDangerSkill(targetActor, targetID)
  86. if skillID then
  87. autoProxy:ResetLaunchAvoidStamp()
  88. else
  89. -- 自动释放技能
  90. skillID, destPos = skillUtils.findAutoLaunchSkill(targetActor, targetID)
  91. end
  92. if skillID then
  93. local launchData = {
  94. skillID = skillID,
  95. destPos = destPos,
  96. priority = global.MMO.LAUNCH_PRIORITY_SYSTEM,
  97. launchType = global.MMO.LAUNCH_TYPE_AUTO,
  98. targetID = targetID
  99. }
  100. global.Facade:sendNotification(global.NoticeTable.InputLaunch, launchData)
  101. return true
  102. end
  103. -- 闪避走位
  104. destPos = skillUtils.findAvoidDangerPos()
  105. if destPos then
  106. local mapProxy = global.Facade:retrieveProxy(global.ProxyTable.Map)
  107. local mapID = mapProxy:GetMapID()
  108. local movePos = {
  109. mapID = mapID,
  110. x = destPos.x,
  111. y = destPos.y,
  112. type = global.MMO.INPUT_MOVE_TYPE_AUTOMOVE
  113. }
  114. global.Facade:sendNotification(global.NoticeTable.InputMove, movePos)
  115. return true
  116. end
  117. return false
  118. end
  119. function AutoFindSkillBehavior:checkLaunchComboSkill()
  120. local inputProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  121. if not inputProxy:GetTargetID() then
  122. return false
  123. end
  124. if inputProxy:GetLaunchSkillID() then
  125. return false
  126. end
  127. local autoProxy = global.Facade:retrieveProxy(global.ProxyTable.Auto)
  128. local isAttackState = global.isWinPlayMode and inputProxy:IsAttackState() or false
  129. if not isAttackState and not autoProxy:IsAutoLockState() and not autoProxy:IsAFKState() and
  130. not autoProxy:IsAutoFightState() then
  131. return false
  132. end
  133. local skillID, destPos, isAuto = skillUtils.findComboLaunchSkill()
  134. if not skillID then
  135. return false
  136. end
  137. local launchData = {
  138. skillID = skillID,
  139. destPos = destPos,
  140. priority = global.MMO.LAUNCH_PRIORITY_SYSTEM,
  141. launchType = isAuto and global.MMO.LAUNCH_TYPE_AUTO or global.MMO.LAUNCH_TYPE_USER,
  142. targetID = inputProxy:GetTargetID()
  143. }
  144. global.Facade:sendNotification(global.NoticeTable.InputLaunch, launchData)
  145. return true
  146. end
  147. function AutoFindSkillBehavior:checkLaunchSimpleSkill()
  148. local inputProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  149. if inputProxy:GetLaunchSkillID() then
  150. return false
  151. end
  152. local targetID = inputProxy:GetTargetID()
  153. if not targetID then
  154. return false
  155. end
  156. local autoProxy = global.Facade:retrieveProxy(global.ProxyTable.Auto)
  157. if not autoProxy:IsAutoLockState() then
  158. return false
  159. end
  160. if not proxyUtils.checkLaunchTargetByID(targetID) then
  161. inputProxy:ClearTarget()
  162. return false
  163. end
  164. local targetActor = global.actorManager:GetActor(targetID)
  165. if not targetActor then
  166. inputProxy:ClearTarget()
  167. return false
  168. end
  169. if CHECK_SETTING(global.MMO.SETTING_IDX_ALWAYS_ATTACK) ~= 1 then
  170. return false
  171. end
  172. local skillID, destPos = skillUtils.findSimpleLaunchSkill()
  173. if skillID then
  174. local launchData = {
  175. skillID = skillID,
  176. destPos = destPos,
  177. priority = global.MMO.LAUNCH_PRIORITY_SYSTEM,
  178. launchType = global.MMO.LAUNCH_TYPE_LOCK,
  179. targetID = targetID
  180. }
  181. global.Facade:sendNotification(global.NoticeTable.InputLaunch, launchData)
  182. return true
  183. end
  184. return false
  185. end
  186. function AutoFindSkillBehavior:checkLaunchLockSkill()
  187. -- shift锁定
  188. if not global.isWinPlayMode then
  189. return false
  190. end
  191. local inputProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  192. -- 不在锁定攻击状态
  193. if not inputProxy:IsAttackState() then
  194. return false
  195. end
  196. local targetID = inputProxy:GetAttackTargetID()
  197. if not targetID then
  198. return false
  199. end
  200. local targetActor = global.actorManager:GetActor(targetID)
  201. if not targetActor then
  202. inputProxy:ClearAttackTargetID()
  203. return false
  204. end
  205. local optionAble = CHECK_SETTING(global.MMO.SETTING_IDX_NOT_NEED_SHIFT) == 1
  206. local shiftAble = global.userInputController:IsPressedShift()
  207. if (targetActor:IsPlayer() and (optionAble or shiftAble)) or targetActor:IsMonster() then
  208. -- 骑马检测
  209. local HorseProxy = global.Facade:retrieveProxy(global.ProxyTable.HorseProxy)
  210. if not HorseProxy:IsLaunch(global.MMO.SKILL_INDEX_BASIC) then
  211. if not HorseProxy:RequestHorseDown() then
  212. inputProxy:SetAttackState(false)
  213. end
  214. return false
  215. end
  216. local skillID, destPos = skillUtils.findLockLaunchSkill()
  217. if skillID then
  218. local launchData = {
  219. skillID = skillID,
  220. destPos = destPos,
  221. priority = global.MMO.LAUNCH_PRIORITY_SYSTEM,
  222. launchType = global.MMO.LAUNCH_TYPE_LOCK,
  223. targetID = targetID
  224. }
  225. global.Facade:sendNotification(global.NoticeTable.InputLaunch, launchData)
  226. end
  227. return true
  228. end
  229. return false
  230. end
  231. function AutoFindSkillBehavior:checkAutoMining()
  232. local autoProxy = global.Facade:retrieveProxy(global.ProxyTable.Auto)
  233. if autoProxy:IsAutoFightState() then
  234. return false
  235. end
  236. local autoMiningDir, autoMiningDst = autoProxy:GetAutoMining()
  237. if not autoMiningDir or not autoMiningDst then
  238. return false
  239. end
  240. local inputProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  241. if not inputProxy:CheckMiningAble() then
  242. autoProxy:ClearAutoMining()
  243. return false
  244. end
  245. local miningData = {
  246. dir = autoMiningDir,
  247. dest = autoMiningDst
  248. }
  249. global.Facade:sendNotification(global.NoticeTable.InputMining, miningData)
  250. return true
  251. end
  252. return AutoFindSkillBehavior