Fractured Wiki
Advertisement
Edit-copy purple.svg Documentation

This module is responsible for the output of various spell information.

  • Mana cost
  • Description
  • Cooldown
  • Allowed Weapons
  • Allowed Armor
  • Image
  • School
  • Other Attributes
  • School spell table
  • Spell Detail Table
  • Spells in zone sorted by type
  • Spell obtainable from
  • Spell categories

It has an accompanying Lua data module at Module:Spell/data. Uses: Module:Spell/data, Module:Creature


local TableTools = require('Module:TableTools')
local Utils = require('Module:Utils')

local mw = mw
local string = string
local sprintf = Utils.sprintf
local table = table
local tsort = Utils.tableSort
local removeDuplicates = TableTools.removeDuplicates
local shallowClone = TableTools.shallowClone
local keysToList = TableTools.keysToList

--[[------------------------------------------------]]
--[[--------------- MODULE FUNCTIONS ---------------]]
--[[------------------------------------------------]]
local p = require("Module:BaseModule"):newModule()
local module_data = p:getModuleData("Module:Spell/data")

local main_args = {
    parentFirst = true,
    wrappers = {
        "Template:Spell",
        "Template:SpellDetail",
        "Template:SpellsInZoneByType",
        "Template:SpellObtainableFrom",
        "Template:SpellCategories"
    }
}

p.manaCost = p:makeInvokeFunc('_manaCost', main_args)
p.description = p:makeInvokeFunc('_description', main_args)
p.image = p:makeInvokeFunc('_image', main_args)
p.school = p:makeInvokeFunc('_school', main_args)
p.schoolTable = p:makeInvokeFunc('_schoolTable', main_args)
p.spellDetail = p:makeInvokeFunc('_spellDetail', main_args)
p.cooldown = p:makeInvokeFunc('_cooldown', main_args)
p.allowedWeapons = p:makeInvokeFunc('_allowedWeapons', main_args)
p.allowedArmor = p:makeInvokeFunc('_allowedArmor', main_args)
p.otherAttributes = p:makeInvokeFunc('_otherAttributes', main_args)
p.spellsInZoneByType = p:makeInvokeFunc('_spellsInZoneByType', main_args)
p.getListOfAllSpellSchools = p:makeInvokeFunc('_getListOfAllSpellSchools', main_args)
p.spellObtainableFrom = p:makeInvokeFunc('_spellObtainableFrom', main_args)
p.spellCategories = p:makeInvokeFunc('_spellCategories', main_args)


--[[------------------------------------------------]]
--[[-------------- INTERNAL FUNCTIONS --------------]]
--[[------------------------------------------------]]
local function spellExists(spell_name)
    return module_data[spell_name]
end

local function getSpellField(spell_name, field)
    if spellExists(spell_name) == nil then return end
    return module_data[spell_name][field]
end


--[[------------------------------------------------]]
--[[---------------- PAGE FUNCTIONS ----------------]]
--[[------------------------------------------------]]
function p._manaCost(args, frame) -- luacheck: ignore
    return getSpellField(args[1], 'mana_cost')
end

function p._description(args, frame) -- luacheck: ignore
    return getSpellField(args[1], 'description')
end

function p._image(args, frame) -- luacheck: ignore
    return getSpellField(args[1], 'image') or getSpellField('Unknown', 'image')
end

function p._school(args, frame) -- luacheck: ignore
    return getSpellField(args[1], 'school')
end

function p._cooldown(args, frame) -- luacheck: ignore
    return getSpellField(args[1], 'cooldown')
end

function p._allowedWeapons(args, frame) -- luacheck: ignore
    return getSpellField(args[1], 'allowed_weapons')
end

function p._allowedArmor(args, frame) -- luacheck: ignore
    return getSpellField(args[1], 'allowed_armor')
end

function p._otherAttributes(args, frame) -- luacheck: ignore
    return getSpellField(args[1], 'other_attributes')
end

----------------------------
-- Build and return a table for the given school with
-- spells in spellbook order.
----------------------------

function p._schoolTable(args, frame) -- luacheck: ignore
    local school_name = args[1]
    local keyList = keysToList(module_data)

    -- Create HTML output
    local mw_table = mw.html.create('table')

    local sendKey = {}
    sendKey[2] = "center"
    for k,v in pairs(keyList) do
    local spellData = module_data[v]
    if spellData["school"] == school_name then
    sendKey[1] = v
    mw_table
       :tag('tr')
          :tag('td')
          :wikitext(p._spellDetail(sendKey))
          :done()
       :done()
    end
    end

    return tostring(mw_table:allDone())
end

----------------------------
-- Spell Detail
----------------------------
function p._spellDetail(args, frame) -- luacheck: ignore
    local spells = module_data[args[1]]
    if spells == nil then return "Error: Spell not found. Check [[Module:Spell/data]]" end
    -- Get values for table -- 
    local spellName = sprintf('[[%s]]', args[1])
    local otherAttributes = ""
    if spells['Toggle Group'] ~= "None" and spells['Toggle Group'] ~= nil then otherAttributes = otherAttributes .. "Toggle Group: " .. spells['Toggle Group'] .. "<br>" end
    if spells['Effect Group'] ~= "None" and spells['Effect Group'] ~= nil then otherAttributes = otherAttributes .. "Effect Group: " .. spells['Effect Group'] .. "<br>" end
    if spells['Ready Trigger'] ~= "None" and spells['Ready Trigger'] ~= nil then otherAttributes = otherAttributes .. "Ready Trigger: " .. spells['Ready Trigger'] .. "<br>" end
    if spells['Friend Fire'] ~= "No" and spells['Friend Fire'] ~= nil then otherAttributes = otherAttributes .. "Friendly Fire: " ..spells['Friend Fire'] .. "<br>" end
    if spells['Secure Hit'] ~= "False" and spells['Secure Hit'] ~= nil then otherAttributes = otherAttributes .. "Secure Hit: " ..spells['Secure Hit'] .. "<br>" end
    if spells['Don\'t Remove Stealth'] ~= "False" and spells['Don\'t Remove Stealth'] ~= nil then otherAttributes = otherAttributes .. "Don't Remove Stealth: " .. spells['Don\'t Remove Stealth'] .. "<br>" end
    if spells['Avoid Block Controller Check'] ~= "False" and spells['Avoid Block Controller Check'] ~= nil then otherAttributes = otherAttributes .. "Avoid Block Controller Check: " .. spells['Avoid Block Controller Check'] .. "<br>" end
    if spells['Can Crit'] ~= "False" and spells['Can Crit'] ~= nil then otherAttributes = otherAttributes .. "Can Crit: " .. spells['Can Crit'] .. "<br>" end
    if spells['Mobility Spell'] ~= "False" and spells['Mobility Spell'] ~= nil then otherAttributes = otherAttributes .. "Mobility Spell: " .. spells['Mobility Spell'] .. "<br>" end
    if spells['Memory Cost'] ~= nil then otherAttributes = otherAttributes .. "Memory Cost: " .. spells['Memory Cost'] .. "<br>" end
    if spells['Spell Group'] ~= "None" and spells['Spell Group'] ~= nil then otherAttributes = otherAttributes .. "Spell Group: " .. spells['Spell Group'] .. "<br>" end
    if spells['Activation Type'] ~= nil then otherAttributes = otherAttributes .. "Activation Type: " .. spells['Activation Type'] .. "<br>" end
    if spells['Target Type'] ~= nil then otherAttributes = otherAttributes .. "Target Type: " .. spells['Target Type'] .. "<br>" end
    if spells['Targeting Range'] ~= nil then otherAttributes = otherAttributes .. "Targeting Range: " .. spells['Targeting Range'] .. "<br>" end
    if spells['Casting Range'] ~= nil then otherAttributes = otherAttributes .. "Casting Range: " .. spells['Casting Range'] .. "<br>" end
    if spells['Check LOS'] ~= nil then otherAttributes = otherAttributes .. "Check LOS: " .. spells['Check LOS'] .. "<br>" end
    if spells['Target Entity Type'] ~= "" and spells['Target Entity Type'] ~= nil then otherAttributes = otherAttributes .. "Target Entity Type: " .. spells['Target Entity Type'] .. "<br>" end
    if spells['other_attributes'] ~= "" and spells['other_attributes'] ~= nil then otherAttributes = otherAttributes .. spells['other_attributes'] .. "<br>" end
    local manaCost = sprintf("Mana Cost: %s", spells["mana_cost"])
    if spells["mana_cost_per_s"] ~= 0 and spells["mana_cost_per_s"] ~= nil then manaCost = manaCost .. " + (" .. spells["mana_cost_per_s"] .. "/s)" end
    local spellImage = sprintf("[[File:%s|center|128px]]", spells["image"])
    local spellDescription = spells["description"]
    local spellCooldown = sprintf('Cooldown: %s', spells["cooldown"])
    local spellSchool = sprintf('School: [[%s]]', spells["school"])
    local allowedWeapons = "Allowed Weapons: "
    local firstWeapon = true
    if spells["Restricted Weapon Weight"] ~= nil and spells["Restricted Weapon Weight"] ~= "" then
       allowedWeapons = allowedWeapons .. spells["Restricted Weapon Weight"]
       firstWeapon = false
    end
    if spells["Restricted Weapon Class"] ~= nil and spells["Restricted Weapon Class"] ~= "" then
       if firstWeapon == false then allowedWeapons = allowedWeapons .. " " end
       allowedWeapons = allowedWeapons .. spells["Restricted Weapon Class"]
       firstWeapon = false
    end
    if spells["Spell Channeling Weapon"] ~= nil and spells["Spell Channeling Weapon"] ~= "False" then
       if firstWeapon == false then allowedWeapons = allowedWeapons .. " " end
       allowedWeapons = allowedWeapons .. "Spell Channeling"
       firstWeapon = false
    end
    if spells["Restricted Weapon Damage"] ~= nil and spells["Restricted Weapon Damage"] ~= "" then
       if firstWeapon == false then allowedWeapons = allowedWeapons .. " " end
       allowedWeapons = allowedWeapons .. "with " .. spells["Restricted Weapon Damage"] .. " damage"
       firstWeapon = false
    end
    if firstWeapon == true and spells["Restricted Weapon Weight"] ~= nil then allowedWeapons = allowedWeapons .. "Any" end
    local allowedArmor = "Allowed Armor: "
    local firstArmor = true
    if spells['Restricted Armor Weight'] ~= "" and spells['Restricted Armor Weight'] ~= nil then
       allowedArmor = allowedArmor .. spells['Restricted Armor Weight']
       firstArmor = false
    end
    if spells['Shield Required'] == "true" then
       if firstArmor == false then allowedArmor = allowedArmor .. ", " end
       allowedArmor = allowedArmor .. "Shields"
       firstArmor = false
    end
    if firstArmor == true and spells['Restricted Armor Weight'] ~= nil then allowedArmor = allowedArmor .. "Any" end

    -- Create HTML output
    local mw_table = mw.html.create('table')
    
    if args[2] == "center" then
    mw_table
        :attr('class', 'wikitable')
        :attr('style','margin-left: auto; margin-right: auto;')
        :cssText('width:80%')
    else
    mw_table
        :attr('class', 'wikitable')
        :attr('style','margin-left: auto; margin-right: 0; float:right')
        :cssText('width:80%')
    end

        mw_table
            :tag('tr')
                :tag('td')
                    :attr('colspan', '2')
                    :cssText('text-align:left; padding-left:5px;font-size:150%')
                    :wikitext(spellName)
                :done()
                :tag('td')
                    :attr('rowspan','3')
                    :attr('width','300')
                    :cssText('text-align:left; padding-left:5px;font-size:120%')
                    :wikitext(otherAttributes)
                :done()
                :tag('td')
                    :attr('width','150')
                    :cssText('text-align:left; padding-left:5px;font-size:120%')
                    :wikitext(manaCost)
                :done()
            :done()
            :tag('tr')
                :tag('td')
                    :attr('rowspan', '2')
                    :cssText('vertical-align:center')
                    :wikitext(spellImage)
                :done()
                :tag('td')
                :attr('rowspan','2')
                    :cssText('text-align:left; padding-left:5px; font-size:120%')
                    :wikitext(spellDescription)
                :done()
                :tag('td')
                    :cssText('text-align:left; font-size:120%')
                    :wikitext(spellCooldown)
                :done()
            :done()
            :tag('tr')
                :tag('td')
                    :attr('colspan', '2')
                    :cssText('padding-left:5px; font-size:120%')
                    :wikitext(spellSchool)
                :done()
            :done()
            :tag('tr')
                :tag('td')
                    :attr('colspan', '2')
                    :attr('width','50%')
                    :cssText('text-align:left; font-size:120%')
                    :wikitext(allowedWeapons)
                :done()
                :tag('td')
                    :attr('colspan','2')
                    :attr('width','50%')
                    :cssText('text-align:left; font-size:120%')
                    :wikitext(allowedArmor)
                :done()
            :done()


    return tostring(mw_table:allDone())
end

----------------------------
-- Spells In Zone By Type
----------------------------
function p._spellsInZoneByType(args, frame) -- luacheck: ignore
    local buffer = {}
    local Creature = require('Module:Creature')
    local listOfSpellsInZone = Creature.getListOfSpellsInZone(args)

   for _, v in pairs(p.getListOfAllSpellSchools(args)) do
      local list = {}
      local spell_data
      for key, _ in pairs(module_data) do
         spell_data = module_data[key]
         if (args[1] == "all") and (v == spell_data['school']) then
            list[#list + 1] = key
         else
            for _, b in pairs(listOfSpellsInZone) do
               if (b == key) and (v == spell_data['school']) then
                  list[#list + 1] = key
               end
            end
         end
      end
      if #list ~= 0 then
         table.insert(buffer, sprintf("* [[%s]]\n",v))

         for _, value in pairs(tsort(list)) do
            table.insert(buffer, sprintf("** [[%s]]\n",value))
         end
      end
   end

    return table.concat(buffer, '')
end

----------------------------
-- Get List of All Spell Types
--
-- Make list of all schools                                    
----------------------------
function p._getListOfAllSpellSchools(args, frame) -- luacheck: ignore
    local list = {}
    local spell_data

   for k, _ in pairs(module_data) do
      spell_data = module_data[k]
      list[#list + 1] = spell_data["school"]
   end

    return tsort(removeDuplicates(list))
end

----------------------------
-- Spell Obtainable From
--
-- Fnc list all creatures you can get spell from and show their known location
----------------------------
function p._spellObtainableFrom(args, frame) -- luacheck: ignore
    local creature_module_data = mw.loadData('Module:Creature/data')
    local world_data = mw.loadData('Module:Places/Data')
    local list = {}
    local WorldRes = ""
    local ContinentRes = ""
    local ZonesRes = ""

    local function tagsLoop(target, boolean, extra)
        local res = {}
            for _, value in pairs(list) do
                local creature_data = creature_module_data[value]
                local tags = creature_data["Tags"]
                for _, b in pairs(tags) do
                    if b == target then
                    table.insert(res, sprintf("%s [[%s]]",extra,target))
                    boolean = true
                    end
                end
                if boolean == true then break end
            end
        return table.concat(res,'')
    end

    local function redoList()
        for k, _ in pairs(creature_module_data) do
            local creature_data = creature_module_data[k]
            if creature_data["Skills and Abilities"] ~= nil then
                for _, value in ipairs(creature_data["Skills and Abilities"]) do
                   if value["Name"] == args[1] then
                      list[#list + 1] = k
                   end
                end
            end
        end
    end

    local function listCreatures(target)
        local res = {}
        local first = true
        local i = 1

        while i <= #list do
            local creature_data = creature_module_data[list[i]]
            local tags = creature_data["Tags"]
            local increment = false
            local remove = false

            for _, b in pairs(tags) do
                if b == target then
                if first == true then
                    table.insert(res,sprintf(': [[%s]]', list[i]))
                    first = false
                else
                    table.insert(res,sprintf(', [[%s]]', list[i]))
                end
                remove = true
                increment = false
                break
                else
                increment = true
                end
            end
            
            if remove == true then
                table.remove(list, i)
            end

            if increment == true then i = i + 1 end
        end

        if #res ~= 0 then table.insert(res,'\n') end
        return table.concat(res,'')
    end

    for k, _ in pairs(world_data) do
        redoList()
        table.sort(list)
        WorldRes = WorldRes .. tagsLoop(k, false, "*")

        local continent_data = world_data[k]
        for cont, _ in pairs(continent_data) do
            ContinentRes = ContinentRes .. tagsLoop(cont, false, "**")
            local zones_data = continent_data[cont]

            for _, zoneName in pairs(zones_data)do
                ZonesRes = ZonesRes .. tagsLoop(zoneName, false, "***") .. listCreatures(zoneName)
            end
            if #list ~= 0 then ContinentRes = ContinentRes .. listCreatures(cont) end
            if ZonesRes ~= "" then
                if string.sub(ContinentRes, -1) == "\n" then
                ContinentRes = ContinentRes .. ZonesRes
                ZonesRes = ""
                else
                ContinentRes = ContinentRes .. "\n" .. ZonesRes
                ZonesRes = ""
                end
            end
        end
      
        if #list ~= 0 then WorldRes = WorldRes .. listCreatures(k) end

        if ContinentRes ~= "" then
            if string.sub(WorldRes, -1) == "\n" then
                WorldRes = WorldRes .. ContinentRes
                ContinentRes = ""
            else
                WorldRes = WorldRes .. "\n" .. ContinentRes
                ContinentRes = ""
            end
        end
    end

    return WorldRes
end

----------------------------
-- Put categories on Spell pages
----------------------------
function p._spellCategories(args, frame) -- luacheck: ignore
local spellName = args[1]
local spellData = module_data[spellName]
local spellCategories = spellData['Categories']
local categoriesToPrint = {"[[Category:Abilities]]"}
   for key, value in pairs(spellCategories) do
      table.insert(categoriesToPrint,sprintf("[[Category:%s]]",value))
   end
return table.concat(categoriesToPrint,'')
end
----------------------------
return p
Advertisement