local ec = EventCallback
ec.onDropLoot = function(self, corpse)
if configManager.getNumber(configKeys.RATE_LOOT) == 0 then
return
end
local player = Player(corpse:getCorpseOwner())
local mType = self:getType()
local monsterLoot = mType:getLoot()
for i = 1, #monsterLoot do
local item = corpse:createLootItem(monsterLoot[i])
if not item then
print('[Warning] DropLoot:', 'Could not add loot item to corpse.')
end
end
if player then
local autolootContainer = Game.createItem(1987, 1)
local items = corpse:getItems()
local item_weight = 0
local item_slots = 0
for _, item in ipairs(items) do
if (player:getAutoLootItem(item.itemid)) then
item_weight = item_weight + item:getWeight()
item_slots = item_slots + 1
end
end
local bp = player:getSlotItem(CONST_SLOT_BACKPACK)
if bp and bp:getEmptySlots(true) < item_slots then
player:sendCancelMessage("Autoloot: No space in backpack!")
elseif player:getFreeCapacity() < (item_weight * 100) then
player:sendCancelMessage("Autoloot: Not enough cap!")
else
for _, item in ipairs(items) do
if (player:getAutoLootItem(item.itemid)) then
item:moveTo(autolootContainer)
end
end
end
local text = ("Loot of %s: %s"):format(mType:getNameDescription(), corpse:getContentDescription())
if (autolootContainer:getSize() > 0) then
text = text .. ' and ' .. autolootContainer:getContentDescription() .. ' that was auto looted'
local autolootItems = autolootContainer:getItems()
for _, item in ipairs(autolootItems) do
item:moveTo(player)
end
end
autolootContainer:remove()
text = text .. '.'
local party = player:getParty()
if party then
party:broadcastPartyLoot(text)
else
player:sendTextMessage(MESSAGE_INFO_DESCR, text)
end
end
end
ec:register()