4,951
edits
Falterfire (talk | contribs) (Swapped Mining over to using SkillData) |
Falterfire (talk | contribs) (If everything worked, the equipment table now automatically hides columns that are zero for all items in the table) |
||
Line 1,618: | Line 1,618: | ||
--Getting some lists set up here that will be used later | --Getting some lists set up here that will be used later | ||
--First, the list of columns used by both weapons & armour | --First, the list of columns used by both weapons & armour | ||
local statColumns = {'slashAttackBonus', 'stabAttackBonus','blockAttackBonus','rangedAttackBonus', 'magicAttackBonus', 'strengthBonus', 'rangedStrengthBonus', 'magicDamageBonus', 'defenceBonus', 'rangedDefenceBonus', 'magicDefenceBonus'} | local statColumns = {'slashAttackBonus', 'stabAttackBonus','blockAttackBonus','rangedAttackBonus', 'magicAttackBonus', 'strengthBonus', 'rangedStrengthBonus', 'magicDamageBonus', 'defenceBonus', 'rangedDefenceBonus', 'magicDefenceBonus', 'damageReduction', 'attackLevelRequired', 'defenceLevelRequired', 'rangedLevelRequired', 'magicLevelRequired'} | ||
--Then the lists for just weapons/just armour | --Then the lists for just weapons/just armour | ||
--Then the list of weapon types | --Then the list of weapon types | ||
local weaponTypes = {'Magic Staff', 'Magic Wand', 'Ranged Weapon', 'Weapon'} | local weaponTypes = {'Magic Staff', 'Magic Wand', 'Ranged Weapon', 'Weapon'} | ||
local isWeaponType = Shared.contains(weaponTypes, type) | local isWeaponType = Shared.contains(weaponTypes, type) | ||
-- | --Now we need to figure out which items are in this list | ||
local itemList = {} | local itemList = {} | ||
for i, itemBase in pairs(ItemData.Items) do | for i, itemBase in pairs(ItemData.Items) do | ||
Line 1,711: | Line 1,652: | ||
end | end | ||
end | end | ||
--Now that we have a preliminary list, let's figure out which columns are irrelevant (IE are zero for all items in the selection) | |||
mw.log(table.concat(statColumns, ', ')) | |||
local ignoreColumns = Shared.clone(statColumns) | |||
for i, item in pairs(itemList) do | |||
local ndx = 1 | |||
while Shared.tableCount(ignoreColumns) > ndx do | |||
if p._getItemStat(item, ignoreColumns[ndx], true) ~= 0 then | |||
table.remove(ignoreColumns, ndx) | |||
else | |||
ndx = ndx + 1 | |||
end | |||
end | |||
end | |||
mw.log(table.concat(ignoreColumns, ', ')) | |||
--Now to remove the ignored columns (and also we need to track groups like defence bonuses to see how many remain) | |||
local attBonusCols = 5 | |||
local strBonusCols = 2 | |||
local defBonusCols = 3 | |||
local lvlReqCols = 4 | |||
local ndx = 1 | |||
while Shared.tableCount(statColumns) >= ndx do | |||
local colName = statColumns[ndx] | |||
if Shared.contains(ignoreColumns, colName) then | |||
mw.log('Removing '..colName..' ('..ndx..')') | |||
if Shared.contains(colName, 'AttackBonus') then attBonusCols = attBonusCols - 1 end | |||
if Shared.contains(colName, 'trengthBonus') then strBonusCols = strBonusCols - 1 end | |||
if Shared.contains(colName, 'efenceBonus') then defBonusCols = defBonusCols - 1 end | |||
if Shared.contains(colName, 'LevelRequired') then lvlReqCols = lvlReqCols - 1 end | |||
table.remove(statColumns, ndx) | |||
else | |||
ndx = ndx + 1 | |||
end | |||
end | |||
mw.log(table.concat(statColumns, ', ')) | |||
--Alright, let's start the table by building the shared header | |||
local result = '{| class="wikitable sortable stickyHeader"\r\n|-class="headerRow-0"' | |||
if isWeaponType then | |||
--Weapons have extra columns here for Attack Speed and "Two Handed?" | |||
result = result..'\r\n!colspan="4"|' | |||
else | |||
result = result..'\r\n!colspan="2"|' | |||
end | |||
if attBonusCols > 0 then | |||
result = result..'\r\n!colspan="'..attBonusCols..'"style="padding:0 0.5em 0 0.5em;"|Attack Bonus' | |||
end | |||
if strBonusCols > 0 then | |||
result = result..'\r\n!colspan="'..strBonusCols..'"style="padding:0 0.5em 0 0.5em;"|Strength Bonus' | |||
end | |||
if Shared.contains(statColumns, 'magicDamageBonus') then | |||
result = result..'\r\n!colspan="1"style="padding:0 0.5em 0 0.5em;"|% Damage Bonus' | |||
end | |||
if defBonusCols > 0 then | |||
result = result..'\r\n!colspan="'..defBonusCols..'"style="padding:0 0.5em 0 0.5em;"|Defence Bonus' | |||
end | |||
if Shared.contains(statColumns, 'damageReduction') then | |||
result = result..'\r\n!colspan="1"style="padding:0 0.5em 0 0.5em;"|Damage Reduction' | |||
end | |||
if lvlReqCols > 0 then | |||
result = result..'\r\n!colspan="'..lvlReqCols..'"style="padding:0 0.5em 0 0.5em;"|Levels Required' | |||
end | |||
result = result..'\r\n!colspan="1"|' | |||
--One header row down, one to go | |||
result = result..'\r\n|-class="headerRow-1"' | |||
result = result..'\r\n!style="padding:0 1em 0 0.5em;"|Item' | |||
result = result..'\r\n!style="padding:0 1em 0 0.5em;"|Name' | |||
--Weapons have Attack Speed here | |||
if isWeaponType then | |||
result = result..'\r\n!style="padding:0 1em 0 0.5em;"|Attack Speed' | |||
result = result..'\r\n!style="padding:0 1em 0 0.5em;"|Two Handed?' | |||
end | |||
--Attack bonuses | |||
if Shared.contains(statColumns, 'slashAttackBonus') then | |||
result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Attack', type='skill', notext='true'}) | |||
end | |||
if Shared.contains(statColumns, 'stabAttackBonus') then | |||
result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Strength', type='skill', notext='true'}) | |||
end | |||
if Shared.contains(statColumns, 'blockAttackBonus') then | |||
result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Defence', type='skill', notext='true'}) | |||
end | |||
if Shared.contains(statColumns, 'rangedAttackBonus') then | |||
result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Ranged', type='skill', notext='true'}) | |||
end | |||
if Shared.contains(statColumns, 'magicAttackBonus') then | |||
result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Magic', type='skill', notext='true'}) | |||
end | |||
--Strength bonuses | |||
if Shared.contains(statColumns, 'strengthBonus') then | |||
result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Strength', type='skill', notext='true'}) | |||
end | |||
if Shared.contains(statColumns, 'rangedStrengthBonus') then | |||
result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Ranged', type='skill', notext='true'}) | |||
end | |||
if Shared.contains(statColumns, 'magicDamageBonus') then | |||
result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Magic', type='skill', notext='true'}) | |||
end | |||
--Defence bonuses | |||
if Shared.contains(statColumns, 'defenceBonus') then | |||
result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Defence', type='skill', notext='true'}) | |||
end | |||
if Shared.contains(statColumns, 'rangedDefenceBonus') then | |||
result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Ranged', type='skill', notext='true'}) | |||
end | |||
if Shared.contains(statColumns, 'magicDefenceBonus') then | |||
result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Magic', type='skill', notext='true'}) | |||
end | |||
if Shared.contains(statColumns, 'damageReduction') then | |||
result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Defence', type='skill', notext='true'}) | |||
end | |||
--Level requirements | |||
if Shared.contains(statColumns, 'attackLevelRequired') then | |||
result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Attack', type='skill', notext='true'}) | |||
end | |||
if Shared.contains(statColumns, 'defenceLevelRequired') then | |||
result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Defence', type='skill', notext='true'}) | |||
end | |||
if Shared.contains(statColumns, 'rangedLevelRequired') then | |||
result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Ranged', type='skill', notext='true'}) | |||
end | |||
if Shared.contains(statColumns, 'magicLevelRequired') then | |||
result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Magic', type='skill', notext='true'}) | |||
end | |||
--And finally Sources | |||
result = result..'\r\n!style="padding:0 1em 0 0.5em;"|Sources' | |||
table.sort(itemList, function(a, b) return a.id < b.id end) | table.sort(itemList, function(a, b) return a.id < b.id end) | ||
Line 1,720: | Line 1,790: | ||
result = result..'\r\n|style ="text-align: left;padding: 0 0.5em 0 0.5em;"|[['..item.name..']]' | result = result..'\r\n|style ="text-align: left;padding: 0 0.5em 0 0.5em;"|[['..item.name..']]' | ||
result = result..'\r\n| style ="text-align: right;padding: 0 0.5em 0 0;" |'..Shared.formatnum(item.attackSpeed) | result = result..'\r\n| style ="text-align: right;padding: 0 0.5em 0 0;" |'..Shared.formatnum(item.attackSpeed) | ||
--That's the first list out of the way, now for 2-Handed | --That's the first list out of the way, now for 2-Handed | ||
result = result..'\r\n| style ="text-align: right;"|' | result = result..'\r\n| style ="text-align: right;"|' | ||
if item.isTwoHanded then result = result..'Yes' else result = result..'No' end | if item.isTwoHanded then result = result..'Yes' else result = result..'No' end | ||
for j, statName in pairs(statColumns) do | |||
for j, statName in pairs( | |||
local statValue = p._getItemStat(item, statName, true) | local statValue = p._getItemStat(item, statName, true) | ||
result = result..'\r\n| style ="text-align: right;padding: 0 0.5em 0 0;' | result = result..'\r\n| style ="text-align: right;padding: 0 0.5em 0 0;' | ||
if not Shared.contains(statName, 'LevelRequired') then | |||
if statValue > 0 then | |||
result = result..'background-color:lightgreen;' | |||
elseif statValue < 0 then | |||
result = result..'background-color:lightpink;' | |||
end | |||
end | |||
result = result..'"|'..Shared.formatnum(statValue) | result = result..'"|'..Shared.formatnum(statValue) | ||
if statName == 'magicDamageBonus' or statName == 'damageReduction' then result = result..'%' end | if statName == 'magicDamageBonus' or statName == 'damageReduction' then result = result..'%' end | ||
Line 1,756: | Line 1,821: | ||
elseif statValue < 0 then | elseif statValue < 0 then | ||
result = result..'background-color:lightpink;' | result = result..'background-color:lightpink;' | ||
end | end | ||
result = result..'"|'..Shared.formatnum(statValue) | result = result..'"|'..Shared.formatnum(statValue) |