AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
ItemEnchantmentMgr.h File Reference
#include "Common.h"

Go to the source code of this file.

Functions

void LoadRandomEnchantmentsTable ()
 
uint32 GetItemEnchantMod (int32 entry)
 
uint32 GenerateEnchSuffixFactor (uint32 item_id)
 

Function Documentation

◆ GenerateEnchSuffixFactor()

uint32 GenerateEnchSuffixFactor ( uint32  item_id)
126{
127 ItemTemplate const* itemProto = sObjectMgr->GetItemTemplate(item_id);
128
129 if (!itemProto)
130 return 0;
131 if (!itemProto->RandomSuffix)
132 return 0;
133
134 RandomPropertiesPointsEntry const* randomProperty = sRandomPropertiesPointsStore.LookupEntry(itemProto->ItemLevel);
135 if (!randomProperty)
136 return 0;
137
138 uint32 suffixFactor;
139 switch (itemProto->InventoryType)
140 {
141 // Items of that type don`t have points
143 case INVTYPE_BAG:
144 case INVTYPE_TABARD:
145 case INVTYPE_AMMO:
146 case INVTYPE_QUIVER:
147 case INVTYPE_RELIC:
148 return 0;
149 // Select point coefficient
150 case INVTYPE_HEAD:
151 case INVTYPE_BODY:
152 case INVTYPE_CHEST:
153 case INVTYPE_LEGS:
154 case INVTYPE_2HWEAPON:
155 case INVTYPE_ROBE:
156 suffixFactor = 0;
157 break;
159 case INVTYPE_WAIST:
160 case INVTYPE_FEET:
161 case INVTYPE_HANDS:
162 case INVTYPE_TRINKET:
163 suffixFactor = 1;
164 break;
165 case INVTYPE_NECK:
166 case INVTYPE_WRISTS:
167 case INVTYPE_FINGER:
168 case INVTYPE_SHIELD:
169 case INVTYPE_CLOAK:
170 case INVTYPE_HOLDABLE:
171 suffixFactor = 2;
172 break;
173 case INVTYPE_WEAPON:
176 suffixFactor = 3;
177 break;
178 case INVTYPE_RANGED:
179 case INVTYPE_THROWN:
181 suffixFactor = 4;
182 break;
183 default:
184 return 0;
185 }
186 // Select rare/epic modifier
187 switch (itemProto->Quality)
188 {
190 return randomProperty->UncommonPropertiesPoints[suffixFactor];
192 return randomProperty->RarePropertiesPoints[suffixFactor];
194 return randomProperty->EpicPropertiesPoints[suffixFactor];
197 return 0; // not have random properties
198 default:
199 break;
200 }
201 return 0;
202}
DBCStorage< RandomPropertiesPointsEntry > sRandomPropertiesPointsStore(RandomPropertiesPointsfmt)
std::uint32_t uint32
Definition Define.h:107
@ INVTYPE_BODY
Definition ItemTemplate.h:260
@ INVTYPE_FINGER
Definition ItemTemplate.h:267
@ INVTYPE_HEAD
Definition ItemTemplate.h:257
@ INVTYPE_CLOAK
Definition ItemTemplate.h:272
@ INVTYPE_ROBE
Definition ItemTemplate.h:276
@ INVTYPE_HOLDABLE
Definition ItemTemplate.h:279
@ INVTYPE_TRINKET
Definition ItemTemplate.h:268
@ INVTYPE_RELIC
Definition ItemTemplate.h:284
@ INVTYPE_RANGED
Definition ItemTemplate.h:271
@ INVTYPE_THROWN
Definition ItemTemplate.h:281
@ INVTYPE_WAIST
Definition ItemTemplate.h:262
@ INVTYPE_RANGEDRIGHT
Definition ItemTemplate.h:282
@ INVTYPE_WRISTS
Definition ItemTemplate.h:265
@ INVTYPE_WEAPON
Definition ItemTemplate.h:269
@ INVTYPE_WEAPONMAINHAND
Definition ItemTemplate.h:277
@ INVTYPE_WEAPONOFFHAND
Definition ItemTemplate.h:278
@ INVTYPE_2HWEAPON
Definition ItemTemplate.h:273
@ INVTYPE_BAG
Definition ItemTemplate.h:274
@ INVTYPE_NECK
Definition ItemTemplate.h:258
@ INVTYPE_SHOULDERS
Definition ItemTemplate.h:259
@ INVTYPE_FEET
Definition ItemTemplate.h:264
@ INVTYPE_NON_EQUIP
Definition ItemTemplate.h:256
@ INVTYPE_AMMO
Definition ItemTemplate.h:280
@ INVTYPE_QUIVER
Definition ItemTemplate.h:283
@ INVTYPE_SHIELD
Definition ItemTemplate.h:270
@ INVTYPE_TABARD
Definition ItemTemplate.h:275
@ INVTYPE_LEGS
Definition ItemTemplate.h:263
@ INVTYPE_CHEST
Definition ItemTemplate.h:261
@ INVTYPE_HANDS
Definition ItemTemplate.h:266
#define sObjectMgr
Definition ObjectMgr.h:1636
@ ITEM_QUALITY_UNCOMMON
Definition SharedDefines.h:331
@ ITEM_QUALITY_RARE
Definition SharedDefines.h:332
@ ITEM_QUALITY_LEGENDARY
Definition SharedDefines.h:334
@ ITEM_QUALITY_ARTIFACT
Definition SharedDefines.h:335
@ ITEM_QUALITY_EPIC
Definition SharedDefines.h:333
Definition ItemTemplate.h:619
uint32 Quality
Definition ItemTemplate.h:626
uint32 ItemLevel
Definition ItemTemplate.h:635
uint32 InventoryType
Definition ItemTemplate.h:632
int32 RandomSuffix
Definition ItemTemplate.h:673
Definition DBCStructure.h:1463
uint32 EpicPropertiesPoints[5]
Definition DBCStructure.h:1466
uint32 UncommonPropertiesPoints[5]
Definition DBCStructure.h:1468
uint32 RarePropertiesPoints[5]
Definition DBCStructure.h:1467

References RandomPropertiesPointsEntry::EpicPropertiesPoints, ItemTemplate::InventoryType, INVTYPE_2HWEAPON, INVTYPE_AMMO, INVTYPE_BAG, INVTYPE_BODY, INVTYPE_CHEST, INVTYPE_CLOAK, INVTYPE_FEET, INVTYPE_FINGER, INVTYPE_HANDS, INVTYPE_HEAD, INVTYPE_HOLDABLE, INVTYPE_LEGS, INVTYPE_NECK, INVTYPE_NON_EQUIP, INVTYPE_QUIVER, INVTYPE_RANGED, INVTYPE_RANGEDRIGHT, INVTYPE_RELIC, INVTYPE_ROBE, INVTYPE_SHIELD, INVTYPE_SHOULDERS, INVTYPE_TABARD, INVTYPE_THROWN, INVTYPE_TRINKET, INVTYPE_WAIST, INVTYPE_WEAPON, INVTYPE_WEAPONMAINHAND, INVTYPE_WEAPONOFFHAND, INVTYPE_WRISTS, ITEM_QUALITY_ARTIFACT, ITEM_QUALITY_EPIC, ITEM_QUALITY_LEGENDARY, ITEM_QUALITY_RARE, ITEM_QUALITY_UNCOMMON, ItemTemplate::ItemLevel, ItemTemplate::Quality, ItemTemplate::RandomSuffix, RandomPropertiesPointsEntry::RarePropertiesPoints, sObjectMgr, sRandomPropertiesPointsStore, and RandomPropertiesPointsEntry::UncommonPropertiesPoints.

Referenced by LootItem::LootItem(), and Item::UpdateItemSuffixFactor().

◆ GetItemEnchantMod()

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

References irand(), LOG_ERROR, rand_chance(), and RandomItemEnch.

Referenced by Item::GenerateItemRandomPropertyId(), and ObjectMgr::LoadItemTemplates().

◆ LoadRandomEnchantmentsTable()

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].Get<uint32>();
65 uint32 ench = fields[1].Get<uint32>();
66 float chance = fields[2].Get<float>();
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 LOG_INFO("server.loading", ">> Loaded {} Item Enchantment Definitions in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
75 LOG_INFO("server.loading", " ");
76 }
77 else
78 {
79 LOG_WARN("server.loading", ">> Loaded 0 Item Enchantment definitions. DB table `item_enchantment_template` is empty.");
80 LOG_INFO("server.loading", " ");
81 }
82}
std::shared_ptr< ResultSet > QueryResult
Definition DatabaseEnvFwd.h:27
DatabaseWorkerPool< WorldDatabaseConnection > WorldDatabase
Accessor to the world database.
Definition DatabaseEnv.cpp:20
#define LOG_INFO(filterType__,...)
Definition Log.h:165
#define LOG_WARN(filterType__,...)
Definition Log.h:161
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition Timer.h:131
uint32 getMSTime()
Definition Timer.h:103
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
Definition ItemEnchantmentMgr.cpp:31

References Field::Get(), getMSTime(), GetMSTimeDiffToNow(), LOG_INFO, LOG_WARN, RandomItemEnch, and WorldDatabase.

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