TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SkillExtraItems.h File Reference
#include "Common.h"
+ Include dependency graph for SkillExtraItems.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

TC_GAME_API bool CanCreatePerfectItem (Player *player, uint32 spellId, float &perfectCreateChance, uint32 &perfectItemType)
 
TC_GAME_API void LoadSkillPerfectItemTable ()
 
TC_GAME_API bool CanCreateExtraItems (Player *player, uint32 spellId, float &additionalChance, uint8 &additionalMax)
 
TC_GAME_API void LoadSkillExtraItemTable ()
 

Function Documentation

TC_GAME_API bool CanCreateExtraItems ( Player *  player,
uint32  spellId,
float &  additionalChance,
uint8 additionalMax 
)
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  additionalMax = specEntry->additionalMaxNum;
246 
247  // enable extra item creation
248  return true;
249 }
Definition: SkillExtraItems.cpp:117
uint8 additionalMaxNum
Definition: SkillExtraItems.cpp:124
SkillExtraItemMap SkillExtraItemStore
Definition: SkillExtraItems.cpp:136
float additionalCreateChance
Definition: SkillExtraItems.cpp:122
uint32 requiredSpecialization
Definition: SkillExtraItems.cpp:120

+ Here is the caller graph for this function:

TC_GAME_API 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 }
uint32 perfectItemType
Definition: SkillExtraItems.cpp:38
float perfectCreateChance
Definition: SkillExtraItems.cpp:36
SkillPerfectItemMap SkillPerfectItemStore
Definition: SkillExtraItems.cpp:49
Definition: SkillExtraItems.cpp:31
uint32 requiredSpecialization
Definition: SkillExtraItems.cpp:34

+ Here is the caller graph for this function:

TC_GAME_API void LoadSkillExtraItemTable ( )
140 {
141  uint32 oldMSTime = getMSTime();
142 
143  SkillExtraItemStore.clear(); // need for reload
144 
145  // 0 1 2 3
146  QueryResult result = WorldDatabase.Query("SELECT spellId, requiredSpecialization, additionalCreateChance, additionalMaxNum FROM skill_extra_item_template");
147 
148  if (!result)
149  {
150  TC_LOG_ERROR("server.loading", ">> Loaded 0 spell specialization definitions. DB table `skill_extra_item_template` is empty.");
151  return;
152  }
153 
154  uint32 count = 0;
155 
156  do
157  {
158  Field* fields = result->Fetch();
159 
160  uint32 spellId = fields[0].GetUInt32();
161 
162  if (!sSpellMgr->GetSpellInfo(spellId))
163  {
164  TC_LOG_ERROR("sql.sql", "Skill specialization %u has non-existent spell id in `skill_extra_item_template`!", spellId);
165  continue;
166  }
167 
168  uint32 requiredSpecialization = fields[1].GetUInt32();
169  if (!sSpellMgr->GetSpellInfo(requiredSpecialization))
170  {
171  TC_LOG_ERROR("sql.sql", "Skill specialization %u have not existed required specialization spell id %u in `skill_extra_item_template`!", spellId, requiredSpecialization);
172  continue;
173  }
174 
175  float additionalCreateChance = fields[2].GetFloat();
176  if (additionalCreateChance <= 0.0f)
177  {
178  TC_LOG_ERROR("sql.sql", "Skill specialization %u has too low additional create chance in `skill_extra_item_template`!", spellId);
179  continue;
180  }
181 
182  uint8 additionalMaxNum = fields[3].GetUInt8();
183  if (!additionalMaxNum)
184  {
185  TC_LOG_ERROR("sql.sql", "Skill specialization %u 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.additionalMaxNum = additionalMaxNum;
194 
195  ++count;
196  }
197  while (result->NextRow());
198 
199  TC_LOG_INFO("server.loading", ">> Loaded %u spell specialization definitions in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
200 }
Definition: SkillExtraItems.cpp:117
float GetFloat() const
Definition: Field.h:222
Class used to access individual fields of database query result.
Definition: Field.h:56
uint32 getMSTime()
Definition: Timer.h:24
uint8 additionalMaxNum
Definition: SkillExtraItems.cpp:124
WorldDatabaseWorkerPool WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
SkillExtraItemMap SkillExtraItemStore
Definition: SkillExtraItems.cpp:136
float additionalCreateChance
Definition: SkillExtraItems.cpp:122
uint8 GetUInt8() const
Definition: Field.h:70
#define sSpellMgr
Definition: SpellMgr.h:756
uint32_t uint32
Definition: Define.h:150
std::shared_ptr< ResultSet > QueryResult
Definition: QueryResult.h:61
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition: Timer.h:42
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
uint32 GetUInt32() const
Definition: Field.h:146
uint8_t uint8
Definition: Define.h:152
#define TC_LOG_INFO(filterType__,...)
Definition: Log.h:201
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
uint32 requiredSpecialization
Definition: SkillExtraItems.cpp:120

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

TC_GAME_API 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  TC_LOG_ERROR("server.loading", ">> Loaded 0 spell perfection definitions. DB table `skill_perfect_item_template` is empty.");
64  return;
65  }
66 
67  uint32 count = 0;
68 
69  do /* fetch data and run sanity checks */
70  {
71  Field* fields = result->Fetch();
72 
73  uint32 spellId = fields[0].GetUInt32();
74 
75  if (!sSpellMgr->GetSpellInfo(spellId))
76  {
77  TC_LOG_ERROR("sql.sql", "Skill perfection data for spell %u has non-existent spell id in `skill_perfect_item_template`!", spellId);
78  continue;
79  }
80 
81  uint32 requiredSpecialization = fields[1].GetUInt32();
82  if (!sSpellMgr->GetSpellInfo(requiredSpecialization))
83  {
84  TC_LOG_ERROR("sql.sql", "Skill perfection data for spell %u has non-existent required specialization spell id %u in `skill_perfect_item_template`!", spellId, requiredSpecialization);
85  continue;
86  }
87 
88  float perfectCreateChance = fields[2].GetFloat();
89  if (perfectCreateChance <= 0.0f)
90  {
91  TC_LOG_ERROR("sql.sql", "Skill perfection data for spell %u has impossibly low proc chance in `skill_perfect_item_template`!", spellId);
92  continue;
93  }
94 
95  uint32 perfectItemType = fields[3].GetUInt32();
96  if (!sObjectMgr->GetItemTemplate(perfectItemType))
97  {
98  TC_LOG_ERROR("sql.sql", "Skill perfection data for spell %u references non-existent perfect item id %u in `skill_perfect_item_template`!", spellId, perfectItemType);
99  continue;
100  }
101 
102  SkillPerfectItemEntry& skillPerfectItemEntry = SkillPerfectItemStore[spellId];
103 
104  skillPerfectItemEntry.requiredSpecialization = requiredSpecialization;
105  skillPerfectItemEntry.perfectCreateChance = perfectCreateChance;
106  skillPerfectItemEntry.perfectItemType = perfectItemType;
107 
108  ++count;
109  }
110  while (result->NextRow());
111 
112  TC_LOG_INFO("server.loading", ">> Loaded %u spell perfection definitions in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
113 }
float GetFloat() const
Definition: Field.h:222
Class used to access individual fields of database query result.
Definition: Field.h:56
uint32 perfectItemType
Definition: SkillExtraItems.cpp:38
uint32 getMSTime()
Definition: Timer.h:24
WorldDatabaseWorkerPool WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
#define sObjectMgr
Definition: ObjectMgr.h:1567
float perfectCreateChance
Definition: SkillExtraItems.cpp:36
SkillPerfectItemMap SkillPerfectItemStore
Definition: SkillExtraItems.cpp:49
#define sSpellMgr
Definition: SpellMgr.h:756
uint32_t uint32
Definition: Define.h:150
std::shared_ptr< ResultSet > QueryResult
Definition: QueryResult.h:61
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition: Timer.h:42
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
uint32 GetUInt32() const
Definition: Field.h:146
#define TC_LOG_INFO(filterType__,...)
Definition: Log.h:201
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
Definition: SkillExtraItems.cpp:31
uint32 requiredSpecialization
Definition: SkillExtraItems.cpp:34

+ Here is the call graph for this function:

+ Here is the caller graph for this function: