TrinityCore
Loading...
Searching...
No Matches
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 "ItemTemplate.h"
19#include "DB2Stores.h"
20#include "Player.h"
21#include "World.h"
22
57
58char const* ItemTemplate::GetName(LocaleConstant locale) const
59{
60 if (ExtendedData->Display[locale][0] == '\0')
61 return GetDefaultLocaleName();
62
63 return ExtendedData->Display[locale];
64}
65
74
76{
77 switch (GetInventoryType())
78 {
79 case INVTYPE_RELIC:
80 case INVTYPE_SHIELD:
82 return true;
83 default:
84 break;
85 }
86
87 switch (GetClass())
88 {
91 return true;
92 }
93
94 return false;
95}
96
98{
99 static constexpr uint32 ItemWeaponSkills[MAX_ITEM_SUBCLASS_WEAPON] =
100 {
106 };
107
108 static constexpr uint32 ItemArmorSkills[MAX_ITEM_SUBCLASS_ARMOR] =
109 {
111 };
112
113 static constexpr uint32 ItemProfessionSkills[MAX_ITEM_SUBCLASS_PROFESSION] =
114 {
118 };
119
120 switch (GetClass())
121 {
124 return 0;
125 else
126 return ItemWeaponSkills[GetSubClass()];
127 case ITEM_CLASS_ARMOR:
129 return 0;
130 else
131 return ItemArmorSkills[GetSubClass()];
134 return 0;
135 else
136 return ItemProfessionSkills[GetSubClass()];
137 default:
138 return 0;
139 }
140}
141
143{
144 return ExtendedData->Display[sWorld->GetDefaultDbcLocale()];
145}
146
148{
150 if (quality > ITEM_QUALITY_ARTIFACT)
151 return 0;
152
153 // all items but shields
155 {
156 ItemArmorQualityEntry const* armorQuality = sItemArmorQualityStore.LookupEntry(itemLevel);
157 ItemArmorTotalEntry const* armorTotal = sItemArmorTotalStore.LookupEntry(itemLevel);
158 if (!armorQuality || !armorTotal)
159 return 0;
160
161 uint32 inventoryType = GetInventoryType();
162 if (inventoryType == INVTYPE_ROBE)
163 inventoryType = INVTYPE_CHEST;
164
165 ArmorLocationEntry const* location = sArmorLocationStore.LookupEntry(inventoryType);
166 if (!location)
167 return 0;
168
170 return 0;
171
172 float total = 1.0f;
173 float locationModifier = 1.0f;
174 switch (GetSubClass())
175 {
177 total = armorTotal->Cloth;
178 locationModifier = location->Clothmodifier;
179 break;
181 total = armorTotal->Leather;
182 locationModifier = location->Leathermodifier;
183 break;
185 total = armorTotal->Mail;
186 locationModifier = location->Chainmodifier;
187 break;
189 total = armorTotal->Plate;
190 locationModifier = location->Platemodifier;
191 break;
192 default:
193 break;
194 }
195
196 return uint32(armorQuality->Qualitymod[quality] * total * locationModifier + 0.5f);
197 }
198
199 // shields
200 ItemArmorShieldEntry const* shield = sItemArmorShieldStore.LookupEntry(itemLevel);
201 if (!shield)
202 return 0;
203
204 return uint32(shield->Quality[quality] + 0.5f);
205}
206
207float ItemTemplate::GetDPS(uint32 itemLevel) const
208{
211 return 0.0f;
212
213 float dps = 0.0f;
214 switch (GetInventoryType())
215 {
216 case INVTYPE_AMMO:
217 dps = sItemDamageAmmoStore.AssertEntry(itemLevel)->Quality[quality];
218 break;
219 case INVTYPE_2HWEAPON:
221 dps = sItemDamageTwoHandCasterStore.AssertEntry(itemLevel)->Quality[quality];
222 else
223 dps = sItemDamageTwoHandStore.AssertEntry(itemLevel)->Quality[quality];
224 break;
225 case INVTYPE_RANGED:
226 case INVTYPE_THROWN:
228 switch (GetSubClass())
229 {
231 dps = sItemDamageOneHandCasterStore.AssertEntry(itemLevel)->Quality[quality];
232 break;
237 dps = sItemDamageTwoHandCasterStore.AssertEntry(itemLevel)->Quality[quality];
238 else
239 dps = sItemDamageTwoHandStore.AssertEntry(itemLevel)->Quality[quality];
240 break;
241 default:
242 break;
243 }
244 break;
245 case INVTYPE_WEAPON:
249 dps = sItemDamageOneHandCasterStore.AssertEntry(itemLevel)->Quality[quality];
250 else
251 dps = sItemDamageOneHandStore.AssertEntry(itemLevel)->Quality[quality];
252 break;
253 default:
254 break;
255 }
256
257 return dps;
258}
259
260void ItemTemplate::GetDamage(uint32 itemLevel, float& minDamage, float& maxDamage) const
261{
262 minDamage = maxDamage = 0.0f;
263 float dps = GetDPS(itemLevel);
264 if (dps > 0.0f)
265 {
266 float avgDamage = dps * GetDelay() * 0.001f;
267 minDamage = (GetDmgVariance() * -0.5f + 1.0f) * avgDamage;
268 maxDamage = floor(float(avgDamage * (GetDmgVariance() * 0.5f + 1.0f) + 0.5f));
269 }
270}
271
272bool ItemTemplate::IsUsableByLootSpecialization(Player const* player, bool alwaysAllowBoundToAccount) const
273{
274 if (HasFlag(ITEM_FLAG_IS_BOUND_TO_ACCOUNT) && alwaysAllowBoundToAccount)
275 return true;
276
277 uint32 spec = player->GetLootSpecId();
278 if (!spec)
280 if (!spec)
281 spec = player->GetDefaultSpecId();
282
283 ChrSpecializationEntry const* chrSpecialization = sChrSpecializationStore.LookupEntry(spec);
284 if (!chrSpecialization)
285 return false;
286
287 std::size_t levelIndex = 0;
288 if (player->GetLevel() >= 110)
289 levelIndex = 2;
290 else if (player->GetLevel() > 40)
291 levelIndex = 1;
292
293 return Specializations[levelIndex].test(CalculateItemSpecBit(chrSpecialization));
294}
295
297{
298 return (spec->ClassID - 1) * MAX_SPECIALIZATIONS + spec->OrderIndex;
299}
300
LocaleConstant
Definition Common.h:51
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)
TransmogOutfitSlotOption
Definition DBCEnums.h:2622
int32_t int32
Definition Define.h:150
uint32_t uint32
Definition Define.h:154
int32 const SocketColorToGemTypeMask[31]
@ ITEM_CLASS_PROFESSION
@ ITEM_CLASS_PROJECTILE
@ ITEM_CLASS_ARMOR
@ ITEM_CLASS_QUEST
@ ITEM_CLASS_WEAPON
@ ITEM_CLASS_CONSUMABLE
@ ITEM_FLAG2_CASTER_WEAPON
@ ITEM_SUBCLASS_WEAPON_CROSSBOW
@ ITEM_SUBCLASS_WEAPON_GUN
@ ITEM_SUBCLASS_WEAPON_AXE2
@ ITEM_SUBCLASS_WEAPON_STAFF
@ ITEM_SUBCLASS_WEAPON_MACE
@ ITEM_SUBCLASS_WEAPON_WARGLAIVES
@ ITEM_SUBCLASS_WEAPON_MACE2
@ ITEM_SUBCLASS_WEAPON_DAGGER
@ ITEM_SUBCLASS_WEAPON_BOW
@ ITEM_SUBCLASS_WEAPON_SWORD
@ ITEM_SUBCLASS_WEAPON_AXE
@ ITEM_SUBCLASS_WEAPON_FIST_WEAPON
@ ITEM_SUBCLASS_WEAPON_WAND
@ ITEM_SUBCLASS_WEAPON_SWORD2
@ ITEM_SUBCLASS_WEAPON_POLEARM
@ ITEM_FLAG_NO_CREATOR
@ ITEM_FLAG_IS_BOUND_TO_ACCOUNT
@ ITEM_SUBCLASS_ARMOR_MAIL
@ ITEM_SUBCLASS_ARMOR_CLOTH
@ ITEM_SUBCLASS_ARMOR_LEATHER
@ ITEM_SUBCLASS_ARMOR_SHIELD
@ ITEM_SUBCLASS_ARMOR_PLATE
#define MAX_ITEM_SUBCLASS_ARMOR
@ SOCKET_COLOR_SINGING_WIND
@ SOCKET_COLOR_DOMINATION_UNHOLY
@ SOCKET_COLOR_RELIC_FEL
@ SOCKET_COLOR_FIBER
@ SOCKET_COLOR_RELIC_WIND
@ SOCKET_COLOR_RELIC_FIRE
@ SOCKET_COLOR_TINKER
@ SOCKET_COLOR_DOMINATION_BLOOD
@ SOCKET_COLOR_META
@ SOCKET_COLOR_RELIC_LIFE
@ SOCKET_COLOR_RELIC_ARCANE
@ SOCKET_COLOR_DOMINATION_FROST
@ SOCKET_COLOR_RELIC_SHADOW
@ SOCKET_COLOR_RELIC_FROST
@ SOCKET_COLOR_SINGING_SEA
@ SOCKET_COLOR_PUNCHCARD_YELLOW
@ SOCKET_COLOR_CYPHER
@ SOCKET_COLOR_FRAGRANCE
@ SOCKET_COLOR_RELIC_IRON
@ SOCKET_COLOR_YELLOW
@ SOCKET_COLOR_PRIMORDIAL
@ SOCKET_COLOR_RED
@ SOCKET_COLOR_RELIC_WATER
@ SOCKET_COLOR_SINGING_THUNDER
@ SOCKET_COLOR_PUNCHCARD_BLUE
@ SOCKET_COLOR_RELIC_HOLY
@ SOCKET_COLOR_BLUE
@ SOCKET_COLOR_PUNCHCARD_RED
@ SOCKET_COLOR_HYDRAULIC
@ SOCKET_COLOR_RELIC_BLOOD
@ SOCKET_COLOR_COGWHEEL
#define MAX_ITEM_SUBCLASS_WEAPON
#define MAX_ITEM_SUBCLASS_PROFESSION
@ ITEM_HEARTHSTONE
@ INVTYPE_ROBE
@ INVTYPE_HOLDABLE
@ INVTYPE_RELIC
@ INVTYPE_RANGED
@ INVTYPE_THROWN
@ INVTYPE_RANGEDRIGHT
@ INVTYPE_WEAPON
@ INVTYPE_WEAPONMAINHAND
@ INVTYPE_WEAPONOFFHAND
@ INVTYPE_2HWEAPON
@ INVTYPE_AMMO
@ INVTYPE_SHIELD
@ INVTYPE_CHEST
ItemQualities
@ ITEM_QUALITY_RARE
@ ITEM_QUALITY_HEIRLOOM
@ ITEM_QUALITY_ARTIFACT
#define MAX_SPECIALIZATIONS
@ 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:565
ChrSpecialization GetPrimarySpecialization() const
Definition Player.h:2008
uint32 GetDefaultSpecId() const
Definition Player.cpp:30814
uint32 GetLootSpecId() const
Definition Player.h:1998
uint8 GetLevel() const
Definition Unit.h:757
#define sWorld
Definition World.h:916
std::array< float, 7 > Qualitymod
std::array< float, 7 > Quality
LocalizedString Display
uint32 GetQuality() const
bool CanChangeEquipStateInCombat() const
TransmogOutfitSlotOption GetWeaponTransmogOutfitSlotOption() const
uint32 GetId() const
uint32 GetMaxStackSize() const
InventoryType GetInventoryType() const
float GetDmgVariance() const
uint32 GetArmor(uint32 itemLevel) const
bool HasSignature() const
std::bitset< MAX_CLASSES *MAX_SPECIALIZATIONS > Specializations[3]
static std::size_t CalculateItemSpecBit(ChrSpecializationEntry const *spec)
ItemSparseEntry const * ExtendedData
bool HasFlag(ItemFlags flag) const
void GetDamage(uint32 itemLevel, float &minDamage, float &maxDamage) const
uint32 GetSubClass() const
bool IsUsableByLootSpecialization(Player const *player, bool alwaysAllowBoundToAccount) const
char const * GetName(LocaleConstant locale) const
char const * GetDefaultLocaleName() const
uint32 GetClass() const
float GetDPS(uint32 itemLevel) const
uint32 GetDelay() const
uint32 GetSkill() const