Module:Items: Difference between revisions

2,339 bytes added ,  19 April 2023
getStatChangeString: Move from Module:Items/ComparisonTables to make available to other modules
(buildSmithableArmourNav: Add classes & styles typical of other nav boxes)
(getStatChangeString: Move from Module:Items/ComparisonTables to make available to other modules)
Line 129: Line 129:
end
end


--Gets the value of a given modifier for a given item
--Gets the value of a given modifier for a given itemg
--asString is false by default, when true it writes the full bonus text
--asString is false by default, when true it writes the full bonus text
function p._getItemModifier(item, modifier, skillID, asString)
function p._getItemModifier(item, modifier, skillID, asString)
Line 225: Line 225:
end
end
return p._getWeaponAttackType(item)
return p._getWeaponAttackType(item)
end
-- Produces a list of stat & modifier changes between two items of equipmednt
function p.getStatChangeString(item1, item2)
local changeArray = {}
local getSpecificStatString = function(val1, val2, subStr)
if val1 == nil then val1 = 0 end
if val2 == nil then val2 = 0 end
if val1 ~= val2 then
local txt = string.gsub(subStr, '{V}', Shared.numStrWithSign(val1 - val2))
table.insert(changeArray, txt)
end
end
--Unfortunately just gonna have to manually check all the changes I think...
local statList = {
-- {'statName', 'statDescription'}
{'stabAttackBonus', '{V} '..Icons.Icon({'Melee', notext=true})..' Stab Bonus'},
{'slashAttackBonus', '{V} '..Icons.Icon({'Melee', notext=true})..' Slash Bonus'},
{'blockAttackBonus', '{V} '..Icons.Icon({'Melee', notext=true})..' Block Bonus'},
{'meleeStrengthBonus', '{V} '..Icons.Icon({'Strength', type='skill', notext=true})..' Strength Bonus'},
{'rangedStrengthBonus', '{V} '..Icons.Icon({'Ranged', type='skill', notext=true})..' Strength Bonus'},
{'magicStrengthBonus', '{V}% '..Icons.Icon({'Magic', type='skill', notext=true})..' Damage Bonus'},
{'meleeDefenceBonus', '{V} '..Icons.Icon({'Defence', type='skill', notext=true})..' Defence Bonus'},
{'rangedDefenceBonus', '{V} '..Icons.Icon({'Ranged', type='skill', notext=true})..' Defence Bonus'},
{'magicDefenceBonus', '{V} '..Icons.Icon({'Magic', type='skill', notext=true})..' Defence Bonus'},
{'damageReduction', '{V}% Damage Reduction'},
{'attackLevelRequired', '{V} '..Icons.Icon({'Attack', type='skill', notext=true})..' Level Required'},
{'defenceLevelRequired', '{V} '..Icons.Icon({'Defence', type='skill', notext=true})..' Level Required'},
{'rangedLevelRequired', '{V} '..Icons.Icon({'Ranged', type='skill', notext=true})..' Level Required'},
{'magicLevelRequired', '{V} '..Icons.Icon({'Magic', type='skill', notext=true})..' Level Required'},
}
for i, stat in ipairs(statList) do
getSpecificStatString(Items._getItemStat(item1, stat[1]), Items._getItemStat(item2, stat[1]), stat[2])
end
-- Include differences in modifiers
local modDiff = Constants.getModifiersText(Constants.getModifiersDifference(item2.modifiers, item1.modifiers))
if modDiff ~= nil and modDiff ~= '' then
table.insert(changeArray, modDiff)
end
return table.concat(changeArray, '<br/>')
end
end