SHARE
TWEET

Untitled

epitaque_ May 25th, 2020 1,196 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Author: Ported from Angel Arena Black Star's Github
  2. -- https://github.com/ark120202/aabs/blob/1faaadbc3cbf9f9d9bf2cbb8c1e2463141c17d2e/game/scripts/vscripts/items/item_bottle.lua
  3.  
  4. -- and then from IMBA
  5. -- https://github.com/EarthSalamander42/dota_imba/blob/master/game/dota_addons/dota_imba/scripts/vscripts/components/items/item_bottle.lua
  6.  
  7. LinkLuaModifier("modifier_item_r1v1r_bottle_heal", "components/items/item_bottle.lua", LUA_MODIFIER_MOTION_NONE)
  8. LinkLuaModifier("modifier_item_r1v1r_bottle_texture_controller", "components/items/item_bottle.lua", LUA_MODIFIER_MOTION_NONE)
  9. LinkLuaModifier("modifier_item_r1v1r_bottle_texture_controller_2", "components/items/item_bottle.lua", LUA_MODIFIER_MOTION_NONE)
  10.  
  11. item_r1v1r_bottle = class({})
  12.  
  13. function item_r1v1r_bottle:GetIntrinsicModifierName() return "modifier_item_r1v1r_bottle_texture_controller" end
  14.  
  15. function item_r1v1r_bottle:SetCurrentCharges(charges)
  16.     return self.BaseClass.SetCurrentCharges(self, charges)
  17. end
  18.  
  19. function item_r1v1r_bottle:OnSpellStart()
  20.     local caster = self:GetCaster()
  21.     if self.RuneStorage then
  22.         -- Safe env. so the rune still gets consumed even if it errors
  23.         --pcall(PickupRune, self.RuneStorage, caster, true)
  24.         RuneManager:PickupRune(self.RuneStorage, caster, true)
  25.         self:SetCurrentCharges(3)
  26.         self.RuneStorage = nil
  27.     else
  28.         local charges = self:GetCurrentCharges()
  29.  
  30.         if charges > 0 then
  31.             caster:AddNewModifier(caster, self, "modifier_item_r1v1r_bottle_heal", {duration = self:GetSpecialValueFor("restore_time")})
  32.             self:SetCurrentCharges(charges - 1)
  33.             caster:EmitSound("Bottle.Drink")
  34.         end
  35.     end
  36. end
  37.  
  38. function item_r1v1r_bottle:SetStorageRune(type)
  39.     --if self.RuneStorage then return end
  40.     if self:GetCaster().GetPlayerID then
  41.         CustomGameEventManager:Send_ServerToTeam(self:GetCaster():GetTeam(), "create_custom_toast", {
  42.             type = "generic",
  43.             text = "#custom_toast_BottledRune",
  44.             player = self:GetCaster():GetPlayerID(),
  45.             runeType = type
  46.         })
  47.     end
  48.  
  49.     Timers:CreateTimer(121, function() 
  50.         if self.RuneStorage and GameRules:GetGameTime() - self.PickupRuneTime > 120 then
  51.             RuneManager:PickupRune(self.RuneStorage, self:GetCaster(), true)
  52.             self:SetCurrentCharges(3)
  53.             self.RuneStorage = nil 
  54.         end
  55.     end)
  56.  
  57.     self.RuneStorage = type
  58.  
  59.     self.PickupRuneTime = GameRules:GetGameTime()
  60.     self:SetCurrentCharges(3)
  61.     self:GetCaster():EmitSound("Bottle.Cork")
  62. end
  63.  
  64.  
  65. function item_r1v1r_bottle:GetAbilityTextureName()
  66.     local texture = "custom/bottle_0_3"
  67.     texture = self.texture_name or texture
  68.     return texture
  69. end
  70.  
  71.  
  72. -- TEXTURE CONTROLLER
  73.  
  74. modifier_item_r1v1r_bottle_texture_controller = modifier_item_r1v1r_bottle_texture_controller or class({})
  75.  
  76. function modifier_item_r1v1r_bottle_texture_controller:IsHidden() return true end
  77. function modifier_item_r1v1r_bottle_texture_controller:IsPurgable() return false end
  78. function modifier_item_r1v1r_bottle_texture_controller:IsDebuff() return false end
  79. function modifier_item_r1v1r_bottle_texture_controller:GetAttributes() return MODIFIER_ATTRIBUTE_MULTIPLE end
  80.  
  81. function modifier_item_r1v1r_bottle_texture_controller:OnCreated()
  82.     if IsServer() then
  83.         self:GetParent():AddNewModifier(self:GetParent(), self:GetAbility(), "modifier_item_r1v1r_bottle_texture_controller_2", {})
  84.     end
  85.  
  86.     self:StartIntervalThink(0.1)
  87. end
  88.  
  89. function modifier_item_r1v1r_bottle_texture_controller:OnIntervalThink()
  90.     local rune_table = {
  91.         tostring(self:GetAbility().bottle_icon).."_0",--1
  92.         tostring(self:GetAbility().bottle_icon).."_1",--2
  93.         tostring(self:GetAbility().bottle_icon).."_2",--3
  94.         tostring(self:GetAbility().bottle_icon).."_3",--4
  95.         "arcane", --5
  96.         "double_damage", --6
  97.         "haste", --7
  98.         "regeneration", --8
  99.         "illusion", --9
  100.         "invisibility",  --10
  101.         "bounty", --11
  102.         "frost" --12
  103.     }
  104.  
  105.     if IsServer() then
  106.         if self:GetAbility():IsCooldownReady() and self:GetParent():HasModifier("modifier_fountain_aura_buff") then
  107.             self:GetAbility():SetCurrentCharges(3)
  108.         end
  109.  
  110.         local stack = self:GetAbility():GetCurrentCharges() + 1
  111.  
  112.         for i = 5, 12 do
  113.             if self:GetAbility().RuneStorage == rune_table[i] then
  114.                 stack = i
  115.                 break
  116.             end
  117.         end
  118.  
  119.         self:SetStackCount(stack)
  120.     end
  121.  
  122.     if self:GetStackCount() >= 1 and self:GetStackCount() <= 4 then
  123.         self:GetAbility().texture_name = "custom/bottle_"..rune_table[self:GetStackCount()]
  124.     elseif self:GetStackCount() >= 5 then
  125.         --print("Stack count: " .. self:GetStackCount())
  126.         self:GetAbility().texture_name = "custom/bottle_rune_"..rune_table[self:GetStackCount()]
  127.     end
  128. end
  129.  
  130. function modifier_item_r1v1r_bottle_texture_controller:OnDestroy()
  131.     --print("Destroying modifier texture... parent classname: " .. self:GetParent():GetClassname())
  132.  
  133.     if self:GetParent():HasModifier("modifier_item_r1v1r_bottle_texture_controller_2") then
  134.         --print("Destroying modifier texture 2... parent classname: " .. self:GetParent():GetClassname())
  135.  
  136.         if self:GetParent().RemoveModifierByName then
  137.             self:GetParent():RemoveModifierByName("modifier_item_r1v1r_bottle_texture_controller_2")
  138.         end
  139.     end
  140. end
  141.  
  142. modifier_item_r1v1r_bottle_texture_controller_2 = modifier_item_r1v1r_bottle_texture_controller_2 or class({})
  143.  
  144. function modifier_item_r1v1r_bottle_texture_controller_2:IsHidden() return true end
  145. function modifier_item_r1v1r_bottle_texture_controller_2:IsPurgable() return false end
  146. function modifier_item_r1v1r_bottle_texture_controller_2:IsDebuff() return false end
  147. function modifier_item_r1v1r_bottle_texture_controller_2:GetAttributes() return MODIFIER_ATTRIBUTE_MULTIPLE end
  148.  
  149. function modifier_item_r1v1r_bottle_texture_controller_2:OnCreated()
  150.     if IsServer() then
  151.         if not self:GetAbility() then self:Destroy() end
  152.     end
  153.  
  154.     if self:GetParent().bottle_icon then
  155.         self:SetStackCount(self:GetParent().bottle_icon)
  156.         self:GetAbility().bottle_icon = self:GetStackCount()
  157.     end
  158.  
  159.     if IsClient() then
  160.         self:GetAbility().bottle_icon = self:GetStackCount()
  161.     end
  162. end
  163.  
  164. modifier_item_r1v1r_bottle_heal = class({
  165.     GetTexture =            function() return "custom/bottle_0_3" end,
  166.     IsPurgable =            function() return false end,
  167.     GetEffectAttachType =   function() return PATTACH_ABSORIGIN_FOLLOW end,
  168. })
  169.  
  170. function modifier_item_r1v1r_bottle_heal:DeclareFunctions()
  171.     return {
  172.         MODIFIER_PROPERTY_HEALTH_REGEN_CONSTANT,
  173.         MODIFIER_PROPERTY_MANA_REGEN_CONSTANT,
  174.         MODIFIER_EVENT_ON_TAKEDAMAGE
  175.     }
  176. end
  177.  
  178. function modifier_item_r1v1r_bottle_heal:OnTakeDamage(params)
  179.     local victim = params.unit
  180.     local attacker = params.attacker
  181.     local current_stacks = self:GetStackCount()
  182.  
  183.  
  184.     if not (self:GetCaster() == victim and (attacker:IsHero() or attacker:IsTower())) then
  185.         return
  186.     end
  187.     print("Decreasing stack... ")
  188.  
  189.     self:Destroy()
  190. end
  191.  
  192. function modifier_item_r1v1r_bottle_heal:GetModifierConstantHealthRegen()
  193.     if self:GetAbility() ~= nil then
  194.         return self:GetAbility():GetSpecialValueFor("health_restore") / self:GetAbility():GetSpecialValueFor("restore_time")
  195.     end
  196. end
  197.  
  198. function modifier_item_r1v1r_bottle_heal:GetModifierConstantManaRegen()
  199.     if self:GetAbility() ~= nil then
  200.         return self:GetAbility():GetSpecialValueFor("mana_restore") / self:GetAbility():GetSpecialValueFor("restore_time")
  201.     end
  202. end
  203.  
  204. function modifier_item_r1v1r_bottle_heal:OnCreated()
  205.     if IsServer() then
  206.         if not self:GetAbility() then self:Destroy() end
  207.     end
  208.  
  209.  
  210.     if not IsServer() then return end
  211.     self.pfx = ParticleManager:CreateParticle(self:GetCaster().bottle_effect, PATTACH_ABSORIGIN_FOLLOW, self:GetCaster())
  212. end
  213.  
  214. function modifier_item_r1v1r_bottle_heal:OnDestroy()
  215.     if not IsServer() then return end
  216.     ParticleManager:DestroyParticle(self.pfx, false)
  217.     ParticleManager:ReleaseParticleIndex(self.pfx)
  218. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top