Advertisement
dr4kedecep

libraries/attributes.lua

Dec 6th, 2015
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.56 KB | None | 0 0
  1. if not Attributes then
  2.     Attributes = class({})
  3. end
  4.  
  5.  
  6. function Attributes:Init()
  7.     local v = LoadKeyValues("scripts/kv/attributes.kv")
  8.     LinkLuaModifier("modifier_movespeed_cap", "libraries/modifiers/modifier_movespeed_cap", LUA_MODIFIER_MOTION_NONE)
  9.  
  10.     -- Default Dota Values
  11.     local DEFAULT_HP_PER_STR = 19
  12.     local DEFAULT_HP_REGEN_PER_STR = 0.03
  13.     local DEFAULT_MANA_PER_INT = 13
  14.     local DEFAULT_MANA_REGEN_PER_INT = 0.04
  15.     local DEFAULT_ARMOR_PER_AGI = 0.14
  16.     local DEFAULT_ATKSPD_PER_AGI = 1
  17.  
  18.     Attributes.hp_adjustment = v.HP_PER_STR - DEFAULT_HP_PER_STR
  19.     Attributes.hp_regen_adjustment = v.HP_REGEN_PER_STR - DEFAULT_HP_REGEN_PER_STR
  20.     Attributes.mana_adjustment = v.MANA_PER_INT - DEFAULT_MANA_PER_INT
  21.     Attributes.mana_regen_adjustment = v.MANA_REGEN_PER_INT - DEFAULT_MANA_REGEN_PER_INT
  22.     Attributes.armor_adjustment = v.ARMOR_PER_AGI - DEFAULT_ARMOR_PER_AGI
  23.     Attributes.attackspeed_adjustment = v.ATKSPD_PER_AGI - DEFAULT_ATKSPD_PER_AGI
  24.  
  25.     Attributes.applier = CreateItem("item_stat_modifier", nil, nil)
  26. end
  27.  
  28. function Attributes:ModifyBonuses(hero)
  29.  
  30.     print("Modifying Stats Bonus of hero "..hero:GetUnitName())
  31.  
  32.     hero:AddNewModifier(hero, nil, "modifier_movespeed_cap", {})
  33.     Timers:CreateTimer(function()
  34.  
  35.         if not IsValidEntity(hero) then
  36.             return
  37.         end
  38.  
  39.         -- Initialize value tracking
  40.         if not hero.custom_stats then
  41.             hero.custom_stats = true
  42.             hero.strength = 0
  43.             hero.agility = 0
  44.             hero.intellect = 0
  45.         end
  46.  
  47.         -- Get player attribute values
  48.         local strength = hero:GetStrength()
  49.         local agility = hero:GetAgility()
  50.         local intellect = hero:GetIntellect()
  51.        
  52.         -- Base Armor Bonus
  53.         local armor = agility * Attributes.armor_adjustment
  54.         hero:SetPhysicalArmorBaseValue(armor)
  55.  
  56.         -- STR
  57.         if strength ~= hero.strength then
  58.            
  59.             -- HP Bonus
  60.             if not hero:HasModifier("modifier_health_bonus") then
  61.                 Attributes.applier:ApplyDataDrivenModifier(hero, hero, "modifier_health_bonus", {})
  62.             end
  63.  
  64.             local health_stacks = math.abs(strength * Attributes.hp_adjustment)
  65.             hero:SetModifierStackCount("modifier_health_bonus", Attributes.applier, health_stacks)
  66.  
  67.             -- HP Regen Bonus
  68.             if not hero:HasModifier("modifier_health_regen_constant") then
  69.                 Attributes.applier:ApplyDataDrivenModifier(hero, hero, "modifier_health_regen_constant", {})
  70.             end
  71.  
  72.             local health_regen_stacks = math.abs(strength * Attributes.hp_regen_adjustment * 100)
  73.             hero:SetModifierStackCount("modifier_health_regen_constant", Attributes.applier, health_regen_stacks)
  74.         end
  75.  
  76.         -- AGI
  77.         if agility ~= hero.agility then        
  78.  
  79.             -- Attack Speed Bonus
  80.             if not hero:HasModifier("modifier_attackspeed_bonus_constant") then
  81.                 Attributes.applier:ApplyDataDrivenModifier(hero, hero, "modifier_attackspeed_bonus_constant", {})
  82.             end
  83.  
  84.             local attackspeed_stacks = math.abs(agility * Attributes.attackspeed_adjustment)
  85.             hero:SetModifierStackCount("modifier_attackspeed_bonus_constant", Attributes.applier, attackspeed_stacks)
  86.         end
  87.  
  88.         -- INT
  89.         if intellect ~= hero.intellect then
  90.            
  91.             -- Mana Bonus
  92.             if not hero:HasModifier("modifier_mana_bonus") then
  93.                 Attributes.applier:ApplyDataDrivenModifier(hero, hero, "modifier_mana_bonus", {})
  94.             end
  95.  
  96.             local mana_stacks = math.abs(intellect * Attributes.mana_adjustment)
  97.             hero:SetModifierStackCount("modifier_mana_bonus", Attributes.applier, mana_stacks)
  98.  
  99.             -- Mana Regen Bonus
  100.             if not hero:HasModifier("modifier_base_mana_regen") then
  101.                 Attributes.applier:ApplyDataDrivenModifier(hero, hero, "modifier_base_mana_regen", {})
  102.             end
  103.  
  104.             local mana_regen_stacks = math.abs(intellect * Attributes.mana_regen_adjustment * 100)
  105.             hero:SetModifierStackCount("modifier_base_mana_regen", Attributes.applier, mana_regen_stacks)
  106.         end
  107.  
  108.         -- Update the stored values for next timer cycle
  109.         hero.strength = strength
  110.         hero.agility = agility
  111.         hero.intellect = intellect
  112.  
  113.         hero:CalculateStatBonus()
  114.  
  115.         return 0.25
  116.     end)
  117.  
  118.     print('Stat Bonnus modified for hero '..hero:GetUnitName())
  119.  
  120. end
  121.  
  122. if not Attributes.applier then Attributes:Init() end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement