BehaviorSelector.lua 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. local Behavior = require("bt/Behavior")
  2. local BehaviorSelector = class("BehaviorSelector", Behavior)
  3. local BehaviorTurn = require("bt/BehaviorTurn")
  4. local BehaviorMove = require("bt/BehaviorMove")
  5. local BehaviorDig = require("bt/BehaviorDig")
  6. local BehaviorCorpse = require("bt/BehaviorCorpse")
  7. local BehaviorMining = require("bt/BehaviorMining")
  8. local BehaviorLaunch = require("bt/BehaviorLaunch")
  9. local BehaviorKLaunch = require("bt/BehaviorKLaunch")
  10. local proxyUtils = requireProxy("proxyUtils")
  11. local skillUtils = requireProxy("skillUtils")
  12. local facade = global.Facade
  13. local BehaviorConfig = global.BehaviorConfig
  14. local AutoCtlName = "AutoController"
  15. function BehaviorSelector:ctor(data)
  16. BehaviorSelector.super.ctor(self, data)
  17. self._behaviors = {}
  18. end
  19. function BehaviorSelector:Init()
  20. table.insert(self._behaviors, BehaviorKLaunch.new())
  21. table.insert(self._behaviors, BehaviorTurn.new())
  22. table.insert(self._behaviors, BehaviorMove.new())
  23. table.insert(self._behaviors, BehaviorDig.new())
  24. table.insert(self._behaviors, BehaviorCorpse.new())
  25. table.insert(self._behaviors, BehaviorMining.new())
  26. table.insert(self._behaviors, BehaviorLaunch.new())
  27. self._autoCtl = facade:retrieveMediator(AutoCtlName)
  28. end
  29. function BehaviorSelector:process(player, actCompleted)
  30. -- 摆摊
  31. if false == CheckCanDoSomething(true) then
  32. if actCompleted ~= global.MMO.ACTION_IDLE then
  33. facade:sendNotification(global.NoticeTable.ActorEnterIdleAction, {actor = player})
  34. end
  35. return nil
  36. end
  37. -- 野蛮等待
  38. if actCompleted == global.MMO.ACTION_DASH_WAITING then
  39. facade:sendNotification(global.NoticeTable.ActorEnterIdleAction, {actor = player})
  40. return nil
  41. end
  42. -- 野蛮失败
  43. if actCompleted == global.MMO.ACTION_DASH_FAIL then
  44. facade:sendNotification(global.NoticeTable.ActorEnterIdleAction, {actor = player})
  45. return nil
  46. end
  47. -- behavior
  48. local status = BehaviorConfig.BTSTATUS_Failure
  49. local currBehavior = nil
  50. for _, behavior in ipairs(self._behaviors) do
  51. status = behavior:update(player, actCompleted)
  52. if status == BehaviorConfig.BTSTATUS_Success or status == BehaviorConfig.BTSTATUS_Running then
  53. currBehavior = behavior
  54. break
  55. end
  56. end
  57. -- 这儿做个处理,释放技能可能需要走位,不等下一帧,当前帧生效
  58. if currBehavior and currBehavior:getType() == BehaviorConfig.BehaviorType.BehaviorLaunch then
  59. local inputProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  60. local pathPoints = inputProxy:GetCurrPathPoint()
  61. if pathPoints > 0 and inputProxy:GetLaunchSkillID() ~= nil then
  62. local behavior = self._behaviors[3]
  63. status = behavior:update(player, actCompleted)
  64. if status == BehaviorConfig.BTSTATUS_Success or status == BehaviorConfig.BTSTATUS_Running then
  65. currBehavior = behavior
  66. end
  67. end
  68. end
  69. -- auto
  70. if status == BehaviorConfig.BTSTATUS_Failure then
  71. if self._autoCtl then
  72. self._autoCtl:stateBegin(player, actCompleted)
  73. end
  74. end
  75. -- 自动战斗选择后,会产生新的行为,再遍历一次
  76. if status == BehaviorConfig.BTSTATUS_Failure then
  77. for _, behavior in ipairs(self._behaviors) do
  78. status = behavior:update(player, actCompleted)
  79. if status == BehaviorConfig.BTSTATUS_Success or status == BehaviorConfig.BTSTATUS_Running then
  80. currBehavior = behavior
  81. break
  82. end
  83. end
  84. end
  85. -- 这儿做个处理,释放技能可能需要走位,不等下一帧,当前帧生效
  86. if currBehavior and currBehavior:getType() == BehaviorConfig.BehaviorType.BehaviorLaunch then
  87. local inputProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  88. local pathPoints = inputProxy:GetCurrPathPoint()
  89. if pathPoints > 0 and inputProxy:GetLaunchSkillID() ~= nil then
  90. local behavior = self._behaviors[3]
  91. status = behavior:update(player, actCompleted)
  92. if status == BehaviorConfig.BTSTATUS_Success or status == BehaviorConfig.BTSTATUS_Running then
  93. currBehavior = behavior
  94. end
  95. end
  96. end
  97. -- idle
  98. if status == BehaviorConfig.BTSTATUS_Failure then
  99. if actCompleted ~= global.MMO.ACTION_IDLE then
  100. facade:sendNotification(global.NoticeTable.ActorEnterIdleAction, {actor = player})
  101. end
  102. end
  103. end
  104. return BehaviorSelector