Blessings.DropLoot = function(player, corpse, chance, skulled)
local multiplier = 100 -- Improve the loot randomness spectrum
math.randomseed(os.time()) -- Improve the loot randomness spectrum
chance = chance * multiplier
Blessings.DebugPrint(chance, "DropLoot chance")
for i = CONST_SLOT_HEAD, CONST_SLOT_AMMO do
local item = player:getSlotItem(i)
if item then
local thisChance = chance
local thisRandom = math.random(100 * multiplier)
if not item:isContainer() then
thisChance = chance / 10
end
Blessings.DebugPrint(thisChance / multiplier .. "%" .. " | thisRandom " .. thisRandom / multiplier .. "%", "DropLoot item " .. item:getName() .. " |")
if skulled or thisRandom <= thisChance then
Blessings.DebugPrint("Dropped " .. item:getName())
item:moveTo(corpse)
end
end
end
if skulled and Blessings.Config.SkulledDeathLoseStoreItem then
local inbox = player:getStoreInbox()
local toBeDeleted = {}
if inbox and inbox:getSize() > 0 then
for i = 0, inbox:getSize() do
local item = inbox:getItem(i)
if item then
toBeDeleted[#toBeDeleted + 1] = item.uid
end
end
if #toBeDeleted > 0 then
for i, v in pairs(toBeDeleted) do
local item = Item(v)
if item then
item:remove()
end
end
end
end
end
end