Module:Weapon

local getArgs = require("Module:Arguments").getArgs local title = mw.title.getCurrentTitle local lang = mw.getContentLanguage local p = {}

-- TODO: Load auto-abilities data. local data = { ["ability chain"] = {"green", "Ability Chain+%d%%", "Using abilities in succession raises damage by %d%%."}, ["ability salvo"] = {"blue", "Ability Salvo+%d%%", "The more times you use abilities in a row, the greater the attack power, Magic, and Break power of your next attack."}, ["armor break"] = {"blue", "Armor Break+%d%%", "Ability to turn Break gauge red increased by %d%%."}, ["attack up"] = {"yellow", "Attack Up+%d%%", "Increases Attack by %d%%."}, ["attuned chain"] = {"green", "Attuned Chain+%d%%", "Using abilities of the same element in succession raises damage by %d%%."}, ["auto-charge ultimate"] = {"blue", "Auto-Charge Ultimate+%d", "Charges the Ultimate gauge by %d every turn."}, ["boost ultimate"] = {"blue", "Boost Ultimate+%d", "Increases Ultimate level by %d."}, ["break power up"] = {"yellow", "Break Power Up+%d%%", "Increases Break Power by %d%%"}, ["cross-counter"] = {"blue", "Cross-Counter(Up to %d%%)", "Increases damage and Break power the more enemies have previously acted immediately before your action."}, ["crystal seeker"] = {"blue", "Crystal Seeker+%d", "Increases the drop rate of crystals from battle"}, ["dark draw"] = {"blue", "Dark Draw+%d", "Increases chance of drawing dark orbs."}, ["earth draw"] = {"blue", "Earth Draw+%d", "Increases chance of drawing earth orbs."}, ["element generator"] = {"blue", "Element Generator+%d", "Start turn with %d orbs drawn."}, ["elemental third strike"] = {"blue", "Elemental Third Strike+%d", "Increases number of orbs drawn by the third normal attack by %d."}, ["enhance light"] = {"green", "Enhance Light+%d%%", "Enhances light abilities by %d%%."}, ["enhance water"] = {"green", "Enhance Water+%d%%", "Enhances water abilities by %d%%."}, ["enhanced heal drive"] = {"blue", "Enhanced Heal Drive+%d%%", "Element Drives using life orbs restore %d%% more HP."}, ["exp up"] = {"blue", "EXP Up+%d%%", "Increases EXP gained after battle by %d%%."}, ["exploit weakness"] = {"green", "Exploit Weakness+%d%%", "Increases damage by %d%% when using weakness element."}, ["extended break"] = {"blue", "Extended Break+%d", "Increases number of actions during Break by %d."}, ["fire draw"] = {"blue", "Fire Draw+%d", "Increases chance of drawing fire orbs."}, ["flash break"] = {"blue", "Flash Break+%d%%", "Break power increased by %d%% against enemies with full Break gauges."}, ["gil up"] = {"blue", "Gil Up+%d%%", "Increases Gil gained after battle by %d%%."}, ["healing victory"] = {"blue", "Healing Victory+%d%%", "Restores %d%% HP after winning a battle."}, ["hp up"] = {"yellow", "HP Up+%d%%", "Increases HP by %d%%."}, ["improved criticals"] = {"green", "Improved Criticals+%d%%", "Increases critical strike damage by %d%%."}, ["improved extra skill unlock"] = {"blue", "Improved Extra Skill Unlock+%d", "Slightly improves the chance to unlock extra skills."}, ["job change recast"] = {"blue", "Job Change Recast", "Lowers your Job Change recast by a turn."}, ["kill & draw"] = {"blue", "Kill & Draw+%d", "Defeating an enemy draws %d element orb(s)."}, ["life draw"] = {"blue", "Life Draw+%d", "Increases chance of drawing life orbs."}, ["light draw"] = {"blue", "Light Draw+%d", "Increases chance of drawing light orbs."}, ["medic"] = {"blue", "Medic+%d%%", "Regenerates %d%% of HP with every action."}, ["overpower"] = {"yellow", "Overpower(Up to %d%%)", "Attack, Magic and Break power increased up to %d%% based on your job level."}, ["painful break"] = {"green", "Painful Break+%d%%", "Increases damage dealt during Break by %d%%."}, ["piercing break"] = {"yellow", "Piercing Break+%d%%", "Increases damage to red Break Gauges by %d%%."}, ["prismatic draw"] = {"blue", "Prismatic Draw+%d%%", "Normal attacks have a %d%% chance to draw prismatic orbs."}, ["prismatic element generator"] = {"blue", "Prismatic Element Generator+%d", "Start turn with %d prismatic orb drawn."}, ["prismatic element starter"] = {"blue", "Prismatic Element Starter+%d", "Start battle with %d prismatic orbs drawn."}, ["prismatic return"] = {"blue", "Prismatic Return+%d%%", "Has a %d%% chance to restore spent orbs as prismatic orbs."}, ["ravage"] = {"blue", "Ravage+%d%%", "Increases damage of cone and area attacks by %d%%."}, ["reunion"] = {"blue", "Reunion+%d%%", "Restores a used orb as a prismatic orb %d%% of the time."}, ["skillseed up"] = {"blue", "Skillseed Up+%d%%", "Increases skillseeds gained after battle by %d%%."}, ["skilled duelist"] = {"blue", "Skilled Duelist+%d%%", "Increases all attributes (HP, Attack, Magic, Break Power) by %d%% when facing an enemy one-on-one."}, ["steelguard"] = {"blue", "Steelguard+%d%%", "Increases Defense by %d%% until end of turn every time you receive damage."}, ["ultimate charger"] = {"blue", "Ultimate Charger+%d", "Normal attacks increase the Ultimate ability gauge."}, ["ultimate charge: abilities"] = {"blue", "Ultimate Charge: Abilities+%d", "Increases the amount of Ultimate gauge charged when using abilities."}, ["water draw"] = {"blue", "Water Draw+%d", "Increases chance of drawing water orbs."}, ["wind draw"] = {"blue", "Wind Draw+%d", "Increases chance of drawing wind orbs."}, }

function p.parse_auto(text) text = mw.text.trim(text) local abi, val = string.match(text, '^%s*(.-)%s*%+%s*(%d+)%%?%s*$') if not abi then abi = text end val = tonumber(val) or 0 local key = lang:lc(abi) local entry = data[key] if not entry then return nil end local color, namefmt, infofmt = unpack(entry) namefmt = mw.text.split(namefmt, '+') if #namefmt==1 then namefmt = mw.text.split(namefmt[1], '%(')		namefmt[1] = ..namefmt[1]..		namefmt = table.concat(namefmt, '(') else namefmt[1] = ..namefmt[1].. namefmt = table.concat(namefmt, '+') end local name = string.format(namefmt, val) local info = string.format(infofmt, val) -- (Element) Draw has a threshold for the text. if (abi == "Fire Draw" or		abi == "Water Draw" or		abi == "Wind Draw" or		abi == "Earth Draw" or		abi == "Light Draw" or		abi == "Dark Draw" or		abi == "Life Draw") then if val <= 0 then info = "" elseif val <= 10 then info = "Slightly " .. lang:lcfirst(info) elseif val <= 60 then info = "Moderately " .. lang:lcfirst(info) else info = lang:ucfirst(info) end end color = lang:lc(color or "") return color, name, info end local function jobtype_icon(jobtype, size) jobtype = lang:lc(jobtype) size = size or 20 local filename if (jobtype == 'warrior' or		jobtype == 'mage' or		jobtype == 'ranger' or 		jobtype == 'monk' or 		jobtype == 'meia' or		jobtype == 'sarah' or 		jobtype == 'sophie' or 		jobtype == 'graff') then filename = jobtype .. ' Icon.png' end if filename then return '' else return '' end end local function formatabi(abi) local color, name, info = p.parse_auto(abi) if color == nil or color == "" then return nil end local icon = '' local node = mw.html.create :tag('dt') :wikitext(icon) :wikitext(name) :done :tag('dd') :wikitext(info) :done return node end function p.infobox(frame) local args = getArgs(frame, {		wrappers = "Template:Infobox weapon"	}) return p._infobox(args) end function p._infobox(args) local name = args.name or title.text local icon = args.icon or (name .. '_(weapon_icon).png') if not mw.title.makeTitle('file', icon).exists then icon = 'Icon question.png' end local info = args.description or args.info or '' local jobtype = lang:lc(args.jobtype or args['type'] or '') local abilityname = string.gsub(args.abilityname or '', '', '/') abilityname = mw.text.split(abilityname, '[/,;]+')

local abi1 = args.ability1 or abilityname[1] or '' local abi2 = args.ability2 or abilityname[2] or '' local abi3 = args.ability3 or abilityname[3] or '' local abi4 = args.ability4 or abilityname[4] or '' -- Storage if title.namespace == 0 or args.demospace == 'main' then local frame = mw.getCurrentFrame frame:callParserFunction('#cargo_store:', {			_table = "weapons",			name = name,			thumbnail = icon,			job_type = lang:ucfirst(jobtype),			description = info,		}) end -- Display local div = mw.html.create('div') div :addClass('infobox weapon') :css('width', '320px') :css('float', 'right') :css('margin', '0 5px 5px') :css('font-family', 'Tahoma, sans-serif') :css('color', 'white') :newline local tbl = div:tag('table') tbl	:css('background-color', '#2fa3bc') :css('box-shadow', '0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24)') :css('border-radius', '4px') :css('width', '100%') :newline tbl :tag('tr') :tag('td') :css('padding', '5px') :css('width','64px') :css('border','0') :css('vertical-align','top') :wikitext('') :done :tag('td') :css('padding', '5px 5px 5px 0') :css('border','0') :css('vertical-align','top') :tag('div') :css('font-size','1.3em'):css('border-bottom','1px solid white') :wikitext(jobtype_icon(jobtype)) :wikitext(name) :done :tag('div') :wikitext(info) :done :done :done :newline local abi_div = tbl :tag('tr') :tag('td') :attr('colspan', 2) :css('padding','5px') :css('border','0') :newline :tag('div') :css('font-size','95%') :css('border-bottom','1px solid white') :wikitext('Auto-Abilities') :done local a1 = formatabi(abi1) local a2 = formatabi(abi2) local a3 = formatabi(abi3) local a4 = formatabi(abi4) if a1 or a2 or a3 or a4 then local abi_list = abi_div :tag('dl') :newline if a1 then abi_list:node(a1) end if a2 then abi_list:node(a2) end if a3 then abi_list:node(a3) end if a4 then abi_list:node(a4) end end -- Categories if title.namespace == 0 or args.demospace == 'main' then div:wikitext('') if (jobtype == 'warrior' or			jobtype == 'mage' or			jobtype == 'ranger' or			jobtype == 'monk' or			jobtype == 'meia' or			jobtype == 'sarah' or 			jobtype == 'sophie' or 			jobtype == 'graff') then div:wikitext('') end if ((abi1 ~="" and not a1) or			(abi2 ~= "" and not a2) or			(abi3 ~= "" and not a3) or			(abi4 ~= "" and not a4)) then div:wikitext('') end end return tostring(div) end

function p.test return p._infobox{ name = "Femme Fatale", jobtype = "Meia", description = "If you must dance to fate's fickle drum, dance well.", ability1 = "HP Up+10%", ability2 = "Elemental Third Strike+2", ability3 = "Prismatic Draw+15%", } end return p