skillPresentHit.lua 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. local skillPresentBase = require("skill/skillPresentBase")
  2. local skillPresentHit = class("skillPresentHit", skillPresentBase)
  3. function skillPresentHit:ctor(data, config, root, target, delagate)
  4. skillPresentHit.super.ctor(self, data, config, root, target, delagate)
  5. end
  6. function skillPresentHit:getType()
  7. return global.MMO.SKILL_PRESENT_HIT
  8. end
  9. function skillPresentHit:init()
  10. skillPresentHit.super.init(self)
  11. self._anim = nil
  12. self._status = -1
  13. self._tickAble = false
  14. self._delayTime = (self._config.hitDelayTime or 0) * 0.001 / self._speed
  15. self._animFollow= (self._config.skillgensui or 1) == 1
  16. end
  17. function skillPresentHit:launch()
  18. skillPresentHit.super.launch(self)
  19. if self._config.hitID and self._config.hitID ~= -1 then
  20. local dir = (self._config.hitDir == 8 and self._data.dir or 0)
  21. local immediate = (self._config.hitID == 198)
  22. self._anim = global.FrameAnimManager:CreateSkillEffAnim(self._config.hitID, dir, nil, immediate)
  23. self._anim:setLocalZOrder(self._config.hitID)
  24. self._anim:setVisible(false)
  25. self._root:addChild(self._anim)
  26. end
  27. if not self._anim then
  28. self._tickAble = false
  29. self:launchNext()
  30. self:disable()
  31. return
  32. end
  33. local destPos = global.sceneManager:MapPos2WorldPos(self._target.dest.x, self._target.dest.y, true)
  34. if self._target.id and (self._data.skillID ~= 58 and self._data.skillID ~= 581) then
  35. local target = global.actorManager:GetActor(self._target.id)
  36. if target then
  37. destPos = target:getPosition()
  38. end
  39. end
  40. self._anim:setPosition(cc.pAdd(destPos, global.MMO.PLAYER_AVATAR_OFFSET))
  41. self._anim:setVisible(false)
  42. self._anim:SetAnimEventCallback(
  43. function(_, eventType)
  44. if self._anim then
  45. self._anim:removeFromParent()
  46. self._anim = nil
  47. end
  48. if self._LightID then
  49. global.darkNodeManager:removeNode(self._LightID)
  50. end
  51. self._LightID = nil
  52. self._tickAble = false
  53. self:launchNext()
  54. self:disable()
  55. end
  56. )
  57. -- launch...
  58. self._status = -1
  59. self._tickAble = true
  60. end
  61. function skillPresentHit:Tick(dt)
  62. if not self._tickAble then
  63. return
  64. end
  65. if self._status == -1 then
  66. self._delayTime = self._delayTime - dt
  67. if self._delayTime <= 0 then
  68. self._status = 0
  69. end
  70. elseif self._status == 0 then
  71. self._status = 1
  72. -- refresh hit pos
  73. if self._anim then
  74. local dir = (self._config.hitDir == 8 and self._data.dir or 0)
  75. self._anim:Play(0, dir, true, self._speed)
  76. self._anim:setVisible(true)
  77. -----light
  78. if not self._LightID and not (self._config.notLight and self._config.notLight == 1) then
  79. local destPos = global.sceneManager:MapPos2WorldPos(self._target.dest.x, self._target.dest.y, true)
  80. local DarkLayerProxy = global.Facade:retrieveProxy(global.ProxyTable.DarkLayerProxy)
  81. local lightData = DarkLayerProxy.LIGHT_TYPE.Two_Skill
  82. self._LightID = global.darkNodeManager:createNode({ x = destPos.x, y = destPos.y, r = lightData.r, w = lightData.w })
  83. end
  84. -- 特殊处理流行火雨
  85. if self._data.skillID == 58 or self._data.skillID == 581 then
  86. elseif self._data.skillID == 840 then --冰霜群雨
  87. local range = 3
  88. local showMapPos = {
  89. {-1 * range, -1 * range }, {-1 * range, range }, { range, -1 * range }, { range, range }
  90. }
  91. self:ShowRandomAnim(self._config.hitID, showMapPos, dir)
  92. else
  93. self:refreshHitPosition()
  94. end
  95. -- sound
  96. local launcher = global.actorManager:GetActor(self._data.launcherID)
  97. local sex = (launcher and launcher:IsPlayer()) and launcher:GetSexID() or global.MMO.ACTOR_PLAYER_SEX_M
  98. global.Facade:sendNotification(global.NoticeTable.Audio_Play, { type = global.MMO.SND_TYPE_SKILL_EXPLOSION, index = self._data.skillID, sex = sex })
  99. end
  100. elseif self._status == 1 then
  101. -- refresh hit pos
  102. if self._animFollow then
  103. self:refreshHitPosition()
  104. end
  105. end
  106. end
  107. function skillPresentHit:setNodeParent(root)
  108. if root and self._anim then
  109. root:addChild(self._anim)
  110. end
  111. end
  112. function skillPresentHit:refreshHitPosition()
  113. if not self._anim then
  114. return false
  115. end
  116. if not self._target.id then
  117. return
  118. end
  119. local target = global.actorManager:GetActor(self._target.id)
  120. if not target then
  121. return
  122. end
  123. local destPos = target:getPosition()
  124. self._anim:setPosition(cc.pAdd(destPos, global.MMO.PLAYER_AVATAR_OFFSET))
  125. -----light
  126. if self._LightID then
  127. global.darkNodeManager:updateNode(self._LightID, { x = destPos.x , y = destPos.y})
  128. end
  129. end
  130. -- 显示随机特效 sfxID: 特效id showMapPos: 显示特效的地图位置 dir: 方向
  131. local randomCount = {} --随机特效显示的数量, 超过30个的就不显示了
  132. function skillPresentHit:ShowRandomAnim(sfxID, showMapPos, dir)
  133. local sfxMaxNum = 30
  134. sfxID = sfxID or 204 -- 默认冰霜群雨特效
  135. if not randomCount[sfxID] then
  136. randomCount[sfxID] = 0
  137. end
  138. if randomCount[sfxID] > sfxMaxNum then
  139. return
  140. end
  141. local mapX = self._target.dest.x
  142. local mapY = self._target.dest.y
  143. if self._target.id and (self._data.skillID ~= 58 and self._data.skillID ~= 581) then
  144. local target = global.actorManager:GetActor(self._target.id)
  145. if target then
  146. mapX = target:GetMapX()
  147. mapY = target:GetMapY()
  148. end
  149. end
  150. local sfxRoot = self._root
  151. local originPos = { mapX, mapY }
  152. for i, mapPos in ipairs(showMapPos) do
  153. randomCount[sfxID] = randomCount[sfxID] + 1
  154. if randomCount[sfxID] > sfxMaxNum then
  155. break
  156. end
  157. local pos = global.sceneManager:MapPos2WorldPos(mapX + mapPos[1], mapY + mapPos[2], true)
  158. local sfx = global.FrameAnimManager:CreateSkillEffAnim(sfxID, dir or 0)
  159. sfxRoot:addChild(sfx)
  160. sfx:setLocalZOrder(sfxID)
  161. sfx:Play(0, 0, true)
  162. sfx:setPosition(cc.pAdd(pos, global.MMO.PLAYER_AVATAR_OFFSET))
  163. sfx:SetAnimEventCallback(
  164. function(_, eventType)
  165. if sfx then
  166. sfx:removeFromParent()
  167. sfx = nil
  168. end
  169. randomCount[sfxID] = randomCount[sfxID] - 1
  170. end
  171. )
  172. end
  173. end
  174. return skillPresentHit