AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
Loot Struct Reference

#include "LootMgr.h"

Public Member Functions

QuestItemMap const & GetPlayerQuestItems () const
 
QuestItemMap const & GetPlayerFFAItems () const
 
QuestItemMap const & GetPlayerNonQuestNonFFAConditionalItems () const
 
 Loot (uint32 _gold=0)
 
 ~Loot ()
 
void addLootValidatorRef (LootValidatorRef *pLootValidatorRef)
 
void clear ()
 
bool empty () const
 
bool isLooted () const
 
void NotifyItemRemoved (uint8 lootIndex)
 
void NotifyQuestItemRemoved (uint8 questIndex)
 
void NotifyMoneyRemoved ()
 
void AddLooter (ObjectGuid GUID)
 
void RemoveLooter (ObjectGuid GUID)
 
void generateMoneyLoot (uint32 minAmount, uint32 maxAmount)
 
bool FillLoot (uint32 lootId, LootStore const &store, Player *lootOwner, bool personal, bool noEmptyError=false, uint16 lootMode=LOOT_MODE_DEFAULT, WorldObject *lootSource=nullptr)
 
void AddItem (LootStoreItem const &item)
 
LootItemLootItemInSlot (uint32 lootslot, Player *player, QuestItem **qitem=nullptr, QuestItem **ffaitem=nullptr, QuestItem **conditem=nullptr)
 
uint32 GetMaxSlotInLootFor (Player *player) const
 
bool hasItemForAll () const
 
bool hasItemFor (Player *player) const
 
bool hasOverThresholdItem () const
 
void FillNotNormalLootFor (Player *player)
 

Public Attributes

std::vector< LootItemitems
 
std::vector< LootItemquest_items
 
uint32 gold
 
uint8 unlootedCount {0}
 
ObjectGuid roundRobinPlayer
 
ObjectGuid lootOwnerGUID
 
LootType loot_type {LOOT_NONE}
 
ObjectGuid containerGUID
 
ObjectGuid sourceWorldObjectGUID
 
GameObjectsourceGameObject {nullptr}
 

Private Types

typedef GuidSet PlayersLootingSet
 

Private Member Functions

QuestItemListFillFFALoot (Player *player)
 
QuestItemListFillQuestLoot (Player *player)
 
QuestItemListFillNonQuestNonFFAConditionalLoot (Player *player)
 

Private Attributes

PlayersLootingSet PlayersLooting
 
QuestItemMap PlayerQuestItems
 
QuestItemMap PlayerFFAItems
 
QuestItemMap PlayerNonQuestNonFFAConditionalItems
 
LootValidatorRefMgr i_LootValidatorRefMgr
 

Friends

ByteBufferoperator<< (ByteBuffer &b, LootView const &lv)
 

Detailed Description

Member Typedef Documentation

◆ PlayersLootingSet

Constructor & Destructor Documentation

◆ Loot()

Loot::Loot ( uint32  _gold = 0)
inline
333: gold(_gold) { }
uint32 gold
Definition LootMgr.h:322

◆ ~Loot()

Loot::~Loot ( )
inline
334{ clear(); }
void clear()
Definition LootMgr.h:343

References clear().

Member Function Documentation

◆ AddItem()

void Loot::AddItem ( LootStoreItem const &  item)
513{
514 ItemTemplate const* proto = sObjectMgr->GetItemTemplate(item.itemid);
515 if (!proto)
516 return;
517
518 uint32 count = urand(item.mincount, item.maxcount);
519 uint32 stacks = count / proto->GetMaxStackSize() + (count % proto->GetMaxStackSize() ? 1 : 0);
520
521 std::vector<LootItem>& lootItems = item.needs_quest ? quest_items : items;
522 uint32 limit = item.needs_quest ? MAX_NR_QUEST_ITEMS : MAX_NR_LOOT_ITEMS;
523
524 for (uint32 i = 0; i < stacks && lootItems.size() < limit; ++i)
525 {
526 LootItem generatedLoot(item);
527 generatedLoot.count = std::min(count, proto->GetMaxStackSize());
528 generatedLoot.itemIndex = lootItems.size();
529 lootItems.push_back(generatedLoot);
530 count -= proto->GetMaxStackSize();
531
532 // In some cases, a dropped item should be visible/lootable only for some players in group
533 bool canSeeItemInLootWindow = false;
534 if (auto player = ObjectAccessor::FindPlayer(lootOwnerGUID))
535 {
536 if (auto group = player->GetGroup())
537 {
538 for (auto itr = group->GetFirstMember(); itr != nullptr; itr = itr->next())
539 {
540 if (auto member = itr->GetSource())
541 {
542 if (generatedLoot.AllowedForPlayer(member, sourceWorldObjectGUID))
543 {
544 canSeeItemInLootWindow = true;
545 break;
546 }
547 }
548 }
549 }
550 else if (generatedLoot.AllowedForPlayer(player, sourceWorldObjectGUID))
551 {
552 canSeeItemInLootWindow = true;
553 }
554 }
555
556 if (!canSeeItemInLootWindow)
557 {
558 LOG_DEBUG("loot", "Skipping ++unlootedCount for unlootable item: {}", item.itemid);
559 continue;
560 }
561
562 // non-conditional one-player only items are counted here,
563 // free for all items are counted in FillFFALoot(),
564 // non-ffa conditionals are counted in FillNonQuestNonFFAConditionalLoot()
565 if (!item.needs_quest && item.conditions.empty() && !proto->HasFlag(ITEM_FLAG_MULTI_DROP))
567 }
568}
std::uint32_t uint32
Definition Define.h:107
@ ITEM_FLAG_MULTI_DROP
Definition ItemTemplate.h:158
#define LOG_DEBUG(filterType__,...)
Definition Log.h:170
#define MAX_NR_QUEST_ITEMS
Definition LootMgr.h:53
#define MAX_NR_LOOT_ITEMS
Definition LootMgr.h:51
#define sObjectMgr
Definition ObjectMgr.h:1650
uint32 urand(uint32 min, uint32 max)
Definition Random.cpp:44
Player * FindPlayer(ObjectGuid const guid)
Definition ObjectAccessor.cpp:245
Definition ItemTemplate.h:619
uint32 GetMaxStackSize() const
Definition ItemTemplate.h:728
bool HasFlag(ItemFlags flag) const
Definition ItemTemplate.h:826
Definition LootMgr.h:154
ObjectGuid sourceWorldObjectGUID
Definition LootMgr.h:330
uint8 unlootedCount
Definition LootMgr.h:323
ObjectGuid lootOwnerGUID
Definition LootMgr.h:325
std::vector< LootItem > items
Definition LootMgr.h:320
std::vector< LootItem > quest_items
Definition LootMgr.h:321

References LootItem::AllowedForPlayer(), LootStoreItem::conditions, LootItem::count, ObjectAccessor::FindPlayer(), Player::GetGroup(), ItemTemplate::GetMaxStackSize(), ItemTemplate::HasFlag(), ITEM_FLAG_MULTI_DROP, LootStoreItem::itemid, LootItem::itemIndex, items, LOG_DEBUG, lootOwnerGUID, MAX_NR_LOOT_ITEMS, MAX_NR_QUEST_ITEMS, LootStoreItem::maxcount, LootStoreItem::mincount, LootStoreItem::needs_quest, quest_items, sObjectMgr, sourceWorldObjectGUID, unlootedCount, and urand().

Referenced by LootTemplate::Process(), and LootTemplate::LootGroup::Process().

◆ AddLooter()

void Loot::AddLooter ( ObjectGuid  GUID)
inline
373{ PlayersLooting.insert(GUID); }
PlayersLootingSet PlayersLooting
Definition LootMgr.h:395

References PlayersLooting.

Referenced by Player::SendLoot().

◆ addLootValidatorRef()

void Loot::addLootValidatorRef ( LootValidatorRef pLootValidatorRef)
inline
338 {
339 i_LootValidatorRefMgr.insertFirst(pLootValidatorRef);
340 }
void insertFirst(LinkedListElement *pElem)
Definition LinkedList.h:105
LootValidatorRefMgr i_LootValidatorRefMgr
Definition LootMgr.h:401

References i_LootValidatorRefMgr, and LinkedListHead::insertFirst().

Referenced by Roll::targetObjectBuildLink().

◆ clear()

void Loot::clear ( )
inline
344 {
345 for (QuestItemMap::const_iterator itr = PlayerQuestItems.begin(); itr != PlayerQuestItems.end(); ++itr)
346 delete itr->second;
347 PlayerQuestItems.clear();
348
349 for (QuestItemMap::const_iterator itr = PlayerFFAItems.begin(); itr != PlayerFFAItems.end(); ++itr)
350 delete itr->second;
351 PlayerFFAItems.clear();
352
353 for (QuestItemMap::const_iterator itr = PlayerNonQuestNonFFAConditionalItems.begin(); itr != PlayerNonQuestNonFFAConditionalItems.end(); ++itr)
354 delete itr->second;
356
357 PlayersLooting.clear();
358 items.clear();
359 quest_items.clear();
360 gold = 0;
361 unlootedCount = 0;
365 }
@ LOOT_NONE
Definition LootMgr.h:78
void Clear()
Definition ObjectGuid.h:138
void clearReferences()
Definition RefMgr.h:42
QuestItemMap PlayerNonQuestNonFFAConditionalItems
Definition LootMgr.h:398
QuestItemMap PlayerQuestItems
Definition LootMgr.h:396
ObjectGuid roundRobinPlayer
Definition LootMgr.h:324
QuestItemMap PlayerFFAItems
Definition LootMgr.h:397
LootType loot_type
Definition LootMgr.h:326

References ObjectGuid::Clear(), RefMgr< TO, FROM >::clearReferences(), gold, i_LootValidatorRefMgr, items, LOOT_NONE, loot_type, PlayerFFAItems, PlayerNonQuestNonFFAConditionalItems, PlayerQuestItems, PlayersLooting, quest_items, roundRobinPlayer, and unlootedCount.

Referenced by NPCStaveQuestAI::ClearLootIfUnfair(), boss_high_king_maulgar::DoAction(), WorldSession::DoLootRelease(), GameObject::GetFishLoot(), Unit::Kill(), Creature::RemoveCorpse(), Creature::Respawn(), Player::SendLoot(), boss_priestess_delrissa::SummonedCreatureDies(), GameObject::Update(), and ~Loot().

◆ empty()

bool Loot::empty ( ) const
inline

◆ FillFFALoot()

QuestItemList * Loot::FillFFALoot ( Player player)
private
665{
666 QuestItemList* ql = new QuestItemList();
667
668 for (uint8 i = 0; i < items.size(); ++i)
669 {
670 LootItem& item = items[i];
671 if (!item.is_looted && item.freeforall && item.AllowedForPlayer(player, containerGUID))
672 {
673 ql->push_back(QuestItem(i));
675 }
676 }
677 if (ql->empty())
678 {
679 delete ql;
680 return nullptr;
681 }
682
683 PlayerFFAItems[player->GetGUID()] = ql;
684 return ql;
685}
std::uint8_t uint8
Definition Define.h:109
std::vector< QuestItem > QuestItemList
Definition LootMgr.h:198
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:113
bool AllowedForPlayer(Player const *player, ObjectGuid source) const
Definition LootMgr.cpp:417
bool is_looted
Definition LootMgr.h:163
bool freeforall
Definition LootMgr.h:165
ObjectGuid containerGUID
Definition LootMgr.h:329
Definition LootMgr.h:185

References LootItem::AllowedForPlayer(), containerGUID, LootItem::freeforall, Object::GetGUID(), LootItem::is_looted, items, PlayerFFAItems, and unlootedCount.

Referenced by FillNotNormalLootFor().

◆ FillLoot()

bool Loot::FillLoot ( uint32  lootId,
LootStore const &  store,
Player lootOwner,
bool  personal,
bool  noEmptyError = false,
uint16  lootMode = LOOT_MODE_DEFAULT,
WorldObject lootSource = nullptr 
)
572{
573 // Must be provided
574 if (!lootOwner)
575 return false;
576
577 lootOwnerGUID = lootOwner->GetGUID();
578
579 LootTemplate const* tab = store.GetLootFor(lootId);
580
581 if (!tab)
582 {
583 if (!noEmptyError)
584 LOG_ERROR("sql.sql", "Table '{}' loot id #{} used but it doesn't have records.", store.GetName(), lootId);
585 return false;
586 }
587
588 items.reserve(MAX_NR_LOOT_ITEMS);
590
591 // Initial group is 0, top level set to True
592 tab->Process(*this, store, lootMode, lootOwner, 0, true); // Processing is done there, callback via Loot::AddItem()
593
594 sScriptMgr->OnAfterLootTemplateProcess(this, tab, store, lootOwner, personal, noEmptyError, lootMode);
595
596 // Setting access rights for group loot case
597 Group* group = lootOwner->GetGroup();
598 if (!personal && group)
599 {
600 roundRobinPlayer = lootOwner->GetGUID();
601
602 for (GroupReference* itr = group->GetFirstMember(); itr != nullptr; itr = itr->next())
603 {
604 if (Player* player = itr->GetSource()) // should actually be looted object instead of lootOwner but looter has to be really close so doesnt really matter
605 {
606 if (player->IsAtLootRewardDistance(lootSource ? lootSource : lootOwner))
607 {
608 FillNotNormalLootFor(player);
609 }
610 }
611 }
612
613 for (uint8 i = 0; i < items.size(); ++i)
614 {
615 if (ItemTemplate const* proto = sObjectMgr->GetItemTemplate(items[i].itemid))
616 if (proto->Quality < uint32(group->GetLootThreshold()))
617 items[i].is_underthreshold = true;
618 }
619 }
620 // ... for personal loot
621 else
622 FillNotNormalLootFor(lootOwner);
623
624 return true;
625}
#define LOG_ERROR(filterType__,...)
Definition Log.h:158
#define sScriptMgr
Definition ScriptMgr.h:727
Definition GroupReference.h:27
Definition Group.h:169
ItemQualities GetLootThreshold() const
Definition Group.cpp:2330
GroupReference * GetFirstMember()
Definition Group.h:243
Definition LootMgr.h:245
void Process(Loot &loot, LootStore const &store, uint16 lootMode, Player const *player, uint8 groupId=0, bool isTopLevel=true) const
Definition LootMgr.cpp:1699
Definition Player.h:1083
Group * GetGroup()
Definition Player.h:2487
void FillNotNormalLootFor(Player *player)
Definition LootMgr.cpp:627

References FillNotNormalLootFor(), Group::GetFirstMember(), Player::GetGroup(), Object::GetGUID(), LootStore::GetLootFor(), Group::GetLootThreshold(), LootStore::GetName(), Player::IsAtLootRewardDistance(), items, LOG_ERROR, lootOwnerGUID, MAX_NR_LOOT_ITEMS, MAX_NR_QUEST_ITEMS, LootTemplate::Process(), quest_items, roundRobinPlayer, sObjectMgr, and sScriptMgr.

Referenced by Player::AutoStoreLoot(), Group::CountTheRoll(), boss_high_king_maulgar::DoAction(), GameObject::GetFishLoot(), Unit::Kill(), MailDraft::prepareItems(), Player::SendLoot(), and boss_priestess_delrissa::SummonedCreatureDies().

◆ FillNonQuestNonFFAConditionalLoot()

QuestItemList * Loot::FillNonQuestNonFFAConditionalLoot ( Player player)
private
739{
740 QuestItemList* ql = new QuestItemList();
741
742 for (uint8 i = 0; i < items.size(); ++i)
743 {
744 LootItem& item = items[i];
745
746 if (!item.is_looted && !item.freeforall && item.AllowedForPlayer(player, sourceWorldObjectGUID))
747 {
748 item.AddAllowedLooter(player);
749
750 if (!item.conditions.empty())
751 {
752 ql->push_back(QuestItem(i));
753 if (!item.is_counted)
754 {
756 item.is_counted = true;
757 }
758 }
759 }
760 }
761 if (ql->empty())
762 {
763 delete ql;
764 return nullptr;
765 }
766
768 return ql;
769}
void AddAllowedLooter(Player const *player)
Definition LootMgr.cpp:502
ConditionList conditions
Definition LootMgr.h:159
bool is_counted
Definition LootMgr.h:167

References LootItem::AddAllowedLooter(), LootItem::AllowedForPlayer(), LootItem::conditions, LootItem::freeforall, Object::GetGUID(), LootItem::is_counted, LootItem::is_looted, items, PlayerNonQuestNonFFAConditionalItems, sourceWorldObjectGUID, and unlootedCount.

Referenced by FillNotNormalLootFor().

◆ FillNotNormalLootFor()

void Loot::FillNotNormalLootFor ( Player player)
628{
629 ObjectGuid playerGuid = player->GetGUID();
630
631 QuestItemMap::const_iterator qmapitr = PlayerQuestItems.find(playerGuid);
632 if (qmapitr == PlayerQuestItems.end())
633 FillQuestLoot(player);
634
635 qmapitr = PlayerFFAItems.find(playerGuid);
636 if (qmapitr == PlayerFFAItems.end())
637 FillFFALoot(player);
638
639 qmapitr = PlayerNonQuestNonFFAConditionalItems.find(playerGuid);
640 if (qmapitr == PlayerNonQuestNonFFAConditionalItems.end())
642
643 // Process currency items
644 uint32 max_slot = GetMaxSlotInLootFor(player);
645 LootItem const* item = nullptr;
646 uint32 itemsSize = uint32(items.size());
647 for (uint32 i = 0; i < max_slot; ++i)
648 {
649 if (i < items.size())
650 item = &items[i];
651 else
652 item = &quest_items[i - itemsSize];
653
654 if (!item->is_looted && item->freeforall && item->AllowedForPlayer(player, sourceWorldObjectGUID))
655 if (ItemTemplate const* proto = sObjectMgr->GetItemTemplate(item->itemid))
656 if (proto->IsCurrencyToken())
657 {
658 InventoryResult msg;
659 player->StoreLootItem(i, this, msg);
660 }
661 }
662}
InventoryResult
Definition Item.h:46
Definition ObjectGuid.h:118
LootItem * StoreLootItem(uint8 lootSlot, Loot *loot, InventoryResult &msg)
Definition Player.cpp:13495
uint32 itemid
Definition LootMgr.h:155
QuestItemList * FillQuestLoot(Player *player)
Definition LootMgr.cpp:687
uint32 GetMaxSlotInLootFor(Player *player) const
Definition LootMgr.cpp:916
QuestItemList * FillFFALoot(Player *player)
Definition LootMgr.cpp:664
QuestItemList * FillNonQuestNonFFAConditionalLoot(Player *player)
Definition LootMgr.cpp:738

References LootItem::AllowedForPlayer(), FillFFALoot(), FillNonQuestNonFFAConditionalLoot(), FillQuestLoot(), LootItem::freeforall, Object::GetGUID(), GetMaxSlotInLootFor(), LootItem::is_looted, LootItem::itemid, items, PlayerFFAItems, PlayerNonQuestNonFFAConditionalItems, PlayerQuestItems, quest_items, sObjectMgr, sourceWorldObjectGUID, and Player::StoreLootItem().

Referenced by FillLoot(), and LootItemStorage::LoadStoredLoot().

◆ FillQuestLoot()

QuestItemList * Loot::FillQuestLoot ( Player player)
private
688{
689 if (items.size() == MAX_NR_LOOT_ITEMS)
690 return nullptr;
691
692 QuestItemList* ql = new QuestItemList();
693
695
696 for (uint8 i = 0; i < quest_items.size(); ++i)
697 {
698 LootItem& item = quest_items[i];
699
700 sScriptMgr->OnPlayerBeforeFillQuestLootItem(player, item);
701
702 // Quest item is not free for all and is already assigned to another player
703 // or player doesn't need it
704 if (item.is_blocked || !item.AllowedForPlayer(player, sourceWorldObjectGUID))
705 {
706 continue;
707 }
708
709 // Player is not the loot owner, and loot owner still needs this quest item
710 if (!item.freeforall &&
711 lootOwner && lootOwner != player &&
713 {
714 continue;
715 }
716
717 ql->push_back(QuestItem(i));
719
720 if (!item.freeforall)
721 {
722 item.is_blocked = true;
723 }
724
725 if (items.size() + ql->size() == MAX_NR_LOOT_ITEMS)
726 break;
727 }
728 if (ql->empty())
729 {
730 delete ql;
731 return nullptr;
732 }
733
734 PlayerQuestItems[player->GetGUID()] = ql;
735 return ql;
736}
bool is_blocked
Definition LootMgr.h:164

References LootItem::AllowedForPlayer(), ObjectAccessor::FindPlayer(), LootItem::freeforall, Object::GetGUID(), LootItem::is_blocked, items, MAX_NR_LOOT_ITEMS, PlayerQuestItems, quest_items, roundRobinPlayer, sourceWorldObjectGUID, sScriptMgr, and unlootedCount.

Referenced by FillNotNormalLootFor().

◆ generateMoneyLoot()

void Loot::generateMoneyLoot ( uint32  minAmount,
uint32  maxAmount 
)
839{
840 if (maxAmount > 0)
841 {
842 if (maxAmount <= minAmount)
843 gold = uint32(maxAmount * sWorld->getRate(RATE_DROP_MONEY));
844 else if ((maxAmount - minAmount) < 32700)
845 gold = uint32(urand(minAmount, maxAmount) * sWorld->getRate(RATE_DROP_MONEY));
846 else
847 gold = uint32(urand(minAmount >> 8, maxAmount >> 8) * sWorld->getRate(RATE_DROP_MONEY)) << 8;
848 }
849}
@ RATE_DROP_MONEY
Definition WorldConfig.h:417
#define sWorld
Definition World.h:320

References gold, RATE_DROP_MONEY, sWorld, and urand().

Referenced by Unit::Kill(), and Player::SendLoot().

◆ GetMaxSlotInLootFor()

uint32 Loot::GetMaxSlotInLootFor ( Player player) const
917{
918 QuestItemMap::const_iterator itr = PlayerQuestItems.find(player->GetGUID());
919 return items.size() + (itr != PlayerQuestItems.end() ? itr->second->size() : 0);
920}

References Object::GetGUID(), items, and PlayerQuestItems.

Referenced by Player::AutoStoreLoot(), Group::CountTheRoll(), FillNotNormalLootFor(), and MailDraft::prepareItems().

◆ GetPlayerFFAItems()

QuestItemMap const & Loot::GetPlayerFFAItems ( ) const
inline
317{ return PlayerFFAItems; }

References PlayerFFAItems.

Referenced by hasItemFor().

◆ GetPlayerNonQuestNonFFAConditionalItems()

QuestItemMap const & Loot::GetPlayerNonQuestNonFFAConditionalItems ( ) const
inline

◆ GetPlayerQuestItems()

QuestItemMap const & Loot::GetPlayerQuestItems ( ) const
inline
316{ return PlayerQuestItems; }

References PlayerQuestItems.

Referenced by hasItemFor(), and Player::StoreLootItem().

◆ hasItemFor()

bool Loot::hasItemFor ( Player player) const
938{
939 QuestItemMap const& lootPlayerQuestItems = GetPlayerQuestItems();
940 QuestItemMap::const_iterator q_itr = lootPlayerQuestItems.find(player->GetGUID());
941 if (q_itr != lootPlayerQuestItems.end())
942 {
943 QuestItemList* q_list = q_itr->second;
944 for (QuestItemList::const_iterator qi = q_list->begin(); qi != q_list->end(); ++qi)
945 {
946 const LootItem& item = quest_items[qi->index];
947 if (!qi->is_looted && !item.is_looted)
948 return true;
949 }
950 }
951
952 QuestItemMap const& lootPlayerFFAItems = GetPlayerFFAItems();
953 QuestItemMap::const_iterator ffa_itr = lootPlayerFFAItems.find(player->GetGUID());
954 if (ffa_itr != lootPlayerFFAItems.end())
955 {
956 QuestItemList* ffa_list = ffa_itr->second;
957 for (QuestItemList::const_iterator fi = ffa_list->begin(); fi != ffa_list->end(); ++fi)
958 {
959 const LootItem& item = items[fi->index];
960 if (!fi->is_looted && !item.is_looted)
961 return true;
962 }
963 }
964
965 QuestItemMap const& lootPlayerNonQuestNonFFAConditionalItems = GetPlayerNonQuestNonFFAConditionalItems();
966 QuestItemMap::const_iterator nn_itr = lootPlayerNonQuestNonFFAConditionalItems.find(player->GetGUID());
967 if (nn_itr != lootPlayerNonQuestNonFFAConditionalItems.end())
968 {
969 QuestItemList* conditional_list = nn_itr->second;
970 for (QuestItemList::const_iterator ci = conditional_list->begin(); ci != conditional_list->end(); ++ci)
971 {
972 const LootItem& item = items[ci->index];
973 if (!ci->is_looted && !item.is_looted)
974 return true;
975 }
976 }
977
978 return false;
979}
std::map< ObjectGuid, QuestItemList * > QuestItemMap
Definition LootMgr.h:200
QuestItemMap const & GetPlayerQuestItems() const
Definition LootMgr.h:316
QuestItemMap const & GetPlayerFFAItems() const
Definition LootMgr.h:317
QuestItemMap const & GetPlayerNonQuestNonFFAConditionalItems() const
Definition LootMgr.h:318

References Object::GetGUID(), GetPlayerFFAItems(), GetPlayerNonQuestNonFFAConditionalItems(), GetPlayerQuestItems(), LootItem::is_looted, items, and quest_items.

Referenced by Player::isAllowedToLoot().

◆ hasItemForAll()

bool Loot::hasItemForAll ( ) const
923{
924 // Gold is always lootable
925 if (gold)
926 {
927 return true;
928 }
929
930 for (LootItem const& item : items)
931 if (!item.is_looted && !item.freeforall && item.conditions.empty())
932 return true;
933 return false;
934}
bool empty() const
Definition LootMgr.h:367

References gold, and items.

Referenced by Player::isAllowedToLoot().

◆ hasOverThresholdItem()

bool Loot::hasOverThresholdItem ( ) const
983{
984 for (uint8 i = 0; i < items.size(); ++i)
985 {
986 if (!items[i].is_looted && !items[i].is_underthreshold && !items[i].freeforall)
987 return true;
988 }
989
990 return false;
991}

References items.

Referenced by Player::isAllowedToLoot(), and Group::SendLooter().

◆ isLooted()

◆ LootItemInSlot()

LootItem * Loot::LootItemInSlot ( uint32  lootslot,
Player player,
QuestItem **  qitem = nullptr,
QuestItem **  ffaitem = nullptr,
QuestItem **  conditem = nullptr 
)
852{
853 LootItem* item = nullptr;
854 bool is_looted = true;
855 if (lootSlot >= items.size())
856 {
857 uint32 questSlot = lootSlot - items.size();
858 QuestItemMap::const_iterator itr = PlayerQuestItems.find(player->GetGUID());
859 if (itr != PlayerQuestItems.end() && questSlot < itr->second->size())
860 {
861 QuestItem* qitem2 = &itr->second->at(questSlot);
862 if (qitem)
863 *qitem = qitem2;
864 item = &quest_items[qitem2->index];
865 if (item->follow_loot_rules && !item->AllowedForPlayer(player, sourceWorldObjectGUID)) // pussywizard: such items (follow_loot_rules) are added to every player, but not everyone is allowed, check it here
866 return nullptr;
867 is_looted = qitem2->is_looted;
868 }
869 }
870 else
871 {
872 item = &items[lootSlot];
873 is_looted = item->is_looted;
874 if (item->freeforall)
875 {
876 QuestItemMap::const_iterator itr = PlayerFFAItems.find(player->GetGUID());
877 if (itr != PlayerFFAItems.end())
878 {
879 for (QuestItemList::const_iterator iter = itr->second->begin(); iter != itr->second->end(); ++iter)
880 if (iter->index == lootSlot)
881 {
882 QuestItem* ffaitem2 = (QuestItem*) & (*iter);
883 if (ffaitem)
884 *ffaitem = ffaitem2;
885 is_looted = ffaitem2->is_looted;
886 break;
887 }
888 }
889 }
890 else if (!item->conditions.empty())
891 {
892 QuestItemMap::const_iterator itr = PlayerNonQuestNonFFAConditionalItems.find(player->GetGUID());
894 {
895 for (QuestItemList::const_iterator iter = itr->second->begin(); iter != itr->second->end(); ++iter)
896 {
897 if (iter->index == lootSlot)
898 {
899 QuestItem* conditem2 = (QuestItem*) & (*iter);
900 if (conditem)
901 *conditem = conditem2;
902 is_looted = conditem2->is_looted;
903 break;
904 }
905 }
906 }
907 }
908 }
909
910 if (is_looted)
911 return nullptr;
912
913 return item;
914}
bool follow_loot_rules
Definition LootMgr.h:169
uint8 index
Definition LootMgr.h:186
bool is_looted
Definition LootMgr.h:187

References LootItem::AllowedForPlayer(), LootItem::conditions, LootItem::follow_loot_rules, LootItem::freeforall, Object::GetGUID(), QuestItem::index, LootItem::is_looted, QuestItem::is_looted, items, PlayerFFAItems, PlayerNonQuestNonFFAConditionalItems, PlayerQuestItems, quest_items, and sourceWorldObjectGUID.

Referenced by Player::AutoStoreLoot(), Group::CountTheRoll(), MailDraft::prepareItems(), and Player::StoreLootItem().

◆ NotifyItemRemoved()

void Loot::NotifyItemRemoved ( uint8  lootIndex)
774{
775 // notify all players that are looting this that the item was removed
776 // convert the index to the slot the player sees
777 PlayersLootingSet::iterator i_next;
778 for (PlayersLootingSet::iterator i = PlayersLooting.begin(); i != PlayersLooting.end(); i = i_next)
779 {
780 i_next = i;
781 ++i_next;
782 if (Player* player = ObjectAccessor::FindPlayer(*i))
783 player->SendNotifyLootItemRemoved(lootIndex);
784 else
785 PlayersLooting.erase(i);
786 }
787}

References ObjectAccessor::FindPlayer(), PlayersLooting, and Player::SendNotifyLootItemRemoved().

Referenced by Group::CountTheRoll(), WorldSession::HandleAutostoreLootItemOpcode(), WorldSession::HandleLootMasterGiveOpcode(), and Player::StoreLootItem().

◆ NotifyMoneyRemoved()

void Loot::NotifyMoneyRemoved ( )
790{
791 // notify all players that are looting this that the money was removed
792 PlayersLootingSet::iterator i_next;
793 for (PlayersLootingSet::iterator i = PlayersLooting.begin(); i != PlayersLooting.end(); i = i_next)
794 {
795 i_next = i;
796 ++i_next;
797 if (Player* player = ObjectAccessor::FindPlayer(*i))
798 player->SendNotifyLootMoneyRemoved();
799 else
800 PlayersLooting.erase(i);
801 }
802}

References ObjectAccessor::FindPlayer(), PlayersLooting, and Player::SendNotifyLootMoneyRemoved().

Referenced by WorldSession::HandleLootMoneyOpcode().

◆ NotifyQuestItemRemoved()

void Loot::NotifyQuestItemRemoved ( uint8  questIndex)
805{
806 // when a free for all questitem is looted
807 // all players will get notified of it being removed
808 // (other questitems can be looted by each group member)
809 // bit inefficient but isn't called often
810
811 PlayersLootingSet::iterator i_next;
812 for (PlayersLootingSet::iterator i = PlayersLooting.begin(); i != PlayersLooting.end(); i = i_next)
813 {
814 i_next = i;
815 ++i_next;
816 if (Player* player = ObjectAccessor::FindPlayer(*i))
817 {
818 QuestItemMap::const_iterator pq = PlayerQuestItems.find(player->GetGUID());
819 if (pq != PlayerQuestItems.end() && pq->second)
820 {
821 // find where/if the player has the given item in it's vector
822 QuestItemList& pql = *pq->second;
823
824 uint8 j;
825 for (j = 0; j < pql.size(); ++j)
826 if (pql[j].index == questIndex)
827 break;
828
829 if (j < pql.size())
830 player->SendNotifyLootItemRemoved(items.size() + j);
831 }
832 }
833 else
834 PlayersLooting.erase(i);
835 }
836}

References ObjectAccessor::FindPlayer(), Object::GetGUID(), items, PlayerQuestItems, PlayersLooting, and Player::SendNotifyLootItemRemoved().

Referenced by Player::StoreLootItem().

◆ RemoveLooter()

void Loot::RemoveLooter ( ObjectGuid  GUID)
inline
374{ PlayersLooting.erase(GUID); }

References PlayersLooting.

Referenced by WorldSession::DoLootRelease().

Friends And Related Symbol Documentation

◆ operator<<

ByteBuffer & operator<< ( ByteBuffer b,
LootView const &  lv 
)
friend
1005{
1006 if (lv.permission == NONE_PERMISSION)
1007 {
1008 b << uint32(0); //gold
1009 b << uint8(0); // item count
1010 return b; // nothing output more
1011 }
1012
1013 Loot& l = lv.loot;
1014
1015 uint8 itemsShown = 0;
1016
1017 b << uint32(l.gold); //gold
1018
1019 std::size_t count_pos = b.wpos(); // pos of item count byte
1020 b << uint8(0); // item count placeholder
1021
1022 switch (lv.permission)
1023 {
1024 case GROUP_PERMISSION:
1025 case MASTER_PERMISSION:
1027 {
1028 bool isMasterLooter = lv.viewer->GetGroup() && lv.viewer->GetGroup()->GetMasterLooterGuid() == lv.viewer->GetGUID();
1029
1030 // if you are not the round-robin group looter, you can only see
1031 // blocked rolled items and quest items, and !ffa items
1032 for (uint8 i = 0; i < l.items.size(); ++i)
1033 {
1034 if (!l.items[i].is_looted && !l.items[i].freeforall && (l.items[i].conditions.empty() || isMasterLooter) && l.items[i].AllowedForPlayer(lv.viewer, l.sourceWorldObjectGUID))
1035 {
1036 uint8 slot_type = 0;
1037
1038 if (l.items[i].is_blocked) // for ML & restricted is_blocked = !is_underthreshold
1039 {
1040 switch (lv.permission)
1041 {
1042 case GROUP_PERMISSION:
1043 slot_type = LOOT_SLOT_TYPE_ROLL_ONGOING;
1044 break;
1045 case MASTER_PERMISSION:
1046 {
1047 if (lv.viewer->GetGroup())
1048 {
1049 if (lv.viewer->GetGroup()->GetMasterLooterGuid() == lv.viewer->GetGUID())
1050 slot_type = LOOT_SLOT_TYPE_MASTER;
1051 else
1052 slot_type = LOOT_SLOT_TYPE_LOCKED;
1053 }
1054 break;
1055 }
1057 slot_type = LOOT_SLOT_TYPE_LOCKED;
1058 break;
1059 default:
1060 continue;
1061 }
1062 }
1063 else if (l.items[i].rollWinnerGUID)
1064 {
1065 if (l.items[i].rollWinnerGUID == lv.viewer->GetGUID())
1066 slot_type = LOOT_SLOT_TYPE_OWNER;
1067 else
1068 continue;
1069 }
1070 else if (!l.roundRobinPlayer || lv.viewer->GetGUID() == l.roundRobinPlayer || !l.items[i].is_underthreshold)
1071 {
1072 // no round robin owner or he has released the loot
1073 // or it IS the round robin group owner
1074 // => item is lootable
1075 slot_type = LOOT_SLOT_TYPE_ALLOW_LOOT;
1076 }
1077 else
1078 // item shall not be displayed.
1079 continue;
1080
1081 b << uint8(i) << l.items[i];
1082 b << uint8(slot_type);
1083 ++itemsShown;
1084 }
1085 }
1086 break;
1087 }
1089 {
1090 for (uint8 i = 0; i < l.items.size(); ++i)
1091 {
1092 if (!l.items[i].is_looted && !l.items[i].freeforall && l.items[i].conditions.empty() && l.items[i].AllowedForPlayer(lv.viewer, l.sourceWorldObjectGUID))
1093 {
1094 if (l.roundRobinPlayer && lv.viewer->GetGUID() != l.roundRobinPlayer)
1095 // item shall not be displayed.
1096 continue;
1097
1098 b << uint8(i) << l.items[i];
1100 ++itemsShown;
1101 }
1102 }
1103 break;
1104 }
1105 case ALL_PERMISSION:
1106 case OWNER_PERMISSION:
1107 {
1109 for (uint8 i = 0; i < l.items.size(); ++i)
1110 {
1111 if (!l.items[i].is_looted && !l.items[i].freeforall && l.items[i].conditions.empty() && l.items[i].AllowedForPlayer(lv.viewer, l.sourceWorldObjectGUID))
1112 {
1113 b << uint8(i) << l.items[i];
1114 b << uint8(slot_type);
1115 ++itemsShown;
1116 }
1117 }
1118 break;
1119 }
1120 default:
1121 return b;
1122 }
1123
1125
1126 // Xinef: items that do not follow loot rules need this
1127 LootSlotType partySlotType = lv.permission == MASTER_PERMISSION ? LOOT_SLOT_TYPE_MASTER : slotType;
1128
1129 QuestItemMap const& lootPlayerQuestItems = l.GetPlayerQuestItems();
1130 QuestItemMap::const_iterator q_itr = lootPlayerQuestItems.find(lv.viewer->GetGUID());
1131 if (q_itr != lootPlayerQuestItems.end())
1132 {
1133 QuestItemList* q_list = q_itr->second;
1134 for (QuestItemList::const_iterator qi = q_list->begin(); qi != q_list->end(); ++qi)
1135 {
1136 LootItem& item = l.quest_items[qi->index];
1137 if (!qi->is_looted && !item.is_looted)
1138 {
1139 bool showInLoot = true;
1140 bool hasQuestForItem = lv.viewer->HasQuestForItem(item.itemid, 0, false, &showInLoot);
1141 if (!hasQuestForItem)
1142 {
1143 if (!showInLoot)
1144 {
1145 const_cast<QuestItem*>(&(*qi))->is_looted = true;
1146 if (!item.freeforall)
1147 {
1148 item.is_looted = true;
1149 }
1150 continue;
1151 }
1152
1153 b << uint8(l.items.size() + (qi - q_list->begin()));
1154 b << item;
1156 }
1157 else
1158 {
1159 b << uint8(l.items.size() + (qi - q_list->begin()));
1160 b << item;
1161
1162 if (item.follow_loot_rules)
1163 {
1164 switch (lv.permission)
1165 {
1166 case MASTER_PERMISSION:
1168 break;
1170 b << (item.is_blocked ? uint8(LOOT_SLOT_TYPE_LOCKED) : uint8(slotType));
1171 break;
1172 case GROUP_PERMISSION:
1174 if (!item.is_blocked)
1176 else
1178 break;
1179 default:
1180 b << uint8(slotType);
1181 break;
1182 }
1183 }
1184 else if (!item.freeforall)
1185 b << uint8(partySlotType);
1186 else
1187 b << uint8(slotType);
1188 }
1189
1190 ++itemsShown;
1191 }
1192 }
1193 }
1194
1195 QuestItemMap const& lootPlayerFFAItems = l.GetPlayerFFAItems();
1196 QuestItemMap::const_iterator ffa_itr = lootPlayerFFAItems.find(lv.viewer->GetGUID());
1197 if (ffa_itr != lootPlayerFFAItems.end())
1198 {
1199 QuestItemList* ffa_list = ffa_itr->second;
1200 for (QuestItemList::const_iterator fi = ffa_list->begin(); fi != ffa_list->end(); ++fi)
1201 {
1202 LootItem& item = l.items[fi->index];
1203 if (!fi->is_looted && !item.is_looted)
1204 {
1205 b << uint8(fi->index);
1206 b << item;
1207 // Xinef: Here are FFA items, so dont use owner permision
1208 b << uint8(LOOT_SLOT_TYPE_ALLOW_LOOT /*slotType*/);
1209 ++itemsShown;
1210 }
1211 }
1212 }
1213
1214 QuestItemMap const& lootPlayerNonQuestNonFFAConditionalItems = l.GetPlayerNonQuestNonFFAConditionalItems();
1215 QuestItemMap::const_iterator nn_itr = lootPlayerNonQuestNonFFAConditionalItems.find(lv.viewer->GetGUID());
1216 if (nn_itr != lootPlayerNonQuestNonFFAConditionalItems.end())
1217 {
1218 QuestItemList* conditional_list = nn_itr->second;
1219 for (QuestItemList::const_iterator ci = conditional_list->begin(); ci != conditional_list->end(); ++ci)
1220 {
1221 LootItem& item = l.items[ci->index];
1222 if (!ci->is_looted && !item.is_looted)
1223 {
1224 b << uint8(ci->index);
1225 b << item;
1226 if (item.follow_loot_rules)
1227 {
1228 switch (lv.permission)
1229 {
1230 case MASTER_PERMISSION:
1232 break;
1234 b << (item.is_blocked ? uint8(LOOT_SLOT_TYPE_LOCKED) : uint8(slotType));
1235 break;
1236 case GROUP_PERMISSION:
1238 if (!item.is_blocked)
1240 else
1242 break;
1243 default:
1244 b << uint8(slotType);
1245 break;
1246 }
1247 }
1248 else if (!item.freeforall)
1249 b << uint8(partySlotType);
1250 else
1251 b << uint8(slotType);
1252 ++itemsShown;
1253 }
1254 }
1255 }
1256
1257 //update number of items shown
1258 b.put<uint8>(count_pos, itemsShown);
1259
1260 return b;
1261}
@ OWNER_PERMISSION
Definition LootMgr.h:72
@ ALL_PERMISSION
Definition LootMgr.h:67
@ RESTRICTED_PERMISSION
Definition LootMgr.h:70
@ NONE_PERMISSION
Definition LootMgr.h:73
@ ROUND_ROBIN_PERMISSION
Definition LootMgr.h:71
@ MASTER_PERMISSION
Definition LootMgr.h:69
@ GROUP_PERMISSION
Definition LootMgr.h:68
LootSlotType
Definition LootMgr.h:113
@ LOOT_SLOT_TYPE_MASTER
Definition LootMgr.h:116
@ LOOT_SLOT_TYPE_ROLL_ONGOING
Definition LootMgr.h:115
@ LOOT_SLOT_TYPE_ALLOW_LOOT
Definition LootMgr.h:114
@ LOOT_SLOT_TYPE_OWNER
Definition LootMgr.h:118
@ LOOT_SLOT_TYPE_LOCKED
Definition LootMgr.h:117
std::size_t wpos() const
Definition ByteBuffer.h:330
void put(std::size_t pos, T value)
Definition ByteBuffer.h:137
Definition LootMgr.h:313

Member Data Documentation

◆ containerGUID

◆ gold

◆ i_LootValidatorRefMgr

LootValidatorRefMgr Loot::i_LootValidatorRefMgr
private

Referenced by addLootValidatorRef(), and clear().

◆ items

◆ loot_type

◆ lootOwnerGUID

ObjectGuid Loot::lootOwnerGUID

Referenced by AddItem(), and FillLoot().

◆ PlayerFFAItems

◆ PlayerNonQuestNonFFAConditionalItems

◆ PlayerQuestItems

◆ PlayersLooting

◆ quest_items

◆ roundRobinPlayer

◆ sourceGameObject

GameObject* Loot::sourceGameObject {nullptr}
331{nullptr};

Referenced by GameObject::GameObject().

◆ sourceWorldObjectGUID

◆ unlootedCount


The documentation for this struct was generated from the following files: