4,951
edits
mNo edit summary |
Falterfire (talk | contribs) (Added 'no item' drop chance to NPC table) |
||
(4 intermediate revisions by one other user not shown) | |||
Line 75: | Line 75: | ||
result = result * 10 | result = result * 10 | ||
elseif stat == 'lootTable' then | elseif stat == 'lootTable' then | ||
return p._formatLootTable(npc['lootTable']) | return p._formatLootTable(npc['lootTable'], 0.75) | ||
elseif stat == 'requirements' then | elseif stat == 'requirements' then | ||
if npc['level'] ~= nil then | if npc['level'] ~= nil then | ||
Line 87: | Line 87: | ||
end | end | ||
function p._formatLootTable(lootTableIn) | function p._formatLootTable(lootTableIn, chanceMultIn) | ||
-- Expects lootTableIn to be in format {{itemID_1, itemWeight_1}, ..., {itemID_n, itemWeight_n}} | -- Expects lootTableIn to be in format {{itemID_1, itemWeight_1}, ..., {itemID_n, itemWeight_n}} | ||
if Shared.tableCount(lootTableIn) == 0 then | if Shared.tableCount(lootTableIn) == 0 then | ||
Line 93: | Line 93: | ||
end | end | ||
local chanceMult = (chanceMultIn or 1) * 100 | |||
local lootTable = Shared.clone(lootTableIn) | local lootTable = Shared.clone(lootTableIn) | ||
-- Sort table from most to least common drop | -- Sort table from most to least common drop | ||
table.sort(lootTable, function(a, b) | table.sort(lootTable, function(a, b) | ||
return a[2] > b[2] | if a[2] == b[2] then | ||
return a[1] < b[1] | |||
else | |||
return a[2] > b[2] | |||
end | |||
end) | end) | ||
Line 108: | Line 113: | ||
-- Get the length (in characters) of the largest drop chance so that they can be right aligned | -- Get the length (in characters) of the largest drop chance so that they can be right aligned | ||
local maxDropLen = string.len(Shared.round(lootTable[1][2] / totalWeight * | -- [4/16/21]: Adding info for no drop | ||
local maxDropLen = math.max(string.len(Shared.round(25, 2, 2)), string.len(Shared.round(lootTable[1][2] / totalWeight * chanceMult, 2, 2))) | |||
local returnPart = {} | local returnPart = {} | ||
table.insert(returnPart, '* ' .. string.rep(' ', math.max(0, (maxDropLen - string.len(Shared.round(25, 2, 2))) * 2)) .. '25.00% No Item') | |||
for i, drop in pairs(lootTable) do | for i, drop in pairs(lootTable) do | ||
local item, itemText, dropChance = Items.getItemByID(drop[1]), nil, Shared.round(drop[2] / totalWeight * | local item, itemText, dropChance = Items.getItemByID(drop[1]), nil, Shared.round(drop[2] / totalWeight * chanceMult, 2, 2) | ||
if item == nil then | if item == nil then | ||
itemText = 'Unknown' | itemText = 'Unknown' | ||
Line 120: | Line 128: | ||
end | end | ||
return table.concat(returnPart, ' | return table.concat(returnPart, '\r\n') | ||
end | |||
function p.getThievingNPCTable() | |||
local returnPart = {} | |||
-- Create table header | |||
table.insert(returnPart, '{| class="wikitable sortable stickyHeader"') | |||
table.insert(returnPart, '|- class="headerRow-0"\r\n!Target!!Name!!' .. Icons.Icon({'Thieving', type='skill', notext=true}).. ' Level!!Experience!!Max Hit!!Max Coins') | |||
local linkOverrides = { ['Golbin'] = 'Golbin (thieving)' } | |||
-- Create row for each NPC | |||
for i, npc in Shared.skpairs(SkillData.Thieving) do | |||
local linkText = npc.name | |||
if linkOverrides[npc.name] ~= nil then | |||
linkText = linkOverrides[npc.name] .. '|' .. npc.name | |||
end | |||
table.insert(returnPart, '|-\r\n|style="text-align: left;" |' .. Icons.Icon({npc.name, type='thieving', size=50, notext=true})) | |||
table.insert(returnPart, '|style="text-align: left;" |[[' .. linkText .. ']]') | |||
table.insert(returnPart, '|style="text-align: right;" |' .. p._getThievingNPCStat(npc, 'level')) | |||
table.insert(returnPart, '|style="text-align: right;" |' .. p._getThievingNPCStat(npc, 'xp')) | |||
table.insert(returnPart, '|style="text-align: right;" |' .. p._getThievingNPCStat(npc, 'maxHit')) | |||
table.insert(returnPart, '|style="text-align: right;" |' .. p._getThievingNPCStat(npc, 'maxCoins')) | |||
end | |||
table.insert(returnPart, '|}') | |||
return table.concat(returnPart, '\r\n') | |||
end | |||
function p.getThievingNavbox() | |||
local returnPart = {} | |||
-- Create table header | |||
table.insert(returnPart, '{| class="wikitable" style="text-align:center; clear:both; margin:auto; margin-bottom:1em;"') | |||
table.insert(returnPart, '|-\r\n!' .. Icons.Icon({'Thieving', type='skill', notext=true}) .. '[[Thieving|Thieving Targets]]') | |||
table.insert(returnPart, '|-\r\n|') | |||
local npcList = {} | |||
local linkOverrides = { ['Golbin'] = 'Golbin (thieving)' } | |||
-- Create row for each NPC | |||
for i, npc in Shared.skpairs(SkillData.Thieving) do | |||
local linkText = npc.name | |||
if linkOverrides[npc.name] ~= nil then | |||
linkText = linkOverrides[npc.name] .. '|' .. npc.name | |||
end | |||
table.insert(npcList, Icons.Icon({npc.name, type='thieving', notext=true}) .. ' [[' .. linkText .. ']]') | |||
end | |||
table.insert(returnPart, table.concat(npcList, ' • ')) | |||
table.insert(returnPart, '|}') | |||
return table.concat(returnPart, '\r\n') | |||
end | end | ||