Difference between revisions of "Module:Augmenting Uses"
Jump to navigation
Jump to search
(Added Dust and Scrap column) |
(Fix typo in augmentation bonuses table; Add links for Bait Power, Bonus Rarity, Reel Power in augmentation bonuses table) |
||
(15 intermediate revisions by 2 users not shown) | |||
Line 7: | Line 7: | ||
local scrappingBaseXp = 20 | local scrappingBaseXp = 20 | ||
local scrappingXpPower = 2 | local scrappingXpPower = 2 | ||
+ | local blocking = {} | ||
local augmentationBonusNames ={ | local augmentationBonusNames ={ | ||
− | [" | + | ["armorBonus.agility"] = "[[Combat#Defensive Stats|Agility]]", |
− | [" | + | ["armorBonus.protection"] = "[[Combat#Defensive Stats|Protection]]", |
+ | ["armorBonus.resistance"] = "[[Combat#Defensive Stats|Resistance]]", | ||
+ | ["armorBonus.stamina"] = "[[Combat#Defensive Stats|Stamina]]", | ||
+ | ["offensiveAccuracyAffinityRating.Blunt"] = "[[Combat#Offensive Stats|Blunt Accuracy]]", | ||
+ | ["offensiveAccuracyAffinityRating.Chaos"] = "[[Combat#Offensive Stats|Chaos Accuracy]]", | ||
+ | ["offensiveAccuracyAffinityRating.Fire"] = "[[Combat#Offensive Stats|Fire Accuracy]]", | ||
["offensiveAccuracyAffinityRating.Ice"] = "[[Combat#Offensive Stats|Ice Accuracy]]", | ["offensiveAccuracyAffinityRating.Ice"] = "[[Combat#Offensive Stats|Ice Accuracy]]", | ||
− | |||
− | |||
["offensiveAccuracyAffinityRating.Lightning"] = "[[Combat#Offensive Stats|Lightning Accuracy]]", | ["offensiveAccuracyAffinityRating.Lightning"] = "[[Combat#Offensive Stats|Lightning Accuracy]]", | ||
["offensiveAccuracyAffinityRating.Magic"] = "[[Combat#Offensive Stats|Magic Accuracy]]", | ["offensiveAccuracyAffinityRating.Magic"] = "[[Combat#Offensive Stats|Magic Accuracy]]", | ||
+ | ["offensiveAccuracyAffinityRating.Melee"] = "[[Combat#Offensive Stats|Melee Accuracy]]", | ||
+ | ["offensiveAccuracyAffinityRating.Nature"] = "[[Combat#Offensive Stats|Nature Accuracy]]", | ||
+ | ["offensiveAccuracyAffinityRating.Piercing"] = "[[Combat|Piercing]]", | ||
+ | ["offensiveAccuracyAffinityRating.Poison"] = "[[Combat|Poison]]", | ||
+ | ["offensiveAccuracyAffinityRating.Range"] = "[[Combat#Offensive Stats|Range Accuracy]]", | ||
+ | ["offensiveAccuracyAffinityRating.Slashing"] = "[[Combat|Slashing]]", | ||
+ | ["offensiveCritical.chance"] = "[[Combat#Offensive Stats|Crit Chance]]", | ||
+ | ["offensiveCritical.damageMultiplier"] = "[[Combat#Offensive Stats|Crit Mult]]", | ||
+ | ["toolBoost.cooking"] = "[[Cooking]]", | ||
+ | ["toolBoost.enchanting"] = "[[Enchanting]]", | ||
["toolBoost.farming"] = "[[Farming]]", | ["toolBoost.farming"] = "[[Farming]]", | ||
+ | ["toolBoost.fishing"] = "[[Fishing]]", | ||
+ | ["toolBoost.fishingBaitPower"] = "[[Fishing|Bait Power]]", | ||
+ | ["toolBoost.fishingRarityPower"] = "[[Fishing|Bonus Rarity]]", | ||
+ | ["toolBoost.fishingReelPower"] = "[[Fishing|Reel Power]]", | ||
+ | ["toolBoost.foraging"] = "[[Foraging]]", | ||
+ | ["toolBoost.mining"] = "[[Mining]]", | ||
+ | ["toolBoost.runecrafting"] = "[[Runecrafting]]", | ||
["toolBoost.smithing"] = "[[Smithing]]", | ["toolBoost.smithing"] = "[[Smithing]]", | ||
− | [" | + | ["weaponBonus.dexterity"] = "[[Combat#Offensive Stats|Dexterity]]", |
− | + | ["weaponBonus.intellect"] = "[[Combat#Offensive Stats|Intellect]]", | |
− | |||
− | [" | ||
− | |||
− | |||
− | |||
− | |||
["weaponBonus.strength"] = "[[Combat#Offensive Stats|Strength]]", | ["weaponBonus.strength"] = "[[Combat#Offensive Stats|Strength]]", | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
} | } | ||
Line 127: | Line 131: | ||
end | end | ||
end | end | ||
− | ---gets the augments that have the itemId in | + | ---gets the augments that have the itemId in their augmenting cost and returns an array of them |
---@param itemId number | ---@param itemId number | ||
---@return table | ---@return table | ||
Line 133: | Line 137: | ||
local matchedAugs = {} | local matchedAugs = {} | ||
for id, data in pairs(craftingAugmentingData) do | for id, data in pairs(craftingAugmentingData) do | ||
− | if data.scrapping then | + | -- An item can have an augmenting cost. If it also has a scrapping |
− | for costId, _ in pairsByKeys(data | + | -- cost, it takes precedence over the augmenting cost |
+ | local action | ||
+ | if data.augmenting then action = 'augmenting' end | ||
+ | if data.scrapping then action = 'scrapping' end | ||
+ | if action then | ||
+ | for costId, _ in pairsByKeys(data[action]) do | ||
if tonumber(costId) == itemId then | if tonumber(costId) == itemId then | ||
− | matchedAugs[id] = data. | + | matchedAugs[id] = data[action] |
+ | if itemsData[id].blockAugmenting == true then blocking.augmenting = true end | ||
+ | if itemsData[id].blockResearching == true then blocking.researching = true end | ||
end | end | ||
end | end | ||
Line 147: | Line 158: | ||
---@return string | ---@return string | ||
local function decideCollapseState(collapse) | local function decideCollapseState(collapse) | ||
− | if collapse == " | + | if collapse == "collapsible" then |
collapse = " mw-made-collapsible mw-collapsible" | collapse = " mw-made-collapsible mw-collapsible" | ||
elseif collapse == "collapsed" then | elseif collapse == "collapsed" then | ||
Line 158: | Line 169: | ||
local function getItemDust(tier) | local function getItemDust(tier) | ||
+ | tier = math.floor(tier) | ||
if tier <= 2 then | if tier <= 2 then | ||
return "Basic Runic Dust" | return "Basic Runic Dust" | ||
Line 168: | Line 180: | ||
elseif tier > 5 then | elseif tier > 5 then | ||
return "Mythical Runic Dust" | return "Mythical Runic Dust" | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
end | end | ||
Line 187: | Line 185: | ||
local function createImgCell(item) | local function createImgCell(item) | ||
local imgCell = mw.html.create('td') | local imgCell = mw.html.create('td') | ||
+ | :css('text-align', 'center') | ||
:wikitext(img._img({item.name, '50'})) | :wikitext(img._img({item.name, '50'})) | ||
:done() | :done() | ||
Line 193: | Line 192: | ||
local function createNameCell(item) | local function createNameCell(item) | ||
+ | local blockAction = '' | ||
+ | if item.blockAugmenting then blockAction = ' <sup>(A)</sup>' end | ||
+ | if item.blockResearching then blockAction = ' <sup>(R)</sup>' end | ||
local nameCell = mw.html.create('td') | local nameCell = mw.html.create('td') | ||
− | :wikitext("[[" .. item.name .. "]]") | + | :wikitext("[[" .. item.name .. "]]" .. blockAction) |
:done() | :done() | ||
return nameCell | return nameCell | ||
Line 210: | Line 212: | ||
local augBonusCell = mw.html.create('td') | local augBonusCell = mw.html.create('td') | ||
local augBonusS = "" | local augBonusS = "" | ||
− | if item.equipmentStats.augmentationBonus then | + | local css = {} |
+ | if item.equipmentStats and item.equipmentStats.augmentationBonus then | ||
local augBonusC = tablelength(item.equipmentStats.augmentationBonus) | local augBonusC = tablelength(item.equipmentStats.augmentationBonus) | ||
for _, augBonus in ipairs(item.equipmentStats.augmentationBonus) do | for _, augBonus in ipairs(item.equipmentStats.augmentationBonus) do | ||
Line 219: | Line 222: | ||
end | end | ||
end | end | ||
− | + | else | |
augBonusS = "-" | augBonusS = "-" | ||
+ | css['text-align'] = 'center' | ||
end | end | ||
augBonusCell | augBonusCell | ||
− | :css( | + | :css(css) |
:wikitext(augBonusS) | :wikitext(augBonusS) | ||
:done() | :done() | ||
Line 262: | Line 266: | ||
local function createDustCell(item) | local function createDustCell(item) | ||
local itemTier = getItemTier(item) | local itemTier = getItemTier(item) | ||
+ | local css = {} | ||
+ | local cellContent | ||
+ | if item.blockResearching then | ||
+ | css['text-align'] = 'center' | ||
+ | cellContent = '-' | ||
+ | else | ||
+ | cellContent = img._img({getItemDust(itemTier), '25', word = 1}) | ||
+ | end | ||
local dustCell = mw.html.create('td') | local dustCell = mw.html.create('td') | ||
− | :wikitext( | + | :css(css) |
+ | :wikitext(cellContent) | ||
:done() | :done() | ||
return dustCell | return dustCell | ||
Line 269: | Line 282: | ||
local function createScrapCell(item) | local function createScrapCell(item) | ||
+ | local rarity = item.rarity or 'Common' | ||
+ | local cellContent | ||
+ | local css = {} | ||
+ | if item.blockResearching then | ||
+ | cellContent = '-' | ||
+ | css['text-align'] = 'center' | ||
+ | else | ||
+ | cellContent = img._img({rarity .. " Gear Scraps", '25', word = 1}) | ||
+ | end | ||
local scrapCell = mw.html.create('td') | local scrapCell = mw.html.create('td') | ||
− | :wikitext( | + | :css(css) |
+ | :wikitext(cellContent) | ||
:done() | :done() | ||
return scrapCell | return scrapCell | ||
Line 277: | Line 300: | ||
local function genTable(name, collapse) | local function genTable(name, collapse) | ||
local item = getItem(findId._findId({name, "item"})) | local item = getItem(findId._findId({name, "item"})) | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
local matchedAugs = getMatchedAugs(item.id) | local matchedAugs = getMatchedAugs(item.id) | ||
local t = mw.html.create("table") | local t = mw.html.create("table") | ||
− | :addClass("wikitable sortable jquery-tablesorter" .. | + | :addClass("wikitable sortable jquery-tablesorter" .. collapse) |
:tag('tr') | :tag('tr') | ||
:tag('th') | :tag('th') | ||
Line 320: | Line 337: | ||
end | end | ||
return t | return t | ||
+ | end | ||
+ | |||
+ | local function createNotification() | ||
+ | local notification = '' | ||
+ | if blocking.augmenting then | ||
+ | notification = notification .. 'A: This item cannot be augmented.' | ||
+ | end | ||
+ | if blocking.researching then | ||
+ | if notification ~= '' then notification = notification .. '<br />' end | ||
+ | notification = notification .. 'R: This item cannot be researched.' | ||
+ | end | ||
+ | return notification | ||
end | end | ||
Line 330: | Line 359: | ||
if tablelength(_args) == 0 then | if tablelength(_args) == 0 then | ||
name = pageName | name = pageName | ||
+ | elseif _args["collapse"] and not _args[1] then | ||
+ | name = pageName | ||
+ | elseif _args["collapse"] and _args[1] then | ||
+ | name = _args[1] | ||
else | else | ||
name = _args[1] | name = _args[1] | ||
end | end | ||
− | local t = genTable(name, decideCollapseState(_args["collapse"])) | + | |
+ | local t = mw.html.create(nil) | ||
+ | :node(genTable(name, decideCollapseState(_args["collapse"]))) | ||
+ | if blocking.augmenting or blocking.researching then | ||
+ | t:tag('p') | ||
+ | :wikitext(createNotification()) | ||
+ | end | ||
return t | return t | ||
end | end | ||
return p | return p |
Latest revision as of 05:46, 18 April 2025
local p = {} local findId = require("Module:FindId") local img = require("Module:Img") local craftingAugmentingData = mw.loadData("Module:CraftingAugmenting/data") local itemsData = mw.loadData("Module:Items/data") local pageName = mw.title.getCurrentTitle().fullText local scrappingBaseXp = 20 local scrappingXpPower = 2 local blocking = {} local augmentationBonusNames ={ ["armorBonus.agility"] = "[[Combat#Defensive Stats|Agility]]", ["armorBonus.protection"] = "[[Combat#Defensive Stats|Protection]]", ["armorBonus.resistance"] = "[[Combat#Defensive Stats|Resistance]]", ["armorBonus.stamina"] = "[[Combat#Defensive Stats|Stamina]]", ["offensiveAccuracyAffinityRating.Blunt"] = "[[Combat#Offensive Stats|Blunt Accuracy]]", ["offensiveAccuracyAffinityRating.Chaos"] = "[[Combat#Offensive Stats|Chaos Accuracy]]", ["offensiveAccuracyAffinityRating.Fire"] = "[[Combat#Offensive Stats|Fire Accuracy]]", ["offensiveAccuracyAffinityRating.Ice"] = "[[Combat#Offensive Stats|Ice Accuracy]]", ["offensiveAccuracyAffinityRating.Lightning"] = "[[Combat#Offensive Stats|Lightning Accuracy]]", ["offensiveAccuracyAffinityRating.Magic"] = "[[Combat#Offensive Stats|Magic Accuracy]]", ["offensiveAccuracyAffinityRating.Melee"] = "[[Combat#Offensive Stats|Melee Accuracy]]", ["offensiveAccuracyAffinityRating.Nature"] = "[[Combat#Offensive Stats|Nature Accuracy]]", ["offensiveAccuracyAffinityRating.Piercing"] = "[[Combat|Piercing]]", ["offensiveAccuracyAffinityRating.Poison"] = "[[Combat|Poison]]", ["offensiveAccuracyAffinityRating.Range"] = "[[Combat#Offensive Stats|Range Accuracy]]", ["offensiveAccuracyAffinityRating.Slashing"] = "[[Combat|Slashing]]", ["offensiveCritical.chance"] = "[[Combat#Offensive Stats|Crit Chance]]", ["offensiveCritical.damageMultiplier"] = "[[Combat#Offensive Stats|Crit Mult]]", ["toolBoost.cooking"] = "[[Cooking]]", ["toolBoost.enchanting"] = "[[Enchanting]]", ["toolBoost.farming"] = "[[Farming]]", ["toolBoost.fishing"] = "[[Fishing]]", ["toolBoost.fishingBaitPower"] = "[[Fishing|Bait Power]]", ["toolBoost.fishingRarityPower"] = "[[Fishing|Bonus Rarity]]", ["toolBoost.fishingReelPower"] = "[[Fishing|Reel Power]]", ["toolBoost.foraging"] = "[[Foraging]]", ["toolBoost.mining"] = "[[Mining]]", ["toolBoost.runecrafting"] = "[[Runecrafting]]", ["toolBoost.smithing"] = "[[Smithing]]", ["weaponBonus.dexterity"] = "[[Combat#Offensive Stats|Dexterity]]", ["weaponBonus.intellect"] = "[[Combat#Offensive Stats|Intellect]]", ["weaponBonus.strength"] = "[[Combat#Offensive Stats|Strength]]", } local tierToDust = { [1] = "basic", [2] = "basic", [3] = "unusual", [4] = "singular", [5] = "prime", [6] = "mythical", [7] = "mythical", [7.5] = "mythical" } local function pairsByKeys(t, f) local a = {} local orgi_key_type local orgi_key_numbered for n in pairs(t) do if tonumber(n) == nil then table.insert(a, n) orgi_key_type = "word" elseif type(n) == "number" then table.insert(a, n) orgi_key_type = "int" elseif type(n) == "string" and type(tonumber(n) == "number") then orgi_key_type = "number" table.insert(a, tonumber(n)) end end table.sort(a, f) local key local value local i = 0 -- iterator variable local iter = function() -- iterator function i = i + 1 if a[i] == nil then return nil elseif orgi_key_type == "word" or orgi_key_type == "int" then key = a[i] value = t[a[i]] elseif orgi_key_type == "number" then key = tostring(a[i]) value = t[tostring(a[i])] end return key, value end return iter end local function tablelength(T) local count = 0 for _ in pairs(T) do count = count + 1 end return count end local function getItemTier(itemData) local highestRequiredLevel if itemData.requiredLevel then -- Highest level of the required skills highestRequiredLevel = 0 for _, level in pairs(itemData.requiredLevel) do if level > highestRequiredLevel then highestRequiredLevel = level end end highestRequiredLevel = tonumber(string.format("%.1f", highestRequiredLevel / 10)) end local itemTier = itemData.overrideItemTier or highestRequiredLevel or itemData.enchantmentTier or 1 return itemTier end local function getScrapExperience(itemData) local item_tier = getItemTier(itemData) local xp = scrappingBaseXp * (item_tier ^ scrappingXpPower) return math.floor(xp) end ---fetches an item object ---@param itemId integer|string or string ---@return table|string local function getItem(itemId) local item = itemsData[tostring(itemId)] if item then return item else return "Module:Items/data out of date" end end ---gets the augments that have the itemId in their augmenting cost and returns an array of them ---@param itemId number ---@return table local function getMatchedAugs(itemId) local matchedAugs = {} for id, data in pairs(craftingAugmentingData) do -- An item can have an augmenting cost. If it also has a scrapping -- cost, it takes precedence over the augmenting cost local action if data.augmenting then action = 'augmenting' end if data.scrapping then action = 'scrapping' end if action then for costId, _ in pairsByKeys(data[action]) do if tonumber(costId) == itemId then matchedAugs[id] = data[action] if itemsData[id].blockAugmenting == true then blocking.augmenting = true end if itemsData[id].blockResearching == true then blocking.researching = true end end end end end return matchedAugs end ---decides the collase state based on the given string ---@param collapse string ---@return string local function decideCollapseState(collapse) if collapse == "collapsible" then collapse = " mw-made-collapsible mw-collapsible" elseif collapse == "collapsed" then collapse = " mw-made-collapsible mw-collapsible mw-collapsed" else collapse = "" end return collapse end local function getItemDust(tier) tier = math.floor(tier) if tier <= 2 then return "Basic Runic Dust" elseif tier <= 3 then return "Unusual Runic Dust" elseif tier <= 4 then return "Singular Runic Dust" elseif tier <= 5 then return "Prime Runic Dust" elseif tier > 5 then return "Mythical Runic Dust" end end local function createImgCell(item) local imgCell = mw.html.create('td') :css('text-align', 'center') :wikitext(img._img({item.name, '50'})) :done() return imgCell end local function createNameCell(item) local blockAction = '' if item.blockAugmenting then blockAction = ' <sup>(A)</sup>' end if item.blockResearching then blockAction = ' <sup>(R)</sup>' end local nameCell = mw.html.create('td') :wikitext("[[" .. item.name .. "]]" .. blockAction) :done() return nameCell end local function createXpCell(item) local xpCell = mw.html.create('td') :css('text-align', 'center') :wikitext(tostring(getScrapExperience(item))) :done() return xpCell end local function createAugBonusCell(item) local augBonusCell = mw.html.create('td') local augBonusS = "" local css = {} if item.equipmentStats and item.equipmentStats.augmentationBonus then local augBonusC = tablelength(item.equipmentStats.augmentationBonus) for _, augBonus in ipairs(item.equipmentStats.augmentationBonus) do augBonusS = augBonusS .. augmentationBonusNames[augBonus.stat] .. " +" .. augBonus.value augBonusC = augBonusC - 1 if augBonusC > 0 then augBonusS = augBonusS .. "<br>" end end else augBonusS = "-" css['text-align'] = 'center' end augBonusCell :css(css) :wikitext(augBonusS) :done() return augBonusCell end local function createCostCell(mItemData, item) local costCell = mw.html.create('td') local augCostC = tablelength(mItemData) for costId, costQuantity in pairsByKeys(mItemData) do local costItem = getItem(costId) if tonumber(costId) == item.id then costCell:tag('span'):css('display', 'inline-block') :wikitext(tostring(costQuantity) .. " " .. img._img({costItem.name, '25'})) :tag('span'):css('font-weight', 'bold') :wikitext(costItem.name) :done() :done() augCostC = augCostC - 1 if augCostC > 0 then costCell:tag('br') end else costCell:tag('span'):css('display', 'inline-block') :wikitext(tostring(costQuantity) .. " " .. img._img({costItem.name, '25', word = 1})) :done() augCostC = augCostC - 1 if augCostC > 0 then costCell:tag('br') end end end return costCell end local function createDustCell(item) local itemTier = getItemTier(item) local css = {} local cellContent if item.blockResearching then css['text-align'] = 'center' cellContent = '-' else cellContent = img._img({getItemDust(itemTier), '25', word = 1}) end local dustCell = mw.html.create('td') :css(css) :wikitext(cellContent) :done() return dustCell end local function createScrapCell(item) local rarity = item.rarity or 'Common' local cellContent local css = {} if item.blockResearching then cellContent = '-' css['text-align'] = 'center' else cellContent = img._img({rarity .. " Gear Scraps", '25', word = 1}) end local scrapCell = mw.html.create('td') :css(css) :wikitext(cellContent) :done() return scrapCell end local function genTable(name, collapse) local item = getItem(findId._findId({name, "item"})) local matchedAugs = getMatchedAugs(item.id) local t = mw.html.create("table") :addClass("wikitable sortable jquery-tablesorter" .. collapse) :tag('tr') :tag('th') :attr("colspan", "2") :wikitext("Item") :done() :tag('th') :wikitext("XP") :done() :tag('th') :wikitext("Dust") :done() :tag('th') :wikitext("Scrap") :done() :tag("th") :wikitext("Aug. Bonus") :done() :tag("th") :wikitext("Cost") :done() :done() for mItemId, mItemData in pairs(matchedAugs) do local mItem = getItem(mItemId) t:tag('tr') :node(createImgCell(mItem)) :node(createNameCell(mItem)) :node(createXpCell(mItem)) :node(createDustCell(mItem)) :node(createScrapCell(mItem)) :node(createAugBonusCell(mItem)) :node(createCostCell(mItemData, item)) :done() end return t end local function createNotification() local notification = '' if blocking.augmenting then notification = notification .. 'A: This item cannot be augmented.' end if blocking.researching then if notification ~= '' then notification = notification .. '<br />' end notification = notification .. 'R: This item cannot be researched.' end return notification end function p.augmentingUses(frame) return p._augmentingUses(frame:getParent().args) end function p._augmentingUses(_args) local name = "" if tablelength(_args) == 0 then name = pageName elseif _args["collapse"] and not _args[1] then name = pageName elseif _args["collapse"] and _args[1] then name = _args[1] else name = _args[1] end local t = mw.html.create(nil) :node(genTable(name, decideCollapseState(_args["collapse"]))) if blocking.augmenting or blocking.researching then t:tag('p') :wikitext(createNotification()) end return t end return p