Module:Monster

From MapleStory 2 Wiki
Jump to: navigation, search

Documentation for this module may be created at Module:Monster/doc

local p = require('Module:Data')
local util    = require('Module:Util')

function p.row( frame )
    local data = p._getData( p._getSubject( frame ) )
    local row = mw.html.create( 'tr' )
    row:tag( 'td' ):wikitext( data.thumbnail )
    row:tag( 'td' ):wikitext( "[[" .. data.name .. "]]" )
    row:tag( 'td' ):wikitext( data.korean )
    row:tag( 'td' ):wikitext( data.level )
    row:tag( 'td' ):wikitext( data.hp)
    row:tag( 'td' ):wikitext( data.experience )
    row:tag( 'td' ):wikitext( data.defense )
    row:tag( 'td' ):wikitext( data.physical_attack )
    row:tag( 'td' ):wikitext( data.magic_attack )
    return tostring( row )
end

function p._list( list )
    if not list or list == "" then return "" end
    local ul = mw.html.create( 'ul' )
    for item in mw.text.gsplit( list, ",", true ) do
        ul:tag( 'li' ):wikitext( item )
    end
    return ul
end

function p.dropList( frame )
    local data = p._getData( p._getSubject( frame ) )
    return tostring( p._list( data.drop ) )
end

function p.mapList( frame )
    local data = p._getData( p._getSubject( frame ) )
    return tostring( p._list( data.map ) )
end

function p.questList( frame )
    local data = p._getData( p._getSubject( frame ) )
    return tostring( p._list( data.quest ) )
end

function p.spawnTimeList( frame )
    local data = p._getData( p._getSubject( frame ) )
    return tostring( p._list( data.spawn ) )
end

function p._allLists( data )
    local drops = p._list( data.drop )
    local maps = p._list( data.map )
    local quests = p._list( data.quest )
    local spawnTime = p._list( data.spawn )
    return  mw.html.create( 'table' )
        :addClass( 'wikitable' )
        :tag( 'tr' )
            :tag( 'th' ):wikitext( "Drops" ):done()
            :tag( 'th' ):wikitext( "Spawn Time" ):allDone()
        :tag( 'tr' )
            :tag( 'td' ):node( drops ):done()
            :tag( 'td' ):node( spawnTime):allDone()
end

function p.allLists( frame )
    local data = p._getData( p._getSubject( frame ) )
    return tostring( p._allLists( data ) )
end

function p._getInlineTooltip( data )
    local tt = {}
    if data.level then table.insert( tt, data.level ) end
    if data.category then table.insert( tt, data.category ) end
    tt = table.concat( tt, " " )
    return tt ~= "" and tt
end

function p._getInfoboxArgs( data )
    return {
        title = data.name or "?", 
        image = data.thumbnail,
        label1 = "Korean Name",       data1 = data.korean or "?",
        label2 = "Level",             data2 = data.level or "?",
        label3 = "Attack (Magic)",    data3 = data.physical_attack or "?",
        label4 = "Attack (Physical)", data4 = data.magic_attack or "?",
        label5 = "Defense",           data5 = data.defense or "?",
        label6 = "HP",                data6 = data.hp or "?",
        label7 = "Experience",        data7 = data.experience or "?",
        label8 = "Location",          data8 = data.map or "?",
        label9 = "Maview ID",         data9 = util.getMaviewURL("//maview.nexon.com/Encyclopedia/MonsterView?c=", data.maview_id),

    }
end

function p._getCategories( data )
    local category = util.getDummyValueIfEmpty(data.category)

    action = {
        ['Mob']            = "Mobs",
        ['Mobs']           = "Mobs",
        ['Elite']          = "Elite Monsters",
        ['Elite Monsters'] = "Elite Monsters",
        ['Boss']           = "Bosses",
        ['Bosses']         = "Bosses",
    }

    util.setDefault(action, "Unknown Category")
    local subCategory = action[category]

    local level = util.isNaN(data.level) and 1 or data.level
    local monsterLevelCategory = p.getMonsterLevelCategory(level)

    return { "Monsters", monsterLevelCategory, subCategory }
end

function p._getTableHeadings()
    return {
        { "Icon", class = "unsortable" },
        "Name",
        "Korean Name",
        "Level",
        "HP",
        "EXP",
        "P.ATK",
        "M.ATK",
        "DEF"
    }
end

function p._getRowData( data )
    return {
        data.thumbnail,
        "[[" .. data.name .. "]]",
        util.getDummyValueIfEmpty( data.korean ),
        util.getDummyValueIfEmpty( data.level ),
        util.getDummyValueIfEmpty( data.hp ),
        util.getDummyValueIfEmpty( data.experience ),
        util.getDummyValueIfEmpty( data.physical_attack ),
        util.getDummyValueIfEmpty( data.magic_attack ),
        util.getDummyValueIfEmpty( data.defense )
    }
end

function p._catTableSort( a, b )
    return a.level < b.level
end

function p.getMonsterLevelCategory(level)
    --Note1: Sets level to 1 as default if level is below 1.
    --Note2: Fixes issue with input level 10 (with zero digit) --> Before: 10 -> Level 11-20 | After: 10 -> Level 1-10
    local level = level - 1 < 1 and 1 or level - 1 --See Note1 and Note2
    local baseLevel = math.floor(level / 10) * 10
    local minLevel = baseLevel + 1
    local maxLevel = baseLevel + 10
    return "Level " .. minLevel .. "-" .. maxLevel .. " Monsters"
end

function p.getEditDataURL(frame) 
    return util.getEditDataURL(frame)
end

return p