AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
Item.cpp File Reference
#include "Item.h"
#include "Common.h"
#include "ConditionMgr.h"
#include "DatabaseEnv.h"
#include "GameTime.h"
#include "ItemEnchantmentMgr.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "ScriptMgr.h"
#include "SpellInfo.h"
#include "SpellMgr.h"
#include "StringConvert.h"
#include "Tokenize.h"
#include "WorldPacket.h"

Go to the source code of this file.

Functions

void AddItemsSetItem (Player *player, Item *item)
 
void RemoveItemsSetItem (Player *player, ItemTemplate const *proto)
 
bool ItemCanGoIntoBag (ItemTemplate const *pProto, ItemTemplate const *pBagProto)
 

Function Documentation

◆ AddItemsSetItem()

void AddItemsSetItem ( Player player,
Item item 
)
34{
35 ItemTemplate const* proto = item->GetTemplate();
36 uint32 setid = proto->ItemSet;
37
38 ItemSetEntry const* set = sItemSetStore.LookupEntry(setid);
39
40 if (!set)
41 {
42 LOG_ERROR("sql.sql", "Item set {} for item (id {}) not found, mods not applied.", setid, proto->ItemId);
43 return;
44 }
45
47 return;
48
49 ItemSetEffect* eff = nullptr;
50
51 for (size_t x = 0; x < player->ItemSetEff.size(); ++x)
52 {
53 if (player->ItemSetEff[x] && player->ItemSetEff[x]->setid == setid)
54 {
55 eff = player->ItemSetEff[x];
56 break;
57 }
58 }
59
60 if (!eff)
61 {
62 eff = new ItemSetEffect();
63 eff->setid = setid;
64
65 size_t x = 0;
66 for (; x < player->ItemSetEff.size(); ++x)
67 if (!player->ItemSetEff[x])
68 break;
69
70 if (x < player->ItemSetEff.size())
71 player->ItemSetEff[x] = eff;
72 else
73 player->ItemSetEff.push_back(eff);
74 }
75
76 ++eff->item_count;
77
78 for (uint32 x = 0; x < MAX_ITEM_SET_SPELLS; ++x)
79 {
80 if (!set->spells [x])
81 continue;
82 //not enough for spell
83 if (set->items_to_triggerspell[x] > eff->item_count)
84 continue;
85
86 uint32 z = 0;
87 for (; z < MAX_ITEM_SET_SPELLS; ++z)
88 if (eff->spells[z] && eff->spells[z]->Id == set->spells[x])
89 break;
90
91 if (z < MAX_ITEM_SET_SPELLS)
92 continue;
93
94 //new spell
95 for (uint32 y = 0; y < MAX_ITEM_SET_SPELLS; ++y)
96 {
97 if (!eff->spells[y]) // free slot
98 {
99 SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(set->spells[x]);
100 if (!spellInfo)
101 {
102 LOG_ERROR("entities.item", "WORLD: unknown spell id {} in items set {} effects", set->spells[x], setid);
103 break;
104 }
105
106 // spell casted only if fit form requirement, in other case will casted at form change
107 if (sScriptMgr->CanItemApplyEquipSpell(player, item))
108 {
109 player->ApplyEquipSpell(spellInfo, nullptr, true);
110 }
111
112 eff->spells[y] = spellInfo;
113 break;
114 }
115 }
116 }
117}
std::uint32_t uint32
Definition: Define.h:108
#define LOG_ERROR(filterType__,...)
Definition: Log.h:157
DBCStorage< ItemSetEntry > sItemSetStore(ItemSetEntryfmt)
#define sScriptMgr
Definition: ScriptMgr.h:698
#define sSpellMgr
Definition: SpellMgr.h:825
#define MAX_ITEM_SET_SPELLS
Definition: DBCStructure.h:1220
Definition: Item.h:32
uint32 item_count
Definition: Item.h:34
uint32 setid
Definition: Item.h:33
SpellInfo const * spells[8]
Definition: Item.h:35
ItemTemplate const * GetTemplate() const
Definition: Item.cpp:545
Definition: ItemTemplate.h:628
uint32 ItemSet
Definition: ItemTemplate.h:684
uint32 ItemId
Definition: ItemTemplate.h:629
uint16 GetSkillValue(uint32 skill) const
Definition: Player.cpp:5367
std::vector< ItemSetEffect * > ItemSetEff
Definition: Player.h:2202
void ApplyEquipSpell(SpellInfo const *spellInfo, Item *item, bool apply, bool form_change=false)
Definition: Player.cpp:7060
Definition: SpellInfo.h:314
uint32 Id
Definition: SpellInfo.h:318
Definition: DBCStructure.h:1223
uint32 required_skill_value
Definition: DBCStructure.h:1232
uint32 items_to_triggerspell[MAX_ITEM_SET_SPELLS]
Definition: DBCStructure.h:1230
uint32 spells[MAX_ITEM_SET_SPELLS]
Definition: DBCStructure.h:1229
uint32 required_skill_id
Definition: DBCStructure.h:1231

References Player::ApplyEquipSpell(), Player::GetSkillValue(), Item::GetTemplate(), SpellInfo::Id, ItemSetEffect::item_count, ItemTemplate::ItemId, ItemSetEntry::items_to_triggerspell, ItemTemplate::ItemSet, Player::ItemSetEff, LOG_ERROR, MAX_ITEM_SET_SPELLS, ItemSetEntry::required_skill_id, ItemSetEntry::required_skill_value, ItemSetEffect::setid, sItemSetStore, ItemSetEffect::spells, ItemSetEntry::spells, sScriptMgr, and sSpellMgr.

Referenced by Player::_ApplyAllItemMods(), and Player::EquipItem().

◆ ItemCanGoIntoBag()

bool ItemCanGoIntoBag ( ItemTemplate const *  pProto,
ItemTemplate const *  pBagProto 
)
178{
179 if (!pProto || !pBagProto)
180 return false;
181
182 switch (pBagProto->Class)
183 {
185 {
186 if (pBagProto->SubClass == ITEM_SUBCLASS_CONTAINER)
187 {
188 return true;
189 }
190 else
191 {
192 if (pProto->Class == ITEM_CLASS_CONTAINER)
193 {
194 return false;
195 }
196
197 switch (pBagProto->SubClass)
198 {
200 if (!(pProto->BagFamily & BAG_FAMILY_MASK_SOUL_SHARDS))
201 return false;
202 return true;
204 if (!(pProto->BagFamily & BAG_FAMILY_MASK_HERBS))
205 return false;
206 return true;
208 if (!(pProto->BagFamily & BAG_FAMILY_MASK_ENCHANTING_SUPP))
209 return false;
210 return true;
212 if (!(pProto->BagFamily & BAG_FAMILY_MASK_MINING_SUPP))
213 return false;
214 return true;
216 if (!(pProto->BagFamily & BAG_FAMILY_MASK_ENGINEERING_SUPP))
217 return false;
218 return true;
220 if (!(pProto->BagFamily & BAG_FAMILY_MASK_GEMS))
221 return false;
222 return true;
224 if (!(pProto->BagFamily & BAG_FAMILY_MASK_LEATHERWORKING_SUPP))
225 return false;
226 return true;
228 if (!(pProto->BagFamily & BAG_FAMILY_MASK_INSCRIPTION_SUPP))
229 return false;
230 return true;
231 default:
232 return false;
233 }
234 }
235 }
237 {
238 if (pProto->Class == ITEM_CLASS_QUIVER)
239 {
240 return false;
241 }
242
243 switch (pBagProto->SubClass)
244 {
246 if (!(pProto->BagFamily & BAG_FAMILY_MASK_ARROWS))
247 return false;
248 return true;
250 if (!(pProto->BagFamily & BAG_FAMILY_MASK_BULLETS))
251 return false;
252 return true;
253 default:
254 return false;
255 }
256 }
257 }
258
259 return false;
260}
@ BAG_FAMILY_MASK_MINING_SUPP
Definition: ItemTemplate.h:246
@ BAG_FAMILY_MASK_HERBS
Definition: ItemTemplate.h:241
@ BAG_FAMILY_MASK_ENCHANTING_SUPP
Definition: ItemTemplate.h:242
@ BAG_FAMILY_MASK_SOUL_SHARDS
Definition: ItemTemplate.h:238
@ BAG_FAMILY_MASK_INSCRIPTION_SUPP
Definition: ItemTemplate.h:240
@ BAG_FAMILY_MASK_GEMS
Definition: ItemTemplate.h:245
@ BAG_FAMILY_MASK_ARROWS
Definition: ItemTemplate.h:236
@ BAG_FAMILY_MASK_BULLETS
Definition: ItemTemplate.h:237
@ BAG_FAMILY_MASK_ENGINEERING_SUPP
Definition: ItemTemplate.h:243
@ BAG_FAMILY_MASK_LEATHERWORKING_SUPP
Definition: ItemTemplate.h:239
@ ITEM_SUBCLASS_CONTAINER
Definition: ItemTemplate.h:338
@ ITEM_SUBCLASS_INSCRIPTION_CONTAINER
Definition: ItemTemplate.h:346
@ ITEM_SUBCLASS_LEATHERWORKING_CONTAINER
Definition: ItemTemplate.h:345
@ ITEM_SUBCLASS_GEM_CONTAINER
Definition: ItemTemplate.h:343
@ ITEM_SUBCLASS_SOUL_CONTAINER
Definition: ItemTemplate.h:339
@ ITEM_SUBCLASS_ENCHANTING_CONTAINER
Definition: ItemTemplate.h:341
@ ITEM_SUBCLASS_MINING_CONTAINER
Definition: ItemTemplate.h:344
@ ITEM_SUBCLASS_HERB_CONTAINER
Definition: ItemTemplate.h:340
@ ITEM_SUBCLASS_ENGINEERING_CONTAINER
Definition: ItemTemplate.h:342
@ ITEM_SUBCLASS_QUIVER
Definition: ItemTemplate.h:489
@ ITEM_SUBCLASS_AMMO_POUCH
Definition: ItemTemplate.h:490
@ ITEM_CLASS_QUIVER
Definition: ItemTemplate.h:311
@ ITEM_CLASS_CONTAINER
Definition: ItemTemplate.h:301

References BAG_FAMILY_MASK_ARROWS, BAG_FAMILY_MASK_BULLETS, BAG_FAMILY_MASK_ENCHANTING_SUPP, BAG_FAMILY_MASK_ENGINEERING_SUPP, BAG_FAMILY_MASK_GEMS, BAG_FAMILY_MASK_HERBS, BAG_FAMILY_MASK_INSCRIPTION_SUPP, BAG_FAMILY_MASK_LEATHERWORKING_SUPP, BAG_FAMILY_MASK_MINING_SUPP, BAG_FAMILY_MASK_SOUL_SHARDS, ItemTemplate::BagFamily, ItemTemplate::Class, ITEM_CLASS_CONTAINER, ITEM_CLASS_QUIVER, ITEM_SUBCLASS_AMMO_POUCH, ITEM_SUBCLASS_CONTAINER, ITEM_SUBCLASS_ENCHANTING_CONTAINER, ITEM_SUBCLASS_ENGINEERING_CONTAINER, ITEM_SUBCLASS_GEM_CONTAINER, ITEM_SUBCLASS_HERB_CONTAINER, ITEM_SUBCLASS_INSCRIPTION_CONTAINER, ITEM_SUBCLASS_LEATHERWORKING_CONTAINER, ITEM_SUBCLASS_MINING_CONTAINER, ITEM_SUBCLASS_QUIVER, ITEM_SUBCLASS_SOUL_CONTAINER, and ItemTemplate::SubClass.

Referenced by Player::CanStoreItem_InBag(), Player::CanStoreItem_InSpecificSlot(), Player::CanStoreItems(), and Player::SwapItem().

◆ RemoveItemsSetItem()

void RemoveItemsSetItem ( Player player,
ItemTemplate const *  proto 
)
120{
121 uint32 setid = proto->ItemSet;
122
123 ItemSetEntry const* set = sItemSetStore.LookupEntry(setid);
124
125 if (!set)
126 {
127 LOG_ERROR("sql.sql", "Item set #{} for item #{} not found, mods not removed.", setid, proto->ItemId);
128 return;
129 }
130
131 ItemSetEffect* eff = nullptr;
132 size_t setindex = 0;
133 for (; setindex < player->ItemSetEff.size(); setindex++)
134 {
135 if (player->ItemSetEff[setindex] && player->ItemSetEff[setindex]->setid == setid)
136 {
137 eff = player->ItemSetEff[setindex];
138 break;
139 }
140 }
141
142 // can be in case now enough skill requirement for set appling but set has been appliend when skill requirement not enough
143 if (!eff)
144 return;
145
146 --eff->item_count;
147
148 for (uint32 x = 0; x < MAX_ITEM_SET_SPELLS; x++)
149 {
150 if (!set->spells[x])
151 continue;
152
153 // enough for spell
154 if (set->items_to_triggerspell[x] <= eff->item_count)
155 continue;
156
157 for (uint32 z = 0; z < MAX_ITEM_SET_SPELLS; z++)
158 {
159 if (eff->spells[z] && eff->spells[z]->Id == set->spells[x])
160 {
161 // spell can be not active if not fit form requirement
162 player->ApplyEquipSpell(eff->spells[z], nullptr, false);
163 eff->spells[z] = nullptr;
164 break;
165 }
166 }
167 }
168
169 if (!eff->item_count) //all items of a set were removed
170 {
171 ASSERT(eff == player->ItemSetEff[setindex]);
172 delete eff;
173 player->ItemSetEff[setindex] = nullptr;
174 }
175}
#define ASSERT
Definition: Errors.h:68

References Player::ApplyEquipSpell(), ASSERT, SpellInfo::Id, ItemSetEffect::item_count, ItemTemplate::ItemId, ItemSetEntry::items_to_triggerspell, ItemTemplate::ItemSet, Player::ItemSetEff, LOG_ERROR, MAX_ITEM_SET_SPELLS, sItemSetStore, ItemSetEffect::spells, and ItemSetEntry::spells.

Referenced by Player::_RemoveAllItemMods(), Player::DestroyItem(), and Player::RemoveItem().