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 "Opcodes.h"
21#include "SpellInfo.h"
22#include "SpellMgr.h"
23
25
27{
28 return GetMaxStackSize() == 1 &&
32 ItemId != 6948; /*Hearthstone*/
33}
34
36{
37 switch (InventoryType)
38 {
39 case INVTYPE_RELIC:
40 case INVTYPE_SHIELD:
42 return true;
43 }
44
45 switch (Class)
46 {
49 return true;
50 }
51
52 return false;
53}
54
56{
57 if (!Delay)
58 return 0.f;
59
60 float temp = 0.f;
61 for (uint8 i = 0; i < MAX_ITEM_PROTO_DAMAGES; ++i)
62 temp += Damage[i].DamageMin + Damage[i].DamageMax;
63
64 return temp * 500.f / Delay;
65}
66
68{
69 constexpr uint32 feralApEnabledInventoryTypeMaks = 1 << INVTYPE_WEAPON | 1 << INVTYPE_2HWEAPON | 1 << INVTYPE_WEAPONMAINHAND | 1 << INVTYPE_WEAPONOFFHAND;
70
71 // 0x02A5F3 - is mask for Melee weapon from ItemSubClassMask.dbc
72 if (Class == ITEM_CLASS_WEAPON && (1 << InventoryType) & feralApEnabledInventoryTypeMaks)
73 {
74 int32 bonus = int32((extraDPS + getDPS()) * 14.0f) - 767;
75 if (bonus < 0)
76 return 0;
77 return bonus;
78 }
79
80 return 0;
81}
82
84{
85 float itemLevel(ItemLevel);
86 switch (Quality)
87 {
93 itemLevel -= 13.f; // leaving this as a separate statement since we do not know the real behavior in this case
94 break;
96 itemLevel -= 13.f;
97 break;
100 default:
101 break;
102 }
103
104 return std::max<float>(0.f, itemLevel);
105}
106
108{
109 static uint32 const itemWeaponSkills[MAX_ITEM_SUBCLASS_WEAPON] =
110 {
116 };
117
118 static uint32 const itemArmorSkills[MAX_ITEM_SUBCLASS_ARMOR] =
119 {
121 };
122
123 switch (Class)
124 {
127 return 0;
128 else
129 return itemWeaponSkills[SubClass];
130
131 case ITEM_CLASS_ARMOR:
133 return 0;
134 else
135 return itemArmorSkills[SubClass];
136
137 default:
138 return 0;
139 }
140}
141
143{
144 int32 totalAP = 0;
145 for (uint32 i = 0; i < StatsCount; ++i)
146 if (ItemStat[i].ItemStatType == ITEM_MOD_ATTACK_POWER)
147 totalAP += ItemStat[i].ItemStatValue;
148
149 // some items can have equip spells with +AP
150 for (ItemEffect const& itemEffect : Effects)
151 if (itemEffect.SpellID > 0 && itemEffect.TriggerType == ITEM_SPELLTRIGGER_ON_EQUIP)
152 if (SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(itemEffect.SpellID))
153 for (SpellEffectInfo const& effect : spellInfo->GetEffects())
154 if (effect.IsAura(SPELL_AURA_MOD_ATTACK_POWER))
155 totalAP += effect.CalcValue();
156
157 _totalAP = totalAP;
158}
159
161{
162 for (uint8 loc = LOCALE_enUS; loc < TOTAL_LOCALES; ++loc)
163 QueryData[loc] = BuildQueryData(static_cast<LocaleConstant>(loc));
164}
165
167{
169
170 std::string locName = Name1;
171 std::string locDescription = Description;
172
173 if (ItemLocale const* il = sObjectMgr->GetItemLocale(ItemId))
174 {
175 ObjectMgr::GetLocaleString(il->Name, loc, locName);
176 ObjectMgr::GetLocaleString(il->Description, loc, locDescription);
177 }
178
179 response.ItemID = ItemId;
180 response.Allow = true;
181
182 response.Stats.Class = Class;
183 response.Stats.SubClass = SubClass;
185 response.Stats.Name = locName;
187 response.Stats.Quality = Quality;
188 response.Stats.Flags = Flags;
189 response.Stats.Flags2 = Flags2;
190 response.Stats.BuyPrice = BuyPrice;
191 response.Stats.SellPrice = SellPrice;
195 response.Stats.ItemLevel = ItemLevel;
204 response.Stats.MaxCount = MaxCount;
205 response.Stats.Stackable = Stackable;
207 response.Stats.StatsCount = StatsCount;
208 for (uint32 i = 0; i < StatsCount; ++i)
209 {
210 response.Stats.ItemStat[i].ItemStatType = ItemStat[i].ItemStatType;
211 response.Stats.ItemStat[i].ItemStatValue = ItemStat[i].ItemStatValue;
212 }
213
216
217 for (uint8 i = 0; i < MAX_ITEM_PROTO_DAMAGES; ++i)
218 {
219 response.Stats.Damage[i].DamageMin = Damage[i].DamageMin;
220 response.Stats.Damage[i].DamageMax = Damage[i].DamageMax;
221 response.Stats.Damage[i].DamageType = Damage[i].DamageType;
222 }
223
231
232 response.Stats.Delay = Delay;
233 response.Stats.AmmoType = AmmoType;
235
236 for (uint8 s = 0; s < MAX_ITEM_PROTO_SPELLS; ++s)
237 {
238 response.Stats.Spells[s].SpellId = Effects[s].SpellID;
239 response.Stats.Spells[s].SpellTrigger = Effects[s].TriggerType;
240 response.Stats.Spells[s].SpellCharges = Effects[s].Charges;
241 response.Stats.Spells[s].SpellCooldown = Effects[s].CoolDownMSec;
242 response.Stats.Spells[s].SpellCategory = Effects[s].SpellCategoryID;
243 response.Stats.Spells[s].SpellCategoryCooldown = Effects[s].CategoryCoolDownMSec;
244 }
245
246 response.Stats.Bonding = Bonding;
247 response.Stats.Description = locDescription;
248 response.Stats.PageText = PageText;
249 response.Stats.LanguageID = LanguageID;
251 response.Stats.StartQuest = StartQuest;
252 response.Stats.LockID = LockID;
253 response.Stats.Material = Material;
254 response.Stats.Sheath = Sheath;
257 response.Stats.Block = Block;
258 response.Stats.ItemSet = ItemSet;
260 response.Stats.Area = Area;
261 response.Stats.Map = Map;
262 response.Stats.BagFamily = BagFamily;
264
265 for (uint8 s = 0; s < MAX_ITEM_PROTO_SOCKETS; ++s)
266 {
267 response.Stats.Socket[s].Color = Socket[s].Color;
268 response.Stats.Socket[s].Content = Socket[s].Content;
269 }
270
271 response.Stats.SocketBonus = socketBonus;
275 response.Stats.Duration = Duration;
277 response.Stats.HolidayId = HolidayId;
278
279 response.Write();
280 response.ShrinkToFit();
281 return response.Move();
282}
LocaleConstant
Definition Common.h:48
@ TOTAL_LOCALES
Definition Common.h:59
@ LOCALE_enUS
Definition Common.h:49
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, size_t locale)
Definition ObjectMgr.h:1525
WorldPacket && Move()
Definition Packet.h:53
int32 RandomProperty
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 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
uint32 PageMaterial
uint32 RequiredLevel
std::string Name1
uint32 GemProperties
uint32 RequiredReputationRank
uint32 ContainerSlots
uint32 DisplayInfoID
uint32 AllowableRace
uint32 RequiredReputationFaction
bool HasFlag(ItemFlags flag) const
uint32 ItemLimitCategory
void InitializeQueryData()
uint32 ScalingStatDistribution
uint32 MaxDurability
uint32 InventoryType
uint32 LanguageID
std::array< WorldPacket, TOTAL_LOCALES > QueryData
std::array< _ItemStat, MAX_ITEM_PROTO_STATS > ItemStat
float getDPS() const
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]
ItemSocketData Socket[MAX_ITEM_PROTO_SOCKETS]
ItemDamageData Damage[MAX_ITEM_PROTO_DAMAGES]