Skip to content

Commit

Permalink
refactor. Updating module logic
Browse files Browse the repository at this point in the history
Co-authored-by: DEV Seaferer <91832265+edgardavid94@users.noreply.github.com>
  • Loading branch information
pangolp and Seaferer committed Sep 13, 2024
1 parent 92bf84b commit 10345cf
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 132 deletions.
20 changes: 10 additions & 10 deletions conf/mod_aoe_loot.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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
172 changes: 59 additions & 113 deletions src/aoe_loot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,140 +17,86 @@

#include "aoe_loot.h"

void OnCreatureLootAOE(Player* player, ObjectGuid lootguid)
void AOELootPlayer::OnLogin(Player* player)
{
bool _enable = sConfigMgr->GetOption<bool>("AOELoot.Enable", true);

if (!_enable)
return;

if (!lootguid.IsCreature())
return;

float range = sConfigMgr->GetOption<float>("AOELoot.Range", 30.0);

std::list<Creature*> deadCreatures;
uint32 gold = 0;
player->GetDeadCreatureListInGrid(deadCreatures, range);

for (auto& _creature : deadCreatures)
if (sConfigMgr->GetOption<bool>("AOELoot.Enable", true))
{
Loot* loot = &_creature->loot;
gold += loot->gold;
loot->gold = 0;
uint8 maxSlot = loot->GetMaxSlotInLootFor(player);
if (sConfigMgr->GetOption<bool>("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<bool>("AOELoot.Enable", true))
return true;

player->SendItemRetrievalMail(lootItem->itemid, lootItem->count);
}
else
{
player->SendLootRelease(player->GetLootGUID());
}
}
if (player->GetGroup() && !sConfigMgr->GetOption<bool>("AOELoot.Group", true))
return true;

if (loot->isLooted())
{
player->GetSession()->DoLootRelease(lootguid);
float range = sConfigMgr->GetOption<float>("AOELoot.Range", 55.0);

// skip pickpocketing loot for speed, skinning timer reduction is no-op in fact
if (!_creature->IsAlive())
_creature->AllLootRemovedFromCorpse();
std::list<Creature*> 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<Player*> 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<Player*>::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<bool>("AOELoot.Enable", true))
{
if (sConfigMgr->GetOption<bool>("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;
}
21 changes: 12 additions & 9 deletions src/aoe_loot.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 10345cf

Please sign in to comment.