BuffEntityAnim.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. local BuffEntity = require("buff/BuffEntity")
  2. local BuffEntityAnim = class("BuffEntityAnim", BuffEntity)
  3. function BuffEntityAnim:ctor(data)
  4. BuffEntityAnim.super.ctor(self, data)
  5. self._rootNodeB = global.sceneGraphCtl:GetSceneNode(global.MMO.NODE_SKILL_BEHIND)
  6. self._rootNodeF = global.sceneGraphCtl:GetSceneNode(global.MMO.NODE_SKILL)
  7. self._sceneAnims = {}
  8. local BuffProxy = global.Facade:retrieveProxy(global.ProxyTable.Buff)
  9. self._sfxOffset = BuffProxy:GetSfxOffset(self._buffID)
  10. self._sfxSpeed = BuffProxy:GetSfxSpeed(self._buffID)
  11. self._unOffset = nil
  12. self._horseOffset = cc.p(0,0)
  13. self._audioID = BuffProxy:GetAudio(self._buffID)
  14. end
  15. function BuffEntityAnim:OnEnter()
  16. BuffEntityAnim.super.OnEnter(self)
  17. self:setVisible( true )
  18. self:updatePosition()
  19. self:PlayBuffAnim()
  20. if self._audioID then
  21. global.Facade:sendNotification( global.NoticeTable.Audio_Play, {type=global.MMO.SND_TYPE_SSR_UI, index=self._audioID} )
  22. end
  23. end
  24. function BuffEntityAnim:OnExit()
  25. BuffEntityAnim.super.OnExit(self)
  26. self:HideAnim()
  27. self:HideAnimStuck()
  28. end
  29. function BuffEntityAnim:PlayBuffAnim()
  30. local buffid = self._buffID
  31. if self._data.replaceId and self._data.replaceId > 0 then
  32. buffid = self._data.replaceId
  33. end
  34. local BuffProxy = global.Facade:retrieveProxy(global.ProxyTable.Buff)
  35. local sfxConfig = BuffProxy:GetBuffSfxByID(buffid)
  36. if sfxConfig then
  37. local playSfx = sfxConfig.play_sfx
  38. if playSfx.sfxID then
  39. local sfxID = playSfx.sfxID
  40. local loop = playSfx.loop
  41. local data =
  42. {
  43. actorID = self._actorID,
  44. sfxID = tonumber(sfxID),
  45. frame = 0,
  46. speed = self._sfxSpeed or 1,
  47. count = loop or 1,
  48. front = true,
  49. offsetX = 0,
  50. offsetY = 0,
  51. }
  52. global.ActorEffectManager:AddEffect(data)
  53. end
  54. end
  55. end
  56. function BuffEntityAnim:ShowAnim(needCheck)
  57. local buffid = self._buffID
  58. if self._data.replaceId and self._data.replaceId > 0 then
  59. buffid = self._data.replaceId
  60. end
  61. local BuffProxy = global.Facade:retrieveProxy(global.ProxyTable.Buff)
  62. local sfxConfig = BuffProxy:GetBuffSfxByID(buffid)
  63. if sfxConfig then
  64. if sfxConfig.front then
  65. local sfxID = sfxConfig.front.sfxID
  66. local loop = sfxConfig.front.loop
  67. local is8dir = sfxConfig.front.is8dir
  68. local dirfollow = sfxConfig.front.dirfollow
  69. self._unOffset = sfxConfig.front.unOffset
  70. self:addBuffSfx(sfxID, true, loop, is8dir, dirfollow)
  71. end
  72. if sfxConfig.behind then
  73. local sfxID = sfxConfig.behind.sfxID
  74. local loop = sfxConfig.behind.loop
  75. local is8dir = sfxConfig.behind.is8dir
  76. local dirfollow = sfxConfig.behind.dirfollow
  77. self:addBuffSfx(sfxID, false, loop, is8dir, dirfollow)
  78. end
  79. end
  80. if needCheck then
  81. local actor = global.actorManager:GetActor(self._actorID)
  82. if not actor then
  83. return
  84. end
  85. if (actor:IsMonster() or actor:IsHumanoid()) and (actor:IsDeath() or actor:IsDie()) then
  86. local isHide = tonumber(SL:GetMetaValue("GAME_DATA", "MonsterDieHideAnim")) == 1
  87. if isHide then
  88. self:HideAnim()
  89. end
  90. end
  91. end
  92. end
  93. function BuffEntityAnim:HideAnim()
  94. local buffid = self._buffID
  95. if self._data.replaceId and self._data.replaceId > 0 then
  96. buffid = self._data.replaceId
  97. end
  98. local BuffProxy = global.Facade:retrieveProxy(global.ProxyTable.Buff)
  99. local sfxConfig = BuffProxy:GetBuffSfxByID(buffid)
  100. if sfxConfig then
  101. if sfxConfig.front then
  102. local sfxID = sfxConfig.front.sfxID
  103. self:removeBuffSfx(sfxID)
  104. end
  105. if sfxConfig.behind then
  106. local sfxID = sfxConfig.behind.sfxID
  107. self:removeBuffSfx(sfxID)
  108. end
  109. if sfxConfig.play_sfx then
  110. local sfxID = sfxConfig.play_sfx.sfxID
  111. self:removeBuffSfx(sfxID)
  112. end
  113. end
  114. end
  115. function BuffEntityAnim:IsShowStuckAnim( ... )
  116. local buffid = self._buffID
  117. if self._data.replaceId and self._data.replaceId > 0 then
  118. buffid = self._data.replaceId
  119. end
  120. local BuffProxy = global.Facade:retrieveProxy(global.ProxyTable.Buff)
  121. local sfxConfig = BuffProxy:GetBuffSfxByID(buffid)
  122. local hasSfx = false
  123. if sfxConfig then
  124. if sfxConfig.front_stuck and sfxConfig.front_stuck.sfxID and sfxConfig.front_stuck.sfxID ~= 0 then
  125. hasSfx = true
  126. end
  127. if sfxConfig.behind_stuck and sfxConfig.behind_stuck.sfxID and sfxConfig.behind_stuck.sfxID ~= 0 then
  128. hasSfx = true
  129. end
  130. end
  131. return hasSfx
  132. end
  133. function BuffEntityAnim:ShowAnimStuck()
  134. local actor = global.actorManager:GetActor(self._actorID)
  135. if not actor then
  136. return nil
  137. end
  138. local buffid = self._buffID
  139. if self._data.replaceId and self._data.replaceId > 0 then
  140. buffid = self._data.replaceId
  141. end
  142. local BuffProxy = global.Facade:retrieveProxy(global.ProxyTable.Buff)
  143. local sfxConfig = BuffProxy:GetBuffSfxByID(buffid)
  144. if sfxConfig then
  145. local falg = false
  146. local function callback()
  147. if self:IsInvalid() then
  148. return
  149. end
  150. if falg then
  151. return
  152. end
  153. falg = true
  154. self:HideAnimStuck()
  155. self:ShowAnim(true)
  156. end
  157. if sfxConfig.front_stuck then
  158. local sfxID = sfxConfig.front_stuck.sfxID
  159. local loop = sfxConfig.front_stuck.loop
  160. local is8dir = sfxConfig.front_stuck.is8dir
  161. local dirfollow = sfxConfig.front_stuck.dirfollow
  162. self:addBuffSfx(sfxID, true, loop, is8dir, dirfollow, callback)
  163. end
  164. if sfxConfig.behind_stuck then
  165. local sfxID = sfxConfig.behind_stuck.sfxID
  166. local loop = sfxConfig.behind_stuck.loop
  167. local is8dir = sfxConfig.behind_stuck.is8dir
  168. local dirfollow = sfxConfig.behind_stuck.dirfollow
  169. self:addBuffSfx(sfxID, false, loop, is8dir, dirfollow, callback)
  170. end
  171. end
  172. end
  173. function BuffEntityAnim:HideAnimStuck()
  174. local actor = global.actorManager:GetActor(self._actorID)
  175. if not actor then
  176. return nil
  177. end
  178. local buffid = self._buffID
  179. if self._data.replaceId and self._data.replaceId > 0 then
  180. buffid = self._data.replaceId
  181. end
  182. local BuffProxy = global.Facade:retrieveProxy(global.ProxyTable.Buff)
  183. local sfxConfig = BuffProxy:GetBuffSfxByID(buffid)
  184. if sfxConfig then
  185. if sfxConfig.front_stuck then
  186. local sfxID = sfxConfig.front_stuck.sfxID
  187. self:removeBuffSfx(sfxID)
  188. end
  189. if sfxConfig.behind_stuck then
  190. local sfxID = sfxConfig.behind_stuck.sfxID
  191. self:removeBuffSfx(sfxID)
  192. end
  193. end
  194. end
  195. function BuffEntityAnim:addBuffSfx(sfxID, front, loop, is8dir, dirfollow, callback)
  196. if not sfxID then
  197. return nil
  198. end
  199. local actor = global.actorManager:GetActor(self._actorID)
  200. if not actor then
  201. return nil
  202. end
  203. -- create sfx
  204. if nil == self._sceneAnims[sfxID] and not actor:GetValueByKey(global.MMO.HUD_SNEAK) then
  205. local dir = (dirfollow or is8dir) and actor:GetDirection() or 0
  206. local sfx = global.FrameAnimManager:CreateSFXAnim(sfxID)
  207. sfx:SetGlobalElapseEnable(loop == 0)
  208. local root = front and self._rootNodeF or self._rootNodeB
  209. root:addChild(sfx, sfxID)
  210. local visible = CHECK_SETTING(global.MMO.SETTING_IDX_EFFECT_SHOW) ~= 1
  211. sfx:setVisible(visible)
  212. sfx:Play(0, dir, true, self._sfxSpeed or 1)
  213. self._sceneAnims[sfxID] = sfx
  214. sfx._dirfollow_ = dirfollow
  215. local count = 0
  216. local function overCB()
  217. if self:IsInvalid() then
  218. return
  219. end
  220. if loop > 0 then
  221. count = count + 1
  222. if loop == count then
  223. sfx:Stop()
  224. sfx:setVisible(false)
  225. end
  226. end
  227. if callback then
  228. callback()
  229. end
  230. end
  231. sfx:SetAnimEventCallback(overCB)
  232. end
  233. local position = actor:getPosition()
  234. self:setPosition(position.x, position.y)
  235. end
  236. function BuffEntityAnim:removeBuffSfx(sfxID)
  237. if not sfxID then
  238. return nil
  239. end
  240. if self._sceneAnims[sfxID] then
  241. self._sceneAnims[sfxID]:removeFromParent()
  242. self._sceneAnims[sfxID] = nil
  243. end
  244. end
  245. function BuffEntityAnim:OnActorStuck()
  246. if not self:IsShowStuckAnim() then
  247. return false
  248. end
  249. self:HideAnim()
  250. self:HideAnimStuck()
  251. self:ShowAnimStuck()
  252. return true
  253. end
  254. function BuffEntityAnim:setPosition(x, y)
  255. local actor = global.actorManager:GetActor(self._actorID)
  256. if not actor then
  257. return nil
  258. end
  259. local notOffset = self._unOffset and self._unOffset == 1
  260. local horseOffset = self._horseOffset or cc.p(0,0)
  261. for animID, anim in pairs(self._sceneAnims) do
  262. if actor:IsDropItem() then
  263. anim:setPosition(cc.pAdd(cc.pAdd(cc.p(x+horseOffset.x, y+horseOffset.y), notOffset and global.MMO.PLAYER_AVATAR_OFFSET or cc.p(0,0)), self._sfxOffset))
  264. else
  265. anim:setPosition(cc.pAdd(cc.pAdd(cc.p(x+horseOffset.x, y+horseOffset.y), global.MMO.PLAYER_AVATAR_OFFSET), self._sfxOffset))
  266. end
  267. end
  268. end
  269. function BuffEntityAnim:setVisible(visible)
  270. local actor = global.actorManager:GetActor(self._actorID)
  271. if not actor then
  272. return
  273. end
  274. if actor:IsPlayer() and actor:IsHoreseCopilot() then
  275. self:HideAnim()
  276. return
  277. end
  278. if actor:IsPlayer() and actor:GetHorseMasterID() and global.actorManager:GetActor(actor:GetHorseMasterID()) then
  279. local BuffProxy = global.Facade:retrieveProxy(global.ProxyTable.Buff)
  280. if not BuffProxy:IsHorseShow(self._buffID) then
  281. self:HideAnim()
  282. return
  283. end
  284. end
  285. -- 潜行
  286. if visible and actor:GetValueByKey(global.MMO.HUD_SNEAK) then
  287. visible = false
  288. end
  289. if visible then
  290. self:ShowAnim()
  291. else
  292. self:HideAnim()
  293. end
  294. end
  295. function BuffEntityAnim:updatePosition()
  296. local actor = global.actorManager:GetActor(self._actorID)
  297. if actor and self._buffID == global.MMO.BUFF_ID_MAGIC_SHIELD then
  298. -- 检测是不是副驾的玩家 副驾玩家的buff特效都不显示出来
  299. self._horseOffset.y = 0
  300. local position = actor:getPosition()
  301. if actor and actor:IsPlayer() and actor:GetHorseMasterID() then
  302. self._horseOffset.y = 10
  303. end
  304. self:setPosition(position.x, position.y)
  305. elseif actor and actor:IsPlayer() then
  306. local BuffProxy = global.Facade:retrieveProxy(global.ProxyTable.Buff)
  307. local offset = BuffProxy:GetHorseOffset(self._buffID)
  308. if offset.x ~= 0 or offset.y ~= 0 then
  309. if actor:GetHorseMasterID() and global.actorManager:GetActor(actor:GetHorseMasterID()) then
  310. else
  311. offset.x = 0
  312. offset.y = 0
  313. end
  314. self._horseOffset = offset
  315. local position = actor:getPosition()
  316. self:setPosition(position.x, position.y)
  317. end
  318. end
  319. end
  320. function BuffEntityAnim:UpdateSfxDir()
  321. local actor = global.actorManager:GetActor(self._actorID)
  322. if not actor then
  323. return false
  324. end
  325. if not actor.GetDirection then
  326. return false
  327. end
  328. for _, sfx in pairs(self._sceneAnims) do
  329. if sfx and sfx._dirfollow_ then
  330. sfx:Stop()
  331. sfx:Play(0, actor:GetDirection(), true)
  332. end
  333. end
  334. end
  335. return BuffEntityAnim