skillPresentLaunch.lua 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. local skillPresentBase = require("skill/skillPresentBase")
  2. local skillPresentLaunch = class("skillPresentLaunch", skillPresentBase)
  3. function skillPresentLaunch:ctor(data, config, root, target, delagate)
  4. skillPresentLaunch.super.ctor(self, data, config, root, target, delagate)
  5. end
  6. function skillPresentLaunch:getType()
  7. return global.MMO.SKILL_PRESENT_LAUNCH
  8. end
  9. function skillPresentLaunch:init()
  10. skillPresentLaunch.super.init(self)
  11. self._anim = nil
  12. self._status = -1
  13. self._tickAble = false
  14. -- delay
  15. self._delayTime = (self._config.delaytime or 0) * 0.001 / self._speed
  16. self._animFollow = (self._config.skillgensui or 0) == 1
  17. end
  18. function skillPresentLaunch:launch()
  19. skillPresentLaunch.super.launch(self)
  20. --
  21. if self._config.launchID and self._config.launchID ~= -1 then
  22. local isCreateAnim = true
  23. if self._data and self._data.skillID == 85 then --裂神符技能
  24. local launcher = global.actorManager:GetActor(self._data.launcherID)
  25. if launcher and launcher:IsMonster() then
  26. isCreateAnim = false
  27. end
  28. end
  29. if isCreateAnim then
  30. local dir = (self._config.launchDir == 8 and self._data.dir or 0)
  31. self._anim = global.FrameAnimManager:CreateSkillEffAnim(self._config.launchID, dir)
  32. self._anim:setLocalZOrder(self._config.launchID)
  33. self._anim:setVisible(false)
  34. self._root:addChild(self._anim)
  35. end
  36. end
  37. if self._anim == nil then
  38. self:launchNext()
  39. self:disable()
  40. return
  41. end
  42. -- // Launch animation
  43. local srcPos = global.sceneManager:MapPos2WorldPos(self._data.launchX, self._data.launchY, true)
  44. self._anim:setPosition(cc.pAdd(srcPos, global.MMO.PLAYER_AVATAR_OFFSET))
  45. self._anim:SetAnimEventCallback(
  46. function(_, eventType)
  47. if self._anim then
  48. self._anim:removeFromParent()
  49. self._anim = nil
  50. end
  51. if self._LightID then
  52. global.darkNodeManager:removeNode(self._LightID)
  53. self._LightID = nil
  54. end
  55. self._tickAble = false
  56. self:launchNext()
  57. self:disable()
  58. end
  59. )
  60. -----light
  61. if not self._LightID and not (self._config.notLight and self._config.notLight == 1) then
  62. local DarkLayerProxy = global.Facade:retrieveProxy(global.ProxyTable.DarkLayerProxy)
  63. local lightData = DarkLayerProxy.LIGHT_TYPE.Two_Skill
  64. self._LightID = global.darkNodeManager:createNode({ x = srcPos.x, y = srcPos.y, r = lightData.r, w = lightData.w })
  65. end
  66. -- launch...
  67. self._status = -1
  68. self._tickAble = true
  69. --
  70. if self._delayTime <= 0 then
  71. self._status = 1
  72. self:launchAnim()
  73. end
  74. end
  75. function skillPresentLaunch:Tick(dt)
  76. if not self._tickAble then
  77. return
  78. end
  79. if self._status == -1 then
  80. -- delay for launch state
  81. self._delayTime = self._delayTime - dt
  82. if self._delayTime <= 0 then
  83. self._status = 0
  84. end
  85. elseif self._status == 0 then
  86. self._status = 1
  87. self:launchAnim()
  88. elseif self._status == 1 then
  89. self:refreshLaunchPosition()
  90. end
  91. end
  92. function skillPresentLaunch:launchAnim()
  93. self:animationLaunchBeforeSFX()
  94. -- anim
  95. if self._anim then
  96. local dir = (self._config.launchDir == 8 and self._data.dir or 0)
  97. self._anim:Play(0, dir, true, self._speed)
  98. self._anim:setVisible(true)
  99. end
  100. -- sound
  101. local launcher = global.actorManager:GetActor(self._data.launcherID)
  102. local sex = (launcher and launcher:IsPlayer()) and launcher:GetSexID() or global.MMO.ACTOR_PLAYER_SEX_M
  103. global.Facade:sendNotification(global.NoticeTable.Audio_Play, { type = global.MMO.SND_TYPE_SKILL_START, index = self._data.skillID, sex = sex })
  104. --
  105. if self._animFollow == false and self._config.flyID == -1 and self._config.hitID == -1 then
  106. self._tickAble = false
  107. self:launchNext()
  108. self:disable()
  109. end
  110. end
  111. function skillPresentLaunch:refreshLaunchPosition()
  112. if not self._anim then
  113. return
  114. end
  115. if not self._animFollow then
  116. return
  117. end
  118. local launcher = global.actorManager:GetActor(self._data.launcherID)
  119. if not launcher then
  120. return
  121. end
  122. local srcPos = launcher:getPosition()
  123. self._anim:setPosition(cc.pAdd(srcPos, global.MMO.PLAYER_AVATAR_OFFSET))
  124. if self._LightID then
  125. global.darkNodeManager:updateNode(self._LightID, { x = srcPos.x, y = srcPos.y })
  126. end
  127. end
  128. function skillPresentLaunch:addLaunchLight(srcPos)
  129. local light = nil
  130. if not (self._config.notLight and self._config.notLight == 1) then
  131. local DarkLayerProxy = global.Facade:retrieveProxy(global.ProxyTable.DarkLayerProxy)
  132. local lightData = DarkLayerProxy.LIGHT_TYPE.Two_Skill
  133. light = global.darkNodeManager:createNode({ x = srcPos.x, y = srcPos.y, r = lightData.r, w = lightData.w })
  134. end
  135. return light
  136. end
  137. function skillPresentLaunch:animationLaunchBeforeSFX()
  138. if self._data and self._data.launcherID then
  139. local launcher = global.actorManager:GetActor(self._data.launcherID)
  140. if launcher and launcher:IsMonster() and launcher:GetAnimationID() == 800 then -- 火龙神
  141. self:animationLightning({-500, 0 }, { 50, -300 })
  142. end
  143. end
  144. end
  145. -- 闪电集
  146. function skillPresentLaunch:animationLightning(xRandom, yRandom)
  147. local launcher = global.actorManager:GetActor(self._data.launcherID)
  148. if not launcher then
  149. return nil
  150. end
  151. local sfxID = 1038
  152. local srcPos = launcher:getPosition()
  153. local sfxCount = 2
  154. local dir = 5
  155. local function animationSfx(sfx_count)
  156. if sfx_count > sfxCount then
  157. return
  158. end
  159. local removeCount = 0
  160. for i = 1, 6 do
  161. PerformWithDelayGlobal(function()
  162. local pos = cc.p(srcPos.x + (math.random(xRandom[1], xRandom[2]) or 0), srcPos.y + (math.random(yRandom[1], yRandom[2]) or 0))
  163. local sfx = global.FrameAnimManager:CreateSkillEffAnim(sfxID, math.random(0, dir) or 0)
  164. self._root:addChild(sfx)
  165. sfx:setLocalZOrder(sfxID)
  166. sfx:Play(0, 0, true)
  167. sfx:setPosition(cc.pAdd(pos, global.MMO.PLAYER_AVATAR_OFFSET))
  168. local light = self:addLaunchLight(pos)
  169. sfx:SetAnimEventCallback(
  170. function(_, eventType)
  171. if sfx then
  172. sfx:removeFromParent()
  173. sfx = nil
  174. if light then
  175. global.darkNodeManager:removeNode(light)
  176. end
  177. end
  178. removeCount = removeCount + 1
  179. if removeCount == 5 then
  180. animationSfx(sfx_count + 1)
  181. end
  182. end
  183. )
  184. end, 0.11 * i)
  185. end
  186. end
  187. animationSfx(1)
  188. end
  189. return skillPresentLaunch