Module:Monsters/Tables: Difference between revisions

From Melvor Idle
mNo edit summary
m (Only allow Normal Damage monsters to show in the Stormsnap table)
 
(18 intermediate revisions by 3 users not shown)
Line 1: Line 1:
p = {}
local p = {}
 
local MonsterData = mw.loadData('Module:Monsters/data')


local Shared = require('Module:Shared')
local GameData = require('Module:GameData')
local Monsters = require('Module:Monsters')
local Monsters = require('Module:Monsters')
local Shared = require('Module:Shared')
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')
local Items = require('Module:Items')
local Num = require('Module:Number')


function p.getFullStormsnapTable(frame)
function p.getFullStormsnapTable(frame)
  local monsterIDs = {}
--Making a single function for getting a table of monsters given a list of IDs.
  for i = 0, Shared.tableCount(MonsterData.Monsters) - 1, 1 do
local tableParts = {}
    table.insert(monsterIDs, i)
table.insert(tableParts, '{| class="wikitable sortable stickyHeader" style="width: 100%;"')
  end
 
  return p._getStormsnapTable(monsterIDs, false)
end
 
function p._getStormsnapTable(monsterIDs, excludeDungeons)
  --Making a single function for getting a table of monsters given a list of IDs.
  local hideDungeons = excludeDungeons ~= nil and excludeDungeons or false
  local tableParts = {}
  table.insert(tableParts, '{| class="wikitable sortable stickyHeader" style="width: 100%;"')


  table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n!Monster !!Name ')
table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n!Monster !!Name ')
  table.insert(tableParts, '!!style="padding:1 1em 0 0"|' .. Icons.Icon({'Magic', type='skill', notext=true}) .. ' Magic Level')
table.insert(tableParts, '!!style="padding:1 1em 0 0"|' .. Icons.Icon({'Magic', type='skill', notext=true}) .. ' Magic Level')
  table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Ranged', type='skill', notext=true}) .. ' Ranged Attack Bonus')
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Ranged', type='skill', notext=true}) .. ' Ranged Attack Bonus')
  table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Strength', type='skill', notext=true}) .. ' Ranged Strength Bonus')
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Strength', type='skill', notext=true}) .. ' Ranged Strength Bonus')




  -- Generate row per monster
-- Generate row per monster
  for i, monsterID in Shared.skpairs(monsterIDs) do
for i, monster in ipairs(GameData.rawData.monsters) do
    local monster = Monsters.getMonsterByID(monsterID)
if monster.damageType == nil or monster.damageType == 'melvorD:Normal' then
local magicLevel = Monsters._getMonsterLevel(monster, 'Magic')
local magicLevel = Monsters._getMonsterLevel(monster, 'Magic')
local rangedStrBonus = 111 + math.floor((6 * magicLevel)/33)
local rangedStrBonus = 111 + math.floor((6 * magicLevel)/33)
local rangedAttBonus = math.floor(102 * (1 + ((6 * magicLevel)/5500)))
local rangedAttBonus = math.floor(102 * (1 + ((6 * magicLevel)/5500)))
if magicLevel > 1 then
if magicLevel > 1 then
    table.insert(tableParts, '\r\n|-\r\n|style="text-align: center;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true}))
table.insert(tableParts, '\r\n|-\r\n|style="text-align: center;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true}))
    table.insert(tableParts, '\r\n|style="text-align:left" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))
table.insert(tableParts, '\r\n|style="text-align:left" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. magicLevel .. '" |' .. Shared.formatnum(magicLevel))
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. magicLevel .. '" |' .. Num.formatnum(magicLevel))
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. rangedAttBonus .. '" |' .. Shared.formatnum(rangedAttBonus))
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. rangedAttBonus .. '" |' .. Num.formatnum(rangedAttBonus))
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. rangedStrBonus .. '" |' .. Shared.formatnum(rangedStrBonus))
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. rangedStrBonus .. '" |' .. Num.formatnum(rangedStrBonus))
end
end
end
end
  end


  table.insert(tableParts, '\r\n|}')
table.insert(tableParts, '\r\n|}')
  return table.concat(tableParts)
return table.concat(tableParts)
end
end


function p.getFullMonsterTable(frame)
function p.getFullMonsterTable(frame)
  local monsterIDs = {}
return p._getMonsterTable(GameData.rawData.monsters, false)
  for i = 0, Shared.tableCount(MonsterData.Monsters) - 1, 1 do
    table.insert(monsterIDs, i)
  end
 
  return p._getMonsterTable(monsterIDs, false)
end
end


function p._getMonsterTable(monsterIDs, excludeDungeons)
function p._getMonsterTable(monsters, excludeDungeons)
  --Making a single function for getting a table of monsters given a list of IDs.
--Making a single function for getting a table of monsters given a list of IDs.
  local hideDungeons = excludeDungeons ~= nil and excludeDungeons or false
local hideDungeons = excludeDungeons ~= nil and excludeDungeons or false
  local tableParts = {}
local tableParts = {}
  table.insert(tableParts, '{| class="wikitable sortable stickyHeader" style="width: 100%;"')
table.insert(tableParts, '{| class="wikitable sortable stickyHeader"')
  -- First header row
-- First header row
  table.insert(tableParts, '\r\n|- class="headerRow-0"\r\n! colspan="5" | !! colspan="4" |Offensive Stats !! colspan="3" |Evasion Rating !! colspan="4" |')
table.insert(tableParts, '\r\n|- class="headerRow-0"\r\n! colspan="5" | !! colspan="4" |Offensive Stats !! colspan="3" |Evasion Rating !! colspan="4" |')
  -- Second header row
-- Second header row
  table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n! colspan="2"|Monster !!ID !!Combat Level ')
table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n!Monster !!Name !!ID !!Combat Level ')
  table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Hitpoints', type='skill'}))
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Hitpoints', type='skill'}))
  table.insert(tableParts, '!!Attack Type !!Attack Speed (s) !!Max Hit !!Accuracy ')
table.insert(tableParts, '!!Attack Speed (s) !!colspan="2"|Max Hit !!Accuracy ')
  table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Defence', type='skill', notext=true}))
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Defence', type='skill', notext=true}))
  table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Ranged', type='skill', notext=true}))
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Ranged', type='skill', notext=true}))
  table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Magic', type='skill', notext=true}))
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Magic', type='skill', notext=true}))
  table.insert(tableParts, '!!Drop Chance !!Coins !!Bones !!Locations')
table.insert(tableParts, '!!' .. Icons.Icon({'Coins', notext=true, nolink=true}) .. ' Coins !!Bones !!Locations')


  -- Generate row per monster
-- Generate row per monster
  for i, monsterID in Shared.skpairs(monsterIDs) do
for i, monster in ipairs(monsters) do
    local monster = Monsters.getMonsterByID(monsterID)
local cmbLevel = p._getMonsterCombatLevel(monster)
    local cmbLevel = Monsters._getMonsterCombatLevel(monster)
local atkSpeed = p._getMonsterAttackSpeed(monster)
    local atkSpeed = Monsters._getMonsterAttackSpeed(monster)
local maxHit = p._getMonsterMaxHit(monster)
    local maxHit = Monsters._getMonsterMaxHit(monster)
local accR = p._getMonsterAR(monster)
    local accR = Monsters._getMonsterAR(monster)
local evaR = {p._getMonsterER(monster, "Melee"), p._getMonsterER(monster, "Ranged"), p._getMonsterER(monster, "Magic")}
    local evaR = {Monsters._getMonsterER(monster, "Melee"), Monsters._getMonsterER(monster, "Ranged"), Monsters._getMonsterER(monster, "Magic")}


    local lootChance = monster.lootChance ~= nil and monster.lootChance or 100
local gpRange = {0, 0}
    local gpRange = {0, 0}
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then
    if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then
gpRange = {monster.dropCoins[1], monster.dropCoins[2]}
      gpRange = {monster.dropCoins[1], monster.dropCoins[2]}
end
    end
local gpTxt = nil
    local gpTxt = nil
if monster.gpDrops.min >= monster.gpDrops.max then
    if gpRange[1] >= gpRange[2] then
gpTxt = Num.formatnum(monster.gpDrops.min)
      gpTxt = Icons.GP(gpRange[1])
else
    else
gpTxt = Num.formatnum(monster.gpDrops.min) .. ' - ' .. Num.formatnum(monster.gpDrops.max)
      gpTxt = Icons.GP(gpRange[1], gpRange[2])
end
    end
local bones = p._getMonsterBones(monster)
    local boneTxt = 'None'
local boneTxt = (bones ~= nil and Icons.Icon({bones.item.name, type='item', notext=true})) or 'None'
    if monster.bones ~= nil and monster.bones >= 0 then
      local bones = Items.getItemByID(monster.bones)
      boneTxt = Icons.Icon({bones.name, type='item', notext=true})
    end


    table.insert(tableParts, '\r\n|-\r\n|style="text-align: center; border-width: 0px;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true}))
table.insert(tableParts, '\r\n|-\r\n|style="text-align: center;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true}))
    table.insert(tableParts, '\r\n|style="text-align:left border-left-width: 0px;" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))
table.insert(tableParts, '\r\n|style="text-align:left" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))
    table.insert(tableParts, '\r\n|style="text-align:right" |' .. monsterID)
table.insert(tableParts, '\r\n|style="text-align:right" |' .. monster.id)
    table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. cmbLevel .. '" |' .. Shared.formatnum(cmbLevel))
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. cmbLevel .. '" |' .. Num.formatnum(cmbLevel))
    table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. Monsters._getMonsterHP(monster) .. '" |' .. Shared.formatnum(Monsters._getMonsterHP(monster)))
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. p._getMonsterHP(monster) .. '" |' .. Num.formatnum(p._getMonsterHP(monster)))
    table.insert(tableParts, '\r\n|style="text-align:center" |' .. Monsters._getMonsterStyleIcon({monster, notext=true}))
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. atkSpeed .. '" |' .. Num.round(atkSpeed, 1, 1))
    table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. atkSpeed .. '" |' .. Shared.round(atkSpeed, 1, 1))
table.insert(tableParts, '\r\n|style="text-align:center;border-right:hidden" |' .. p._getMonsterStyleIcon({monster, notext=true}))
    table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. maxHit .. '" |' .. Shared.formatnum(maxHit))
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. maxHit .. '" |' .. Num.formatnum(maxHit))
    table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. accR .. '" |' .. Shared.formatnum(accR))
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. accR .. '" |' .. Num.formatnum(accR))
    table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[1] .. '" |' .. Shared.formatnum(evaR[1]))
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[1] .. '" |' .. Num.formatnum(evaR[1]))
    table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[2] .. '" |' .. Shared.formatnum(evaR[2]))
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[2] .. '" |' .. Num.formatnum(evaR[2]))
    table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[3] .. '" |' .. Shared.formatnum(evaR[3]))
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[3] .. '" |' .. Num.formatnum(evaR[3]))
    table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. lootChance .. '" |' .. lootChance .. '%')
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. (monster.gpDrops.min + monster.gpDrops.max) / 2 .. '" |' .. gpTxt)
    table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)
table.insert(tableParts, '\r\n|style="text-align:center" |' .. boneTxt)
    table.insert(tableParts, '\r\n|style="text-align:center" |' .. boneTxt)
table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))
    table.insert(tableParts, '\r\n|style="text-align:right;white-space:nowrap" |' .. Monsters._getMonsterAreas(monster, hideDungeons))
end
  end


  table.insert(tableParts, '\r\n|}')
table.insert(tableParts, '\r\n|}')
  return table.concat(tableParts)
return table.concat(tableParts)
end
end


return p
return p

Latest revision as of 23:52, 27 October 2024

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

local p = {}

local Shared = require('Module:Shared')
local GameData = require('Module:GameData')
local Monsters = require('Module:Monsters')
local Icons = require('Module:Icons')
local Num = require('Module:Number')

function p.getFullStormsnapTable(frame)
	--Making a single function for getting a table of monsters given a list of IDs.
	local tableParts = {}
	table.insert(tableParts, '{| class="wikitable sortable stickyHeader" style="width: 100%;"')

	table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n!Monster !!Name ')
	table.insert(tableParts, '!!style="padding:1 1em 0 0"|' .. Icons.Icon({'Magic', type='skill', notext=true}) .. ' Magic Level')
	table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Ranged', type='skill', notext=true}) .. ' Ranged Attack Bonus')
	table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Strength', type='skill', notext=true}) .. ' Ranged Strength Bonus')


	-- Generate row per monster
	for i, monster in ipairs(GameData.rawData.monsters) do
		if monster.damageType == nil or monster.damageType == 'melvorD:Normal' then
			local magicLevel = Monsters._getMonsterLevel(monster, 'Magic')
			local rangedStrBonus = 111 + math.floor((6 * magicLevel)/33)
			local rangedAttBonus = math.floor(102 * (1 + ((6 * magicLevel)/5500)))
		
			if magicLevel > 1 then
				table.insert(tableParts, '\r\n|-\r\n|style="text-align: center;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true}))
				table.insert(tableParts, '\r\n|style="text-align:left" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))
				table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. magicLevel .. '" |' .. Num.formatnum(magicLevel))
				table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. rangedAttBonus .. '" |' .. Num.formatnum(rangedAttBonus))
				table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. rangedStrBonus .. '" |' .. Num.formatnum(rangedStrBonus))
			end
		end
	end

	table.insert(tableParts, '\r\n|}')
	return table.concat(tableParts)
end

function p.getFullMonsterTable(frame)
	return p._getMonsterTable(GameData.rawData.monsters, false)
end

function p._getMonsterTable(monsters, excludeDungeons)
	--Making a single function for getting a table of monsters given a list of IDs.
	local hideDungeons = excludeDungeons ~= nil and excludeDungeons or false
	local tableParts = {}
	table.insert(tableParts, '{| class="wikitable sortable stickyHeader"')
	-- First header row
	table.insert(tableParts, '\r\n|- class="headerRow-0"\r\n! colspan="5" | !! colspan="4" |Offensive Stats !! colspan="3" |Evasion Rating !! colspan="4" |')
	-- Second header row
	table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n!Monster !!Name !!ID !!Combat Level ')
	table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Hitpoints', type='skill'}))
	table.insert(tableParts, '!!Attack Speed (s) !!colspan="2"|Max Hit !!Accuracy ')
	table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Defence', type='skill', notext=true}))
	table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Ranged', type='skill', notext=true}))
	table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Magic', type='skill', notext=true}))
	table.insert(tableParts, '!!' .. Icons.Icon({'Coins', notext=true, nolink=true}) .. ' Coins !!Bones !!Locations')

	-- Generate row per monster
	for i, monster in ipairs(monsters) do
		local cmbLevel = p._getMonsterCombatLevel(monster)
		local atkSpeed = p._getMonsterAttackSpeed(monster)
		local maxHit = p._getMonsterMaxHit(monster)
		local accR = p._getMonsterAR(monster)
		local evaR = {p._getMonsterER(monster, "Melee"), p._getMonsterER(monster, "Ranged"), p._getMonsterER(monster, "Magic")}

		local gpRange = {0, 0}
		if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then
			gpRange = {monster.dropCoins[1], monster.dropCoins[2]}
		end
		local gpTxt = nil
		if monster.gpDrops.min >= monster.gpDrops.max then
			gpTxt = Num.formatnum(monster.gpDrops.min)
		else
			gpTxt = Num.formatnum(monster.gpDrops.min) .. ' - ' .. Num.formatnum(monster.gpDrops.max)
		end
		local bones = p._getMonsterBones(monster)
		local boneTxt = (bones ~= nil and Icons.Icon({bones.item.name, type='item', notext=true})) or 'None'

		table.insert(tableParts, '\r\n|-\r\n|style="text-align: center;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true}))
		table.insert(tableParts, '\r\n|style="text-align:left" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))
		table.insert(tableParts, '\r\n|style="text-align:right" |' .. monster.id)
		table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. cmbLevel .. '" |' .. Num.formatnum(cmbLevel))
		table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. p._getMonsterHP(monster) .. '" |' .. Num.formatnum(p._getMonsterHP(monster)))
		table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. atkSpeed .. '" |' .. Num.round(atkSpeed, 1, 1))
		table.insert(tableParts, '\r\n|style="text-align:center;border-right:hidden" |' .. p._getMonsterStyleIcon({monster, notext=true}))
		table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. maxHit .. '" |' .. Num.formatnum(maxHit))
		table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. accR .. '" |' .. Num.formatnum(accR))
		table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[1] .. '" |' .. Num.formatnum(evaR[1]))
		table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[2] .. '" |' .. Num.formatnum(evaR[2]))
		table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[3] .. '" |' .. Num.formatnum(evaR[3]))
		table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. (monster.gpDrops.min + monster.gpDrops.max) / 2 .. '" |' .. gpTxt)
		table.insert(tableParts, '\r\n|style="text-align:center" |' .. boneTxt)
		table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))
	end

	table.insert(tableParts, '\r\n|}')
	return table.concat(tableParts)
end

return p