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

Public Member Functions

 LootGroup ()
 
 ~LootGroup ()
 
void AddEntry (LootStoreItem *item)
 
bool HasQuestDrop () const
 
bool HasQuestDropForPlayer (Player const *player) const
 
void Process (Loot &loot, uint16 lootMode) const
 
float RawTotalChance () const
 
float TotalChance () const
 
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
 
LootStoreItemListGetExplicitlyChancedItemList ()
 
LootStoreItemListGetEqualChancedItemList ()
 
void CopyConditions (ConditionContainer conditions)
 

Private Member Functions

LootStoreItem constRoll (Loot &loot, uint16 lootMode) const
 
 LootGroup (LootGroup const &)
 
LootGroupoperator= (LootGroup const &)
 

Private Attributes

LootStoreItemList ExplicitlyChanced
 
LootStoreItemList EqualChanced
 

Constructor & Destructor Documentation

LootTemplate::LootGroup::LootGroup ( )
inline
83 { }
LootTemplate::LootGroup::~LootGroup ( )
1082 {
1083  while (!ExplicitlyChanced.empty())
1084  {
1085  delete ExplicitlyChanced.back();
1086  ExplicitlyChanced.pop_back();
1087  }
1088 
1089  while (!EqualChanced.empty())
1090  {
1091  delete EqualChanced.back();
1092  EqualChanced.pop_back();
1093  }
1094 }
LootStoreItemList EqualChanced
Definition: LootMgr.cpp:102
LootStoreItemList ExplicitlyChanced
Definition: LootMgr.cpp:101
LootTemplate::LootGroup::LootGroup ( LootGroup const )
private

Member Function Documentation

void LootTemplate::LootGroup::AddEntry ( LootStoreItem item)
1098 {
1099  if (item->chance != 0)
1100  ExplicitlyChanced.push_back(item);
1101  else
1102  EqualChanced.push_back(item);
1103 }
LootStoreItemList EqualChanced
Definition: LootMgr.cpp:102
LootStoreItemList ExplicitlyChanced
Definition: LootMgr.cpp:101
float chance
Definition: LootMgr.h:138
void LootTemplate::LootGroup::CheckLootRefs ( LootTemplateMap const store,
LootIdSet ref_set 
) const
1213 {
1214  for (LootStoreItemList::const_iterator ieItr = ExplicitlyChanced.begin(); ieItr != ExplicitlyChanced.end(); ++ieItr)
1215  {
1216  LootStoreItem* item = *ieItr;
1217  if (item->reference > 0)
1218  {
1220  LootTemplates_Reference.ReportNonExistingId(item->reference, "Reference", item->itemid);
1221  else if (ref_set)
1222  ref_set->erase(item->reference);
1223  }
1224  }
1225 
1226  for (LootStoreItemList::const_iterator ieItr = EqualChanced.begin(); ieItr != EqualChanced.end(); ++ieItr)
1227  {
1228  LootStoreItem* item = *ieItr;
1229  if (item->reference > 0)
1230  {
1232  LootTemplates_Reference.ReportNonExistingId(item->reference, "Reference", item->itemid);
1233  else if (ref_set)
1234  ref_set->erase(item->reference);
1235  }
1236  }
1237 }
LootStoreItemList EqualChanced
Definition: LootMgr.cpp:102
Definition: LootMgr.h:134
LootStoreItemList ExplicitlyChanced
Definition: LootMgr.cpp:101
uint32 itemid
Definition: LootMgr.h:136
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::LootGroup::CollectLootIds ( LootIdSet set) const
void LootTemplate::LootGroup::CopyConditions ( ConditionContainer  conditions)
1164 {
1165  for (LootStoreItemList::iterator i = ExplicitlyChanced.begin(); i != ExplicitlyChanced.end(); ++i)
1166  (*i)->conditions.clear();
1167 
1168  for (LootStoreItemList::iterator i = EqualChanced.begin(); i != EqualChanced.end(); ++i)
1169  (*i)->conditions.clear();
1170 }
LootStoreItemList EqualChanced
Definition: LootMgr.cpp:102
LootStoreItemList ExplicitlyChanced
Definition: LootMgr.cpp:101
LootStoreItemList* LootTemplate::LootGroup::GetEqualChancedItemList ( )
inline
98 { return &EqualChanced; }
LootStoreItemList EqualChanced
Definition: LootMgr.cpp:102

+ Here is the caller graph for this function:

LootStoreItemList* LootTemplate::LootGroup::GetExplicitlyChancedItemList ( )
inline
97 { return &ExplicitlyChanced; }
LootStoreItemList ExplicitlyChanced
Definition: LootMgr.cpp:101

+ Here is the caller graph for this function:

bool LootTemplate::LootGroup::HasQuestDrop ( ) const
1137 {
1138  for (LootStoreItemList::const_iterator i = ExplicitlyChanced.begin(); i != ExplicitlyChanced.end(); ++i)
1139  if ((*i)->needs_quest)
1140  return true;
1141 
1142  for (LootStoreItemList::const_iterator i = EqualChanced.begin(); i != EqualChanced.end(); ++i)
1143  if ((*i)->needs_quest)
1144  return true;
1145 
1146  return false;
1147 }
LootStoreItemList EqualChanced
Definition: LootMgr.cpp:102
LootStoreItemList ExplicitlyChanced
Definition: LootMgr.cpp:101
bool LootTemplate::LootGroup::HasQuestDropForPlayer ( Player const player) const
1151 {
1152  for (LootStoreItemList::const_iterator i = ExplicitlyChanced.begin(); i != ExplicitlyChanced.end(); ++i)
1153  if (player->HasQuestForItem((*i)->itemid))
1154  return true;
1155 
1156  for (LootStoreItemList::const_iterator i = EqualChanced.begin(); i != EqualChanced.end(); ++i)
1157  if (player->HasQuestForItem((*i)->itemid))
1158  return true;
1159 
1160  return false;
1161 }
LootStoreItemList EqualChanced
Definition: LootMgr.cpp:102
LootStoreItemList ExplicitlyChanced
Definition: LootMgr.cpp:101
LootGroup& LootTemplate::LootGroup::operator= ( LootGroup const )
private
void LootTemplate::LootGroup::Process ( Loot loot,
uint16  lootMode 
) const
1174 {
1175  if (LootStoreItem const* item = Roll(loot, lootMode))
1176  loot.AddItem(*item);
1177 }
Definition: LootMgr.h:134
LootStoreItem const * Roll(Loot &loot, uint16 lootMode) const
Definition: LootMgr.cpp:1106
void AddItem(LootStoreItem const &item)
Definition: LootMgr.cpp:416

+ Here is the call graph for this function:

float LootTemplate::LootGroup::RawTotalChance ( ) const
1181 {
1182  float result = 0;
1183 
1184  for (LootStoreItemList::const_iterator i=ExplicitlyChanced.begin(); i != ExplicitlyChanced.end(); ++i)
1185  if (!(*i)->needs_quest)
1186  result += (*i)->chance;
1187 
1188  return result;
1189 }
LootStoreItemList ExplicitlyChanced
Definition: LootMgr.cpp:101
LootStoreItem const * LootTemplate::LootGroup::Roll ( Loot loot,
uint16  lootMode 
) const
private
1107 {
1108  LootStoreItemList possibleLoot = ExplicitlyChanced;
1109  possibleLoot.remove_if(LootGroupInvalidSelector(loot, lootMode));
1110 
1111  if (!possibleLoot.empty()) // First explicitly chanced entries are checked
1112  {
1113  float roll = (float)rand_chance();
1114 
1115  for (LootStoreItemList::const_iterator itr = possibleLoot.begin(); itr != possibleLoot.end(); ++itr) // check each explicitly chanced entry in the template and modify its chance based on quality.
1116  {
1117  LootStoreItem* item = *itr;
1118  if (item->chance >= 100.0f)
1119  return item;
1120 
1121  roll -= item->chance;
1122  if (roll < 0)
1123  return item;
1124  }
1125  }
1126 
1127  possibleLoot = EqualChanced;
1128  possibleLoot.remove_if(LootGroupInvalidSelector(loot, lootMode));
1129  if (!possibleLoot.empty()) // If nothing selected yet - an item is taken from equal-chanced part
1131 
1132  return NULL; // Empty drop from the group
1133 }
LootStoreItemList EqualChanced
Definition: LootMgr.cpp:102
C::value_type const & SelectRandomContainerElement(C const &container)
Definition: Containers.h:68
Definition: LootMgr.h:134
std::list< LootStoreItem * > LootStoreItemList
Definition: LootMgr.h:208
Definition: LootMgr.cpp:57
LootStoreItemList ExplicitlyChanced
Definition: LootMgr.cpp:101
float chance
Definition: LootMgr.h:138
arena_t NULL
Definition: jemalloc_internal.h:624
double rand_chance()
Definition: Random.cpp:74

+ Here is the call graph for this function:

float LootTemplate::LootGroup::TotalChance ( ) const
1193 {
1194  float result = RawTotalChance();
1195 
1196  if (!EqualChanced.empty() && result < 100.0f)
1197  return 100.0f;
1198 
1199  return result;
1200 }
LootStoreItemList EqualChanced
Definition: LootMgr.cpp:102
float RawTotalChance() const
Definition: LootMgr.cpp:1180
void LootTemplate::LootGroup::Verify ( LootStore const lootstore,
uint32  id,
uint8  group_id 
) const
Todo:
replace with 100% when DBs will be ready
1203 {
1204  float chance = RawTotalChance();
1205  if (chance > 101.0f)
1206  TC_LOG_ERROR("sql.sql", "Table '%s' entry %u group %d has total chance > 100%% (%f)", lootstore.GetName(), id, group_id, chance);
1207 
1208  if (chance >= 100.0f && !EqualChanced.empty())
1209  TC_LOG_ERROR("sql.sql", "Table '%s' entry %u group %d has items with chance=0%% but group total chance >= 100%% (%f)", lootstore.GetName(), id, group_id, chance);
1210 }
LootStoreItemList EqualChanced
Definition: LootMgr.cpp:102
float RawTotalChance() const
Definition: LootMgr.cpp:1180
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207

+ Here is the call graph for this function:

Member Data Documentation

LootStoreItemList LootTemplate::LootGroup::EqualChanced
private
LootStoreItemList LootTemplate::LootGroup::ExplicitlyChanced
private

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