Add better damage conversion (bad code inside)
Posted: Sat Apr 06, 2013 1:54 am
In short, add a list that can convert any elements to any other elements:
like {DT.FIRE = {DT.ACID = 0.75}} EDIT: I don't know how arrays work, I thought that these constants were numbers but something like this, perhaps by name as I had done it elsewhere. A second array stores damage types not to convert to
This is useful for addon developers to be able to properly convert damage without superloading (which is bad) and generalizes the fire damage convert of the alchemist (also allowing it to stack to a degree). And it can make cool artifacts or skills that convert damage types.
Not guarenteed to compile or be correct, this does not perfectly handle conversion sums over 100%, which could be done by normalizing the sum. This does it by ignoring damage over the base in an undefined order.
This code is definitely incorrect probably.
like {DT.FIRE = {DT.ACID = 0.75}} EDIT: I don't know how arrays work, I thought that these constants were numbers but something like this, perhaps by name as I had done it elsewhere. A second array stores damage types not to convert to
This is useful for addon developers to be able to properly convert damage without superloading (which is bad) and generalizes the fire damage convert of the alchemist (also allowing it to stack to a degree). And it can make cool artifacts or skills that convert damage types.
Not guarenteed to compile or be correct, this does not perfectly handle conversion sums over 100%, which could be done by normalizing the sum. This does it by ignoring damage over the base in an undefined order.
This code is definitely incorrect probably.
Code: Select all
if src.convert_damage[typ] then
local dam_base = dam
local add_dam = 0
for new_type, frac in pairs(src.convert_damage[typ]) do
if not src.no_convert[new_type] then
dam = math.max(dam - frac * dam_base, 0)
old_no_convert = src.no_convert[new_type] = true
src.no_convert[new_type] = true
add_dam = add_dam + DamageType:get(new_type).projector(src, x, y, new_type, math.max(dam_base * frac, dam), tmp, no_martyr)
src.no_convert = old_no_convert
end
end
if (dam <= 0) then return add_dam end
end