OregonCore  revision fb2a440-git
Your Favourite TBC server
SkillExtraItems.h File Reference
#include "Common.h"

Go to the source code of this file.

Functions

bool canCreateExtraItems (Player *player, uint32 spellId, float &additionalChance, uint8 &additionalMax)
 
void LoadSkillExtraItemTable ()
 

Function Documentation

bool canCreateExtraItems ( Player player,
uint32  spellId,
float &  additionalChance,
uint8 additionalMax 
)

Definition at line 112 of file SkillExtraItems.cpp.

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

Referenced by Spell::DoCreateItem().

113 {
114  // get the info for the specified spell
115  SkillExtraItemMap::const_iterator ret = SkillExtraItemStore.find(spellId);
116  if (ret == SkillExtraItemStore.end())
117  return false;
118 
119  SkillExtraItemEntry const* specEntry = &ret->second;
120 
121  // if no entry, then no extra items can be created
122  if (!specEntry)
123  return false;
124 
125  // the player doesn't have the required specialization, return false
126  if (!player->HasSpell(specEntry->requiredSpecialization))
127  return false;
128 
129  // set the arguments to the appropriate values
130  additionalChance = specEntry->additionalCreateChance;
131  additionalMax = specEntry->additionalMaxNum;
132 
133  // enable extra item creation
134  return true;
135 }
SkillExtraItemMap SkillExtraItemStore
bool HasSpell(uint32 spell) const override
Definition: Player.cpp:3755
void LoadSkillExtraItemTable ( )

Definition at line 51 of file SkillExtraItems.cpp.

References SkillExtraItemEntry::additionalCreateChance, SkillExtraItemEntry::additionalMaxNum, Database::Query(), SkillExtraItemEntry::requiredSpecialization, SkillExtraItemStore, sLog, sSpellStore, and WorldDatabase.

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

52 {
53  uint32 count = 0;
54 
55  SkillExtraItemStore.clear(); // need for reload
56 
57  // 0 1 2 3
58  QueryResult_AutoPtr result = WorldDatabase.Query("SELECT spellId, requiredSpecialization, additionalCreateChance, additionalMaxNum FROM skill_extra_item_template");
59 
60  if (result)
61  {
62 
63  do
64  {
65  Field* fields = result->Fetch();
66 
67  uint32 spellId = fields[0].GetUInt32();
68 
69  if (!sSpellStore.LookupEntry(spellId))
70  {
71  sLog.outError("Skill specialization %u has non-existent spell id in skill_extra_item_template!", spellId);
72  continue;
73  }
74 
75  uint32 requiredSpecialization = fields[1].GetUInt32();
76  if (!sSpellStore.LookupEntry(requiredSpecialization))
77  {
78  sLog.outError("Skill specialization %u has invalid required specialization spell id %u in skill_extra_item_template!", spellId, requiredSpecialization);
79  continue;
80  }
81 
82  float additionalCreateChance = fields[2].GetFloat();
83  if (additionalCreateChance <= 0.0f)
84  {
85  sLog.outError("Skill specialization %u has too low additional create chance in skill_extra_item_template!", spellId);
86  continue;
87  }
88 
89  uint8 additionalMaxNum = fields[3].GetUInt8();
90  if (!additionalMaxNum)
91  {
92  sLog.outError("Skill specialization %u has 0 max number of extra items in skill_extra_item_template!", spellId);
93  continue;
94  }
95 
96  SkillExtraItemEntry& skillExtraItemEntry = SkillExtraItemStore[spellId];
97 
98  skillExtraItemEntry.requiredSpecialization = requiredSpecialization;
99  skillExtraItemEntry.additionalCreateChance = additionalCreateChance;
100  skillExtraItemEntry.additionalMaxNum = additionalMaxNum;
101 
102  ++count;
103  }
104  while (result->NextRow());
105 
106  sLog.outString(">> Loaded %u spell specialization definitions", count);
107  }
108  else
109  sLog.outString(">> Loaded 0 spell specialization definitions. DB table skill_extra_item_template is empty.");
110 }
DatabaseType WorldDatabase
Accessor to the world database.
Definition: Main.cpp:53
Definition: Field.h:24
#define sLog
Log class singleton.
Definition: Log.h:187
QueryResult_AutoPtr Query(const char *sql)
Definition: Database.cpp:383
SkillExtraItemMap SkillExtraItemStore
DBCStorage< SpellEntry > sSpellStore(SpellEntryfmt)
ACE_UINT8 uint8
Definition: Define.h:73
ACE_Refcounted_Auto_Ptr< QueryResult, ACE_Null_Mutex > QueryResult_AutoPtr
Definition: QueryResult.h:113
ACE_UINT32 uint32
Definition: Define.h:71