local U=require("\109\111\115\101\115")local e=require("\112\108\046\099\108\097\115\115")local Q=require("\105\110\118\111\107\097\116\105\111\110\046\100\111\116\097\050\046\107\118\046\072\101\114\111\075\101\121\086\097\108\117\101\115")local R=require("\105\110\118\111\107\097\116\105\111\110\046\099\111\110\115\116\046\108\105\109\105\116\115")CDOTA_BaseNPC_Hero=e(CDOTA_BaseNPC)local k={hasInventory=true}local A={abilityPoints=1;goldReliable=0;goldUnreliable=0}function CDOTA_BaseNPC_Hero._init(Q,e)e=U.extend({},k,A,e or{})Q:super(e)Q.__attributes=e end function CDOTA_BaseNPC_Hero.HeroLevelUp(e,U)if e:GetLevel()==R.MAX_HERO_LEVEL then return end e:SetLevel(e:GetLevel()+1)if e:GetLevel()==R.MAX_HERO_LEVEL then e:upgradeAllTalents()else e:SetAbilityPoints(e:GetAbilityPoints()+1)end end function CDOTA_BaseNPC_Hero.GetGold(U)return U.goldReliable+U.goldUnreliable end function CDOTA_BaseNPC_Hero.SetGold(Q,U,e)if e then Q.goldReliable=U else Q.goldUnreliable=U end end function CDOTA_BaseNPC_Hero.ModifyGold(R,U,e,Q)if e then R.goldReliable=R.goldReliable+U else R.goldUnreliable=R.goldUnreliable+U end return R:GetGold()end function CDOTA_BaseNPC_Hero.GetAbilityPoints(U)return U.abilityPoints end function CDOTA_BaseNPC_Hero.SetAbilityPoints(e,U)e.abilityPoints=U end function CDOTA_BaseNPC_Hero.UpgradeAbility(e,U)if e:GetAbilityPoints()>0 then U:UpgradeAbility(false)e:SetAbilityPoints(e:GetAbilityPoints()-1)end end function CDOTA_BaseNPC_Hero.upgradeAllTalents(U)local e=Q(U:GetName(),U.__attributes)local R=e:Talents()for e,Q in pairs(R)do local R=U:FindAbilityByName(Q)if R~=nil then U:UpgradeAbility(R)end end end
local m = require("moses")
local class = require("pl.class")

local HeroKeyValues = require("invokation.dota2.kv.HeroKeyValues")

local LIMITS = require("invokation.const.limits")

-- selene: allow(incorrect_standard_library_use)
CDOTA_BaseNPC_Hero = class(CDOTA_BaseNPC)

local ATTRIBUTES = { hasInventory = true }
local DEFAULTS = { abilityPoints = 1, goldReliable = 0, goldUnreliable = 0 }

function CDOTA_BaseNPC_Hero:_init(attributes)
  attributes = m.extend({}, ATTRIBUTES, DEFAULTS, attributes or {})

  self:super(attributes)
  self.__attributes = attributes
end

function CDOTA_BaseNPC_Hero:HeroLevelUp(_playEffects)
  if self:GetLevel() == LIMITS.MAX_HERO_LEVEL then
    return
  end

  self:SetLevel(self:GetLevel() + 1)

  if self:GetLevel() == LIMITS.MAX_HERO_LEVEL then
    self:upgradeAllTalents()
  else
    self:SetAbilityPoints(self:GetAbilityPoints() + 1)
  end
end

function CDOTA_BaseNPC_Hero:GetGold()
  return self.goldReliable + self.goldUnreliable
end

function CDOTA_BaseNPC_Hero:SetGold(amount, isReliable)
  if isReliable then
    self.goldReliable = amount
  else
    self.goldUnreliable = amount
  end
end

function CDOTA_BaseNPC_Hero:ModifyGold(amount, isReliable, _reason)
  if isReliable then
    self.goldReliable = self.goldReliable + amount
  else
    self.goldUnreliable = self.goldUnreliable + amount
  end

  return self:GetGold()
end

function CDOTA_BaseNPC_Hero:GetAbilityPoints()
  return self.abilityPoints
end

function CDOTA_BaseNPC_Hero:SetAbilityPoints(points)
  self.abilityPoints = points
end

function CDOTA_BaseNPC_Hero:UpgradeAbility(ability)
  if self:GetAbilityPoints() > 0 then
    ability:UpgradeAbility(false)
    self:SetAbilityPoints(self:GetAbilityPoints() - 1)
  end
end

-- not part of Dota2's scripting API
function CDOTA_BaseNPC_Hero:upgradeAllTalents()
  local kv = HeroKeyValues(self:GetName(), self.__attributes)
  local talents = kv:Talents()

  for _, value in pairs(talents) do
    local ability = self:FindAbilityByName(value)

    if ability ~= nil then
      self:UpgradeAbility(ability)
    end
  end
end
