Module:Monsters: Difference between revisions

Added value and EV
(Added 'none' for when a monster has no drops)
(Added value and EV)
Line 380: Line 380:
   if monster.lootTable ~= nil and not monster.isBoss then
   if monster.lootTable ~= nil and not monster.isBoss then
     local lootChance = monster.lootChance ~= nil and monster.lootChance or 100
     local lootChance = monster.lootChance ~= nil and monster.lootChance or 100
    local lootValue = 0


     result = result.."'''Loot:'''"
     result = result.."'''Loot:'''"
Line 399: Line 400:
     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
     result = result..'!!colspan="2"|Chance!!Price'


    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)
     for i, row in pairs(monster.lootTable) do
     for i, row in pairs(monster.lootTable) do
       local thisItem = Items.getItemByID(row[1])
       local thisItem = Items.getItemByID(row[1])
      local maxQty = row[3]
       result = result..'\r\n|-\r\n|'..Icons.Icon({thisItem.name, type='item'})
       result = result..'\r\n|-\r\n|'..Icons.Icon({thisItem.name, type='item'})
       result = result..'||style="text-align:right" data-sort-value="'..row[3]..'"|'
       result = result..'||style="text-align:right" data-sort-value="'..maxQty..'"|'


       if row[3] > 1 then  
       if maxQty > 1 then  
         result = result.. '1 - '  
         result = result.. '1 - '  
       end
       end
       result = result..Shared.formatnum(row[3])
       result = result..Shared.formatnum(row[3])


      --Getting the drop chance
       local dropChance = (row[2] / totalWt * lootChance)
       local dropChance = (row[2] / totalWt * lootChance)
       result = result..'||style="text-align:right" data-sort-value="'..row[2]..'"'
       result = result..'||style="text-align:right" data-sort-value="'..row[2]..'"'
       result = result..'|'..Shared.fraction(row[2] * lootChance, totalWt * 100)
       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)..'%'
      --Adding price columns
      local itemPrice = thisItem.sellsFor ~= nil and thisItem.sellsFor or 0
      if itemPrice == 0 or maxQty == 1 then
        result = result..'||'..Icons.GP(itemPrice)
        lootValue = lootValue + (dropChance * 0.01 * itemPrice)
      else
        result = result..'||'..Icons.GP(itemPrice, itemPrice * maxQty)
        lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((1 + maxQty) / 2))
      end
     end
     end
     if multiDrop then
     if multiDrop then
Line 424: Line 436:
         result = result..'\r\n|style="text-align:right"|'..Shared.fraction(lootChance, 100)..'||'
         result = result..'\r\n|style="text-align:right"|'..Shared.fraction(lootChance, 100)..'||'
       else
       else
         result = result..'\r\n|colspan="2" '
         result = result..'\r\n|colspan="3" '
       end
       end
       result = result..'style="text-align:right"|'..lootChance..'.00%'
       result = result..'style="text-align:right"|'..lootChance..'.00%'
      result = result..'\r\n! '
     end
     end
     result = result..'\r\n|}'
     result = result..'\r\n|}'
    result = result..'\r\nThe loot from the average kill is worth '..Icons.GP(Shared.round(lootValue, 2, 0)).." (Not including GP)"
   end
   end