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();
{
if (player->GetGroup()->GetMembersCount() > 1)
{
if (_creature->IsDungeonBoss() || _creature->isWorldBoss())
continue;
}
else if (player->GetGroup()->GetMembersCount() == 1)
{
player->GetGroup()->SetLootMethod(FREE_FOR_ALL);
}
}
if (player == _creature->GetLootRecipient() && (_creature->HasDynamicFlag(UNIT_DYNFLAG_LOOTABLE)))
{
Loot* loot = &_creature->loot; Loot* loot = &_creature->loot;
gold += loot->gold; gold += loot->gold;
loot->gold = 0; loot->gold = 0;
uint8 maxSlot = loot->GetMaxSlotInLootFor(player);
for (auto const& item : loot->items) for (uint32 lootSlot = 0; lootSlot < maxSlot; ++lootSlot)
{ {
if (loot->items.size() > 1 && (loot->items[item.itemIndex].itemid == loot->items[item.itemIndex + 1].itemid)) InventoryResult msg;
continue; LootItem* lootItem = player->StoreLootItem(lootSlot, loot, msg);
ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(item.itemid); if (msg != EQUIP_ERR_OK && lootGuid.IsItem() && loot->loot_type != LOOT_CORPSE)
{
lootItem->is_looted = true;
loot->NotifyItemRemoved(lootItem->itemIndex);
loot->unlootedCount--;
if (itemTemplate->MaxCount != 1) player->SendItemRetrievalMail(lootItem->itemid, lootItem->count);
{
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) if (loot->isLooted())
{
aoeLoot[item.itemid] += (uint32)item.count;
}
player->SendLootRelease(player->GetLootGUID());
if (!loot->empty())
{ {
// skip pickpocketing loot for speed, skinning timer reduction is no-op in fact
if (!_creature->IsAlive()) if (!_creature->IsAlive())
{
_creature->AllLootRemovedFromCorpse(); _creature->AllLootRemovedFromCorpse();
_creature->RemoveFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_LOOTABLE);
_creature->RemoveDynamicFlag(UNIT_DYNFLAG_LOOTABLE);
loot->clear(); loot->clear();
} }
}
else else
{ {
_creature->RemoveFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_LOOTABLE); // if the round robin player release, reset it.
_creature->AllLootRemovedFromCorpse(); if (player->GetGUID() == loot->roundRobinPlayer)
} {
} loot->roundRobinPlayer.Clear();
}
for (auto const& [itemId, count] : aoeLoot) if (Group* group = player->GetGroup())
{ group->SendLooter(_creature, nullptr);
if (!player->AddItem(itemId, count))
{
if (sConfigMgr->GetOption<bool>("AOELoot.MailEnable", true))
{
player->SendItemRetrievalMail(itemId, count);
ChatHandler(player->GetSession()).SendSysMessage(AOE_ITEM_IN_THE_MAIL);
} }
// force dynflag update to update looter and lootable info
_creature->ForceValuesUpdateAtIndex(UNIT_DYNAMIC_FLAGS);
} }
} }