Difference between revisions of "Module:Infobox Item"

From Idlescape Wiki
Jump to navigation Jump to search
m
m
 
(8 intermediate revisions by the same user not shown)
Line 4: Line 4:
 
item = 'Module:Items/data',
 
item = 'Module:Items/data',
 
enchantment = 'Module:Enchantment/data',
 
enchantment = 'Module:Enchantment/data',
location = 'Module:Location/data'
+
location = 'Module:Location/data',
 +
craftaug = 'Module:CraftingAugmenting/data'
 
}
 
}
  
Line 70: Line 71:
 
lname = lname:gsub('^%s*(.-)%s*$', '%1')
 
lname = lname:gsub('^%s*(.-)%s*$', '%1')
 
for key, item in pairs(p.loadData("item")) do
 
for key, item in pairs(p.loadData("item")) do
if lname == item['name']:lower() then
+
if lname == item.name:lower() then
 
return item
 
return item
 
end
 
end
Line 82: Line 83:
  
 
local function getEnchantmentName(id)
 
local function getEnchantmentName(id)
return p.loadData("enchantment")[tostring(id)]['name']
+
return p.loadData("enchantment")[tostring(id)].name
 
end
 
end
  
 
local function getItemName(id)
 
local function getItemName(id)
return p.loadData("item")[tostring(id)]['name']
+
return p.loadData("item")[tostring(id)].name
 +
end
 +
 
 +
local function getCraftAug(id)
 +
return p.loadData("craftaug")[tostring(id)]
 
end
 
end
  
Line 117: Line 122:
 
local item = p.loadData("item")[tostring(id)]
 
local item = p.loadData("item")[tostring(id)]
 
local url = ""
 
local url = ""
if item['itemIcon'] then
+
if item.itemIcon then
url = item['itemIcon']
+
url = item.itemIcon
 +
else
 +
url = item.itemImage
 +
end
 +
return icon(item.name, url, word)
 +
end
 +
 
 +
local function locationImage(id, word)
 +
local loc = p.loadData("location")[tostring(id)]
 +
local url = ""
 +
if loc.locationImage then
 +
url = loc.locationImage
 
else
 
else
url = item['itemImage']
+
return "[[" .. loc.name .. "]]"
 
end
 
end
return icon(item['name'], url, word)
+
return icon(loc.name, url, word)
 
end
 
end
  
 
local function img(id)
 
local function img(id)
 
local url = ""
 
local url = ""
if item['itemIcon'] then
+
if item.itemIcon then
url = item['itemIcon']
+
url = item.itemIcon
 
else
 
else
url = item['itemImage']
+
url = item.itemImage
 
end
 
end
 
return fullUrl(url)
 
return fullUrl(url)
Line 139: Line 155:
 
end
 
end
  
local function farmingSource(id)
+
local function gatheringSource(id)
 
local s = ""
 
local s = ""
+
for key, loc in pairs(p.loadData('location')) do
for key, item in pairs(p.loadData('item')) do
+
if loc.loot then
if item['farmingStats'] then
+
for key2, loot in pairs(loc.loot) do
for key2, yield in pairs(item['farmingStats']['yield']) do
+
if id == loot.id then
if id == yield['id'] then
+
s = s .. locationImage(loc.locID, true)
s = s .. itemImage(item['id'], true)
 
 
s = s .. "<br>"
 
s = s .. "<br>"
 
end
 
end
Line 154: Line 169:
 
return s
 
return s
 
end
 
end
 +
 +
-- local function farmingSource(id)
 +
-- local s = ""
 +
 +
-- for key, item in pairs(p.loadData('item')) do
 +
-- if item.farmingStats then
 +
-- for key2, yield in pairs(item.farmingStats.yield) do
 +
-- if id == yield.id then
 +
-- s = s .. itemImage(item.id, true)
 +
-- s = s .. "<br>"
 +
-- end
 +
-- end
 +
-- end
 +
-- end
 +
-- return s
 +
-- end
  
 
local function smithingSource(id)
 
local function smithingSource(id)
 
local s = ""
 
local s = ""
 
local item = getItem(id)
 
local item = getItem(id)
if item['skill'] == "smithing" and item['name'] ~= 'Ichor' then
+
if item.skill == "smithing" and item.name ~= 'Ichor' then
 
s = '[[Smithing]]<br>'
 
s = '[[Smithing]]<br>'
 
end
 
end
Line 167: Line 198:
 
local s = ""
 
local s = ""
 
local item = getItem(id)
 
local item = getItem(id)
if (item['class'] == "cooking-ingredient" and not item['ingredientTags']) or item['class'] == 'cookedFish' or item['name']=='Ashes' then
+
if (item.class == "cooking-ingredient" and not item.ingredientTags) or item.class == 'cookedFish' or item.name=='Ashes' then
 
s = '[[Cooking]]<br>'
 
s = '[[Cooking]]<br>'
 
end
 
end
Line 176: Line 207:
 
local s = ""
 
local s = ""
 
local item = getItem(id)
 
local item = getItem(id)
if item['class'] == "cloth" or (item['class'] == 'rune' and item['requiredResources']) then
+
if item.class == "cloth" or (item.class == 'rune' and item.requiredResources) then
 
s = '[[Runecrafting]]<br>'
 
s = '[[Runecrafting]]<br>'
 
end
 
end
Line 185: Line 216:
 
local s = ""
 
local s = ""
 
local item = getItem(id)
 
local item = getItem(id)
if item['class'] == "enchanted-scroll" and item['level'] < 100 then
+
if item.class == "enchanted-scroll" and item.level < 100 then
 
s = '[[Scrollcrafting]]<br>'
 
s = '[[Scrollcrafting]]<br>'
 
end
 
end
Line 191: Line 222:
 
end
 
end
  
local function gatheringSource(id)
 
local s = ""
 
for key, loc in pairs(p.loadData('location')) do
 
if loc['loot'] then
 
for key2, loot in pairs(loc['loot']) do
 
if id == loot['id'] then
 
s = s .. "[[" .. loc['name'] .. "]]"
 
s = s .. "<br>"
 
end
 
end
 
end
 
end
 
return s
 
end
 
  
 
local function craftingSource(id)
 
local function craftingSource(id)
 
local s = ""
 
local s = ""
 
local item = getItem(id)
 
local item = getItem(id)
if item['craftable'] then
+
if item.craftable then
 
s = '[[Crafting]]<br>'
 
s = '[[Crafting]]<br>'
 
end
 
end
Line 218: Line 235:
 
local s = ""
 
local s = ""
 
s = s .. gatheringSource(id)
 
s = s .. gatheringSource(id)
s = s .. farmingSource(id)
+
-- s = s .. farmingSource(id)
 
s = s .. scrollcraftingSource(id)
 
s = s .. scrollcraftingSource(id)
 
s = s .. runecraftingSource(id)
 
s = s .. runecraftingSource(id)
Line 234: Line 251:
 
local url = ""
 
local url = ""
 
local s = ""
 
local s = ""
args['autoheaders'] = "y"
+
args.autoheaders = "y"
args['subbox'] = "no"
+
args.subbox = "no"
args['bodystyle'] = " "
+
args.bodystyle = " "
args['title'] = item['name']
+
args.title = item.name
 
 
if item['itemIcon'] then
+
if item.itemIcon then
url = item['itemIcon']
+
url = item.itemIcon
 
else
 
else
url = item['itemImage']
+
url = item.itemImage
 
end
 
end
args['image'] = "<img src=\"" .. fullUrl(url) .. "\" width=\"150\">"
+
args.image = "<img src=\"" .. fullUrl(url) .. "\" width=\"150\">"
 
 
if item['value'] then
+
if item.value then
 
args[l()] = icon('Gold', "/images/gold_coin.png")
 
args[l()] = icon('Gold', "/images/gold_coin.png")
args[d()] = addSeparator(item['value'])
+
args[d()] = addSeparator(item.value)
 
end
 
end
 
 
if item['tradeable'] then
+
if item.tradeable then
 
args[l()] = icon('Market', "/images/ui/marketplace_icon.png")
 
args[l()] = icon('Market', "/images/ui/marketplace_icon.png")
local market = require("Module:Market")["_price"]({item['name'], 1, 1})
+
local market = require("Module:Market")["_price"]({item.name, 1, 1})
 
if market then
 
if market then
 
args[d()] = addSeparator(market)
 
args[d()] = addSeparator(market)
Line 261: Line 278:
 
end
 
end
 
 
if item['requiredLevel'] then
+
if item.requiredLevel then
 
s = ""
 
s = ""
for skill, level in pairs(item['requiredLevel']) do
+
for skill, level in pairs(item.requiredLevel) do
 
s = s .. level .. " " .. skill .. "<br>"
 
s = s .. level .. " " .. skill .. "<br>"
 
end
 
end
Line 272: Line 289:
 
 
 
args[l()] = "Source"
 
args[l()] = "Source"
args[d()] = findSource(item['id'])
+
args[d()] = findSource(item.id)
 
 
if item['heat'] then
+
if item.heat then
 
args[l()] = itemImage(2)
 
args[l()] = itemImage(2)
args[d()] = addSeparator(item['heat'])
+
args[d()] = addSeparator(item.heat)
 
end
 
end
 
 
local stats = item['equipmentStats']
+
local stats = item.equipmentStats
 
if stats then
 
if stats then
 
args[l()] = "Slot"
 
args[l()] = "Slot"
args[d()] = stats['slot']
+
args[d()] = stats.slot
 
 
if item['enchantmentTier'] then
+
if item.enchantmentTier then
 
args[l()] = "Enchantment Slots"
 
args[l()] = "Enchantment Slots"
args[d()] = item['enchantmentTier']
+
args[d()] = item.enchantmentTier
 
end
 
end
 
 
if item['forcedEnchant'] then
+
if item.forcedEnchant then
 
args[l()] = "Enchantments"
 
args[l()] = "Enchantments"
args[d()] = "[[" .. getEnchantmentName(item['forcedEnchant']) .. "]]"
+
args[d()] = "[[" .. getEnchantmentName(item.forcedEnchant) .. "]]"
 
end
 
end
 
 
if stats['toolBoost'] then
+
if stats.toolBoost then
 
s = ""
 
s = ""
for key, stat in pairs(stats['toolBoost']) do
+
for key, stat in pairs(stats.toolBoost) do
 
s = s .. stat.boost .. " "
 
s = s .. stat.boost .. " "
 
s = s .. stat.skill .. "<br>"
 
s = s .. stat.skill .. "<br>"
Line 305: Line 322:
 
end
 
end
 
 
if stats['oneHanded'] == false then
+
if stats.oneHanded == false then
 
args[l()] = "Two-handed"
 
args[l()] = "Two-handed"
 
args[d()] = "Yes"
 
args[d()] = "Yes"
 
end
 
end
 
 
if stats['attackSpeed'] then
+
if stats.attackSpeed then
 
args[l()] = "Attack Speed"
 
args[l()] = "Attack Speed"
args[d()] = stats['attackSpeed']
+
args[d()] = stats.attackSpeed
 
end
 
end
 
 
Line 318: Line 335:
 
args[h()] = "Offensive Stats"
 
args[h()] = "Offensive Stats"
 
 
local stat = stats['offensiveCritical']
+
local stat = stats.offensiveCritical
 
if stat then
 
if stat then
 
args[l()] = "Crit Chance"
 
args[l()] = "Crit Chance"
args[d()] = stat['chance']
+
args[d()] = stat.chance
 
args[l()] = "Crit Multiplier"
 
args[l()] = "Crit Multiplier"
args[d()] = stat['damageMultiplier']
+
args[d()] = stat.damageMultiplier
 
end
 
end
 
 
stat = stats['weaponBonus']
+
stat = stats.weaponBonus
 
if stat then
 
if stat then
 
args[sl()] = "Str"
 
args[sl()] = "Str"
args[sd()] = stat['strength']
+
args[sd()] = stat.strength
 
args[sl()] = "Int"
 
args[sl()] = "Int"
args[sd()] = stat['intellect']
+
args[sd()] = stat.intellect
 
args[sl()] = "Dex"
 
args[sl()] = "Dex"
args[sd()] = stat['dexterity']
+
args[sd()] = stat.dexterity
 
end
 
end
 
 
 
args[h()] = "Offensive Affinity"
 
args[h()] = "Offensive Affinity"
stat = stats['offensiveDamageAffinity']
+
stat = stats.offensiveDamageAffinity
 
if stat then
 
if stat then
 
args[sl()] = "Melee"
 
args[sl()] = "Melee"
args[sd()] = stat['Melee'] and stat['Melee'] * 100 .. "%"
+
args[sd()] = stat.Melee and stat.Melee * 100 .. "%"
 
args[sl()] = "Magic"
 
args[sl()] = "Magic"
args[sd()] = stat['Magic'] and stat['Magic'] * 100 .. "%"
+
args[sd()] = stat.Magic and stat.Magic * 100 .. "%"
 
args[sl()] = "Range"
 
args[sl()] = "Range"
args[sd()] = stat['Range'] and stat['Range'] * 100 .. "%"
+
args[sd()] = stat.Range and stat.Range * 100 .. "%"
 
args[sbreak()] = "yes"
 
args[sbreak()] = "yes"
 
 
 
args[sl()] = "Piercing"
 
args[sl()] = "Piercing"
args[sd()] = stat['Piercing'] and stat['Piercing'] * 100 .. "%"
+
args[sd()] = stat.Piercing and stat.Piercing * 100 .. "%"
 
args[sl()] = "Blunt"
 
args[sl()] = "Blunt"
args[sd()] = stat['Blunt'] and stat['Blunt'] * 100 .. "%"
+
args[sd()] = stat.Blunt and stat.Blunt * 100 .. "%"
 
args[sl()] = "Slashing"
 
args[sl()] = "Slashing"
args[sd()] = stat['Slashing'] and stat['Slashing'] * 100 .. "%"
+
args[sd()] = stat.Slashing and stat.Slashing * 100 .. "%"
 
args[sl()] = "Fire"
 
args[sl()] = "Fire"
args[sd()] = stat['Fire'] and stat['Fire'] * 100 .. "%"
+
args[sd()] = stat.Fire and stat.Fire * 100 .. "%"
 
args[sl()] = "Ice"
 
args[sl()] = "Ice"
args[sd()] = stat['Ice'] and stat['Ice'] * 100 .. "%"
+
args[sd()] = stat.Ice and stat.Ice * 100 .. "%"
 
args[sl()] = "Nature"
 
args[sl()] = "Nature"
args[sd()] = stat['Nature'] and stat['Nature'] * 100 .. "%"
+
args[sd()] = stat.Nature and stat.Nature * 100 .. "%"
 
args[sl()] = "Chaos"
 
args[sl()] = "Chaos"
args[sd()] = stat['Chaos'] and stat['Chaos'] * 100 .. "%"
+
args[sd()] = stat.Chaos and stat.Chaos * 100 .. "%"
 
args[sbreak()] = "yes"
 
args[sbreak()] = "yes"
 
end
 
end
 
 
 
args[h()] = "Accuracy"
 
args[h()] = "Accuracy"
stat = stats['offensiveAccuracyAffinityRating']
+
stat = stats.offensiveAccuracyAffinityRating
 
if stat then
 
if stat then
 
args[sl()] = "Melee"
 
args[sl()] = "Melee"
args[sd()] = stat['Melee']
+
args[sd()] = stat.Melee
 
args[sl()] = "Magic"
 
args[sl()] = "Magic"
args[sd()] = stat['Magic']
+
args[sd()] = stat.Magic
 
args[sl()] = "Range"
 
args[sl()] = "Range"
args[sd()] = stat['Range']
+
args[sd()] = stat.Range
 
args[sbreak()] = "yes"
 
args[sbreak()] = "yes"
 
 
 
args[sl()] = "Piercing"
 
args[sl()] = "Piercing"
args[sd()] = stat['Piercing']
+
args[sd()] = stat.Piercing
 
args[sl()] = "Blunt"
 
args[sl()] = "Blunt"
args[sd()] = stat['Blunt']
+
args[sd()] = stat.Blunt
 
args[sl()] = "Slashing"
 
args[sl()] = "Slashing"
args[sd()] = stat['Slashing']
+
args[sd()] = stat.Slashing
 
args[sl()] = "Fire"
 
args[sl()] = "Fire"
args[sd()] = stat['Fire']
+
args[sd()] = stat.Fire
 
args[sl()] = "Ice"
 
args[sl()] = "Ice"
args[sd()] = stat['Ice']
+
args[sd()] = stat.Ice
 
args[sl()] = "Nature"
 
args[sl()] = "Nature"
args[sd()] = stat['Nature']
+
args[sd()] = stat.Nature
 
args[sl()] = "Chaos"
 
args[sl()] = "Chaos"
args[sd()] = stat['Chaos']
+
args[sd()] = stat.Chaos
 
args[sbreak()] = "yes"
 
args[sbreak()] = "yes"
 
end
 
end
Line 394: Line 411:
 
args[h()] = "Defensive Stats"
 
args[h()] = "Defensive Stats"
 
 
local stat = stats['defensiveCritical']
+
local stat = stats.defensiveCritical
 
if stat then
 
if stat then
 
args[l()] = "Crit Avoidance"
 
args[l()] = "Crit Avoidance"
args[d()] = stat['chance']
+
args[d()] = stat.chance
 
args[l()] = "Crit Reduction"
 
args[l()] = "Crit Reduction"
args[d()] = stat['damageMultiplier']
+
args[d()] = stat.damageMultiplier
 
end
 
end
 
 
stat = stats['armorBonus']
+
stat = stats.armorBonus
 
if stat then
 
if stat then
 
args[sl()] = "Protection"
 
args[sl()] = "Protection"
args[sd()] = stat['protection']
+
args[sd()] = stat.protection
 
args[sl()] = "Resistance"
 
args[sl()] = "Resistance"
args[sd()] = stat['resistance']
+
args[sd()] = stat.resistance
 
args[sl()] = "Agility"
 
args[sl()] = "Agility"
args[sd()] = stat['agility']
+
args[sd()] = stat.agility
 
args[sl()] = "Stamina"
 
args[sl()] = "Stamina"
args[sd()] = stat['stamina']
+
args[sd()] = stat.stamina
 
end
 
end
 
 
 
args[h()] = "Defensive Affinity"
 
args[h()] = "Defensive Affinity"
stat = stats['defensiveDamageAffinity']
+
stat = stats.defensiveDamageAffinity
 
if stat then
 
if stat then
 
args[sl()] = "Melee"
 
args[sl()] = "Melee"
args[sd()] = stat['Melee'] and stat['Melee'] * 100 .. "%"
+
args[sd()] = stat.Melee and stat.Melee * 100 .. "%"
 
args[sl()] = "Magic"
 
args[sl()] = "Magic"
args[sd()] = stat['Magic'] and stat['Magic'] * 100 .. "%"
+
args[sd()] = stat.Magic and stat.Magic * 100 .. "%"
 
args[sl()] = "Range"
 
args[sl()] = "Range"
args[sd()] = stat['Range'] and stat['Range'] * 100 .. "%"
+
args[sd()] = stat.Range and stat.Range * 100 .. "%"
 
args[sbreak()] = "yes"
 
args[sbreak()] = "yes"
 
 
 
args[sl()] = "Piercing"
 
args[sl()] = "Piercing"
args[sd()] = stat['Piercing'] and stat['Piercing'] * 100 .. "%"
+
args[sd()] = stat.Piercing and stat.Piercing * 100 .. "%"
 
args[sl()] = "Blunt"
 
args[sl()] = "Blunt"
args[sd()] = stat['Blunt'] and stat['Blunt'] * 100 .. "%"
+
args[sd()] = stat.Blunt and stat.Blunt * 100 .. "%"
 
args[sl()] = "Slashing"
 
args[sl()] = "Slashing"
args[sd()] = stat['Slashing'] and stat['Slashing'] * 100 .. "%"
+
args[sd()] = stat.Slashing and stat.Slashing * 100 .. "%"
 
args[sl()] = "Fire"
 
args[sl()] = "Fire"
args[sd()] = stat['Fire'] and stat['Fire'] * 100 .. "%"
+
args[sd()] = stat.Fire and stat.Fire * 100 .. "%"
 
args[sl()] = "Ice"
 
args[sl()] = "Ice"
args[sd()] = stat['Ice'] and stat['Ice'] * 100 .. "%"
+
args[sd()] = stat.Ice and stat.Ice * 100 .. "%"
 
args[sl()] = "Nature"
 
args[sl()] = "Nature"
args[sd()] = stat['Nature'] and stat['Nature'] * 100 .. "%"
+
args[sd()] = stat.Nature and stat.Nature * 100 .. "%"
 
args[sl()] = "Chaos"
 
args[sl()] = "Chaos"
args[sd()] = stat['Chaos'] and stat['Chaos'] * 100 .. "%"
+
args[sd()] = stat.Chaos and stat.Chaos * 100 .. "%"
 
args[sbreak()] = "yes"
 
args[sbreak()] = "yes"
 
end
 
end
Line 444: Line 461:
 
 
 
args[h()] = "Augment"
 
args[h()] = "Augment"
 +
local craftAug = getCraftAug(item.id)
 
 
if item['augmentationCost'] then
+
if craftAug and craftAug.augmenting then
 
s = ""
 
s = ""
for key, bonus in pairs(item['equipmentStats']['augmentationBonus']) do
+
for key, bonus in pairs(item.equipmentStats.augmentationBonus) do
 
s = s .. "+" .. bonus.value .. " "
 
s = s .. "+" .. bonus.value .. " "
 
s = s .. bonus.stat:sub(bonus.stat:find('%.')+1,bonus.stat:len()) .. "<br>"
 
s = s .. bonus.stat:sub(bonus.stat:find('%.')+1,bonus.stat:len()) .. "<br>"
Line 456: Line 474:
 
 
 
s = ""
 
s = ""
for key, cost in pairs(item['augmentationCost']) do
+
for key, cost in pairs(craftAug.augmenting) do
 
s = s .. cost .. " "
 
s = s .. cost .. " "
 
s = s .. itemImage(key, true) .. "<br>"
 
s = s .. itemImage(key, true) .. "<br>"
Line 467: Line 485:
 
args[h()] = "Cooking"
 
args[h()] = "Cooking"
 
 
if item['size'] then
+
if item.size then
 
args[l()] = "Size"
 
args[l()] = "Size"
args[d()] = item['size']
+
args[d()] = item.size
 
end
 
end
 
 
if item['difficulty'] then
+
if item.difficulty then
 
args[l()] = "Difficulty"
 
args[l()] = "Difficulty"
args[d()] = item['difficulty']
+
args[d()] = item.difficulty
 
end
 
end
 
 
if item['ingredientTags'] then
+
if item.ingredientTags then
 
s = ""
 
s = ""
for key, tag in pairs(item['ingredientTags']) do
+
for key, tag in pairs(item.ingredientTags) do
 
s = s .. tag .. "<br>"
 
s = s .. tag .. "<br>"
 
end
 
end
Line 487: Line 505:
 
end
 
end
 
 
if item['cookingEnchantment'] then
+
if item.cookingEnchantment then
 
args[l()] = "Buff"
 
args[l()] = "Buff"
args[d()] = getEnchantmentName(item['cookingEnchantment'])
+
args[d()] = getEnchantmentName(item.cookingEnchantment)
 
end
 
end
 
 
 
args[h()] = "Seeds"
 
args[h()] = "Seeds"
 
 
local farming = item['farmingStats']
+
-- local farming = item.farmingStats
if farming then
+
-- if farming then
s = ""
+
-- s = ""
for key, yield in pairs(farming['yield']) do
+
-- for key, yield in pairs(farming.yield) do
s = s .. yield['min'] .. "-" .. yield['max'] .. " "
+
-- s = s .. yield.min .. "-" .. yield.max .. " "
s = s .. itemImage(yield['id'], true)
+
-- s = s .. itemImage(yield.id, true)
if yield['chance'] ~= 1 then
+
-- if yield.chance ~= 1 then
s = s .. " " .. tonumber(string.format('%.2f', yield['chance'] * 100)) .. "%"
+
-- s = s .. " " .. tonumber(string.format('%.2f', yield.chance * 100)) .. "%"
end
+
-- end
s = s .. "<br>"
+
-- s = s .. "<br>"
end
+
-- end
s = s:sub(1,s:len()-4)
+
-- s = s:sub(1,s:len()-4)
args[l()] = "Level Required"
+
-- args[l()] = "Level Required"
args[d()] = farming['requiredLevel']
+
-- args[d()] = farming.requiredLevel
args[l()] = "Experience"
+
-- args[l()] = "Experience"
args[d()] = farming['experience']
+
-- args[d()] = addSeparator(farming.experience)
args[l()] = "Plot Size"
+
-- args[l()] = "Plot Size"
args[d()] = farming['height'] .. "x" .. farming['width']
+
-- args[d()] = farming.height .. "x" .. farming.width
args[l()] = "Harvest Time"
+
-- args[l()] = "Harvest Time"
args[d()] = farming['time'] .. " minutes"
+
-- args[d()] = farming.time .. " minutes"
args[l()] = "Yield"
+
-- args[l()] = "Yield"
args[d()] = s
+
-- args[d()] = s
end
+
-- end
 
 
 
local args2 = {}
 
local args2 = {}
 
 
args2['subbox'] = "yes"
+
args2.subbox = "yes"
args2['bodystyle'] = "padding: 0.5em; margin:auto; font-style:italic; font-size:110%; text-align: center"
+
args2.bodystyle = "padding: 0.5em; margin:auto; font-style:italic; font-size:110%; text-align: center"
args2['data1'] = item['extraTooltipInfo']
+
args2.data1 = item.extraTooltipInfo
 
args[h()] = "Tooltip"
 
args[h()] = "Tooltip"
args[d()] = require('Module:Infobox')['infobox'](args2)
+
args[d()] = require('Module:Infobox').infobox(args2)
 
 
 
for key, data in pairs(args) do
 
for key, data in pairs(args) do
Line 532: Line 550:
 
end
 
end
 
 
return require('Module:Infobox')['infobox'](args)
+
return require('Module:Infobox').infobox(args)
 
end
 
end
  

Latest revision as of 20:31, 27 May 2024


local p = {}

local data_module_names = {
	item = 'Module:Items/data',
	enchantment = 'Module:Enchantment/data',
	location = 'Module:Location/data',
	craftaug = 'Module:CraftingAugmenting/data'
}

local loaded_data_modules = {}

local headerCount = 1
local labelCount = 1
local dataCount = 1

local function h()
	local s = "header" .. headerCount
	headerCount = headerCount + 1
	labelCount = headerCount
	dataCount = headerCount
	return s
end

local function sbreak()
	local s = "sbreak" .. headerCount
	headerCount = headerCount + 1
	labelCount = headerCount
	dataCount = headerCount
	return s
end

local function l()
	local s = "label" .. labelCount
	dataCount = labelCount
	labelCount = labelCount + 1
	headerCount = labelCount
	return s
end

local function d() 
	local s = "data" .. dataCount
	dataCount = dataCount + 1
	headerCount = dataCount
	labelCount = dataCount
	return s
end

local function sl()
	local s = "s" .. l{}
	return s
end

local function sd()
	local s = "s" .. d{}
	return s
end

function p.loadData(data_type) 
	local module_name = data_module_names[data_type]
	if loaded_data_modules[module_name] == nil then
		loaded_data_modules[module_name] = mw.loadData(module_name)
	end
		
	return loaded_data_modules[module_name]
end

local function findItem(name)
	local lname = name:lower()
	
	 --Remove leading and trailing spaces.
	lname = lname:gsub('^%s*(.-)%s*$', '%1')
	for key, item in pairs(p.loadData("item")) do
		if lname == item.name:lower() then
			return item
		end
	end
	return 0
end

local function getItem(id)
	return p.loadData("item")[tostring(id)]
end

local function getEnchantmentName(id)
	return p.loadData("enchantment")[tostring(id)].name
end

local function getItemName(id)
	return p.loadData("item")[tostring(id)].name
end

local function getCraftAug(id)
	return p.loadData("craftaug")[tostring(id)]
end

local function fullUrl(url)
	local newUrl = url
	if url:sub(1,5) == "https" then
		return newUrl
	end
	
	if url:sub(1,1) ~= "/" then
		newUrl = "/" .. newUrl
	end
	
	newUrl = "https://www.play.idlescape.com" .. newUrl
	return newUrl
end

local function icon(name, url, word)
	local s = fullUrl(url)
	s = "[[" .. name .. "|<img src=\"" .. s
	s = s .. "\" alt=\""  .. name .. "\" width=\"20\">"
	if word then
		s = s .. name
	end
	s = s .. "]]"
	return s
end

local function itemImage(id, word)
	local item = p.loadData("item")[tostring(id)]
	local url = ""
	if item.itemIcon then
		url = item.itemIcon
	else
		url = item.itemImage
	end
	return icon(item.name, url, word)
end

local function locationImage(id, word)
	local loc = p.loadData("location")[tostring(id)]
	local url = ""
	if loc.locationImage then
		url = loc.locationImage
	else
		return "[[" .. loc.name .. "]]"
	end
	return icon(loc.name, url, word)
end

local function img(id)
	local url = ""
	if item.itemIcon then
		url = item.itemIcon
	else
		url = item.itemImage
	end
	return fullUrl(url)
end

local function addSeparator(num)
	return tostring(tonumber(num)):reverse():gsub("(%d%d%d)","%1,"):gsub(",(%-?)$","%1"):reverse()
end

local function gatheringSource(id)
	local s = ""
	for key, loc in pairs(p.loadData('location')) do
		if loc.loot then
			for key2, loot in pairs(loc.loot) do
				if id == loot.id then
					s = s .. locationImage(loc.locID, true)
					s = s .. "<br>"
				end
			end
		end
	end
	return s
end

-- local function farmingSource(id)
-- 	local s = ""
	
-- 	for key, item in pairs(p.loadData('item')) do
-- 		if item.farmingStats then
-- 			for key2, yield in pairs(item.farmingStats.yield) do
-- 				if id == yield.id then
-- 					s = s .. itemImage(item.id, true)
-- 					s = s .. "<br>"
-- 				end
-- 			end
-- 		end
-- 	end
-- 	return s
-- end

local function smithingSource(id)
	local s = ""
	local item = getItem(id)
	if item.skill == "smithing" and item.name ~= 'Ichor' then
		s = '[[Smithing]]<br>'
	end
	return s
end

local function cookingSource(id)
	local s = ""
	local item = getItem(id)
	if (item.class == "cooking-ingredient" and not item.ingredientTags) or item.class == 'cookedFish' or item.name=='Ashes' then
		s = '[[Cooking]]<br>'
	end
	return s
end

local function runecraftingSource(id)
	local s = ""
	local item = getItem(id)
	if item.class == "cloth" or (item.class == 'rune' and item.requiredResources) then
		s = '[[Runecrafting]]<br>'
	end
	return s
end

local function scrollcraftingSource(id)
	local s = ""
	local item = getItem(id)
	if item.class == "enchanted-scroll" and item.level < 100 then
		s = '[[Scrollcrafting]]<br>'
	end
	return s
end


local function craftingSource(id)
	local s = ""
	local item = getItem(id)
	if item.craftable then
		s = '[[Crafting]]<br>'
	end
	return s
end

local function findSource(id)
	local s = ""
	s = s .. gatheringSource(id)
	-- s = s .. farmingSource(id)
	s = s .. scrollcraftingSource(id)
	s = s .. runecraftingSource(id)
	s = s .. smithingSource(id)
	s = s .. craftingSource(id)
	s = s .. cookingSource(id)
	if s:len() > 4 then 
		s = s:sub(1,s:len()-4)
	end
	return s	
end

local function createInfobox(item)
	local args = {}	
	local url = ""
	local s = ""
	args.autoheaders = "y"
	args.subbox = "no"
	args.bodystyle = " "
	args.title = item.name
	
	if item.itemIcon then
		url = item.itemIcon
	else
		url = item.itemImage
	end
	args.image = "<img src=\"" .. fullUrl(url) .. "\" width=\"150\">"
	
	if item.value then
		args[l()] = icon('Gold', "/images/gold_coin.png")
		args[d()] = addSeparator(item.value)
	end
	
	if item.tradeable then
		args[l()] = icon('Market', "/images/ui/marketplace_icon.png")
		local market = require("Module:Market")["_price"]({item.name, 1, 1})
		if market then
			args[d()] = addSeparator(market)
		else
			args[d()] = "Yes"
		end
	end
	
	if item.requiredLevel then
		s = ""
		for skill, level in pairs(item.requiredLevel) do
			s = s .. level .. " " .. skill .. "<br>"
		end
		s = s:sub(1,s:len()-4)
		args[l()] = "Level Required"
		args[d()] = s
	end
	
	args[l()] = "Source"
	args[d()] = findSource(item.id)
	
	if item.heat then
		args[l()] = itemImage(2)
		args[d()] = addSeparator(item.heat)
	end
	
	local stats = item.equipmentStats
	if stats then
		args[l()] = "Slot"
		args[d()] = stats.slot
		
		if item.enchantmentTier then
			args[l()] = "Enchantment Slots"
			args[d()] = item.enchantmentTier
		end
		
		if item.forcedEnchant then
			args[l()] = "Enchantments"
			args[d()] = "[[" .. getEnchantmentName(item.forcedEnchant) .. "]]"
		end
		
		if stats.toolBoost then
			s = ""
			for key, stat in pairs(stats.toolBoost) do
				s = s .. stat.boost .. " "
				s = s .. stat.skill .. "<br>"
			end
			s = s:sub(1,s:len()-4)
			args[l()] = "Stats"
			args[d()] = s
		end
		
		if stats.oneHanded == false then
			args[l()] = "Two-handed"
			args[d()] = "Yes"
		end
		
		if stats.attackSpeed then
			args[l()] = "Attack Speed"
			args[d()] = stats.attackSpeed
		end
		
		
		args[h()] = "Offensive Stats"
		
		local stat = stats.offensiveCritical
		if stat then
			args[l()] = "Crit Chance"
			args[d()] = stat.chance
			args[l()] = "Crit Multiplier"
			args[d()] = stat.damageMultiplier
		end
		
		stat = stats.weaponBonus
		if stat then
			args[sl()] = "Str"
			args[sd()] = stat.strength
			args[sl()] = "Int"
			args[sd()] = stat.intellect
			args[sl()] = "Dex"
			args[sd()] = stat.dexterity
		end
		
		args[h()] = "Offensive Affinity"
		stat = stats.offensiveDamageAffinity
		if stat then
			args[sl()] = "Melee"
			args[sd()] = stat.Melee and stat.Melee * 100 .. "%"
			args[sl()] = "Magic"
			args[sd()] = stat.Magic and stat.Magic * 100 .. "%"
			args[sl()] = "Range"
			args[sd()] = stat.Range and stat.Range * 100 .. "%"
			args[sbreak()] = "yes"
			
			args[sl()] = "Piercing"
			args[sd()] = stat.Piercing and stat.Piercing * 100 .. "%"
			args[sl()] = "Blunt"
			args[sd()] = stat.Blunt and stat.Blunt * 100 .. "%"
			args[sl()] = "Slashing"
			args[sd()] = stat.Slashing and stat.Slashing * 100 .. "%"			
			args[sl()] = "Fire"
			args[sd()] = stat.Fire and stat.Fire * 100 .. "%"
			args[sl()] = "Ice"
			args[sd()] = stat.Ice and stat.Ice * 100 .. "%"
			args[sl()] = "Nature"
			args[sd()] = stat.Nature and stat.Nature * 100 .. "%"
			args[sl()] = "Chaos"
			args[sd()] = stat.Chaos and stat.Chaos * 100 .. "%"
			args[sbreak()] = "yes"
		end
		
		args[h()] = "Accuracy"
		stat = stats.offensiveAccuracyAffinityRating
		if stat then
			args[sl()] = "Melee"
			args[sd()] = stat.Melee
			args[sl()] = "Magic"
			args[sd()] = stat.Magic
			args[sl()] = "Range"
			args[sd()] = stat.Range
			args[sbreak()] = "yes"
			
			args[sl()] = "Piercing"
			args[sd()] = stat.Piercing
			args[sl()] = "Blunt"
			args[sd()] = stat.Blunt
			args[sl()] = "Slashing"
			args[sd()] = stat.Slashing			
			args[sl()] = "Fire"
			args[sd()] = stat.Fire
			args[sl()] = "Ice"
			args[sd()] = stat.Ice
			args[sl()] = "Nature"
			args[sd()] = stat.Nature
			args[sl()] = "Chaos"
			args[sd()] = stat.Chaos
			args[sbreak()] = "yes"
		end
		
		args[h()] = "Defensive Stats"
		
		local stat = stats.defensiveCritical
		if stat then
			args[l()] = "Crit Avoidance"
			args[d()] = stat.chance
			args[l()] = "Crit Reduction"
			args[d()] = stat.damageMultiplier
		end
		
		stat = stats.armorBonus
		if stat then
			args[sl()] = "Protection"
			args[sd()] = stat.protection
			args[sl()] = "Resistance"
			args[sd()] = stat.resistance
			args[sl()] = "Agility"
			args[sd()] = stat.agility
			args[sl()] = "Stamina"
			args[sd()] = stat.stamina
		end
		
		args[h()] = "Defensive Affinity"
		stat = stats.defensiveDamageAffinity
		if stat then
			args[sl()] = "Melee"
			args[sd()] = stat.Melee and stat.Melee * 100 .. "%"
			args[sl()] = "Magic"
			args[sd()] = stat.Magic and stat.Magic * 100 .. "%"
			args[sl()] = "Range"
			args[sd()] = stat.Range and stat.Range * 100 .. "%"
			args[sbreak()] = "yes"
			
			args[sl()] = "Piercing"
			args[sd()] = stat.Piercing and stat.Piercing * 100 .. "%"
			args[sl()] = "Blunt"
			args[sd()] = stat.Blunt and stat.Blunt * 100 .. "%"
			args[sl()] = "Slashing"
			args[sd()] = stat.Slashing and stat.Slashing * 100 .. "%"			
			args[sl()] = "Fire"
			args[sd()] = stat.Fire and stat.Fire * 100 .. "%"
			args[sl()] = "Ice"
			args[sd()] = stat.Ice and stat.Ice * 100 .. "%"
			args[sl()] = "Nature"
			args[sd()] = stat.Nature and stat.Nature * 100 .. "%"
			args[sl()] = "Chaos"
			args[sd()] = stat.Chaos and stat.Chaos * 100 .. "%"
			args[sbreak()] = "yes"
		end
	end
	
	args[h()] = "Augment"
	local craftAug = getCraftAug(item.id)
		
	if craftAug and craftAug.augmenting then
		s = ""
		for key, bonus in pairs(item.equipmentStats.augmentationBonus) do
			s = s .. "+" .. bonus.value .. " "
			s = s .. bonus.stat:sub(bonus.stat:find('%.')+1,bonus.stat:len()) .. "<br>"
		end
		s = s:sub(1,s:len()-4)
		args[sl()] = "Aug Bonus"
		args[sd()] = s
		
		s = ""
		for key, cost in pairs(craftAug.augmenting) do
			s = s .. cost .. " "
			s = s .. itemImage(key, true) .. "<br>"
		end
		s = s:sub(1,s:len()-4)
		args[sl()] = "Aug Cost"
		args[sd()] = s
	end
	
	args[h()] = "Cooking"
	
	if item.size then
		args[l()] = "Size"
		args[d()] = item.size
	end
	
	if item.difficulty then
		args[l()] = "Difficulty"
		args[d()] = item.difficulty
	end
	
	if item.ingredientTags then
		s = ""
		for key, tag in pairs(item.ingredientTags) do
			s = s .. tag .. "<br>"
		end
		s = s:sub(1,s:len()-4)
		args[l()] = "Category"
		args[d()] = s
	end	
	
	if item.cookingEnchantment then
		args[l()] = "Buff"
		args[d()] = getEnchantmentName(item.cookingEnchantment)
	end
	
	args[h()] = "Seeds"
	
	-- local farming = item.farmingStats
	-- if farming then
	-- 	s = ""
	-- 	for key, yield in pairs(farming.yield) do
	-- 		s = s .. yield.min .. "-" .. yield.max .. " "
	-- 		s = s .. itemImage(yield.id, true)
	-- 		if yield.chance ~= 1 then
	-- 			s = s .. " " .. tonumber(string.format('%.2f', yield.chance * 100)) .. "%"
	-- 		end
	-- 		s = s .. "<br>"
	-- 	end
	-- 	s = s:sub(1,s:len()-4)
	-- 	args[l()] = "Level Required"
	-- 	args[d()] = farming.requiredLevel
	-- 	args[l()] = "Experience"
	-- 	args[d()] = addSeparator(farming.experience)
	-- 	args[l()] = "Plot Size"
	-- 	args[d()] = farming.height .. "x" .. farming.width
	-- 	args[l()] = "Harvest Time"
	-- 	args[d()] = farming.time .. " minutes"
	-- 	args[l()] = "Yield"
	-- 	args[d()] = s
	-- end
	
	local args2 = {}
	
	args2.subbox = "yes"
	args2.bodystyle = "padding: 0.5em; margin:auto; font-style:italic; font-size:110%; text-align: center"
	args2.data1 = item.extraTooltipInfo
	args[h()] = "Tooltip"
	args[d()] = require('Module:Infobox').infobox(args2)
	
	for key, data in pairs(args) do
		if string.find(key, "data") then
			args[key] = tostring(data)
		end
	end
	
	return require('Module:Infobox').infobox(args)
end

function p.item(frame)
	local args = frame:getParent().args
	return p._item(args)
end

function p._item(args)
	local name = ""
	local item = 0
	local infobox = ""
	
	if args[1] then
		name = args[1]
	else
		name = mw.title.getCurrentTitle().text
	end
	
	item = findItem(name)
		
	if item == 0 then
		return "<div style=\"color:red\"> No item named '" .. name .. "'</div>. The Module:Items/data maybe outdated."
	end
	
	infobox = createInfobox(item)
	return infobox
end

return p