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

#include <LootMgr.h>

Public Member Functions

 LootStoreItem (uint32 _itemid, uint32 _reference, float _chance, bool _needs_quest, uint16 _lootmode, uint8 _groupid, uint8 _mincount, uint8 _maxcount)
 
bool Roll (bool rate) const
 
bool IsValid (LootStore const &store, uint32 entry) const
 

Public Attributes

uint32 itemid
 
uint32 reference
 
float chance
 
uint16 lootmode
 
bool needs_quest: 1
 
uint8 groupid: 7
 
uint8 mincount
 
uint8 maxcount
 
ConditionContainer conditions
 

Constructor & Destructor Documentation

LootStoreItem::LootStoreItem ( uint32  _itemid,
uint32  _reference,
float  _chance,
bool  _needs_quest,
uint16  _lootmode,
uint8  _groupid,
uint8  _mincount,
uint8  _maxcount 
)
inline
149  : itemid(_itemid), reference(_reference), chance(_chance), lootmode(_lootmode),
150  needs_quest(_needs_quest), groupid(_groupid), mincount(_mincount), maxcount(_maxcount)
151  { }
uint8 maxcount
Definition: LootMgr.h:143
float chance
Definition: LootMgr.h:138
uint16 lootmode
Definition: LootMgr.h:139
uint32 itemid
Definition: LootMgr.h:136
uint8 groupid
Definition: LootMgr.h:141
bool needs_quest
Definition: LootMgr.h:140
uint8 mincount
Definition: LootMgr.h:142
uint32 reference
Definition: LootMgr.h:137

Member Function Documentation

bool LootStoreItem::IsValid ( LootStore const store,
uint32  entry 
) const
303 {
304  if (mincount == 0)
305  {
306  TC_LOG_ERROR("sql.sql", "Table '%s' Entry %d Item %d: wrong MinCount (%d) - skipped", store.GetName(), entry, itemid, mincount);
307  return false;
308  }
309 
310  if (reference == 0) // item (quest or non-quest) entry, maybe grouped
311  {
312  ItemTemplate const* proto = sObjectMgr->GetItemTemplate(itemid);
313  if (!proto)
314  {
315  TC_LOG_ERROR("sql.sql", "Table '%s' Entry %d Item %d: item entry not listed in `item_template` - skipped", store.GetName(), entry, itemid);
316  return false;
317  }
318 
319  if (chance == 0 && groupid == 0) // Zero chance is allowed for grouped entries only
320  {
321  TC_LOG_ERROR("sql.sql", "Table '%s' Entry %d Item %d: equal-chanced grouped entry, but group not defined - skipped", store.GetName(), entry, itemid);
322  return false;
323  }
324 
325  if (chance != 0 && chance < 0.000001f) // loot with low chance
326  {
327  TC_LOG_ERROR("sql.sql", "Table '%s' Entry %d Item %d: low chance (%f) - skipped",
328  store.GetName(), entry, itemid, chance);
329  return false;
330  }
331 
332  if (maxcount < mincount) // wrong max count
333  {
334  TC_LOG_ERROR("sql.sql", "Table '%s' Entry %d Item %d: MaxCount (%u) less that MinCount (%i) - skipped", store.GetName(), entry, itemid, int32(maxcount), mincount);
335  return false;
336  }
337  }
338  else // if reference loot
339  {
340  if (needs_quest)
341  TC_LOG_ERROR("sql.sql", "Table '%s' Entry %d Item %d: quest required will be ignored", store.GetName(), entry, itemid);
342  else if (chance == 0) // no chance for the reference
343  {
344  TC_LOG_ERROR("sql.sql", "Table '%s' Entry %d Item %d: zero chance is specified for a reference, skipped", store.GetName(), entry, itemid);
345  return false;
346  }
347  }
348  return true; // Referenced template existence is checked at whole store level
349 }
uint8 maxcount
Definition: LootMgr.h:143
float chance
Definition: LootMgr.h:138
uint32 itemid
Definition: LootMgr.h:136
uint8 groupid
Definition: LootMgr.h:141
#define sObjectMgr
Definition: ObjectMgr.h:1567
bool needs_quest
Definition: LootMgr.h:140
uint8 mincount
Definition: LootMgr.h:142
Definition: ItemTemplate.h:647
int32_t int32
Definition: g3dmath.h:167
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
uint32 reference
Definition: LootMgr.h:137

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool LootStoreItem::Roll ( bool  rate) const
287 {
288  if (chance >= 100.0f)
289  return true;
290 
291  if (reference > 0) // reference case
292  return roll_chance_f(chance* (rate ? sWorld->getRate(RATE_DROP_ITEM_REFERENCED) : 1.0f));
293 
294  ItemTemplate const* pProto = sObjectMgr->GetItemTemplate(itemid);
295 
296  float qualityModifier = pProto && rate ? sWorld->getRate(qualityToRate[pProto->GetQuality()]) : 1.0f;
297 
298  return roll_chance_f(chance * qualityModifier);
299 }
float chance
Definition: LootMgr.h:138
uint32 itemid
Definition: LootMgr.h:136
#define sWorld
Definition: World.h:887
#define sObjectMgr
Definition: ObjectMgr.h:1567
Definition: World.h:399
bool roll_chance_f(float chance)
Definition: Random.h:47
static Rates const qualityToRate[MAX_ITEM_QUALITY]
Definition: LootMgr.cpp:32
Definition: ItemTemplate.h:647
uint32 reference
Definition: LootMgr.h:137
uint32 GetQuality() const
Definition: ItemTemplate.h:655

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

float LootStoreItem::chance
ConditionContainer LootStoreItem::conditions
uint8 LootStoreItem::groupid
uint32 LootStoreItem::itemid
uint16 LootStoreItem::lootmode
uint8 LootStoreItem::maxcount
uint8 LootStoreItem::mincount
bool LootStoreItem::needs_quest
uint32 LootStoreItem::reference

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