FANDOM


--Replacing current info at Template:Database to unify in Lua
--Plus Lua is easier to read/edit than templates
local p = {}
 
local DropData = mw.loadData( 'Module:DropTables/data' )
local MissionData = mw.loadData( 'Module:Missions/data' )
local script = require( "Module:Icon" )
local Shared = require( "Module:Shared" )
local cache = {FromAlias = {}, Name = {}, ShortName = {}, CategoryName = {}}
local tierTypes = {"Arena", "Capture", "Defection", "Defense", "Excavation", "Exterminate", "Interception", "Rescue", "Sabotage", "Spy", "Survival"}
 
--Function for pulling mission names to category names
--Basically: You can use either the Data name or the 'true' name
--So you can get low level defenses with EITHER "Defense", "Easy" or "Defense", "Tier 1"
function p.getCategoryName(MType, MCat)
    if(cache.CategoryName[MType..MCat] ~= nil) then
        return cache.CategoryName[MType..MCat]
    end
 
    if (DropData["Categories"][MType] == nil or DropData["Categories"][MType][MCat] ~= nil) then
        cache.CategoryName[MType..MCat] = MCat
        return MCat
    else
        local mSets = DropData["Categories"][MType]
        for catCode, cat in Shared.skpairs(mSets) do
            if(cat.Name == MCat) then
                cache.CategoryName[MType..MCat] = catCode
                return catCode
            end
        end
        cache.CategoryName[MType..MCat] = MCat
        return MCat
    end
end
 
--Function for converting mission alises to category names
--With any luck I can get rid of this soon-ish.
--I'm swapping from one method of tracking things to another, hopefully less confusing one
--The trick is doing it without killing every drop table on the wiki for an hour+
function p.getMissionFromAlias(Alias)
    local MType, MCat
    if(cache.FromAlias[Alias] ~= nil) then
        return cache.FromAlias[Alias].Type, cache.FromAlias[Alias].Category
    end
 
    for Type, Array in Shared.skpairs(DropData["Categories"]) do
        for Cat, CatType in Shared.skpairs(Array) do
            if(string.upper(CatType.Alias) == string.upper(Alias)) then
                MType = Type
                MCat = Cat
                cache.FromAlias[Alias] = {Type = MType, Category = MCat}
            end
        end
    end
 
    return MType, MCat
end
 
function p.getAlias(MType, MCat)
    if (DropData["Categories"][MType] == nil) then
        return MCat
    elseif (DropData["Categories"][MType][MCat] ~= nil) then
        return DropData["Categories"][MType][MCat].Alias
    else
        local mSets = DropData["Categories"][MType]
        for catCode, cat in Shared.skpairs(mSets) do
            if(cat.Name == MCat) then
                return cat.Alias
            end
        end
        return "INVALID"
    end
end
 
--Strictly speaking unnecessary
--But easier to read in the middle of other stuff
function p.getName(MType, MCat)
    if(MCat == nil) then
        MType, MCat = p.getMissionFromAlias(MType)
    else
        MCat = p.getCategoryName(MType, MCat)
    end
 
    if(cache.Name[MType..MCat] ~= nil) then
        return cache.Name[MType..MCat]
    end
 
    if(DropData["Categories"][MType] ~= nil and DropData["Categories"][MType][MCat] ~= nil) then
        cache.Name[MType..MCat] = DropData["Categories"][MType][MCat].Name
        return DropData["Categories"][MType][MCat].Name
    else
        DropData["Categories"][MType][MCat].Name = MCat
        return MCat
    end
end
 
function p.getShortName(MType, MCat)
    if(MCat == nil) then
        MType, MCat = p.getMissionFromAlias(MType)
    else
        MCat = p.getCategoryName(MType, MCat)
    end
    if(DropData["Categories"][MType] ~= nil and DropData["Categories"][MType][MCat] ~= nil) then
        if(DropData["Categories"][MType][MCat].ShortName == nil) then
            return DropData["Categories"][MType][MCat].Name
        else
            return '<span title="'..DropData["Categories"][MType][MCat].Name..'">'..DropData["Categories"][MType][MCat].ShortName..'</span>'
        end
    else
        return MCat
    end
end
 
function p.isSingleRot(MType, MCat)
    if(MCat == nil) then
        MType, MCat = p.getMissionFromAlias(MType)
    else
        MCat = p.getCategoryName(MType, MCat)
    end
 
    if(DropData["Categories"][MType] ~= nil and DropData["Categories"][MType][MCat] ~= nil) then
        if(DropData["Categories"][MType][MCat].SingleRot ~= nil) then
            return DropData["Categories"][MType][MCat].SingleRot
        end
    end
    return false
end
 
function p.linkType(MType)
    if(MType == "Salvage") then
        return "[[Infested Salvage|Salvage]]"
    else
        return "[["..MType.."]]"
    end
end
 
function p.getMissions(compareFunction)
    local data = {}
    for key, mission in Shared.skpairs(DropData["MissionDetails"]) do
        if(compareFunction(mission)) then
            table.insert(data, mission)
        end
    end
    return data
end
 
function p.getMissionsOfType(frame)
    local MType = frame.args ~= nil and frame.args[1] or frame
    local compFunc = function(mission) return mission.Type == MType end
 
    local data = p.getMissions(compFunc)
 
    local tHeader = '{| border="0" cellpadding="0" cellspacing="0" class="wikitable sortable" style="width: 600px;margin:auto;"'
    tHeader = tHeader..'\n|-\n!Planet'
    tHeader = tHeader..'\n!Mission Name'
    tHeader = tHeader..'\n!Faction'
    tHeader = tHeader..'\n! style="text-align:center" data-sort-type="number"|Level'
    local hasTier = false
    if(Shared.contains(tierTypes, MType)) then
        tHeader = tHeader..'\n! style="text-align:center" |Tier'
        hasTier = true
    end
 
    local compare = function(M1, M2) return M1.MinLevel < M2.MinLevel end
    table.sort(data, compare)
 
    local tBody = ''
    for i, mission in pairs(data) do
        tBody = tBody..'\n|-\n|[['..mission.Planet..']]||'..mission.Node..'||[['..mission.Enemy..']]'
        tBody = tBody..'||'..mission.MinLevel..' - '..mission.MaxLevel
        if(hasTier) then
            if(MType == "Capture") then
                --Capture is weird because not tied to rewards
                if(mission.MinLevel < 10) then
                    tBody = tBody..'||1'
                elseif(mission.MinLevel < 20) then
                    tBody = tBody..'||2'
                else
                    tBody = tBody..'||3'
                end
            else
                if(mission.Tier ~= nil) then
                    tBody = tBody..'||'..p.getName(mission.Tier)
                else
                    tBody = tBody..'||-'
                end
            end
        end
    end
 
    local result = tHeader..tBody
    result = result.."\n|+There are a total of "..Shared.tableCount(data).." "..p.linkType(MType).." Missions\n|}"
 
    return result
end
 
function p.getMissionsOnPlanet(frame)
    local Planet = frame.args ~= nil and frame.args[1] or frame
    local compFunc = function(mission) return mission.Planet == Planet end
 
    local data = p.getMissions(compFunc)
    local tHeader = ''
    tHeader = tHeader..'{| style="max-width:700px;margin:auto; text-align: center; background: #848484; color:#1C1C1C; font-size: 11px;"'      tHeader = tHeader..'cellpadding="3" cellspacing="2" |-'
    tHeader = tHeader..'\n! style="width:15%; background-color:#585858; font-size:12px; color:#FFFFFF;" | Target'
    tHeader = tHeader..'\n! style="width:20%; background-color:#585858; font-size:12px; color:#FFFFFF;" | Name'
    tHeader = tHeader..'\n! style="width:25%; background-color:#585858; font-size:12px; color:#FFFFFF;" | Type'
    tHeader = tHeader..'\n! style="width:15%; background-color:#585858; font-size:12px; color:#FFFFFF;" | Level'
    tHeader = tHeader..'\n! style="width:25%; background-color:#585858; font-size:12px; color:#FFFFFF;" | Tile Set'
 
    local tBody = ''
    local cellHeader1 = '\n| style="width:15%; background-color:#1C1C1C; font-size:12px; border:1px solid black;" |'
    local cellHeader2 = '\n| style="width:20%; background-color:#D8D8D8; font-size:12px; border:1px solid black;" |'
    local cellHeader3 = '\n| style="width:25%; background-color:#D8D8D8; font-size:12px; border:1px solid black;" |'
 
    for i, mission in pairs(data) do
        local img = nil
        if(mission.Enemy ~= nil and MissionData["FactionImages"][mission.Enemy] ~= nil) then
            img = MissionData["FactionImages"][mission.Enemy].MissionIcon
        end
        tBody = tBody..'\n|-'
        if(mission.Enemy ~= nil and img ~= nil) then
            tBody = tBody..cellHeader1..'[[File:'..img..'|link='..mission.Enemy..'|64px]]'
        else
            tBody = tBody..cellHeader1..'[[File:Panel.png|64px]]'
        end
        tBody = tBody..cellHeader2..mission.Node
        tBody = tBody..cellHeader2..p.linkType(mission.Type)
        tBody = tBody..cellHeader2..mission.MinLevel..' - '..mission.MaxLevel
        tBody = tBody..cellHeader3..mission.Tileset
 
        if(mission.Tier ~= nil) then
            tBody = tBody..'\n|-\n| colspan="5" |<div class="mw-collapsible mw-collapsed" style="width:100%;text-align:center;">'
            tBody = tBody.."'''Rewards'''"
            tBody = tBody..'\n<div class="mw-collapsible-content">'
 
            tBody = tBody..'\n</div></div>'
        end
    end
 
    local result = tHeader..tBody..'\n|}'
    return result
end
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.