Advertisement
Guest User

Untitled

a guest
Mar 25th, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.61 KB | None | 0 0
  1. LinkLuaModifier( "modifier_chain_light_custom", "abilities/chain_light_custom", LUA_MODIFIER_MOTION_NONE )
  2. LinkLuaModifier( "modifier_chain_light_custom_thinker", "abilities/chain_light_custom", LUA_MODIFIER_MOTION_NONE )
  3.  
  4. chain_light_custom = class({})
  5.  
  6. function chain_light_custom:GetIntrinsicModifierName()
  7. return "modifier_chain_light_custom"
  8. end
  9.  
  10. function chain_light_custom:GetCastRange()
  11. return self:GetSpecialValueFor("cast_range")
  12. end
  13.  
  14. function chain_light_custom:Spawn()
  15. self.thinkers = {}
  16. end
  17.  
  18.  
  19. function chain_light_custom:OnSpellStart()
  20. local caster = self:GetCaster()
  21. local target = self:GetCursorTarget()
  22. caster:EmitSound("Item.Maelstrom.Chain_Lightning")
  23.  
  24. local thinker = CreateModifierThinker(caster, self, "modifier_chain_light_custom_thinker", nil, caster:GetAbsOrigin(), caster:GetTeam(), false)
  25. thinker.id = thinker:entindex()
  26. table.insert(self.thinkers, thinker.id, thinker)
  27. local thinker_modifier = thinker:FindModifierByName("modifier_chain_light_custom_thinker")
  28. thinker_modifier:ChainLight(caster, target)
  29. end
  30.  
  31. modifier_chain_light_custom = class({
  32. IsHidden = function(self) return true end,
  33. DeclareFunctions = function(self) return {
  34. MODIFIER_EVENT_ON_ATTACK_LANDED,
  35. }end,
  36. })
  37.  
  38. function modifier_chain_light_custom:OnAttackLanded(data)
  39. local caster = self:GetCaster()
  40. local target = data.target
  41. local attacker = data.attacker
  42.  
  43. if attacker == caster and not target:IsBuilding() and not target:IsMagicImmune() then
  44. local ability = self:GetAbility()
  45. local trigger_chance = ability:GetSpecialValueFor("trigger_chance")
  46.  
  47. if RollPercentage(trigger_chance) then
  48. caster:EmitSound("Item.Maelstrom.Chain_Lightning")
  49.  
  50. local thinker = CreateModifierThinker(caster, ability, "modifier_chain_light_custom_thinker", nil, caster:GetAbsOrigin(), caster:GetTeam(), false)
  51. thinker.id = thinker:entindex()
  52. table.insert(ability.thinkers, thinker.id, thinker)
  53. local thinker_modifier = thinker:FindModifierByName("modifier_chain_light_custom_thinker")
  54. thinker_modifier:ChainLightAlt(caster, target)
  55. end
  56. end
  57. end
  58.  
  59. modifier_chain_light_custom_thinker = class({})
  60.  
  61. function modifier_chain_light_custom_thinker:OnCreated()
  62. self.caster = self:GetCaster()
  63. self.parent = self:GetParent()
  64. self.ability = self:GetAbility()
  65.  
  66. self.bounce_damage = self.ability:GetSpecialValueFor("bounce_damage")
  67. self.bounce_radius = self.ability:GetSpecialValueFor("bounce_radius")
  68. self.bounce_interval = self.ability:GetSpecialValueFor("bounce_interval")
  69. self.bounce_count = self.ability:GetSpecialValueFor("bounce_count")
  70.  
  71. self.target_count = 0
  72. self.bounced_targets = {}
  73. end
  74. function modifier_chain_light_custom_thinker:OnDestroy()
  75. table.remove(self.ability.thinkers, self.parent:entindex())
  76. end
  77.  
  78. function modifier_chain_light_custom_thinker:ChainLight(target1, target2)
  79. self.bounced_targets[target2:entindex()] = true
  80. self.target_count = self.target_count + 1
  81.  
  82. target2:EmitSound("Item.Maelstrom.Chain_Lightning.Jump")
  83. -- ZapThem(caster, ability, caster, target, damage)
  84.  
  85. local particle = "particles/items_fx/chain_lightning.vpcf"
  86. -- if ability:GetAbilityName() == "item_imba_jarnbjorn" then
  87. -- particle = "particles/items_fx/chain_lightning_jarnbjorn.vpcf"
  88. -- end
  89.  
  90. local bounce_pfx = ParticleManager:CreateParticle(particle, PATTACH_ABSORIGIN_FOLLOW, target1)
  91. ParticleManager:SetParticleControlEnt(bounce_pfx, 0, target1, PATTACH_POINT_FOLLOW, "attach_hitloc", target2:GetAbsOrigin(), true)
  92. ParticleManager:SetParticleControlEnt(bounce_pfx, 1, target2, PATTACH_POINT_FOLLOW, "attach_hitloc", target2:GetAbsOrigin(), true)
  93. ParticleManager:SetParticleControl(bounce_pfx, 2, Vector(1, 1, 1))
  94. ParticleManager:ReleaseParticleIndex(bounce_pfx)
  95.  
  96. ApplyDamage({
  97. attacker = self.caster,
  98. victim = target2,
  99. ability = self.ability,
  100. damage = self.bounce_damage,
  101. damage_type = DAMAGE_TYPE_MAGICAL})
  102.  
  103. Timers:CreateTimer(self.bounce_interval, function()
  104. self.trigger = false
  105. if self.target_count >= self.bounce_count then
  106. self:Destroy()
  107. return
  108. end
  109.  
  110. local nearby_enemies = FindUnitsInRadius(self.caster:GetTeamNumber(),
  111. target2:GetAbsOrigin(),
  112. nil,
  113. self.bounce_radius,
  114. DOTA_UNIT_TARGET_TEAM_ENEMY,
  115. DOTA_UNIT_TARGET_HERO + DOTA_UNIT_TARGET_BASIC,
  116. DOTA_UNIT_TARGET_FLAG_NO_INVIS + DOTA_UNIT_TARGET_FLAG_FOW_VISIBLE,
  117. FIND_ANY_ORDER,
  118. false)
  119.  
  120. for _, enemy in pairs(nearby_enemies) do
  121. local enemy_index = enemy:entindex()
  122. if self.bounced_targets[enemy_index] == nil then
  123. self:ChainLight(target2, enemy)
  124. self.trigger = true
  125. break
  126. end
  127. end
  128.  
  129. if self.trigger == false then
  130. self:Destroy()
  131. end
  132. end)
  133. end
  134.  
  135. function modifier_chain_light_custom_thinker:ChainLightAlt(target1, target2)
  136. self.bounced_targets[target2:entindex()] = true
  137. self.target_count = self.target_count + 1
  138.  
  139. target2:EmitSound("Item.Maelstrom.Chain_Lightning.Jump")
  140. -- ZapThem(caster, ability, caster, target, damage)
  141.  
  142. -- local particle = "particles/items_fx/chain_lightning.vpcf"
  143. local particle = "particles/econ/events/ti7/maelstorm_ti7.vpcf"
  144. -- if ability:GetAbilityName() == "item_imba_jarnbjorn" then
  145. -- particle = "particles/items_fx/chain_lightning_jarnbjorn.vpcf"
  146. -- end
  147.  
  148. local bounce_pfx = ParticleManager:CreateParticle(particle, PATTACH_ABSORIGIN_FOLLOW, target1)
  149. ParticleManager:SetParticleControlEnt(bounce_pfx, 0, target1, PATTACH_POINT_FOLLOW, "attach_hitloc", target2:GetAbsOrigin(), true)
  150. ParticleManager:SetParticleControlEnt(bounce_pfx, 1, target2, PATTACH_POINT_FOLLOW, "attach_hitloc", target2:GetAbsOrigin(), true)
  151. ParticleManager:SetParticleControl(bounce_pfx, 2, Vector(1, 1, 1))
  152. ParticleManager:ReleaseParticleIndex(bounce_pfx)
  153.  
  154. ApplyDamage({
  155. attacker = self.caster,
  156. victim = target2,
  157. ability = self.ability,
  158. damage = self.bounce_damage,
  159. damage_type = DAMAGE_TYPE_MAGICAL})
  160.  
  161. Timers:CreateTimer(self.bounce_interval, function()
  162. self.trigger = false
  163. if self.target_count >= self.bounce_count then
  164. self:Destroy()
  165. return
  166. end
  167.  
  168. local nearby_enemies = FindUnitsInRadius(self.caster:GetTeamNumber(),
  169. target2:GetAbsOrigin(),
  170. nil,
  171. self.bounce_radius,
  172. DOTA_UNIT_TARGET_TEAM_ENEMY,
  173. DOTA_UNIT_TARGET_HERO + DOTA_UNIT_TARGET_BASIC,
  174. DOTA_UNIT_TARGET_FLAG_NO_INVIS + DOTA_UNIT_TARGET_FLAG_FOW_VISIBLE,
  175. FIND_ANY_ORDER,
  176. false)
  177.  
  178. for _, enemy in pairs(nearby_enemies) do
  179. local enemy_index = enemy:entindex()
  180. if enemy ~= target2 then
  181. self:ChainLightAlt(target2, enemy)
  182. self.trigger = true
  183. break
  184. end
  185. end
  186.  
  187. if self.trigger == false then
  188. self:Destroy()
  189. end
  190. end)
  191. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement