TrinityCore
ItemTemplate.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "DB2Stores.h"
19#include "World.h"
20#include "ItemTemplate.h"
21#include "Player.h"
22
24{
25 0,
51};
52
53char const* ItemTemplate::GetName(LocaleConstant locale) const
54{
55 if (!strlen(ExtendedData->Display[locale]))
56 return GetDefaultLocaleName();
57
58 return ExtendedData->Display[locale];
59}
60
62{
63 return GetMaxStackSize() == 1 &&
67 GetId() != 6948; /*Hearthstone*/
68}
69
71{
72 switch (GetInventoryType())
73 {
74 case INVTYPE_RELIC:
75 case INVTYPE_SHIELD:
77 return true;
78 default:
79 break;
80 }
81
82 switch (GetClass())
83 {
86 return true;
87 }
88
89 return false;
90}
91
93{
94 static uint32 const itemWeaponSkills[MAX_ITEM_SUBCLASS_WEAPON] =
95 {
101 };
102
103 static uint32 const itemArmorSkills[MAX_ITEM_SUBCLASS_ARMOR] =
104 {
106 };
107
108 static uint32 const itemProfessionSkills[MAX_ITEM_SUBCLASS_PROFESSION] =
109 {
113 };
114
115 switch (GetClass())
116 {
119 return 0;
120 else
121 return itemWeaponSkills[GetSubClass()];
122 case ITEM_CLASS_ARMOR:
124 return 0;
125 else
126 return itemArmorSkills[GetSubClass()];
129 return 0;
130 else
131 return itemProfessionSkills[GetSubClass()];
132 default:
133 return 0;
134 }
135}
136
138{
139 return ExtendedData->Display[sWorld->GetDefaultDbcLocale()];
140}
141
143{
145 if (quality > ITEM_QUALITY_ARTIFACT)
146 return 0;
147
148 // all items but shields
150 {
151 ItemArmorQualityEntry const* armorQuality = sItemArmorQualityStore.LookupEntry(itemLevel);
152 ItemArmorTotalEntry const* armorTotal = sItemArmorTotalStore.LookupEntry(itemLevel);
153 if (!armorQuality || !armorTotal)
154 return 0;
155
156 uint32 inventoryType = GetInventoryType();
157 if (inventoryType == INVTYPE_ROBE)
158 inventoryType = INVTYPE_CHEST;
159
160 ArmorLocationEntry const* location = sArmorLocationStore.LookupEntry(inventoryType);
161 if (!location)
162 return 0;
163
165 return 0;
166
167 float total = 1.0f;
168 float locationModifier = 1.0f;
169 switch (GetSubClass())
170 {
172 total = armorTotal->Cloth;
173 locationModifier = location->Clothmodifier;
174 break;
176 total = armorTotal->Leather;
177 locationModifier = location->Leathermodifier;
178 break;
180 total = armorTotal->Mail;
181 locationModifier = location->Chainmodifier;
182 break;
184 total = armorTotal->Plate;
185 locationModifier = location->Platemodifier;
186 break;
187 default:
188 break;
189 }
190
191 return uint32(armorQuality->Qualitymod[quality] * total * locationModifier + 0.5f);
192 }
193
194 // shields
195 ItemArmorShieldEntry const* shield = sItemArmorShieldStore.LookupEntry(itemLevel);
196 if (!shield)
197 return 0;
198
199 return uint32(shield->Quality[quality] + 0.5f);
200}
201
202float ItemTemplate::GetDPS(uint32 itemLevel) const
203{
206 return 0.0f;
207
208 float dps = 0.0f;
209 switch (GetInventoryType())
210 {
211 case INVTYPE_AMMO:
212 dps = sItemDamageAmmoStore.AssertEntry(itemLevel)->Quality[quality];
213 break;
214 case INVTYPE_2HWEAPON:
216 dps = sItemDamageTwoHandCasterStore.AssertEntry(itemLevel)->Quality[quality];
217 else
218 dps = sItemDamageTwoHandStore.AssertEntry(itemLevel)->Quality[quality];
219 break;
220 case INVTYPE_RANGED:
221 case INVTYPE_THROWN:
223 switch (GetSubClass())
224 {
226 dps = sItemDamageOneHandCasterStore.AssertEntry(itemLevel)->Quality[quality];
227 break;
232 dps = sItemDamageTwoHandCasterStore.AssertEntry(itemLevel)->Quality[quality];
233 else
234 dps = sItemDamageTwoHandStore.AssertEntry(itemLevel)->Quality[quality];
235 break;
236 default:
237 break;
238 }
239 break;
240 case INVTYPE_WEAPON:
244 dps = sItemDamageOneHandCasterStore.AssertEntry(itemLevel)->Quality[quality];
245 else
246 dps = sItemDamageOneHandStore.AssertEntry(itemLevel)->Quality[quality];
247 break;
248 default:
249 break;
250 }
251
252 return dps;
253}
254
255void ItemTemplate::GetDamage(uint32 itemLevel, float& minDamage, float& maxDamage) const
256{
257 minDamage = maxDamage = 0.0f;
258 float dps = GetDPS(itemLevel);
259 if (dps > 0.0f)
260 {
261 float avgDamage = dps * GetDelay() * 0.001f;
262 minDamage = (GetDmgVariance() * -0.5f + 1.0f) * avgDamage;
263 maxDamage = floor(float(avgDamage * (GetDmgVariance() * 0.5f + 1.0f) + 0.5f));
264 }
265}
266
267bool ItemTemplate::IsUsableByLootSpecialization(Player const* player, bool alwaysAllowBoundToAccount) const
268{
269 if (HasFlag(ITEM_FLAG_IS_BOUND_TO_ACCOUNT) && alwaysAllowBoundToAccount)
270 return true;
271
272 uint32 spec = player->GetLootSpecId();
273 if (!spec)
275 if (!spec)
276 spec = player->GetDefaultSpecId();
277
278 ChrSpecializationEntry const* chrSpecialization = sChrSpecializationStore.LookupEntry(spec);
279 if (!chrSpecialization)
280 return false;
281
282 std::size_t levelIndex = 0;
283 if (player->GetLevel() >= 110)
284 levelIndex = 2;
285 else if (player->GetLevel() > 40)
286 levelIndex = 1;
287
288 return Specializations[levelIndex].test(CalculateItemSpecBit(chrSpecialization));
289}
290
292{
293 return (spec->ClassID - 1) * MAX_SPECIALIZATIONS + spec->OrderIndex;
294}
LocaleConstant
Definition: Common.h:48
DB2Storage< ItemDamageTwoHandCasterEntry > sItemDamageTwoHandCasterStore("ItemDamageTwoHandCaster.db2", &ItemDamageTwoHandCasterLoadInfo::Instance)
DB2Storage< ItemDamageOneHandEntry > sItemDamageOneHandStore("ItemDamageOneHand.db2", &ItemDamageOneHandLoadInfo::Instance)
DB2Storage< ItemArmorTotalEntry > sItemArmorTotalStore("ItemArmorTotal.db2", &ItemArmorTotalLoadInfo::Instance)
DB2Storage< ChrSpecializationEntry > sChrSpecializationStore("ChrSpecialization.db2", &ChrSpecializationLoadInfo::Instance)
DB2Storage< ItemArmorShieldEntry > sItemArmorShieldStore("ItemArmorShield.db2", &ItemArmorShieldLoadInfo::Instance)
DB2Storage< ItemArmorQualityEntry > sItemArmorQualityStore("ItemArmorQuality.db2", &ItemArmorQualityLoadInfo::Instance)
DB2Storage< ItemDamageAmmoEntry > sItemDamageAmmoStore("ItemDamageAmmo.db2", &ItemDamageAmmoLoadInfo::Instance)
DB2Storage< ArmorLocationEntry > sArmorLocationStore("ArmorLocation.db2", &ArmorLocationLoadInfo::Instance)
DB2Storage< ItemDamageTwoHandEntry > sItemDamageTwoHandStore("ItemDamageTwoHand.db2", &ItemDamageTwoHandLoadInfo::Instance)
DB2Storage< ItemDamageOneHandCasterEntry > sItemDamageOneHandCasterStore("ItemDamageOneHandCaster.db2", &ItemDamageOneHandCasterLoadInfo::Instance)
int32_t int32
Definition: Define.h:138
uint32_t uint32
Definition: Define.h:142
int32 const SocketColorToGemTypeMask[26]
@ ITEM_CLASS_PROFESSION
Definition: ItemTemplate.h:439
@ ITEM_CLASS_PROJECTILE
Definition: ItemTemplate.h:426
@ ITEM_CLASS_ARMOR
Definition: ItemTemplate.h:424
@ ITEM_CLASS_QUEST
Definition: ItemTemplate.h:432
@ ITEM_CLASS_WEAPON
Definition: ItemTemplate.h:422
@ ITEM_CLASS_CONSUMABLE
Definition: ItemTemplate.h:420
@ ITEM_FLAG2_CASTER_WEAPON
Definition: ItemTemplate.h:221
@ ITEM_SUBCLASS_WEAPON_CROSSBOW
Definition: ItemTemplate.h:498
@ ITEM_SUBCLASS_WEAPON_GUN
Definition: ItemTemplate.h:483
@ ITEM_SUBCLASS_WEAPON_BOW
Definition: ItemTemplate.h:482
@ ITEM_SUBCLASS_WEAPON_WAND
Definition: ItemTemplate.h:499
@ ITEM_FLAG_NO_CREATOR
Definition: ItemTemplate.h:193
@ ITEM_FLAG_IS_BOUND_TO_ACCOUNT
Definition: ItemTemplate.h:203
@ ITEM_SUBCLASS_ARMOR_MAIL
Definition: ItemTemplate.h:532
@ ITEM_SUBCLASS_ARMOR_CLOTH
Definition: ItemTemplate.h:530
@ ITEM_SUBCLASS_ARMOR_LEATHER
Definition: ItemTemplate.h:531
@ ITEM_SUBCLASS_ARMOR_SHIELD
Definition: ItemTemplate.h:535
@ ITEM_SUBCLASS_ARMOR_PLATE
Definition: ItemTemplate.h:533
#define MAX_ITEM_SUBCLASS_ARMOR
Definition: ItemTemplate.h:543
@ SOCKET_COLOR_RELIC_FEL
Definition: ItemTemplate.h:356
@ SOCKET_COLOR_RELIC_WIND
Definition: ItemTemplate.h:362
@ SOCKET_COLOR_RELIC_FIRE
Definition: ItemTemplate.h:359
@ SOCKET_COLOR_TINKER
Definition: ItemTemplate.h:369
@ SOCKET_COLOR_META
Definition: ItemTemplate.h:346
@ SOCKET_COLOR_RELIC_LIFE
Definition: ItemTemplate.h:361
@ SOCKET_COLOR_RELIC_ARCANE
Definition: ItemTemplate.h:357
@ SOCKET_COLOR_RELIC_SHADOW
Definition: ItemTemplate.h:355
@ SOCKET_COLOR_RELIC_FROST
Definition: ItemTemplate.h:358
@ SOCKET_COLOR_PUNCHCARD_YELLOW
Definition: ItemTemplate.h:365
@ SOCKET_COLOR_CYPHER
Definition: ItemTemplate.h:368
@ SOCKET_COLOR_DOMINATION
Definition: ItemTemplate.h:367
@ SOCKET_COLOR_RELIC_IRON
Definition: ItemTemplate.h:353
@ SOCKET_COLOR_YELLOW
Definition: ItemTemplate.h:348
@ SOCKET_COLOR_PRIMORDIAL
Definition: ItemTemplate.h:370
@ SOCKET_COLOR_RED
Definition: ItemTemplate.h:347
@ SOCKET_COLOR_PRISMATIC
Definition: ItemTemplate.h:352
@ SOCKET_COLOR_RELIC_WATER
Definition: ItemTemplate.h:360
@ SOCKET_COLOR_PUNCHCARD_BLUE
Definition: ItemTemplate.h:366
@ SOCKET_COLOR_RELIC_HOLY
Definition: ItemTemplate.h:363
@ SOCKET_COLOR_BLUE
Definition: ItemTemplate.h:349
@ SOCKET_COLOR_PUNCHCARD_RED
Definition: ItemTemplate.h:364
@ SOCKET_COLOR_HYDRAULIC
Definition: ItemTemplate.h:350
@ SOCKET_COLOR_RELIC_BLOOD
Definition: ItemTemplate.h:354
@ SOCKET_COLOR_COGWHEEL
Definition: ItemTemplate.h:351
#define MAX_ITEM_SUBCLASS_WEAPON
Definition: ItemTemplate.h:507
#define MAX_ITEM_SUBCLASS_PROFESSION
Definition: ItemTemplate.h:734
@ INVTYPE_ROBE
Definition: ItemTemplate.h:399
@ INVTYPE_HOLDABLE
Definition: ItemTemplate.h:402
@ INVTYPE_RELIC
Definition: ItemTemplate.h:407
@ INVTYPE_RANGED
Definition: ItemTemplate.h:394
@ INVTYPE_THROWN
Definition: ItemTemplate.h:404
@ INVTYPE_RANGEDRIGHT
Definition: ItemTemplate.h:405
@ INVTYPE_WEAPON
Definition: ItemTemplate.h:392
@ INVTYPE_WEAPONMAINHAND
Definition: ItemTemplate.h:400
@ INVTYPE_WEAPONOFFHAND
Definition: ItemTemplate.h:401
@ INVTYPE_2HWEAPON
Definition: ItemTemplate.h:396
@ INVTYPE_AMMO
Definition: ItemTemplate.h:403
@ INVTYPE_SHIELD
Definition: ItemTemplate.h:393
@ INVTYPE_CHEST
Definition: ItemTemplate.h:384
#define MAX_SPECIALIZATIONS
ItemQualities
@ ITEM_QUALITY_RARE
@ ITEM_QUALITY_HEIRLOOM
@ ITEM_QUALITY_ARTIFACT
@ SKILL_BOWS
@ SKILL_INSCRIPTION
@ SKILL_ARCHAEOLOGY
@ SKILL_TWO_HANDED_MACES
@ SKILL_MACES
@ SKILL_PLATE_MAIL
@ SKILL_LEATHER
@ SKILL_COOKING
@ SKILL_WANDS
@ SKILL_BLACKSMITHING
@ SKILL_GUNS
@ SKILL_LEATHERWORKING
@ SKILL_SHIELD
@ SKILL_CROSSBOWS
@ SKILL_TWO_HANDED_AXES
@ SKILL_TAILORING
@ SKILL_MINING
@ SKILL_FISHING
@ SKILL_ENGINEERING
@ SKILL_SWORDS
@ SKILL_TWO_HANDED_SWORDS
@ SKILL_WARGLAIVES
@ SKILL_DAGGERS
@ SKILL_CLOTH
@ SKILL_POLEARMS
@ SKILL_SKINNING
@ SKILL_ALCHEMY
@ SKILL_MAIL
@ SKILL_FIST_WEAPONS
@ SKILL_AXES
@ SKILL_STAVES
@ SKILL_ENCHANTING
@ SKILL_JEWELCRAFTING
@ SKILL_HERBALISM
constexpr std::underlying_type< E >::type AsUnderlyingType(E enumValue)
Definition: Util.h:491
ChrSpecialization GetPrimarySpecialization() const
Definition: Player.h:1841
uint32 GetDefaultSpecId() const
Definition: Player.cpp:29822
uint32 GetLootSpecId() const
Definition: Player.h:1831
uint8 GetLevel() const
Definition: Unit.h:746
#define sWorld
Definition: World.h:931
std::array< float, 7 > Qualitymod
std::array< float, 7 > Quality
LocalizedString Display
uint32 GetQuality() const
Definition: ItemTemplate.h:779
bool CanChangeEquipStateInCombat() const
uint32 GetId() const
Definition: ItemTemplate.h:776
uint32 GetMaxStackSize() const
Definition: ItemTemplate.h:847
InventoryType GetInventoryType() const
Definition: ItemTemplate.h:786
float GetDmgVariance() const
Definition: ItemTemplate.h:823
uint32 GetArmor(uint32 itemLevel) const
bool HasSignature() const
std::bitset< MAX_CLASSES *MAX_SPECIALIZATIONS > Specializations[3]
Definition: ItemTemplate.h:838
static std::size_t CalculateItemSpecBit(ChrSpecializationEntry const *spec)
ItemSparseEntry const * ExtendedData
Definition: ItemTemplate.h:774
bool HasFlag(ItemFlags flag) const
Definition: ItemTemplate.h:871
void GetDamage(uint32 itemLevel, float &minDamage, float &maxDamage) const
uint32 GetSubClass() const
Definition: ItemTemplate.h:778
bool IsUsableByLootSpecialization(Player const *player, bool alwaysAllowBoundToAccount) const
char const * GetName(LocaleConstant locale) const
char const * GetDefaultLocaleName() const
uint32 GetClass() const
Definition: ItemTemplate.h:777
float GetDPS(uint32 itemLevel) const
uint32 GetDelay() const
Definition: ItemTemplate.h:804
uint32 GetSkill() const