BuffEntitySneak.lua 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. local BuffEntityAnim = require("buff/BuffEntityAnim")
  2. local BuffEntitySneak = class("BuffEntitySneak", BuffEntityAnim)
  3. local optionsUtils = requireProxy("optionsUtils")
  4. function BuffEntitySneak:ctor(data)
  5. BuffEntitySneak.super.ctor(self, data)
  6. self._isSneak = false --潜行状态
  7. self._range = 2 --范围内显示
  8. end
  9. function BuffEntitySneak:OnEnter()
  10. BuffEntitySneak.super.OnEnter(self)
  11. local actor = global.actorManager:GetActor(self._actorID)
  12. if not actor then
  13. return false
  14. end
  15. actor:SetKeyValue(global.MMO.ACT_SNEAK, true)
  16. local isSneak = self:CheckSneak()
  17. if self._isSneak ~= isSneak then
  18. self._isSneak = isSneak
  19. if isSneak then
  20. self:SneakActor()
  21. else
  22. self:UnSneakActor()
  23. end
  24. end
  25. global.BuffManager:AddHandleOnMainActBegin(self._actorID, handler(self, self.OnMainPlayerHandle))
  26. end
  27. function BuffEntitySneak:OnExit()
  28. BuffEntitySneak.super.OnExit(self)
  29. local actor = global.actorManager:GetActor(self._actorID)
  30. if not actor then
  31. return false
  32. end
  33. actor:SetKeyValue(global.MMO.ACT_SNEAK, false)
  34. self:UnSneakActor()
  35. global.BuffManager:RemoveHandleOnMainActBegin(self._actorID)
  36. end
  37. function BuffEntitySneak:CheckSneak()
  38. local actor = global.actorManager:GetActor(self._actorID)
  39. if not actor then
  40. return false
  41. end
  42. if actor:IsPlayer() and actor:IsMainPlayer() then
  43. return false
  44. end
  45. local mainPlayer = global.gamePlayerController:GetMainPlayer()
  46. if not mainPlayer then
  47. return false
  48. end
  49. local mainPlayerPos = cc.p(mainPlayer:GetMapX(), mainPlayer:GetMapY())
  50. local actorPos = cc.p(actor:GetMapX(), actor:GetMapY())
  51. if cc.pGetDistance(actorPos, mainPlayerPos) > self._range then
  52. return true
  53. end
  54. return false
  55. end
  56. function BuffEntitySneak:OnMainPlayerHandle(actor, act)
  57. local isSneak = self:CheckSneak()
  58. if self._isSneak ~= isSneak then
  59. self._isSneak = isSneak
  60. if isSneak then
  61. self:SneakActor()
  62. else
  63. self:UnSneakActor()
  64. end
  65. end
  66. end
  67. function BuffEntitySneak:SneakActor()
  68. local actor = global.actorManager:GetActor(self._actorID)
  69. if not actor then
  70. return false
  71. end
  72. if not actor:IsPlayer() then
  73. return false
  74. end
  75. -- 判断目标是否是潜行者,如果是,就清理目标
  76. local PlayerInputProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  77. if PlayerInputProxy:GetTargetID() == self._actorID then
  78. PlayerInputProxy:ClearTarget()
  79. end
  80. actor:SetKeyValue(global.MMO.HUD_SNEAK, true)
  81. actor:GetNode():setVisible(false)
  82. -- Hp、Mp
  83. optionsUtils:refreshHUDHMpLabelVisible(actor)
  84. -- 血条
  85. optionsUtils:CheckHUDHpBarVisible(actor)
  86. -- 蓝条
  87. optionsUtils:CheckHUDMpBarVisible(actor)
  88. -- 内功条
  89. optionsUtils:CheckHUDNGBarVisible(actor)
  90. -- 人名、行会、称号、顶戴
  91. optionsUtils:refreshLabelVisible(actor)
  92. optionsUtils:refreshPlayerVisible(actor)
  93. optionsUtils:refreshPlayerBVisible(actor)
  94. -- 身上的特效
  95. global.ActorEffectManager:RefreshActorEffectVisible(self._actorID, false)
  96. -- 身上的buff特效
  97. global.BuffManager:UpdateBuffItemVisible(self._actorID, false)
  98. -- 刷新附近
  99. global.Facade:sendNotification(global.NoticeTable.Layer_MainNear_Refresh, {actor = actor, actorID = self._actorID})
  100. -- 刷新灯光
  101. local lightID = actor:GetLightID()
  102. if lightID and not actor:IsMainPlayer() then
  103. local lightData = global.darkNodeManager:getNodeByLightID(lightID)
  104. if lightData then
  105. local DarkLayerProxy = global.Facade:retrieveProxy(global.ProxyTable.DarkLayerProxy)
  106. local darkSneak = DarkLayerProxy.LIGHT_TYPE.Sneak
  107. global.darkNodeManager:updateNode(lightID, {r = darkSneak.r, w = darkSneak.w, isLast = true})
  108. end
  109. end
  110. -- 刷新小地图点
  111. global.Facade:sendNotification(global.NoticeTable.MainMiniMap_Actor_Point_Update, {actor = actor})
  112. end
  113. function BuffEntitySneak:UnSneakActor()
  114. local actor = global.actorManager:GetActor(self._actorID)
  115. if not actor then
  116. return false
  117. end
  118. if not actor:IsPlayer() then
  119. return false
  120. end
  121. actor:SetKeyValue(global.MMO.HUD_SNEAK, false)
  122. actor:GetNode():setVisible(true)
  123. actor:dirtyAnimFlag()
  124. -- 清理选中目标
  125. local inputProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  126. if inputProxy:GetTargetID() == self._actorID then
  127. inputProxy:ClearTarget()
  128. end
  129. -- Hp、Mp
  130. optionsUtils:refreshHUDHMpLabelVisible(actor)
  131. -- 血条
  132. optionsUtils:CheckHUDHpBarVisible(actor)
  133. -- 蓝条
  134. optionsUtils:CheckHUDMpBarVisible(actor)
  135. -- 内功条
  136. optionsUtils:CheckHUDNGBarVisible(actor)
  137. -- 人名、行会、称号、顶戴
  138. optionsUtils:refreshLabelVisible(actor)
  139. optionsUtils:refreshPlayerVisible(actor)
  140. optionsUtils:refreshPlayerBVisible(actor)
  141. -- 身上的特效
  142. global.ActorEffectManager:RefreshActorEffectVisible(self._actorID, true)
  143. -- 身上的buff特效
  144. global.BuffManager:UpdateBuffItemVisible(self._actorID, true)
  145. -- 刷新附近
  146. global.Facade:sendNotification(global.NoticeTable.Layer_MainNear_Refresh, {actor = actor, actorID = self._actorID})
  147. local lightID = actor:GetLightID()
  148. if lightID and not actor:IsMainPlayer() then
  149. local lightData = global.darkNodeManager:getNodeByLightID(lightID)
  150. if lightData then
  151. global.darkNodeManager:updateNode(lightID, {r = lightData.last_r, w = lightData.last_w})
  152. end
  153. end
  154. -- 刷新小地图点
  155. global.Facade:sendNotification(global.NoticeTable.MainMiniMap_Actor_Point_Update, {actor = actor})
  156. end
  157. function BuffEntitySneak:setPosition(x, y)
  158. BuffEntitySneak.super.setPosition(self, x, y)
  159. local isSneak = self:CheckSneak()
  160. if self._isSneak ~= isSneak then
  161. self._isSneak = isSneak
  162. if isSneak then
  163. self:SneakActor()
  164. else
  165. self:UnSneakActor()
  166. end
  167. end
  168. end
  169. return BuffEntitySneak