[9581] Fixed apply damage reduction to melee/ranged damage.
[getmangos.git] / src / game / AuctionHouseHandler.cpp
blob1a8425c429fc44835469de3bde4a16b1715dc55d
1 /*
2 * Copyright (C) 2005-2010 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 "WorldPacket.h"
20 #include "WorldSession.h"
21 #include "Opcodes.h"
22 #include "Log.h"
23 #include "World.h"
24 #include "ObjectMgr.h"
25 #include "ObjectGuid.h"
26 #include "Player.h"
27 #include "UpdateMask.h"
28 #include "AuctionHouseMgr.h"
29 #include "Util.h"
31 //please DO NOT use iterator++, because it is slower than ++iterator!!!
32 //post-incrementation is always slower than pre-incrementation !
34 //void called when player click on auctioneer npc
35 void WorldSession::HandleAuctionHelloOpcode( WorldPacket & recv_data )
37 uint64 guid; //NPC guid
38 recv_data >> guid;
40 Creature *unit = GetPlayer()->GetNPCIfCanInteractWith(guid,UNIT_NPC_FLAG_AUCTIONEER);
41 if (!unit)
43 sLog.outDebug( "WORLD: HandleAuctionHelloOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) );
44 return;
47 // remove fake death
48 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
49 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
51 SendAuctionHello(guid, unit);
54 //this void causes that auction window is opened
55 void WorldSession::SendAuctionHello( uint64 guid, Creature* unit )
57 AuctionHouseEntry const* ahEntry = AuctionHouseMgr::GetAuctionHouseEntry(unit->getFaction());
58 if(!ahEntry)
59 return;
61 WorldPacket data( MSG_AUCTION_HELLO, 12 );
62 data << (uint64) guid;
63 data << (uint32) ahEntry->houseId;
64 SendPacket( &data );
67 //call this method when player bids, creates, or deletes auction
68 void WorldSession::SendAuctionCommandResult(uint32 auctionId, uint32 Action, uint32 ErrorCode, uint32 bidError )
70 WorldPacket data( SMSG_AUCTION_COMMAND_RESULT, 16 );
71 data << auctionId;
72 data << Action;
73 data << ErrorCode;
74 if ( !ErrorCode && Action )
75 data << bidError; //when bid, then send 0, once...
76 SendPacket(&data);
79 //this function sends notification, if bidder is online
80 void WorldSession::SendAuctionBidderNotification( uint32 location, uint32 auctionId, uint64 bidder, uint32 bidSum, uint32 diff, uint32 item_template)
82 WorldPacket data(SMSG_AUCTION_BIDDER_NOTIFICATION, (8*4));
83 data << uint32(location);
84 data << uint32(auctionId);
85 data << uint64(bidder);
86 data << uint32(bidSum);
87 data << uint32(diff);
88 data << uint32(item_template);
89 data << uint32(0);
90 SendPacket(&data);
93 //this void causes on client to display: "Your auction sold"
94 void WorldSession::SendAuctionOwnerNotification( AuctionEntry* auction)
96 WorldPacket data(SMSG_AUCTION_OWNER_NOTIFICATION, (7*4));
97 data << auction->Id;
98 data << auction->bid;
99 data << (uint32) 0; //unk
100 data << (uint32) 0; //unk
101 data << (uint32) 0; //unk
102 data << auction->item_template;
103 data << (uint32) 0; //unk
104 SendPacket(&data);
107 //this function sends mail to old bidder
108 void WorldSession::SendAuctionOutbiddedMail(AuctionEntry *auction, uint32 newPrice)
110 uint64 oldBidder_guid = MAKE_NEW_GUID(auction->bidder,0, HIGHGUID_PLAYER);
111 Player *oldBidder = sObjectMgr.GetPlayer(oldBidder_guid);
113 uint32 oldBidder_accId = 0;
114 if(!oldBidder)
115 oldBidder_accId = sObjectMgr.GetPlayerAccountIdByGUID(oldBidder_guid);
117 // old bidder exist
118 if(oldBidder || oldBidder_accId)
120 std::ostringstream msgAuctionOutbiddedSubject;
121 msgAuctionOutbiddedSubject << auction->item_template << ":0:" << AUCTION_OUTBIDDED;
123 if (oldBidder)
124 oldBidder->GetSession()->SendAuctionBidderNotification( auction->GetHouseId(), auction->Id, _player->GetGUID(), newPrice, auction->GetAuctionOutBid(), auction->item_template);
126 MailDraft(msgAuctionOutbiddedSubject.str())
127 .AddMoney(auction->bid)
128 .SendMailTo(MailReceiver(oldBidder, auction->bidder), auction);
132 //this function sends mail, when auction is cancelled to old bidder
133 void WorldSession::SendAuctionCancelledToBidderMail( AuctionEntry* auction )
135 uint64 bidder_guid = MAKE_NEW_GUID(auction->bidder, 0, HIGHGUID_PLAYER);
136 Player *bidder = sObjectMgr.GetPlayer(bidder_guid);
138 uint32 bidder_accId = 0;
139 if(!bidder)
140 bidder_accId = sObjectMgr.GetPlayerAccountIdByGUID(bidder_guid);
142 // bidder exist
143 if(bidder || bidder_accId)
145 std::ostringstream msgAuctionCancelledSubject;
146 msgAuctionCancelledSubject << auction->item_template << ":0:" << AUCTION_CANCELLED_TO_BIDDER;
148 MailDraft(msgAuctionCancelledSubject.str())
149 .AddMoney(auction->bid)
150 .SendMailTo(MailReceiver(bidder, auction->bidder), auction);
154 //this void creates new auction and adds auction to some auctionhouse
155 void WorldSession::HandleAuctionSellItem( WorldPacket & recv_data )
157 uint64 auctioneer, item;
158 uint32 etime, bid, buyout;
159 recv_data >> auctioneer;
160 recv_data.read_skip<uint32>(); // const 1?
161 recv_data >> item;
162 recv_data.read_skip<uint32>(); // unk 3.2.2, const 1?
163 recv_data >> bid;
164 recv_data >> buyout;
165 recv_data >> etime;
167 Player *pl = GetPlayer();
169 if (!item || !bid || !etime)
170 return; //check for cheaters
172 Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(auctioneer,UNIT_NPC_FLAG_AUCTIONEER);
173 if (!pCreature)
175 sLog.outDebug( "WORLD: HandleAuctionSellItem - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(auctioneer)) );
176 return;
179 AuctionHouseEntry const* auctionHouseEntry = AuctionHouseMgr::GetAuctionHouseEntry(pCreature->getFaction());
180 if(!auctionHouseEntry)
182 sLog.outDebug( "WORLD: HandleAuctionSellItem - Unit (GUID: %u) has wrong faction.", uint32(GUID_LOPART(auctioneer)) );
183 return;
186 // client send time in minutes, convert to common used sec time
187 etime *= MINUTE;
189 // client understand only 3 auction time
190 switch(etime)
192 case 1*MIN_AUCTION_TIME:
193 case 2*MIN_AUCTION_TIME:
194 case 4*MIN_AUCTION_TIME:
195 break;
196 default:
197 return;
200 // remove fake death
201 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
202 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
204 Item *it = pl->GetItemByGuid( item );
205 //do not allow to sell already auctioned items
206 if(sAuctionMgr.GetAItem(GUID_LOPART(item)))
208 sLog.outError("AuctionError, player %s is sending item id: %u, but item is already in another auction", pl->GetName(), GUID_LOPART(item));
209 SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_INTERNAL_ERROR);
210 return;
212 // prevent sending bag with items (cheat: can be placed in bag after adding equiped empty bag to auction)
213 if(!it)
215 SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_ITEM_NOT_FOUND);
216 return;
219 if(!it->CanBeTraded())
221 SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_INTERNAL_ERROR);
222 return;
225 if (it->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_CONJURED) || it->GetUInt32Value(ITEM_FIELD_DURATION))
227 SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_INTERNAL_ERROR);
228 return;
231 AuctionHouseObject* auctionHouse = sAuctionMgr.GetAuctionsMap( pCreature->getFaction() );
233 //we have to take deposit :
234 uint32 deposit = AuctionHouseMgr::GetAuctionDeposit( auctionHouseEntry, etime, it );
235 if ( pl->GetMoney() < deposit )
237 SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_NOT_ENOUGHT_MONEY);
238 return;
241 if( GetSecurity() > SEC_PLAYER && sWorld.getConfig(CONFIG_BOOL_GM_LOG_TRADE) )
243 sLog.outCommand(GetAccountId(),"GM %s (Account: %u) create auction: %s (Entry: %u Count: %u)",
244 GetPlayerName(),GetAccountId(),it->GetProto()->Name1,it->GetEntry(),it->GetCount());
247 pl->ModifyMoney( -int32(deposit) );
249 uint32 auction_time = uint32(etime * sWorld.getConfig(CONFIG_FLOAT_RATE_AUCTION_TIME));
251 AuctionEntry *AH = new AuctionEntry;
252 AH->Id = sObjectMgr.GenerateAuctionID();
253 AH->auctioneer = GUID_LOPART(auctioneer);
254 AH->item_guidlow = GUID_LOPART(item);
255 AH->item_template = it->GetEntry();
256 AH->owner = pl->GetGUIDLow();
257 AH->startbid = bid;
258 AH->bidder = 0;
259 AH->bid = 0;
260 AH->buyout = buyout;
261 AH->expire_time = time(NULL) + auction_time;
262 AH->deposit = deposit;
263 AH->auctionHouseEntry = auctionHouseEntry;
265 sLog.outDetail("selling item %u to auctioneer %u with initial bid %u with buyout %u and with time %u (in sec) in auctionhouse %u", GUID_LOPART(item), GUID_LOPART(auctioneer), bid, buyout, auction_time, AH->GetHouseId());
266 auctionHouse->AddAuction(AH);
268 sAuctionMgr.AddAItem(it);
269 pl->MoveItemFromInventory( it->GetBagSlot(), it->GetSlot(), true);
271 CharacterDatabase.BeginTransaction();
272 it->DeleteFromInventoryDB();
273 it->SaveToDB(); // recursive and not have transaction guard into self, not in inventiory and can be save standalone
274 AH->SaveToDB();
275 pl->SaveInventoryAndGoldToDB();
276 CharacterDatabase.CommitTransaction();
278 SendAuctionCommandResult(AH->Id, AUCTION_SELL_ITEM, AUCTION_OK);
280 GetPlayer()->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_CREATE_AUCTION, 1);
283 //this function is called when client bids or buys out auction
284 void WorldSession::HandleAuctionPlaceBid( WorldPacket & recv_data )
286 uint64 auctioneer;
287 uint32 auctionId;
288 uint32 price;
289 recv_data >> auctioneer;
290 recv_data >> auctionId >> price;
292 if (!auctionId || !price)
293 return; //check for cheaters
295 Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(auctioneer,UNIT_NPC_FLAG_AUCTIONEER);
296 if (!pCreature)
298 sLog.outDebug( "WORLD: HandleAuctionPlaceBid - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(auctioneer)) );
299 return;
302 // remove fake death
303 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
304 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
306 AuctionHouseObject* auctionHouse = sAuctionMgr.GetAuctionsMap( pCreature->getFaction() );
308 AuctionEntry *auction = auctionHouse->GetAuction(auctionId);
309 Player *pl = GetPlayer();
311 if( !auction || auction->owner == pl->GetGUIDLow() )
313 //you cannot bid your own auction:
314 SendAuctionCommandResult( 0, AUCTION_PLACE_BID, CANNOT_BID_YOUR_AUCTION_ERROR );
315 return;
318 // impossible have online own another character (use this for speedup check in case online owner)
319 Player* auction_owner = sObjectMgr.GetPlayer(MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER));
320 if( !auction_owner && sObjectMgr.GetPlayerAccountIdByGUID(MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER)) == pl->GetSession()->GetAccountId())
322 //you cannot bid your another character auction:
323 SendAuctionCommandResult( 0, AUCTION_PLACE_BID, CANNOT_BID_YOUR_AUCTION_ERROR );
324 return;
327 // cheating
328 if(price <= auction->bid || price < auction->startbid)
329 return;
331 // price too low for next bid if not buyout
332 if ((price < auction->buyout || auction->buyout == 0) &&
333 price < auction->bid + auction->GetAuctionOutBid())
335 //auction has already higher bid, client tests it!
336 return;
339 if (price > pl->GetMoney())
341 //you don't have enought money!, client tests!
342 //SendAuctionCommandResult(auction->auctionId, AUCTION_PLACE_BID, ???);
343 return;
346 if ((price < auction->buyout) || (auction->buyout == 0))
348 if (auction->bidder > 0)
350 if ( auction->bidder == pl->GetGUIDLow() )
352 pl->ModifyMoney( -int32(price - auction->bid));
354 else
356 // mail to last bidder and return money
357 SendAuctionOutbiddedMail( auction , price );
358 pl->ModifyMoney( -int32(price) );
361 else
363 pl->ModifyMoney( -int32(price) );
365 auction->bidder = pl->GetGUIDLow();
366 auction->bid = price;
367 GetPlayer()->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_AUCTION_BID, price);
369 // after this update we should save player's money ...
370 CharacterDatabase.PExecute("UPDATE auctionhouse SET buyguid = '%u',lastbid = '%u' WHERE id = '%u'", auction->bidder, auction->bid, auction->Id);
372 SendAuctionCommandResult(auction->Id, AUCTION_PLACE_BID, AUCTION_OK, 0 );
374 else
376 //buyout:
377 if (pl->GetGUIDLow() == auction->bidder )
379 pl->ModifyMoney(-int32(auction->buyout - auction->bid));
381 else
383 pl->ModifyMoney(-int32(auction->buyout));
384 if ( auction->bidder ) //buyout for bidded auction ..
386 SendAuctionOutbiddedMail( auction, auction->buyout );
389 auction->bidder = pl->GetGUIDLow();
390 auction->bid = auction->buyout;
391 GetPlayer()->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_AUCTION_BID, auction->buyout);
393 sAuctionMgr.SendAuctionSalePendingMail( auction );
394 sAuctionMgr.SendAuctionSuccessfulMail( auction );
395 sAuctionMgr.SendAuctionWonMail( auction );
397 SendAuctionCommandResult(auction->Id, AUCTION_PLACE_BID, AUCTION_OK);
399 sAuctionMgr.RemoveAItem(auction->item_guidlow);
400 auctionHouse->RemoveAuction(auction->Id);
401 auction->DeleteFromDB();
403 delete auction;
405 CharacterDatabase.BeginTransaction();
406 pl->SaveInventoryAndGoldToDB();
407 CharacterDatabase.CommitTransaction();
410 //this void is called when auction_owner cancels his auction
411 void WorldSession::HandleAuctionRemoveItem( WorldPacket & recv_data )
413 uint64 auctioneer;
414 uint32 auctionId;
415 recv_data >> auctioneer;
416 recv_data >> auctionId;
417 //sLog.outDebug( "Cancel AUCTION AuctionID: %u", auctionId);
419 Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(auctioneer,UNIT_NPC_FLAG_AUCTIONEER);
420 if (!pCreature)
422 sLog.outDebug( "WORLD: HandleAuctionRemoveItem - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(auctioneer)) );
423 return;
426 // remove fake death
427 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
428 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
430 AuctionHouseObject* auctionHouse = sAuctionMgr.GetAuctionsMap( pCreature->getFaction() );
432 AuctionEntry *auction = auctionHouse->GetAuction(auctionId);
433 Player *pl = GetPlayer();
435 if (auction && auction->owner == pl->GetGUIDLow())
437 Item *pItem = sAuctionMgr.GetAItem(auction->item_guidlow);
438 if (pItem)
440 if (auction->bidder > 0) // If we have a bidder, we have to send him the money he paid
442 uint32 auctionCut = auction->GetAuctionCut();
443 if ( pl->GetMoney() < auctionCut ) //player doesn't have enough money, maybe message needed
444 return;
445 //some auctionBidderNotification would be needed, but don't know that parts..
446 SendAuctionCancelledToBidderMail( auction );
447 pl->ModifyMoney( -int32(auctionCut) );
449 // Return the item by mail
450 std::ostringstream msgAuctionCanceledOwner;
451 msgAuctionCanceledOwner << auction->item_template << ":0:" << AUCTION_CANCELED;
453 // item will deleted or added to received mail list
454 MailDraft(msgAuctionCanceledOwner.str())
455 .AddItem(pItem)
456 .SendMailTo(pl, auction);
458 else
460 sLog.outError("Auction id: %u has non-existed item (item guid : %u)!!!", auction->Id, auction->item_guidlow);
461 SendAuctionCommandResult( 0, AUCTION_CANCEL, AUCTION_INTERNAL_ERROR );
462 return;
465 else
467 SendAuctionCommandResult( 0, AUCTION_CANCEL, AUCTION_INTERNAL_ERROR );
468 //this code isn't possible ... maybe there should be assert
469 sLog.outError("CHEATER : %u, he tried to cancel auction (id: %u) of another player, or auction is NULL", pl->GetGUIDLow(), auctionId );
470 return;
473 //inform player, that auction is removed
474 SendAuctionCommandResult( auction->Id, AUCTION_CANCEL, AUCTION_OK );
475 // Now remove the auction
476 CharacterDatabase.BeginTransaction();
477 auction->DeleteFromDB();
478 pl->SaveInventoryAndGoldToDB();
479 CharacterDatabase.CommitTransaction();
480 sAuctionMgr.RemoveAItem( auction->item_guidlow );
481 auctionHouse->RemoveAuction( auction->Id );
482 delete auction;
485 //called when player lists his bids
486 void WorldSession::HandleAuctionListBidderItems( WorldPacket & recv_data )
488 uint64 guid; //NPC guid
489 uint32 listfrom; //page of auctions
490 uint32 outbiddedCount; //count of outbidded auctions
492 recv_data >> guid;
493 recv_data >> listfrom; // not used in fact (this list not have page control in client)
494 recv_data >> outbiddedCount;
495 if (recv_data.size() != (16 + outbiddedCount * 4 ))
497 sLog.outError("Client sent bad opcode!!! with count: %u and size : %lu (must be: %u)", outbiddedCount, (unsigned long)recv_data.size(),(16 + outbiddedCount * 4 ));
498 outbiddedCount = 0;
501 Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(guid,UNIT_NPC_FLAG_AUCTIONEER);
502 if (!pCreature)
504 sLog.outDebug( "WORLD: HandleAuctionListBidderItems - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) );
505 return;
508 // remove fake death
509 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
510 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
512 AuctionHouseObject* auctionHouse = sAuctionMgr.GetAuctionsMap( pCreature->getFaction() );
514 WorldPacket data( SMSG_AUCTION_BIDDER_LIST_RESULT, (4+4+4) );
515 Player *pl = GetPlayer();
516 data << (uint32) 0; //add 0 as count
517 uint32 count = 0;
518 uint32 totalcount = 0;
519 while ( outbiddedCount > 0) //add all data, which client requires
521 --outbiddedCount;
522 uint32 outbiddedAuctionId;
523 recv_data >> outbiddedAuctionId;
524 AuctionEntry * auction = auctionHouse->GetAuction( outbiddedAuctionId );
525 if ( auction && auction->BuildAuctionInfo(data))
527 ++totalcount;
528 ++count;
532 auctionHouse->BuildListBidderItems(data,pl,count,totalcount);
533 data.put<uint32>( 0, count ); // add count to placeholder
534 data << totalcount;
535 data << (uint32)300; //unk 2.3.0
536 SendPacket(&data);
539 //this void sends player info about his auctions
540 void WorldSession::HandleAuctionListOwnerItems( WorldPacket & recv_data )
542 uint32 listfrom;
543 uint64 guid;
545 recv_data >> guid;
546 recv_data >> listfrom; // not used in fact (this list not have page control in client)
548 Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(guid,UNIT_NPC_FLAG_AUCTIONEER);
549 if (!pCreature)
551 sLog.outDebug( "WORLD: HandleAuctionListOwnerItems - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) );
552 return;
555 // remove fake death
556 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
557 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
559 AuctionHouseObject* auctionHouse = sAuctionMgr.GetAuctionsMap( pCreature->getFaction() );
561 WorldPacket data( SMSG_AUCTION_OWNER_LIST_RESULT, (4+4+4) );
562 data << (uint32) 0; // amount place holder
564 uint32 count = 0;
565 uint32 totalcount = 0;
567 auctionHouse->BuildListOwnerItems(data,_player,count,totalcount);
568 data.put<uint32>(0, count);
569 data << (uint32) totalcount;
570 data << (uint32) 0;
571 SendPacket(&data);
574 //this void is called when player clicks on search button
575 void WorldSession::HandleAuctionListItems( WorldPacket & recv_data )
577 std::string searchedname;
578 uint8 levelmin, levelmax, usable;
579 uint32 listfrom, auctionSlotID, auctionMainCategory, auctionSubCategory, quality;
580 uint64 guid;
582 recv_data >> guid;
583 recv_data >> listfrom; // start, used for page control listing by 50 elements
584 recv_data >> searchedname;
586 recv_data >> levelmin >> levelmax;
587 recv_data >> auctionSlotID >> auctionMainCategory >> auctionSubCategory;
588 recv_data >> quality >> usable;
590 recv_data.read_skip(16); // unknown 16 bytes: 00 07 01 00 00 01 05 00 06 00 09 01 08 00 03 00
592 Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(guid,UNIT_NPC_FLAG_AUCTIONEER);
593 if (!pCreature)
595 sLog.outDebug( "WORLD: HandleAuctionListItems - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) );
596 return;
599 // remove fake death
600 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
601 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
603 AuctionHouseObject* auctionHouse = sAuctionMgr.GetAuctionsMap( pCreature->getFaction() );
605 //sLog.outDebug("Auctionhouse search (GUID: %u TypeId: %u)", , list from: %u, searchedname: %s, levelmin: %u, levelmax: %u, auctionSlotID: %u, auctionMainCategory: %u, auctionSubCategory: %u, quality: %u, usable: %u",
606 // GUID_LOPART(guid),GuidHigh2TypeId(GUID_HIPART(guid)), listfrom, searchedname.c_str(), levelmin, levelmax, auctionSlotID, auctionMainCategory, auctionSubCategory, quality, usable);
608 WorldPacket data( SMSG_AUCTION_LIST_RESULT, (4+4+4) );
609 uint32 count = 0;
610 uint32 totalcount = 0;
611 data << (uint32) 0;
613 // converting string that we try to find to lower case
614 std::wstring wsearchedname;
615 if(!Utf8toWStr(searchedname,wsearchedname))
616 return;
618 wstrToLower(wsearchedname);
620 auctionHouse->BuildListAuctionItems(data,_player,
621 wsearchedname, listfrom, levelmin, levelmax, usable,
622 auctionSlotID, auctionMainCategory, auctionSubCategory, quality,
623 count,totalcount);
625 data.put<uint32>(0, count);
626 data << (uint32) totalcount;
627 data << (uint32) 300; // unk 2.3.0 const?
628 SendPacket(&data);
631 void WorldSession::HandleAuctionListPendingSales( WorldPacket & recv_data )
633 sLog.outDebug("CMSG_AUCTION_LIST_PENDING_SALES");
635 recv_data.read_skip<uint64>(); // auctioner guid
637 uint32 count = 0;
639 WorldPacket data(SMSG_AUCTION_LIST_PENDING_SALES, 4);
640 data << uint32(count); // count
641 /*for(uint32 i = 0; i < count; ++i)
643 data << ""; // string
644 data << ""; // string
645 data << uint32(0);
646 data << uint32(0);
647 data << float(0);
649 SendPacket(&data);