FANDOM


u = require("Module:Util")
c = require("Module:Combat")
db = require("Module:Enemy_DB")
lt = require("Module:Loot_Table")
 
local p = {}
 
function round(n)
    return n + 0.5 - (n + 0.5) % 1
end
 
function p.enemy_table(enemy)
    result = [[]]
    for _, e in ipairs(enemy[7]) do
        -- TODO: refactor 1 - 1 -> 1 conversion to loot table module if possible
        result = result .. lt.ltr({args= {e[1], (e[2] == e[3] and u.c(e[2]) or (u.c(e[2]) .. ' - ' .. u.c(e[3]))), e[4], e[6], e[5] and enemy[2], image=e['image']}})
    end
    return lt.lt({args= {result, area=enemy[2]}}) .. [[
 
]]
end
 
function p.enemy_stats(enemy)
    return [[{| class="article-table"
!Enemy
]] .. '![[File: HeartIcon.png|20px]]\n![[File: Attack.png|20px]]\n![[File: Accuracy.png|20px]]\n![[File: Defence.png|20px]]' .. [[
 
|-
|]] .. '[[' .. [[File: ]] .. (enemy['raw_image'] and enemy['raw_image'] or ((enemy['image'] or enemy[1]:gsub(' ', ''):gsub('%(', ''):gsub('%)', '')) .. 'Monster.png')) .. [[|40px|link=]] .. enemy[1] .. ']]' .. [[
 
|]] .. enemy[3] .. [[
 
|]] .. enemy[4] .. [[
 
|]] .. enemy[5] .. [[
 
|]] .. enemy[6] .. [[
 
|}
]] .. p.enemy_table(enemy)
end
 
function p.enemy_zone_tabber(enemies)
    result = [[{{#tag:tabber|
]]
    for _, e in ipairs(enemies) do
        result = result .. e[1] .. [[=
]] .. p.enemy_stats(e):gsub('|', '{{!}}') .. [[
{{!}}-{{!}}
]]
    end
    return result:sub(1, -13) .. [[}}
]]
end
 
function p.enemy_all_tabber()
    result = [[<tabber>
]]
    area = [[]]
    enemies = {}
    for _, e in ipairs(db) do
        if e[2] ~= area and area ~= [[]] then
            result = result .. area .. [[=
]] .. p.enemy_zone_tabber(enemies) .. [[|-|
]]
            enemies = {}
        end
        table.insert(enemies, e)
        area = e[2]
    end
    return result .. area .. [[=
]] .. p.enemy_zone_tabber(enemies) .. [[</tabber>
]]
end
 
function p.enemy_page_before(name)
    enemy = nil
    if type(name) == 'table' then
        enemy = name
        name = name[1]
    else
        for _, e in ipairs(db) do
            if e[1] == name then
                enemy = e
                break
            end
        end
    end
    return [[
<div style="float:right; width:280px; padding-left: 35px;">
{{Infobox Monster
| title= ]] .. enemy[1] .. [[
 
| image= ]] .. (enemy['raw_image'] and enemy['raw_image'] or ((enemy['image'] or enemy[1]:gsub(' ', ''):gsub('%(', ''):gsub('%)', '')) .. 'Monster.png'))  .. [[
 
| imagewidth= 90
| hp= ]] .. enemy[3] .. [[
 
| attack= ]] .. enemy[4] .. [[
 
| accuracy= ]] .. enemy[5] .. [[
 
| defense= ]] .. enemy[6] .. [[
 
| areas= ]] .. enemy[2] .. [[
}}
</div>
]] .. c.enemy_combat_info(name)
end
 
function p.enemy_page_after(name)
    enemy = nil
    if type(name) == 'table' then
        enemy = name
        name = name[1]
    else
        for _, e in ipairs(db) do
            if e[1] == name then
                enemy = e
                break
            end
        end
    end
    return [[{{Navbox Monsters}}
 
]] .. '[[Category:' .. enemy[2] .. ']] [[Category:Enemies]]' .. [[
 
]]
end
 
function p.enemy_page(name)
    enemy = nil
    for _, e in ipairs(db) do
        if e[1] == name then
            enemy = e
            break
        end
    end
    return p.enemy_page_before(enemy) .. [[
== Loot == 
]] .. p.enemy_table(enemy) .. p.enemy_page_after(enemy)
end
 
function p.tep(frame)
    return p.enemy_page(frame.args[1] or frame:getParent():getTitle())
end
function p.tepb(frame)
    return p.enemy_page_before(frame.args[1] or frame:getParent():getTitle())
end
function p.tepa(frame)
    return p.enemy_page_after(frame.args[1] or frame:getParent():getTitle())
end
 
function p.tet(frame)
    name = frame.args[1] or frame:getParent():getTitle()
    for _, e in ipairs(db) do
        if e[1] == name then
            return [[
== Loot == 
]] .. p.enemy_table(e)
        end
    end
end
 
function p.tes(frame)
    name = frame.args[1] or frame:getParent():getTitle()
    for _, e in ipairs(db) do
        if e[1] == name then
            return p.enemy_stats(e)
        end
    end
end
 
return p
Community content is available under CC-BY-SA unless otherwise noted.