Module:Items/SourceTables: Difference between revisions

added a p.getItemMonsterSources for use in a table for Mazunki
(_getItemLootSourceTable: Amend display of very small chances)
(added a p.getItemMonsterSources for use in a table for Mazunki)
Line 341: Line 341:
if isDrop then
if isDrop then
-- Item drops when the monster is killed
-- Item drops when the monster is killed
table.insert(killStrPart, Icons.Icon({monster.name, type='monster', notext=true}))
table.insert(killStrPart, Icons.Icon({monster.name, type='monster', notext=true}))
end
end
end
end
Line 566: Line 566:
table.insert(lineArray, '[[Events]]')
table.insert(lineArray, '[[Events]]')
end
end
 
--Gold Topaz Ring drops from any action (when not wearing a Gold Topaz Ring)
--Gold Topaz Ring drops from any action (when not wearing a Gold Topaz Ring)
--Also handling Signet Ring things here
--Also handling Signet Ring things here
Line 950: Line 950:


return table.concat(resultPart)
return table.concat(resultPart)
end
function p._getItemMonsterSources(item)
local resultArray = {}
for i, monster in ipairs(MonsterData.Monsters) do
local chance = 0
local weight = 0
local minQty = 1
local maxQty = 1
if monster.bones == item.id and Monsters.getMonsterBones(monster) ~= nil then
-- Item is a bone, and is either a shard from God dungeons or dropped by a non-boss monster with a loot table
chance = 1
weight = 1
if monster.bonesQty ~= nil then
minQty = monster.bonesQty
maxQty = monster.bonesQty
end
elseif monster.lootTable ~= nil then
-- If the monster has a loot table, check if the item we are looking for is in there
-- Dungeon exclusive monsters don't count as they are either:
--  - A monster before the boss, which doesn't drop anything except shards (checked above)
--  - A boss monster, whose drops are accounted for in data from Areas instead
local monsterWeight
for j, loot in ipairs(monster.lootTable) do
weight = weight + loot[2]
if loot[1] == item.id and not Monsters._isDungeonOnlyMonster(monster) then
chance = loot[2]
maxQty = loot[3]
end
end
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100
chance = chance * lootChance
weight = weight * 100
chance, weight = Shared.fractionpair(chance, weight)
end
if chance > 0 then
-- Item drops when the monster is killed
table.insert(resultArray, {monster = monster.id, chance = chance, weight = weight, minQty = minQty, maxQty = maxQty})
end
end
return resultArray
end
function p.getItemMonsterSources(itemName)
local item = Items.getItem(itemName)
return p._getItemMonsterSources(item)
end
end


return p
return p