4,951
edits
Falterfire (talk | contribs) (Moving p.GetOtherItemBoxText back over) |
Falterfire (talk | contribs) (Fixed string.upper call) |
||
(19 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
--Several functions related to use tables can be found at Module:Items/UseTables | --Several functions related to use tables can be found at Module:Items/UseTables | ||
--Functions related to source tables can be found at Module:Items/SourceTables | --Functions related to source tables can be found at Module:Items/SourceTables | ||
--Other functions moved to Module:Items/ComparisonTables | |||
local p = {} | local p = {} | ||
Line 8: | Line 9: | ||
local ItemData = mw.loadData('Module:Items/data') | local ItemData = mw.loadData('Module:Items/data') | ||
local SkillData = mw.loadData('Module:Skills/data') | local SkillData = mw.loadData('Module:Skills/data') | ||
local Constants = require('Module:Constants') | |||
local Shared = require('Module:Shared') | local Shared = require('Module:Shared') | ||
local Icons = require('Module:Icons') | local Icons = require('Module:Icons') | ||
p.EasterEggs = {'Amulet of Calculated Promotion', 'Clue Chasers Insignia', '8', 'Lemon'} | |||
p.OtherShopItems = {'Cooking Gloves', 'Mining Gloves', 'Gem Gloves', 'Smithing Gloves', 'Thieving Gloves'} | |||
--This is hardcoded, so there's no easy way to scrape it. Hopefully it doesn't change | --This is hardcoded, so there's no easy way to scrape it. Hopefully it doesn't change | ||
p.GemTable = {["Topaz"] = {name = 'Topaz', id = 128, chance = 50}, | |||
["Sapphire"] = {name = "Sapphire", id = 129, chance = 17.5}, | ["Sapphire"] = {name = "Sapphire", id = 129, chance = 17.5}, | ||
["Ruby"] = {name = "Ruby", id = 130, chance = 17.5}, | ["Ruby"] = {name = "Ruby", id = 130, chance = 17.5}, | ||
Line 24: | Line 23: | ||
["Diamond"] = {name = "Diamond", id = 132, chance = 5}} | ["Diamond"] = {name = "Diamond", id = 132, chance = 5}} | ||
--The base chance to receive a gem while mining | --The base chance to receive a gem while mining | ||
p.GemChance = .01 | |||
--The number of different fishing junk items | --The number of different fishing junk items | ||
p.junkCount = 8 | |||
--Items (aside from bars & gems) which can be created via Alt Magic | --Items (aside from bars & gems) which can be created via Alt Magic | ||
local AltMagicProducts = {'Rune Essence', 'Bones', 'Holy Dust'} | local AltMagicProducts = {'Rune Essence', 'Bones', 'Holy Dust'} | ||
Line 131: | Line 130: | ||
result = item.description | result = item.description | ||
if result == nil or result == '' then result = 'No Description' end | if result == nil or result == '' then result = 'No Description' end | ||
elseif StatName == 'completionReq' then | |||
if item.ignoreCompletion == nil or not item.ignoreCompletion then | |||
return 'Yes' | |||
else | |||
return 'No' | |||
end | |||
elseif StatName == 'slayerBonusXP' then | |||
return p._getItemModifier(item, 'increasedSkillXP', 'Slayer', false) | |||
end | end | ||
if result == nil and ZeroIfNil then result = 0 end | if result == nil and ZeroIfNil then result = 0 end | ||
Line 144: | Line 151: | ||
local item = p.getItem(ItemName) | local item = p.getItem(ItemName) | ||
if item == nil then | if item == nil then | ||
return "ERROR: No item named "..ItemName.." exists in the data module" | return "ERROR: No item named "..ItemName.." exists in the data module[[Category:Pages with script errors]]" | ||
end | end | ||
local result = p._getItemStat(item, StatName, ZeroIfNil) | local result = p._getItemStat(item, StatName, ZeroIfNil) | ||
if formatNum then result = Shared.formatnum(result) end | if formatNum then result = Shared.formatnum(result) end | ||
return result | return result | ||
end | |||
--Gets the value of a given modifier for a given item | |||
--asString is false by default, when true it writes the full bonus text | |||
function p._getItemModifier(item, modifier, skill, asString) | |||
if asString == nil then asString = false end | |||
if skill == '' then | |||
skill = nil | |||
elseif type(skill) == 'string' then | |||
skill = Constants.getSkillID(skill) | |||
end | |||
mw.log(item.name..', '..modifier) | |||
local result = 0 | |||
if item.modifiers ~= nil and item.modifiers[modifier] ~= nil then | |||
if type(item.modifiers[modifier]) == 'table' then | |||
for i, subVal in Shared.skpairs(item.modifiers[modifier]) do | |||
if subVal[1] == skill then | |||
result = subVal[2] | |||
break | |||
end | |||
end | |||
else | |||
result = item.modifiers[modifier] | |||
end | |||
end | |||
if asString then | |||
if skill ~= nil then | |||
return Constants._getModifierText(modifier, {skill, result}) | |||
else | |||
return Constants._getModifierText(modifier, result) | |||
end | |||
else | |||
return result | |||
end | |||
end | |||
function p.getItemModifier(frame) | |||
local itemName = frame.args ~= nil and frame.args[1] or frame[1] | |||
local modName = frame.args ~= nil and frame.args[2] or frame[2] | |||
local skillName = frame.args ~= nil and frame.args[3] or frame[3] | |||
local asString = frame.args ~= nil and frame.args[4] or frame[4] | |||
if asString ~= nil then | |||
if string.upper(asString) == 'FALSE' then | |||
asString = false | |||
else | |||
asString = true | |||
end | |||
end | |||
local item = p.getItem(itemName) | |||
if item == nil then | |||
return "ERROR: No item named "..itemName.." exists in the data module[[Category:Pages with script errors]]" | |||
end | |||
return p._getItemModifier(item, modName, skillName, asString) | |||
end | end | ||
Line 168: | Line 234: | ||
local item = p.getItem(itemName) | local item = p.getItem(itemName) | ||
if item == nil then | if item == nil then | ||
return "ERROR: No item named "..ItemName.." exists in the data module" | return "ERROR: No item named "..ItemName.." exists in the data module[[Category:Pages with script errors]]" | ||
end | end | ||
return p._getWeaponAttackType(item) | return p._getWeaponAttackType(item) | ||
Line 194: | Line 260: | ||
result = result..'\r\n|}' | result = result..'\r\n|}' | ||
return result | return result | ||
end | end | ||
Line 209: | Line 266: | ||
--For equipment, show the slot they go in | --For equipment, show the slot they go in | ||
if item.equipmentSlot ~= nil then | if item.equipmentSlot ~= nil then | ||
result = result.. | result = result.."\r\n|-\r\n|'''Equipment Slot:''' "..Constants.getEquipmentSlotName(item.equipmentSlot) | ||
if item.isPassiveItem then | |||
result = result..', Passive' | |||
end | |||
end | end | ||
--For weapons with a special attack, show the details | --For weapons with a special attack, show the details | ||
if item.hasSpecialAttack then | if item.hasSpecialAttack then | ||
local spAtt = p.getSpecialAttackByID(item.specialAttackID) | local spAtt = p.getSpecialAttackByID(item.specialAttackID) | ||
result = result.. | result = result.."\r\n|-\r\n|'''Special Attack:'''" | ||
result = result..'\r\n* '..spAtt.chance..'% chance for '..spAtt.name..':' | result = result..'\r\n* '..spAtt.chance..'% chance for '..spAtt.name..':' | ||
result = result..'\r\n** '..spAtt.description | result = result..'\r\n** '..spAtt.description | ||
Line 220: | Line 280: | ||
--For potions, show the number of charges | --For potions, show the number of charges | ||
if item.potionCharges ~= nil then | if item.potionCharges ~= nil then | ||
result = result.. | result = result.."\r\n|-\r\n|'''Charges:''' "..item.potionCharges | ||
end | end | ||
--For food, show how much it heals for | --For food, show how much it heals for | ||
if item.healsFor ~= nil then | if item.healsFor ~= nil then | ||
result = result.. | result = result.."\r\n|-\r\n|'''Heals for:''' "..Icons.Icon({"Hitpoints", type="skill", notext="true"})..' '..(item.healsFor * 10) | ||
end | end | ||
--For Prayer Points, show how many you get | --For Prayer Points, show how many you get | ||
if item.prayerPoints ~= nil then | if item.prayerPoints ~= nil then | ||
result = result.. | result = result.."\r\n|-\r\n|'''"..Icons.Icon({'Prayer', type='skill'}).." Points:''' "..item.prayerPoints | ||
end | |||
--For items with modifiers, show what those are | |||
if item.modifiers ~= nil and Shared.tableCount(item.modifiers) > 0 then | |||
local modArray = {} | |||
for bonus, value in Shared.skpairs(item.modifiers) do | |||
table.insert(modArray, Constants._getModifierText(bonus, value, false)) | |||
end | |||
result = result.."\r\n|-\r\n|'''Bonuses:'''\r\n"..table.concat(modArray, "<br/>") | |||
end | end | ||
return result | return result | ||
Line 241: | Line 309: | ||
end | end | ||
if item == nil then | if item == nil then | ||
return "ERROR: No item named "..itemName.." exists in the data module" | return "ERROR: No item named "..itemName.." exists in the data module[[Category:Pages with script errors]]" | ||
end | end | ||
return p._getOtherItemBoxText(item, asList) | return p._getOtherItemBoxText(item, asList) | ||
end | end | ||
Line 494: | Line 319: | ||
if item.category ~= nil then result = result..'[[Category:'..item.category..']]' end | if item.category ~= nil then result = result..'[[Category:'..item.category..']]' end | ||
if item.type ~= nil then result = result..'[[Category:'..item.type..']]' end | if item.type ~= nil then result = result..'[[Category:'..item.type..']]' end | ||
if item.tier ~= nil then result = result..'[[Category:'..Shared.titleCase(item.tier)..' '..item.type..']]' end | |||
if item.hasSpecialAttack then result = result..'[[Category:Items With Special Attacks]]' end | |||
if item.isPassiveItem then result = result..'[[Category:Passive Items]]' end | |||
if item.chanceToDoubleLoot ~= nil and item.chanceToDoubleLoot > 0 then result = result..'[[Category:Double Loot Chance Items]]' end | |||
return result | return result | ||
end | end | ||
Line 501: | Line 330: | ||
local item = p.getItem(itemName) | local item = p.getItem(itemName) | ||
if item == nil then | if item == nil then | ||
return "ERROR: No item named "..itemName.." exists in the data module" | return "ERROR: No item named "..itemName.." exists in the data module[[Category:Pages with script errors]]" | ||
end | end | ||
Line 563: | Line 392: | ||
end | end | ||
result = result..'\r\n|}' | result = result..'\r\n|}' | ||
return result | |||
end | |||
function p.getSpecialAttackTable(frame) | |||
local spAttTable = {} | |||
for i, item in Shared.skpairs(ItemData.Items) do | |||
if item.hasSpecialAttack then | |||
if spAttTable[item.specialAttackID] == nil then spAttTable[item.specialAttackID] = {sortName=item.name, Icons = {}} end | |||
table.insert(spAttTable[item.specialAttackID].Icons, Icons.Icon({item.name, type='item'})) | |||
end | |||
end | |||
local result = '{|class="wikitable sortable stickyHeader"' | |||
result = result..'\r\n|-class="headerRow-0"' | |||
result = result..'\r\n!style="min-width:180px"|Weapon(s)!!Name!!Chance!!Effect' | |||
for i, spAttData in Shared.skpairs(spAttTable) do | |||
local spAtt = p.getSpecialAttackByID(i) | |||
table.sort(spAttData.Icons, function(a, b) return a < b end) | |||
result = result..'\r\n|-' | |||
result = result..'\r\n|data-sort-value="'..spAttData.sortName..'"|'..table.concat(spAttData.Icons, '<br/>') | |||
result = result..'||'..spAtt.name..'||data-sort-value="'..spAtt.chance..'"|'..spAtt.chance..'%' | |||
result = result..'||'..spAtt.description | |||
end | |||
result = result..'\r\n|}' | |||
return result | return result | ||
end | end | ||
return p | return p |