Module:UtilsSpells

local p = {} local utilsCode = require("Module:UtilsCode") local utilsDisplay = require("Module:UtilsDisplay") local utilsIcons = require("Module:UtilsIcons") local utilsCargo = require("Module:UtilsCargo") local utilsString = require("Module:UtilsString")

local FIELDS = { {name = "name", type = "String"}, {name = "class", type = "String"}, {name = "type", type = "String"}, {name = "description", type = "String"}, {name = "AP_cost", type = "Integer"}, {name = "MP_cost", type = "Integer"}, {name = "WP_cost", type = "Integer"}, {name = "spell_range", type = "String"}, {name = "line_of_sight", type = "Boolean"}, {name = "modifiable_range", type = "Boolean"}, {name = "straight_line", type = "Boolean"}, {name = "diagonal_line", type = "Boolean"}, {name = "self_target", type = "Boolean"}, {name = "target_type", type = "String"}, {name = "effects", type = "List of String"}, {name = "critical_effects", type = "List of String"}, {name = "conditions", type = "List of String"}, {name = "unlock_level", type = "Integer"}, }

-- Displays a spell function p._DisplaySpell(frame) local args = frame:getParent.args local spellArgs = {name = args[1], class = args[2], link = false} return p.DisplaySpell(spellArgs) end

function p.DisplaySpell(spellArgs) local filepath = "" local result = mw.html.create("div") :addClass("spell-image") :wikitext(filepath) return result end

function p.GetSpell(spellArgs) local query = {tables = 'Spells', fields = FIELDS, args = { where = 'class = "' .. spellArgs["class"] .. '" AND name = "' .. spellArgs["name"] .. '"', }   			}    local results = utilsCargo.Query(query)

return results[1] end

function p.GetSpellsByClass(class) local query = {tables = 'Spells', fields = FIELDS, args = { where = 'class = "' .. class .. '"', orderBy = "unlock_level ASC" }   			}    local results = utilsCargo.Query(query)

return results end

function p._DisplayDetails(frame) local args = frame:getParent.args local spellArgs = {class = args[1], name = args[2]} return p.DisplayDetails(spellArgs) end

function p.DisplayDetails(spellArgs) local spell = p.GetSpell(spellArgs) -- Formats the info section local info = "" -- Action Points if not utilsCode.IsEmpty(spell["AP_cost"]) then info = info .. " " .. spell["AP_cost"] .. utilsIcons.Display("Action Point") end -- Movement Points if not utilsCode.IsEmpty(spell["MP_cost"]) then info = info .. " " .. spell["MP_cost"] .. utilsIcons.Display("Movement Point") end -- Wakfu Points if not utilsCode.IsEmpty(spell["WP_cost"]) then info = info .. " " .. spell["WP_cost"] .. utilsIcons.Display("Wakfu Point") end -- Range info = info .. " " .. spell["spell_range"] -- Line of Sight if spell["line_of_sight"] == true then info = info .. utilsIcons.Display("Range") else info = info .. utilsIcons.Display("Range (No Line of Sight)") end -- Modifiable range if spell["modifiable_range"] == true then info = info .. utilsIcons.Display("Modifiable Range") end -- Straight line if spell["straight_line"] == true then info = info .. utilsIcons.Display("Straight Line") end -- Diagonal line if spell["diagonal_line"] == true then info = info .. utilsIcons.Display("Diagonal Line") end -- Self target if spell["self_target"] == true then info = info .. utilsIcons.Display("Self Target") end -- Target type if not utilsCode.IsEmpty(spell["target_type"]) then info = info .. utilsIcons.Display(spell["target_type"]) end local result = mw.html.create("div") :addClass("spell-details-container") :node(mw.html.create("div")			:addClass("spell-details-image")			:wikitext(tostring(p.DisplaySpell({name = spell["name"], class = spell["class"], link = false})))) :node(mw.html.create("div")			:addClass("spell-details-name")			:wikitext(spell["name"])) :node(mw.html.create("div")			:addClass("spell-details-level")			:wikitext("Lvl. 0")) :node(mw.html.create("div")			:addClass("spell-details-info")			:wikitext(info)) :node(mw.html.create("div")			:addClass("spell-details-description")			:wikitext(spell["description"])) local tabsToParse = {} local effectTabs = { {name = "Effect", effects = spell["effects"]}, {name = "Critical", effects = spell["critical_effects"]}, {name = "Conditions", effects = spell["conditions"]} }		-- Checking if they're empty before sending for key, effectTab in ipairs(effectTabs) do			if not utilsCode.IsEmpty(effectTab["effects"][1]) then table.insert(tabsToParse, effectTab) end end -- Only display the unlock tab for spells that are not obtained at level 1 if not utilsCode.IsEmpty(spell["unlock_level"]) then if spell["unlock_level"] > 1 then table.insert(tabsToParse, {name = "Unlock", effects = {"Level >= " .. spell["unlock_level"]}}) end end local effects = utilsDisplay.DisplayEffectTables(tabsToParse) result:node(effects) return result end

function p._DisplaySpells(frame) local args = frame:getParent.args return p.DisplaySpells(args[1]) end

function p.DisplaySpells(class) local queryArgs = {orderBy = "unlock_level ASC"} local spells = p.GetSpellsByClass(class, queryArgs) local elementalSpells = {} local activeSpells = {} local passiveSpells = {} for key, spell in ipairs(spells) do		if spell["type"] == "Elemental" then table.insert(elementalSpells, spell) elseif spell["type"] == "Active" then table.insert(activeSpells, spell) elseif spell["type"] == "Passive" then table.insert(passiveSpells, spell) end end local firstSpells = { Cra = {"Blazing Arrow", "Riddling Arrow", "Retreat Arrow"}, Ecaflip = {"Craps", "Rough Tongue", "Heads or Tails"}, Eliotrope = {"Wakmeha", "Deafening Target", "Torrential Flux"}, Eniripsa = {"Sadist Mark", "Healing Word", "Fear Flask"}, Enutrof = {"Fusion", "Purge", "Shovel of Judgement"}, Feca = {"Natural Attack", "Drip", "Fecabo"}, Foggernaut = {"Flambé", "Pummel", "Heart of Steam"}, Huppermage = {"Energy Flux", "Downpour", "Collapse", "Diurnal Butterflies"}, Iop = {"Thunderbolt", "Shaker", "Jabs"}, Masqueraider = {"Fracture", "Fugue", "Whipkick"}, Osamodas = {"Magpie", "Crocodyl Spirit", "Crobak"}, Ouginak = {"Weigh Down", "Fits and Starts", "Sweeping"}, Pandawa = {"Flaming Burp", "Milky Breath", "Triple Whammy"}, Rogue = {"Barbed Fire", "Machine Gun", "Slap Shot"}, Sacrier = {"Blood Rush", "Rocky Foot", "Rippling Tattoo"}, Sadida = {"Vaporize", "Bramble", "Woodland Stench"}, Sram = {"First Blood", "Kleptosram", "Forceful Blow"}, Xelor = {"Hand", "Frostbite", "Underhand"} }	local result = mw.html.create("div") :addClass("spells-display") -- Elemental Spells if not utilsCode.IsEmpty(elementalSpells[1]) then result:node(mw.html.create("div")			:addClass("header")			:wikitext("Elemental Spells")) local elementalSpellsContainer = mw.html.create("div") :addClass("spells-display-container") local tempcol = 0 local temprow = 0 local counter = 0 while counter < #elementalSpells do			tempcol = (counter % 5) + 1 temprow = math.floor(counter / 5) + 1 if tempcol == 1 then elementalSpellsContainer:node(p.DisplaySpell({name = firstSpells[class][temprow], class = class, link = true})) else elementalSpellsContainer:node(p.DisplaySpell({name = elementalSpells[temprow + ((tempcol - 1) * (#elementalSpells / 5))]["name"], class = class, link = true})) end counter = counter + 1 end result:node(elementalSpellsContainer) end -- Active Spells if not utilsCode.IsEmpty(activeSpells[1]) then result:node(mw.html.create("div")			:addClass("header")			:wikitext("Active Spells")) local activeSpellsContainer = mw.html.create("div") :addClass("spells-display-container") for key, spell in ipairs(activeSpells) do			activeSpellsContainer:node(p.DisplaySpell({name = spell["name"], class = class, link = true})) end result:node(activeSpellsContainer) end return result end

return p