https://wiki.melvoridle.com/api.php?action=feedcontributions&user=Roko&feedformat=atom
Melvor Idle - User contributions [en]
2024-03-28T23:15:44Z
User contributions
MediaWiki 1.39.3
https://wiki.melvoridle.com/index.php?title=Generous_Resupply&diff=51151
Generous Resupply
2022-02-21T21:23:08Z
<p>Roko: </p>
<hr />
<div>{{V}}{{PurchaseBox}}<br />
{{Main|Reference=Shop}}<br />
A '''{{PAGENAME}}''' can be purchased from the [[Shop]] for {{#invoke:Shop|getPurchaseStat|{{PAGENAME}}|cost|inline=true}}. Purchasing requires {{#invoke:Shop|getPurchaseStat|{{PAGENAME}}|requirements}}.<br />
<br />
== Contents ==<br />
{{#invoke:Shop|getPurchaseContents|{{PAGENAME}}}}<br />
<br />
Once purchased, these items will be added to the {{Icon|Bank Slot|type=upgrade|Bank}}. Total gold value is {{GP|483800}}.<br />
<br />
== See Also ==<br />
* {{ItemIcon|Basic Resupply}}<br />
* {{ItemIcon|Standard Resupply}}<br />
<br />
[[Category:Misc]]</div>
Roko
https://wiki.melvoridle.com/index.php?title=Standard_Resupply&diff=51150
Standard Resupply
2022-02-21T21:22:47Z
<p>Roko: </p>
<hr />
<div>{{V}}{{PurchaseBox}}<br />
{{Main|Reference=Shop}}<br />
A '''{{PAGENAME}}''' can be purchased from the [[Shop]] for {{#invoke:Shop|getPurchaseStat|{{PAGENAME}}|cost|inline=true}}. Purchasing requires {{#invoke:Shop|getPurchaseStat|{{PAGENAME}}|requirements}}.<br />
<br />
== Contents ==<br />
{{#invoke:Shop|getPurchaseContents|{{PAGENAME}}}}<br />
<br />
Once purchased, these items will be added to the {{Icon|Bank Slot|type=upgrade|Bank}}. Total gold value is {{GP|221500}}.<br />
<br />
== See Also ==<br />
* {{ItemIcon|Basic Resupply}}<br />
* {{ItemIcon|Generous Resupply}}<br />
<br />
[[Category:Misc]]</div>
Roko
https://wiki.melvoridle.com/index.php?title=Basic_Resupply&diff=51149
Basic Resupply
2022-02-21T21:22:21Z
<p>Roko: </p>
<hr />
<div>{{V}}{{PurchaseBox}}<br />
{{Main|Reference=Shop}}<br />
A '''{{PAGENAME}}''' can be purchased from the [[Shop]] for {{#invoke:Shop|getPurchaseStat|{{PAGENAME}}|cost|inline=true}}. <br />
<br />
== Contents ==<br />
{{#invoke:Shop|getPurchaseContents|{{PAGENAME}}}}<br />
<br />
Once purchased, these items will be added to the {{Icon|Bank Slot|type=upgrade|Bank}}. The total gold value is {{GP|91600}}.<br />
<br />
== See Also ==<br />
* {{ItemIcon|Standard Resupply}}<br />
* {{ItemIcon|Generous Resupply}}<br />
<br />
[[Category:Misc]]</div>
Roko
https://wiki.melvoridle.com/index.php?title=Generous_Resupply&diff=51148
Generous Resupply
2022-02-21T21:20:08Z
<p>Roko: </p>
<hr />
<div>{{V}}{{PurchaseBox}}<br />
{{Main|Reference=Shop}}<br />
A '''{{PAGENAME}}''' can be purchased from the [[Shop]] for {{#invoke:Shop|getPurchaseStat|{{PAGENAME}}|cost|inline=true}}. Purchasing requires {{#invoke:Shop|getPurchaseStat|{{PAGENAME}}|requirements}}.<br />
<br />
== Contents ==<br />
{{#invoke:Shop|getPurchaseContents|{{PAGENAME}}}}<br />
<br />
Once purchased, these items will be added to the {{Icon|Bank Slot|type=upgrade|Bank}}. Total gold value is 483800.<br />
<br />
== See Also ==<br />
* {{ItemIcon|Basic Resupply}}<br />
* {{ItemIcon|Standard Resupply}}<br />
<br />
[[Category:Misc]]</div>
Roko
https://wiki.melvoridle.com/index.php?title=Standard_Resupply&diff=51147
Standard Resupply
2022-02-21T21:17:57Z
<p>Roko: </p>
<hr />
<div>{{V}}{{PurchaseBox}}<br />
{{Main|Reference=Shop}}<br />
A '''{{PAGENAME}}''' can be purchased from the [[Shop]] for {{#invoke:Shop|getPurchaseStat|{{PAGENAME}}|cost|inline=true}}. Purchasing requires {{#invoke:Shop|getPurchaseStat|{{PAGENAME}}|requirements}}.<br />
<br />
== Contents ==<br />
{{#invoke:Shop|getPurchaseContents|{{PAGENAME}}}}<br />
<br />
Once purchased, these items will be added to the {{Icon|Bank Slot|type=upgrade|Bank}}. Total gold value is 221500.<br />
<br />
== See Also ==<br />
* {{ItemIcon|Basic Resupply}}<br />
* {{ItemIcon|Generous Resupply}}<br />
<br />
[[Category:Misc]]</div>
Roko
https://wiki.melvoridle.com/index.php?title=Basic_Resupply&diff=51145
Basic Resupply
2022-02-21T20:45:25Z
<p>Roko: Calculated gold value by hand.</p>
<hr />
<div>{{V}}{{PurchaseBox}}<br />
{{Main|Reference=Shop}}<br />
A '''{{PAGENAME}}''' can be purchased from the [[Shop]] for {{#invoke:Shop|getPurchaseStat|{{PAGENAME}}|cost|inline=true}}. <br />
<br />
== Contents ==<br />
{{#invoke:Shop|getPurchaseContents|{{PAGENAME}}}}<br />
<br />
Once purchased, these items will be added to the {{Icon|Bank Slot|type=upgrade|Bank}}. The total gold value is 91600.<br />
<br />
== See Also ==<br />
* {{ItemIcon|Standard Resupply}}<br />
* {{ItemIcon|Generous Resupply}}<br />
<br />
[[Category:Misc]]</div>
Roko
https://wiki.melvoridle.com/index.php?title=Module:Monsters&diff=51094
Module:Monsters
2022-02-19T13:38:58Z
<p>Roko: </p>
<hr />
<div>local p = {}<br />
<br />
local MonsterData = mw.loadData('Module:Monsters/data')<br />
<br />
local Constants = require('Module:Constants')<br />
local Areas = require('Module:CombatAreas')<br />
local Magic = require('Module:Magic')<br />
local Shared = require('Module:Shared')<br />
local Icons = require('Module:Icons')<br />
local Items = require('Module:Items')<br />
<br />
function p.getMonster(name)<br />
local result = nil<br />
if name == 'Spider (lv. 51)' or name == 'Spider' then<br />
return p.getMonsterByID(50)<br />
elseif name == 'Spider (lv. 52)' or name == 'Spider2' then<br />
return p.getMonsterByID(51)<br />
end<br />
<br />
for i, monster in pairs(MonsterData.Monsters) do<br />
if monster.name == name then<br />
result = Shared.clone(monster)<br />
--Make sure every monster has an ID, and account for the 1-based indexing of Lua<br />
result.id = i - 1<br />
break<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.getMonsterByID(ID)<br />
local result = Shared.clone(MonsterData.Monsters[ID + 1])<br />
if result ~= nil then<br />
result.id = ID<br />
return result<br />
else<br />
return nil<br />
end<br />
end<br />
<br />
function p.getPassive(name)<br />
local result = nil<br />
<br />
for i, passive in pairs(MonsterData.Passives) do<br />
if passive.name == name then<br />
result = Shared.clone(passive)<br />
--Make sure every passive has an ID, and account for the 1-based indexing of Lua<br />
result.id = i - 1<br />
break<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.getPassiveByID(ID)<br />
return MonsterData.Passives[ID + 1]<br />
end<br />
<br />
-- Given a list of monster IDs, calls statFunc with each monster and returns<br />
-- the lowest & highest values<br />
function p.getLowHighStat(idList, statFunc)<br />
local lowVal, highVal = nil, nil<br />
for i, monID in ipairs(idList) do<br />
local monster = p.getMonsterByID(monID)<br />
local statVal = statFunc(monster)<br />
if lowVal == nil or statVal < lowVal then lowVal = statVal end<br />
if highVal == nil or statVal > highVal then highVal = statVal end<br />
end<br />
return lowVal, highVal<br />
end<br />
<br />
function p._getMonsterStat(monster, statName)<br />
if statName == 'HP' then<br />
return p._getMonsterHP(monster)<br />
elseif statName == 'maxHit' then<br />
return p._getMonsterMaxHit(monster)<br />
elseif statName == 'accuracyRating' then<br />
return p._getMonsterAR(monster)<br />
elseif statName == 'meleeEvasionRating' then<br />
return p._getMonsterER(monster, 'Melee')<br />
elseif statName == 'rangedEvasionRating' then<br />
return p._getMonsterER(monster, 'Ranged')<br />
elseif statName == 'magicEvasionRating' then<br />
return p._getMonsterER(monster, 'Magic')<br />
elseif statName == 'damageReduction' then<br />
return p.getEquipmentStat(monster, 'damageReduction')<br />
end<br />
<br />
return monster[statName]<br />
end<br />
<br />
function p.getMonsterStat(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame[1]<br />
local StatName = frame.args ~= nil and frame.args[2] or frame[2]<br />
local monster = p.getMonster(MonsterName)<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterStat(monster, StatName)<br />
end<br />
<br />
function p._getMonsterStyleIcon(frame)<br />
local args = frame.args ~= nil and frame.args or frame<br />
local monster = args[1]<br />
local notext = args.notext<br />
local nolink = args.nolink<br />
<br />
local iconText = ''<br />
if monster.attackType == 'melee' then<br />
iconText = Icons.Icon({'Melee', notext=notext, nolink=nolink})<br />
elseif monster.attackType == 'ranged' then<br />
iconText = Icons.Icon({'Ranged', type='skill', notext=notext, nolink=nolink})<br />
elseif monster.attackType == 'magic' then<br />
iconText = Icons.Icon({'Magic', type='skill', notext=notext, nolink=nolink})<br />
elseif monster.attackType == 'random' then<br />
iconText = Icons.Icon({'Bane', notext=notext, nolink=nolink, img='Question'})<br />
end<br />
<br />
return iconText<br />
end<br />
<br />
function p.getMonsterStyleIcon(frame)<br />
local args = frame.args ~= nil and frame.args or frame<br />
local MonsterName = args[1]<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
args[1] = monster<br />
return p._getMonsterStyleIcon(args)<br />
end<br />
<br />
function p._getMonsterHP(monster)<br />
return 10 * p._getMonsterLevel(monster, 'Hitpoints')<br />
end<br />
<br />
function p.getMonsterEffectiveHP(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
if monster ~= nil then<br />
return math.floor((p._getMonsterHP(monster)/(1 - p._getMonsterStat(monster, 'damageReduction')/100)) + 0.5)<br />
else<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
end<br />
<br />
function p.getMonsterHP(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
if monster ~= nil then<br />
return p._getMonsterHP(monster)<br />
else<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
end<br />
<br />
function p._getMonsterLevel(monster, skillName)<br />
local result = 0<br />
if monster.levels[skillName] ~= nil then<br />
result = monster.levels[skillName]<br />
end<br />
return result<br />
end<br />
<br />
function p.getMonsterLevel(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame[1]<br />
local SkillName = frame.args ~= nil and frame.args[2] or frame[2]<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterLevel(monster, SkillName)<br />
end<br />
<br />
function p.getEquipmentStat(monster, statName)<br />
local result = 0<br />
for i, stat in Shared.skpairs(monster.equipmentStats) do<br />
if stat.key == statName then<br />
result = stat.value<br />
break<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.calculateStandardStat(effectiveLevel, bonus)<br />
--Based on calculateStandardStat in Characters.js<br />
return (effectiveLevel + 9) * (bonus + 64)<br />
end<br />
<br />
function p.calculateStandardMaxHit(baseLevel, strengthBonus)<br />
--Based on calculateStandardMaxHit in Characters.js<br />
local effectiveLevel = baseLevel + 9<br />
return math.floor(10 * (1.3 + effectiveLevel / 10 + strengthBonus / 80 + effectiveLevel * strengthBonus / 640))<br />
end<br />
<br />
function p._getMonsterAttackSpeed(monster)<br />
return p.getEquipmentStat(monster, 'attackSpeed') / 1000<br />
end<br />
<br />
function p.getMonsterAttackSpeed(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
if monster ~= nil then<br />
return p._getMonsterAttackSpeed(monster)<br />
else<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
end<br />
<br />
function p._getMonsterCombatLevel(monster)<br />
local base = 0.25 * (p._getMonsterLevel(monster, 'Defence') + p._getMonsterLevel(monster, 'Hitpoints'))<br />
local melee = 0.325 * (p._getMonsterLevel(monster, 'Attack') + p._getMonsterLevel(monster, 'Strength'))<br />
local range = 0.325 * (1.5 * p._getMonsterLevel(monster, 'Ranged'))<br />
local magic = 0.325 * (1.5 * p._getMonsterLevel(monster, 'Magic'))<br />
return math.floor(base + math.max(melee, range, magic))<br />
end<br />
<br />
function p.getMonsterCombatLevel(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterCombatLevel(monster)<br />
end<br />
<br />
function p._getMonsterAR(monster)<br />
local baseLevel = 0<br />
local bonus = 0<br />
if monster.attackType == 'melee' then<br />
baseLevel = p._getMonsterLevel(monster, 'Attack')<br />
bonus = p.getEquipmentStat(monster, 'stabAttackBonus')<br />
elseif monster.attackType == 'ranged' then<br />
baseLevel = p._getMonsterLevel(monster, 'Ranged')<br />
bonus = p.getEquipmentStat(monster, 'rangedAttackBonus')<br />
elseif monster.attackType == 'magic' then<br />
baseLevel = p._getMonsterLevel(monster, 'Magic')<br />
bonus = p.getEquipmentStat(monster, 'magicAttackBonus')<br />
elseif monster.attackType == 'random' then<br />
--Bane has the same AR with every attack type so being lazy and just showing the one.<br />
baseLevel = p._getMonsterLevel(monster, 'Attack')<br />
bonus = p.getEquipmentStat(monster, 'stabAttackBonus')<br />
else<br />
return "ERROR: This monster has an invalid attack type somehow[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p.calculateStandardStat(baseLevel, bonus)<br />
end<br />
<br />
function p.getMonsterAR(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterAR(monster)<br />
end<br />
<br />
function p._getMonsterER(monster, style)<br />
local baseLevel= 0<br />
local bonus = 0<br />
<br />
if style == "Melee" then<br />
baseLevel = p._getMonsterLevel(monster, 'Defence')<br />
bonus = p.getEquipmentStat(monster, 'meleeDefenceBonus')<br />
elseif style == "Ranged" then<br />
baseLevel = p._getMonsterLevel(monster, 'Defence')<br />
bonus = p.getEquipmentStat(monster, 'rangedDefenceBonus')<br />
elseif style == "Magic" then<br />
baseLevel = math.floor(p._getMonsterLevel(monster, 'Magic') * 0.7 + p._getMonsterLevel(monster, 'Defence') * 0.3)<br />
bonus = p.getEquipmentStat(monster, 'magicDefenceBonus')<br />
else<br />
return "ERROR: Must choose Melee, Ranged, or Magic[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p.calculateStandardStat(baseLevel, bonus)<br />
end<br />
<br />
function p.getMonsterER(frame)<br />
local args = frame.args ~= nil and frame.args or frame<br />
local MonsterName = args[1]<br />
local style = args[2]<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterER(monster, style)<br />
end<br />
<br />
-- Determines if the monster is capable of dropping bones, and returns the bones<br />
-- item if so, or nil otherwise<br />
function p._getMonsterBones(monster)<br />
if monster.bones ~= nil and monster.bones >= 0 then<br />
local boneItem = Items.getItemByID(monster.bones)<br />
if boneItem.prayerPoints == nil then<br />
-- Assume bones without prayer points are shards (from God dungeons),<br />
-- and drop unconditionally<br />
return boneItem<br />
elseif not monster.isBoss and not p._isDungeonOnlyMonster(monster) then<br />
-- Otherwise, bones drop when the monster isn't dungeon exclusive<br />
return boneItem<br />
end<br />
end<br />
end<br />
<br />
function p._isDungeonOnlyMonster(monster)<br />
local areaList = Areas.getMonsterAreas(monster.id)<br />
local inDungeon = false<br />
<br />
for i, area in ipairs(areaList) do<br />
if area.type == 'dungeon' then<br />
inDungeon = true<br />
else<br />
return false<br />
end<br />
end<br />
return inDungeon<br />
end<br />
<br />
function p.isDungeonOnlyMonster(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with name "..monsterName.." found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._isDungeonOnlyMonster(monster)<br />
end<br />
<br />
function p._getMonsterAreas(monster, excludeDungeons)<br />
local resultPart = {}<br />
local hideDungeons = excludeDungeons ~= nil and excludeDungeons or false<br />
local areaList = Areas.getMonsterAreas(monster.id)<br />
for i, area in ipairs(areaList) do<br />
if area.type ~= 'dungeon' or not hideDungeons then<br />
table.insert(resultPart, Icons.Icon({area.name, type = area.type}))<br />
end<br />
end<br />
return table.concat(resultPart, '<br/>')<br />
end<br />
<br />
function p.getMonsterAreas(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local hideDungeons = frame.args ~= nil and frame.args[2] or nil<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with name "..monsterName.." found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterAreas(monster, hideDungeons)<br />
end<br />
<br />
function p.getSpecAttackMaxHit(specAttack, normalMaxHit)<br />
local result = 0<br />
for i, dmg in pairs(specAttack.damage) do<br />
if dmg.maxRoll == 'Fixed' then<br />
result = dmg.maxPercent * 10<br />
elseif dmg.maxRoll == 'MaxHit' then<br />
if dmg.character == 'Target' then<br />
--Confusion applied damage based on the player's max hit. Gonna just ignore that one<br />
result = 0<br />
else<br />
result = dmg.maxPercent * normalMaxHit * 0.01<br />
end<br />
elseif Shared.contains({'Bleeding', 'Poisoned'}, dmg.maxRoll) then<br />
-- TODO: This is limited in that there is no verification that bleed/poison<br />
-- can be applied to the target, it is assumed that it can and so this applies<br />
result = result + dmg.maxPercent * 10<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.canSpecAttackApplyEffect(specAttack, effectType)<br />
local result = false<br />
for i, effect in pairs(specAttack.prehitEffects) do<br />
if effect.type == effectType then<br />
result = true<br />
break<br />
end<br />
end<br />
<br />
for i, effect in pairs(specAttack.onhitEffects) do<br />
if effect.type == effectType then<br />
result = true<br />
break<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p._getMonsterMaxHit(monster, doStuns)<br />
-- 2021-06-11 Adjusted for v0.20 stun/sleep changes, where damage multiplier now applies<br />
-- to all enemy attacks if stun/sleep is present on at least one special attack<br />
if doStuns == nil then<br />
doStuns = true<br />
elseif type(doStuns) == 'string' then<br />
doStuns = string.upper(doStuns) == 'TRUE'<br />
end<br />
<br />
local normalChance = 100<br />
local specialMaxHit = 0<br />
local normalMaxHit = p._getMonsterBaseMaxHit(monster)<br />
local hasActiveBuffSpec = false<br />
local damageMultiplier = 1<br />
if monster.specialAttacks[1] ~= nil then<br />
local canStun, canSleep = false, false<br />
for i, specAttack in pairs(monster.specialAttacks) do<br />
if monster.overrideSpecialChances ~= nil then<br />
normalChance = normalChance - monster.overrideSpecialChances[i]<br />
else<br />
normalChance = normalChance - specAttack.defaultChance<br />
end<br />
local thisMax = p.getSpecAttackMaxHit(specAttack, normalMaxHit)<br />
if not canStun and p.canSpecAttackApplyEffect(specAttack, 'Stun') then canStun = true end<br />
if not canSleep and p.canSpecAttackApplyEffect(specAttack, 'Sleep') then canSleep = true end<br />
<br />
if thisMax > specialMaxHit then specialMaxHit = thisMax end<br />
if Shared.contains(string.upper(specAttack.description), 'NORMAL ATTACK INSTEAD') then <br />
hasActiveBuffSpec = true <br />
end<br />
end<br />
<br />
if canSleep and doStuns then damageMultiplier = damageMultiplier * 1.2 end<br />
if canStun and doStuns then damageMultiplier = damageMultiplier * 1.3 end<br />
end<br />
--Ensure that if the monster never does a normal attack, the normal max hit is irrelevant<br />
if normalChance == 0 and not hasActiveBuffSpec then normalMaxHit = 0 end<br />
return math.floor(math.max(specialMaxHit, normalMaxHit) * damageMultiplier)<br />
end<br />
<br />
function p.getMonsterMaxHit(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local doStuns = frame.args ~= nil and frame.args[2] or true<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterMaxHit(monster, doStuns)<br />
end<br />
<br />
function p._getMonsterBaseMaxHit(monster)<br />
--8/27/21 - Now references p.calculateStandardMaxHit for Melee & Ranged<br />
local result = 0<br />
local baseLevel = 0<br />
local bonus = 0<br />
if monster.attackType == 'melee' then<br />
baseLevel = p._getMonsterLevel(monster, 'Strength')<br />
bonus = p.getEquipmentStat(monster, 'meleeStrengthBonus')<br />
result = p.calculateStandardMaxHit(baseLevel, bonus)<br />
elseif monster.attackType == 'ranged' then<br />
baseLevel = p._getMonsterLevel(monster, 'Ranged')<br />
bonus = p.getEquipmentStat(monster, 'rangedStrengthBonus')<br />
result = p.calculateStandardMaxHit(baseLevel, bonus)<br />
elseif monster.attackType == 'magic' then<br />
local mSpell = nil<br />
if monster.selectedSpell ~= nil then mSpell = Magic.getSpellByID('Spells', monster.selectedSpell) end<br />
<br />
bonus = p.getEquipmentStat(monster, 'magicDamageBonus')<br />
baseLevel = p._getMonsterLevel(monster, 'Magic')<br />
<br />
result = math.floor(10 * mSpell.maxHit * (1 + bonus / 100) * (1 + (baseLevel + 1) / 200))<br />
elseif monster.attackType == 'random' then<br />
local hitArray = {}<br />
local iconText = Icons.Icon({'Melee', notext=true})<br />
baseLevel = p._getMonsterLevel(monster, 'Strength')<br />
bonus = p.getEquipmentStat(monster, 'meleeStrengthBonus')<br />
table.insert(hitArray, p.calculateStandardMaxHit(baseLevel, bonus))<br />
<br />
iconText = Icons.Icon({'Ranged', type='skill', notext=true})<br />
baseLevel = p._getMonsterLevel(monster, 'Ranged')<br />
bonus = p.getEquipmentStat(monster, 'rangedStrengthBonus')<br />
table.insert(hitArray, p.calculateStandardMaxHit(baseLevel, bonus))<br />
<br />
iconText = Icons.Icon({'Magic', type='skill', notext=true})<br />
local mSpell = nil<br />
if monster.selectedSpell ~= nil then mSpell = Magic.getSpellByID('Spells', monster.selectedSpell) end<br />
bonus = p.getEquipmentStat(monster, 'magicDamageBonus')<br />
baseLevel = p._getMonsterLevel(monster, 'Magic')<br />
local magicDmg = math.floor(10 * mSpell.maxHit * (1 + bonus / 100) * (1 + (baseLevel + 1) / 200))<br />
table.insert(hitArray, magicDmg)<br />
<br />
local max = 0<br />
for i, val in pairs(hitArray) do<br />
if val > max then max = val end<br />
end<br />
result = max<br />
else<br />
return "ERROR: This monster has an invalid attack type somehow[[Category:Pages with script errors]]"<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getMonsterBaseMaxHit(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterBaseMaxHit(monster)<br />
end<br />
<br />
function p.getMonsterAttacks(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = ''<br />
local iconText = p._getMonsterStyleIcon({monster, notext=true})<br />
local typeText = ''<br />
if monster.attackType == 'melee' then<br />
typeText = 'Melee'<br />
elseif monster.attackType == 'ranged' then<br />
typeText = 'Ranged'<br />
elseif monster.attackType == 'magic' then<br />
typeText = 'Magic'<br />
elseif monster.attackType == 'random' then<br />
typeText = "Random"<br />
end<br />
<br />
local buffAttacks = {}<br />
local hasActiveBuffSpec = false<br />
<br />
local normalAttackChance = 100<br />
if monster.specialAttacks[1] ~= nil then<br />
for i, specAttack in pairs(monster.specialAttacks) do<br />
local attChance = 0<br />
if monster.overrideSpecialChances ~= nil then<br />
attChance = monster.overrideSpecialChances[i]<br />
else<br />
attChance = specAttack.defaultChance<br />
end<br />
normalAttackChance = normalAttackChance - attChance<br />
<br />
result = result..'\r\n* '..attChance..'% '..iconText..' '..specAttack.name..'\r\n** '..specAttack.description<br />
<br />
if Shared.contains(string.upper(specAttack.description), 'NORMAL ATTACK INSTEAD') then<br />
table.insert(buffAttacks, specAttack.name)<br />
hasActiveBuffSpec = true <br />
end<br />
end<br />
end<br />
if normalAttackChance == 100 then<br />
result = iconText..' 1 - '..p._getMonsterBaseMaxHit(monster)..' '..typeText..' Damage'<br />
elseif normalAttackChance > 0 then<br />
result = '* '..normalAttackChance..'% '..iconText..' 1 - '..p.getMonsterBaseMaxHit(frame)..' '..typeText..' Damage'..result<br />
elseif hasActiveBuffSpec then<br />
--If the monster normally has a 0% chance of doing a normal attack but some special attacks can't be repeated, include it<br />
--(With a note about when it does it)<br />
result = '* '..iconText..' 1 - '..p._getMonsterBaseMaxHit(monster)..' '..typeText..' Damage (Instead of repeating '..table.concat(buffAttacks, ' or ')..' while the effect is already active)'..result<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getMonsterPassives(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = ''<br />
if type(monster.passiveID) == 'table' and Shared.tableCount(monster.passiveID) > 0 then<br />
result = result .. '===Passives==='<br />
for i, passiveID in pairs(monster.passiveID) do<br />
local passive = p.getPassiveByID(passiveID)<br />
result = result .. '\r\n* ' .. passive.name .. '\r\n** ' .. passive.description<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.getMonsterCategories(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = '[[Category:Monsters]]'<br />
<br />
if monster.attackType == 'melee' then<br />
result = result..'[[Category:Melee Monsters]]'<br />
elseif monster.attackType == 'ranged' then<br />
result = result..'[[Category:Ranged Monsters]]'<br />
elseif monster.attackType == 'magic' then<br />
result = result..'[[Category:Magic Monsters]]'<br />
end<br />
<br />
if monster.specialAttacks[1] ~= nil then<br />
result = result..'[[Category:Monsters with Special Attacks]]'<br />
end<br />
<br />
if monster.isBoss then<br />
result = result..'[[Category:Bosses]]'<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getOtherMonsterBoxText(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = ''<br />
<br />
--Going through and finding out which damage bonuses will apply to this monster<br />
local monsterTypes = {}<br />
if monster.isBoss then table.insert(monsterTypes, 'Boss') end<br />
<br />
local areaList = Areas.getMonsterAreas(monster.id)<br />
local counts = {combat = 0, slayer = 0, dungeon = 0}<br />
for i, area in Shared.skpairs(areaList) do<br />
counts[area.type] = counts[area.type] + 1<br />
end<br />
<br />
if counts.combat > 0 then table.insert(monsterTypes, 'Combat Area') end<br />
if counts.slayer > 0 then table.insert(monsterTypes, 'Slayer Area') end<br />
if counts.dungeon > 0 then table.insert(monsterTypes, 'Dungeon') end<br />
<br />
result = result.."\r\n|-\r\n|'''Monster Types:''' "..table.concat(monsterTypes, ", ")<br />
<br />
local SlayerTier = 'N/A'<br />
if monster.canSlayer then<br />
SlayerTier = Constants.getSlayerTierNameByLevel(p._getMonsterCombatLevel(monster))<br />
end<br />
<br />
result = result.."\r\n|-\r\n|'''"..Icons.Icon({'Slayer', type='skill'}).." [[Slayer#Slayer Tier Monsters|Tier]]:''' "<br />
if monster.canSlayer then<br />
result = result.."[[Slayer#"..SlayerTier.."|"..SlayerTier.."]]"<br />
else<br />
result = result..SlayerTier<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getMonsterDrops(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = ''<br />
<br />
local bones = p._getMonsterBones(monster)<br />
local boneVal = 0<br />
--Show the bones only if either the monster shows up outside of dungeons _or_ the monster drops shards<br />
if bones ~= nil then<br />
local boneQty = (monster.boneQty ~= nil and monster.boneQty or 1)<br />
result = result.."'''Always Drops:'''"<br />
result = result..'\r\n{|class="wikitable" id="bonedrops"'<br />
result = result..'\r\n!Item !! Qty'<br />
result = result..'\r\n|-\r\n|'..Icons.Icon({bones.name, type='item'})<br />
result = result..'||'..boneQty..'\r\n'..'|}'<br />
boneVal = boneQty * bones.sellsFor<br />
end<br />
<br />
--Likewise, seeing the loot table is tied to the monster appearing outside of dungeons<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100<br />
local lootValue = 0<br />
<br />
result = result.."'''Loot:'''"<br />
local avgGp = 0<br />
<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2<br />
local gpTxt = Icons.GP(monster.dropCoins[1], monster.dropCoins[2])<br />
result = result.."\r\nIn addition to loot, the monster will also drop "..gpTxt..'.'<br />
end<br />
<br />
local multiDrop = Shared.tableCount(monster.lootTable) > 1<br />
local totalWt = 0<br />
for i, row in pairs(monster.lootTable) do<br />
totalWt = totalWt + row[2]<br />
end<br />
result = result..'\r\n{|class="wikitable sortable" id="itemdrops"'<br />
result = result..'\r\n!Item!!Qty'<br />
result = result..'!!Price!!colspan="2"|Chance'<br />
<br />
--Sort the loot table by weight in descending order<br />
table.sort(monster.lootTable, function(a, b) return a[2] > b[2] end)<br />
for i, row in Shared.skpairs(monster.lootTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
<br />
local maxQty = row[3]<br />
if thisItem ~= nil then<br />
result = result..'\r\n|-\r\n|'..Icons.Icon({thisItem.name, type='item'})<br />
else<br />
result = result..'\r\n|-\r\n|Unknown Item[[Category:Pages with script errors]]'<br />
end<br />
result = result..'||style="text-align:right" data-sort-value="'..maxQty..'"|'<br />
<br />
if maxQty > 1 then<br />
result = result.. '1 - '<br />
end<br />
result = result..Shared.formatnum(row[3])<br />
<br />
--Adding price columns<br />
local itemPrice = 0<br />
if thisItem == nil then<br />
result = result..'||data-sort-value="0"|???'<br />
else<br />
itemPrice = thisItem.sellsFor ~= nil and thisItem.sellsFor or 0<br />
if itemPrice == 0 or maxQty == 1 then<br />
result = result..'||'..Icons.GP(itemPrice)<br />
else<br />
result = result..'||'..Icons.GP(itemPrice, itemPrice * maxQty)<br />
end<br />
end<br />
<br />
--Getting the drop chance<br />
local dropChance = (row[2] / totalWt * lootChance)<br />
if dropChance < 100 then<br />
--Show fraction as long as it isn't going to be 1/1<br />
result = result..'||style="text-align:right" data-sort-value="'..row[2]..'"'<br />
result = result..'|'..Shared.fraction(row[2] * lootChance, totalWt * 100)<br />
result = result..'||'<br />
else<br />
result = result..'||colspan="2" data-sort-value="'..row[2]..'"'<br />
end<br />
-- If chance is less than 0.10% then show 2 significant figures, otherwise 2 decimal places<br />
local fmt = (dropChance < 0.10 and '%.2g') or '%.2f'<br />
result = result..'style="text-align:right"|'..string.format(fmt, dropChance)..'%'<br />
<br />
--Adding to the average loot value based on price & dropchance<br />
lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((1 + maxQty) / 2))<br />
end<br />
if multiDrop then<br />
result = result..'\r\n|-class="sortbottom" \r\n!colspan="3"|Total:'<br />
if lootChance < 100 then<br />
result = result..'\r\n|style="text-align:right"|'..Shared.fraction(lootChance, 100)..'||'<br />
else<br />
result = result..'\r\n|colspan="2" '<br />
end<br />
result = result..'style="text-align:right"|'..Shared.round(lootChance, 2, 2)..'%'<br />
end<br />
result = result..'\r\n|}'<br />
result = result..'\r\nThe loot dropped by the average kill is worth '..Icons.GP(Shared.round(lootValue, 2, 0)).." if sold."<br />
if avgGp > 0 then<br />
result = result.."<br/>Including GP"<br />
if boneVal > 0 then<br />
result = result..' and bones'<br />
end<br />
result = result..', the average kill is worth '..Icons.GP(Shared.round(avgGp + lootValue + boneVal, 2, 0))..'.'<br />
end<br />
end<br />
<br />
--If no other drops, make sure to at least say so.<br />
if result == '' then result = 'None' end<br />
return result<br />
end<br />
<br />
function p._getMonsterLootValue(monster)<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = 0<br />
local boneVal = 0<br />
<br />
local bones = p._getMonsterBones(monster)<br />
--Show the bones only if either the monster shows up outside of dungeons _or_ the monster drops shards<br />
if bones ~= nil then<br />
local boneQty = monster.boneQty ~= nil and monster.boneQty or 1<br />
boneVal = bones.sellsFor * boneQty<br />
result = result + boneVal<br />
end<br />
<br />
--Likewise, seeing the loot table is tied to the monster appearing outside of dungeons<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100<br />
local lootValue = 0<br />
<br />
local avgGp = 0<br />
<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2<br />
end<br />
<br />
local multiDrop = Shared.tableCount(monster.lootTable) > 1<br />
local totalWt = 0<br />
for i, row in pairs(monster.lootTable) do<br />
totalWt = totalWt + row[2]<br />
end<br />
<br />
for i, row in Shared.skpairs(monster.lootTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
<br />
local maxQty = row[3]<br />
<br />
--Adding price columns<br />
local itemPrice = 0<br />
if thisItem ~= nil then<br />
itemPrice = thisItem.sellsFor ~= nil and thisItem.sellsFor or 0<br />
end<br />
<br />
--Getting the drop chance<br />
local dropChance = (row[2] / totalWt * lootChance)<br />
--Adding to the average loot value based on price & dropchance<br />
lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((1 + maxQty) / 2))<br />
end<br />
if avgGp > 0 then<br />
result = result + avgGp + lootValue<br />
end<br />
end<br />
<br />
return result<br />
end<br />
<br />
-- Find drop chance of specified item from specified monster. <br />
-- Usage: |Monster Name|Item Name<br />
function p.getItemDropChance(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame[1]<br />
local ItemName = frame.args ~= nil and frame.args[2] or frame[2]<br />
<br />
local monster = p.getMonster(MonsterName)<br />
local item = Items.getItem(ItemName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
if item == nil then<br />
return "ERROR: No item with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100<br />
<br />
local totalWt = 0<br />
--for i, row in pairs(monster.lootTable) do<br />
--totalWt = totalWt + row[2]<br />
--end<br />
<br />
local dropChance = 0<br />
local dropWt = 0<br />
for i, row in Shared.skpairs(monster.lootTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
totalWt = totalWt + row[2]<br />
if item['id'] == thisItem['id'] then<br />
dropWt = row[2]<br />
end<br />
end<br />
dropChance = (dropWt / totalWt * lootChance)<br />
return Shared.round(dropChance, 2, 2)<br />
end<br />
end <br />
<br />
function p.getChestDrops(frame)<br />
local ChestName = frame.args ~= nil and frame.args[1] or frame<br />
local chest = Items.getItem(ChestName)<br />
<br />
if chest == nil then<br />
return "ERROR: No item named "..ChestName..' found[[Category:Pages with script errors]]'<br />
end<br />
<br />
local result = ''<br />
<br />
if chest.dropTable == nil then<br />
return "ERROR: "..ChestName.." does not have a drop table[[Category:Pages with script errors]]"<br />
else<br />
local lootChance = 100<br />
local lootValue = 0<br />
<br />
local multiDrop = Shared.tableCount(chest.dropTable) > 1<br />
local totalWt = 0<br />
for i, row in pairs(chest.dropTable) do<br />
totalWt = totalWt + row[2]<br />
end<br />
result = result..'\r\n{|class="wikitable sortable"'<br />
result = result..'\r\n!Item!!Qty'<br />
result = result..'!!colspan="2"|Chance!!Price'<br />
<br />
--Sort the loot table by weight in descending order<br />
for i, row in pairs(chest.dropTable) do<br />
if chest.dropQty ~= nil then<br />
table.insert(row, chest.dropQty[i])<br />
else<br />
table.insert(row, 1)<br />
end<br />
end<br />
table.sort(chest.dropTable, function(a, b) return a[2] > b[2] end)<br />
for i, row in Shared.skpairs(chest.dropTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
local qty = row[3]<br />
result = result..'\r\n|-\r\n|'..Icons.Icon({thisItem.name, type='item'})<br />
result = result..'||style="text-align:right" data-sort-value="'..qty..'"|'<br />
<br />
if qty > 1 then<br />
result = result.. '1 - '<br />
end<br />
result = result..Shared.formatnum(qty)<br />
<br />
local dropChance = (row[2] / totalWt) * 100<br />
result = result..'||style="text-align:right" data-sort-value="'..row[2]..'"'<br />
result = result..'|'..Shared.fraction(row[2], totalWt)<br />
<br />
result = result..'||style="text-align:right"|'..Shared.round(dropChance, 2, 2)..'%'<br />
<br />
result = result..'||style="text-align:left" data-sort-value="'..thisItem.sellsFor..'"'<br />
if qty > 1 then<br />
result = result..'|'..Icons.GP(thisItem.sellsFor, thisItem.sellsFor * qty)<br />
else<br />
result = result..'|'..Icons.GP(thisItem.sellsFor)<br />
end<br />
lootValue = lootValue + (dropChance * 0.01 * thisItem.sellsFor * ((1 + qty)/ 2))<br />
end<br />
result = result..'\r\n|}'<br />
result = result..'\r\nThe average value of the contents of one chest is '..Icons.GP(Shared.round(lootValue, 2, 0))..'.'<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getAreaMonsterTable(frame)<br />
local areaName = frame.args ~= nil and frame.args[1] or frame<br />
local area = Areas.getArea(areaName)<br />
if area == nil then<br />
return "ERROR: Could not find an area named "..areaName..'[[Category:Pages with script errors]]'<br />
end<br />
<br />
if area.type == 'dungeon' then<br />
return p.getDungeonMonsterTable(frame)<br />
end<br />
<br />
local tableTxt = '{| class="wikitable sortable"'<br />
tableTxt = tableTxt..'\r\n! Name !! Combat Level !! Hitpoints !! Max Hit !! [[Combat Triangle|Combat Style]]'<br />
for i, monsterID in pairs(area.monsters) do<br />
local monster = p.getMonsterByID(monsterID)<br />
tableTxt = tableTxt..'\r\n|-\r\n|'..Icons.Icon({monster.name, type='monster'})<br />
tableTxt = tableTxt..'||'..p._getMonsterCombatLevel(monster)<br />
tableTxt = tableTxt..'||'..Shared.formatnum(p._getMonsterHP(monster))<br />
tableTxt = tableTxt..'||'..Shared.formatnum(p._getMonsterMaxHit(monster))<br />
tableTxt = tableTxt..'||'..p._getMonsterStyleIcon({monster, nolink=true})<br />
end<br />
tableTxt = tableTxt..'\r\n|}'<br />
return tableTxt<br />
end<br />
<br />
function p.getDungeonMonsterTable(frame)<br />
local areaName = frame.args ~= nil and frame.args[1] or frame<br />
local area = Areas.getArea(areaName)<br />
if area == nil then<br />
return "ERROR: Could not find a dungeon named "..areaName..'[[Category:Pages with script errors]]'<br />
end<br />
<br />
--For Dungeons, go through and count how many of each monster are in the dungeon first<br />
local monsterCounts = {}<br />
for i, monsterID in pairs(area.monsters) do<br />
if monsterCounts[monsterID] == nil then<br />
monsterCounts[monsterID] = 1<br />
else<br />
monsterCounts[monsterID] = monsterCounts[monsterID] + 1<br />
end<br />
end<br />
<br />
local usedMonsters = {}<br />
<br />
-- Declare function for building table rows to avoid repeating code<br />
local buildRow = function(entityID, monsterCount, specialType)<br />
local monIcon, monLevel, monHP, monMaxHit, monStyle, monCount<br />
local monData = {}<br />
if specialType ~= nil and Shared.contains({'Afflicted', 'SlayerArea'}, specialType) then<br />
-- Special handling for Into the Mist<br />
if specialType == 'Afflicted' then<br />
local iconQ = Icons.Icon({'Into the Mist', notext=true, nolink=true, img='Question'})<br />
monIcon = Icons.Icon({'Into the Mist', 'Afflicted Monster', nolink=true, img='Question'})<br />
monLevel, monHP, monMaxHit, monStyle, monCount = iconQ, iconQ, iconQ, iconQ, monsterCount<br />
elseif specialType == 'SlayerArea' then<br />
-- entityID corresponds to a slayer area<br />
local area = Areas.getAreaByID('slayer', entityID)<br />
monIcon = Icons.Icon({area.name, type='combatArea'}) .. ' Monsters'<br />
monLevel = {p.getLowHighStat(area.monsters, function(monster) return p._getMonsterCombatLevel(monster) end)}<br />
monHP = {p.getLowHighStat(area.monsters, function(monster) return p._getMonsterHP(monster) end)}<br />
local lowMaxHit, highMaxHit = p.getLowHighStat(area.monsters, function(monster) return p._getMonsterMaxHit(monster) end)<br />
monMaxHit = highMaxHit<br />
monStyle = Icons.Icon({area.name, area.name, notext=true, nolink=true, img='Question'})<br />
monCount = monsterCount<br />
end<br />
else<br />
-- entityID corresponds to a monster<br />
local monster = p.getMonsterByID(entityID)<br />
monIcon = Icons.Icon({monster.name, type='monster'})<br />
monLevel = p._getMonsterCombatLevel(monster)<br />
monHP = p._getMonsterHP(monster)<br />
monMaxHit = p._getMonsterMaxHit(monster)<br />
monStyle = p._getMonsterStyleIcon({monster})<br />
monCount = monsterCount<br />
end<br />
local getValSort = function(val)<br />
if type(val) == 'table' then<br />
if type(val[1]) == 'number' and type(val[2]) == 'number' then<br />
return (val[1] + val[2]) / 2<br />
else<br />
return (type(val[1]) == 'number' and val[1]) or 0<br />
end<br />
else<br />
return (type(val) == 'number' and val) or 0<br />
end<br />
end<br />
local getValText = function(val)<br />
if type(val) == 'table' and Shared.tableCount(val) == 2 then<br />
if type(val[1]) == 'number' and type(val[2]) == 'number' then<br />
return Shared.formatnum(val[1]) .. ' - ' .. Shared.formatnum(val[2])<br />
else<br />
return val[1] .. ' - ' .. val[2]<br />
end<br />
elseif type(val) == 'number' then<br />
return Shared.formatnum(val)<br />
else<br />
return val<br />
end<br />
end<br />
<br />
local resultPart = {}<br />
table.insert(resultPart, '\r\n|-\r\n| ' .. monIcon)<br />
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monLevel) .. '"| ' .. getValText(monLevel))<br />
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monHP) .. '"| ' .. getValText(monHP))<br />
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monMaxHit) .. '"| ' .. getValText(monMaxHit))<br />
table.insert(resultPart, '\r\n| ' .. monStyle)<br />
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monCount) .. '"| ' .. getValText(monCount))<br />
return table.concat(resultPart)<br />
end<br />
<br />
local returnPart = {}<br />
table.insert(returnPart, '{| class="wikitable sortable"')<br />
table.insert(returnPart, '\r\n! Name !! Combat Level !! Hitpoints !! Max Hit !! [[Combat Triangle|Combat Style]] !! Count')<br />
-- Special handing for Impending Darkness event<br />
-- TODO needs to be revised once there is a better understanding of how the event works<br />
--if area.isEvent ~= nil and area.isEvent then<br />
-- for i, eventAreaID in ipairs(Areas.eventData.slayerAreas) do<br />
-- table.insert(returnPart, buildRow(eventAreaID, {5, 8}, 'SlayerArea'))<br />
-- end<br />
-- -- Add Bane * 4<br />
-- table.insert(returnPart, buildRow(152, 4))<br />
--end<br />
for i, monsterID in pairs(area.monsters) do<br />
if not Shared.contains(usedMonsters, monsterID) then<br />
if monsterID >= 0 then<br />
table.insert(returnPart, buildRow(monsterID, monsterCounts[monsterID]))<br />
else<br />
--Special handling for Into the Mist<br />
table.insert(returnPart, buildRow(monsterID, monsterCounts[monsterID], 'Afflicted'))<br />
end<br />
table.insert(usedMonsters, monsterID)<br />
end<br />
end<br />
table.insert(returnPart, '\r\n|}')<br />
return table.concat(returnPart)<br />
end<br />
<br />
function p.getDungeonTotalHp(frame)<br />
local areaName = frame.args ~= nil and frame.args[1] or frame<br />
local area = Areas.getArea(areaName)<br />
if area == nil then<br />
return "ERROR: Could not find a dungeon named "..areaName..'[[Category:Pages with script errors]]'<br />
end<br />
local totalHP = 0<br />
<br />
for i, monsterID in pairs(area.monsters) do<br />
if not Shared.contains(usedMonsters, monsterID) then<br />
local monster = p.getMonsterByID(monsterID)<br />
totalHP = totalHP + p._getMonsterHP(monster)<br />
end<br />
end<br />
return totalHP<br />
end<br />
<br />
function p._getAreaMonsterList(area)<br />
local monsterList = {}<br />
for i, monsterID in pairs(area.monsters) do<br />
local monster = p.getMonsterByID(monsterID)<br />
table.insert(monsterList, Icons.Icon({monster.name, type='monster'}))<br />
end<br />
return table.concat(monsterList, '<br/>')<br />
end<br />
<br />
function p._getDungeonMonsterList(area)<br />
local monsterList = {}<br />
local lastMonster = nil<br />
local lastID = -2<br />
local count = 0<br />
-- Special handing for Impending Darkness event<br />
-- TODO needs to be revised once there is a better understanding of how the event works<br />
--if area.isEvent ~= nil and area.isEvent then<br />
-- for i, eventAreaID in ipairs(Areas.eventData.slayerAreas) do<br />
-- local eventArea = Areas.getAreaByID('slayer', eventAreaID)<br />
-- table.insert(monsterList, '5-8 ' .. Icons.Icon({eventArea.name, type='combatArea'}) .. ' Monsters')<br />
-- end<br />
-- table.insert(monsterList, '4 ' .. Icons.Icon({'Bane', type='monster'}))<br />
--end<br />
for i, monsterID in Shared.skpairs(area.monsters) do<br />
if monsterID ~= lastID then<br />
local monster = nil <br />
if monsterID ~= -1 then monster = p.getMonsterByID(monsterID) end<br />
if lastID ~= -2 then<br />
if lastID == -1 then<br />
--Special handling for Afflicted Monsters<br />
table.insert(monsterList, Icons.Icon({'Affliction', 'Afflicted Monster', img='Question', qty=count}))<br />
else<br />
local name = lastMonster.name<br />
table.insert(monsterList, Icons.Icon({name, type='monster', qty=count}))<br />
end<br />
end<br />
lastMonster = monster<br />
lastID = monsterID<br />
count = 1<br />
else<br />
count = count + 1<br />
end<br />
--Make sure the final monster in the dungeon gets counted<br />
if i == Shared.tableCount(area.monsters) then<br />
local name = lastMonster.name<br />
table.insert(monsterList, Icons.Icon({lastMonster.name, type='monster', qty=count}))<br />
end<br />
end<br />
return table.concat(monsterList, '<br/>')<br />
end<br />
<br />
function p.getAreaMonsterList(frame)<br />
local areaName = frame.args ~= nil and frame.args[1] or frame<br />
local area = Areas.getArea(areaName)<br />
if area == nil then<br />
return "ERROR: Could not find an area named "..areaName..'[[Category:Pages with script errors]]'<br />
end<br />
<br />
if area.type == 'dungeon' then<br />
return p._getDungeonMonsterList(area)<br />
else<br />
return p._getAreaMonsterList(area)<br />
end<br />
end<br />
<br />
function p.getFoxyTable(frame)<br />
local result = 'Monster,Min GP,Max GP,Average GP'<br />
for i, monster in Shared.skpairs(MonsterData.Monsters) do<br />
if not p._isDungeonOnlyMonster(monster) then<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
local avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2<br />
result = result..'<br/>'..monster.name..','..monster.dropCoins[1]..','..(monster.dropCoins[2])..','..avgGp<br />
end<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p._getMonsterAverageGP(monster)<br />
local result = ''<br />
local totalGP = 0<br />
<br />
local bones = p._getMonsterBones(monster)<br />
if bones ~= nil then<br />
totalGP = totalGP + bones.sellsFor * (type(monster.boneQty) == 'number' and monster.boneQty or 1)<br />
end<br />
<br />
--Likewise, seeing the loot table is tied to the monster appearing outside of dungeons<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100<br />
local lootValue = 0<br />
<br />
local avgGp = 0<br />
<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2<br />
end<br />
<br />
totalGP = totalGP + avgGp<br />
<br />
local multiDrop = Shared.tableCount(monster.lootTable) > 1<br />
local totalWt = 0<br />
for i, row in pairs(monster.lootTable) do<br />
totalWt = totalWt + row[2]<br />
end<br />
<br />
for i, row in Shared.skpairs(monster.lootTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
local maxQty = row[3]<br />
<br />
local itemPrice = thisItem.sellsFor ~= nil and thisItem.sellsFor or 0<br />
<br />
--Getting the drop chance<br />
local dropChance = (row[2] / totalWt * lootChance)<br />
<br />
--Adding to the average loot value based on price & dropchance<br />
lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((1 + maxQty) / 2))<br />
end<br />
<br />
totalGP = totalGP + lootValue<br />
end<br />
<br />
return Shared.round(totalGP, 2, 2)<br />
end<br />
<br />
function p.getMonsterAverageGP(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterAverageGP(monster)<br />
end<br />
<br />
function p.getMonsterEVTable(frame)<br />
local result = '{| class="wikitable sortable"'<br />
result = result..'\r\n!Monster!!Combat Level!!Average GP'<br />
for i, monsterTemp in Shared.skpairs(MonsterData.Monsters) do<br />
local monster = Shared.clone(monsterTemp)<br />
monster.id = i - 1<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local monsterGP = p._getMonsterAverageGP(monster)<br />
local combatLevel = p._getMonsterCombatLevel(monster, 'Combat Level')<br />
result = result..'\r\n|-\r\n|'..Icons.Icon({monster.name, type='monster', noicon=true})..'||'..combatLevel..'||'..monsterGP<br />
end<br />
end<br />
result = result..'\r\n|}'<br />
return result<br />
end<br />
<br />
function p.getSlayerTierMonsterTable(frame)<br />
-- Input validation<br />
local tier = frame.args ~= nil and frame.args[1] or frame<br />
local slayerTier = nil<br />
<br />
if tier == nil then<br />
return "ERROR: No tier specified[[Category:Pages with script errors]]"<br />
end<br />
<br />
if tonumber(tier) ~= nil then<br />
slayerTier = Constants.getSlayerTierByID(tonumber(tier))<br />
else<br />
slayerTier = Constants.getSlayerTier(tier)<br />
end<br />
<br />
if slayerTier == nil then<br />
return "ERROR: Invalid slayer tier[[Category:Pages with script errors]]"<br />
end<br />
<br />
-- Obtain required tier details<br />
local minLevel, maxLevel = slayerTier.minLevel, slayerTier.maxLevel<br />
<br />
-- Build list of monster IDs<br />
-- Right now hiddenMonsterIDs is empty<br />
local hiddenMonsterIDs = {}<br />
local monsterIDs = {}<br />
for i, monster in Shared.skpairs(MonsterData.Monsters) do<br />
if monster.canSlayer and not Shared.contains(hiddenMonsterIDs, i - 1) then<br />
local cmbLevel = p._getMonsterCombatLevel(monster)<br />
if cmbLevel >= minLevel and (maxLevel == nil or cmbLevel <= maxLevel) then<br />
table.insert(monsterIDs, i - 1)<br />
end<br />
end<br />
end<br />
<br />
if Shared.tableCount(monsterIDs) == 0 then<br />
-- Somehow no monsters are in the tier, return nothing<br />
return ''<br />
else<br />
return p._getMonsterTable(monsterIDs, true)<br />
end<br />
end<br />
<br />
function p.getFullMonsterTable(frame)<br />
local monsterIDs = {}<br />
for i = 0, Shared.tableCount(MonsterData.Monsters) - 1, 1 do<br />
table.insert(monsterIDs, i)<br />
end<br />
<br />
return p._getMonsterTable(monsterIDs, false)<br />
end<br />
<br />
function p._getMonsterTable(monsterIDs, excludeDungeons)<br />
--Making a single function for getting a table of monsters given a list of IDs.<br />
local hideDungeons = excludeDungeons ~= nil and excludeDungeons or false<br />
local tableParts = {}<br />
table.insert(tableParts, '{| class="wikitable sortable stickyHeader"')<br />
-- First header row<br />
table.insert(tableParts, '\r\n|- class="headerRow-0"\r\n! colspan="5" | !! colspan="4" |Offensive Stats !! colspan="3" |Evasion Rating !! colspan="4" |')<br />
-- Second header row<br />
table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n!Monster !!Name !!ID !!Combat Level ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Hitpoints', type='skill'}))<br />
table.insert(tableParts, '!!Attack Speed (s) !!colspan="2"|Max Hit !!Accuracy ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Defence', type='skill', notext=true}))<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Ranged', type='skill', notext=true}))<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Magic', type='skill', notext=true}))<br />
table.insert(tableParts, '!!' .. Icons.Icon({'Coins', notext=true, nolink=true}) .. ' Coins !!Bones !!Locations')<br />
<br />
-- Generate row per monster<br />
for i, monsterID in Shared.skpairs(monsterIDs) do<br />
local monster = p.getMonsterByID(monsterID)<br />
local cmbLevel = p._getMonsterCombatLevel(monster)<br />
local atkSpeed = p._getMonsterAttackSpeed(monster)<br />
local maxHit = p._getMonsterMaxHit(monster)<br />
local accR = p._getMonsterAR(monster)<br />
local evaR = {p._getMonsterER(monster, "Melee"), p._getMonsterER(monster, "Ranged"), p._getMonsterER(monster, "Magic")}<br />
<br />
local gpRange = {0, 0}<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
gpRange = {monster.dropCoins[1], monster.dropCoins[2]}<br />
end<br />
local gpTxt = nil<br />
if gpRange[1] >= gpRange[2] then<br />
gpTxt = Shared.formatnum(gpRange[1])<br />
else<br />
gpTxt = Shared.formatnum(gpRange[1]) .. ' - ' .. Shared.formatnum(gpRange[2])<br />
end<br />
local bones = p._getMonsterBones(monster)<br />
local boneTxt = (bones ~= nil and Icons.Icon({bones.name, type='item', notext=true})) or 'None'<br />
<br />
table.insert(tableParts, '\r\n|-\r\n|style="text-align: center;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:left" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:right" |' .. monsterID)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. cmbLevel .. '" |' .. Shared.formatnum(cmbLevel))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. p._getMonsterHP(monster) .. '" |' .. Shared.formatnum(p._getMonsterHP(monster)))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. atkSpeed .. '" |' .. Shared.round(atkSpeed, 1, 1))<br />
table.insert(tableParts, '\r\n|style="text-align:center;border-right:hidden" |' .. p._getMonsterStyleIcon({monster, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. maxHit .. '" |' .. Shared.formatnum(maxHit))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. accR .. '" |' .. Shared.formatnum(accR))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[1] .. '" |' .. Shared.formatnum(evaR[1]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[2] .. '" |' .. Shared.formatnum(evaR[2]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[3] .. '" |' .. Shared.formatnum(evaR[3]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:center" |' .. boneTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))<br />
end<br />
<br />
table.insert(tableParts, '\r\n|}')<br />
return table.concat(tableParts)<br />
end<br />
<br />
function p.getMattMonsterTable(frame)<br />
--Making a single function for getting a table of monsters given a list of IDs.<br />
local tableParts = {}<br />
table.insert(tableParts, '{| class="wikitable sortable stickyHeader"')<br />
-- Second header row<br />
table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n!Monster !!Name !!ID !!Combat Level ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Hitpoints', type='skill'}))<br />
table.insert(tableParts, '!!' .. Icons.Icon({'Coins', notext=true, nolink=true}) .. ' Coins !!Avg. Kill Value!!Locations')<br />
<br />
-- Generate row per monster<br />
for i, monster in Shared.skpairs(MonsterData.Monsters) do<br />
local cmbLevel = p._getMonsterCombatLevel(monster)<br />
<br />
local gpRange = {0, 0}<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
gpRange = {monster.dropCoins[1], monster.dropCoins[2]}<br />
end<br />
local gpTxt = nil<br />
if gpRange[1] >= gpRange[2] then<br />
gpTxt = Shared.formatnum(gpRange[1])<br />
else<br />
gpTxt = Shared.formatnum(gpRange[1]) .. ' - ' .. Shared.formatnum(gpRange[2])<br />
end<br />
<br />
local lootVal = p._getMonsterLootValue(monster)<br />
local lootTxt = '0'<br />
if lootVal ~= 0 then<br />
lootTxt = Shared.formatnum(Shared.round(lootVal, 2, 2))<br />
end<br />
<br />
<br />
table.insert(tableParts, '\r\n|-\r\n|style="text-align: center;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:left" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:right" |' .. monster.id)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. cmbLevel .. '" |' .. Shared.formatnum(cmbLevel))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. p._getMonsterHP(monster) .. '" |' .. Shared.formatnum(p._getMonsterHP(monster)))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. lootVal .. '" |' .. lootTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))<br />
end<br />
<br />
table.insert(tableParts, '\r\n|}')<br />
return table.concat(tableParts)<br />
end<br />
<br />
function p.getMattMonsterTableV2(frame)<br />
--Making a single function for getting a table of monsters given a list of IDs.<br />
local tableParts = {}<br />
table.insert(tableParts, '{| class="wikitable sortable stickyHeader"')<br />
-- Second header row<br />
table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n!Monster !!Name !!Combat Level ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Hitpoints', type='skill'}))<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Defence', type='skill', notext=true}))<br />
table.insert(tableParts, '!!Attack Speed (s) !!colspan="2"|Max Hit !!Accuracy ')<br />
<br />
-- table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Ranged', type='skill', notext=true}))<br />
-- table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Magic', type='skill', notext=true}))<br />
table.insert(tableParts, '!!' .. Icons.Icon({'Coins', notext=true, nolink=true}) .. ' Coins !!Avg. Kill Value !!Bones')<br />
<br />
-- Generate row per monster<br />
for i, monster in Shared.skpairs(MonsterData.Monsters) do<br />
local cmbLevel = p._getMonsterCombatLevel(monster)<br />
<br />
local gpRange = {0, 0}<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
gpRange = {monster.dropCoins[1], monster.dropCoins[2]}<br />
end<br />
local gpTxt = nil<br />
if gpRange[1] >= gpRange[2] then<br />
gpTxt = Shared.formatnum(gpRange[1])<br />
else<br />
gpTxt = Shared.formatnum(gpRange[1]) .. ' - ' .. Shared.formatnum(gpRange[2])<br />
end<br />
<br />
local lootVal = p._getMonsterLootValue(monster)<br />
local lootTxt = '0'<br />
if lootVal ~= 0 then<br />
lootTxt = Shared.formatnum(Shared.round(lootVal, 2, 2))<br />
end<br />
<br />
local atkSpeed = p._getMonsterAttackSpeed(monster)<br />
local maxHit = p._getMonsterMaxHit(monster)<br />
local accR = p._getMonsterAR(monster)<br />
local evaR = {p._getMonsterER(monster, "Melee"), p._getMonsterER(monster, "Ranged"), p._getMonsterER(monster, "Magic")}<br />
<br />
local bones = p._getMonsterBones(monster)<br />
local boneTxt = (bones ~= nil and Icons.Icon({bones.name, type='item', notext=true})) or 'None'<br />
<br />
table.insert(tableParts, '\r\n|-\r\n|style="text-align: center;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:left" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))<br />
-- table.insert(tableParts, '\r\n|style="text-align:right" |' .. monster.id)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. cmbLevel .. '" |' .. Shared.formatnum(cmbLevel))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. p._getMonsterHP(monster) .. '" |' .. Shared.formatnum(p._getMonsterHP(monster)))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[1] .. '" |' .. Shared.formatnum(evaR[1]))<br />
<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. atkSpeed .. '" |' .. Shared.round(atkSpeed, 1, 1))<br />
table.insert(tableParts, '\r\n|style="text-align:center;border-right:hidden" |' .. p._getMonsterStyleIcon({monster, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. maxHit .. '" |' .. Shared.formatnum(maxHit))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. accR .. '" |' .. Shared.formatnum(accR))<br />
--table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[2] .. '" |' .. Shared.formatnum(evaR[2]))<br />
--table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[3] .. '" |' .. Shared.formatnum(evaR[3]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. lootVal .. '" |' .. lootTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:center" |' .. boneTxt)<br />
-- table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))<br />
end<br />
<br />
table.insert(tableParts, '\r\n|}')<br />
return table.concat(tableParts)<br />
end<br />
<br />
function p.getSpecialAttackTable(frame)<br />
local spAttTable = {}<br />
<br />
for i, monster in ipairs(MonsterData.Monsters) do<br />
if monster.specialAttacks ~= nil and Shared.tableCount(monster.specialAttacks) > 0 then<br />
local overrideChance = (monster.overrideSpecialChances ~= nil and Shared.tableCount(monster.overrideSpecialChances) > 0)<br />
for j, spAtt in ipairs(monster.specialAttacks) do<br />
local attChance = (overrideChance and monster.overrideSpecialChances[j] or spAtt.defaultChance)<br />
if spAttTable[spAtt.id] == nil then<br />
spAttTable[spAtt.id] = { ['defn'] = spAtt, ['icons'] = {} }<br />
end<br />
if spAttTable[spAtt.id]['icons'][attChance] == nil then<br />
spAttTable[spAtt.id]['icons'][attChance] = {}<br />
end<br />
table.insert(spAttTable[spAtt.id]['icons'][attChance], Icons.Icon({ monster.name, type = 'monster' }))<br />
end<br />
end<br />
end<br />
<br />
local resultPart = {}<br />
table.insert(resultPart, '{|class="wikitable sortable stickyHeader"')<br />
table.insert(resultPart, '\r\n|- class="headerRow-0"')<br />
table.insert(resultPart, '\r\n!Name!!style="min-width:225px"|Monsters!!Chance!!Effect')<br />
<br />
for i, spAttData in Shared.skpairs(spAttTable) do<br />
local spAtt = spAttData.defn<br />
local firstRow = true<br />
local rowsSpanned = Shared.tableCount(spAttData.icons)<br />
local rowSuffix = ''<br />
if rowsSpanned > 1 then<br />
rowSuffix = '|rowspan="' .. rowsSpanned .. '"'<br />
end<br />
for chance, iconList in Shared.skpairs(spAttData.icons) do<br />
table.insert(resultPart, '\r\n|-')<br />
if firstRow then<br />
table.insert(resultPart, '\r\n' .. rowSuffix .. '| ' .. spAtt.name)<br />
end<br />
table.insert(resultPart, '\r\n|data-sort-value="' .. spAtt.name .. '"| ' .. table.concat(iconList, '<br/>'))<br />
table.insert(resultPart, '\r\n|data-sort-value="' .. chance .. '"| ' .. Shared.round(chance, 2, 0) .. '%')<br />
if firstRow then<br />
table.insert(resultPart, '\r\n' .. rowSuffix .. '| ' .. spAtt.description)<br />
firstRow = false<br />
end<br />
end<br />
end<br />
table.insert(resultPart, '\r\n|}')<br />
<br />
return table.concat(resultPart)<br />
end<br />
<br />
return p</div>
Roko
https://wiki.melvoridle.com/index.php?title=Module:Monsters&diff=51093
Module:Monsters
2022-02-19T13:38:00Z
<p>Roko: </p>
<hr />
<div>local p = {}<br />
<br />
local MonsterData = mw.loadData('Module:Monsters/data')<br />
<br />
local Constants = require('Module:Constants')<br />
local Areas = require('Module:CombatAreas')<br />
local Magic = require('Module:Magic')<br />
local Shared = require('Module:Shared')<br />
local Icons = require('Module:Icons')<br />
local Items = require('Module:Items')<br />
<br />
function p.getMonster(name)<br />
local result = nil<br />
if name == 'Spider (lv. 51)' or name == 'Spider' then<br />
return p.getMonsterByID(50)<br />
elseif name == 'Spider (lv. 52)' or name == 'Spider2' then<br />
return p.getMonsterByID(51)<br />
end<br />
<br />
for i, monster in pairs(MonsterData.Monsters) do<br />
if monster.name == name then<br />
result = Shared.clone(monster)<br />
--Make sure every monster has an ID, and account for the 1-based indexing of Lua<br />
result.id = i - 1<br />
break<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.getMonsterByID(ID)<br />
local result = Shared.clone(MonsterData.Monsters[ID + 1])<br />
if result ~= nil then<br />
result.id = ID<br />
return result<br />
else<br />
return nil<br />
end<br />
end<br />
<br />
function p.getPassive(name)<br />
local result = nil<br />
<br />
for i, passive in pairs(MonsterData.Passives) do<br />
if passive.name == name then<br />
result = Shared.clone(passive)<br />
--Make sure every passive has an ID, and account for the 1-based indexing of Lua<br />
result.id = i - 1<br />
break<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.getPassiveByID(ID)<br />
return MonsterData.Passives[ID + 1]<br />
end<br />
<br />
-- Given a list of monster IDs, calls statFunc with each monster and returns<br />
-- the lowest & highest values<br />
function p.getLowHighStat(idList, statFunc)<br />
local lowVal, highVal = nil, nil<br />
for i, monID in ipairs(idList) do<br />
local monster = p.getMonsterByID(monID)<br />
local statVal = statFunc(monster)<br />
if lowVal == nil or statVal < lowVal then lowVal = statVal end<br />
if highVal == nil or statVal > highVal then highVal = statVal end<br />
end<br />
return lowVal, highVal<br />
end<br />
<br />
function p._getMonsterStat(monster, statName)<br />
if statName == 'HP' then<br />
return p._getMonsterHP(monster)<br />
elseif statName == 'maxHit' then<br />
return p._getMonsterMaxHit(monster)<br />
elseif statName == 'accuracyRating' then<br />
return p._getMonsterAR(monster)<br />
elseif statName == 'meleeEvasionRating' then<br />
return p._getMonsterER(monster, 'Melee')<br />
elseif statName == 'rangedEvasionRating' then<br />
return p._getMonsterER(monster, 'Ranged')<br />
elseif statName == 'magicEvasionRating' then<br />
return p._getMonsterER(monster, 'Magic')<br />
elseif statName == 'damageReduction' then<br />
return p.getEquipmentStat(monster, 'damageReduction')<br />
end<br />
<br />
return monster[statName]<br />
end<br />
<br />
function p.getMonsterStat(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame[1]<br />
local StatName = frame.args ~= nil and frame.args[2] or frame[2]<br />
local monster = p.getMonster(MonsterName)<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterStat(monster, StatName)<br />
end<br />
<br />
function p._getMonsterStyleIcon(frame)<br />
local args = frame.args ~= nil and frame.args or frame<br />
local monster = args[1]<br />
local notext = args.notext<br />
local nolink = args.nolink<br />
<br />
local iconText = ''<br />
if monster.attackType == 'melee' then<br />
iconText = Icons.Icon({'Melee', notext=notext, nolink=nolink})<br />
elseif monster.attackType == 'ranged' then<br />
iconText = Icons.Icon({'Ranged', type='skill', notext=notext, nolink=nolink})<br />
elseif monster.attackType == 'magic' then<br />
iconText = Icons.Icon({'Magic', type='skill', notext=notext, nolink=nolink})<br />
elseif monster.attackType == 'random' then<br />
iconText = Icons.Icon({'Bane', notext=notext, nolink=nolink, img='Question'})<br />
end<br />
<br />
return iconText<br />
end<br />
<br />
function p.getMonsterStyleIcon(frame)<br />
local args = frame.args ~= nil and frame.args or frame<br />
local MonsterName = args[1]<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
args[1] = monster<br />
return p._getMonsterStyleIcon(args)<br />
end<br />
<br />
function p._getMonsterHP(monster)<br />
return 10 * p._getMonsterLevel(monster, 'Hitpoints')<br />
end<br />
<br />
function p.getMonsterEffectiveHP(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
if monster ~= nil then<br />
return math.floor((p._getMonsterHP(monster)/(1 - p._getMonsterStat(monster, 'damageReduction')/100)) + 0.5)<br />
else<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
end<br />
<br />
function p.getMonsterHP(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
if monster ~= nil then<br />
return p._getMonsterHP(monster)<br />
else<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
end<br />
<br />
function p._getMonsterLevel(monster, skillName)<br />
local result = 0<br />
if monster.levels[skillName] ~= nil then<br />
result = monster.levels[skillName]<br />
end<br />
return result<br />
end<br />
<br />
function p.getMonsterLevel(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame[1]<br />
local SkillName = frame.args ~= nil and frame.args[2] or frame[2]<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterLevel(monster, SkillName)<br />
end<br />
<br />
function p.getEquipmentStat(monster, statName)<br />
local result = 0<br />
for i, stat in Shared.skpairs(monster.equipmentStats) do<br />
if stat.key == statName then<br />
result = stat.value<br />
break<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.calculateStandardStat(effectiveLevel, bonus)<br />
--Based on calculateStandardStat in Characters.js<br />
return (effectiveLevel + 9) * (bonus + 64)<br />
end<br />
<br />
function p.calculateStandardMaxHit(baseLevel, strengthBonus)<br />
--Based on calculateStandardMaxHit in Characters.js<br />
local effectiveLevel = baseLevel + 9<br />
return math.floor(10 * (1.3 + effectiveLevel / 10 + strengthBonus / 80 + effectiveLevel * strengthBonus / 640))<br />
end<br />
<br />
function p._getMonsterAttackSpeed(monster)<br />
return p.getEquipmentStat(monster, 'attackSpeed') / 1000<br />
end<br />
<br />
function p.getMonsterAttackSpeed(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
if monster ~= nil then<br />
return p._getMonsterAttackSpeed(monster)<br />
else<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
end<br />
<br />
function p._getMonsterCombatLevel(monster)<br />
local base = 0.25 * (p._getMonsterLevel(monster, 'Defence') + p._getMonsterLevel(monster, 'Hitpoints'))<br />
local melee = 0.325 * (p._getMonsterLevel(monster, 'Attack') + p._getMonsterLevel(monster, 'Strength'))<br />
local range = 0.325 * (1.5 * p._getMonsterLevel(monster, 'Ranged'))<br />
local magic = 0.325 * (1.5 * p._getMonsterLevel(monster, 'Magic'))<br />
return math.floor(base + math.max(melee, range, magic))<br />
end<br />
<br />
function p.getMonsterCombatLevel(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterCombatLevel(monster)<br />
end<br />
<br />
function p._getMonsterAR(monster)<br />
local baseLevel = 0<br />
local bonus = 0<br />
if monster.attackType == 'melee' then<br />
baseLevel = p._getMonsterLevel(monster, 'Attack')<br />
bonus = p.getEquipmentStat(monster, 'stabAttackBonus')<br />
elseif monster.attackType == 'ranged' then<br />
baseLevel = p._getMonsterLevel(monster, 'Ranged')<br />
bonus = p.getEquipmentStat(monster, 'rangedAttackBonus')<br />
elseif monster.attackType == 'magic' then<br />
baseLevel = p._getMonsterLevel(monster, 'Magic')<br />
bonus = p.getEquipmentStat(monster, 'magicAttackBonus')<br />
elseif monster.attackType == 'random' then<br />
--Bane has the same AR with every attack type so being lazy and just showing the one.<br />
baseLevel = p._getMonsterLevel(monster, 'Attack')<br />
bonus = p.getEquipmentStat(monster, 'stabAttackBonus')<br />
else<br />
return "ERROR: This monster has an invalid attack type somehow[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p.calculateStandardStat(baseLevel, bonus)<br />
end<br />
<br />
function p.getMonsterAR(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterAR(monster)<br />
end<br />
<br />
function p._getMonsterER(monster, style)<br />
local baseLevel= 0<br />
local bonus = 0<br />
<br />
if style == "Melee" then<br />
baseLevel = p._getMonsterLevel(monster, 'Defence')<br />
bonus = p.getEquipmentStat(monster, 'meleeDefenceBonus')<br />
elseif style == "Ranged" then<br />
baseLevel = p._getMonsterLevel(monster, 'Defence')<br />
bonus = p.getEquipmentStat(monster, 'rangedDefenceBonus')<br />
elseif style == "Magic" then<br />
baseLevel = math.floor(p._getMonsterLevel(monster, 'Magic') * 0.7 + p._getMonsterLevel(monster, 'Defence') * 0.3)<br />
bonus = p.getEquipmentStat(monster, 'magicDefenceBonus')<br />
else<br />
return "ERROR: Must choose Melee, Ranged, or Magic[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p.calculateStandardStat(baseLevel, bonus)<br />
end<br />
<br />
function p.getMonsterER(frame)<br />
local args = frame.args ~= nil and frame.args or frame<br />
local MonsterName = args[1]<br />
local style = args[2]<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterER(monster, style)<br />
end<br />
<br />
-- Determines if the monster is capable of dropping bones, and returns the bones<br />
-- item if so, or nil otherwise<br />
function p._getMonsterBones(monster)<br />
if monster.bones ~= nil and monster.bones >= 0 then<br />
local boneItem = Items.getItemByID(monster.bones)<br />
if boneItem.prayerPoints == nil then<br />
-- Assume bones without prayer points are shards (from God dungeons),<br />
-- and drop unconditionally<br />
return boneItem<br />
elseif not monster.isBoss and not p._isDungeonOnlyMonster(monster) then<br />
-- Otherwise, bones drop when the monster isn't dungeon exclusive<br />
return boneItem<br />
end<br />
end<br />
end<br />
<br />
function p._isDungeonOnlyMonster(monster)<br />
local areaList = Areas.getMonsterAreas(monster.id)<br />
local inDungeon = false<br />
<br />
for i, area in ipairs(areaList) do<br />
if area.type == 'dungeon' then<br />
inDungeon = true<br />
else<br />
return false<br />
end<br />
end<br />
return inDungeon<br />
end<br />
<br />
function p.isDungeonOnlyMonster(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with name "..monsterName.." found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._isDungeonOnlyMonster(monster)<br />
end<br />
<br />
function p._getMonsterAreas(monster, excludeDungeons)<br />
local resultPart = {}<br />
local hideDungeons = excludeDungeons ~= nil and excludeDungeons or false<br />
local areaList = Areas.getMonsterAreas(monster.id)<br />
for i, area in ipairs(areaList) do<br />
if area.type ~= 'dungeon' or not hideDungeons then<br />
table.insert(resultPart, Icons.Icon({area.name, type = area.type}))<br />
end<br />
end<br />
return table.concat(resultPart, '<br/>')<br />
end<br />
<br />
function p.getMonsterAreas(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local hideDungeons = frame.args ~= nil and frame.args[2] or nil<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with name "..monsterName.." found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterAreas(monster, hideDungeons)<br />
end<br />
<br />
function p.getSpecAttackMaxHit(specAttack, normalMaxHit)<br />
local result = 0<br />
for i, dmg in pairs(specAttack.damage) do<br />
if dmg.maxRoll == 'Fixed' then<br />
result = dmg.maxPercent * 10<br />
elseif dmg.maxRoll == 'MaxHit' then<br />
if dmg.character == 'Target' then<br />
--Confusion applied damage based on the player's max hit. Gonna just ignore that one<br />
result = 0<br />
else<br />
result = dmg.maxPercent * normalMaxHit * 0.01<br />
end<br />
elseif Shared.contains({'Bleeding', 'Poisoned'}, dmg.maxRoll) then<br />
-- TODO: This is limited in that there is no verification that bleed/poison<br />
-- can be applied to the target, it is assumed that it can and so this applies<br />
result = result + dmg.maxPercent * 10<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.canSpecAttackApplyEffect(specAttack, effectType)<br />
local result = false<br />
for i, effect in pairs(specAttack.prehitEffects) do<br />
if effect.type == effectType then<br />
result = true<br />
break<br />
end<br />
end<br />
<br />
for i, effect in pairs(specAttack.onhitEffects) do<br />
if effect.type == effectType then<br />
result = true<br />
break<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p._getMonsterMaxHit(monster, doStuns)<br />
-- 2021-06-11 Adjusted for v0.20 stun/sleep changes, where damage multiplier now applies<br />
-- to all enemy attacks if stun/sleep is present on at least one special attack<br />
if doStuns == nil then<br />
doStuns = true<br />
elseif type(doStuns) == 'string' then<br />
doStuns = string.upper(doStuns) == 'TRUE'<br />
end<br />
<br />
local normalChance = 100<br />
local specialMaxHit = 0<br />
local normalMaxHit = p._getMonsterBaseMaxHit(monster)<br />
local hasActiveBuffSpec = false<br />
local damageMultiplier = 1<br />
if monster.specialAttacks[1] ~= nil then<br />
local canStun, canSleep = false, false<br />
for i, specAttack in pairs(monster.specialAttacks) do<br />
if monster.overrideSpecialChances ~= nil then<br />
normalChance = normalChance - monster.overrideSpecialChances[i]<br />
else<br />
normalChance = normalChance - specAttack.defaultChance<br />
end<br />
local thisMax = p.getSpecAttackMaxHit(specAttack, normalMaxHit)<br />
if not canStun and p.canSpecAttackApplyEffect(specAttack, 'Stun') then canStun = true end<br />
if not canSleep and p.canSpecAttackApplyEffect(specAttack, 'Sleep') then canSleep = true end<br />
<br />
if thisMax > specialMaxHit then specialMaxHit = thisMax end<br />
if Shared.contains(string.upper(specAttack.description), 'NORMAL ATTACK INSTEAD') then <br />
hasActiveBuffSpec = true <br />
end<br />
end<br />
<br />
if canSleep and doStuns then damageMultiplier = damageMultiplier * 1.2 end<br />
if canStun and doStuns then damageMultiplier = damageMultiplier * 1.3 end<br />
end<br />
--Ensure that if the monster never does a normal attack, the normal max hit is irrelevant<br />
if normalChance == 0 and not hasActiveBuffSpec then normalMaxHit = 0 end<br />
return math.floor(math.max(specialMaxHit, normalMaxHit) * damageMultiplier)<br />
end<br />
<br />
function p.getMonsterMaxHit(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local doStuns = frame.args ~= nil and frame.args[2] or true<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterMaxHit(monster, doStuns)<br />
end<br />
<br />
function p._getMonsterBaseMaxHit(monster)<br />
--8/27/21 - Now references p.calculateStandardMaxHit for Melee & Ranged<br />
local result = 0<br />
local baseLevel = 0<br />
local bonus = 0<br />
if monster.attackType == 'melee' then<br />
baseLevel = p._getMonsterLevel(monster, 'Strength')<br />
bonus = p.getEquipmentStat(monster, 'meleeStrengthBonus')<br />
result = p.calculateStandardMaxHit(baseLevel, bonus)<br />
elseif monster.attackType == 'ranged' then<br />
baseLevel = p._getMonsterLevel(monster, 'Ranged')<br />
bonus = p.getEquipmentStat(monster, 'rangedStrengthBonus')<br />
result = p.calculateStandardMaxHit(baseLevel, bonus)<br />
elseif monster.attackType == 'magic' then<br />
local mSpell = nil<br />
if monster.selectedSpell ~= nil then mSpell = Magic.getSpellByID('Spells', monster.selectedSpell) end<br />
<br />
bonus = p.getEquipmentStat(monster, 'magicDamageBonus')<br />
baseLevel = p._getMonsterLevel(monster, 'Magic')<br />
<br />
result = math.floor(10 * mSpell.maxHit * (1 + bonus / 100) * (1 + (baseLevel + 1) / 200))<br />
elseif monster.attackType == 'random' then<br />
local hitArray = {}<br />
local iconText = Icons.Icon({'Melee', notext=true})<br />
baseLevel = p._getMonsterLevel(monster, 'Strength')<br />
bonus = p.getEquipmentStat(monster, 'meleeStrengthBonus')<br />
table.insert(hitArray, p.calculateStandardMaxHit(baseLevel, bonus))<br />
<br />
iconText = Icons.Icon({'Ranged', type='skill', notext=true})<br />
baseLevel = p._getMonsterLevel(monster, 'Ranged')<br />
bonus = p.getEquipmentStat(monster, 'rangedStrengthBonus')<br />
table.insert(hitArray, p.calculateStandardMaxHit(baseLevel, bonus))<br />
<br />
iconText = Icons.Icon({'Magic', type='skill', notext=true})<br />
local mSpell = nil<br />
if monster.selectedSpell ~= nil then mSpell = Magic.getSpellByID('Spells', monster.selectedSpell) end<br />
bonus = p.getEquipmentStat(monster, 'magicDamageBonus')<br />
baseLevel = p._getMonsterLevel(monster, 'Magic')<br />
local magicDmg = math.floor(10 * mSpell.maxHit * (1 + bonus / 100) * (1 + (baseLevel + 1) / 200))<br />
table.insert(hitArray, magicDmg)<br />
<br />
local max = 0<br />
for i, val in pairs(hitArray) do<br />
if val > max then max = val end<br />
end<br />
result = max<br />
else<br />
return "ERROR: This monster has an invalid attack type somehow[[Category:Pages with script errors]]"<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getMonsterBaseMaxHit(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterBaseMaxHit(monster)<br />
end<br />
<br />
function p.getMonsterAttacks(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = ''<br />
local iconText = p._getMonsterStyleIcon({monster, notext=true})<br />
local typeText = ''<br />
if monster.attackType == 'melee' then<br />
typeText = 'Melee'<br />
elseif monster.attackType == 'ranged' then<br />
typeText = 'Ranged'<br />
elseif monster.attackType == 'magic' then<br />
typeText = 'Magic'<br />
elseif monster.attackType == 'random' then<br />
typeText = "Random"<br />
end<br />
<br />
local buffAttacks = {}<br />
local hasActiveBuffSpec = false<br />
<br />
local normalAttackChance = 100<br />
if monster.specialAttacks[1] ~= nil then<br />
for i, specAttack in pairs(monster.specialAttacks) do<br />
local attChance = 0<br />
if monster.overrideSpecialChances ~= nil then<br />
attChance = monster.overrideSpecialChances[i]<br />
else<br />
attChance = specAttack.defaultChance<br />
end<br />
normalAttackChance = normalAttackChance - attChance<br />
<br />
result = result..'\r\n* '..attChance..'% '..iconText..' '..specAttack.name..'\r\n** '..specAttack.description<br />
<br />
if Shared.contains(string.upper(specAttack.description), 'NORMAL ATTACK INSTEAD') then<br />
table.insert(buffAttacks, specAttack.name)<br />
hasActiveBuffSpec = true <br />
end<br />
end<br />
end<br />
if normalAttackChance == 100 then<br />
result = iconText..' 1 - '..p._getMonsterBaseMaxHit(monster)..' '..typeText..' Damage'<br />
elseif normalAttackChance > 0 then<br />
result = '* '..normalAttackChance..'% '..iconText..' 1 - '..p.getMonsterBaseMaxHit(frame)..' '..typeText..' Damage'..result<br />
elseif hasActiveBuffSpec then<br />
--If the monster normally has a 0% chance of doing a normal attack but some special attacks can't be repeated, include it<br />
--(With a note about when it does it)<br />
result = '* '..iconText..' 1 - '..p._getMonsterBaseMaxHit(monster)..' '..typeText..' Damage (Instead of repeating '..table.concat(buffAttacks, ' or ')..' while the effect is already active)'..result<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getMonsterPassives(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = ''<br />
if type(monster.passiveID) == 'table' and Shared.tableCount(monster.passiveID) > 0 then<br />
result = result .. '===Passives==='<br />
for i, passiveID in pairs(monster.passiveID) do<br />
local passive = p.getPassiveByID(passiveID)<br />
result = result .. '\r\n* ' .. passive.name .. '\r\n** ' .. passive.description<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.getMonsterCategories(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = '[[Category:Monsters]]'<br />
<br />
if monster.attackType == 'melee' then<br />
result = result..'[[Category:Melee Monsters]]'<br />
elseif monster.attackType == 'ranged' then<br />
result = result..'[[Category:Ranged Monsters]]'<br />
elseif monster.attackType == 'magic' then<br />
result = result..'[[Category:Magic Monsters]]'<br />
end<br />
<br />
if monster.specialAttacks[1] ~= nil then<br />
result = result..'[[Category:Monsters with Special Attacks]]'<br />
end<br />
<br />
if monster.isBoss then<br />
result = result..'[[Category:Bosses]]'<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getOtherMonsterBoxText(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = ''<br />
<br />
--Going through and finding out which damage bonuses will apply to this monster<br />
local monsterTypes = {}<br />
if monster.isBoss then table.insert(monsterTypes, 'Boss') end<br />
<br />
local areaList = Areas.getMonsterAreas(monster.id)<br />
local counts = {combat = 0, slayer = 0, dungeon = 0}<br />
for i, area in Shared.skpairs(areaList) do<br />
counts[area.type] = counts[area.type] + 1<br />
end<br />
<br />
if counts.combat > 0 then table.insert(monsterTypes, 'Combat Area') end<br />
if counts.slayer > 0 then table.insert(monsterTypes, 'Slayer Area') end<br />
if counts.dungeon > 0 then table.insert(monsterTypes, 'Dungeon') end<br />
<br />
result = result.."\r\n|-\r\n|'''Monster Types:''' "..table.concat(monsterTypes, ", ")<br />
<br />
local SlayerTier = 'N/A'<br />
if monster.canSlayer then<br />
SlayerTier = Constants.getSlayerTierNameByLevel(p._getMonsterCombatLevel(monster))<br />
end<br />
<br />
result = result.."\r\n|-\r\n|'''"..Icons.Icon({'Slayer', type='skill'}).." [[Slayer#Slayer Tier Monsters|Tier]]:''' "<br />
if monster.canSlayer then<br />
result = result.."[[Slayer#"..SlayerTier.."|"..SlayerTier.."]]"<br />
else<br />
result = result..SlayerTier<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getMonsterDrops(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = ''<br />
<br />
local bones = p._getMonsterBones(monster)<br />
local boneVal = 0<br />
--Show the bones only if either the monster shows up outside of dungeons _or_ the monster drops shards<br />
if bones ~= nil then<br />
local boneQty = (monster.boneQty ~= nil and monster.boneQty or 1)<br />
result = result.."'''Always Drops:'''"<br />
result = result..'\r\n{|class="wikitable" id="bonedrops"'<br />
result = result..'\r\n!Item !! Qty'<br />
result = result..'\r\n|-\r\n|'..Icons.Icon({bones.name, type='item'})<br />
result = result..'||'..boneQty..'\r\n'..'|}'<br />
boneVal = boneQty * bones.sellsFor<br />
end<br />
<br />
--Likewise, seeing the loot table is tied to the monster appearing outside of dungeons<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100<br />
local lootValue = 0<br />
<br />
result = result.."'''Loot:'''"<br />
local avgGp = 0<br />
<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2<br />
local gpTxt = Icons.GP(monster.dropCoins[1], monster.dropCoins[2])<br />
result = result.."\r\nIn addition to loot, the monster will also drop "..gpTxt..'.'<br />
end<br />
<br />
local multiDrop = Shared.tableCount(monster.lootTable) > 1<br />
local totalWt = 0<br />
for i, row in pairs(monster.lootTable) do<br />
totalWt = totalWt + row[2]<br />
end<br />
result = result..'\r\n{|class="wikitable sortable" id="itemdrops"'<br />
result = result..'\r\n!Item!!Qty'<br />
result = result..'!!Price!!colspan="2"|Chance'<br />
<br />
--Sort the loot table by weight in descending order<br />
table.sort(monster.lootTable, function(a, b) return a[2] > b[2] end)<br />
for i, row in Shared.skpairs(monster.lootTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
<br />
local maxQty = row[3]<br />
if thisItem ~= nil then<br />
result = result..'\r\n|-\r\n|'..Icons.Icon({thisItem.name, type='item'})<br />
else<br />
result = result..'\r\n|-\r\n|Unknown Item[[Category:Pages with script errors]]'<br />
end<br />
result = result..'||style="text-align:right" data-sort-value="'..maxQty..'"|'<br />
<br />
if maxQty > 1 then<br />
result = result.. '1 - '<br />
end<br />
result = result..Shared.formatnum(row[3])<br />
<br />
--Adding price columns<br />
local itemPrice = 0<br />
if thisItem == nil then<br />
result = result..'||data-sort-value="0"|???'<br />
else<br />
itemPrice = thisItem.sellsFor ~= nil and thisItem.sellsFor or 0<br />
if itemPrice == 0 or maxQty == 1 then<br />
result = result..'||'..Icons.GP(itemPrice)<br />
else<br />
result = result..'||'..Icons.GP(itemPrice, itemPrice * maxQty)<br />
end<br />
end<br />
<br />
--Getting the drop chance<br />
local dropChance = (row[2] / totalWt * lootChance)<br />
if dropChance < 100 then<br />
--Show fraction as long as it isn't going to be 1/1<br />
result = result..'||style="text-align:right" data-sort-value="'..row[2]..'"'<br />
result = result..'|'..Shared.fraction(row[2] * lootChance, totalWt * 100)<br />
result = result..'||'<br />
else<br />
result = result..'||colspan="2" data-sort-value="'..row[2]..'"'<br />
end<br />
-- If chance is less than 0.10% then show 2 significant figures, otherwise 2 decimal places<br />
local fmt = (dropChance < 0.10 and '%.2g') or '%.2f'<br />
result = result..'style="text-align:right"|'..string.format(fmt, dropChance)..'%'<br />
<br />
--Adding to the average loot value based on price & dropchance<br />
lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((1 + maxQty) / 2))<br />
end<br />
if multiDrop then<br />
result = result..'\r\n|-class="sortbottom" \r\n!colspan="3"|Total:'<br />
if lootChance < 100 then<br />
result = result..'\r\n|style="text-align:right"|'..Shared.fraction(lootChance, 100)..'||'<br />
else<br />
result = result..'\r\n|colspan="2" '<br />
end<br />
result = result..'style="text-align:right"|'..Shared.round(lootChance, 2, 2)..'%'<br />
end<br />
result = result..'\r\n|}'<br />
result = result..'\r\nThe loot dropped by the average kill is worth '..Icons.GP(Shared.round(lootValue, 2, 0)).." if sold."<br />
if avgGp > 0 then<br />
result = result.."<br/>Including GP"<br />
if boneVal > 0 then<br />
result = result..' and bones'<br />
end<br />
result = result..', the average kill is worth '..Icons.GP(Shared.round(avgGp + lootValue + boneVal, 2, 0))..'.'<br />
end<br />
end<br />
<br />
--If no other drops, make sure to at least say so.<br />
if result == '' then result = 'None' end<br />
return result<br />
end<br />
<br />
function p._getMonsterLootValue(monster)<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = 0<br />
local boneVal = 0<br />
<br />
local bones = p._getMonsterBones(monster)<br />
--Show the bones only if either the monster shows up outside of dungeons _or_ the monster drops shards<br />
if bones ~= nil then<br />
local boneQty = monster.boneQty ~= nil and monster.boneQty or 1<br />
boneVal = bones.sellsFor * boneQty<br />
result = result + boneVal<br />
end<br />
<br />
--Likewise, seeing the loot table is tied to the monster appearing outside of dungeons<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100<br />
local lootValue = 0<br />
<br />
local avgGp = 0<br />
<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2<br />
end<br />
<br />
local multiDrop = Shared.tableCount(monster.lootTable) > 1<br />
local totalWt = 0<br />
for i, row in pairs(monster.lootTable) do<br />
totalWt = totalWt + row[2]<br />
end<br />
<br />
for i, row in Shared.skpairs(monster.lootTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
<br />
local maxQty = row[3]<br />
<br />
--Adding price columns<br />
local itemPrice = 0<br />
if thisItem ~= nil then<br />
itemPrice = thisItem.sellsFor ~= nil and thisItem.sellsFor or 0<br />
end<br />
<br />
--Getting the drop chance<br />
local dropChance = (row[2] / totalWt * lootChance)<br />
--Adding to the average loot value based on price & dropchance<br />
lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((1 + maxQty) / 2))<br />
end<br />
if avgGp > 0 then<br />
result = result + avgGp + lootValue<br />
end<br />
end<br />
<br />
return result<br />
end<br />
<br />
-- Find drop chance of specified item from specified monster. <br />
-- Usage: |Monster Name|Item Name<br />
function p.getItemDropChance(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame[1]<br />
local ItemName = frame.args ~= nil and frame.args[2] or frame[2]<br />
<br />
local monster = p.getMonster(MonsterName)<br />
local item = Items.getItem(ItemName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
if item == nil then<br />
return "ERROR: No item with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100<br />
<br />
local totalWt = 0<br />
--for i, row in pairs(monster.lootTable) do<br />
--totalWt = totalWt + row[2]<br />
--end<br />
<br />
local dropChance = 0<br />
local dropWt = 0<br />
for i, row in Shared.skpairs(monster.lootTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
totalWt = totalWt + row[2]<br />
if item['id'] == thisItem['id'] then<br />
dropWt = row[2]<br />
end<br />
end<br />
dropChance = (dropWt / totalWt * lootChance)<br />
return Shared.round(dropChance, 2, 2)<br />
end<br />
end <br />
<br />
function p.getChestDrops(frame)<br />
local ChestName = frame.args ~= nil and frame.args[1] or frame<br />
local chest = Items.getItem(ChestName)<br />
<br />
if chest == nil then<br />
return "ERROR: No item named "..ChestName..' found[[Category:Pages with script errors]]'<br />
end<br />
<br />
local result = ''<br />
<br />
if chest.dropTable == nil then<br />
return "ERROR: "..ChestName.." does not have a drop table[[Category:Pages with script errors]]"<br />
else<br />
local lootChance = 100<br />
local lootValue = 0<br />
<br />
local multiDrop = Shared.tableCount(chest.dropTable) > 1<br />
local totalWt = 0<br />
for i, row in pairs(chest.dropTable) do<br />
totalWt = totalWt + row[2]<br />
end<br />
result = result..'\r\n{|class="wikitable sortable"'<br />
result = result..'\r\n!Item!!Qty'<br />
result = result..'!!colspan="2"|Chance!!Price'<br />
<br />
--Sort the loot table by weight in descending order<br />
for i, row in pairs(chest.dropTable) do<br />
if chest.dropQty ~= nil then<br />
table.insert(row, chest.dropQty[i])<br />
else<br />
table.insert(row, 1)<br />
end<br />
end<br />
table.sort(chest.dropTable, function(a, b) return a[2] > b[2] end)<br />
for i, row in Shared.skpairs(chest.dropTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
local qty = row[3]<br />
result = result..'\r\n|-\r\n|'..Icons.Icon({thisItem.name, type='item'})<br />
result = result..'||style="text-align:right" data-sort-value="'..qty..'"|'<br />
<br />
if qty > 1 then<br />
result = result.. '1 - '<br />
end<br />
result = result..Shared.formatnum(qty)<br />
<br />
local dropChance = (row[2] / totalWt) * 100<br />
result = result..'||style="text-align:right" data-sort-value="'..row[2]..'"'<br />
result = result..'|'..Shared.fraction(row[2], totalWt)<br />
<br />
result = result..'||style="text-align:right"|'..Shared.round(dropChance, 2, 2)..'%'<br />
<br />
result = result..'||style="text-align:left" data-sort-value="'..thisItem.sellsFor..'"'<br />
if qty > 1 then<br />
result = result..'|'..Icons.GP(thisItem.sellsFor, thisItem.sellsFor * qty)<br />
else<br />
result = result..'|'..Icons.GP(thisItem.sellsFor)<br />
end<br />
lootValue = lootValue + (dropChance * 0.01 * thisItem.sellsFor * ((1 + qty)/ 2))<br />
end<br />
result = result..'\r\n|}'<br />
result = result..'\r\nThe average value of the contents of one chest is '..Icons.GP(Shared.round(lootValue, 2, 0))..'.'<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getAreaMonsterTable(frame)<br />
local areaName = frame.args ~= nil and frame.args[1] or frame<br />
local area = Areas.getArea(areaName)<br />
if area == nil then<br />
return "ERROR: Could not find an area named "..areaName..'[[Category:Pages with script errors]]'<br />
end<br />
<br />
if area.type == 'dungeon' then<br />
return p.getDungeonMonsterTable(frame)<br />
end<br />
<br />
local tableTxt = '{| class="wikitable sortable"'<br />
tableTxt = tableTxt..'\r\n! Name !! Combat Level !! Hitpoints !! Max Hit !! [[Combat Triangle|Combat Style]]'<br />
for i, monsterID in pairs(area.monsters) do<br />
local monster = p.getMonsterByID(monsterID)<br />
tableTxt = tableTxt..'\r\n|-\r\n|'..Icons.Icon({monster.name, type='monster'})<br />
tableTxt = tableTxt..'||'..p._getMonsterCombatLevel(monster)<br />
tableTxt = tableTxt..'||'..Shared.formatnum(p._getMonsterHP(monster))<br />
tableTxt = tableTxt..'||'..Shared.formatnum(p._getMonsterMaxHit(monster))<br />
tableTxt = tableTxt..'||'..p._getMonsterStyleIcon({monster, nolink=true})<br />
end<br />
tableTxt = tableTxt..'\r\n|}'<br />
return tableTxt<br />
end<br />
<br />
function p.getDungeonMonsterTable(frame)<br />
local areaName = frame.args ~= nil and frame.args[1] or frame<br />
local area = Areas.getArea(areaName)<br />
if area == nil then<br />
return "ERROR: Could not find a dungeon named "..areaName..'[[Category:Pages with script errors]]'<br />
end<br />
<br />
--For Dungeons, go through and count how many of each monster are in the dungeon first<br />
local monsterCounts = {}<br />
for i, monsterID in pairs(area.monsters) do<br />
if monsterCounts[monsterID] == nil then<br />
monsterCounts[monsterID] = 1<br />
else<br />
monsterCounts[monsterID] = monsterCounts[monsterID] + 1<br />
end<br />
end<br />
<br />
local usedMonsters = {}<br />
<br />
-- Declare function for building table rows to avoid repeating code<br />
local buildRow = function(entityID, monsterCount, specialType)<br />
local monIcon, monLevel, monHP, monMaxHit, monStyle, monCount<br />
local monData = {}<br />
if specialType ~= nil and Shared.contains({'Afflicted', 'SlayerArea'}, specialType) then<br />
-- Special handling for Into the Mist<br />
if specialType == 'Afflicted' then<br />
local iconQ = Icons.Icon({'Into the Mist', notext=true, nolink=true, img='Question'})<br />
monIcon = Icons.Icon({'Into the Mist', 'Afflicted Monster', nolink=true, img='Question'})<br />
monLevel, monHP, monMaxHit, monStyle, monCount = iconQ, iconQ, iconQ, iconQ, monsterCount<br />
elseif specialType == 'SlayerArea' then<br />
-- entityID corresponds to a slayer area<br />
local area = Areas.getAreaByID('slayer', entityID)<br />
monIcon = Icons.Icon({area.name, type='combatArea'}) .. ' Monsters'<br />
monLevel = {p.getLowHighStat(area.monsters, function(monster) return p._getMonsterCombatLevel(monster) end)}<br />
monHP = {p.getLowHighStat(area.monsters, function(monster) return p._getMonsterHP(monster) end)}<br />
local lowMaxHit, highMaxHit = p.getLowHighStat(area.monsters, function(monster) return p._getMonsterMaxHit(monster) end)<br />
monMaxHit = highMaxHit<br />
monStyle = Icons.Icon({area.name, area.name, notext=true, nolink=true, img='Question'})<br />
monCount = monsterCount<br />
end<br />
else<br />
-- entityID corresponds to a monster<br />
local monster = p.getMonsterByID(entityID)<br />
monIcon = Icons.Icon({monster.name, type='monster'})<br />
monLevel = p._getMonsterCombatLevel(monster)<br />
monHP = p._getMonsterHP(monster)<br />
monMaxHit = p._getMonsterMaxHit(monster)<br />
monStyle = p._getMonsterStyleIcon({monster})<br />
monCount = monsterCount<br />
end<br />
local getValSort = function(val)<br />
if type(val) == 'table' then<br />
if type(val[1]) == 'number' and type(val[2]) == 'number' then<br />
return (val[1] + val[2]) / 2<br />
else<br />
return (type(val[1]) == 'number' and val[1]) or 0<br />
end<br />
else<br />
return (type(val) == 'number' and val) or 0<br />
end<br />
end<br />
local getValText = function(val)<br />
if type(val) == 'table' and Shared.tableCount(val) == 2 then<br />
if type(val[1]) == 'number' and type(val[2]) == 'number' then<br />
return Shared.formatnum(val[1]) .. ' - ' .. Shared.formatnum(val[2])<br />
else<br />
return val[1] .. ' - ' .. val[2]<br />
end<br />
elseif type(val) == 'number' then<br />
return Shared.formatnum(val)<br />
else<br />
return val<br />
end<br />
end<br />
<br />
local resultPart = {}<br />
table.insert(resultPart, '\r\n|-\r\n| ' .. monIcon)<br />
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monLevel) .. '"| ' .. getValText(monLevel))<br />
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monHP) .. '"| ' .. getValText(monHP))<br />
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monMaxHit) .. '"| ' .. getValText(monMaxHit))<br />
table.insert(resultPart, '\r\n| ' .. monStyle)<br />
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monCount) .. '"| ' .. getValText(monCount))<br />
return table.concat(resultPart)<br />
end<br />
<br />
local returnPart = {}<br />
table.insert(returnPart, '{| class="wikitable sortable"')<br />
table.insert(returnPart, '\r\n! Name !! Combat Level !! Hitpoints !! Max Hit !! [[Combat Triangle|Combat Style]] !! Count')<br />
-- Special handing for Impending Darkness event<br />
-- TODO needs to be revised once there is a better understanding of how the event works<br />
--if area.isEvent ~= nil and area.isEvent then<br />
-- for i, eventAreaID in ipairs(Areas.eventData.slayerAreas) do<br />
-- table.insert(returnPart, buildRow(eventAreaID, {5, 8}, 'SlayerArea'))<br />
-- end<br />
-- -- Add Bane * 4<br />
-- table.insert(returnPart, buildRow(152, 4))<br />
--end<br />
for i, monsterID in pairs(area.monsters) do<br />
if not Shared.contains(usedMonsters, monsterID) then<br />
if monsterID >= 0 then<br />
table.insert(returnPart, buildRow(monsterID, monsterCounts[monsterID]))<br />
else<br />
--Special handling for Into the Mist<br />
table.insert(returnPart, buildRow(monsterID, monsterCounts[monsterID], 'Afflicted'))<br />
end<br />
table.insert(usedMonsters, monsterID)<br />
end<br />
end<br />
table.insert(returnPart, '\r\n|}')<br />
return table.concat(returnPart)<br />
end<br />
<br />
function p.getDungeonTotalHp(frame)<br />
local areaName = frame.args ~= nil and frame.args[1] or frame<br />
local area = Areas.getArea(areaName)<br />
if area == nil then<br />
return "ERROR: Could not find a dungeon named "..areaName..'[[Category:Pages with script errors]]'<br />
end<br />
local totalHP = 0<br />
<br />
for i, monsterID in pairs(area.monsters) do<br />
if not Shared.contains(usedMonsters, monsterID) then<br />
local monster = p.getMonsterByID(monsterID)<br />
totalHP = totalHP + p._getMonsterHP(monster)<br />
end<br />
end<br />
return totalHP<br />
end<br />
<br />
function p._getAreaMonsterList(area)<br />
local monsterList = {}<br />
for i, monsterID in pairs(area.monsters) do<br />
local monster = p.getMonsterByID(monsterID)<br />
table.insert(monsterList, Icons.Icon({monster.name, type='monster'}))<br />
end<br />
return table.concat(monsterList, '<br/>')<br />
end<br />
<br />
function p._getDungeonMonsterList(area)<br />
local monsterList = {}<br />
local lastMonster = nil<br />
local lastID = -2<br />
local count = 0<br />
-- Special handing for Impending Darkness event<br />
-- TODO needs to be revised once there is a better understanding of how the event works<br />
--if area.isEvent ~= nil and area.isEvent then<br />
-- for i, eventAreaID in ipairs(Areas.eventData.slayerAreas) do<br />
-- local eventArea = Areas.getAreaByID('slayer', eventAreaID)<br />
-- table.insert(monsterList, '5-8 ' .. Icons.Icon({eventArea.name, type='combatArea'}) .. ' Monsters')<br />
-- end<br />
-- table.insert(monsterList, '4 ' .. Icons.Icon({'Bane', type='monster'}))<br />
--end<br />
for i, monsterID in Shared.skpairs(area.monsters) do<br />
if monsterID ~= lastID then<br />
local monster = nil <br />
if monsterID ~= -1 then monster = p.getMonsterByID(monsterID) end<br />
if lastID ~= -2 then<br />
if lastID == -1 then<br />
--Special handling for Afflicted Monsters<br />
table.insert(monsterList, Icons.Icon({'Affliction', 'Afflicted Monster', img='Question', qty=count}))<br />
else<br />
local name = lastMonster.name<br />
table.insert(monsterList, Icons.Icon({name, type='monster', qty=count}))<br />
end<br />
end<br />
lastMonster = monster<br />
lastID = monsterID<br />
count = 1<br />
else<br />
count = count + 1<br />
end<br />
--Make sure the final monster in the dungeon gets counted<br />
if i == Shared.tableCount(area.monsters) then<br />
local name = lastMonster.name<br />
table.insert(monsterList, Icons.Icon({lastMonster.name, type='monster', qty=count}))<br />
end<br />
end<br />
return table.concat(monsterList, '<br/>')<br />
end<br />
<br />
function p.getAreaMonsterList(frame)<br />
local areaName = frame.args ~= nil and frame.args[1] or frame<br />
local area = Areas.getArea(areaName)<br />
if area == nil then<br />
return "ERROR: Could not find an area named "..areaName..'[[Category:Pages with script errors]]'<br />
end<br />
<br />
if area.type == 'dungeon' then<br />
return p._getDungeonMonsterList(area)<br />
else<br />
return p._getAreaMonsterList(area)<br />
end<br />
end<br />
<br />
function p.getFoxyTable(frame)<br />
local result = 'Monster,Min GP,Max GP,Average GP'<br />
for i, monster in Shared.skpairs(MonsterData.Monsters) do<br />
if not p._isDungeonOnlyMonster(monster) then<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
local avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2<br />
result = result..'<br/>'..monster.name..','..monster.dropCoins[1]..','..(monster.dropCoins[2])..','..avgGp<br />
end<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p._getMonsterAverageGP(monster)<br />
local result = ''<br />
local totalGP = 0<br />
<br />
local bones = p._getMonsterBones(monster)<br />
if bones ~= nil then<br />
totalGP = totalGP + bones.sellsFor * (type(monster.boneQty) == 'number' and monster.boneQty or 1)<br />
end<br />
<br />
--Likewise, seeing the loot table is tied to the monster appearing outside of dungeons<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100<br />
local lootValue = 0<br />
<br />
local avgGp = 0<br />
<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2<br />
end<br />
<br />
totalGP = totalGP + avgGp<br />
<br />
local multiDrop = Shared.tableCount(monster.lootTable) > 1<br />
local totalWt = 0<br />
for i, row in pairs(monster.lootTable) do<br />
totalWt = totalWt + row[2]<br />
end<br />
<br />
for i, row in Shared.skpairs(monster.lootTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
local maxQty = row[3]<br />
<br />
local itemPrice = thisItem.sellsFor ~= nil and thisItem.sellsFor or 0<br />
<br />
--Getting the drop chance<br />
local dropChance = (row[2] / totalWt * lootChance)<br />
<br />
--Adding to the average loot value based on price & dropchance<br />
lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((1 + maxQty) / 2))<br />
end<br />
<br />
totalGP = totalGP + lootValue<br />
end<br />
<br />
return Shared.round(totalGP, 2, 2)<br />
end<br />
<br />
function p.getMonsterAverageGP(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterAverageGP(monster)<br />
end<br />
<br />
function p.getMonsterEVTable(frame)<br />
local result = '{| class="wikitable sortable"'<br />
result = result..'\r\n!Monster!!Combat Level!!Average GP'<br />
for i, monsterTemp in Shared.skpairs(MonsterData.Monsters) do<br />
local monster = Shared.clone(monsterTemp)<br />
monster.id = i - 1<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local monsterGP = p._getMonsterAverageGP(monster)<br />
local combatLevel = p._getMonsterCombatLevel(monster, 'Combat Level')<br />
result = result..'\r\n|-\r\n|'..Icons.Icon({monster.name, type='monster', noicon=true})..'||'..combatLevel..'||'..monsterGP<br />
end<br />
end<br />
result = result..'\r\n|}'<br />
return result<br />
end<br />
<br />
function p.getSlayerTierMonsterTable(frame)<br />
-- Input validation<br />
local tier = frame.args ~= nil and frame.args[1] or frame<br />
local slayerTier = nil<br />
<br />
if tier == nil then<br />
return "ERROR: No tier specified[[Category:Pages with script errors]]"<br />
end<br />
<br />
if tonumber(tier) ~= nil then<br />
slayerTier = Constants.getSlayerTierByID(tonumber(tier))<br />
else<br />
slayerTier = Constants.getSlayerTier(tier)<br />
end<br />
<br />
if slayerTier == nil then<br />
return "ERROR: Invalid slayer tier[[Category:Pages with script errors]]"<br />
end<br />
<br />
-- Obtain required tier details<br />
local minLevel, maxLevel = slayerTier.minLevel, slayerTier.maxLevel<br />
<br />
-- Build list of monster IDs<br />
-- Right now hiddenMonsterIDs is empty<br />
local hiddenMonsterIDs = {}<br />
local monsterIDs = {}<br />
for i, monster in Shared.skpairs(MonsterData.Monsters) do<br />
if monster.canSlayer and not Shared.contains(hiddenMonsterIDs, i - 1) then<br />
local cmbLevel = p._getMonsterCombatLevel(monster)<br />
if cmbLevel >= minLevel and (maxLevel == nil or cmbLevel <= maxLevel) then<br />
table.insert(monsterIDs, i - 1)<br />
end<br />
end<br />
end<br />
<br />
if Shared.tableCount(monsterIDs) == 0 then<br />
-- Somehow no monsters are in the tier, return nothing<br />
return ''<br />
else<br />
return p._getMonsterTable(monsterIDs, true)<br />
end<br />
end<br />
<br />
function p.getFullMonsterTable(frame)<br />
local monsterIDs = {}<br />
for i = 0, Shared.tableCount(MonsterData.Monsters) - 1, 1 do<br />
table.insert(monsterIDs, i)<br />
end<br />
<br />
return p._getMonsterTable(monsterIDs, false)<br />
end<br />
<br />
function p._getMonsterTable(monsterIDs, excludeDungeons)<br />
--Making a single function for getting a table of monsters given a list of IDs.<br />
local hideDungeons = excludeDungeons ~= nil and excludeDungeons or false<br />
local tableParts = {}<br />
table.insert(tableParts, '{| class="wikitable sortable stickyHeader"')<br />
-- First header row<br />
table.insert(tableParts, '\r\n|- class="headerRow-0"\r\n! colspan="5" | !! colspan="4" |Offensive Stats !! colspan="3" |Evasion Rating !! colspan="4" |')<br />
-- Second header row<br />
table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n!Monster !!Name !!ID !!Combat Level ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Hitpoints', type='skill'}))<br />
table.insert(tableParts, '!!Attack Speed (s) !!colspan="2"|Max Hit !!Accuracy ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Defence', type='skill', notext=true}))<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Ranged', type='skill', notext=true}))<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Magic', type='skill', notext=true}))<br />
table.insert(tableParts, '!!' .. Icons.Icon({'Coins', notext=true, nolink=true}) .. ' Coins !!Bones !!Locations')<br />
<br />
-- Generate row per monster<br />
for i, monsterID in Shared.skpairs(monsterIDs) do<br />
local monster = p.getMonsterByID(monsterID)<br />
local cmbLevel = p._getMonsterCombatLevel(monster)<br />
local atkSpeed = p._getMonsterAttackSpeed(monster)<br />
local maxHit = p._getMonsterMaxHit(monster)<br />
local accR = p._getMonsterAR(monster)<br />
local evaR = {p._getMonsterER(monster, "Melee"), p._getMonsterER(monster, "Ranged"), p._getMonsterER(monster, "Magic")}<br />
<br />
local gpRange = {0, 0}<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
gpRange = {monster.dropCoins[1], monster.dropCoins[2]}<br />
end<br />
local gpTxt = nil<br />
if gpRange[1] >= gpRange[2] then<br />
gpTxt = Shared.formatnum(gpRange[1])<br />
else<br />
gpTxt = Shared.formatnum(gpRange[1]) .. ' - ' .. Shared.formatnum(gpRange[2])<br />
end<br />
local bones = p._getMonsterBones(monster)<br />
local boneTxt = (bones ~= nil and Icons.Icon({bones.name, type='item', notext=true})) or 'None'<br />
<br />
table.insert(tableParts, '\r\n|-\r\n|style="text-align: center;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:left" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:right" |' .. monsterID)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. cmbLevel .. '" |' .. Shared.formatnum(cmbLevel))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. p._getMonsterHP(monster) .. '" |' .. Shared.formatnum(p._getMonsterHP(monster)))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. atkSpeed .. '" |' .. Shared.round(atkSpeed, 1, 1))<br />
table.insert(tableParts, '\r\n|style="text-align:center;border-right:hidden" |' .. p._getMonsterStyleIcon({monster, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. maxHit .. '" |' .. Shared.formatnum(maxHit))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. accR .. '" |' .. Shared.formatnum(accR))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[1] .. '" |' .. Shared.formatnum(evaR[1]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[2] .. '" |' .. Shared.formatnum(evaR[2]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[3] .. '" |' .. Shared.formatnum(evaR[3]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:center" |' .. boneTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))<br />
end<br />
<br />
table.insert(tableParts, '\r\n|}')<br />
return table.concat(tableParts)<br />
end<br />
<br />
function p.getMattMonsterTable(frame)<br />
--Making a single function for getting a table of monsters given a list of IDs.<br />
local tableParts = {}<br />
table.insert(tableParts, '{| class="wikitable sortable stickyHeader"')<br />
-- Second header row<br />
table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n!Monster !!Name !!ID !!Combat Level ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Hitpoints', type='skill'}))<br />
table.insert(tableParts, '!!' .. Icons.Icon({'Coins', notext=true, nolink=true}) .. ' Coins !!Avg. Kill Value!!Locations')<br />
<br />
-- Generate row per monster<br />
for i, monster in Shared.skpairs(MonsterData.Monsters) do<br />
local cmbLevel = p._getMonsterCombatLevel(monster)<br />
<br />
local gpRange = {0, 0}<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
gpRange = {monster.dropCoins[1], monster.dropCoins[2]}<br />
end<br />
local gpTxt = nil<br />
if gpRange[1] >= gpRange[2] then<br />
gpTxt = Shared.formatnum(gpRange[1])<br />
else<br />
gpTxt = Shared.formatnum(gpRange[1]) .. ' - ' .. Shared.formatnum(gpRange[2])<br />
end<br />
<br />
local lootVal = p._getMonsterLootValue(monster)<br />
local lootTxt = '0'<br />
if lootVal ~= 0 then<br />
lootTxt = Shared.formatnum(Shared.round(lootVal, 2, 2))<br />
end<br />
<br />
<br />
table.insert(tableParts, '\r\n|-\r\n|style="text-align: center;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:left" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:right" |' .. monster.id)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. cmbLevel .. '" |' .. Shared.formatnum(cmbLevel))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. p._getMonsterHP(monster) .. '" |' .. Shared.formatnum(p._getMonsterHP(monster)))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. lootVal .. '" |' .. lootTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))<br />
end<br />
<br />
table.insert(tableParts, '\r\n|}')<br />
return table.concat(tableParts)<br />
end<br />
<br />
function p.getMattMonsterTableV2(frame)<br />
--Making a single function for getting a table of monsters given a list of IDs.<br />
local tableParts = {}<br />
table.insert(tableParts, '{| class="wikitable sortable stickyHeader"')<br />
-- Second header row<br />
table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n!Monster !!Name !!Combat Level ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Hitpoints', type='skill'}))<br />
table.insert(tableParts, '!!Attack Speed (s) !!colspan="2"|Max Hit !!Accuracy ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Defence', type='skill', notext=true}))<br />
-- table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Ranged', type='skill', notext=true}))<br />
-- table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Magic', type='skill', notext=true}))<br />
table.insert(tableParts, '!!' .. Icons.Icon({'Coins', notext=true, nolink=true}) .. ' Coins !!Avg. Kill Value !!Bones')<br />
<br />
-- Generate row per monster<br />
for i, monster in Shared.skpairs(MonsterData.Monsters) do<br />
local cmbLevel = p._getMonsterCombatLevel(monster)<br />
<br />
local gpRange = {0, 0}<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
gpRange = {monster.dropCoins[1], monster.dropCoins[2]}<br />
end<br />
local gpTxt = nil<br />
if gpRange[1] >= gpRange[2] then<br />
gpTxt = Shared.formatnum(gpRange[1])<br />
else<br />
gpTxt = Shared.formatnum(gpRange[1]) .. ' - ' .. Shared.formatnum(gpRange[2])<br />
end<br />
<br />
local lootVal = p._getMonsterLootValue(monster)<br />
local lootTxt = '0'<br />
if lootVal ~= 0 then<br />
lootTxt = Shared.formatnum(Shared.round(lootVal, 2, 2))<br />
end<br />
<br />
local atkSpeed = p._getMonsterAttackSpeed(monster)<br />
local maxHit = p._getMonsterMaxHit(monster)<br />
local accR = p._getMonsterAR(monster)<br />
local evaR = {p._getMonsterER(monster, "Melee"), p._getMonsterER(monster, "Ranged"), p._getMonsterER(monster, "Magic")}<br />
<br />
local bones = p._getMonsterBones(monster)<br />
local boneTxt = (bones ~= nil and Icons.Icon({bones.name, type='item', notext=true})) or 'None'<br />
<br />
table.insert(tableParts, '\r\n|-\r\n|style="text-align: center;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:left" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))<br />
-- table.insert(tableParts, '\r\n|style="text-align:right" |' .. monster.id)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. cmbLevel .. '" |' .. Shared.formatnum(cmbLevel))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. p._getMonsterHP(monster) .. '" |' .. Shared.formatnum(p._getMonsterHP(monster)))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. atkSpeed .. '" |' .. Shared.round(atkSpeed, 1, 1))<br />
table.insert(tableParts, '\r\n|style="text-align:center;border-right:hidden" |' .. p._getMonsterStyleIcon({monster, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. maxHit .. '" |' .. Shared.formatnum(maxHit))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. accR .. '" |' .. Shared.formatnum(accR))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[1] .. '" |' .. Shared.formatnum(evaR[1]))<br />
--table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[2] .. '" |' .. Shared.formatnum(evaR[2]))<br />
--table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[3] .. '" |' .. Shared.formatnum(evaR[3]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. lootVal .. '" |' .. lootTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:center" |' .. boneTxt)<br />
-- table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))<br />
end<br />
<br />
table.insert(tableParts, '\r\n|}')<br />
return table.concat(tableParts)<br />
end<br />
<br />
function p.getSpecialAttackTable(frame)<br />
local spAttTable = {}<br />
<br />
for i, monster in ipairs(MonsterData.Monsters) do<br />
if monster.specialAttacks ~= nil and Shared.tableCount(monster.specialAttacks) > 0 then<br />
local overrideChance = (monster.overrideSpecialChances ~= nil and Shared.tableCount(monster.overrideSpecialChances) > 0)<br />
for j, spAtt in ipairs(monster.specialAttacks) do<br />
local attChance = (overrideChance and monster.overrideSpecialChances[j] or spAtt.defaultChance)<br />
if spAttTable[spAtt.id] == nil then<br />
spAttTable[spAtt.id] = { ['defn'] = spAtt, ['icons'] = {} }<br />
end<br />
if spAttTable[spAtt.id]['icons'][attChance] == nil then<br />
spAttTable[spAtt.id]['icons'][attChance] = {}<br />
end<br />
table.insert(spAttTable[spAtt.id]['icons'][attChance], Icons.Icon({ monster.name, type = 'monster' }))<br />
end<br />
end<br />
end<br />
<br />
local resultPart = {}<br />
table.insert(resultPart, '{|class="wikitable sortable stickyHeader"')<br />
table.insert(resultPart, '\r\n|- class="headerRow-0"')<br />
table.insert(resultPart, '\r\n!Name!!style="min-width:225px"|Monsters!!Chance!!Effect')<br />
<br />
for i, spAttData in Shared.skpairs(spAttTable) do<br />
local spAtt = spAttData.defn<br />
local firstRow = true<br />
local rowsSpanned = Shared.tableCount(spAttData.icons)<br />
local rowSuffix = ''<br />
if rowsSpanned > 1 then<br />
rowSuffix = '|rowspan="' .. rowsSpanned .. '"'<br />
end<br />
for chance, iconList in Shared.skpairs(spAttData.icons) do<br />
table.insert(resultPart, '\r\n|-')<br />
if firstRow then<br />
table.insert(resultPart, '\r\n' .. rowSuffix .. '| ' .. spAtt.name)<br />
end<br />
table.insert(resultPart, '\r\n|data-sort-value="' .. spAtt.name .. '"| ' .. table.concat(iconList, '<br/>'))<br />
table.insert(resultPart, '\r\n|data-sort-value="' .. chance .. '"| ' .. Shared.round(chance, 2, 0) .. '%')<br />
if firstRow then<br />
table.insert(resultPart, '\r\n' .. rowSuffix .. '| ' .. spAtt.description)<br />
firstRow = false<br />
end<br />
end<br />
end<br />
table.insert(resultPart, '\r\n|}')<br />
<br />
return table.concat(resultPart)<br />
end<br />
<br />
return p</div>
Roko
https://wiki.melvoridle.com/index.php?title=Module:Monsters&diff=51092
Module:Monsters
2022-02-19T13:31:45Z
<p>Roko: </p>
<hr />
<div>local p = {}<br />
<br />
local MonsterData = mw.loadData('Module:Monsters/data')<br />
<br />
local Constants = require('Module:Constants')<br />
local Areas = require('Module:CombatAreas')<br />
local Magic = require('Module:Magic')<br />
local Shared = require('Module:Shared')<br />
local Icons = require('Module:Icons')<br />
local Items = require('Module:Items')<br />
<br />
function p.getMonster(name)<br />
local result = nil<br />
if name == 'Spider (lv. 51)' or name == 'Spider' then<br />
return p.getMonsterByID(50)<br />
elseif name == 'Spider (lv. 52)' or name == 'Spider2' then<br />
return p.getMonsterByID(51)<br />
end<br />
<br />
for i, monster in pairs(MonsterData.Monsters) do<br />
if monster.name == name then<br />
result = Shared.clone(monster)<br />
--Make sure every monster has an ID, and account for the 1-based indexing of Lua<br />
result.id = i - 1<br />
break<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.getMonsterByID(ID)<br />
local result = Shared.clone(MonsterData.Monsters[ID + 1])<br />
if result ~= nil then<br />
result.id = ID<br />
return result<br />
else<br />
return nil<br />
end<br />
end<br />
<br />
function p.getPassive(name)<br />
local result = nil<br />
<br />
for i, passive in pairs(MonsterData.Passives) do<br />
if passive.name == name then<br />
result = Shared.clone(passive)<br />
--Make sure every passive has an ID, and account for the 1-based indexing of Lua<br />
result.id = i - 1<br />
break<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.getPassiveByID(ID)<br />
return MonsterData.Passives[ID + 1]<br />
end<br />
<br />
-- Given a list of monster IDs, calls statFunc with each monster and returns<br />
-- the lowest & highest values<br />
function p.getLowHighStat(idList, statFunc)<br />
local lowVal, highVal = nil, nil<br />
for i, monID in ipairs(idList) do<br />
local monster = p.getMonsterByID(monID)<br />
local statVal = statFunc(monster)<br />
if lowVal == nil or statVal < lowVal then lowVal = statVal end<br />
if highVal == nil or statVal > highVal then highVal = statVal end<br />
end<br />
return lowVal, highVal<br />
end<br />
<br />
function p._getMonsterStat(monster, statName)<br />
if statName == 'HP' then<br />
return p._getMonsterHP(monster)<br />
elseif statName == 'maxHit' then<br />
return p._getMonsterMaxHit(monster)<br />
elseif statName == 'accuracyRating' then<br />
return p._getMonsterAR(monster)<br />
elseif statName == 'meleeEvasionRating' then<br />
return p._getMonsterER(monster, 'Melee')<br />
elseif statName == 'rangedEvasionRating' then<br />
return p._getMonsterER(monster, 'Ranged')<br />
elseif statName == 'magicEvasionRating' then<br />
return p._getMonsterER(monster, 'Magic')<br />
elseif statName == 'damageReduction' then<br />
return p.getEquipmentStat(monster, 'damageReduction')<br />
end<br />
<br />
return monster[statName]<br />
end<br />
<br />
function p.getMonsterStat(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame[1]<br />
local StatName = frame.args ~= nil and frame.args[2] or frame[2]<br />
local monster = p.getMonster(MonsterName)<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterStat(monster, StatName)<br />
end<br />
<br />
function p._getMonsterStyleIcon(frame)<br />
local args = frame.args ~= nil and frame.args or frame<br />
local monster = args[1]<br />
local notext = args.notext<br />
local nolink = args.nolink<br />
<br />
local iconText = ''<br />
if monster.attackType == 'melee' then<br />
iconText = Icons.Icon({'Melee', notext=notext, nolink=nolink})<br />
elseif monster.attackType == 'ranged' then<br />
iconText = Icons.Icon({'Ranged', type='skill', notext=notext, nolink=nolink})<br />
elseif monster.attackType == 'magic' then<br />
iconText = Icons.Icon({'Magic', type='skill', notext=notext, nolink=nolink})<br />
elseif monster.attackType == 'random' then<br />
iconText = Icons.Icon({'Bane', notext=notext, nolink=nolink, img='Question'})<br />
end<br />
<br />
return iconText<br />
end<br />
<br />
function p.getMonsterStyleIcon(frame)<br />
local args = frame.args ~= nil and frame.args or frame<br />
local MonsterName = args[1]<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
args[1] = monster<br />
return p._getMonsterStyleIcon(args)<br />
end<br />
<br />
function p._getMonsterHP(monster)<br />
return 10 * p._getMonsterLevel(monster, 'Hitpoints')<br />
end<br />
<br />
function p.getMonsterEffectiveHP(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
if monster ~= nil then<br />
return math.floor((p._getMonsterHP(monster)/(1 - p._getMonsterStat(monster, 'damageReduction')/100)) + 0.5)<br />
else<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
end<br />
<br />
function p.getMonsterHP(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
if monster ~= nil then<br />
return p._getMonsterHP(monster)<br />
else<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
end<br />
<br />
function p._getMonsterLevel(monster, skillName)<br />
local result = 0<br />
if monster.levels[skillName] ~= nil then<br />
result = monster.levels[skillName]<br />
end<br />
return result<br />
end<br />
<br />
function p.getMonsterLevel(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame[1]<br />
local SkillName = frame.args ~= nil and frame.args[2] or frame[2]<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterLevel(monster, SkillName)<br />
end<br />
<br />
function p.getEquipmentStat(monster, statName)<br />
local result = 0<br />
for i, stat in Shared.skpairs(monster.equipmentStats) do<br />
if stat.key == statName then<br />
result = stat.value<br />
break<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.calculateStandardStat(effectiveLevel, bonus)<br />
--Based on calculateStandardStat in Characters.js<br />
return (effectiveLevel + 9) * (bonus + 64)<br />
end<br />
<br />
function p.calculateStandardMaxHit(baseLevel, strengthBonus)<br />
--Based on calculateStandardMaxHit in Characters.js<br />
local effectiveLevel = baseLevel + 9<br />
return math.floor(10 * (1.3 + effectiveLevel / 10 + strengthBonus / 80 + effectiveLevel * strengthBonus / 640))<br />
end<br />
<br />
function p._getMonsterAttackSpeed(monster)<br />
return p.getEquipmentStat(monster, 'attackSpeed') / 1000<br />
end<br />
<br />
function p.getMonsterAttackSpeed(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
if monster ~= nil then<br />
return p._getMonsterAttackSpeed(monster)<br />
else<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
end<br />
<br />
function p._getMonsterCombatLevel(monster)<br />
local base = 0.25 * (p._getMonsterLevel(monster, 'Defence') + p._getMonsterLevel(monster, 'Hitpoints'))<br />
local melee = 0.325 * (p._getMonsterLevel(monster, 'Attack') + p._getMonsterLevel(monster, 'Strength'))<br />
local range = 0.325 * (1.5 * p._getMonsterLevel(monster, 'Ranged'))<br />
local magic = 0.325 * (1.5 * p._getMonsterLevel(monster, 'Magic'))<br />
return math.floor(base + math.max(melee, range, magic))<br />
end<br />
<br />
function p.getMonsterCombatLevel(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterCombatLevel(monster)<br />
end<br />
<br />
function p._getMonsterAR(monster)<br />
local baseLevel = 0<br />
local bonus = 0<br />
if monster.attackType == 'melee' then<br />
baseLevel = p._getMonsterLevel(monster, 'Attack')<br />
bonus = p.getEquipmentStat(monster, 'stabAttackBonus')<br />
elseif monster.attackType == 'ranged' then<br />
baseLevel = p._getMonsterLevel(monster, 'Ranged')<br />
bonus = p.getEquipmentStat(monster, 'rangedAttackBonus')<br />
elseif monster.attackType == 'magic' then<br />
baseLevel = p._getMonsterLevel(monster, 'Magic')<br />
bonus = p.getEquipmentStat(monster, 'magicAttackBonus')<br />
elseif monster.attackType == 'random' then<br />
--Bane has the same AR with every attack type so being lazy and just showing the one.<br />
baseLevel = p._getMonsterLevel(monster, 'Attack')<br />
bonus = p.getEquipmentStat(monster, 'stabAttackBonus')<br />
else<br />
return "ERROR: This monster has an invalid attack type somehow[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p.calculateStandardStat(baseLevel, bonus)<br />
end<br />
<br />
function p.getMonsterAR(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterAR(monster)<br />
end<br />
<br />
function p._getMonsterER(monster, style)<br />
local baseLevel= 0<br />
local bonus = 0<br />
<br />
if style == "Melee" then<br />
baseLevel = p._getMonsterLevel(monster, 'Defence')<br />
bonus = p.getEquipmentStat(monster, 'meleeDefenceBonus')<br />
elseif style == "Ranged" then<br />
baseLevel = p._getMonsterLevel(monster, 'Defence')<br />
bonus = p.getEquipmentStat(monster, 'rangedDefenceBonus')<br />
elseif style == "Magic" then<br />
baseLevel = math.floor(p._getMonsterLevel(monster, 'Magic') * 0.7 + p._getMonsterLevel(monster, 'Defence') * 0.3)<br />
bonus = p.getEquipmentStat(monster, 'magicDefenceBonus')<br />
else<br />
return "ERROR: Must choose Melee, Ranged, or Magic[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p.calculateStandardStat(baseLevel, bonus)<br />
end<br />
<br />
function p.getMonsterER(frame)<br />
local args = frame.args ~= nil and frame.args or frame<br />
local MonsterName = args[1]<br />
local style = args[2]<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterER(monster, style)<br />
end<br />
<br />
-- Determines if the monster is capable of dropping bones, and returns the bones<br />
-- item if so, or nil otherwise<br />
function p._getMonsterBones(monster)<br />
if monster.bones ~= nil and monster.bones >= 0 then<br />
local boneItem = Items.getItemByID(monster.bones)<br />
if boneItem.prayerPoints == nil then<br />
-- Assume bones without prayer points are shards (from God dungeons),<br />
-- and drop unconditionally<br />
return boneItem<br />
elseif not monster.isBoss and not p._isDungeonOnlyMonster(monster) then<br />
-- Otherwise, bones drop when the monster isn't dungeon exclusive<br />
return boneItem<br />
end<br />
end<br />
end<br />
<br />
function p._isDungeonOnlyMonster(monster)<br />
local areaList = Areas.getMonsterAreas(monster.id)<br />
local inDungeon = false<br />
<br />
for i, area in ipairs(areaList) do<br />
if area.type == 'dungeon' then<br />
inDungeon = true<br />
else<br />
return false<br />
end<br />
end<br />
return inDungeon<br />
end<br />
<br />
function p.isDungeonOnlyMonster(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with name "..monsterName.." found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._isDungeonOnlyMonster(monster)<br />
end<br />
<br />
function p._getMonsterAreas(monster, excludeDungeons)<br />
local resultPart = {}<br />
local hideDungeons = excludeDungeons ~= nil and excludeDungeons or false<br />
local areaList = Areas.getMonsterAreas(monster.id)<br />
for i, area in ipairs(areaList) do<br />
if area.type ~= 'dungeon' or not hideDungeons then<br />
table.insert(resultPart, Icons.Icon({area.name, type = area.type}))<br />
end<br />
end<br />
return table.concat(resultPart, '<br/>')<br />
end<br />
<br />
function p.getMonsterAreas(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local hideDungeons = frame.args ~= nil and frame.args[2] or nil<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with name "..monsterName.." found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterAreas(monster, hideDungeons)<br />
end<br />
<br />
function p.getSpecAttackMaxHit(specAttack, normalMaxHit)<br />
local result = 0<br />
for i, dmg in pairs(specAttack.damage) do<br />
if dmg.maxRoll == 'Fixed' then<br />
result = dmg.maxPercent * 10<br />
elseif dmg.maxRoll == 'MaxHit' then<br />
if dmg.character == 'Target' then<br />
--Confusion applied damage based on the player's max hit. Gonna just ignore that one<br />
result = 0<br />
else<br />
result = dmg.maxPercent * normalMaxHit * 0.01<br />
end<br />
elseif Shared.contains({'Bleeding', 'Poisoned'}, dmg.maxRoll) then<br />
-- TODO: This is limited in that there is no verification that bleed/poison<br />
-- can be applied to the target, it is assumed that it can and so this applies<br />
result = result + dmg.maxPercent * 10<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.canSpecAttackApplyEffect(specAttack, effectType)<br />
local result = false<br />
for i, effect in pairs(specAttack.prehitEffects) do<br />
if effect.type == effectType then<br />
result = true<br />
break<br />
end<br />
end<br />
<br />
for i, effect in pairs(specAttack.onhitEffects) do<br />
if effect.type == effectType then<br />
result = true<br />
break<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p._getMonsterMaxHit(monster, doStuns)<br />
-- 2021-06-11 Adjusted for v0.20 stun/sleep changes, where damage multiplier now applies<br />
-- to all enemy attacks if stun/sleep is present on at least one special attack<br />
if doStuns == nil then<br />
doStuns = true<br />
elseif type(doStuns) == 'string' then<br />
doStuns = string.upper(doStuns) == 'TRUE'<br />
end<br />
<br />
local normalChance = 100<br />
local specialMaxHit = 0<br />
local normalMaxHit = p._getMonsterBaseMaxHit(monster)<br />
local hasActiveBuffSpec = false<br />
local damageMultiplier = 1<br />
if monster.specialAttacks[1] ~= nil then<br />
local canStun, canSleep = false, false<br />
for i, specAttack in pairs(monster.specialAttacks) do<br />
if monster.overrideSpecialChances ~= nil then<br />
normalChance = normalChance - monster.overrideSpecialChances[i]<br />
else<br />
normalChance = normalChance - specAttack.defaultChance<br />
end<br />
local thisMax = p.getSpecAttackMaxHit(specAttack, normalMaxHit)<br />
if not canStun and p.canSpecAttackApplyEffect(specAttack, 'Stun') then canStun = true end<br />
if not canSleep and p.canSpecAttackApplyEffect(specAttack, 'Sleep') then canSleep = true end<br />
<br />
if thisMax > specialMaxHit then specialMaxHit = thisMax end<br />
if Shared.contains(string.upper(specAttack.description), 'NORMAL ATTACK INSTEAD') then <br />
hasActiveBuffSpec = true <br />
end<br />
end<br />
<br />
if canSleep and doStuns then damageMultiplier = damageMultiplier * 1.2 end<br />
if canStun and doStuns then damageMultiplier = damageMultiplier * 1.3 end<br />
end<br />
--Ensure that if the monster never does a normal attack, the normal max hit is irrelevant<br />
if normalChance == 0 and not hasActiveBuffSpec then normalMaxHit = 0 end<br />
return math.floor(math.max(specialMaxHit, normalMaxHit) * damageMultiplier)<br />
end<br />
<br />
function p.getMonsterMaxHit(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local doStuns = frame.args ~= nil and frame.args[2] or true<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterMaxHit(monster, doStuns)<br />
end<br />
<br />
function p._getMonsterBaseMaxHit(monster)<br />
--8/27/21 - Now references p.calculateStandardMaxHit for Melee & Ranged<br />
local result = 0<br />
local baseLevel = 0<br />
local bonus = 0<br />
if monster.attackType == 'melee' then<br />
baseLevel = p._getMonsterLevel(monster, 'Strength')<br />
bonus = p.getEquipmentStat(monster, 'meleeStrengthBonus')<br />
result = p.calculateStandardMaxHit(baseLevel, bonus)<br />
elseif monster.attackType == 'ranged' then<br />
baseLevel = p._getMonsterLevel(monster, 'Ranged')<br />
bonus = p.getEquipmentStat(monster, 'rangedStrengthBonus')<br />
result = p.calculateStandardMaxHit(baseLevel, bonus)<br />
elseif monster.attackType == 'magic' then<br />
local mSpell = nil<br />
if monster.selectedSpell ~= nil then mSpell = Magic.getSpellByID('Spells', monster.selectedSpell) end<br />
<br />
bonus = p.getEquipmentStat(monster, 'magicDamageBonus')<br />
baseLevel = p._getMonsterLevel(monster, 'Magic')<br />
<br />
result = math.floor(10 * mSpell.maxHit * (1 + bonus / 100) * (1 + (baseLevel + 1) / 200))<br />
elseif monster.attackType == 'random' then<br />
local hitArray = {}<br />
local iconText = Icons.Icon({'Melee', notext=true})<br />
baseLevel = p._getMonsterLevel(monster, 'Strength')<br />
bonus = p.getEquipmentStat(monster, 'meleeStrengthBonus')<br />
table.insert(hitArray, p.calculateStandardMaxHit(baseLevel, bonus))<br />
<br />
iconText = Icons.Icon({'Ranged', type='skill', notext=true})<br />
baseLevel = p._getMonsterLevel(monster, 'Ranged')<br />
bonus = p.getEquipmentStat(monster, 'rangedStrengthBonus')<br />
table.insert(hitArray, p.calculateStandardMaxHit(baseLevel, bonus))<br />
<br />
iconText = Icons.Icon({'Magic', type='skill', notext=true})<br />
local mSpell = nil<br />
if monster.selectedSpell ~= nil then mSpell = Magic.getSpellByID('Spells', monster.selectedSpell) end<br />
bonus = p.getEquipmentStat(monster, 'magicDamageBonus')<br />
baseLevel = p._getMonsterLevel(monster, 'Magic')<br />
local magicDmg = math.floor(10 * mSpell.maxHit * (1 + bonus / 100) * (1 + (baseLevel + 1) / 200))<br />
table.insert(hitArray, magicDmg)<br />
<br />
local max = 0<br />
for i, val in pairs(hitArray) do<br />
if val > max then max = val end<br />
end<br />
result = max<br />
else<br />
return "ERROR: This monster has an invalid attack type somehow[[Category:Pages with script errors]]"<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getMonsterBaseMaxHit(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterBaseMaxHit(monster)<br />
end<br />
<br />
function p.getMonsterAttacks(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = ''<br />
local iconText = p._getMonsterStyleIcon({monster, notext=true})<br />
local typeText = ''<br />
if monster.attackType == 'melee' then<br />
typeText = 'Melee'<br />
elseif monster.attackType == 'ranged' then<br />
typeText = 'Ranged'<br />
elseif monster.attackType == 'magic' then<br />
typeText = 'Magic'<br />
elseif monster.attackType == 'random' then<br />
typeText = "Random"<br />
end<br />
<br />
local buffAttacks = {}<br />
local hasActiveBuffSpec = false<br />
<br />
local normalAttackChance = 100<br />
if monster.specialAttacks[1] ~= nil then<br />
for i, specAttack in pairs(monster.specialAttacks) do<br />
local attChance = 0<br />
if monster.overrideSpecialChances ~= nil then<br />
attChance = monster.overrideSpecialChances[i]<br />
else<br />
attChance = specAttack.defaultChance<br />
end<br />
normalAttackChance = normalAttackChance - attChance<br />
<br />
result = result..'\r\n* '..attChance..'% '..iconText..' '..specAttack.name..'\r\n** '..specAttack.description<br />
<br />
if Shared.contains(string.upper(specAttack.description), 'NORMAL ATTACK INSTEAD') then<br />
table.insert(buffAttacks, specAttack.name)<br />
hasActiveBuffSpec = true <br />
end<br />
end<br />
end<br />
if normalAttackChance == 100 then<br />
result = iconText..' 1 - '..p._getMonsterBaseMaxHit(monster)..' '..typeText..' Damage'<br />
elseif normalAttackChance > 0 then<br />
result = '* '..normalAttackChance..'% '..iconText..' 1 - '..p.getMonsterBaseMaxHit(frame)..' '..typeText..' Damage'..result<br />
elseif hasActiveBuffSpec then<br />
--If the monster normally has a 0% chance of doing a normal attack but some special attacks can't be repeated, include it<br />
--(With a note about when it does it)<br />
result = '* '..iconText..' 1 - '..p._getMonsterBaseMaxHit(monster)..' '..typeText..' Damage (Instead of repeating '..table.concat(buffAttacks, ' or ')..' while the effect is already active)'..result<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getMonsterPassives(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = ''<br />
if type(monster.passiveID) == 'table' and Shared.tableCount(monster.passiveID) > 0 then<br />
result = result .. '===Passives==='<br />
for i, passiveID in pairs(monster.passiveID) do<br />
local passive = p.getPassiveByID(passiveID)<br />
result = result .. '\r\n* ' .. passive.name .. '\r\n** ' .. passive.description<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.getMonsterCategories(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = '[[Category:Monsters]]'<br />
<br />
if monster.attackType == 'melee' then<br />
result = result..'[[Category:Melee Monsters]]'<br />
elseif monster.attackType == 'ranged' then<br />
result = result..'[[Category:Ranged Monsters]]'<br />
elseif monster.attackType == 'magic' then<br />
result = result..'[[Category:Magic Monsters]]'<br />
end<br />
<br />
if monster.specialAttacks[1] ~= nil then<br />
result = result..'[[Category:Monsters with Special Attacks]]'<br />
end<br />
<br />
if monster.isBoss then<br />
result = result..'[[Category:Bosses]]'<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getOtherMonsterBoxText(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = ''<br />
<br />
--Going through and finding out which damage bonuses will apply to this monster<br />
local monsterTypes = {}<br />
if monster.isBoss then table.insert(monsterTypes, 'Boss') end<br />
<br />
local areaList = Areas.getMonsterAreas(monster.id)<br />
local counts = {combat = 0, slayer = 0, dungeon = 0}<br />
for i, area in Shared.skpairs(areaList) do<br />
counts[area.type] = counts[area.type] + 1<br />
end<br />
<br />
if counts.combat > 0 then table.insert(monsterTypes, 'Combat Area') end<br />
if counts.slayer > 0 then table.insert(monsterTypes, 'Slayer Area') end<br />
if counts.dungeon > 0 then table.insert(monsterTypes, 'Dungeon') end<br />
<br />
result = result.."\r\n|-\r\n|'''Monster Types:''' "..table.concat(monsterTypes, ", ")<br />
<br />
local SlayerTier = 'N/A'<br />
if monster.canSlayer then<br />
SlayerTier = Constants.getSlayerTierNameByLevel(p._getMonsterCombatLevel(monster))<br />
end<br />
<br />
result = result.."\r\n|-\r\n|'''"..Icons.Icon({'Slayer', type='skill'}).." [[Slayer#Slayer Tier Monsters|Tier]]:''' "<br />
if monster.canSlayer then<br />
result = result.."[[Slayer#"..SlayerTier.."|"..SlayerTier.."]]"<br />
else<br />
result = result..SlayerTier<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getMonsterDrops(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = ''<br />
<br />
local bones = p._getMonsterBones(monster)<br />
local boneVal = 0<br />
--Show the bones only if either the monster shows up outside of dungeons _or_ the monster drops shards<br />
if bones ~= nil then<br />
local boneQty = (monster.boneQty ~= nil and monster.boneQty or 1)<br />
result = result.."'''Always Drops:'''"<br />
result = result..'\r\n{|class="wikitable" id="bonedrops"'<br />
result = result..'\r\n!Item !! Qty'<br />
result = result..'\r\n|-\r\n|'..Icons.Icon({bones.name, type='item'})<br />
result = result..'||'..boneQty..'\r\n'..'|}'<br />
boneVal = boneQty * bones.sellsFor<br />
end<br />
<br />
--Likewise, seeing the loot table is tied to the monster appearing outside of dungeons<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100<br />
local lootValue = 0<br />
<br />
result = result.."'''Loot:'''"<br />
local avgGp = 0<br />
<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2<br />
local gpTxt = Icons.GP(monster.dropCoins[1], monster.dropCoins[2])<br />
result = result.."\r\nIn addition to loot, the monster will also drop "..gpTxt..'.'<br />
end<br />
<br />
local multiDrop = Shared.tableCount(monster.lootTable) > 1<br />
local totalWt = 0<br />
for i, row in pairs(monster.lootTable) do<br />
totalWt = totalWt + row[2]<br />
end<br />
result = result..'\r\n{|class="wikitable sortable" id="itemdrops"'<br />
result = result..'\r\n!Item!!Qty'<br />
result = result..'!!Price!!colspan="2"|Chance'<br />
<br />
--Sort the loot table by weight in descending order<br />
table.sort(monster.lootTable, function(a, b) return a[2] > b[2] end)<br />
for i, row in Shared.skpairs(monster.lootTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
<br />
local maxQty = row[3]<br />
if thisItem ~= nil then<br />
result = result..'\r\n|-\r\n|'..Icons.Icon({thisItem.name, type='item'})<br />
else<br />
result = result..'\r\n|-\r\n|Unknown Item[[Category:Pages with script errors]]'<br />
end<br />
result = result..'||style="text-align:right" data-sort-value="'..maxQty..'"|'<br />
<br />
if maxQty > 1 then<br />
result = result.. '1 - '<br />
end<br />
result = result..Shared.formatnum(row[3])<br />
<br />
--Adding price columns<br />
local itemPrice = 0<br />
if thisItem == nil then<br />
result = result..'||data-sort-value="0"|???'<br />
else<br />
itemPrice = thisItem.sellsFor ~= nil and thisItem.sellsFor or 0<br />
if itemPrice == 0 or maxQty == 1 then<br />
result = result..'||'..Icons.GP(itemPrice)<br />
else<br />
result = result..'||'..Icons.GP(itemPrice, itemPrice * maxQty)<br />
end<br />
end<br />
<br />
--Getting the drop chance<br />
local dropChance = (row[2] / totalWt * lootChance)<br />
if dropChance < 100 then<br />
--Show fraction as long as it isn't going to be 1/1<br />
result = result..'||style="text-align:right" data-sort-value="'..row[2]..'"'<br />
result = result..'|'..Shared.fraction(row[2] * lootChance, totalWt * 100)<br />
result = result..'||'<br />
else<br />
result = result..'||colspan="2" data-sort-value="'..row[2]..'"'<br />
end<br />
-- If chance is less than 0.10% then show 2 significant figures, otherwise 2 decimal places<br />
local fmt = (dropChance < 0.10 and '%.2g') or '%.2f'<br />
result = result..'style="text-align:right"|'..string.format(fmt, dropChance)..'%'<br />
<br />
--Adding to the average loot value based on price & dropchance<br />
lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((1 + maxQty) / 2))<br />
end<br />
if multiDrop then<br />
result = result..'\r\n|-class="sortbottom" \r\n!colspan="3"|Total:'<br />
if lootChance < 100 then<br />
result = result..'\r\n|style="text-align:right"|'..Shared.fraction(lootChance, 100)..'||'<br />
else<br />
result = result..'\r\n|colspan="2" '<br />
end<br />
result = result..'style="text-align:right"|'..Shared.round(lootChance, 2, 2)..'%'<br />
end<br />
result = result..'\r\n|}'<br />
result = result..'\r\nThe loot dropped by the average kill is worth '..Icons.GP(Shared.round(lootValue, 2, 0)).." if sold."<br />
if avgGp > 0 then<br />
result = result.."<br/>Including GP"<br />
if boneVal > 0 then<br />
result = result..' and bones'<br />
end<br />
result = result..', the average kill is worth '..Icons.GP(Shared.round(avgGp + lootValue + boneVal, 2, 0))..'.'<br />
end<br />
end<br />
<br />
--If no other drops, make sure to at least say so.<br />
if result == '' then result = 'None' end<br />
return result<br />
end<br />
<br />
function p._getMonsterLootValue(monster)<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = 0<br />
local boneVal = 0<br />
<br />
local bones = p._getMonsterBones(monster)<br />
--Show the bones only if either the monster shows up outside of dungeons _or_ the monster drops shards<br />
if bones ~= nil then<br />
local boneQty = monster.boneQty ~= nil and monster.boneQty or 1<br />
boneVal = bones.sellsFor * boneQty<br />
result = result + boneVal<br />
end<br />
<br />
--Likewise, seeing the loot table is tied to the monster appearing outside of dungeons<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100<br />
local lootValue = 0<br />
<br />
local avgGp = 0<br />
<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2<br />
end<br />
<br />
local multiDrop = Shared.tableCount(monster.lootTable) > 1<br />
local totalWt = 0<br />
for i, row in pairs(monster.lootTable) do<br />
totalWt = totalWt + row[2]<br />
end<br />
<br />
for i, row in Shared.skpairs(monster.lootTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
<br />
local maxQty = row[3]<br />
<br />
--Adding price columns<br />
local itemPrice = 0<br />
if thisItem ~= nil then<br />
itemPrice = thisItem.sellsFor ~= nil and thisItem.sellsFor or 0<br />
end<br />
<br />
--Getting the drop chance<br />
local dropChance = (row[2] / totalWt * lootChance)<br />
--Adding to the average loot value based on price & dropchance<br />
lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((1 + maxQty) / 2))<br />
end<br />
if avgGp > 0 then<br />
result = result + avgGp + lootValue<br />
end<br />
end<br />
<br />
return result<br />
end<br />
<br />
-- Find drop chance of specified item from specified monster. <br />
-- Usage: |Monster Name|Item Name<br />
function p.getItemDropChance(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame[1]<br />
local ItemName = frame.args ~= nil and frame.args[2] or frame[2]<br />
<br />
local monster = p.getMonster(MonsterName)<br />
local item = Items.getItem(ItemName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
if item == nil then<br />
return "ERROR: No item with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100<br />
<br />
local totalWt = 0<br />
--for i, row in pairs(monster.lootTable) do<br />
--totalWt = totalWt + row[2]<br />
--end<br />
<br />
local dropChance = 0<br />
local dropWt = 0<br />
for i, row in Shared.skpairs(monster.lootTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
totalWt = totalWt + row[2]<br />
if item['id'] == thisItem['id'] then<br />
dropWt = row[2]<br />
end<br />
end<br />
dropChance = (dropWt / totalWt * lootChance)<br />
return Shared.round(dropChance, 2, 2)<br />
end<br />
end <br />
<br />
function p.getChestDrops(frame)<br />
local ChestName = frame.args ~= nil and frame.args[1] or frame<br />
local chest = Items.getItem(ChestName)<br />
<br />
if chest == nil then<br />
return "ERROR: No item named "..ChestName..' found[[Category:Pages with script errors]]'<br />
end<br />
<br />
local result = ''<br />
<br />
if chest.dropTable == nil then<br />
return "ERROR: "..ChestName.." does not have a drop table[[Category:Pages with script errors]]"<br />
else<br />
local lootChance = 100<br />
local lootValue = 0<br />
<br />
local multiDrop = Shared.tableCount(chest.dropTable) > 1<br />
local totalWt = 0<br />
for i, row in pairs(chest.dropTable) do<br />
totalWt = totalWt + row[2]<br />
end<br />
result = result..'\r\n{|class="wikitable sortable"'<br />
result = result..'\r\n!Item!!Qty'<br />
result = result..'!!colspan="2"|Chance!!Price'<br />
<br />
--Sort the loot table by weight in descending order<br />
for i, row in pairs(chest.dropTable) do<br />
if chest.dropQty ~= nil then<br />
table.insert(row, chest.dropQty[i])<br />
else<br />
table.insert(row, 1)<br />
end<br />
end<br />
table.sort(chest.dropTable, function(a, b) return a[2] > b[2] end)<br />
for i, row in Shared.skpairs(chest.dropTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
local qty = row[3]<br />
result = result..'\r\n|-\r\n|'..Icons.Icon({thisItem.name, type='item'})<br />
result = result..'||style="text-align:right" data-sort-value="'..qty..'"|'<br />
<br />
if qty > 1 then<br />
result = result.. '1 - '<br />
end<br />
result = result..Shared.formatnum(qty)<br />
<br />
local dropChance = (row[2] / totalWt) * 100<br />
result = result..'||style="text-align:right" data-sort-value="'..row[2]..'"'<br />
result = result..'|'..Shared.fraction(row[2], totalWt)<br />
<br />
result = result..'||style="text-align:right"|'..Shared.round(dropChance, 2, 2)..'%'<br />
<br />
result = result..'||style="text-align:left" data-sort-value="'..thisItem.sellsFor..'"'<br />
if qty > 1 then<br />
result = result..'|'..Icons.GP(thisItem.sellsFor, thisItem.sellsFor * qty)<br />
else<br />
result = result..'|'..Icons.GP(thisItem.sellsFor)<br />
end<br />
lootValue = lootValue + (dropChance * 0.01 * thisItem.sellsFor * ((1 + qty)/ 2))<br />
end<br />
result = result..'\r\n|}'<br />
result = result..'\r\nThe average value of the contents of one chest is '..Icons.GP(Shared.round(lootValue, 2, 0))..'.'<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getAreaMonsterTable(frame)<br />
local areaName = frame.args ~= nil and frame.args[1] or frame<br />
local area = Areas.getArea(areaName)<br />
if area == nil then<br />
return "ERROR: Could not find an area named "..areaName..'[[Category:Pages with script errors]]'<br />
end<br />
<br />
if area.type == 'dungeon' then<br />
return p.getDungeonMonsterTable(frame)<br />
end<br />
<br />
local tableTxt = '{| class="wikitable sortable"'<br />
tableTxt = tableTxt..'\r\n! Name !! Combat Level !! Hitpoints !! Max Hit !! [[Combat Triangle|Combat Style]]'<br />
for i, monsterID in pairs(area.monsters) do<br />
local monster = p.getMonsterByID(monsterID)<br />
tableTxt = tableTxt..'\r\n|-\r\n|'..Icons.Icon({monster.name, type='monster'})<br />
tableTxt = tableTxt..'||'..p._getMonsterCombatLevel(monster)<br />
tableTxt = tableTxt..'||'..Shared.formatnum(p._getMonsterHP(monster))<br />
tableTxt = tableTxt..'||'..Shared.formatnum(p._getMonsterMaxHit(monster))<br />
tableTxt = tableTxt..'||'..p._getMonsterStyleIcon({monster, nolink=true})<br />
end<br />
tableTxt = tableTxt..'\r\n|}'<br />
return tableTxt<br />
end<br />
<br />
function p.getDungeonMonsterTable(frame)<br />
local areaName = frame.args ~= nil and frame.args[1] or frame<br />
local area = Areas.getArea(areaName)<br />
if area == nil then<br />
return "ERROR: Could not find a dungeon named "..areaName..'[[Category:Pages with script errors]]'<br />
end<br />
<br />
--For Dungeons, go through and count how many of each monster are in the dungeon first<br />
local monsterCounts = {}<br />
for i, monsterID in pairs(area.monsters) do<br />
if monsterCounts[monsterID] == nil then<br />
monsterCounts[monsterID] = 1<br />
else<br />
monsterCounts[monsterID] = monsterCounts[monsterID] + 1<br />
end<br />
end<br />
<br />
local usedMonsters = {}<br />
<br />
-- Declare function for building table rows to avoid repeating code<br />
local buildRow = function(entityID, monsterCount, specialType)<br />
local monIcon, monLevel, monHP, monMaxHit, monStyle, monCount<br />
local monData = {}<br />
if specialType ~= nil and Shared.contains({'Afflicted', 'SlayerArea'}, specialType) then<br />
-- Special handling for Into the Mist<br />
if specialType == 'Afflicted' then<br />
local iconQ = Icons.Icon({'Into the Mist', notext=true, nolink=true, img='Question'})<br />
monIcon = Icons.Icon({'Into the Mist', 'Afflicted Monster', nolink=true, img='Question'})<br />
monLevel, monHP, monMaxHit, monStyle, monCount = iconQ, iconQ, iconQ, iconQ, monsterCount<br />
elseif specialType == 'SlayerArea' then<br />
-- entityID corresponds to a slayer area<br />
local area = Areas.getAreaByID('slayer', entityID)<br />
monIcon = Icons.Icon({area.name, type='combatArea'}) .. ' Monsters'<br />
monLevel = {p.getLowHighStat(area.monsters, function(monster) return p._getMonsterCombatLevel(monster) end)}<br />
monHP = {p.getLowHighStat(area.monsters, function(monster) return p._getMonsterHP(monster) end)}<br />
local lowMaxHit, highMaxHit = p.getLowHighStat(area.monsters, function(monster) return p._getMonsterMaxHit(monster) end)<br />
monMaxHit = highMaxHit<br />
monStyle = Icons.Icon({area.name, area.name, notext=true, nolink=true, img='Question'})<br />
monCount = monsterCount<br />
end<br />
else<br />
-- entityID corresponds to a monster<br />
local monster = p.getMonsterByID(entityID)<br />
monIcon = Icons.Icon({monster.name, type='monster'})<br />
monLevel = p._getMonsterCombatLevel(monster)<br />
monHP = p._getMonsterHP(monster)<br />
monMaxHit = p._getMonsterMaxHit(monster)<br />
monStyle = p._getMonsterStyleIcon({monster})<br />
monCount = monsterCount<br />
end<br />
local getValSort = function(val)<br />
if type(val) == 'table' then<br />
if type(val[1]) == 'number' and type(val[2]) == 'number' then<br />
return (val[1] + val[2]) / 2<br />
else<br />
return (type(val[1]) == 'number' and val[1]) or 0<br />
end<br />
else<br />
return (type(val) == 'number' and val) or 0<br />
end<br />
end<br />
local getValText = function(val)<br />
if type(val) == 'table' and Shared.tableCount(val) == 2 then<br />
if type(val[1]) == 'number' and type(val[2]) == 'number' then<br />
return Shared.formatnum(val[1]) .. ' - ' .. Shared.formatnum(val[2])<br />
else<br />
return val[1] .. ' - ' .. val[2]<br />
end<br />
elseif type(val) == 'number' then<br />
return Shared.formatnum(val)<br />
else<br />
return val<br />
end<br />
end<br />
<br />
local resultPart = {}<br />
table.insert(resultPart, '\r\n|-\r\n| ' .. monIcon)<br />
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monLevel) .. '"| ' .. getValText(monLevel))<br />
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monHP) .. '"| ' .. getValText(monHP))<br />
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monMaxHit) .. '"| ' .. getValText(monMaxHit))<br />
table.insert(resultPart, '\r\n| ' .. monStyle)<br />
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monCount) .. '"| ' .. getValText(monCount))<br />
return table.concat(resultPart)<br />
end<br />
<br />
local returnPart = {}<br />
table.insert(returnPart, '{| class="wikitable sortable"')<br />
table.insert(returnPart, '\r\n! Name !! Combat Level !! Hitpoints !! Max Hit !! [[Combat Triangle|Combat Style]] !! Count')<br />
-- Special handing for Impending Darkness event<br />
-- TODO needs to be revised once there is a better understanding of how the event works<br />
--if area.isEvent ~= nil and area.isEvent then<br />
-- for i, eventAreaID in ipairs(Areas.eventData.slayerAreas) do<br />
-- table.insert(returnPart, buildRow(eventAreaID, {5, 8}, 'SlayerArea'))<br />
-- end<br />
-- -- Add Bane * 4<br />
-- table.insert(returnPart, buildRow(152, 4))<br />
--end<br />
for i, monsterID in pairs(area.monsters) do<br />
if not Shared.contains(usedMonsters, monsterID) then<br />
if monsterID >= 0 then<br />
table.insert(returnPart, buildRow(monsterID, monsterCounts[monsterID]))<br />
else<br />
--Special handling for Into the Mist<br />
table.insert(returnPart, buildRow(monsterID, monsterCounts[monsterID], 'Afflicted'))<br />
end<br />
table.insert(usedMonsters, monsterID)<br />
end<br />
end<br />
table.insert(returnPart, '\r\n|}')<br />
return table.concat(returnPart)<br />
end<br />
<br />
function p.getDungeonTotalHp(frame)<br />
local areaName = frame.args ~= nil and frame.args[1] or frame<br />
local area = Areas.getArea(areaName)<br />
if area == nil then<br />
return "ERROR: Could not find a dungeon named "..areaName..'[[Category:Pages with script errors]]'<br />
end<br />
local totalHP = 0<br />
<br />
for i, monsterID in pairs(area.monsters) do<br />
if not Shared.contains(usedMonsters, monsterID) then<br />
local monster = p.getMonsterByID(monsterID)<br />
totalHP = totalHP + p._getMonsterHP(monster)<br />
end<br />
end<br />
return totalHP<br />
end<br />
<br />
function p._getAreaMonsterList(area)<br />
local monsterList = {}<br />
for i, monsterID in pairs(area.monsters) do<br />
local monster = p.getMonsterByID(monsterID)<br />
table.insert(monsterList, Icons.Icon({monster.name, type='monster'}))<br />
end<br />
return table.concat(monsterList, '<br/>')<br />
end<br />
<br />
function p._getDungeonMonsterList(area)<br />
local monsterList = {}<br />
local lastMonster = nil<br />
local lastID = -2<br />
local count = 0<br />
-- Special handing for Impending Darkness event<br />
-- TODO needs to be revised once there is a better understanding of how the event works<br />
--if area.isEvent ~= nil and area.isEvent then<br />
-- for i, eventAreaID in ipairs(Areas.eventData.slayerAreas) do<br />
-- local eventArea = Areas.getAreaByID('slayer', eventAreaID)<br />
-- table.insert(monsterList, '5-8 ' .. Icons.Icon({eventArea.name, type='combatArea'}) .. ' Monsters')<br />
-- end<br />
-- table.insert(monsterList, '4 ' .. Icons.Icon({'Bane', type='monster'}))<br />
--end<br />
for i, monsterID in Shared.skpairs(area.monsters) do<br />
if monsterID ~= lastID then<br />
local monster = nil <br />
if monsterID ~= -1 then monster = p.getMonsterByID(monsterID) end<br />
if lastID ~= -2 then<br />
if lastID == -1 then<br />
--Special handling for Afflicted Monsters<br />
table.insert(monsterList, Icons.Icon({'Affliction', 'Afflicted Monster', img='Question', qty=count}))<br />
else<br />
local name = lastMonster.name<br />
table.insert(monsterList, Icons.Icon({name, type='monster', qty=count}))<br />
end<br />
end<br />
lastMonster = monster<br />
lastID = monsterID<br />
count = 1<br />
else<br />
count = count + 1<br />
end<br />
--Make sure the final monster in the dungeon gets counted<br />
if i == Shared.tableCount(area.monsters) then<br />
local name = lastMonster.name<br />
table.insert(monsterList, Icons.Icon({lastMonster.name, type='monster', qty=count}))<br />
end<br />
end<br />
return table.concat(monsterList, '<br/>')<br />
end<br />
<br />
function p.getAreaMonsterList(frame)<br />
local areaName = frame.args ~= nil and frame.args[1] or frame<br />
local area = Areas.getArea(areaName)<br />
if area == nil then<br />
return "ERROR: Could not find an area named "..areaName..'[[Category:Pages with script errors]]'<br />
end<br />
<br />
if area.type == 'dungeon' then<br />
return p._getDungeonMonsterList(area)<br />
else<br />
return p._getAreaMonsterList(area)<br />
end<br />
end<br />
<br />
function p.getFoxyTable(frame)<br />
local result = 'Monster,Min GP,Max GP,Average GP'<br />
for i, monster in Shared.skpairs(MonsterData.Monsters) do<br />
if not p._isDungeonOnlyMonster(monster) then<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
local avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2<br />
result = result..'<br/>'..monster.name..','..monster.dropCoins[1]..','..(monster.dropCoins[2])..','..avgGp<br />
end<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p._getMonsterAverageGP(monster)<br />
local result = ''<br />
local totalGP = 0<br />
<br />
local bones = p._getMonsterBones(monster)<br />
if bones ~= nil then<br />
totalGP = totalGP + bones.sellsFor * (type(monster.boneQty) == 'number' and monster.boneQty or 1)<br />
end<br />
<br />
--Likewise, seeing the loot table is tied to the monster appearing outside of dungeons<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100<br />
local lootValue = 0<br />
<br />
local avgGp = 0<br />
<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2<br />
end<br />
<br />
totalGP = totalGP + avgGp<br />
<br />
local multiDrop = Shared.tableCount(monster.lootTable) > 1<br />
local totalWt = 0<br />
for i, row in pairs(monster.lootTable) do<br />
totalWt = totalWt + row[2]<br />
end<br />
<br />
for i, row in Shared.skpairs(monster.lootTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
local maxQty = row[3]<br />
<br />
local itemPrice = thisItem.sellsFor ~= nil and thisItem.sellsFor or 0<br />
<br />
--Getting the drop chance<br />
local dropChance = (row[2] / totalWt * lootChance)<br />
<br />
--Adding to the average loot value based on price & dropchance<br />
lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((1 + maxQty) / 2))<br />
end<br />
<br />
totalGP = totalGP + lootValue<br />
end<br />
<br />
return Shared.round(totalGP, 2, 2)<br />
end<br />
<br />
function p.getMonsterAverageGP(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterAverageGP(monster)<br />
end<br />
<br />
function p.getMonsterEVTable(frame)<br />
local result = '{| class="wikitable sortable"'<br />
result = result..'\r\n!Monster!!Combat Level!!Average GP'<br />
for i, monsterTemp in Shared.skpairs(MonsterData.Monsters) do<br />
local monster = Shared.clone(monsterTemp)<br />
monster.id = i - 1<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local monsterGP = p._getMonsterAverageGP(monster)<br />
local combatLevel = p._getMonsterCombatLevel(monster, 'Combat Level')<br />
result = result..'\r\n|-\r\n|'..Icons.Icon({monster.name, type='monster', noicon=true})..'||'..combatLevel..'||'..monsterGP<br />
end<br />
end<br />
result = result..'\r\n|}'<br />
return result<br />
end<br />
<br />
function p.getSlayerTierMonsterTable(frame)<br />
-- Input validation<br />
local tier = frame.args ~= nil and frame.args[1] or frame<br />
local slayerTier = nil<br />
<br />
if tier == nil then<br />
return "ERROR: No tier specified[[Category:Pages with script errors]]"<br />
end<br />
<br />
if tonumber(tier) ~= nil then<br />
slayerTier = Constants.getSlayerTierByID(tonumber(tier))<br />
else<br />
slayerTier = Constants.getSlayerTier(tier)<br />
end<br />
<br />
if slayerTier == nil then<br />
return "ERROR: Invalid slayer tier[[Category:Pages with script errors]]"<br />
end<br />
<br />
-- Obtain required tier details<br />
local minLevel, maxLevel = slayerTier.minLevel, slayerTier.maxLevel<br />
<br />
-- Build list of monster IDs<br />
-- Right now hiddenMonsterIDs is empty<br />
local hiddenMonsterIDs = {}<br />
local monsterIDs = {}<br />
for i, monster in Shared.skpairs(MonsterData.Monsters) do<br />
if monster.canSlayer and not Shared.contains(hiddenMonsterIDs, i - 1) then<br />
local cmbLevel = p._getMonsterCombatLevel(monster)<br />
if cmbLevel >= minLevel and (maxLevel == nil or cmbLevel <= maxLevel) then<br />
table.insert(monsterIDs, i - 1)<br />
end<br />
end<br />
end<br />
<br />
if Shared.tableCount(monsterIDs) == 0 then<br />
-- Somehow no monsters are in the tier, return nothing<br />
return ''<br />
else<br />
return p._getMonsterTable(monsterIDs, true)<br />
end<br />
end<br />
<br />
function p.getFullMonsterTable(frame)<br />
local monsterIDs = {}<br />
for i = 0, Shared.tableCount(MonsterData.Monsters) - 1, 1 do<br />
table.insert(monsterIDs, i)<br />
end<br />
<br />
return p._getMonsterTable(monsterIDs, false)<br />
end<br />
<br />
function p._getMonsterTable(monsterIDs, excludeDungeons)<br />
--Making a single function for getting a table of monsters given a list of IDs.<br />
local hideDungeons = excludeDungeons ~= nil and excludeDungeons or false<br />
local tableParts = {}<br />
table.insert(tableParts, '{| class="wikitable sortable stickyHeader"')<br />
-- First header row<br />
table.insert(tableParts, '\r\n|- class="headerRow-0"\r\n! colspan="5" | !! colspan="4" |Offensive Stats !! colspan="3" |Evasion Rating !! colspan="4" |')<br />
-- Second header row<br />
table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n!Monster !!Name !!ID !!Combat Level ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Hitpoints', type='skill'}))<br />
table.insert(tableParts, '!!Attack Speed (s) !!colspan="2"|Max Hit !!Accuracy ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Defence', type='skill', notext=true}))<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Ranged', type='skill', notext=true}))<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Magic', type='skill', notext=true}))<br />
table.insert(tableParts, '!!' .. Icons.Icon({'Coins', notext=true, nolink=true}) .. ' Coins !!Bones !!Locations')<br />
<br />
-- Generate row per monster<br />
for i, monsterID in Shared.skpairs(monsterIDs) do<br />
local monster = p.getMonsterByID(monsterID)<br />
local cmbLevel = p._getMonsterCombatLevel(monster)<br />
local atkSpeed = p._getMonsterAttackSpeed(monster)<br />
local maxHit = p._getMonsterMaxHit(monster)<br />
local accR = p._getMonsterAR(monster)<br />
local evaR = {p._getMonsterER(monster, "Melee"), p._getMonsterER(monster, "Ranged"), p._getMonsterER(monster, "Magic")}<br />
<br />
local gpRange = {0, 0}<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
gpRange = {monster.dropCoins[1], monster.dropCoins[2]}<br />
end<br />
local gpTxt = nil<br />
if gpRange[1] >= gpRange[2] then<br />
gpTxt = Shared.formatnum(gpRange[1])<br />
else<br />
gpTxt = Shared.formatnum(gpRange[1]) .. ' - ' .. Shared.formatnum(gpRange[2])<br />
end<br />
local bones = p._getMonsterBones(monster)<br />
local boneTxt = (bones ~= nil and Icons.Icon({bones.name, type='item', notext=true})) or 'None'<br />
<br />
table.insert(tableParts, '\r\n|-\r\n|style="text-align: center;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:left" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:right" |' .. monsterID)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. cmbLevel .. '" |' .. Shared.formatnum(cmbLevel))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. p._getMonsterHP(monster) .. '" |' .. Shared.formatnum(p._getMonsterHP(monster)))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. atkSpeed .. '" |' .. Shared.round(atkSpeed, 1, 1))<br />
table.insert(tableParts, '\r\n|style="text-align:center;border-right:hidden" |' .. p._getMonsterStyleIcon({monster, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. maxHit .. '" |' .. Shared.formatnum(maxHit))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. accR .. '" |' .. Shared.formatnum(accR))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[1] .. '" |' .. Shared.formatnum(evaR[1]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[2] .. '" |' .. Shared.formatnum(evaR[2]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[3] .. '" |' .. Shared.formatnum(evaR[3]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:center" |' .. boneTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))<br />
end<br />
<br />
table.insert(tableParts, '\r\n|}')<br />
return table.concat(tableParts)<br />
end<br />
<br />
function p.getMattMonsterTable(frame)<br />
--Making a single function for getting a table of monsters given a list of IDs.<br />
local tableParts = {}<br />
table.insert(tableParts, '{| class="wikitable sortable stickyHeader"')<br />
-- Second header row<br />
table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n!Monster !!Name !!ID !!Combat Level ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Hitpoints', type='skill'}))<br />
table.insert(tableParts, '!!' .. Icons.Icon({'Coins', notext=true, nolink=true}) .. ' Coins !!Avg. Kill Value!!Locations')<br />
<br />
-- Generate row per monster<br />
for i, monster in Shared.skpairs(MonsterData.Monsters) do<br />
local cmbLevel = p._getMonsterCombatLevel(monster)<br />
<br />
local gpRange = {0, 0}<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
gpRange = {monster.dropCoins[1], monster.dropCoins[2]}<br />
end<br />
local gpTxt = nil<br />
if gpRange[1] >= gpRange[2] then<br />
gpTxt = Shared.formatnum(gpRange[1])<br />
else<br />
gpTxt = Shared.formatnum(gpRange[1]) .. ' - ' .. Shared.formatnum(gpRange[2])<br />
end<br />
<br />
local lootVal = p._getMonsterLootValue(monster)<br />
local lootTxt = '0'<br />
if lootVal ~= 0 then<br />
lootTxt = Shared.formatnum(Shared.round(lootVal, 2, 2))<br />
end<br />
<br />
<br />
table.insert(tableParts, '\r\n|-\r\n|style="text-align: center;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:left" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:right" |' .. monster.id)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. cmbLevel .. '" |' .. Shared.formatnum(cmbLevel))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. p._getMonsterHP(monster) .. '" |' .. Shared.formatnum(p._getMonsterHP(monster)))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. lootVal .. '" |' .. lootTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))<br />
end<br />
<br />
table.insert(tableParts, '\r\n|}')<br />
return table.concat(tableParts)<br />
end<br />
<br />
function p.getMattMonsterTableV2(frame)<br />
--Making a single function for getting a table of monsters given a list of IDs.<br />
local tableParts = {}<br />
table.insert(tableParts, '{| class="wikitable sortable stickyHeader"')<br />
-- Second header row<br />
table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n!Monster !!Name !!Combat Level ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Hitpoints', type='skill'}))<br />
table.insert(tableParts, '!!Attack Speed (s) !!colspan="2"|Max Hit !!Accuracy ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Defence', type='skill', notext=true}))<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Ranged', type='skill', notext=true}))<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Magic', type='skill', notext=true}))<br />
table.insert(tableParts, '!!' .. Icons.Icon({'Coins', notext=true, nolink=true}) .. ' Coins !!Avg. Kill Value !!Bones')<br />
<br />
-- Generate row per monster<br />
for i, monster in Shared.skpairs(MonsterData.Monsters) do<br />
local cmbLevel = p._getMonsterCombatLevel(monster)<br />
<br />
local gpRange = {0, 0}<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
gpRange = {monster.dropCoins[1], monster.dropCoins[2]}<br />
end<br />
local gpTxt = nil<br />
if gpRange[1] >= gpRange[2] then<br />
gpTxt = Shared.formatnum(gpRange[1])<br />
else<br />
gpTxt = Shared.formatnum(gpRange[1]) .. ' - ' .. Shared.formatnum(gpRange[2])<br />
end<br />
<br />
local lootVal = p._getMonsterLootValue(monster)<br />
local lootTxt = '0'<br />
if lootVal ~= 0 then<br />
lootTxt = Shared.formatnum(Shared.round(lootVal, 2, 2))<br />
end<br />
<br />
local atkSpeed = p._getMonsterAttackSpeed(monster)<br />
local maxHit = p._getMonsterMaxHit(monster)<br />
local accR = p._getMonsterAR(monster)<br />
local evaR = {p._getMonsterER(monster, "Melee"), p._getMonsterER(monster, "Ranged"), p._getMonsterER(monster, "Magic")}<br />
<br />
local bones = p._getMonsterBones(monster)<br />
local boneTxt = (bones ~= nil and Icons.Icon({bones.name, type='item', notext=true})) or 'None'<br />
<br />
table.insert(tableParts, '\r\n|-\r\n|style="text-align: center;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:left" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))<br />
-- table.insert(tableParts, '\r\n|style="text-align:right" |' .. monster.id)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. cmbLevel .. '" |' .. Shared.formatnum(cmbLevel))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. p._getMonsterHP(monster) .. '" |' .. Shared.formatnum(p._getMonsterHP(monster)))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. atkSpeed .. '" |' .. Shared.round(atkSpeed, 1, 1))<br />
table.insert(tableParts, '\r\n|style="text-align:center;border-right:hidden" |' .. p._getMonsterStyleIcon({monster, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. maxHit .. '" |' .. Shared.formatnum(maxHit))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. accR .. '" |' .. Shared.formatnum(accR))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[1] .. '" |' .. Shared.formatnum(evaR[1]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[2] .. '" |' .. Shared.formatnum(evaR[2]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[3] .. '" |' .. Shared.formatnum(evaR[3]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. lootVal .. '" |' .. lootTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:center" |' .. boneTxt)<br />
-- table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))<br />
end<br />
<br />
table.insert(tableParts, '\r\n|}')<br />
return table.concat(tableParts)<br />
end<br />
<br />
function p.getSpecialAttackTable(frame)<br />
local spAttTable = {}<br />
<br />
for i, monster in ipairs(MonsterData.Monsters) do<br />
if monster.specialAttacks ~= nil and Shared.tableCount(monster.specialAttacks) > 0 then<br />
local overrideChance = (monster.overrideSpecialChances ~= nil and Shared.tableCount(monster.overrideSpecialChances) > 0)<br />
for j, spAtt in ipairs(monster.specialAttacks) do<br />
local attChance = (overrideChance and monster.overrideSpecialChances[j] or spAtt.defaultChance)<br />
if spAttTable[spAtt.id] == nil then<br />
spAttTable[spAtt.id] = { ['defn'] = spAtt, ['icons'] = {} }<br />
end<br />
if spAttTable[spAtt.id]['icons'][attChance] == nil then<br />
spAttTable[spAtt.id]['icons'][attChance] = {}<br />
end<br />
table.insert(spAttTable[spAtt.id]['icons'][attChance], Icons.Icon({ monster.name, type = 'monster' }))<br />
end<br />
end<br />
end<br />
<br />
local resultPart = {}<br />
table.insert(resultPart, '{|class="wikitable sortable stickyHeader"')<br />
table.insert(resultPart, '\r\n|- class="headerRow-0"')<br />
table.insert(resultPart, '\r\n!Name!!style="min-width:225px"|Monsters!!Chance!!Effect')<br />
<br />
for i, spAttData in Shared.skpairs(spAttTable) do<br />
local spAtt = spAttData.defn<br />
local firstRow = true<br />
local rowsSpanned = Shared.tableCount(spAttData.icons)<br />
local rowSuffix = ''<br />
if rowsSpanned > 1 then<br />
rowSuffix = '|rowspan="' .. rowsSpanned .. '"'<br />
end<br />
for chance, iconList in Shared.skpairs(spAttData.icons) do<br />
table.insert(resultPart, '\r\n|-')<br />
if firstRow then<br />
table.insert(resultPart, '\r\n' .. rowSuffix .. '| ' .. spAtt.name)<br />
end<br />
table.insert(resultPart, '\r\n|data-sort-value="' .. spAtt.name .. '"| ' .. table.concat(iconList, '<br/>'))<br />
table.insert(resultPart, '\r\n|data-sort-value="' .. chance .. '"| ' .. Shared.round(chance, 2, 0) .. '%')<br />
if firstRow then<br />
table.insert(resultPart, '\r\n' .. rowSuffix .. '| ' .. spAtt.description)<br />
firstRow = false<br />
end<br />
end<br />
end<br />
table.insert(resultPart, '\r\n|}')<br />
<br />
return table.concat(resultPart)<br />
end<br />
<br />
return p</div>
Roko
https://wiki.melvoridle.com/index.php?title=Module:Monsters&diff=51091
Module:Monsters
2022-02-19T13:30:54Z
<p>Roko: </p>
<hr />
<div>local p = {}<br />
<br />
local MonsterData = mw.loadData('Module:Monsters/data')<br />
<br />
local Constants = require('Module:Constants')<br />
local Areas = require('Module:CombatAreas')<br />
local Magic = require('Module:Magic')<br />
local Shared = require('Module:Shared')<br />
local Icons = require('Module:Icons')<br />
local Items = require('Module:Items')<br />
<br />
function p.getMonster(name)<br />
local result = nil<br />
if name == 'Spider (lv. 51)' or name == 'Spider' then<br />
return p.getMonsterByID(50)<br />
elseif name == 'Spider (lv. 52)' or name == 'Spider2' then<br />
return p.getMonsterByID(51)<br />
end<br />
<br />
for i, monster in pairs(MonsterData.Monsters) do<br />
if monster.name == name then<br />
result = Shared.clone(monster)<br />
--Make sure every monster has an ID, and account for the 1-based indexing of Lua<br />
result.id = i - 1<br />
break<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.getMonsterByID(ID)<br />
local result = Shared.clone(MonsterData.Monsters[ID + 1])<br />
if result ~= nil then<br />
result.id = ID<br />
return result<br />
else<br />
return nil<br />
end<br />
end<br />
<br />
function p.getPassive(name)<br />
local result = nil<br />
<br />
for i, passive in pairs(MonsterData.Passives) do<br />
if passive.name == name then<br />
result = Shared.clone(passive)<br />
--Make sure every passive has an ID, and account for the 1-based indexing of Lua<br />
result.id = i - 1<br />
break<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.getPassiveByID(ID)<br />
return MonsterData.Passives[ID + 1]<br />
end<br />
<br />
-- Given a list of monster IDs, calls statFunc with each monster and returns<br />
-- the lowest & highest values<br />
function p.getLowHighStat(idList, statFunc)<br />
local lowVal, highVal = nil, nil<br />
for i, monID in ipairs(idList) do<br />
local monster = p.getMonsterByID(monID)<br />
local statVal = statFunc(monster)<br />
if lowVal == nil or statVal < lowVal then lowVal = statVal end<br />
if highVal == nil or statVal > highVal then highVal = statVal end<br />
end<br />
return lowVal, highVal<br />
end<br />
<br />
function p._getMonsterStat(monster, statName)<br />
if statName == 'HP' then<br />
return p._getMonsterHP(monster)<br />
elseif statName == 'maxHit' then<br />
return p._getMonsterMaxHit(monster)<br />
elseif statName == 'accuracyRating' then<br />
return p._getMonsterAR(monster)<br />
elseif statName == 'meleeEvasionRating' then<br />
return p._getMonsterER(monster, 'Melee')<br />
elseif statName == 'rangedEvasionRating' then<br />
return p._getMonsterER(monster, 'Ranged')<br />
elseif statName == 'magicEvasionRating' then<br />
return p._getMonsterER(monster, 'Magic')<br />
elseif statName == 'damageReduction' then<br />
return p.getEquipmentStat(monster, 'damageReduction')<br />
end<br />
<br />
return monster[statName]<br />
end<br />
<br />
function p.getMonsterStat(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame[1]<br />
local StatName = frame.args ~= nil and frame.args[2] or frame[2]<br />
local monster = p.getMonster(MonsterName)<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterStat(monster, StatName)<br />
end<br />
<br />
function p._getMonsterStyleIcon(frame)<br />
local args = frame.args ~= nil and frame.args or frame<br />
local monster = args[1]<br />
local notext = args.notext<br />
local nolink = args.nolink<br />
<br />
local iconText = ''<br />
if monster.attackType == 'melee' then<br />
iconText = Icons.Icon({'Melee', notext=notext, nolink=nolink})<br />
elseif monster.attackType == 'ranged' then<br />
iconText = Icons.Icon({'Ranged', type='skill', notext=notext, nolink=nolink})<br />
elseif monster.attackType == 'magic' then<br />
iconText = Icons.Icon({'Magic', type='skill', notext=notext, nolink=nolink})<br />
elseif monster.attackType == 'random' then<br />
iconText = Icons.Icon({'Bane', notext=notext, nolink=nolink, img='Question'})<br />
end<br />
<br />
return iconText<br />
end<br />
<br />
function p.getMonsterStyleIcon(frame)<br />
local args = frame.args ~= nil and frame.args or frame<br />
local MonsterName = args[1]<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
args[1] = monster<br />
return p._getMonsterStyleIcon(args)<br />
end<br />
<br />
function p._getMonsterHP(monster)<br />
return 10 * p._getMonsterLevel(monster, 'Hitpoints')<br />
end<br />
<br />
function p.getMonsterEffectiveHP(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
if monster ~= nil then<br />
return math.floor((p._getMonsterHP(monster)/(1 - p._getMonsterStat(monster, 'damageReduction')/100)) + 0.5)<br />
else<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
end<br />
<br />
function p.getMonsterHP(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
if monster ~= nil then<br />
return p._getMonsterHP(monster)<br />
else<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
end<br />
<br />
function p._getMonsterLevel(monster, skillName)<br />
local result = 0<br />
if monster.levels[skillName] ~= nil then<br />
result = monster.levels[skillName]<br />
end<br />
return result<br />
end<br />
<br />
function p.getMonsterLevel(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame[1]<br />
local SkillName = frame.args ~= nil and frame.args[2] or frame[2]<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterLevel(monster, SkillName)<br />
end<br />
<br />
function p.getEquipmentStat(monster, statName)<br />
local result = 0<br />
for i, stat in Shared.skpairs(monster.equipmentStats) do<br />
if stat.key == statName then<br />
result = stat.value<br />
break<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.calculateStandardStat(effectiveLevel, bonus)<br />
--Based on calculateStandardStat in Characters.js<br />
return (effectiveLevel + 9) * (bonus + 64)<br />
end<br />
<br />
function p.calculateStandardMaxHit(baseLevel, strengthBonus)<br />
--Based on calculateStandardMaxHit in Characters.js<br />
local effectiveLevel = baseLevel + 9<br />
return math.floor(10 * (1.3 + effectiveLevel / 10 + strengthBonus / 80 + effectiveLevel * strengthBonus / 640))<br />
end<br />
<br />
function p._getMonsterAttackSpeed(monster)<br />
return p.getEquipmentStat(monster, 'attackSpeed') / 1000<br />
end<br />
<br />
function p.getMonsterAttackSpeed(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
if monster ~= nil then<br />
return p._getMonsterAttackSpeed(monster)<br />
else<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
end<br />
<br />
function p._getMonsterCombatLevel(monster)<br />
local base = 0.25 * (p._getMonsterLevel(monster, 'Defence') + p._getMonsterLevel(monster, 'Hitpoints'))<br />
local melee = 0.325 * (p._getMonsterLevel(monster, 'Attack') + p._getMonsterLevel(monster, 'Strength'))<br />
local range = 0.325 * (1.5 * p._getMonsterLevel(monster, 'Ranged'))<br />
local magic = 0.325 * (1.5 * p._getMonsterLevel(monster, 'Magic'))<br />
return math.floor(base + math.max(melee, range, magic))<br />
end<br />
<br />
function p.getMonsterCombatLevel(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterCombatLevel(monster)<br />
end<br />
<br />
function p._getMonsterAR(monster)<br />
local baseLevel = 0<br />
local bonus = 0<br />
if monster.attackType == 'melee' then<br />
baseLevel = p._getMonsterLevel(monster, 'Attack')<br />
bonus = p.getEquipmentStat(monster, 'stabAttackBonus')<br />
elseif monster.attackType == 'ranged' then<br />
baseLevel = p._getMonsterLevel(monster, 'Ranged')<br />
bonus = p.getEquipmentStat(monster, 'rangedAttackBonus')<br />
elseif monster.attackType == 'magic' then<br />
baseLevel = p._getMonsterLevel(monster, 'Magic')<br />
bonus = p.getEquipmentStat(monster, 'magicAttackBonus')<br />
elseif monster.attackType == 'random' then<br />
--Bane has the same AR with every attack type so being lazy and just showing the one.<br />
baseLevel = p._getMonsterLevel(monster, 'Attack')<br />
bonus = p.getEquipmentStat(monster, 'stabAttackBonus')<br />
else<br />
return "ERROR: This monster has an invalid attack type somehow[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p.calculateStandardStat(baseLevel, bonus)<br />
end<br />
<br />
function p.getMonsterAR(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterAR(monster)<br />
end<br />
<br />
function p._getMonsterER(monster, style)<br />
local baseLevel= 0<br />
local bonus = 0<br />
<br />
if style == "Melee" then<br />
baseLevel = p._getMonsterLevel(monster, 'Defence')<br />
bonus = p.getEquipmentStat(monster, 'meleeDefenceBonus')<br />
elseif style == "Ranged" then<br />
baseLevel = p._getMonsterLevel(monster, 'Defence')<br />
bonus = p.getEquipmentStat(monster, 'rangedDefenceBonus')<br />
elseif style == "Magic" then<br />
baseLevel = math.floor(p._getMonsterLevel(monster, 'Magic') * 0.7 + p._getMonsterLevel(monster, 'Defence') * 0.3)<br />
bonus = p.getEquipmentStat(monster, 'magicDefenceBonus')<br />
else<br />
return "ERROR: Must choose Melee, Ranged, or Magic[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p.calculateStandardStat(baseLevel, bonus)<br />
end<br />
<br />
function p.getMonsterER(frame)<br />
local args = frame.args ~= nil and frame.args or frame<br />
local MonsterName = args[1]<br />
local style = args[2]<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterER(monster, style)<br />
end<br />
<br />
-- Determines if the monster is capable of dropping bones, and returns the bones<br />
-- item if so, or nil otherwise<br />
function p._getMonsterBones(monster)<br />
if monster.bones ~= nil and monster.bones >= 0 then<br />
local boneItem = Items.getItemByID(monster.bones)<br />
if boneItem.prayerPoints == nil then<br />
-- Assume bones without prayer points are shards (from God dungeons),<br />
-- and drop unconditionally<br />
return boneItem<br />
elseif not monster.isBoss and not p._isDungeonOnlyMonster(monster) then<br />
-- Otherwise, bones drop when the monster isn't dungeon exclusive<br />
return boneItem<br />
end<br />
end<br />
end<br />
<br />
function p._isDungeonOnlyMonster(monster)<br />
local areaList = Areas.getMonsterAreas(monster.id)<br />
local inDungeon = false<br />
<br />
for i, area in ipairs(areaList) do<br />
if area.type == 'dungeon' then<br />
inDungeon = true<br />
else<br />
return false<br />
end<br />
end<br />
return inDungeon<br />
end<br />
<br />
function p.isDungeonOnlyMonster(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with name "..monsterName.." found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._isDungeonOnlyMonster(monster)<br />
end<br />
<br />
function p._getMonsterAreas(monster, excludeDungeons)<br />
local resultPart = {}<br />
local hideDungeons = excludeDungeons ~= nil and excludeDungeons or false<br />
local areaList = Areas.getMonsterAreas(monster.id)<br />
for i, area in ipairs(areaList) do<br />
if area.type ~= 'dungeon' or not hideDungeons then<br />
table.insert(resultPart, Icons.Icon({area.name, type = area.type}))<br />
end<br />
end<br />
return table.concat(resultPart, '<br/>')<br />
end<br />
<br />
function p.getMonsterAreas(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local hideDungeons = frame.args ~= nil and frame.args[2] or nil<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with name "..monsterName.." found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterAreas(monster, hideDungeons)<br />
end<br />
<br />
function p.getSpecAttackMaxHit(specAttack, normalMaxHit)<br />
local result = 0<br />
for i, dmg in pairs(specAttack.damage) do<br />
if dmg.maxRoll == 'Fixed' then<br />
result = dmg.maxPercent * 10<br />
elseif dmg.maxRoll == 'MaxHit' then<br />
if dmg.character == 'Target' then<br />
--Confusion applied damage based on the player's max hit. Gonna just ignore that one<br />
result = 0<br />
else<br />
result = dmg.maxPercent * normalMaxHit * 0.01<br />
end<br />
elseif Shared.contains({'Bleeding', 'Poisoned'}, dmg.maxRoll) then<br />
-- TODO: This is limited in that there is no verification that bleed/poison<br />
-- can be applied to the target, it is assumed that it can and so this applies<br />
result = result + dmg.maxPercent * 10<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.canSpecAttackApplyEffect(specAttack, effectType)<br />
local result = false<br />
for i, effect in pairs(specAttack.prehitEffects) do<br />
if effect.type == effectType then<br />
result = true<br />
break<br />
end<br />
end<br />
<br />
for i, effect in pairs(specAttack.onhitEffects) do<br />
if effect.type == effectType then<br />
result = true<br />
break<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p._getMonsterMaxHit(monster, doStuns)<br />
-- 2021-06-11 Adjusted for v0.20 stun/sleep changes, where damage multiplier now applies<br />
-- to all enemy attacks if stun/sleep is present on at least one special attack<br />
if doStuns == nil then<br />
doStuns = true<br />
elseif type(doStuns) == 'string' then<br />
doStuns = string.upper(doStuns) == 'TRUE'<br />
end<br />
<br />
local normalChance = 100<br />
local specialMaxHit = 0<br />
local normalMaxHit = p._getMonsterBaseMaxHit(monster)<br />
local hasActiveBuffSpec = false<br />
local damageMultiplier = 1<br />
if monster.specialAttacks[1] ~= nil then<br />
local canStun, canSleep = false, false<br />
for i, specAttack in pairs(monster.specialAttacks) do<br />
if monster.overrideSpecialChances ~= nil then<br />
normalChance = normalChance - monster.overrideSpecialChances[i]<br />
else<br />
normalChance = normalChance - specAttack.defaultChance<br />
end<br />
local thisMax = p.getSpecAttackMaxHit(specAttack, normalMaxHit)<br />
if not canStun and p.canSpecAttackApplyEffect(specAttack, 'Stun') then canStun = true end<br />
if not canSleep and p.canSpecAttackApplyEffect(specAttack, 'Sleep') then canSleep = true end<br />
<br />
if thisMax > specialMaxHit then specialMaxHit = thisMax end<br />
if Shared.contains(string.upper(specAttack.description), 'NORMAL ATTACK INSTEAD') then <br />
hasActiveBuffSpec = true <br />
end<br />
end<br />
<br />
if canSleep and doStuns then damageMultiplier = damageMultiplier * 1.2 end<br />
if canStun and doStuns then damageMultiplier = damageMultiplier * 1.3 end<br />
end<br />
--Ensure that if the monster never does a normal attack, the normal max hit is irrelevant<br />
if normalChance == 0 and not hasActiveBuffSpec then normalMaxHit = 0 end<br />
return math.floor(math.max(specialMaxHit, normalMaxHit) * damageMultiplier)<br />
end<br />
<br />
function p.getMonsterMaxHit(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local doStuns = frame.args ~= nil and frame.args[2] or true<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterMaxHit(monster, doStuns)<br />
end<br />
<br />
function p._getMonsterBaseMaxHit(monster)<br />
--8/27/21 - Now references p.calculateStandardMaxHit for Melee & Ranged<br />
local result = 0<br />
local baseLevel = 0<br />
local bonus = 0<br />
if monster.attackType == 'melee' then<br />
baseLevel = p._getMonsterLevel(monster, 'Strength')<br />
bonus = p.getEquipmentStat(monster, 'meleeStrengthBonus')<br />
result = p.calculateStandardMaxHit(baseLevel, bonus)<br />
elseif monster.attackType == 'ranged' then<br />
baseLevel = p._getMonsterLevel(monster, 'Ranged')<br />
bonus = p.getEquipmentStat(monster, 'rangedStrengthBonus')<br />
result = p.calculateStandardMaxHit(baseLevel, bonus)<br />
elseif monster.attackType == 'magic' then<br />
local mSpell = nil<br />
if monster.selectedSpell ~= nil then mSpell = Magic.getSpellByID('Spells', monster.selectedSpell) end<br />
<br />
bonus = p.getEquipmentStat(monster, 'magicDamageBonus')<br />
baseLevel = p._getMonsterLevel(monster, 'Magic')<br />
<br />
result = math.floor(10 * mSpell.maxHit * (1 + bonus / 100) * (1 + (baseLevel + 1) / 200))<br />
elseif monster.attackType == 'random' then<br />
local hitArray = {}<br />
local iconText = Icons.Icon({'Melee', notext=true})<br />
baseLevel = p._getMonsterLevel(monster, 'Strength')<br />
bonus = p.getEquipmentStat(monster, 'meleeStrengthBonus')<br />
table.insert(hitArray, p.calculateStandardMaxHit(baseLevel, bonus))<br />
<br />
iconText = Icons.Icon({'Ranged', type='skill', notext=true})<br />
baseLevel = p._getMonsterLevel(monster, 'Ranged')<br />
bonus = p.getEquipmentStat(monster, 'rangedStrengthBonus')<br />
table.insert(hitArray, p.calculateStandardMaxHit(baseLevel, bonus))<br />
<br />
iconText = Icons.Icon({'Magic', type='skill', notext=true})<br />
local mSpell = nil<br />
if monster.selectedSpell ~= nil then mSpell = Magic.getSpellByID('Spells', monster.selectedSpell) end<br />
bonus = p.getEquipmentStat(monster, 'magicDamageBonus')<br />
baseLevel = p._getMonsterLevel(monster, 'Magic')<br />
local magicDmg = math.floor(10 * mSpell.maxHit * (1 + bonus / 100) * (1 + (baseLevel + 1) / 200))<br />
table.insert(hitArray, magicDmg)<br />
<br />
local max = 0<br />
for i, val in pairs(hitArray) do<br />
if val > max then max = val end<br />
end<br />
result = max<br />
else<br />
return "ERROR: This monster has an invalid attack type somehow[[Category:Pages with script errors]]"<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getMonsterBaseMaxHit(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterBaseMaxHit(monster)<br />
end<br />
<br />
function p.getMonsterAttacks(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = ''<br />
local iconText = p._getMonsterStyleIcon({monster, notext=true})<br />
local typeText = ''<br />
if monster.attackType == 'melee' then<br />
typeText = 'Melee'<br />
elseif monster.attackType == 'ranged' then<br />
typeText = 'Ranged'<br />
elseif monster.attackType == 'magic' then<br />
typeText = 'Magic'<br />
elseif monster.attackType == 'random' then<br />
typeText = "Random"<br />
end<br />
<br />
local buffAttacks = {}<br />
local hasActiveBuffSpec = false<br />
<br />
local normalAttackChance = 100<br />
if monster.specialAttacks[1] ~= nil then<br />
for i, specAttack in pairs(monster.specialAttacks) do<br />
local attChance = 0<br />
if monster.overrideSpecialChances ~= nil then<br />
attChance = monster.overrideSpecialChances[i]<br />
else<br />
attChance = specAttack.defaultChance<br />
end<br />
normalAttackChance = normalAttackChance - attChance<br />
<br />
result = result..'\r\n* '..attChance..'% '..iconText..' '..specAttack.name..'\r\n** '..specAttack.description<br />
<br />
if Shared.contains(string.upper(specAttack.description), 'NORMAL ATTACK INSTEAD') then<br />
table.insert(buffAttacks, specAttack.name)<br />
hasActiveBuffSpec = true <br />
end<br />
end<br />
end<br />
if normalAttackChance == 100 then<br />
result = iconText..' 1 - '..p._getMonsterBaseMaxHit(monster)..' '..typeText..' Damage'<br />
elseif normalAttackChance > 0 then<br />
result = '* '..normalAttackChance..'% '..iconText..' 1 - '..p.getMonsterBaseMaxHit(frame)..' '..typeText..' Damage'..result<br />
elseif hasActiveBuffSpec then<br />
--If the monster normally has a 0% chance of doing a normal attack but some special attacks can't be repeated, include it<br />
--(With a note about when it does it)<br />
result = '* '..iconText..' 1 - '..p._getMonsterBaseMaxHit(monster)..' '..typeText..' Damage (Instead of repeating '..table.concat(buffAttacks, ' or ')..' while the effect is already active)'..result<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getMonsterPassives(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = ''<br />
if type(monster.passiveID) == 'table' and Shared.tableCount(monster.passiveID) > 0 then<br />
result = result .. '===Passives==='<br />
for i, passiveID in pairs(monster.passiveID) do<br />
local passive = p.getPassiveByID(passiveID)<br />
result = result .. '\r\n* ' .. passive.name .. '\r\n** ' .. passive.description<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.getMonsterCategories(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = '[[Category:Monsters]]'<br />
<br />
if monster.attackType == 'melee' then<br />
result = result..'[[Category:Melee Monsters]]'<br />
elseif monster.attackType == 'ranged' then<br />
result = result..'[[Category:Ranged Monsters]]'<br />
elseif monster.attackType == 'magic' then<br />
result = result..'[[Category:Magic Monsters]]'<br />
end<br />
<br />
if monster.specialAttacks[1] ~= nil then<br />
result = result..'[[Category:Monsters with Special Attacks]]'<br />
end<br />
<br />
if monster.isBoss then<br />
result = result..'[[Category:Bosses]]'<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getOtherMonsterBoxText(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = ''<br />
<br />
--Going through and finding out which damage bonuses will apply to this monster<br />
local monsterTypes = {}<br />
if monster.isBoss then table.insert(monsterTypes, 'Boss') end<br />
<br />
local areaList = Areas.getMonsterAreas(monster.id)<br />
local counts = {combat = 0, slayer = 0, dungeon = 0}<br />
for i, area in Shared.skpairs(areaList) do<br />
counts[area.type] = counts[area.type] + 1<br />
end<br />
<br />
if counts.combat > 0 then table.insert(monsterTypes, 'Combat Area') end<br />
if counts.slayer > 0 then table.insert(monsterTypes, 'Slayer Area') end<br />
if counts.dungeon > 0 then table.insert(monsterTypes, 'Dungeon') end<br />
<br />
result = result.."\r\n|-\r\n|'''Monster Types:''' "..table.concat(monsterTypes, ", ")<br />
<br />
local SlayerTier = 'N/A'<br />
if monster.canSlayer then<br />
SlayerTier = Constants.getSlayerTierNameByLevel(p._getMonsterCombatLevel(monster))<br />
end<br />
<br />
result = result.."\r\n|-\r\n|'''"..Icons.Icon({'Slayer', type='skill'}).." [[Slayer#Slayer Tier Monsters|Tier]]:''' "<br />
if monster.canSlayer then<br />
result = result.."[[Slayer#"..SlayerTier.."|"..SlayerTier.."]]"<br />
else<br />
result = result..SlayerTier<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getMonsterDrops(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = ''<br />
<br />
local bones = p._getMonsterBones(monster)<br />
local boneVal = 0<br />
--Show the bones only if either the monster shows up outside of dungeons _or_ the monster drops shards<br />
if bones ~= nil then<br />
local boneQty = (monster.boneQty ~= nil and monster.boneQty or 1)<br />
result = result.."'''Always Drops:'''"<br />
result = result..'\r\n{|class="wikitable" id="bonedrops"'<br />
result = result..'\r\n!Item !! Qty'<br />
result = result..'\r\n|-\r\n|'..Icons.Icon({bones.name, type='item'})<br />
result = result..'||'..boneQty..'\r\n'..'|}'<br />
boneVal = boneQty * bones.sellsFor<br />
end<br />
<br />
--Likewise, seeing the loot table is tied to the monster appearing outside of dungeons<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100<br />
local lootValue = 0<br />
<br />
result = result.."'''Loot:'''"<br />
local avgGp = 0<br />
<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2<br />
local gpTxt = Icons.GP(monster.dropCoins[1], monster.dropCoins[2])<br />
result = result.."\r\nIn addition to loot, the monster will also drop "..gpTxt..'.'<br />
end<br />
<br />
local multiDrop = Shared.tableCount(monster.lootTable) > 1<br />
local totalWt = 0<br />
for i, row in pairs(monster.lootTable) do<br />
totalWt = totalWt + row[2]<br />
end<br />
result = result..'\r\n{|class="wikitable sortable" id="itemdrops"'<br />
result = result..'\r\n!Item!!Qty'<br />
result = result..'!!Price!!colspan="2"|Chance'<br />
<br />
--Sort the loot table by weight in descending order<br />
table.sort(monster.lootTable, function(a, b) return a[2] > b[2] end)<br />
for i, row in Shared.skpairs(monster.lootTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
<br />
local maxQty = row[3]<br />
if thisItem ~= nil then<br />
result = result..'\r\n|-\r\n|'..Icons.Icon({thisItem.name, type='item'})<br />
else<br />
result = result..'\r\n|-\r\n|Unknown Item[[Category:Pages with script errors]]'<br />
end<br />
result = result..'||style="text-align:right" data-sort-value="'..maxQty..'"|'<br />
<br />
if maxQty > 1 then<br />
result = result.. '1 - '<br />
end<br />
result = result..Shared.formatnum(row[3])<br />
<br />
--Adding price columns<br />
local itemPrice = 0<br />
if thisItem == nil then<br />
result = result..'||data-sort-value="0"|???'<br />
else<br />
itemPrice = thisItem.sellsFor ~= nil and thisItem.sellsFor or 0<br />
if itemPrice == 0 or maxQty == 1 then<br />
result = result..'||'..Icons.GP(itemPrice)<br />
else<br />
result = result..'||'..Icons.GP(itemPrice, itemPrice * maxQty)<br />
end<br />
end<br />
<br />
--Getting the drop chance<br />
local dropChance = (row[2] / totalWt * lootChance)<br />
if dropChance < 100 then<br />
--Show fraction as long as it isn't going to be 1/1<br />
result = result..'||style="text-align:right" data-sort-value="'..row[2]..'"'<br />
result = result..'|'..Shared.fraction(row[2] * lootChance, totalWt * 100)<br />
result = result..'||'<br />
else<br />
result = result..'||colspan="2" data-sort-value="'..row[2]..'"'<br />
end<br />
-- If chance is less than 0.10% then show 2 significant figures, otherwise 2 decimal places<br />
local fmt = (dropChance < 0.10 and '%.2g') or '%.2f'<br />
result = result..'style="text-align:right"|'..string.format(fmt, dropChance)..'%'<br />
<br />
--Adding to the average loot value based on price & dropchance<br />
lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((1 + maxQty) / 2))<br />
end<br />
if multiDrop then<br />
result = result..'\r\n|-class="sortbottom" \r\n!colspan="3"|Total:'<br />
if lootChance < 100 then<br />
result = result..'\r\n|style="text-align:right"|'..Shared.fraction(lootChance, 100)..'||'<br />
else<br />
result = result..'\r\n|colspan="2" '<br />
end<br />
result = result..'style="text-align:right"|'..Shared.round(lootChance, 2, 2)..'%'<br />
end<br />
result = result..'\r\n|}'<br />
result = result..'\r\nThe loot dropped by the average kill is worth '..Icons.GP(Shared.round(lootValue, 2, 0)).." if sold."<br />
if avgGp > 0 then<br />
result = result.."<br/>Including GP"<br />
if boneVal > 0 then<br />
result = result..' and bones'<br />
end<br />
result = result..', the average kill is worth '..Icons.GP(Shared.round(avgGp + lootValue + boneVal, 2, 0))..'.'<br />
end<br />
end<br />
<br />
--If no other drops, make sure to at least say so.<br />
if result == '' then result = 'None' end<br />
return result<br />
end<br />
<br />
function p._getMonsterLootValue(monster)<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = 0<br />
local boneVal = 0<br />
<br />
local bones = p._getMonsterBones(monster)<br />
--Show the bones only if either the monster shows up outside of dungeons _or_ the monster drops shards<br />
if bones ~= nil then<br />
local boneQty = monster.boneQty ~= nil and monster.boneQty or 1<br />
boneVal = bones.sellsFor * boneQty<br />
result = result + boneVal<br />
end<br />
<br />
--Likewise, seeing the loot table is tied to the monster appearing outside of dungeons<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100<br />
local lootValue = 0<br />
<br />
local avgGp = 0<br />
<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2<br />
end<br />
<br />
local multiDrop = Shared.tableCount(monster.lootTable) > 1<br />
local totalWt = 0<br />
for i, row in pairs(monster.lootTable) do<br />
totalWt = totalWt + row[2]<br />
end<br />
<br />
for i, row in Shared.skpairs(monster.lootTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
<br />
local maxQty = row[3]<br />
<br />
--Adding price columns<br />
local itemPrice = 0<br />
if thisItem ~= nil then<br />
itemPrice = thisItem.sellsFor ~= nil and thisItem.sellsFor or 0<br />
end<br />
<br />
--Getting the drop chance<br />
local dropChance = (row[2] / totalWt * lootChance)<br />
--Adding to the average loot value based on price & dropchance<br />
lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((1 + maxQty) / 2))<br />
end<br />
if avgGp > 0 then<br />
result = result + avgGp + lootValue<br />
end<br />
end<br />
<br />
return result<br />
end<br />
<br />
-- Find drop chance of specified item from specified monster. <br />
-- Usage: |Monster Name|Item Name<br />
function p.getItemDropChance(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame[1]<br />
local ItemName = frame.args ~= nil and frame.args[2] or frame[2]<br />
<br />
local monster = p.getMonster(MonsterName)<br />
local item = Items.getItem(ItemName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
if item == nil then<br />
return "ERROR: No item with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100<br />
<br />
local totalWt = 0<br />
--for i, row in pairs(monster.lootTable) do<br />
--totalWt = totalWt + row[2]<br />
--end<br />
<br />
local dropChance = 0<br />
local dropWt = 0<br />
for i, row in Shared.skpairs(monster.lootTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
totalWt = totalWt + row[2]<br />
if item['id'] == thisItem['id'] then<br />
dropWt = row[2]<br />
end<br />
end<br />
dropChance = (dropWt / totalWt * lootChance)<br />
return Shared.round(dropChance, 2, 2)<br />
end<br />
end <br />
<br />
function p.getChestDrops(frame)<br />
local ChestName = frame.args ~= nil and frame.args[1] or frame<br />
local chest = Items.getItem(ChestName)<br />
<br />
if chest == nil then<br />
return "ERROR: No item named "..ChestName..' found[[Category:Pages with script errors]]'<br />
end<br />
<br />
local result = ''<br />
<br />
if chest.dropTable == nil then<br />
return "ERROR: "..ChestName.." does not have a drop table[[Category:Pages with script errors]]"<br />
else<br />
local lootChance = 100<br />
local lootValue = 0<br />
<br />
local multiDrop = Shared.tableCount(chest.dropTable) > 1<br />
local totalWt = 0<br />
for i, row in pairs(chest.dropTable) do<br />
totalWt = totalWt + row[2]<br />
end<br />
result = result..'\r\n{|class="wikitable sortable"'<br />
result = result..'\r\n!Item!!Qty'<br />
result = result..'!!colspan="2"|Chance!!Price'<br />
<br />
--Sort the loot table by weight in descending order<br />
for i, row in pairs(chest.dropTable) do<br />
if chest.dropQty ~= nil then<br />
table.insert(row, chest.dropQty[i])<br />
else<br />
table.insert(row, 1)<br />
end<br />
end<br />
table.sort(chest.dropTable, function(a, b) return a[2] > b[2] end)<br />
for i, row in Shared.skpairs(chest.dropTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
local qty = row[3]<br />
result = result..'\r\n|-\r\n|'..Icons.Icon({thisItem.name, type='item'})<br />
result = result..'||style="text-align:right" data-sort-value="'..qty..'"|'<br />
<br />
if qty > 1 then<br />
result = result.. '1 - '<br />
end<br />
result = result..Shared.formatnum(qty)<br />
<br />
local dropChance = (row[2] / totalWt) * 100<br />
result = result..'||style="text-align:right" data-sort-value="'..row[2]..'"'<br />
result = result..'|'..Shared.fraction(row[2], totalWt)<br />
<br />
result = result..'||style="text-align:right"|'..Shared.round(dropChance, 2, 2)..'%'<br />
<br />
result = result..'||style="text-align:left" data-sort-value="'..thisItem.sellsFor..'"'<br />
if qty > 1 then<br />
result = result..'|'..Icons.GP(thisItem.sellsFor, thisItem.sellsFor * qty)<br />
else<br />
result = result..'|'..Icons.GP(thisItem.sellsFor)<br />
end<br />
lootValue = lootValue + (dropChance * 0.01 * thisItem.sellsFor * ((1 + qty)/ 2))<br />
end<br />
result = result..'\r\n|}'<br />
result = result..'\r\nThe average value of the contents of one chest is '..Icons.GP(Shared.round(lootValue, 2, 0))..'.'<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getAreaMonsterTable(frame)<br />
local areaName = frame.args ~= nil and frame.args[1] or frame<br />
local area = Areas.getArea(areaName)<br />
if area == nil then<br />
return "ERROR: Could not find an area named "..areaName..'[[Category:Pages with script errors]]'<br />
end<br />
<br />
if area.type == 'dungeon' then<br />
return p.getDungeonMonsterTable(frame)<br />
end<br />
<br />
local tableTxt = '{| class="wikitable sortable"'<br />
tableTxt = tableTxt..'\r\n! Name !! Combat Level !! Hitpoints !! Max Hit !! [[Combat Triangle|Combat Style]]'<br />
for i, monsterID in pairs(area.monsters) do<br />
local monster = p.getMonsterByID(monsterID)<br />
tableTxt = tableTxt..'\r\n|-\r\n|'..Icons.Icon({monster.name, type='monster'})<br />
tableTxt = tableTxt..'||'..p._getMonsterCombatLevel(monster)<br />
tableTxt = tableTxt..'||'..Shared.formatnum(p._getMonsterHP(monster))<br />
tableTxt = tableTxt..'||'..Shared.formatnum(p._getMonsterMaxHit(monster))<br />
tableTxt = tableTxt..'||'..p._getMonsterStyleIcon({monster, nolink=true})<br />
end<br />
tableTxt = tableTxt..'\r\n|}'<br />
return tableTxt<br />
end<br />
<br />
function p.getDungeonMonsterTable(frame)<br />
local areaName = frame.args ~= nil and frame.args[1] or frame<br />
local area = Areas.getArea(areaName)<br />
if area == nil then<br />
return "ERROR: Could not find a dungeon named "..areaName..'[[Category:Pages with script errors]]'<br />
end<br />
<br />
--For Dungeons, go through and count how many of each monster are in the dungeon first<br />
local monsterCounts = {}<br />
for i, monsterID in pairs(area.monsters) do<br />
if monsterCounts[monsterID] == nil then<br />
monsterCounts[monsterID] = 1<br />
else<br />
monsterCounts[monsterID] = monsterCounts[monsterID] + 1<br />
end<br />
end<br />
<br />
local usedMonsters = {}<br />
<br />
-- Declare function for building table rows to avoid repeating code<br />
local buildRow = function(entityID, monsterCount, specialType)<br />
local monIcon, monLevel, monHP, monMaxHit, monStyle, monCount<br />
local monData = {}<br />
if specialType ~= nil and Shared.contains({'Afflicted', 'SlayerArea'}, specialType) then<br />
-- Special handling for Into the Mist<br />
if specialType == 'Afflicted' then<br />
local iconQ = Icons.Icon({'Into the Mist', notext=true, nolink=true, img='Question'})<br />
monIcon = Icons.Icon({'Into the Mist', 'Afflicted Monster', nolink=true, img='Question'})<br />
monLevel, monHP, monMaxHit, monStyle, monCount = iconQ, iconQ, iconQ, iconQ, monsterCount<br />
elseif specialType == 'SlayerArea' then<br />
-- entityID corresponds to a slayer area<br />
local area = Areas.getAreaByID('slayer', entityID)<br />
monIcon = Icons.Icon({area.name, type='combatArea'}) .. ' Monsters'<br />
monLevel = {p.getLowHighStat(area.monsters, function(monster) return p._getMonsterCombatLevel(monster) end)}<br />
monHP = {p.getLowHighStat(area.monsters, function(monster) return p._getMonsterHP(monster) end)}<br />
local lowMaxHit, highMaxHit = p.getLowHighStat(area.monsters, function(monster) return p._getMonsterMaxHit(monster) end)<br />
monMaxHit = highMaxHit<br />
monStyle = Icons.Icon({area.name, area.name, notext=true, nolink=true, img='Question'})<br />
monCount = monsterCount<br />
end<br />
else<br />
-- entityID corresponds to a monster<br />
local monster = p.getMonsterByID(entityID)<br />
monIcon = Icons.Icon({monster.name, type='monster'})<br />
monLevel = p._getMonsterCombatLevel(monster)<br />
monHP = p._getMonsterHP(monster)<br />
monMaxHit = p._getMonsterMaxHit(monster)<br />
monStyle = p._getMonsterStyleIcon({monster})<br />
monCount = monsterCount<br />
end<br />
local getValSort = function(val)<br />
if type(val) == 'table' then<br />
if type(val[1]) == 'number' and type(val[2]) == 'number' then<br />
return (val[1] + val[2]) / 2<br />
else<br />
return (type(val[1]) == 'number' and val[1]) or 0<br />
end<br />
else<br />
return (type(val) == 'number' and val) or 0<br />
end<br />
end<br />
local getValText = function(val)<br />
if type(val) == 'table' and Shared.tableCount(val) == 2 then<br />
if type(val[1]) == 'number' and type(val[2]) == 'number' then<br />
return Shared.formatnum(val[1]) .. ' - ' .. Shared.formatnum(val[2])<br />
else<br />
return val[1] .. ' - ' .. val[2]<br />
end<br />
elseif type(val) == 'number' then<br />
return Shared.formatnum(val)<br />
else<br />
return val<br />
end<br />
end<br />
<br />
local resultPart = {}<br />
table.insert(resultPart, '\r\n|-\r\n| ' .. monIcon)<br />
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monLevel) .. '"| ' .. getValText(monLevel))<br />
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monHP) .. '"| ' .. getValText(monHP))<br />
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monMaxHit) .. '"| ' .. getValText(monMaxHit))<br />
table.insert(resultPart, '\r\n| ' .. monStyle)<br />
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monCount) .. '"| ' .. getValText(monCount))<br />
return table.concat(resultPart)<br />
end<br />
<br />
local returnPart = {}<br />
table.insert(returnPart, '{| class="wikitable sortable"')<br />
table.insert(returnPart, '\r\n! Name !! Combat Level !! Hitpoints !! Max Hit !! [[Combat Triangle|Combat Style]] !! Count')<br />
-- Special handing for Impending Darkness event<br />
-- TODO needs to be revised once there is a better understanding of how the event works<br />
--if area.isEvent ~= nil and area.isEvent then<br />
-- for i, eventAreaID in ipairs(Areas.eventData.slayerAreas) do<br />
-- table.insert(returnPart, buildRow(eventAreaID, {5, 8}, 'SlayerArea'))<br />
-- end<br />
-- -- Add Bane * 4<br />
-- table.insert(returnPart, buildRow(152, 4))<br />
--end<br />
for i, monsterID in pairs(area.monsters) do<br />
if not Shared.contains(usedMonsters, monsterID) then<br />
if monsterID >= 0 then<br />
table.insert(returnPart, buildRow(monsterID, monsterCounts[monsterID]))<br />
else<br />
--Special handling for Into the Mist<br />
table.insert(returnPart, buildRow(monsterID, monsterCounts[monsterID], 'Afflicted'))<br />
end<br />
table.insert(usedMonsters, monsterID)<br />
end<br />
end<br />
table.insert(returnPart, '\r\n|}')<br />
return table.concat(returnPart)<br />
end<br />
<br />
function p.getDungeonTotalHp(frame)<br />
local areaName = frame.args ~= nil and frame.args[1] or frame<br />
local area = Areas.getArea(areaName)<br />
if area == nil then<br />
return "ERROR: Could not find a dungeon named "..areaName..'[[Category:Pages with script errors]]'<br />
end<br />
local totalHP = 0<br />
<br />
for i, monsterID in pairs(area.monsters) do<br />
if not Shared.contains(usedMonsters, monsterID) then<br />
local monster = p.getMonsterByID(monsterID)<br />
totalHP = totalHP + p._getMonsterHP(monster)<br />
end<br />
end<br />
return totalHP<br />
end<br />
<br />
function p._getAreaMonsterList(area)<br />
local monsterList = {}<br />
for i, monsterID in pairs(area.monsters) do<br />
local monster = p.getMonsterByID(monsterID)<br />
table.insert(monsterList, Icons.Icon({monster.name, type='monster'}))<br />
end<br />
return table.concat(monsterList, '<br/>')<br />
end<br />
<br />
function p._getDungeonMonsterList(area)<br />
local monsterList = {}<br />
local lastMonster = nil<br />
local lastID = -2<br />
local count = 0<br />
-- Special handing for Impending Darkness event<br />
-- TODO needs to be revised once there is a better understanding of how the event works<br />
--if area.isEvent ~= nil and area.isEvent then<br />
-- for i, eventAreaID in ipairs(Areas.eventData.slayerAreas) do<br />
-- local eventArea = Areas.getAreaByID('slayer', eventAreaID)<br />
-- table.insert(monsterList, '5-8 ' .. Icons.Icon({eventArea.name, type='combatArea'}) .. ' Monsters')<br />
-- end<br />
-- table.insert(monsterList, '4 ' .. Icons.Icon({'Bane', type='monster'}))<br />
--end<br />
for i, monsterID in Shared.skpairs(area.monsters) do<br />
if monsterID ~= lastID then<br />
local monster = nil <br />
if monsterID ~= -1 then monster = p.getMonsterByID(monsterID) end<br />
if lastID ~= -2 then<br />
if lastID == -1 then<br />
--Special handling for Afflicted Monsters<br />
table.insert(monsterList, Icons.Icon({'Affliction', 'Afflicted Monster', img='Question', qty=count}))<br />
else<br />
local name = lastMonster.name<br />
table.insert(monsterList, Icons.Icon({name, type='monster', qty=count}))<br />
end<br />
end<br />
lastMonster = monster<br />
lastID = monsterID<br />
count = 1<br />
else<br />
count = count + 1<br />
end<br />
--Make sure the final monster in the dungeon gets counted<br />
if i == Shared.tableCount(area.monsters) then<br />
local name = lastMonster.name<br />
table.insert(monsterList, Icons.Icon({lastMonster.name, type='monster', qty=count}))<br />
end<br />
end<br />
return table.concat(monsterList, '<br/>')<br />
end<br />
<br />
function p.getAreaMonsterList(frame)<br />
local areaName = frame.args ~= nil and frame.args[1] or frame<br />
local area = Areas.getArea(areaName)<br />
if area == nil then<br />
return "ERROR: Could not find an area named "..areaName..'[[Category:Pages with script errors]]'<br />
end<br />
<br />
if area.type == 'dungeon' then<br />
return p._getDungeonMonsterList(area)<br />
else<br />
return p._getAreaMonsterList(area)<br />
end<br />
end<br />
<br />
function p.getFoxyTable(frame)<br />
local result = 'Monster,Min GP,Max GP,Average GP'<br />
for i, monster in Shared.skpairs(MonsterData.Monsters) do<br />
if not p._isDungeonOnlyMonster(monster) then<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
local avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2<br />
result = result..'<br/>'..monster.name..','..monster.dropCoins[1]..','..(monster.dropCoins[2])..','..avgGp<br />
end<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p._getMonsterAverageGP(monster)<br />
local result = ''<br />
local totalGP = 0<br />
<br />
local bones = p._getMonsterBones(monster)<br />
if bones ~= nil then<br />
totalGP = totalGP + bones.sellsFor * (type(monster.boneQty) == 'number' and monster.boneQty or 1)<br />
end<br />
<br />
--Likewise, seeing the loot table is tied to the monster appearing outside of dungeons<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100<br />
local lootValue = 0<br />
<br />
local avgGp = 0<br />
<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2<br />
end<br />
<br />
totalGP = totalGP + avgGp<br />
<br />
local multiDrop = Shared.tableCount(monster.lootTable) > 1<br />
local totalWt = 0<br />
for i, row in pairs(monster.lootTable) do<br />
totalWt = totalWt + row[2]<br />
end<br />
<br />
for i, row in Shared.skpairs(monster.lootTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
local maxQty = row[3]<br />
<br />
local itemPrice = thisItem.sellsFor ~= nil and thisItem.sellsFor or 0<br />
<br />
--Getting the drop chance<br />
local dropChance = (row[2] / totalWt * lootChance)<br />
<br />
--Adding to the average loot value based on price & dropchance<br />
lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((1 + maxQty) / 2))<br />
end<br />
<br />
totalGP = totalGP + lootValue<br />
end<br />
<br />
return Shared.round(totalGP, 2, 2)<br />
end<br />
<br />
function p.getMonsterAverageGP(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterAverageGP(monster)<br />
end<br />
<br />
function p.getMonsterEVTable(frame)<br />
local result = '{| class="wikitable sortable"'<br />
result = result..'\r\n!Monster!!Combat Level!!Average GP'<br />
for i, monsterTemp in Shared.skpairs(MonsterData.Monsters) do<br />
local monster = Shared.clone(monsterTemp)<br />
monster.id = i - 1<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local monsterGP = p._getMonsterAverageGP(monster)<br />
local combatLevel = p._getMonsterCombatLevel(monster, 'Combat Level')<br />
result = result..'\r\n|-\r\n|'..Icons.Icon({monster.name, type='monster', noicon=true})..'||'..combatLevel..'||'..monsterGP<br />
end<br />
end<br />
result = result..'\r\n|}'<br />
return result<br />
end<br />
<br />
function p.getSlayerTierMonsterTable(frame)<br />
-- Input validation<br />
local tier = frame.args ~= nil and frame.args[1] or frame<br />
local slayerTier = nil<br />
<br />
if tier == nil then<br />
return "ERROR: No tier specified[[Category:Pages with script errors]]"<br />
end<br />
<br />
if tonumber(tier) ~= nil then<br />
slayerTier = Constants.getSlayerTierByID(tonumber(tier))<br />
else<br />
slayerTier = Constants.getSlayerTier(tier)<br />
end<br />
<br />
if slayerTier == nil then<br />
return "ERROR: Invalid slayer tier[[Category:Pages with script errors]]"<br />
end<br />
<br />
-- Obtain required tier details<br />
local minLevel, maxLevel = slayerTier.minLevel, slayerTier.maxLevel<br />
<br />
-- Build list of monster IDs<br />
-- Right now hiddenMonsterIDs is empty<br />
local hiddenMonsterIDs = {}<br />
local monsterIDs = {}<br />
for i, monster in Shared.skpairs(MonsterData.Monsters) do<br />
if monster.canSlayer and not Shared.contains(hiddenMonsterIDs, i - 1) then<br />
local cmbLevel = p._getMonsterCombatLevel(monster)<br />
if cmbLevel >= minLevel and (maxLevel == nil or cmbLevel <= maxLevel) then<br />
table.insert(monsterIDs, i - 1)<br />
end<br />
end<br />
end<br />
<br />
if Shared.tableCount(monsterIDs) == 0 then<br />
-- Somehow no monsters are in the tier, return nothing<br />
return ''<br />
else<br />
return p._getMonsterTable(monsterIDs, true)<br />
end<br />
end<br />
<br />
function p.getFullMonsterTable(frame)<br />
local monsterIDs = {}<br />
for i = 0, Shared.tableCount(MonsterData.Monsters) - 1, 1 do<br />
table.insert(monsterIDs, i)<br />
end<br />
<br />
return p._getMonsterTable(monsterIDs, false)<br />
end<br />
<br />
function p._getMonsterTable(monsterIDs, excludeDungeons)<br />
--Making a single function for getting a table of monsters given a list of IDs.<br />
local hideDungeons = excludeDungeons ~= nil and excludeDungeons or false<br />
local tableParts = {}<br />
table.insert(tableParts, '{| class="wikitable sortable stickyHeader"')<br />
-- First header row<br />
table.insert(tableParts, '\r\n|- class="headerRow-0"\r\n! colspan="5" | !! colspan="4" |Offensive Stats !! colspan="3" |Evasion Rating !! colspan="4" |')<br />
-- Second header row<br />
table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n!Monster !!Name !!ID !!Combat Level ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Hitpoints', type='skill'}))<br />
table.insert(tableParts, '!!Attack Speed (s) !!colspan="2"|Max Hit !!Accuracy ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Defence', type='skill', notext=true}))<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Ranged', type='skill', notext=true}))<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Magic', type='skill', notext=true}))<br />
table.insert(tableParts, '!!' .. Icons.Icon({'Coins', notext=true, nolink=true}) .. ' Coins !!Bones !!Locations')<br />
<br />
-- Generate row per monster<br />
for i, monsterID in Shared.skpairs(monsterIDs) do<br />
local monster = p.getMonsterByID(monsterID)<br />
local cmbLevel = p._getMonsterCombatLevel(monster)<br />
local atkSpeed = p._getMonsterAttackSpeed(monster)<br />
local maxHit = p._getMonsterMaxHit(monster)<br />
local accR = p._getMonsterAR(monster)<br />
local evaR = {p._getMonsterER(monster, "Melee"), p._getMonsterER(monster, "Ranged"), p._getMonsterER(monster, "Magic")}<br />
<br />
local gpRange = {0, 0}<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
gpRange = {monster.dropCoins[1], monster.dropCoins[2]}<br />
end<br />
local gpTxt = nil<br />
if gpRange[1] >= gpRange[2] then<br />
gpTxt = Shared.formatnum(gpRange[1])<br />
else<br />
gpTxt = Shared.formatnum(gpRange[1]) .. ' - ' .. Shared.formatnum(gpRange[2])<br />
end<br />
local bones = p._getMonsterBones(monster)<br />
local boneTxt = (bones ~= nil and Icons.Icon({bones.name, type='item', notext=true})) or 'None'<br />
<br />
table.insert(tableParts, '\r\n|-\r\n|style="text-align: center;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:left" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:right" |' .. monsterID)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. cmbLevel .. '" |' .. Shared.formatnum(cmbLevel))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. p._getMonsterHP(monster) .. '" |' .. Shared.formatnum(p._getMonsterHP(monster)))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. atkSpeed .. '" |' .. Shared.round(atkSpeed, 1, 1))<br />
table.insert(tableParts, '\r\n|style="text-align:center;border-right:hidden" |' .. p._getMonsterStyleIcon({monster, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. maxHit .. '" |' .. Shared.formatnum(maxHit))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. accR .. '" |' .. Shared.formatnum(accR))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[1] .. '" |' .. Shared.formatnum(evaR[1]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[2] .. '" |' .. Shared.formatnum(evaR[2]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[3] .. '" |' .. Shared.formatnum(evaR[3]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:center" |' .. boneTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))<br />
end<br />
<br />
table.insert(tableParts, '\r\n|}')<br />
return table.concat(tableParts)<br />
end<br />
<br />
function p.getMattMonsterTable(frame)<br />
--Making a single function for getting a table of monsters given a list of IDs.<br />
local tableParts = {}<br />
table.insert(tableParts, '{| class="wikitable sortable stickyHeader"')<br />
-- Second header row<br />
table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n!Monster !!Name !!ID !!Combat Level ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Hitpoints', type='skill'}))<br />
table.insert(tableParts, '!!' .. Icons.Icon({'Coins', notext=true, nolink=true}) .. ' Coins !!Avg. Kill Value!!Locations')<br />
<br />
-- Generate row per monster<br />
for i, monster in Shared.skpairs(MonsterData.Monsters) do<br />
local cmbLevel = p._getMonsterCombatLevel(monster)<br />
<br />
local gpRange = {0, 0}<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
gpRange = {monster.dropCoins[1], monster.dropCoins[2]}<br />
end<br />
local gpTxt = nil<br />
if gpRange[1] >= gpRange[2] then<br />
gpTxt = Shared.formatnum(gpRange[1])<br />
else<br />
gpTxt = Shared.formatnum(gpRange[1]) .. ' - ' .. Shared.formatnum(gpRange[2])<br />
end<br />
<br />
local lootVal = p._getMonsterLootValue(monster)<br />
local lootTxt = '0'<br />
if lootVal ~= 0 then<br />
lootTxt = Shared.formatnum(Shared.round(lootVal, 2, 2))<br />
end<br />
<br />
<br />
table.insert(tableParts, '\r\n|-\r\n|style="text-align: center;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:left" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:right" |' .. monster.id)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. cmbLevel .. '" |' .. Shared.formatnum(cmbLevel))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. p._getMonsterHP(monster) .. '" |' .. Shared.formatnum(p._getMonsterHP(monster)))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. lootVal .. '" |' .. lootTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))<br />
end<br />
<br />
table.insert(tableParts, '\r\n|}')<br />
return table.concat(tableParts)<br />
end<br />
<br />
function p.getMattMonsterTableV2(frame)<br />
--Making a single function for getting a table of monsters given a list of IDs.<br />
local tableParts = {}<br />
table.insert(tableParts, '{| class="wikitable sortable stickyHeader"')<br />
-- Second header row<br />
table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n!Monster !!Name !!Combat Level ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Hitpoints', type='skill'}))<br />
table.insert(tableParts, '!!Attack Speed (s) !!colspan="2"|Max Hit !!Accuracy ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Defence', type='skill', notext=true}))<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Ranged', type='skill', notext=true}))<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Magic', type='skill', notext=true}))<br />
table.insert(tableParts, '!!' .. Icons.Icon({'Coins', notext=true, nolink=true}) .. ' Coins !!Avg. Kill Value !!Bones')<br />
<br />
-- Generate row per monster<br />
for i, monster in Shared.skpairs(MonsterData.Monsters) do<br />
local cmbLevel = p._getMonsterCombatLevel(monster)<br />
<br />
local gpRange = {0, 0}<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
gpRange = {monster.dropCoins[1], monster.dropCoins[2]}<br />
end<br />
local gpTxt = nil<br />
if gpRange[1] >= gpRange[2] then<br />
gpTxt = Shared.formatnum(gpRange[1])<br />
else<br />
gpTxt = Shared.formatnum(gpRange[1]) .. ' - ' .. Shared.formatnum(gpRange[2])<br />
end<br />
<br />
local lootVal = p._getMonsterLootValue(monster)<br />
local lootTxt = '0'<br />
if lootVal ~= 0 then<br />
lootTxt = Shared.formatnum(Shared.round(lootVal, 2, 2))<br />
end<br />
<br />
local atkSpeed = p._getMonsterAttackSpeed(monster)<br />
local maxHit = p._getMonsterMaxHit(monster)<br />
local accR = p._getMonsterAR(monster)<br />
local evaR = {p._getMonsterER(monster, "Melee"), p._getMonsterER(monster, "Ranged"), p._getMonsterER(monster, "Magic")}<br />
<br />
local boneTxt = (bones ~= nil and Icons.Icon({bones.name, type='item', notext=true})) or 'None'<br />
<br />
table.insert(tableParts, '\r\n|-\r\n|style="text-align: center;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:left" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))<br />
-- table.insert(tableParts, '\r\n|style="text-align:right" |' .. monster.id)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. cmbLevel .. '" |' .. Shared.formatnum(cmbLevel))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. p._getMonsterHP(monster) .. '" |' .. Shared.formatnum(p._getMonsterHP(monster)))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. atkSpeed .. '" |' .. Shared.round(atkSpeed, 1, 1))<br />
table.insert(tableParts, '\r\n|style="text-align:center;border-right:hidden" |' .. p._getMonsterStyleIcon({monster, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. maxHit .. '" |' .. Shared.formatnum(maxHit))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. accR .. '" |' .. Shared.formatnum(accR))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[1] .. '" |' .. Shared.formatnum(evaR[1]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[2] .. '" |' .. Shared.formatnum(evaR[2]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[3] .. '" |' .. Shared.formatnum(evaR[3]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. lootVal .. '" |' .. lootTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:center" |' .. boneTxt)<br />
-- table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))<br />
end<br />
<br />
table.insert(tableParts, '\r\n|}')<br />
return table.concat(tableParts)<br />
end<br />
<br />
function p.getSpecialAttackTable(frame)<br />
local spAttTable = {}<br />
<br />
for i, monster in ipairs(MonsterData.Monsters) do<br />
if monster.specialAttacks ~= nil and Shared.tableCount(monster.specialAttacks) > 0 then<br />
local overrideChance = (monster.overrideSpecialChances ~= nil and Shared.tableCount(monster.overrideSpecialChances) > 0)<br />
for j, spAtt in ipairs(monster.specialAttacks) do<br />
local attChance = (overrideChance and monster.overrideSpecialChances[j] or spAtt.defaultChance)<br />
if spAttTable[spAtt.id] == nil then<br />
spAttTable[spAtt.id] = { ['defn'] = spAtt, ['icons'] = {} }<br />
end<br />
if spAttTable[spAtt.id]['icons'][attChance] == nil then<br />
spAttTable[spAtt.id]['icons'][attChance] = {}<br />
end<br />
table.insert(spAttTable[spAtt.id]['icons'][attChance], Icons.Icon({ monster.name, type = 'monster' }))<br />
end<br />
end<br />
end<br />
<br />
local resultPart = {}<br />
table.insert(resultPart, '{|class="wikitable sortable stickyHeader"')<br />
table.insert(resultPart, '\r\n|- class="headerRow-0"')<br />
table.insert(resultPart, '\r\n!Name!!style="min-width:225px"|Monsters!!Chance!!Effect')<br />
<br />
for i, spAttData in Shared.skpairs(spAttTable) do<br />
local spAtt = spAttData.defn<br />
local firstRow = true<br />
local rowsSpanned = Shared.tableCount(spAttData.icons)<br />
local rowSuffix = ''<br />
if rowsSpanned > 1 then<br />
rowSuffix = '|rowspan="' .. rowsSpanned .. '"'<br />
end<br />
for chance, iconList in Shared.skpairs(spAttData.icons) do<br />
table.insert(resultPart, '\r\n|-')<br />
if firstRow then<br />
table.insert(resultPart, '\r\n' .. rowSuffix .. '| ' .. spAtt.name)<br />
end<br />
table.insert(resultPart, '\r\n|data-sort-value="' .. spAtt.name .. '"| ' .. table.concat(iconList, '<br/>'))<br />
table.insert(resultPart, '\r\n|data-sort-value="' .. chance .. '"| ' .. Shared.round(chance, 2, 0) .. '%')<br />
if firstRow then<br />
table.insert(resultPart, '\r\n' .. rowSuffix .. '| ' .. spAtt.description)<br />
firstRow = false<br />
end<br />
end<br />
end<br />
table.insert(resultPart, '\r\n|}')<br />
<br />
return table.concat(resultPart)<br />
end<br />
<br />
return p</div>
Roko
https://wiki.melvoridle.com/index.php?title=Module:Monsters&diff=51090
Module:Monsters
2022-02-19T13:29:42Z
<p>Roko: </p>
<hr />
<div>local p = {}<br />
<br />
local MonsterData = mw.loadData('Module:Monsters/data')<br />
<br />
local Constants = require('Module:Constants')<br />
local Areas = require('Module:CombatAreas')<br />
local Magic = require('Module:Magic')<br />
local Shared = require('Module:Shared')<br />
local Icons = require('Module:Icons')<br />
local Items = require('Module:Items')<br />
<br />
function p.getMonster(name)<br />
local result = nil<br />
if name == 'Spider (lv. 51)' or name == 'Spider' then<br />
return p.getMonsterByID(50)<br />
elseif name == 'Spider (lv. 52)' or name == 'Spider2' then<br />
return p.getMonsterByID(51)<br />
end<br />
<br />
for i, monster in pairs(MonsterData.Monsters) do<br />
if monster.name == name then<br />
result = Shared.clone(monster)<br />
--Make sure every monster has an ID, and account for the 1-based indexing of Lua<br />
result.id = i - 1<br />
break<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.getMonsterByID(ID)<br />
local result = Shared.clone(MonsterData.Monsters[ID + 1])<br />
if result ~= nil then<br />
result.id = ID<br />
return result<br />
else<br />
return nil<br />
end<br />
end<br />
<br />
function p.getPassive(name)<br />
local result = nil<br />
<br />
for i, passive in pairs(MonsterData.Passives) do<br />
if passive.name == name then<br />
result = Shared.clone(passive)<br />
--Make sure every passive has an ID, and account for the 1-based indexing of Lua<br />
result.id = i - 1<br />
break<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.getPassiveByID(ID)<br />
return MonsterData.Passives[ID + 1]<br />
end<br />
<br />
-- Given a list of monster IDs, calls statFunc with each monster and returns<br />
-- the lowest & highest values<br />
function p.getLowHighStat(idList, statFunc)<br />
local lowVal, highVal = nil, nil<br />
for i, monID in ipairs(idList) do<br />
local monster = p.getMonsterByID(monID)<br />
local statVal = statFunc(monster)<br />
if lowVal == nil or statVal < lowVal then lowVal = statVal end<br />
if highVal == nil or statVal > highVal then highVal = statVal end<br />
end<br />
return lowVal, highVal<br />
end<br />
<br />
function p._getMonsterStat(monster, statName)<br />
if statName == 'HP' then<br />
return p._getMonsterHP(monster)<br />
elseif statName == 'maxHit' then<br />
return p._getMonsterMaxHit(monster)<br />
elseif statName == 'accuracyRating' then<br />
return p._getMonsterAR(monster)<br />
elseif statName == 'meleeEvasionRating' then<br />
return p._getMonsterER(monster, 'Melee')<br />
elseif statName == 'rangedEvasionRating' then<br />
return p._getMonsterER(monster, 'Ranged')<br />
elseif statName == 'magicEvasionRating' then<br />
return p._getMonsterER(monster, 'Magic')<br />
elseif statName == 'damageReduction' then<br />
return p.getEquipmentStat(monster, 'damageReduction')<br />
end<br />
<br />
return monster[statName]<br />
end<br />
<br />
function p.getMonsterStat(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame[1]<br />
local StatName = frame.args ~= nil and frame.args[2] or frame[2]<br />
local monster = p.getMonster(MonsterName)<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterStat(monster, StatName)<br />
end<br />
<br />
function p._getMonsterStyleIcon(frame)<br />
local args = frame.args ~= nil and frame.args or frame<br />
local monster = args[1]<br />
local notext = args.notext<br />
local nolink = args.nolink<br />
<br />
local iconText = ''<br />
if monster.attackType == 'melee' then<br />
iconText = Icons.Icon({'Melee', notext=notext, nolink=nolink})<br />
elseif monster.attackType == 'ranged' then<br />
iconText = Icons.Icon({'Ranged', type='skill', notext=notext, nolink=nolink})<br />
elseif monster.attackType == 'magic' then<br />
iconText = Icons.Icon({'Magic', type='skill', notext=notext, nolink=nolink})<br />
elseif monster.attackType == 'random' then<br />
iconText = Icons.Icon({'Bane', notext=notext, nolink=nolink, img='Question'})<br />
end<br />
<br />
return iconText<br />
end<br />
<br />
function p.getMonsterStyleIcon(frame)<br />
local args = frame.args ~= nil and frame.args or frame<br />
local MonsterName = args[1]<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
args[1] = monster<br />
return p._getMonsterStyleIcon(args)<br />
end<br />
<br />
function p._getMonsterHP(monster)<br />
return 10 * p._getMonsterLevel(monster, 'Hitpoints')<br />
end<br />
<br />
function p.getMonsterEffectiveHP(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
if monster ~= nil then<br />
return math.floor((p._getMonsterHP(monster)/(1 - p._getMonsterStat(monster, 'damageReduction')/100)) + 0.5)<br />
else<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
end<br />
<br />
function p.getMonsterHP(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
if monster ~= nil then<br />
return p._getMonsterHP(monster)<br />
else<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
end<br />
<br />
function p._getMonsterLevel(monster, skillName)<br />
local result = 0<br />
if monster.levels[skillName] ~= nil then<br />
result = monster.levels[skillName]<br />
end<br />
return result<br />
end<br />
<br />
function p.getMonsterLevel(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame[1]<br />
local SkillName = frame.args ~= nil and frame.args[2] or frame[2]<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterLevel(monster, SkillName)<br />
end<br />
<br />
function p.getEquipmentStat(monster, statName)<br />
local result = 0<br />
for i, stat in Shared.skpairs(monster.equipmentStats) do<br />
if stat.key == statName then<br />
result = stat.value<br />
break<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.calculateStandardStat(effectiveLevel, bonus)<br />
--Based on calculateStandardStat in Characters.js<br />
return (effectiveLevel + 9) * (bonus + 64)<br />
end<br />
<br />
function p.calculateStandardMaxHit(baseLevel, strengthBonus)<br />
--Based on calculateStandardMaxHit in Characters.js<br />
local effectiveLevel = baseLevel + 9<br />
return math.floor(10 * (1.3 + effectiveLevel / 10 + strengthBonus / 80 + effectiveLevel * strengthBonus / 640))<br />
end<br />
<br />
function p._getMonsterAttackSpeed(monster)<br />
return p.getEquipmentStat(monster, 'attackSpeed') / 1000<br />
end<br />
<br />
function p.getMonsterAttackSpeed(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
if monster ~= nil then<br />
return p._getMonsterAttackSpeed(monster)<br />
else<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
end<br />
<br />
function p._getMonsterCombatLevel(monster)<br />
local base = 0.25 * (p._getMonsterLevel(monster, 'Defence') + p._getMonsterLevel(monster, 'Hitpoints'))<br />
local melee = 0.325 * (p._getMonsterLevel(monster, 'Attack') + p._getMonsterLevel(monster, 'Strength'))<br />
local range = 0.325 * (1.5 * p._getMonsterLevel(monster, 'Ranged'))<br />
local magic = 0.325 * (1.5 * p._getMonsterLevel(monster, 'Magic'))<br />
return math.floor(base + math.max(melee, range, magic))<br />
end<br />
<br />
function p.getMonsterCombatLevel(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterCombatLevel(monster)<br />
end<br />
<br />
function p._getMonsterAR(monster)<br />
local baseLevel = 0<br />
local bonus = 0<br />
if monster.attackType == 'melee' then<br />
baseLevel = p._getMonsterLevel(monster, 'Attack')<br />
bonus = p.getEquipmentStat(monster, 'stabAttackBonus')<br />
elseif monster.attackType == 'ranged' then<br />
baseLevel = p._getMonsterLevel(monster, 'Ranged')<br />
bonus = p.getEquipmentStat(monster, 'rangedAttackBonus')<br />
elseif monster.attackType == 'magic' then<br />
baseLevel = p._getMonsterLevel(monster, 'Magic')<br />
bonus = p.getEquipmentStat(monster, 'magicAttackBonus')<br />
elseif monster.attackType == 'random' then<br />
--Bane has the same AR with every attack type so being lazy and just showing the one.<br />
baseLevel = p._getMonsterLevel(monster, 'Attack')<br />
bonus = p.getEquipmentStat(monster, 'stabAttackBonus')<br />
else<br />
return "ERROR: This monster has an invalid attack type somehow[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p.calculateStandardStat(baseLevel, bonus)<br />
end<br />
<br />
function p.getMonsterAR(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterAR(monster)<br />
end<br />
<br />
function p._getMonsterER(monster, style)<br />
local baseLevel= 0<br />
local bonus = 0<br />
<br />
if style == "Melee" then<br />
baseLevel = p._getMonsterLevel(monster, 'Defence')<br />
bonus = p.getEquipmentStat(monster, 'meleeDefenceBonus')<br />
elseif style == "Ranged" then<br />
baseLevel = p._getMonsterLevel(monster, 'Defence')<br />
bonus = p.getEquipmentStat(monster, 'rangedDefenceBonus')<br />
elseif style == "Magic" then<br />
baseLevel = math.floor(p._getMonsterLevel(monster, 'Magic') * 0.7 + p._getMonsterLevel(monster, 'Defence') * 0.3)<br />
bonus = p.getEquipmentStat(monster, 'magicDefenceBonus')<br />
else<br />
return "ERROR: Must choose Melee, Ranged, or Magic[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p.calculateStandardStat(baseLevel, bonus)<br />
end<br />
<br />
function p.getMonsterER(frame)<br />
local args = frame.args ~= nil and frame.args or frame<br />
local MonsterName = args[1]<br />
local style = args[2]<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterER(monster, style)<br />
end<br />
<br />
-- Determines if the monster is capable of dropping bones, and returns the bones<br />
-- item if so, or nil otherwise<br />
function p._getMonsterBones(monster)<br />
if monster.bones ~= nil and monster.bones >= 0 then<br />
local boneItem = Items.getItemByID(monster.bones)<br />
if boneItem.prayerPoints == nil then<br />
-- Assume bones without prayer points are shards (from God dungeons),<br />
-- and drop unconditionally<br />
return boneItem<br />
elseif not monster.isBoss and not p._isDungeonOnlyMonster(monster) then<br />
-- Otherwise, bones drop when the monster isn't dungeon exclusive<br />
return boneItem<br />
end<br />
end<br />
end<br />
<br />
function p._isDungeonOnlyMonster(monster)<br />
local areaList = Areas.getMonsterAreas(monster.id)<br />
local inDungeon = false<br />
<br />
for i, area in ipairs(areaList) do<br />
if area.type == 'dungeon' then<br />
inDungeon = true<br />
else<br />
return false<br />
end<br />
end<br />
return inDungeon<br />
end<br />
<br />
function p.isDungeonOnlyMonster(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with name "..monsterName.." found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._isDungeonOnlyMonster(monster)<br />
end<br />
<br />
function p._getMonsterAreas(monster, excludeDungeons)<br />
local resultPart = {}<br />
local hideDungeons = excludeDungeons ~= nil and excludeDungeons or false<br />
local areaList = Areas.getMonsterAreas(monster.id)<br />
for i, area in ipairs(areaList) do<br />
if area.type ~= 'dungeon' or not hideDungeons then<br />
table.insert(resultPart, Icons.Icon({area.name, type = area.type}))<br />
end<br />
end<br />
return table.concat(resultPart, '<br/>')<br />
end<br />
<br />
function p.getMonsterAreas(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local hideDungeons = frame.args ~= nil and frame.args[2] or nil<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with name "..monsterName.." found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterAreas(monster, hideDungeons)<br />
end<br />
<br />
function p.getSpecAttackMaxHit(specAttack, normalMaxHit)<br />
local result = 0<br />
for i, dmg in pairs(specAttack.damage) do<br />
if dmg.maxRoll == 'Fixed' then<br />
result = dmg.maxPercent * 10<br />
elseif dmg.maxRoll == 'MaxHit' then<br />
if dmg.character == 'Target' then<br />
--Confusion applied damage based on the player's max hit. Gonna just ignore that one<br />
result = 0<br />
else<br />
result = dmg.maxPercent * normalMaxHit * 0.01<br />
end<br />
elseif Shared.contains({'Bleeding', 'Poisoned'}, dmg.maxRoll) then<br />
-- TODO: This is limited in that there is no verification that bleed/poison<br />
-- can be applied to the target, it is assumed that it can and so this applies<br />
result = result + dmg.maxPercent * 10<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.canSpecAttackApplyEffect(specAttack, effectType)<br />
local result = false<br />
for i, effect in pairs(specAttack.prehitEffects) do<br />
if effect.type == effectType then<br />
result = true<br />
break<br />
end<br />
end<br />
<br />
for i, effect in pairs(specAttack.onhitEffects) do<br />
if effect.type == effectType then<br />
result = true<br />
break<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p._getMonsterMaxHit(monster, doStuns)<br />
-- 2021-06-11 Adjusted for v0.20 stun/sleep changes, where damage multiplier now applies<br />
-- to all enemy attacks if stun/sleep is present on at least one special attack<br />
if doStuns == nil then<br />
doStuns = true<br />
elseif type(doStuns) == 'string' then<br />
doStuns = string.upper(doStuns) == 'TRUE'<br />
end<br />
<br />
local normalChance = 100<br />
local specialMaxHit = 0<br />
local normalMaxHit = p._getMonsterBaseMaxHit(monster)<br />
local hasActiveBuffSpec = false<br />
local damageMultiplier = 1<br />
if monster.specialAttacks[1] ~= nil then<br />
local canStun, canSleep = false, false<br />
for i, specAttack in pairs(monster.specialAttacks) do<br />
if monster.overrideSpecialChances ~= nil then<br />
normalChance = normalChance - monster.overrideSpecialChances[i]<br />
else<br />
normalChance = normalChance - specAttack.defaultChance<br />
end<br />
local thisMax = p.getSpecAttackMaxHit(specAttack, normalMaxHit)<br />
if not canStun and p.canSpecAttackApplyEffect(specAttack, 'Stun') then canStun = true end<br />
if not canSleep and p.canSpecAttackApplyEffect(specAttack, 'Sleep') then canSleep = true end<br />
<br />
if thisMax > specialMaxHit then specialMaxHit = thisMax end<br />
if Shared.contains(string.upper(specAttack.description), 'NORMAL ATTACK INSTEAD') then <br />
hasActiveBuffSpec = true <br />
end<br />
end<br />
<br />
if canSleep and doStuns then damageMultiplier = damageMultiplier * 1.2 end<br />
if canStun and doStuns then damageMultiplier = damageMultiplier * 1.3 end<br />
end<br />
--Ensure that if the monster never does a normal attack, the normal max hit is irrelevant<br />
if normalChance == 0 and not hasActiveBuffSpec then normalMaxHit = 0 end<br />
return math.floor(math.max(specialMaxHit, normalMaxHit) * damageMultiplier)<br />
end<br />
<br />
function p.getMonsterMaxHit(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local doStuns = frame.args ~= nil and frame.args[2] or true<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterMaxHit(monster, doStuns)<br />
end<br />
<br />
function p._getMonsterBaseMaxHit(monster)<br />
--8/27/21 - Now references p.calculateStandardMaxHit for Melee & Ranged<br />
local result = 0<br />
local baseLevel = 0<br />
local bonus = 0<br />
if monster.attackType == 'melee' then<br />
baseLevel = p._getMonsterLevel(monster, 'Strength')<br />
bonus = p.getEquipmentStat(monster, 'meleeStrengthBonus')<br />
result = p.calculateStandardMaxHit(baseLevel, bonus)<br />
elseif monster.attackType == 'ranged' then<br />
baseLevel = p._getMonsterLevel(monster, 'Ranged')<br />
bonus = p.getEquipmentStat(monster, 'rangedStrengthBonus')<br />
result = p.calculateStandardMaxHit(baseLevel, bonus)<br />
elseif monster.attackType == 'magic' then<br />
local mSpell = nil<br />
if monster.selectedSpell ~= nil then mSpell = Magic.getSpellByID('Spells', monster.selectedSpell) end<br />
<br />
bonus = p.getEquipmentStat(monster, 'magicDamageBonus')<br />
baseLevel = p._getMonsterLevel(monster, 'Magic')<br />
<br />
result = math.floor(10 * mSpell.maxHit * (1 + bonus / 100) * (1 + (baseLevel + 1) / 200))<br />
elseif monster.attackType == 'random' then<br />
local hitArray = {}<br />
local iconText = Icons.Icon({'Melee', notext=true})<br />
baseLevel = p._getMonsterLevel(monster, 'Strength')<br />
bonus = p.getEquipmentStat(monster, 'meleeStrengthBonus')<br />
table.insert(hitArray, p.calculateStandardMaxHit(baseLevel, bonus))<br />
<br />
iconText = Icons.Icon({'Ranged', type='skill', notext=true})<br />
baseLevel = p._getMonsterLevel(monster, 'Ranged')<br />
bonus = p.getEquipmentStat(monster, 'rangedStrengthBonus')<br />
table.insert(hitArray, p.calculateStandardMaxHit(baseLevel, bonus))<br />
<br />
iconText = Icons.Icon({'Magic', type='skill', notext=true})<br />
local mSpell = nil<br />
if monster.selectedSpell ~= nil then mSpell = Magic.getSpellByID('Spells', monster.selectedSpell) end<br />
bonus = p.getEquipmentStat(monster, 'magicDamageBonus')<br />
baseLevel = p._getMonsterLevel(monster, 'Magic')<br />
local magicDmg = math.floor(10 * mSpell.maxHit * (1 + bonus / 100) * (1 + (baseLevel + 1) / 200))<br />
table.insert(hitArray, magicDmg)<br />
<br />
local max = 0<br />
for i, val in pairs(hitArray) do<br />
if val > max then max = val end<br />
end<br />
result = max<br />
else<br />
return "ERROR: This monster has an invalid attack type somehow[[Category:Pages with script errors]]"<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getMonsterBaseMaxHit(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterBaseMaxHit(monster)<br />
end<br />
<br />
function p.getMonsterAttacks(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = ''<br />
local iconText = p._getMonsterStyleIcon({monster, notext=true})<br />
local typeText = ''<br />
if monster.attackType == 'melee' then<br />
typeText = 'Melee'<br />
elseif monster.attackType == 'ranged' then<br />
typeText = 'Ranged'<br />
elseif monster.attackType == 'magic' then<br />
typeText = 'Magic'<br />
elseif monster.attackType == 'random' then<br />
typeText = "Random"<br />
end<br />
<br />
local buffAttacks = {}<br />
local hasActiveBuffSpec = false<br />
<br />
local normalAttackChance = 100<br />
if monster.specialAttacks[1] ~= nil then<br />
for i, specAttack in pairs(monster.specialAttacks) do<br />
local attChance = 0<br />
if monster.overrideSpecialChances ~= nil then<br />
attChance = monster.overrideSpecialChances[i]<br />
else<br />
attChance = specAttack.defaultChance<br />
end<br />
normalAttackChance = normalAttackChance - attChance<br />
<br />
result = result..'\r\n* '..attChance..'% '..iconText..' '..specAttack.name..'\r\n** '..specAttack.description<br />
<br />
if Shared.contains(string.upper(specAttack.description), 'NORMAL ATTACK INSTEAD') then<br />
table.insert(buffAttacks, specAttack.name)<br />
hasActiveBuffSpec = true <br />
end<br />
end<br />
end<br />
if normalAttackChance == 100 then<br />
result = iconText..' 1 - '..p._getMonsterBaseMaxHit(monster)..' '..typeText..' Damage'<br />
elseif normalAttackChance > 0 then<br />
result = '* '..normalAttackChance..'% '..iconText..' 1 - '..p.getMonsterBaseMaxHit(frame)..' '..typeText..' Damage'..result<br />
elseif hasActiveBuffSpec then<br />
--If the monster normally has a 0% chance of doing a normal attack but some special attacks can't be repeated, include it<br />
--(With a note about when it does it)<br />
result = '* '..iconText..' 1 - '..p._getMonsterBaseMaxHit(monster)..' '..typeText..' Damage (Instead of repeating '..table.concat(buffAttacks, ' or ')..' while the effect is already active)'..result<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getMonsterPassives(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = ''<br />
if type(monster.passiveID) == 'table' and Shared.tableCount(monster.passiveID) > 0 then<br />
result = result .. '===Passives==='<br />
for i, passiveID in pairs(monster.passiveID) do<br />
local passive = p.getPassiveByID(passiveID)<br />
result = result .. '\r\n* ' .. passive.name .. '\r\n** ' .. passive.description<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.getMonsterCategories(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = '[[Category:Monsters]]'<br />
<br />
if monster.attackType == 'melee' then<br />
result = result..'[[Category:Melee Monsters]]'<br />
elseif monster.attackType == 'ranged' then<br />
result = result..'[[Category:Ranged Monsters]]'<br />
elseif monster.attackType == 'magic' then<br />
result = result..'[[Category:Magic Monsters]]'<br />
end<br />
<br />
if monster.specialAttacks[1] ~= nil then<br />
result = result..'[[Category:Monsters with Special Attacks]]'<br />
end<br />
<br />
if monster.isBoss then<br />
result = result..'[[Category:Bosses]]'<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getOtherMonsterBoxText(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = ''<br />
<br />
--Going through and finding out which damage bonuses will apply to this monster<br />
local monsterTypes = {}<br />
if monster.isBoss then table.insert(monsterTypes, 'Boss') end<br />
<br />
local areaList = Areas.getMonsterAreas(monster.id)<br />
local counts = {combat = 0, slayer = 0, dungeon = 0}<br />
for i, area in Shared.skpairs(areaList) do<br />
counts[area.type] = counts[area.type] + 1<br />
end<br />
<br />
if counts.combat > 0 then table.insert(monsterTypes, 'Combat Area') end<br />
if counts.slayer > 0 then table.insert(monsterTypes, 'Slayer Area') end<br />
if counts.dungeon > 0 then table.insert(monsterTypes, 'Dungeon') end<br />
<br />
result = result.."\r\n|-\r\n|'''Monster Types:''' "..table.concat(monsterTypes, ", ")<br />
<br />
local SlayerTier = 'N/A'<br />
if monster.canSlayer then<br />
SlayerTier = Constants.getSlayerTierNameByLevel(p._getMonsterCombatLevel(monster))<br />
end<br />
<br />
result = result.."\r\n|-\r\n|'''"..Icons.Icon({'Slayer', type='skill'}).." [[Slayer#Slayer Tier Monsters|Tier]]:''' "<br />
if monster.canSlayer then<br />
result = result.."[[Slayer#"..SlayerTier.."|"..SlayerTier.."]]"<br />
else<br />
result = result..SlayerTier<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getMonsterDrops(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = ''<br />
<br />
local bones = p._getMonsterBones(monster)<br />
local boneVal = 0<br />
--Show the bones only if either the monster shows up outside of dungeons _or_ the monster drops shards<br />
if bones ~= nil then<br />
local boneQty = (monster.boneQty ~= nil and monster.boneQty or 1)<br />
result = result.."'''Always Drops:'''"<br />
result = result..'\r\n{|class="wikitable" id="bonedrops"'<br />
result = result..'\r\n!Item !! Qty'<br />
result = result..'\r\n|-\r\n|'..Icons.Icon({bones.name, type='item'})<br />
result = result..'||'..boneQty..'\r\n'..'|}'<br />
boneVal = boneQty * bones.sellsFor<br />
end<br />
<br />
--Likewise, seeing the loot table is tied to the monster appearing outside of dungeons<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100<br />
local lootValue = 0<br />
<br />
result = result.."'''Loot:'''"<br />
local avgGp = 0<br />
<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2<br />
local gpTxt = Icons.GP(monster.dropCoins[1], monster.dropCoins[2])<br />
result = result.."\r\nIn addition to loot, the monster will also drop "..gpTxt..'.'<br />
end<br />
<br />
local multiDrop = Shared.tableCount(monster.lootTable) > 1<br />
local totalWt = 0<br />
for i, row in pairs(monster.lootTable) do<br />
totalWt = totalWt + row[2]<br />
end<br />
result = result..'\r\n{|class="wikitable sortable" id="itemdrops"'<br />
result = result..'\r\n!Item!!Qty'<br />
result = result..'!!Price!!colspan="2"|Chance'<br />
<br />
--Sort the loot table by weight in descending order<br />
table.sort(monster.lootTable, function(a, b) return a[2] > b[2] end)<br />
for i, row in Shared.skpairs(monster.lootTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
<br />
local maxQty = row[3]<br />
if thisItem ~= nil then<br />
result = result..'\r\n|-\r\n|'..Icons.Icon({thisItem.name, type='item'})<br />
else<br />
result = result..'\r\n|-\r\n|Unknown Item[[Category:Pages with script errors]]'<br />
end<br />
result = result..'||style="text-align:right" data-sort-value="'..maxQty..'"|'<br />
<br />
if maxQty > 1 then<br />
result = result.. '1 - '<br />
end<br />
result = result..Shared.formatnum(row[3])<br />
<br />
--Adding price columns<br />
local itemPrice = 0<br />
if thisItem == nil then<br />
result = result..'||data-sort-value="0"|???'<br />
else<br />
itemPrice = thisItem.sellsFor ~= nil and thisItem.sellsFor or 0<br />
if itemPrice == 0 or maxQty == 1 then<br />
result = result..'||'..Icons.GP(itemPrice)<br />
else<br />
result = result..'||'..Icons.GP(itemPrice, itemPrice * maxQty)<br />
end<br />
end<br />
<br />
--Getting the drop chance<br />
local dropChance = (row[2] / totalWt * lootChance)<br />
if dropChance < 100 then<br />
--Show fraction as long as it isn't going to be 1/1<br />
result = result..'||style="text-align:right" data-sort-value="'..row[2]..'"'<br />
result = result..'|'..Shared.fraction(row[2] * lootChance, totalWt * 100)<br />
result = result..'||'<br />
else<br />
result = result..'||colspan="2" data-sort-value="'..row[2]..'"'<br />
end<br />
-- If chance is less than 0.10% then show 2 significant figures, otherwise 2 decimal places<br />
local fmt = (dropChance < 0.10 and '%.2g') or '%.2f'<br />
result = result..'style="text-align:right"|'..string.format(fmt, dropChance)..'%'<br />
<br />
--Adding to the average loot value based on price & dropchance<br />
lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((1 + maxQty) / 2))<br />
end<br />
if multiDrop then<br />
result = result..'\r\n|-class="sortbottom" \r\n!colspan="3"|Total:'<br />
if lootChance < 100 then<br />
result = result..'\r\n|style="text-align:right"|'..Shared.fraction(lootChance, 100)..'||'<br />
else<br />
result = result..'\r\n|colspan="2" '<br />
end<br />
result = result..'style="text-align:right"|'..Shared.round(lootChance, 2, 2)..'%'<br />
end<br />
result = result..'\r\n|}'<br />
result = result..'\r\nThe loot dropped by the average kill is worth '..Icons.GP(Shared.round(lootValue, 2, 0)).." if sold."<br />
if avgGp > 0 then<br />
result = result.."<br/>Including GP"<br />
if boneVal > 0 then<br />
result = result..' and bones'<br />
end<br />
result = result..', the average kill is worth '..Icons.GP(Shared.round(avgGp + lootValue + boneVal, 2, 0))..'.'<br />
end<br />
end<br />
<br />
--If no other drops, make sure to at least say so.<br />
if result == '' then result = 'None' end<br />
return result<br />
end<br />
<br />
function p._getMonsterLootValue(monster)<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = 0<br />
local boneVal = 0<br />
<br />
local bones = p._getMonsterBones(monster)<br />
--Show the bones only if either the monster shows up outside of dungeons _or_ the monster drops shards<br />
if bones ~= nil then<br />
local boneQty = monster.boneQty ~= nil and monster.boneQty or 1<br />
boneVal = bones.sellsFor * boneQty<br />
result = result + boneVal<br />
end<br />
<br />
--Likewise, seeing the loot table is tied to the monster appearing outside of dungeons<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100<br />
local lootValue = 0<br />
<br />
local avgGp = 0<br />
<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2<br />
end<br />
<br />
local multiDrop = Shared.tableCount(monster.lootTable) > 1<br />
local totalWt = 0<br />
for i, row in pairs(monster.lootTable) do<br />
totalWt = totalWt + row[2]<br />
end<br />
<br />
for i, row in Shared.skpairs(monster.lootTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
<br />
local maxQty = row[3]<br />
<br />
--Adding price columns<br />
local itemPrice = 0<br />
if thisItem ~= nil then<br />
itemPrice = thisItem.sellsFor ~= nil and thisItem.sellsFor or 0<br />
end<br />
<br />
--Getting the drop chance<br />
local dropChance = (row[2] / totalWt * lootChance)<br />
--Adding to the average loot value based on price & dropchance<br />
lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((1 + maxQty) / 2))<br />
end<br />
if avgGp > 0 then<br />
result = result + avgGp + lootValue<br />
end<br />
end<br />
<br />
return result<br />
end<br />
<br />
-- Find drop chance of specified item from specified monster. <br />
-- Usage: |Monster Name|Item Name<br />
function p.getItemDropChance(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame[1]<br />
local ItemName = frame.args ~= nil and frame.args[2] or frame[2]<br />
<br />
local monster = p.getMonster(MonsterName)<br />
local item = Items.getItem(ItemName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
if item == nil then<br />
return "ERROR: No item with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100<br />
<br />
local totalWt = 0<br />
--for i, row in pairs(monster.lootTable) do<br />
--totalWt = totalWt + row[2]<br />
--end<br />
<br />
local dropChance = 0<br />
local dropWt = 0<br />
for i, row in Shared.skpairs(monster.lootTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
totalWt = totalWt + row[2]<br />
if item['id'] == thisItem['id'] then<br />
dropWt = row[2]<br />
end<br />
end<br />
dropChance = (dropWt / totalWt * lootChance)<br />
return Shared.round(dropChance, 2, 2)<br />
end<br />
end <br />
<br />
function p.getChestDrops(frame)<br />
local ChestName = frame.args ~= nil and frame.args[1] or frame<br />
local chest = Items.getItem(ChestName)<br />
<br />
if chest == nil then<br />
return "ERROR: No item named "..ChestName..' found[[Category:Pages with script errors]]'<br />
end<br />
<br />
local result = ''<br />
<br />
if chest.dropTable == nil then<br />
return "ERROR: "..ChestName.." does not have a drop table[[Category:Pages with script errors]]"<br />
else<br />
local lootChance = 100<br />
local lootValue = 0<br />
<br />
local multiDrop = Shared.tableCount(chest.dropTable) > 1<br />
local totalWt = 0<br />
for i, row in pairs(chest.dropTable) do<br />
totalWt = totalWt + row[2]<br />
end<br />
result = result..'\r\n{|class="wikitable sortable"'<br />
result = result..'\r\n!Item!!Qty'<br />
result = result..'!!colspan="2"|Chance!!Price'<br />
<br />
--Sort the loot table by weight in descending order<br />
for i, row in pairs(chest.dropTable) do<br />
if chest.dropQty ~= nil then<br />
table.insert(row, chest.dropQty[i])<br />
else<br />
table.insert(row, 1)<br />
end<br />
end<br />
table.sort(chest.dropTable, function(a, b) return a[2] > b[2] end)<br />
for i, row in Shared.skpairs(chest.dropTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
local qty = row[3]<br />
result = result..'\r\n|-\r\n|'..Icons.Icon({thisItem.name, type='item'})<br />
result = result..'||style="text-align:right" data-sort-value="'..qty..'"|'<br />
<br />
if qty > 1 then<br />
result = result.. '1 - '<br />
end<br />
result = result..Shared.formatnum(qty)<br />
<br />
local dropChance = (row[2] / totalWt) * 100<br />
result = result..'||style="text-align:right" data-sort-value="'..row[2]..'"'<br />
result = result..'|'..Shared.fraction(row[2], totalWt)<br />
<br />
result = result..'||style="text-align:right"|'..Shared.round(dropChance, 2, 2)..'%'<br />
<br />
result = result..'||style="text-align:left" data-sort-value="'..thisItem.sellsFor..'"'<br />
if qty > 1 then<br />
result = result..'|'..Icons.GP(thisItem.sellsFor, thisItem.sellsFor * qty)<br />
else<br />
result = result..'|'..Icons.GP(thisItem.sellsFor)<br />
end<br />
lootValue = lootValue + (dropChance * 0.01 * thisItem.sellsFor * ((1 + qty)/ 2))<br />
end<br />
result = result..'\r\n|}'<br />
result = result..'\r\nThe average value of the contents of one chest is '..Icons.GP(Shared.round(lootValue, 2, 0))..'.'<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getAreaMonsterTable(frame)<br />
local areaName = frame.args ~= nil and frame.args[1] or frame<br />
local area = Areas.getArea(areaName)<br />
if area == nil then<br />
return "ERROR: Could not find an area named "..areaName..'[[Category:Pages with script errors]]'<br />
end<br />
<br />
if area.type == 'dungeon' then<br />
return p.getDungeonMonsterTable(frame)<br />
end<br />
<br />
local tableTxt = '{| class="wikitable sortable"'<br />
tableTxt = tableTxt..'\r\n! Name !! Combat Level !! Hitpoints !! Max Hit !! [[Combat Triangle|Combat Style]]'<br />
for i, monsterID in pairs(area.monsters) do<br />
local monster = p.getMonsterByID(monsterID)<br />
tableTxt = tableTxt..'\r\n|-\r\n|'..Icons.Icon({monster.name, type='monster'})<br />
tableTxt = tableTxt..'||'..p._getMonsterCombatLevel(monster)<br />
tableTxt = tableTxt..'||'..Shared.formatnum(p._getMonsterHP(monster))<br />
tableTxt = tableTxt..'||'..Shared.formatnum(p._getMonsterMaxHit(monster))<br />
tableTxt = tableTxt..'||'..p._getMonsterStyleIcon({monster, nolink=true})<br />
end<br />
tableTxt = tableTxt..'\r\n|}'<br />
return tableTxt<br />
end<br />
<br />
function p.getDungeonMonsterTable(frame)<br />
local areaName = frame.args ~= nil and frame.args[1] or frame<br />
local area = Areas.getArea(areaName)<br />
if area == nil then<br />
return "ERROR: Could not find a dungeon named "..areaName..'[[Category:Pages with script errors]]'<br />
end<br />
<br />
--For Dungeons, go through and count how many of each monster are in the dungeon first<br />
local monsterCounts = {}<br />
for i, monsterID in pairs(area.monsters) do<br />
if monsterCounts[monsterID] == nil then<br />
monsterCounts[monsterID] = 1<br />
else<br />
monsterCounts[monsterID] = monsterCounts[monsterID] + 1<br />
end<br />
end<br />
<br />
local usedMonsters = {}<br />
<br />
-- Declare function for building table rows to avoid repeating code<br />
local buildRow = function(entityID, monsterCount, specialType)<br />
local monIcon, monLevel, monHP, monMaxHit, monStyle, monCount<br />
local monData = {}<br />
if specialType ~= nil and Shared.contains({'Afflicted', 'SlayerArea'}, specialType) then<br />
-- Special handling for Into the Mist<br />
if specialType == 'Afflicted' then<br />
local iconQ = Icons.Icon({'Into the Mist', notext=true, nolink=true, img='Question'})<br />
monIcon = Icons.Icon({'Into the Mist', 'Afflicted Monster', nolink=true, img='Question'})<br />
monLevel, monHP, monMaxHit, monStyle, monCount = iconQ, iconQ, iconQ, iconQ, monsterCount<br />
elseif specialType == 'SlayerArea' then<br />
-- entityID corresponds to a slayer area<br />
local area = Areas.getAreaByID('slayer', entityID)<br />
monIcon = Icons.Icon({area.name, type='combatArea'}) .. ' Monsters'<br />
monLevel = {p.getLowHighStat(area.monsters, function(monster) return p._getMonsterCombatLevel(monster) end)}<br />
monHP = {p.getLowHighStat(area.monsters, function(monster) return p._getMonsterHP(monster) end)}<br />
local lowMaxHit, highMaxHit = p.getLowHighStat(area.monsters, function(monster) return p._getMonsterMaxHit(monster) end)<br />
monMaxHit = highMaxHit<br />
monStyle = Icons.Icon({area.name, area.name, notext=true, nolink=true, img='Question'})<br />
monCount = monsterCount<br />
end<br />
else<br />
-- entityID corresponds to a monster<br />
local monster = p.getMonsterByID(entityID)<br />
monIcon = Icons.Icon({monster.name, type='monster'})<br />
monLevel = p._getMonsterCombatLevel(monster)<br />
monHP = p._getMonsterHP(monster)<br />
monMaxHit = p._getMonsterMaxHit(monster)<br />
monStyle = p._getMonsterStyleIcon({monster})<br />
monCount = monsterCount<br />
end<br />
local getValSort = function(val)<br />
if type(val) == 'table' then<br />
if type(val[1]) == 'number' and type(val[2]) == 'number' then<br />
return (val[1] + val[2]) / 2<br />
else<br />
return (type(val[1]) == 'number' and val[1]) or 0<br />
end<br />
else<br />
return (type(val) == 'number' and val) or 0<br />
end<br />
end<br />
local getValText = function(val)<br />
if type(val) == 'table' and Shared.tableCount(val) == 2 then<br />
if type(val[1]) == 'number' and type(val[2]) == 'number' then<br />
return Shared.formatnum(val[1]) .. ' - ' .. Shared.formatnum(val[2])<br />
else<br />
return val[1] .. ' - ' .. val[2]<br />
end<br />
elseif type(val) == 'number' then<br />
return Shared.formatnum(val)<br />
else<br />
return val<br />
end<br />
end<br />
<br />
local resultPart = {}<br />
table.insert(resultPart, '\r\n|-\r\n| ' .. monIcon)<br />
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monLevel) .. '"| ' .. getValText(monLevel))<br />
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monHP) .. '"| ' .. getValText(monHP))<br />
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monMaxHit) .. '"| ' .. getValText(monMaxHit))<br />
table.insert(resultPart, '\r\n| ' .. monStyle)<br />
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monCount) .. '"| ' .. getValText(monCount))<br />
return table.concat(resultPart)<br />
end<br />
<br />
local returnPart = {}<br />
table.insert(returnPart, '{| class="wikitable sortable"')<br />
table.insert(returnPart, '\r\n! Name !! Combat Level !! Hitpoints !! Max Hit !! [[Combat Triangle|Combat Style]] !! Count')<br />
-- Special handing for Impending Darkness event<br />
-- TODO needs to be revised once there is a better understanding of how the event works<br />
--if area.isEvent ~= nil and area.isEvent then<br />
-- for i, eventAreaID in ipairs(Areas.eventData.slayerAreas) do<br />
-- table.insert(returnPart, buildRow(eventAreaID, {5, 8}, 'SlayerArea'))<br />
-- end<br />
-- -- Add Bane * 4<br />
-- table.insert(returnPart, buildRow(152, 4))<br />
--end<br />
for i, monsterID in pairs(area.monsters) do<br />
if not Shared.contains(usedMonsters, monsterID) then<br />
if monsterID >= 0 then<br />
table.insert(returnPart, buildRow(monsterID, monsterCounts[monsterID]))<br />
else<br />
--Special handling for Into the Mist<br />
table.insert(returnPart, buildRow(monsterID, monsterCounts[monsterID], 'Afflicted'))<br />
end<br />
table.insert(usedMonsters, monsterID)<br />
end<br />
end<br />
table.insert(returnPart, '\r\n|}')<br />
return table.concat(returnPart)<br />
end<br />
<br />
function p.getDungeonTotalHp(frame)<br />
local areaName = frame.args ~= nil and frame.args[1] or frame<br />
local area = Areas.getArea(areaName)<br />
if area == nil then<br />
return "ERROR: Could not find a dungeon named "..areaName..'[[Category:Pages with script errors]]'<br />
end<br />
local totalHP = 0<br />
<br />
for i, monsterID in pairs(area.monsters) do<br />
if not Shared.contains(usedMonsters, monsterID) then<br />
local monster = p.getMonsterByID(monsterID)<br />
totalHP = totalHP + p._getMonsterHP(monster)<br />
end<br />
end<br />
return totalHP<br />
end<br />
<br />
function p._getAreaMonsterList(area)<br />
local monsterList = {}<br />
for i, monsterID in pairs(area.monsters) do<br />
local monster = p.getMonsterByID(monsterID)<br />
table.insert(monsterList, Icons.Icon({monster.name, type='monster'}))<br />
end<br />
return table.concat(monsterList, '<br/>')<br />
end<br />
<br />
function p._getDungeonMonsterList(area)<br />
local monsterList = {}<br />
local lastMonster = nil<br />
local lastID = -2<br />
local count = 0<br />
-- Special handing for Impending Darkness event<br />
-- TODO needs to be revised once there is a better understanding of how the event works<br />
--if area.isEvent ~= nil and area.isEvent then<br />
-- for i, eventAreaID in ipairs(Areas.eventData.slayerAreas) do<br />
-- local eventArea = Areas.getAreaByID('slayer', eventAreaID)<br />
-- table.insert(monsterList, '5-8 ' .. Icons.Icon({eventArea.name, type='combatArea'}) .. ' Monsters')<br />
-- end<br />
-- table.insert(monsterList, '4 ' .. Icons.Icon({'Bane', type='monster'}))<br />
--end<br />
for i, monsterID in Shared.skpairs(area.monsters) do<br />
if monsterID ~= lastID then<br />
local monster = nil <br />
if monsterID ~= -1 then monster = p.getMonsterByID(monsterID) end<br />
if lastID ~= -2 then<br />
if lastID == -1 then<br />
--Special handling for Afflicted Monsters<br />
table.insert(monsterList, Icons.Icon({'Affliction', 'Afflicted Monster', img='Question', qty=count}))<br />
else<br />
local name = lastMonster.name<br />
table.insert(monsterList, Icons.Icon({name, type='monster', qty=count}))<br />
end<br />
end<br />
lastMonster = monster<br />
lastID = monsterID<br />
count = 1<br />
else<br />
count = count + 1<br />
end<br />
--Make sure the final monster in the dungeon gets counted<br />
if i == Shared.tableCount(area.monsters) then<br />
local name = lastMonster.name<br />
table.insert(monsterList, Icons.Icon({lastMonster.name, type='monster', qty=count}))<br />
end<br />
end<br />
return table.concat(monsterList, '<br/>')<br />
end<br />
<br />
function p.getAreaMonsterList(frame)<br />
local areaName = frame.args ~= nil and frame.args[1] or frame<br />
local area = Areas.getArea(areaName)<br />
if area == nil then<br />
return "ERROR: Could not find an area named "..areaName..'[[Category:Pages with script errors]]'<br />
end<br />
<br />
if area.type == 'dungeon' then<br />
return p._getDungeonMonsterList(area)<br />
else<br />
return p._getAreaMonsterList(area)<br />
end<br />
end<br />
<br />
function p.getFoxyTable(frame)<br />
local result = 'Monster,Min GP,Max GP,Average GP'<br />
for i, monster in Shared.skpairs(MonsterData.Monsters) do<br />
if not p._isDungeonOnlyMonster(monster) then<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
local avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2<br />
result = result..'<br/>'..monster.name..','..monster.dropCoins[1]..','..(monster.dropCoins[2])..','..avgGp<br />
end<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p._getMonsterAverageGP(monster)<br />
local result = ''<br />
local totalGP = 0<br />
<br />
local bones = p._getMonsterBones(monster)<br />
if bones ~= nil then<br />
totalGP = totalGP + bones.sellsFor * (type(monster.boneQty) == 'number' and monster.boneQty or 1)<br />
end<br />
<br />
--Likewise, seeing the loot table is tied to the monster appearing outside of dungeons<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100<br />
local lootValue = 0<br />
<br />
local avgGp = 0<br />
<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2<br />
end<br />
<br />
totalGP = totalGP + avgGp<br />
<br />
local multiDrop = Shared.tableCount(monster.lootTable) > 1<br />
local totalWt = 0<br />
for i, row in pairs(monster.lootTable) do<br />
totalWt = totalWt + row[2]<br />
end<br />
<br />
for i, row in Shared.skpairs(monster.lootTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
local maxQty = row[3]<br />
<br />
local itemPrice = thisItem.sellsFor ~= nil and thisItem.sellsFor or 0<br />
<br />
--Getting the drop chance<br />
local dropChance = (row[2] / totalWt * lootChance)<br />
<br />
--Adding to the average loot value based on price & dropchance<br />
lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((1 + maxQty) / 2))<br />
end<br />
<br />
totalGP = totalGP + lootValue<br />
end<br />
<br />
return Shared.round(totalGP, 2, 2)<br />
end<br />
<br />
function p.getMonsterAverageGP(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterAverageGP(monster)<br />
end<br />
<br />
function p.getMonsterEVTable(frame)<br />
local result = '{| class="wikitable sortable"'<br />
result = result..'\r\n!Monster!!Combat Level!!Average GP'<br />
for i, monsterTemp in Shared.skpairs(MonsterData.Monsters) do<br />
local monster = Shared.clone(monsterTemp)<br />
monster.id = i - 1<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local monsterGP = p._getMonsterAverageGP(monster)<br />
local combatLevel = p._getMonsterCombatLevel(monster, 'Combat Level')<br />
result = result..'\r\n|-\r\n|'..Icons.Icon({monster.name, type='monster', noicon=true})..'||'..combatLevel..'||'..monsterGP<br />
end<br />
end<br />
result = result..'\r\n|}'<br />
return result<br />
end<br />
<br />
function p.getSlayerTierMonsterTable(frame)<br />
-- Input validation<br />
local tier = frame.args ~= nil and frame.args[1] or frame<br />
local slayerTier = nil<br />
<br />
if tier == nil then<br />
return "ERROR: No tier specified[[Category:Pages with script errors]]"<br />
end<br />
<br />
if tonumber(tier) ~= nil then<br />
slayerTier = Constants.getSlayerTierByID(tonumber(tier))<br />
else<br />
slayerTier = Constants.getSlayerTier(tier)<br />
end<br />
<br />
if slayerTier == nil then<br />
return "ERROR: Invalid slayer tier[[Category:Pages with script errors]]"<br />
end<br />
<br />
-- Obtain required tier details<br />
local minLevel, maxLevel = slayerTier.minLevel, slayerTier.maxLevel<br />
<br />
-- Build list of monster IDs<br />
-- Right now hiddenMonsterIDs is empty<br />
local hiddenMonsterIDs = {}<br />
local monsterIDs = {}<br />
for i, monster in Shared.skpairs(MonsterData.Monsters) do<br />
if monster.canSlayer and not Shared.contains(hiddenMonsterIDs, i - 1) then<br />
local cmbLevel = p._getMonsterCombatLevel(monster)<br />
if cmbLevel >= minLevel and (maxLevel == nil or cmbLevel <= maxLevel) then<br />
table.insert(monsterIDs, i - 1)<br />
end<br />
end<br />
end<br />
<br />
if Shared.tableCount(monsterIDs) == 0 then<br />
-- Somehow no monsters are in the tier, return nothing<br />
return ''<br />
else<br />
return p._getMonsterTable(monsterIDs, true)<br />
end<br />
end<br />
<br />
function p.getFullMonsterTable(frame)<br />
local monsterIDs = {}<br />
for i = 0, Shared.tableCount(MonsterData.Monsters) - 1, 1 do<br />
table.insert(monsterIDs, i)<br />
end<br />
<br />
return p._getMonsterTable(monsterIDs, false)<br />
end<br />
<br />
function p._getMonsterTable(monsterIDs, excludeDungeons)<br />
--Making a single function for getting a table of monsters given a list of IDs.<br />
local hideDungeons = excludeDungeons ~= nil and excludeDungeons or false<br />
local tableParts = {}<br />
table.insert(tableParts, '{| class="wikitable sortable stickyHeader"')<br />
-- First header row<br />
table.insert(tableParts, '\r\n|- class="headerRow-0"\r\n! colspan="5" | !! colspan="4" |Offensive Stats !! colspan="3" |Evasion Rating !! colspan="4" |')<br />
-- Second header row<br />
table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n!Monster !!Name !!ID !!Combat Level ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Hitpoints', type='skill'}))<br />
table.insert(tableParts, '!!Attack Speed (s) !!colspan="2"|Max Hit !!Accuracy ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Defence', type='skill', notext=true}))<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Ranged', type='skill', notext=true}))<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Magic', type='skill', notext=true}))<br />
table.insert(tableParts, '!!' .. Icons.Icon({'Coins', notext=true, nolink=true}) .. ' Coins !!Bones !!Locations')<br />
<br />
-- Generate row per monster<br />
for i, monsterID in Shared.skpairs(monsterIDs) do<br />
local monster = p.getMonsterByID(monsterID)<br />
local cmbLevel = p._getMonsterCombatLevel(monster)<br />
local atkSpeed = p._getMonsterAttackSpeed(monster)<br />
local maxHit = p._getMonsterMaxHit(monster)<br />
local accR = p._getMonsterAR(monster)<br />
local evaR = {p._getMonsterER(monster, "Melee"), p._getMonsterER(monster, "Ranged"), p._getMonsterER(monster, "Magic")}<br />
<br />
local gpRange = {0, 0}<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
gpRange = {monster.dropCoins[1], monster.dropCoins[2]}<br />
end<br />
local gpTxt = nil<br />
if gpRange[1] >= gpRange[2] then<br />
gpTxt = Shared.formatnum(gpRange[1])<br />
else<br />
gpTxt = Shared.formatnum(gpRange[1]) .. ' - ' .. Shared.formatnum(gpRange[2])<br />
end<br />
local bones = p._getMonsterBones(monster)<br />
local boneTxt = (bones ~= nil and Icons.Icon({bones.name, type='item', notext=true})) or 'None'<br />
<br />
table.insert(tableParts, '\r\n|-\r\n|style="text-align: center;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:left" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:right" |' .. monsterID)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. cmbLevel .. '" |' .. Shared.formatnum(cmbLevel))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. p._getMonsterHP(monster) .. '" |' .. Shared.formatnum(p._getMonsterHP(monster)))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. atkSpeed .. '" |' .. Shared.round(atkSpeed, 1, 1))<br />
table.insert(tableParts, '\r\n|style="text-align:center;border-right:hidden" |' .. p._getMonsterStyleIcon({monster, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. maxHit .. '" |' .. Shared.formatnum(maxHit))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. accR .. '" |' .. Shared.formatnum(accR))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[1] .. '" |' .. Shared.formatnum(evaR[1]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[2] .. '" |' .. Shared.formatnum(evaR[2]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[3] .. '" |' .. Shared.formatnum(evaR[3]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:center" |' .. boneTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))<br />
end<br />
<br />
table.insert(tableParts, '\r\n|}')<br />
return table.concat(tableParts)<br />
end<br />
<br />
function p.getMattMonsterTable(frame)<br />
--Making a single function for getting a table of monsters given a list of IDs.<br />
local tableParts = {}<br />
table.insert(tableParts, '{| class="wikitable sortable stickyHeader"')<br />
-- Second header row<br />
table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n!Monster !!Name !!ID !!Combat Level ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Hitpoints', type='skill'}))<br />
table.insert(tableParts, '!!' .. Icons.Icon({'Coins', notext=true, nolink=true}) .. ' Coins !!Avg. Kill Value!!Locations')<br />
<br />
-- Generate row per monster<br />
for i, monster in Shared.skpairs(MonsterData.Monsters) do<br />
local cmbLevel = p._getMonsterCombatLevel(monster)<br />
<br />
local gpRange = {0, 0}<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
gpRange = {monster.dropCoins[1], monster.dropCoins[2]}<br />
end<br />
local gpTxt = nil<br />
if gpRange[1] >= gpRange[2] then<br />
gpTxt = Shared.formatnum(gpRange[1])<br />
else<br />
gpTxt = Shared.formatnum(gpRange[1]) .. ' - ' .. Shared.formatnum(gpRange[2])<br />
end<br />
<br />
local lootVal = p._getMonsterLootValue(monster)<br />
local lootTxt = '0'<br />
if lootVal ~= 0 then<br />
lootTxt = Shared.formatnum(Shared.round(lootVal, 2, 2))<br />
end<br />
<br />
<br />
table.insert(tableParts, '\r\n|-\r\n|style="text-align: center;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:left" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:right" |' .. monster.id)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. cmbLevel .. '" |' .. Shared.formatnum(cmbLevel))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. p._getMonsterHP(monster) .. '" |' .. Shared.formatnum(p._getMonsterHP(monster)))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. lootVal .. '" |' .. lootTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))<br />
end<br />
<br />
table.insert(tableParts, '\r\n|}')<br />
return table.concat(tableParts)<br />
end<br />
<br />
function p.getMattMonsterTableV2(frame)<br />
--Making a single function for getting a table of monsters given a list of IDs.<br />
local tableParts = {}<br />
table.insert(tableParts, '{| class="wikitable sortable stickyHeader"')<br />
-- Second header row<br />
table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n!Monster !!Name !!Combat Level ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Hitpoints', type='skill'}))<br />
table.insert(tableParts, '!!Attack Speed (s) !!colspan="2"|Max Hit !!Accuracy ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Defence', type='skill', notext=true}))<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Ranged', type='skill', notext=true}))<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Magic', type='skill', notext=true}))<br />
table.insert(tableParts, '!!' .. Icons.Icon({'Coins', notext=true, nolink=true}) .. ' Coins !!Avg. Kill Value !!Bones')<br />
<br />
-- Generate row per monster<br />
for i, monster in Shared.skpairs(MonsterData.Monsters) do<br />
local cmbLevel = p._getMonsterCombatLevel(monster)<br />
<br />
local gpRange = {0, 0}<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
gpRange = {monster.dropCoins[1], monster.dropCoins[2]}<br />
end<br />
local gpTxt = nil<br />
if gpRange[1] >= gpRange[2] then<br />
gpTxt = Shared.formatnum(gpRange[1])<br />
else<br />
gpTxt = Shared.formatnum(gpRange[1]) .. ' - ' .. Shared.formatnum(gpRange[2])<br />
end<br />
<br />
local lootVal = p._getMonsterLootValue(monster)<br />
local lootTxt = '0'<br />
if lootVal ~= 0 then<br />
lootTxt = Shared.formatnum(Shared.round(lootVal, 2, 2))<br />
end<br />
<br />
local atkSpeed = p._getMonsterAttackSpeed(monster)<br />
local maxHit = p._getMonsterMaxHit(monster)<br />
local accR = p._getMonsterAR(monster)<br />
local evaR = {p._getMonsterER(monster, "Melee"), p._getMonsterER(monster, "Ranged"), p._getMonsterER(monster, "Magic")}<br />
<br />
<br />
table.insert(tableParts, '\r\n|-\r\n|style="text-align: center;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:left" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))<br />
-- table.insert(tableParts, '\r\n|style="text-align:right" |' .. monster.id)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. cmbLevel .. '" |' .. Shared.formatnum(cmbLevel))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. p._getMonsterHP(monster) .. '" |' .. Shared.formatnum(p._getMonsterHP(monster)))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. atkSpeed .. '" |' .. Shared.round(atkSpeed, 1, 1))<br />
table.insert(tableParts, '\r\n|style="text-align:center;border-right:hidden" |' .. p._getMonsterStyleIcon({monster, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. maxHit .. '" |' .. Shared.formatnum(maxHit))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. accR .. '" |' .. Shared.formatnum(accR))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[1] .. '" |' .. Shared.formatnum(evaR[1]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[2] .. '" |' .. Shared.formatnum(evaR[2]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[3] .. '" |' .. Shared.formatnum(evaR[3]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. lootVal .. '" |' .. lootTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:center" |' .. boneTxt)<br />
-- table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))<br />
end<br />
<br />
table.insert(tableParts, '\r\n|}')<br />
return table.concat(tableParts)<br />
end<br />
<br />
function p.getSpecialAttackTable(frame)<br />
local spAttTable = {}<br />
<br />
for i, monster in ipairs(MonsterData.Monsters) do<br />
if monster.specialAttacks ~= nil and Shared.tableCount(monster.specialAttacks) > 0 then<br />
local overrideChance = (monster.overrideSpecialChances ~= nil and Shared.tableCount(monster.overrideSpecialChances) > 0)<br />
for j, spAtt in ipairs(monster.specialAttacks) do<br />
local attChance = (overrideChance and monster.overrideSpecialChances[j] or spAtt.defaultChance)<br />
if spAttTable[spAtt.id] == nil then<br />
spAttTable[spAtt.id] = { ['defn'] = spAtt, ['icons'] = {} }<br />
end<br />
if spAttTable[spAtt.id]['icons'][attChance] == nil then<br />
spAttTable[spAtt.id]['icons'][attChance] = {}<br />
end<br />
table.insert(spAttTable[spAtt.id]['icons'][attChance], Icons.Icon({ monster.name, type = 'monster' }))<br />
end<br />
end<br />
end<br />
<br />
local resultPart = {}<br />
table.insert(resultPart, '{|class="wikitable sortable stickyHeader"')<br />
table.insert(resultPart, '\r\n|- class="headerRow-0"')<br />
table.insert(resultPart, '\r\n!Name!!style="min-width:225px"|Monsters!!Chance!!Effect')<br />
<br />
for i, spAttData in Shared.skpairs(spAttTable) do<br />
local spAtt = spAttData.defn<br />
local firstRow = true<br />
local rowsSpanned = Shared.tableCount(spAttData.icons)<br />
local rowSuffix = ''<br />
if rowsSpanned > 1 then<br />
rowSuffix = '|rowspan="' .. rowsSpanned .. '"'<br />
end<br />
for chance, iconList in Shared.skpairs(spAttData.icons) do<br />
table.insert(resultPart, '\r\n|-')<br />
if firstRow then<br />
table.insert(resultPart, '\r\n' .. rowSuffix .. '| ' .. spAtt.name)<br />
end<br />
table.insert(resultPart, '\r\n|data-sort-value="' .. spAtt.name .. '"| ' .. table.concat(iconList, '<br/>'))<br />
table.insert(resultPart, '\r\n|data-sort-value="' .. chance .. '"| ' .. Shared.round(chance, 2, 0) .. '%')<br />
if firstRow then<br />
table.insert(resultPart, '\r\n' .. rowSuffix .. '| ' .. spAtt.description)<br />
firstRow = false<br />
end<br />
end<br />
end<br />
table.insert(resultPart, '\r\n|}')<br />
<br />
return table.concat(resultPart)<br />
end<br />
<br />
return p</div>
Roko
https://wiki.melvoridle.com/index.php?title=Module:Monsters&diff=51089
Module:Monsters
2022-02-19T13:28:16Z
<p>Roko: </p>
<hr />
<div>local p = {}<br />
<br />
local MonsterData = mw.loadData('Module:Monsters/data')<br />
<br />
local Constants = require('Module:Constants')<br />
local Areas = require('Module:CombatAreas')<br />
local Magic = require('Module:Magic')<br />
local Shared = require('Module:Shared')<br />
local Icons = require('Module:Icons')<br />
local Items = require('Module:Items')<br />
<br />
function p.getMonster(name)<br />
local result = nil<br />
if name == 'Spider (lv. 51)' or name == 'Spider' then<br />
return p.getMonsterByID(50)<br />
elseif name == 'Spider (lv. 52)' or name == 'Spider2' then<br />
return p.getMonsterByID(51)<br />
end<br />
<br />
for i, monster in pairs(MonsterData.Monsters) do<br />
if monster.name == name then<br />
result = Shared.clone(monster)<br />
--Make sure every monster has an ID, and account for the 1-based indexing of Lua<br />
result.id = i - 1<br />
break<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.getMonsterByID(ID)<br />
local result = Shared.clone(MonsterData.Monsters[ID + 1])<br />
if result ~= nil then<br />
result.id = ID<br />
return result<br />
else<br />
return nil<br />
end<br />
end<br />
<br />
function p.getPassive(name)<br />
local result = nil<br />
<br />
for i, passive in pairs(MonsterData.Passives) do<br />
if passive.name == name then<br />
result = Shared.clone(passive)<br />
--Make sure every passive has an ID, and account for the 1-based indexing of Lua<br />
result.id = i - 1<br />
break<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.getPassiveByID(ID)<br />
return MonsterData.Passives[ID + 1]<br />
end<br />
<br />
-- Given a list of monster IDs, calls statFunc with each monster and returns<br />
-- the lowest & highest values<br />
function p.getLowHighStat(idList, statFunc)<br />
local lowVal, highVal = nil, nil<br />
for i, monID in ipairs(idList) do<br />
local monster = p.getMonsterByID(monID)<br />
local statVal = statFunc(monster)<br />
if lowVal == nil or statVal < lowVal then lowVal = statVal end<br />
if highVal == nil or statVal > highVal then highVal = statVal end<br />
end<br />
return lowVal, highVal<br />
end<br />
<br />
function p._getMonsterStat(monster, statName)<br />
if statName == 'HP' then<br />
return p._getMonsterHP(monster)<br />
elseif statName == 'maxHit' then<br />
return p._getMonsterMaxHit(monster)<br />
elseif statName == 'accuracyRating' then<br />
return p._getMonsterAR(monster)<br />
elseif statName == 'meleeEvasionRating' then<br />
return p._getMonsterER(monster, 'Melee')<br />
elseif statName == 'rangedEvasionRating' then<br />
return p._getMonsterER(monster, 'Ranged')<br />
elseif statName == 'magicEvasionRating' then<br />
return p._getMonsterER(monster, 'Magic')<br />
elseif statName == 'damageReduction' then<br />
return p.getEquipmentStat(monster, 'damageReduction')<br />
end<br />
<br />
return monster[statName]<br />
end<br />
<br />
function p.getMonsterStat(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame[1]<br />
local StatName = frame.args ~= nil and frame.args[2] or frame[2]<br />
local monster = p.getMonster(MonsterName)<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterStat(monster, StatName)<br />
end<br />
<br />
function p._getMonsterStyleIcon(frame)<br />
local args = frame.args ~= nil and frame.args or frame<br />
local monster = args[1]<br />
local notext = args.notext<br />
local nolink = args.nolink<br />
<br />
local iconText = ''<br />
if monster.attackType == 'melee' then<br />
iconText = Icons.Icon({'Melee', notext=notext, nolink=nolink})<br />
elseif monster.attackType == 'ranged' then<br />
iconText = Icons.Icon({'Ranged', type='skill', notext=notext, nolink=nolink})<br />
elseif monster.attackType == 'magic' then<br />
iconText = Icons.Icon({'Magic', type='skill', notext=notext, nolink=nolink})<br />
elseif monster.attackType == 'random' then<br />
iconText = Icons.Icon({'Bane', notext=notext, nolink=nolink, img='Question'})<br />
end<br />
<br />
return iconText<br />
end<br />
<br />
function p.getMonsterStyleIcon(frame)<br />
local args = frame.args ~= nil and frame.args or frame<br />
local MonsterName = args[1]<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
args[1] = monster<br />
return p._getMonsterStyleIcon(args)<br />
end<br />
<br />
function p._getMonsterHP(monster)<br />
return 10 * p._getMonsterLevel(monster, 'Hitpoints')<br />
end<br />
<br />
function p.getMonsterEffectiveHP(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
if monster ~= nil then<br />
return math.floor((p._getMonsterHP(monster)/(1 - p._getMonsterStat(monster, 'damageReduction')/100)) + 0.5)<br />
else<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
end<br />
<br />
function p.getMonsterHP(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
if monster ~= nil then<br />
return p._getMonsterHP(monster)<br />
else<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
end<br />
<br />
function p._getMonsterLevel(monster, skillName)<br />
local result = 0<br />
if monster.levels[skillName] ~= nil then<br />
result = monster.levels[skillName]<br />
end<br />
return result<br />
end<br />
<br />
function p.getMonsterLevel(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame[1]<br />
local SkillName = frame.args ~= nil and frame.args[2] or frame[2]<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterLevel(monster, SkillName)<br />
end<br />
<br />
function p.getEquipmentStat(monster, statName)<br />
local result = 0<br />
for i, stat in Shared.skpairs(monster.equipmentStats) do<br />
if stat.key == statName then<br />
result = stat.value<br />
break<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.calculateStandardStat(effectiveLevel, bonus)<br />
--Based on calculateStandardStat in Characters.js<br />
return (effectiveLevel + 9) * (bonus + 64)<br />
end<br />
<br />
function p.calculateStandardMaxHit(baseLevel, strengthBonus)<br />
--Based on calculateStandardMaxHit in Characters.js<br />
local effectiveLevel = baseLevel + 9<br />
return math.floor(10 * (1.3 + effectiveLevel / 10 + strengthBonus / 80 + effectiveLevel * strengthBonus / 640))<br />
end<br />
<br />
function p._getMonsterAttackSpeed(monster)<br />
return p.getEquipmentStat(monster, 'attackSpeed') / 1000<br />
end<br />
<br />
function p.getMonsterAttackSpeed(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
if monster ~= nil then<br />
return p._getMonsterAttackSpeed(monster)<br />
else<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
end<br />
<br />
function p._getMonsterCombatLevel(monster)<br />
local base = 0.25 * (p._getMonsterLevel(monster, 'Defence') + p._getMonsterLevel(monster, 'Hitpoints'))<br />
local melee = 0.325 * (p._getMonsterLevel(monster, 'Attack') + p._getMonsterLevel(monster, 'Strength'))<br />
local range = 0.325 * (1.5 * p._getMonsterLevel(monster, 'Ranged'))<br />
local magic = 0.325 * (1.5 * p._getMonsterLevel(monster, 'Magic'))<br />
return math.floor(base + math.max(melee, range, magic))<br />
end<br />
<br />
function p.getMonsterCombatLevel(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterCombatLevel(monster)<br />
end<br />
<br />
function p._getMonsterAR(monster)<br />
local baseLevel = 0<br />
local bonus = 0<br />
if monster.attackType == 'melee' then<br />
baseLevel = p._getMonsterLevel(monster, 'Attack')<br />
bonus = p.getEquipmentStat(monster, 'stabAttackBonus')<br />
elseif monster.attackType == 'ranged' then<br />
baseLevel = p._getMonsterLevel(monster, 'Ranged')<br />
bonus = p.getEquipmentStat(monster, 'rangedAttackBonus')<br />
elseif monster.attackType == 'magic' then<br />
baseLevel = p._getMonsterLevel(monster, 'Magic')<br />
bonus = p.getEquipmentStat(monster, 'magicAttackBonus')<br />
elseif monster.attackType == 'random' then<br />
--Bane has the same AR with every attack type so being lazy and just showing the one.<br />
baseLevel = p._getMonsterLevel(monster, 'Attack')<br />
bonus = p.getEquipmentStat(monster, 'stabAttackBonus')<br />
else<br />
return "ERROR: This monster has an invalid attack type somehow[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p.calculateStandardStat(baseLevel, bonus)<br />
end<br />
<br />
function p.getMonsterAR(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterAR(monster)<br />
end<br />
<br />
function p._getMonsterER(monster, style)<br />
local baseLevel= 0<br />
local bonus = 0<br />
<br />
if style == "Melee" then<br />
baseLevel = p._getMonsterLevel(monster, 'Defence')<br />
bonus = p.getEquipmentStat(monster, 'meleeDefenceBonus')<br />
elseif style == "Ranged" then<br />
baseLevel = p._getMonsterLevel(monster, 'Defence')<br />
bonus = p.getEquipmentStat(monster, 'rangedDefenceBonus')<br />
elseif style == "Magic" then<br />
baseLevel = math.floor(p._getMonsterLevel(monster, 'Magic') * 0.7 + p._getMonsterLevel(monster, 'Defence') * 0.3)<br />
bonus = p.getEquipmentStat(monster, 'magicDefenceBonus')<br />
else<br />
return "ERROR: Must choose Melee, Ranged, or Magic[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p.calculateStandardStat(baseLevel, bonus)<br />
end<br />
<br />
function p.getMonsterER(frame)<br />
local args = frame.args ~= nil and frame.args or frame<br />
local MonsterName = args[1]<br />
local style = args[2]<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterER(monster, style)<br />
end<br />
<br />
-- Determines if the monster is capable of dropping bones, and returns the bones<br />
-- item if so, or nil otherwise<br />
function p._getMonsterBones(monster)<br />
if monster.bones ~= nil and monster.bones >= 0 then<br />
local boneItem = Items.getItemByID(monster.bones)<br />
if boneItem.prayerPoints == nil then<br />
-- Assume bones without prayer points are shards (from God dungeons),<br />
-- and drop unconditionally<br />
return boneItem<br />
elseif not monster.isBoss and not p._isDungeonOnlyMonster(monster) then<br />
-- Otherwise, bones drop when the monster isn't dungeon exclusive<br />
return boneItem<br />
end<br />
end<br />
end<br />
<br />
function p._isDungeonOnlyMonster(monster)<br />
local areaList = Areas.getMonsterAreas(monster.id)<br />
local inDungeon = false<br />
<br />
for i, area in ipairs(areaList) do<br />
if area.type == 'dungeon' then<br />
inDungeon = true<br />
else<br />
return false<br />
end<br />
end<br />
return inDungeon<br />
end<br />
<br />
function p.isDungeonOnlyMonster(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with name "..monsterName.." found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._isDungeonOnlyMonster(monster)<br />
end<br />
<br />
function p._getMonsterAreas(monster, excludeDungeons)<br />
local resultPart = {}<br />
local hideDungeons = excludeDungeons ~= nil and excludeDungeons or false<br />
local areaList = Areas.getMonsterAreas(monster.id)<br />
for i, area in ipairs(areaList) do<br />
if area.type ~= 'dungeon' or not hideDungeons then<br />
table.insert(resultPart, Icons.Icon({area.name, type = area.type}))<br />
end<br />
end<br />
return table.concat(resultPart, '<br/>')<br />
end<br />
<br />
function p.getMonsterAreas(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local hideDungeons = frame.args ~= nil and frame.args[2] or nil<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with name "..monsterName.." found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterAreas(monster, hideDungeons)<br />
end<br />
<br />
function p.getSpecAttackMaxHit(specAttack, normalMaxHit)<br />
local result = 0<br />
for i, dmg in pairs(specAttack.damage) do<br />
if dmg.maxRoll == 'Fixed' then<br />
result = dmg.maxPercent * 10<br />
elseif dmg.maxRoll == 'MaxHit' then<br />
if dmg.character == 'Target' then<br />
--Confusion applied damage based on the player's max hit. Gonna just ignore that one<br />
result = 0<br />
else<br />
result = dmg.maxPercent * normalMaxHit * 0.01<br />
end<br />
elseif Shared.contains({'Bleeding', 'Poisoned'}, dmg.maxRoll) then<br />
-- TODO: This is limited in that there is no verification that bleed/poison<br />
-- can be applied to the target, it is assumed that it can and so this applies<br />
result = result + dmg.maxPercent * 10<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.canSpecAttackApplyEffect(specAttack, effectType)<br />
local result = false<br />
for i, effect in pairs(specAttack.prehitEffects) do<br />
if effect.type == effectType then<br />
result = true<br />
break<br />
end<br />
end<br />
<br />
for i, effect in pairs(specAttack.onhitEffects) do<br />
if effect.type == effectType then<br />
result = true<br />
break<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p._getMonsterMaxHit(monster, doStuns)<br />
-- 2021-06-11 Adjusted for v0.20 stun/sleep changes, where damage multiplier now applies<br />
-- to all enemy attacks if stun/sleep is present on at least one special attack<br />
if doStuns == nil then<br />
doStuns = true<br />
elseif type(doStuns) == 'string' then<br />
doStuns = string.upper(doStuns) == 'TRUE'<br />
end<br />
<br />
local normalChance = 100<br />
local specialMaxHit = 0<br />
local normalMaxHit = p._getMonsterBaseMaxHit(monster)<br />
local hasActiveBuffSpec = false<br />
local damageMultiplier = 1<br />
if monster.specialAttacks[1] ~= nil then<br />
local canStun, canSleep = false, false<br />
for i, specAttack in pairs(monster.specialAttacks) do<br />
if monster.overrideSpecialChances ~= nil then<br />
normalChance = normalChance - monster.overrideSpecialChances[i]<br />
else<br />
normalChance = normalChance - specAttack.defaultChance<br />
end<br />
local thisMax = p.getSpecAttackMaxHit(specAttack, normalMaxHit)<br />
if not canStun and p.canSpecAttackApplyEffect(specAttack, 'Stun') then canStun = true end<br />
if not canSleep and p.canSpecAttackApplyEffect(specAttack, 'Sleep') then canSleep = true end<br />
<br />
if thisMax > specialMaxHit then specialMaxHit = thisMax end<br />
if Shared.contains(string.upper(specAttack.description), 'NORMAL ATTACK INSTEAD') then <br />
hasActiveBuffSpec = true <br />
end<br />
end<br />
<br />
if canSleep and doStuns then damageMultiplier = damageMultiplier * 1.2 end<br />
if canStun and doStuns then damageMultiplier = damageMultiplier * 1.3 end<br />
end<br />
--Ensure that if the monster never does a normal attack, the normal max hit is irrelevant<br />
if normalChance == 0 and not hasActiveBuffSpec then normalMaxHit = 0 end<br />
return math.floor(math.max(specialMaxHit, normalMaxHit) * damageMultiplier)<br />
end<br />
<br />
function p.getMonsterMaxHit(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local doStuns = frame.args ~= nil and frame.args[2] or true<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterMaxHit(monster, doStuns)<br />
end<br />
<br />
function p._getMonsterBaseMaxHit(monster)<br />
--8/27/21 - Now references p.calculateStandardMaxHit for Melee & Ranged<br />
local result = 0<br />
local baseLevel = 0<br />
local bonus = 0<br />
if monster.attackType == 'melee' then<br />
baseLevel = p._getMonsterLevel(monster, 'Strength')<br />
bonus = p.getEquipmentStat(monster, 'meleeStrengthBonus')<br />
result = p.calculateStandardMaxHit(baseLevel, bonus)<br />
elseif monster.attackType == 'ranged' then<br />
baseLevel = p._getMonsterLevel(monster, 'Ranged')<br />
bonus = p.getEquipmentStat(monster, 'rangedStrengthBonus')<br />
result = p.calculateStandardMaxHit(baseLevel, bonus)<br />
elseif monster.attackType == 'magic' then<br />
local mSpell = nil<br />
if monster.selectedSpell ~= nil then mSpell = Magic.getSpellByID('Spells', monster.selectedSpell) end<br />
<br />
bonus = p.getEquipmentStat(monster, 'magicDamageBonus')<br />
baseLevel = p._getMonsterLevel(monster, 'Magic')<br />
<br />
result = math.floor(10 * mSpell.maxHit * (1 + bonus / 100) * (1 + (baseLevel + 1) / 200))<br />
elseif monster.attackType == 'random' then<br />
local hitArray = {}<br />
local iconText = Icons.Icon({'Melee', notext=true})<br />
baseLevel = p._getMonsterLevel(monster, 'Strength')<br />
bonus = p.getEquipmentStat(monster, 'meleeStrengthBonus')<br />
table.insert(hitArray, p.calculateStandardMaxHit(baseLevel, bonus))<br />
<br />
iconText = Icons.Icon({'Ranged', type='skill', notext=true})<br />
baseLevel = p._getMonsterLevel(monster, 'Ranged')<br />
bonus = p.getEquipmentStat(monster, 'rangedStrengthBonus')<br />
table.insert(hitArray, p.calculateStandardMaxHit(baseLevel, bonus))<br />
<br />
iconText = Icons.Icon({'Magic', type='skill', notext=true})<br />
local mSpell = nil<br />
if monster.selectedSpell ~= nil then mSpell = Magic.getSpellByID('Spells', monster.selectedSpell) end<br />
bonus = p.getEquipmentStat(monster, 'magicDamageBonus')<br />
baseLevel = p._getMonsterLevel(monster, 'Magic')<br />
local magicDmg = math.floor(10 * mSpell.maxHit * (1 + bonus / 100) * (1 + (baseLevel + 1) / 200))<br />
table.insert(hitArray, magicDmg)<br />
<br />
local max = 0<br />
for i, val in pairs(hitArray) do<br />
if val > max then max = val end<br />
end<br />
result = max<br />
else<br />
return "ERROR: This monster has an invalid attack type somehow[[Category:Pages with script errors]]"<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getMonsterBaseMaxHit(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterBaseMaxHit(monster)<br />
end<br />
<br />
function p.getMonsterAttacks(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = ''<br />
local iconText = p._getMonsterStyleIcon({monster, notext=true})<br />
local typeText = ''<br />
if monster.attackType == 'melee' then<br />
typeText = 'Melee'<br />
elseif monster.attackType == 'ranged' then<br />
typeText = 'Ranged'<br />
elseif monster.attackType == 'magic' then<br />
typeText = 'Magic'<br />
elseif monster.attackType == 'random' then<br />
typeText = "Random"<br />
end<br />
<br />
local buffAttacks = {}<br />
local hasActiveBuffSpec = false<br />
<br />
local normalAttackChance = 100<br />
if monster.specialAttacks[1] ~= nil then<br />
for i, specAttack in pairs(monster.specialAttacks) do<br />
local attChance = 0<br />
if monster.overrideSpecialChances ~= nil then<br />
attChance = monster.overrideSpecialChances[i]<br />
else<br />
attChance = specAttack.defaultChance<br />
end<br />
normalAttackChance = normalAttackChance - attChance<br />
<br />
result = result..'\r\n* '..attChance..'% '..iconText..' '..specAttack.name..'\r\n** '..specAttack.description<br />
<br />
if Shared.contains(string.upper(specAttack.description), 'NORMAL ATTACK INSTEAD') then<br />
table.insert(buffAttacks, specAttack.name)<br />
hasActiveBuffSpec = true <br />
end<br />
end<br />
end<br />
if normalAttackChance == 100 then<br />
result = iconText..' 1 - '..p._getMonsterBaseMaxHit(monster)..' '..typeText..' Damage'<br />
elseif normalAttackChance > 0 then<br />
result = '* '..normalAttackChance..'% '..iconText..' 1 - '..p.getMonsterBaseMaxHit(frame)..' '..typeText..' Damage'..result<br />
elseif hasActiveBuffSpec then<br />
--If the monster normally has a 0% chance of doing a normal attack but some special attacks can't be repeated, include it<br />
--(With a note about when it does it)<br />
result = '* '..iconText..' 1 - '..p._getMonsterBaseMaxHit(monster)..' '..typeText..' Damage (Instead of repeating '..table.concat(buffAttacks, ' or ')..' while the effect is already active)'..result<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getMonsterPassives(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = ''<br />
if type(monster.passiveID) == 'table' and Shared.tableCount(monster.passiveID) > 0 then<br />
result = result .. '===Passives==='<br />
for i, passiveID in pairs(monster.passiveID) do<br />
local passive = p.getPassiveByID(passiveID)<br />
result = result .. '\r\n* ' .. passive.name .. '\r\n** ' .. passive.description<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.getMonsterCategories(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = '[[Category:Monsters]]'<br />
<br />
if monster.attackType == 'melee' then<br />
result = result..'[[Category:Melee Monsters]]'<br />
elseif monster.attackType == 'ranged' then<br />
result = result..'[[Category:Ranged Monsters]]'<br />
elseif monster.attackType == 'magic' then<br />
result = result..'[[Category:Magic Monsters]]'<br />
end<br />
<br />
if monster.specialAttacks[1] ~= nil then<br />
result = result..'[[Category:Monsters with Special Attacks]]'<br />
end<br />
<br />
if monster.isBoss then<br />
result = result..'[[Category:Bosses]]'<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getOtherMonsterBoxText(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = ''<br />
<br />
--Going through and finding out which damage bonuses will apply to this monster<br />
local monsterTypes = {}<br />
if monster.isBoss then table.insert(monsterTypes, 'Boss') end<br />
<br />
local areaList = Areas.getMonsterAreas(monster.id)<br />
local counts = {combat = 0, slayer = 0, dungeon = 0}<br />
for i, area in Shared.skpairs(areaList) do<br />
counts[area.type] = counts[area.type] + 1<br />
end<br />
<br />
if counts.combat > 0 then table.insert(monsterTypes, 'Combat Area') end<br />
if counts.slayer > 0 then table.insert(monsterTypes, 'Slayer Area') end<br />
if counts.dungeon > 0 then table.insert(monsterTypes, 'Dungeon') end<br />
<br />
result = result.."\r\n|-\r\n|'''Monster Types:''' "..table.concat(monsterTypes, ", ")<br />
<br />
local SlayerTier = 'N/A'<br />
if monster.canSlayer then<br />
SlayerTier = Constants.getSlayerTierNameByLevel(p._getMonsterCombatLevel(monster))<br />
end<br />
<br />
result = result.."\r\n|-\r\n|'''"..Icons.Icon({'Slayer', type='skill'}).." [[Slayer#Slayer Tier Monsters|Tier]]:''' "<br />
if monster.canSlayer then<br />
result = result.."[[Slayer#"..SlayerTier.."|"..SlayerTier.."]]"<br />
else<br />
result = result..SlayerTier<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getMonsterDrops(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = ''<br />
<br />
local bones = p._getMonsterBones(monster)<br />
local boneVal = 0<br />
--Show the bones only if either the monster shows up outside of dungeons _or_ the monster drops shards<br />
if bones ~= nil then<br />
local boneQty = (monster.boneQty ~= nil and monster.boneQty or 1)<br />
result = result.."'''Always Drops:'''"<br />
result = result..'\r\n{|class="wikitable" id="bonedrops"'<br />
result = result..'\r\n!Item !! Qty'<br />
result = result..'\r\n|-\r\n|'..Icons.Icon({bones.name, type='item'})<br />
result = result..'||'..boneQty..'\r\n'..'|}'<br />
boneVal = boneQty * bones.sellsFor<br />
end<br />
<br />
--Likewise, seeing the loot table is tied to the monster appearing outside of dungeons<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100<br />
local lootValue = 0<br />
<br />
result = result.."'''Loot:'''"<br />
local avgGp = 0<br />
<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2<br />
local gpTxt = Icons.GP(monster.dropCoins[1], monster.dropCoins[2])<br />
result = result.."\r\nIn addition to loot, the monster will also drop "..gpTxt..'.'<br />
end<br />
<br />
local multiDrop = Shared.tableCount(monster.lootTable) > 1<br />
local totalWt = 0<br />
for i, row in pairs(monster.lootTable) do<br />
totalWt = totalWt + row[2]<br />
end<br />
result = result..'\r\n{|class="wikitable sortable" id="itemdrops"'<br />
result = result..'\r\n!Item!!Qty'<br />
result = result..'!!Price!!colspan="2"|Chance'<br />
<br />
--Sort the loot table by weight in descending order<br />
table.sort(monster.lootTable, function(a, b) return a[2] > b[2] end)<br />
for i, row in Shared.skpairs(monster.lootTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
<br />
local maxQty = row[3]<br />
if thisItem ~= nil then<br />
result = result..'\r\n|-\r\n|'..Icons.Icon({thisItem.name, type='item'})<br />
else<br />
result = result..'\r\n|-\r\n|Unknown Item[[Category:Pages with script errors]]'<br />
end<br />
result = result..'||style="text-align:right" data-sort-value="'..maxQty..'"|'<br />
<br />
if maxQty > 1 then<br />
result = result.. '1 - '<br />
end<br />
result = result..Shared.formatnum(row[3])<br />
<br />
--Adding price columns<br />
local itemPrice = 0<br />
if thisItem == nil then<br />
result = result..'||data-sort-value="0"|???'<br />
else<br />
itemPrice = thisItem.sellsFor ~= nil and thisItem.sellsFor or 0<br />
if itemPrice == 0 or maxQty == 1 then<br />
result = result..'||'..Icons.GP(itemPrice)<br />
else<br />
result = result..'||'..Icons.GP(itemPrice, itemPrice * maxQty)<br />
end<br />
end<br />
<br />
--Getting the drop chance<br />
local dropChance = (row[2] / totalWt * lootChance)<br />
if dropChance < 100 then<br />
--Show fraction as long as it isn't going to be 1/1<br />
result = result..'||style="text-align:right" data-sort-value="'..row[2]..'"'<br />
result = result..'|'..Shared.fraction(row[2] * lootChance, totalWt * 100)<br />
result = result..'||'<br />
else<br />
result = result..'||colspan="2" data-sort-value="'..row[2]..'"'<br />
end<br />
-- If chance is less than 0.10% then show 2 significant figures, otherwise 2 decimal places<br />
local fmt = (dropChance < 0.10 and '%.2g') or '%.2f'<br />
result = result..'style="text-align:right"|'..string.format(fmt, dropChance)..'%'<br />
<br />
--Adding to the average loot value based on price & dropchance<br />
lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((1 + maxQty) / 2))<br />
end<br />
if multiDrop then<br />
result = result..'\r\n|-class="sortbottom" \r\n!colspan="3"|Total:'<br />
if lootChance < 100 then<br />
result = result..'\r\n|style="text-align:right"|'..Shared.fraction(lootChance, 100)..'||'<br />
else<br />
result = result..'\r\n|colspan="2" '<br />
end<br />
result = result..'style="text-align:right"|'..Shared.round(lootChance, 2, 2)..'%'<br />
end<br />
result = result..'\r\n|}'<br />
result = result..'\r\nThe loot dropped by the average kill is worth '..Icons.GP(Shared.round(lootValue, 2, 0)).." if sold."<br />
if avgGp > 0 then<br />
result = result.."<br/>Including GP"<br />
if boneVal > 0 then<br />
result = result..' and bones'<br />
end<br />
result = result..', the average kill is worth '..Icons.GP(Shared.round(avgGp + lootValue + boneVal, 2, 0))..'.'<br />
end<br />
end<br />
<br />
--If no other drops, make sure to at least say so.<br />
if result == '' then result = 'None' end<br />
return result<br />
end<br />
<br />
function p._getMonsterLootValue(monster)<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = 0<br />
local boneVal = 0<br />
<br />
local bones = p._getMonsterBones(monster)<br />
--Show the bones only if either the monster shows up outside of dungeons _or_ the monster drops shards<br />
if bones ~= nil then<br />
local boneQty = monster.boneQty ~= nil and monster.boneQty or 1<br />
boneVal = bones.sellsFor * boneQty<br />
result = result + boneVal<br />
end<br />
<br />
--Likewise, seeing the loot table is tied to the monster appearing outside of dungeons<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100<br />
local lootValue = 0<br />
<br />
local avgGp = 0<br />
<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2<br />
end<br />
<br />
local multiDrop = Shared.tableCount(monster.lootTable) > 1<br />
local totalWt = 0<br />
for i, row in pairs(monster.lootTable) do<br />
totalWt = totalWt + row[2]<br />
end<br />
<br />
for i, row in Shared.skpairs(monster.lootTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
<br />
local maxQty = row[3]<br />
<br />
--Adding price columns<br />
local itemPrice = 0<br />
if thisItem ~= nil then<br />
itemPrice = thisItem.sellsFor ~= nil and thisItem.sellsFor or 0<br />
end<br />
<br />
--Getting the drop chance<br />
local dropChance = (row[2] / totalWt * lootChance)<br />
--Adding to the average loot value based on price & dropchance<br />
lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((1 + maxQty) / 2))<br />
end<br />
if avgGp > 0 then<br />
result = result + avgGp + lootValue<br />
end<br />
end<br />
<br />
return result<br />
end<br />
<br />
-- Find drop chance of specified item from specified monster. <br />
-- Usage: |Monster Name|Item Name<br />
function p.getItemDropChance(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame[1]<br />
local ItemName = frame.args ~= nil and frame.args[2] or frame[2]<br />
<br />
local monster = p.getMonster(MonsterName)<br />
local item = Items.getItem(ItemName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
if item == nil then<br />
return "ERROR: No item with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100<br />
<br />
local totalWt = 0<br />
--for i, row in pairs(monster.lootTable) do<br />
--totalWt = totalWt + row[2]<br />
--end<br />
<br />
local dropChance = 0<br />
local dropWt = 0<br />
for i, row in Shared.skpairs(monster.lootTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
totalWt = totalWt + row[2]<br />
if item['id'] == thisItem['id'] then<br />
dropWt = row[2]<br />
end<br />
end<br />
dropChance = (dropWt / totalWt * lootChance)<br />
return Shared.round(dropChance, 2, 2)<br />
end<br />
end <br />
<br />
function p.getChestDrops(frame)<br />
local ChestName = frame.args ~= nil and frame.args[1] or frame<br />
local chest = Items.getItem(ChestName)<br />
<br />
if chest == nil then<br />
return "ERROR: No item named "..ChestName..' found[[Category:Pages with script errors]]'<br />
end<br />
<br />
local result = ''<br />
<br />
if chest.dropTable == nil then<br />
return "ERROR: "..ChestName.." does not have a drop table[[Category:Pages with script errors]]"<br />
else<br />
local lootChance = 100<br />
local lootValue = 0<br />
<br />
local multiDrop = Shared.tableCount(chest.dropTable) > 1<br />
local totalWt = 0<br />
for i, row in pairs(chest.dropTable) do<br />
totalWt = totalWt + row[2]<br />
end<br />
result = result..'\r\n{|class="wikitable sortable"'<br />
result = result..'\r\n!Item!!Qty'<br />
result = result..'!!colspan="2"|Chance!!Price'<br />
<br />
--Sort the loot table by weight in descending order<br />
for i, row in pairs(chest.dropTable) do<br />
if chest.dropQty ~= nil then<br />
table.insert(row, chest.dropQty[i])<br />
else<br />
table.insert(row, 1)<br />
end<br />
end<br />
table.sort(chest.dropTable, function(a, b) return a[2] > b[2] end)<br />
for i, row in Shared.skpairs(chest.dropTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
local qty = row[3]<br />
result = result..'\r\n|-\r\n|'..Icons.Icon({thisItem.name, type='item'})<br />
result = result..'||style="text-align:right" data-sort-value="'..qty..'"|'<br />
<br />
if qty > 1 then<br />
result = result.. '1 - '<br />
end<br />
result = result..Shared.formatnum(qty)<br />
<br />
local dropChance = (row[2] / totalWt) * 100<br />
result = result..'||style="text-align:right" data-sort-value="'..row[2]..'"'<br />
result = result..'|'..Shared.fraction(row[2], totalWt)<br />
<br />
result = result..'||style="text-align:right"|'..Shared.round(dropChance, 2, 2)..'%'<br />
<br />
result = result..'||style="text-align:left" data-sort-value="'..thisItem.sellsFor..'"'<br />
if qty > 1 then<br />
result = result..'|'..Icons.GP(thisItem.sellsFor, thisItem.sellsFor * qty)<br />
else<br />
result = result..'|'..Icons.GP(thisItem.sellsFor)<br />
end<br />
lootValue = lootValue + (dropChance * 0.01 * thisItem.sellsFor * ((1 + qty)/ 2))<br />
end<br />
result = result..'\r\n|}'<br />
result = result..'\r\nThe average value of the contents of one chest is '..Icons.GP(Shared.round(lootValue, 2, 0))..'.'<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getAreaMonsterTable(frame)<br />
local areaName = frame.args ~= nil and frame.args[1] or frame<br />
local area = Areas.getArea(areaName)<br />
if area == nil then<br />
return "ERROR: Could not find an area named "..areaName..'[[Category:Pages with script errors]]'<br />
end<br />
<br />
if area.type == 'dungeon' then<br />
return p.getDungeonMonsterTable(frame)<br />
end<br />
<br />
local tableTxt = '{| class="wikitable sortable"'<br />
tableTxt = tableTxt..'\r\n! Name !! Combat Level !! Hitpoints !! Max Hit !! [[Combat Triangle|Combat Style]]'<br />
for i, monsterID in pairs(area.monsters) do<br />
local monster = p.getMonsterByID(monsterID)<br />
tableTxt = tableTxt..'\r\n|-\r\n|'..Icons.Icon({monster.name, type='monster'})<br />
tableTxt = tableTxt..'||'..p._getMonsterCombatLevel(monster)<br />
tableTxt = tableTxt..'||'..Shared.formatnum(p._getMonsterHP(monster))<br />
tableTxt = tableTxt..'||'..Shared.formatnum(p._getMonsterMaxHit(monster))<br />
tableTxt = tableTxt..'||'..p._getMonsterStyleIcon({monster, nolink=true})<br />
end<br />
tableTxt = tableTxt..'\r\n|}'<br />
return tableTxt<br />
end<br />
<br />
function p.getDungeonMonsterTable(frame)<br />
local areaName = frame.args ~= nil and frame.args[1] or frame<br />
local area = Areas.getArea(areaName)<br />
if area == nil then<br />
return "ERROR: Could not find a dungeon named "..areaName..'[[Category:Pages with script errors]]'<br />
end<br />
<br />
--For Dungeons, go through and count how many of each monster are in the dungeon first<br />
local monsterCounts = {}<br />
for i, monsterID in pairs(area.monsters) do<br />
if monsterCounts[monsterID] == nil then<br />
monsterCounts[monsterID] = 1<br />
else<br />
monsterCounts[monsterID] = monsterCounts[monsterID] + 1<br />
end<br />
end<br />
<br />
local usedMonsters = {}<br />
<br />
-- Declare function for building table rows to avoid repeating code<br />
local buildRow = function(entityID, monsterCount, specialType)<br />
local monIcon, monLevel, monHP, monMaxHit, monStyle, monCount<br />
local monData = {}<br />
if specialType ~= nil and Shared.contains({'Afflicted', 'SlayerArea'}, specialType) then<br />
-- Special handling for Into the Mist<br />
if specialType == 'Afflicted' then<br />
local iconQ = Icons.Icon({'Into the Mist', notext=true, nolink=true, img='Question'})<br />
monIcon = Icons.Icon({'Into the Mist', 'Afflicted Monster', nolink=true, img='Question'})<br />
monLevel, monHP, monMaxHit, monStyle, monCount = iconQ, iconQ, iconQ, iconQ, monsterCount<br />
elseif specialType == 'SlayerArea' then<br />
-- entityID corresponds to a slayer area<br />
local area = Areas.getAreaByID('slayer', entityID)<br />
monIcon = Icons.Icon({area.name, type='combatArea'}) .. ' Monsters'<br />
monLevel = {p.getLowHighStat(area.monsters, function(monster) return p._getMonsterCombatLevel(monster) end)}<br />
monHP = {p.getLowHighStat(area.monsters, function(monster) return p._getMonsterHP(monster) end)}<br />
local lowMaxHit, highMaxHit = p.getLowHighStat(area.monsters, function(monster) return p._getMonsterMaxHit(monster) end)<br />
monMaxHit = highMaxHit<br />
monStyle = Icons.Icon({area.name, area.name, notext=true, nolink=true, img='Question'})<br />
monCount = monsterCount<br />
end<br />
else<br />
-- entityID corresponds to a monster<br />
local monster = p.getMonsterByID(entityID)<br />
monIcon = Icons.Icon({monster.name, type='monster'})<br />
monLevel = p._getMonsterCombatLevel(monster)<br />
monHP = p._getMonsterHP(monster)<br />
monMaxHit = p._getMonsterMaxHit(monster)<br />
monStyle = p._getMonsterStyleIcon({monster})<br />
monCount = monsterCount<br />
end<br />
local getValSort = function(val)<br />
if type(val) == 'table' then<br />
if type(val[1]) == 'number' and type(val[2]) == 'number' then<br />
return (val[1] + val[2]) / 2<br />
else<br />
return (type(val[1]) == 'number' and val[1]) or 0<br />
end<br />
else<br />
return (type(val) == 'number' and val) or 0<br />
end<br />
end<br />
local getValText = function(val)<br />
if type(val) == 'table' and Shared.tableCount(val) == 2 then<br />
if type(val[1]) == 'number' and type(val[2]) == 'number' then<br />
return Shared.formatnum(val[1]) .. ' - ' .. Shared.formatnum(val[2])<br />
else<br />
return val[1] .. ' - ' .. val[2]<br />
end<br />
elseif type(val) == 'number' then<br />
return Shared.formatnum(val)<br />
else<br />
return val<br />
end<br />
end<br />
<br />
local resultPart = {}<br />
table.insert(resultPart, '\r\n|-\r\n| ' .. monIcon)<br />
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monLevel) .. '"| ' .. getValText(monLevel))<br />
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monHP) .. '"| ' .. getValText(monHP))<br />
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monMaxHit) .. '"| ' .. getValText(monMaxHit))<br />
table.insert(resultPart, '\r\n| ' .. monStyle)<br />
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monCount) .. '"| ' .. getValText(monCount))<br />
return table.concat(resultPart)<br />
end<br />
<br />
local returnPart = {}<br />
table.insert(returnPart, '{| class="wikitable sortable"')<br />
table.insert(returnPart, '\r\n! Name !! Combat Level !! Hitpoints !! Max Hit !! [[Combat Triangle|Combat Style]] !! Count')<br />
-- Special handing for Impending Darkness event<br />
-- TODO needs to be revised once there is a better understanding of how the event works<br />
--if area.isEvent ~= nil and area.isEvent then<br />
-- for i, eventAreaID in ipairs(Areas.eventData.slayerAreas) do<br />
-- table.insert(returnPart, buildRow(eventAreaID, {5, 8}, 'SlayerArea'))<br />
-- end<br />
-- -- Add Bane * 4<br />
-- table.insert(returnPart, buildRow(152, 4))<br />
--end<br />
for i, monsterID in pairs(area.monsters) do<br />
if not Shared.contains(usedMonsters, monsterID) then<br />
if monsterID >= 0 then<br />
table.insert(returnPart, buildRow(monsterID, monsterCounts[monsterID]))<br />
else<br />
--Special handling for Into the Mist<br />
table.insert(returnPart, buildRow(monsterID, monsterCounts[monsterID], 'Afflicted'))<br />
end<br />
table.insert(usedMonsters, monsterID)<br />
end<br />
end<br />
table.insert(returnPart, '\r\n|}')<br />
return table.concat(returnPart)<br />
end<br />
<br />
function p.getDungeonTotalHp(frame)<br />
local areaName = frame.args ~= nil and frame.args[1] or frame<br />
local area = Areas.getArea(areaName)<br />
if area == nil then<br />
return "ERROR: Could not find a dungeon named "..areaName..'[[Category:Pages with script errors]]'<br />
end<br />
local totalHP = 0<br />
<br />
for i, monsterID in pairs(area.monsters) do<br />
if not Shared.contains(usedMonsters, monsterID) then<br />
local monster = p.getMonsterByID(monsterID)<br />
totalHP = totalHP + p._getMonsterHP(monster)<br />
end<br />
end<br />
return totalHP<br />
end<br />
<br />
function p._getAreaMonsterList(area)<br />
local monsterList = {}<br />
for i, monsterID in pairs(area.monsters) do<br />
local monster = p.getMonsterByID(monsterID)<br />
table.insert(monsterList, Icons.Icon({monster.name, type='monster'}))<br />
end<br />
return table.concat(monsterList, '<br/>')<br />
end<br />
<br />
function p._getDungeonMonsterList(area)<br />
local monsterList = {}<br />
local lastMonster = nil<br />
local lastID = -2<br />
local count = 0<br />
-- Special handing for Impending Darkness event<br />
-- TODO needs to be revised once there is a better understanding of how the event works<br />
--if area.isEvent ~= nil and area.isEvent then<br />
-- for i, eventAreaID in ipairs(Areas.eventData.slayerAreas) do<br />
-- local eventArea = Areas.getAreaByID('slayer', eventAreaID)<br />
-- table.insert(monsterList, '5-8 ' .. Icons.Icon({eventArea.name, type='combatArea'}) .. ' Monsters')<br />
-- end<br />
-- table.insert(monsterList, '4 ' .. Icons.Icon({'Bane', type='monster'}))<br />
--end<br />
for i, monsterID in Shared.skpairs(area.monsters) do<br />
if monsterID ~= lastID then<br />
local monster = nil <br />
if monsterID ~= -1 then monster = p.getMonsterByID(monsterID) end<br />
if lastID ~= -2 then<br />
if lastID == -1 then<br />
--Special handling for Afflicted Monsters<br />
table.insert(monsterList, Icons.Icon({'Affliction', 'Afflicted Monster', img='Question', qty=count}))<br />
else<br />
local name = lastMonster.name<br />
table.insert(monsterList, Icons.Icon({name, type='monster', qty=count}))<br />
end<br />
end<br />
lastMonster = monster<br />
lastID = monsterID<br />
count = 1<br />
else<br />
count = count + 1<br />
end<br />
--Make sure the final monster in the dungeon gets counted<br />
if i == Shared.tableCount(area.monsters) then<br />
local name = lastMonster.name<br />
table.insert(monsterList, Icons.Icon({lastMonster.name, type='monster', qty=count}))<br />
end<br />
end<br />
return table.concat(monsterList, '<br/>')<br />
end<br />
<br />
function p.getAreaMonsterList(frame)<br />
local areaName = frame.args ~= nil and frame.args[1] or frame<br />
local area = Areas.getArea(areaName)<br />
if area == nil then<br />
return "ERROR: Could not find an area named "..areaName..'[[Category:Pages with script errors]]'<br />
end<br />
<br />
if area.type == 'dungeon' then<br />
return p._getDungeonMonsterList(area)<br />
else<br />
return p._getAreaMonsterList(area)<br />
end<br />
end<br />
<br />
function p.getFoxyTable(frame)<br />
local result = 'Monster,Min GP,Max GP,Average GP'<br />
for i, monster in Shared.skpairs(MonsterData.Monsters) do<br />
if not p._isDungeonOnlyMonster(monster) then<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
local avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2<br />
result = result..'<br/>'..monster.name..','..monster.dropCoins[1]..','..(monster.dropCoins[2])..','..avgGp<br />
end<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p._getMonsterAverageGP(monster)<br />
local result = ''<br />
local totalGP = 0<br />
<br />
local bones = p._getMonsterBones(monster)<br />
if bones ~= nil then<br />
totalGP = totalGP + bones.sellsFor * (type(monster.boneQty) == 'number' and monster.boneQty or 1)<br />
end<br />
<br />
--Likewise, seeing the loot table is tied to the monster appearing outside of dungeons<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100<br />
local lootValue = 0<br />
<br />
local avgGp = 0<br />
<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2<br />
end<br />
<br />
totalGP = totalGP + avgGp<br />
<br />
local multiDrop = Shared.tableCount(monster.lootTable) > 1<br />
local totalWt = 0<br />
for i, row in pairs(monster.lootTable) do<br />
totalWt = totalWt + row[2]<br />
end<br />
<br />
for i, row in Shared.skpairs(monster.lootTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
local maxQty = row[3]<br />
<br />
local itemPrice = thisItem.sellsFor ~= nil and thisItem.sellsFor or 0<br />
<br />
--Getting the drop chance<br />
local dropChance = (row[2] / totalWt * lootChance)<br />
<br />
--Adding to the average loot value based on price & dropchance<br />
lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((1 + maxQty) / 2))<br />
end<br />
<br />
totalGP = totalGP + lootValue<br />
end<br />
<br />
return Shared.round(totalGP, 2, 2)<br />
end<br />
<br />
function p.getMonsterAverageGP(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterAverageGP(monster)<br />
end<br />
<br />
function p.getMonsterEVTable(frame)<br />
local result = '{| class="wikitable sortable"'<br />
result = result..'\r\n!Monster!!Combat Level!!Average GP'<br />
for i, monsterTemp in Shared.skpairs(MonsterData.Monsters) do<br />
local monster = Shared.clone(monsterTemp)<br />
monster.id = i - 1<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local monsterGP = p._getMonsterAverageGP(monster)<br />
local combatLevel = p._getMonsterCombatLevel(monster, 'Combat Level')<br />
result = result..'\r\n|-\r\n|'..Icons.Icon({monster.name, type='monster', noicon=true})..'||'..combatLevel..'||'..monsterGP<br />
end<br />
end<br />
result = result..'\r\n|}'<br />
return result<br />
end<br />
<br />
function p.getSlayerTierMonsterTable(frame)<br />
-- Input validation<br />
local tier = frame.args ~= nil and frame.args[1] or frame<br />
local slayerTier = nil<br />
<br />
if tier == nil then<br />
return "ERROR: No tier specified[[Category:Pages with script errors]]"<br />
end<br />
<br />
if tonumber(tier) ~= nil then<br />
slayerTier = Constants.getSlayerTierByID(tonumber(tier))<br />
else<br />
slayerTier = Constants.getSlayerTier(tier)<br />
end<br />
<br />
if slayerTier == nil then<br />
return "ERROR: Invalid slayer tier[[Category:Pages with script errors]]"<br />
end<br />
<br />
-- Obtain required tier details<br />
local minLevel, maxLevel = slayerTier.minLevel, slayerTier.maxLevel<br />
<br />
-- Build list of monster IDs<br />
-- Right now hiddenMonsterIDs is empty<br />
local hiddenMonsterIDs = {}<br />
local monsterIDs = {}<br />
for i, monster in Shared.skpairs(MonsterData.Monsters) do<br />
if monster.canSlayer and not Shared.contains(hiddenMonsterIDs, i - 1) then<br />
local cmbLevel = p._getMonsterCombatLevel(monster)<br />
if cmbLevel >= minLevel and (maxLevel == nil or cmbLevel <= maxLevel) then<br />
table.insert(monsterIDs, i - 1)<br />
end<br />
end<br />
end<br />
<br />
if Shared.tableCount(monsterIDs) == 0 then<br />
-- Somehow no monsters are in the tier, return nothing<br />
return ''<br />
else<br />
return p._getMonsterTable(monsterIDs, true)<br />
end<br />
end<br />
<br />
function p.getFullMonsterTable(frame)<br />
local monsterIDs = {}<br />
for i = 0, Shared.tableCount(MonsterData.Monsters) - 1, 1 do<br />
table.insert(monsterIDs, i)<br />
end<br />
<br />
return p._getMonsterTable(monsterIDs, false)<br />
end<br />
<br />
function p._getMonsterTable(monsterIDs, excludeDungeons)<br />
--Making a single function for getting a table of monsters given a list of IDs.<br />
local hideDungeons = excludeDungeons ~= nil and excludeDungeons or false<br />
local tableParts = {}<br />
table.insert(tableParts, '{| class="wikitable sortable stickyHeader"')<br />
-- First header row<br />
table.insert(tableParts, '\r\n|- class="headerRow-0"\r\n! colspan="5" | !! colspan="4" |Offensive Stats !! colspan="3" |Evasion Rating !! colspan="4" |')<br />
-- Second header row<br />
table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n!Monster !!Name !!ID !!Combat Level ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Hitpoints', type='skill'}))<br />
table.insert(tableParts, '!!Attack Speed (s) !!colspan="2"|Max Hit !!Accuracy ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Defence', type='skill', notext=true}))<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Ranged', type='skill', notext=true}))<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Magic', type='skill', notext=true}))<br />
table.insert(tableParts, '!!' .. Icons.Icon({'Coins', notext=true, nolink=true}) .. ' Coins !!Bones !!Locations')<br />
<br />
-- Generate row per monster<br />
for i, monsterID in Shared.skpairs(monsterIDs) do<br />
local monster = p.getMonsterByID(monsterID)<br />
local cmbLevel = p._getMonsterCombatLevel(monster)<br />
local atkSpeed = p._getMonsterAttackSpeed(monster)<br />
local maxHit = p._getMonsterMaxHit(monster)<br />
local accR = p._getMonsterAR(monster)<br />
local evaR = {p._getMonsterER(monster, "Melee"), p._getMonsterER(monster, "Ranged"), p._getMonsterER(monster, "Magic")}<br />
<br />
local gpRange = {0, 0}<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
gpRange = {monster.dropCoins[1], monster.dropCoins[2]}<br />
end<br />
local gpTxt = nil<br />
if gpRange[1] >= gpRange[2] then<br />
gpTxt = Shared.formatnum(gpRange[1])<br />
else<br />
gpTxt = Shared.formatnum(gpRange[1]) .. ' - ' .. Shared.formatnum(gpRange[2])<br />
end<br />
local bones = p._getMonsterBones(monster)<br />
local boneTxt = (bones ~= nil and Icons.Icon({bones.name, type='item', notext=true})) or 'None'<br />
<br />
table.insert(tableParts, '\r\n|-\r\n|style="text-align: center;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:left" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:right" |' .. monsterID)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. cmbLevel .. '" |' .. Shared.formatnum(cmbLevel))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. p._getMonsterHP(monster) .. '" |' .. Shared.formatnum(p._getMonsterHP(monster)))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. atkSpeed .. '" |' .. Shared.round(atkSpeed, 1, 1))<br />
table.insert(tableParts, '\r\n|style="text-align:center;border-right:hidden" |' .. p._getMonsterStyleIcon({monster, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. maxHit .. '" |' .. Shared.formatnum(maxHit))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. accR .. '" |' .. Shared.formatnum(accR))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[1] .. '" |' .. Shared.formatnum(evaR[1]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[2] .. '" |' .. Shared.formatnum(evaR[2]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[3] .. '" |' .. Shared.formatnum(evaR[3]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:center" |' .. boneTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))<br />
end<br />
<br />
table.insert(tableParts, '\r\n|}')<br />
return table.concat(tableParts)<br />
end<br />
<br />
function p.getMattMonsterTable(frame)<br />
--Making a single function for getting a table of monsters given a list of IDs.<br />
local tableParts = {}<br />
table.insert(tableParts, '{| class="wikitable sortable stickyHeader"')<br />
-- Second header row<br />
table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n!Monster !!Name !!ID !!Combat Level ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Hitpoints', type='skill'}))<br />
table.insert(tableParts, '!!' .. Icons.Icon({'Coins', notext=true, nolink=true}) .. ' Coins !!Avg. Kill Value!!Locations')<br />
<br />
-- Generate row per monster<br />
for i, monster in Shared.skpairs(MonsterData.Monsters) do<br />
local cmbLevel = p._getMonsterCombatLevel(monster)<br />
<br />
local gpRange = {0, 0}<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
gpRange = {monster.dropCoins[1], monster.dropCoins[2]}<br />
end<br />
local gpTxt = nil<br />
if gpRange[1] >= gpRange[2] then<br />
gpTxt = Shared.formatnum(gpRange[1])<br />
else<br />
gpTxt = Shared.formatnum(gpRange[1]) .. ' - ' .. Shared.formatnum(gpRange[2])<br />
end<br />
<br />
local lootVal = p._getMonsterLootValue(monster)<br />
local lootTxt = '0'<br />
if lootVal ~= 0 then<br />
lootTxt = Shared.formatnum(Shared.round(lootVal, 2, 2))<br />
end<br />
<br />
<br />
table.insert(tableParts, '\r\n|-\r\n|style="text-align: center;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:left" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:right" |' .. monster.id)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. cmbLevel .. '" |' .. Shared.formatnum(cmbLevel))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. p._getMonsterHP(monster) .. '" |' .. Shared.formatnum(p._getMonsterHP(monster)))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. lootVal .. '" |' .. lootTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))<br />
end<br />
<br />
table.insert(tableParts, '\r\n|}')<br />
return table.concat(tableParts)<br />
end<br />
<br />
function p.getMattMonsterTableV2(frame)<br />
--Making a single function for getting a table of monsters given a list of IDs.<br />
local tableParts = {}<br />
table.insert(tableParts, '{| class="wikitable sortable stickyHeader"')<br />
-- Second header row<br />
table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n!Monster !!Name !!Combat Level ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Hitpoints', type='skill'}))<br />
table.insert(tableParts, '!!Attack Speed (s) !!colspan="2"|Max Hit !!Accuracy ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Defence', type='skill', notext=true}))<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Ranged', type='skill', notext=true}))<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Magic', type='skill', notext=true}))<br />
table.insert(tableParts, '!!' .. Icons.Icon({'Coins', notext=true, nolink=true}) .. ' Coins !!Avg. Kill Value !!Bones')<br />
<br />
-- Generate row per monster<br />
for i, monster in Shared.skpairs(MonsterData.Monsters) do<br />
local cmbLevel = p._getMonsterCombatLevel(monster)<br />
<br />
local gpRange = {0, 0}<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
gpRange = {monster.dropCoins[1], monster.dropCoins[2]}<br />
end<br />
local gpTxt = nil<br />
if gpRange[1] >= gpRange[2] then<br />
gpTxt = Shared.formatnum(gpRange[1])<br />
else<br />
gpTxt = Shared.formatnum(gpRange[1]) .. ' - ' .. Shared.formatnum(gpRange[2])<br />
end<br />
<br />
local lootVal = p._getMonsterLootValue(monster)<br />
local lootTxt = '0'<br />
if lootVal ~= 0 then<br />
lootTxt = Shared.formatnum(Shared.round(lootVal, 2, 2))<br />
end<br />
<br />
<br />
table.insert(tableParts, '\r\n|-\r\n|style="text-align: center;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:left" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))<br />
-- table.insert(tableParts, '\r\n|style="text-align:right" |' .. monster.id)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. cmbLevel .. '" |' .. Shared.formatnum(cmbLevel))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. p._getMonsterHP(monster) .. '" |' .. Shared.formatnum(p._getMonsterHP(monster)))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. atkSpeed .. '" |' .. Shared.round(atkSpeed, 1, 1))<br />
table.insert(tableParts, '\r\n|style="text-align:center;border-right:hidden" |' .. p._getMonsterStyleIcon({monster, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. maxHit .. '" |' .. Shared.formatnum(maxHit))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. accR .. '" |' .. Shared.formatnum(accR))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[1] .. '" |' .. Shared.formatnum(evaR[1]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[2] .. '" |' .. Shared.formatnum(evaR[2]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[3] .. '" |' .. Shared.formatnum(evaR[3]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. lootVal .. '" |' .. lootTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:center" |' .. boneTxt)<br />
-- table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))<br />
end<br />
<br />
table.insert(tableParts, '\r\n|}')<br />
return table.concat(tableParts)<br />
end<br />
<br />
function p.getSpecialAttackTable(frame)<br />
local spAttTable = {}<br />
<br />
for i, monster in ipairs(MonsterData.Monsters) do<br />
if monster.specialAttacks ~= nil and Shared.tableCount(monster.specialAttacks) > 0 then<br />
local overrideChance = (monster.overrideSpecialChances ~= nil and Shared.tableCount(monster.overrideSpecialChances) > 0)<br />
for j, spAtt in ipairs(monster.specialAttacks) do<br />
local attChance = (overrideChance and monster.overrideSpecialChances[j] or spAtt.defaultChance)<br />
if spAttTable[spAtt.id] == nil then<br />
spAttTable[spAtt.id] = { ['defn'] = spAtt, ['icons'] = {} }<br />
end<br />
if spAttTable[spAtt.id]['icons'][attChance] == nil then<br />
spAttTable[spAtt.id]['icons'][attChance] = {}<br />
end<br />
table.insert(spAttTable[spAtt.id]['icons'][attChance], Icons.Icon({ monster.name, type = 'monster' }))<br />
end<br />
end<br />
end<br />
<br />
local resultPart = {}<br />
table.insert(resultPart, '{|class="wikitable sortable stickyHeader"')<br />
table.insert(resultPart, '\r\n|- class="headerRow-0"')<br />
table.insert(resultPart, '\r\n!Name!!style="min-width:225px"|Monsters!!Chance!!Effect')<br />
<br />
for i, spAttData in Shared.skpairs(spAttTable) do<br />
local spAtt = spAttData.defn<br />
local firstRow = true<br />
local rowsSpanned = Shared.tableCount(spAttData.icons)<br />
local rowSuffix = ''<br />
if rowsSpanned > 1 then<br />
rowSuffix = '|rowspan="' .. rowsSpanned .. '"'<br />
end<br />
for chance, iconList in Shared.skpairs(spAttData.icons) do<br />
table.insert(resultPart, '\r\n|-')<br />
if firstRow then<br />
table.insert(resultPart, '\r\n' .. rowSuffix .. '| ' .. spAtt.name)<br />
end<br />
table.insert(resultPart, '\r\n|data-sort-value="' .. spAtt.name .. '"| ' .. table.concat(iconList, '<br/>'))<br />
table.insert(resultPart, '\r\n|data-sort-value="' .. chance .. '"| ' .. Shared.round(chance, 2, 0) .. '%')<br />
if firstRow then<br />
table.insert(resultPart, '\r\n' .. rowSuffix .. '| ' .. spAtt.description)<br />
firstRow = false<br />
end<br />
end<br />
end<br />
table.insert(resultPart, '\r\n|}')<br />
<br />
return table.concat(resultPart)<br />
end<br />
<br />
return p</div>
Roko
https://wiki.melvoridle.com/index.php?title=Module:Monsters&diff=51088
Module:Monsters
2022-02-19T13:27:05Z
<p>Roko: </p>
<hr />
<div>local p = {}<br />
<br />
local MonsterData = mw.loadData('Module:Monsters/data')<br />
<br />
local Constants = require('Module:Constants')<br />
local Areas = require('Module:CombatAreas')<br />
local Magic = require('Module:Magic')<br />
local Shared = require('Module:Shared')<br />
local Icons = require('Module:Icons')<br />
local Items = require('Module:Items')<br />
<br />
function p.getMonster(name)<br />
local result = nil<br />
if name == 'Spider (lv. 51)' or name == 'Spider' then<br />
return p.getMonsterByID(50)<br />
elseif name == 'Spider (lv. 52)' or name == 'Spider2' then<br />
return p.getMonsterByID(51)<br />
end<br />
<br />
for i, monster in pairs(MonsterData.Monsters) do<br />
if monster.name == name then<br />
result = Shared.clone(monster)<br />
--Make sure every monster has an ID, and account for the 1-based indexing of Lua<br />
result.id = i - 1<br />
break<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.getMonsterByID(ID)<br />
local result = Shared.clone(MonsterData.Monsters[ID + 1])<br />
if result ~= nil then<br />
result.id = ID<br />
return result<br />
else<br />
return nil<br />
end<br />
end<br />
<br />
function p.getPassive(name)<br />
local result = nil<br />
<br />
for i, passive in pairs(MonsterData.Passives) do<br />
if passive.name == name then<br />
result = Shared.clone(passive)<br />
--Make sure every passive has an ID, and account for the 1-based indexing of Lua<br />
result.id = i - 1<br />
break<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.getPassiveByID(ID)<br />
return MonsterData.Passives[ID + 1]<br />
end<br />
<br />
-- Given a list of monster IDs, calls statFunc with each monster and returns<br />
-- the lowest & highest values<br />
function p.getLowHighStat(idList, statFunc)<br />
local lowVal, highVal = nil, nil<br />
for i, monID in ipairs(idList) do<br />
local monster = p.getMonsterByID(monID)<br />
local statVal = statFunc(monster)<br />
if lowVal == nil or statVal < lowVal then lowVal = statVal end<br />
if highVal == nil or statVal > highVal then highVal = statVal end<br />
end<br />
return lowVal, highVal<br />
end<br />
<br />
function p._getMonsterStat(monster, statName)<br />
if statName == 'HP' then<br />
return p._getMonsterHP(monster)<br />
elseif statName == 'maxHit' then<br />
return p._getMonsterMaxHit(monster)<br />
elseif statName == 'accuracyRating' then<br />
return p._getMonsterAR(monster)<br />
elseif statName == 'meleeEvasionRating' then<br />
return p._getMonsterER(monster, 'Melee')<br />
elseif statName == 'rangedEvasionRating' then<br />
return p._getMonsterER(monster, 'Ranged')<br />
elseif statName == 'magicEvasionRating' then<br />
return p._getMonsterER(monster, 'Magic')<br />
elseif statName == 'damageReduction' then<br />
return p.getEquipmentStat(monster, 'damageReduction')<br />
end<br />
<br />
return monster[statName]<br />
end<br />
<br />
function p.getMonsterStat(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame[1]<br />
local StatName = frame.args ~= nil and frame.args[2] or frame[2]<br />
local monster = p.getMonster(MonsterName)<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterStat(monster, StatName)<br />
end<br />
<br />
function p._getMonsterStyleIcon(frame)<br />
local args = frame.args ~= nil and frame.args or frame<br />
local monster = args[1]<br />
local notext = args.notext<br />
local nolink = args.nolink<br />
<br />
local iconText = ''<br />
if monster.attackType == 'melee' then<br />
iconText = Icons.Icon({'Melee', notext=notext, nolink=nolink})<br />
elseif monster.attackType == 'ranged' then<br />
iconText = Icons.Icon({'Ranged', type='skill', notext=notext, nolink=nolink})<br />
elseif monster.attackType == 'magic' then<br />
iconText = Icons.Icon({'Magic', type='skill', notext=notext, nolink=nolink})<br />
elseif monster.attackType == 'random' then<br />
iconText = Icons.Icon({'Bane', notext=notext, nolink=nolink, img='Question'})<br />
end<br />
<br />
return iconText<br />
end<br />
<br />
function p.getMonsterStyleIcon(frame)<br />
local args = frame.args ~= nil and frame.args or frame<br />
local MonsterName = args[1]<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
args[1] = monster<br />
return p._getMonsterStyleIcon(args)<br />
end<br />
<br />
function p._getMonsterHP(monster)<br />
return 10 * p._getMonsterLevel(monster, 'Hitpoints')<br />
end<br />
<br />
function p.getMonsterEffectiveHP(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
if monster ~= nil then<br />
return math.floor((p._getMonsterHP(monster)/(1 - p._getMonsterStat(monster, 'damageReduction')/100)) + 0.5)<br />
else<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
end<br />
<br />
function p.getMonsterHP(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
if monster ~= nil then<br />
return p._getMonsterHP(monster)<br />
else<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
end<br />
<br />
function p._getMonsterLevel(monster, skillName)<br />
local result = 0<br />
if monster.levels[skillName] ~= nil then<br />
result = monster.levels[skillName]<br />
end<br />
return result<br />
end<br />
<br />
function p.getMonsterLevel(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame[1]<br />
local SkillName = frame.args ~= nil and frame.args[2] or frame[2]<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterLevel(monster, SkillName)<br />
end<br />
<br />
function p.getEquipmentStat(monster, statName)<br />
local result = 0<br />
for i, stat in Shared.skpairs(monster.equipmentStats) do<br />
if stat.key == statName then<br />
result = stat.value<br />
break<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.calculateStandardStat(effectiveLevel, bonus)<br />
--Based on calculateStandardStat in Characters.js<br />
return (effectiveLevel + 9) * (bonus + 64)<br />
end<br />
<br />
function p.calculateStandardMaxHit(baseLevel, strengthBonus)<br />
--Based on calculateStandardMaxHit in Characters.js<br />
local effectiveLevel = baseLevel + 9<br />
return math.floor(10 * (1.3 + effectiveLevel / 10 + strengthBonus / 80 + effectiveLevel * strengthBonus / 640))<br />
end<br />
<br />
function p._getMonsterAttackSpeed(monster)<br />
return p.getEquipmentStat(monster, 'attackSpeed') / 1000<br />
end<br />
<br />
function p.getMonsterAttackSpeed(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
if monster ~= nil then<br />
return p._getMonsterAttackSpeed(monster)<br />
else<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
end<br />
<br />
function p._getMonsterCombatLevel(monster)<br />
local base = 0.25 * (p._getMonsterLevel(monster, 'Defence') + p._getMonsterLevel(monster, 'Hitpoints'))<br />
local melee = 0.325 * (p._getMonsterLevel(monster, 'Attack') + p._getMonsterLevel(monster, 'Strength'))<br />
local range = 0.325 * (1.5 * p._getMonsterLevel(monster, 'Ranged'))<br />
local magic = 0.325 * (1.5 * p._getMonsterLevel(monster, 'Magic'))<br />
return math.floor(base + math.max(melee, range, magic))<br />
end<br />
<br />
function p.getMonsterCombatLevel(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterCombatLevel(monster)<br />
end<br />
<br />
function p._getMonsterAR(monster)<br />
local baseLevel = 0<br />
local bonus = 0<br />
if monster.attackType == 'melee' then<br />
baseLevel = p._getMonsterLevel(monster, 'Attack')<br />
bonus = p.getEquipmentStat(monster, 'stabAttackBonus')<br />
elseif monster.attackType == 'ranged' then<br />
baseLevel = p._getMonsterLevel(monster, 'Ranged')<br />
bonus = p.getEquipmentStat(monster, 'rangedAttackBonus')<br />
elseif monster.attackType == 'magic' then<br />
baseLevel = p._getMonsterLevel(monster, 'Magic')<br />
bonus = p.getEquipmentStat(monster, 'magicAttackBonus')<br />
elseif monster.attackType == 'random' then<br />
--Bane has the same AR with every attack type so being lazy and just showing the one.<br />
baseLevel = p._getMonsterLevel(monster, 'Attack')<br />
bonus = p.getEquipmentStat(monster, 'stabAttackBonus')<br />
else<br />
return "ERROR: This monster has an invalid attack type somehow[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p.calculateStandardStat(baseLevel, bonus)<br />
end<br />
<br />
function p.getMonsterAR(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterAR(monster)<br />
end<br />
<br />
function p._getMonsterER(monster, style)<br />
local baseLevel= 0<br />
local bonus = 0<br />
<br />
if style == "Melee" then<br />
baseLevel = p._getMonsterLevel(monster, 'Defence')<br />
bonus = p.getEquipmentStat(monster, 'meleeDefenceBonus')<br />
elseif style == "Ranged" then<br />
baseLevel = p._getMonsterLevel(monster, 'Defence')<br />
bonus = p.getEquipmentStat(monster, 'rangedDefenceBonus')<br />
elseif style == "Magic" then<br />
baseLevel = math.floor(p._getMonsterLevel(monster, 'Magic') * 0.7 + p._getMonsterLevel(monster, 'Defence') * 0.3)<br />
bonus = p.getEquipmentStat(monster, 'magicDefenceBonus')<br />
else<br />
return "ERROR: Must choose Melee, Ranged, or Magic[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p.calculateStandardStat(baseLevel, bonus)<br />
end<br />
<br />
function p.getMonsterER(frame)<br />
local args = frame.args ~= nil and frame.args or frame<br />
local MonsterName = args[1]<br />
local style = args[2]<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterER(monster, style)<br />
end<br />
<br />
-- Determines if the monster is capable of dropping bones, and returns the bones<br />
-- item if so, or nil otherwise<br />
function p._getMonsterBones(monster)<br />
if monster.bones ~= nil and monster.bones >= 0 then<br />
local boneItem = Items.getItemByID(monster.bones)<br />
if boneItem.prayerPoints == nil then<br />
-- Assume bones without prayer points are shards (from God dungeons),<br />
-- and drop unconditionally<br />
return boneItem<br />
elseif not monster.isBoss and not p._isDungeonOnlyMonster(monster) then<br />
-- Otherwise, bones drop when the monster isn't dungeon exclusive<br />
return boneItem<br />
end<br />
end<br />
end<br />
<br />
function p._isDungeonOnlyMonster(monster)<br />
local areaList = Areas.getMonsterAreas(monster.id)<br />
local inDungeon = false<br />
<br />
for i, area in ipairs(areaList) do<br />
if area.type == 'dungeon' then<br />
inDungeon = true<br />
else<br />
return false<br />
end<br />
end<br />
return inDungeon<br />
end<br />
<br />
function p.isDungeonOnlyMonster(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with name "..monsterName.." found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._isDungeonOnlyMonster(monster)<br />
end<br />
<br />
function p._getMonsterAreas(monster, excludeDungeons)<br />
local resultPart = {}<br />
local hideDungeons = excludeDungeons ~= nil and excludeDungeons or false<br />
local areaList = Areas.getMonsterAreas(monster.id)<br />
for i, area in ipairs(areaList) do<br />
if area.type ~= 'dungeon' or not hideDungeons then<br />
table.insert(resultPart, Icons.Icon({area.name, type = area.type}))<br />
end<br />
end<br />
return table.concat(resultPart, '<br/>')<br />
end<br />
<br />
function p.getMonsterAreas(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local hideDungeons = frame.args ~= nil and frame.args[2] or nil<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with name "..monsterName.." found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterAreas(monster, hideDungeons)<br />
end<br />
<br />
function p.getSpecAttackMaxHit(specAttack, normalMaxHit)<br />
local result = 0<br />
for i, dmg in pairs(specAttack.damage) do<br />
if dmg.maxRoll == 'Fixed' then<br />
result = dmg.maxPercent * 10<br />
elseif dmg.maxRoll == 'MaxHit' then<br />
if dmg.character == 'Target' then<br />
--Confusion applied damage based on the player's max hit. Gonna just ignore that one<br />
result = 0<br />
else<br />
result = dmg.maxPercent * normalMaxHit * 0.01<br />
end<br />
elseif Shared.contains({'Bleeding', 'Poisoned'}, dmg.maxRoll) then<br />
-- TODO: This is limited in that there is no verification that bleed/poison<br />
-- can be applied to the target, it is assumed that it can and so this applies<br />
result = result + dmg.maxPercent * 10<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.canSpecAttackApplyEffect(specAttack, effectType)<br />
local result = false<br />
for i, effect in pairs(specAttack.prehitEffects) do<br />
if effect.type == effectType then<br />
result = true<br />
break<br />
end<br />
end<br />
<br />
for i, effect in pairs(specAttack.onhitEffects) do<br />
if effect.type == effectType then<br />
result = true<br />
break<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p._getMonsterMaxHit(monster, doStuns)<br />
-- 2021-06-11 Adjusted for v0.20 stun/sleep changes, where damage multiplier now applies<br />
-- to all enemy attacks if stun/sleep is present on at least one special attack<br />
if doStuns == nil then<br />
doStuns = true<br />
elseif type(doStuns) == 'string' then<br />
doStuns = string.upper(doStuns) == 'TRUE'<br />
end<br />
<br />
local normalChance = 100<br />
local specialMaxHit = 0<br />
local normalMaxHit = p._getMonsterBaseMaxHit(monster)<br />
local hasActiveBuffSpec = false<br />
local damageMultiplier = 1<br />
if monster.specialAttacks[1] ~= nil then<br />
local canStun, canSleep = false, false<br />
for i, specAttack in pairs(monster.specialAttacks) do<br />
if monster.overrideSpecialChances ~= nil then<br />
normalChance = normalChance - monster.overrideSpecialChances[i]<br />
else<br />
normalChance = normalChance - specAttack.defaultChance<br />
end<br />
local thisMax = p.getSpecAttackMaxHit(specAttack, normalMaxHit)<br />
if not canStun and p.canSpecAttackApplyEffect(specAttack, 'Stun') then canStun = true end<br />
if not canSleep and p.canSpecAttackApplyEffect(specAttack, 'Sleep') then canSleep = true end<br />
<br />
if thisMax > specialMaxHit then specialMaxHit = thisMax end<br />
if Shared.contains(string.upper(specAttack.description), 'NORMAL ATTACK INSTEAD') then <br />
hasActiveBuffSpec = true <br />
end<br />
end<br />
<br />
if canSleep and doStuns then damageMultiplier = damageMultiplier * 1.2 end<br />
if canStun and doStuns then damageMultiplier = damageMultiplier * 1.3 end<br />
end<br />
--Ensure that if the monster never does a normal attack, the normal max hit is irrelevant<br />
if normalChance == 0 and not hasActiveBuffSpec then normalMaxHit = 0 end<br />
return math.floor(math.max(specialMaxHit, normalMaxHit) * damageMultiplier)<br />
end<br />
<br />
function p.getMonsterMaxHit(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local doStuns = frame.args ~= nil and frame.args[2] or true<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterMaxHit(monster, doStuns)<br />
end<br />
<br />
function p._getMonsterBaseMaxHit(monster)<br />
--8/27/21 - Now references p.calculateStandardMaxHit for Melee & Ranged<br />
local result = 0<br />
local baseLevel = 0<br />
local bonus = 0<br />
if monster.attackType == 'melee' then<br />
baseLevel = p._getMonsterLevel(monster, 'Strength')<br />
bonus = p.getEquipmentStat(monster, 'meleeStrengthBonus')<br />
result = p.calculateStandardMaxHit(baseLevel, bonus)<br />
elseif monster.attackType == 'ranged' then<br />
baseLevel = p._getMonsterLevel(monster, 'Ranged')<br />
bonus = p.getEquipmentStat(monster, 'rangedStrengthBonus')<br />
result = p.calculateStandardMaxHit(baseLevel, bonus)<br />
elseif monster.attackType == 'magic' then<br />
local mSpell = nil<br />
if monster.selectedSpell ~= nil then mSpell = Magic.getSpellByID('Spells', monster.selectedSpell) end<br />
<br />
bonus = p.getEquipmentStat(monster, 'magicDamageBonus')<br />
baseLevel = p._getMonsterLevel(monster, 'Magic')<br />
<br />
result = math.floor(10 * mSpell.maxHit * (1 + bonus / 100) * (1 + (baseLevel + 1) / 200))<br />
elseif monster.attackType == 'random' then<br />
local hitArray = {}<br />
local iconText = Icons.Icon({'Melee', notext=true})<br />
baseLevel = p._getMonsterLevel(monster, 'Strength')<br />
bonus = p.getEquipmentStat(monster, 'meleeStrengthBonus')<br />
table.insert(hitArray, p.calculateStandardMaxHit(baseLevel, bonus))<br />
<br />
iconText = Icons.Icon({'Ranged', type='skill', notext=true})<br />
baseLevel = p._getMonsterLevel(monster, 'Ranged')<br />
bonus = p.getEquipmentStat(monster, 'rangedStrengthBonus')<br />
table.insert(hitArray, p.calculateStandardMaxHit(baseLevel, bonus))<br />
<br />
iconText = Icons.Icon({'Magic', type='skill', notext=true})<br />
local mSpell = nil<br />
if monster.selectedSpell ~= nil then mSpell = Magic.getSpellByID('Spells', monster.selectedSpell) end<br />
bonus = p.getEquipmentStat(monster, 'magicDamageBonus')<br />
baseLevel = p._getMonsterLevel(monster, 'Magic')<br />
local magicDmg = math.floor(10 * mSpell.maxHit * (1 + bonus / 100) * (1 + (baseLevel + 1) / 200))<br />
table.insert(hitArray, magicDmg)<br />
<br />
local max = 0<br />
for i, val in pairs(hitArray) do<br />
if val > max then max = val end<br />
end<br />
result = max<br />
else<br />
return "ERROR: This monster has an invalid attack type somehow[[Category:Pages with script errors]]"<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getMonsterBaseMaxHit(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterBaseMaxHit(monster)<br />
end<br />
<br />
function p.getMonsterAttacks(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = ''<br />
local iconText = p._getMonsterStyleIcon({monster, notext=true})<br />
local typeText = ''<br />
if monster.attackType == 'melee' then<br />
typeText = 'Melee'<br />
elseif monster.attackType == 'ranged' then<br />
typeText = 'Ranged'<br />
elseif monster.attackType == 'magic' then<br />
typeText = 'Magic'<br />
elseif monster.attackType == 'random' then<br />
typeText = "Random"<br />
end<br />
<br />
local buffAttacks = {}<br />
local hasActiveBuffSpec = false<br />
<br />
local normalAttackChance = 100<br />
if monster.specialAttacks[1] ~= nil then<br />
for i, specAttack in pairs(monster.specialAttacks) do<br />
local attChance = 0<br />
if monster.overrideSpecialChances ~= nil then<br />
attChance = monster.overrideSpecialChances[i]<br />
else<br />
attChance = specAttack.defaultChance<br />
end<br />
normalAttackChance = normalAttackChance - attChance<br />
<br />
result = result..'\r\n* '..attChance..'% '..iconText..' '..specAttack.name..'\r\n** '..specAttack.description<br />
<br />
if Shared.contains(string.upper(specAttack.description), 'NORMAL ATTACK INSTEAD') then<br />
table.insert(buffAttacks, specAttack.name)<br />
hasActiveBuffSpec = true <br />
end<br />
end<br />
end<br />
if normalAttackChance == 100 then<br />
result = iconText..' 1 - '..p._getMonsterBaseMaxHit(monster)..' '..typeText..' Damage'<br />
elseif normalAttackChance > 0 then<br />
result = '* '..normalAttackChance..'% '..iconText..' 1 - '..p.getMonsterBaseMaxHit(frame)..' '..typeText..' Damage'..result<br />
elseif hasActiveBuffSpec then<br />
--If the monster normally has a 0% chance of doing a normal attack but some special attacks can't be repeated, include it<br />
--(With a note about when it does it)<br />
result = '* '..iconText..' 1 - '..p._getMonsterBaseMaxHit(monster)..' '..typeText..' Damage (Instead of repeating '..table.concat(buffAttacks, ' or ')..' while the effect is already active)'..result<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getMonsterPassives(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = ''<br />
if type(monster.passiveID) == 'table' and Shared.tableCount(monster.passiveID) > 0 then<br />
result = result .. '===Passives==='<br />
for i, passiveID in pairs(monster.passiveID) do<br />
local passive = p.getPassiveByID(passiveID)<br />
result = result .. '\r\n* ' .. passive.name .. '\r\n** ' .. passive.description<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.getMonsterCategories(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = '[[Category:Monsters]]'<br />
<br />
if monster.attackType == 'melee' then<br />
result = result..'[[Category:Melee Monsters]]'<br />
elseif monster.attackType == 'ranged' then<br />
result = result..'[[Category:Ranged Monsters]]'<br />
elseif monster.attackType == 'magic' then<br />
result = result..'[[Category:Magic Monsters]]'<br />
end<br />
<br />
if monster.specialAttacks[1] ~= nil then<br />
result = result..'[[Category:Monsters with Special Attacks]]'<br />
end<br />
<br />
if monster.isBoss then<br />
result = result..'[[Category:Bosses]]'<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getOtherMonsterBoxText(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = ''<br />
<br />
--Going through and finding out which damage bonuses will apply to this monster<br />
local monsterTypes = {}<br />
if monster.isBoss then table.insert(monsterTypes, 'Boss') end<br />
<br />
local areaList = Areas.getMonsterAreas(monster.id)<br />
local counts = {combat = 0, slayer = 0, dungeon = 0}<br />
for i, area in Shared.skpairs(areaList) do<br />
counts[area.type] = counts[area.type] + 1<br />
end<br />
<br />
if counts.combat > 0 then table.insert(monsterTypes, 'Combat Area') end<br />
if counts.slayer > 0 then table.insert(monsterTypes, 'Slayer Area') end<br />
if counts.dungeon > 0 then table.insert(monsterTypes, 'Dungeon') end<br />
<br />
result = result.."\r\n|-\r\n|'''Monster Types:''' "..table.concat(monsterTypes, ", ")<br />
<br />
local SlayerTier = 'N/A'<br />
if monster.canSlayer then<br />
SlayerTier = Constants.getSlayerTierNameByLevel(p._getMonsterCombatLevel(monster))<br />
end<br />
<br />
result = result.."\r\n|-\r\n|'''"..Icons.Icon({'Slayer', type='skill'}).." [[Slayer#Slayer Tier Monsters|Tier]]:''' "<br />
if monster.canSlayer then<br />
result = result.."[[Slayer#"..SlayerTier.."|"..SlayerTier.."]]"<br />
else<br />
result = result..SlayerTier<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getMonsterDrops(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = ''<br />
<br />
local bones = p._getMonsterBones(monster)<br />
local boneVal = 0<br />
--Show the bones only if either the monster shows up outside of dungeons _or_ the monster drops shards<br />
if bones ~= nil then<br />
local boneQty = (monster.boneQty ~= nil and monster.boneQty or 1)<br />
result = result.."'''Always Drops:'''"<br />
result = result..'\r\n{|class="wikitable" id="bonedrops"'<br />
result = result..'\r\n!Item !! Qty'<br />
result = result..'\r\n|-\r\n|'..Icons.Icon({bones.name, type='item'})<br />
result = result..'||'..boneQty..'\r\n'..'|}'<br />
boneVal = boneQty * bones.sellsFor<br />
end<br />
<br />
--Likewise, seeing the loot table is tied to the monster appearing outside of dungeons<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100<br />
local lootValue = 0<br />
<br />
result = result.."'''Loot:'''"<br />
local avgGp = 0<br />
<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2<br />
local gpTxt = Icons.GP(monster.dropCoins[1], monster.dropCoins[2])<br />
result = result.."\r\nIn addition to loot, the monster will also drop "..gpTxt..'.'<br />
end<br />
<br />
local multiDrop = Shared.tableCount(monster.lootTable) > 1<br />
local totalWt = 0<br />
for i, row in pairs(monster.lootTable) do<br />
totalWt = totalWt + row[2]<br />
end<br />
result = result..'\r\n{|class="wikitable sortable" id="itemdrops"'<br />
result = result..'\r\n!Item!!Qty'<br />
result = result..'!!Price!!colspan="2"|Chance'<br />
<br />
--Sort the loot table by weight in descending order<br />
table.sort(monster.lootTable, function(a, b) return a[2] > b[2] end)<br />
for i, row in Shared.skpairs(monster.lootTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
<br />
local maxQty = row[3]<br />
if thisItem ~= nil then<br />
result = result..'\r\n|-\r\n|'..Icons.Icon({thisItem.name, type='item'})<br />
else<br />
result = result..'\r\n|-\r\n|Unknown Item[[Category:Pages with script errors]]'<br />
end<br />
result = result..'||style="text-align:right" data-sort-value="'..maxQty..'"|'<br />
<br />
if maxQty > 1 then<br />
result = result.. '1 - '<br />
end<br />
result = result..Shared.formatnum(row[3])<br />
<br />
--Adding price columns<br />
local itemPrice = 0<br />
if thisItem == nil then<br />
result = result..'||data-sort-value="0"|???'<br />
else<br />
itemPrice = thisItem.sellsFor ~= nil and thisItem.sellsFor or 0<br />
if itemPrice == 0 or maxQty == 1 then<br />
result = result..'||'..Icons.GP(itemPrice)<br />
else<br />
result = result..'||'..Icons.GP(itemPrice, itemPrice * maxQty)<br />
end<br />
end<br />
<br />
--Getting the drop chance<br />
local dropChance = (row[2] / totalWt * lootChance)<br />
if dropChance < 100 then<br />
--Show fraction as long as it isn't going to be 1/1<br />
result = result..'||style="text-align:right" data-sort-value="'..row[2]..'"'<br />
result = result..'|'..Shared.fraction(row[2] * lootChance, totalWt * 100)<br />
result = result..'||'<br />
else<br />
result = result..'||colspan="2" data-sort-value="'..row[2]..'"'<br />
end<br />
-- If chance is less than 0.10% then show 2 significant figures, otherwise 2 decimal places<br />
local fmt = (dropChance < 0.10 and '%.2g') or '%.2f'<br />
result = result..'style="text-align:right"|'..string.format(fmt, dropChance)..'%'<br />
<br />
--Adding to the average loot value based on price & dropchance<br />
lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((1 + maxQty) / 2))<br />
end<br />
if multiDrop then<br />
result = result..'\r\n|-class="sortbottom" \r\n!colspan="3"|Total:'<br />
if lootChance < 100 then<br />
result = result..'\r\n|style="text-align:right"|'..Shared.fraction(lootChance, 100)..'||'<br />
else<br />
result = result..'\r\n|colspan="2" '<br />
end<br />
result = result..'style="text-align:right"|'..Shared.round(lootChance, 2, 2)..'%'<br />
end<br />
result = result..'\r\n|}'<br />
result = result..'\r\nThe loot dropped by the average kill is worth '..Icons.GP(Shared.round(lootValue, 2, 0)).." if sold."<br />
if avgGp > 0 then<br />
result = result.."<br/>Including GP"<br />
if boneVal > 0 then<br />
result = result..' and bones'<br />
end<br />
result = result..', the average kill is worth '..Icons.GP(Shared.round(avgGp + lootValue + boneVal, 2, 0))..'.'<br />
end<br />
end<br />
<br />
--If no other drops, make sure to at least say so.<br />
if result == '' then result = 'None' end<br />
return result<br />
end<br />
<br />
function p._getMonsterLootValue(monster)<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = 0<br />
local boneVal = 0<br />
<br />
local bones = p._getMonsterBones(monster)<br />
--Show the bones only if either the monster shows up outside of dungeons _or_ the monster drops shards<br />
if bones ~= nil then<br />
local boneQty = monster.boneQty ~= nil and monster.boneQty or 1<br />
boneVal = bones.sellsFor * boneQty<br />
result = result + boneVal<br />
end<br />
<br />
--Likewise, seeing the loot table is tied to the monster appearing outside of dungeons<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100<br />
local lootValue = 0<br />
<br />
local avgGp = 0<br />
<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2<br />
end<br />
<br />
local multiDrop = Shared.tableCount(monster.lootTable) > 1<br />
local totalWt = 0<br />
for i, row in pairs(monster.lootTable) do<br />
totalWt = totalWt + row[2]<br />
end<br />
<br />
for i, row in Shared.skpairs(monster.lootTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
<br />
local maxQty = row[3]<br />
<br />
--Adding price columns<br />
local itemPrice = 0<br />
if thisItem ~= nil then<br />
itemPrice = thisItem.sellsFor ~= nil and thisItem.sellsFor or 0<br />
end<br />
<br />
--Getting the drop chance<br />
local dropChance = (row[2] / totalWt * lootChance)<br />
--Adding to the average loot value based on price & dropchance<br />
lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((1 + maxQty) / 2))<br />
end<br />
if avgGp > 0 then<br />
result = result + avgGp + lootValue<br />
end<br />
end<br />
<br />
return result<br />
end<br />
<br />
-- Find drop chance of specified item from specified monster. <br />
-- Usage: |Monster Name|Item Name<br />
function p.getItemDropChance(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame[1]<br />
local ItemName = frame.args ~= nil and frame.args[2] or frame[2]<br />
<br />
local monster = p.getMonster(MonsterName)<br />
local item = Items.getItem(ItemName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
if item == nil then<br />
return "ERROR: No item with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100<br />
<br />
local totalWt = 0<br />
--for i, row in pairs(monster.lootTable) do<br />
--totalWt = totalWt + row[2]<br />
--end<br />
<br />
local dropChance = 0<br />
local dropWt = 0<br />
for i, row in Shared.skpairs(monster.lootTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
totalWt = totalWt + row[2]<br />
if item['id'] == thisItem['id'] then<br />
dropWt = row[2]<br />
end<br />
end<br />
dropChance = (dropWt / totalWt * lootChance)<br />
return Shared.round(dropChance, 2, 2)<br />
end<br />
end <br />
<br />
function p.getChestDrops(frame)<br />
local ChestName = frame.args ~= nil and frame.args[1] or frame<br />
local chest = Items.getItem(ChestName)<br />
<br />
if chest == nil then<br />
return "ERROR: No item named "..ChestName..' found[[Category:Pages with script errors]]'<br />
end<br />
<br />
local result = ''<br />
<br />
if chest.dropTable == nil then<br />
return "ERROR: "..ChestName.." does not have a drop table[[Category:Pages with script errors]]"<br />
else<br />
local lootChance = 100<br />
local lootValue = 0<br />
<br />
local multiDrop = Shared.tableCount(chest.dropTable) > 1<br />
local totalWt = 0<br />
for i, row in pairs(chest.dropTable) do<br />
totalWt = totalWt + row[2]<br />
end<br />
result = result..'\r\n{|class="wikitable sortable"'<br />
result = result..'\r\n!Item!!Qty'<br />
result = result..'!!colspan="2"|Chance!!Price'<br />
<br />
--Sort the loot table by weight in descending order<br />
for i, row in pairs(chest.dropTable) do<br />
if chest.dropQty ~= nil then<br />
table.insert(row, chest.dropQty[i])<br />
else<br />
table.insert(row, 1)<br />
end<br />
end<br />
table.sort(chest.dropTable, function(a, b) return a[2] > b[2] end)<br />
for i, row in Shared.skpairs(chest.dropTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
local qty = row[3]<br />
result = result..'\r\n|-\r\n|'..Icons.Icon({thisItem.name, type='item'})<br />
result = result..'||style="text-align:right" data-sort-value="'..qty..'"|'<br />
<br />
if qty > 1 then<br />
result = result.. '1 - '<br />
end<br />
result = result..Shared.formatnum(qty)<br />
<br />
local dropChance = (row[2] / totalWt) * 100<br />
result = result..'||style="text-align:right" data-sort-value="'..row[2]..'"'<br />
result = result..'|'..Shared.fraction(row[2], totalWt)<br />
<br />
result = result..'||style="text-align:right"|'..Shared.round(dropChance, 2, 2)..'%'<br />
<br />
result = result..'||style="text-align:left" data-sort-value="'..thisItem.sellsFor..'"'<br />
if qty > 1 then<br />
result = result..'|'..Icons.GP(thisItem.sellsFor, thisItem.sellsFor * qty)<br />
else<br />
result = result..'|'..Icons.GP(thisItem.sellsFor)<br />
end<br />
lootValue = lootValue + (dropChance * 0.01 * thisItem.sellsFor * ((1 + qty)/ 2))<br />
end<br />
result = result..'\r\n|}'<br />
result = result..'\r\nThe average value of the contents of one chest is '..Icons.GP(Shared.round(lootValue, 2, 0))..'.'<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getAreaMonsterTable(frame)<br />
local areaName = frame.args ~= nil and frame.args[1] or frame<br />
local area = Areas.getArea(areaName)<br />
if area == nil then<br />
return "ERROR: Could not find an area named "..areaName..'[[Category:Pages with script errors]]'<br />
end<br />
<br />
if area.type == 'dungeon' then<br />
return p.getDungeonMonsterTable(frame)<br />
end<br />
<br />
local tableTxt = '{| class="wikitable sortable"'<br />
tableTxt = tableTxt..'\r\n! Name !! Combat Level !! Hitpoints !! Max Hit !! [[Combat Triangle|Combat Style]]'<br />
for i, monsterID in pairs(area.monsters) do<br />
local monster = p.getMonsterByID(monsterID)<br />
tableTxt = tableTxt..'\r\n|-\r\n|'..Icons.Icon({monster.name, type='monster'})<br />
tableTxt = tableTxt..'||'..p._getMonsterCombatLevel(monster)<br />
tableTxt = tableTxt..'||'..Shared.formatnum(p._getMonsterHP(monster))<br />
tableTxt = tableTxt..'||'..Shared.formatnum(p._getMonsterMaxHit(monster))<br />
tableTxt = tableTxt..'||'..p._getMonsterStyleIcon({monster, nolink=true})<br />
end<br />
tableTxt = tableTxt..'\r\n|}'<br />
return tableTxt<br />
end<br />
<br />
function p.getDungeonMonsterTable(frame)<br />
local areaName = frame.args ~= nil and frame.args[1] or frame<br />
local area = Areas.getArea(areaName)<br />
if area == nil then<br />
return "ERROR: Could not find a dungeon named "..areaName..'[[Category:Pages with script errors]]'<br />
end<br />
<br />
--For Dungeons, go through and count how many of each monster are in the dungeon first<br />
local monsterCounts = {}<br />
for i, monsterID in pairs(area.monsters) do<br />
if monsterCounts[monsterID] == nil then<br />
monsterCounts[monsterID] = 1<br />
else<br />
monsterCounts[monsterID] = monsterCounts[monsterID] + 1<br />
end<br />
end<br />
<br />
local usedMonsters = {}<br />
<br />
-- Declare function for building table rows to avoid repeating code<br />
local buildRow = function(entityID, monsterCount, specialType)<br />
local monIcon, monLevel, monHP, monMaxHit, monStyle, monCount<br />
local monData = {}<br />
if specialType ~= nil and Shared.contains({'Afflicted', 'SlayerArea'}, specialType) then<br />
-- Special handling for Into the Mist<br />
if specialType == 'Afflicted' then<br />
local iconQ = Icons.Icon({'Into the Mist', notext=true, nolink=true, img='Question'})<br />
monIcon = Icons.Icon({'Into the Mist', 'Afflicted Monster', nolink=true, img='Question'})<br />
monLevel, monHP, monMaxHit, monStyle, monCount = iconQ, iconQ, iconQ, iconQ, monsterCount<br />
elseif specialType == 'SlayerArea' then<br />
-- entityID corresponds to a slayer area<br />
local area = Areas.getAreaByID('slayer', entityID)<br />
monIcon = Icons.Icon({area.name, type='combatArea'}) .. ' Monsters'<br />
monLevel = {p.getLowHighStat(area.monsters, function(monster) return p._getMonsterCombatLevel(monster) end)}<br />
monHP = {p.getLowHighStat(area.monsters, function(monster) return p._getMonsterHP(monster) end)}<br />
local lowMaxHit, highMaxHit = p.getLowHighStat(area.monsters, function(monster) return p._getMonsterMaxHit(monster) end)<br />
monMaxHit = highMaxHit<br />
monStyle = Icons.Icon({area.name, area.name, notext=true, nolink=true, img='Question'})<br />
monCount = monsterCount<br />
end<br />
else<br />
-- entityID corresponds to a monster<br />
local monster = p.getMonsterByID(entityID)<br />
monIcon = Icons.Icon({monster.name, type='monster'})<br />
monLevel = p._getMonsterCombatLevel(monster)<br />
monHP = p._getMonsterHP(monster)<br />
monMaxHit = p._getMonsterMaxHit(monster)<br />
monStyle = p._getMonsterStyleIcon({monster})<br />
monCount = monsterCount<br />
end<br />
local getValSort = function(val)<br />
if type(val) == 'table' then<br />
if type(val[1]) == 'number' and type(val[2]) == 'number' then<br />
return (val[1] + val[2]) / 2<br />
else<br />
return (type(val[1]) == 'number' and val[1]) or 0<br />
end<br />
else<br />
return (type(val) == 'number' and val) or 0<br />
end<br />
end<br />
local getValText = function(val)<br />
if type(val) == 'table' and Shared.tableCount(val) == 2 then<br />
if type(val[1]) == 'number' and type(val[2]) == 'number' then<br />
return Shared.formatnum(val[1]) .. ' - ' .. Shared.formatnum(val[2])<br />
else<br />
return val[1] .. ' - ' .. val[2]<br />
end<br />
elseif type(val) == 'number' then<br />
return Shared.formatnum(val)<br />
else<br />
return val<br />
end<br />
end<br />
<br />
local resultPart = {}<br />
table.insert(resultPart, '\r\n|-\r\n| ' .. monIcon)<br />
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monLevel) .. '"| ' .. getValText(monLevel))<br />
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monHP) .. '"| ' .. getValText(monHP))<br />
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monMaxHit) .. '"| ' .. getValText(monMaxHit))<br />
table.insert(resultPart, '\r\n| ' .. monStyle)<br />
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monCount) .. '"| ' .. getValText(monCount))<br />
return table.concat(resultPart)<br />
end<br />
<br />
local returnPart = {}<br />
table.insert(returnPart, '{| class="wikitable sortable"')<br />
table.insert(returnPart, '\r\n! Name !! Combat Level !! Hitpoints !! Max Hit !! [[Combat Triangle|Combat Style]] !! Count')<br />
-- Special handing for Impending Darkness event<br />
-- TODO needs to be revised once there is a better understanding of how the event works<br />
--if area.isEvent ~= nil and area.isEvent then<br />
-- for i, eventAreaID in ipairs(Areas.eventData.slayerAreas) do<br />
-- table.insert(returnPart, buildRow(eventAreaID, {5, 8}, 'SlayerArea'))<br />
-- end<br />
-- -- Add Bane * 4<br />
-- table.insert(returnPart, buildRow(152, 4))<br />
--end<br />
for i, monsterID in pairs(area.monsters) do<br />
if not Shared.contains(usedMonsters, monsterID) then<br />
if monsterID >= 0 then<br />
table.insert(returnPart, buildRow(monsterID, monsterCounts[monsterID]))<br />
else<br />
--Special handling for Into the Mist<br />
table.insert(returnPart, buildRow(monsterID, monsterCounts[monsterID], 'Afflicted'))<br />
end<br />
table.insert(usedMonsters, monsterID)<br />
end<br />
end<br />
table.insert(returnPart, '\r\n|}')<br />
return table.concat(returnPart)<br />
end<br />
<br />
function p.getDungeonTotalHp(frame)<br />
local areaName = frame.args ~= nil and frame.args[1] or frame<br />
local area = Areas.getArea(areaName)<br />
if area == nil then<br />
return "ERROR: Could not find a dungeon named "..areaName..'[[Category:Pages with script errors]]'<br />
end<br />
local totalHP = 0<br />
<br />
for i, monsterID in pairs(area.monsters) do<br />
if not Shared.contains(usedMonsters, monsterID) then<br />
local monster = p.getMonsterByID(monsterID)<br />
totalHP = totalHP + p._getMonsterHP(monster)<br />
end<br />
end<br />
return totalHP<br />
end<br />
<br />
function p._getAreaMonsterList(area)<br />
local monsterList = {}<br />
for i, monsterID in pairs(area.monsters) do<br />
local monster = p.getMonsterByID(monsterID)<br />
table.insert(monsterList, Icons.Icon({monster.name, type='monster'}))<br />
end<br />
return table.concat(monsterList, '<br/>')<br />
end<br />
<br />
function p._getDungeonMonsterList(area)<br />
local monsterList = {}<br />
local lastMonster = nil<br />
local lastID = -2<br />
local count = 0<br />
-- Special handing for Impending Darkness event<br />
-- TODO needs to be revised once there is a better understanding of how the event works<br />
--if area.isEvent ~= nil and area.isEvent then<br />
-- for i, eventAreaID in ipairs(Areas.eventData.slayerAreas) do<br />
-- local eventArea = Areas.getAreaByID('slayer', eventAreaID)<br />
-- table.insert(monsterList, '5-8 ' .. Icons.Icon({eventArea.name, type='combatArea'}) .. ' Monsters')<br />
-- end<br />
-- table.insert(monsterList, '4 ' .. Icons.Icon({'Bane', type='monster'}))<br />
--end<br />
for i, monsterID in Shared.skpairs(area.monsters) do<br />
if monsterID ~= lastID then<br />
local monster = nil <br />
if monsterID ~= -1 then monster = p.getMonsterByID(monsterID) end<br />
if lastID ~= -2 then<br />
if lastID == -1 then<br />
--Special handling for Afflicted Monsters<br />
table.insert(monsterList, Icons.Icon({'Affliction', 'Afflicted Monster', img='Question', qty=count}))<br />
else<br />
local name = lastMonster.name<br />
table.insert(monsterList, Icons.Icon({name, type='monster', qty=count}))<br />
end<br />
end<br />
lastMonster = monster<br />
lastID = monsterID<br />
count = 1<br />
else<br />
count = count + 1<br />
end<br />
--Make sure the final monster in the dungeon gets counted<br />
if i == Shared.tableCount(area.monsters) then<br />
local name = lastMonster.name<br />
table.insert(monsterList, Icons.Icon({lastMonster.name, type='monster', qty=count}))<br />
end<br />
end<br />
return table.concat(monsterList, '<br/>')<br />
end<br />
<br />
function p.getAreaMonsterList(frame)<br />
local areaName = frame.args ~= nil and frame.args[1] or frame<br />
local area = Areas.getArea(areaName)<br />
if area == nil then<br />
return "ERROR: Could not find an area named "..areaName..'[[Category:Pages with script errors]]'<br />
end<br />
<br />
if area.type == 'dungeon' then<br />
return p._getDungeonMonsterList(area)<br />
else<br />
return p._getAreaMonsterList(area)<br />
end<br />
end<br />
<br />
function p.getFoxyTable(frame)<br />
local result = 'Monster,Min GP,Max GP,Average GP'<br />
for i, monster in Shared.skpairs(MonsterData.Monsters) do<br />
if not p._isDungeonOnlyMonster(monster) then<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
local avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2<br />
result = result..'<br/>'..monster.name..','..monster.dropCoins[1]..','..(monster.dropCoins[2])..','..avgGp<br />
end<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p._getMonsterAverageGP(monster)<br />
local result = ''<br />
local totalGP = 0<br />
<br />
local bones = p._getMonsterBones(monster)<br />
if bones ~= nil then<br />
totalGP = totalGP + bones.sellsFor * (type(monster.boneQty) == 'number' and monster.boneQty or 1)<br />
end<br />
<br />
--Likewise, seeing the loot table is tied to the monster appearing outside of dungeons<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100<br />
local lootValue = 0<br />
<br />
local avgGp = 0<br />
<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2<br />
end<br />
<br />
totalGP = totalGP + avgGp<br />
<br />
local multiDrop = Shared.tableCount(monster.lootTable) > 1<br />
local totalWt = 0<br />
for i, row in pairs(monster.lootTable) do<br />
totalWt = totalWt + row[2]<br />
end<br />
<br />
for i, row in Shared.skpairs(monster.lootTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
local maxQty = row[3]<br />
<br />
local itemPrice = thisItem.sellsFor ~= nil and thisItem.sellsFor or 0<br />
<br />
--Getting the drop chance<br />
local dropChance = (row[2] / totalWt * lootChance)<br />
<br />
--Adding to the average loot value based on price & dropchance<br />
lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((1 + maxQty) / 2))<br />
end<br />
<br />
totalGP = totalGP + lootValue<br />
end<br />
<br />
return Shared.round(totalGP, 2, 2)<br />
end<br />
<br />
function p.getMonsterAverageGP(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterAverageGP(monster)<br />
end<br />
<br />
function p.getMonsterEVTable(frame)<br />
local result = '{| class="wikitable sortable"'<br />
result = result..'\r\n!Monster!!Combat Level!!Average GP'<br />
for i, monsterTemp in Shared.skpairs(MonsterData.Monsters) do<br />
local monster = Shared.clone(monsterTemp)<br />
monster.id = i - 1<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local monsterGP = p._getMonsterAverageGP(monster)<br />
local combatLevel = p._getMonsterCombatLevel(monster, 'Combat Level')<br />
result = result..'\r\n|-\r\n|'..Icons.Icon({monster.name, type='monster', noicon=true})..'||'..combatLevel..'||'..monsterGP<br />
end<br />
end<br />
result = result..'\r\n|}'<br />
return result<br />
end<br />
<br />
function p.getSlayerTierMonsterTable(frame)<br />
-- Input validation<br />
local tier = frame.args ~= nil and frame.args[1] or frame<br />
local slayerTier = nil<br />
<br />
if tier == nil then<br />
return "ERROR: No tier specified[[Category:Pages with script errors]]"<br />
end<br />
<br />
if tonumber(tier) ~= nil then<br />
slayerTier = Constants.getSlayerTierByID(tonumber(tier))<br />
else<br />
slayerTier = Constants.getSlayerTier(tier)<br />
end<br />
<br />
if slayerTier == nil then<br />
return "ERROR: Invalid slayer tier[[Category:Pages with script errors]]"<br />
end<br />
<br />
-- Obtain required tier details<br />
local minLevel, maxLevel = slayerTier.minLevel, slayerTier.maxLevel<br />
<br />
-- Build list of monster IDs<br />
-- Right now hiddenMonsterIDs is empty<br />
local hiddenMonsterIDs = {}<br />
local monsterIDs = {}<br />
for i, monster in Shared.skpairs(MonsterData.Monsters) do<br />
if monster.canSlayer and not Shared.contains(hiddenMonsterIDs, i - 1) then<br />
local cmbLevel = p._getMonsterCombatLevel(monster)<br />
if cmbLevel >= minLevel and (maxLevel == nil or cmbLevel <= maxLevel) then<br />
table.insert(monsterIDs, i - 1)<br />
end<br />
end<br />
end<br />
<br />
if Shared.tableCount(monsterIDs) == 0 then<br />
-- Somehow no monsters are in the tier, return nothing<br />
return ''<br />
else<br />
return p._getMonsterTable(monsterIDs, true)<br />
end<br />
end<br />
<br />
function p.getFullMonsterTable(frame)<br />
local monsterIDs = {}<br />
for i = 0, Shared.tableCount(MonsterData.Monsters) - 1, 1 do<br />
table.insert(monsterIDs, i)<br />
end<br />
<br />
return p._getMonsterTable(monsterIDs, false)<br />
end<br />
<br />
function p._getMonsterTable(monsterIDs, excludeDungeons)<br />
--Making a single function for getting a table of monsters given a list of IDs.<br />
local hideDungeons = excludeDungeons ~= nil and excludeDungeons or false<br />
local tableParts = {}<br />
table.insert(tableParts, '{| class="wikitable sortable stickyHeader"')<br />
-- First header row<br />
table.insert(tableParts, '\r\n|- class="headerRow-0"\r\n! colspan="5" | !! colspan="4" |Offensive Stats !! colspan="3" |Evasion Rating !! colspan="4" |')<br />
-- Second header row<br />
table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n!Monster !!Name !!ID !!Combat Level ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Hitpoints', type='skill'}))<br />
table.insert(tableParts, '!!Attack Speed (s) !!colspan="2"|Max Hit !!Accuracy ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Defence', type='skill', notext=true}))<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Ranged', type='skill', notext=true}))<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Magic', type='skill', notext=true}))<br />
table.insert(tableParts, '!!' .. Icons.Icon({'Coins', notext=true, nolink=true}) .. ' Coins !!Bones !!Locations')<br />
<br />
-- Generate row per monster<br />
for i, monsterID in Shared.skpairs(monsterIDs) do<br />
local monster = p.getMonsterByID(monsterID)<br />
local cmbLevel = p._getMonsterCombatLevel(monster)<br />
local atkSpeed = p._getMonsterAttackSpeed(monster)<br />
local maxHit = p._getMonsterMaxHit(monster)<br />
local accR = p._getMonsterAR(monster)<br />
local evaR = {p._getMonsterER(monster, "Melee"), p._getMonsterER(monster, "Ranged"), p._getMonsterER(monster, "Magic")}<br />
<br />
local gpRange = {0, 0}<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
gpRange = {monster.dropCoins[1], monster.dropCoins[2]}<br />
end<br />
local gpTxt = nil<br />
if gpRange[1] >= gpRange[2] then<br />
gpTxt = Shared.formatnum(gpRange[1])<br />
else<br />
gpTxt = Shared.formatnum(gpRange[1]) .. ' - ' .. Shared.formatnum(gpRange[2])<br />
end<br />
local bones = p._getMonsterBones(monster)<br />
local boneTxt = (bones ~= nil and Icons.Icon({bones.name, type='item', notext=true})) or 'None'<br />
<br />
table.insert(tableParts, '\r\n|-\r\n|style="text-align: center;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:left" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:right" |' .. monsterID)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. cmbLevel .. '" |' .. Shared.formatnum(cmbLevel))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. p._getMonsterHP(monster) .. '" |' .. Shared.formatnum(p._getMonsterHP(monster)))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. atkSpeed .. '" |' .. Shared.round(atkSpeed, 1, 1))<br />
table.insert(tableParts, '\r\n|style="text-align:center;border-right:hidden" |' .. p._getMonsterStyleIcon({monster, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. maxHit .. '" |' .. Shared.formatnum(maxHit))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. accR .. '" |' .. Shared.formatnum(accR))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[1] .. '" |' .. Shared.formatnum(evaR[1]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[2] .. '" |' .. Shared.formatnum(evaR[2]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[3] .. '" |' .. Shared.formatnum(evaR[3]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:center" |' .. boneTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))<br />
end<br />
<br />
table.insert(tableParts, '\r\n|}')<br />
return table.concat(tableParts)<br />
end<br />
<br />
function p.getMattMonsterTable(frame)<br />
--Making a single function for getting a table of monsters given a list of IDs.<br />
local tableParts = {}<br />
table.insert(tableParts, '{| class="wikitable sortable stickyHeader"')<br />
-- Second header row<br />
table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n!Monster !!Name !!ID !!Combat Level ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Hitpoints', type='skill'}))<br />
table.insert(tableParts, '!!Attack Speed (s) !!colspan="2"|Max Hit !!Accuracy ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Defence', type='skill', notext=true}))<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Ranged', type='skill', notext=true}))<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Magic', type='skill', notext=true}))<br />
table.insert(tableParts, '!!' .. Icons.Icon({'Coins', notext=true, nolink=true}) .. ' Coins !!Avg. Kill Value!!Locations')<br />
<br />
-- Generate row per monster<br />
for i, monster in Shared.skpairs(MonsterData.Monsters) do<br />
local cmbLevel = p._getMonsterCombatLevel(monster)<br />
<br />
local gpRange = {0, 0}<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
gpRange = {monster.dropCoins[1], monster.dropCoins[2]}<br />
end<br />
local gpTxt = nil<br />
if gpRange[1] >= gpRange[2] then<br />
gpTxt = Shared.formatnum(gpRange[1])<br />
else<br />
gpTxt = Shared.formatnum(gpRange[1]) .. ' - ' .. Shared.formatnum(gpRange[2])<br />
end<br />
<br />
local lootVal = p._getMonsterLootValue(monster)<br />
local lootTxt = '0'<br />
if lootVal ~= 0 then<br />
lootTxt = Shared.formatnum(Shared.round(lootVal, 2, 2))<br />
end<br />
<br />
<br />
table.insert(tableParts, '\r\n|-\r\n|style="text-align: center;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:left" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:right" |' .. monster.id)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. cmbLevel .. '" |' .. Shared.formatnum(cmbLevel))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. p._getMonsterHP(monster) .. '" |' .. Shared.formatnum(p._getMonsterHP(monster)))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. lootVal .. '" |' .. lootTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))<br />
end<br />
<br />
table.insert(tableParts, '\r\n|}')<br />
return table.concat(tableParts)<br />
end<br />
<br />
function p.getMattMonsterTableV2(frame)<br />
--Making a single function for getting a table of monsters given a list of IDs.<br />
local tableParts = {}<br />
table.insert(tableParts, '{| class="wikitable sortable stickyHeader"')<br />
-- Second header row<br />
table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n!Monster !!Name !!Combat Level ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Hitpoints', type='skill'}))<br />
table.insert(tableParts, '!!' .. Icons.Icon({'Coins', notext=true, nolink=true}) .. ' Coins !!Avg. Kill Value !!Bones')<br />
<br />
-- Generate row per monster<br />
for i, monster in Shared.skpairs(MonsterData.Monsters) do<br />
local cmbLevel = p._getMonsterCombatLevel(monster)<br />
<br />
local gpRange = {0, 0}<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
gpRange = {monster.dropCoins[1], monster.dropCoins[2]}<br />
end<br />
local gpTxt = nil<br />
if gpRange[1] >= gpRange[2] then<br />
gpTxt = Shared.formatnum(gpRange[1])<br />
else<br />
gpTxt = Shared.formatnum(gpRange[1]) .. ' - ' .. Shared.formatnum(gpRange[2])<br />
end<br />
<br />
local lootVal = p._getMonsterLootValue(monster)<br />
local lootTxt = '0'<br />
if lootVal ~= 0 then<br />
lootTxt = Shared.formatnum(Shared.round(lootVal, 2, 2))<br />
end<br />
<br />
<br />
table.insert(tableParts, '\r\n|-\r\n|style="text-align: center;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:left" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))<br />
-- table.insert(tableParts, '\r\n|style="text-align:right" |' .. monster.id)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. cmbLevel .. '" |' .. Shared.formatnum(cmbLevel))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. p._getMonsterHP(monster) .. '" |' .. Shared.formatnum(p._getMonsterHP(monster)))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. atkSpeed .. '" |' .. Shared.round(atkSpeed, 1, 1))<br />
table.insert(tableParts, '\r\n|style="text-align:center;border-right:hidden" |' .. p._getMonsterStyleIcon({monster, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. maxHit .. '" |' .. Shared.formatnum(maxHit))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. accR .. '" |' .. Shared.formatnum(accR))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[1] .. '" |' .. Shared.formatnum(evaR[1]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[2] .. '" |' .. Shared.formatnum(evaR[2]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[3] .. '" |' .. Shared.formatnum(evaR[3]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. lootVal .. '" |' .. lootTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:center" |' .. boneTxt)<br />
-- table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))<br />
end<br />
<br />
table.insert(tableParts, '\r\n|}')<br />
return table.concat(tableParts)<br />
end<br />
<br />
function p.getSpecialAttackTable(frame)<br />
local spAttTable = {}<br />
<br />
for i, monster in ipairs(MonsterData.Monsters) do<br />
if monster.specialAttacks ~= nil and Shared.tableCount(monster.specialAttacks) > 0 then<br />
local overrideChance = (monster.overrideSpecialChances ~= nil and Shared.tableCount(monster.overrideSpecialChances) > 0)<br />
for j, spAtt in ipairs(monster.specialAttacks) do<br />
local attChance = (overrideChance and monster.overrideSpecialChances[j] or spAtt.defaultChance)<br />
if spAttTable[spAtt.id] == nil then<br />
spAttTable[spAtt.id] = { ['defn'] = spAtt, ['icons'] = {} }<br />
end<br />
if spAttTable[spAtt.id]['icons'][attChance] == nil then<br />
spAttTable[spAtt.id]['icons'][attChance] = {}<br />
end<br />
table.insert(spAttTable[spAtt.id]['icons'][attChance], Icons.Icon({ monster.name, type = 'monster' }))<br />
end<br />
end<br />
end<br />
<br />
local resultPart = {}<br />
table.insert(resultPart, '{|class="wikitable sortable stickyHeader"')<br />
table.insert(resultPart, '\r\n|- class="headerRow-0"')<br />
table.insert(resultPart, '\r\n!Name!!style="min-width:225px"|Monsters!!Chance!!Effect')<br />
<br />
for i, spAttData in Shared.skpairs(spAttTable) do<br />
local spAtt = spAttData.defn<br />
local firstRow = true<br />
local rowsSpanned = Shared.tableCount(spAttData.icons)<br />
local rowSuffix = ''<br />
if rowsSpanned > 1 then<br />
rowSuffix = '|rowspan="' .. rowsSpanned .. '"'<br />
end<br />
for chance, iconList in Shared.skpairs(spAttData.icons) do<br />
table.insert(resultPart, '\r\n|-')<br />
if firstRow then<br />
table.insert(resultPart, '\r\n' .. rowSuffix .. '| ' .. spAtt.name)<br />
end<br />
table.insert(resultPart, '\r\n|data-sort-value="' .. spAtt.name .. '"| ' .. table.concat(iconList, '<br/>'))<br />
table.insert(resultPart, '\r\n|data-sort-value="' .. chance .. '"| ' .. Shared.round(chance, 2, 0) .. '%')<br />
if firstRow then<br />
table.insert(resultPart, '\r\n' .. rowSuffix .. '| ' .. spAtt.description)<br />
firstRow = false<br />
end<br />
end<br />
end<br />
table.insert(resultPart, '\r\n|}')<br />
<br />
return table.concat(resultPart)<br />
end<br />
<br />
return p</div>
Roko
https://wiki.melvoridle.com/index.php?title=Module:Monsters&diff=51087
Module:Monsters
2022-02-19T13:15:17Z
<p>Roko: </p>
<hr />
<div>local p = {}<br />
<br />
local MonsterData = mw.loadData('Module:Monsters/data')<br />
<br />
local Constants = require('Module:Constants')<br />
local Areas = require('Module:CombatAreas')<br />
local Magic = require('Module:Magic')<br />
local Shared = require('Module:Shared')<br />
local Icons = require('Module:Icons')<br />
local Items = require('Module:Items')<br />
<br />
function p.getMonster(name)<br />
local result = nil<br />
if name == 'Spider (lv. 51)' or name == 'Spider' then<br />
return p.getMonsterByID(50)<br />
elseif name == 'Spider (lv. 52)' or name == 'Spider2' then<br />
return p.getMonsterByID(51)<br />
end<br />
<br />
for i, monster in pairs(MonsterData.Monsters) do<br />
if monster.name == name then<br />
result = Shared.clone(monster)<br />
--Make sure every monster has an ID, and account for the 1-based indexing of Lua<br />
result.id = i - 1<br />
break<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.getMonsterByID(ID)<br />
local result = Shared.clone(MonsterData.Monsters[ID + 1])<br />
if result ~= nil then<br />
result.id = ID<br />
return result<br />
else<br />
return nil<br />
end<br />
end<br />
<br />
function p.getPassive(name)<br />
local result = nil<br />
<br />
for i, passive in pairs(MonsterData.Passives) do<br />
if passive.name == name then<br />
result = Shared.clone(passive)<br />
--Make sure every passive has an ID, and account for the 1-based indexing of Lua<br />
result.id = i - 1<br />
break<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.getPassiveByID(ID)<br />
return MonsterData.Passives[ID + 1]<br />
end<br />
<br />
-- Given a list of monster IDs, calls statFunc with each monster and returns<br />
-- the lowest & highest values<br />
function p.getLowHighStat(idList, statFunc)<br />
local lowVal, highVal = nil, nil<br />
for i, monID in ipairs(idList) do<br />
local monster = p.getMonsterByID(monID)<br />
local statVal = statFunc(monster)<br />
if lowVal == nil or statVal < lowVal then lowVal = statVal end<br />
if highVal == nil or statVal > highVal then highVal = statVal end<br />
end<br />
return lowVal, highVal<br />
end<br />
<br />
function p._getMonsterStat(monster, statName)<br />
if statName == 'HP' then<br />
return p._getMonsterHP(monster)<br />
elseif statName == 'maxHit' then<br />
return p._getMonsterMaxHit(monster)<br />
elseif statName == 'accuracyRating' then<br />
return p._getMonsterAR(monster)<br />
elseif statName == 'meleeEvasionRating' then<br />
return p._getMonsterER(monster, 'Melee')<br />
elseif statName == 'rangedEvasionRating' then<br />
return p._getMonsterER(monster, 'Ranged')<br />
elseif statName == 'magicEvasionRating' then<br />
return p._getMonsterER(monster, 'Magic')<br />
elseif statName == 'damageReduction' then<br />
return p.getEquipmentStat(monster, 'damageReduction')<br />
end<br />
<br />
return monster[statName]<br />
end<br />
<br />
function p.getMonsterStat(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame[1]<br />
local StatName = frame.args ~= nil and frame.args[2] or frame[2]<br />
local monster = p.getMonster(MonsterName)<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterStat(monster, StatName)<br />
end<br />
<br />
function p._getMonsterStyleIcon(frame)<br />
local args = frame.args ~= nil and frame.args or frame<br />
local monster = args[1]<br />
local notext = args.notext<br />
local nolink = args.nolink<br />
<br />
local iconText = ''<br />
if monster.attackType == 'melee' then<br />
iconText = Icons.Icon({'Melee', notext=notext, nolink=nolink})<br />
elseif monster.attackType == 'ranged' then<br />
iconText = Icons.Icon({'Ranged', type='skill', notext=notext, nolink=nolink})<br />
elseif monster.attackType == 'magic' then<br />
iconText = Icons.Icon({'Magic', type='skill', notext=notext, nolink=nolink})<br />
elseif monster.attackType == 'random' then<br />
iconText = Icons.Icon({'Bane', notext=notext, nolink=nolink, img='Question'})<br />
end<br />
<br />
return iconText<br />
end<br />
<br />
function p.getMonsterStyleIcon(frame)<br />
local args = frame.args ~= nil and frame.args or frame<br />
local MonsterName = args[1]<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
args[1] = monster<br />
return p._getMonsterStyleIcon(args)<br />
end<br />
<br />
function p._getMonsterHP(monster)<br />
return 10 * p._getMonsterLevel(monster, 'Hitpoints')<br />
end<br />
<br />
function p.getMonsterEffectiveHP(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
if monster ~= nil then<br />
return math.floor((p._getMonsterHP(monster)/(1 - p._getMonsterStat(monster, 'damageReduction')/100)) + 0.5)<br />
else<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
end<br />
<br />
function p.getMonsterHP(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
if monster ~= nil then<br />
return p._getMonsterHP(monster)<br />
else<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
end<br />
<br />
function p._getMonsterLevel(monster, skillName)<br />
local result = 0<br />
if monster.levels[skillName] ~= nil then<br />
result = monster.levels[skillName]<br />
end<br />
return result<br />
end<br />
<br />
function p.getMonsterLevel(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame[1]<br />
local SkillName = frame.args ~= nil and frame.args[2] or frame[2]<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterLevel(monster, SkillName)<br />
end<br />
<br />
function p.getEquipmentStat(monster, statName)<br />
local result = 0<br />
for i, stat in Shared.skpairs(monster.equipmentStats) do<br />
if stat.key == statName then<br />
result = stat.value<br />
break<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.calculateStandardStat(effectiveLevel, bonus)<br />
--Based on calculateStandardStat in Characters.js<br />
return (effectiveLevel + 9) * (bonus + 64)<br />
end<br />
<br />
function p.calculateStandardMaxHit(baseLevel, strengthBonus)<br />
--Based on calculateStandardMaxHit in Characters.js<br />
local effectiveLevel = baseLevel + 9<br />
return math.floor(10 * (1.3 + effectiveLevel / 10 + strengthBonus / 80 + effectiveLevel * strengthBonus / 640))<br />
end<br />
<br />
function p._getMonsterAttackSpeed(monster)<br />
return p.getEquipmentStat(monster, 'attackSpeed') / 1000<br />
end<br />
<br />
function p.getMonsterAttackSpeed(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
if monster ~= nil then<br />
return p._getMonsterAttackSpeed(monster)<br />
else<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
end<br />
<br />
function p._getMonsterCombatLevel(monster)<br />
local base = 0.25 * (p._getMonsterLevel(monster, 'Defence') + p._getMonsterLevel(monster, 'Hitpoints'))<br />
local melee = 0.325 * (p._getMonsterLevel(monster, 'Attack') + p._getMonsterLevel(monster, 'Strength'))<br />
local range = 0.325 * (1.5 * p._getMonsterLevel(monster, 'Ranged'))<br />
local magic = 0.325 * (1.5 * p._getMonsterLevel(monster, 'Magic'))<br />
return math.floor(base + math.max(melee, range, magic))<br />
end<br />
<br />
function p.getMonsterCombatLevel(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterCombatLevel(monster)<br />
end<br />
<br />
function p._getMonsterAR(monster)<br />
local baseLevel = 0<br />
local bonus = 0<br />
if monster.attackType == 'melee' then<br />
baseLevel = p._getMonsterLevel(monster, 'Attack')<br />
bonus = p.getEquipmentStat(monster, 'stabAttackBonus')<br />
elseif monster.attackType == 'ranged' then<br />
baseLevel = p._getMonsterLevel(monster, 'Ranged')<br />
bonus = p.getEquipmentStat(monster, 'rangedAttackBonus')<br />
elseif monster.attackType == 'magic' then<br />
baseLevel = p._getMonsterLevel(monster, 'Magic')<br />
bonus = p.getEquipmentStat(monster, 'magicAttackBonus')<br />
elseif monster.attackType == 'random' then<br />
--Bane has the same AR with every attack type so being lazy and just showing the one.<br />
baseLevel = p._getMonsterLevel(monster, 'Attack')<br />
bonus = p.getEquipmentStat(monster, 'stabAttackBonus')<br />
else<br />
return "ERROR: This monster has an invalid attack type somehow[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p.calculateStandardStat(baseLevel, bonus)<br />
end<br />
<br />
function p.getMonsterAR(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterAR(monster)<br />
end<br />
<br />
function p._getMonsterER(monster, style)<br />
local baseLevel= 0<br />
local bonus = 0<br />
<br />
if style == "Melee" then<br />
baseLevel = p._getMonsterLevel(monster, 'Defence')<br />
bonus = p.getEquipmentStat(monster, 'meleeDefenceBonus')<br />
elseif style == "Ranged" then<br />
baseLevel = p._getMonsterLevel(monster, 'Defence')<br />
bonus = p.getEquipmentStat(monster, 'rangedDefenceBonus')<br />
elseif style == "Magic" then<br />
baseLevel = math.floor(p._getMonsterLevel(monster, 'Magic') * 0.7 + p._getMonsterLevel(monster, 'Defence') * 0.3)<br />
bonus = p.getEquipmentStat(monster, 'magicDefenceBonus')<br />
else<br />
return "ERROR: Must choose Melee, Ranged, or Magic[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p.calculateStandardStat(baseLevel, bonus)<br />
end<br />
<br />
function p.getMonsterER(frame)<br />
local args = frame.args ~= nil and frame.args or frame<br />
local MonsterName = args[1]<br />
local style = args[2]<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterER(monster, style)<br />
end<br />
<br />
-- Determines if the monster is capable of dropping bones, and returns the bones<br />
-- item if so, or nil otherwise<br />
function p._getMonsterBones(monster)<br />
if monster.bones ~= nil and monster.bones >= 0 then<br />
local boneItem = Items.getItemByID(monster.bones)<br />
if boneItem.prayerPoints == nil then<br />
-- Assume bones without prayer points are shards (from God dungeons),<br />
-- and drop unconditionally<br />
return boneItem<br />
elseif not monster.isBoss and not p._isDungeonOnlyMonster(monster) then<br />
-- Otherwise, bones drop when the monster isn't dungeon exclusive<br />
return boneItem<br />
end<br />
end<br />
end<br />
<br />
function p._isDungeonOnlyMonster(monster)<br />
local areaList = Areas.getMonsterAreas(monster.id)<br />
local inDungeon = false<br />
<br />
for i, area in ipairs(areaList) do<br />
if area.type == 'dungeon' then<br />
inDungeon = true<br />
else<br />
return false<br />
end<br />
end<br />
return inDungeon<br />
end<br />
<br />
function p.isDungeonOnlyMonster(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with name "..monsterName.." found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._isDungeonOnlyMonster(monster)<br />
end<br />
<br />
function p._getMonsterAreas(monster, excludeDungeons)<br />
local resultPart = {}<br />
local hideDungeons = excludeDungeons ~= nil and excludeDungeons or false<br />
local areaList = Areas.getMonsterAreas(monster.id)<br />
for i, area in ipairs(areaList) do<br />
if area.type ~= 'dungeon' or not hideDungeons then<br />
table.insert(resultPart, Icons.Icon({area.name, type = area.type}))<br />
end<br />
end<br />
return table.concat(resultPart, '<br/>')<br />
end<br />
<br />
function p.getMonsterAreas(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local hideDungeons = frame.args ~= nil and frame.args[2] or nil<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with name "..monsterName.." found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterAreas(monster, hideDungeons)<br />
end<br />
<br />
function p.getSpecAttackMaxHit(specAttack, normalMaxHit)<br />
local result = 0<br />
for i, dmg in pairs(specAttack.damage) do<br />
if dmg.maxRoll == 'Fixed' then<br />
result = dmg.maxPercent * 10<br />
elseif dmg.maxRoll == 'MaxHit' then<br />
if dmg.character == 'Target' then<br />
--Confusion applied damage based on the player's max hit. Gonna just ignore that one<br />
result = 0<br />
else<br />
result = dmg.maxPercent * normalMaxHit * 0.01<br />
end<br />
elseif Shared.contains({'Bleeding', 'Poisoned'}, dmg.maxRoll) then<br />
-- TODO: This is limited in that there is no verification that bleed/poison<br />
-- can be applied to the target, it is assumed that it can and so this applies<br />
result = result + dmg.maxPercent * 10<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.canSpecAttackApplyEffect(specAttack, effectType)<br />
local result = false<br />
for i, effect in pairs(specAttack.prehitEffects) do<br />
if effect.type == effectType then<br />
result = true<br />
break<br />
end<br />
end<br />
<br />
for i, effect in pairs(specAttack.onhitEffects) do<br />
if effect.type == effectType then<br />
result = true<br />
break<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p._getMonsterMaxHit(monster, doStuns)<br />
-- 2021-06-11 Adjusted for v0.20 stun/sleep changes, where damage multiplier now applies<br />
-- to all enemy attacks if stun/sleep is present on at least one special attack<br />
if doStuns == nil then<br />
doStuns = true<br />
elseif type(doStuns) == 'string' then<br />
doStuns = string.upper(doStuns) == 'TRUE'<br />
end<br />
<br />
local normalChance = 100<br />
local specialMaxHit = 0<br />
local normalMaxHit = p._getMonsterBaseMaxHit(monster)<br />
local hasActiveBuffSpec = false<br />
local damageMultiplier = 1<br />
if monster.specialAttacks[1] ~= nil then<br />
local canStun, canSleep = false, false<br />
for i, specAttack in pairs(monster.specialAttacks) do<br />
if monster.overrideSpecialChances ~= nil then<br />
normalChance = normalChance - monster.overrideSpecialChances[i]<br />
else<br />
normalChance = normalChance - specAttack.defaultChance<br />
end<br />
local thisMax = p.getSpecAttackMaxHit(specAttack, normalMaxHit)<br />
if not canStun and p.canSpecAttackApplyEffect(specAttack, 'Stun') then canStun = true end<br />
if not canSleep and p.canSpecAttackApplyEffect(specAttack, 'Sleep') then canSleep = true end<br />
<br />
if thisMax > specialMaxHit then specialMaxHit = thisMax end<br />
if Shared.contains(string.upper(specAttack.description), 'NORMAL ATTACK INSTEAD') then <br />
hasActiveBuffSpec = true <br />
end<br />
end<br />
<br />
if canSleep and doStuns then damageMultiplier = damageMultiplier * 1.2 end<br />
if canStun and doStuns then damageMultiplier = damageMultiplier * 1.3 end<br />
end<br />
--Ensure that if the monster never does a normal attack, the normal max hit is irrelevant<br />
if normalChance == 0 and not hasActiveBuffSpec then normalMaxHit = 0 end<br />
return math.floor(math.max(specialMaxHit, normalMaxHit) * damageMultiplier)<br />
end<br />
<br />
function p.getMonsterMaxHit(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local doStuns = frame.args ~= nil and frame.args[2] or true<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterMaxHit(monster, doStuns)<br />
end<br />
<br />
function p._getMonsterBaseMaxHit(monster)<br />
--8/27/21 - Now references p.calculateStandardMaxHit for Melee & Ranged<br />
local result = 0<br />
local baseLevel = 0<br />
local bonus = 0<br />
if monster.attackType == 'melee' then<br />
baseLevel = p._getMonsterLevel(monster, 'Strength')<br />
bonus = p.getEquipmentStat(monster, 'meleeStrengthBonus')<br />
result = p.calculateStandardMaxHit(baseLevel, bonus)<br />
elseif monster.attackType == 'ranged' then<br />
baseLevel = p._getMonsterLevel(monster, 'Ranged')<br />
bonus = p.getEquipmentStat(monster, 'rangedStrengthBonus')<br />
result = p.calculateStandardMaxHit(baseLevel, bonus)<br />
elseif monster.attackType == 'magic' then<br />
local mSpell = nil<br />
if monster.selectedSpell ~= nil then mSpell = Magic.getSpellByID('Spells', monster.selectedSpell) end<br />
<br />
bonus = p.getEquipmentStat(monster, 'magicDamageBonus')<br />
baseLevel = p._getMonsterLevel(monster, 'Magic')<br />
<br />
result = math.floor(10 * mSpell.maxHit * (1 + bonus / 100) * (1 + (baseLevel + 1) / 200))<br />
elseif monster.attackType == 'random' then<br />
local hitArray = {}<br />
local iconText = Icons.Icon({'Melee', notext=true})<br />
baseLevel = p._getMonsterLevel(monster, 'Strength')<br />
bonus = p.getEquipmentStat(monster, 'meleeStrengthBonus')<br />
table.insert(hitArray, p.calculateStandardMaxHit(baseLevel, bonus))<br />
<br />
iconText = Icons.Icon({'Ranged', type='skill', notext=true})<br />
baseLevel = p._getMonsterLevel(monster, 'Ranged')<br />
bonus = p.getEquipmentStat(monster, 'rangedStrengthBonus')<br />
table.insert(hitArray, p.calculateStandardMaxHit(baseLevel, bonus))<br />
<br />
iconText = Icons.Icon({'Magic', type='skill', notext=true})<br />
local mSpell = nil<br />
if monster.selectedSpell ~= nil then mSpell = Magic.getSpellByID('Spells', monster.selectedSpell) end<br />
bonus = p.getEquipmentStat(monster, 'magicDamageBonus')<br />
baseLevel = p._getMonsterLevel(monster, 'Magic')<br />
local magicDmg = math.floor(10 * mSpell.maxHit * (1 + bonus / 100) * (1 + (baseLevel + 1) / 200))<br />
table.insert(hitArray, magicDmg)<br />
<br />
local max = 0<br />
for i, val in pairs(hitArray) do<br />
if val > max then max = val end<br />
end<br />
result = max<br />
else<br />
return "ERROR: This monster has an invalid attack type somehow[[Category:Pages with script errors]]"<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getMonsterBaseMaxHit(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterBaseMaxHit(monster)<br />
end<br />
<br />
function p.getMonsterAttacks(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = ''<br />
local iconText = p._getMonsterStyleIcon({monster, notext=true})<br />
local typeText = ''<br />
if monster.attackType == 'melee' then<br />
typeText = 'Melee'<br />
elseif monster.attackType == 'ranged' then<br />
typeText = 'Ranged'<br />
elseif monster.attackType == 'magic' then<br />
typeText = 'Magic'<br />
elseif monster.attackType == 'random' then<br />
typeText = "Random"<br />
end<br />
<br />
local buffAttacks = {}<br />
local hasActiveBuffSpec = false<br />
<br />
local normalAttackChance = 100<br />
if monster.specialAttacks[1] ~= nil then<br />
for i, specAttack in pairs(monster.specialAttacks) do<br />
local attChance = 0<br />
if monster.overrideSpecialChances ~= nil then<br />
attChance = monster.overrideSpecialChances[i]<br />
else<br />
attChance = specAttack.defaultChance<br />
end<br />
normalAttackChance = normalAttackChance - attChance<br />
<br />
result = result..'\r\n* '..attChance..'% '..iconText..' '..specAttack.name..'\r\n** '..specAttack.description<br />
<br />
if Shared.contains(string.upper(specAttack.description), 'NORMAL ATTACK INSTEAD') then<br />
table.insert(buffAttacks, specAttack.name)<br />
hasActiveBuffSpec = true <br />
end<br />
end<br />
end<br />
if normalAttackChance == 100 then<br />
result = iconText..' 1 - '..p._getMonsterBaseMaxHit(monster)..' '..typeText..' Damage'<br />
elseif normalAttackChance > 0 then<br />
result = '* '..normalAttackChance..'% '..iconText..' 1 - '..p.getMonsterBaseMaxHit(frame)..' '..typeText..' Damage'..result<br />
elseif hasActiveBuffSpec then<br />
--If the monster normally has a 0% chance of doing a normal attack but some special attacks can't be repeated, include it<br />
--(With a note about when it does it)<br />
result = '* '..iconText..' 1 - '..p._getMonsterBaseMaxHit(monster)..' '..typeText..' Damage (Instead of repeating '..table.concat(buffAttacks, ' or ')..' while the effect is already active)'..result<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getMonsterPassives(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = ''<br />
if type(monster.passiveID) == 'table' and Shared.tableCount(monster.passiveID) > 0 then<br />
result = result .. '===Passives==='<br />
for i, passiveID in pairs(monster.passiveID) do<br />
local passive = p.getPassiveByID(passiveID)<br />
result = result .. '\r\n* ' .. passive.name .. '\r\n** ' .. passive.description<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.getMonsterCategories(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = '[[Category:Monsters]]'<br />
<br />
if monster.attackType == 'melee' then<br />
result = result..'[[Category:Melee Monsters]]'<br />
elseif monster.attackType == 'ranged' then<br />
result = result..'[[Category:Ranged Monsters]]'<br />
elseif monster.attackType == 'magic' then<br />
result = result..'[[Category:Magic Monsters]]'<br />
end<br />
<br />
if monster.specialAttacks[1] ~= nil then<br />
result = result..'[[Category:Monsters with Special Attacks]]'<br />
end<br />
<br />
if monster.isBoss then<br />
result = result..'[[Category:Bosses]]'<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getOtherMonsterBoxText(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = ''<br />
<br />
--Going through and finding out which damage bonuses will apply to this monster<br />
local monsterTypes = {}<br />
if monster.isBoss then table.insert(monsterTypes, 'Boss') end<br />
<br />
local areaList = Areas.getMonsterAreas(monster.id)<br />
local counts = {combat = 0, slayer = 0, dungeon = 0}<br />
for i, area in Shared.skpairs(areaList) do<br />
counts[area.type] = counts[area.type] + 1<br />
end<br />
<br />
if counts.combat > 0 then table.insert(monsterTypes, 'Combat Area') end<br />
if counts.slayer > 0 then table.insert(monsterTypes, 'Slayer Area') end<br />
if counts.dungeon > 0 then table.insert(monsterTypes, 'Dungeon') end<br />
<br />
result = result.."\r\n|-\r\n|'''Monster Types:''' "..table.concat(monsterTypes, ", ")<br />
<br />
local SlayerTier = 'N/A'<br />
if monster.canSlayer then<br />
SlayerTier = Constants.getSlayerTierNameByLevel(p._getMonsterCombatLevel(monster))<br />
end<br />
<br />
result = result.."\r\n|-\r\n|'''"..Icons.Icon({'Slayer', type='skill'}).." [[Slayer#Slayer Tier Monsters|Tier]]:''' "<br />
if monster.canSlayer then<br />
result = result.."[[Slayer#"..SlayerTier.."|"..SlayerTier.."]]"<br />
else<br />
result = result..SlayerTier<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getMonsterDrops(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = ''<br />
<br />
local bones = p._getMonsterBones(monster)<br />
local boneVal = 0<br />
--Show the bones only if either the monster shows up outside of dungeons _or_ the monster drops shards<br />
if bones ~= nil then<br />
local boneQty = (monster.boneQty ~= nil and monster.boneQty or 1)<br />
result = result.."'''Always Drops:'''"<br />
result = result..'\r\n{|class="wikitable" id="bonedrops"'<br />
result = result..'\r\n!Item !! Qty'<br />
result = result..'\r\n|-\r\n|'..Icons.Icon({bones.name, type='item'})<br />
result = result..'||'..boneQty..'\r\n'..'|}'<br />
boneVal = boneQty * bones.sellsFor<br />
end<br />
<br />
--Likewise, seeing the loot table is tied to the monster appearing outside of dungeons<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100<br />
local lootValue = 0<br />
<br />
result = result.."'''Loot:'''"<br />
local avgGp = 0<br />
<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2<br />
local gpTxt = Icons.GP(monster.dropCoins[1], monster.dropCoins[2])<br />
result = result.."\r\nIn addition to loot, the monster will also drop "..gpTxt..'.'<br />
end<br />
<br />
local multiDrop = Shared.tableCount(monster.lootTable) > 1<br />
local totalWt = 0<br />
for i, row in pairs(monster.lootTable) do<br />
totalWt = totalWt + row[2]<br />
end<br />
result = result..'\r\n{|class="wikitable sortable" id="itemdrops"'<br />
result = result..'\r\n!Item!!Qty'<br />
result = result..'!!Price!!colspan="2"|Chance'<br />
<br />
--Sort the loot table by weight in descending order<br />
table.sort(monster.lootTable, function(a, b) return a[2] > b[2] end)<br />
for i, row in Shared.skpairs(monster.lootTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
<br />
local maxQty = row[3]<br />
if thisItem ~= nil then<br />
result = result..'\r\n|-\r\n|'..Icons.Icon({thisItem.name, type='item'})<br />
else<br />
result = result..'\r\n|-\r\n|Unknown Item[[Category:Pages with script errors]]'<br />
end<br />
result = result..'||style="text-align:right" data-sort-value="'..maxQty..'"|'<br />
<br />
if maxQty > 1 then<br />
result = result.. '1 - '<br />
end<br />
result = result..Shared.formatnum(row[3])<br />
<br />
--Adding price columns<br />
local itemPrice = 0<br />
if thisItem == nil then<br />
result = result..'||data-sort-value="0"|???'<br />
else<br />
itemPrice = thisItem.sellsFor ~= nil and thisItem.sellsFor or 0<br />
if itemPrice == 0 or maxQty == 1 then<br />
result = result..'||'..Icons.GP(itemPrice)<br />
else<br />
result = result..'||'..Icons.GP(itemPrice, itemPrice * maxQty)<br />
end<br />
end<br />
<br />
--Getting the drop chance<br />
local dropChance = (row[2] / totalWt * lootChance)<br />
if dropChance < 100 then<br />
--Show fraction as long as it isn't going to be 1/1<br />
result = result..'||style="text-align:right" data-sort-value="'..row[2]..'"'<br />
result = result..'|'..Shared.fraction(row[2] * lootChance, totalWt * 100)<br />
result = result..'||'<br />
else<br />
result = result..'||colspan="2" data-sort-value="'..row[2]..'"'<br />
end<br />
-- If chance is less than 0.10% then show 2 significant figures, otherwise 2 decimal places<br />
local fmt = (dropChance < 0.10 and '%.2g') or '%.2f'<br />
result = result..'style="text-align:right"|'..string.format(fmt, dropChance)..'%'<br />
<br />
--Adding to the average loot value based on price & dropchance<br />
lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((1 + maxQty) / 2))<br />
end<br />
if multiDrop then<br />
result = result..'\r\n|-class="sortbottom" \r\n!colspan="3"|Total:'<br />
if lootChance < 100 then<br />
result = result..'\r\n|style="text-align:right"|'..Shared.fraction(lootChance, 100)..'||'<br />
else<br />
result = result..'\r\n|colspan="2" '<br />
end<br />
result = result..'style="text-align:right"|'..Shared.round(lootChance, 2, 2)..'%'<br />
end<br />
result = result..'\r\n|}'<br />
result = result..'\r\nThe loot dropped by the average kill is worth '..Icons.GP(Shared.round(lootValue, 2, 0)).." if sold."<br />
if avgGp > 0 then<br />
result = result.."<br/>Including GP"<br />
if boneVal > 0 then<br />
result = result..' and bones'<br />
end<br />
result = result..', the average kill is worth '..Icons.GP(Shared.round(avgGp + lootValue + boneVal, 2, 0))..'.'<br />
end<br />
end<br />
<br />
--If no other drops, make sure to at least say so.<br />
if result == '' then result = 'None' end<br />
return result<br />
end<br />
<br />
function p._getMonsterLootValue(monster)<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = 0<br />
local boneVal = 0<br />
<br />
local bones = p._getMonsterBones(monster)<br />
--Show the bones only if either the monster shows up outside of dungeons _or_ the monster drops shards<br />
if bones ~= nil then<br />
local boneQty = monster.boneQty ~= nil and monster.boneQty or 1<br />
boneVal = bones.sellsFor * boneQty<br />
result = result + boneVal<br />
end<br />
<br />
--Likewise, seeing the loot table is tied to the monster appearing outside of dungeons<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100<br />
local lootValue = 0<br />
<br />
local avgGp = 0<br />
<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2<br />
end<br />
<br />
local multiDrop = Shared.tableCount(monster.lootTable) > 1<br />
local totalWt = 0<br />
for i, row in pairs(monster.lootTable) do<br />
totalWt = totalWt + row[2]<br />
end<br />
<br />
for i, row in Shared.skpairs(monster.lootTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
<br />
local maxQty = row[3]<br />
<br />
--Adding price columns<br />
local itemPrice = 0<br />
if thisItem ~= nil then<br />
itemPrice = thisItem.sellsFor ~= nil and thisItem.sellsFor or 0<br />
end<br />
<br />
--Getting the drop chance<br />
local dropChance = (row[2] / totalWt * lootChance)<br />
--Adding to the average loot value based on price & dropchance<br />
lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((1 + maxQty) / 2))<br />
end<br />
if avgGp > 0 then<br />
result = result + avgGp + lootValue<br />
end<br />
end<br />
<br />
return result<br />
end<br />
<br />
-- Find drop chance of specified item from specified monster. <br />
-- Usage: |Monster Name|Item Name<br />
function p.getItemDropChance(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame[1]<br />
local ItemName = frame.args ~= nil and frame.args[2] or frame[2]<br />
<br />
local monster = p.getMonster(MonsterName)<br />
local item = Items.getItem(ItemName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
if item == nil then<br />
return "ERROR: No item with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100<br />
<br />
local totalWt = 0<br />
--for i, row in pairs(monster.lootTable) do<br />
--totalWt = totalWt + row[2]<br />
--end<br />
<br />
local dropChance = 0<br />
local dropWt = 0<br />
for i, row in Shared.skpairs(monster.lootTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
totalWt = totalWt + row[2]<br />
if item['id'] == thisItem['id'] then<br />
dropWt = row[2]<br />
end<br />
end<br />
dropChance = (dropWt / totalWt * lootChance)<br />
return Shared.round(dropChance, 2, 2)<br />
end<br />
end <br />
<br />
function p.getChestDrops(frame)<br />
local ChestName = frame.args ~= nil and frame.args[1] or frame<br />
local chest = Items.getItem(ChestName)<br />
<br />
if chest == nil then<br />
return "ERROR: No item named "..ChestName..' found[[Category:Pages with script errors]]'<br />
end<br />
<br />
local result = ''<br />
<br />
if chest.dropTable == nil then<br />
return "ERROR: "..ChestName.." does not have a drop table[[Category:Pages with script errors]]"<br />
else<br />
local lootChance = 100<br />
local lootValue = 0<br />
<br />
local multiDrop = Shared.tableCount(chest.dropTable) > 1<br />
local totalWt = 0<br />
for i, row in pairs(chest.dropTable) do<br />
totalWt = totalWt + row[2]<br />
end<br />
result = result..'\r\n{|class="wikitable sortable"'<br />
result = result..'\r\n!Item!!Qty'<br />
result = result..'!!colspan="2"|Chance!!Price'<br />
<br />
--Sort the loot table by weight in descending order<br />
for i, row in pairs(chest.dropTable) do<br />
if chest.dropQty ~= nil then<br />
table.insert(row, chest.dropQty[i])<br />
else<br />
table.insert(row, 1)<br />
end<br />
end<br />
table.sort(chest.dropTable, function(a, b) return a[2] > b[2] end)<br />
for i, row in Shared.skpairs(chest.dropTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
local qty = row[3]<br />
result = result..'\r\n|-\r\n|'..Icons.Icon({thisItem.name, type='item'})<br />
result = result..'||style="text-align:right" data-sort-value="'..qty..'"|'<br />
<br />
if qty > 1 then<br />
result = result.. '1 - '<br />
end<br />
result = result..Shared.formatnum(qty)<br />
<br />
local dropChance = (row[2] / totalWt) * 100<br />
result = result..'||style="text-align:right" data-sort-value="'..row[2]..'"'<br />
result = result..'|'..Shared.fraction(row[2], totalWt)<br />
<br />
result = result..'||style="text-align:right"|'..Shared.round(dropChance, 2, 2)..'%'<br />
<br />
result = result..'||style="text-align:left" data-sort-value="'..thisItem.sellsFor..'"'<br />
if qty > 1 then<br />
result = result..'|'..Icons.GP(thisItem.sellsFor, thisItem.sellsFor * qty)<br />
else<br />
result = result..'|'..Icons.GP(thisItem.sellsFor)<br />
end<br />
lootValue = lootValue + (dropChance * 0.01 * thisItem.sellsFor * ((1 + qty)/ 2))<br />
end<br />
result = result..'\r\n|}'<br />
result = result..'\r\nThe average value of the contents of one chest is '..Icons.GP(Shared.round(lootValue, 2, 0))..'.'<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getAreaMonsterTable(frame)<br />
local areaName = frame.args ~= nil and frame.args[1] or frame<br />
local area = Areas.getArea(areaName)<br />
if area == nil then<br />
return "ERROR: Could not find an area named "..areaName..'[[Category:Pages with script errors]]'<br />
end<br />
<br />
if area.type == 'dungeon' then<br />
return p.getDungeonMonsterTable(frame)<br />
end<br />
<br />
local tableTxt = '{| class="wikitable sortable"'<br />
tableTxt = tableTxt..'\r\n! Name !! Combat Level !! Hitpoints !! Max Hit !! [[Combat Triangle|Combat Style]]'<br />
for i, monsterID in pairs(area.monsters) do<br />
local monster = p.getMonsterByID(monsterID)<br />
tableTxt = tableTxt..'\r\n|-\r\n|'..Icons.Icon({monster.name, type='monster'})<br />
tableTxt = tableTxt..'||'..p._getMonsterCombatLevel(monster)<br />
tableTxt = tableTxt..'||'..Shared.formatnum(p._getMonsterHP(monster))<br />
tableTxt = tableTxt..'||'..Shared.formatnum(p._getMonsterMaxHit(monster))<br />
tableTxt = tableTxt..'||'..p._getMonsterStyleIcon({monster, nolink=true})<br />
end<br />
tableTxt = tableTxt..'\r\n|}'<br />
return tableTxt<br />
end<br />
<br />
function p.getDungeonMonsterTable(frame)<br />
local areaName = frame.args ~= nil and frame.args[1] or frame<br />
local area = Areas.getArea(areaName)<br />
if area == nil then<br />
return "ERROR: Could not find a dungeon named "..areaName..'[[Category:Pages with script errors]]'<br />
end<br />
<br />
--For Dungeons, go through and count how many of each monster are in the dungeon first<br />
local monsterCounts = {}<br />
for i, monsterID in pairs(area.monsters) do<br />
if monsterCounts[monsterID] == nil then<br />
monsterCounts[monsterID] = 1<br />
else<br />
monsterCounts[monsterID] = monsterCounts[monsterID] + 1<br />
end<br />
end<br />
<br />
local usedMonsters = {}<br />
<br />
-- Declare function for building table rows to avoid repeating code<br />
local buildRow = function(entityID, monsterCount, specialType)<br />
local monIcon, monLevel, monHP, monMaxHit, monStyle, monCount<br />
local monData = {}<br />
if specialType ~= nil and Shared.contains({'Afflicted', 'SlayerArea'}, specialType) then<br />
-- Special handling for Into the Mist<br />
if specialType == 'Afflicted' then<br />
local iconQ = Icons.Icon({'Into the Mist', notext=true, nolink=true, img='Question'})<br />
monIcon = Icons.Icon({'Into the Mist', 'Afflicted Monster', nolink=true, img='Question'})<br />
monLevel, monHP, monMaxHit, monStyle, monCount = iconQ, iconQ, iconQ, iconQ, monsterCount<br />
elseif specialType == 'SlayerArea' then<br />
-- entityID corresponds to a slayer area<br />
local area = Areas.getAreaByID('slayer', entityID)<br />
monIcon = Icons.Icon({area.name, type='combatArea'}) .. ' Monsters'<br />
monLevel = {p.getLowHighStat(area.monsters, function(monster) return p._getMonsterCombatLevel(monster) end)}<br />
monHP = {p.getLowHighStat(area.monsters, function(monster) return p._getMonsterHP(monster) end)}<br />
local lowMaxHit, highMaxHit = p.getLowHighStat(area.monsters, function(monster) return p._getMonsterMaxHit(monster) end)<br />
monMaxHit = highMaxHit<br />
monStyle = Icons.Icon({area.name, area.name, notext=true, nolink=true, img='Question'})<br />
monCount = monsterCount<br />
end<br />
else<br />
-- entityID corresponds to a monster<br />
local monster = p.getMonsterByID(entityID)<br />
monIcon = Icons.Icon({monster.name, type='monster'})<br />
monLevel = p._getMonsterCombatLevel(monster)<br />
monHP = p._getMonsterHP(monster)<br />
monMaxHit = p._getMonsterMaxHit(monster)<br />
monStyle = p._getMonsterStyleIcon({monster})<br />
monCount = monsterCount<br />
end<br />
local getValSort = function(val)<br />
if type(val) == 'table' then<br />
if type(val[1]) == 'number' and type(val[2]) == 'number' then<br />
return (val[1] + val[2]) / 2<br />
else<br />
return (type(val[1]) == 'number' and val[1]) or 0<br />
end<br />
else<br />
return (type(val) == 'number' and val) or 0<br />
end<br />
end<br />
local getValText = function(val)<br />
if type(val) == 'table' and Shared.tableCount(val) == 2 then<br />
if type(val[1]) == 'number' and type(val[2]) == 'number' then<br />
return Shared.formatnum(val[1]) .. ' - ' .. Shared.formatnum(val[2])<br />
else<br />
return val[1] .. ' - ' .. val[2]<br />
end<br />
elseif type(val) == 'number' then<br />
return Shared.formatnum(val)<br />
else<br />
return val<br />
end<br />
end<br />
<br />
local resultPart = {}<br />
table.insert(resultPart, '\r\n|-\r\n| ' .. monIcon)<br />
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monLevel) .. '"| ' .. getValText(monLevel))<br />
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monHP) .. '"| ' .. getValText(monHP))<br />
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monMaxHit) .. '"| ' .. getValText(monMaxHit))<br />
table.insert(resultPart, '\r\n| ' .. monStyle)<br />
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monCount) .. '"| ' .. getValText(monCount))<br />
return table.concat(resultPart)<br />
end<br />
<br />
local returnPart = {}<br />
table.insert(returnPart, '{| class="wikitable sortable"')<br />
table.insert(returnPart, '\r\n! Name !! Combat Level !! Hitpoints !! Max Hit !! [[Combat Triangle|Combat Style]] !! Count')<br />
-- Special handing for Impending Darkness event<br />
-- TODO needs to be revised once there is a better understanding of how the event works<br />
--if area.isEvent ~= nil and area.isEvent then<br />
-- for i, eventAreaID in ipairs(Areas.eventData.slayerAreas) do<br />
-- table.insert(returnPart, buildRow(eventAreaID, {5, 8}, 'SlayerArea'))<br />
-- end<br />
-- -- Add Bane * 4<br />
-- table.insert(returnPart, buildRow(152, 4))<br />
--end<br />
for i, monsterID in pairs(area.monsters) do<br />
if not Shared.contains(usedMonsters, monsterID) then<br />
if monsterID >= 0 then<br />
table.insert(returnPart, buildRow(monsterID, monsterCounts[monsterID]))<br />
else<br />
--Special handling for Into the Mist<br />
table.insert(returnPart, buildRow(monsterID, monsterCounts[monsterID], 'Afflicted'))<br />
end<br />
table.insert(usedMonsters, monsterID)<br />
end<br />
end<br />
table.insert(returnPart, '\r\n|}')<br />
return table.concat(returnPart)<br />
end<br />
<br />
function p.getDungeonTotalHp(frame)<br />
local areaName = frame.args ~= nil and frame.args[1] or frame<br />
local area = Areas.getArea(areaName)<br />
if area == nil then<br />
return "ERROR: Could not find a dungeon named "..areaName..'[[Category:Pages with script errors]]'<br />
end<br />
local totalHP = 0<br />
<br />
for i, monsterID in pairs(area.monsters) do<br />
if not Shared.contains(usedMonsters, monsterID) then<br />
local monster = p.getMonsterByID(monsterID)<br />
totalHP = totalHP + p._getMonsterHP(monster)<br />
end<br />
end<br />
return totalHP<br />
end<br />
<br />
function p._getAreaMonsterList(area)<br />
local monsterList = {}<br />
for i, monsterID in pairs(area.monsters) do<br />
local monster = p.getMonsterByID(monsterID)<br />
table.insert(monsterList, Icons.Icon({monster.name, type='monster'}))<br />
end<br />
return table.concat(monsterList, '<br/>')<br />
end<br />
<br />
function p._getDungeonMonsterList(area)<br />
local monsterList = {}<br />
local lastMonster = nil<br />
local lastID = -2<br />
local count = 0<br />
-- Special handing for Impending Darkness event<br />
-- TODO needs to be revised once there is a better understanding of how the event works<br />
--if area.isEvent ~= nil and area.isEvent then<br />
-- for i, eventAreaID in ipairs(Areas.eventData.slayerAreas) do<br />
-- local eventArea = Areas.getAreaByID('slayer', eventAreaID)<br />
-- table.insert(monsterList, '5-8 ' .. Icons.Icon({eventArea.name, type='combatArea'}) .. ' Monsters')<br />
-- end<br />
-- table.insert(monsterList, '4 ' .. Icons.Icon({'Bane', type='monster'}))<br />
--end<br />
for i, monsterID in Shared.skpairs(area.monsters) do<br />
if monsterID ~= lastID then<br />
local monster = nil <br />
if monsterID ~= -1 then monster = p.getMonsterByID(monsterID) end<br />
if lastID ~= -2 then<br />
if lastID == -1 then<br />
--Special handling for Afflicted Monsters<br />
table.insert(monsterList, Icons.Icon({'Affliction', 'Afflicted Monster', img='Question', qty=count}))<br />
else<br />
local name = lastMonster.name<br />
table.insert(monsterList, Icons.Icon({name, type='monster', qty=count}))<br />
end<br />
end<br />
lastMonster = monster<br />
lastID = monsterID<br />
count = 1<br />
else<br />
count = count + 1<br />
end<br />
--Make sure the final monster in the dungeon gets counted<br />
if i == Shared.tableCount(area.monsters) then<br />
local name = lastMonster.name<br />
table.insert(monsterList, Icons.Icon({lastMonster.name, type='monster', qty=count}))<br />
end<br />
end<br />
return table.concat(monsterList, '<br/>')<br />
end<br />
<br />
function p.getAreaMonsterList(frame)<br />
local areaName = frame.args ~= nil and frame.args[1] or frame<br />
local area = Areas.getArea(areaName)<br />
if area == nil then<br />
return "ERROR: Could not find an area named "..areaName..'[[Category:Pages with script errors]]'<br />
end<br />
<br />
if area.type == 'dungeon' then<br />
return p._getDungeonMonsterList(area)<br />
else<br />
return p._getAreaMonsterList(area)<br />
end<br />
end<br />
<br />
function p.getFoxyTable(frame)<br />
local result = 'Monster,Min GP,Max GP,Average GP'<br />
for i, monster in Shared.skpairs(MonsterData.Monsters) do<br />
if not p._isDungeonOnlyMonster(monster) then<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
local avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2<br />
result = result..'<br/>'..monster.name..','..monster.dropCoins[1]..','..(monster.dropCoins[2])..','..avgGp<br />
end<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p._getMonsterAverageGP(monster)<br />
local result = ''<br />
local totalGP = 0<br />
<br />
local bones = p._getMonsterBones(monster)<br />
if bones ~= nil then<br />
totalGP = totalGP + bones.sellsFor * (type(monster.boneQty) == 'number' and monster.boneQty or 1)<br />
end<br />
<br />
--Likewise, seeing the loot table is tied to the monster appearing outside of dungeons<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100<br />
local lootValue = 0<br />
<br />
local avgGp = 0<br />
<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2<br />
end<br />
<br />
totalGP = totalGP + avgGp<br />
<br />
local multiDrop = Shared.tableCount(monster.lootTable) > 1<br />
local totalWt = 0<br />
for i, row in pairs(monster.lootTable) do<br />
totalWt = totalWt + row[2]<br />
end<br />
<br />
for i, row in Shared.skpairs(monster.lootTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
local maxQty = row[3]<br />
<br />
local itemPrice = thisItem.sellsFor ~= nil and thisItem.sellsFor or 0<br />
<br />
--Getting the drop chance<br />
local dropChance = (row[2] / totalWt * lootChance)<br />
<br />
--Adding to the average loot value based on price & dropchance<br />
lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((1 + maxQty) / 2))<br />
end<br />
<br />
totalGP = totalGP + lootValue<br />
end<br />
<br />
return Shared.round(totalGP, 2, 2)<br />
end<br />
<br />
function p.getMonsterAverageGP(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterAverageGP(monster)<br />
end<br />
<br />
function p.getMonsterEVTable(frame)<br />
local result = '{| class="wikitable sortable"'<br />
result = result..'\r\n!Monster!!Combat Level!!Average GP'<br />
for i, monsterTemp in Shared.skpairs(MonsterData.Monsters) do<br />
local monster = Shared.clone(monsterTemp)<br />
monster.id = i - 1<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local monsterGP = p._getMonsterAverageGP(monster)<br />
local combatLevel = p._getMonsterCombatLevel(monster, 'Combat Level')<br />
result = result..'\r\n|-\r\n|'..Icons.Icon({monster.name, type='monster', noicon=true})..'||'..combatLevel..'||'..monsterGP<br />
end<br />
end<br />
result = result..'\r\n|}'<br />
return result<br />
end<br />
<br />
function p.getSlayerTierMonsterTable(frame)<br />
-- Input validation<br />
local tier = frame.args ~= nil and frame.args[1] or frame<br />
local slayerTier = nil<br />
<br />
if tier == nil then<br />
return "ERROR: No tier specified[[Category:Pages with script errors]]"<br />
end<br />
<br />
if tonumber(tier) ~= nil then<br />
slayerTier = Constants.getSlayerTierByID(tonumber(tier))<br />
else<br />
slayerTier = Constants.getSlayerTier(tier)<br />
end<br />
<br />
if slayerTier == nil then<br />
return "ERROR: Invalid slayer tier[[Category:Pages with script errors]]"<br />
end<br />
<br />
-- Obtain required tier details<br />
local minLevel, maxLevel = slayerTier.minLevel, slayerTier.maxLevel<br />
<br />
-- Build list of monster IDs<br />
-- Right now hiddenMonsterIDs is empty<br />
local hiddenMonsterIDs = {}<br />
local monsterIDs = {}<br />
for i, monster in Shared.skpairs(MonsterData.Monsters) do<br />
if monster.canSlayer and not Shared.contains(hiddenMonsterIDs, i - 1) then<br />
local cmbLevel = p._getMonsterCombatLevel(monster)<br />
if cmbLevel >= minLevel and (maxLevel == nil or cmbLevel <= maxLevel) then<br />
table.insert(monsterIDs, i - 1)<br />
end<br />
end<br />
end<br />
<br />
if Shared.tableCount(monsterIDs) == 0 then<br />
-- Somehow no monsters are in the tier, return nothing<br />
return ''<br />
else<br />
return p._getMonsterTable(monsterIDs, true)<br />
end<br />
end<br />
<br />
function p.getFullMonsterTable(frame)<br />
local monsterIDs = {}<br />
for i = 0, Shared.tableCount(MonsterData.Monsters) - 1, 1 do<br />
table.insert(monsterIDs, i)<br />
end<br />
<br />
return p._getMonsterTable(monsterIDs, false)<br />
end<br />
<br />
function p._getMonsterTable(monsterIDs, excludeDungeons)<br />
--Making a single function for getting a table of monsters given a list of IDs.<br />
local hideDungeons = excludeDungeons ~= nil and excludeDungeons or false<br />
local tableParts = {}<br />
table.insert(tableParts, '{| class="wikitable sortable stickyHeader"')<br />
-- First header row<br />
table.insert(tableParts, '\r\n|- class="headerRow-0"\r\n! colspan="5" | !! colspan="4" |Offensive Stats !! colspan="3" |Evasion Rating !! colspan="4" |')<br />
-- Second header row<br />
table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n!Monster !!Name !!ID !!Combat Level ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Hitpoints', type='skill'}))<br />
table.insert(tableParts, '!!Attack Speed (s) !!colspan="2"|Max Hit !!Accuracy ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Defence', type='skill', notext=true}))<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Ranged', type='skill', notext=true}))<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Magic', type='skill', notext=true}))<br />
table.insert(tableParts, '!!' .. Icons.Icon({'Coins', notext=true, nolink=true}) .. ' Coins !!Bones !!Locations')<br />
<br />
-- Generate row per monster<br />
for i, monsterID in Shared.skpairs(monsterIDs) do<br />
local monster = p.getMonsterByID(monsterID)<br />
local cmbLevel = p._getMonsterCombatLevel(monster)<br />
local atkSpeed = p._getMonsterAttackSpeed(monster)<br />
local maxHit = p._getMonsterMaxHit(monster)<br />
local accR = p._getMonsterAR(monster)<br />
local evaR = {p._getMonsterER(monster, "Melee"), p._getMonsterER(monster, "Ranged"), p._getMonsterER(monster, "Magic")}<br />
<br />
local gpRange = {0, 0}<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
gpRange = {monster.dropCoins[1], monster.dropCoins[2]}<br />
end<br />
local gpTxt = nil<br />
if gpRange[1] >= gpRange[2] then<br />
gpTxt = Shared.formatnum(gpRange[1])<br />
else<br />
gpTxt = Shared.formatnum(gpRange[1]) .. ' - ' .. Shared.formatnum(gpRange[2])<br />
end<br />
local bones = p._getMonsterBones(monster)<br />
local boneTxt = (bones ~= nil and Icons.Icon({bones.name, type='item', notext=true})) or 'None'<br />
<br />
table.insert(tableParts, '\r\n|-\r\n|style="text-align: center;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:left" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:right" |' .. monsterID)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. cmbLevel .. '" |' .. Shared.formatnum(cmbLevel))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. p._getMonsterHP(monster) .. '" |' .. Shared.formatnum(p._getMonsterHP(monster)))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. atkSpeed .. '" |' .. Shared.round(atkSpeed, 1, 1))<br />
table.insert(tableParts, '\r\n|style="text-align:center;border-right:hidden" |' .. p._getMonsterStyleIcon({monster, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. maxHit .. '" |' .. Shared.formatnum(maxHit))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. accR .. '" |' .. Shared.formatnum(accR))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[1] .. '" |' .. Shared.formatnum(evaR[1]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[2] .. '" |' .. Shared.formatnum(evaR[2]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[3] .. '" |' .. Shared.formatnum(evaR[3]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:center" |' .. boneTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))<br />
end<br />
<br />
table.insert(tableParts, '\r\n|}')<br />
return table.concat(tableParts)<br />
end<br />
<br />
function p.getMattMonsterTable(frame)<br />
--Making a single function for getting a table of monsters given a list of IDs.<br />
local tableParts = {}<br />
table.insert(tableParts, '{| class="wikitable sortable stickyHeader"')<br />
-- Second header row<br />
table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n!Monster !!Name !!ID !!Combat Level ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Hitpoints', type='skill'}))<br />
table.insert(tableParts, '!!' .. Icons.Icon({'Coins', notext=true, nolink=true}) .. ' Coins !!Avg. Kill Value!!Locations')<br />
<br />
-- Generate row per monster<br />
for i, monster in Shared.skpairs(MonsterData.Monsters) do<br />
local cmbLevel = p._getMonsterCombatLevel(monster)<br />
<br />
local gpRange = {0, 0}<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
gpRange = {monster.dropCoins[1], monster.dropCoins[2]}<br />
end<br />
local gpTxt = nil<br />
if gpRange[1] >= gpRange[2] then<br />
gpTxt = Shared.formatnum(gpRange[1])<br />
else<br />
gpTxt = Shared.formatnum(gpRange[1]) .. ' - ' .. Shared.formatnum(gpRange[2])<br />
end<br />
<br />
local lootVal = p._getMonsterLootValue(monster)<br />
local lootTxt = '0'<br />
if lootVal ~= 0 then<br />
lootTxt = Shared.formatnum(Shared.round(lootVal, 2, 2))<br />
end<br />
<br />
<br />
table.insert(tableParts, '\r\n|-\r\n|style="text-align: center;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:left" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:right" |' .. monster.id)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. cmbLevel .. '" |' .. Shared.formatnum(cmbLevel))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. p._getMonsterHP(monster) .. '" |' .. Shared.formatnum(p._getMonsterHP(monster)))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. lootVal .. '" |' .. lootTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))<br />
end<br />
<br />
table.insert(tableParts, '\r\n|}')<br />
return table.concat(tableParts)<br />
end<br />
<br />
function p.getMattMonsterTableV2(frame)<br />
--Making a single function for getting a table of monsters given a list of IDs.<br />
local tableParts = {}<br />
table.insert(tableParts, '{| class="wikitable sortable stickyHeader"')<br />
-- Second header row<br />
table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n!Monster !!Name !!Combat Level ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Hitpoints', type='skill'}))<br />
table.insert(tableParts, '!!' .. Icons.Icon({'Coins', notext=true, nolink=true}) .. ' Coins !!Avg. Kill Value!!Locations')<br />
<br />
-- Generate row per monster<br />
for i, monster in Shared.skpairs(MonsterData.Monsters) do<br />
local cmbLevel = p._getMonsterCombatLevel(monster)<br />
<br />
local gpRange = {0, 0}<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
gpRange = {monster.dropCoins[1], monster.dropCoins[2]}<br />
end<br />
local gpTxt = nil<br />
if gpRange[1] >= gpRange[2] then<br />
gpTxt = Shared.formatnum(gpRange[1])<br />
else<br />
gpTxt = Shared.formatnum(gpRange[1]) .. ' - ' .. Shared.formatnum(gpRange[2])<br />
end<br />
<br />
local lootVal = p._getMonsterLootValue(monster)<br />
local lootTxt = '0'<br />
if lootVal ~= 0 then<br />
lootTxt = Shared.formatnum(Shared.round(lootVal, 2, 2))<br />
end<br />
<br />
<br />
table.insert(tableParts, '\r\n|-\r\n|style="text-align: center;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:left" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))<br />
-- table.insert(tableParts, '\r\n|style="text-align:right" |' .. monster.id)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. cmbLevel .. '" |' .. Shared.formatnum(cmbLevel))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. p._getMonsterHP(monster) .. '" |' .. Shared.formatnum(p._getMonsterHP(monster)))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. lootVal .. '" |' .. lootTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))<br />
end<br />
<br />
table.insert(tableParts, '\r\n|}')<br />
return table.concat(tableParts)<br />
end<br />
<br />
function p.getSpecialAttackTable(frame)<br />
local spAttTable = {}<br />
<br />
for i, monster in ipairs(MonsterData.Monsters) do<br />
if monster.specialAttacks ~= nil and Shared.tableCount(monster.specialAttacks) > 0 then<br />
local overrideChance = (monster.overrideSpecialChances ~= nil and Shared.tableCount(monster.overrideSpecialChances) > 0)<br />
for j, spAtt in ipairs(monster.specialAttacks) do<br />
local attChance = (overrideChance and monster.overrideSpecialChances[j] or spAtt.defaultChance)<br />
if spAttTable[spAtt.id] == nil then<br />
spAttTable[spAtt.id] = { ['defn'] = spAtt, ['icons'] = {} }<br />
end<br />
if spAttTable[spAtt.id]['icons'][attChance] == nil then<br />
spAttTable[spAtt.id]['icons'][attChance] = {}<br />
end<br />
table.insert(spAttTable[spAtt.id]['icons'][attChance], Icons.Icon({ monster.name, type = 'monster' }))<br />
end<br />
end<br />
end<br />
<br />
local resultPart = {}<br />
table.insert(resultPart, '{|class="wikitable sortable stickyHeader"')<br />
table.insert(resultPart, '\r\n|- class="headerRow-0"')<br />
table.insert(resultPart, '\r\n!Name!!style="min-width:225px"|Monsters!!Chance!!Effect')<br />
<br />
for i, spAttData in Shared.skpairs(spAttTable) do<br />
local spAtt = spAttData.defn<br />
local firstRow = true<br />
local rowsSpanned = Shared.tableCount(spAttData.icons)<br />
local rowSuffix = ''<br />
if rowsSpanned > 1 then<br />
rowSuffix = '|rowspan="' .. rowsSpanned .. '"'<br />
end<br />
for chance, iconList in Shared.skpairs(spAttData.icons) do<br />
table.insert(resultPart, '\r\n|-')<br />
if firstRow then<br />
table.insert(resultPart, '\r\n' .. rowSuffix .. '| ' .. spAtt.name)<br />
end<br />
table.insert(resultPart, '\r\n|data-sort-value="' .. spAtt.name .. '"| ' .. table.concat(iconList, '<br/>'))<br />
table.insert(resultPart, '\r\n|data-sort-value="' .. chance .. '"| ' .. Shared.round(chance, 2, 0) .. '%')<br />
if firstRow then<br />
table.insert(resultPart, '\r\n' .. rowSuffix .. '| ' .. spAtt.description)<br />
firstRow = false<br />
end<br />
end<br />
end<br />
table.insert(resultPart, '\r\n|}')<br />
<br />
return table.concat(resultPart)<br />
end<br />
<br />
return p</div>
Roko
https://wiki.melvoridle.com/index.php?title=User:Roko&diff=51086
User:Roko
2022-02-19T13:14:07Z
<p>Roko: </p>
<hr />
<div>{{#invoke:Monsters|getMattMonsterTableV2}}</div>
Roko
https://wiki.melvoridle.com/index.php?title=Module:Monsters&diff=51085
Module:Monsters
2022-02-19T13:13:45Z
<p>Roko: making another version of the MattMonsterTable</p>
<hr />
<div>local p = {}<br />
<br />
local MonsterData = mw.loadData('Module:Monsters/data')<br />
<br />
local Constants = require('Module:Constants')<br />
local Areas = require('Module:CombatAreas')<br />
local Magic = require('Module:Magic')<br />
local Shared = require('Module:Shared')<br />
local Icons = require('Module:Icons')<br />
local Items = require('Module:Items')<br />
<br />
function p.getMonster(name)<br />
local result = nil<br />
if name == 'Spider (lv. 51)' or name == 'Spider' then<br />
return p.getMonsterByID(50)<br />
elseif name == 'Spider (lv. 52)' or name == 'Spider2' then<br />
return p.getMonsterByID(51)<br />
end<br />
<br />
for i, monster in pairs(MonsterData.Monsters) do<br />
if monster.name == name then<br />
result = Shared.clone(monster)<br />
--Make sure every monster has an ID, and account for the 1-based indexing of Lua<br />
result.id = i - 1<br />
break<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.getMonsterByID(ID)<br />
local result = Shared.clone(MonsterData.Monsters[ID + 1])<br />
if result ~= nil then<br />
result.id = ID<br />
return result<br />
else<br />
return nil<br />
end<br />
end<br />
<br />
function p.getPassive(name)<br />
local result = nil<br />
<br />
for i, passive in pairs(MonsterData.Passives) do<br />
if passive.name == name then<br />
result = Shared.clone(passive)<br />
--Make sure every passive has an ID, and account for the 1-based indexing of Lua<br />
result.id = i - 1<br />
break<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.getPassiveByID(ID)<br />
return MonsterData.Passives[ID + 1]<br />
end<br />
<br />
-- Given a list of monster IDs, calls statFunc with each monster and returns<br />
-- the lowest & highest values<br />
function p.getLowHighStat(idList, statFunc)<br />
local lowVal, highVal = nil, nil<br />
for i, monID in ipairs(idList) do<br />
local monster = p.getMonsterByID(monID)<br />
local statVal = statFunc(monster)<br />
if lowVal == nil or statVal < lowVal then lowVal = statVal end<br />
if highVal == nil or statVal > highVal then highVal = statVal end<br />
end<br />
return lowVal, highVal<br />
end<br />
<br />
function p._getMonsterStat(monster, statName)<br />
if statName == 'HP' then<br />
return p._getMonsterHP(monster)<br />
elseif statName == 'maxHit' then<br />
return p._getMonsterMaxHit(monster)<br />
elseif statName == 'accuracyRating' then<br />
return p._getMonsterAR(monster)<br />
elseif statName == 'meleeEvasionRating' then<br />
return p._getMonsterER(monster, 'Melee')<br />
elseif statName == 'rangedEvasionRating' then<br />
return p._getMonsterER(monster, 'Ranged')<br />
elseif statName == 'magicEvasionRating' then<br />
return p._getMonsterER(monster, 'Magic')<br />
elseif statName == 'damageReduction' then<br />
return p.getEquipmentStat(monster, 'damageReduction')<br />
end<br />
<br />
return monster[statName]<br />
end<br />
<br />
function p.getMonsterStat(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame[1]<br />
local StatName = frame.args ~= nil and frame.args[2] or frame[2]<br />
local monster = p.getMonster(MonsterName)<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterStat(monster, StatName)<br />
end<br />
<br />
function p._getMonsterStyleIcon(frame)<br />
local args = frame.args ~= nil and frame.args or frame<br />
local monster = args[1]<br />
local notext = args.notext<br />
local nolink = args.nolink<br />
<br />
local iconText = ''<br />
if monster.attackType == 'melee' then<br />
iconText = Icons.Icon({'Melee', notext=notext, nolink=nolink})<br />
elseif monster.attackType == 'ranged' then<br />
iconText = Icons.Icon({'Ranged', type='skill', notext=notext, nolink=nolink})<br />
elseif monster.attackType == 'magic' then<br />
iconText = Icons.Icon({'Magic', type='skill', notext=notext, nolink=nolink})<br />
elseif monster.attackType == 'random' then<br />
iconText = Icons.Icon({'Bane', notext=notext, nolink=nolink, img='Question'})<br />
end<br />
<br />
return iconText<br />
end<br />
<br />
function p.getMonsterStyleIcon(frame)<br />
local args = frame.args ~= nil and frame.args or frame<br />
local MonsterName = args[1]<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
args[1] = monster<br />
return p._getMonsterStyleIcon(args)<br />
end<br />
<br />
function p._getMonsterHP(monster)<br />
return 10 * p._getMonsterLevel(monster, 'Hitpoints')<br />
end<br />
<br />
function p.getMonsterEffectiveHP(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
if monster ~= nil then<br />
return math.floor((p._getMonsterHP(monster)/(1 - p._getMonsterStat(monster, 'damageReduction')/100)) + 0.5)<br />
else<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
end<br />
<br />
function p.getMonsterHP(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
if monster ~= nil then<br />
return p._getMonsterHP(monster)<br />
else<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
end<br />
<br />
function p._getMonsterLevel(monster, skillName)<br />
local result = 0<br />
if monster.levels[skillName] ~= nil then<br />
result = monster.levels[skillName]<br />
end<br />
return result<br />
end<br />
<br />
function p.getMonsterLevel(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame[1]<br />
local SkillName = frame.args ~= nil and frame.args[2] or frame[2]<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterLevel(monster, SkillName)<br />
end<br />
<br />
function p.getEquipmentStat(monster, statName)<br />
local result = 0<br />
for i, stat in Shared.skpairs(monster.equipmentStats) do<br />
if stat.key == statName then<br />
result = stat.value<br />
break<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.calculateStandardStat(effectiveLevel, bonus)<br />
--Based on calculateStandardStat in Characters.js<br />
return (effectiveLevel + 9) * (bonus + 64)<br />
end<br />
<br />
function p.calculateStandardMaxHit(baseLevel, strengthBonus)<br />
--Based on calculateStandardMaxHit in Characters.js<br />
local effectiveLevel = baseLevel + 9<br />
return math.floor(10 * (1.3 + effectiveLevel / 10 + strengthBonus / 80 + effectiveLevel * strengthBonus / 640))<br />
end<br />
<br />
function p._getMonsterAttackSpeed(monster)<br />
return p.getEquipmentStat(monster, 'attackSpeed') / 1000<br />
end<br />
<br />
function p.getMonsterAttackSpeed(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
if monster ~= nil then<br />
return p._getMonsterAttackSpeed(monster)<br />
else<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
end<br />
<br />
function p._getMonsterCombatLevel(monster)<br />
local base = 0.25 * (p._getMonsterLevel(monster, 'Defence') + p._getMonsterLevel(monster, 'Hitpoints'))<br />
local melee = 0.325 * (p._getMonsterLevel(monster, 'Attack') + p._getMonsterLevel(monster, 'Strength'))<br />
local range = 0.325 * (1.5 * p._getMonsterLevel(monster, 'Ranged'))<br />
local magic = 0.325 * (1.5 * p._getMonsterLevel(monster, 'Magic'))<br />
return math.floor(base + math.max(melee, range, magic))<br />
end<br />
<br />
function p.getMonsterCombatLevel(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterCombatLevel(monster)<br />
end<br />
<br />
function p._getMonsterAR(monster)<br />
local baseLevel = 0<br />
local bonus = 0<br />
if monster.attackType == 'melee' then<br />
baseLevel = p._getMonsterLevel(monster, 'Attack')<br />
bonus = p.getEquipmentStat(monster, 'stabAttackBonus')<br />
elseif monster.attackType == 'ranged' then<br />
baseLevel = p._getMonsterLevel(monster, 'Ranged')<br />
bonus = p.getEquipmentStat(monster, 'rangedAttackBonus')<br />
elseif monster.attackType == 'magic' then<br />
baseLevel = p._getMonsterLevel(monster, 'Magic')<br />
bonus = p.getEquipmentStat(monster, 'magicAttackBonus')<br />
elseif monster.attackType == 'random' then<br />
--Bane has the same AR with every attack type so being lazy and just showing the one.<br />
baseLevel = p._getMonsterLevel(monster, 'Attack')<br />
bonus = p.getEquipmentStat(monster, 'stabAttackBonus')<br />
else<br />
return "ERROR: This monster has an invalid attack type somehow[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p.calculateStandardStat(baseLevel, bonus)<br />
end<br />
<br />
function p.getMonsterAR(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterAR(monster)<br />
end<br />
<br />
function p._getMonsterER(monster, style)<br />
local baseLevel= 0<br />
local bonus = 0<br />
<br />
if style == "Melee" then<br />
baseLevel = p._getMonsterLevel(monster, 'Defence')<br />
bonus = p.getEquipmentStat(monster, 'meleeDefenceBonus')<br />
elseif style == "Ranged" then<br />
baseLevel = p._getMonsterLevel(monster, 'Defence')<br />
bonus = p.getEquipmentStat(monster, 'rangedDefenceBonus')<br />
elseif style == "Magic" then<br />
baseLevel = math.floor(p._getMonsterLevel(monster, 'Magic') * 0.7 + p._getMonsterLevel(monster, 'Defence') * 0.3)<br />
bonus = p.getEquipmentStat(monster, 'magicDefenceBonus')<br />
else<br />
return "ERROR: Must choose Melee, Ranged, or Magic[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p.calculateStandardStat(baseLevel, bonus)<br />
end<br />
<br />
function p.getMonsterER(frame)<br />
local args = frame.args ~= nil and frame.args or frame<br />
local MonsterName = args[1]<br />
local style = args[2]<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterER(monster, style)<br />
end<br />
<br />
-- Determines if the monster is capable of dropping bones, and returns the bones<br />
-- item if so, or nil otherwise<br />
function p._getMonsterBones(monster)<br />
if monster.bones ~= nil and monster.bones >= 0 then<br />
local boneItem = Items.getItemByID(monster.bones)<br />
if boneItem.prayerPoints == nil then<br />
-- Assume bones without prayer points are shards (from God dungeons),<br />
-- and drop unconditionally<br />
return boneItem<br />
elseif not monster.isBoss and not p._isDungeonOnlyMonster(monster) then<br />
-- Otherwise, bones drop when the monster isn't dungeon exclusive<br />
return boneItem<br />
end<br />
end<br />
end<br />
<br />
function p._isDungeonOnlyMonster(monster)<br />
local areaList = Areas.getMonsterAreas(monster.id)<br />
local inDungeon = false<br />
<br />
for i, area in ipairs(areaList) do<br />
if area.type == 'dungeon' then<br />
inDungeon = true<br />
else<br />
return false<br />
end<br />
end<br />
return inDungeon<br />
end<br />
<br />
function p.isDungeonOnlyMonster(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with name "..monsterName.." found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._isDungeonOnlyMonster(monster)<br />
end<br />
<br />
function p._getMonsterAreas(monster, excludeDungeons)<br />
local resultPart = {}<br />
local hideDungeons = excludeDungeons ~= nil and excludeDungeons or false<br />
local areaList = Areas.getMonsterAreas(monster.id)<br />
for i, area in ipairs(areaList) do<br />
if area.type ~= 'dungeon' or not hideDungeons then<br />
table.insert(resultPart, Icons.Icon({area.name, type = area.type}))<br />
end<br />
end<br />
return table.concat(resultPart, '<br/>')<br />
end<br />
<br />
function p.getMonsterAreas(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local hideDungeons = frame.args ~= nil and frame.args[2] or nil<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with name "..monsterName.." found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterAreas(monster, hideDungeons)<br />
end<br />
<br />
function p.getSpecAttackMaxHit(specAttack, normalMaxHit)<br />
local result = 0<br />
for i, dmg in pairs(specAttack.damage) do<br />
if dmg.maxRoll == 'Fixed' then<br />
result = dmg.maxPercent * 10<br />
elseif dmg.maxRoll == 'MaxHit' then<br />
if dmg.character == 'Target' then<br />
--Confusion applied damage based on the player's max hit. Gonna just ignore that one<br />
result = 0<br />
else<br />
result = dmg.maxPercent * normalMaxHit * 0.01<br />
end<br />
elseif Shared.contains({'Bleeding', 'Poisoned'}, dmg.maxRoll) then<br />
-- TODO: This is limited in that there is no verification that bleed/poison<br />
-- can be applied to the target, it is assumed that it can and so this applies<br />
result = result + dmg.maxPercent * 10<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.canSpecAttackApplyEffect(specAttack, effectType)<br />
local result = false<br />
for i, effect in pairs(specAttack.prehitEffects) do<br />
if effect.type == effectType then<br />
result = true<br />
break<br />
end<br />
end<br />
<br />
for i, effect in pairs(specAttack.onhitEffects) do<br />
if effect.type == effectType then<br />
result = true<br />
break<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p._getMonsterMaxHit(monster, doStuns)<br />
-- 2021-06-11 Adjusted for v0.20 stun/sleep changes, where damage multiplier now applies<br />
-- to all enemy attacks if stun/sleep is present on at least one special attack<br />
if doStuns == nil then<br />
doStuns = true<br />
elseif type(doStuns) == 'string' then<br />
doStuns = string.upper(doStuns) == 'TRUE'<br />
end<br />
<br />
local normalChance = 100<br />
local specialMaxHit = 0<br />
local normalMaxHit = p._getMonsterBaseMaxHit(monster)<br />
local hasActiveBuffSpec = false<br />
local damageMultiplier = 1<br />
if monster.specialAttacks[1] ~= nil then<br />
local canStun, canSleep = false, false<br />
for i, specAttack in pairs(monster.specialAttacks) do<br />
if monster.overrideSpecialChances ~= nil then<br />
normalChance = normalChance - monster.overrideSpecialChances[i]<br />
else<br />
normalChance = normalChance - specAttack.defaultChance<br />
end<br />
local thisMax = p.getSpecAttackMaxHit(specAttack, normalMaxHit)<br />
if not canStun and p.canSpecAttackApplyEffect(specAttack, 'Stun') then canStun = true end<br />
if not canSleep and p.canSpecAttackApplyEffect(specAttack, 'Sleep') then canSleep = true end<br />
<br />
if thisMax > specialMaxHit then specialMaxHit = thisMax end<br />
if Shared.contains(string.upper(specAttack.description), 'NORMAL ATTACK INSTEAD') then <br />
hasActiveBuffSpec = true <br />
end<br />
end<br />
<br />
if canSleep and doStuns then damageMultiplier = damageMultiplier * 1.2 end<br />
if canStun and doStuns then damageMultiplier = damageMultiplier * 1.3 end<br />
end<br />
--Ensure that if the monster never does a normal attack, the normal max hit is irrelevant<br />
if normalChance == 0 and not hasActiveBuffSpec then normalMaxHit = 0 end<br />
return math.floor(math.max(specialMaxHit, normalMaxHit) * damageMultiplier)<br />
end<br />
<br />
function p.getMonsterMaxHit(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local doStuns = frame.args ~= nil and frame.args[2] or true<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterMaxHit(monster, doStuns)<br />
end<br />
<br />
function p._getMonsterBaseMaxHit(monster)<br />
--8/27/21 - Now references p.calculateStandardMaxHit for Melee & Ranged<br />
local result = 0<br />
local baseLevel = 0<br />
local bonus = 0<br />
if monster.attackType == 'melee' then<br />
baseLevel = p._getMonsterLevel(monster, 'Strength')<br />
bonus = p.getEquipmentStat(monster, 'meleeStrengthBonus')<br />
result = p.calculateStandardMaxHit(baseLevel, bonus)<br />
elseif monster.attackType == 'ranged' then<br />
baseLevel = p._getMonsterLevel(monster, 'Ranged')<br />
bonus = p.getEquipmentStat(monster, 'rangedStrengthBonus')<br />
result = p.calculateStandardMaxHit(baseLevel, bonus)<br />
elseif monster.attackType == 'magic' then<br />
local mSpell = nil<br />
if monster.selectedSpell ~= nil then mSpell = Magic.getSpellByID('Spells', monster.selectedSpell) end<br />
<br />
bonus = p.getEquipmentStat(monster, 'magicDamageBonus')<br />
baseLevel = p._getMonsterLevel(monster, 'Magic')<br />
<br />
result = math.floor(10 * mSpell.maxHit * (1 + bonus / 100) * (1 + (baseLevel + 1) / 200))<br />
elseif monster.attackType == 'random' then<br />
local hitArray = {}<br />
local iconText = Icons.Icon({'Melee', notext=true})<br />
baseLevel = p._getMonsterLevel(monster, 'Strength')<br />
bonus = p.getEquipmentStat(monster, 'meleeStrengthBonus')<br />
table.insert(hitArray, p.calculateStandardMaxHit(baseLevel, bonus))<br />
<br />
iconText = Icons.Icon({'Ranged', type='skill', notext=true})<br />
baseLevel = p._getMonsterLevel(monster, 'Ranged')<br />
bonus = p.getEquipmentStat(monster, 'rangedStrengthBonus')<br />
table.insert(hitArray, p.calculateStandardMaxHit(baseLevel, bonus))<br />
<br />
iconText = Icons.Icon({'Magic', type='skill', notext=true})<br />
local mSpell = nil<br />
if monster.selectedSpell ~= nil then mSpell = Magic.getSpellByID('Spells', monster.selectedSpell) end<br />
bonus = p.getEquipmentStat(monster, 'magicDamageBonus')<br />
baseLevel = p._getMonsterLevel(monster, 'Magic')<br />
local magicDmg = math.floor(10 * mSpell.maxHit * (1 + bonus / 100) * (1 + (baseLevel + 1) / 200))<br />
table.insert(hitArray, magicDmg)<br />
<br />
local max = 0<br />
for i, val in pairs(hitArray) do<br />
if val > max then max = val end<br />
end<br />
result = max<br />
else<br />
return "ERROR: This monster has an invalid attack type somehow[[Category:Pages with script errors]]"<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getMonsterBaseMaxHit(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterBaseMaxHit(monster)<br />
end<br />
<br />
function p.getMonsterAttacks(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = ''<br />
local iconText = p._getMonsterStyleIcon({monster, notext=true})<br />
local typeText = ''<br />
if monster.attackType == 'melee' then<br />
typeText = 'Melee'<br />
elseif monster.attackType == 'ranged' then<br />
typeText = 'Ranged'<br />
elseif monster.attackType == 'magic' then<br />
typeText = 'Magic'<br />
elseif monster.attackType == 'random' then<br />
typeText = "Random"<br />
end<br />
<br />
local buffAttacks = {}<br />
local hasActiveBuffSpec = false<br />
<br />
local normalAttackChance = 100<br />
if monster.specialAttacks[1] ~= nil then<br />
for i, specAttack in pairs(monster.specialAttacks) do<br />
local attChance = 0<br />
if monster.overrideSpecialChances ~= nil then<br />
attChance = monster.overrideSpecialChances[i]<br />
else<br />
attChance = specAttack.defaultChance<br />
end<br />
normalAttackChance = normalAttackChance - attChance<br />
<br />
result = result..'\r\n* '..attChance..'% '..iconText..' '..specAttack.name..'\r\n** '..specAttack.description<br />
<br />
if Shared.contains(string.upper(specAttack.description), 'NORMAL ATTACK INSTEAD') then<br />
table.insert(buffAttacks, specAttack.name)<br />
hasActiveBuffSpec = true <br />
end<br />
end<br />
end<br />
if normalAttackChance == 100 then<br />
result = iconText..' 1 - '..p._getMonsterBaseMaxHit(monster)..' '..typeText..' Damage'<br />
elseif normalAttackChance > 0 then<br />
result = '* '..normalAttackChance..'% '..iconText..' 1 - '..p.getMonsterBaseMaxHit(frame)..' '..typeText..' Damage'..result<br />
elseif hasActiveBuffSpec then<br />
--If the monster normally has a 0% chance of doing a normal attack but some special attacks can't be repeated, include it<br />
--(With a note about when it does it)<br />
result = '* '..iconText..' 1 - '..p._getMonsterBaseMaxHit(monster)..' '..typeText..' Damage (Instead of repeating '..table.concat(buffAttacks, ' or ')..' while the effect is already active)'..result<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getMonsterPassives(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = ''<br />
if type(monster.passiveID) == 'table' and Shared.tableCount(monster.passiveID) > 0 then<br />
result = result .. '===Passives==='<br />
for i, passiveID in pairs(monster.passiveID) do<br />
local passive = p.getPassiveByID(passiveID)<br />
result = result .. '\r\n* ' .. passive.name .. '\r\n** ' .. passive.description<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p.getMonsterCategories(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = '[[Category:Monsters]]'<br />
<br />
if monster.attackType == 'melee' then<br />
result = result..'[[Category:Melee Monsters]]'<br />
elseif monster.attackType == 'ranged' then<br />
result = result..'[[Category:Ranged Monsters]]'<br />
elseif monster.attackType == 'magic' then<br />
result = result..'[[Category:Magic Monsters]]'<br />
end<br />
<br />
if monster.specialAttacks[1] ~= nil then<br />
result = result..'[[Category:Monsters with Special Attacks]]'<br />
end<br />
<br />
if monster.isBoss then<br />
result = result..'[[Category:Bosses]]'<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getOtherMonsterBoxText(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = ''<br />
<br />
--Going through and finding out which damage bonuses will apply to this monster<br />
local monsterTypes = {}<br />
if monster.isBoss then table.insert(monsterTypes, 'Boss') end<br />
<br />
local areaList = Areas.getMonsterAreas(monster.id)<br />
local counts = {combat = 0, slayer = 0, dungeon = 0}<br />
for i, area in Shared.skpairs(areaList) do<br />
counts[area.type] = counts[area.type] + 1<br />
end<br />
<br />
if counts.combat > 0 then table.insert(monsterTypes, 'Combat Area') end<br />
if counts.slayer > 0 then table.insert(monsterTypes, 'Slayer Area') end<br />
if counts.dungeon > 0 then table.insert(monsterTypes, 'Dungeon') end<br />
<br />
result = result.."\r\n|-\r\n|'''Monster Types:''' "..table.concat(monsterTypes, ", ")<br />
<br />
local SlayerTier = 'N/A'<br />
if monster.canSlayer then<br />
SlayerTier = Constants.getSlayerTierNameByLevel(p._getMonsterCombatLevel(monster))<br />
end<br />
<br />
result = result.."\r\n|-\r\n|'''"..Icons.Icon({'Slayer', type='skill'}).." [[Slayer#Slayer Tier Monsters|Tier]]:''' "<br />
if monster.canSlayer then<br />
result = result.."[[Slayer#"..SlayerTier.."|"..SlayerTier.."]]"<br />
else<br />
result = result..SlayerTier<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getMonsterDrops(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = ''<br />
<br />
local bones = p._getMonsterBones(monster)<br />
local boneVal = 0<br />
--Show the bones only if either the monster shows up outside of dungeons _or_ the monster drops shards<br />
if bones ~= nil then<br />
local boneQty = (monster.boneQty ~= nil and monster.boneQty or 1)<br />
result = result.."'''Always Drops:'''"<br />
result = result..'\r\n{|class="wikitable" id="bonedrops"'<br />
result = result..'\r\n!Item !! Qty'<br />
result = result..'\r\n|-\r\n|'..Icons.Icon({bones.name, type='item'})<br />
result = result..'||'..boneQty..'\r\n'..'|}'<br />
boneVal = boneQty * bones.sellsFor<br />
end<br />
<br />
--Likewise, seeing the loot table is tied to the monster appearing outside of dungeons<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100<br />
local lootValue = 0<br />
<br />
result = result.."'''Loot:'''"<br />
local avgGp = 0<br />
<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2<br />
local gpTxt = Icons.GP(monster.dropCoins[1], monster.dropCoins[2])<br />
result = result.."\r\nIn addition to loot, the monster will also drop "..gpTxt..'.'<br />
end<br />
<br />
local multiDrop = Shared.tableCount(monster.lootTable) > 1<br />
local totalWt = 0<br />
for i, row in pairs(monster.lootTable) do<br />
totalWt = totalWt + row[2]<br />
end<br />
result = result..'\r\n{|class="wikitable sortable" id="itemdrops"'<br />
result = result..'\r\n!Item!!Qty'<br />
result = result..'!!Price!!colspan="2"|Chance'<br />
<br />
--Sort the loot table by weight in descending order<br />
table.sort(monster.lootTable, function(a, b) return a[2] > b[2] end)<br />
for i, row in Shared.skpairs(monster.lootTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
<br />
local maxQty = row[3]<br />
if thisItem ~= nil then<br />
result = result..'\r\n|-\r\n|'..Icons.Icon({thisItem.name, type='item'})<br />
else<br />
result = result..'\r\n|-\r\n|Unknown Item[[Category:Pages with script errors]]'<br />
end<br />
result = result..'||style="text-align:right" data-sort-value="'..maxQty..'"|'<br />
<br />
if maxQty > 1 then<br />
result = result.. '1 - '<br />
end<br />
result = result..Shared.formatnum(row[3])<br />
<br />
--Adding price columns<br />
local itemPrice = 0<br />
if thisItem == nil then<br />
result = result..'||data-sort-value="0"|???'<br />
else<br />
itemPrice = thisItem.sellsFor ~= nil and thisItem.sellsFor or 0<br />
if itemPrice == 0 or maxQty == 1 then<br />
result = result..'||'..Icons.GP(itemPrice)<br />
else<br />
result = result..'||'..Icons.GP(itemPrice, itemPrice * maxQty)<br />
end<br />
end<br />
<br />
--Getting the drop chance<br />
local dropChance = (row[2] / totalWt * lootChance)<br />
if dropChance < 100 then<br />
--Show fraction as long as it isn't going to be 1/1<br />
result = result..'||style="text-align:right" data-sort-value="'..row[2]..'"'<br />
result = result..'|'..Shared.fraction(row[2] * lootChance, totalWt * 100)<br />
result = result..'||'<br />
else<br />
result = result..'||colspan="2" data-sort-value="'..row[2]..'"'<br />
end<br />
-- If chance is less than 0.10% then show 2 significant figures, otherwise 2 decimal places<br />
local fmt = (dropChance < 0.10 and '%.2g') or '%.2f'<br />
result = result..'style="text-align:right"|'..string.format(fmt, dropChance)..'%'<br />
<br />
--Adding to the average loot value based on price & dropchance<br />
lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((1 + maxQty) / 2))<br />
end<br />
if multiDrop then<br />
result = result..'\r\n|-class="sortbottom" \r\n!colspan="3"|Total:'<br />
if lootChance < 100 then<br />
result = result..'\r\n|style="text-align:right"|'..Shared.fraction(lootChance, 100)..'||'<br />
else<br />
result = result..'\r\n|colspan="2" '<br />
end<br />
result = result..'style="text-align:right"|'..Shared.round(lootChance, 2, 2)..'%'<br />
end<br />
result = result..'\r\n|}'<br />
result = result..'\r\nThe loot dropped by the average kill is worth '..Icons.GP(Shared.round(lootValue, 2, 0)).." if sold."<br />
if avgGp > 0 then<br />
result = result.."<br/>Including GP"<br />
if boneVal > 0 then<br />
result = result..' and bones'<br />
end<br />
result = result..', the average kill is worth '..Icons.GP(Shared.round(avgGp + lootValue + boneVal, 2, 0))..'.'<br />
end<br />
end<br />
<br />
--If no other drops, make sure to at least say so.<br />
if result == '' then result = 'None' end<br />
return result<br />
end<br />
<br />
function p._getMonsterLootValue(monster)<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
local result = 0<br />
local boneVal = 0<br />
<br />
local bones = p._getMonsterBones(monster)<br />
--Show the bones only if either the monster shows up outside of dungeons _or_ the monster drops shards<br />
if bones ~= nil then<br />
local boneQty = monster.boneQty ~= nil and monster.boneQty or 1<br />
boneVal = bones.sellsFor * boneQty<br />
result = result + boneVal<br />
end<br />
<br />
--Likewise, seeing the loot table is tied to the monster appearing outside of dungeons<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100<br />
local lootValue = 0<br />
<br />
local avgGp = 0<br />
<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2<br />
end<br />
<br />
local multiDrop = Shared.tableCount(monster.lootTable) > 1<br />
local totalWt = 0<br />
for i, row in pairs(monster.lootTable) do<br />
totalWt = totalWt + row[2]<br />
end<br />
<br />
for i, row in Shared.skpairs(monster.lootTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
<br />
local maxQty = row[3]<br />
<br />
--Adding price columns<br />
local itemPrice = 0<br />
if thisItem ~= nil then<br />
itemPrice = thisItem.sellsFor ~= nil and thisItem.sellsFor or 0<br />
end<br />
<br />
--Getting the drop chance<br />
local dropChance = (row[2] / totalWt * lootChance)<br />
--Adding to the average loot value based on price & dropchance<br />
lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((1 + maxQty) / 2))<br />
end<br />
if avgGp > 0 then<br />
result = result + avgGp + lootValue<br />
end<br />
end<br />
<br />
return result<br />
end<br />
<br />
-- Find drop chance of specified item from specified monster. <br />
-- Usage: |Monster Name|Item Name<br />
function p.getItemDropChance(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame[1]<br />
local ItemName = frame.args ~= nil and frame.args[2] or frame[2]<br />
<br />
local monster = p.getMonster(MonsterName)<br />
local item = Items.getItem(ItemName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
if item == nil then<br />
return "ERROR: No item with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100<br />
<br />
local totalWt = 0<br />
--for i, row in pairs(monster.lootTable) do<br />
--totalWt = totalWt + row[2]<br />
--end<br />
<br />
local dropChance = 0<br />
local dropWt = 0<br />
for i, row in Shared.skpairs(monster.lootTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
totalWt = totalWt + row[2]<br />
if item['id'] == thisItem['id'] then<br />
dropWt = row[2]<br />
end<br />
end<br />
dropChance = (dropWt / totalWt * lootChance)<br />
return Shared.round(dropChance, 2, 2)<br />
end<br />
end <br />
<br />
function p.getChestDrops(frame)<br />
local ChestName = frame.args ~= nil and frame.args[1] or frame<br />
local chest = Items.getItem(ChestName)<br />
<br />
if chest == nil then<br />
return "ERROR: No item named "..ChestName..' found[[Category:Pages with script errors]]'<br />
end<br />
<br />
local result = ''<br />
<br />
if chest.dropTable == nil then<br />
return "ERROR: "..ChestName.." does not have a drop table[[Category:Pages with script errors]]"<br />
else<br />
local lootChance = 100<br />
local lootValue = 0<br />
<br />
local multiDrop = Shared.tableCount(chest.dropTable) > 1<br />
local totalWt = 0<br />
for i, row in pairs(chest.dropTable) do<br />
totalWt = totalWt + row[2]<br />
end<br />
result = result..'\r\n{|class="wikitable sortable"'<br />
result = result..'\r\n!Item!!Qty'<br />
result = result..'!!colspan="2"|Chance!!Price'<br />
<br />
--Sort the loot table by weight in descending order<br />
for i, row in pairs(chest.dropTable) do<br />
if chest.dropQty ~= nil then<br />
table.insert(row, chest.dropQty[i])<br />
else<br />
table.insert(row, 1)<br />
end<br />
end<br />
table.sort(chest.dropTable, function(a, b) return a[2] > b[2] end)<br />
for i, row in Shared.skpairs(chest.dropTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
local qty = row[3]<br />
result = result..'\r\n|-\r\n|'..Icons.Icon({thisItem.name, type='item'})<br />
result = result..'||style="text-align:right" data-sort-value="'..qty..'"|'<br />
<br />
if qty > 1 then<br />
result = result.. '1 - '<br />
end<br />
result = result..Shared.formatnum(qty)<br />
<br />
local dropChance = (row[2] / totalWt) * 100<br />
result = result..'||style="text-align:right" data-sort-value="'..row[2]..'"'<br />
result = result..'|'..Shared.fraction(row[2], totalWt)<br />
<br />
result = result..'||style="text-align:right"|'..Shared.round(dropChance, 2, 2)..'%'<br />
<br />
result = result..'||style="text-align:left" data-sort-value="'..thisItem.sellsFor..'"'<br />
if qty > 1 then<br />
result = result..'|'..Icons.GP(thisItem.sellsFor, thisItem.sellsFor * qty)<br />
else<br />
result = result..'|'..Icons.GP(thisItem.sellsFor)<br />
end<br />
lootValue = lootValue + (dropChance * 0.01 * thisItem.sellsFor * ((1 + qty)/ 2))<br />
end<br />
result = result..'\r\n|}'<br />
result = result..'\r\nThe average value of the contents of one chest is '..Icons.GP(Shared.round(lootValue, 2, 0))..'.'<br />
end<br />
<br />
return result<br />
end<br />
<br />
function p.getAreaMonsterTable(frame)<br />
local areaName = frame.args ~= nil and frame.args[1] or frame<br />
local area = Areas.getArea(areaName)<br />
if area == nil then<br />
return "ERROR: Could not find an area named "..areaName..'[[Category:Pages with script errors]]'<br />
end<br />
<br />
if area.type == 'dungeon' then<br />
return p.getDungeonMonsterTable(frame)<br />
end<br />
<br />
local tableTxt = '{| class="wikitable sortable"'<br />
tableTxt = tableTxt..'\r\n! Name !! Combat Level !! Hitpoints !! Max Hit !! [[Combat Triangle|Combat Style]]'<br />
for i, monsterID in pairs(area.monsters) do<br />
local monster = p.getMonsterByID(monsterID)<br />
tableTxt = tableTxt..'\r\n|-\r\n|'..Icons.Icon({monster.name, type='monster'})<br />
tableTxt = tableTxt..'||'..p._getMonsterCombatLevel(monster)<br />
tableTxt = tableTxt..'||'..Shared.formatnum(p._getMonsterHP(monster))<br />
tableTxt = tableTxt..'||'..Shared.formatnum(p._getMonsterMaxHit(monster))<br />
tableTxt = tableTxt..'||'..p._getMonsterStyleIcon({monster, nolink=true})<br />
end<br />
tableTxt = tableTxt..'\r\n|}'<br />
return tableTxt<br />
end<br />
<br />
function p.getDungeonMonsterTable(frame)<br />
local areaName = frame.args ~= nil and frame.args[1] or frame<br />
local area = Areas.getArea(areaName)<br />
if area == nil then<br />
return "ERROR: Could not find a dungeon named "..areaName..'[[Category:Pages with script errors]]'<br />
end<br />
<br />
--For Dungeons, go through and count how many of each monster are in the dungeon first<br />
local monsterCounts = {}<br />
for i, monsterID in pairs(area.monsters) do<br />
if monsterCounts[monsterID] == nil then<br />
monsterCounts[monsterID] = 1<br />
else<br />
monsterCounts[monsterID] = monsterCounts[monsterID] + 1<br />
end<br />
end<br />
<br />
local usedMonsters = {}<br />
<br />
-- Declare function for building table rows to avoid repeating code<br />
local buildRow = function(entityID, monsterCount, specialType)<br />
local monIcon, monLevel, monHP, monMaxHit, monStyle, monCount<br />
local monData = {}<br />
if specialType ~= nil and Shared.contains({'Afflicted', 'SlayerArea'}, specialType) then<br />
-- Special handling for Into the Mist<br />
if specialType == 'Afflicted' then<br />
local iconQ = Icons.Icon({'Into the Mist', notext=true, nolink=true, img='Question'})<br />
monIcon = Icons.Icon({'Into the Mist', 'Afflicted Monster', nolink=true, img='Question'})<br />
monLevel, monHP, monMaxHit, monStyle, monCount = iconQ, iconQ, iconQ, iconQ, monsterCount<br />
elseif specialType == 'SlayerArea' then<br />
-- entityID corresponds to a slayer area<br />
local area = Areas.getAreaByID('slayer', entityID)<br />
monIcon = Icons.Icon({area.name, type='combatArea'}) .. ' Monsters'<br />
monLevel = {p.getLowHighStat(area.monsters, function(monster) return p._getMonsterCombatLevel(monster) end)}<br />
monHP = {p.getLowHighStat(area.monsters, function(monster) return p._getMonsterHP(monster) end)}<br />
local lowMaxHit, highMaxHit = p.getLowHighStat(area.monsters, function(monster) return p._getMonsterMaxHit(monster) end)<br />
monMaxHit = highMaxHit<br />
monStyle = Icons.Icon({area.name, area.name, notext=true, nolink=true, img='Question'})<br />
monCount = monsterCount<br />
end<br />
else<br />
-- entityID corresponds to a monster<br />
local monster = p.getMonsterByID(entityID)<br />
monIcon = Icons.Icon({monster.name, type='monster'})<br />
monLevel = p._getMonsterCombatLevel(monster)<br />
monHP = p._getMonsterHP(monster)<br />
monMaxHit = p._getMonsterMaxHit(monster)<br />
monStyle = p._getMonsterStyleIcon({monster})<br />
monCount = monsterCount<br />
end<br />
local getValSort = function(val)<br />
if type(val) == 'table' then<br />
if type(val[1]) == 'number' and type(val[2]) == 'number' then<br />
return (val[1] + val[2]) / 2<br />
else<br />
return (type(val[1]) == 'number' and val[1]) or 0<br />
end<br />
else<br />
return (type(val) == 'number' and val) or 0<br />
end<br />
end<br />
local getValText = function(val)<br />
if type(val) == 'table' and Shared.tableCount(val) == 2 then<br />
if type(val[1]) == 'number' and type(val[2]) == 'number' then<br />
return Shared.formatnum(val[1]) .. ' - ' .. Shared.formatnum(val[2])<br />
else<br />
return val[1] .. ' - ' .. val[2]<br />
end<br />
elseif type(val) == 'number' then<br />
return Shared.formatnum(val)<br />
else<br />
return val<br />
end<br />
end<br />
<br />
local resultPart = {}<br />
table.insert(resultPart, '\r\n|-\r\n| ' .. monIcon)<br />
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monLevel) .. '"| ' .. getValText(monLevel))<br />
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monHP) .. '"| ' .. getValText(monHP))<br />
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monMaxHit) .. '"| ' .. getValText(monMaxHit))<br />
table.insert(resultPart, '\r\n| ' .. monStyle)<br />
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monCount) .. '"| ' .. getValText(monCount))<br />
return table.concat(resultPart)<br />
end<br />
<br />
local returnPart = {}<br />
table.insert(returnPart, '{| class="wikitable sortable"')<br />
table.insert(returnPart, '\r\n! Name !! Combat Level !! Hitpoints !! Max Hit !! [[Combat Triangle|Combat Style]] !! Count')<br />
-- Special handing for Impending Darkness event<br />
-- TODO needs to be revised once there is a better understanding of how the event works<br />
--if area.isEvent ~= nil and area.isEvent then<br />
-- for i, eventAreaID in ipairs(Areas.eventData.slayerAreas) do<br />
-- table.insert(returnPart, buildRow(eventAreaID, {5, 8}, 'SlayerArea'))<br />
-- end<br />
-- -- Add Bane * 4<br />
-- table.insert(returnPart, buildRow(152, 4))<br />
--end<br />
for i, monsterID in pairs(area.monsters) do<br />
if not Shared.contains(usedMonsters, monsterID) then<br />
if monsterID >= 0 then<br />
table.insert(returnPart, buildRow(monsterID, monsterCounts[monsterID]))<br />
else<br />
--Special handling for Into the Mist<br />
table.insert(returnPart, buildRow(monsterID, monsterCounts[monsterID], 'Afflicted'))<br />
end<br />
table.insert(usedMonsters, monsterID)<br />
end<br />
end<br />
table.insert(returnPart, '\r\n|}')<br />
return table.concat(returnPart)<br />
end<br />
<br />
function p.getDungeonTotalHp(frame)<br />
local areaName = frame.args ~= nil and frame.args[1] or frame<br />
local area = Areas.getArea(areaName)<br />
if area == nil then<br />
return "ERROR: Could not find a dungeon named "..areaName..'[[Category:Pages with script errors]]'<br />
end<br />
local totalHP = 0<br />
<br />
for i, monsterID in pairs(area.monsters) do<br />
if not Shared.contains(usedMonsters, monsterID) then<br />
local monster = p.getMonsterByID(monsterID)<br />
totalHP = totalHP + p._getMonsterHP(monster)<br />
end<br />
end<br />
return totalHP<br />
end<br />
<br />
function p._getAreaMonsterList(area)<br />
local monsterList = {}<br />
for i, monsterID in pairs(area.monsters) do<br />
local monster = p.getMonsterByID(monsterID)<br />
table.insert(monsterList, Icons.Icon({monster.name, type='monster'}))<br />
end<br />
return table.concat(monsterList, '<br/>')<br />
end<br />
<br />
function p._getDungeonMonsterList(area)<br />
local monsterList = {}<br />
local lastMonster = nil<br />
local lastID = -2<br />
local count = 0<br />
-- Special handing for Impending Darkness event<br />
-- TODO needs to be revised once there is a better understanding of how the event works<br />
--if area.isEvent ~= nil and area.isEvent then<br />
-- for i, eventAreaID in ipairs(Areas.eventData.slayerAreas) do<br />
-- local eventArea = Areas.getAreaByID('slayer', eventAreaID)<br />
-- table.insert(monsterList, '5-8 ' .. Icons.Icon({eventArea.name, type='combatArea'}) .. ' Monsters')<br />
-- end<br />
-- table.insert(monsterList, '4 ' .. Icons.Icon({'Bane', type='monster'}))<br />
--end<br />
for i, monsterID in Shared.skpairs(area.monsters) do<br />
if monsterID ~= lastID then<br />
local monster = nil <br />
if monsterID ~= -1 then monster = p.getMonsterByID(monsterID) end<br />
if lastID ~= -2 then<br />
if lastID == -1 then<br />
--Special handling for Afflicted Monsters<br />
table.insert(monsterList, Icons.Icon({'Affliction', 'Afflicted Monster', img='Question', qty=count}))<br />
else<br />
local name = lastMonster.name<br />
table.insert(monsterList, Icons.Icon({name, type='monster', qty=count}))<br />
end<br />
end<br />
lastMonster = monster<br />
lastID = monsterID<br />
count = 1<br />
else<br />
count = count + 1<br />
end<br />
--Make sure the final monster in the dungeon gets counted<br />
if i == Shared.tableCount(area.monsters) then<br />
local name = lastMonster.name<br />
table.insert(monsterList, Icons.Icon({lastMonster.name, type='monster', qty=count}))<br />
end<br />
end<br />
return table.concat(monsterList, '<br/>')<br />
end<br />
<br />
function p.getAreaMonsterList(frame)<br />
local areaName = frame.args ~= nil and frame.args[1] or frame<br />
local area = Areas.getArea(areaName)<br />
if area == nil then<br />
return "ERROR: Could not find an area named "..areaName..'[[Category:Pages with script errors]]'<br />
end<br />
<br />
if area.type == 'dungeon' then<br />
return p._getDungeonMonsterList(area)<br />
else<br />
return p._getAreaMonsterList(area)<br />
end<br />
end<br />
<br />
function p.getFoxyTable(frame)<br />
local result = 'Monster,Min GP,Max GP,Average GP'<br />
for i, monster in Shared.skpairs(MonsterData.Monsters) do<br />
if not p._isDungeonOnlyMonster(monster) then<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
local avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2<br />
result = result..'<br/>'..monster.name..','..monster.dropCoins[1]..','..(monster.dropCoins[2])..','..avgGp<br />
end<br />
end<br />
end<br />
return result<br />
end<br />
<br />
function p._getMonsterAverageGP(monster)<br />
local result = ''<br />
local totalGP = 0<br />
<br />
local bones = p._getMonsterBones(monster)<br />
if bones ~= nil then<br />
totalGP = totalGP + bones.sellsFor * (type(monster.boneQty) == 'number' and monster.boneQty or 1)<br />
end<br />
<br />
--Likewise, seeing the loot table is tied to the monster appearing outside of dungeons<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100<br />
local lootValue = 0<br />
<br />
local avgGp = 0<br />
<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2<br />
end<br />
<br />
totalGP = totalGP + avgGp<br />
<br />
local multiDrop = Shared.tableCount(monster.lootTable) > 1<br />
local totalWt = 0<br />
for i, row in pairs(monster.lootTable) do<br />
totalWt = totalWt + row[2]<br />
end<br />
<br />
for i, row in Shared.skpairs(monster.lootTable) do<br />
local thisItem = Items.getItemByID(row[1])<br />
local maxQty = row[3]<br />
<br />
local itemPrice = thisItem.sellsFor ~= nil and thisItem.sellsFor or 0<br />
<br />
--Getting the drop chance<br />
local dropChance = (row[2] / totalWt * lootChance)<br />
<br />
--Adding to the average loot value based on price & dropchance<br />
lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((1 + maxQty) / 2))<br />
end<br />
<br />
totalGP = totalGP + lootValue<br />
end<br />
<br />
return Shared.round(totalGP, 2, 2)<br />
end<br />
<br />
function p.getMonsterAverageGP(frame)<br />
local MonsterName = frame.args ~= nil and frame.args[1] or frame<br />
local monster = p.getMonster(MonsterName)<br />
<br />
if monster == nil then<br />
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"<br />
end<br />
<br />
return p._getMonsterAverageGP(monster)<br />
end<br />
<br />
function p.getMonsterEVTable(frame)<br />
local result = '{| class="wikitable sortable"'<br />
result = result..'\r\n!Monster!!Combat Level!!Average GP'<br />
for i, monsterTemp in Shared.skpairs(MonsterData.Monsters) do<br />
local monster = Shared.clone(monsterTemp)<br />
monster.id = i - 1<br />
if not p._isDungeonOnlyMonster(monster) then<br />
local monsterGP = p._getMonsterAverageGP(monster)<br />
local combatLevel = p._getMonsterCombatLevel(monster, 'Combat Level')<br />
result = result..'\r\n|-\r\n|'..Icons.Icon({monster.name, type='monster', noicon=true})..'||'..combatLevel..'||'..monsterGP<br />
end<br />
end<br />
result = result..'\r\n|}'<br />
return result<br />
end<br />
<br />
function p.getSlayerTierMonsterTable(frame)<br />
-- Input validation<br />
local tier = frame.args ~= nil and frame.args[1] or frame<br />
local slayerTier = nil<br />
<br />
if tier == nil then<br />
return "ERROR: No tier specified[[Category:Pages with script errors]]"<br />
end<br />
<br />
if tonumber(tier) ~= nil then<br />
slayerTier = Constants.getSlayerTierByID(tonumber(tier))<br />
else<br />
slayerTier = Constants.getSlayerTier(tier)<br />
end<br />
<br />
if slayerTier == nil then<br />
return "ERROR: Invalid slayer tier[[Category:Pages with script errors]]"<br />
end<br />
<br />
-- Obtain required tier details<br />
local minLevel, maxLevel = slayerTier.minLevel, slayerTier.maxLevel<br />
<br />
-- Build list of monster IDs<br />
-- Right now hiddenMonsterIDs is empty<br />
local hiddenMonsterIDs = {}<br />
local monsterIDs = {}<br />
for i, monster in Shared.skpairs(MonsterData.Monsters) do<br />
if monster.canSlayer and not Shared.contains(hiddenMonsterIDs, i - 1) then<br />
local cmbLevel = p._getMonsterCombatLevel(monster)<br />
if cmbLevel >= minLevel and (maxLevel == nil or cmbLevel <= maxLevel) then<br />
table.insert(monsterIDs, i - 1)<br />
end<br />
end<br />
end<br />
<br />
if Shared.tableCount(monsterIDs) == 0 then<br />
-- Somehow no monsters are in the tier, return nothing<br />
return ''<br />
else<br />
return p._getMonsterTable(monsterIDs, true)<br />
end<br />
end<br />
<br />
function p.getFullMonsterTable(frame)<br />
local monsterIDs = {}<br />
for i = 0, Shared.tableCount(MonsterData.Monsters) - 1, 1 do<br />
table.insert(monsterIDs, i)<br />
end<br />
<br />
return p._getMonsterTable(monsterIDs, false)<br />
end<br />
<br />
function p._getMonsterTable(monsterIDs, excludeDungeons)<br />
--Making a single function for getting a table of monsters given a list of IDs.<br />
local hideDungeons = excludeDungeons ~= nil and excludeDungeons or false<br />
local tableParts = {}<br />
table.insert(tableParts, '{| class="wikitable sortable stickyHeader"')<br />
-- First header row<br />
table.insert(tableParts, '\r\n|- class="headerRow-0"\r\n! colspan="5" | !! colspan="4" |Offensive Stats !! colspan="3" |Evasion Rating !! colspan="4" |')<br />
-- Second header row<br />
table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n!Monster !!Name !!ID !!Combat Level ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Hitpoints', type='skill'}))<br />
table.insert(tableParts, '!!Attack Speed (s) !!colspan="2"|Max Hit !!Accuracy ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Defence', type='skill', notext=true}))<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Ranged', type='skill', notext=true}))<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Magic', type='skill', notext=true}))<br />
table.insert(tableParts, '!!' .. Icons.Icon({'Coins', notext=true, nolink=true}) .. ' Coins !!Bones !!Locations')<br />
<br />
-- Generate row per monster<br />
for i, monsterID in Shared.skpairs(monsterIDs) do<br />
local monster = p.getMonsterByID(monsterID)<br />
local cmbLevel = p._getMonsterCombatLevel(monster)<br />
local atkSpeed = p._getMonsterAttackSpeed(monster)<br />
local maxHit = p._getMonsterMaxHit(monster)<br />
local accR = p._getMonsterAR(monster)<br />
local evaR = {p._getMonsterER(monster, "Melee"), p._getMonsterER(monster, "Ranged"), p._getMonsterER(monster, "Magic")}<br />
<br />
local gpRange = {0, 0}<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
gpRange = {monster.dropCoins[1], monster.dropCoins[2]}<br />
end<br />
local gpTxt = nil<br />
if gpRange[1] >= gpRange[2] then<br />
gpTxt = Shared.formatnum(gpRange[1])<br />
else<br />
gpTxt = Shared.formatnum(gpRange[1]) .. ' - ' .. Shared.formatnum(gpRange[2])<br />
end<br />
local bones = p._getMonsterBones(monster)<br />
local boneTxt = (bones ~= nil and Icons.Icon({bones.name, type='item', notext=true})) or 'None'<br />
<br />
table.insert(tableParts, '\r\n|-\r\n|style="text-align: center;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:left" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:right" |' .. monsterID)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. cmbLevel .. '" |' .. Shared.formatnum(cmbLevel))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. p._getMonsterHP(monster) .. '" |' .. Shared.formatnum(p._getMonsterHP(monster)))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. atkSpeed .. '" |' .. Shared.round(atkSpeed, 1, 1))<br />
table.insert(tableParts, '\r\n|style="text-align:center;border-right:hidden" |' .. p._getMonsterStyleIcon({monster, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. maxHit .. '" |' .. Shared.formatnum(maxHit))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. accR .. '" |' .. Shared.formatnum(accR))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[1] .. '" |' .. Shared.formatnum(evaR[1]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[2] .. '" |' .. Shared.formatnum(evaR[2]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[3] .. '" |' .. Shared.formatnum(evaR[3]))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:center" |' .. boneTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))<br />
end<br />
<br />
table.insert(tableParts, '\r\n|}')<br />
return table.concat(tableParts)<br />
end<br />
<br />
function p.getMattMonsterTable(frame)<br />
--Making a single function for getting a table of monsters given a list of IDs.<br />
local tableParts = {}<br />
table.insert(tableParts, '{| class="wikitable sortable stickyHeader"')<br />
-- Second header row<br />
table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n!Monster !!Name !!ID !!Combat Level ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Hitpoints', type='skill'}))<br />
table.insert(tableParts, '!!' .. Icons.Icon({'Coins', notext=true, nolink=true}) .. ' Coins !!Avg. Kill Value!!Locations')<br />
<br />
-- Generate row per monster<br />
for i, monster in Shared.skpairs(MonsterData.Monsters) do<br />
local cmbLevel = p._getMonsterCombatLevel(monster)<br />
<br />
local gpRange = {0, 0}<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
gpRange = {monster.dropCoins[1], monster.dropCoins[2]}<br />
end<br />
local gpTxt = nil<br />
if gpRange[1] >= gpRange[2] then<br />
gpTxt = Shared.formatnum(gpRange[1])<br />
else<br />
gpTxt = Shared.formatnum(gpRange[1]) .. ' - ' .. Shared.formatnum(gpRange[2])<br />
end<br />
<br />
local lootVal = p._getMonsterLootValue(monster)<br />
local lootTxt = '0'<br />
if lootVal ~= 0 then<br />
lootTxt = Shared.formatnum(Shared.round(lootVal, 2, 2))<br />
end<br />
<br />
<br />
table.insert(tableParts, '\r\n|-\r\n|style="text-align: center;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:left" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:right" |' .. monster.id)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. cmbLevel .. '" |' .. Shared.formatnum(cmbLevel))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. p._getMonsterHP(monster) .. '" |' .. Shared.formatnum(p._getMonsterHP(monster)))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. lootVal .. '" |' .. lootTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))<br />
end<br />
<br />
table.insert(tableParts, '\r\n|}')<br />
return table.concat(tableParts)<br />
end<br />
<br />
function p.getMattMonsterTableV2(frame)<br />
--Making a single function for getting a table of monsters given a list of IDs.<br />
local tableParts = {}<br />
table.insert(tableParts, '{| class="wikitable sortable stickyHeader"')<br />
-- Second header row<br />
table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n!Monster !!Name !!Combat Level ')<br />
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Hitpoints', type='skill'}))<br />
table.insert(tableParts, '!!' .. Icons.Icon({'Coins', notext=true, nolink=true}) .. ' Coins !!Avg. Kill Value!!Locations')<br />
<br />
-- Generate row per monster<br />
for i, monster in Shared.skpairs(MonsterData.Monsters) do<br />
local cmbLevel = p._getMonsterCombatLevel(monster)<br />
<br />
local gpRange = {0, 0}<br />
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then<br />
gpRange = {monster.dropCoins[1], monster.dropCoins[2]}<br />
end<br />
local gpTxt = nil<br />
if gpRange[1] >= gpRange[2] then<br />
gpTxt = Shared.formatnum(gpRange[1])<br />
else<br />
gpTxt = Shared.formatnum(gpRange[1]) .. ' - ' .. Shared.formatnum(gpRange[2])<br />
end<br />
<br />
local lootVal = p._getMonsterLootValue(monster)<br />
local lootTxt = '0'<br />
if lootVal ~= 0 then<br />
lootTxt = Shared.formatnum(Shared.round(lootVal, 2, 2))<br />
end<br />
<br />
<br />
table.insert(tableParts, '\r\n|-\r\n|style="text-align: center;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:left" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))<br />
table.insert(tableParts, '\r\n|style="text-align:right" |' .. monster.id)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. cmbLevel .. '" |' .. Shared.formatnum(cmbLevel))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. p._getMonsterHP(monster) .. '" |' .. Shared.formatnum(p._getMonsterHP(monster)))<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. lootVal .. '" |' .. lootTxt)<br />
table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))<br />
end<br />
<br />
table.insert(tableParts, '\r\n|}')<br />
return table.concat(tableParts)<br />
end<br />
<br />
function p.getSpecialAttackTable(frame)<br />
local spAttTable = {}<br />
<br />
for i, monster in ipairs(MonsterData.Monsters) do<br />
if monster.specialAttacks ~= nil and Shared.tableCount(monster.specialAttacks) > 0 then<br />
local overrideChance = (monster.overrideSpecialChances ~= nil and Shared.tableCount(monster.overrideSpecialChances) > 0)<br />
for j, spAtt in ipairs(monster.specialAttacks) do<br />
local attChance = (overrideChance and monster.overrideSpecialChances[j] or spAtt.defaultChance)<br />
if spAttTable[spAtt.id] == nil then<br />
spAttTable[spAtt.id] = { ['defn'] = spAtt, ['icons'] = {} }<br />
end<br />
if spAttTable[spAtt.id]['icons'][attChance] == nil then<br />
spAttTable[spAtt.id]['icons'][attChance] = {}<br />
end<br />
table.insert(spAttTable[spAtt.id]['icons'][attChance], Icons.Icon({ monster.name, type = 'monster' }))<br />
end<br />
end<br />
end<br />
<br />
local resultPart = {}<br />
table.insert(resultPart, '{|class="wikitable sortable stickyHeader"')<br />
table.insert(resultPart, '\r\n|- class="headerRow-0"')<br />
table.insert(resultPart, '\r\n!Name!!style="min-width:225px"|Monsters!!Chance!!Effect')<br />
<br />
for i, spAttData in Shared.skpairs(spAttTable) do<br />
local spAtt = spAttData.defn<br />
local firstRow = true<br />
local rowsSpanned = Shared.tableCount(spAttData.icons)<br />
local rowSuffix = ''<br />
if rowsSpanned > 1 then<br />
rowSuffix = '|rowspan="' .. rowsSpanned .. '"'<br />
end<br />
for chance, iconList in Shared.skpairs(spAttData.icons) do<br />
table.insert(resultPart, '\r\n|-')<br />
if firstRow then<br />
table.insert(resultPart, '\r\n' .. rowSuffix .. '| ' .. spAtt.name)<br />
end<br />
table.insert(resultPart, '\r\n|data-sort-value="' .. spAtt.name .. '"| ' .. table.concat(iconList, '<br/>'))<br />
table.insert(resultPart, '\r\n|data-sort-value="' .. chance .. '"| ' .. Shared.round(chance, 2, 0) .. '%')<br />
if firstRow then<br />
table.insert(resultPart, '\r\n' .. rowSuffix .. '| ' .. spAtt.description)<br />
firstRow = false<br />
end<br />
end<br />
end<br />
table.insert(resultPart, '\r\n|}')<br />
<br />
return table.concat(resultPart)<br />
end<br />
<br />
return p</div>
Roko
https://wiki.melvoridle.com/index.php?title=User:Roko&diff=51084
User:Roko
2022-02-19T13:07:09Z
<p>Roko: Created page with "{{#invoke:Monsters|getMattMonsterTable}}"</p>
<hr />
<div>{{#invoke:Monsters|getMattMonsterTable}}</div>
Roko