Skip to main content

DamageLib

Damage Library for accurate damage calculations.

Properties

slot: SpellSlot

Functions

GetDamageFunctionMap

DamageLib.GetDamageFunctionMap() unordered_map<hash, fun(source: AIBaseHero, bRawDamage: boolean, stage: integer): float>

Returns <hash, function> map with functions which calculate spell damage.

tip

You can extend our DamageLib with missing damage calculations for your champion script or overwrite existing ones if you think it will improve it.

note

Function must accept (source: AIBaseHero, bRawDamage: boolean, stage: integer) parameters and return float (damage).

Example: Get damage function map and replace Lux Q damage calculation function.
local LuxLightBindingSpellDataHash = Game.spelldataHash("LuxLightBinding") -- Spell Data hash is used as key for damageMap
local damageMap = DamageLib.GetDamageFunctionMap()
damageMap[LuxLightBindingSpellDataHash] = function(source, target, bRawDamage, stage)
rawDamage = 100
return bRawDamage and rawDamage or DamageLib.CalculateMagicalDamage(source, target, rawDamage)
end

GetSpellDamage

DamageLib.GetSpellDamage(
spellHash: number,
source: AIHeroClient,
target: AIBaseClient,
bRawDamage: boolean,
stage: number,
slot: SpellSlot
) float

ArgumentTypeDescription
spellHashnumber - unsignedspelldataHash of the given spell.
sourceAIHeroClientSource unit.
targetAIBaseClientTarget unit.
bRawDamagebooleanReturn raw damage if true.
stagenumber - integerReturn damage of certain stage, if spell supports multiple stages.
slotSpellSlotSpellSlot of the given spell.

Returns calculated damage of the given spell.


GetSpellDamage

DamageLib.GetSpellDamage(
spellName: string,
source: AIHeroClient,
target: AIBaseClient,
bRawDamage: boolean,
stage: number
) float

ArgumentTypeDescription
spellNamestringName of the given spell.
sourceAIHeroClientSource unit.
targetAIBaseClientTarget unit.
bRawDamagebooleanReturn raw damage if true.
stagenumber - integerReturn damage of certain stage, if spell supports multiple stages.

Returns calculated damage of the given spell.


CalculateAutoAttackDamage

DamageLib.CalculateAutoAttackDamage(source: AIBaseClient, target: AIBaseClient) float

ArgumentTypeDescription
sourceAIBaseClientSource unit. AA damage will be taked from this unit.
targetAIBaseClientTarget unit

Returns calculated auto attack damage including various modifiers (armor, resistances, empowerments etc).


CalculatePhysicalDamage

DamageLib.CalculatePhysicalDamage(source: AIBaseClient, target: AIBaseClient, amount: float) float

ArgumentTypeDescription
sourceAIBaseClientSource unit
targetAIBaseClientTarget unit
amountfloatRaw damage

Returns calculated physical damage including various modifiers (armor, resistances, empowerments etc).


CalculateMagicalDamage

DamageLib.CalculateMagicalDamage(source: AIBaseClient, target: AIBaseClient, amount: float) float

ArgumentTypeDescription
sourceAIBaseClientSource unit
targetAIBaseClientTarget unit
amountfloatRaw damage

Returns calculated magical damage including various modifiers (armor, resistances, empowerments etc).


Examples

Replace Lux Q damage calc function, get damage from tooltip and print it using SDKSpell:GetDamage().

local LuxLightBindingSpellDataHash = Game.spelldataHash("LuxLightBinding") -- Spell Data hash is used as key for damageMap
local LuxLightBindingHash = Game.fnvhash("LuxLightBinding") -- FNV hash is used by AIBaseClient:GetSpellSlot(spellHash) function
local TotalDamageHash = Game.fnvhash("TotalDamageTT") -- FNV hash is used to access tooltip property with SpellBookEntry:GetCalculateInfo(...)
local damageMap = DamageLib.GetDamageFunctionMap()

damageMap[LuxLightBindingSpellDataHash] = function(source, target, bRawDamage, stage)
local slot = source:GetSpellSlot(LuxLightBindingHash) -- This uses fnv hash
if slot == SpellSlot.NullSlot then
return 0
end

local entry = source:GetSpellEntry(slot)
if not entry or not entry:IsValid() then
return 0
end

local rawDamage = entry:GetCalculateInfo(source, TotalDamageHash, slot)

if bRawDamage or not target or not target:IsValid() then
return rawDamage
end

return DamageLib.CalculateMagicalDamage(source, target, rawDamage)
end

local Q = SDKSpell.Create(SpellSlot.Q, 1300, DamageType.Magical)
print("Q Damage", Q:GetDamage(Game.localPlayer)) -- This will use our custom damage calc function