Module:Weapon

-- Get other Required Modules local p = {} local getArgs = require('Module:Arguments').getArgs local loader = require('Module:Loader')

local string, table, yesno, statname, currency, mr, mainonly, color, makeStatsList = loader.require('String', 'Table', 'Yesno', 'Statname', 'Currency', 'RarityTier', 'Mainonly', 'Color', 'Armor/StatsList') local makeStat = statname._getStatName local makeRarity, makeRarityLink = mr._getTier, mr._link

local weaponData, weaponAliases, statData, statAliases = loader.loadData('Weapon/Data', 'Weapon/Aliases', 'Statname/Data', 'Statname/Aliases')

- -- Template:GetWeaponInfo -- -- Gets Input from the Template - function p.getWeaponInfo( frame ) local args = getArgs( frame ) local weapon = string.lower(args[1] or (mainonly.on_main and mw.title.getCurrentTitle.text)) local a = string.lower(args[2]) return mw.getCurrentFrame:preprocess(p._getWeaponInfo( weapon, a )) end

function p._getWeaponInfo( weaponName, a ) local weapon = weaponData[weaponName] if not weapon or not weaponName then return '' end -- Local Parameters local ia = weapon.itemAbility or weapon.ia or {} local specialEffect = weapon.specialEffect local source = weapon.source local weapontype = weapon.weapontype local rarity = weapon.rarity local function all return table.concat{ specialEffect and ' '..specialEffect or '', ia.iaName and ' ' or '', ia.iaDesc or '', ia.iaCost and ' ' or '', ia.iaCooldown and ' ' or '', ia.iaCooldownAlt and ' '..ia.iaCooldownAlt or '', }	end --Get the Weapon Info local query = weaponAliases.query[a:lower] or a:lower mw.log(query) local outputInfo = query and (			query == 'rarity' and rarity or			query == 'specialEffect' and specialEffect or			query == 'weapontype' and weapontype or			query == 'source' and source or			query == 'all' and all or			ia[query] or 		) or  return outputInfo or '' end

- -- Template:GetWeaponStat -- -- Get Inputs from the Template - function p.getWeaponStat( frame ) local args = getArgs( frame ) local weapon = string.lower(args[1]) or mw.title.getCurrentTitle.text local stat = string.lower(args[2]) return p._getWeaponStat( weapon, stat ) end

function p._getWeaponStat( weaponName, stat ) local weapon = weaponData[weaponName] --Error Function if not weapon or not weaponName then return ' Template Error: Bad Argument to #1 "'..weaponName..'" ' end local stats = weapon.stats --Get Stats from Data Module --Damage outputStat = statname._getstatdata(stat, true) or string.error('Stat requested is unknown %q', stat) outputStat = stats[outputStat.shortcode] or 0 --Return the Stat return outputStat end

- -- Template:WeaponInfo -- -- Get Inputs from the Template - function p._weaponStatsTable(frame) --local parameters = frame.args local args = getArgs(frame) local weapon = args[1] or args["weapon"] or args["w"] or mw.title.getCurrentTitle.text return mw.getCurrentFrame:preprocess(p.weaponStatsTable(weapon)) end

function p.weaponStatsTable(weaponName) local weapon = weaponData[weaponName:lower] local stats, specialEffect, weaponType, rarity, ia = weapon.stats, weapon.specialEffect, weapon.type, weapon.rarity, weapon.ia	local wikitable = mw.html.create('table') :addClass('article-table') :css({ ["max-width"]="50%" }) :tag("tr") :tag("th") :wikitext(					string.centerText({ 'Weapon Stats', string.wrapHtml{ {								string.makeLink('Module:Weapon/Data', 'v'), ' &bull; ', string.fullUrl('Module:Weapon/Data', { action="edit" }, 'e'), },							' ', {								style={ ["float"]="right"; ["color"]="white"; ["font-size"]="75%"; },							},						},					})				)			:done :done :tag('tr') :tag('td') :wikitext(makeRarityLink(rarity, weaponName)) :wikitext(makeStatsList(stats)) :wikitext('Weapon Rarity: ') :wikitext(makeRarityLink(rarity)) :wikitext(' ', 'Weapon Type: ', string.makeLink(weaponType, { , weaponType,  })) :done :done if specialEffect then wikitable :tag('tr') :tag('th') :wikitext('Weapon Special Effect') :done :done :tag('tr') :tag('td') :wikitext(specialEffect) :done :done end if ia then wikitable :tag('tr') :tag('th') :wikitext('Weapon Item Ability') :done :done :tag('tr') :tag('td') :wikitext('') :wikitext(' ', (ia.desc:gsub('\n', ' '))) :done :done if ia.cost or ia.cooldown or ia.cooldownAlt then wikitable :tag('tr') :tag('td') :wikitext(							(not ia.cooldownAlt and ia.cooldown) and color.makeColor('dark gray', 'Cooldown: ') or ia.cooldownAlt or , 							(not ia.cooldownAlt and ia.cooldown) and color.makeColor('yellow', ia.cooldown) or ,							(ia.cooldownAlt or ia.cooldown) and ' ' or ,							ia.cost and color.makeColor('dark gray', 'Mana Cost: ') or ,							ia.cost and makeStat('mana', tostring(ia.cost)) or ''						) :done :done end end --Return the Table return tostring(wikitable:done) end

function p.weaponPrice(frame) -- unimplemented return 0 end

function p.calcMidasSwordDamage(frame) local args = getArgs( frame ) local price_paid = tonumber(args[1] or 0) return p._calcMidasSwordDamage(price_paid) end function p._calcMidasSwordDamage(price_paid) if price_paid >= 50000000 then return 120 end local dmg = 0 if price_paid >= 0 then dmg = dmg + math.floor((math.min(price_paid,1000000)-0)/50000) end if price_paid >= 1000000 then dmg = dmg + math.floor((math.min(price_paid,2500000)-1000000)/100000) end if price_paid >= 2500000 then dmg = dmg + math.floor((math.min(price_paid,7500000)-2500000)/200000) end if price_paid >= 7500000 then dmg = dmg + math.floor((math.min(price_paid,25000000)-7500000)/500000) end if price_paid >= 25000000 then dmg = dmg + math.floor((math.min(price_paid,50000000)-25000000)/1000000) end return dmg end

-- Finish Module -- return p