OregonCore  revision fb2a440-git
Your Favourite TBC server
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 (uint64 GUID)
 
void RemoveLooter (uint64 GUID)
 
void generateMoneyLoot (uint32 minAmount, uint32 maxAmount)
 
void FillLoot (uint32 loot_id, LootStore const &store, Player *loot_owner, bool personal)
 
void FillNotNormalLootFor (Player *player)
 
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 hasItemForAll () const
 
bool hasItemFor (Player *player) const
 
bool hasOverThresholdItem () const
 

Public Attributes

std::vector< LootItemitems
 
std::vector< LootItemquest_items
 
uint32 gold
 
uint8 unlootedCount
 
uint64 roundRobinPlayer
 
LootType loot_type
 

Private Member Functions

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

Private Attributes

std::set< uint64PlayersLooting
 
QuestItemMap PlayerQuestItems
 
QuestItemMap PlayerFFAItems
 
QuestItemMap PlayerNonQuestNonFFAConditionalItems
 
LootValidatorRefManager i_LootValidatorRefManager
 

Friends

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

Detailed Description

Definition at line 290 of file LootMgr.h.

Constructor & Destructor Documentation

Loot::Loot ( uint32  _gold = 0)
inline

Definition at line 314 of file LootMgr.h.

uint8 unlootedCount
Definition: LootMgr.h:310
uint64 roundRobinPlayer
Definition: LootMgr.h:311
uint32 gold
Definition: LootMgr.h:309
LootType loot_type
Definition: LootMgr.h:312
Loot::~Loot ( )
inline

Definition at line 315 of file LootMgr.h.

316  {
317  clear();
318  }
void clear()
Definition: LootMgr.h:327

Member Function Documentation

void Loot::AddItem ( LootStoreItem const &  item)

Definition at line 348 of file LootMgr.cpp.

References LootStoreItem::conditions, ItemTemplate::Flags, ITEM_PROTO_FLAG_MULTI_DROP, LootStoreItem::itemid, MAX_NR_LOOT_ITEMS, MAX_NR_QUEST_ITEMS, LootStoreItem::needs_quest, and sObjectMgr.

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

349 {
350  ItemTemplate const* proto = sObjectMgr.GetItemTemplate(item.itemid);
351  if (!proto)
352  return;
353 
354  if (item.needs_quest) // Quest drop
355  {
356  if (quest_items.size() < MAX_NR_QUEST_ITEMS)
357  quest_items.push_back(LootItem(item));
358  }
359  else if (items.size() < MAX_NR_LOOT_ITEMS) // Non-quest drop
360  {
361  items.push_back(LootItem(item));
362 
363  // non-conditional one-player only items are counted here,
364  // free for all items are counted in FillFFALoot(),
365  // non-ffa conditionals are counted in FillNonQuestNonFFAConditionalLoot()
366  if (item.conditions.empty())
367  {
368  if ((proto->Flags & ITEM_PROTO_FLAG_MULTI_DROP) == 0)
369  ++unlootedCount;
370  }
371  }
372 }
#define MAX_NR_LOOT_ITEMS
Definition: LootMgr.h:29
#define sObjectMgr
Definition: ObjectMgr.h:1285
uint8 unlootedCount
Definition: LootMgr.h:310
std::vector< LootItem > items
Definition: LootMgr.h:307
#define MAX_NR_QUEST_ITEMS
Definition: LootMgr.h:31
std::vector< LootItem > quest_items
Definition: LootMgr.h:308
void Loot::AddLooter ( uint64  GUID)
inline

Definition at line 363 of file LootMgr.h.

Referenced by Player::SendLoot().

364  {
365  PlayersLooting.insert(GUID);
366  }
std::set< uint64 > PlayersLooting
Definition: LootMgr.h:390
void Loot::addLootValidatorRef ( LootValidatorRef pLootValidatorRef)
inline

Definition at line 321 of file LootMgr.h.

322  {
323  i_LootValidatorRefManager.insertFirst(pLootValidatorRef);
324  }
void insertFirst(LinkedListElement *pElem)
Definition: LinkedList.h:105
LootValidatorRefManager i_LootValidatorRefManager
Definition: LootMgr.h:396
void Loot::clear ( )
inline

Definition at line 327 of file LootMgr.h.

References LOOT_NONE.

Referenced by WorldSession::DoLootRelease(), GameObject::getFishLoot(), Unit::Kill(), Creature::RemoveCorpse(), Creature::Respawn(), Player::SendLoot(), Aura::TriggerSpell(), and GameObject::Update().

328  {
329  gold = 0;
330  PlayersLooting.clear();
331  for (QuestItemMap::iterator itr = PlayerQuestItems.begin(); itr != PlayerQuestItems.end(); ++itr)
332  delete itr->second;
333  for (QuestItemMap::iterator itr = PlayerFFAItems.begin(); itr != PlayerFFAItems.end(); ++itr)
334  delete itr->second;
335  for (QuestItemMap::iterator itr = PlayerNonQuestNonFFAConditionalItems.begin(); itr != PlayerNonQuestNonFFAConditionalItems.end(); ++itr)
336  delete itr->second;
337 
338  PlayerQuestItems.clear();
339  PlayerFFAItems.clear();
341 
342  items.clear();
343  quest_items.clear();
344  gold = 0;
345  unlootedCount = 0;
347  roundRobinPlayer = 0;
349  }
QuestItemMap PlayerFFAItems
Definition: LootMgr.h:392
std::set< uint64 > PlayersLooting
Definition: LootMgr.h:390
void clearReferences()
Definition: RefManager.h:68
uint8 unlootedCount
Definition: LootMgr.h:310
uint64 roundRobinPlayer
Definition: LootMgr.h:311
uint32 gold
Definition: LootMgr.h:309
std::vector< LootItem > items
Definition: LootMgr.h:307
LootType loot_type
Definition: LootMgr.h:312
LootValidatorRefManager i_LootValidatorRefManager
Definition: LootMgr.h:396
QuestItemMap PlayerQuestItems
Definition: LootMgr.h:391
QuestItemMap PlayerNonQuestNonFFAConditionalItems
Definition: LootMgr.h:393
std::vector< LootItem > quest_items
Definition: LootMgr.h:308
bool Loot::empty ( ) const
inline

Definition at line 351 of file LootMgr.h.

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

352  {
353  return items.empty() && gold == 0;
354  }
uint32 gold
Definition: LootMgr.h:309
std::vector< LootItem > items
Definition: LootMgr.h:307
QuestItemList * Loot::FillFFALoot ( Player player)
private

Definition at line 445 of file LootMgr.cpp.

References LootItem::AllowedForPlayer(), LootItem::freeforall, Object::GetGUIDLow(), and LootItem::is_looted.

446 {
447  QuestItemList* ql = new QuestItemList();
448 
449  for (uint8 i = 0; i < items.size(); i++)
450  {
451  LootItem& item = items[i];
452  if (!item.is_looted && item.freeforall && item.AllowedForPlayer(player))
453  {
454  ql->push_back(QuestItem(i));
455  ++unlootedCount;
456  }
457  }
458  if (ql->empty())
459  {
460  delete ql;
461  return NULL;
462  }
463 
464  PlayerFFAItems[player->GetGUIDLow()] = ql;
465  return ql;
466 }
bool freeforall
Definition: LootMgr.h:133
QuestItemMap PlayerFFAItems
Definition: LootMgr.h:392
uint32 GetGUIDLow() const
Definition: Object.h:166
bool is_looted
Definition: LootMgr.h:131
ACE_UINT8 uint8
Definition: Define.h:73
uint8 unlootedCount
Definition: LootMgr.h:310
bool AllowedForPlayer(Player const *player) const
Definition: LootMgr.cpp:322
std::vector< LootItem > items
Definition: LootMgr.h:307
std::vector< QuestItem > QuestItemList
Definition: LootMgr.h:159
void Loot::FillLoot ( uint32  loot_id,
LootStore const &  store,
Player loot_owner,
bool  personal 
)

Definition at line 375 of file LootMgr.cpp.

References Group::GetFirstMember(), Player::GetGroup(), Object::GetGUID(), LootStore::GetLootFor(), Group::GetLootThreshold(), LootStore::GetName(), MAX_NR_LOOT_ITEMS, MAX_NR_QUEST_ITEMS, GroupReference::next(), LootTemplate::Process(), sLog, and sObjectMgr.

Referenced by GameObject::getFishLoot(), Unit::Kill(), MailDraft::prepareItems(), Player::SendLoot(), and Aura::TriggerSpell().

376 {
377  // Must be provided
378  if (!loot_owner)
379  return;
380 
381  LootTemplate const* tab = store.GetLootFor(loot_id);
382 
383  if (!tab)
384  {
385  sLog.outErrorDb("Table '%s' loot id #%u used but it doesn't have records.", store.GetName(), loot_id);
386  return;
387  }
388 
389  items.reserve(MAX_NR_LOOT_ITEMS);
391 
392  tab->Process(*this, store); // Processing is done there, callback via Loot::AddItem()
393 
394  Group* group = loot_owner->GetGroup();
395  if (!personal && group)
396  {
397  roundRobinPlayer = loot_owner->GetGUID();
398 
399  for (GroupReference* itr = group->GetFirstMember(); itr != NULL; itr = itr->next())
400  if (Player* player = itr->GetSource()) // should actually be looted object instead of lootOwner but looter has to be really close so doesnt really matter
401  if (player->IsInMap(loot_owner))
402  FillNotNormalLootFor(player);
403 
404  for (uint8 i = 0; i < items.size(); ++i)
405  {
406  if (ItemTemplate const* proto = sObjectMgr.GetItemTemplate(items[i].itemid))
407  if (proto->Quality < uint32(group->GetLootThreshold()))
408  items[i].is_underthreshold = true;
409  }
410  }
411  // ... for personal loot
412  else
413  FillNotNormalLootFor(loot_owner);
414 }
#define MAX_NR_LOOT_ITEMS
Definition: LootMgr.h:29
Group * GetGroup()
Definition: Player.h:2577
#define sLog
Log class singleton.
Definition: Log.h:187
#define sObjectMgr
Definition: ObjectMgr.h:1285
ItemQualities GetLootThreshold() const
Definition: Group.h:241
ACE_UINT8 uint8
Definition: Define.h:73
void FillNotNormalLootFor(Player *player)
Definition: LootMgr.cpp:416
uint64 roundRobinPlayer
Definition: LootMgr.h:311
GroupReference * GetFirstMember()
Definition: Group.h:304
void Process(Loot &loot, LootStore const &store, uint8 GroupId=0) const
Definition: LootMgr.cpp:1097
GroupReference * next()
std::vector< LootItem > items
Definition: LootMgr.h:307
ACE_UINT32 uint32
Definition: Define.h:71
Definition: Player.h:922
#define MAX_NR_QUEST_ITEMS
Definition: LootMgr.h:31
std::vector< LootItem > quest_items
Definition: LootMgr.h:308
Definition: Group.h:154
const uint64 & GetGUID() const
Definition: Object.h:162
QuestItemList * Loot::FillNonQuestNonFFAConditionalLoot ( Player player)
private

Definition at line 505 of file LootMgr.cpp.

References LootItem::AllowedForPlayer(), LootItem::conditions, LootItem::freeforall, Object::GetGUIDLow(), LootItem::is_counted, and LootItem::is_looted.

506 {
507  QuestItemList* ql = new QuestItemList();
508 
509  for (uint8 i = 0; i < items.size(); ++i)
510  {
511  LootItem& item = items[i];
512  if (!item.is_looted && !item.freeforall && !item.conditions.empty() && item.AllowedForPlayer(player))
513  {
514  ql->push_back(QuestItem(i));
515  if (!item.is_counted)
516  {
517  ++unlootedCount;
518  item.is_counted = true;
519  }
520  }
521  }
522  if (ql->empty())
523  {
524  delete ql;
525  return NULL;
526  }
527 
529  return ql;
530 }
ConditionList conditions
Definition: LootMgr.h:129
bool is_counted
Definition: LootMgr.h:135
bool freeforall
Definition: LootMgr.h:133
uint32 GetGUIDLow() const
Definition: Object.h:166
bool is_looted
Definition: LootMgr.h:131
ACE_UINT8 uint8
Definition: Define.h:73
uint8 unlootedCount
Definition: LootMgr.h:310
bool AllowedForPlayer(Player const *player) const
Definition: LootMgr.cpp:322
std::vector< LootItem > items
Definition: LootMgr.h:307
std::vector< QuestItem > QuestItemList
Definition: LootMgr.h:159
QuestItemMap PlayerNonQuestNonFFAConditionalItems
Definition: LootMgr.h:393
void Loot::FillNotNormalLootFor ( Player player)

Definition at line 416 of file LootMgr.cpp.

References Object::GetGUIDLow().

Referenced by Player::SendLoot().

417 {
418  uint32 plguid = player->GetGUIDLow();
419 
420  QuestItemMap::const_iterator qmapitr = PlayerQuestItems.find(plguid);
421  if (qmapitr == PlayerQuestItems.end())
422  FillQuestLoot(player);
423 
424  qmapitr = PlayerFFAItems.find(plguid);
425  if (qmapitr == PlayerFFAItems.end())
426  FillFFALoot(player);
427 
428  qmapitr = PlayerNonQuestNonFFAConditionalItems.find(plguid);
429  if (qmapitr == PlayerNonQuestNonFFAConditionalItems.end())
431 
432  // Process currency items
433  uint32 max_slot = GetMaxSlotInLootFor(player);
434  LootItem const* item = NULL;
435  uint32 itemsSize = uint32(items.size());
436  for (uint32 i = 0; i < max_slot; ++i)
437  {
438  if (i < items.size())
439  item = &items[i];
440  else
441  item = &quest_items[i-itemsSize];
442  }
443 }
uint32 GetMaxSlotInLootFor(Player *player) const
Definition: LootMgr.cpp:675
QuestItemMap PlayerFFAItems
Definition: LootMgr.h:392
uint32 GetGUIDLow() const
Definition: Object.h:166
QuestItemList * FillQuestLoot(Player *player)
Definition: LootMgr.cpp:468
QuestItemList * FillNonQuestNonFFAConditionalLoot(Player *player)
Definition: LootMgr.cpp:505
std::vector< LootItem > items
Definition: LootMgr.h:307
QuestItemMap PlayerQuestItems
Definition: LootMgr.h:391
ACE_UINT32 uint32
Definition: Define.h:71
QuestItemList * FillFFALoot(Player *player)
Definition: LootMgr.cpp:445
QuestItemMap PlayerNonQuestNonFFAConditionalItems
Definition: LootMgr.h:393
std::vector< LootItem > quest_items
Definition: LootMgr.h:308
QuestItemList * Loot::FillQuestLoot ( Player player)
private

Definition at line 468 of file LootMgr.cpp.

References LootItem::AllowedForPlayer(), LootItem::freeforall, Player::GetGroup(), Object::GetGUIDLow(), Group::GetLootMethod(), GROUP_LOOT, LootItem::is_blocked, LootItem::is_looted, MAX_NR_LOOT_ITEMS, and ROUND_ROBIN.

469 {
470  if (items.size() == MAX_NR_LOOT_ITEMS)
471  return NULL;
472 
473  QuestItemList* ql = new QuestItemList();
474 
475  for (uint8 i = 0; i < quest_items.size(); i++)
476  {
477  LootItem& item = quest_items[i];
478  if (!item.is_looted && item.AllowedForPlayer(player))
479  {
480  ql->push_back(QuestItem(i));
481 
482  // quest items get blocked when they first appear in a
483  // player's quest vector
484  //
485  // increase once if one looter only, looter-times if free for all
486  if (item.freeforall || !item.is_blocked)
487  ++unlootedCount;
488  if (!player->GetGroup() || (player->GetGroup()->GetLootMethod() != GROUP_LOOT && player->GetGroup()->GetLootMethod() != ROUND_ROBIN))
489  item.is_blocked = true;
490 
491  if (items.size() + ql->size() == MAX_NR_LOOT_ITEMS)
492  break;
493  }
494  }
495  if (ql->empty())
496  {
497  delete ql;
498  return NULL;
499  }
500 
501  PlayerQuestItems[player->GetGUIDLow()] = ql;
502  return ql;
503 }
#define MAX_NR_LOOT_ITEMS
Definition: LootMgr.h:29
Group * GetGroup()
Definition: Player.h:2577
bool freeforall
Definition: LootMgr.h:133
bool is_blocked
Definition: LootMgr.h:132
uint32 GetGUIDLow() const
Definition: Object.h:166
bool is_looted
Definition: LootMgr.h:131
ACE_UINT8 uint8
Definition: Define.h:73
uint8 unlootedCount
Definition: LootMgr.h:310
bool AllowedForPlayer(Player const *player) const
Definition: LootMgr.cpp:322
std::vector< LootItem > items
Definition: LootMgr.h:307
std::vector< QuestItem > QuestItemList
Definition: LootMgr.h:159
QuestItemMap PlayerQuestItems
Definition: LootMgr.h:391
LootMethod GetLootMethod() const
Definition: Group.h:230
std::vector< LootItem > quest_items
Definition: LootMgr.h:308
void Loot::generateMoneyLoot ( uint32  minAmount,
uint32  maxAmount 
)

Definition at line 599 of file LootMgr.cpp.

References RATE_DROP_MONEY, sWorld, and urand().

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

600 {
601  if (maxAmount > 0)
602  {
603  if (maxAmount <= minAmount)
604  gold = uint32(maxAmount * sWorld.getRate(RATE_DROP_MONEY));
605  else if ((maxAmount - minAmount) < 32700)
606  gold = uint32(urand(minAmount, maxAmount) * sWorld.getRate(RATE_DROP_MONEY));
607  else
608  gold = uint32(urand(minAmount >> 8, maxAmount >> 8) * sWorld.getRate(RATE_DROP_MONEY)) << 8;
609  }
610 }
uint32 gold
Definition: LootMgr.h:309
#define sWorld
Definition: World.h:860
ACE_UINT32 uint32
Definition: Define.h:71
uint32 urand(uint32 min, uint32 max)
Definition: Util.cpp:33
uint32 Loot::GetMaxSlotInLootFor ( Player player) const

Definition at line 675 of file LootMgr.cpp.

References Object::GetGUIDLow().

Referenced by MailDraft::prepareItems().

676 {
677  QuestItemMap::const_iterator itr = PlayerQuestItems.find(player->GetGUIDLow());
678  return items.size() + (itr != PlayerQuestItems.end() ? itr->second->size() : 0);
679 }
uint32 GetGUIDLow() const
Definition: Object.h:166
std::vector< LootItem > items
Definition: LootMgr.h:307
QuestItemMap PlayerQuestItems
Definition: LootMgr.h:391
QuestItemMap const& Loot::GetPlayerFFAItems ( ) const
inline

Definition at line 298 of file LootMgr.h.

Referenced by operator<<().

299  {
300  return PlayerFFAItems;
301  }
QuestItemMap PlayerFFAItems
Definition: LootMgr.h:392
QuestItemMap const& Loot::GetPlayerNonQuestNonFFAConditionalItems ( ) const
inline

Definition at line 302 of file LootMgr.h.

Referenced by operator<<().

303  {
305  }
QuestItemMap PlayerNonQuestNonFFAConditionalItems
Definition: LootMgr.h:393
QuestItemMap const& Loot::GetPlayerQuestItems ( ) const
inline

Definition at line 294 of file LootMgr.h.

Referenced by WorldSession::HandleAutostoreLootItemOpcode(), and operator<<().

295  {
296  return PlayerQuestItems;
297  }
QuestItemMap PlayerQuestItems
Definition: LootMgr.h:391
bool Loot::hasItemFor ( Player player) const

Definition at line 695 of file LootMgr.cpp.

References Object::GetGUIDLow(), and LootItem::is_looted.

Referenced by Player::isAllowedToLoot().

696 {
697  QuestItemMap const& lootPlayerQuestItems = GetPlayerQuestItems();
698  QuestItemMap::const_iterator q_itr = lootPlayerQuestItems.find(player->GetGUIDLow());
699  if (q_itr != lootPlayerQuestItems.end())
700  {
701  QuestItemList* q_list = q_itr->second;
702  for (QuestItemList::const_iterator qi = q_list->begin(); qi != q_list->end(); ++qi)
703  {
704  const LootItem &item = quest_items[qi->index];
705  if (!qi->is_looted && !item.is_looted)
706  return true;
707  }
708  }
709 
710  QuestItemMap const& lootPlayerFFAItems = GetPlayerFFAItems();
711  QuestItemMap::const_iterator ffa_itr = lootPlayerFFAItems.find(player->GetGUIDLow());
712  if (ffa_itr != lootPlayerFFAItems.end())
713  {
714  QuestItemList* ffa_list = ffa_itr->second;
715  for (QuestItemList::const_iterator fi = ffa_list->begin(); fi != ffa_list->end(); ++fi)
716  {
717  const LootItem &item = items[fi->index];
718  if (!fi->is_looted && !item.is_looted)
719  return true;
720  }
721  }
722 
723  QuestItemMap const& lootPlayerNonQuestNonFFAConditionalItems = GetPlayerNonQuestNonFFAConditionalItems();
724  QuestItemMap::const_iterator nn_itr = lootPlayerNonQuestNonFFAConditionalItems.find(player->GetGUIDLow());
725  if (nn_itr != lootPlayerNonQuestNonFFAConditionalItems.end())
726  {
727  QuestItemList* conditional_list = nn_itr->second;
728  for (QuestItemList::const_iterator ci = conditional_list->begin(); ci != conditional_list->end(); ++ci)
729  {
730  const LootItem &item = items[ci->index];
731  if (!ci->is_looted && !item.is_looted)
732  return true;
733  }
734  }
735 
736  return false;
737 }
std::map< uint32, QuestItemList * > QuestItemMap
Definition: LootMgr.h:162
uint32 GetGUIDLow() const
Definition: Object.h:166
bool is_looted
Definition: LootMgr.h:131
QuestItemMap const & GetPlayerNonQuestNonFFAConditionalItems() const
Definition: LootMgr.h:302
QuestItemMap const & GetPlayerQuestItems() const
Definition: LootMgr.h:294
std::vector< LootItem > items
Definition: LootMgr.h:307
std::vector< QuestItem > QuestItemList
Definition: LootMgr.h:159
QuestItemMap const & GetPlayerFFAItems() const
Definition: LootMgr.h:298
std::vector< LootItem > quest_items
Definition: LootMgr.h:308
bool Loot::hasItemForAll ( ) const

Definition at line 682 of file LootMgr.cpp.

Referenced by Player::isAllowedToLoot().

683 {
684  // Gold is always lootable
685  if (gold)
686  return true;
687 
688  for (LootItem const& item : items)
689  if (!item.is_looted && !item.freeforall && item.conditions.empty())
690  return true;
691  return false;
692 }
uint32 gold
Definition: LootMgr.h:309
std::vector< LootItem > items
Definition: LootMgr.h:307
bool Loot::hasOverThresholdItem ( ) const

Definition at line 740 of file LootMgr.cpp.

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

741 {
742  for (uint8 i = 0; i < items.size(); ++i)
743  {
744  if (!items[i].is_looted && !items[i].is_underthreshold && !items[i].freeforall)
745  return true;
746  }
747 
748  return false;
749 }
ACE_UINT8 uint8
Definition: Define.h:73
std::vector< LootItem > items
Definition: LootMgr.h:307
bool Loot::isLooted ( ) const
inline

Definition at line 355 of file LootMgr.h.

Referenced by Spell::CheckCast(), WorldSession::DoLootRelease(), Player::isAllowedToLoot(), and Unit::Kill().

356  {
357  return gold == 0 && unlootedCount == 0;
358  }
uint8 unlootedCount
Definition: LootMgr.h:310
uint32 gold
Definition: LootMgr.h:309
LootItem * Loot::LootItemInSlot ( uint32  lootslot,
Player player,
QuestItem **  qitem = NULL,
QuestItem **  ffaitem = NULL,
QuestItem **  conditem = NULL 
)

Definition at line 612 of file LootMgr.cpp.

References LootItem::conditions, LootItem::freeforall, Object::GetGUIDLow(), QuestItem::index, LootItem::is_looted, and QuestItem::is_looted.

Referenced by WorldSession::HandleAutostoreLootItemOpcode(), MailDraft::prepareItems(), and Aura::TriggerSpell().

613 {
614  LootItem* item = NULL;
615  bool is_looted = true;
616  if (lootSlot >= items.size())
617  {
618  uint32 questSlot = lootSlot - items.size();
619  QuestItemMap::const_iterator itr = PlayerQuestItems.find(player->GetGUIDLow());
620  if (itr != PlayerQuestItems.end() && questSlot < itr->second->size())
621  {
622  QuestItem* qitem2 = &itr->second->at(questSlot);
623  if (qitem)
624  *qitem = qitem2;
625  item = &quest_items[qitem2->index];
626  is_looted = qitem2->is_looted;
627  }
628  }
629  else
630  {
631  item = &items[lootSlot];
632  is_looted = item->is_looted;
633  if (item->freeforall)
634  {
635  QuestItemMap::const_iterator itr = PlayerFFAItems.find(player->GetGUIDLow());
636  if (itr != PlayerFFAItems.end())
637  {
638  for (QuestItemList::iterator iter = itr->second->begin(); iter != itr->second->end(); ++iter)
639  if (iter->index == lootSlot)
640  {
641  QuestItem* ffaitem2 = (QuestItem*) & (*iter);
642  if (ffaitem)
643  *ffaitem = ffaitem2;
644  is_looted = ffaitem2->is_looted;
645  break;
646  }
647  }
648  }
649  else if (!item->conditions.empty())
650  {
651  QuestItemMap::const_iterator itr = PlayerNonQuestNonFFAConditionalItems.find(player->GetGUIDLow());
652  if (itr != PlayerNonQuestNonFFAConditionalItems.end())
653  {
654  for (QuestItemList::iterator iter = itr->second->begin(); iter != itr->second->end(); ++iter)
655  {
656  if (iter->index == lootSlot)
657  {
658  QuestItem* conditem2 = (QuestItem*) & (*iter);
659  if (conditem)
660  *conditem = conditem2;
661  is_looted = conditem2->is_looted;
662  break;
663  }
664  }
665  }
666  }
667  }
668 
669  if (is_looted)
670  return NULL;
671 
672  return item;
673 }
ConditionList conditions
Definition: LootMgr.h:129
bool freeforall
Definition: LootMgr.h:133
QuestItemMap PlayerFFAItems
Definition: LootMgr.h:392
bool is_looted
Definition: LootMgr.h:149
uint32 GetGUIDLow() const
Definition: Object.h:166
bool is_looted
Definition: LootMgr.h:131
uint8 index
Definition: LootMgr.h:148
std::vector< LootItem > items
Definition: LootMgr.h:307
QuestItemMap PlayerQuestItems
Definition: LootMgr.h:391
ACE_UINT32 uint32
Definition: Define.h:71
QuestItemMap PlayerNonQuestNonFFAConditionalItems
Definition: LootMgr.h:393
std::vector< LootItem > quest_items
Definition: LootMgr.h:308
void Loot::NotifyItemRemoved ( uint8  lootIndex)

Definition at line 534 of file LootMgr.cpp.

References ObjectAccessor::FindPlayer().

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

535 {
536  // notify all players that are looting this that the item was removed
537  // convert the index to the slot the player sees
538  std::set<uint64>::iterator i_next;
539  for (std::set<uint64>::iterator i = PlayersLooting.begin(); i != PlayersLooting.end(); i = i_next)
540  {
541  i_next = i;
542  ++i_next;
543  if (Player* player = ObjectAccessor::FindPlayer(*i))
544  player->SendNotifyLootItemRemoved(lootIndex);
545  else
546  PlayersLooting.erase(i);
547  }
548 }
std::set< uint64 > PlayersLooting
Definition: LootMgr.h:390
static Player * FindPlayer(uint64, bool force=false)
Definition: Player.h:922
void Loot::NotifyMoneyRemoved ( )

Definition at line 550 of file LootMgr.cpp.

References ObjectAccessor::FindPlayer().

Referenced by WorldSession::HandleLootMoneyOpcode().

551 {
552  // notify all players that are looting this that the money was removed
553  std::set<uint64>::iterator i_next;
554  for (std::set<uint64>::iterator i = PlayersLooting.begin(); i != PlayersLooting.end(); i = i_next)
555  {
556  i_next = i;
557  ++i_next;
558  if (Player* player = ObjectAccessor::FindPlayer(*i))
559  player->SendNotifyLootMoneyRemoved();
560  else
561  PlayersLooting.erase(i);
562  }
563 }
std::set< uint64 > PlayersLooting
Definition: LootMgr.h:390
static Player * FindPlayer(uint64, bool force=false)
Definition: Player.h:922
void Loot::NotifyQuestItemRemoved ( uint8  questIndex)

Definition at line 565 of file LootMgr.cpp.

References ObjectAccessor::FindPlayer().

Referenced by WorldSession::HandleAutostoreLootItemOpcode().

566 {
567  // when a free for all questitem is looted
568  // all players will get notified of it being removed
569  // (other questitems can be looted by each group member)
570  // bit inefficient but isn't called often
571 
572  std::set<uint64>::iterator i_next;
573  for (std::set<uint64>::iterator i = PlayersLooting.begin(); i != PlayersLooting.end(); i = i_next)
574  {
575  i_next = i;
576  ++i_next;
577  if (Player* player = ObjectAccessor::FindPlayer(*i))
578  {
579  QuestItemMap::const_iterator pq = PlayerQuestItems.find(player->GetGUIDLow());
580  if (pq != PlayerQuestItems.end() && pq->second)
581  {
582  // find where/if the player has the given item in it's vector
583  QuestItemList& pql = *pq->second;
584 
585  uint8 j;
586  for (j = 0; j < pql.size(); ++j)
587  if (pql[j].index == questIndex)
588  break;
589 
590  if (j < pql.size())
591  player->SendNotifyLootItemRemoved(items.size()+j);
592  }
593  }
594  else
595  PlayersLooting.erase(i);
596  }
597 }
std::set< uint64 > PlayersLooting
Definition: LootMgr.h:390
ACE_UINT8 uint8
Definition: Define.h:73
static Player * FindPlayer(uint64, bool force=false)
std::vector< LootItem > items
Definition: LootMgr.h:307
std::vector< QuestItem > QuestItemList
Definition: LootMgr.h:159
QuestItemMap PlayerQuestItems
Definition: LootMgr.h:391
Definition: Player.h:922
void Loot::RemoveLooter ( uint64  GUID)
inline

Definition at line 367 of file LootMgr.h.

Referenced by WorldSession::DoLootRelease().

368  {
369  PlayersLooting.erase(GUID);
370  }
std::set< uint64 > PlayersLooting
Definition: LootMgr.h:390

Friends And Related Function Documentation

ByteBuffer& operator<< ( ByteBuffer b,
LootView const &  lv 
)
friend

Definition at line 762 of file LootMgr.cpp.

763 {
764  if (lv.permission == NONE_PERMISSION)
765  {
766  b << uint32(0); // gold
767  b << uint8(0); // item count
768  return b;
769  }
770 
771  Loot &l = lv.loot;
772 
773  uint8 itemsShown = 0;
774 
775  b << uint32(l.gold); //gold
776 
777  size_t count_pos = b.wpos(); // pos of item count byte
778  b << uint8(0); // item count placeholder
779 
780  switch (lv.permission)
781  {
782  case GROUP_PERMISSION:
783  case MASTER_PERMISSION:
785  {
786  // if you are not the round-robin group looter, you can only see
787  // blocked rolled items and quest items, and !ffa items
788  for (uint8 i = 0; i < l.items.size(); ++i)
789  {
790  if (!l.items[i].is_looted && !l.items[i].freeforall && l.items[i].conditions.empty() && l.items[i].AllowedForPlayer(lv.viewer))
791  {
792  uint8 slot_type;
793 
794  if (l.items[i].is_blocked) // for ML & restricted is_blocked = !is_underthreshold
795  {
796  switch (lv.permission)
797  {
798  case GROUP_PERMISSION:
799  slot_type = LOOT_SLOT_TYPE_ROLL_ONGOING;
800  break;
801  case MASTER_PERMISSION:
802  {
803  if (lv.viewer->GetGroup() && lv.viewer->GetGroup()->GetMasterLooterGuid() == lv.viewer->GetGUID())
804  slot_type = LOOT_SLOT_TYPE_MASTER;
805  else
806  slot_type = LOOT_SLOT_TYPE_LOCKED;
807  break;
808  }
810  slot_type = LOOT_SLOT_TYPE_LOCKED;
811  break;
812  default:
813  continue;
814  }
815  }
816  else if (!l.roundRobinPlayer || lv.viewer->GetGUID() == l.roundRobinPlayer || !l.items[i].is_underthreshold)
817  {
818  // no round robin owner or he has released the loot
819  // or it IS the round robin group owner
820  // => item is lootable
821  slot_type = LOOT_SLOT_TYPE_ALLOW_LOOT;
822  }
823  else
824  // item shall not be displayed.
825  continue;
826 
827  b << uint8(i) << l.items[i];
828  b << uint8(slot_type);
829  ++itemsShown;
830  }
831  }
832  break;
833  }
835  {
836  for (uint8 i = 0; i < l.items.size(); ++i)
837  {
838  if (!l.items[i].is_looted && !l.items[i].freeforall && l.items[i].conditions.empty() && l.items[i].AllowedForPlayer(lv.viewer))
839  {
840  if (l.roundRobinPlayer && lv.viewer->GetGUID() != l.roundRobinPlayer)
841  // item shall not be displayed.
842  continue;
843 
844  b << uint8(i) << l.items[i];
846  ++itemsShown;
847  }
848  }
849  break;
850  }
851  case ALL_PERMISSION:
852  case OWNER_PERMISSION:
853  {
854  uint8 slot_type = lv.permission == OWNER_PERMISSION ? LOOT_SLOT_TYPE_OWNER : LOOT_SLOT_TYPE_ALLOW_LOOT;
855  for (uint8 i = 0; i < l.items.size(); ++i)
856  {
857  if (!l.items[i].is_looted && !l.items[i].freeforall && l.items[i].conditions.empty() && l.items[i].AllowedForPlayer(lv.viewer))
858  {
859  b << uint8(i) << l.items[i];
860  b << uint8(slot_type);
861  ++itemsShown;
862  }
863  }
864  break;
865  }
866  default:
867  return b;
868  }
869 
871  QuestItemMap const& lootPlayerQuestItems = l.GetPlayerQuestItems();
872  QuestItemMap::const_iterator q_itr = lootPlayerQuestItems.find(lv.viewer->GetGUIDLow());
873  if (q_itr != lootPlayerQuestItems.end())
874  {
875  QuestItemList* q_list = q_itr->second;
876  for (QuestItemList::const_iterator qi = q_list->begin(); qi != q_list->end(); ++qi)
877  {
878  LootItem &item = l.quest_items[qi->index];
879  if (!qi->is_looted && !item.is_looted)
880  {
881  b << uint8(l.items.size() + (qi - q_list->begin()));
882  b << item;
883  b << uint8(slotType);
884  ++itemsShown;
885  }
886  }
887  }
888 
889  QuestItemMap const& lootPlayerFFAItems = l.GetPlayerFFAItems();
890  QuestItemMap::const_iterator ffa_itr = lootPlayerFFAItems.find(lv.viewer->GetGUIDLow());
891  if (ffa_itr != lootPlayerFFAItems.end())
892  {
893  QuestItemList* ffa_list = ffa_itr->second;
894  for (QuestItemList::const_iterator fi = ffa_list->begin(); fi != ffa_list->end(); ++fi)
895  {
896  LootItem &item = l.items[fi->index];
897  if (!fi->is_looted && !item.is_looted)
898  {
899  b << uint8(fi->index);
900  b << item;
901  b << uint8(slotType);
902  ++itemsShown;
903  }
904  }
905  }
906 
907  QuestItemMap const& lootPlayerNonQuestNonFFAConditionalItems = l.GetPlayerNonQuestNonFFAConditionalItems();
908  QuestItemMap::const_iterator nn_itr = lootPlayerNonQuestNonFFAConditionalItems.find(lv.viewer->GetGUIDLow());
909  if (nn_itr != lootPlayerNonQuestNonFFAConditionalItems.end())
910  {
911  QuestItemList* conditional_list = nn_itr->second;
912  for (QuestItemList::const_iterator ci = conditional_list->begin(); ci != conditional_list->end(); ++ci)
913  {
914  LootItem &item = l.items[ci->index];
915  if (!ci->is_looted && !item.is_looted)
916  {
917  b << uint8(ci->index);
918  b << item;
919  b << uint8(slotType);
920  ++itemsShown;
921  }
922  }
923  }
924 
925  //update number of items shown
926  b.put<uint8>(count_pos, itemsShown);
927 
928  return b;
929 }
std::map< uint32, QuestItemList * > QuestItemMap
Definition: LootMgr.h:162
bool is_looted
Definition: LootMgr.h:131
LootSlotType
Definition: LootMgr.h:88
QuestItemMap const & GetPlayerNonQuestNonFFAConditionalItems() const
Definition: LootMgr.h:302
size_t wpos() const
Definition: ByteBuffer.h:264
QuestItemMap const & GetPlayerQuestItems() const
Definition: LootMgr.h:294
ACE_UINT8 uint8
Definition: Define.h:73
Definition: LootMgr.h:290
void put(size_t pos, T value)
Definition: ByteBuffer.h:79
uint64 roundRobinPlayer
Definition: LootMgr.h:311
uint32 gold
Definition: LootMgr.h:309
std::vector< LootItem > items
Definition: LootMgr.h:307
std::vector< QuestItem > QuestItemList
Definition: LootMgr.h:159
QuestItemMap const & GetPlayerFFAItems() const
Definition: LootMgr.h:298
ACE_UINT32 uint32
Definition: Define.h:71
std::vector< LootItem > quest_items
Definition: LootMgr.h:308

Member Data Documentation

LootValidatorRefManager Loot::i_LootValidatorRefManager
private

Definition at line 396 of file LootMgr.h.

QuestItemMap Loot::PlayerFFAItems
private

Definition at line 392 of file LootMgr.h.

QuestItemMap Loot::PlayerNonQuestNonFFAConditionalItems
private

Definition at line 393 of file LootMgr.h.

QuestItemMap Loot::PlayerQuestItems
private

Definition at line 391 of file LootMgr.h.

std::set<uint64> Loot::PlayersLooting
private

Definition at line 390 of file LootMgr.h.

std::vector<LootItem> Loot::quest_items

Definition at line 308 of file LootMgr.h.

Referenced by Group::CountTheRoll(), Group::MasterLoot(), and operator<<().

uint64 Loot::roundRobinPlayer

Definition at line 311 of file LootMgr.h.

Referenced by WorldSession::DoLootRelease(), Player::isAllowedToLoot(), and operator<<().


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