Jump to content

Module:ItemSources

From Apogea Wiki
Revision as of 22:21, 27 January 2026 by Jayarrowz (talk | contribs)

Module:ItemSources

This module displays item drop sources from NPCs in a table format.

Basic Usage

{{#invoke:ItemSources|list
|source1=NPC Name,Quantity,Rarity
|source2=NPC Name,Quantity,Rarity
}}

Source Format

Each source uses the format:

NPC Name,Quantity,Rarity
  • NPC Name - Required. The name of the NPC (automatically linked)
  • Quantity - Optional. Amount dropped (default: 1). Can be a range like "2-4"
  • Rarity - Optional. Drop rate like "1/50", "Rare", or "Always"

Parameters

Parameter Required Description
source1, source2, etc. Yes Source entries in "NPC,Quantity,Rarity" format
s1, s2, etc. No Shorthand for source1, source2, etc.

Examples

Basic Drop Table

{{#invoke:ItemSources|list
|source1=Goblin,1,1/50
|source2=Orc Warrior,2-4,1/100
|source3=Dragon,5,1/500
}}

Without Rarity

If no sources have rarity specified, the Rarity column is automatically hidden:

{{#invoke:ItemSources|list
|source1=Goblin,1
|source2=Orc Warrior,3
|source3=Chest,1
}}

Mixed Rarity

Some sources can have rarity while others don't:

{{#invoke:ItemSources|list
|source1=Cave Troll,1
|source2=Tomb Worker,1
|source3=Bear,1,Semi Rare
|source4=Bandit,1,Rare
}}

Using Shorthand

{{#invoke:ItemSources|list
|s1=Goblin,1,1/50
|s2=Orc,2,1/100
}}

Guaranteed Drops

{{#invoke:ItemSources|list
|source1=Quest Reward,1,Always
|source2=Boss,1,100%
|source3=Chest,1-3,Always
}}

Table Columns

Column Description
Source Linked name of the NPC
Quantity Amount dropped (can be a range)
Rarity Drop rate (only shown if any source has rarity)

Notes

  • The Rarity column only appears if at least one source has a rarity value
  • NPC names are automatically linked using [[NPC Name]]
  • Quantity can be a single number or a range (e.g., "1-5", "2-4")

-- Module:ItemSources
-- Displays item drop sources from NPCs in a table format
-- Usage: {{#invoke:ItemSources|list|source1=NPC Name,Quantity,Rarity}}

local p = {}

-- Helper to get args from either direct invoke or template
local function getArgs(frame)
    local args = {}
    
    local parent = frame:getParent()
    if parent and parent.args then
        for k, v in pairs(parent.args) do
            args[k] = v
        end
    end
    
    if frame.args then
        for k, v in pairs(frame.args) do
            args[k] = v
        end
    end
    
    return args
end

-- Display a list of item sources
function p.list(frame)
    local args = getArgs(frame)
    
    -- Parse all sources
    local sources = {}
    
    local i = 1
    while args["source" .. i] or args["s" .. i] do
        local sourceStr = args["source" .. i] or args["s" .. i]
        
        -- Parse: "NPC Name,Quantity,Rarity" or "NPC Name,Quantity" or just "NPC Name"
        local parts = {}
        for part in sourceStr:gmatch("[^,]+") do
            table.insert(parts, part:match("^%s*(.-)%s*$")) -- trim
        end
        
        local npcName = parts[1] or "Unknown"
        local quantity = parts[2] or "1"
        local rarity = parts[3] or ""
        
        table.insert(sources, {
            npc = npcName,
            quantity = quantity,
            rarity = rarity
        })
        
        i = i + 1
    end
    
    -- Check if any source has rarity
    local hasRarity = false
    for _, source in ipairs(sources) do
        if source.rarity ~= "" then
            hasRarity = true
            break
        end
    end
    
    -- Build HTML
    local html = {}
    
    table.insert(html, '<div class="item-sources">')
    
    -- Table
    table.insert(html, '<table class="wikitable sortable item-sources-table">')
    
    -- Header row
    table.insert(html, '<tr>')
    table.insert(html, '<th>Source</th>')
    table.insert(html, '<th>Quantity</th>')
    if hasRarity then
        table.insert(html, '<th>Rarity</th>')
    end
    table.insert(html, '</tr>')
    
    -- Render each source
    for _, source in ipairs(sources) do
        table.insert(html, '<tr>')
        
        -- Source name cell
        table.insert(html, string.format(
            '<td class="item-sources-cell-name">[[%s]]</td>',
            source.npc
        ))
        
        -- Quantity cell
        table.insert(html, string.format(
            '<td class="item-sources-cell-quantity">%s</td>',
            source.quantity
        ))
        
        -- Rarity cell (only if any source has rarity)
        if hasRarity then
            table.insert(html, string.format(
                '<td class="item-sources-cell-rarity">%s</td>',
                source.rarity
            ))
        end
        
        table.insert(html, '</tr>')
    end
    
    table.insert(html, '</table>')
    table.insert(html, '</div>')
    
    return frame:preprocess(table.concat(html, '\n'))
end

return p