TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loot Struct Reference

#include <LootMgr.h>

Public Member Functions

QuestItemMap constGetPlayerQuestItems () const
 
QuestItemMap constGetPlayerFFAItems () const
 
QuestItemMap constGetPlayerNonQuestNonFFAConditionalItems () const
 
 Loot (uint32 _gold=0)
 
 ~Loot ()
 
ObjectGuid constGetGUID () const
 
void SetGUID (ObjectGuid const &guid)
 
void DeleteLootItemFromContainerItemDB (uint32 itemID)
 
void DeleteLootMoneyFromContainerItemDB ()
 
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)
 
void AddItem (LootStoreItem const &item)
 
LootItemLootItemInSlot (uint32 lootslot, Player *player, QuestItem **qitem=NULL, QuestItem **ffaitem=NULL, QuestItem **conditem=NULL)
 
uint32 GetMaxSlotInLootFor (Player *player) const
 
bool hasItemFor (Player *player) const
 
bool hasOverThresholdItem () const
 
void BuildLootResponse (WorldPackets::Loot::LootResponse &packet, Player *viewer, PermissionTypes permission=ALL_PERMISSION) const
 

Public Attributes

std::vector< LootItemitems
 
std::vector< LootItemquest_items
 
uint32 gold
 
uint8 unlootedCount
 
ObjectGuid roundRobinPlayer
 
LootType loot_type
 
uint8 maxDuplicates
 
ObjectGuid containerID
 

Private Member Functions

void FillNotNormalLootFor (Player *player, bool presentAtLooting)
 
QuestItemListFillFFALoot (Player *player)
 
QuestItemListFillQuestLoot (Player *player)
 
QuestItemListFillNonQuestNonFFAConditionalLoot (Player *player, bool presentAtLooting)
 

Private Attributes

GuidSet PlayersLooting
 
QuestItemMap PlayerQuestItems
 
QuestItemMap PlayerFFAItems
 
QuestItemMap PlayerNonQuestNonFFAConditionalItems
 
LootValidatorRefManager i_LootValidatorRefManager
 
ObjectGuid _GUID
 
uint32 _difficultyBonusTreeMod
 

Constructor & Destructor Documentation

Loot::Loot ( uint32  _gold = 0)
inline
uint32 _difficultyBonusTreeMod
Definition: LootMgr.h:414
uint8 unlootedCount
Definition: LootMgr.h:323
Definition: LootMgr.h:90
ObjectGuid roundRobinPlayer
Definition: LootMgr.h:324
uint32 gold
Definition: LootMgr.h:322
uint8 maxDuplicates
Definition: LootMgr.h:326
LootType loot_type
Definition: LootMgr.h:325
Loot::~Loot ( )
inline
333 { clear(); }
void clear()
Definition: LootMgr.h:349

Member Function Documentation

void Loot::AddItem ( LootStoreItem const item)
417 {
418  ItemTemplate const* proto = sObjectMgr->GetItemTemplate(item.itemid);
419  if (!proto)
420  return;
421 
422  uint32 count = urand(item.mincount, item.maxcount);
423  uint32 stacks = count / proto->GetMaxStackSize() + ((count % proto->GetMaxStackSize()) ? 1 : 0);
424 
425  std::vector<LootItem>& lootItems = item.needs_quest ? quest_items : items;
426  uint32 limit = item.needs_quest ? MAX_NR_QUEST_ITEMS : MAX_NR_LOOT_ITEMS;
427 
428  for (uint32 i = 0; i < stacks && lootItems.size() < limit; ++i)
429  {
430  LootItem generatedLoot(item);
431  generatedLoot.count = std::min(count, proto->GetMaxStackSize());
433  {
434  std::set<uint32> bonusListIDs = sDB2Manager.GetItemBonusTree(generatedLoot.itemid, _difficultyBonusTreeMod);
435  generatedLoot.BonusListIDs.insert(generatedLoot.BonusListIDs.end(), bonusListIDs.begin(), bonusListIDs.end());
436  }
437 
438  lootItems.push_back(generatedLoot);
439  count -= proto->GetMaxStackSize();
440 
441  // non-conditional one-player only items are counted here,
442  // free for all items are counted in FillFFALoot(),
443  // non-ffa conditionals are counted in FillNonQuestNonFFAConditionalLoot()
444  if (!item.needs_quest && item.conditions.empty() && !(proto->GetFlags() & ITEM_FLAG_PARTY_LOOT))
445  ++unlootedCount;
446  }
447 }
#define MAX_NR_LOOT_ITEMS
Definition: LootMgr.h:60
#define sDB2Manager
Definition: DB2Stores.h:224
uint32 _difficultyBonusTreeMod
Definition: LootMgr.h:414
Definition: ItemTemplate.h:184
#define sObjectMgr
Definition: ObjectMgr.h:1567
T min(const T &x, const T &y)
Definition: g3dmath.h:305
uint8 unlootedCount
Definition: LootMgr.h:323
uint32 urand(uint32 min, uint32 max)
Definition: Random.cpp:45
uint32_t uint32
Definition: Define.h:150
uint32 GetMaxStackSize() const
Definition: ItemTemplate.h:745
Definition: LootMgr.h:157
std::vector< LootItem > items
Definition: LootMgr.h:320
Definition: ItemTemplate.h:647
uint32 GetFlags() const
Definition: ItemTemplate.h:656
#define MAX_NR_QUEST_ITEMS
Definition: LootMgr.h:62
std::vector< LootItem > quest_items
Definition: LootMgr.h:321

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Loot::AddLooter ( ObjectGuid  GUID)
inline
380 { PlayersLooting.insert(GUID); }
GuidSet PlayersLooting
Definition: LootMgr.h:404
void Loot::addLootValidatorRef ( LootValidatorRef pLootValidatorRef)
inline
344  {
345  i_LootValidatorRefManager.insertFirst(pLootValidatorRef);
346  }
void insertFirst(LinkedListElement *pElem)
Definition: LinkedList.h:110
LootValidatorRefManager i_LootValidatorRefManager
Definition: LootMgr.h:410

+ Here is the caller graph for this function:

void Loot::BuildLootResponse ( WorldPackets::Loot::LootResponse packet,
Player viewer,
PermissionTypes  permission = ALL_PERMISSION 
) const
861 {
862  if (permission == NONE_PERMISSION)
863  return;
864 
865  packet.Coins = gold;
866 
867  switch (permission)
868  {
869  case GROUP_PERMISSION:
870  case MASTER_PERMISSION:
872  {
873  // if you are not the round-robin group looter, you can only see
874  // blocked rolled items and quest items, and !ffa items
875  for (uint8 i = 0; i < items.size(); ++i)
876  {
877  if (!items[i].is_looted && !items[i].freeforall && items[i].conditions.empty() && items[i].AllowedForPlayer(viewer))
878  {
879  uint8 slot_type;
880 
881  if (items[i].is_blocked) // for ML & restricted is_blocked = !is_underthreshold
882  {
883  switch (permission)
884  {
885  case GROUP_PERMISSION:
886  slot_type = LOOT_SLOT_TYPE_ROLL_ONGOING;
887  break;
888  case MASTER_PERMISSION:
889  {
890  if (viewer->GetGroup() && viewer->GetGroup()->GetMasterLooterGuid() == viewer->GetGUID())
891  slot_type = LOOT_SLOT_TYPE_MASTER;
892  else
893  slot_type = LOOT_SLOT_TYPE_LOCKED;
894  break;
895  }
897  slot_type = LOOT_SLOT_TYPE_LOCKED;
898  break;
899  default:
900  continue;
901  }
902  }
903  else if (roundRobinPlayer.IsEmpty() || viewer->GetGUID() == roundRobinPlayer || !items[i].is_underthreshold)
904  {
905  // no round robin owner or he has released the loot
906  // or it IS the round robin group owner
907  // => item is lootable
908  slot_type = LOOT_SLOT_TYPE_ALLOW_LOOT;
909  }
910  else
911  // item shall not be displayed.
912  continue;
913 
915  lootItem.LootListID = packet.Items.size()+1;
916  lootItem.UIType = slot_type;
917  lootItem.Quantity = items[i].count;
918  lootItem.Loot.Initialize(items[i]);
919  packet.Items.push_back(lootItem);
920  }
921  }
922  break;
923  }
925  {
926  for (uint8 i = 0; i < items.size(); ++i)
927  {
928  if (!items[i].is_looted && !items[i].freeforall && items[i].conditions.empty() && items[i].AllowedForPlayer(viewer))
929  {
930  if (!roundRobinPlayer.IsEmpty() && viewer->GetGUID() != roundRobinPlayer)
931  // item shall not be displayed.
932  continue;
933 
935  lootItem.LootListID = packet.Items.size()+1;
937  lootItem.Quantity = items[i].count;
938  lootItem.Loot.Initialize(items[i]);
939  packet.Items.push_back(lootItem);
940  }
941  }
942  break;
943  }
944  case ALL_PERMISSION:
945  case OWNER_PERMISSION:
946  {
947  for (uint8 i = 0; i < items.size(); ++i)
948  {
949  if (!items[i].is_looted && !items[i].freeforall && items[i].conditions.empty() && items[i].AllowedForPlayer(viewer))
950  {
952  lootItem.LootListID = packet.Items.size()+1;
954  lootItem.Quantity = items[i].count;
955  lootItem.Loot.Initialize(items[i]);
956  packet.Items.push_back(lootItem);
957  }
958  }
959  break;
960  }
961  default:
962  return;
963  }
964 
966  QuestItemMap const& lootPlayerQuestItems = GetPlayerQuestItems();
967  QuestItemMap::const_iterator q_itr = lootPlayerQuestItems.find(viewer->GetGUID().GetCounter());
968  if (q_itr != lootPlayerQuestItems.end())
969  {
970  QuestItemList* q_list = q_itr->second;
971  for (QuestItemList::const_iterator qi = q_list->begin(); qi != q_list->end(); ++qi)
972  {
973  LootItem const& item = quest_items[qi->index];
974  if (!qi->is_looted && !item.is_looted)
975  {
977  lootItem.LootListID = packet.Items.size()+1;
978  lootItem.Quantity = item.count;
979  lootItem.Loot.Initialize(item);
980 
981  if (item.follow_loot_rules)
982  {
983  switch (permission)
984  {
985  case MASTER_PERMISSION:
986  lootItem.UIType = LOOT_SLOT_TYPE_MASTER;
987  break;
990  break;
991  case GROUP_PERMISSION:
993  if (!item.is_blocked)
995  else
997  break;
998  default:
999  lootItem.UIType = slotType;
1000  break;
1001  }
1002  }
1003  else
1004  lootItem.UIType = slotType;
1005 
1006  packet.Items.push_back(lootItem);
1007  }
1008  }
1009  }
1010 
1011  QuestItemMap const& lootPlayerFFAItems = GetPlayerFFAItems();
1012  QuestItemMap::const_iterator ffa_itr = lootPlayerFFAItems.find(viewer->GetGUID().GetCounter());
1013  if (ffa_itr != lootPlayerFFAItems.end())
1014  {
1015  QuestItemList* ffa_list = ffa_itr->second;
1016  for (QuestItemList::const_iterator fi = ffa_list->begin(); fi != ffa_list->end(); ++fi)
1017  {
1018  LootItem const& item = items[fi->index];
1019  if (!fi->is_looted && !item.is_looted)
1020  {
1022  lootItem.LootListID = packet.Items.size()+1;
1023  lootItem.UIType = slotType;
1024  lootItem.Quantity = item.count;
1025  lootItem.Loot.Initialize(item);
1026  packet.Items.push_back(lootItem);
1027  }
1028  }
1029  }
1030 
1031  QuestItemMap const& lootPlayerNonQuestNonFFAConditionalItems = GetPlayerNonQuestNonFFAConditionalItems();
1032  QuestItemMap::const_iterator nn_itr = lootPlayerNonQuestNonFFAConditionalItems.find(viewer->GetGUID().GetCounter());
1033  if (nn_itr != lootPlayerNonQuestNonFFAConditionalItems.end())
1034  {
1035  QuestItemList* conditional_list = nn_itr->second;
1036  for (QuestItemList::const_iterator ci = conditional_list->begin(); ci != conditional_list->end(); ++ci)
1037  {
1038  LootItem const& item = items[ci->index];
1039  if (!ci->is_looted && !item.is_looted)
1040  {
1042  lootItem.LootListID = packet.Items.size()+1;
1043  lootItem.Quantity = item.count;
1044  lootItem.Loot.Initialize(item);
1045 
1046  if (item.follow_loot_rules)
1047  {
1048  switch (permission)
1049  {
1050  case MASTER_PERMISSION:
1051  lootItem.UIType = LOOT_SLOT_TYPE_MASTER;
1052  break;
1053  case RESTRICTED_PERMISSION:
1055  break;
1056  case GROUP_PERMISSION:
1058  if (!item.is_blocked)
1059  lootItem.UIType = LOOT_SLOT_TYPE_ALLOW_LOOT;
1060  else
1062  break;
1063  default:
1064  lootItem.UIType = slotType;
1065  break;
1066  }
1067  }
1068  else
1069  lootItem.UIType = slotType;
1070 
1071  packet.Items.push_back(lootItem);
1072  }
1073  }
1074  }
1075 }
Definition: LootMgr.h:78
bool follow_loot_rules
Definition: LootMgr.h:172
std::vector< LootItemData > Items
Definition: LootPackets.h:72
Definition: LootMgr.h:77
Definition: LootMgr.h:83
bool is_blocked
Definition: LootMgr.h:167
uint8 LootListID
Definition: LootPackets.h:45
bool is_looted
Definition: LootMgr.h:166
Definition: LootMgr.h:124
Definition: LootMgr.h:82
LootSlotType
Definition: LootMgr.h:122
Definition: LootMgr.h:79
uint32 Coins
Definition: LootPackets.h:71
QuestItemMap const & GetPlayerNonQuestNonFFAConditionalItems() const
Definition: LootMgr.h:318
QuestItemMap const & GetPlayerQuestItems() const
Definition: LootMgr.h:316
Definition: LootPackets.h:39
Definition: LootMgr.h:125
Definition: LootMgr.h:128
ObjectGuid roundRobinPlayer
Definition: LootMgr.h:324
uint32 gold
Definition: LootMgr.h:322
Definition: LootMgr.h:157
WorldPackets::Item::ItemInstance Loot
Definition: LootPackets.h:47
std::vector< LootItem > items
Definition: LootMgr.h:320
std::vector< QuestItem > QuestItemList
Definition: LootMgr.h:203
uint8 UIType
Definition: LootPackets.h:42
void Initialize(::Item const *item)
Definition: ItemPackets.cpp:248
uint32 Quantity
Definition: LootPackets.h:43
uint8_t uint8
Definition: Define.h:152
QuestItemMap const & GetPlayerFFAItems() const
Definition: LootMgr.h:317
Definition: LootMgr.h:126
Definition: LootMgr.h:80
uint8 count
Definition: LootMgr.h:165
Definition: LootMgr.h:127
std::map< ObjectGuid::LowType, QuestItemList * > QuestItemMap
Definition: LootMgr.h:207
Definition: LootMgr.h:81
bool IsEmpty() const
Definition: ObjectGuid.h:242
std::vector< LootItem > quest_items
Definition: LootMgr.h:321

+ Here is the call graph for this function:

void Loot::clear ( )
inline
350  {
351  for (QuestItemMap::const_iterator itr = PlayerQuestItems.begin(); itr != PlayerQuestItems.end(); ++itr)
352  delete itr->second;
353  PlayerQuestItems.clear();
354 
355  for (QuestItemMap::const_iterator itr = PlayerFFAItems.begin(); itr != PlayerFFAItems.end(); ++itr)
356  delete itr->second;
357  PlayerFFAItems.clear();
358 
359  for (QuestItemMap::const_iterator itr = PlayerNonQuestNonFFAConditionalItems.begin(); itr != PlayerNonQuestNonFFAConditionalItems.end(); ++itr)
360  delete itr->second;
362 
363  PlayersLooting.clear();
364  items.clear();
365  quest_items.clear();
366  gold = 0;
367  unlootedCount = 0;
372  }
uint32 _difficultyBonusTreeMod
Definition: LootMgr.h:414
QuestItemMap PlayerFFAItems
Definition: LootMgr.h:406
Definition: LootMgr.h:88
void clearReferences()
Definition: RefManager.h:43
uint8 unlootedCount
Definition: LootMgr.h:323
ObjectGuid roundRobinPlayer
Definition: LootMgr.h:324
uint32 gold
Definition: LootMgr.h:322
void Clear()
Definition: ObjectGuid.h:215
std::vector< LootItem > items
Definition: LootMgr.h:320
LootType loot_type
Definition: LootMgr.h:325
LootValidatorRefManager i_LootValidatorRefManager
Definition: LootMgr.h:410
QuestItemMap PlayerQuestItems
Definition: LootMgr.h:405
QuestItemMap PlayerNonQuestNonFFAConditionalItems
Definition: LootMgr.h:407
std::vector< LootItem > quest_items
Definition: LootMgr.h:321
GuidSet PlayersLooting
Definition: LootMgr.h:404

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Loot::DeleteLootItemFromContainerItemDB ( uint32  itemID)
708 {
709  // Deletes a single item associated with an openable item from the DB
711  stmt->setUInt64(0, containerID.GetCounter());
712  stmt->setUInt32(1, itemID);
714 
715  // Mark the item looted to prevent resaving
716  for (LootItemList::iterator _itr = items.begin(); _itr != items.end(); ++_itr)
717  {
718  if (_itr->itemid != itemID)
719  continue;
720 
721  _itr->canSave = true;
722  break;
723  }
724 }
Definition: CharacterDatabase.h:565
void Execute(const char *sql)
Definition: DatabaseWorkerPool.h:87
Definition: PreparedStatement.h:74
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115
std::vector< LootItem > items
Definition: LootMgr.h:320
void setUInt64(const uint8 index, const uint64 value)
Definition: PreparedStatement.cpp:124
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
ObjectGuid containerID
Definition: LootMgr.h:330
LowType GetCounter() const
Definition: ObjectGuid.h:221

+ Here is the call graph for this function:

void Loot::DeleteLootMoneyFromContainerItemDB ( )
727 {
728  // Deletes money loot associated with an openable item from the DB
730  stmt->setUInt64(0, containerID.GetCounter());
732 }
void Execute(const char *sql)
Definition: DatabaseWorkerPool.h:87
Definition: CharacterDatabase.h:568
Definition: PreparedStatement.h:74
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
void setUInt64(const uint8 index, const uint64 value)
Definition: PreparedStatement.cpp:124
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
ObjectGuid containerID
Definition: LootMgr.h:330
LowType GetCounter() const
Definition: ObjectGuid.h:221

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool Loot::empty ( ) const
inline
374 { return items.empty() && gold == 0; }
uint32 gold
Definition: LootMgr.h:322
std::vector< LootItem > items
Definition: LootMgr.h:320

+ Here is the caller graph for this function:

QuestItemList * Loot::FillFFALoot ( Player player)
private
535 {
536  QuestItemList* ql = new QuestItemList();
537 
538  for (uint8 i = 0; i < items.size(); ++i)
539  {
540  LootItem &item = items[i];
541  if (!item.is_looted && item.freeforall && item.AllowedForPlayer(player))
542  {
543  ql->push_back(QuestItem(i));
544  ++unlootedCount;
545  }
546  }
547  if (ql->empty())
548  {
549  delete ql;
550  return NULL;
551  }
552 
553  PlayerFFAItems[player->GetGUID().GetCounter()] = ql;
554  return ql;
555 }
Definition: LootMgr.h:190
bool freeforall
Definition: LootMgr.h:168
QuestItemMap PlayerFFAItems
Definition: LootMgr.h:406
arena_t NULL
Definition: jemalloc_internal.h:624
bool is_looted
Definition: LootMgr.h:166
uint8 unlootedCount
Definition: LootMgr.h:323
bool AllowedForPlayer(Player const *player) const
Definition: LootMgr.cpp:378
Definition: LootMgr.h:157
std::vector< LootItem > items
Definition: LootMgr.h:320
std::vector< QuestItem > QuestItemList
Definition: LootMgr.h:203
uint8_t uint8
Definition: Define.h:152

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool Loot::FillLoot ( uint32  lootId,
LootStore const store,
Player lootOwner,
bool  personal,
bool  noEmptyError = false,
uint16  lootMode = LOOT_MODE_DEFAULT 
)
451 {
452  // Must be provided
453  if (!lootOwner)
454  return false;
455 
456  LootTemplate const* tab = store.GetLootFor(lootId);
457 
458  if (!tab)
459  {
460  if (!noEmptyError)
461  TC_LOG_ERROR("sql.sql", "Table '%s' loot id #%u used but it doesn't have records.", store.GetName(), lootId);
462  return false;
463  }
464 
465  _difficultyBonusTreeMod = lootOwner->GetMap()->GetDifficultyLootBonusTreeMod();
466 
467  items.reserve(MAX_NR_LOOT_ITEMS);
469 
470  tab->Process(*this, store.IsRatesAllowed(), lootMode); // Processing is done there, callback via Loot::AddItem()
471 
472  // Setting access rights for group loot case
473  Group* group = lootOwner->GetGroup();
474  if (!personal && group)
475  {
476  roundRobinPlayer = lootOwner->GetGUID();
477 
478  for (GroupReference* itr = group->GetFirstMember(); itr != NULL; itr = itr->next())
479  if (Player* player = itr->GetSource()) // should actually be looted object instead of lootOwner but looter has to be really close so doesnt really matter
480  FillNotNormalLootFor(player, player->IsAtGroupRewardDistance(lootOwner));
481 
482  for (uint8 i = 0; i < items.size(); ++i)
483  {
484  if (ItemTemplate const* proto = sObjectMgr->GetItemTemplate(items[i].itemid))
485  if (proto->GetQuality() < uint32(group->GetLootThreshold()))
486  items[i].is_underthreshold = true;
487  }
488  }
489  // ... for personal loot
490  else
491  FillNotNormalLootFor(lootOwner, true);
492 
493  return true;
494 }
#define MAX_NR_LOOT_ITEMS
Definition: LootMgr.h:60
uint32 _difficultyBonusTreeMod
Definition: LootMgr.h:414
arena_t NULL
Definition: jemalloc_internal.h:624
void Process(Loot &loot, bool rate, uint16 lootMode, uint8 groupId=0) const
Definition: LootMgr.cpp:1293
#define sObjectMgr
Definition: ObjectMgr.h:1567
ItemQualities GetLootThreshold() const
Definition: Group.cpp:2561
GroupReference * GetFirstMember()
Definition: Group.h:295
void FillNotNormalLootFor(Player *player, bool presentAtLooting)
Definition: LootMgr.cpp:496
ObjectGuid roundRobinPlayer
Definition: LootMgr.h:324
Definition: LootMgr.h:250
std::vector< LootItem > items
Definition: LootMgr.h:320
Definition: ItemTemplate.h:647
uint8_t uint8
Definition: Define.h:152
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
uint32_t uint32
Definition: g3dmath.h:168
#define MAX_NR_QUEST_ITEMS
Definition: LootMgr.h:62
std::vector< LootItem > quest_items
Definition: LootMgr.h:321
Definition: Group.h:191
Definition: GroupReference.h:27

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QuestItemList * Loot::FillNonQuestNonFFAConditionalLoot ( Player player,
bool  presentAtLooting 
)
private
596 {
597  QuestItemList* ql = new QuestItemList();
598 
599  for (uint8 i = 0; i < items.size(); ++i)
600  {
601  LootItem &item = items[i];
602  if (!item.is_looted && !item.freeforall && (item.AllowedForPlayer(player) || (item.follow_loot_rules && player->GetGroup() && ((player->GetGroup()->GetLootMethod() == MASTER_LOOT && player->GetGroup()->GetMasterLooterGuid() == player->GetGUID()) || player->GetGroup()->GetLootMethod() != MASTER_LOOT))))
603  {
604  if (presentAtLooting)
605  item.AddAllowedLooter(player);
606  if (!item.conditions.empty())
607  {
608  ql->push_back(QuestItem(i));
609  if (!item.is_counted)
610  {
611  ++unlootedCount;
612  item.is_counted = true;
613  }
614  }
615  }
616  }
617  if (ql->empty())
618  {
619  delete ql;
620  return NULL;
621  }
622 
623  PlayerNonQuestNonFFAConditionalItems[player->GetGUID().GetCounter()] = ql;
624  return ql;
625 }
bool follow_loot_rules
Definition: LootMgr.h:172
bool is_counted
Definition: LootMgr.h:170
Definition: LootMgr.h:190
bool freeforall
Definition: LootMgr.h:168
arena_t NULL
Definition: jemalloc_internal.h:624
ConditionContainer conditions
Definition: LootMgr.h:163
bool is_looted
Definition: LootMgr.h:166
uint8 unlootedCount
Definition: LootMgr.h:323
bool AllowedForPlayer(Player const *player) const
Definition: LootMgr.cpp:378
Definition: LootMgr.h:157
std::vector< LootItem > items
Definition: LootMgr.h:320
std::vector< QuestItem > QuestItemList
Definition: LootMgr.h:203
void AddAllowedLooter(Player const *player)
Definition: LootMgr.cpp:406
uint8_t uint8
Definition: Define.h:152
QuestItemMap PlayerNonQuestNonFFAConditionalItems
Definition: LootMgr.h:407
Definition: LootMgr.h:69

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Loot::FillNotNormalLootFor ( Player player,
bool  presentAtLooting 
)
private
497 {
498  ObjectGuid::LowType plguid = player->GetGUID().GetCounter();
499 
500  QuestItemMap::const_iterator qmapitr = PlayerQuestItems.find(plguid);
501  if (qmapitr == PlayerQuestItems.end())
502  FillQuestLoot(player);
503 
504  qmapitr = PlayerFFAItems.find(plguid);
505  if (qmapitr == PlayerFFAItems.end())
506  FillFFALoot(player);
507 
508  qmapitr = PlayerNonQuestNonFFAConditionalItems.find(plguid);
509  if (qmapitr == PlayerNonQuestNonFFAConditionalItems.end())
510  FillNonQuestNonFFAConditionalLoot(player, presentAtLooting);
511 
512  // if not auto-processed player will have to come and pick it up manually
513  if (!presentAtLooting)
514  return;
515 
516  // Process currency items
517  uint32 max_slot = GetMaxSlotInLootFor(player);
518  LootItem const* item = NULL;
519  uint32 itemsSize = uint32(items.size());
520  for (uint32 i = 0; i < max_slot; ++i)
521  {
522  if (i < items.size())
523  item = &items[i];
524  else
525  item = &quest_items[i-itemsSize];
526 
527  if (!item->is_looted && item->freeforall && item->AllowedForPlayer(player))
528  if (ItemTemplate const* proto = sObjectMgr->GetItemTemplate(item->itemid))
529  if (proto->IsCurrencyToken())
530  player->StoreLootItem(i, this);
531  }
532 }
uint32 GetMaxSlotInLootFor(Player *player) const
Definition: LootMgr.cpp:797
bool freeforall
Definition: LootMgr.h:168
QuestItemMap PlayerFFAItems
Definition: LootMgr.h:406
arena_t NULL
Definition: jemalloc_internal.h:624
bool is_looted
Definition: LootMgr.h:166
uint64 LowType
Definition: ObjectGuid.h:199
#define sObjectMgr
Definition: ObjectMgr.h:1567
QuestItemList * FillQuestLoot(Player *player)
Definition: LootMgr.cpp:557
bool AllowedForPlayer(Player const *player) const
Definition: LootMgr.cpp:378
uint32_t uint32
Definition: Define.h:150
Definition: LootMgr.h:157
std::vector< LootItem > items
Definition: LootMgr.h:320
Definition: ItemTemplate.h:647
QuestItemList * FillNonQuestNonFFAConditionalLoot(Player *player, bool presentAtLooting)
Definition: LootMgr.cpp:595
QuestItemMap PlayerQuestItems
Definition: LootMgr.h:405
uint32_t uint32
Definition: g3dmath.h:168
QuestItemList * FillFFALoot(Player *player)
Definition: LootMgr.cpp:534
QuestItemMap PlayerNonQuestNonFFAConditionalItems
Definition: LootMgr.h:407
uint32 itemid
Definition: LootMgr.h:159
std::vector< LootItem > quest_items
Definition: LootMgr.h:321

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QuestItemList * Loot::FillQuestLoot ( Player player)
private
558 {
559  if (items.size() == MAX_NR_LOOT_ITEMS)
560  return NULL;
561 
562  QuestItemList* ql = new QuestItemList();
563 
564  for (uint8 i = 0; i < quest_items.size(); ++i)
565  {
566  LootItem &item = quest_items[i];
567 
568  if (!item.is_looted && (item.AllowedForPlayer(player) || (item.follow_loot_rules && player->GetGroup() && ((player->GetGroup()->GetLootMethod() == MASTER_LOOT && player->GetGroup()->GetMasterLooterGuid() == player->GetGUID()) || player->GetGroup()->GetLootMethod() != MASTER_LOOT))))
569  {
570  ql->push_back(QuestItem(i));
571 
572  // quest items get blocked when they first appear in a
573  // player's quest vector
574  //
575  // increase once if one looter only, looter-times if free for all
576  if (item.freeforall || !item.is_blocked)
577  ++unlootedCount;
578  if (!player->GetGroup() || (player->GetGroup()->GetLootMethod() != GROUP_LOOT && player->GetGroup()->GetLootMethod() != ROUND_ROBIN))
579  item.is_blocked = true;
580 
581  if (items.size() + ql->size() == MAX_NR_LOOT_ITEMS)
582  break;
583  }
584  }
585  if (ql->empty())
586  {
587  delete ql;
588  return NULL;
589  }
590 
591  PlayerQuestItems[player->GetGUID().GetCounter()] = ql;
592  return ql;
593 }
Definition: LootMgr.h:70
#define MAX_NR_LOOT_ITEMS
Definition: LootMgr.h:60
bool follow_loot_rules
Definition: LootMgr.h:172
Definition: LootMgr.h:190
bool freeforall
Definition: LootMgr.h:168
bool is_blocked
Definition: LootMgr.h:167
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: LootMgr.h:68
bool is_looted
Definition: LootMgr.h:166
uint8 unlootedCount
Definition: LootMgr.h:323
bool AllowedForPlayer(Player const *player) const
Definition: LootMgr.cpp:378
Definition: LootMgr.h:157
std::vector< LootItem > items
Definition: LootMgr.h:320
std::vector< QuestItem > QuestItemList
Definition: LootMgr.h:203
uint8_t uint8
Definition: Define.h:152
QuestItemMap PlayerQuestItems
Definition: LootMgr.h:405
std::vector< LootItem > quest_items
Definition: LootMgr.h:321
Definition: LootMgr.h:69

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Loot::generateMoneyLoot ( uint32  minAmount,
uint32  maxAmount 
)
695 {
696  if (maxAmount > 0)
697  {
698  if (maxAmount <= minAmount)
699  gold = uint32(maxAmount * sWorld->getRate(RATE_DROP_MONEY));
700  else if ((maxAmount - minAmount) < 32700)
701  gold = uint32(urand(minAmount, maxAmount) * sWorld->getRate(RATE_DROP_MONEY));
702  else
703  gold = uint32(urand(minAmount >> 8, maxAmount >> 8) * sWorld->getRate(RATE_DROP_MONEY)) << 8;
704  }
705 }
#define sWorld
Definition: World.h:887
Definition: World.h:401
uint32 urand(uint32 min, uint32 max)
Definition: Random.cpp:45
uint32 gold
Definition: LootMgr.h:322
uint32_t uint32
Definition: g3dmath.h:168

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ObjectGuid const& Loot::GetGUID ( ) const
inline
335 { return _GUID; }
ObjectGuid _GUID
Definition: LootMgr.h:413

+ Here is the caller graph for this function:

uint32 Loot::GetMaxSlotInLootFor ( Player player) const
798 {
799  QuestItemMap::const_iterator itr = PlayerQuestItems.find(player->GetGUID().GetCounter());
800  return items.size() + (itr != PlayerQuestItems.end() ? itr->second->size() : 0);
801 }
std::vector< LootItem > items
Definition: LootMgr.h:320
QuestItemMap PlayerQuestItems
Definition: LootMgr.h:405

+ Here is the caller graph for this function:

QuestItemMap const& Loot::GetPlayerFFAItems ( ) const
inline
317 { return PlayerFFAItems; }
QuestItemMap PlayerFFAItems
Definition: LootMgr.h:406

+ Here is the caller graph for this function:

QuestItemMap const& Loot::GetPlayerNonQuestNonFFAConditionalItems ( ) const
inline
QuestItemMap PlayerNonQuestNonFFAConditionalItems
Definition: LootMgr.h:407

+ Here is the caller graph for this function:

QuestItemMap const& Loot::GetPlayerQuestItems ( ) const
inline
316 { return PlayerQuestItems; }
QuestItemMap PlayerQuestItems
Definition: LootMgr.h:405

+ Here is the caller graph for this function:

bool Loot::hasItemFor ( Player player) const
805 {
806  QuestItemMap const& lootPlayerQuestItems = GetPlayerQuestItems();
807  QuestItemMap::const_iterator q_itr = lootPlayerQuestItems.find(player->GetGUID().GetCounter());
808  if (q_itr != lootPlayerQuestItems.end())
809  {
810  QuestItemList* q_list = q_itr->second;
811  for (QuestItemList::const_iterator qi = q_list->begin(); qi != q_list->end(); ++qi)
812  {
813  const LootItem &item = quest_items[qi->index];
814  if (!qi->is_looted && !item.is_looted)
815  return true;
816  }
817  }
818 
819  QuestItemMap const& lootPlayerFFAItems = GetPlayerFFAItems();
820  QuestItemMap::const_iterator ffa_itr = lootPlayerFFAItems.find(player->GetGUID().GetCounter());
821  if (ffa_itr != lootPlayerFFAItems.end())
822  {
823  QuestItemList* ffa_list = ffa_itr->second;
824  for (QuestItemList::const_iterator fi = ffa_list->begin(); fi != ffa_list->end(); ++fi)
825  {
826  const LootItem &item = items[fi->index];
827  if (!fi->is_looted && !item.is_looted)
828  return true;
829  }
830  }
831 
832  QuestItemMap const& lootPlayerNonQuestNonFFAConditionalItems = GetPlayerNonQuestNonFFAConditionalItems();
833  QuestItemMap::const_iterator nn_itr = lootPlayerNonQuestNonFFAConditionalItems.find(player->GetGUID().GetCounter());
834  if (nn_itr != lootPlayerNonQuestNonFFAConditionalItems.end())
835  {
836  QuestItemList* conditional_list = nn_itr->second;
837  for (QuestItemList::const_iterator ci = conditional_list->begin(); ci != conditional_list->end(); ++ci)
838  {
839  const LootItem &item = items[ci->index];
840  if (!ci->is_looted && !item.is_looted)
841  return true;
842  }
843  }
844 
845  return false;
846 }
bool is_looted
Definition: LootMgr.h:166
QuestItemMap const & GetPlayerNonQuestNonFFAConditionalItems() const
Definition: LootMgr.h:318
QuestItemMap const & GetPlayerQuestItems() const
Definition: LootMgr.h:316
Definition: LootMgr.h:157
std::vector< LootItem > items
Definition: LootMgr.h:320
std::vector< QuestItem > QuestItemList
Definition: LootMgr.h:203
QuestItemMap const & GetPlayerFFAItems() const
Definition: LootMgr.h:317
std::map< ObjectGuid::LowType, QuestItemList * > QuestItemMap
Definition: LootMgr.h:207
std::vector< LootItem > quest_items
Definition: LootMgr.h:321

+ Here is the call graph for this function:

bool Loot::hasOverThresholdItem ( ) const
850 {
851  for (uint8 i = 0; i < items.size(); ++i)
852  {
853  if (!items[i].is_looted && !items[i].is_underthreshold && !items[i].freeforall)
854  return true;
855  }
856 
857  return false;
858 }
std::vector< LootItem > items
Definition: LootMgr.h:320
uint8_t uint8
Definition: Define.h:152

+ Here is the caller graph for this function:

bool Loot::isLooted ( ) const
inline
375 { return gold == 0 && unlootedCount == 0; }
uint8 unlootedCount
Definition: LootMgr.h:323
uint32 gold
Definition: LootMgr.h:322

+ Here is the caller graph for this function:

LootItem * Loot::LootItemInSlot ( uint32  lootslot,
Player player,
QuestItem **  qitem = NULL,
QuestItem **  ffaitem = NULL,
QuestItem **  conditem = NULL 
)
735 {
736  LootItem* item = NULL;
737  bool is_looted = true;
738  if (lootSlot >= items.size())
739  {
740  uint32 questSlot = lootSlot - items.size();
741  QuestItemMap::const_iterator itr = PlayerQuestItems.find(player->GetGUID().GetCounter());
742  if (itr != PlayerQuestItems.end() && questSlot < itr->second->size())
743  {
744  QuestItem* qitem2 = &itr->second->at(questSlot);
745  if (qitem)
746  *qitem = qitem2;
747  item = &quest_items[qitem2->index];
748  is_looted = qitem2->is_looted;
749  }
750  }
751  else
752  {
753  item = &items[lootSlot];
754  is_looted = item->is_looted;
755  if (item->freeforall)
756  {
757  QuestItemMap::const_iterator itr = PlayerFFAItems.find(player->GetGUID().GetCounter());
758  if (itr != PlayerFFAItems.end())
759  {
760  for (QuestItemList::const_iterator iter=itr->second->begin(); iter!= itr->second->end(); ++iter)
761  if (iter->index == lootSlot)
762  {
763  QuestItem* ffaitem2 = (QuestItem*)&(*iter);
764  if (ffaitem)
765  *ffaitem = ffaitem2;
766  is_looted = ffaitem2->is_looted;
767  break;
768  }
769  }
770  }
771  else if (!item->conditions.empty())
772  {
773  QuestItemMap::const_iterator itr = PlayerNonQuestNonFFAConditionalItems.find(player->GetGUID().GetCounter());
774  if (itr != PlayerNonQuestNonFFAConditionalItems.end())
775  {
776  for (QuestItemList::const_iterator iter=itr->second->begin(); iter!= itr->second->end(); ++iter)
777  {
778  if (iter->index == lootSlot)
779  {
780  QuestItem* conditem2 = (QuestItem*)&(*iter);
781  if (conditem)
782  *conditem = conditem2;
783  is_looted = conditem2->is_looted;
784  break;
785  }
786  }
787  }
788  }
789  }
790 
791  if (is_looted)
792  return NULL;
793 
794  return item;
795 }
Definition: LootMgr.h:190
bool freeforall
Definition: LootMgr.h:168
QuestItemMap PlayerFFAItems
Definition: LootMgr.h:406
bool is_looted
Definition: LootMgr.h:193
arena_t NULL
Definition: jemalloc_internal.h:624
ConditionContainer conditions
Definition: LootMgr.h:163
bool is_looted
Definition: LootMgr.h:166
uint8 index
Definition: LootMgr.h:192
uint32_t uint32
Definition: Define.h:150
Definition: LootMgr.h:157
std::vector< LootItem > items
Definition: LootMgr.h:320
QuestItemMap PlayerQuestItems
Definition: LootMgr.h:405
QuestItemMap PlayerNonQuestNonFFAConditionalItems
Definition: LootMgr.h:407
std::vector< LootItem > quest_items
Definition: LootMgr.h:321

+ Here is the caller graph for this function:

void Loot::NotifyItemRemoved ( uint8  lootIndex)
630 {
631  // notify all players that are looting this that the item was removed
632  // convert the index to the slot the player sees
633  GuidSet::iterator i_next;
634  for (GuidSet::iterator i = PlayersLooting.begin(); i != PlayersLooting.end(); i = i_next)
635  {
636  i_next = i;
637  ++i_next;
638  if (Player* player = ObjectAccessor::FindPlayer(*i))
639  player->SendNotifyLootItemRemoved(player->GetLootGUID(), GetGUID(), lootIndex);
640  else
641  PlayersLooting.erase(i);
642  }
643 }
TC_GAME_API Player * FindPlayer(ObjectGuid const &)
Definition: ObjectAccessor.cpp:209
ObjectGuid const & GetGUID() const
Definition: LootMgr.h:335
GuidSet PlayersLooting
Definition: LootMgr.h:404

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Loot::NotifyMoneyRemoved ( )
646 {
647  // notify all players that are looting this that the money was removed
648  GuidSet::iterator i_next;
649  for (GuidSet::iterator i = PlayersLooting.begin(); i != PlayersLooting.end(); i = i_next)
650  {
651  i_next = i;
652  ++i_next;
653  if (Player* player = ObjectAccessor::FindPlayer(*i))
654  player->SendNotifyLootMoneyRemoved(GetGUID());
655  else
656  PlayersLooting.erase(i);
657  }
658 }
TC_GAME_API Player * FindPlayer(ObjectGuid const &)
Definition: ObjectAccessor.cpp:209
ObjectGuid const & GetGUID() const
Definition: LootMgr.h:335
GuidSet PlayersLooting
Definition: LootMgr.h:404

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Loot::NotifyQuestItemRemoved ( uint8  questIndex)
661 {
662  // when a free for all questitem is looted
663  // all players will get notified of it being removed
664  // (other questitems can be looted by each group member)
665  // bit inefficient but isn't called often
666 
667  GuidSet::iterator i_next;
668  for (GuidSet::iterator i = PlayersLooting.begin(); i != PlayersLooting.end(); i = i_next)
669  {
670  i_next = i;
671  ++i_next;
672  if (Player* player = ObjectAccessor::FindPlayer(*i))
673  {
674  QuestItemMap::const_iterator pq = PlayerQuestItems.find(player->GetGUID().GetCounter());
675  if (pq != PlayerQuestItems.end() && pq->second)
676  {
677  // find where/if the player has the given item in it's vector
678  QuestItemList& pql = *pq->second;
679 
680  uint8 j;
681  for (j = 0; j < pql.size(); ++j)
682  if (pql[j].index == questIndex)
683  break;
684 
685  if (j < pql.size())
686  player->SendNotifyLootItemRemoved(player->GetLootGUID(), GetGUID(), items.size()+j);
687  }
688  }
689  else
690  PlayersLooting.erase(i);
691  }
692 }
TC_GAME_API Player * FindPlayer(ObjectGuid const &)
Definition: ObjectAccessor.cpp:209
ObjectGuid const & GetGUID() const
Definition: LootMgr.h:335
std::vector< LootItem > items
Definition: LootMgr.h:320
std::vector< QuestItem > QuestItemList
Definition: LootMgr.h:203
uint8_t uint8
Definition: Define.h:152
QuestItemMap PlayerQuestItems
Definition: LootMgr.h:405
GuidSet PlayersLooting
Definition: LootMgr.h:404

+ Here is the call graph for this function:

void Loot::RemoveLooter ( ObjectGuid  GUID)
inline
381 { PlayersLooting.erase(GUID); }
GuidSet PlayersLooting
Definition: LootMgr.h:404

+ Here is the caller graph for this function:

void Loot::SetGUID ( ObjectGuid const guid)
inline
336 { _GUID = guid; }
ObjectGuid _GUID
Definition: LootMgr.h:413

+ Here is the caller graph for this function:

Member Data Documentation

uint32 Loot::_difficultyBonusTreeMod
private
ObjectGuid Loot::_GUID
private
ObjectGuid Loot::containerID
uint32 Loot::gold
LootValidatorRefManager Loot::i_LootValidatorRefManager
private
std::vector<LootItem> Loot::items
LootType Loot::loot_type
uint8 Loot::maxDuplicates
QuestItemMap Loot::PlayerFFAItems
private
QuestItemMap Loot::PlayerNonQuestNonFFAConditionalItems
private
QuestItemMap Loot::PlayerQuestItems
private
GuidSet Loot::PlayersLooting
private
std::vector<LootItem> Loot::quest_items
ObjectGuid Loot::roundRobinPlayer
uint8 Loot::unlootedCount

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