[7915] Implement more stricted checks and limitations at loading creature addon data.
[getmangos.git] / src / game / ItemHandler.cpp
blob61c377b339a9a6aa0085eb7bef9696f378f04ca5
1 /*
2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "Common.h"
20 #include "WorldPacket.h"
21 #include "WorldSession.h"
22 #include "Opcodes.h"
23 #include "Log.h"
24 #include "ObjectMgr.h"
25 #include "Player.h"
26 #include "Item.h"
27 #include "UpdateData.h"
28 #include "ObjectAccessor.h"
30 void WorldSession::HandleSplitItemOpcode( WorldPacket & recv_data )
32 CHECK_PACKET_SIZE(recv_data,1+1+1+1+1);
34 //sLog.outDebug("WORLD: CMSG_SPLIT_ITEM");
35 uint8 srcbag, srcslot, dstbag, dstslot, count;
37 recv_data >> srcbag >> srcslot >> dstbag >> dstslot >> count;
38 //sLog.outDebug("STORAGE: receive srcbag = %u, srcslot = %u, dstbag = %u, dstslot = %u, count = %u", srcbag, srcslot, dstbag, dstslot, count);
40 uint16 src = ( (srcbag << 8) | srcslot );
41 uint16 dst = ( (dstbag << 8) | dstslot );
43 if(src==dst)
44 return;
46 if (count==0)
47 return; //check count - if zero it's fake packet
49 if(!_player->IsValidPos(srcbag,srcslot))
51 _player->SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND, NULL, NULL );
52 return;
55 if(!_player->IsValidPos(dstbag,dstslot))
57 _player->SendEquipError( EQUIP_ERR_ITEM_DOESNT_GO_TO_SLOT, NULL, NULL );
58 return;
61 _player->SplitItem( src, dst, count );
64 void WorldSession::HandleSwapInvItemOpcode( WorldPacket & recv_data )
66 CHECK_PACKET_SIZE(recv_data,1+1);
68 //sLog.outDebug("WORLD: CMSG_SWAP_INV_ITEM");
69 uint8 srcslot, dstslot;
71 recv_data >> srcslot >> dstslot;
72 //sLog.outDebug("STORAGE: receive srcslot = %u, dstslot = %u", srcslot, dstslot);
74 // prevent attempt swap same item to current position generated by client at special checting sequence
75 if(srcslot==dstslot)
76 return;
78 if(!_player->IsValidPos(INVENTORY_SLOT_BAG_0,srcslot))
80 _player->SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND, NULL, NULL );
81 return;
84 if(!_player->IsValidPos(INVENTORY_SLOT_BAG_0,dstslot))
86 _player->SendEquipError( EQUIP_ERR_ITEM_DOESNT_GO_TO_SLOT, NULL, NULL );
87 return;
90 uint16 src = ( (INVENTORY_SLOT_BAG_0 << 8) | srcslot );
91 uint16 dst = ( (INVENTORY_SLOT_BAG_0 << 8) | dstslot );
93 _player->SwapItem( src, dst );
96 void WorldSession::HandleAutoEquipItemSlotOpcode( WorldPacket & recv_data )
98 CHECK_PACKET_SIZE(recv_data,8+1);
99 uint64 itemguid;
100 uint8 dstslot;
101 recv_data >> itemguid >> dstslot;
103 // cheating attempt, client should never send opcode in that case
104 if(!Player::IsEquipmentPos(INVENTORY_SLOT_BAG_0, dstslot))
105 return;
107 Item* item = _player->GetItemByGuid(itemguid);
108 uint16 dstpos = dstslot | (INVENTORY_SLOT_BAG_0 << 8);
110 if(!item || item->GetPos() == dstpos)
111 return;
113 _player->SwapItem(item->GetPos(), dstpos);
116 void WorldSession::HandleSwapItem( WorldPacket & recv_data )
118 CHECK_PACKET_SIZE(recv_data,1+1+1+1);
120 //sLog.outDebug("WORLD: CMSG_SWAP_ITEM");
121 uint8 dstbag, dstslot, srcbag, srcslot;
123 recv_data >> dstbag >> dstslot >> srcbag >> srcslot ;
124 //sLog.outDebug("STORAGE: receive srcbag = %u, srcslot = %u, dstbag = %u, dstslot = %u", srcbag, srcslot, dstbag, dstslot);
126 uint16 src = ( (srcbag << 8) | srcslot );
127 uint16 dst = ( (dstbag << 8) | dstslot );
129 // prevent attempt swap same item to current position generated by client at special checting sequence
130 if(src==dst)
131 return;
133 if(!_player->IsValidPos(srcbag,srcslot))
135 _player->SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND, NULL, NULL );
136 return;
139 if(!_player->IsValidPos(dstbag,dstslot))
141 _player->SendEquipError( EQUIP_ERR_ITEM_DOESNT_GO_TO_SLOT, NULL, NULL );
142 return;
145 _player->SwapItem( src, dst );
148 void WorldSession::HandleAutoEquipItemOpcode( WorldPacket & recv_data )
150 CHECK_PACKET_SIZE(recv_data,1+1);
152 //sLog.outDebug("WORLD: CMSG_AUTOEQUIP_ITEM");
153 uint8 srcbag, srcslot;
155 recv_data >> srcbag >> srcslot;
156 //sLog.outDebug("STORAGE: receive srcbag = %u, srcslot = %u", srcbag, srcslot);
158 Item *pSrcItem = _player->GetItemByPos( srcbag, srcslot );
159 if( !pSrcItem )
160 return; // only at cheat
162 if(pSrcItem->m_lootGenerated) // prevent swap looting item
164 //best error message found for attempting to swap while looting
165 _player->SendEquipError( EQUIP_ERR_CANT_DO_RIGHT_NOW, pSrcItem, NULL );
166 return;
169 uint16 dest;
170 uint8 msg = _player->CanEquipItem( NULL_SLOT, dest, pSrcItem, !pSrcItem->IsBag() );
171 if( msg != EQUIP_ERR_OK )
173 _player->SendEquipError( msg, pSrcItem, NULL );
174 return;
177 uint16 src = pSrcItem->GetPos();
178 if(dest==src) // prevent equip in same slot, only at cheat
179 return;
181 Item *pDstItem = _player->GetItemByPos( dest );
182 if( !pDstItem ) // empty slot, simple case
184 _player->RemoveItem( srcbag, srcslot, true );
185 _player->EquipItem( dest, pSrcItem, true );
186 _player->AutoUnequipOffhandIfNeed();
188 else // have currently equipped item, not simple case
190 uint8 dstbag = pDstItem->GetBagSlot();
191 uint8 dstslot = pDstItem->GetSlot();
193 msg = _player->CanUnequipItem( dest, !pSrcItem->IsBag() );
194 if( msg != EQUIP_ERR_OK )
196 _player->SendEquipError( msg, pDstItem, NULL );
197 return;
200 // check dest->src move possibility
201 ItemPosCountVec sSrc;
202 uint16 eSrc = 0;
203 if( _player->IsInventoryPos( src ) )
205 msg = _player->CanStoreItem( srcbag, srcslot, sSrc, pDstItem, true );
206 if( msg != EQUIP_ERR_OK )
207 msg = _player->CanStoreItem( srcbag, NULL_SLOT, sSrc, pDstItem, true );
208 if( msg != EQUIP_ERR_OK )
209 msg = _player->CanStoreItem( NULL_BAG, NULL_SLOT, sSrc, pDstItem, true );
211 else if( _player->IsBankPos( src ) )
213 msg = _player->CanBankItem( srcbag, srcslot, sSrc, pDstItem, true );
214 if( msg != EQUIP_ERR_OK )
215 msg = _player->CanBankItem( srcbag, NULL_SLOT, sSrc, pDstItem, true );
216 if( msg != EQUIP_ERR_OK )
217 msg = _player->CanBankItem( NULL_BAG, NULL_SLOT, sSrc, pDstItem, true );
219 else if( _player->IsEquipmentPos( src ) )
221 msg = _player->CanEquipItem( srcslot, eSrc, pDstItem, true);
222 if( msg == EQUIP_ERR_OK )
223 msg = _player->CanUnequipItem( eSrc, true);
226 if( msg != EQUIP_ERR_OK )
228 _player->SendEquipError( msg, pDstItem, pSrcItem );
229 return;
232 // now do moves, remove...
233 _player->RemoveItem(dstbag, dstslot, false);
234 _player->RemoveItem(srcbag, srcslot, false);
236 // add to dest
237 _player->EquipItem(dest, pSrcItem, true);
239 // add to src
240 if( _player->IsInventoryPos( src ) )
241 _player->StoreItem(sSrc, pDstItem, true);
242 else if( _player->IsBankPos( src ) )
243 _player->BankItem(sSrc, pDstItem, true);
244 else if( _player->IsEquipmentPos( src ) )
245 _player->EquipItem(eSrc, pDstItem, true);
247 _player->AutoUnequipOffhandIfNeed();
251 void WorldSession::HandleDestroyItemOpcode( WorldPacket & recv_data )
253 CHECK_PACKET_SIZE(recv_data,1+1+1+1+1+1);
255 //sLog.outDebug("WORLD: CMSG_DESTROYITEM");
256 uint8 bag, slot, count, data1, data2, data3;
258 recv_data >> bag >> slot >> count >> data1 >> data2 >> data3;
259 //sLog.outDebug("STORAGE: receive bag = %u, slot = %u, count = %u", bag, slot, count);
261 uint16 pos = (bag << 8) | slot;
263 // prevent drop unequipable items (in combat, for example) and non-empty bags
264 if(_player->IsEquipmentPos(pos) || _player->IsBagPos(pos))
266 uint8 msg = _player->CanUnequipItem( pos, false );
267 if( msg != EQUIP_ERR_OK )
269 _player->SendEquipError( msg, _player->GetItemByPos(pos), NULL );
270 return;
274 Item *pItem = _player->GetItemByPos( bag, slot );
275 if(!pItem)
277 _player->SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND, NULL, NULL );
278 return;
281 if(count)
283 uint32 i_count = count;
284 _player->DestroyItemCount( pItem, i_count, true );
286 else
287 _player->DestroyItem( bag, slot, true );
290 // Only _static_ data send in this packet !!!
291 void WorldSession::HandleItemQuerySingleOpcode( WorldPacket & recv_data )
293 CHECK_PACKET_SIZE(recv_data, 4);
295 //sLog.outDebug("WORLD: CMSG_ITEM_QUERY_SINGLE");
296 uint32 item;
297 recv_data >> item;
299 sLog.outDetail("STORAGE: Item Query = %u", item);
301 ItemPrototype const *pProto = objmgr.GetItemPrototype( item );
302 if( pProto )
304 std::string Name = pProto->Name1;
305 std::string Description = pProto->Description;
307 int loc_idx = GetSessionDbLocaleIndex();
308 if ( loc_idx >= 0 )
310 ItemLocale const *il = objmgr.GetItemLocale(pProto->ItemId);
311 if (il)
313 if (il->Name.size() > size_t(loc_idx) && !il->Name[loc_idx].empty())
314 Name = il->Name[loc_idx];
315 if (il->Description.size() > size_t(loc_idx) && !il->Description[loc_idx].empty())
316 Description = il->Description[loc_idx];
319 // guess size
320 WorldPacket data( SMSG_ITEM_QUERY_SINGLE_RESPONSE, 600);
321 data << pProto->ItemId;
322 data << pProto->Class;
323 data << pProto->SubClass;
324 data << int32(pProto->Unk0); // new 2.0.3, not exist in wdb cache?
325 data << Name;
326 data << uint8(0x00); //pProto->Name2; // blizz not send name there, just uint8(0x00); <-- \0 = empty string = empty name...
327 data << uint8(0x00); //pProto->Name3; // blizz not send name there, just uint8(0x00);
328 data << uint8(0x00); //pProto->Name4; // blizz not send name there, just uint8(0x00);
329 data << pProto->DisplayInfoID;
330 data << pProto->Quality;
331 data << pProto->Flags;
332 data << pProto->BuyPrice;
333 data << pProto->SellPrice;
334 data << pProto->InventoryType;
335 data << pProto->AllowableClass;
336 data << pProto->AllowableRace;
337 data << pProto->ItemLevel;
338 data << pProto->RequiredLevel;
339 data << pProto->RequiredSkill;
340 data << pProto->RequiredSkillRank;
341 data << pProto->RequiredSpell;
342 data << pProto->RequiredHonorRank;
343 data << pProto->RequiredCityRank;
344 data << pProto->RequiredReputationFaction;
345 data << pProto->RequiredReputationRank;
346 data << int32(pProto->MaxCount);
347 data << int32(pProto->Stackable);
348 data << pProto->ContainerSlots;
349 data << pProto->StatsCount; // item stats count
350 for(uint32 i = 0; i < pProto->StatsCount; ++i)
352 data << pProto->ItemStat[i].ItemStatType;
353 data << pProto->ItemStat[i].ItemStatValue;
355 data << pProto->ScalingStatDistribution; // scaling stats distribution
356 data << pProto->ScalingStatValue; // some kind of flags used to determine stat values column
357 for(int i = 0; i < MAX_ITEM_PROTO_DAMAGES; ++i)
359 data << pProto->Damage[i].DamageMin;
360 data << pProto->Damage[i].DamageMax;
361 data << pProto->Damage[i].DamageType;
364 // resistances (7)
365 data << pProto->Armor;
366 data << pProto->HolyRes;
367 data << pProto->FireRes;
368 data << pProto->NatureRes;
369 data << pProto->FrostRes;
370 data << pProto->ShadowRes;
371 data << pProto->ArcaneRes;
373 data << pProto->Delay;
374 data << pProto->AmmoType;
375 data << pProto->RangedModRange;
377 for(int s = 0; s < MAX_ITEM_PROTO_SPELLS; ++s)
379 // send DBC data for cooldowns in same way as it used in Spell::SendSpellCooldown
380 // use `item_template` or if not set then only use spell cooldowns
381 SpellEntry const* spell = sSpellStore.LookupEntry(pProto->Spells[s].SpellId);
382 if(spell)
384 bool db_data = pProto->Spells[s].SpellCooldown >= 0 || pProto->Spells[s].SpellCategoryCooldown >= 0;
386 data << pProto->Spells[s].SpellId;
387 data << pProto->Spells[s].SpellTrigger;
388 data << uint32(-abs(pProto->Spells[s].SpellCharges));
390 if(db_data)
392 data << uint32(pProto->Spells[s].SpellCooldown);
393 data << uint32(pProto->Spells[s].SpellCategory);
394 data << uint32(pProto->Spells[s].SpellCategoryCooldown);
396 else
398 data << uint32(spell->RecoveryTime);
399 data << uint32(spell->Category);
400 data << uint32(spell->CategoryRecoveryTime);
403 else
405 data << uint32(0);
406 data << uint32(0);
407 data << uint32(0);
408 data << uint32(-1);
409 data << uint32(0);
410 data << uint32(-1);
413 data << pProto->Bonding;
414 data << Description;
415 data << pProto->PageText;
416 data << pProto->LanguageID;
417 data << pProto->PageMaterial;
418 data << pProto->StartQuest;
419 data << pProto->LockID;
420 data << int32(pProto->Material);
421 data << pProto->Sheath;
422 data << pProto->RandomProperty;
423 data << pProto->RandomSuffix;
424 data << pProto->Block;
425 data << pProto->ItemSet;
426 data << pProto->MaxDurability;
427 data << pProto->Area;
428 data << pProto->Map; // Added in 1.12.x & 2.0.1 client branch
429 data << pProto->BagFamily;
430 data << pProto->TotemCategory;
431 for(int s = 0; s < MAX_ITEM_PROTO_SOCKETS; ++s)
433 data << pProto->Socket[s].Color;
434 data << pProto->Socket[s].Content;
436 data << pProto->socketBonus;
437 data << pProto->GemProperties;
438 data << pProto->RequiredDisenchantSkill;
439 data << pProto->ArmorDamageModifier;
440 data << pProto->Duration; // added in 2.4.2.8209, duration (seconds)
441 data << pProto->ItemLimitCategory; // WotLK, ItemLimitCategory
442 SendPacket( &data );
444 else
446 sLog.outDebug( "WORLD: CMSG_ITEM_QUERY_SINGLE - NO item INFO! (ENTRY: %u)", item );
447 WorldPacket data( SMSG_ITEM_QUERY_SINGLE_RESPONSE, 4);
448 data << uint32(item | 0x80000000);
449 SendPacket( &data );
453 void WorldSession::HandleReadItem( WorldPacket & recv_data )
455 CHECK_PACKET_SIZE(recv_data,1+1);
457 //sLog.outDebug( "WORLD: CMSG_READ_ITEM");
459 uint8 bag, slot;
460 recv_data >> bag >> slot;
462 //sLog.outDetail("STORAGE: Read bag = %u, slot = %u", bag, slot);
463 Item *pItem = _player->GetItemByPos( bag, slot );
465 if( pItem && pItem->GetProto()->PageText )
467 WorldPacket data;
469 uint8 msg = _player->CanUseItem( pItem );
470 if( msg == EQUIP_ERR_OK )
472 data.Initialize (SMSG_READ_ITEM_OK, 8);
473 sLog.outDetail("STORAGE: Item page sent");
475 else
477 data.Initialize( SMSG_READ_ITEM_FAILED, 8 );
478 sLog.outDetail("STORAGE: Unable to read item");
479 _player->SendEquipError( msg, pItem, NULL );
481 data << pItem->GetGUID();
482 SendPacket(&data);
484 else
485 _player->SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND, NULL, NULL );
488 void WorldSession::HandlePageQuerySkippedOpcode( WorldPacket & recv_data )
490 CHECK_PACKET_SIZE(recv_data,4+8);
492 sLog.outDebug( "WORLD: Received CMSG_PAGE_TEXT_QUERY" );
494 uint32 itemid;
495 uint64 guid;
497 recv_data >> itemid >> guid;
499 sLog.outDetail( "Packet Info: itemid: %u guidlow: %u guidentry: %u guidhigh: %u",
500 itemid, GUID_LOPART(guid), GUID_ENPART(guid), GUID_HIPART(guid));
503 void WorldSession::HandleSellItemOpcode( WorldPacket & recv_data )
505 CHECK_PACKET_SIZE(recv_data,8+8+1);
507 sLog.outDebug( "WORLD: Received CMSG_SELL_ITEM" );
508 uint64 vendorguid, itemguid;
509 uint8 _count;
511 recv_data >> vendorguid >> itemguid >> _count;
513 // prevent possible overflow, as mangos uses uint32 for item count
514 uint32 count = _count;
516 if(!itemguid)
517 return;
519 Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(vendorguid,UNIT_NPC_FLAG_VENDOR);
520 if (!pCreature)
522 sLog.outDebug( "WORLD: HandleSellItemOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(vendorguid)) );
523 _player->SendSellError( SELL_ERR_CANT_FIND_VENDOR, NULL, itemguid, 0);
524 return;
527 // remove fake death
528 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
529 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
531 Item *pItem = _player->GetItemByGuid( itemguid );
532 if( pItem )
534 // prevent sell not owner item
535 if(_player->GetGUID()!=pItem->GetOwnerGUID())
537 _player->SendSellError( SELL_ERR_CANT_SELL_ITEM, pCreature, itemguid, 0);
538 return;
541 // prevent sell non empty bag by drag-and-drop at vendor's item list
542 if(pItem->IsBag() && !((Bag*)pItem)->IsEmpty())
544 _player->SendSellError( SELL_ERR_CANT_SELL_ITEM, pCreature, itemguid, 0);
545 return;
548 // prevent sell currently looted item
549 if(_player->GetLootGUID()==pItem->GetGUID())
551 _player->SendSellError( SELL_ERR_CANT_SELL_ITEM, pCreature, itemguid, 0);
552 return;
555 // special case at auto sell (sell all)
556 if(count==0)
558 count = pItem->GetCount();
560 else
562 // prevent sell more items that exist in stack (possable only not from client)
563 if(count > pItem->GetCount())
565 _player->SendSellError( SELL_ERR_CANT_SELL_ITEM, pCreature, itemguid, 0);
566 return;
570 ItemPrototype const *pProto = pItem->GetProto();
571 if( pProto )
573 if( pProto->SellPrice > 0 )
575 if(count < pItem->GetCount()) // need split items
577 Item *pNewItem = pItem->CloneItem( count, _player );
578 if (!pNewItem)
580 sLog.outError("WORLD: HandleSellItemOpcode - could not create clone of item %u; count = %u", pItem->GetEntry(), count );
581 _player->SendSellError( SELL_ERR_CANT_SELL_ITEM, pCreature, itemguid, 0);
582 return;
585 pItem->SetCount( pItem->GetCount() - count );
586 _player->ItemRemovedQuestCheck( pItem->GetEntry(), count );
587 if( _player->IsInWorld() )
588 pItem->SendUpdateToPlayer( _player );
589 pItem->SetState(ITEM_CHANGED, _player);
591 _player->AddItemToBuyBackSlot( pNewItem );
592 if( _player->IsInWorld() )
593 pNewItem->SendUpdateToPlayer( _player );
595 else
597 _player->ItemRemovedQuestCheck( pItem->GetEntry(), pItem->GetCount());
598 _player->RemoveItem( pItem->GetBagSlot(), pItem->GetSlot(), true);
599 pItem->RemoveFromUpdateQueueOf(_player);
600 _player->AddItemToBuyBackSlot( pItem );
603 _player->ModifyMoney( pProto->SellPrice * count );
605 else
606 _player->SendSellError( SELL_ERR_CANT_SELL_ITEM, pCreature, itemguid, 0);
607 return;
610 _player->SendSellError( SELL_ERR_CANT_FIND_ITEM, pCreature, itemguid, 0);
611 return;
614 void WorldSession::HandleBuybackItem(WorldPacket & recv_data)
616 CHECK_PACKET_SIZE(recv_data,8+4);
618 sLog.outDebug( "WORLD: Received CMSG_BUYBACK_ITEM" );
619 uint64 vendorguid;
620 uint32 slot;
622 recv_data >> vendorguid >> slot;
624 Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(vendorguid,UNIT_NPC_FLAG_VENDOR);
625 if (!pCreature)
627 sLog.outDebug( "WORLD: HandleBuybackItem - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(vendorguid)) );
628 _player->SendSellError( SELL_ERR_CANT_FIND_VENDOR, NULL, 0, 0);
629 return;
632 // remove fake death
633 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
634 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
636 Item *pItem = _player->GetItemFromBuyBackSlot( slot );
637 if( pItem )
639 uint32 price = _player->GetUInt32Value( PLAYER_FIELD_BUYBACK_PRICE_1 + slot - BUYBACK_SLOT_START );
640 if( _player->GetMoney() < price )
642 _player->SendBuyError( BUY_ERR_NOT_ENOUGHT_MONEY, pCreature, pItem->GetEntry(), 0);
643 return;
646 ItemPosCountVec dest;
647 uint8 msg = _player->CanStoreItem( NULL_BAG, NULL_SLOT, dest, pItem, false );
648 if( msg == EQUIP_ERR_OK )
650 _player->ModifyMoney( -(int32)price );
651 _player->RemoveItemFromBuyBackSlot( slot, false );
652 _player->ItemAddedQuestCheck( pItem->GetEntry(), pItem->GetCount());
653 _player->StoreItem( dest, pItem, true );
655 else
656 _player->SendEquipError( msg, pItem, NULL );
657 return;
659 else
660 _player->SendBuyError( BUY_ERR_CANT_FIND_ITEM, pCreature, 0, 0);
663 void WorldSession::HandleBuyItemInSlotOpcode( WorldPacket & recv_data )
665 CHECK_PACKET_SIZE(recv_data,8+4+8+1+1);
667 sLog.outDebug( "WORLD: Received CMSG_BUY_ITEM_IN_SLOT" );
668 uint64 vendorguid, bagguid;
669 uint32 item;
670 uint8 slot, count;
672 recv_data >> vendorguid >> item >> bagguid >> slot >> count;
674 GetPlayer()->BuyItemFromVendor(vendorguid,item,count,bagguid,slot);
677 void WorldSession::HandleBuyItemOpcode( WorldPacket & recv_data )
679 CHECK_PACKET_SIZE(recv_data,8+4+1+1);
681 sLog.outDebug( "WORLD: Received CMSG_BUY_ITEM" );
682 uint64 vendorguid;
683 uint32 item;
684 uint8 count, unk1;
686 recv_data >> vendorguid >> item >> count >> unk1;
688 GetPlayer()->BuyItemFromVendor(vendorguid,item,count,NULL_BAG,NULL_SLOT);
691 void WorldSession::HandleListInventoryOpcode( WorldPacket & recv_data )
693 CHECK_PACKET_SIZE(recv_data,8);
695 uint64 guid;
697 recv_data >> guid;
699 if(!GetPlayer()->isAlive())
700 return;
702 sLog.outDebug( "WORLD: Recvd CMSG_LIST_INVENTORY" );
704 SendListInventory( guid );
707 void WorldSession::SendListInventory( uint64 vendorguid )
709 sLog.outDebug( "WORLD: Sent SMSG_LIST_INVENTORY" );
711 Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(vendorguid,UNIT_NPC_FLAG_VENDOR);
712 if (!pCreature)
714 sLog.outDebug( "WORLD: SendListInventory - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(vendorguid)) );
715 _player->SendSellError( SELL_ERR_CANT_FIND_VENDOR, NULL, 0, 0);
716 return;
719 // remove fake death
720 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
721 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
723 // Stop the npc if moving
724 pCreature->StopMoving();
726 VendorItemData const* vItems = pCreature->GetVendorItems();
727 if(!vItems)
729 _player->SendSellError( SELL_ERR_CANT_FIND_VENDOR, NULL, 0, 0);
730 return;
733 uint8 numitems = vItems->GetItemCount();
734 uint8 count = 0;
736 WorldPacket data( SMSG_LIST_INVENTORY, (8+1+numitems*8*4) );
737 data << uint64(vendorguid);
738 data << uint8(numitems);
740 float discountMod = _player->GetReputationPriceDiscount(pCreature);
742 for(int i = 0; i < numitems; ++i )
744 if(VendorItem const* crItem = vItems->GetItem(i))
746 if(ItemPrototype const *pProto = objmgr.GetItemPrototype(crItem->item))
748 if((pProto->AllowableClass & _player->getClassMask()) == 0 && pProto->Bonding == BIND_WHEN_PICKED_UP && !_player->isGameMaster())
749 continue;
751 ++count;
753 // reputation discount
754 uint32 price = uint32(floor(pProto->BuyPrice * discountMod));
756 data << uint32(count);
757 data << uint32(crItem->item);
758 data << uint32(pProto->DisplayInfoID);
759 data << uint32(crItem->maxcount <= 0 ? 0xFFFFFFFF : pCreature->GetVendorItemCurrentCount(crItem));
760 data << uint32(price);
761 data << uint32(pProto->MaxDurability);
762 data << uint32(pProto->BuyCount);
763 data << uint32(crItem->ExtendedCost);
768 if ( count == 0 || data.size() != 8 + 1 + size_t(count) * 8 * 4 )
769 return;
771 data.put<uint8>(8, count);
772 SendPacket( &data );
775 void WorldSession::HandleAutoStoreBagItemOpcode( WorldPacket & recv_data )
777 CHECK_PACKET_SIZE(recv_data,1+1+1);
779 //sLog.outDebug("WORLD: CMSG_AUTOSTORE_BAG_ITEM");
780 uint8 srcbag, srcslot, dstbag;
782 recv_data >> srcbag >> srcslot >> dstbag;
783 //sLog.outDebug("STORAGE: receive srcbag = %u, srcslot = %u, dstbag = %u", srcbag, srcslot, dstbag);
785 Item *pItem = _player->GetItemByPos( srcbag, srcslot );
786 if( !pItem )
787 return;
789 if(!_player->IsValidPos(dstbag,NULL_SLOT))
791 _player->SendEquipError( EQUIP_ERR_ITEM_DOESNT_GO_TO_SLOT, NULL, NULL );
792 return;
795 uint16 src = pItem->GetPos();
797 // check unequip potability for equipped items and bank bags
798 if(_player->IsEquipmentPos ( src ) || _player->IsBagPos ( src ))
800 uint8 msg = _player->CanUnequipItem( src, !_player->IsBagPos ( src ));
801 if(msg != EQUIP_ERR_OK)
803 _player->SendEquipError( msg, pItem, NULL );
804 return;
808 ItemPosCountVec dest;
809 uint8 msg = _player->CanStoreItem( dstbag, NULL_SLOT, dest, pItem, false );
810 if( msg != EQUIP_ERR_OK )
812 _player->SendEquipError( msg, pItem, NULL );
813 return;
816 // no-op: placed in same slot
817 if(dest.size()==1 && dest[0].pos==src)
819 // just remove grey item state
820 _player->SendEquipError( EQUIP_ERR_NONE, pItem, NULL );
821 return;
824 _player->RemoveItem(srcbag, srcslot, true );
825 _player->StoreItem( dest, pItem, true );
828 void WorldSession::HandleBuyBankSlotOpcode(WorldPacket& recvPacket)
830 CHECK_PACKET_SIZE(recvPacket, 8);
832 sLog.outDebug("WORLD: CMSG_BUY_BANK_SLOT");
834 uint64 guid;
835 recvPacket >> guid;
837 // cheating protection
838 Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_BANKER);
839 if(!pCreature)
841 sLog.outDebug( "WORLD: HandleBuyBankSlotOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) );
842 return;
845 uint32 slot = _player->GetBankBagSlotCount();
847 // next slot
848 ++slot;
850 sLog.outDetail("PLAYER: Buy bank bag slot, slot number = %u", slot);
852 BankBagSlotPricesEntry const* slotEntry = sBankBagSlotPricesStore.LookupEntry(slot);
854 if(!slotEntry)
855 return;
857 uint32 price = slotEntry->price;
859 if (_player->GetMoney() < price)
860 return;
862 _player->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_BUY_BANK_SLOT, slot);
863 _player->SetBankBagSlotCount(slot);
864 _player->ModifyMoney(-int32(price));
867 void WorldSession::HandleAutoBankItemOpcode(WorldPacket& recvPacket)
869 CHECK_PACKET_SIZE(recvPacket,1+1);
871 sLog.outDebug("WORLD: CMSG_AUTOBANK_ITEM");
872 uint8 srcbag, srcslot;
874 recvPacket >> srcbag >> srcslot;
875 sLog.outDebug("STORAGE: receive srcbag = %u, srcslot = %u", srcbag, srcslot);
877 Item *pItem = _player->GetItemByPos( srcbag, srcslot );
878 if( !pItem )
879 return;
881 ItemPosCountVec dest;
882 uint8 msg = _player->CanBankItem( NULL_BAG, NULL_SLOT, dest, pItem, false );
883 if( msg != EQUIP_ERR_OK )
885 _player->SendEquipError( msg, pItem, NULL );
886 return;
889 _player->RemoveItem(srcbag, srcslot, true);
890 _player->BankItem( dest, pItem, true );
893 void WorldSession::HandleAutoStoreBankItemOpcode(WorldPacket& recvPacket)
895 CHECK_PACKET_SIZE(recvPacket,1+1);
897 sLog.outDebug("WORLD: CMSG_AUTOSTORE_BANK_ITEM");
898 uint8 srcbag, srcslot;
900 recvPacket >> srcbag >> srcslot;
901 sLog.outDebug("STORAGE: receive srcbag = %u, srcslot = %u", srcbag, srcslot);
903 Item *pItem = _player->GetItemByPos( srcbag, srcslot );
904 if( !pItem )
905 return;
907 if(_player->IsBankPos(srcbag, srcslot)) // moving from bank to inventory
909 ItemPosCountVec dest;
910 uint8 msg = _player->CanStoreItem( NULL_BAG, NULL_SLOT, dest, pItem, false );
911 if( msg != EQUIP_ERR_OK )
913 _player->SendEquipError( msg, pItem, NULL );
914 return;
917 _player->RemoveItem(srcbag, srcslot, true);
918 _player->StoreItem( dest, pItem, true );
920 else // moving from inventory to bank
922 ItemPosCountVec dest;
923 uint8 msg = _player->CanBankItem( NULL_BAG, NULL_SLOT, dest, pItem, false );
924 if( msg != EQUIP_ERR_OK )
926 _player->SendEquipError( msg, pItem, NULL );
927 return;
930 _player->RemoveItem(srcbag, srcslot, true);
931 _player->BankItem( dest, pItem, true );
935 void WorldSession::HandleSetAmmoOpcode(WorldPacket & recv_data)
937 CHECK_PACKET_SIZE(recv_data,4);
939 if(!GetPlayer()->isAlive())
941 GetPlayer()->SendEquipError( EQUIP_ERR_YOU_ARE_DEAD, NULL, NULL );
942 return;
945 sLog.outDebug("WORLD: CMSG_SET_AMMO");
946 uint32 item;
948 recv_data >> item;
950 if(!item)
951 GetPlayer()->RemoveAmmo();
952 else
953 GetPlayer()->SetAmmo(item);
956 void WorldSession::SendEnchantmentLog(uint64 Target, uint64 Caster,uint32 ItemID,uint32 SpellID)
958 WorldPacket data(SMSG_ENCHANTMENTLOG, (8+8+4+4+1)); // last check 2.0.10
959 data << Target;
960 data << Caster;
961 data << ItemID;
962 data << SpellID;
963 data << uint8(0);
964 SendPacket(&data);
967 void WorldSession::SendItemEnchantTimeUpdate(uint64 Playerguid, uint64 Itemguid,uint32 slot,uint32 Duration)
969 // last check 2.0.10
970 WorldPacket data(SMSG_ITEM_ENCHANT_TIME_UPDATE, (8+4+4+8));
971 data << uint64(Itemguid);
972 data << uint32(slot);
973 data << uint32(Duration);
974 data << uint64(Playerguid);
975 SendPacket(&data);
978 void WorldSession::HandleItemNameQueryOpcode(WorldPacket & recv_data)
980 CHECK_PACKET_SIZE(recv_data,4);
982 uint32 itemid;
983 recv_data >> itemid;
984 sLog.outDebug("WORLD: CMSG_ITEM_NAME_QUERY %u", itemid);
985 ItemPrototype const *pProto = objmgr.GetItemPrototype( itemid );
986 if( pProto )
988 std::string Name;
989 Name = pProto->Name1;
991 int loc_idx = GetSessionDbLocaleIndex();
992 if (loc_idx >= 0)
994 ItemLocale const *il = objmgr.GetItemLocale(pProto->ItemId);
995 if (il)
997 if (il->Name.size() > size_t(loc_idx) && !il->Name[loc_idx].empty())
998 Name = il->Name[loc_idx];
1001 // guess size
1002 WorldPacket data(SMSG_ITEM_NAME_QUERY_RESPONSE, (4+10));
1003 data << uint32(pProto->ItemId);
1004 data << Name;
1005 data << uint32(pProto->InventoryType);
1006 SendPacket(&data);
1007 return;
1009 else
1010 sLog.outErrorDb("WORLD: CMSG_ITEM_NAME_QUERY for item %u failed (unknown item)", itemid);
1013 void WorldSession::HandleWrapItemOpcode(WorldPacket& recv_data)
1015 CHECK_PACKET_SIZE(recv_data,1+1+1+1);
1017 sLog.outDebug("Received opcode CMSG_WRAP_ITEM");
1019 uint8 gift_bag, gift_slot, item_bag, item_slot;
1020 //recv_data.hexlike();
1022 recv_data >> gift_bag >> gift_slot; // paper
1023 recv_data >> item_bag >> item_slot; // item
1025 sLog.outDebug("WRAP: receive gift_bag = %u, gift_slot = %u, item_bag = %u, item_slot = %u", gift_bag, gift_slot, item_bag, item_slot);
1027 Item *gift = _player->GetItemByPos( gift_bag, gift_slot );
1028 if(!gift)
1030 _player->SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND, gift, NULL );
1031 return;
1034 if(!gift->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_WRAPPER))// cheating: non-wrapper wrapper
1036 _player->SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND, gift, NULL );
1037 return;
1040 Item *item = _player->GetItemByPos( item_bag, item_slot );
1042 if( !item )
1044 _player->SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND, item, NULL );
1045 return;
1048 if(item==gift) // not possable with pacjket from real client
1050 _player->SendEquipError( EQUIP_ERR_WRAPPED_CANT_BE_WRAPPED, item, NULL );
1051 return;
1054 if(item->IsEquipped())
1056 _player->SendEquipError( EQUIP_ERR_EQUIPPED_CANT_BE_WRAPPED, item, NULL );
1057 return;
1060 if(item->GetUInt64Value(ITEM_FIELD_GIFTCREATOR)) // HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_WRAPPED);
1062 _player->SendEquipError( EQUIP_ERR_WRAPPED_CANT_BE_WRAPPED, item, NULL );
1063 return;
1066 if(item->IsBag())
1068 _player->SendEquipError( EQUIP_ERR_BAGS_CANT_BE_WRAPPED, item, NULL );
1069 return;
1072 if(item->IsSoulBound())
1074 _player->SendEquipError( EQUIP_ERR_BOUND_CANT_BE_WRAPPED, item, NULL );
1075 return;
1078 if(item->GetMaxStackCount() != 1)
1080 _player->SendEquipError( EQUIP_ERR_STACKABLE_CANT_BE_WRAPPED, item, NULL );
1081 return;
1084 // maybe not correct check (it is better than nothing)
1085 if(item->GetProto()->MaxCount>0)
1087 _player->SendEquipError( EQUIP_ERR_UNIQUE_CANT_BE_WRAPPED, item, NULL );
1088 return;
1091 CharacterDatabase.BeginTransaction();
1092 CharacterDatabase.PExecute("INSERT INTO character_gifts VALUES ('%u', '%u', '%u', '%u')", GUID_LOPART(item->GetOwnerGUID()), item->GetGUIDLow(), item->GetEntry(), item->GetUInt32Value(ITEM_FIELD_FLAGS));
1093 item->SetEntry(gift->GetEntry());
1095 switch (item->GetEntry())
1097 case 5042: item->SetEntry( 5043); break;
1098 case 5048: item->SetEntry( 5044); break;
1099 case 17303: item->SetEntry(17302); break;
1100 case 17304: item->SetEntry(17305); break;
1101 case 17307: item->SetEntry(17308); break;
1102 case 21830: item->SetEntry(21831); break;
1104 item->SetUInt64Value(ITEM_FIELD_GIFTCREATOR, _player->GetGUID());
1105 item->SetUInt32Value(ITEM_FIELD_FLAGS, ITEM_FLAGS_WRAPPED);
1106 item->SetState(ITEM_CHANGED, _player);
1108 if(item->GetState()==ITEM_NEW) // save new item, to have alway for `character_gifts` record in `item_instance`
1110 // after save it will be impossible to remove the item from the queue
1111 item->RemoveFromUpdateQueueOf(_player);
1112 item->SaveToDB(); // item gave inventory record unchanged and can be save standalone
1114 CharacterDatabase.CommitTransaction();
1116 uint32 count = 1;
1117 _player->DestroyItemCount(gift, count, true);
1120 void WorldSession::HandleSocketOpcode(WorldPacket& recv_data)
1122 sLog.outDebug("WORLD: CMSG_SOCKET_GEMS");
1124 CHECK_PACKET_SIZE(recv_data,8+8*MAX_GEM_SOCKETS);
1126 uint64 item_guid;
1127 uint64 gem_guids[MAX_GEM_SOCKETS];
1129 recv_data >> item_guid;
1130 if(!item_guid)
1131 return;
1133 for(int i = 0; i < MAX_GEM_SOCKETS; ++i)
1134 recv_data >> gem_guids[i];
1136 //cheat -> tried to socket same gem multiple times
1137 if ((gem_guids[0] && (gem_guids[0] == gem_guids[1] || gem_guids[0] == gem_guids[2])) ||
1138 (gem_guids[1] && (gem_guids[1] == gem_guids[2])))
1139 return;
1141 Item *itemTarget = _player->GetItemByGuid(item_guid);
1142 if(!itemTarget) //missing item to socket
1143 return;
1145 ItemPrototype const* itemProto = itemTarget->GetProto();
1146 if(!itemProto)
1147 return;
1149 //this slot is excepted when applying / removing meta gem bonus
1150 uint8 slot = itemTarget->IsEquipped() ? itemTarget->GetSlot() : uint8(NULL_SLOT);
1152 Item *Gems[MAX_GEM_SOCKETS];
1153 for(int i = 0; i < MAX_GEM_SOCKETS; ++i)
1154 Gems[i] = gem_guids[i] ? _player->GetItemByGuid(gem_guids[i]) : NULL;
1156 GemPropertiesEntry const *GemProps[MAX_GEM_SOCKETS];
1157 for(int i = 0; i < MAX_GEM_SOCKETS; ++i) //get geminfo from dbc storage
1158 GemProps[i] = (Gems[i]) ? sGemPropertiesStore.LookupEntry(Gems[i]->GetProto()->GemProperties) : NULL;
1160 for(int i = 0; i < MAX_GEM_SOCKETS; ++i) //check for hack maybe
1162 if (!GemProps[i])
1163 continue;
1165 // tried to put gem in socket where no socket exists (take care about prismatic sockets)
1166 if (!itemProto->Socket[i].Color)
1168 // no prismatic socket
1169 if(!itemTarget->GetEnchantmentId(PRISMATIC_ENCHANTMENT_SLOT))
1170 return;
1172 // not first not-colored (not normaly used) socket
1173 if(i!=0 && !itemProto->Socket[i-1].Color && (i+1 >= MAX_GEM_SOCKETS || itemProto->Socket[i+1].Color))
1174 return;
1176 // ok, this is first not colored socket for item with prismatic socket
1179 // tried to put normal gem in meta socket
1180 if (itemProto->Socket[i].Color == SOCKET_COLOR_META && GemProps[i]->color != SOCKET_COLOR_META)
1181 return;
1183 // tried to put meta gem in normal socket
1184 if (itemProto->Socket[i].Color != SOCKET_COLOR_META && GemProps[i]->color == SOCKET_COLOR_META)
1185 return;
1188 uint32 GemEnchants[MAX_GEM_SOCKETS];
1189 uint32 OldEnchants[MAX_GEM_SOCKETS];
1190 for(int i = 0; i < MAX_GEM_SOCKETS; ++i) //get new and old enchantments
1192 GemEnchants[i] = (GemProps[i]) ? GemProps[i]->spellitemenchantement : 0;
1193 OldEnchants[i] = itemTarget->GetEnchantmentId(EnchantmentSlot(SOCK_ENCHANTMENT_SLOT+i));
1196 // check unique-equipped conditions
1197 for(int i = 0; i < MAX_GEM_SOCKETS; ++i)
1199 if(!Gems[i])
1200 continue;
1202 // continue check for case when attempt add 2 similar unique equipped gems in one item.
1203 ItemPrototype const* iGemProto = Gems[i]->GetProto();
1205 // unique item (for new and already placed bit removed enchantments
1206 if (iGemProto->Flags & ITEM_FLAGS_UNIQUE_EQUIPPED)
1208 for (int j = 0; j < MAX_GEM_SOCKETS; ++j)
1210 if(i==j) // skip self
1211 continue;
1213 if (Gems[j])
1215 if (iGemProto->ItemId == Gems[j]->GetEntry())
1217 _player->SendEquipError( EQUIP_ERR_ITEM_UNIQUE_EQUIPPABLE_SOCKETED, itemTarget, NULL );
1218 return;
1221 else if(OldEnchants[j])
1223 if(SpellItemEnchantmentEntry const* enchantEntry = sSpellItemEnchantmentStore.LookupEntry(OldEnchants[j]))
1225 if (iGemProto->ItemId == enchantEntry->GemID)
1227 _player->SendEquipError( EQUIP_ERR_ITEM_UNIQUE_EQUIPPABLE_SOCKETED, itemTarget, NULL );
1228 return;
1236 // unique limit type item
1237 int32 limit_newcount = 0;
1238 if (iGemProto->ItemLimitCategory)
1240 if(ItemLimitCategoryEntry const* limitEntry = sItemLimitCategoryStore.LookupEntry(iGemProto->ItemLimitCategory))
1242 for (int j = 0; j < MAX_GEM_SOCKETS; ++j)
1244 if (Gems[j])
1246 // destroyed gem
1247 if (OldEnchants[j])
1249 if(SpellItemEnchantmentEntry const* enchantEntry = sSpellItemEnchantmentStore.LookupEntry(OldEnchants[j]))
1250 if(ItemPrototype const* jProto = ObjectMgr::GetItemPrototype(enchantEntry->GemID))
1251 if (iGemProto->ItemLimitCategory == jProto->ItemLimitCategory)
1252 --limit_newcount;
1255 // new gem
1256 if (iGemProto->ItemLimitCategory == Gems[j]->GetProto()->ItemLimitCategory)
1257 ++limit_newcount;
1259 // existed gem
1260 else if(OldEnchants[j])
1262 if(SpellItemEnchantmentEntry const* enchantEntry = sSpellItemEnchantmentStore.LookupEntry(OldEnchants[j]))
1263 if(ItemPrototype const* jProto = ObjectMgr::GetItemPrototype(enchantEntry->GemID))
1264 if (iGemProto->ItemLimitCategory == jProto->ItemLimitCategory)
1265 ++limit_newcount;
1269 if(limit_newcount > 0 && uint32(limit_newcount) > limitEntry->maxCount)
1271 _player->SendEquipError( EQUIP_ERR_ITEM_UNIQUE_EQUIPPABLE_SOCKETED, itemTarget, NULL );
1272 return;
1277 // for equipped item check all equipment for duplicate equipped gems
1278 if(itemTarget->IsEquipped())
1280 if(uint8 res = _player->CanEquipUniqueItem(Gems[i],slot,limit_newcount >= 0 ? limit_newcount : 0))
1282 _player->SendEquipError( res, itemTarget, NULL );
1283 return;
1288 bool SocketBonusActivated = itemTarget->GemsFitSockets(); //save state of socketbonus
1289 _player->ToggleMetaGemsActive(slot, false); //turn off all metagems (except for the target item)
1291 //if a meta gem is being equipped, all information has to be written to the item before testing if the conditions for the gem are met
1293 //remove ALL enchants
1294 for(uint32 enchant_slot = SOCK_ENCHANTMENT_SLOT; enchant_slot < SOCK_ENCHANTMENT_SLOT+MAX_GEM_SOCKETS; ++enchant_slot)
1295 _player->ApplyEnchantment(itemTarget,EnchantmentSlot(enchant_slot),false);
1297 for(int i = 0; i < MAX_GEM_SOCKETS; ++i)
1299 if(GemEnchants[i])
1301 itemTarget->SetEnchantment(EnchantmentSlot(SOCK_ENCHANTMENT_SLOT+i), GemEnchants[i],0,0);
1302 if(Item* guidItem = _player->GetItemByGuid(gem_guids[i]))
1303 _player->DestroyItem(guidItem->GetBagSlot(), guidItem->GetSlot(), true );
1307 for(uint32 enchant_slot = SOCK_ENCHANTMENT_SLOT; enchant_slot < SOCK_ENCHANTMENT_SLOT+MAX_GEM_SOCKETS; ++enchant_slot)
1308 _player->ApplyEnchantment(itemTarget,EnchantmentSlot(enchant_slot),true);
1310 bool SocketBonusToBeActivated = itemTarget->GemsFitSockets();//current socketbonus state
1311 if(SocketBonusActivated ^ SocketBonusToBeActivated) //if there was a change...
1313 _player->ApplyEnchantment(itemTarget,BONUS_ENCHANTMENT_SLOT,false);
1314 itemTarget->SetEnchantment(BONUS_ENCHANTMENT_SLOT, (SocketBonusToBeActivated ? itemTarget->GetProto()->socketBonus : 0), 0, 0);
1315 _player->ApplyEnchantment(itemTarget,BONUS_ENCHANTMENT_SLOT,true);
1316 //it is not displayed, client has an inbuilt system to determine if the bonus is activated
1319 _player->ToggleMetaGemsActive(slot, true); //turn on all metagems (except for target item)
1322 void WorldSession::HandleCancelTempEnchantmentOpcode(WorldPacket& recv_data)
1324 sLog.outDebug("WORLD: CMSG_CANCEL_TEMP_ENCHANTMENT");
1326 CHECK_PACKET_SIZE(recv_data,4);
1328 uint32 eslot;
1330 recv_data >> eslot;
1332 // apply only to equipped item
1333 if(!Player::IsEquipmentPos(INVENTORY_SLOT_BAG_0,eslot))
1334 return;
1336 Item* item = GetPlayer()->GetItemByPos(INVENTORY_SLOT_BAG_0, eslot);
1338 if(!item)
1339 return;
1341 if(!item->GetEnchantmentId(TEMP_ENCHANTMENT_SLOT))
1342 return;
1344 GetPlayer()->ApplyEnchantment(item,TEMP_ENCHANTMENT_SLOT,false);
1345 item->ClearEnchantment(TEMP_ENCHANTMENT_SLOT);