Module:Data

-- Purposes of this module: -- Functions for spell lists. -- Generate a spell list for all spells in a certain class -- Make a spell list for a single character --     (Option for just spell names by level, and for reference data version)

local p = {} local Shared = require( "Module:Shared" ) local Abilities = require( "Module:Abilities" ) local Spells = require( "Module:Spells" ) local Names = require( "Module:Names" ) local MagicItems = require( "Module:MagicItems" ) local Alchemy = require( "Module:Alchemy" )

local SpellData = mw.loadData( 'Module:Data/spells' ) local MagicItemData = mw.loadData( 'Module:Data/magicitems' ) local NameData = mw.loadData( 'Module:Data/names' )

local CategoryList3 = "List3"

--========================================================== --   MAGIC ITEM ARTICLE PARSER --  to be used for generating database item profiles --==========================================================

function p.transcludeArticle(frame) local Str = frame.args[2] local NameStr = frame.args[1] if(string.find(string.sub(NameStr, 1,2), '%s') ~= nil) then NameStr = string.sub(NameStr, 2) end --local itemIndex = frame.args["Index"] local inputSubtype = frame.args["Subtype"] local CategoryList2 = tostring(frame.args["List"]) local debugStr = Shared.tableCount(Shared.splitString(CategoryList2, "|")) local finalTable = { Name = NameStr, Index = 0, Rarity = "", Type = "", Subtype = "", Attune = "", PriceBalanced = "", PriceZankoBase = 0, PriceZankoDisc = 0, DescrBrief = "", DescrLong = "", DMGRef = "", Link = "http://ennorath.wikia.com/wiki/"..string.gsub(NameStr, " ", "_"), }

--If the item has no entry in the database yet, create info --if (itemIndex == nil) or (itemIndex == "") then itemIndex = p.getLastIndex end --finalTable.Index = itemIndex local strTable = p.transcludeDescription(Str) strTable = p.trimDescription(strTable) local debugT = strTable --strTable = p.transcludeDescription(Str) for k,v in ipairs(strTable) do       if (p.findRarity(v) ~= nil) then finalTable.Rarity = p.findRarity(v) if (string.find(string.lower(v), 'attunement') ~= nil) then finalTable.Attune = "y" end finalTable.Subtype = p.findSubtype(string.lower(v)) finalTable.Type = p.findType(v.." "..finalTable.Rarity) end end finalTable.DescrLong = p.cleanDescription(strTable)

--if the item DOES have an entry in the table, use that entry's data if (p.getItemEntry(NameStr) ~= nil) then local Entry = p.getItemEntry(NameStr) Entry = Entry[1] finalTable.Index = Entry.Index finalTable.Type = Entry.Type finalTable.Subtype = Entry.Subtype finalTable.PriceBalanced = Entry.PriceBalanced finalTable.PriceZankoBase = Entry.PriceZankoBase finalTable.PriceZankoDisc = Entry.PriceZankoDisc finalTable.DescrBrief = Entry.DescrBrief finalTable.DMGRef = Entry.DMGRef end

finalTable.Index = p.getNewItemIndex(finalTable.Name, CategoryList2)

return p.displayDatablock(finalTable, finalTable.Index)--.." "..debugStr--Shared.tablePrint(debugT) end

--========================================================== --   DATABASE DISPLAYER --  Input string or table, output a codeblock that can be copypasted into a database module --==========================================================

function p.displayDatablock(Table, Index) local sp = "       " local sp1 = "   " local Str = sp1.."["..Table.Index.."] = { "..sp.."Name = \""..Table.Name.."\", "..sp.."Index = "..Table.Index..", "..sp.."Rarity = \""..Table.Rarity.."\", "..sp.."Type = \""..Table.Type.."\", "..sp.."Subtype = \""..Table.Subtype.."\", "..sp.."Attune = \""..Table.Attune.."\", "..sp.."PriceBalanced = \""..Table.PriceBalanced.."\", "..sp.."PriceZankoBase = \""..Table.PriceZankoBase.."\", "..sp.."PriceZankoDisc = \""..Table.PriceZankoDisc.."\", "..sp.."DescrBrief = \""..Table.DescrBrief.."\", "..sp.."DescrLong = \""..Table.DescrLong.."\", "..sp.."DMGRef = \""..Table.DMGRef.."\", "..sp.."Link = \""..Table.Link.."\", "..sp1.."}," return Str end

--========================================================== --   PARAGRAPH TRIMMERS --  Used in other functions - trims any style or table code from a string --  input = string or table, output = table --==========================================================

--pass a table in, get a full description string out function p.cleanDescription(frame) local strTable = frame--.args[1] local DescrString = "" local tempTable = {} --Trim out the subtitle line for k,v in ipairs(strTable) do       if (string.find(string.sub(v, 1, 10), '%[') == nil) then table.insert(tempTable, v) end end DescrString = Shared.tableString(p.transcludeDescription(Shared.tableString(tempTable))) DescrString = string.gsub(DescrString, " ", " ") DescrString = string.gsub(DescrString, " ", " ") DescrString = string.gsub(DescrString, " ", " ")

DescrString = string.gsub(DescrString, "&lt;p&gt;", "OPENP") DescrString = string.gsub(DescrString, "&lt;/p&gt;", "CLOSEP") DescrString = string.gsub(DescrString, "CLOSEPCLOSEP", "CLOSEP") DescrString = string.gsub(DescrString, "OPENPOPENP", "OPENP") DescrString = string.gsub(DescrString, "OPENPCLOSEP", "1")

DescrString = string.gsub(DescrString, "OPENP", "&lt;p&gt;") DescrString = string.gsub(DescrString, "CLOSEP", "&lt;/p&gt;") --DescrString = string.gsub(DescrString, "[%a+]", "")

return DescrString end

--Trim out lines that are mostly code from pre-existing item pages function p.trimDescription(frame) local Str = frame--.args[1] local sTable = {} if (type(Str) == "table") then sTable = Str else sTable = Shared.splitString(Str, "\n") end local newTable = {} local i = 1 local sample = "" --Only keep lines that start with, , or a function-inserted formatting tag --Exclude lines that contain the Tags local Tags = "supercalifra,style,border,|,/div,class=,dm statistics"--"{|,|},|-" for k,v in ipairs(sTable) do       sample = string.sub(v, 1, 10) if (string.match(v, ' .-%a%p.- ') ~= nil) or (string.find(sample, '%[') ~= nil) or (string.find(sample, '') ~= nil) then --if (string.match(v, ' .-%a%p.- ') ~= nil) or (string.find(sample, '') ~= nil) then if (Shared.findTags(string.lower(v), Tags) == nil) then newTable[i] = v           else newTable[i] = "" end else newTable[i] = "" end i = i+1 end return newTable--string.gsub(Shared.tableString(newTable, y), " ", "\n") end

--========================================================== --   PARAGRAPH PARSER --  Used in other functions - parses wikitext to be used in a database --  Input = string or table, output = table --==========================================================

function p.transcludeDescription(frame) local Str = frame--.args[1] Str = string.gsub(Str, "<", "&lt;") Str = string.gsub(Str, ">", "&gt;") Str = string.gsub(Str, "'", "[BoldItalic]") Str = string.gsub(Str, "'''", "[Bold]") Str = string.gsub(Str, "''", "[Italic]") Str = string.gsub(Str, "", "") local sTable = {} if (type(Str) == "table") then sTable = Str else sTable = Shared.splitString(Str, "\n") end --local sTable = Shared.splitString(Str, "\n") --for k,v in ipairs(sTable) do       v = string.gsub(v, "<", "&lt;")        v = string.gsub(v, ">", "&gt;")        v = string.gsub(v, "", "[BoldItalic]")        v = string.gsub(v, "", "[Bold]")        v = string.gsub(v, "", "[Italic]")    end -- --set up new table local newTable = {} local i = 1 for k,v in ipairs(sTable) do       newTable[i] = v        i = i+1 end --handle Bolds and Italics

--handle bullet replacement local newrow = "" local lv1 = "n" local lv2 = "n" i = 1 for k,v in ipairs(sTable) do       newrow = v        --If there is a bullet * in the first three characters of a line if (string.find(string.sub(v, 1, 3), '%*%s-%a') ~= nil) then if(lv1 == "n") then lv1 = "y" newrow = ""..v.."" elseif(lv1 == "y") then newrow = ""..v.."" end if(string.find(newTable[i+1], '%*') == nil) or (newTable[i+1] == nil) or (newTable[i+1] == "") then lv1 = "n" lv2 = "n" newrow = newrow.."" end --If there is a nested bullet ** in the first four characters of a line elseif (string.find(string.sub(v, 1, 4), '%*%*%s-%a') ~= nil) then if(lv2 == "n") then lv2 = "y" newrow = ""..v.."" elseif(lv2 == "y") then newrow = ""..v.."" end if(string.find(newTable[i+1], '%*%*') == nil) then lv2 = "n" newrow = newrow.."" end if(string.find(newTable[i+1], '*') == nil) or (newTable[i+1] == nil) or (newTable[i+1] == "") then lv1 = "n" newrow = newrow.."" end end --table.insert(newTable, newrow) newTable[i] = newrow i = i+1 end i=1 for k,v in ipairs(sTable) do       newTable[i] = string.gsub(newTable[i], "*", "") i = i+1 end --handle paragraphs i=1 for k,v in ipairs(sTable) do       if(string.find(newTable[i], '') == nil) then newTable[i] = " "..newTable[i].." " end i = i+1 end local fOutput = newTable--Shared.tableString(newTable) return fOutput end

--========================================================

--Input a string: return nil if not rarity, else return Rarity function p.findRarity(Str) local Rarity = nil if (string.find(string.lower(Str), 'legendary') ~= nil) then Rarity = "Legendary" elseif (string.find(string.lower(Str), 'unique') ~= nil) then Rarity = "Unique" elseif (string.find(string.lower(Str), 'very rare') ~= nil) then Rarity = "Very Rare" elseif (string.find(string.lower(Str), 'rare') ~= nil) then Rarity = "Rare" elseif (string.find(string.lower(Str), 'uncommon') ~= nil) then Rarity = "Uncommon" elseif (string.find(string.lower(Str), 'common') ~= nil) then Rarity = "Common" end return Rarity end

--Choose Subtype from: Armor, Boots, Cloak / Robe, Headgear, Necklace, Other, Other Apparel, Potion, Ring, Scroll, Shield, Wand / Staff, Weapon function p.findSubtype(Str) local Subtype = "Other" local Armor = "armor,plate" local Boots = "boots,greaves,sandals,shoes" local CloakRobe = "cloak,robe,cape,mantle" local Headgear = "crown,headband,headgear,circlet,coronet" local Necklace = "necklace,periapt,pendant,totem" local OtherApparel = "apparel" local Potion = "potion,poison,draught" local Ring = "ring,band" local Scroll = "scroll,tome" local Shield= "shield" local WandStaff = "staff,wand,rod" local Weapon = "weapon,sword,dagger,axe,club,mace,spear,scimitar,glaive,firearm" if (Shared.findTags(Str, Armor) ~= nil) then Subtype = "Armor" elseif (Shared.findTags(Str, Boots) ~= nil) then Subtype = "Boots" elseif (Shared.findTags(Str, CloakRobe) ~= nil) then Subtype = "CLoak / Robe" elseif (Shared.findTags(Str, Headgear) ~= nil) then Subtype = "Headgear" elseif (Shared.findTags(Str, Necklace) ~= nil) then Subtype = "Necklace" elseif (Shared.findTags(Str, OtherApparel) ~= nil) then Subtype = "Other Apparel" elseif (Shared.findTags(Str, Potion) ~= nil) then Subtype = "Potion" elseif (Shared.findTags(Str, Ring) ~= nil) then Subtype = "Ring" elseif (Shared.findTags(Str, Scroll) ~= nil) then Subtype = "Scroll" elseif (Shared.findTags(Str, Shield) ~= nil) then Subtype = "Shield" elseif (Shared.findTags(Str, WandStaff) ~= nil) then Subtype = "Wand / Staff" elseif (Shared.findTags(Str, Weapon) ~= nil) then Subtype = "Weapon" end return Subtype end

--Choose Type from: Combat, NonCombat, Summoning, Consumable, Gamechanging --Input should be a concatenation of SUBTYPE and RARITY function p.findType(Str) local Type = "NonCombat" local Combat = "weapon,shield,wand,staff,armor" local Gamechanging = "legendary,unique" local Consumable = "potion,scroll,consumable" local Summoning = "summoning" if (Shared.findTags(Str, Combat) ~= nil) then Type = "Combat" elseif (Shared.findTags(Str, Gamechanging) ~= nil) then Type = "Gamechanging" elseif (Shared.findTags(Str, Consumable) ~= nil) then Type = "Consumable" elseif (Shared.findTags(Str, Summoning) ~= nil) then Type = "Summoning" end return Type end

--Find the last index in the Magic Items database function p.getLastIndex local LastIndex = 0 for i=1, 500 do       if(MagicItemData[i] ~= nil) then if (MagicItemData[i].Index > LastIndex) then LastIndex = i end end end LastIndex = LastIndex + 17 return LastIndex end

--Output an unused index not in the database, based on the --number of items within the Magic Items category function p.getNewItemIndex(ItemName, nCategoryList) --local nList = string.gsub(nCategoryList, "\n", "") local List = Shared.splitString(nCategoryList, "|") local NewIndex = 999 local startIndex = p.getLastIndex --If the item isn't in the database if(p.getItemEntry(ItemName) == nil) then

for i=1,200 do           if(List[i] ~= nil) and (p.getItemEntry(List[i])==nil) then startIndex = startIndex + 1 if(string.find( string.lower(ItemName), string.lower(List[i])) ~= nil) or (string.find(string.lower(List[i]), string.lower(ItemName)) ~= nil) then --if(string.lower(List[i]) == string.lower(ItemName)) then NewIndex = startIndex end end end --If the item IS in the database else NewIndex = p.getItemEntry(ItemName)[1].Index end return NewIndex end

--If an item already has an entry, find it function p.getItemEntry(Str) local Item = {} for i=1, 500 do       if(MagicItemData[i] ~= nil) then if (string.find(string.lower(string.gsub(MagicItemData[i].Name, '%s', "")), string.lower(string.gsub(Str, '%s', ""))) ~= nil) then ---or (string.find( string.lower(Str), string.lower(MagicItemData[i].Name)) ~= nil) then table.insert (Item, MagicItemData[i]) return Item end end end return nil end

--======================================================== --REFERENCE FUNCTIONS --  taken from the Warframe wiki

local function linkMeleeClass(weapClass) if(weapClass == nil) then return nil else return ""..weapClass.."" end 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 local function getMeleeWeapons(weapClass, PvP) local weaps = {} local weapClasses = {} if(weapClass ~= nil) then weapClasses = Shared.splitString(weapClass, ',') end for i, weap in Shared.skpairs(WeaponData["Weapons"]) do       if(weap.Type ~= nil and weap.Type == "Melee") then local classMatch = (weapClass == nil or Shared.contains(weapClasses, weap.Class)) local pvpMatch = (PvP == nil or (PvP and weap.Conclave ~= nil and weap.Conclave)) if (classMatch and pvpMatch) then table.insert(weaps, weap) end end end return weaps end

--========================================================

return p