chore. Add group loot (#30)

* Add group loot

* fix. loot in group

* Distribute the gold obtained, in a group or alone
This commit is contained in:
Walter Pagani
2024-03-11 05:00:48 -03:00
committed by GitHub
parent 8b197baa3b
commit d777d183c5

View File

@@ -15,7 +15,6 @@
* with this program. If not, see <http://www.gnu.org/licenses/>. * with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "Log.h"
#include "ScriptMgr.h" #include "ScriptMgr.h"
#include "Config.h" #include "Config.h"
#include "Chat.h" #include "Chat.h"
@@ -28,7 +27,6 @@ enum AoeLootString
AOE_ITEM_IN_THE_MAIL AOE_ITEM_IN_THE_MAIL
}; };
typedef std::map<uint32, uint32> AOEContainer;
class AoeLoot_Player : public PlayerScript class AoeLoot_Player : public PlayerScript
{ {
@@ -55,87 +53,58 @@ public:
if (!_enable) if (!_enable)
return; return;
std::list<Creature*> deadCreatures;
float range = sConfigMgr->GetOption<float>("AOELoot.Range", 30.0); float range = sConfigMgr->GetOption<float>("AOELoot.Range", 30.0);
uint32 gold = 0; uint32 gold = 0;
std::list<Creature*> deadCreatures; player->GetDeadCreatureListInGrid(deadCreatures, range);
deadCreatures.clear();
AOEContainer aoeLoot;
player->GetDeadCreatureListInGrid(deadCreatures, range, false);
for (auto& _creature : deadCreatures) for (auto& _creature : deadCreatures)
{ {
if (player->GetGroup()) ObjectGuid lootGuid = player->GetLootGUID();
Loot* loot = &_creature->loot;
gold += loot->gold;
loot->gold = 0;
uint8 maxSlot = loot->GetMaxSlotInLootFor(player);
for (uint32 lootSlot = 0; lootSlot < maxSlot; ++lootSlot)
{ {
if (player->GetGroup()->GetMembersCount() > 1) InventoryResult msg;
LootItem* lootItem = player->StoreLootItem(lootSlot, loot, msg);
if (msg != EQUIP_ERR_OK && lootGuid.IsItem() && loot->loot_type != LOOT_CORPSE)
{ {
if (_creature->IsDungeonBoss() || _creature->isWorldBoss()) lootItem->is_looted = true;
continue; loot->NotifyItemRemoved(lootItem->itemIndex);
} loot->unlootedCount--;
else if (player->GetGroup()->GetMembersCount() == 1)
{ player->SendItemRetrievalMail(lootItem->itemid, lootItem->count);
player->GetGroup()->SetLootMethod(FREE_FOR_ALL);
} }
} }
if (player == _creature->GetLootRecipient() && (_creature->HasDynamicFlag(UNIT_DYNFLAG_LOOTABLE))) if (loot->isLooted())
{ {
Loot* loot = &_creature->loot; // skip pickpocketing loot for speed, skinning timer reduction is no-op in fact
gold += loot->gold; if (!_creature->IsAlive())
loot->gold = 0;
for (auto const& item : loot->items)
{
if (loot->items.size() > 1 && (loot->items[item.itemIndex].itemid == loot->items[item.itemIndex + 1].itemid))
continue;
ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(item.itemid);
if (itemTemplate->MaxCount != 1)
{
aoeLoot[item.itemid] += (uint32)item.count;
}
else
{
if (!player->HasItemCount(item.itemid, 1, true))
aoeLoot[item.itemid] = 1;
}
}
for (auto const& item : loot->quest_items)
{
aoeLoot[item.itemid] += (uint32)item.count;
}
player->SendLootRelease(player->GetLootGUID());
if (!loot->empty())
{
if (!_creature->IsAlive())
{
_creature->AllLootRemovedFromCorpse();
_creature->RemoveFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_LOOTABLE);
loot->clear();
}
}
else
{
_creature->RemoveFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_LOOTABLE);
_creature->AllLootRemovedFromCorpse(); _creature->AllLootRemovedFromCorpse();
}
}
}
for (auto const& [itemId, count] : aoeLoot) _creature->RemoveDynamicFlag(UNIT_DYNFLAG_LOOTABLE);
{ loot->clear();
if (!player->AddItem(itemId, count)) }
else
{ {
if (sConfigMgr->GetOption<bool>("AOELoot.MailEnable", true)) // if the round robin player release, reset it.
if (player->GetGUID() == loot->roundRobinPlayer)
{ {
player->SendItemRetrievalMail(itemId, count); loot->roundRobinPlayer.Clear();
ChatHandler(player->GetSession()).SendSysMessage(AOE_ITEM_IN_THE_MAIL);
if (Group* group = player->GetGroup())
group->SendLooter(_creature, nullptr);
} }
// force dynflag update to update looter and lootable info
_creature->ForceValuesUpdateAtIndex(UNIT_DYNAMIC_FLAGS);
} }
} }