AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
LootStoreItem Struct Reference

#include "LootMgr.h"

Public Member Functions

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

Public Attributes

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

Detailed Description

Constructor & Destructor Documentation

◆ LootStoreItem()

LootStoreItem::LootStoreItem ( uint32  _itemid,
int32  _reference,
float  _chance,
bool  _needs_quest,
uint16  _lootmode,
uint8  _groupid,
int32  _mincount,
uint8  _maxcount 
)
inline
142 : itemid(_itemid), reference(_reference), chance(_chance), needs_quest(_needs_quest),
143 lootmode(_lootmode), groupid(_groupid), mincount(_mincount), maxcount(_maxcount)
144 {}
float chance
Definition LootMgr.h:131
int32 reference
Definition LootMgr.h:130
bool needs_quest
Definition LootMgr.h:132
uint32 itemid
Definition LootMgr.h:129
uint8 maxcount
Definition LootMgr.h:136
uint16 lootmode
Definition LootMgr.h:133
uint8 groupid
Definition LootMgr.h:134
uint8 mincount
Definition LootMgr.h:135

Member Function Documentation

◆ IsValid()

bool LootStoreItem::IsValid ( LootStore const &  store,
uint32  entry 
) const
334{
335 if (groupid >= 1 << 7) // it stored in 7 bit field
336 {
337 LOG_ERROR("sql.sql", "Table '{}' Entry {} Item {}: GroupId ({}) must be less {} - skipped", store.GetName(), entry, itemid, groupid, 1 << 7);
338 return false;
339 }
340
341 if (mincount == 0)
342 {
343 LOG_ERROR("sql.sql", "Table '{}' Entry {} Item {}: wrong MinCount ({}) - skipped", store.GetName(), entry, itemid, mincount);
344 return false;
345 }
346
347 if (!reference) // item (quest or non-quest) entry, maybe grouped
348 {
349 ItemTemplate const* proto = sObjectMgr->GetItemTemplate(itemid);
350 if (!proto)
351 {
352 LOG_ERROR("sql.sql", "Table '{}' Entry {} Item {}: item entry not listed in `item_template` - skipped", store.GetName(), entry, itemid);
353 return false;
354 }
355
356 if (chance == 0 && groupid == 0) // Zero chance is allowed for grouped entries only
357 {
358 LOG_ERROR("sql.sql", "Table '{}' Entry {} Item {}: equal-chanced grouped entry, but group not defined - skipped", store.GetName(), entry, itemid);
359 return false;
360 }
361
362 if (chance != 0 && chance < 0.000001f) // loot with low chance
363 {
364 LOG_ERROR("sql.sql", "Table '{}' Entry {} Item {}: low chance ({}) - skipped",
365 store.GetName(), entry, itemid, chance);
366 return false;
367 }
368
369 if (maxcount < mincount) // wrong max count
370 {
371 LOG_ERROR("sql.sql", "Table '{}' Entry {} Item {}: MaxCount ({}) less that MinCount ({}) - skipped", store.GetName(), entry, itemid, int32(maxcount), mincount);
372 return false;
373 }
374 }
375 else // if reference loot
376 {
377 if (needs_quest)
378 LOG_ERROR("sql.sql", "Table '{}' Entry {} Item {}: quest required will be ignored", store.GetName(), entry, itemid);
379 else if (chance == 0) // no chance for the reference
380 {
381 LOG_ERROR("sql.sql", "Table '{}' Entry {} Item {}: zero chance is specified for a reference, skipped", store.GetName(), entry, itemid);
382 return false;
383 }
384 }
385 return true; // Referenced template existence is checked at whole store level
386}
std::int32_t int32
Definition Define.h:103
#define LOG_ERROR(filterType__,...)
Definition Log.h:158
#define sObjectMgr
Definition ObjectMgr.h:1650
Definition ItemTemplate.h:619

References chance, LootStore::GetName(), groupid, itemid, LOG_ERROR, maxcount, mincount, needs_quest, reference, and sObjectMgr.

Referenced by LootStore::LoadLootTable().

◆ Roll()

bool LootStoreItem::Roll ( bool  rate,
Player const *  player,
Loot loot,
LootStore const &  store 
) const
312{
313 float _chance = chance;
314
315 if (!sScriptMgr->OnItemRoll(player, this, _chance, loot, store))
316 return false;
317
318 if (_chance >= 100.0f)
319 return true;
320
321 if (reference) // reference case
322 return roll_chance_f(_chance * (rate ? sWorld->getRate(RATE_DROP_ITEM_REFERENCED) : 1.0f));
323
324 ItemTemplate const* pProto = sObjectMgr->GetItemTemplate(itemid);
325 float qualityModifier = 1.0f;
326 if (pProto && pProto->Quality < ITEM_QUALITY_HEIRLOOM && rate)
327 qualityModifier = sWorld->getRate(qualityToRate[pProto->Quality]);
328
329 return roll_chance_f(_chance * qualityModifier);
330}
ServerConfigs const qualityToRate[]
Definition LootMgr.cpp:33
bool roll_chance_f(float chance)
Definition Random.h:57
#define sScriptMgr
Definition ScriptMgr.h:727
@ ITEM_QUALITY_HEIRLOOM
Definition SharedDefines.h:336
@ RATE_DROP_ITEM_REFERENCED
Definition WorldConfig.h:398
#define sWorld
Definition World.h:320
uint32 Quality
Definition ItemTemplate.h:626

References chance.

Referenced by LootTemplate::Process().

Member Data Documentation

◆ chance

float LootStoreItem::chance

◆ conditions

◆ groupid

◆ itemid

◆ lootmode

uint16 LootStoreItem::lootmode

◆ maxcount

◆ mincount

◆ needs_quest

◆ reference


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