Fandom

Dark Souls Wiki

Module:DaSIIWeaponBox

4,430pages on
this wiki
Add New Page
Talk0

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.

local insert = table.insert
local concat = table.concat
local format = string.format
 
-- The input width. Every totalWidth values, we have a row.
local totalWidth = 7+6+7+3
 
-- Types that do not need a prefix
local basicTypes = {[""]=true, Standard=true, Dragon=true, Unique=true, Flame=true}
 
-- Represents the input index where the corresponding row can be found.
-- So for example, the Physical resistance value is at rowIndexex["PhyRed"] which is 14
local colIndexes = {
    ["PhyAtkWpn"]=1,
    ["MagAtkWpn"]=2,
    ["FireAtkWpn"]=3,
    ["LtnAtkWpn"]=4,
    ["DarkAtkWpn"]=5,
    ["PsnAtkWpn"]=6,
    ["BldAtkWpn"]=7,
 
    ["Str Bonus"]=8,
    ["Dex Bonus"]=9,
    ["Mag Bonus"]=10,
    ["Fire Bonus"]=11,
    ["Ltn Bonus"]=12,
    ["Dark Bonus"]=13,
 
    ["PhyRed"]=14,
    ["MagRed"]=15,
    ["FireRed"]=16,
    ["LtnRed"]=17,
    ["DarkRed"]=18,
    ["PsnRed"]=19,
    ["BldRed"]=20,
 
    ["PetrifyRed"]=21,
    ["CurseRed"]=22,
    ["Stability"]=23,
}
 
-- The section titles and the rows they own.
local sectionTitles = {
    {
        Name = "Attack Values",
        Values = {
            "PhyAtkWpn",
            "MagAtkWpn",
            "FireAtkWpn",
            "LtnAtkWpn",
            "DarkAtkWpn",
            "PsnAtkWpn",
            "BldAtkWpn",
        }
    },
    {
        Name = "Bonus",
        Values = {
            "Str Bonus",
            "Dex Bonus",
            "Mag Bonus",
            "Fire Bonus",
            "Ltn Bonus",
            "Dark Bonus",
        }
    },
    {
        Name = "Damage Reduction",
        Values = {
            "PhyRed",
            "MagRed",
            "FireRed",
            "LtnRed",
            "DarkRed",
            "PsnRed",
            "BldRed",
        }
    },
    {
        Name = "Others",
        Values = {
            "PetrifyRed.png",
            "CurseRed.png",
            "Stability",
        }
    },
}
 
 
local args
 
local function getArgs(inArgs)
    args = inArgs
 
    -- Trim everyone
    for i, v in pairs(args) do
        args[i] = v:gsub("^%s*(.-)%s*$", "%1")
    end
 
    -- Defaults for easier testing
    if not args.Name then
        args.Name = ""
    end
    if not args.Type then
        args.Type = ""
    end
    if not args.Upgrade then
        args.Upgrade = ""
    end
    if not args.Cost then
        args.Cost = ""
    end
    if not args.ForceFeed then
        args.ForceFeed = ""
    end
end
 
local function splitString(str)
    local ret = {}
    for id in str:gmatch('([^,]+)') do
        id = id:gsub("^%s*(.-)%s*$", "%1")
        insert(ret, id)
    end
    return ret
end
 
local p = {}
 
local infusions = {
    Magic = true
}
 
local variationsMap = {
    Magic = true,
    Enchanted = true,
    Fire = true,
    Lightning = true,
    Dark = true,
    Bleed = true,
    Poison = true,
    Raw = true,
    Mundane = true,
}
 
function p.generateFirstRow(text, colsToDisplay)
    insert(text, format([=[    <tr style="border:1px solid black;">]=]))
 
    local variation = args.Type
    if args.Type == "Standard" or args.Type == "Unique" then
        variation = format("[[%s (Dark Souls II Upgrade Path)|%s]]", args.Type, args.Type)
    elseif args.Type == "Flame" or args.Type == "Dragon" then
        variation = format("[[%s (Dark Souls II Upgrade Path)|%s]]", "Standard", "Standard")
    elseif variationsMap[args.Type] then
        variation = format("[[File:Upgrade II %s.png|link=Infusion#{{{Type|}}}]] [[Infusion#%s|%s]]", args.Type, args.Type, args.Type)
    end
 
    insert(text, format([=[        <th rowspan="2" style="background-color:#151515; border:1px solid black; width:100%%";>%s Variation</th>]=], variation))
 
    for i, sectionTitle in ipairs(sectionTitles) do
        local colCount = 0
        for j, col in ipairs(sectionTitle.Values) do
            if colsToDisplay[col] then
                colCount = colCount + 1
            end
        end
        if colCount ~= 0 then
            insert(text, format([=[        <th colspan="%s" style="background-color:#151515; border:1px solid black;">%s</th>]=], colCount, sectionTitle.Name))
        end
    end
    insert(text, format([=[    </tr>]=]))
 
    insert(text, format([=[    <tr>]=]))
    for i, col in ipairs(colsToDisplay) do
        insert(text, format([=[        <th style="border:1px solid black;">[[File:Icon DaSII %s.png]]</th>]=], col))
    end
    insert(text, format([=[    </tr>]=]))
end
 
local materialMap = {
    Dragon = "[[Petrified Dragon Bone]]",
    Unique = "[[Twinkling Titanite (Dark Souls II)|Twinkling Titanite]]",
    Flame = "[[Fire Seed]]",
}
local titaniteShard = "[[Titanite Shard (Dark Souls II)|Titanite Shard]]"
local titaniteLargeShard = "[[Large Titanite Shard (Dark Souls II)|L. Titanite Shard]]"
local titaniteChunk = "[[Titanite Chunk (Dark Souls II)|Titanite Chunk]]"
local titaniteSlab = "[[Titanite Slab (Dark Souls II)|Titanite Slab]]"
local standardMaterialMap = {
    titaniteShard,
    titaniteShard,
    titaniteShard,
    titaniteLargeShard,
    titaniteLargeShard,
    titaniteLargeShard,
    titaniteChunk,
    titaniteChunk,
    titaniteChunk,
    titaniteSlab,
}
local amountMap = {
    Standard = {1, 2, 3, 1, 2, 3, 1, 2, 3, 1},
    Dragon = {1, 2, 3, 4, 5},
    Unique = {1, 2, 3, 4, 5},
    Flame = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
}
 
 
function p.generateFirstCell(text, grade, costs)
    local content = {}
 
    local titleStrings = {}
    if not basicTypes[args.Type] then
        insert(titleStrings, args.Type)
    end
    insert(titleStrings, args.Name)
    if grade ~= 0 then
        insert(titleStrings, format("+%s", grade))
    end
    if (#titleStrings ~= 0) then
        insert(content, concat(titleStrings, " "))
    end
 
    local finePrint = {}
    local material = args.Upgrade == "Standard" and standardMaterialMap[grade] or (grade ~= 0 and materialMap[args.Upgrade])
    if material then
        insert(finePrint, material)
    end
    local amount = amountMap[args.Upgrade] and amountMap[args.Upgrade][grade]
    if amount then
        insert(finePrint, format("&times;%s", amount))
    end
    if costs[grade] and costs[grade] ~= "" then
        if #finePrint ~= 0 then
            insert(finePrint, "&amp;")
        end
        insert(finePrint, costs[grade])
        insert(finePrint, "souls")
    end
    if (#finePrint ~= 0) then
        insert(
            content,
            format(
                [=[<span style="white-space:nowrap; font-size:x-small;">(%s)</span>]=],
                concat(finePrint, " ")))
    end
 
    local sep = args.ForceFeed == "" and " " or "<br />"
    local style = args.ForceFeed == "" and "" or "height:42px;"
 
    insert(
        text,
        format(
            [=[        <td style="text-align:left; padding: 0 0.2em 0 0.5em; border:1px solid black;%s">%s</td>]=],
            style,
            concat(content, sep)))
end
 
function p.generateCell(text, string)
    if (not string or string == "") then
        string = "???" -- TODO: Invoke "Missing"
    elseif (string == "-") then
        string = "&ndash;"
    end
    insert(text, format([=[        <td style="border:1px solid black;">%s</td>]=], string))
end
 
function p.generateRow(text, colsToDisplay, grade, costs, rowValues)
    insert(text, format([=[    <tr>]=]))
    p.generateFirstCell(text, grade, costs)
    for i, col in ipairs(colsToDisplay) do
        p.generateCell(text, rowValues[colIndexes[col]])
    end
    insert(text, format([=[    </tr>]=]))
end
 
-- This is where the magic happens. Simply add/remove columns to show/hide here.
function p.populateColsToDisplay()
 
    local function doInsert(tab, value)
        insert(tab, value)
        tab[value] = true
    end
 
    local ret = {}
 
    -- attacks
    doInsert(ret, "PhyAtkWpn")
    doInsert(ret, "MagAtkWpn")
    doInsert(ret, "FireAtkWpn")
    doInsert(ret, "LtnAtkWpn")
    doInsert(ret, "DarkAtkWpn")
    doInsert(ret, "PsnAtkWpn")
    doInsert(ret, "BldAtkWpn")
 
    -- bonuses
    doInsert(ret, "Str Bonus")
    doInsert(ret, "Dex Bonus")
    doInsert(ret, "Mag Bonus")
    doInsert(ret, "Fire Bonus")
    doInsert(ret, "Ltn Bonus")
    doInsert(ret, "Dark Bonus")
 
    -- resistances
    doInsert(ret, "PhyRed")
    doInsert(ret, "MagRed")
    doInsert(ret, "FireRed")
    doInsert(ret, "LtnRed")
    doInsert(ret, "DarkRed")
    doInsert(ret, "PsnRed")
    doInsert(ret, "BldRed")
 
    -- others, not shown by default.
    -- insert(ret, "PetrifyRed")
    -- insert(ret, "CurseRed")
    -- insert(ret, "Stability")
    return ret
end
 
function p.main(frame)
    getArgs(frame.args)
 
    local text = {}
 
    local colsToDisplay = p.populateColsToDisplay()
    local costs = splitString(args.Cost)
 
    insert(text, format([=[<table cellspacing="1" cellpadding="2" style="width:100%%; text-align:center; border-collapse: collapse; box-shadow:0 0 5px 3px black; margin:1em 1em 1em 0;">]=]))
 
    p.generateFirstRow(text, colsToDisplay)
 
    local row = -1
    while true do
        row = row + 1
 
        local firstIndex = row * totalWidth
 
        local hasNonEmpty = false
        local hasNull = false
 
        for i = firstIndex+1, firstIndex+totalWidth do
            local arg = args[i]
            if not arg then
                hasNull = true
            elseif arg and arg ~= "" then
                hasNonEmpty = true
                break
            end
        end
 
        if hasNonEmpty == true then
            local rowData = {}
            for i = 1, totalWidth do
                rowData[i] = args[firstIndex + i] or ""
            end
            p.generateRow(text, colsToDisplay, row, costs, rowData)
        end
 
        if hasNull == true then
            break
        end
    end
 
    insert(text, format([=[</table>]=]))
 
    return concat(text, "\n")
end
 
return p

Also on Fandom

Random Wiki