AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
SkillExtraItems.cpp File Reference
#include "SkillExtraItems.h"
#include "DatabaseEnv.h"
#include "Log.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "SpellMgr.h"
#include <map>

Go to the source code of this file.

Classes

struct  SkillPerfectItemEntry
 
struct  SkillExtraItemEntry
 

Typedefs

typedef std::map< uint32, SkillPerfectItemEntrySkillPerfectItemMap
 
typedef std::map< uint32, SkillExtraItemEntrySkillExtraItemMap
 

Functions

void LoadSkillPerfectItemTable ()
 
void LoadSkillExtraItemTable ()
 
bool CanCreatePerfectItem (Player *player, uint32 spellId, float &perfectCreateChance, uint32 &perfectItemType)
 
bool canCreateExtraItems (Player *player, uint32 spellId, float &additionalChance, int32 &newMaxOrEntry)
 

Variables

SkillPerfectItemMap SkillPerfectItemStore
 
SkillExtraItemMap SkillExtraItemStore
 

Typedef Documentation

◆ SkillExtraItemMap

◆ SkillPerfectItemMap

Function Documentation

◆ canCreateExtraItems()

bool canCreateExtraItems ( Player player,
uint32  spellId,
float &  additionalChance,
int32 newMaxOrEntry 
)
227{
228 // get the info for the specified spell
229 SkillExtraItemMap::const_iterator ret = SkillExtraItemStore.find(spellId);
230 if (ret == SkillExtraItemStore.end())
231 return false;
232
233 SkillExtraItemEntry const* specEntry = &ret->second;
234
235 // if no entry, then no extra items can be created
236 if (!specEntry)
237 return false;
238
239 // the player doesn't have the required specialization, return false
240 if (!player->HasSpell(specEntry->requiredSpecialization))
241 return false;
242
243 // set the arguments to the appropriate values
244 additionalChance = specEntry->additionalCreateChance;
245 newMaxOrEntry = specEntry->newMaxOrEntry;
246
247 // enable extra item creation
248 return true;
249}
SkillExtraItemMap SkillExtraItemStore
Definition: SkillExtraItems.cpp:135
bool HasSpell(uint32 spell) const override
Definition: Player.cpp:3859
Definition: SkillExtraItems.cpp:117
uint32 requiredSpecialization
Definition: SkillExtraItems.cpp:119
float additionalCreateChance
Definition: SkillExtraItems.cpp:121
int32 newMaxOrEntry
Definition: SkillExtraItems.cpp:123

References SkillExtraItemEntry::additionalCreateChance, Player::HasSpell(), SkillExtraItemEntry::newMaxOrEntry, SkillExtraItemEntry::requiredSpecialization, and SkillExtraItemStore.

Referenced by Spell::DoCreateItem().

◆ CanCreatePerfectItem()

bool CanCreatePerfectItem ( Player player,
uint32  spellId,
float &  perfectCreateChance,
uint32 perfectItemType 
)
203{
204 SkillPerfectItemMap::const_iterator ret = SkillPerfectItemStore.find(spellId);
205 // no entry in DB means no perfection proc possible
206 if (ret == SkillPerfectItemStore.end())
207 return false;
208
209 SkillPerfectItemEntry const* thisEntry = &ret->second;
210 // lack of entry means no perfection proc possible
211 if (!thisEntry)
212 return false;
213
214 // if you don't have the spell needed, then no procs for you
215 if (!player->HasSpell(thisEntry->requiredSpecialization))
216 return false;
217
218 // set values as appropriate
219 perfectCreateChance = thisEntry->perfectCreateChance;
220 perfectItemType = thisEntry->perfectItemType;
221
222 // and tell the caller to start rolling the dice
223 return true;
224}
SkillPerfectItemMap SkillPerfectItemStore
Definition: SkillExtraItems.cpp:49
Definition: SkillExtraItems.cpp:32
uint32 perfectItemType
Definition: SkillExtraItems.cpp:38
float perfectCreateChance
Definition: SkillExtraItems.cpp:36
uint32 requiredSpecialization
Definition: SkillExtraItems.cpp:34

References Player::HasSpell(), SkillPerfectItemEntry::perfectCreateChance, SkillPerfectItemEntry::perfectItemType, SkillPerfectItemEntry::requiredSpecialization, and SkillPerfectItemStore.

Referenced by Spell::DoCreateItem().

◆ LoadSkillExtraItemTable()

void LoadSkillExtraItemTable ( )
139{
140 uint32 oldMSTime = getMSTime();
141
142 SkillExtraItemStore.clear(); // need for reload
143
144 // 0 1 2 3
145 QueryResult result = WorldDatabase.Query("SELECT spellId, requiredSpecialization, additionalCreateChance, additionalMaxNum FROM skill_extra_item_template");
146
147 if (!result)
148 {
149 LOG_WARN("server.loading", ">> Loaded 0 spell specialization definitions. DB table `skill_extra_item_template` is empty.");
150 LOG_INFO("server.loading", " ");
151 return;
152 }
153
154 uint32 count = 0;
155
156 do
157 {
158 Field* fields = result->Fetch();
159
160 uint32 spellId = fields[0].Get<uint32>();
161
162 if (!sSpellMgr->GetSpellInfo(spellId))
163 {
164 LOG_ERROR("sql.sql", "Skill specialization {} has non-existent spell id in `skill_extra_item_template`!", spellId);
165 continue;
166 }
167
168 uint32 requiredSpecialization = fields[1].Get<uint32>();
169 if (!sSpellMgr->GetSpellInfo(requiredSpecialization))
170 {
171 LOG_ERROR("sql.sql", "Skill specialization {} have not existed required specialization spell id {} in `skill_extra_item_template`!", spellId, requiredSpecialization);
172 continue;
173 }
174
175 float additionalCreateChance = fields[2].Get<float>();
176 if (additionalCreateChance <= 0.0f)
177 {
178 LOG_ERROR("sql.sql", "Skill specialization {} has too low additional create chance in `skill_extra_item_template`!", spellId);
179 continue;
180 }
181
182 int32 newMaxOrEntry = fields[3].Get<int32>();
183 if (!newMaxOrEntry)
184 {
185 LOG_ERROR("sql.sql", "Skill specialization {} has 0 max number of extra items in `skill_extra_item_template`!", spellId);
186 continue;
187 }
188
189 SkillExtraItemEntry& skillExtraItemEntry = SkillExtraItemStore[spellId];
190
191 skillExtraItemEntry.requiredSpecialization = requiredSpecialization;
192 skillExtraItemEntry.additionalCreateChance = additionalCreateChance;
193 skillExtraItemEntry.newMaxOrEntry = newMaxOrEntry;
194
195 ++count;
196 } while (result->NextRow());
197
198 LOG_INFO("server.loading", ">> Loaded {} spell specialization definitions in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
199 LOG_INFO("server.loading", " ");
200}
#define LOG_INFO(filterType__,...)
Definition: Log.h:164
#define LOG_ERROR(filterType__,...)
Definition: Log.h:156
#define LOG_WARN(filterType__,...)
Definition: Log.h:160
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition: Timer.h:131
uint32 getMSTime()
Definition: Timer.h:103
std::int32_t int32
Definition: Define.h:103
std::uint32_t uint32
Definition: Define.h:107
#define sSpellMgr
Definition: SpellMgr.h:825
std::shared_ptr< ResultSet > QueryResult
Definition: DatabaseEnvFwd.h:27
DatabaseWorkerPool< WorldDatabaseConnection > WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
Class used to access individual fields of database query result.
Definition: Field.h:98
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition: Field.h:112

References SkillExtraItemEntry::additionalCreateChance, Field::Get(), getMSTime(), GetMSTimeDiffToNow(), LOG_ERROR, LOG_INFO, LOG_WARN, SkillExtraItemEntry::newMaxOrEntry, SkillExtraItemEntry::requiredSpecialization, SkillExtraItemStore, sSpellMgr, and WorldDatabase.

Referenced by reload_commandscript::HandleReloadSkillExtraItemTemplateCommand(), and World::SetInitialWorldSettings().

◆ LoadSkillPerfectItemTable()

void LoadSkillPerfectItemTable ( )
53{
54 uint32 oldMSTime = getMSTime();
55
56 SkillPerfectItemStore.clear(); // reload capability
57
58 // 0 1 2 3
59 QueryResult result = WorldDatabase.Query("SELECT spellId, requiredSpecialization, perfectCreateChance, perfectItemType FROM skill_perfect_item_template");
60
61 if (!result)
62 {
63 LOG_WARN("server.loading", ">> Loaded 0 spell perfection definitions. DB table `skill_perfect_item_template` is empty.");
64 LOG_INFO("server.loading", " ");
65 return;
66 }
67
68 uint32 count = 0;
69
70 do /* fetch data and run sanity checks */
71 {
72 Field* fields = result->Fetch();
73
74 uint32 spellId = fields[0].Get<uint32>();
75
76 if (!sSpellMgr->GetSpellInfo(spellId))
77 {
78 LOG_ERROR("sql.sql", "Skill perfection data for spell {} has non-existent spell id in `skill_perfect_item_template`!", spellId);
79 continue;
80 }
81
82 uint32 requiredSpecialization = fields[1].Get<uint32>();
83 if (!sSpellMgr->GetSpellInfo(requiredSpecialization))
84 {
85 LOG_ERROR("sql.sql", "Skill perfection data for spell {} has non-existent required specialization spell id {} in `skill_perfect_item_template`!", spellId, requiredSpecialization);
86 continue;
87 }
88
89 float perfectCreateChance = fields[2].Get<float>();
90 if (perfectCreateChance <= 0.0f)
91 {
92 LOG_ERROR("sql.sql", "Skill perfection data for spell {} has impossibly low proc chance in `skill_perfect_item_template`!", spellId);
93 continue;
94 }
95
96 uint32 perfectItemType = fields[3].Get<uint32>();
97 if (!sObjectMgr->GetItemTemplate(perfectItemType))
98 {
99 LOG_ERROR("sql.sql", "Skill perfection data for spell {} references non-existent perfect item id {} in `skill_perfect_item_template`!", spellId, perfectItemType);
100 continue;
101 }
102
103 SkillPerfectItemEntry& skillPerfectItemEntry = SkillPerfectItemStore[spellId];
104
105 skillPerfectItemEntry.requiredSpecialization = requiredSpecialization;
106 skillPerfectItemEntry.perfectCreateChance = perfectCreateChance;
107 skillPerfectItemEntry.perfectItemType = perfectItemType;
108
109 ++count;
110 } while (result->NextRow());
111
112 LOG_INFO("server.loading", ">> Loaded {} spell perfection definitions in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
113 LOG_INFO("server.loading", " ");
114}
#define sObjectMgr
Definition: ObjectMgr.h:1623

References Field::Get(), getMSTime(), GetMSTimeDiffToNow(), LOG_ERROR, LOG_INFO, LOG_WARN, SkillPerfectItemEntry::perfectCreateChance, SkillPerfectItemEntry::perfectItemType, SkillPerfectItemEntry::requiredSpecialization, SkillPerfectItemStore, sObjectMgr, sSpellMgr, and WorldDatabase.

Referenced by reload_commandscript::HandleReloadSkillPerfectItemTemplateCommand(), and World::SetInitialWorldSettings().

Variable Documentation

◆ SkillExtraItemStore

SkillExtraItemMap SkillExtraItemStore

◆ SkillPerfectItemStore

SkillPerfectItemMap SkillPerfectItemStore