TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
LootTemplate Class Reference

#include <LootMgr.h>

Classes

class  LootGroup
 

Public Member Functions

 LootTemplate ()
 
 ~LootTemplate ()
 
void AddEntry (LootStoreItem *item)
 
void Process (Loot &loot, bool rate, uint16 lootMode, uint8 groupId=0) const
 
void CopyConditions (const ConditionContainer &conditions)
 
void CopyConditions (LootItem *li) const
 
bool HasQuestDrop (LootTemplateMap const &store, uint8 groupId=0) const
 
bool HasQuestDropForPlayer (LootTemplateMap const &store, Player const *player, uint8 groupId=0) const
 
void Verify (LootStore const &store, uint32 Id) const
 
void CheckLootRefs (LootTemplateMap const &store, LootIdSet *ref_set) const
 
bool addConditionItem (Condition *cond)
 
bool isReference (uint32 id)
 

Private Types

typedef std::vector< LootGroup * > LootGroups
 

Private Member Functions

 LootTemplate (LootTemplate const &)
 
LootTemplateoperator= (LootTemplate const &)
 

Private Attributes

LootStoreItemList Entries
 
LootGroups Groups
 

Member Typedef Documentation

typedef std::vector<LootGroup*> LootTemplate::LootGroups
private

Constructor & Destructor Documentation

LootTemplate::LootTemplate ( )
inline
256 { }
LootTemplate::~LootTemplate ( )
1244 {
1245  for (LootStoreItemList::iterator i = Entries.begin(); i != Entries.end(); ++i)
1246  delete *i;
1247 
1248  for (size_t i = 0; i < Groups.size(); ++i)
1249  delete Groups[i];
1250 }
LootGroups Groups
Definition: LootMgr.h:279
Entries
Definition: boss_slabhide.cpp:48
LootTemplate::LootTemplate ( LootTemplate const )
private

Member Function Documentation

bool LootTemplate::addConditionItem ( Condition cond)
1445 {
1446  if (!cond || !cond->isLoaded())//should never happen, checked at loading
1447  {
1448  TC_LOG_ERROR("loot", "LootTemplate::addConditionItem: condition is null");
1449  return false;
1450  }
1451 
1452  if (!Entries.empty())
1453  {
1454  for (LootStoreItemList::iterator i = Entries.begin(); i != Entries.end(); ++i)
1455  {
1456  if ((*i)->itemid == uint32(cond->SourceEntry))
1457  {
1458  (*i)->conditions.push_back(cond);
1459  return true;
1460  }
1461  }
1462  }
1463 
1464  if (!Groups.empty())
1465  {
1466  for (LootGroups::iterator groupItr = Groups.begin(); groupItr != Groups.end(); ++groupItr)
1467  {
1468  LootGroup* group = *groupItr;
1469  if (!group)
1470  continue;
1471 
1472  LootStoreItemList* itemList = group->GetExplicitlyChancedItemList();
1473  if (!itemList->empty())
1474  {
1475  for (LootStoreItemList::iterator i = itemList->begin(); i != itemList->end(); ++i)
1476  {
1477  if ((*i)->itemid == uint32(cond->SourceEntry))
1478  {
1479  (*i)->conditions.push_back(cond);
1480  return true;
1481  }
1482  }
1483  }
1484 
1485  itemList = group->GetEqualChancedItemList();
1486  if (!itemList->empty())
1487  {
1488  for (LootStoreItemList::iterator i = itemList->begin(); i != itemList->end(); ++i)
1489  {
1490  if ((*i)->itemid == uint32(cond->SourceEntry))
1491  {
1492  (*i)->conditions.push_back(cond);
1493  return true;
1494  }
1495  }
1496  }
1497  }
1498  }
1499  return false;
1500 }
std::list< LootStoreItem * > LootStoreItemList
Definition: LootMgr.h:208
LootGroups Groups
Definition: LootMgr.h:279
int32 SourceEntry
Definition: ConditionMgr.h:198
Entries
Definition: boss_slabhide.cpp:48
bool isLoaded() const
Definition: ConditionMgr.h:233
uint32_t uint32
Definition: Define.h:150
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void LootTemplate::AddEntry ( LootStoreItem item)
1254 {
1255  if (item->groupid > 0 && item->reference == 0) // Group
1256  {
1257  if (item->groupid >= Groups.size())
1258  Groups.resize(item->groupid, NULL); // Adds new group the the loot template if needed
1259  if (!Groups[item->groupid - 1])
1260  Groups[item->groupid - 1] = new LootGroup();
1261 
1262  Groups[item->groupid - 1]->AddEntry(item); // Adds new entry to the group
1263  }
1264  else // Non-grouped entries and references are stored together
1265  Entries.push_back(item);
1266 }
LootGroups Groups
Definition: LootMgr.h:279
arena_t NULL
Definition: jemalloc_internal.h:624
Entries
Definition: boss_slabhide.cpp:48
uint8 groupid
Definition: LootMgr.h:141
uint32 reference
Definition: LootMgr.h:137
void LootTemplate::CheckLootRefs ( LootTemplateMap const store,
LootIdSet ref_set 
) const
1426 {
1427  for (LootStoreItemList::const_iterator ieItr = Entries.begin(); ieItr != Entries.end(); ++ieItr)
1428  {
1429  LootStoreItem* item = *ieItr;
1430  if (item->reference > 0)
1431  {
1433  LootTemplates_Reference.ReportNonExistingId(item->reference, "Reference", item->itemid);
1434  else if (ref_set)
1435  ref_set->erase(item->reference);
1436  }
1437  }
1438 
1439  for (LootGroups::const_iterator grItr = Groups.begin(); grItr != Groups.end(); ++grItr)
1440  if (LootGroup* group = *grItr)
1441  group->CheckLootRefs(store, ref_set);
1442 }
Definition: LootMgr.h:134
LootGroups Groups
Definition: LootMgr.h:279
uint32 itemid
Definition: LootMgr.h:136
Entries
Definition: boss_slabhide.cpp:48
LootTemplate const * GetLootFor(uint32 loot_id) const
Definition: LootMgr.cpp:227
void ReportNonExistingId(uint32 lootId) const
Definition: LootMgr.cpp:270
uint32 reference
Definition: LootMgr.h:137
LootStore LootTemplates_Reference("reference_loot_template","reference id", false)

+ Here is the call graph for this function:

void LootTemplate::CopyConditions ( const ConditionContainer conditions)
1269 {
1270  for (LootStoreItemList::iterator i = Entries.begin(); i != Entries.end(); ++i)
1271  (*i)->conditions.clear();
1272 
1273  for (LootGroups::iterator i = Groups.begin(); i != Groups.end(); ++i)
1274  if (LootGroup* group = *i)
1275  group->CopyConditions(conditions);
1276 }
LootGroups Groups
Definition: LootMgr.h:279
Entries
Definition: boss_slabhide.cpp:48

+ Here is the caller graph for this function:

void LootTemplate::CopyConditions ( LootItem li) const
1279 {
1280  // Copies the conditions list from a template item to a LootItemData
1281  for (LootStoreItemList::const_iterator _iter = Entries.begin(); _iter != Entries.end(); ++_iter)
1282  {
1283  LootStoreItem* item = *_iter;
1284  if (item->itemid != li->itemid)
1285  continue;
1286 
1287  li->conditions = item->conditions;
1288  break;
1289  }
1290 }
Definition: LootMgr.h:134
uint32 itemid
Definition: LootMgr.h:136
ConditionContainer conditions
Definition: LootMgr.h:163
Entries
Definition: boss_slabhide.cpp:48
ConditionContainer conditions
Definition: LootMgr.h:144
uint32 itemid
Definition: LootMgr.h:159
bool LootTemplate::HasQuestDrop ( LootTemplateMap const store,
uint8  groupId = 0 
) const
1339 {
1340  if (groupId) // Group reference
1341  {
1342  if (groupId > Groups.size())
1343  return false; // Error message [should be] already printed at loading stage
1344 
1345  if (!Groups[groupId - 1])
1346  return false;
1347 
1348  return Groups[groupId-1]->HasQuestDrop();
1349  }
1350 
1351  for (LootStoreItemList::const_iterator i = Entries.begin(); i != Entries.end(); ++i)
1352  {
1353  LootStoreItem* item = *i;
1354  if (item->reference > 0) // References
1355  {
1356  LootTemplateMap::const_iterator Referenced = store.find(item->reference);
1357  if (Referenced == store.end())
1358  continue; // Error message [should be] already printed at loading stage
1359  if (Referenced->second->HasQuestDrop(store, item->groupid))
1360  return true;
1361  }
1362  else if (item->needs_quest)
1363  return true; // quest drop found
1364  }
1365 
1366  // Now processing groups
1367  for (LootGroups::const_iterator i = Groups.begin(); i != Groups.end(); ++i)
1368  if (LootGroup* group = *i)
1369  if (group->HasQuestDrop())
1370  return true;
1371 
1372  return false;
1373 }
Definition: LootMgr.h:134
LootGroups Groups
Definition: LootMgr.h:279
Entries
Definition: boss_slabhide.cpp:48
uint8 groupid
Definition: LootMgr.h:141
bool needs_quest
Definition: LootMgr.h:140
uint32 reference
Definition: LootMgr.h:137
bool LootTemplate::HasQuestDropForPlayer ( LootTemplateMap const store,
Player const player,
uint8  groupId = 0 
) const
1377 {
1378  if (groupId) // Group reference
1379  {
1380  if (groupId > Groups.size())
1381  return false; // Error message already printed at loading stage
1382 
1383  if (!Groups[groupId - 1])
1384  return false;
1385 
1386  return Groups[groupId - 1]->HasQuestDropForPlayer(player);
1387  }
1388 
1389  // Checking non-grouped entries
1390  for (LootStoreItemList::const_iterator i = Entries.begin(); i != Entries.end(); ++i)
1391  {
1392  LootStoreItem* item = *i;
1393  if (item->reference > 0) // References processing
1394  {
1395  LootTemplateMap::const_iterator Referenced = store.find(item->reference);
1396  if (Referenced == store.end())
1397  continue; // Error message already printed at loading stage
1398  if (Referenced->second->HasQuestDropForPlayer(store, player, item->groupid))
1399  return true;
1400  }
1401  else if (player->HasQuestForItem(item->itemid))
1402  return true; // active quest drop found
1403  }
1404 
1405  // Now checking groups
1406  for (LootGroups::const_iterator i = Groups.begin(); i != Groups.end(); ++i)
1407  if (LootGroup* group = *i)
1408  if (group->HasQuestDropForPlayer(player))
1409  return true;
1410 
1411  return false;
1412 }
Definition: LootMgr.h:134
LootGroups Groups
Definition: LootMgr.h:279
uint32 itemid
Definition: LootMgr.h:136
Entries
Definition: boss_slabhide.cpp:48
uint8 groupid
Definition: LootMgr.h:141
uint32 reference
Definition: LootMgr.h:137
bool LootTemplate::isReference ( uint32  id)
1503 {
1504  for (LootStoreItemList::const_iterator ieItr = Entries.begin(); ieItr != Entries.end(); ++ieItr)
1505  if ((*ieItr)->itemid == id && (*ieItr)->reference > 0)
1506  return true;
1507 
1508  return false;//not found or not reference
1509 }
Entries
Definition: boss_slabhide.cpp:48

+ Here is the caller graph for this function:

LootTemplate& LootTemplate::operator= ( LootTemplate const )
private
void LootTemplate::Process ( Loot loot,
bool  rate,
uint16  lootMode,
uint8  groupId = 0 
) const
1294 {
1295  if (groupId) // Group reference uses own processing of the group
1296  {
1297  if (groupId > Groups.size())
1298  return; // Error message already printed at loading stage
1299 
1300  if (!Groups[groupId - 1])
1301  return;
1302 
1303  Groups[groupId - 1]->Process(loot, lootMode);
1304  return;
1305  }
1306 
1307  // Rolling non-grouped items
1308  for (LootStoreItemList::const_iterator i = Entries.begin(); i != Entries.end(); ++i)
1309  {
1310  LootStoreItem* item = *i;
1311  if (!(item->lootmode & lootMode)) // Do not add if mode mismatch
1312  continue;
1313 
1314  if (!item->Roll(rate))
1315  continue; // Bad luck for the entry
1316 
1317  if (item->reference > 0) // References processing
1318  {
1319  LootTemplate const* Referenced = LootTemplates_Reference.GetLootFor(item->reference);
1320  if (!Referenced)
1321  continue; // Error message already printed at loading stage
1322 
1323  uint32 maxcount = uint32(float(item->maxcount) * sWorld->getRate(RATE_DROP_ITEM_REFERENCED_AMOUNT));
1324  for (uint32 loop = 0; loop < maxcount; ++loop) // Ref multiplicator
1325  Referenced->Process(loot, rate, lootMode, item->groupid);
1326  }
1327  else // Plain entries (not a reference, not grouped)
1328  loot.AddItem(*item); // Chance is already checked, just add
1329  }
1330 
1331  // Now processing groups
1332  for (LootGroups::const_iterator i = Groups.begin(); i != Groups.end(); ++i)
1333  if (LootGroup* group = *i)
1334  group->Process(loot, lootMode);
1335 }
bool Roll(bool rate) const
Definition: LootMgr.cpp:286
uint8 maxcount
Definition: LootMgr.h:143
Definition: LootMgr.h:134
uint16 lootmode
Definition: LootMgr.h:139
LootGroups Groups
Definition: LootMgr.h:279
void Process(Loot &loot, bool rate, uint16 lootMode, uint8 groupId=0) const
Definition: LootMgr.cpp:1293
Entries
Definition: boss_slabhide.cpp:48
uint8 groupid
Definition: LootMgr.h:141
#define sWorld
Definition: World.h:887
Definition: World.h:400
LootTemplate const * GetLootFor(uint32 loot_id) const
Definition: LootMgr.cpp:227
uint32_t uint32
Definition: Define.h:150
void AddItem(LootStoreItem const &item)
Definition: LootMgr.cpp:416
Definition: LootMgr.h:250
uint32_t uint32
Definition: g3dmath.h:168
uint32 reference
Definition: LootMgr.h:137
LootStore LootTemplates_Reference("reference_loot_template","reference id", false)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void LootTemplate::Verify ( LootStore const store,
uint32  Id 
) const
Todo:
References validity checks
1416 {
1417  // Checking group chances
1418  for (uint32 i = 0; i < Groups.size(); ++i)
1419  if (Groups[i])
1420  Groups[i]->Verify(lootstore, id, i + 1);
1421 
1423 }
LootGroups Groups
Definition: LootMgr.h:279
uint32_t uint32
Definition: Define.h:150

Member Data Documentation

LootStoreItemList LootTemplate::Entries
private
LootGroups LootTemplate::Groups
private

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