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 "WorldPacket.h"
#include "WorldSession.h"
#include "Tokenize.h"
#include "StringConvert.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 
)
35{
36 ItemTemplate const* proto = item->GetTemplate();
37 uint32 setid = proto->ItemSet;
38
39 ItemSetEntry const* set = sItemSetStore.LookupEntry(setid);
40
41 if (!set)
42 {
43 LOG_ERROR("sql.sql", "Item set {} for item (id {}) not found, mods not applied.", setid, proto->ItemId);
44 return;
45 }
46
48 return;
49
50 ItemSetEffect* eff = nullptr;
51
52 for (size_t x = 0; x < player->ItemSetEff.size(); ++x)
53 {
54 if (player->ItemSetEff[x] && player->ItemSetEff[x]->setid == setid)
55 {
56 eff = player->ItemSetEff[x];
57 break;
58 }
59 }
60
61 if (!eff)
62 {
63 eff = new ItemSetEffect();
64 eff->setid = setid;
65
66 size_t x = 0;
67 for (; x < player->ItemSetEff.size(); ++x)
68 if (!player->ItemSetEff[x])
69 break;
70
71 if (x < player->ItemSetEff.size())
72 player->ItemSetEff[x] = eff;
73 else
74 player->ItemSetEff.push_back(eff);
75 }
76
77 ++eff->item_count;
78
79 for (uint32 x = 0; x < MAX_ITEM_SET_SPELLS; ++x)
80 {
81 if (!set->spells [x])
82 continue;
83 //not enough for spell
84 if (set->items_to_triggerspell[x] > eff->item_count)
85 continue;
86
87 uint32 z = 0;
88 for (; z < MAX_ITEM_SET_SPELLS; ++z)
89 if (eff->spells[z] && eff->spells[z]->Id == set->spells[x])
90 break;
91
92 if (z < MAX_ITEM_SET_SPELLS)
93 continue;
94
95 //new spell
96 for (uint32 y = 0; y < MAX_ITEM_SET_SPELLS; ++y)
97 {
98 if (!eff->spells[y]) // free slot
99 {
100 SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(set->spells[x]);
101 if (!spellInfo)
102 {
103 LOG_ERROR("entities.item", "WORLD: unknown spell id {} in items set {} effects", set->spells[x], setid);
104 break;
105 }
106
107 // spell casted only if fit form requirement, in other case will casted at form change
108 if (sScriptMgr->CanItemApplyEquipSpell(player, item))
109 {
110 player->ApplyEquipSpell(spellInfo, nullptr, true);
111 }
112
113 eff->spells[y] = spellInfo;
114 break;
115 }
116 }
117 }
118}
std::uint32_t uint32
Definition: Define.h:108
#define LOG_ERROR(filterType__,...)
Definition: Log.h:159
DBCStorage< ItemSetEntry > sItemSetStore(ItemSetEntryfmt)
#define sScriptMgr
Definition: ScriptMgr.h:2762
#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:546
Definition: ItemTemplate.h:628
uint32 ItemSet
Definition: ItemTemplate.h:684
uint32 ItemId
Definition: ItemTemplate.h:629
uint16 GetSkillValue(uint32 skill) const
Definition: Player.cpp:5362
std::vector< ItemSetEffect * > ItemSetEff
Definition: Player.h:2199
void ApplyEquipSpell(SpellInfo const *spellInfo, Item *item, bool apply, bool form_change=false)
Definition: Player.cpp:7055
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 
)
179{
180 if (!pProto || !pBagProto)
181 return false;
182
183 switch (pBagProto->Class)
184 {
186 {
187 if (pBagProto->SubClass == ITEM_SUBCLASS_CONTAINER)
188 {
189 return true;
190 }
191 else
192 {
193 if (pProto->Class == ITEM_CLASS_CONTAINER)
194 {
195 return false;
196 }
197
198 switch (pBagProto->SubClass)
199 {
201 if (!(pProto->BagFamily & BAG_FAMILY_MASK_SOUL_SHARDS))
202 return false;
203 return true;
205 if (!(pProto->BagFamily & BAG_FAMILY_MASK_HERBS))
206 return false;
207 return true;
209 if (!(pProto->BagFamily & BAG_FAMILY_MASK_ENCHANTING_SUPP))
210 return false;
211 return true;
213 if (!(pProto->BagFamily & BAG_FAMILY_MASK_MINING_SUPP))
214 return false;
215 return true;
217 if (!(pProto->BagFamily & BAG_FAMILY_MASK_ENGINEERING_SUPP))
218 return false;
219 return true;
221 if (!(pProto->BagFamily & BAG_FAMILY_MASK_GEMS))
222 return false;
223 return true;
225 if (!(pProto->BagFamily & BAG_FAMILY_MASK_LEATHERWORKING_SUPP))
226 return false;
227 return true;
229 if (!(pProto->BagFamily & BAG_FAMILY_MASK_INSCRIPTION_SUPP))
230 return false;
231 return true;
232 default:
233 return false;
234 }
235 }
236 }
238 {
239 if (pProto->Class == ITEM_CLASS_QUIVER)
240 {
241 return false;
242 }
243
244 switch (pBagProto->SubClass)
245 {
247 if (!(pProto->BagFamily & BAG_FAMILY_MASK_ARROWS))
248 return false;
249 return true;
251 if (!(pProto->BagFamily & BAG_FAMILY_MASK_BULLETS))
252 return false;
253 return true;
254 default:
255 return false;
256 }
257 }
258 }
259
260 return false;
261}
@ 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 
)
121{
122 uint32 setid = proto->ItemSet;
123
124 ItemSetEntry const* set = sItemSetStore.LookupEntry(setid);
125
126 if (!set)
127 {
128 LOG_ERROR("sql.sql", "Item set #{} for item #{} not found, mods not removed.", setid, proto->ItemId);
129 return;
130 }
131
132 ItemSetEffect* eff = nullptr;
133 size_t setindex = 0;
134 for (; setindex < player->ItemSetEff.size(); setindex++)
135 {
136 if (player->ItemSetEff[setindex] && player->ItemSetEff[setindex]->setid == setid)
137 {
138 eff = player->ItemSetEff[setindex];
139 break;
140 }
141 }
142
143 // can be in case now enough skill requirement for set appling but set has been appliend when skill requirement not enough
144 if (!eff)
145 return;
146
147 --eff->item_count;
148
149 for (uint32 x = 0; x < MAX_ITEM_SET_SPELLS; x++)
150 {
151 if (!set->spells[x])
152 continue;
153
154 // enough for spell
155 if (set->items_to_triggerspell[x] <= eff->item_count)
156 continue;
157
158 for (uint32 z = 0; z < MAX_ITEM_SET_SPELLS; z++)
159 {
160 if (eff->spells[z] && eff->spells[z]->Id == set->spells[x])
161 {
162 // spell can be not active if not fit form requirement
163 player->ApplyEquipSpell(eff->spells[z], nullptr, false);
164 eff->spells[z] = nullptr;
165 break;
166 }
167 }
168 }
169
170 if (!eff->item_count) //all items of a set were removed
171 {
172 ASSERT(eff == player->ItemSetEff[setindex]);
173 delete eff;
174 player->ItemSetEff[setindex] = nullptr;
175 }
176}
#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().