--Attempting to recreate Module:Weapons for Mods
--go away error messages
--
local p = {}
local ModData = mw.loadData( 'Module:Mods/data' )
local Shared = require( "Module:Shared" )
local Icon = require( "Module:Icon" )
local Version = require( "Module:Version" )
local Tooltip = require('Module:Tooltip')
local function getMod(name)
local _mod = ModData["Mods"][name]
if _mod ~= nil and _mod.Name == name then
return _mod
else
for modName, Mod in pairs(ModData["Mods"]) do
if modName == name or Mod.Name == name then
return Mod
end
end
end
end
local function ifModExists(name, _mod)
if type(_mod) ~= table then
_mod = ModData["Mods"][name]
elseif _mod.Name == name then
return true
end
if _mod ~= nil and _mod.Name == name then
return true
else
for modName, Mod in pairs(ModData["Mods"]) do
if modName == name or Mod.Name == name then
return true
end
end
end
return false
end
function p.getValueRaw(frame)
local ModName = frame.args[1]
local ValName = frame.args[2]
local Mod = getMod(ModName)
if Mod ~= nil then
return Mod[ValName]
end
end
function p.getValue(frame)
local modName = frame.args[1]
local valName = frame.args[2]
return p._getValue(modName, valName)
end
function p._getValue(ModName, ValName)
local Mod = nil
if(type(ModName) == "table") then
Mod = ModName
ModName = Mod.Name
else
Mod = getMod(ModName)
end
local UpName = string.upper(ValName)
if(ModName == nil) then
return "ERREUR : Pas de mod spécifié"
end
if(ValName == nil) then
return "ERREUR : Pas de valeur spécifiée"
end
if(not ifModExists(ModName,Mod)) then
if(UpName == "IMAGE") then
return 'Mod_inconnu.png'
else
return "ERREUR : Le Mod "..ModName.." n\'a pas été trouvé"
end
end
if(UpName == "FAMILY") then
return Mod.Family
elseif(UpName == "HASFAMILY") then
return Mod.Family ~= nil
elseif(UpName == "IMAGE") then
if(Mod.Image ~= nil and Mod.Image ~= "") then
return Mod.Image
else
return 'Mod_inconnu.png'
end
elseif(UpName == "INTRODUCED") then
if(Mod.Introduced ~= nil) then
return Version._getVersionLink(Mod.Introduced)
else
return nil
end
elseif(UpName == "LINK") then
if(Mod.Link ~= nil) then
return Mod.Link
else
return Mod.Name
end
elseif(UpName == "NAME") then
return Mod.Name
elseif(UpName == "NAMEEN") then
return Shared.trim(Mod.NameEN:gsub(" ", "_"))
elseif(UpName == "POLARITY") then
if(Mod.Polarity ~= nil) then
return Mod.Polarity
else
return "Aucune"
end
elseif(UpName == "POLARITYICON") then
if(Mod.Polarity ~= nil) then
return Icon._Pol(Mod.Polarity)
else
return "Aucune"
end
elseif(UpName == "PVP") then
return Mod.PvP
elseif(UpName == "RARITY") then
if(Mod.Rarity ~= nil) then
return Mod.Rarity
else
return "Inconnue"
end
elseif(UpName == "STANCE") then
return Mod.Stance
elseif(UpName == "TRADETAX") then
if(Mod.Rarity ~= nil) then
if(Mod.Rarity == "Commun") then
return '2,000 '..Icon._Item("Crédits")
elseif(Mod.Rarity == "Inhabituel") then
return '4,000 '..Icon._Item("Crédits")
elseif(Mod.Rarity == "Rare") then
return '8,000 '..Icon._Item("Crédits")
elseif(Mod.Rarity == "Légendaire") then
return '1,000,000 '..Icon._Item("Crédits")
elseif(Mod.Rarity == "Atypique") then
return '4,000 '..Icon._Item("Crédits")
elseif(Mod.Rarity == "Amalgame") then
return "Non Échangeable"
else
return nil
end
else
return nil
end
elseif(UpName == "TRANSMUTABLE") then
if(Mod.Transmutable ~= nil) then
if(Mod.Transmutable) then
return '[[Transmutation|<span style="color:green">Transmutable</span>]][[Category:Mod Transmutable]]'
else
return '[[Transmutation|<span style="color:red">Non Transmutable</span>]][[Category:Mod Non Transmutable]]'
end
else
return '[[Transmutation|<span style="color:green">Transmutable</span>]][[Category:Mod Transmutable]]'
end
elseif(UpName == "WEAPONAUGMENT") then
return Mod.WeaponAugment
else
return ModData["Mods"][ModName][ValName]
end
end
local function build_checkArray(modArray)
if(type(modArray[1]) == 'string') then
newArray = {}
for i, name in pairs(modArray) do
table.insert(newArray, getMod(name))
end
modArray = newArray
end
return modArray
end
local function buildModColumn(modArray)
local ret = nil
if(Shared.tableCount(modArray) > 0) then
modArray = build_checkArray(modArray)
local first = true
for i, Mod in pairs(modArray) do
if(first) then
first = false
ret = Tooltip._tooltipText(Mod.Name, 'Mod')
else
ret = ret..'<br/>'..Tooltip._tooltipText(Mod.Name, 'Mod')
end
if(Mod.PvP) then
ret = ret.." (PvP)"
end
end
end
return ret
end
local function getFamilyArray(family2LookFor, mod2Exclude)
local ret = {}
for name, Mod in Shared.skpairs(ModData["Mods"]) do
if(Mod.Family ~= nil and Mod.Family == family2LookFor and Mod.Name ~= mod2Exclude) then
table.insert(ret, Mod)
end
end
return ret
end
function p.getFamilyInfoBox(frame)
local modName = frame.args[1]
local Mod = getMod(modName)
local ret = nil
if(Mod ~= nil and Mod.Family ~= nil) then
local modArray = getFamilyArray(Mod.Family, Mod.Name)
ret = buildModColumn(modArray)
end
return ret
end
function p.buildModTableByRarity()
buildLegendaryTable = ""
countLegendary = 0
buildRareTable = ""
countRare = 0
buildUncommonTable = ""
countUncommon = 0
buildCommonTable = ""
countCommon = 0
for key, Mod in Shared.skpairs(ModData["Mods"]) do
-- mw.log(Mod.Rarity)
if Mod.Rarity == "Légendaire" then
buildLegendaryTable = buildLegendaryTable .. "[[File:" .. Mod.Image .. "|114px|link=" .. Mod.Name .."]]"
countLegendary = countLegendary + 1
elseif Mod.Rarity == "Rare" then
buildRareTable = buildRareTable .. "[[File:" .. Mod.Image .. "|114px|link=" .. Mod.Name .."]]"
countRare = countRare + 1
elseif Mod.Rarity == "Inhabituel" then
buildUncommonTable = buildUncommonTable .. "[[File:" .. Mod.Image .. "|114px|link=" .. Mod.Name .."]]"
countUncommon = countUncommon + 1
elseif Mod.Rarity == "Commun" then
buildCommonTable = buildCommonTable .. "[[File:" .. Mod.Image .. "|114px|link=" .. Mod.Name .."]]"
countCommon = countCommon +1
end
end
countTotal = countLegendary + countRare + countUncommon + countCommon
buildTable =
countTotal .. "\n" ..
"{| border=\"1\" cellpadding=\"1\" cellspacing=\"1\" class=\"article-table\"\n" ..
"|-\n" ..
"!Légendaire\n" .. countLegendary .. "\n" ..
"| " .. buildLegendaryTable .. "\n" ..
"|-\n" ..
"! Rare\n" .. countRare .. "\n" ..
"| " .. buildRareTable .. "\n" ..
"|-\n" ..
"! Inhabituel\n" .. countUncommon .. "\n" ..
"| " .. buildUncommonTable .. "\n" ..
"|-\n" ..
"! Commun\n" .. countCommon .. "\n" ..
"| " .. buildCommonTable .. "\n" ..
"|}"
return buildTable
end
function p.buildModTableByPolarity()
buildMaduraiTable = ""
buildVazarinTable = ""
buildNaramonTable = ""
buildZenurikTable = ""
buildPenjagaTable = "" --wtf is penjaga
buildUnairuTable = ""
countMadurai = 0
countVazarin = 0
countNaramon = 0
countZenurik = 0
countPenjaga = 0
countUnairu = 0
--Madurai "V" "Madurai"
--Vazarin "D"
--Naramon "Bar"
--Zenurik "Ability" "Zenurik"
--Penjaga "Sentinel"
-- Unairu Pol Unairu - R - Introduced in Update 13.0 and used for certain Melee Stance Mods.
for key, Mod in Shared.skpairs(ModData["Mods"]) do
-- mw.log(Mod.Polarity)
if Mod.Polarity == "V" or Mod.Polarity == "Madurai" then
buildMaduraiTable = buildMaduraiTable .. "[[File:" .. Mod.Image .. "|114px|link=" .. Mod.Name .."]]"
countMadurai = countMadurai + 1
elseif Mod.Polarity == "D" or Mod.Polarity == "Vazarin" then
buildVazarinTable = buildVazarinTable .. "[[File:" .. Mod.Image .. "|114px|link=" .. Mod.Name .."]]"
countVazarin = countVazarin + 1
elseif Mod.Polarity == "Bar" or Mod.Polarity == "Dash" or Mod.Polarity == "Naramon" then
buildNaramonTable = buildNaramonTable .. "[[File:" .. Mod.Image .. "|114px|link=" .. Mod.Name .."]]"
countNaramon = countNaramon + 1
elseif Mod.Polarity == "Ability" or Mod.Polarity == "Zenurik" or Mod.Polarity == "Scratch" then
buildZenurikTable = buildZenurikTable .. "[[File:" .. Mod.Image .. "|114px|link=" .. Mod.Name .."]]"
countZenurik = countZenurik + 1
elseif Mod.Polarity == "Sentinel" or Mod.Polarity == "Penjaga" then
buildPenjagaTable = buildPenjagaTable .. "[[File:" .. Mod.Image .. "|114px|link=" .. Mod.Name .."]]"
countPenjaga = countPenjaga + 1
elseif Mod.Polarity == "R" or Mod.Polarity == "Unairu" or Mod.Polarity == "Ward" then
buildUnairuTable = buildUnairuTable .. "[[File:" .. Mod.Image .. "|114px|link=" .. Mod.Name .."]]"
countUnairu = countUnairu + 1
end
end
countTotal = countMadurai + countVazarin + countNaramon + countZenurik + countPenjaga + countUnairu
buildTable =
countTotal .. "\n" ..
"{| border=\"1\" cellpadding=\"1\" cellspacing=\"1\" class=\"article-table\"\n" ..
"|-\n" ..
"! Madurai\n" .. countMadurai .. "\n" ..
"| " .. buildMaduraiTable .. "\n" ..
"|-\n" ..
"! Vazarin\n" .. countVazarin .. "\n" ..
"| " .. buildVazarinTable .. "\n" ..
"|-\n" ..
"! Naramon\n" .. countNaramon .. "\n" ..
"| " .. buildNaramonTable .. "\n" ..
"|-\n" ..
"! Zenurik\n" .. countZenurik .. "\n" ..
"| " .. buildZenurikTable .. "\n" ..
"|-\n" ..
"! Penjaga\n" .. countPenjaga .. "\n" ..
"| " .. buildPenjagaTable .. "\n" ..
"|-\n" ..
"! Unairu\n" .. countUnairu .. "\n" ..
"| " .. buildUnairuTable .. "\n" ..
"|}"
return buildTable
end
function p.getPolarityList()
local pols = {}
for name, Mod in Shared.skpairs(ModData["Mods"]) do
if(pols[Mod.Polarity] == nil) then
pols[Mod.Polarity] = 1
else
pols[Mod.Polarity] = pols[Mod.Polarity] + 1
end
end
local result = "POLARITES:"
for key, trash in Shared.skpairs(pols) do
result = result.."\n"..key.." ("..trash..")"
end
return result
end
function p.getRarityList()
local pols = {}
for name, Mod in Shared.skpairs(ModData["Mods"]) do
if(pols[Mod.Rarity] == nil) then
pols[Mod.Rarity] = 1
else
pols[Mod.Rarity] = pols[Mod.Rarity] + 1
end
end
local result = "RARETES:"
for key, trash in Shared.skpairs(pols) do
result = result.."\n"..key.." ("..trash..")"
end
return result
end
--Returns the mods (structures) that have the given trait
local function getTraitArray(trait2LookFor)
local ret = {}
for name, Mod in Shared.skpairs(ModData["Mods"]) do
if(Mod.Traits ~= nil) then
if(Shared.contains(Mod.Traits, trait2LookFor)) then
table.insert(ret, Mod)
end
end
end
return ret
end
local function buildModGallery(modArray)
local ret = '\n{| style="margin:auto; text-align:center;"'
if(Shared.tableCount(modArray) > 0) then
modArray = build_checkArray(modArray)
local nameRow = ''
for i, Mod in pairs(modArray) do
if((i - 1) % 4 == 0) then
ret = ret..nameRow..'\n|-'
nameRow = '\n|-'
end
modImg = p._getValue(Mod, "IMAGE")
modLink = p._getValue(Mod, "LINK")
ret = ret..'\n| style="width:165px" |[[File:'..modImg..'|150px|link='..modLink..']]'
nameRow = nameRow..'\n| style="vertical-align:text-top;" | '..Tooltip._tooltipText(Mod.Name, 'Mod')
if(Mod.PvP) then
nameRow = nameRow..'<br/>([[Conclave]] uniquement)'
end
end
ret = ret..nameRow
end
ret = ret..'\n|}'
return ret
end
function p.getTraitGallery(frame)
local trait2LookFor = frame.args[1]
local modArray = getTraitArray(trait2LookFor)
local ret = buildModGallery(modArray)
return ret
end
--Returns the mods (structures) that are from the given set
local function getSetArray(set2LookFor)
local ret = {}
for name, Mod in Shared.skpairs(ModData["Mods"]) do
if(Mod.Set ~= nil and Mod.Set == set2LookFor) then
table.insert(ret, Mod)
end
end
return ret
end
function p.getSetGallery(frame)
local set2LookFor = frame.args[1]
local modArray = getSetArray(set2LookFor)
local ret = buildModGallery(modArray)
return ret
end
function p.buildModList(modArray, ignoreFamily)
local ret = nil
if(Shared.tableCount(modArray) > 0) then
modArray = build_checkArray(modArray)
local first = true
local next = next --More efficient access to global function
local i, Mod = next(modArray)
local modArray_count = Shared.tableCount(modArray)
while(i <= modArray_count) do
if(Mod == nil) then
if(first) then
first = false
ret = ""
else
ret = ret.." • "
end
if(ignoreFamily or Mod.Family == nil) then
ret = ret..Tooltip._tooltipText(Mod.Name, 'Mod')
if(Mod.PvP) then
ret = ret.." (PvP)"
end
modArray[i] = nil
else
--Manage family mods
local familyName = Mod.Family
local familyMods = {}
local familyCount = 0
local hasFamilySeed = false
local familyMods_index = {}
--Select family mods
for i, fam_mod in pairs(modArray) do
if(fam_mod.Family == familyName) then
hasFamilySeed = hasFamilySeed or (fan_mod == familyName)
familyCount = familyCount + 1
if(fan_mod ~= familyName) then
table.insert(familyMods, fan_mod)
familyMods_index[fan_mod.Name] = i
end
end
end
if(familyCount > 1 and hasFamilySeed) then
ret = ret..Tooltip._tooltipText(familyName, 'Mod').." ("
local familyFirst = true
for _, fam_mod in pairs(familyMods) do
local newName = Shared.trim(fam_mod.Name:gsub(familyName, ""))
if(string.find(newName, "Amalgame")) then
newName = "Amalgame"
end
if(familyFirst) then
familyFirst = false
else
ret = ret..", "
end
ret = ret..Tooltip._tooltipText(fam_mod.Name, 'Mod', newName)
end
ret = ret..")"
--Remove family members from original printing list
for j, index in pairs(familyMods_index) do
--Remove one to index for each removed item
modArray[index - (j - 1)] = nil
end
else
--If only member of the family present or without the seed, just print the mod
ret = ret..Tooltip._tooltipText(Mod.Name, 'Mod')
if(Mod.PvP) then
ret = ret.." (PvP)"
end
modArray[i] = nil
end
end
end
i, Mod = next(modArray, i)
end
end
return ret
end
function p.getTraitList(frame)
local trait2LookFor = frame.args[1]
local modArray = getTraitArray(trait2LookFor)
local ret = p.buildModList(modArray)
return ret
end
function p.getSetList(frame)
local set2LookFor = frame.args[1]
local modArray = getSetArray(set2LookFor)
local ret = p.buildModList(modArray)
return ret
end
--function p.getModTraitsCategories(frame)
--
-- local modName = frame.args[1]
-- local Mod = getMod(modName)
-- local ret = ""
--
-- if(Mod ~= nil and Mod.Traits ~= nil) then
-- if(Shared.contains(Mod.Traits, "CORROMPU")) then
-- ret = ret.."[[Category:Mod Corrompu]]"
-- end
-- end
-- return ret
--end
------------------------
------------------------
--POSTURES
------------------------
------------------------
function p.getStance(StanceName)
for i, Stance in pairs(ModData["Postures"]) do
if(Stance.Name == StanceName) then
return Stance
end
end
return nil
end
function p.getStanceValue(frame)
local modName = frame.args[1]
local valName = frame.args[2]
return p._getStanceValue(modName, valName)
end
function p._getStanceValue(modName, valName)
--Check input parameters
if(modName == nil or modName == '') then
return 'Error: No mod specified.'
end
if(valName == nil or valName == '') then
return 'Error: No value specified.'
end
--Recover stance
local stance = p.getStance(modName)
if(stance == nil) then
return 'Error: The stance "'..modName..'" couldn\'t be found in [[Module:Weapons/data]]'
end
local ret = nil
local UpName = string.upper(valName)
if(UpName == "CLASS") then
ret = stance.Class
end
return ret
end
local function _getStancesList(weapType)
local stanceArray = p.getStances(weapType, true)
local modArray = {}
for _, stance in pairs(stanceArray) do
table.insert(modArray, getMod(stance.Name))
end
local ret = p.buildModList(modArray)
return ret
end
function p.getStancesList(frame)
local weapType = frame.args ~= nil and frame.args[1]
return _getStancesList(weapType)
end
--Returns all melee weapons.
--If weapType is not nil, only grab for a specific type
--For example, if weapType is "Nikana", only pull Nikanas
--TODO, correct confusion with pvpOnly
function p.getStances(weapType, pvpOnly, weapName)
local stances = {}
--Exception de Serres de Garuda
if weapName == "Serres de Garuda" then
weapType = "Griffes"
end
if(weapType == "Arme Exaltée" and weapName ~= nil) then
for i, stance in Shared.skpairs(ModData["Postures"]) do
local nameMatch = (weapName == nil or weapName == stance.Weapon)
if nameMatch then
table.insert(stances, stance)
end
end
else
for i, stance in Shared.skpairs(ModData["Postures"]) do
local classMatch = (weapType == nil or weapType == stance.Class)
local stancePvP = p._getValue(stance.Name, "PVP")
local pvpMatch = (pvpOnly ~= nil and pvpOnly) or (stancePvP == nil or not stancePvP)
if (classMatch and pvpMatch) then
table.insert(stances, stance)
end
end
end
return stances
end
function p.getStanceGallery(frame)
local StanceType = frame.args ~= nil and frame.args[1] or frame
local Stances = p.getStances(StanceType, true)
local result = "==[[Posture|Mods de Posture]] pour "..StanceType.."=="
local modArray = {}
for i, posture in pairs(Stances) do
table.insert(modArray, getMod(posture.Name))
end
result = result..buildModGallery(modArray)
return result
end
------------------------
------------------------
--AUGMENTS
------------------------
------------------------
function p.getAugments(Weapon)
local name = Weapon.Name ~= nil and Weapon.Name or Weapon
local augments = {}
for i, Augment in pairs(ModData["Augments"]) do
for j, WeapName in pairs(Augment.Weapons) do
if(WeapName == name) then
table.insert(augments, Augment)
end
end
end
return augments
end
function p.buildAugmentTable(frame)
local result = ""
result = result..'\n{|class="listtable sortable" style="width:100%;"'
result = result..'\n|-'
result = result..'\n! Nom'
result = result..'\n! Catégorie'
result = result..'\n! Source'
result = result..'\n! Arme'
for i, Augment in pairs(ModData["Augments"]) do
local thisStr = "\n|-"
thisStr = thisStr.."\n| <span class=\"mod-tooltip\" data-param=\""..Augment.Name.."\" style=\"white-space:pre\">[["..Augment.Name.."]]</span>" --span class = displays the mod tooltip in the table on hover.
thisStr = thisStr.."\n| "..Augment.Category
thisStr = thisStr.."\n| [["..Augment.Source.."]]"
thisStr = thisStr.."\n| "
for i, weap in pairs(Augment.Weapons) do
if(i>1) then thisStr = thisStr.."<br/>" end
thisStr = thisStr.."[["..weap.."]]"
end
result = result..thisStr
end
result = result..'\n|}'
return result
end
function p.getAugmentWeapons(frame)
local augmentName = frame.args[1]
return p._getAugmentWeapons(augmentName)
end
function p._getAugmentWeapons(augmentName)
local ret = nil
local i = 1
while(i <= Shared.tableCount(ModData["Augments"]) and ret == nil) do
if(ModData["Augments"][i].Name == augmentName) then
ret = ModData["Augments"][i].Weapons
end
i = i + 1
end
return ret
end
function p.printAugmentWeaponsColumn(frame)
local modName = frame.args ~= nil and frame.args[1]
return p._printAugmentWeapons_Column(modName)
end
function p._printAugmentWeapons_Column(modName)
local ret = nil
local wpList = p._getAugmentWeapons(modName)
local first = true
for _, wp in pairs(wpList) do
if(first) then
first = false
ret = Tooltip._tooltipText(wp, 'Weapon')
else
ret = ret.."\n"..Tooltip._tooltipText(wp, 'Weapon')
end
end
return ret
end
local function _getAugmentList(category, source)
local ret = nil
local augmentArray = ModData["Augments"]
local modArray = {}
for _, val in pairs(augmentArray) do
if(val.Category == category and val.Source == source) then
table.insert(modArray, getMod(val.Name))
end
end
ret = p.buildModList(modArray)
return ret
end
function p.getAugmentList(frame)
local category = frame.args[1]
local source = frame.args[2]
return _getAugmentList(category, source)
end
return p