aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Loot/LootMgr.cpp
diff options
context:
space:
mode:
authorariel- <ariel-@users.noreply.github.com>2017-06-19 23:20:06 -0300
committerariel- <ariel-@users.noreply.github.com>2017-06-19 23:20:06 -0300
commit85a7d5ce9ac68b30da2277cc91d4b70358f1880d (patch)
treedf3d2084ee2e35008903c03178039b9c986e2d08 /src/server/game/Loot/LootMgr.cpp
parent052fc24315ace866ea1cf610e85df119b68100c9 (diff)
Core: ported headers cleanup from master branch
Diffstat (limited to 'src/server/game/Loot/LootMgr.cpp')
-rw-r--r--src/server/game/Loot/LootMgr.cpp759
1 files changed, 21 insertions, 738 deletions
diff --git a/src/server/game/Loot/LootMgr.cpp b/src/server/game/Loot/LootMgr.cpp
index 34712308070..7c6cc28fb48 100644
--- a/src/server/game/Loot/LootMgr.cpp
+++ b/src/server/game/Loot/LootMgr.cpp
@@ -17,16 +17,19 @@
*/
#include "LootMgr.h"
+#include "Containers.h"
+#include "DatabaseEnv.h"
+#include "DBCStores.h"
+#include "Group.h"
#include "Log.h"
+#include "Loot.h"
#include "ObjectMgr.h"
-#include "World.h"
-#include "Util.h"
+#include "Player.h"
#include "SharedDefines.h"
-#include "SpellMgr.h"
#include "SpellInfo.h"
-#include "Group.h"
-#include "Player.h"
-#include "Containers.h"
+#include "SpellMgr.h"
+#include "Util.h"
+#include "World.h"
static Rates const qualityToRate[MAX_ITEM_QUALITY] =
{
@@ -91,7 +94,6 @@ class LootTemplate::LootGroup // A set of loot def
float TotalChance() const; // Overall chance for the group
void Verify(LootStore const& lootstore, uint32 id, uint8 group_id) const;
- void CollectLootIds(LootIdSet& set) const;
void CheckLootRefs(LootTemplateMap const& store, LootIdSet* ref_set) const;
LootStoreItemList* GetExplicitlyChancedItemList() { return &ExplicitlyChanced; }
LootStoreItemList* GetEqualChancedItemList() { return &EqualChanced; }
@@ -103,14 +105,14 @@ class LootTemplate::LootGroup // A set of loot def
LootStoreItem const* Roll(Loot& loot, uint16 lootMode) const; // Rolls an item from the group, returns NULL if all miss their chances
// This class must never be copied - storing pointers
- LootGroup(LootGroup const&);
- LootGroup& operator=(LootGroup const&);
+ LootGroup(LootGroup const&) = delete;
+ LootGroup& operator=(LootGroup const&) = delete;
};
//Remove all data and free all memory
void LootStore::Clear()
{
- for (LootTemplateMap::const_iterator itr=m_LootTemplates.begin(); itr != m_LootTemplates.end(); ++itr)
+ for (LootTemplateMap::const_iterator itr = m_LootTemplates.begin(); itr != m_LootTemplates.end(); ++itr)
delete itr->second;
m_LootTemplates.clear();
}
@@ -228,7 +230,7 @@ LootTemplate const* LootStore::GetLootFor(uint32 loot_id) const
LootTemplateMap::const_iterator tab = m_LootTemplates.find(loot_id);
if (tab == m_LootTemplates.end())
- return NULL;
+ return nullptr;
return tab->second;
}
@@ -238,7 +240,7 @@ LootTemplate* LootStore::GetLootForConditionFill(uint32 loot_id)
LootTemplateMap::iterator tab = m_LootTemplates.find(loot_id);
if (tab == m_LootTemplates.end())
- return NULL;
+ return nullptr;
return tab->second;
}
@@ -266,7 +268,7 @@ void LootStore::ReportUnusedIds(LootIdSet const& lootIdSet) const
TC_LOG_ERROR("sql.sql", "Table '%s' Entry %d isn't %s and not referenced from loot, and thus useless.", GetName(), *itr, GetEntryName());
}
-void LootStore::ReportNonExistingId(uint32 lootId, const char* ownerType, uint32 ownerId) const
+void LootStore::ReportNonExistingId(uint32 lootId, char const* ownerType, uint32 ownerId) const
{
TC_LOG_ERROR("sql.sql", "Table '%s' Entry %d does not exist but it is used by %s %d", GetName(), lootId, ownerType, ownerId);
}
@@ -343,722 +345,6 @@ bool LootStoreItem::IsValid(LootStore const& store, uint32 entry) const
}
//
-// --------- LootItem ---------
-//
-
-// Constructor, copies most fields from LootStoreItem and generates random count
-LootItem::LootItem(LootStoreItem const& li)
-{
- itemid = li.itemid;
- conditions = li.conditions;
-
- ItemTemplate const* proto = sObjectMgr->GetItemTemplate(itemid);
- freeforall = proto && (proto->Flags & ITEM_FLAG_MULTI_DROP);
- follow_loot_rules = proto && (proto->FlagsCu & ITEM_FLAGS_CU_FOLLOW_LOOT_RULES);
-
- needs_quest = li.needs_quest;
-
- randomSuffix = GenerateEnchSuffixFactor(itemid);
- randomPropertyId = Item::GenerateItemRandomPropertyId(itemid);
- count = 0;
- is_looted = 0;
- is_blocked = 0;
- is_underthreshold = 0;
- is_counted = 0;
- rollWinnerGUID = ObjectGuid::Empty;
-}
-
-// Basic checks for player/item compatibility - if false no chance to see the item in the loot
-bool LootItem::AllowedForPlayer(Player const* player) const
-{
- // DB conditions check
- if (!sConditionMgr->IsObjectMeetToConditions(const_cast<Player*>(player), conditions))
- return false;
-
- ItemTemplate const* pProto = sObjectMgr->GetItemTemplate(itemid);
- if (!pProto)
- return false;
-
- // not show loot for players without profession or those who already know the recipe
- if ((pProto->Flags & ITEM_FLAG_HIDE_UNUSABLE_RECIPE) && (!player->HasSkill(pProto->RequiredSkill) || player->HasSpell(pProto->Spells[1].SpellId)))
- return false;
-
- // not show loot for not own team
- if ((pProto->Flags2 & ITEM_FLAG2_FACTION_HORDE) && player->GetTeam() != HORDE)
- return false;
-
- if ((pProto->Flags2 & ITEM_FLAG2_FACTION_ALLIANCE) && player->GetTeam() != ALLIANCE)
- return false;
-
- // check quest requirements
- if (!(pProto->FlagsCu & ITEM_FLAGS_CU_IGNORE_QUEST_STATUS) && ((needs_quest || (pProto->StartQuest && player->GetQuestStatus(pProto->StartQuest) != QUEST_STATUS_NONE)) && !player->HasQuestForItem(itemid)))
- return false;
-
- return true;
-}
-
-void LootItem::AddAllowedLooter(const Player* player)
-{
- allowedGUIDs.insert(player->GetGUID().GetCounter());
-}
-
-//
-// --------- Loot ---------
-//
-
-// Inserts the item into the loot (called by LootTemplate processors)
-void Loot::AddItem(LootStoreItem const& item)
-{
- ItemTemplate const* proto = sObjectMgr->GetItemTemplate(item.itemid);
- if (!proto)
- return;
-
- uint32 count = urand(item.mincount, item.maxcount);
- uint32 stacks = count / proto->GetMaxStackSize() + ((count % proto->GetMaxStackSize()) ? 1 : 0);
-
- std::vector<LootItem>& lootItems = item.needs_quest ? quest_items : items;
- uint32 limit = item.needs_quest ? MAX_NR_QUEST_ITEMS : MAX_NR_LOOT_ITEMS;
-
- for (uint32 i = 0; i < stacks && lootItems.size() < limit; ++i)
- {
- LootItem generatedLoot(item);
- generatedLoot.count = std::min(count, proto->GetMaxStackSize());
- lootItems.push_back(generatedLoot);
- count -= proto->GetMaxStackSize();
-
- // non-conditional one-player only items are counted here,
- // free for all items are counted in FillFFALoot(),
- // non-ffa conditionals are counted in FillNonQuestNonFFAConditionalLoot()
- if (!item.needs_quest && item.conditions.empty() && !(proto->Flags & ITEM_FLAG_MULTI_DROP))
- ++unlootedCount;
- }
-}
-
-// Calls processor of corresponding LootTemplate (which handles everything including references)
-bool Loot::FillLoot(uint32 lootId, LootStore const& store, Player* lootOwner, bool personal, bool noEmptyError, uint16 lootMode /*= LOOT_MODE_DEFAULT*/)
-{
- // Must be provided
- if (!lootOwner)
- return false;
-
- LootTemplate const* tab = store.GetLootFor(lootId);
-
- if (!tab)
- {
- if (!noEmptyError)
- TC_LOG_ERROR("sql.sql", "Table '%s' loot id #%u used but it doesn't have records.", store.GetName(), lootId);
- return false;
- }
-
- items.reserve(MAX_NR_LOOT_ITEMS);
- quest_items.reserve(MAX_NR_QUEST_ITEMS);
-
- tab->Process(*this, store.IsRatesAllowed(), lootMode); // Processing is done there, callback via Loot::AddItem()
-
- // Setting access rights for group loot case
- Group* group = lootOwner->GetGroup();
- if (!personal && group)
- {
- roundRobinPlayer = lootOwner->GetGUID();
-
- for (GroupReference* itr = group->GetFirstMember(); itr != NULL; itr = itr->next())
- if (Player* player = itr->GetSource()) // should actually be looted object instead of lootOwner but looter has to be really close so doesnt really matter
- if (player->IsInMap(lootOwner))
- FillNotNormalLootFor(player, player->IsAtGroupRewardDistance(lootOwner));
-
- for (uint8 i = 0; i < items.size(); ++i)
- {
- if (ItemTemplate const* proto = sObjectMgr->GetItemTemplate(items[i].itemid))
- if (proto->Quality < uint32(group->GetLootThreshold()))
- items[i].is_underthreshold = true;
- }
- }
- // ... for personal loot
- else
- FillNotNormalLootFor(lootOwner, true);
-
- return true;
-}
-
-void Loot::FillNotNormalLootFor(Player* player, bool presentAtLooting)
-{
- ObjectGuid::LowType plguid = player->GetGUID().GetCounter();
-
- NotNormalLootItemMap::const_iterator qmapitr = PlayerQuestItems.find(plguid);
- if (qmapitr == PlayerQuestItems.end())
- FillQuestLoot(player);
-
- qmapitr = PlayerFFAItems.find(plguid);
- if (qmapitr == PlayerFFAItems.end())
- FillFFALoot(player);
-
- qmapitr = PlayerNonQuestNonFFAConditionalItems.find(plguid);
- if (qmapitr == PlayerNonQuestNonFFAConditionalItems.end())
- FillNonQuestNonFFAConditionalLoot(player, presentAtLooting);
-
- // if not auto-processed player will have to come and pick it up manually
- if (!presentAtLooting)
- return;
-
- // Process currency items
- uint32 max_slot = GetMaxSlotInLootFor(player);
- LootItem const* item = NULL;
- uint32 itemsSize = uint32(items.size());
- for (uint32 i = 0; i < max_slot; ++i)
- {
- if (i < items.size())
- item = &items[i];
- else
- item = &quest_items[i-itemsSize];
-
- if (!item->is_looted && item->freeforall && item->AllowedForPlayer(player))
- if (ItemTemplate const* proto = sObjectMgr->GetItemTemplate(item->itemid))
- if (proto->IsCurrencyToken())
- player->StoreLootItem(i, this);
- }
-}
-
-NotNormalLootItemList* Loot::FillFFALoot(Player* player)
-{
- NotNormalLootItemList* ql = new NotNormalLootItemList();
-
- for (uint8 i = 0; i < items.size(); ++i)
- {
- LootItem &item = items[i];
- if (!item.is_looted && item.freeforall && item.AllowedForPlayer(player))
- {
- ql->push_back(NotNormalLootItem(i));
- ++unlootedCount;
- }
- }
- if (ql->empty())
- {
- delete ql;
- return NULL;
- }
-
- PlayerFFAItems[player->GetGUID().GetCounter()] = ql;
- return ql;
-}
-
-NotNormalLootItemList* Loot::FillQuestLoot(Player* player)
-{
- if (items.size() == MAX_NR_LOOT_ITEMS)
- return NULL;
-
- NotNormalLootItemList* ql = new NotNormalLootItemList();
-
- for (uint8 i = 0; i < quest_items.size(); ++i)
- {
- LootItem &item = quest_items[i];
-
- 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))))
- {
- ql->push_back(NotNormalLootItem(i));
-
- // quest items get blocked when they first appear in a
- // player's quest vector
- //
- // increase once if one looter only, looter-times if free for all
- if (item.freeforall || !item.is_blocked)
- ++unlootedCount;
- if (!player->GetGroup() || (player->GetGroup()->GetLootMethod() != GROUP_LOOT && player->GetGroup()->GetLootMethod() != ROUND_ROBIN))
- item.is_blocked = true;
-
- if (items.size() + ql->size() == MAX_NR_LOOT_ITEMS)
- break;
- }
- }
- if (ql->empty())
- {
- delete ql;
- return NULL;
- }
-
- PlayerQuestItems[player->GetGUID().GetCounter()] = ql;
- return ql;
-}
-
-NotNormalLootItemList* Loot::FillNonQuestNonFFAConditionalLoot(Player* player, bool presentAtLooting)
-{
- NotNormalLootItemList* ql = new NotNormalLootItemList();
-
- for (uint8 i = 0; i < items.size(); ++i)
- {
- LootItem &item = items[i];
- if (!item.is_looted && !item.freeforall && (item.AllowedForPlayer(player)))
- {
- if (presentAtLooting)
- item.AddAllowedLooter(player);
- if (!item.conditions.empty())
- {
- ql->push_back(NotNormalLootItem(i));
- if (!item.is_counted)
- {
- ++unlootedCount;
- item.is_counted = true;
- }
- }
- }
- }
- if (ql->empty())
- {
- delete ql;
- return NULL;
- }
-
- PlayerNonQuestNonFFAConditionalItems[player->GetGUID().GetCounter()] = ql;
- return ql;
-}
-
-//===================================================
-
-void Loot::NotifyItemRemoved(uint8 lootIndex)
-{
- // notify all players that are looting this that the item was removed
- // convert the index to the slot the player sees
- GuidSet::iterator i_next;
- for (GuidSet::iterator i = PlayersLooting.begin(); i != PlayersLooting.end(); i = i_next)
- {
- i_next = i;
- ++i_next;
- if (Player* player = ObjectAccessor::FindPlayer(*i))
- player->SendNotifyLootItemRemoved(lootIndex);
- else
- PlayersLooting.erase(i);
- }
-}
-
-void Loot::NotifyMoneyRemoved()
-{
- // notify all players that are looting this that the money was removed
- GuidSet::iterator i_next;
- for (GuidSet::iterator i = PlayersLooting.begin(); i != PlayersLooting.end(); i = i_next)
- {
- i_next = i;
- ++i_next;
- if (Player* player = ObjectAccessor::FindPlayer(*i))
- player->SendNotifyLootMoneyRemoved();
- else
- PlayersLooting.erase(i);
- }
-}
-
-void Loot::NotifyQuestItemRemoved(uint8 questIndex)
-{
- // when a free for all questitem is looted
- // all players will get notified of it being removed
- // (other questitems can be looted by each group member)
- // bit inefficient but isn't called often
-
- GuidSet::iterator i_next;
- for (GuidSet::iterator i = PlayersLooting.begin(); i != PlayersLooting.end(); i = i_next)
- {
- i_next = i;
- ++i_next;
- if (Player* player = ObjectAccessor::FindPlayer(*i))
- {
- NotNormalLootItemMap::const_iterator pq = PlayerQuestItems.find(player->GetGUID().GetCounter());
- if (pq != PlayerQuestItems.end() && pq->second)
- {
- // find where/if the player has the given item in it's vector
- NotNormalLootItemList& pql = *pq->second;
-
- uint8 j;
- for (j = 0; j < pql.size(); ++j)
- if (pql[j].index == questIndex)
- break;
-
- if (j < pql.size())
- player->SendNotifyLootItemRemoved(items.size()+j);
- }
- }
- else
- PlayersLooting.erase(i);
- }
-}
-
-void Loot::generateMoneyLoot(uint32 minAmount, uint32 maxAmount)
-{
- if (maxAmount > 0)
- {
- if (maxAmount <= minAmount)
- gold = uint32(maxAmount * sWorld->getRate(RATE_DROP_MONEY));
- else if ((maxAmount - minAmount) < 32700)
- gold = uint32(urand(minAmount, maxAmount) * sWorld->getRate(RATE_DROP_MONEY));
- else
- gold = uint32(urand(minAmount >> 8, maxAmount >> 8) * sWorld->getRate(RATE_DROP_MONEY)) << 8;
- }
-}
-
-LootItem* Loot::LootItemInSlot(uint32 lootSlot, Player* player, NotNormalLootItem* *qitem, NotNormalLootItem* *ffaitem, NotNormalLootItem* *conditem)
-{
- LootItem* item = NULL;
- bool is_looted = true;
- if (lootSlot >= items.size())
- {
- uint32 questSlot = lootSlot - items.size();
- NotNormalLootItemMap::const_iterator itr = PlayerQuestItems.find(player->GetGUID().GetCounter());
- if (itr != PlayerQuestItems.end() && questSlot < itr->second->size())
- {
- NotNormalLootItem* qitem2 = &itr->second->at(questSlot);
- if (qitem)
- *qitem = qitem2;
- item = &quest_items[qitem2->index];
- is_looted = qitem2->is_looted;
- }
- }
- else
- {
- item = &items[lootSlot];
- is_looted = item->is_looted;
- if (item->freeforall)
- {
- NotNormalLootItemMap::const_iterator itr = PlayerFFAItems.find(player->GetGUID().GetCounter());
- if (itr != PlayerFFAItems.end())
- {
- for (NotNormalLootItemList::const_iterator iter=itr->second->begin(); iter!= itr->second->end(); ++iter)
- if (iter->index == lootSlot)
- {
- NotNormalLootItem* ffaitem2 = (NotNormalLootItem*)&(*iter);
- if (ffaitem)
- *ffaitem = ffaitem2;
- is_looted = ffaitem2->is_looted;
- break;
- }
- }
- }
- else if (!item->conditions.empty())
- {
- NotNormalLootItemMap::const_iterator itr = PlayerNonQuestNonFFAConditionalItems.find(player->GetGUID().GetCounter());
- if (itr != PlayerNonQuestNonFFAConditionalItems.end())
- {
- for (NotNormalLootItemList::const_iterator iter=itr->second->begin(); iter!= itr->second->end(); ++iter)
- {
- if (iter->index == lootSlot)
- {
- NotNormalLootItem* conditem2 = (NotNormalLootItem*)&(*iter);
- if (conditem)
- *conditem = conditem2;
- is_looted = conditem2->is_looted;
- break;
- }
- }
- }
- }
- }
-
- if (is_looted)
- return NULL;
-
- return item;
-}
-
-uint32 Loot::GetMaxSlotInLootFor(Player* player) const
-{
- NotNormalLootItemMap::const_iterator itr = PlayerQuestItems.find(player->GetGUID().GetCounter());
- return items.size() + (itr != PlayerQuestItems.end() ? itr->second->size() : 0);
-}
-
-// return true if there is any item that is lootable for any player (not quest item, FFA or conditional)
-bool Loot::hasItemForAll() const
-{
- // Gold is always lootable
- if (gold)
- return true;
-
- for (LootItem const& item : items)
- if (!item.is_looted && !item.freeforall && item.conditions.empty())
- return true;
- return false;
-}
-
-// return true if there is any FFA, quest or conditional item for the player.
-bool Loot::hasItemFor(Player* player) const
-{
- NotNormalLootItemMap const& lootPlayerQuestItems = GetPlayerQuestItems();
- NotNormalLootItemMap::const_iterator q_itr = lootPlayerQuestItems.find(player->GetGUID().GetCounter());
- if (q_itr != lootPlayerQuestItems.end())
- {
- NotNormalLootItemList* q_list = q_itr->second;
- for (NotNormalLootItemList::const_iterator qi = q_list->begin(); qi != q_list->end(); ++qi)
- {
- const LootItem &item = quest_items[qi->index];
- if (!qi->is_looted && !item.is_looted)
- return true;
- }
- }
-
- NotNormalLootItemMap const& lootPlayerFFAItems = GetPlayerFFAItems();
- NotNormalLootItemMap::const_iterator ffa_itr = lootPlayerFFAItems.find(player->GetGUID().GetCounter());
- if (ffa_itr != lootPlayerFFAItems.end())
- {
- NotNormalLootItemList* ffa_list = ffa_itr->second;
- for (NotNormalLootItemList::const_iterator fi = ffa_list->begin(); fi != ffa_list->end(); ++fi)
- {
- const LootItem &item = items[fi->index];
- if (!fi->is_looted && !item.is_looted)
- return true;
- }
- }
-
- NotNormalLootItemMap const& lootPlayerNonQuestNonFFAConditionalItems = GetPlayerNonQuestNonFFAConditionalItems();
- NotNormalLootItemMap::const_iterator nn_itr = lootPlayerNonQuestNonFFAConditionalItems.find(player->GetGUID().GetCounter());
- if (nn_itr != lootPlayerNonQuestNonFFAConditionalItems.end())
- {
- NotNormalLootItemList* conditional_list = nn_itr->second;
- for (NotNormalLootItemList::const_iterator ci = conditional_list->begin(); ci != conditional_list->end(); ++ci)
- {
- const LootItem &item = items[ci->index];
- if (!ci->is_looted && !item.is_looted)
- return true;
- }
- }
-
- return false;
-}
-
-// return true if there is any item over the group threshold (i.e. not underthreshold).
-bool Loot::hasOverThresholdItem() const
-{
- for (uint8 i = 0; i < items.size(); ++i)
- {
- if (!items[i].is_looted && !items[i].is_underthreshold && !items[i].freeforall)
- return true;
- }
-
- return false;
-}
-
-ByteBuffer& operator<<(ByteBuffer& b, LootItem const& li)
-{
- b << uint32(li.itemid);
- b << uint32(li.count); // nr of items of this type
- b << uint32(ASSERT_NOTNULL(sObjectMgr->GetItemTemplate(li.itemid))->DisplayInfoID);
- b << uint32(li.randomSuffix);
- b << uint32(li.randomPropertyId);
- //b << uint8(0); // slot type - will send after this function call
- return b;
-}
-
-ByteBuffer& operator<<(ByteBuffer& b, LootView const& lv)
-{
- if (lv.permission == NONE_PERMISSION)
- {
- b << uint32(0); // gold
- b << uint8(0); // item count
- return b;
- }
-
- Loot &l = lv.loot;
-
- uint8 itemsShown = 0;
-
- b << uint32(l.gold); //gold
-
- size_t count_pos = b.wpos(); // pos of item count byte
- b << uint8(0); // item count placeholder
-
- switch (lv.permission)
- {
- case GROUP_PERMISSION:
- case MASTER_PERMISSION:
- case RESTRICTED_PERMISSION:
- {
- // if you are not the round-robin group looter, you can only see
- // blocked rolled items and quest items, and !ffa items
- for (uint8 i = 0; i < l.items.size(); ++i)
- {
- if (!l.items[i].is_looted && !l.items[i].freeforall && l.items[i].conditions.empty() && l.items[i].AllowedForPlayer(lv.viewer))
- {
- uint8 slot_type;
-
- if (l.items[i].is_blocked) // for ML & restricted is_blocked = !is_underthreshold
- {
- switch (lv.permission)
- {
- case GROUP_PERMISSION:
- slot_type = LOOT_SLOT_TYPE_ROLL_ONGOING;
- break;
- case MASTER_PERMISSION:
- {
- if (lv.viewer->GetGroup() && lv.viewer->GetGroup()->GetMasterLooterGuid() == lv.viewer->GetGUID())
- slot_type = LOOT_SLOT_TYPE_MASTER;
- else
- slot_type = LOOT_SLOT_TYPE_LOCKED;
- break;
- }
- case RESTRICTED_PERMISSION:
- slot_type = LOOT_SLOT_TYPE_LOCKED;
- break;
- default:
- continue;
- }
- }
- else if (!l.items[i].rollWinnerGUID.IsEmpty())
- {
- if (l.items[i].rollWinnerGUID == lv.viewer->GetGUID())
- slot_type = LOOT_SLOT_TYPE_OWNER;
- else
- continue;
- }
- else if (l.roundRobinPlayer.IsEmpty() || lv.viewer->GetGUID() == l.roundRobinPlayer || !l.items[i].is_underthreshold)
- {
- // no round robin owner or he has released the loot
- // or it IS the round robin group owner
- // => item is lootable
- slot_type = LOOT_SLOT_TYPE_ALLOW_LOOT;
- }
- else
- // item shall not be displayed.
- continue;
-
- b << uint8(i) << l.items[i];
- b << uint8(slot_type);
- ++itemsShown;
- }
- }
- break;
- }
- case ROUND_ROBIN_PERMISSION:
- {
- for (uint8 i = 0; i < l.items.size(); ++i)
- {
- if (!l.items[i].is_looted && !l.items[i].freeforall && l.items[i].conditions.empty() && l.items[i].AllowedForPlayer(lv.viewer))
- {
- if (!l.roundRobinPlayer.IsEmpty() && lv.viewer->GetGUID() != l.roundRobinPlayer)
- // item shall not be displayed.
- continue;
-
- b << uint8(i) << l.items[i];
- b << uint8(LOOT_SLOT_TYPE_ALLOW_LOOT);
- ++itemsShown;
- }
- }
- break;
- }
- case ALL_PERMISSION:
- case OWNER_PERMISSION:
- {
- uint8 slot_type = lv.permission == OWNER_PERMISSION ? LOOT_SLOT_TYPE_OWNER : LOOT_SLOT_TYPE_ALLOW_LOOT;
- for (uint8 i = 0; i < l.items.size(); ++i)
- {
- if (!l.items[i].is_looted && !l.items[i].freeforall && l.items[i].conditions.empty() && l.items[i].AllowedForPlayer(lv.viewer))
- {
- b << uint8(i) << l.items[i];
- b << uint8(slot_type);
- ++itemsShown;
- }
- }
- break;
- }
- default:
- return b;
- }
-
- LootSlotType slotType = lv.permission == OWNER_PERMISSION ? LOOT_SLOT_TYPE_OWNER : LOOT_SLOT_TYPE_ALLOW_LOOT;
- NotNormalLootItemMap const& lootPlayerQuestItems = l.GetPlayerQuestItems();
- NotNormalLootItemMap::const_iterator q_itr = lootPlayerQuestItems.find(lv.viewer->GetGUID().GetCounter());
- if (q_itr != lootPlayerQuestItems.end())
- {
- NotNormalLootItemList* q_list = q_itr->second;
- for (NotNormalLootItemList::const_iterator qi = q_list->begin(); qi != q_list->end(); ++qi)
- {
- LootItem &item = l.quest_items[qi->index];
- if (!qi->is_looted && !item.is_looted)
- {
- b << uint8(l.items.size() + (qi - q_list->begin()));
- b << item;
- if (item.follow_loot_rules)
- {
- switch (lv.permission)
- {
- case MASTER_PERMISSION:
- b << uint8(LOOT_SLOT_TYPE_MASTER);
- break;
- case RESTRICTED_PERMISSION:
- b << (item.is_blocked ? uint8(LOOT_SLOT_TYPE_LOCKED) : uint8(slotType));
- break;
- case GROUP_PERMISSION:
- case ROUND_ROBIN_PERMISSION:
- if (!item.is_blocked)
- b << uint8(LOOT_SLOT_TYPE_ALLOW_LOOT);
- else
- b << uint8(LOOT_SLOT_TYPE_ROLL_ONGOING);
- break;
- default:
- b << uint8(slotType);
- break;
- }
- }
- else
- b << uint8(slotType);
- ++itemsShown;
- }
- }
- }
-
- NotNormalLootItemMap const& lootPlayerFFAItems = l.GetPlayerFFAItems();
- NotNormalLootItemMap::const_iterator ffa_itr = lootPlayerFFAItems.find(lv.viewer->GetGUID().GetCounter());
- if (ffa_itr != lootPlayerFFAItems.end())
- {
- NotNormalLootItemList* ffa_list = ffa_itr->second;
- for (NotNormalLootItemList::const_iterator fi = ffa_list->begin(); fi != ffa_list->end(); ++fi)
- {
- LootItem &item = l.items[fi->index];
- if (!fi->is_looted && !item.is_looted)
- {
- b << uint8(fi->index);
- b << item;
- b << uint8(slotType);
- ++itemsShown;
- }
- }
- }
-
- NotNormalLootItemMap const& lootPlayerNonQuestNonFFAConditionalItems = l.GetPlayerNonQuestNonFFAConditionalItems();
- NotNormalLootItemMap::const_iterator nn_itr = lootPlayerNonQuestNonFFAConditionalItems.find(lv.viewer->GetGUID().GetCounter());
- if (nn_itr != lootPlayerNonQuestNonFFAConditionalItems.end())
- {
- NotNormalLootItemList* conditional_list = nn_itr->second;
- for (NotNormalLootItemList::const_iterator ci = conditional_list->begin(); ci != conditional_list->end(); ++ci)
- {
- LootItem &item = l.items[ci->index];
- if (!ci->is_looted && !item.is_looted)
- {
- b << uint8(ci->index);
- b << item;
- switch (lv.permission)
- {
- case MASTER_PERMISSION:
- b << uint8(LOOT_SLOT_TYPE_MASTER);
- break;
- case RESTRICTED_PERMISSION:
- b << (item.is_blocked ? uint8(LOOT_SLOT_TYPE_LOCKED) : uint8(slotType));
- break;
- case GROUP_PERMISSION:
- case ROUND_ROBIN_PERMISSION:
- if (!item.is_blocked)
- b << uint8(LOOT_SLOT_TYPE_ALLOW_LOOT);
- else
- b << uint8(LOOT_SLOT_TYPE_ROLL_ONGOING);
- break;
- default:
- b << uint8(slotType);
- break;
- }
- ++itemsShown;
- }
- }
- }
-
- //update number of items shown
- b.put<uint8>(count_pos, itemsShown);
-
- return b;
-}
-
-//
// --------- LootTemplate::LootGroup ---------
//
@@ -1113,7 +399,7 @@ LootStoreItem const* LootTemplate::LootGroup::Roll(Loot& loot, uint16 lootMode)
if (!possibleLoot.empty()) // If nothing selected yet - an item is taken from equal-chanced part
return Trinity::Containers::SelectRandomContainerElement(possibleLoot);
- return NULL; // Empty drop from the group
+ return nullptr; // Empty drop from the group
}
// True if group includes at least 1 quest drop entry
@@ -1239,7 +525,7 @@ void LootTemplate::AddEntry(LootStoreItem* item)
if (item->groupid > 0 && item->reference == 0) // Group
{
if (item->groupid >= Groups.size())
- Groups.resize(item->groupid, NULL); // Adds new group the the loot template if needed
+ Groups.resize(item->groupid, nullptr); // Adds new group the the loot template if needed
if (!Groups[item->groupid - 1])
Groups[item->groupid - 1] = new LootGroup();
@@ -1249,7 +535,7 @@ void LootTemplate::AddEntry(LootStoreItem* item)
Entries.push_back(item);
}
-void LootTemplate::CopyConditions(const ConditionContainer& conditions)
+void LootTemplate::CopyConditions(ConditionContainer const& conditions)
{
for (LootStoreItemList::iterator i = Entries.begin(); i != Entries.end(); ++i)
(*i)->conditions.clear();
@@ -1572,10 +858,9 @@ void LoadLootTemplates_Fishing()
uint32 count = LootTemplates_Fishing.LoadAndCollectLootIds(lootIdSet);
// remove real entries and check existence loot
- for (uint32 i = 1; i < sAreaTableStore.GetNumRows(); ++i)
- if (AreaTableEntry const* areaEntry = sAreaTableStore.LookupEntry(i))
- if (lootIdSet.find(areaEntry->ID) != lootIdSet.end())
- lootIdSet.erase(areaEntry->ID);
+ for (AreaTableEntry const* areaTable : sAreaTableStore)
+ if (lootIdSet.find(areaTable->ID) != lootIdSet.end())
+ lootIdSet.erase(areaTable->ID);
// output error for any still listed (not referenced from appropriate table) ids
LootTemplates_Fishing.ReportUnusedIds(lootIdSet);
@@ -1819,9 +1104,7 @@ void LoadLootTemplates_Spell()
// not report about not trainable spells (optionally supported by DB)
// ignore 61756 (Northrend Inscription Research (FAST QA VERSION) for example
if (!spellInfo->HasAttribute(SPELL_ATTR0_NOT_SHAPESHIFT) || spellInfo->HasAttribute(SPELL_ATTR0_TRADESPELL))
- {
LootTemplates_Spell.ReportNonExistingId(spell_id, "Spell", spellInfo->Id);
- }
}
else
lootIdSet.erase(spell_id);