mirror of
https://github.com/azerothcore/mod-aoe-loot
synced 2025-11-29 21:38:16 +08:00
Refactor loot processing and improve readability
This commit is contained in:
@@ -29,11 +29,9 @@ void AOELootPlayer::OnPlayerLogin(Player* player)
|
|||||||
if (sConfigMgr->GetOption<bool>("AOELoot.Message", true))
|
if (sConfigMgr->GetOption<bool>("AOELoot.Message", true))
|
||||||
{
|
{
|
||||||
if (WorldSession* session = player->GetSession())
|
if (WorldSession* session = player->GetSession())
|
||||||
{
|
|
||||||
ChatHandler(session).PSendSysMessage(AOE_ACORE_STRING_MESSAGE);
|
ChatHandler(session).PSendSysMessage(AOE_ACORE_STRING_MESSAGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AOELootServer::CanPacketReceive(WorldSession* session, WorldPacket& packet)
|
bool AOELootServer::CanPacketReceive(WorldSession* session, WorldPacket& packet)
|
||||||
@@ -64,6 +62,7 @@ bool AOELootServer::CanPacketReceive(WorldSession* session, WorldPacket& packet)
|
|||||||
// Limit range to reasonable values
|
// Limit range to reasonable values
|
||||||
if (range < 5.0f)
|
if (range < 5.0f)
|
||||||
range = 5.0f;
|
range = 5.0f;
|
||||||
|
|
||||||
if (range > 100.0f)
|
if (range > 100.0f)
|
||||||
range = 100.0f;
|
range = 100.0f;
|
||||||
|
|
||||||
@@ -107,7 +106,7 @@ bool AOELootServer::CanPacketReceive(WorldSession* session, WorldPacket& packet)
|
|||||||
Loot* mainLoot = &mainCreature->loot;
|
Loot* mainLoot = &mainCreature->loot;
|
||||||
|
|
||||||
// Limit number of corpses to process
|
// Limit number of corpses to process
|
||||||
const size_t maxCorpses = 10; // set to 10 to improve stability
|
size_t const maxCorpses = 10; // set to 10 to improve stability
|
||||||
size_t processedCorpses = 0;
|
size_t processedCorpses = 0;
|
||||||
|
|
||||||
// Track total gold to merge
|
// Track total gold to merge
|
||||||
@@ -135,21 +134,16 @@ bool AOELootServer::CanPacketReceive(WorldSession* session, WorldPacket& packet)
|
|||||||
if (loot->gold > 0)
|
if (loot->gold > 0)
|
||||||
{
|
{
|
||||||
// Prevent overflow
|
// Prevent overflow
|
||||||
if (totalGold < std::numeric_limits<uint32>::max() - loot->gold)
|
if (totalGold < (std::numeric_limits<uint32>::max() - loot->gold))
|
||||||
{
|
|
||||||
totalGold += loot->gold;
|
totalGold += loot->gold;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Collect regular items
|
// Collect regular items
|
||||||
for (size_t i = 0; i < loot->items.size(); ++i)
|
for (size_t i = 0; i < loot->items.size(); ++i)
|
||||||
{
|
{
|
||||||
// Check if there's still space
|
// Check if there's still space
|
||||||
if (mainLoot->items.size() + itemsToAdd.size() +
|
if ((mainLoot->items.size() + itemsToAdd.size() + mainLoot->quest_items.size() + questItemsToAdd.size()) >= 15)
|
||||||
mainLoot->quest_items.size() + questItemsToAdd.size() >= 15)
|
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
itemsToAdd.push_back(loot->items[i]);
|
itemsToAdd.push_back(loot->items[i]);
|
||||||
}
|
}
|
||||||
@@ -158,11 +152,8 @@ bool AOELootServer::CanPacketReceive(WorldSession* session, WorldPacket& packet)
|
|||||||
for (size_t i = 0; i < loot->quest_items.size(); ++i)
|
for (size_t i = 0; i < loot->quest_items.size(); ++i)
|
||||||
{
|
{
|
||||||
// Check if there's still space
|
// Check if there's still space
|
||||||
if (mainLoot->items.size() + itemsToAdd.size() +
|
if ((mainLoot->items.size() + itemsToAdd.size() + mainLoot->quest_items.size() + questItemsToAdd.size()) >= 15)
|
||||||
mainLoot->quest_items.size() + questItemsToAdd.size() >= 15)
|
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
questItemsToAdd.push_back(loot->quest_items[i]);
|
questItemsToAdd.push_back(loot->quest_items[i]);
|
||||||
}
|
}
|
||||||
@@ -183,19 +174,15 @@ bool AOELootServer::CanPacketReceive(WorldSession* session, WorldPacket& packet)
|
|||||||
for (const auto& item : itemsToAdd)
|
for (const auto& item : itemsToAdd)
|
||||||
{
|
{
|
||||||
if (mainLoot->items.size() < 15)
|
if (mainLoot->items.size() < 15)
|
||||||
{
|
|
||||||
mainLoot->items.push_back(item);
|
mainLoot->items.push_back(item);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Add quest items
|
// Add quest items
|
||||||
for (const auto& item : questItemsToAdd)
|
for (const auto& item : questItemsToAdd)
|
||||||
{
|
{
|
||||||
if (mainLoot->quest_items.size() < 15)
|
if (mainLoot->quest_items.size() < 15)
|
||||||
{
|
|
||||||
mainLoot->quest_items.push_back(item);
|
mainLoot->quest_items.push_back(item);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Send merged loot window
|
// Send merged loot window
|
||||||
player->SendLoot(targetGuid, LOOT_CORPSE);
|
player->SendLoot(targetGuid, LOOT_CORPSE);
|
||||||
|
|||||||
Reference in New Issue
Block a user