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)
123{
124 ItemTemplate const* itemProto = sObjectMgr->GetItemTemplate(item_id);
125
126 if (!itemProto)
127 return 0;
128 if (!itemProto->RandomSuffix)
129 return 0;
130
131 RandomPropertiesPointsEntry const* randomProperty = sRandomPropertiesPointsStore.LookupEntry(itemProto->ItemLevel);
132 if (!randomProperty)
133 return 0;
134
135 uint32 suffixFactor;
136 switch (itemProto->InventoryType)
137 {
138 // Items of that type don`t have points
140 case INVTYPE_BAG:
141 case INVTYPE_TABARD:
142 case INVTYPE_AMMO:
143 case INVTYPE_QUIVER:
144 case INVTYPE_RELIC:
145 return 0;
146 // Select point coefficient
147 case INVTYPE_HEAD:
148 case INVTYPE_BODY:
149 case INVTYPE_CHEST:
150 case INVTYPE_LEGS:
151 case INVTYPE_2HWEAPON:
152 case INVTYPE_ROBE:
153 suffixFactor = 0;
154 break;
156 case INVTYPE_WAIST:
157 case INVTYPE_FEET:
158 case INVTYPE_HANDS:
159 case INVTYPE_TRINKET:
160 suffixFactor = 1;
161 break;
162 case INVTYPE_NECK:
163 case INVTYPE_WRISTS:
164 case INVTYPE_FINGER:
165 case INVTYPE_SHIELD:
166 case INVTYPE_CLOAK:
167 case INVTYPE_HOLDABLE:
168 suffixFactor = 2;
169 break;
170 case INVTYPE_WEAPON:
173 suffixFactor = 3;
174 break;
175 case INVTYPE_RANGED:
176 case INVTYPE_THROWN:
178 suffixFactor = 4;
179 break;
180 default:
181 return 0;
182 }
183 // Select rare/epic modifier
184 switch (itemProto->Quality)
185 {
187 return randomProperty->UncommonPropertiesPoints[suffixFactor];
189 return randomProperty->RarePropertiesPoints[suffixFactor];
191 return randomProperty->EpicPropertiesPoints[suffixFactor];
194 return 0; // not have random properties
195 default:
196 break;
197 }
198 return 0;
199}
std::uint32_t uint32
Definition: Define.h:108
DBCStorage< RandomPropertiesPointsEntry > sRandomPropertiesPointsStore(RandomPropertiesPointsfmt)
@ INVTYPE_BODY
Definition: ItemTemplate.h:269
@ INVTYPE_FINGER
Definition: ItemTemplate.h:276
@ INVTYPE_HEAD
Definition: ItemTemplate.h:266
@ INVTYPE_CLOAK
Definition: ItemTemplate.h:281
@ INVTYPE_ROBE
Definition: ItemTemplate.h:285
@ INVTYPE_HOLDABLE
Definition: ItemTemplate.h:288
@ INVTYPE_TRINKET
Definition: ItemTemplate.h:277
@ INVTYPE_RELIC
Definition: ItemTemplate.h:293
@ INVTYPE_RANGED
Definition: ItemTemplate.h:280
@ INVTYPE_THROWN
Definition: ItemTemplate.h:290
@ INVTYPE_WAIST
Definition: ItemTemplate.h:271
@ INVTYPE_RANGEDRIGHT
Definition: ItemTemplate.h:291
@ INVTYPE_WRISTS
Definition: ItemTemplate.h:274
@ INVTYPE_WEAPON
Definition: ItemTemplate.h:278
@ INVTYPE_WEAPONMAINHAND
Definition: ItemTemplate.h:286
@ INVTYPE_WEAPONOFFHAND
Definition: ItemTemplate.h:287
@ INVTYPE_2HWEAPON
Definition: ItemTemplate.h:282
@ INVTYPE_BAG
Definition: ItemTemplate.h:283
@ INVTYPE_NECK
Definition: ItemTemplate.h:267
@ INVTYPE_SHOULDERS
Definition: ItemTemplate.h:268
@ INVTYPE_FEET
Definition: ItemTemplate.h:273
@ INVTYPE_NON_EQUIP
Definition: ItemTemplate.h:265
@ INVTYPE_AMMO
Definition: ItemTemplate.h:289
@ INVTYPE_QUIVER
Definition: ItemTemplate.h:292
@ INVTYPE_SHIELD
Definition: ItemTemplate.h:279
@ INVTYPE_TABARD
Definition: ItemTemplate.h:284
@ INVTYPE_LEGS
Definition: ItemTemplate.h:272
@ INVTYPE_CHEST
Definition: ItemTemplate.h:270
@ INVTYPE_HANDS
Definition: ItemTemplate.h:275
#define sObjectMgr
Definition: ObjectMgr.h:1640
@ 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:628
uint32 Quality
Definition: ItemTemplate.h:635
uint32 ItemLevel
Definition: ItemTemplate.h:644
uint32 InventoryType
Definition: ItemTemplate.h:641
int32 RandomSuffix
Definition: ItemTemplate.h:682
Definition: DBCStructure.h:1462
uint32 EpicPropertiesPoints[5]
Definition: DBCStructure.h:1465
uint32 UncommonPropertiesPoints[5]
Definition: DBCStructure.h:1467
uint32 RarePropertiesPoints[5]
Definition: DBCStructure.h:1466

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

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

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

◆ LoadRandomEnchantmentsTable()

void LoadRandomEnchantmentsTable ( )
45{
46 uint32 oldMSTime = getMSTime();
47
48 RandomItemEnch.clear(); // for reload case
49
50 // 0 1 2
51 QueryResult result = WorldDatabase.Query("SELECT entry, ench, chance FROM item_enchantment_template");
52
53 if (result)
54 {
55 uint32 count = 0;
56
57 do
58 {
59 Field* fields = result->Fetch();
60
61 uint32 entry = fields[0].Get<uint32>();
62 uint32 ench = fields[1].Get<uint32>();
63 float chance = fields[2].Get<float>();
64
65 if (chance > 0.000001f && chance <= 100.0f)
66 RandomItemEnch[entry].push_back(EnchStoreItem(ench, chance));
67
68 ++count;
69 } while (result->NextRow());
70
71 LOG_INFO("server.loading", ">> Loaded {} Item Enchantment Definitions in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
72 LOG_INFO("server.loading", " ");
73 }
74 else
75 {
76 LOG_WARN("server.loading", ">> Loaded 0 Item Enchantment definitions. DB table `item_enchantment_template` is empty.");
77 LOG_INFO("server.loading", " ");
78 }
79}
#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
DatabaseWorkerPool< WorldDatabaseConnection > WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
std::shared_ptr< ResultSet > QueryResult
Definition: DatabaseEnvFwd.h:28
Class used to access individual fields of database query result.
Definition: Field.h:99
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition: Field.h:113
Definition: ItemEnchantmentMgr.cpp:28

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

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