Anonymous

Module:Monsters: Difference between revisions

From Melvor Idle
MonsterDrops: Now with fractions
(Prevent sorting footer row)
(MonsterDrops: Now with fractions)
Line 377: Line 377:
   if monster.lootTable ~= nil then
   if monster.lootTable ~= nil then
     local lootChance = monster.lootChance ~= nil and monster.lootChance or 100
     local lootChance = monster.lootChance ~= nil and monster.lootChance or 100
    result = result.."'''Loot:'''"
    if monster.dropCoins ~= nil then
      local gpTxt = Icons.GP(monster.dropCoins[1], monster.dropCoins[2])
      if lootChance == 100 then
        result = result.."\r\nIn addition to loot, the monster will also drop "..gpTxt
      else
        result = result.."\r\nIf loot is received, the monster will also drop "..gpTxt
      end
    end
     local multiDrop = Shared.tableCount(monster.lootTable) > 1
     local multiDrop = Shared.tableCount(monster.lootTable) > 1
     local totalWt = 0
     local totalWt = 0
Line 382: Line 394:
       totalWt = totalWt + row[2]
       totalWt = totalWt + row[2]
     end
     end
    result = result.."'''Loot:'''"
     result = result..'\r\n{|class="wikitable sortable"'
     result = result..'\r\n{|class="wikitable sortable"'
     result = result..'\r\n!Item!!Qty'
     result = result..'\r\n!Item!!Qty'
     --if multiDrop then result = result..'!!Weight' end
     --if multiDrop then result = result..'!!Weight' end


     result = result..'!!Chance'
     result = result..'!!colspan="2"|Chance'
     --Sort the loot table by weight in descending order
     --Sort the loot table by weight in descending order
     table.sort(monster.lootTable, function(a, b) return a[2] > b[2] end)
     table.sort(monster.lootTable, function(a, b) return a[2] > b[2] end)
Line 396: Line 406:
       if row[3] > 1 then result = result.. '1 - ' end
       if row[3] > 1 then result = result.. '1 - ' end
       result = result..row[3]
       result = result..row[3]
      --if multiDrop then result = result..'||'..row[2]  end


       local dropChance = (row[2] / totalWt * lootChance)
       local dropChance = (row[2] / totalWt * lootChance)
      result = result..'||'..Shared.fraction(row[2] * lootChance, totalWt * 100)
       result = result..'||style="text-align:right"|'..Shared.round(dropChance, 2, 2)..'%'
       result = result..'||style="text-align:right"|'..Shared.round(dropChance, 2, 2)..'%'
     end
     end
     if multiDrop then
     if multiDrop then
      --result = result..'\r\n|-\r\n|colspan="2"|Total:||'..Shared.formatnum(totalWt)..'||'..lootChance..'%'
       result = result..'\r\n|-class="sortbottom" \r\n!colspan="2"|Total:'
       result = result..'\r\n|-class="sortbottom" \r\n!colspan="2"|Total:\r\n|style="text-align:right"|'..lootChance..'.00%'
      if lootChance < 100 then
    end
        result = result..'\r\n|'..Shared.fraction(lootChance, 100)..'||'
    result = result..'\r\n|}'
 
 
    if monster.dropCoins ~= nil then
      local gpTxt = Icons.GP(monster.dropCoins[1], monster.dropCoins[2])
      if lootChance == 100 then
        result = result.."\r\nThe player will also receive "..gpTxt
       else
       else
         result = result.."\r\nIf loot is received, the player will also receive "..gpTxt
         result = result..'\r\n|colspan="2" '
       end
       end
      result = result..'style="text-align:right"|'..lootChance..'.00%'
     end
     end
    result = result..'\r\n|}'
   end
   end


   return result
   return result
end
end


return p
return p