Module:Monsters: Difference between revisions

_getMonsterTable: Optimise by using table.concat() instead of repeated string concatenation
(Added p.getOtherMonsterBoxText)
(_getMonsterTable: Optimise by using table.concat() instead of repeated string concatenation)
Line 980: Line 980:
   --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 tableTxt = '{| class="wikitable sortable stickyHeader"'
   local tableParts = {}
  table.insert(tableParts, '{| class="wikitable sortable stickyHeader"')
   -- First header row
   -- First header row
   tableTxt = tableTxt .. '\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
   tableTxt = tableTxt .. '\r\n|- class="headerRow-1"\r\n!Monster !!Name !!ID !!Combat Level '
   table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n!Monster !!Name !!ID !!Combat Level ')
   tableTxt = tableTxt .. '!!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'}))
   tableTxt = tableTxt .. '!!Attack Type !!Attack Speed (s) !!Max Hit !!Accuracy '
   table.insert(tableParts, '!!Attack Type !!Attack Speed (s) !!Max Hit !!Accuracy ')
   tableTxt = tableTxt .. '!!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}))
   tableTxt = tableTxt .. '!!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}))
   tableTxt = tableTxt .. '!!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}))
   tableTxt = tableTxt .. '!!Drop Chance !!Coins !!Bones !!Locations'
   table.insert(tableParts, '!!Drop Chance !!Coins !!Bones !!Locations')


   -- Generate row per monster
   -- Generate row per monster
Line 1,017: Line 1,018:
     end
     end


     tableTxt = tableTxt .. '\r\n|-\r\n|style="text-align: left;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true})
     table.insert(tableParts, '\r\n|-\r\n|style="text-align: left;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true}))
     tableTxt = tableTxt .. '\r\n|style="text-align:left" |[[' .. monster.name .. ']]'
     table.insert(tableParts, '\r\n|style="text-align:left" |[[' .. monster.name .. ']]')
     tableTxt = tableTxt .. '\r\n|style="text-align:right" |' .. monsterID
     table.insert(tableParts, '\r\n|style="text-align:right" |' .. monsterID)
     tableTxt = tableTxt .. '\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 .. '" |' .. Shared.formatnum(cmbLevel))
     tableTxt = tableTxt .. '\r\n|style="text-align:right" data-sort-value="' .. monster.hitpoints .. '" |' .. Shared.formatnum(p._getMonsterHP(monster))
     table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. monster.hitpoints .. '" |' .. Shared.formatnum(p._getMonsterHP(monster)))
     tableTxt = tableTxt .. '\r\n|style="text-align:right;white-space:nowrap" |' .. p._getMonsterStyleIcon({monster, nolink='true'})
     table.insert(tableParts, '\r\n|style="text-align:right;white-space:nowrap" |' .. p._getMonsterStyleIcon({monster, nolink='true'}))
     tableTxt = tableTxt .. '\r\n|style="text-align:right" data-sort-value="' .. atkSpeed .. '" |' .. Shared.round(atkSpeed, 1, 1)
     table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. atkSpeed .. '" |' .. Shared.round(atkSpeed, 1, 1))
     tableTxt = tableTxt .. '\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 .. '" |' .. Shared.formatnum(maxHit))
     tableTxt = tableTxt .. '\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 .. '" |' .. Shared.formatnum(accR))
     tableTxt = tableTxt .. '\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] .. '" |' .. Shared.formatnum(evaR[1]))
     tableTxt = tableTxt .. '\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] .. '" |' .. Shared.formatnum(evaR[2]))
     tableTxt = tableTxt .. '\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] .. '" |' .. Shared.formatnum(evaR[3]))
     tableTxt = tableTxt .. '\r\n|style="text-align:right" data-sort-value="' .. lootChance .. '" |' .. lootChance .. '%'
     table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. lootChance .. '" |' .. lootChance .. '%')
     tableTxt = tableTxt .. '\r\n|style="text-align:right" data-sort-value="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt
     table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)
     tableTxt = tableTxt .. '\r\n|style="text-align:center" |' .. boneTxt
     table.insert(tableParts, '\r\n|style="text-align:center" |' .. boneTxt)
     tableTxt = tableTxt .. '\r\n|style="text-align:right;white-space:nowrap" |' .. p._getMonsterAreas(monster, hideDungeons)
     table.insert(tableParts, '\r\n|style="text-align:right;white-space:nowrap" |' .. p._getMonsterAreas(monster, hideDungeons))
   end
   end


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


return p
return p