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
143 : itemid(_itemid), reference(_reference), chance(_chance), needs_quest(_needs_quest),
144 lootmode(_lootmode), groupid(_groupid), mincount(_mincount), maxcount(_maxcount)
145 {}
float chance
Definition: LootMgr.h:132
int32 reference
Definition: LootMgr.h:131
bool needs_quest
Definition: LootMgr.h:133
uint32 itemid
Definition: LootMgr.h:130
uint8 maxcount
Definition: LootMgr.h:137
uint16 lootmode
Definition: LootMgr.h:134
uint8 groupid
Definition: LootMgr.h:135
uint8 mincount
Definition: LootMgr.h:136

Member Function Documentation

◆ IsValid()

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

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
306{
307 float _chance = chance;
308
309 if (!sScriptMgr->OnItemRoll(player, this, _chance, loot, store))
310 return false;
311
312 if (_chance >= 100.0f)
313 return true;
314
315 if (reference) // reference case
316 return roll_chance_f(_chance * (rate ? sWorld->getRate(RATE_DROP_ITEM_REFERENCED) : 1.0f));
317
318 ItemTemplate const* pProto = sObjectMgr->GetItemTemplate(itemid);
319
320 float qualityModifier = pProto && rate ? sWorld->getRate(qualityToRate[pProto->Quality]) : 1.0f;
321
322 return roll_chance_f(_chance * qualityModifier);
323}
bool roll_chance_f(float chance)
Definition: Random.h:53
static Rates const qualityToRate[MAX_ITEM_QUALITY]
Definition: LootMgr.cpp:32
#define sScriptMgr
Definition: ScriptMgr.h:2702
@ RATE_DROP_ITEM_REFERENCED
Definition: IWorld.h:437
#define sWorld
Definition: World.h:451
uint32 Quality
Definition: ItemTemplate.h:635

References chance, and sScriptMgr.

Referenced by LootTemplate::Process().

Member Data Documentation

◆ chance

float LootStoreItem::chance

◆ conditions

ConditionList LootStoreItem::conditions

◆ groupid

◆ itemid

◆ lootmode

uint16 LootStoreItem::lootmode

◆ maxcount

uint8 LootStoreItem::maxcount

◆ mincount

uint8 LootStoreItem::mincount

Referenced by Loot::AddItem(), and IsValid().

◆ needs_quest

◆ reference