AutoFightBackCommand.lua 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. --[[
  2. author:yzy
  3. time:2022-02-25 09:52:04
  4. desc: 受攻击后自动反击
  5. ]]
  6. local AutoFightBackCommand = class('AutoFightBackCommand', framework.SimpleCommand)
  7. local proxyUtils = requireProxy("proxyUtils")
  8. function AutoFightBackCommand:ctor()
  9. end
  10. function AutoFightBackCommand:execute(notification)
  11. local data = notification:getBody() or {}
  12. local attackActorID = data.attackActorID
  13. local actorID = data.actorID or global.gamePlayerController:GetMainPlayerID()
  14. local setValues = GET_SETTING(global.MMO.SETTING_IDX_BEDAMAGED_PLAYER, true) -- 被玩家攻击 1不处理 2反击 3逃跑
  15. if not setValues or not setValues[1] or not (setValues[1] == 2 or setValues[1] == 3) then
  16. return
  17. end
  18. if not attackActorID then -- 没有攻击者id
  19. return
  20. end
  21. local attackActor = global.actorManager:GetActor(attackActorID)
  22. if not attackActor then
  23. return
  24. end
  25. local attackMasterID = attackActor:GetMasterID()
  26. if (attackActor:IsHumanoid() or attackActor:IsMonster()) and not (attackMasterID and attackMasterID ~= "") then
  27. return
  28. end
  29. local actor = global.actorManager:GetActor(actorID)
  30. if not actor then
  31. return
  32. end
  33. local HeroPropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroPropertyProxy)
  34. local mainPlayerID = global.gamePlayerController:GetMainPlayerID()
  35. local heroActorID = HeroPropertyProxy:GetRoleUID() or -1
  36. local masterID = actor:GetMasterID() or -1
  37. -- 攻击 我的宠物/元神/主角
  38. if not (masterID == mainPlayerID or actorID == heroActorID or actorID == mainPlayerID) then
  39. return
  40. end
  41. local mainPlayer = global.gamePlayerController:GetMainPlayer()
  42. if not mainPlayer then
  43. return
  44. end
  45. -- 挂机
  46. local AutoProxy = global.Facade:retrieveProxy(global.ProxyTable.Auto)
  47. if not AutoProxy:IsAFKState() and not AutoProxy:IsAutoFightState() then
  48. return
  49. end
  50. local PlayerInputProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  51. if setValues[1] == 2 then
  52. local attackBackID = nil -- 要反击的对象id
  53. if attackMasterID and attackMasterID ~= "" then
  54. local attackActorMaster = global.actorManager:GetActor(attackMasterID)
  55. local value = GET_SETTING(global.MMO.SETTING_IDX_FIRST_ATTACK_MASTER) -- 优先打主人
  56. if attackActorMaster and value[1] == 1 and attackActorMaster:IsPlayer() and not attackActorMaster:IsHumanoid() then
  57. attackBackID = attackMasterID
  58. end
  59. end
  60. if not attackBackID then
  61. attackBackID = attackActorID
  62. end
  63. local hateID = mainPlayer:GetHateID()
  64. if hateID and global.actorManager:GetActor(hateID) then
  65. return
  66. end
  67. -- 没仇恨对象
  68. PlayerInputProxy:ClearAttackTargetID()
  69. PlayerInputProxy:ClearTarget()
  70. PlayerInputProxy:ClearMove()
  71. PlayerInputProxy:SetTargetID(attackBackID)
  72. mainPlayer:SetHateID(attackBackID)
  73. -- 攻击者必须是玩家 不是我的宠物/元神/主角
  74. elseif setValues[1] == 3 and (not attackActor:IsPlayer() or not attackActor:IsMainPlayer()) and attackMasterID ~= mainPlayerID then
  75. PlayerInputProxy:ClearAttackTargetID()
  76. PlayerInputProxy:ClearTarget()
  77. PlayerInputProxy:SetTargetID(nil)
  78. local AssistProxy = global.Facade:retrieveProxy(global.ProxyTable.AssistProxy)
  79. AssistProxy:checkAimlessMove()
  80. end
  81. end
  82. return AutoFightBackCommand