2 * Copyright (C) 2005-2008 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
20 #include "WorldPacket.h"
21 #include "WorldSession.h"
25 #include "ObjectMgr.h"
28 #include "UpdateData.h"
29 #include "ObjectAccessor.h"
31 void WorldSession::HandleSplitItemOpcode( WorldPacket
& recv_data
)
33 CHECK_PACKET_SIZE(recv_data
,1+1+1+1+1);
35 //sLog.outDebug("WORLD: CMSG_SPLIT_ITEM");
36 uint8 srcbag
, srcslot
, dstbag
, dstslot
, count
;
38 recv_data
>> srcbag
>> srcslot
>> dstbag
>> dstslot
>> count
;
39 //sLog.outDebug("STORAGE: receive srcbag = %u, srcslot = %u, dstbag = %u, dstslot = %u, count = %u", srcbag, srcslot, dstbag, dstslot, count);
41 uint16 src
= ( (srcbag
<< 8) | srcslot
);
42 uint16 dst
= ( (dstbag
<< 8) | dstslot
);
48 return; //check count - if zero it's fake packet
50 if(!_player
->IsValidPos(srcbag
,srcslot
))
52 _player
->SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND
, NULL
, NULL
);
56 if(!_player
->IsValidPos(dstbag
,dstslot
))
58 _player
->SendEquipError( EQUIP_ERR_ITEM_DOESNT_GO_TO_SLOT
, NULL
, NULL
);
62 _player
->SplitItem( src
, dst
, count
);
65 void WorldSession::HandleSwapInvItemOpcode( WorldPacket
& recv_data
)
67 CHECK_PACKET_SIZE(recv_data
,1+1);
69 //sLog.outDebug("WORLD: CMSG_SWAP_INV_ITEM");
70 uint8 srcslot
, dstslot
;
72 recv_data
>> srcslot
>> dstslot
;
73 //sLog.outDebug("STORAGE: receive srcslot = %u, dstslot = %u", srcslot, dstslot);
75 // prevent attempt swap same item to current position generated by client at special checting sequence
79 if(!_player
->IsValidPos(INVENTORY_SLOT_BAG_0
,srcslot
))
81 _player
->SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND
, NULL
, NULL
);
85 if(!_player
->IsValidPos(INVENTORY_SLOT_BAG_0
,dstslot
))
87 _player
->SendEquipError( EQUIP_ERR_ITEM_DOESNT_GO_TO_SLOT
, NULL
, NULL
);
91 uint16 src
= ( (INVENTORY_SLOT_BAG_0
<< 8) | srcslot
);
92 uint16 dst
= ( (INVENTORY_SLOT_BAG_0
<< 8) | dstslot
);
94 _player
->SwapItem( src
, dst
);
97 void WorldSession::HandleAutoEquipItemSlotOpcode( WorldPacket
& recv_data
)
99 CHECK_PACKET_SIZE(recv_data
,8+1);
102 recv_data
>> itemguid
>> dstslot
;
104 // cheating attempt, client should never send opcode in that case
105 if(!Player::IsEquipmentPos(INVENTORY_SLOT_BAG_0
, dstslot
))
108 Item
* item
= _player
->GetItemByGuid(itemguid
);
109 uint16 dstpos
= dstslot
| (INVENTORY_SLOT_BAG_0
<< 8);
111 if(!item
|| item
->GetPos() == dstpos
)
114 _player
->SwapItem(item
->GetPos(), dstpos
);
117 void WorldSession::HandleSwapItem( WorldPacket
& recv_data
)
119 CHECK_PACKET_SIZE(recv_data
,1+1+1+1);
121 //sLog.outDebug("WORLD: CMSG_SWAP_ITEM");
122 uint8 dstbag
, dstslot
, srcbag
, srcslot
;
124 recv_data
>> dstbag
>> dstslot
>> srcbag
>> srcslot
;
125 //sLog.outDebug("STORAGE: receive srcbag = %u, srcslot = %u, dstbag = %u, dstslot = %u", srcbag, srcslot, dstbag, dstslot);
127 uint16 src
= ( (srcbag
<< 8) | srcslot
);
128 uint16 dst
= ( (dstbag
<< 8) | dstslot
);
130 // prevent attempt swap same item to current position generated by client at special checting sequence
134 if(!_player
->IsValidPos(srcbag
,srcslot
))
136 _player
->SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND
, NULL
, NULL
);
140 if(!_player
->IsValidPos(dstbag
,dstslot
))
142 _player
->SendEquipError( EQUIP_ERR_ITEM_DOESNT_GO_TO_SLOT
, NULL
, NULL
);
146 _player
->SwapItem( src
, dst
);
149 void WorldSession::HandleAutoEquipItemOpcode( WorldPacket
& recv_data
)
151 CHECK_PACKET_SIZE(recv_data
,1+1);
153 //sLog.outDebug("WORLD: CMSG_AUTOEQUIP_ITEM");
154 uint8 srcbag
, srcslot
;
156 recv_data
>> srcbag
>> srcslot
;
157 //sLog.outDebug("STORAGE: receive srcbag = %u, srcslot = %u", srcbag, srcslot);
159 Item
*pSrcItem
= _player
->GetItemByPos( srcbag
, srcslot
);
161 return; // only at cheat
163 if(pSrcItem
->m_lootGenerated
) // prevent swap looting item
165 //best error message found for attempting to swap while looting
166 _player
->SendEquipError( EQUIP_ERR_CANT_DO_RIGHT_NOW
, pSrcItem
, NULL
);
171 uint8 msg
= _player
->CanEquipItem( NULL_SLOT
, dest
, pSrcItem
, !pSrcItem
->IsBag() );
172 if( msg
!= EQUIP_ERR_OK
)
174 _player
->SendEquipError( msg
, pSrcItem
, NULL
);
178 uint16 src
= pSrcItem
->GetPos();
179 if(dest
==src
) // prevent equip in same slot, only at cheat
182 Item
*pDstItem
= _player
->GetItemByPos( dest
);
183 if( !pDstItem
) // empty slot, simple case
185 _player
->RemoveItem( srcbag
, srcslot
, true );
186 _player
->EquipItem( dest
, pSrcItem
, true );
187 _player
->AutoUnequipOffhandIfNeed();
189 else // have currently equipped item, not simple case
191 uint8 dstbag
= pDstItem
->GetBagSlot();
192 uint8 dstslot
= pDstItem
->GetSlot();
194 msg
= _player
->CanUnequipItem( dest
, !pSrcItem
->IsBag() );
195 if( msg
!= EQUIP_ERR_OK
)
197 _player
->SendEquipError( msg
, pDstItem
, NULL
);
201 // check dest->src move possibility
202 ItemPosCountVec sSrc
;
204 if( _player
->IsInventoryPos( src
) )
206 msg
= _player
->CanStoreItem( srcbag
, srcslot
, sSrc
, pDstItem
, true );
207 if( msg
!= EQUIP_ERR_OK
)
208 msg
= _player
->CanStoreItem( srcbag
, NULL_SLOT
, sSrc
, pDstItem
, true );
209 if( msg
!= EQUIP_ERR_OK
)
210 msg
= _player
->CanStoreItem( NULL_BAG
, NULL_SLOT
, sSrc
, pDstItem
, true );
212 else if( _player
->IsBankPos( src
) )
214 msg
= _player
->CanBankItem( srcbag
, srcslot
, sSrc
, pDstItem
, true );
215 if( msg
!= EQUIP_ERR_OK
)
216 msg
= _player
->CanBankItem( srcbag
, NULL_SLOT
, sSrc
, pDstItem
, true );
217 if( msg
!= EQUIP_ERR_OK
)
218 msg
= _player
->CanBankItem( NULL_BAG
, NULL_SLOT
, sSrc
, pDstItem
, true );
220 else if( _player
->IsEquipmentPos( src
) )
222 msg
= _player
->CanEquipItem( srcslot
, eSrc
, pDstItem
, true);
223 if( msg
== EQUIP_ERR_OK
)
224 msg
= _player
->CanUnequipItem( eSrc
, true);
227 if( msg
!= EQUIP_ERR_OK
)
229 _player
->SendEquipError( msg
, pDstItem
, pSrcItem
);
233 // now do moves, remove...
234 _player
->RemoveItem(dstbag
, dstslot
, false);
235 _player
->RemoveItem(srcbag
, srcslot
, false);
238 _player
->EquipItem(dest
, pSrcItem
, true);
241 if( _player
->IsInventoryPos( src
) )
242 _player
->StoreItem(sSrc
, pDstItem
, true);
243 else if( _player
->IsBankPos( src
) )
244 _player
->BankItem(sSrc
, pDstItem
, true);
245 else if( _player
->IsEquipmentPos( src
) )
246 _player
->EquipItem(eSrc
, pDstItem
, true);
248 _player
->AutoUnequipOffhandIfNeed();
252 void WorldSession::HandleDestroyItemOpcode( WorldPacket
& recv_data
)
254 CHECK_PACKET_SIZE(recv_data
,1+1+1+1+1+1);
256 //sLog.outDebug("WORLD: CMSG_DESTROYITEM");
257 uint8 bag
, slot
, count
, data1
, data2
, data3
;
259 recv_data
>> bag
>> slot
>> count
>> data1
>> data2
>> data3
;
260 //sLog.outDebug("STORAGE: receive bag = %u, slot = %u, count = %u", bag, slot, count);
262 uint16 pos
= (bag
<< 8) | slot
;
264 // prevent drop unequipable items (in combat, for example) and non-empty bags
265 if(_player
->IsEquipmentPos(pos
) || _player
->IsBagPos(pos
))
267 uint8 msg
= _player
->CanUnequipItem( pos
, false );
268 if( msg
!= EQUIP_ERR_OK
)
270 _player
->SendEquipError( msg
, _player
->GetItemByPos(pos
), NULL
);
275 Item
*pItem
= _player
->GetItemByPos( bag
, slot
);
278 _player
->SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND
, NULL
, NULL
);
284 uint32 i_count
= count
;
285 _player
->DestroyItemCount( pItem
, i_count
, true );
288 _player
->DestroyItem( bag
, slot
, true );
291 // Only _static_ data send in this packet !!!
292 void WorldSession::HandleItemQuerySingleOpcode( WorldPacket
& recv_data
)
294 CHECK_PACKET_SIZE(recv_data
, 4);
296 //sLog.outDebug("WORLD: CMSG_ITEM_QUERY_SINGLE");
300 sLog
.outDetail("STORAGE: Item Query = %u", item
);
302 ItemPrototype
const *pProto
= objmgr
.GetItemPrototype( item
);
305 std::string Name
= pProto
->Name1
;
306 std::string Description
= pProto
->Description
;
308 int loc_idx
= GetSessionDbLocaleIndex();
311 ItemLocale
const *il
= objmgr
.GetItemLocale(pProto
->ItemId
);
314 if (il
->Name
.size() > size_t(loc_idx
) && !il
->Name
[loc_idx
].empty())
315 Name
= il
->Name
[loc_idx
];
316 if (il
->Description
.size() > size_t(loc_idx
) && !il
->Description
[loc_idx
].empty())
317 Description
= il
->Description
[loc_idx
];
321 WorldPacket
data( SMSG_ITEM_QUERY_SINGLE_RESPONSE
, 600);
322 data
<< pProto
->ItemId
;
323 data
<< pProto
->Class
;
324 data
<< pProto
->SubClass
;
325 data
<< uint32(-1); // new 2.0.3, not exist in wdb cache?
327 data
<< uint8(0x00); //pProto->Name2; // blizz not send name there, just uint8(0x00); <-- \0 = empty string = empty name...
328 data
<< uint8(0x00); //pProto->Name3; // blizz not send name there, just uint8(0x00);
329 data
<< uint8(0x00); //pProto->Name4; // blizz not send name there, just uint8(0x00);
330 data
<< pProto
->DisplayInfoID
;
331 data
<< pProto
->Quality
;
332 data
<< pProto
->Flags
;
333 data
<< pProto
->BuyPrice
;
334 data
<< pProto
->SellPrice
;
335 data
<< pProto
->InventoryType
;
336 data
<< pProto
->AllowableClass
;
337 data
<< pProto
->AllowableRace
;
338 data
<< pProto
->ItemLevel
;
339 data
<< pProto
->RequiredLevel
;
340 data
<< pProto
->RequiredSkill
;
341 data
<< pProto
->RequiredSkillRank
;
342 data
<< pProto
->RequiredSpell
;
343 data
<< pProto
->RequiredHonorRank
;
344 data
<< pProto
->RequiredCityRank
;
345 data
<< pProto
->RequiredReputationFaction
;
346 data
<< pProto
->RequiredReputationRank
;
347 data
<< pProto
->MaxCount
;
348 data
<< pProto
->Stackable
;
349 data
<< pProto
->ContainerSlots
;
350 for(int i
= 0; i
< 10; i
++)
352 data
<< pProto
->ItemStat
[i
].ItemStatType
;
353 data
<< pProto
->ItemStat
[i
].ItemStatValue
;
355 for(int i
= 0; i
< 5; i
++)
357 data
<< pProto
->Damage
[i
].DamageMin
;
358 data
<< pProto
->Damage
[i
].DamageMax
;
359 data
<< pProto
->Damage
[i
].DamageType
;
363 data
<< pProto
->Armor
;
364 data
<< pProto
->HolyRes
;
365 data
<< pProto
->FireRes
;
366 data
<< pProto
->NatureRes
;
367 data
<< pProto
->FrostRes
;
368 data
<< pProto
->ShadowRes
;
369 data
<< pProto
->ArcaneRes
;
371 data
<< pProto
->Delay
;
372 data
<< pProto
->AmmoType
;
373 data
<< pProto
->RangedModRange
;
375 for(int s
= 0; s
< 5; s
++)
377 // send DBC data for cooldowns in same way as it used in Spell::SendSpellCooldown
378 // use `item_template` or if not set then only use spell cooldowns
379 SpellEntry
const* spell
= sSpellStore
.LookupEntry(pProto
->Spells
[s
].SpellId
);
382 bool db_data
= pProto
->Spells
[s
].SpellCooldown
>= 0 || pProto
->Spells
[s
].SpellCategoryCooldown
>= 0;
384 data
<< pProto
->Spells
[s
].SpellId
;
385 data
<< pProto
->Spells
[s
].SpellTrigger
;
386 data
<< uint32(-abs(pProto
->Spells
[s
].SpellCharges
));
390 data
<< uint32(pProto
->Spells
[s
].SpellCooldown
);
391 data
<< uint32(pProto
->Spells
[s
].SpellCategory
);
392 data
<< uint32(pProto
->Spells
[s
].SpellCategoryCooldown
);
396 data
<< uint32(spell
->RecoveryTime
);
397 data
<< uint32(spell
->Category
);
398 data
<< uint32(spell
->CategoryRecoveryTime
);
411 data
<< pProto
->Bonding
;
413 data
<< pProto
->PageText
;
414 data
<< pProto
->LanguageID
;
415 data
<< pProto
->PageMaterial
;
416 data
<< pProto
->StartQuest
;
417 data
<< pProto
->LockID
;
418 data
<< pProto
->Material
;
419 data
<< pProto
->Sheath
;
420 data
<< pProto
->RandomProperty
;
421 data
<< pProto
->RandomSuffix
;
422 data
<< pProto
->Block
;
423 data
<< pProto
->ItemSet
;
424 data
<< pProto
->MaxDurability
;
425 data
<< pProto
->Area
;
426 data
<< pProto
->Map
; // Added in 1.12.x & 2.0.1 client branch
427 data
<< pProto
->BagFamily
;
428 data
<< pProto
->TotemCategory
;
429 for(int s
= 0; s
< 3; s
++)
431 data
<< pProto
->Socket
[s
].Color
;
432 data
<< pProto
->Socket
[s
].Content
;
434 data
<< pProto
->socketBonus
;
435 data
<< pProto
->GemProperties
;
436 data
<< pProto
->RequiredDisenchantSkill
;
437 data
<< pProto
->ArmorDamageModifier
;
438 data
<< uint32(0); // added in 2.4.2.8209, duration (seconds)
443 sLog
.outDebug( "WORLD: CMSG_ITEM_QUERY_SINGLE - NO item INFO! (ENTRY: %u)", item
);
444 WorldPacket
data( SMSG_ITEM_QUERY_SINGLE_RESPONSE
, 4);
445 data
<< uint32(item
| 0x80000000);
450 void WorldSession::HandleReadItem( WorldPacket
& recv_data
)
452 CHECK_PACKET_SIZE(recv_data
,1+1);
454 //sLog.outDebug( "WORLD: CMSG_READ_ITEM");
457 recv_data
>> bag
>> slot
;
459 //sLog.outDetail("STORAGE: Read bag = %u, slot = %u", bag, slot);
460 Item
*pItem
= _player
->GetItemByPos( bag
, slot
);
462 if( pItem
&& pItem
->GetProto()->PageText
)
466 uint8 msg
= _player
->CanUseItem( pItem
);
467 if( msg
== EQUIP_ERR_OK
)
469 data
.Initialize (SMSG_READ_ITEM_OK
, 8);
470 sLog
.outDetail("STORAGE: Item page sent");
474 data
.Initialize( SMSG_READ_ITEM_FAILED
, 8 );
475 sLog
.outDetail("STORAGE: Unable to read item");
476 _player
->SendEquipError( msg
, pItem
, NULL
);
478 data
<< pItem
->GetGUID();
482 _player
->SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND
, NULL
, NULL
);
485 void WorldSession::HandlePageQuerySkippedOpcode( WorldPacket
& recv_data
)
487 CHECK_PACKET_SIZE(recv_data
,4+8);
489 sLog
.outDebug( "WORLD: Received CMSG_PAGE_TEXT_QUERY" );
494 recv_data
>> itemid
>> guid
;
496 sLog
.outDetail( "Packet Info: itemid: %u guidlow: %u guidentry: %u guidhigh: %u",
497 itemid
, GUID_LOPART(guid
), GUID_ENPART(guid
), GUID_HIPART(guid
));
500 void WorldSession::HandleSellItemOpcode( WorldPacket
& recv_data
)
502 CHECK_PACKET_SIZE(recv_data
,8+8+1);
504 sLog
.outDebug( "WORLD: Received CMSG_SELL_ITEM" );
505 uint64 vendorguid
, itemguid
;
508 recv_data
>> vendorguid
>> itemguid
>> _count
;
510 // prevent possible overflow, as mangos uses uint32 for item count
511 uint32 count
= _count
;
516 Creature
*pCreature
= ObjectAccessor::GetNPCIfCanInteractWith(*_player
, vendorguid
,UNIT_NPC_FLAG_VENDOR
);
519 sLog
.outDebug( "WORLD: HandleSellItemOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(vendorguid
)) );
520 _player
->SendSellError( SELL_ERR_CANT_FIND_VENDOR
, NULL
, itemguid
, 0);
525 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED
))
526 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
528 Item
*pItem
= _player
->GetItemByGuid( itemguid
);
531 // prevent sell not owner item
532 if(_player
->GetGUID()!=pItem
->GetOwnerGUID())
534 _player
->SendSellError( SELL_ERR_CANT_SELL_ITEM
, pCreature
, itemguid
, 0);
538 // prevent sell non empty bag by drag-and-drop at vendor's item list
539 if(pItem
->IsBag() && !((Bag
*)pItem
)->IsEmpty())
541 _player
->SendSellError( SELL_ERR_CANT_SELL_ITEM
, pCreature
, itemguid
, 0);
545 // prevent sell currently looted item
546 if(_player
->GetLootGUID()==pItem
->GetGUID())
548 _player
->SendSellError( SELL_ERR_CANT_SELL_ITEM
, pCreature
, itemguid
, 0);
552 // special case at auto sell (sell all)
555 count
= pItem
->GetCount();
559 // prevent sell more items that exist in stack (possable only not from client)
560 if(count
> pItem
->GetCount())
562 _player
->SendSellError( SELL_ERR_CANT_SELL_ITEM
, pCreature
, itemguid
, 0);
567 ItemPrototype
const *pProto
= pItem
->GetProto();
570 if( pProto
->SellPrice
> 0 )
572 if(count
< pItem
->GetCount()) // need split items
574 Item
*pNewItem
= pItem
->CloneItem( count
, _player
);
577 sLog
.outError("WORLD: HandleSellItemOpcode - could not create clone of item %u; count = %u", pItem
->GetEntry(), count
);
578 _player
->SendSellError( SELL_ERR_CANT_SELL_ITEM
, pCreature
, itemguid
, 0);
582 pItem
->SetCount( pItem
->GetCount() - count
);
583 _player
->ItemRemovedQuestCheck( pItem
->GetEntry(), count
);
584 if( _player
->IsInWorld() )
585 pItem
->SendUpdateToPlayer( _player
);
586 pItem
->SetState(ITEM_CHANGED
, _player
);
588 _player
->AddItemToBuyBackSlot( pNewItem
);
589 if( _player
->IsInWorld() )
590 pNewItem
->SendUpdateToPlayer( _player
);
594 _player
->ItemRemovedQuestCheck( pItem
->GetEntry(), pItem
->GetCount());
595 _player
->RemoveItem( pItem
->GetBagSlot(), pItem
->GetSlot(), true);
596 pItem
->RemoveFromUpdateQueueOf(_player
);
597 _player
->AddItemToBuyBackSlot( pItem
);
600 _player
->ModifyMoney( pProto
->SellPrice
* count
);
603 _player
->SendSellError( SELL_ERR_CANT_SELL_ITEM
, pCreature
, itemguid
, 0);
607 _player
->SendSellError( SELL_ERR_CANT_FIND_ITEM
, pCreature
, itemguid
, 0);
611 void WorldSession::HandleBuybackItem(WorldPacket
& recv_data
)
613 CHECK_PACKET_SIZE(recv_data
,8+4);
615 sLog
.outDebug( "WORLD: Received CMSG_BUYBACK_ITEM" );
619 recv_data
>> vendorguid
>> slot
;
621 Creature
*pCreature
= ObjectAccessor::GetNPCIfCanInteractWith(*_player
, vendorguid
,UNIT_NPC_FLAG_VENDOR
);
624 sLog
.outDebug( "WORLD: HandleBuybackItem - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(vendorguid
)) );
625 _player
->SendSellError( SELL_ERR_CANT_FIND_VENDOR
, NULL
, 0, 0);
630 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED
))
631 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
633 Item
*pItem
= _player
->GetItemFromBuyBackSlot( slot
);
636 uint32 price
= _player
->GetUInt32Value( PLAYER_FIELD_BUYBACK_PRICE_1
+ slot
- BUYBACK_SLOT_START
);
637 if( _player
->GetMoney() < price
)
639 _player
->SendBuyError( BUY_ERR_NOT_ENOUGHT_MONEY
, pCreature
, pItem
->GetEntry(), 0);
643 ItemPosCountVec dest
;
644 uint8 msg
= _player
->CanStoreItem( NULL_BAG
, NULL_SLOT
, dest
, pItem
, false );
645 if( msg
== EQUIP_ERR_OK
)
647 _player
->ModifyMoney( -(int32
)price
);
648 _player
->RemoveItemFromBuyBackSlot( slot
, false );
649 _player
->ItemAddedQuestCheck( pItem
->GetEntry(), pItem
->GetCount());
650 _player
->StoreItem( dest
, pItem
, true );
653 _player
->SendEquipError( msg
, pItem
, NULL
);
657 _player
->SendBuyError( BUY_ERR_CANT_FIND_ITEM
, pCreature
, 0, 0);
660 void WorldSession::HandleBuyItemInSlotOpcode( WorldPacket
& recv_data
)
662 CHECK_PACKET_SIZE(recv_data
,8+4+8+1+1);
664 sLog
.outDebug( "WORLD: Received CMSG_BUY_ITEM_IN_SLOT" );
665 uint64 vendorguid
, bagguid
;
669 recv_data
>> vendorguid
>> item
>> bagguid
>> slot
>> count
;
671 GetPlayer()->BuyItemFromVendor(vendorguid
,item
,count
,bagguid
,slot
);
674 void WorldSession::HandleBuyItemOpcode( WorldPacket
& recv_data
)
676 CHECK_PACKET_SIZE(recv_data
,8+4+1+1);
678 sLog
.outDebug( "WORLD: Received CMSG_BUY_ITEM" );
683 recv_data
>> vendorguid
>> item
>> count
>> unk1
;
685 GetPlayer()->BuyItemFromVendor(vendorguid
,item
,count
,NULL_BAG
,NULL_SLOT
);
688 void WorldSession::HandleListInventoryOpcode( WorldPacket
& recv_data
)
690 CHECK_PACKET_SIZE(recv_data
,8);
696 if(!GetPlayer()->isAlive())
699 sLog
.outDebug( "WORLD: Recvd CMSG_LIST_INVENTORY" );
701 SendListInventory( guid
);
704 void WorldSession::SendListInventory( uint64 vendorguid
)
706 sLog
.outDebug( "WORLD: Sent SMSG_LIST_INVENTORY" );
708 Creature
*pCreature
= ObjectAccessor::GetNPCIfCanInteractWith(*_player
, vendorguid
,UNIT_NPC_FLAG_VENDOR
);
711 sLog
.outDebug( "WORLD: SendListInventory - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(vendorguid
)) );
712 _player
->SendSellError( SELL_ERR_CANT_FIND_VENDOR
, NULL
, 0, 0);
717 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED
))
718 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
720 // Stop the npc if moving
721 pCreature
->StopMoving();
723 VendorItemData
const* vItems
= pCreature
->GetVendorItems();
726 _player
->SendSellError( SELL_ERR_CANT_FIND_VENDOR
, NULL
, 0, 0);
730 uint8 numitems
= vItems
->GetItemCount();
733 WorldPacket
data( SMSG_LIST_INVENTORY
, (8+1+numitems
*8*4) );
734 data
<< uint64(vendorguid
);
735 data
<< uint8(numitems
);
737 float discountMod
= _player
->GetReputationPriceDiscount(pCreature
);
739 for(int i
= 0; i
< numitems
; i
++ )
741 if(VendorItem
const* crItem
= vItems
->GetItem(i
))
743 if(ItemPrototype
const *pProto
= objmgr
.GetItemPrototype(crItem
->item
))
745 if((pProto
->AllowableClass
& _player
->getClassMask()) == 0 && pProto
->Bonding
== BIND_WHEN_PICKED_UP
&& !_player
->isGameMaster())
750 // reputation discount
751 uint32 price
= uint32(floor(pProto
->BuyPrice
* discountMod
));
753 data
<< uint32(count
);
754 data
<< uint32(crItem
->item
);
755 data
<< uint32(pProto
->DisplayInfoID
);
756 data
<< uint32(crItem
->maxcount
<= 0 ? 0xFFFFFFFF : pCreature
->GetVendorItemCurrentCount(crItem
));
757 data
<< uint32(price
);
758 data
<< uint32(pProto
->MaxDurability
);
759 data
<< uint32(pProto
->BuyCount
);
760 data
<< uint32(crItem
->ExtendedCost
);
765 if ( count
== 0 || data
.size() != 8 + 1 + size_t(count
) * 8 * 4 )
768 data
.put
<uint8
>(8, count
);
772 void WorldSession::HandleAutoStoreBagItemOpcode( WorldPacket
& recv_data
)
774 CHECK_PACKET_SIZE(recv_data
,1+1+1);
776 //sLog.outDebug("WORLD: CMSG_AUTOSTORE_BAG_ITEM");
777 uint8 srcbag
, srcslot
, dstbag
;
779 recv_data
>> srcbag
>> srcslot
>> dstbag
;
780 //sLog.outDebug("STORAGE: receive srcbag = %u, srcslot = %u, dstbag = %u", srcbag, srcslot, dstbag);
782 Item
*pItem
= _player
->GetItemByPos( srcbag
, srcslot
);
786 if(!_player
->IsValidPos(dstbag
,NULL_SLOT
))
788 _player
->SendEquipError( EQUIP_ERR_ITEM_DOESNT_GO_TO_SLOT
, NULL
, NULL
);
792 uint16 src
= pItem
->GetPos();
794 // check unequip potability for equipped items and bank bags
795 if(_player
->IsEquipmentPos ( src
) || _player
->IsBagPos ( src
))
797 uint8 msg
= _player
->CanUnequipItem( src
, !_player
->IsBagPos ( src
));
798 if(msg
!= EQUIP_ERR_OK
)
800 _player
->SendEquipError( msg
, pItem
, NULL
);
805 ItemPosCountVec dest
;
806 uint8 msg
= _player
->CanStoreItem( dstbag
, NULL_SLOT
, dest
, pItem
, false );
807 if( msg
!= EQUIP_ERR_OK
)
809 _player
->SendEquipError( msg
, pItem
, NULL
);
813 // no-op: placed in same slot
814 if(dest
.size()==1 && dest
[0].pos
==src
)
816 // just remove grey item state
817 _player
->SendEquipError( EQUIP_ERR_NONE
, pItem
, NULL
);
821 _player
->RemoveItem(srcbag
, srcslot
, true );
822 _player
->StoreItem( dest
, pItem
, true );
825 void WorldSession::HandleBuyBankSlotOpcode(WorldPacket
& /*recvPacket*/)
827 sLog
.outDebug("WORLD: CMSG_BUY_BANK_SLOT");
829 uint32 slot
= _player
->GetByteValue(PLAYER_BYTES_2
, 2);
834 sLog
.outDetail("PLAYER: Buy bank bag slot, slot number = %u", slot
);
836 BankBagSlotPricesEntry
const* slotEntry
= sBankBagSlotPricesStore
.LookupEntry(slot
);
841 uint32 price
= slotEntry
->price
;
843 if (_player
->GetMoney() < price
)
846 _player
->SetByteValue(PLAYER_BYTES_2
, 2, slot
);
847 _player
->ModifyMoney(-int32(price
));
850 void WorldSession::HandleAutoBankItemOpcode(WorldPacket
& recvPacket
)
852 CHECK_PACKET_SIZE(recvPacket
,1+1);
854 sLog
.outDebug("WORLD: CMSG_AUTOBANK_ITEM");
855 uint8 srcbag
, srcslot
;
857 recvPacket
>> srcbag
>> srcslot
;
858 sLog
.outDebug("STORAGE: receive srcbag = %u, srcslot = %u", srcbag
, srcslot
);
860 Item
*pItem
= _player
->GetItemByPos( srcbag
, srcslot
);
864 ItemPosCountVec dest
;
865 uint8 msg
= _player
->CanBankItem( NULL_BAG
, NULL_SLOT
, dest
, pItem
, false );
866 if( msg
!= EQUIP_ERR_OK
)
868 _player
->SendEquipError( msg
, pItem
, NULL
);
872 _player
->RemoveItem(srcbag
, srcslot
, true);
873 _player
->BankItem( dest
, pItem
, true );
876 void WorldSession::HandleAutoStoreBankItemOpcode(WorldPacket
& recvPacket
)
878 CHECK_PACKET_SIZE(recvPacket
,1+1);
880 sLog
.outDebug("WORLD: CMSG_AUTOSTORE_BANK_ITEM");
881 uint8 srcbag
, srcslot
;
883 recvPacket
>> srcbag
>> srcslot
;
884 sLog
.outDebug("STORAGE: receive srcbag = %u, srcslot = %u", srcbag
, srcslot
);
886 Item
*pItem
= _player
->GetItemByPos( srcbag
, srcslot
);
890 if(_player
->IsBankPos(srcbag
, srcslot
)) // moving from bank to inventory
892 ItemPosCountVec dest
;
893 uint8 msg
= _player
->CanStoreItem( NULL_BAG
, NULL_SLOT
, dest
, pItem
, false );
894 if( msg
!= EQUIP_ERR_OK
)
896 _player
->SendEquipError( msg
, pItem
, NULL
);
900 _player
->RemoveItem(srcbag
, srcslot
, true);
901 _player
->StoreItem( dest
, pItem
, true );
903 else // moving from inventory to bank
905 ItemPosCountVec dest
;
906 uint8 msg
= _player
->CanBankItem( NULL_BAG
, NULL_SLOT
, dest
, pItem
, false );
907 if( msg
!= EQUIP_ERR_OK
)
909 _player
->SendEquipError( msg
, pItem
, NULL
);
913 _player
->RemoveItem(srcbag
, srcslot
, true);
914 _player
->BankItem( dest
, pItem
, true );
918 void WorldSession::HandleSetAmmoOpcode(WorldPacket
& recv_data
)
920 CHECK_PACKET_SIZE(recv_data
,4);
922 if(!GetPlayer()->isAlive())
924 GetPlayer()->SendEquipError( EQUIP_ERR_YOU_ARE_DEAD
, NULL
, NULL
);
928 sLog
.outDebug("WORLD: CMSG_SET_AMMO");
934 GetPlayer()->RemoveAmmo();
936 GetPlayer()->SetAmmo(item
);
939 void WorldSession::SendEnchantmentLog(uint64 Target
, uint64 Caster
,uint32 ItemID
,uint32 SpellID
)
941 WorldPacket
data(SMSG_ENCHANTMENTLOG
, (8+8+4+4+1)); // last check 2.0.10
950 void WorldSession::SendItemEnchantTimeUpdate(uint64 Playerguid
, uint64 Itemguid
,uint32 slot
,uint32 Duration
)
953 WorldPacket
data(SMSG_ITEM_ENCHANT_TIME_UPDATE
, (8+4+4+8));
954 data
<< uint64(Itemguid
);
955 data
<< uint32(slot
);
956 data
<< uint32(Duration
);
957 data
<< uint64(Playerguid
);
961 void WorldSession::HandleItemNameQueryOpcode(WorldPacket
& recv_data
)
963 CHECK_PACKET_SIZE(recv_data
,4);
967 sLog
.outDebug("WORLD: CMSG_ITEM_NAME_QUERY %u", itemid
);
968 ItemPrototype
const *pProto
= objmgr
.GetItemPrototype( itemid
);
972 Name
= pProto
->Name1
;
974 int loc_idx
= GetSessionDbLocaleIndex();
977 ItemLocale
const *il
= objmgr
.GetItemLocale(pProto
->ItemId
);
980 if (il
->Name
.size() > size_t(loc_idx
) && !il
->Name
[loc_idx
].empty())
981 Name
= il
->Name
[loc_idx
];
985 WorldPacket
data(SMSG_ITEM_NAME_QUERY_RESPONSE
, (4+10));
986 data
<< uint32(pProto
->ItemId
);
988 data
<< uint32(pProto
->InventoryType
);
993 sLog
.outDebug("WORLD: CMSG_ITEM_NAME_QUERY for item %u failed (unknown item)", itemid
);
996 void WorldSession::HandleWrapItemOpcode(WorldPacket
& recv_data
)
998 CHECK_PACKET_SIZE(recv_data
,1+1+1+1);
1000 sLog
.outDebug("Received opcode CMSG_WRAP_ITEM");
1002 uint8 gift_bag
, gift_slot
, item_bag
, item_slot
;
1003 //recv_data.hexlike();
1005 recv_data
>> gift_bag
>> gift_slot
; // paper
1006 recv_data
>> item_bag
>> item_slot
; // item
1008 sLog
.outDebug("WRAP: receive gift_bag = %u, gift_slot = %u, item_bag = %u, item_slot = %u", gift_bag
, gift_slot
, item_bag
, item_slot
);
1010 Item
*gift
= _player
->GetItemByPos( gift_bag
, gift_slot
);
1013 _player
->SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND
, gift
, NULL
);
1017 if(!gift
->HasFlag(ITEM_FIELD_FLAGS
, ITEM_FLAGS_WRAPPER
))// cheating: non-wrapper wrapper
1019 _player
->SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND
, gift
, NULL
);
1023 Item
*item
= _player
->GetItemByPos( item_bag
, item_slot
);
1027 _player
->SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND
, item
, NULL
);
1031 if(item
==gift
) // not possable with pacjket from real client
1033 _player
->SendEquipError( EQUIP_ERR_WRAPPED_CANT_BE_WRAPPED
, item
, NULL
);
1037 if(item
->IsEquipped())
1039 _player
->SendEquipError( EQUIP_ERR_EQUIPPED_CANT_BE_WRAPPED
, item
, NULL
);
1043 if(item
->GetUInt64Value(ITEM_FIELD_GIFTCREATOR
)) // HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_WRAPPED);
1045 _player
->SendEquipError( EQUIP_ERR_WRAPPED_CANT_BE_WRAPPED
, item
, NULL
);
1051 _player
->SendEquipError( EQUIP_ERR_BAGS_CANT_BE_WRAPPED
, item
, NULL
);
1055 if(item
->IsSoulBound())
1057 _player
->SendEquipError( EQUIP_ERR_BOUND_CANT_BE_WRAPPED
, item
, NULL
);
1061 if(item
->GetMaxStackCount() != 1)
1063 _player
->SendEquipError( EQUIP_ERR_STACKABLE_CANT_BE_WRAPPED
, item
, NULL
);
1067 // maybe not correct check (it is better than nothing)
1068 if(item
->GetProto()->MaxCount
>0)
1070 _player
->SendEquipError( EQUIP_ERR_UNIQUE_CANT_BE_WRAPPED
, item
, NULL
);
1074 CharacterDatabase
.BeginTransaction();
1075 CharacterDatabase
.PExecute("INSERT INTO character_gifts VALUES ('%u', '%u', '%u', '%u')", GUID_LOPART(item
->GetOwnerGUID()), item
->GetGUIDLow(), item
->GetEntry(), item
->GetUInt32Value(ITEM_FIELD_FLAGS
));
1076 item
->SetEntry(gift
->GetEntry());
1078 switch (item
->GetEntry())
1080 case 5042: item
->SetEntry( 5043); break;
1081 case 5048: item
->SetEntry( 5044); break;
1082 case 17303: item
->SetEntry(17302); break;
1083 case 17304: item
->SetEntry(17305); break;
1084 case 17307: item
->SetEntry(17308); break;
1085 case 21830: item
->SetEntry(21831); break;
1087 item
->SetUInt64Value(ITEM_FIELD_GIFTCREATOR
, _player
->GetGUID());
1088 item
->SetUInt32Value(ITEM_FIELD_FLAGS
, ITEM_FLAGS_WRAPPED
);
1089 item
->SetState(ITEM_CHANGED
, _player
);
1091 if(item
->GetState()==ITEM_NEW
) // save new item, to have alway for `character_gifts` record in `item_instance`
1093 // after save it will be impossible to remove the item from the queue
1094 item
->RemoveFromUpdateQueueOf(_player
);
1095 item
->SaveToDB(); // item gave inventory record unchanged and can be save standalone
1097 CharacterDatabase
.CommitTransaction();
1100 _player
->DestroyItemCount(gift
, count
, true);
1103 void WorldSession::HandleSocketOpcode(WorldPacket
& recv_data
)
1105 sLog
.outDebug("WORLD: CMSG_SOCKET_GEMS");
1107 CHECK_PACKET_SIZE(recv_data
,8*4);
1110 uint32 GemEnchants
[3], OldEnchants
[3];
1112 bool SocketBonusActivated
, SocketBonusToBeActivated
;
1114 for(int i
= 0; i
< 4; i
++)
1115 recv_data
>> guids
[i
];
1120 //cheat -> tried to socket same gem multiple times
1121 if((guids
[1] && (guids
[1] == guids
[2] || guids
[1] == guids
[3])) || (guids
[2] && (guids
[2] == guids
[3])))
1124 Item
*itemTarget
= _player
->GetItemByGuid(guids
[0]);
1125 if(!itemTarget
) //missing item to socket
1128 //this slot is excepted when applying / removing meta gem bonus
1129 uint8 slot
= itemTarget
->IsEquipped() ? itemTarget
->GetSlot() : NULL_SLOT
;
1131 for(int i
= 0; i
< 3; i
++)
1132 Gems
[i
] = guids
[i
+ 1] ? _player
->GetItemByGuid(guids
[i
+ 1]) : NULL
;
1134 GemPropertiesEntry
const *GemProps
[3];
1135 for(int i
= 0; i
< 3; ++i
) //get geminfo from dbc storage
1137 GemProps
[i
] = (Gems
[i
]) ? sGemPropertiesStore
.LookupEntry(Gems
[i
]->GetProto()->GemProperties
) : NULL
;
1140 for(int i
= 0; i
< 3; ++i
) //check for hack maybe
1142 // tried to put gem in socket where no socket exists / tried to put normal gem in meta socket
1143 // tried to put meta gem in normal socket
1144 if( GemProps
[i
] && ( !itemTarget
->GetProto()->Socket
[i
].Color
||
1145 itemTarget
->GetProto()->Socket
[i
].Color
== SOCKET_COLOR_META
&& GemProps
[i
]->color
!= SOCKET_COLOR_META
||
1146 itemTarget
->GetProto()->Socket
[i
].Color
!= SOCKET_COLOR_META
&& GemProps
[i
]->color
== SOCKET_COLOR_META
) )
1150 for(int i
= 0; i
< 3; ++i
) //get new and old enchantments
1152 GemEnchants
[i
] = (GemProps
[i
]) ? GemProps
[i
]->spellitemenchantement
: 0;
1153 OldEnchants
[i
] = itemTarget
->GetEnchantmentId(EnchantmentSlot(SOCK_ENCHANTMENT_SLOT
+i
));
1156 // check unique-equipped conditions
1157 for(int i
= 0; i
< 3; ++i
)
1159 if (Gems
[i
] && (Gems
[i
]->GetProto()->Flags
& ITEM_FLAGS_UNIQUE_EQUIPPED
))
1161 // for equipped item check all equipment for duplicate equipped gems
1162 if(itemTarget
->IsEquipped())
1164 if(GetPlayer()->GetItemOrItemWithGemEquipped(Gems
[i
]->GetEntry()))
1166 _player
->SendEquipError( EQUIP_ERR_ITEM_UNIQUE_EQUIPABLE
, itemTarget
, NULL
);
1171 // continue check for case when attempt add 2 similar unique equipped gems in one item.
1172 for (int j
= 0; j
< 3; ++j
)
1174 if ((i
!= j
) && (Gems
[j
]) && (Gems
[i
]->GetProto()->ItemId
== Gems
[j
]->GetProto()->ItemId
))
1176 _player
->SendEquipError( EQUIP_ERR_ITEM_UNIQUE_EQUIPPABLE_SOCKETED
, itemTarget
, NULL
);
1180 for (int j
= 0; j
< 3; ++j
)
1184 SpellItemEnchantmentEntry
const* enchantEntry
= sSpellItemEnchantmentStore
.LookupEntry(OldEnchants
[j
]);
1188 if ((enchantEntry
->GemID
== Gems
[i
]->GetProto()->ItemId
) && (i
!= j
))
1190 _player
->SendEquipError( EQUIP_ERR_ITEM_UNIQUE_EQUIPPABLE_SOCKETED
, itemTarget
, NULL
);
1198 SocketBonusActivated
= itemTarget
->GemsFitSockets(); //save state of socketbonus
1199 _player
->ToggleMetaGemsActive(slot
, false); //turn off all metagems (except for the target item)
1201 //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
1203 //remove ALL enchants
1204 for(uint32 enchant_slot
= SOCK_ENCHANTMENT_SLOT
; enchant_slot
< SOCK_ENCHANTMENT_SLOT
+3; ++enchant_slot
)
1205 _player
->ApplyEnchantment(itemTarget
,EnchantmentSlot(enchant_slot
),false);
1207 for(int i
= 0; i
< 3; ++i
)
1211 itemTarget
->SetEnchantment(EnchantmentSlot(SOCK_ENCHANTMENT_SLOT
+i
), GemEnchants
[i
],0,0);
1212 if(Item
* guidItem
= _player
->GetItemByGuid(guids
[i
+ 1]))
1213 _player
->DestroyItem(guidItem
->GetBagSlot(), guidItem
->GetSlot(), true );
1217 for(uint32 enchant_slot
= SOCK_ENCHANTMENT_SLOT
; enchant_slot
< SOCK_ENCHANTMENT_SLOT
+3; ++enchant_slot
)
1218 _player
->ApplyEnchantment(itemTarget
,EnchantmentSlot(enchant_slot
),true);
1220 SocketBonusToBeActivated
= itemTarget
->GemsFitSockets();//current socketbonus state
1221 if(SocketBonusActivated
^ SocketBonusToBeActivated
) //if there was a change...
1223 _player
->ApplyEnchantment(itemTarget
,BONUS_ENCHANTMENT_SLOT
,false);
1224 itemTarget
->SetEnchantment(BONUS_ENCHANTMENT_SLOT
, (SocketBonusToBeActivated
? itemTarget
->GetProto()->socketBonus
: 0), 0, 0);
1225 _player
->ApplyEnchantment(itemTarget
,BONUS_ENCHANTMENT_SLOT
,true);
1226 //it is not displayed, client has an inbuilt system to determine if the bonus is activated
1229 _player
->ToggleMetaGemsActive(slot
, true); //turn on all metagems (except for target item)
1232 void WorldSession::HandleCancelTempItemEnchantmentOpcode(WorldPacket
& recv_data
)
1234 sLog
.outDebug("WORLD: CMSG_CANCEL_TEMP_ENCHANTMENT");
1236 CHECK_PACKET_SIZE(recv_data
,4);
1242 // apply only to equipped item
1243 if(!Player::IsEquipmentPos(INVENTORY_SLOT_BAG_0
,eslot
))
1246 Item
* item
= GetPlayer()->GetItemByPos(INVENTORY_SLOT_BAG_0
, eslot
);
1251 if(!item
->GetEnchantmentId(TEMP_ENCHANTMENT_SLOT
))
1254 GetPlayer()->ApplyEnchantment(item
,TEMP_ENCHANTMENT_SLOT
,false);
1255 item
->ClearEnchantment(TEMP_ENCHANTMENT_SLOT
);