badspacebar / sdk

6 stars 3 forks source link

damagelib is not calculating any items damage #20

Closed 69sinisterblade69 closed 1 year ago

69sinisterblade69 commented 1 year ago

[Not visible in screenshots and not present in code but I also tested player:spellSlot():getDamage() and damagelib.get_spell_damage("XerathArcanopulseChargeUp", 0, player, resQ.object, false, 0) and was getting the same result as damagelib.calc_magical_damage(), so all points against it also stand against those]

Relevant pieces of code.

local q = {
    damage = function(m)
        return damagelib.get_spell_damage("XerathArcanopulseChargeUp", 0, player, player, true, 0)
    end,
   }

-- not the best code I've written xd
 function common.MagicReduction(target, damageSource)
    local damageSource = damageSource or player
    local flatpens = damageSource.flatMagicPenetration
    for i=6,0,-1 do --shadowflame monkeypatch
        if player:itemID(i) == 4645 then
            if target.health <= 1000 then flatpens = flatpens + 20 goto shadowshit end
            if target.health <= 1150 then flatpens = flatpens + 19 goto shadowshit end
            if target.health <= 1300 then flatpens = flatpens + 18 goto shadowshit end
            if target.health <= 1450 then flatpens = flatpens + 17 goto shadowshit end
            if target.health <= 1600 then flatpens = flatpens + 16 goto shadowshit end
            if target.health <= 1750 then flatpens = flatpens + 15 goto shadowshit end
            if target.health <= 1900 then flatpens = flatpens + 14 goto shadowshit end
            if target.health <= 2050 then flatpens = flatpens + 13 goto shadowshit end
            if target.health <= 2200 then flatpens = flatpens + 12 goto shadowshit end
            if target.health <= 2350 then flatpens = flatpens + 11 goto shadowshit end
            if target.health > 2350 then flatpens = flatpens + 10 goto shadowshit end
        end
    end
    ::shadowshit::
    local magicResist = (target.spellBlock * damageSource.percentMagicPenetration) - flatpens
    return magicResist >= 0 and (100 / (100 + magicResist)) or (2 - (100 / (100 - magicResist)))
end

chat.print(q.damage().." "..tostring(damagelib.calc_magical_damage(player, resQ.object, q.damage())).." "..tostring(q.damage() * common.MagicReduction(resQ.object, player)))

In q.damage() damagelib.get_spell_damage() i'm using player as both source and target as a workaround to get raw damage, because I'm not sure what's the correct way to do that and I can't just pass nil as a target (I think it may be spell_slot:calculate(spellNameHash, calculationHash), but I didn't want to deal with hashes, and the output is still correct [or it's +-1 damage off, not sure how rounding should work in this case, which is insignificant in this example])

Target dummy has 200 magic resist image

As you can see q.damage() * common.MagicReduction() calculates damage correctly (61) but damagelib.calc_magical_damage() doesn't (57).

I understand if you don't want to add items damage like Luden or Night harvester to damagelib.calc_magical_damage() or player:spellSlot():getDamage() or any other damage calc function but I think maybe exception should be made for items like Shadowflame as it only changes magic penetration and doesn't have cooldown or horizon focus (Im not expecting it to tell me if that skill will activate it but at least take it into account once target has its buff as it is active for 6 seconds)

badspacebar commented 1 year ago

example to using damagelib

local damagelib = module.internal('damagelib')
-- target is practice_tool_dummy
local g_target = nil
for i=0, objManager.enemies_n-1 do
    g_target = objManager.enemies[i]
    break
end
print('AA damage', damagelib.calc_aa_damage(player, g_target, true))
print('Q  damage', damagelib.get_spell_damage('XerathArcanopulseChargeUp', 0, player, g_target, false, 0))
print('W1 damage', damagelib.get_spell_damage('XerathArcaneBarrage2', 1, player, g_target, false, 0))
print('W2 damage', damagelib.get_spell_damage('XerathArcaneBarrage2', 1, player, g_target, false, 1))

damage calculation for Shadowflame/FirstStrike will be fixed soon