4,951
edits
Falterfire (talk | contribs) (Added p.getItemLootSourceTable) |
Falterfire (talk | contribs) (Updates to getItemLootSourceTable) |
||
Line 389: | Line 389: | ||
--Set up function for adding rows | --Set up function for adding rows | ||
local buildRow = function(source, type, qty, chance) | local buildRow = function(source, type, minqty, qty, chance) | ||
local rowTxt = '\r\n|-' | local rowTxt = '\r\n|-' | ||
rowTxt = rowTxt..'\r\n|style ="text-align: left;"|'..source | rowTxt = rowTxt..'\r\n|style ="text-align: left;"|'..source | ||
rowTxt = rowTxt..'\r\n|style ="text-align: left;"|'..type | rowTxt = rowTxt..'\r\n|style ="text-align: left;"|'..type | ||
rowTxt = rowTxt..'\r\n|style ="text-align: right;" data-sort-value:"'..qty..'"| | rowTxt = rowTxt..'\r\n|style ="text-align: right;" data-sort-value:"'..qty..'"|'..minqty | ||
if qty | if qty ~= minqty then rowTxt = rowTxt..' - '..qty end | ||
rowTxt = rowTxt..'\r\n|style ="text-align: right;"|'..Shared.round(chance, 2, 2)..'%' | rowTxt = rowTxt..'\r\n|style ="text-align: right;"|'..Shared.round(chance, 2, 2)..'%' | ||
return rowTxt | return rowTxt | ||
Line 404: | Line 404: | ||
--First up: Can we kill somebody and take theirs? | --First up: Can we kill somebody and take theirs? | ||
for i, monster in pairs(MonsterData.Monsters) do | for i, monster in pairs(MonsterData.Monsters) do | ||
local minqty = 1 | |||
local qty = 1 | local qty = 1 | ||
local chance = 0 | local chance = 0 | ||
local wt = 0 | local wt = 0 | ||
local totalWt = 0 | local totalWt = 0 | ||
if monster.bones == item.id then | --Only add bones if this monster has loot (ie appears outside a dungeon) and isn't a boss | ||
--... unless we're looking for Shards of course, at which point we'll take any monster with the right bones | |||
if ((monster.lootTable ~= nil and not monster.isBoss) or Shared.contains(item.name, 'Shard')) and monster.bones == item.id then | |||
qty = monster.boneQty ~= nil and monster.boneQty or 1 | qty = monster.boneQty ~= nil and monster.boneQty or 1 | ||
minqty = qty | |||
chance = 100 | chance = 100 | ||
elseif monster.lootTable ~= nil then | elseif monster.lootTable ~= nil then | ||
Line 426: | Line 430: | ||
if chance > 0 then | if chance > 0 then | ||
local sourceTxt = Icons.Icon({monster.name, type='monster'}) | local sourceTxt = Icons.Icon({monster.name, type='monster'}) | ||
table.insert(dropRows, {source = sourceTxt, type = '[[Monster]]', qty = qty, chance = chance}) | table.insert(dropRows, {source = sourceTxt, type = '[[Monster]]', minqty = minqty, qty = qty, chance = chance}) | ||
end | end | ||
end | end | ||
Line 448: | Line 452: | ||
chance = (wt / totalWt) * 100 | chance = (wt / totalWt) * 100 | ||
local sourceTxt = Icons.Icon({item2.name, type='item'}) | local sourceTxt = Icons.Icon({item2.name, type='item'}) | ||
table.insert(dropRows, {source = sourceTxt, type = '[[Chest]]', qty = qty, chance = chance}) | table.insert(dropRows, {source = sourceTxt, type = '[[Chest]]', minqty = 1, qty = qty, chance = chance}) | ||
end | end | ||
end | end | ||
Line 470: | Line 474: | ||
chance = (wt / totalWt) * 75 | chance = (wt / totalWt) * 75 | ||
local sourceTxt = Icons.Icon({npc.name, type='npc'}) | local sourceTxt = Icons.Icon({npc.name, type='npc'}) | ||
table.insert(dropRows, {source = sourceTxt, type = thiefType, qty = qty, chance = chance}) | table.insert(dropRows, {source = sourceTxt, type = thiefType, minqty = 1, qty = qty, chance = chance}) | ||
end | end | ||
end | end | ||
end | end | ||
table.sort(dropRows, function(a, b) return a.qty * a.chance > b.qty * b.chance end) | |||
for i, data in pairs(dropRows) do | for i, data in pairs(dropRows) do | ||
result = result..buildRow(data.source, data.type, data.qty, data.chance) | result = result..buildRow(data.source, data.type, data.minqty, data.qty, data.chance) | ||
end | end | ||