local ec = EventCallback
local lootRate = {
["rat"] = 1,
["dragon"] = 1,
["rotworm"] = 2,
}
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 monsterName = mType:getName():lower()
local customRate = 1
if lootRate[monsterName] then
customRate = lootRate[monsterName]
end
if not player or player:getStamina() > 840 then
local monsterLoot = mType:getLoot()
for i = 1, #monsterLoot do
if monsterLoot[i].chance then
monsterLoot[i].chance = math.min(monsterLoot[i].chance * customRate, MAX_LOOTCHANCE)
end
end
for i = 1, #monsterLoot do
local item = corpse:createLootItem(monsterLoot[i], self:getName())
if not item then
print('[Warning] DropLoot:', 'Could not add loot item to corpse.')
end
end
local gold = 0
if corpse:isContainer() then
local container = Container(corpse:getUniqueId())
if container then
for slot = 0, container:getSize() - 1 do
local item = container:getItem(slot)
if item and item:getId() == ITEM_GOLD_COIN then
gold = gold + item:getCount()
item:remove()
end
end
else
print("[Warning] DropLoot:", "Container not found.")
end
end
local text = ("Botín de %s: %s"):format(mType:getNameDescription(), corpse:getContentDescription())
if gold > 0 then
player:addMoney(gold)
local balance = player:getBankBalance()
player:setBankBalance(balance + gold)
text = ("%s, x%d monedas de oro fueron enviadas a su saldo bancario."):format(text, gold)
end
local party = player:getParty()
if party then
party:broadcastPartyLoot(text)
else
player:sendChannelMessage("", text, TALKTYPE_CHANNEL_O, 6)
end
else
local text = ("Botín de %s: nada (debido a la baja resistencia)"):format(mType:getNameDescription())
local party = player:getParty()
if party then
party:broadcastPartyLoot(text)
else
player:sendTextMessage(MESSAGE_INFO_DESCR, text)
end
end
end
ec:register()