skillPresentFly.lua 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. local skillPresentBase = require("skill/skillPresentBase")
  2. local skillPresentFly = class("skillPresentFly", skillPresentBase)
  3. local effectOff = {
  4. [131] = { x = -25, y = 0 }
  5. }
  6. local offsetys = {[13] = 1, [14] = 1, [15] = 1, [19] = 1, [38] = 1, [44] = 1, [63] = 1 }--13灵魂火符 14幽灵盾 15神圣战甲术 19集体隐身术 38诅咒术 44寒冰掌 85裂神符 63噬魂沼泽需要向上偏移
  7. local dir1t8 = {
  8. [9] = true
  9. }
  10. function skillPresentFly:ctor(data, config, root, target, delagate)
  11. skillPresentFly.super.ctor(self, data, config, root, target, delagate)
  12. end
  13. function skillPresentFly:getType()
  14. return global.MMO.SKILL_PRESENT_FLY
  15. end
  16. function skillPresentFly:init()
  17. skillPresentFly.super.init(self)
  18. self._anim = nil
  19. self._status = -1
  20. self._tickAble = false
  21. self._delayTime = (self._config.flyDelayTime or 0) * 0.001 / self._speed
  22. self._flyDir = cc.p(0.0, 0.0)
  23. self._flySpeed = ((not self._config.flySpeed or self._config.flySpeed == 0) and 1500.0 or self._config.flySpeed) * self._speed
  24. self._currWorldPos = cc.p(0.0, 0.0)
  25. self._destWorldPos = cc.p(0.0, 0.0)
  26. self._animDir = (self._config.flyDir == 8) and 8 or 0
  27. end
  28. function skillPresentFly:launch()
  29. skillPresentFly.super.launch(self)
  30. if self._config.flyID and self._config.flyID ~= -1 then
  31. self._anim = global.FrameAnimManager:CreateSkillEffAnim(self._config.flyID)
  32. self._anim:setLocalZOrder(self._config.flyID)
  33. self._anim:setVisible(false)
  34. self._root:addChild(self._anim)
  35. end
  36. if self._anim == nil then
  37. self._tickAble = false
  38. self:launchNext()
  39. self:disable()
  40. return
  41. end
  42. -- fix hit pos
  43. local hitX = self._target.dest.x
  44. local hitY = self._target.dest.y
  45. if self._target.id then
  46. local target = global.actorManager:GetActor(self._target.id)
  47. if target then
  48. hitX = target:GetMapX()
  49. hitY = target:GetMapY()
  50. end
  51. end
  52. local srcWorldPos = global.sceneManager:MapPos2WorldPos(self._data.launchX, self._data.launchY, true)
  53. srcWorldPos.y = srcWorldPos.y + 40
  54. local destWorldPos = global.sceneManager:MapPos2WorldPos(hitX, hitY, true)
  55. destWorldPos.y = destWorldPos.y + 40
  56. self._currWorldPos = srcWorldPos
  57. self._destWorldPos = destWorldPos
  58. if effectOff[self._config.flyID] then
  59. srcWorldPos.x = srcWorldPos.x + effectOff[self._config.flyID].x
  60. srcWorldPos.y = srcWorldPos.y + effectOff[self._config.flyID].y
  61. end
  62. self._anim:setPosition(srcWorldPos)
  63. self._anim:setVisible(false)
  64. -- launch...
  65. self._status = -1
  66. self._tickAble = true
  67. end
  68. function skillPresentFly:Tick(dt)
  69. if not self._tickAble then
  70. return
  71. end
  72. if self._status == -1 then
  73. self._delayTime = self._delayTime - dt
  74. if self._delayTime <= 0 then
  75. self._status = 0
  76. end
  77. elseif self._status == 0 then
  78. if self._anim then
  79. local launcher = global.actorManager:GetActor(self._data.launcherID)
  80. local direction = (self._animDir == 8 and launcher and (not dir1t8[self._config.flyID])) and launcher:GetDirection() or 0
  81. self._anim:Stop()
  82. self._anim:Play(0, direction, true, self._speed)
  83. self._anim:setVisible(true)
  84. -- calc dir
  85. local destSub = cc.pSub(self._destWorldPos, self._currWorldPos)
  86. self._flyDir = cc.pNormalize(destSub)
  87. local angle = cc.pGetAngle(self._flyDir, cc.p(0, 1))
  88. local rotate = (self._animDir == 0) and angle*57.29577951 or 0
  89. self._anim:setRotation(rotate)
  90. -- play sound
  91. local sex = (launcher and launcher:IsPlayer()) and launcher:GetSexID() or global.MMO.ACTOR_PLAYER_SEX_M
  92. global.Facade:sendNotification(global.NoticeTable.Audio_Play, {type=global.MMO.SND_TYPE_SKILL_FIRE, index=self._data.skillID, sex=sex})
  93. -----light
  94. if not self._LightID and not (self._config.notLight and self._config.notLight == 1) then
  95. local DarkLayerProxy = global.Facade:retrieveProxy(global.ProxyTable.DarkLayerProxy)
  96. local lightData = DarkLayerProxy.LIGHT_TYPE.Two_Skill
  97. self._LightID = global.darkNodeManager:createNode({ x = self._currWorldPos.x, y = self._currWorldPos.y, r = lightData.r, w = lightData.w })
  98. end
  99. end
  100. self._status = 1
  101. elseif self._status == 1 then
  102. if self._anim then
  103. local distance = self._flySpeed * dt
  104. --
  105. self:calcTarget()
  106. if self:isHitTarget(distance) then
  107. if self._anim then
  108. self._anim:removeFromParent()
  109. self._anim = nil
  110. end
  111. self._tickAble = false
  112. self:launchNext()
  113. self:disable()
  114. if self._LightID then
  115. global.darkNodeManager:removeNode(self._LightID)
  116. self._LightID = nil
  117. end
  118. else
  119. local displ = cc.pMul(self._flyDir, distance)
  120. local posNew = cc.pAdd(self._currWorldPos, displ)
  121. local offy = 0
  122. if self._data and self._data.skillID and offsetys[self._data.skillID] then
  123. offy = 28
  124. end
  125. self._anim:setPosition(posNew.x, posNew.y + offy)
  126. self._currWorldPos = posNew
  127. -----light
  128. if self._LightID then
  129. global.darkNodeManager:updateNode(self._LightID, { x = posNew.x, y = posNew.y })
  130. end
  131. end
  132. end
  133. end
  134. end
  135. function skillPresentFly:setNodeParent(root)
  136. if self._anim and root then
  137. root:addChild(self._anim)
  138. end
  139. end
  140. function skillPresentFly:calcTarget()
  141. if self._anim and self._config.needTarget == 1 then
  142. if self._target.id then
  143. local targetActor = global.actorManager:GetActor(self._target.id)
  144. if targetActor then
  145. self._destWorldPos = targetActor:getPosition()
  146. self._destWorldPos.y = self._destWorldPos.y + 40
  147. end
  148. else
  149. local inputProxy = global.Facade:retrieveProxy( global.ProxyTable.PlayerInputProxy )
  150. local normal = inputProxy:DirToNormalizeVec2(self._data.dir)
  151. local origin = cc.p(self._data.launchX, self._data.launchY)
  152. local moved = cc.pMul(normal, 25)
  153. local dest = cc.pAdd(origin, moved)
  154. self._destWorldPos = global.sceneManager:MapPos2WorldPos(dest.x, dest.y, true)
  155. self._destWorldPos.y= self._destWorldPos.y + 40
  156. end
  157. local destSub = cc.pSub(self._destWorldPos, self._currWorldPos)
  158. self._flyDir = cc.pNormalize(destSub)
  159. local angle = cc.pGetAngle(self._flyDir, cc.p(0, 1))
  160. local rotate = (self._animDir == 0) and angle*57.29577951 or 0
  161. self._anim:setRotation(rotate)
  162. end
  163. end
  164. function skillPresentFly:isHitTarget(distance)
  165. local destSub = cc.pSub(self._destWorldPos, self._currWorldPos)
  166. local destDist = cc.pGetLength(destSub)
  167. return destDist <= distance*3
  168. end
  169. return skillPresentFly