FANDOM


-- <pre>
local p = {}
local yesno = require("Module:Yesno")
local weaknessClickpick = mw.loadData("Module:Weakness clickpic/data")
local Exchange = require("Module:Exchange")
local Coins = require("Module:Coins")
local AddCommas = require("Module:Addcommas")
local skillClickpick = require("Module:Skill clickpic")
 
-- Accepted rowTypes
function makeRowType(c, iconOnly)
	local v = weaknessClickpick[c]
	local s = v.text or v.link
	if iconOnly then
	    return string.format("[[File:%s|26x26px|link=%s]]",v.image,v.link)
	else
	    return string.format("[[File:%s|26x26px|link=%s]] [[%s|%s]]",v.image,v.link,v.link,s)
	end
end
 
local rowTypes = {
    melee = makeRowType('melee', false),
    ['melee icon'] = makeRowType('melee', true),
    ranged = makeRowType('ranged', false),
    ['ranged icon'] = makeRowType('ranged', true),
    magic =makeRowType('magic', false),
    ['magic icon'] =makeRowType('magic', true),
    all = makeRowType('none', false),
    ['all icon'] = makeRowType('none', true),
    none = "-"
}
 
-- Accepted headerTypes
local headerTypes = {
    melee = "[[File:Attack.png|x34px|link=Melee]]<br />Item",
    ranged = "[[File:Ranged.png|x34px|link=Ranged]]<br />Item",
    magic = "[[File:Magic.png|x34px|link=Magic]]<br />Item",
    all = "[[File:CombatSwords.png|All]]<br />Item",
    hybrid = "[[File:CombatSwords.png|Hybrid]]<div style='display:inline-block; width:50px; text-align:center; margin-top:-10px; margin-bottom:10px; position:relative; top:12px'>'''Hybrid''' '''Item'''</div>",
    mixed = "Item",
    none = "Item"
}
 
-- Accepted weapon styles
local styles = {
    stab = "'''Stab'''",
    stabbing = "'''Stab'''",
    crush = "'''Crush'''",
    crushing = "'''Crush'''",
    slash = "'''Slash'''",
    slashing = "'''Slash'''",
    arrow = "'''Arrow'''",
    arrows = "'''Arrow'''",
    bolt = "'''Bolt'''",
    bolts = "'''Bolt'''",
    thrown = "'''Thrown'''",
    spell = "'''Spell-<br />casting'''",
    spells = "'''Spell-<br />casting'''",
    ['spell-casting'] = "'''Spell-<br />casting'''",
    none = "'''None'''"
}
 
local function isnotempty(s)
    return not (s == nil or s == "")
end
 
local function addSortCell(row, n, type)
    for i=1,n do    
            row:tag("th"):addClass(type):done()
    end
    return row
end
 
function p.main(frame)
    local frameargs = frame:getParent().args
    --local frameargs = frame
    local htmltable = mw.html.create("table")       -- The output of this module
    local tblrow = ""
    local tblcell = ""
    local totalPrice = 0    -- Sum of the individual prices
    local totalspanrange = 6    -- This is the minimum spanrange of the label incase the totals parameter is used
    local imageRowsSpan = 0    -- Default row span
 
    -- Create the tabel header
    --[[Parameters used (variable type)     [note]
        class / type    (string)            [@mandatory]
        noinv           (yes/no)            [@optional, default is no, if yes the rowspan of the class header is 1 otherwise its 2]
        skill           (string)            [@optional, accepted values are those for Module:Skill clickpic]
        skill2          (string)            [@optional, accepted values are those for Module:Skill clickpic]
        noweapon        (yes/no)            [@optional, default is no, if yes hides the weapons stats]
        price           (ge/number/string)  [@optional, ge is the the string "ge", ge and number are preferred so it adds to the totalprice]
        price2          (ge/number/string)  [@optional]
        image           (string)            [@optional, image is given by the form "image name.png"]
        image2          (string)            [@optional]
        rows            (number)            [@optional, only affects image and image2]
        tot             (number)            [@optional, only affects image and image2]
        sortable        (yes/no)            [@optional]
    ]]
 
    htmltable
        :addClass("wikitable infotableBonuses")
        :css("text-align", "center")
 
        -- Make first header row
        tblrow = htmltable:tag("tr")
 
            -- Set the header class
            tblcell = tblrow:tag("th")
                :attr("rowspan", "2")
                :wikitext(headerTypes[string.lower(frameargs.class or frameargs.type or "")] or ("''Type Unknown<br /><small>[" .. tostring(mw.uri.fullUrl( mw.title.getCurrentTitle().prefixedText, "action=edit")) .. " edit]</small>''"))
                if not yesno(frameargs.noinv) then
                    tblcell
                        :attr("colspan", "2")
                end
 
            -- Add extra type colomn if the header class is mixed
            if string.lower(frameargs.class or frameargs.type or "") == "mixed" then
                tblrow
                    :tag("th")
                        :attr("rowspan", "2")
                        :wikitext("Type")
                    :done()
                totalspanrange = totalspanrange + 1
            end
 
            -- Add extra skill column
            if isnotempty(frameargs.skill) then
                tblrow
                    :tag("th")
                        :attr("rowspan", "2")
                        :css("vertical-align", "bottom")
                        :wikitext(skillClickpick._main(frameargs.skill or ""))
                            :tag("br")
                            :done()
                        :tag("span")
                            :css("font-size", "90%")
                            :wikitext("Level")
                        :done()
                    :done()
                totalspanrange = totalspanrange + 1
            end
 
            -- Add extra skill2 column
            if isnotempty(frameargs.skill2) then
                tblrow
                    :tag("th")
                        :attr("rowspan", "2")
                        :css("vertical-align", "bottom")
                        :wikitext(skillClickpick._main(frameargs.skill2 or ""))
                            :tag("br")
                            :done()
                        :tag("span")
                            :css("font-size", "90%")
                            :wikitext("Level")
                        :done()
                    :done()
                totalspanrange = totalspanrange + 1
            end
 
            -- Show/hide weapon stats
            if not yesno(frameargs.noweapon) then
                tblrow
                    :tag("th")
                        :attr("colspan", "3")
                        :wikitext("Main-hand")
                    :done()
                    :tag("th")
                        :attr("colspan", "3")
                        :wikitext("Off-hand")
                    :done()
                totalspanrange = totalspanrange + 6
            end
 
            -- Add atribute columns
            tblrow
                :tag("th")
                    :attr("colspan", "3")
                    :attr("title", "Determines their character's endurance determined by their armour rating, life point boost, and prayer bonus")
                    :wikitext("Attribute")
                :done()
 
            -- Add style bonuses columns
            tblrow
                :tag("th")
                    :attr("colspan", "3")
                    :wikitext("Style&nbsp;bonus")
                :done()
 
            -- Add price and/or price2 column
            if yesno(frameargs.price) ~= yesno(frameargs.price2) then   -- XOR
                tblrow
                    :tag("th")
                        :attr("rowspan", "2")
                        :wikitext("Price")
                    :done()
                totalspanrange = totalspanrange + 1
            elseif yesno(frameargs.price) and yesno(frameargs.price2) then
                tblrow
                    :tag("th")
                        :attr("rowspan", "2")
                        :wikitext("Price<br />Main-hand")
                    :done()
                    :tag("th")
                        :attr("rowspan", "2")
                        :wikitext("Price<br />Off-hand")
                    :done()
                totalspanrange = totalspanrange + 2
            end
 
            -- Get default rowspan for images if they are used
            if isnotempty(frameargs.image) or isnotempty(frameargs.image2) then
                for i,j in ipairs(frameargs) do
                     imageRowsSpan = imageRowsSpan + 1
                end
            end
 
            -- Add image column
            if isnotempty(frameargs.image) then
                tblrow
                    :tag("th")
                        :attr("rowspan", tostring(2 + tonumber(frameargs.rows or imageRowsSpan) + tonumber(frameargs.tot or 0)))
                        :css("width", "125px")
                        :css("text-align", "center")
                        :css("vertical-align", "center")
                        :wikitext("[[File:" .. frameargs.image .. "]]")
                    :done()
            end
 
            -- Add image2 comlumn
            if isnotempty(frameargs.image2) then
                tblrow
                    :tag("th")
                        :attr("rowspan", tostring(2 + tonumber(frameargs.rows or imageRowsSpan) + tonumber(frameargs.tot or 0)))
                        :css("width", "125px")
                        :css("text-align", "center")
                        :css("vertical-align", "center")
                        :wikitext("[[File:" .. frameargs.image2 .. "]]")
                    :done()
            end
 
        -- Make second header row
        tblrow = htmltable:tag("tr")
 
            -- Show/hide weapon stats
            if not yesno(frameargs.noweapon) then
                tblrow
                    :tag("th")
                        :attr("title", "Mainhand attacking style")
                        :wikitext("Style")
                    :done()
                    :tag("th")
                        :attr("title", "Mainhand weapon damage")
                        :wikitext("Dmg")
                    :done()
                    :tag("th")
                        :attr("title", "Mainhand weapon accuracy")
                        :wikitext("Acc")
                    :done()
                    :tag("th")
                        :attr("title", "Offhand attacking style")
                        :wikitext("Style")
                    :done()
                    :tag("th")
                        :attr("title", "Offhand weapon damage")
                        :wikitext("Dmg")
                    :done()
                    :tag("th")
                        :attr("title", "Offhand weapon accuracy")
                        :wikitext("Acc")
                    :done()
            end
 
            -- Ass atribute and style bonuses columns
            tblrow
                :tag("th")
                    :wikitext(skillClickpick._main("Defence"))
                :done()
                :tag("th")
                    :wikitext(skillClickpick._main("Constitution"))
                :done()
                :tag("th")
                    :wikitext(skillClickpick._main("Prayer"))
                :done()
                :tag("th")
                    :wikitext("[[File:Attack-icon.png|20px|link=Melee]]")
                :done()
                :tag("th")
                    :wikitext("[[File:Ranged-icon.png|20px|link=Ranged]]")
                :done()
                :tag("th")
                    :wikitext("[[File:Magic-icon.png|20px|link=Magic]]")
                :done()
            :done()
 
        -- sortable row
        if yesno(frameargs.sortable) then
            htmltable:addClass("sortable")
            tblrow = htmltable:tag("tr")
 
            if yesno(frameargs.noinv) then 
                addSortCell(tblrow, 1, "text")
            else
                tblrow
                    :tag("th")
                        :addClass("unsortable")
                    :done()
                addSortCell(tblrow, 1, "text")
            end
            if string.lower(frameargs.class or frameargs.type or "") == "mixed" then addSortCell(tblrow, 1, "text") end
            if isnotempty(frameargs.skill) then addSortCell(tblrow, 1, "number") end
            if isnotempty(frameargs.skill2) then addSortCell(tblrow, 1, "number") end
            if not yesno(frameargs.noweapon) then addSortCell(tblrow, 6, "number") end
            addSortCell(tblrow, 6, "number")
            if yesno(frameargs.price) then addSortCell(tblrow, 1, "number") end
            if yesno(frameargs.price2) then addSortCell(tblrow, 1, "number") end
        end
    -- Header ends here
 
    -- Table rows are created here
    --[[Parameters used     (variable type)     [note]
            [all paramerers are @optional]
        totals          (yes/no)            [Default is no]
        label           (string)            [Only has an effect if totals is used]
        ge              (string)    
        image           (string)            [Only works if the ge parameter is not used]
        name            (string)            [Only works if the ge parameter is not used]
        type            (string)            [Default is "-"]
        level/skill     (number/string)     [Default is "-"]
        level2/skill2   (number/string)     [Default is "-"]
        mstyle          (string)            [Default is "-"]
        mdmg            (number)            [Default is "-"]
        macc            (number)            [Default is "-"]
        ostyle          (string)            [Default is "-"]
        odmg            (number)            [Default is "-"]            
        oacc            (number)            [Default is "-"]
        armour          (number)            [Default is "0"]
        life            (number)            [Default is "0"]
        prayer          (number)            [Default is "0"]
        strength        (number)            [Default is "-"]
        ranged          (number)            [Default is "-"]
        magic           (number)            [Default is "-"]
        price           (ge/number/string)  [ge only works if the ge parameter is used. ge and number are preferred if the totals prameter is used]
        price2          (ge/number/string)
        priceimage      (string)            [can be used incase the ge parameter is not used but you want the price to add to the totalprice]
        dontaddtototal  (yes/no)            [default is no]
        nocoinstotals   (yes/no)            [default is no]
        ref             (string)
    ]]
    for i,j in ipairs(frameargs) do     -- Iterate in order over all frameargs with a integer key
        -- Parse the framearg j into a table of rowargs, j = {{Equipment bonuses inforow}}
        local argstable = {}
        for argduo in j:gmatch("!(.-)!") do
            local argname = argduo:match("&(.-)&")
            local argvalue = argduo:match( "µ(.-)µ")
            if argvalue == "" then
                argvalue = nil
            end
            argstable[argname] = argvalue
        end
 
        -- Add extra row if the totals + label parameters are used
        if yesno(argstable.totals) and isnotempty(argstable.label) then
            tblrow = htmltable:tag("tr")
                :addClass("attribute-total sortbottom")
                tblcell = tblrow:tag("th")
                    :attr("rowspan", "2")
                    :wikitext("Totals")
                    if not yesno(frameargs.noinv) then
                        tblcell
                            :attr("colspan","2")
                    end
 
            tblrow
                :tag("th")
                    :attr("colspan", totalspanrange)
                    :wikitext(argstable.label)
                :done()
        end
 
        -- Create a new inforow
        tblrow = htmltable:tag("tr")
 
            -- Add special css to the row incase the totals parameter is used
            if yesno(argstable.totals) then
                tblrow
                    :addClass("attribute-total sortbottom")
            end
 
            -- Add the totals text cell
            if yesno(argstable.totals) and not isnotempty(argstable.label) then
                tblcell = tblrow:tag("th")
                    :wikitext("Totals")
                    if not yesno(frameargs.noinv) then
                        tblcell
                            :attr("colspan","2")          
                    end
            end
 
            -- Add the item image and name cells
            if isnotempty(argstable.ge) then
                tblrow
                    :tag("td")
                        :wikitext("[[File:" .. argstable.ge .. ".png]]")
                    :done()
                    :tag("td")
                        :css("text-align", "left")
                        :wikitext("[[" .. argstable.ge .. "]]" .. ((argstable.ref and (" " .. argstable.ref)) or ""))
                    :done()
            elseif isnotempty(argstable.image) then
                tblrow
                    :tag("td")
                        :wikitext("[[File:" .. argstable.image .. "]]")
                    :done()
                if isnotempty(argstable.name) then
                    tblrow
                        :tag("td")
                            :css("text-align", "left")
                            :wikitext(argstable.name .. ((argstable.ref and (" " .. argstable.ref)) or ""))
                        :done()
                end
            elseif isnotempty(argstable.name) then
                tblrow
                    :tag("td")
                        :css("text-align", "left")
                        :wikitext(argstable.name .. ((argstable.ref and (" " .. argstable.ref)) or ""))
                    :done()
            end
 
            -- Add the type cell incase the header class is mixed
            if string.lower(frameargs.class or frameargs.type or "") == "mixed" then
                tblrow
                    :tag("td")
                        :wikitext(rowTypes[string.lower(argstable.type or "")] or argstable.type or "-")
                    :done()
            end
 
            -- Add the skill cell
            if isnotempty(frameargs.skill) then
                tblrow
                    :tag("td")
                        :wikitext(argstable.level or argstable.skill or "-")
                        :attr("data-sort-value", argstable.level or argstable.skill or 0)
                    :done()
            end
 
            -- Add the skill2 cell
            if isnotempty(frameargs.skill2) then
                tblrow
                    :tag("td")
                        :wikitext(argstable.level2 or argstable.skill2 or "-")
                        :attr("data-sort-value", argstable.level2 or argstable.skill2 or 0)
                    :done()
            end
 
            -- Show/hide weapon stats
            if not yesno(frameargs.noweapon) then
                tblrow
                    :tag("td")
                        :addClass("attribute-value")
                        :wikitext(styles[string.lower(argstable.mstyle or "")] or argstable.mstyle or "-")
                    :done()
                    :tag("td")
                        :addClass("attribute-value")
                        :wikitext(argstable.mdmg or "-")
                        :attr("data-sort-value", argstable.mdmg or 0)
                    :done()
                    :tag("td")
                        :addClass("attribute-value")
                        :wikitext(argstable.macc or "-")
                        :attr("data-sort-value", argstable.macc or 0)
                    :done()
                    :tag("td")
                        :wikitext(styles[string.lower(argstable.ostyle or "")] or argstable.ostyle or "-")
                    :done()
                    :tag("td")
                        :wikitext(argstable.odmg or "-")
                        :attr("data-sort-value", argstable.odmg or 0)
                    :done()
                    :tag("td")
                        :wikitext(argstable.oacc or "-")
                        :attr("data-sort-value", argstable.oacc or 0)
                    :done()
            end
 
            -- Add atribute and style bonuses cells
            tblrow
                :tag("td")
                    :addClass("attribute-value")
                    :wikitext(argstable.armour or "0")
                :done()
                :tag("td")
                    :addClass("attribute-value")
                    :wikitext(argstable.life or "0")
                :done()
                :tag("td")
                    :addClass("attribute-value")
                    :wikitext(argstable.prayer or "0")
                :done()
                :tag("td")
                    :wikitext(argstable.strength or "-")
                    :attr("data-sort-value", argstable.strength or 0)
                :done()
                :tag("td")
                    :wikitext(argstable.ranged or "-")
                    :attr("data-sort-value", argstable.ranged or 0)
                :done()
                :tag("td")
                    :wikitext(argstable.magic or "-")
                    :attr("data-sort-value", argstable.magic or 0)
                :done()
 
            -- Add price cell
            if yesno(frameargs.price) then
 
                -- Total price
                if (yesno(argstable.totals) and argstable.price == nil) or string.lower(argstable.price or "") == "total" then
                    if isnotempty(argstable.priceimage) then
                        tblrow
                            :tag("td")
                                :css("text-align", "right")
                                :wikitext((argstable.priceimage and ("[[File:" .. argstable.priceimage .. "]] ")) or "")
                                :tag("span")
                                    :addClass("coins coins-pos")
                                    :wikitext(AddCommas._add(totalPrice))
                                :done()
                            :done()
                    else
                        tblrow
                            :tag("td")
                                :css("text-align", "right")
                                :wikitext(Coins._amount(totalPrice, false))
                            :done()
                    end
 
                -- Empty the cell incase price2 = ge and price is not given
                elseif string.lower(argstable.price2 or "") == "ge" and argstable.price == nil then
                    tblrow
                        :tag("td")
                            :wikitext("-")
                        :done()
 
                -- GE price, this is the default value if no price parameter was given
                elseif string.lower(argstable.price or "") == "ge" or argstable.price == nil then
 
                    -- Check if the item exist on the GE
                    if Exchange._exists(argstable.ge) then
                        local GEprice = Exchange._price(argstable.ge)
                        if not yesno(argstable.dontaddtototal) then
                            totalPrice = totalPrice + GEprice
                        end
                        tblrow
                            :tag("td")
                                :css("text-align", "right")
                                :wikitext(Coins._amount(GEprice, false))
                            :done()
                    else
 
                        -- Empty the cell if the item doesn't exist on the GE and it defaulted to GEprice, else give an error
                        if string.lower(argstable.price or "") == "ge" then
                            tblrow
                                :tag("td")
                                    :tag("span")
                                        :css("color", "red")
                                        :wikitext("Item does not exist on the [[Grand Exchange|")
                                            :tag("span")
                                                :css("color", "darkred")
                                                :wikitext("Grand Exchange")
                                            :done()
                                        :wikitext("]]")
                                    :done()
                                :done()
                        else
                            tblrow
                                :tag("td")
                                    :wikitext("-")
                                :done()
                        end
                    end
 
                -- If the price parameter is just a number
                elseif tonumber(argstable.price) ~= nil then
                    if not yesno(argstable.dontaddtototal) then
                        totalPrice = totalPrice + tonumber(argstable.price)
                    end
                    if argstable.priceimage == nil then
                        tblrow
                            :tag("td")
                                :css("text-align", "right")
                                :wikitext(Coins._amount(tonumber(argstable.price)))
                            :done()
                    else
                        tblrow
                            :tag("td")
                                :css("text-align", "right")
                                :wikitext((argstable.priceimage and ("[[File:" .. argstable.priceimage .. "]] ")) or "")
                                :tag("span")
                                    :addClass("coins coins-pos")
                                    :wikitext(AddCommas._add(tonumber(argstable.price)))
                                :done()
                            :done()
                    end
 
                -- If the price parameter is a non recognized value
                else
                    tblrow
                        :tag("td")
                            :css("text-align", "right")
                            :wikitext(argstable.price)
                        :done()
                end
            end
 
            -- Add price2 cell
            if yesno(frameargs.price2) then
 
                -- Empty the cell incase price = ge and price2 is not given or if the totals parameter is used
                if (yesno(argstable.totals) and argstable.price2 == nil) or (argstable.price2 == nil and string.lower(argstable.price or "") == "ge") then 
                    tblrow
                        :tag("td")
                            :wikitext("-")
                        :done()
 
                -- GE price, this is the default value if no price2 parameter was given
                elseif string.lower(argstable.price2 or "") == "ge" or argstable.price2 == nil then
 
                    -- Check if the item exists on the GE
                    if string.lower(argstable.price2 or "") == "ge" and argstable.price == nil and Exchange._exists(string.lower(argstable.ge or ""))then
                        local GEprice2 = Exchange._price(string.lower(argstable.ge or ""))
                        tblrow
                            :tag("td")
                                :css("text-align", "right")
                                :wikitext(Coins._amount(GEprice2, false))
                            :done()
 
                    -- Check if the off-hand of the item exists on the GE
                    elseif Exchange._exists("Off-hand " .. string.lower(argstable.ge or "")) then
                        local GEprice2 = Exchange._price("Off-hand " .. string.lower(argstable.ge or ""))
                        tblrow
                            :tag("td")
                                :css("text-align", "right")
                                :wikitext(Coins._amount(GEprice2, false))
                            :done()
                    else
 
                        -- Empty the cell if the item doesn't exist on the GE and it defaulted to GEprice, else give an error
                        if string.lower(argstable.price2 or "") == "ge" then
                            tblrow
                                :tag("td")
                                    :tag("span")
                                        :css("color", "red")
                                        :wikitext("Item does not exist on the [[Grand Exchange|")
                                            :tag("span")
                                                :css("color", "darkred")
                                                :wikitext("Grand Exchange")
                                            :done()
                                        :wikitext("]]")
                                    :done()
                                :done()
                        else
                            tblrow
                                :tag("td")
                                    :wikitext("-")
                                :done()
                        end
                    end
 
                -- If the proce2 parameter is a number
                elseif tonumber(argstable.price2) ~= nil then
                    if argstable.priceimage == nil then
                        tblrow
                            :tag("td")
                                :wikitext(Coins._amount(argstable.price2))
                            :done()
                    else
                        tblrow
                            :tag("td")
                                :css("text-align", "right")
                                :wikitext((argstable.priceimage and ("[[File:" .. argstable.priceimage .. "]] ")) or "")
                                :tag("span")
                                    :addClass("coins coins-pos")
                                    :wikitext(AddCommas._add(argstable.price2))
                            :done()
                    end
 
                -- If the price parameter is a non recognized value
                else
                    tblrow
                        :tag("td")
                            :css("text-align", "right")
                            :wikitext(argstable.price2)
                        :done()
                end
            end
        -- Inforow ends here
    end
    -- Table is complete here
 
    return htmltable
end
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.