TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ItemEnchantmentMgr.cpp File Reference
#include "ItemEnchantmentMgr.h"
#include "DatabaseEnv.h"
#include "Log.h"
#include "ObjectMgr.h"
#include "Util.h"
#include "DBCStores.h"
#include <list>
#include <vector>
#include <stdlib.h>
+ Include dependency graph for ItemEnchantmentMgr.cpp:

Classes

struct  EnchStoreItem
 

Typedefs

typedef std::vector
< EnchStoreItem
EnchStoreList
 
typedef std::unordered_map
< uint32, EnchStoreList
EnchantmentStore
 

Functions

TC_GAME_API void LoadRandomEnchantmentsTable ()
 
TC_GAME_API uint32 GetItemEnchantMod (int32 entry)
 
TC_GAME_API uint32 GenerateEnchSuffixFactor (uint32 item_id)
 
TC_GAME_API uint32 GetRandomPropertyPoints (uint32 itemLevel, uint32 quality, uint32 inventoryType, uint32 subClass)
 

Variables

static EnchantmentStore RandomItemEnch
 

Typedef Documentation

typedef std::unordered_map<uint32, EnchStoreList> EnchantmentStore
typedef std::vector<EnchStoreItem> EnchStoreList

Function Documentation

TC_GAME_API uint32 GenerateEnchSuffixFactor ( uint32  item_id)
122 {
123  ItemTemplate const* itemProto = sObjectMgr->GetItemTemplate(item_id);
124 
125  if (!itemProto)
126  return 0;
127  if (!itemProto->GetRandomSuffix())
128  return 0;
129 
130  return GetRandomPropertyPoints(itemProto->GetBaseItemLevel(), itemProto->GetQuality(), itemProto->GetInventoryType(), itemProto->GetSubClass());
131 }
uint32 GetBaseItemLevel() const
Definition: ItemTemplate.h:667
uint32 GetRandomSuffix() const
Definition: ItemTemplate.h:689
#define sObjectMgr
Definition: ObjectMgr.h:1567
InventoryType GetInventoryType() const
Definition: ItemTemplate.h:664
Definition: ItemTemplate.h:647
uint32 GetSubClass() const
Definition: ItemTemplate.h:654
TC_GAME_API uint32 GetRandomPropertyPoints(uint32 itemLevel, uint32 quality, uint32 inventoryType, uint32 subClass)
Definition: ItemEnchantmentMgr.cpp:133
uint32 GetQuality() const
Definition: ItemTemplate.h:655

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

TC_GAME_API uint32 GetItemEnchantMod ( int32  entry)
81 {
82  if (!entry)
83  return 0;
84 
85  if (entry == -1)
86  return 0;
87 
88  EnchantmentStore::const_iterator tab = RandomItemEnch.find(entry);
89  if (tab == RandomItemEnch.end())
90  {
91  TC_LOG_ERROR("sql.sql", "Item RandomProperty / RandomSuffix id #%u used in `item_template` but it does not have records in `item_enchantment_template` table.", entry);
92  return 0;
93  }
94 
95  double dRoll = rand_chance();
96  float fCount = 0;
97 
98  for (EnchStoreList::const_iterator ench_iter = tab->second.begin(); ench_iter != tab->second.end(); ++ench_iter)
99  {
100  fCount += ench_iter->chance;
101 
102  if (fCount > dRoll)
103  return ench_iter->ench;
104  }
105 
106  //we could get here only if sum of all enchantment chances is lower than 100%
107  dRoll = (irand(0, (int)floor(fCount * 100) + 1)) / 100;
108  fCount = 0;
109 
110  for (EnchStoreList::const_iterator ench_iter = tab->second.begin(); ench_iter != tab->second.end(); ++ench_iter)
111  {
112  fCount += ench_iter->chance;
113 
114  if (fCount > dRoll)
115  return ench_iter->ench;
116  }
117 
118  return 0;
119 }
static Vector3int16 floor(const Vector3 &v)
static EnchantmentStore RandomItemEnch
Definition: ItemEnchantmentMgr.cpp:45
double rand_chance()
Definition: Random.cpp:74
int32 irand(int32 min, int32 max)
Definition: Random.cpp:39
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

TC_GAME_API uint32 GetRandomPropertyPoints ( uint32  itemLevel,
uint32  quality,
uint32  inventoryType,
uint32  subClass 
)
134 {
135  uint32 propIndex;
136 
137  switch (inventoryType)
138  {
139  case INVTYPE_HEAD:
140  case INVTYPE_BODY:
141  case INVTYPE_CHEST:
142  case INVTYPE_LEGS:
143  case INVTYPE_RANGED:
144  case INVTYPE_2HWEAPON:
145  case INVTYPE_ROBE:
146  case INVTYPE_THROWN:
147  propIndex = 0;
148  break;
149  case INVTYPE_RANGEDRIGHT:
150  if (subClass == ITEM_SUBCLASS_WEAPON_WAND)
151  propIndex = 3;
152  else
153  propIndex = 0;
154  break;
155  case INVTYPE_WEAPON:
158  propIndex = 3;
159  break;
160  case INVTYPE_SHOULDERS:
161  case INVTYPE_WAIST:
162  case INVTYPE_FEET:
163  case INVTYPE_HANDS:
164  case INVTYPE_TRINKET:
165  propIndex = 1;
166  break;
167  case INVTYPE_NECK:
168  case INVTYPE_WRISTS:
169  case INVTYPE_FINGER:
170  case INVTYPE_SHIELD:
171  case INVTYPE_CLOAK:
172  case INVTYPE_HOLDABLE:
173  propIndex = 2;
174  break;
175  case INVTYPE_RELIC:
176  propIndex = 4;
177  default:
178  return 0;
179  }
180 
181  RandomPropertiesPointsEntry const* randPropPointsEntry = sRandomPropertiesPointsStore.LookupEntry(itemLevel);
182  if (!randPropPointsEntry)
183  return 0;
184 
185  switch (quality)
186  {
188  return randPropPointsEntry->UncommonPropertiesPoints[propIndex];
189  case ITEM_QUALITY_RARE:
191  return randPropPointsEntry->RarePropertiesPoints[propIndex];
192  case ITEM_QUALITY_EPIC:
194  return randPropPointsEntry->EpicPropertiesPoints[propIndex];
195  }
196 
197  return 0;
198 }
Definition: ItemTemplate.h:360
uint32 UncommonPropertiesPoints[5]
Definition: DBCStructure.h:949
Definition: ItemTemplate.h:352
Definition: ItemTemplate.h:344
Definition: ItemTemplate.h:348
Definition: ItemTemplate.h:334
uint32 EpicPropertiesPoints[5]
Definition: DBCStructure.h:947
Definition: ItemTemplate.h:343
Definition: ItemTemplate.h:335
DBCStorage< RandomPropertiesPointsEntry > sRandomPropertiesPointsStore(RandPropPointsfmt)
Definition: SharedDefines.h:327
Definition: ItemTemplate.h:345
Definition: ItemTemplate.h:346
Definition: ItemTemplate.h:333
Definition: ItemTemplate.h:340
Definition: DBCStructure.h:944
Definition: ItemTemplate.h:354
Definition: ItemTemplate.h:347
uint32_t uint32
Definition: Define.h:150
Definition: ItemTemplate.h:337
Definition: SharedDefines.h:322
Definition: ItemTemplate.h:357
Definition: ItemTemplate.h:349
Definition: ItemTemplate.h:441
Definition: ItemTemplate.h:353
Definition: ItemTemplate.h:336
Definition: ItemTemplate.h:342
Definition: ItemTemplate.h:339
Definition: ItemTemplate.h:358
Definition: SharedDefines.h:323
Definition: SharedDefines.h:325
Definition: ItemTemplate.h:355
Definition: ItemTemplate.h:341
Definition: SharedDefines.h:324
Definition: ItemTemplate.h:338
uint32 RarePropertiesPoints[5]
Definition: DBCStructure.h:948

+ Here is the caller graph for this function:

TC_GAME_API void LoadRandomEnchantmentsTable ( )
48 {
49  uint32 oldMSTime = getMSTime();
50 
51  RandomItemEnch.clear(); // for reload case
52 
53  // 0 1 2
54  QueryResult result = WorldDatabase.Query("SELECT entry, ench, chance FROM item_enchantment_template");
55 
56  if (result)
57  {
58  uint32 count = 0;
59 
60  do
61  {
62  Field* fields = result->Fetch();
63 
64  uint32 entry = fields[0].GetUInt32();
65  uint32 ench = fields[1].GetUInt32();
66  float chance = fields[2].GetFloat();
67 
68  if (chance > 0.000001f && chance <= 100.0f)
69  RandomItemEnch[entry].push_back(EnchStoreItem(ench, chance));
70 
71  ++count;
72  } while (result->NextRow());
73 
74  TC_LOG_INFO("server.loading", ">> Loaded %u Item Enchantment definitions in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
75  }
76  else
77  TC_LOG_ERROR("server.loading", ">> Loaded 0 Item Enchantment definitions. DB table `item_enchantment_template` is empty.");
78 }
float GetFloat() const
Definition: Field.h:222
Class used to access individual fields of database query result.
Definition: Field.h:56
static EnchantmentStore RandomItemEnch
Definition: ItemEnchantmentMgr.cpp:45
uint32 getMSTime()
Definition: Timer.h:24
WorldDatabaseWorkerPool WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
uint32_t uint32
Definition: Define.h:150
std::shared_ptr< ResultSet > QueryResult
Definition: QueryResult.h:61
Definition: ItemEnchantmentMgr.cpp:30
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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

EnchantmentStore RandomItemEnch
static