Module:Equipinfo

local trim = mw.text.trim local cargo = mw.ext.cargo

local currentFrame local args_table local lang local l10n_table

local l10n = function(key, args) return currentFrame:expandTemplate{ title = 'lang', args = { 'getEquipInfo', key, args } } end

local getArg = function(key) local value = args_table[key] if not value then return nil end value = trim(value) if value == '' then return nil end return value end

-- credit: http://richard.warburton.it -- this version is with trim. local function explode(div,str) if (div=='') then return false end local pos,arr = 0,{} -- for each divider found for st,sp in function return string.find(str,div,pos,true) end do		arr[#arr + 1] = trim(string.sub(str,pos,st-1)) -- Attach chars left of current divider pos = sp + 1 -- Jump past current divider end arr[#arr + 1] = trim(string.sub(str,pos)) -- Attach chars right of last divider return arr end

local function round(x, dec) local factor = 10^(dec or 0) return math.floor(x * factor + 0.5) / factor end

local function statList return 'ccdryLight, cciceBarrier, ccwetLight, accCalendar, accCompass, accCritterGuide, accDepthMeter, accDivingHelm, accDreamCatcher, accFishFinder, accFishingLine, accFlipper, accJarOfSouls, accLavaFishing, accMerman, accOreFinder, accRunSpeed, accStopwatch, accTackleBox, accThirdEye, accWatch, accWeatherRadio, aggro, ammoCost75, ammoCost80, arcticDivingGear, armorPenetration, arrowDamage, autoActuator, autoJump, autoPaint, autoReuseGlove, blackBelt, blockRange, boneGlove, brainOfConfusion, buffImmune, bulletDamage, canFloatInWater, CanSeeInvisibleBlocks, carpet, chloroAmmoCost80, cordage, counterWeight, dashType, dd2Accessory, desertBoots, discount, empressBrooch, endurance, equippedAnyTileRangeAcc, equippedAnyTileSpeedAcc, equippedAnyWallSpeedAcc, extraFall, fireWalk, fishingSkill, flowerBoots, frogLegJumpBoost, goldRing, gravControl2, hasCreditsSceneMusicBox, hasJumpOption_Blizzard, hasJumpOption_Cloud, hasJumpOption_Fart, hasJumpOption_Sail, hasJumpOption_Sandstorm, hasLuckyCoin, hasMoltenQuiver, hasPaladinShield, huntressAmmoCost90, iceSkate, InfoAccMechShowWires, jumpBoost, jumpSpeedBoost, kbGlove, killClothier, killGuide, lavaMax, lavaRose, lifeRegen, longInvince, magicCrit, magicCuffs, magicDamage, magicQuiver, magmaStone, manaCost, manaFlower, manaMagnet, manaRegenBonus, manaRegenDelayBonus, maxMinions, maxTurrets, meleeCrit, meleeDamage, meleeScaleGlove, meleeSpeed, minionDamage, minionKB, moonLordLegs, moveSpeed, nightVision, noFallDmg, noKnockback, npcTypeNoAggro, panic, pickSpeed, pStone, rangedCrit, rangedDamage, releaseBeesWhenHurt, rocketBoots, rocketDamage, rulerGrid, rulerLine, scope, shinyStone, skyStoneEffects, slowFall, spikedBoots, sporeSac, starCloak, starCloakIsBeeCloak, starCloakIsManaCloak, starCloakIsStarVeil, statManaMax2, strongBees, tileRangeX, tileRangeY, treasureMagnet, volatileGelatin, waterWalk, waterWalk2, wolfAcc, yoyoGlove, yoyoString' --	currentFrame:expandTemplate{ title = 'getEquipInfo/db', args = {} }	return currentFrame:callParserFunction{ name = ' end

local function formatStat(statvalues, stat) -- format stat, for l10n key local statFormatted = '' if stat == 'accWatch' or stat == 'dashType' or stat == 'rocketBoots' then statFormatted = 'stat_' .. stat .. '-' .. value elseif statvalues['allDamage'] ~= nil and (stat == 'magicDamage' or stat == 'meleeDamage' or stat == 'minionDamage' or stat == 'rangedDamage') then --		--><!--			else statFormatted = 'stat_' .. stat end -- format value local value = statvalues[stat] if value == nil then return { statFormatted = statFormatted, valueFormatted = { 'foo' } } end local valueFormatted = {} if stat == 'accRunSpeed' then -- pixels/tick → tiles/sec local tps = round(value * 3.75, 2) valueFormatted = { tps, currentFrame:expandTemplate{ title = 'mph', args = { tps, 'tiles'} } } elseif stat == 'buffImmune' then -- buff id → name local valueList = explode(value, '¤') local vF1 = '' for _, buffname in ipairs(valueList) do vF1 = vF1 .. currentFrame:expandTemplate{ title = 'exclusive icon link', args = { currentFrame:expandTemplate{ title = 'buffNameFromId', args = { buffname, lang='en' } } } } end valueFormatted = { vF1, #valueList } elseif stat == 'counterWeight' then -- projectile id → name local valueList = explode(value, '¤') local vF1 = '' for _, projectileName in ipairs(valueList) do vF1 = vF1 .. currentFrame:expandTemplate{ title = 'exclusive icon link', args = { currentFrame:expandTemplate{ title = 'projectileNameFromId', args = { projectilename, lang='en' } } } } end valueFormatted = { vF1, #valueList } elseif stat == 'desertBoots' then -- pixels/tick → tiles/sec local tps = round(statvalues['accRunSpeed'] * 1.75 * 3.75, 2) valueFormatted = { tps, currentFrame:expandTemplate{ title = 'mph', args = { tps, 'tiles'} } } elseif stat == 'lavaMax' then -- ticks → valueFormatted = { currentFrame:expandTemplate{ title = 'duration', args = { value/60 } } } elseif stat == 'lifeRegen' then -- half valueFormatted = value/2 elseif stat == 'magicDamage' or stat == 'meleeDamage' or stat == 'minionDamage' or stat == 'rangedDamage' or stat == 'arrowDamage' or stat == 'bulletDamage' or stat == 'rocketDamage' or stat == 'meleeSpeed' or stat == 'moveSpeed' or stat == 'pickSpeed' or stat == 'manaCost' or stat == 'endurance' then -- decimal → valueFormatted = { currentFrame:expandTemplate{ title = 'percent', args = { round(value*100, 2) .. '%' } } }	elseif stat == 'magicCrit' or stat == 'meleeCrit' or stat == 'rangedCrit' or stat == 'fishingSkill' then -- 		valueFormatted = { currentFrame:expandTemplate{ title = 'percent', args = { value .. '%' } } }	elseif stat == 'npcTypeNoAggro' then -- npc id → name local valueList = explode(value, '¤') local vF1 = '' for _, npcName in ipairs(valueList) do vF1 = vF1 .. currentFrame:expandTemplate{ title = 'exclusive icon link', args = { currentFrame:expandTemplate{ title = 'npcNameFromId', args = { npcName, lang='en' } } } } end valueFormatted = { vF1, #valueList } else -- no format valueFormatted = { value } end return { statFormatted = statFormatted, valueFormatted = valueFormatted } end

local function formatSingleStat(statvalues, stat) formatted = formatStat(statvalues, stat) return formatted['valueFormatted'][1] end

- -- main return object return {

go = function(frame) -- init cache currentFrame = frame args_table = frame.args lang = getArg('lang') or 'en'

local queryStat = getArg('queryStat') local queryItemId = getArg('queryItemId') local outputMode = getArg('outputMode') local statList = statList local result = cargo.query('Equipinfo', statList, { where = 'itemid IN (' .. queryItemId .. ')' } )	if result == nil then return end local statvalues = {} for _, row in ipairs(result) do		for stat, value in pairs(row) do			if value ~= '' then if statvalues[stat] ~= nil then statvalues[stat] = statvalues[stat] + value else statvalues[stat] = value end end end end -- pre-process local allDamageSet = statvalues['magicDamage'] ~= nil and statvalues['meleeDamage'] ~= nil and statvalues['minionDamage'] ~= nil and statvalues['rangedDamage'] ~= nil if allDamageSet and statvalues['magicDamage'] == statvalues['meleeDamage'] and statvalues['meleeDamage'] == statvalues['minionDamage'] and statvalues['minionDamage'] == statvalues['rangedDamage'] then statvalues['allDamage'] = statvalues['magicDamage'] end local allCritSet = statvalues['magicCrit'] ~= nil and statvalues['meleeCrit'] ~= nil and statvalues['rangedCrit'] ~= nil if allCritSet and statvalues['magicCrit'] == statvalues['meleeCrit'] and statvalues['meleeCrit'] == statvalues['rangedCrit'] then statvalues['allDamage'] = statvalues['magicCrit'] end if statvalues['equippedAnyTileRangeAcc'] then if statvalues['tileRangeX'] ~= nil then statvalues['tileRangeX'] = statvalues['tileRangeX'] + 3 else statvalues['tileRangeX'] = 3 end if statvalues['tileRangeY'] ~= nil then statvalues['tileRangeY'] = statvalues['tileRangeY'] + 2 else statvalues['tileRangeY'] = 2 end end if outputMode == 'raw' then return statvalues[queryStat] elseif outputMode == 'singlestat' then return formatSingleStat(statvalues, queryStat) elseif outputMode == 'listraw' then local str = '' for stat, value in pairs(statvalues) do str = str .. stat .. ':' .. value .. ';'		end return str elseif outputMode == 'list' then return formatStatList(statvalues) -- end end, }