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
333{
334 if (groupid >= 1 << 7) // it stored in 7 bit field
335 {
336 LOG_ERROR("sql.sql", "Table '{}' Entry {} Item {}: GroupId ({}) must be less {} - skipped", store.GetName(), entry, itemid, groupid, 1 << 7);
337 return false;
338 }
339
340 if (mincount == 0)
341 {
342 LOG_ERROR("sql.sql", "Table '{}' Entry {} Item {}: wrong MinCount ({}) - skipped", store.GetName(), entry, itemid, mincount);
343 return false;
344 }
345
346 if (!reference) // item (quest or non-quest) entry, maybe grouped
347 {
348 ItemTemplate const* proto = sObjectMgr->GetItemTemplate(itemid);
349 if (!proto)
350 {
351 LOG_ERROR("sql.sql", "Table '{}' Entry {} Item {}: item entry not listed in `item_template` - skipped", store.GetName(), entry, itemid);
352 return false;
353 }
354
355 if (chance == 0 && groupid == 0) // Zero chance is allowed for grouped entries only
356 {
357 LOG_ERROR("sql.sql", "Table '{}' Entry {} Item {}: equal-chanced grouped entry, but group not defined - skipped", store.GetName(), entry, itemid);
358 return false;
359 }
360
361 if (chance != 0 && chance < 0.000001f) // loot with low chance
362 {
363 LOG_ERROR("sql.sql", "Table '{}' Entry {} Item {}: low chance ({}) - skipped",
364 store.GetName(), entry, itemid, chance);
365 return false;
366 }
367
368 if (maxcount < mincount) // wrong max count
369 {
370 LOG_ERROR("sql.sql", "Table '{}' Entry {} Item {}: MaxCount ({}) less that MinCount ({}) - skipped", store.GetName(), entry, itemid, int32(maxcount), mincount);
371 return false;
372 }
373 }
374 else // if reference loot
375 {
376 if (needs_quest)
377 LOG_ERROR("sql.sql", "Table '{}' Entry {} Item {}: quest required will be ignored", store.GetName(), entry, itemid);
378 else if (chance == 0) // no chance for the reference
379 {
380 LOG_ERROR("sql.sql", "Table '{}' Entry {} Item {}: zero chance is specified for a reference, skipped", store.GetName(), entry, itemid);
381 return false;
382 }
383 }
384 return true; // Referenced template existence is checked at whole store level
385}
#define LOG_ERROR(filterType__,...)
Definition: Log.h:157
std::int32_t int32
Definition: Define.h:103
#define sObjectMgr
Definition: ObjectMgr.h:1635
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
326 float qualityModifier = pProto && rate ? sWorld->getRate(qualityToRate[pProto->Quality]) : 1.0f;
327
328 return roll_chance_f(_chance * qualityModifier);
329}
bool roll_chance_f(float chance)
Definition: Random.h:53
@ RATE_DROP_ITEM_REFERENCED
Definition: IWorld.h:446
static Rates const qualityToRate[MAX_ITEM_QUALITY]
Definition: LootMgr.cpp:33
#define sScriptMgr
Definition: ScriptMgr.h:709
#define sWorld
Definition: World.h:443
uint32 Quality
Definition: ItemTemplate.h:626

References chance.

Referenced by LootTemplate::Process().

Member Data Documentation

◆ chance

float LootStoreItem::chance

◆ conditions

ConditionList LootStoreItem::conditions

◆ groupid

◆ itemid

◆ lootmode

uint16 LootStoreItem::lootmode

◆ maxcount

◆ mincount

◆ needs_quest

◆ reference