Created
October 22, 2011 11:28
-
-
Save DDuarte/1305892 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Goes into AuctionHouseHandler.cpp | |
#include "ObjectMgr.h" | |
#include "Player.h" | |
#include "World.h" | |
#include "WorldPacket.h" | |
#include "WorldSession.h" | |
#include "Item.h" | |
#include "Common.h" | |
#include "ObjectMgr.h" | |
#include "UpdateData.h" | |
#include "ObjectAccessor.h" | |
#include "SpellInfo.h" | |
#include "AuctionHouseMgr.h" | |
#include "Log.h" | |
#include "Opcodes.h" | |
#include "UpdateMask.h" | |
#include "Util.h | |
//this void creates new auction and adds auction to some auctionhouse | |
void WorldSession::HandleAuctionSellItem(WorldPacket & recv_data) | |
{ | |
uint64 auctioneer; | |
uint32 items_count, etime, bid, buyout; | |
recv_data >> auctioneer; | |
recv_data >> items_count; | |
uint64 itemGUIDs[MAX_AUCTION_ITEMS]; // 160 slot = 4x 36 slot bag + backpack 16 slot | |
uint32 count[MAX_AUCTION_ITEMS]; | |
for (uint32 i = 0; i < items_count; ++i) | |
{ | |
recv_data >> itemGUIDs[i]; | |
recv_data >> count[i]; | |
if (!itemGUIDs[i] || !count[i] || count[i] > 1000 ) | |
return; | |
} | |
recv_data >> bid; | |
recv_data >> buyout; | |
recv_data >> etime; | |
if (!bid || !etime) | |
return; | |
Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(auctioneer, UNIT_NPC_FLAG_AUCTIONEER); | |
if (!pCreature) | |
{ | |
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: HandleAuctionSellItem - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(auctioneer))); | |
return; | |
} | |
AuctionHouseEntry const* auctionHouseEntry = AuctionHouseMgr::GetAuctionHouseEntry(pCreature->getFaction()); | |
if (!auctionHouseEntry) | |
{ | |
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: HandleAuctionSellItem - Unit (GUID: %u) has wrong faction.", uint32(GUID_LOPART(auctioneer))); | |
return; | |
} | |
if (items_count > MAX_AUCTION_ITEMS) | |
{ | |
SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_INTERNAL_ERROR); | |
return; | |
} | |
etime *= MINUTE; | |
switch(etime) | |
{ | |
case 1*MIN_AUCTION_TIME: | |
case 2*MIN_AUCTION_TIME: | |
case 4*MIN_AUCTION_TIME: | |
break; | |
default: | |
return; | |
} | |
if (GetPlayer()->HasUnitState(UNIT_STAT_DIED)) | |
GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH); | |
Item* items[MAX_AUCTION_ITEMS]; | |
uint32 final_count = 0; | |
for (uint32 i = 0; i < items_count; ++i) | |
{ | |
Item *item = _player->GetItemByGuid(itemGUIDs[i]); | |
if (!item) | |
{ | |
SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_ITEM_NOT_FOUND); | |
return; | |
} | |
if (sAuctionMgr->GetAItem(item->GetGUIDLow())) | |
{ | |
SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_INTERNAL_ERROR); | |
return; | |
} | |
if (!item->CanBeTraded()) | |
{ | |
SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_INTERNAL_ERROR); | |
return; | |
} | |
if (item->IsNotEmptyBag()) | |
{ | |
SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_INTERNAL_ERROR); | |
return; | |
} | |
if (item->GetTemplate()->Flags & ITEM_PROTO_FLAG_CONJURED || item->GetUInt32Value(ITEM_FIELD_DURATION)) | |
{ | |
SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_INTERNAL_ERROR); | |
return; | |
} | |
if (item->GetCount() < count[i]) | |
{ | |
SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_INTERNAL_ERROR); | |
return; | |
} | |
items[i] = item; | |
final_count = (final_count + count[i]); | |
} | |
if (final_count == 0) | |
{ | |
SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_INTERNAL_ERROR); | |
return; | |
} | |
for (uint32 i = 0; i < items_count; ++i) | |
{ | |
Item *item = items[i]; | |
if (item->GetMaxStackCount() < final_count) | |
{ | |
SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_INTERNAL_ERROR); | |
return; | |
} | |
} | |
for (uint32 i = 0; i < items_count; ++i) | |
{ | |
Item *item = items[i]; | |
uint32 auction_time = uint32(etime * sWorld->getRate(RATE_AUCTION_TIME)); | |
AuctionHouseObject* auctionHouse = sAuctionMgr->GetAuctionsMap(pCreature->getFaction()); | |
uint32 deposit = sAuctionMgr->GetAuctionDeposit(auctionHouseEntry, etime, item, final_count); | |
if (!_player->HasEnoughMoney(deposit)) | |
{ | |
SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_NOT_ENOUGHT_MONEY); | |
return; | |
} | |
_player->ModifyMoney(-int32(deposit)); | |
AuctionEntry *AH = new AuctionEntry; | |
AH->Id = sObjectMgr->GenerateAuctionID(); | |
if (sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION)) | |
AH->auctioneer = 23442; | |
else | |
AH->auctioneer = GUID_LOPART(auctioneer); | |
if (items_count == 1 && item->GetCount() == count[i]) | |
{ | |
if (GetSecurity() > SEC_PLAYER && sWorld->getBoolConfig(CONFIG_GM_LOG_TRADE)) | |
{ | |
sLog->outCommand(GetAccountId(), "GM %s (Account: %u) create auction: %s (Entry: %u Count: %u)", | |
GetPlayerName(), GetAccountId(), item->GetTemplate()->Name1.c_str(), item->GetEntry(), item->GetCount()); | |
} | |
AH->item_guidlow = item->GetGUIDLow(); | |
AH->item_template = item->GetEntry(); | |
AH->owner = _player->GetGUIDLow(); | |
AH->startbid = bid; | |
AH->bidder = 0; | |
AH->bid = 0; | |
AH->buyout = buyout; | |
AH->expire_time = time(NULL) + auction_time; | |
AH->deposit = deposit; | |
AH->auctionHouseEntry = auctionHouseEntry; | |
sLog->outDetail("CMSG_AUCTION_SELL_ITEM: Player %s (guid %d) is selling item %s entry %u (guid %d) to auctioneer %u with count %u with initial bid %u with buyout %u and with time %u (in sec) in auctionhouse %u", _player->GetName(), _player->GetGUIDLow(), item->GetTemplate()->Name1.c_str(), item->GetEntry(), item->GetGUIDLow(), AH->auctioneer, item->GetCount(), bid, buyout, auction_time, AH->GetHouseId()); | |
sAuctionMgr->AddAItem(item); | |
auctionHouse->AddAuction(AH); | |
_player->MoveItemFromInventory(item->GetBagSlot(), item->GetSlot(), true); | |
SQLTransaction trans = CharacterDatabase.BeginTransaction(); | |
item->DeleteFromInventoryDB(trans); | |
item->SaveToDB(trans); | |
AH->SaveToDB(trans); | |
_player->SaveInventoryAndGoldToDB(trans); | |
CharacterDatabase.CommitTransaction(trans); | |
SendAuctionCommandResult(AH->Id, AUCTION_SELL_ITEM, AUCTION_OK); | |
GetPlayer()->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_CREATE_AUCTION, 1); | |
return; | |
} | |
else | |
{ | |
Item *pNewItem = item->CloneItem(final_count, _player); | |
if (!pNewItem) | |
{ | |
sLog->outError("CMSG_AUCTION_SELL_ITEM: Could not create clone of item %u", item->GetEntry()); | |
SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_INTERNAL_ERROR); | |
return; | |
} | |
if (GetSecurity() > SEC_PLAYER && sWorld->getBoolConfig(CONFIG_GM_LOG_TRADE)) | |
{ | |
sLog->outCommand(GetAccountId(), "GM %s (Account: %u) create auction: %s (Entry: %u Count: %u)", | |
GetPlayerName(), GetAccountId(), pNewItem->GetTemplate()->Name1.c_str(), pNewItem->GetEntry(), pNewItem->GetCount()); | |
} | |
AH->item_guidlow = pNewItem->GetGUIDLow(); | |
AH->item_template = pNewItem->GetEntry(); | |
AH->owner = _player->GetGUIDLow(); | |
AH->startbid = bid; | |
AH->bidder = 0; | |
AH->bid = 0; | |
AH->buyout = buyout; | |
AH->expire_time = time(NULL) + auction_time; | |
AH->deposit = deposit; | |
AH->auctionHouseEntry = auctionHouseEntry; | |
sLog->outDetail("CMSG_AUCTION_SELL_ITEM: Player %s (guid %d) is selling item %s entry %u (guid %d) to auctioneer %u with count %u with initial bid %u with buyout %u and with time %u (in sec) in auctionhouse %u", _player->GetName(), _player->GetGUIDLow(), pNewItem->GetTemplate()->Name1.c_str(), pNewItem->GetEntry(), pNewItem->GetGUIDLow(), AH->auctioneer, pNewItem->GetCount(), bid, buyout, auction_time, AH->GetHouseId()); | |
sAuctionMgr->AddAItem(pNewItem); | |
auctionHouse->AddAuction(AH); | |
for (uint32 i = 0; i < items_count; ++i) | |
{ | |
Item *item = items[i]; | |
if (item->GetCount() == count[i]) | |
{ | |
_player->MoveItemFromInventory(item->GetBagSlot(), item->GetSlot(), true); | |
SQLTransaction trans = CharacterDatabase.BeginTransaction(); | |
item->DeleteFromInventoryDB(trans); | |
item->SaveToDB(trans); | |
CharacterDatabase.CommitTransaction(trans); | |
} | |
else | |
{ | |
item->SetCount(item->GetCount() - count[i]); | |
item->SetState(ITEM_CHANGED, _player); | |
_player->ItemRemovedQuestCheck(item->GetEntry(), count[i]); | |
item->SendUpdateToPlayer(_player); | |
SQLTransaction trans = CharacterDatabase.BeginTransaction(); | |
item->SaveToDB(trans); | |
CharacterDatabase.CommitTransaction(trans); | |
} | |
} | |
SQLTransaction trans = CharacterDatabase.BeginTransaction(); | |
AH->SaveToDB(trans); | |
_player->SaveInventoryAndGoldToDB(trans); | |
CharacterDatabase.CommitTransaction(trans); | |
SendAuctionCommandResult(AH->Id, AUCTION_SELL_ITEM, AUCTION_OK); | |
GetPlayer()->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_CREATE_AUCTION, 1); | |
return; | |
} | |
} | |
} | |
Goes into AuctionHouseMgr.h | |
#define MAX_AUCTION_ITEMS 160 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment