AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
Item.cpp File Reference
#include "Item.h"
#include "Common.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 
)
33{
34 ItemTemplate const* proto = item->GetTemplate();
35 uint32 setid = proto->ItemSet;
36
37 ItemSetEntry const* set = sItemSetStore.LookupEntry(setid);
38
39 if (!set)
40 {
41 LOG_ERROR("sql.sql", "Item set {} for item (id {}) not found, mods not applied.", setid, proto->ItemId);
42 return;
43 }
44
46 return;
47
48 ItemSetEffect* eff = nullptr;
49
50 for (std::size_t x = 0; x < player->ItemSetEff.size(); ++x)
51 {
52 if (player->ItemSetEff[x] && player->ItemSetEff[x]->setid == setid)
53 {
54 eff = player->ItemSetEff[x];
55 break;
56 }
57 }
58
59 if (!eff)
60 {
61 eff = new ItemSetEffect();
62 eff->setid = setid;
63
64 std::size_t x = 0;
65 for (; x < player->ItemSetEff.size(); ++x)
66 if (!player->ItemSetEff[x])
67 break;
68
69 if (x < player->ItemSetEff.size())
70 player->ItemSetEff[x] = eff;
71 else
72 player->ItemSetEff.push_back(eff);
73 }
74
75 ++eff->item_count;
76
77 for (uint32 x = 0; x < MAX_ITEM_SET_SPELLS; ++x)
78 {
79 if (!set->spells [x])
80 continue;
81 //not enough for spell
82 if (set->items_to_triggerspell[x] > eff->item_count)
83 continue;
84
85 uint32 z = 0;
86 for (; z < MAX_ITEM_SET_SPELLS; ++z)
87 if (eff->spells[z] && eff->spells[z]->Id == set->spells[x])
88 break;
89
90 if (z < MAX_ITEM_SET_SPELLS)
91 continue;
92
93 //new spell
94 for (uint32 y = 0; y < MAX_ITEM_SET_SPELLS; ++y)
95 {
96 if (!eff->spells[y]) // free slot
97 {
98 SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(set->spells[x]);
99 if (!spellInfo)
100 {
101 LOG_ERROR("entities.item", "WORLD: unknown spell id {} in items set {} effects", set->spells[x], setid);
102 break;
103 }
104
105 // spell casted only if fit form requirement, in other case will casted at form change
106 if (sScriptMgr->CanItemApplyEquipSpell(player, item))
107 {
108 player->ApplyEquipSpell(spellInfo, nullptr, true);
109 }
110
111 eff->spells[y] = spellInfo;
112 break;
113 }
114 }
115 }
116}
#define LOG_ERROR(filterType__,...)
Definition: Log.h:157
std::uint32_t uint32
Definition: Define.h:107
#define MAX_ITEM_SET_SPELLS
Definition: DBCStructure.h:1228
#define sSpellMgr
Definition: SpellMgr.h:825
DBCStorage< ItemSetEntry > sItemSetStore(ItemSetEntryfmt)
#define sScriptMgr
Definition: ScriptMgr.h:709
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:544
Definition: ItemTemplate.h:619
uint32 ItemSet
Definition: ItemTemplate.h:675
uint32 ItemId
Definition: ItemTemplate.h:620
uint16 GetSkillValue(uint32 skill) const
Definition: Player.cpp:5468
std::vector< ItemSetEffect * > ItemSetEff
Definition: Player.h:2240
void ApplyEquipSpell(SpellInfo const *spellInfo, Item *item, bool apply, bool form_change=false)
Definition: Player.cpp:7180
Definition: SpellInfo.h:316
uint32 Id
Definition: SpellInfo.h:320
Definition: DBCStructure.h:1231
uint32 required_skill_value
Definition: DBCStructure.h:1240
uint32 items_to_triggerspell[MAX_ITEM_SET_SPELLS]
Definition: DBCStructure.h:1238
uint32 spells[MAX_ITEM_SET_SPELLS]
Definition: DBCStructure.h:1237
uint32 required_skill_id
Definition: DBCStructure.h:1239

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 
)
177{
178 if (!pProto || !pBagProto)
179 return false;
180
181 switch (pBagProto->Class)
182 {
184 {
185 if (pBagProto->SubClass == ITEM_SUBCLASS_CONTAINER)
186 {
187 return true;
188 }
189 else
190 {
191 if (pProto->Class == ITEM_CLASS_CONTAINER)
192 {
193 return false;
194 }
195
196 switch (pBagProto->SubClass)
197 {
199 if (!(pProto->BagFamily & BAG_FAMILY_MASK_SOUL_SHARDS))
200 return false;
201 return true;
203 if (!(pProto->BagFamily & BAG_FAMILY_MASK_HERBS))
204 return false;
205 return true;
207 if (!(pProto->BagFamily & BAG_FAMILY_MASK_ENCHANTING_SUPP))
208 return false;
209 return true;
211 if (!(pProto->BagFamily & BAG_FAMILY_MASK_MINING_SUPP))
212 return false;
213 return true;
215 if (!(pProto->BagFamily & BAG_FAMILY_MASK_ENGINEERING_SUPP))
216 return false;
217 return true;
219 if (!(pProto->BagFamily & BAG_FAMILY_MASK_GEMS))
220 return false;
221 return true;
223 if (!(pProto->BagFamily & BAG_FAMILY_MASK_LEATHERWORKING_SUPP))
224 return false;
225 return true;
227 if (!(pProto->BagFamily & BAG_FAMILY_MASK_INSCRIPTION_SUPP))
228 return false;
229 return true;
230 default:
231 return false;
232 }
233 }
234 }
236 {
237 if (pProto->Class == ITEM_CLASS_QUIVER)
238 {
239 return false;
240 }
241
242 switch (pBagProto->SubClass)
243 {
245 if (!(pProto->BagFamily & BAG_FAMILY_MASK_ARROWS))
246 return false;
247 return true;
249 if (!(pProto->BagFamily & BAG_FAMILY_MASK_BULLETS))
250 return false;
251 return true;
252 default:
253 return false;
254 }
255 }
256 }
257
258 return false;
259}
@ BAG_FAMILY_MASK_MINING_SUPP
Definition: ItemTemplate.h:237
@ BAG_FAMILY_MASK_HERBS
Definition: ItemTemplate.h:232
@ BAG_FAMILY_MASK_ENCHANTING_SUPP
Definition: ItemTemplate.h:233
@ BAG_FAMILY_MASK_SOUL_SHARDS
Definition: ItemTemplate.h:229
@ BAG_FAMILY_MASK_INSCRIPTION_SUPP
Definition: ItemTemplate.h:231
@ BAG_FAMILY_MASK_GEMS
Definition: ItemTemplate.h:236
@ BAG_FAMILY_MASK_ARROWS
Definition: ItemTemplate.h:227
@ BAG_FAMILY_MASK_BULLETS
Definition: ItemTemplate.h:228
@ BAG_FAMILY_MASK_ENGINEERING_SUPP
Definition: ItemTemplate.h:234
@ BAG_FAMILY_MASK_LEATHERWORKING_SUPP
Definition: ItemTemplate.h:230
@ ITEM_SUBCLASS_CONTAINER
Definition: ItemTemplate.h:329
@ ITEM_SUBCLASS_INSCRIPTION_CONTAINER
Definition: ItemTemplate.h:337
@ ITEM_SUBCLASS_LEATHERWORKING_CONTAINER
Definition: ItemTemplate.h:336
@ ITEM_SUBCLASS_GEM_CONTAINER
Definition: ItemTemplate.h:334
@ ITEM_SUBCLASS_SOUL_CONTAINER
Definition: ItemTemplate.h:330
@ ITEM_SUBCLASS_ENCHANTING_CONTAINER
Definition: ItemTemplate.h:332
@ ITEM_SUBCLASS_MINING_CONTAINER
Definition: ItemTemplate.h:335
@ ITEM_SUBCLASS_HERB_CONTAINER
Definition: ItemTemplate.h:331
@ ITEM_SUBCLASS_ENGINEERING_CONTAINER
Definition: ItemTemplate.h:333
@ ITEM_SUBCLASS_QUIVER
Definition: ItemTemplate.h:480
@ ITEM_SUBCLASS_AMMO_POUCH
Definition: ItemTemplate.h:481
@ ITEM_CLASS_QUIVER
Definition: ItemTemplate.h:302
@ ITEM_CLASS_CONTAINER
Definition: ItemTemplate.h:292

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