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 "ObjectMgr.h"
20#include "QueryPackets.h"
21#include "SpellInfo.h"
22#include "SpellMgr.h"
23#include "World.h"
24
25std::string const& ItemTemplate::GetName(LocaleConstant locale) const
26{
27 if (locale != DEFAULT_LOCALE)
28 if (ItemLocale const* itemLocale = sObjectMgr->GetItemLocale(GetId()))
29 if (locale < itemLocale->Name.size() && !itemLocale->Name[locale].empty())
30 return itemLocale->Name[locale];
31
32 return Name1;
33}
34
36{
37 return GetMaxStackSize() == 1 &&
41 ItemId != 6948; /*Hearthstone*/
42}
43
45{
46 switch (GetInventoryType())
47 {
48 case INVTYPE_RELIC:
49 case INVTYPE_SHIELD:
51 return true;
52 default:
53 break;
54 }
55
56 switch (Class)
57 {
60 return true;
61 default:
62 break;
63 }
64
65 return false;
66}
67
69{
70 if (!Delay)
71 return 0.f;
72
73 float temp = 0.f;
74 for (uint8 i = 0; i < MAX_ITEM_PROTO_DAMAGES; ++i)
75 temp += Damage[i].DamageMin + Damage[i].DamageMax;
76
77 return temp * 500.f / Delay;
78}
79
81{
82 constexpr uint32 feralApEnabledInventoryTypeMaks = 1 << INVTYPE_WEAPON | 1 << INVTYPE_2HWEAPON | 1 << INVTYPE_WEAPONMAINHAND | 1 << INVTYPE_WEAPONOFFHAND;
83
84 // 0x02A5F3 - is mask for Melee weapon from ItemSubClassMask.dbc
85 if (Class == ITEM_CLASS_WEAPON && (1 << InventoryType) & feralApEnabledInventoryTypeMaks)
86 {
87 int32 bonus = int32((extraDPS + GetDPS()) * 14.0f) - 767;
88 if (bonus < 0)
89 return 0;
90 return bonus;
91 }
92
93 return 0;
94}
95
97{
98 float itemLevel(ItemLevel);
99 switch (Quality)
100 {
106 itemLevel -= 13.f; // leaving this as a separate statement since we do not know the real behavior in this case
107 break;
109 itemLevel -= 13.f;
110 break;
113 default:
114 break;
115 }
116
117 return std::max<float>(0.f, itemLevel);
118}
119
121{
122 static uint32 const itemWeaponSkills[MAX_ITEM_SUBCLASS_WEAPON] =
123 {
129 };
130
131 static uint32 const itemArmorSkills[MAX_ITEM_SUBCLASS_ARMOR] =
132 {
134 };
135
136 switch (Class)
137 {
140 return 0;
141 else
142 return itemWeaponSkills[SubClass];
143
144 case ITEM_CLASS_ARMOR:
146 return 0;
147 else
148 return itemArmorSkills[SubClass];
149
150 default:
151 return 0;
152 }
153}
154
155std::string const& ItemTemplate::GetDefaultLocaleName() const
156{
157 return GetName(sWorld->GetDefaultDbcLocale());
158}
159
161{
162 int32 totalAP = 0;
163 for (uint32 i = 0; i < StatsCount; ++i)
164 if (ItemStat[i].ItemStatType == ITEM_MOD_ATTACK_POWER)
165 totalAP += ItemStat[i].ItemStatValue;
166
167 // some items can have equip spells with +AP
168 for (ItemEffect const& itemEffect : Effects)
169 if (itemEffect.SpellID > 0 && itemEffect.TriggerType == ITEM_SPELLTRIGGER_ON_EQUIP)
170 if (SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(itemEffect.SpellID))
171 for (SpellEffectInfo const& effect : spellInfo->GetEffects())
172 if (effect.IsAura(SPELL_AURA_MOD_ATTACK_POWER))
173 totalAP += effect.CalcValue();
174
175 _totalAP = totalAP;
176}
177
179{
180 for (uint8 loc = LOCALE_enUS; loc < TOTAL_LOCALES; ++loc)
181 QueryData[loc] = BuildQueryData(static_cast<LocaleConstant>(loc));
182}
183
185{
187
188 response.ItemID = ItemId;
189 response.Allow = true;
190
191 response.Stats.Class = Class;
192 response.Stats.SubClass = SubClass;
194 response.Stats.Name = Name1;
196 response.Stats.Quality = Quality;
197 response.Stats.Flags = Flags;
198 response.Stats.BuyPrice = BuyPrice;
199 response.Stats.SellPrice = SellPrice;
203 response.Stats.ItemLevel = ItemLevel;
212 response.Stats.MaxCount = MaxCount;
213 response.Stats.Stackable = Stackable;
215 response.Stats.StatsCount = StatsCount;
216 for (uint32 i = 0; i < StatsCount; ++i)
217 {
218 response.Stats.ItemStat[i].ItemStatType = ItemStat[i].ItemStatType;
219 response.Stats.ItemStat[i].ItemStatValue = ItemStat[i].ItemStatValue;
220 }
221
224
225 for (uint8 i = 0; i < MAX_ITEM_PROTO_DAMAGES; ++i)
226 {
227 response.Stats.Damage[i].DamageMin = Damage[i].DamageMin;
228 response.Stats.Damage[i].DamageMax = Damage[i].DamageMax;
229 response.Stats.Damage[i].DamageType = Damage[i].DamageType;
230 }
231
239
240 response.Stats.Delay = Delay;
241 response.Stats.AmmoType = AmmoType;
243
244 for (uint8 s = 0; s < MAX_ITEM_PROTO_SPELLS; ++s)
245 {
246 response.Stats.Spells[s].SpellId = Effects[s].SpellID;
247 response.Stats.Spells[s].SpellTrigger = Effects[s].TriggerType;
248 response.Stats.Spells[s].SpellCharges = Effects[s].Charges;
249 response.Stats.Spells[s].SpellCooldown = Effects[s].CoolDownMSec;
250 response.Stats.Spells[s].SpellCategory = Effects[s].SpellCategoryID;
251 response.Stats.Spells[s].SpellCategoryCooldown = Effects[s].CategoryCoolDownMSec;
252 }
253
254 response.Stats.Bonding = Bonding;
255 response.Stats.Description = Description;
256 response.Stats.PageText = PageText;
257 response.Stats.LanguageID = LanguageID;
259 response.Stats.StartQuest = StartQuest;
260 response.Stats.LockID = LockID;
261 response.Stats.Material = Material;
262 response.Stats.Sheath = Sheath;
265 response.Stats.Block = Block;
266 response.Stats.ItemSet = ItemSet;
268 response.Stats.Area = Area;
269 response.Stats.Map = Map;
270 response.Stats.BagFamily = BagFamily;
272
273 for (uint8 s = 0; s < MAX_ITEM_PROTO_SOCKETS; ++s)
274 {
275 response.Stats.Socket[s].Color = Socket[s].Color;
276 response.Stats.Socket[s].Content = Socket[s].Content;
277 }
278
279 response.Stats.SocketBonus = socketBonus;
283 response.Stats.Duration = Duration;
285 response.Stats.HolidayId = HolidayId;
286
287 if (ItemLocale const* il = sObjectMgr->GetItemLocale(ItemId))
288 {
289 ObjectMgr::GetLocaleString(il->Name, loc, response.Stats.Name);
290 ObjectMgr::GetLocaleString(il->Description, loc, response.Stats.Description);
291 }
292
293 response.Write();
294 response.ShrinkToFit();
295 return response.Move();
296}
LocaleConstant
Definition Common.h:48
@ TOTAL_LOCALES
Definition Common.h:59
@ LOCALE_enUS
Definition Common.h:49
#define DEFAULT_LOCALE
Definition Common.h:62
uint8_t uint8
Definition Define.h:135
int32_t int32
Definition Define.h:129
uint32_t uint32
Definition Define.h:133
@ ITEM_CLASS_PROJECTILE
@ ITEM_CLASS_ARMOR
@ ITEM_CLASS_QUEST
@ ITEM_CLASS_WEAPON
@ ITEM_CLASS_CONSUMABLE
@ ITEM_SPELLTRIGGER_ON_EQUIP
@ ITEM_FLAG_NO_CREATOR
@ ITEM_MOD_ATTACK_POWER
#define MAX_ITEM_SUBCLASS_ARMOR
#define MAX_ITEM_PROTO_SOCKETS
#define MAX_ITEM_PROTO_DAMAGES
#define MAX_ITEM_PROTO_SPELLS
#define MAX_ITEM_SUBCLASS_WEAPON
InventoryType
@ INVTYPE_HOLDABLE
@ INVTYPE_RELIC
@ INVTYPE_WEAPON
@ INVTYPE_WEAPONMAINHAND
@ INVTYPE_WEAPONOFFHAND
@ INVTYPE_2HWEAPON
@ INVTYPE_SHIELD
#define sObjectMgr
Definition ObjectMgr.h:1721
@ SPELL_SCHOOL_SHADOW
@ SPELL_SCHOOL_NORMAL
@ SPELL_SCHOOL_NATURE
@ SPELL_SCHOOL_FROST
@ SPELL_SCHOOL_ARCANE
@ SPELL_SCHOOL_FIRE
@ SPELL_SCHOOL_HOLY
@ ITEM_QUALITY_UNCOMMON
@ ITEM_QUALITY_RARE
@ ITEM_QUALITY_NORMAL
@ ITEM_QUALITY_LEGENDARY
@ ITEM_QUALITY_HEIRLOOM
@ ITEM_QUALITY_POOR
@ ITEM_QUALITY_ARTIFACT
@ ITEM_QUALITY_EPIC
@ SKILL_BOWS
@ SKILL_MACES
@ SKILL_PLATE_MAIL
@ SKILL_LEATHER
@ SKILL_WANDS
@ SKILL_GUNS
@ SKILL_SHIELD
@ SKILL_CROSSBOWS
@ SKILL_THROWN
@ SKILL_FISHING
@ SKILL_SWORDS
@ SKILL_DAGGERS
@ SKILL_2H_AXES
@ SKILL_CLOTH
@ SKILL_POLEARMS
@ SKILL_2H_SWORDS
@ SKILL_MAIL
@ SKILL_FIST_WEAPONS
@ SKILL_2H_MACES
@ SKILL_AXES
@ SKILL_STAVES
@ SKILL_ASSASSINATION
@ SPELL_AURA_MOD_ATTACK_POWER
#define sSpellMgr
Definition SpellMgr.h:738
static std::string_view GetLocaleString(std::vector< std::string > const &data, LocaleConstant locale)
Definition ObjectMgr.h:1519
WorldPacket && Move()
Definition Packet.h:53
#define sWorld
Definition World.h:901
std::string const & GetDefaultLocaleName() const
int32 RandomProperty
std::array< uint32, MAX_ITEM_PROTO_FLAGS > Flags
std::array< ItemEffect, MAX_ITEM_PROTO_SPELLS > Effects
bool CanChangeEquipStateInCombat() const
uint32 RequiredCityRank
uint32 RequiredSkill
uint32 RequiredSpell
uint32 ScalingStatValue
std::string Description
uint32 AllowableClass
uint32 RequiredSkillRank
uint32 GetId() const
uint32 RequiredHonorRank
uint32 GetMaxStackSize() const
float RangedModRange
float ArmorDamageModifier
std::array< _Socket, MAX_ITEM_PROTO_SOCKETS > Socket
WorldPacket BuildQueryData(LocaleConstant loc) const
bool HasSignature() const
float GetItemLevelIncludingQuality() const
uint32 socketBonus
uint32 RequiredDisenchantSkill
uint32 TotemCategory
std::string const & GetName(LocaleConstant locale) const
uint32 PageMaterial
uint32 RequiredLevel
std::string Name1
uint32 GemProperties
uint32 RequiredReputationRank
uint32 ContainerSlots
uint32 DisplayInfoID
uint32 AllowableRace
float GetDPS() const
uint32 RequiredReputationFaction
bool HasFlag(ItemFlags flag) const
uint32 ItemLimitCategory
void InitializeQueryData()
uint32 ScalingStatDistribution
::InventoryType GetInventoryType() const
uint32 MaxDurability
uint32 InventoryType
uint32 LanguageID
std::array< WorldPacket, TOTAL_LOCALES > QueryData
std::array< _ItemStat, MAX_ITEM_PROTO_STATS > ItemStat
uint32 StartQuest
int32 SoundOverrideSubclass
int32 getFeralBonus(int32 extraDPS=0) const
std::array< _Damage, MAX_ITEM_PROTO_DAMAGES > Damage
uint32 StatsCount
uint32 GetSkill() const
ItemSpellData Spells[MAX_ITEM_PROTO_SPELLS]
ItemStatData ItemStat[MAX_ITEM_PROTO_STATS]
uint32 Resistance[MAX_SPELL_SCHOOL]
std::array< uint32, MAX_ITEM_PROTO_FLAGS > Flags
ItemSocketData Socket[MAX_ITEM_PROTO_SOCKETS]
ItemDamageData Damage[MAX_ITEM_PROTO_DAMAGES]