Module:Equipment bonuses infotable

local p = {} local yesno = require("Module:Yesno") local weaknessClickpick = require("Module:Weakness clickpic") local Exchange = require("Module:Exchange") local Coins = require("Module:Coins") local AddCommas = require("Module:Addcommas") local skillClickpick = require("Module:Skill clickpic")

-- Accepted rowTypes local rowTypes = { melee = weaknessClickpick._main({"melee"}, false), ranged = weaknessClickpick._main({"ranged"}, false), magic = weaknessClickpick._main({"magic"}, false), all = weaknessClickpick._main({"none"}, false), none = "-" } -- Accepted headerTypes local headerTypes = { melee = " Item", ranged = " Item", magic = " Item", all = " Item", hybrid = "Hybrid Item ", mixed = "Item", none = "Item" }

-- Accepted styles local styles = { stab = "Stab", crush = "Crush", slash = "Slash", arrow = "Arrow", bolt = "Bolt", thrown = "Thrown", spell = "Spell- casting", spells = "Spell- casting", ['spell-casting'] = "Spell- casting", none = "None" } function p.main(frame) local frameargs = frame:getParent.args 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 -- Create the tabel header --Parameters used (variable type)    [note]        class / type    (string)            [@mandatory]        noinv           (yes/no)            [@optional, default is no]        skill           (string)            [@optional]        skill2          (string)            [@optional]        noweapon        (yes/no)            [@optional, default is no]        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]        image2          (string)            [@optional]        rows            (number)            [@optional, only effects image and image2]        tot             (number)            [@optional, only effects image and image2] htmltable :attr("class", "wikitable infotableBonuses") :css("text-align", "center") tblrow = htmltable:tag("tr") tblcell = tblrow:tag("th") if yesno(frameargs.noinv) then tblcell :attr("rowspan", "2") :attr("colspan", "1") :wikitext(headerTypes[string.lower(frameargs.class or frameargs.type or "")] or ("''Type Unknown [" .. tostring(mw.uri.fullUrl( mw.title.getCurrentTitle.prefixedText, "action=edit")) .. " edit] '' ")) else tblcell :attr("rowspan", "2") :attr("colspan", "2") :wikitext(headerTypes[string.lower(frameargs.class or frameargs.type or "")] or ("''Type Unknown [" .. tostring(mw.uri.fullUrl( mw.title.getCurrentTitle.prefixedText, "action=edit")) .. " edit] '' ")) end if string.lower(frameargs.class or frameargs.type or "") == "mixed" then tblrow :tag("th") :attr("rowspan", "2") :wikitext("Type") :done totalspanrange = totalspanrange + 1 end if isnotempty(frameargs.skill) then tblrow :tag("th") :attr("rowspan", "2") :wikitext(skillClickpick._main(frameargs.skill or "")) :tag("br") :done :tag("span") :css("font-size", "90%") :wikitext("Level") :done :done totalspanrange = totalspanrange + 1 end if isnotempty(frameargs.skill2) then tblrow :tag("th") :attr("rowspan", "2") :wikitext(skillClickpick._main(frameargs.skill2 or "")) :tag("br") :done :tag("span") :css("font-size", "90%") :wikitext("Level") :done :done totalspanrange = totalspanrange + 1 end 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 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 tblrow :tag("th") :attr("colspan", "3") :wikitext("Style bonus") :done 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 Main-hand") :done :tag("th") :attr("rowspan", "2") :wikitext("Price Off-hand") :done totalspanrange = totalspanrange + 2 end if isnotempty(frameargs.image) then tblrow :tag("th") :attr("rowspan", tostring(2 + tonumber(frameargs.rows or 0) + tonumber(frameargs.tot or 0))) :css("width", "125px") :css("text-align", "center") :css("vertical-align", "center") :wikitext("") :done end if isnotempty(frameargs.image2) then tblrow :tag("th") :attr("rowspan", tostring(2 + tonumber(frameargs.rows or 0) + tonumber(frameargs.tot or 0))) :css("width", "125px") :css("text-align", "center") :css("vertical-align", "center") :wikitext("") :done end tblrow = htmltable:tag("tr") 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 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("") :done :tag("th") :wikitext("") :done :tag("th") :wikitext("") :done :done -- 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]    ]] for i,j in ipairs(frameargs) do       local argstable = {}    -- Parse the framearg into a table of args for argduo in j:gmatch("!(.-)!") do           local argname = argduo:match("&(.-)&") local argvalue = argduo:match( "<(.-)>") if argvalue == "" then argvalue = nil end argstable[argname] = argvalue end if (yesno(argstable.totals) or yesno(argstable.nocoinstotals)) and isnotempty(argstable.label) then tblrow = htmltable:tag("tr") :attr("class", "attribute-total") tblcell = tblrow:tag("th") if yesno(frameargs.noinv) then tblcell :attr("rowspan", "2") :attr("colspan","1") :wikitext("Totals") else tblcell :attr("rowspan", "2") :attr("colspan","2") :wikitext("Totals") end tblrow :tag("th") :attr("colspan", totalspanrange) :wikitext(argstable.label) :done end tblrow = htmltable:tag("tr") if (yesno(argstable.totals) or yesno(argstable.nocoinstotals)) then tblrow :attr("class", "attribute-total") end if (yesno(argstable.totals) or yesno(argstable.nocoinstotals)) and not isnotempty(argstable.label) then tblcell = tblrow:tag("th") if yesno(frameargs.noinv) then tblcell :attr("colspan","1") :wikitext("Totals") else tblcell :attr("colspan","2") :wikitext("Totals") end end if isnotempty(argstable.ge) then tblrow :tag("td") :wikitext("") :done :tag("td") :css("text-align", "left") :wikitext("" .. argstable.ge .. "") :done elseif isnotempty(argstable.image) then tblrow :tag("td") :wikitext(argstable.image) :done if isnotempty(argstable.name) then tblrow :tag("td") :css("text-align", "left") :wikitext(argstable.name) :done end elseif isnotempty(argstable.name) then tblrow :tag("td") :css("text-align", "left") :wikitext(argstable.name) :done end 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 if isnotempty(frameargs.skill) then tblrow :tag("td") :wikitext(argstable.level or argstable.skill or "-") :done end if isnotempty(frameargs.skill2) then tblrow :tag("td") :wikitext(argstable.level2 or argstable.skill2 or "-") :done end if not yesno(frameargs.noweapon) then tblrow :tag("td") :attr("class", "attribute-value") :wikitext(styles[string.lower(argstable.mstyle or "")] or argstable.mstyle or "-") :done :tag("td") :attr("class", "attribute-value") :wikitext(argstable.mdmg or "-") :done :tag("td") :attr("class", "attribute-value") :wikitext(argstable.macc or "-") :done :tag("td") :wikitext(styles[string.lower(argstable.ostyle or "")] or argstable.ostyle or "-") :done :tag("td") :wikitext(argstable.odmg or "-") :done :tag("td") :wikitext(argstable.oacc or "-") :done end tblrow :tag("td") :attr("class", "attribute-value") :wikitext(argstable.armour or "0") :done :tag("td") :attr("class", "attribute-value") :wikitext(argstable.life or "0") :done :tag("td") :attr("class", "attribute-value") :wikitext(argstable.prayer or "0") :done :tag("td") :wikitext(argstable.strength or "-") :done :tag("td") :wikitext(argstable.ranged or "-") :done :tag("td") :wikitext(argstable.magic or "-") :done if yesno(frameargs.price) then if ((yesno(argstable.totals) or yesno(argstable.nocoinstotals)) and argstable.price == nil) or string.lower(argstable.price or "") == "total" then if yesno(argstable.nocoinstotals) then tblrow :tag("td") :css("text-align", "right") :wikitext((argstable.priceimage or "") .. AddCommas._add(totalPrice)) :done else tblrow :tag("td") :css("text-align", "right") :wikitext(Coins._amount(totalPrice, false)) :done end elseif string.lower(argstable.price or "") == "ge" or argstable.price == nil then 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 if string.lower(argstable.price or "") == "ge" then tblrow :tag("td") :tag("span") :css("color", "red") :wikitext("Item does not exist on the ")                                           :tag("span")                                                :css("color", "darkred")                                                :wikitext("Grand Exchange")                                            :done                                        :wikitext("") :done :done else tblrow :tag("td") :wikitext("-") :done end end elseif tonumber(argstable.price) ~= nil then if not yesno(argstable.dontaddtototal) then totalPrice = totalPrice + tonumber(argstable.price) end tblrow :tag("td") :css("text-align", "right") :wikitext((argstable.priceimage or "") .. AddCommas._add(argstable.price)) :done else tblrow :tag("td") :css("text-align", "right") :wikitext(argstable.price) :done end end if yesno(frameargs.price2) then if string.lower(argstable.price2 or "") == "ge" or argstable.price2 == nil then if 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 if string.lower(argstable.price2 or "") == "ge" then tblrow :tag("td") :tag("span") :css("color", "red") :wikitext("Item does not exist on the ")                                           :tag("span")                                                :css("color", "darkred")                                                :wikitext("Grand Exchange")                                            :done                                        :wikitext("") :done :done else tblrow :tag("td") :wikitext("-") :done end end elseif tonumber(argstable.price) ~= nil then tblrow :tag("td") :css("text-align", "right") :wikitext((argstable.priceimage or "") .. AddCommas._add(argstable.price2)) :done else tblrow :tag("td") :css("text-align", "right") :wikitext(argstable.price2) :done end end end -- Table is complete here return htmltable end

function isnotempty(s) return not (s == nil or s == "") end

return p