From 10345cf4d6449a572f46a2fcb212c96ea745965a Mon Sep 17 00:00:00 2001 From: Pagani Walter Date: Fri, 13 Sep 2024 04:47:58 -0300 Subject: [PATCH] refactor. Updating module logic Co-authored-by: DEV Seaferer <91832265+edgardavid94@users.noreply.github.com> --- conf/mod_aoe_loot.conf.dist | 20 ++--- src/aoe_loot.cpp | 172 +++++++++++++----------------------- src/aoe_loot.h | 21 +++-- 3 files changed, 81 insertions(+), 132 deletions(-) diff --git a/conf/mod_aoe_loot.conf.dist b/conf/mod_aoe_loot.conf.dist index 4b3c64c..cb7abfc 100644 --- a/conf/mod_aoe_loot.conf.dist +++ b/conf/mod_aoe_loot.conf.dist @@ -35,19 +35,19 @@ AOELoot.Enable = 1 AOELoot.Message = 1 # -# AOELoot.MailEnable -# Description: Enables the sending of mail if there are no spaces in the bags. -# Default: 1 (Enabled) -# Possible values: 0 - (Disabled) -# 1 - (Enabled) +# AOELoot.Range +# Description: Maximum reach range search loot. +# Default: 55.0 # -AOELoot.MailEnable = 1 +AOELoot.Range = 55.0 # -# AOELoot.Range -# Description: Maximum reach range search loot. -# Default: 30.0 +# AOELoot.Group +# Description: Enables area loot if the player is in a group +# Default: 1 (Enabled) +# Possible values: 0 - (Disabled) +# 1 - (Enabled) # -AOELoot.Range = 30.0 +AOELoot.Group = 1 diff --git a/src/aoe_loot.cpp b/src/aoe_loot.cpp index 9949d2f..bb5e823 100644 --- a/src/aoe_loot.cpp +++ b/src/aoe_loot.cpp @@ -17,140 +17,86 @@ #include "aoe_loot.h" -void OnCreatureLootAOE(Player* player, ObjectGuid lootguid) +void AOELootPlayer::OnLogin(Player* player) { - bool _enable = sConfigMgr->GetOption("AOELoot.Enable", true); - - if (!_enable) - return; - - if (!lootguid.IsCreature()) - return; - - float range = sConfigMgr->GetOption("AOELoot.Range", 30.0); - - std::list deadCreatures; - uint32 gold = 0; - player->GetDeadCreatureListInGrid(deadCreatures, range); - - for (auto& _creature : deadCreatures) + if (sConfigMgr->GetOption("AOELoot.Enable", true)) { - Loot* loot = &_creature->loot; - gold += loot->gold; - loot->gold = 0; - uint8 maxSlot = loot->GetMaxSlotInLootFor(player); + if (sConfigMgr->GetOption("AOELoot.Message", true)) + ChatHandler(player->GetSession()).PSendSysMessage(AOE_ACORE_STRING_MESSAGE); + } +} - for (uint32 lootSlot = 0; lootSlot < maxSlot; ++lootSlot) - { - InventoryResult msg; - LootItem* lootItem = player->StoreLootItem(lootSlot, loot, msg); +bool AOELootServer::CanPacketReceive(WorldSession* session, WorldPacket& packet) +{ + if (packet.GetOpcode() == CMSG_LOOT) + { + Player* player = session->GetPlayer(); - if (msg != EQUIP_ERR_OK && lootguid.IsItem() && loot->loot_type != LOOT_CORPSE) - { - lootItem->is_looted = true; - loot->NotifyItemRemoved(lootItem->itemIndex); - loot->unlootedCount--; + if (!sConfigMgr->GetOption("AOELoot.Enable", true)) + return true; - player->SendItemRetrievalMail(lootItem->itemid, lootItem->count); - } - else - { - player->SendLootRelease(player->GetLootGUID()); - } - } + if (player->GetGroup() && !sConfigMgr->GetOption("AOELoot.Group", true)) + return true; - if (loot->isLooted()) - { - player->GetSession()->DoLootRelease(lootguid); + float range = sConfigMgr->GetOption("AOELoot.Range", 55.0); - // skip pickpocketing loot for speed, skinning timer reduction is no-op in fact - if (!_creature->IsAlive()) - _creature->AllLootRemovedFromCorpse(); + std::list lootcreature; player->GetDeadCreatureListInGrid(lootcreature, range); - _creature->RemoveDynamicFlag(UNIT_DYNFLAG_LOOTABLE); - loot->clear(); - } - } + ObjectGuid guid; packet >> guid; - if (player->GetGroup()) - { - Group* group = player->GetGroup(); + Loot* mainloot = &(player->GetMap()->GetCreature(guid))->loot; - std::vector playersNear; - for (GroupReference* itr = group->GetFirstMember(); itr != nullptr; itr = itr->next()) + for (auto itr = lootcreature.begin(); itr != lootcreature.end(); ++itr) { - Player* member = itr->GetSource(); - if (!member) - continue; + Creature* creature = *itr; - if (player->IsAtLootRewardDistance(member)) - playersNear.push_back(member); - } - - uint32 goldPerPlayer = uint32((gold) / (playersNear.size())); - - for (std::vector::const_iterator i = playersNear.begin(); i != playersNear.end(); ++i) - { - (*i)->ModifyMoney(goldPerPlayer); - (*i)->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_LOOT_MONEY, goldPerPlayer); + // Prevent infiny add items + if (creature->GetGUID() == guid) + continue; - WorldPacket data(SMSG_LOOT_MONEY_NOTIFY, 4 + 1); - data << uint32(goldPerPlayer); - data << uint8(playersNear.size() > 1 ? 0 : 1); - (*i)->GetSession()->SendPacket(&data); - } - } - else - { - player->ModifyMoney(gold); - player->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_LOOT_MONEY, gold); + // Prevent steal loot + if (!player->GetMap()->Instanceable()) + if (!player->isAllowedToLoot(creature)) + continue; - WorldPacket data(SMSG_LOOT_MONEY_NOTIFY, 4 + 1); - data << uint32(gold); - data << uint8(1); - player->GetSession()->SendPacket(&data); - } -} + // Max 15 items per creature + if (mainloot->items.size() + mainloot->quest_items.size() > 15) + break; -void AoeLootPlayer::OnLogin(Player* player) -{ - if (sConfigMgr->GetOption("AOELoot.Enable", true)) - { - if (sConfigMgr->GetOption("AOELoot.Message", true)) - ChatHandler(player->GetSession()).PSendSysMessage(AOE_ACORE_STRING_MESSAGE); - } -} + Loot* loot = &(*itr)->loot; -bool AoeLootPlayer::CanSendErrorAlreadyLooted(Player* /*player*/) -{ - return true; -} + // FILL QITEMS + if (!loot->quest_items.empty()) + { + mainloot->items.insert(mainloot->items.end(), loot->quest_items.begin(), loot->quest_items.end()); + loot->quest_items.clear(); + } -void AoeLootPlayer::OnLootItem(Player* player, Item* /*item*/, uint32 /*count*/, ObjectGuid lootguid) -{ - OnCreatureLootAOE(player, lootguid); -} + // FILL GOLD + if (loot->gold != 0) + { + mainloot->gold += loot->gold; + loot->gold = 0; + } -void AoeLootPlayer::OnBeforeLootMoney(Player* player, Loot* /*loot*/) -{ - OnCreatureLootAOE(player, player->GetLootGUID()); -} + // FILL ITEMS + if (!loot->items.empty()) + { + mainloot->items.insert(mainloot->items.end(), loot->items.begin(), loot->items.end()); + loot->items.clear(); + } -/* -* This function is responsible for deleting the player's leftover items. -* But it only deletes those that are from a quest, and that cannot be obtained if the quest were not being carried out. -* Since there are some items that can be obtained even if you are not doing a quest. -*/ -void AoeLootPlayer::OnPlayerCompleteQuest(Player* player, Quest const* quest) -{ - for (uint8 i = 0; i < QUEST_ITEM_OBJECTIVES_COUNT; ++i) - { - if (ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(quest->RequiredItemId[i])) - { - if ((itemTemplate->Bonding == BIND_QUEST_ITEM) && (!quest->IsRepeatable())) + // Set flag for skinning + if (loot->items.empty() && loot->quest_items.empty()) { - player->DestroyItemCount(quest->RequiredItemId[i], 9999, true); + creature->AllLootRemovedFromCorpse(); + creature->RemoveDynamicFlag(UNIT_DYNFLAG_LOOTABLE); } } + + player->SendLoot(guid, LOOT_CORPSE); + return false; } + + return true; } diff --git a/src/aoe_loot.h b/src/aoe_loot.h index 8ec77e1..17ae33c 100644 --- a/src/aoe_loot.h +++ b/src/aoe_loot.h @@ -30,23 +30,26 @@ enum AoeLootString AOE_ITEM_IN_THE_MAIL }; -void OnCreatureLootAOE(Player* player, ObjectGuid lootguid); - -class AoeLootPlayer : public PlayerScript +class AOELootPlayer : public PlayerScript { public: - AoeLootPlayer() : PlayerScript("AoeLootPlayer") { } + AOELootPlayer() : PlayerScript("AOELootPlayer") { } void OnLogin(Player* player) override; - bool CanSendErrorAlreadyLooted(Player* /*player*/) override; - void OnLootItem(Player* player, Item* /*item*/, uint32 /*count*/, ObjectGuid lootguid) override; - void OnBeforeLootMoney(Player* player, Loot* /*loot*/) override; - void OnPlayerCompleteQuest(Player* player, Quest const* quest) override; +}; + +class AOELootServer : public ServerScript +{ +public: + AOELootServer() : ServerScript("AOELootServer") { } + + bool CanPacketReceive(WorldSession* session, WorldPacket& packet) override; }; void AddSC_AoeLoot() { - new AoeLootPlayer(); + new AOELootPlayer(); + new AOELootServer(); } #endif //MODULE_AOELOOT_H