Module:Monsters: Difference between revisions

added functions to get average GP for all monster drops and then made a table of that
m (typing iz hard)
(added functions to get average GP for all monster drops and then made a table of that)
Line 136: Line 136:
end
end


function p.getMonsterCombatLevel(frame)
function p._getMonsterCombatLevel(monster)
  local MonsterName = frame.args ~= nil and frame.args[1] or frame
  local monster = p.getMonster(MonsterName)
 
  if monster == nil then
    return "ERROR: No monster with that name found"
  end
 
   local base = 0.25 * (monster.defenceLevel + monster.hitpoints)
   local base = 0.25 * (monster.defenceLevel + monster.hitpoints)
   local melee = 0.325 * (monster.attackLevel + monster.strengthLevel)
   local melee = 0.325 * (monster.attackLevel + monster.strengthLevel)
Line 155: Line 148:
     return math.floor(base + magic)
     return math.floor(base + magic)
   end
   end
end
function p.getMonsterCombatLevel(frame)
  local MonsterName = frame.args ~= nil and frame.args[1] or frame
  local monster = p.getMonster(MonsterName)
  if monster == nil then
    return "ERROR: No monster with that name found"
  end
  return p._getMonsterCombatLevel(monster)
end
end


Line 214: Line 218:
   local dunCount = 0
   local dunCount = 0
   local nonDunCount = 0
   local nonDunCount = 0
   for i, area in Shared.skpairs(areaList) do
   for i, area in Shared.skpairs(areaList) do
    mw.log(area.type)
     if area.type == 'dungeon' then
     if area.type == 'dungeon' then
       dunCount = dunCount + 1
       dunCount = dunCount + 1
Line 764: Line 770:
     end
     end
   end
   end
  return result
end
function p._getMonsterAverageGP(monster)
  local result = ''
  local totalGP = 0
  if monster.bones ~= nil then
    local bones = Items.getItemByID(monster.bones)
    --Show the bones only if either the monster shows up outside of dungeons _or_ the monster drops shards
    if not p._isDungeonOnlyMonster(monster) or Shared.contains(bones.name, 'Shard') then
      totalGP = totalGP + bones.sellsFor
    end
  end
  --Likewise, seeing the loot table is tied to the monster appearing outside of dungeons
  if not p._isDungeonOnlyMonster(monster) then
    local lootChance = monster.lootChance ~= nil and monster.lootChance or 100
    local lootValue = 0
    local avgGp = 0
    if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then
      avgGp = (monster.dropCoins[1] + monster.dropCoins[2] - 1) / 2
    end
    totalGP = totalGP + avgGp
    local multiDrop = Shared.tableCount(monster.lootTable) > 1
    local totalWt = 0
    for i, row in pairs(monster.lootTable) do
      totalWt = totalWt + row[2]
    end
    for i, row in Shared.skpairs(monster.lootTable) do
      local thisItem = Items.getItemByID(row[1])
      local maxQty = row[3]
      local itemPrice = thisItem.sellsFor ~= nil and thisItem.sellsFor or 0
      --Getting the drop chance
      local dropChance = (row[2] / totalWt * lootChance)
      --Adding to the average loot value based on price & dropchance
      lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((1 + maxQty) / 2))
    end
   
    totalGP = totalGP + lootValue
  end
  return Shared.round(totalGP, 2, 2)
end
function p.getMonsterAverageGP(frame)
  local MonsterName = frame.args ~= nil and frame.args[1] or frame
  local monster = p.getMonster(MonsterName)
  if monster == nil then
    return "ERROR: No monster with that name found"
  end
 
  return p._getMonsterAverageGP(monster)
end
function p.getMonsterEVTable(frame)
  local result = '{| class="wikitable sortable"'
  result = result..'\r\n!Monster!!Combat Level!!Average GP'
  for i, monsterTemp in Shared.skpairs(MonsterData.Monsters) do
    local monster = Shared.clone(monsterTemp)
    monster.id = i - 1
    if not p._isDungeonOnlyMonster(monster) then
      local monsterGP = p._getMonsterAverageGP(monster)
      local combatLevel = p._getMonsterCombatLevel(monster, 'Combat Level')
      result = result..'\r\n|-\r\n|[['..monster.name..']]||'..combatLevel..'||'..monsterGP
    end
  end
  result = result..'\r\n|}'
   return result
   return result
end
end


return p
return p