mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-30 00:53:46 +00:00
feat(Core/Misc): implement ObjectGuid class (port from TC) (#4885)
This commit is contained in:
@@ -56,8 +56,26 @@ AuctionHouseObject* AuctionHouseMgr::GetAuctionsMap(uint32 factionTemplateId)
|
||||
return &mAllianceAuctions;
|
||||
else if (u_entry->ourMask & FACTION_MASK_HORDE)
|
||||
return &mHordeAuctions;
|
||||
else
|
||||
|
||||
return &mNeutralAuctions;
|
||||
}
|
||||
|
||||
AuctionHouseObject* AuctionHouseMgr::GetAuctionsMapByHouseId(uint8 auctionHouseId)
|
||||
{
|
||||
if (sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION))
|
||||
return &mNeutralAuctions;
|
||||
|
||||
switch(auctionHouseId)
|
||||
{
|
||||
case AUCTIONHOUSE_ALLIANCE:
|
||||
return &mAllianceAuctions;
|
||||
case AUCTIONHOUSE_HORDE:
|
||||
return &mHordeAuctions;
|
||||
break;
|
||||
}
|
||||
|
||||
return &mNeutralAuctions;
|
||||
|
||||
}
|
||||
|
||||
uint32 AuctionHouseMgr::GetAuctionDeposit(AuctionHouseEntry const* entry, uint32 time, Item* pItem, uint32 count)
|
||||
@@ -87,17 +105,16 @@ uint32 AuctionHouseMgr::GetAuctionDeposit(AuctionHouseEntry const* entry, uint32
|
||||
//does not clear ram
|
||||
void AuctionHouseMgr::SendAuctionWonMail(AuctionEntry* auction, SQLTransaction& trans, bool sendNotification, bool updateAchievementCriteria, bool sendMail)
|
||||
{
|
||||
Item* pItem = GetAItem(auction->item_guidlow);
|
||||
Item* pItem = GetAItem(auction->item_guid);
|
||||
if (!pItem)
|
||||
return;
|
||||
|
||||
uint64 bidder_guid = MAKE_NEW_GUID(auction->bidder, 0, HIGHGUID_PLAYER);
|
||||
uint32 bidder_accId = 0;
|
||||
Player* bidder = ObjectAccessor::FindPlayerInOrOutOfWorld(bidder_guid);
|
||||
Player* bidder = ObjectAccessor::FindConnectedPlayer(auction->bidder);
|
||||
if (bidder)
|
||||
bidder_accId = bidder->GetSession()->GetAccountId();
|
||||
else
|
||||
bidder_accId = sObjectMgr->GetPlayerAccountIdByGUID(bidder_guid);
|
||||
bidder_accId = sObjectMgr->GetPlayerAccountIdByGUID(auction->bidder.GetCounter());
|
||||
|
||||
// receiver exist
|
||||
if (bidder || bidder_accId)
|
||||
@@ -106,14 +123,14 @@ void AuctionHouseMgr::SendAuctionWonMail(AuctionEntry* auction, SQLTransaction&
|
||||
// set owner to bidder (to prevent delete item with sender char deleting)
|
||||
// owner in `data` will set at mail receive and item extracting
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ITEM_OWNER);
|
||||
stmt->setUInt32(0, auction->bidder);
|
||||
stmt->setUInt32(1, pItem->GetGUIDLow());
|
||||
stmt->setUInt32(0, auction->bidder.GetCounter());
|
||||
stmt->setUInt32(1, pItem->GetGUID().GetCounter());
|
||||
trans->Append(stmt);
|
||||
|
||||
if (bidder)
|
||||
{
|
||||
if (sendNotification) // can be changed in the hook
|
||||
bidder->GetSession()->SendAuctionBidderNotification(auction->GetHouseId(), auction->Id, bidder_guid, 0, 0, auction->item_template);
|
||||
bidder->GetSession()->SendAuctionBidderNotification(auction->GetHouseId(), auction->Id, auction->bidder, 0, 0, auction->item_template);
|
||||
// FIXME: for offline player need also
|
||||
if (updateAchievementCriteria) // can be changed in the hook
|
||||
bidder->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_WON_AUCTIONS, 1);
|
||||
@@ -122,33 +139,31 @@ void AuctionHouseMgr::SendAuctionWonMail(AuctionEntry* auction, SQLTransaction&
|
||||
if (sendMail) // can be changed in the hook
|
||||
MailDraft(auction->BuildAuctionMailSubject(AUCTION_WON), AuctionEntry::BuildAuctionMailBody(auction->owner, auction->bid, auction->buyout, 0, 0))
|
||||
.AddItem(pItem)
|
||||
.SendMailTo(trans, MailReceiver(bidder, auction->bidder), auction, MAIL_CHECK_MASK_COPIED);
|
||||
.SendMailTo(trans, MailReceiver(bidder, auction->bidder.GetCounter()), auction, MAIL_CHECK_MASK_COPIED);
|
||||
}
|
||||
else
|
||||
sAuctionMgr->RemoveAItem(auction->item_guidlow, true);
|
||||
sAuctionMgr->RemoveAItem(auction->item_guid, true);
|
||||
}
|
||||
|
||||
void AuctionHouseMgr::SendAuctionSalePendingMail(AuctionEntry* auction, SQLTransaction& trans, bool sendMail)
|
||||
{
|
||||
uint64 owner_guid = MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER);
|
||||
Player* owner = ObjectAccessor::FindPlayerInOrOutOfWorld(owner_guid);
|
||||
uint32 owner_accId = sObjectMgr->GetPlayerAccountIdByGUID(owner_guid);
|
||||
Player* owner = ObjectAccessor::FindConnectedPlayer(auction->owner);
|
||||
uint32 owner_accId = sObjectMgr->GetPlayerAccountIdByGUID(auction->owner.GetCounter());
|
||||
// owner exist (online or offline)
|
||||
if (owner || owner_accId)
|
||||
{
|
||||
sScriptMgr->OnBeforeAuctionHouseMgrSendAuctionSalePendingMail(this, auction, owner, owner_accId, sendMail);
|
||||
if (sendMail) // can be changed in the hook
|
||||
MailDraft(auction->BuildAuctionMailSubject(AUCTION_SALE_PENDING), AuctionEntry::BuildAuctionMailBody(auction->bidder, auction->bid, auction->buyout, auction->deposit, auction->GetAuctionCut()))
|
||||
.SendMailTo(trans, MailReceiver(owner, auction->owner), auction, MAIL_CHECK_MASK_COPIED);
|
||||
.SendMailTo(trans, MailReceiver(owner, auction->owner.GetCounter()), auction, MAIL_CHECK_MASK_COPIED);
|
||||
}
|
||||
}
|
||||
|
||||
//call this method to send mail to auction owner, when auction is successful, it does not clear ram
|
||||
void AuctionHouseMgr::SendAuctionSuccessfulMail(AuctionEntry* auction, SQLTransaction& trans, bool sendNotification, bool updateAchievementCriteria, bool sendMail)
|
||||
{
|
||||
uint64 owner_guid = MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER);
|
||||
Player* owner = ObjectAccessor::FindPlayerInOrOutOfWorld(owner_guid);
|
||||
uint32 owner_accId = sObjectMgr->GetPlayerAccountIdByGUID(owner_guid);
|
||||
Player* owner = ObjectAccessor::FindConnectedPlayer(auction->owner);
|
||||
uint32 owner_accId = sObjectMgr->GetPlayerAccountIdByGUID(auction->owner.GetCounter());
|
||||
// owner exist
|
||||
if (owner || owner_accId)
|
||||
{
|
||||
@@ -170,21 +185,21 @@ void AuctionHouseMgr::SendAuctionSuccessfulMail(AuctionEntry* auction, SQLTransa
|
||||
if (sendMail) // can be changed in the hook
|
||||
MailDraft(auction->BuildAuctionMailSubject(AUCTION_SUCCESSFUL), AuctionEntry::BuildAuctionMailBody(auction->bidder, auction->bid, auction->buyout, auction->deposit, auction->GetAuctionCut()))
|
||||
.AddMoney(profit)
|
||||
.SendMailTo(trans, MailReceiver(owner, auction->owner), auction, MAIL_CHECK_MASK_COPIED, sWorld->getIntConfig(CONFIG_MAIL_DELIVERY_DELAY));
|
||||
.SendMailTo(trans, MailReceiver(owner, auction->owner.GetCounter()), auction, MAIL_CHECK_MASK_COPIED, sWorld->getIntConfig(CONFIG_MAIL_DELIVERY_DELAY));
|
||||
|
||||
if (auction->bid >= 500 * GOLD)
|
||||
if (const GlobalPlayerData* gpd = sWorld->GetGlobalPlayerData(auction->bidder))
|
||||
if (const GlobalPlayerData* gpd = sWorld->GetGlobalPlayerData(auction->bidder.GetCounter()))
|
||||
{
|
||||
uint64 bidder_guid = MAKE_NEW_GUID(auction->bidder, 0, HIGHGUID_PLAYER);
|
||||
Player* bidder = ObjectAccessor::FindPlayerInOrOutOfWorld(bidder_guid);
|
||||
Player* bidder = ObjectAccessor::FindConnectedPlayer(auction->bidder);
|
||||
std::string owner_name = "";
|
||||
uint8 owner_level = 0;
|
||||
if (const GlobalPlayerData* gpd_owner = sWorld->GetGlobalPlayerData(auction->owner))
|
||||
if (const GlobalPlayerData* gpd_owner = sWorld->GetGlobalPlayerData(auction->owner.GetCounter()))
|
||||
{
|
||||
owner_name = gpd_owner->name;
|
||||
owner_level = gpd_owner->level;
|
||||
}
|
||||
CharacterDatabase.PExecute("INSERT INTO log_money VALUES(%u, %u, \"%s\", \"%s\", %u, \"%s\", %u, \"<AH> profit: %ug, bidder: %s %u lvl (guid: %u), seller: %s %u lvl (guid: %u), item %u (%u)\", NOW())", gpd->accountId, auction->bidder, gpd->name.c_str(), bidder ? bidder->GetSession()->GetRemoteAddress().c_str() : "", owner_accId, owner_name.c_str(), auction->bid, (profit / GOLD), gpd->name.c_str(), gpd->level, auction->bidder, owner_name.c_str(), owner_level, auction->owner, auction->item_template, auction->itemCount);
|
||||
CharacterDatabase.PExecute("INSERT INTO log_money VALUES(%u, %u, \"%s\", \"%s\", %u, \"%s\", %u, \"<AH> profit: %ug, bidder: %s %u lvl (guid: %u), seller: %s %u lvl (guid: %u), item %u (%u)\", NOW())",
|
||||
gpd->accountId, auction->bidder.GetCounter(), gpd->name.c_str(), bidder ? bidder->GetSession()->GetRemoteAddress().c_str() : "", owner_accId, owner_name.c_str(), auction->bid, (profit / GOLD), gpd->name.c_str(), gpd->level, auction->bidder.GetCounter(), owner_name.c_str(), owner_level, auction->owner.GetCounter(), auction->item_template, auction->itemCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -193,13 +208,12 @@ void AuctionHouseMgr::SendAuctionSuccessfulMail(AuctionEntry* auction, SQLTransa
|
||||
void AuctionHouseMgr::SendAuctionExpiredMail(AuctionEntry* auction, SQLTransaction& trans, bool sendNotification, bool sendMail)
|
||||
{
|
||||
//return an item in auction to its owner by mail
|
||||
Item* pItem = GetAItem(auction->item_guidlow);
|
||||
Item* pItem = GetAItem(auction->item_guid);
|
||||
if (!pItem)
|
||||
return;
|
||||
|
||||
uint64 owner_guid = MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER);
|
||||
Player* owner = ObjectAccessor::FindPlayerInOrOutOfWorld(owner_guid);
|
||||
uint32 owner_accId = sObjectMgr->GetPlayerAccountIdByGUID(owner_guid);
|
||||
Player* owner = ObjectAccessor::FindConnectedPlayer(auction->owner);
|
||||
uint32 owner_accId = sObjectMgr->GetPlayerAccountIdByGUID(auction->owner.GetCounter());
|
||||
|
||||
// owner exist
|
||||
if (owner || owner_accId)
|
||||
@@ -210,23 +224,22 @@ void AuctionHouseMgr::SendAuctionExpiredMail(AuctionEntry* auction, SQLTransacti
|
||||
owner->GetSession()->SendAuctionOwnerNotification(auction);
|
||||
|
||||
if (sendMail) // can be changed in the hook
|
||||
MailDraft(auction->BuildAuctionMailSubject(AUCTION_EXPIRED), AuctionEntry::BuildAuctionMailBody(0, 0, auction->buyout, auction->deposit, 0))
|
||||
MailDraft(auction->BuildAuctionMailSubject(AUCTION_EXPIRED), AuctionEntry::BuildAuctionMailBody(ObjectGuid::Empty, 0, auction->buyout, auction->deposit, 0))
|
||||
.AddItem(pItem)
|
||||
.SendMailTo(trans, MailReceiver(owner, auction->owner), auction, MAIL_CHECK_MASK_COPIED, 0);
|
||||
.SendMailTo(trans, MailReceiver(owner, auction->owner.GetCounter()), auction, MAIL_CHECK_MASK_COPIED, 0);
|
||||
}
|
||||
else
|
||||
sAuctionMgr->RemoveAItem(auction->item_guidlow, true);
|
||||
sAuctionMgr->RemoveAItem(auction->item_guid, true);
|
||||
}
|
||||
|
||||
//this function sends mail to old bidder
|
||||
void AuctionHouseMgr::SendAuctionOutbiddedMail(AuctionEntry* auction, uint32 newPrice, Player* newBidder, SQLTransaction& trans, bool sendNotification, bool sendMail)
|
||||
{
|
||||
uint64 oldBidder_guid = MAKE_NEW_GUID(auction->bidder, 0, HIGHGUID_PLAYER);
|
||||
Player* oldBidder = ObjectAccessor::FindPlayerInOrOutOfWorld(oldBidder_guid);
|
||||
Player* oldBidder = ObjectAccessor::FindConnectedPlayer(auction->bidder);
|
||||
|
||||
uint32 oldBidder_accId = 0;
|
||||
if (!oldBidder)
|
||||
oldBidder_accId = sObjectMgr->GetPlayerAccountIdByGUID(oldBidder_guid);
|
||||
oldBidder_accId = sObjectMgr->GetPlayerAccountIdByGUID(auction->bidder.GetCounter());
|
||||
|
||||
// old bidder exist
|
||||
if (oldBidder || oldBidder_accId)
|
||||
@@ -239,19 +252,18 @@ void AuctionHouseMgr::SendAuctionOutbiddedMail(AuctionEntry* auction, uint32 new
|
||||
if (sendMail) // can be changed in the hook
|
||||
MailDraft(auction->BuildAuctionMailSubject(AUCTION_OUTBIDDED), AuctionEntry::BuildAuctionMailBody(auction->owner, auction->bid, auction->buyout, auction->deposit, auction->GetAuctionCut()))
|
||||
.AddMoney(auction->bid)
|
||||
.SendMailTo(trans, MailReceiver(oldBidder, auction->bidder), auction, MAIL_CHECK_MASK_COPIED);
|
||||
.SendMailTo(trans, MailReceiver(oldBidder, auction->bidder.GetCounter()), auction, MAIL_CHECK_MASK_COPIED);
|
||||
}
|
||||
}
|
||||
|
||||
//this function sends mail, when auction is cancelled to old bidder
|
||||
void AuctionHouseMgr::SendAuctionCancelledToBidderMail(AuctionEntry* auction, SQLTransaction& trans, bool sendMail)
|
||||
{
|
||||
uint64 bidder_guid = MAKE_NEW_GUID(auction->bidder, 0, HIGHGUID_PLAYER);
|
||||
Player* bidder = ObjectAccessor::FindPlayerInOrOutOfWorld(bidder_guid);
|
||||
Player* bidder = ObjectAccessor::FindConnectedPlayer(auction->bidder);
|
||||
|
||||
uint32 bidder_accId = 0;
|
||||
if (!bidder)
|
||||
bidder_accId = sObjectMgr->GetPlayerAccountIdByGUID(bidder_guid);
|
||||
bidder_accId = sObjectMgr->GetPlayerAccountIdByGUID(auction->bidder.GetCounter());
|
||||
|
||||
// bidder exist
|
||||
if (bidder || bidder_accId)
|
||||
@@ -260,7 +272,7 @@ void AuctionHouseMgr::SendAuctionCancelledToBidderMail(AuctionEntry* auction, SQ
|
||||
if (sendMail) // can be changed in the hook
|
||||
MailDraft(auction->BuildAuctionMailSubject(AUCTION_CANCELLED_TO_BIDDER), AuctionEntry::BuildAuctionMailBody(auction->owner, auction->bid, auction->buyout, auction->deposit, 0))
|
||||
.AddMoney(auction->bid)
|
||||
.SendMailTo(trans, MailReceiver(bidder, auction->bidder), auction, MAIL_CHECK_MASK_COPIED);
|
||||
.SendMailTo(trans, MailReceiver(bidder, auction->bidder.GetCounter()), auction, MAIL_CHECK_MASK_COPIED);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,8 +306,8 @@ void AuctionHouseMgr::LoadAuctionItems()
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
uint32 item_guid = fields[11].GetUInt32();
|
||||
uint32 item_template = fields[12].GetUInt32();
|
||||
ObjectGuid::LowType item_guid = fields[11].GetUInt32();
|
||||
uint32 item_template = fields[12].GetUInt32();
|
||||
|
||||
ItemTemplate const* proto = sObjectMgr->GetItemTemplate(item_template);
|
||||
if (!proto)
|
||||
@@ -305,7 +317,7 @@ void AuctionHouseMgr::LoadAuctionItems()
|
||||
}
|
||||
|
||||
Item* item = NewItemOrBag(proto);
|
||||
if (!item->LoadFromDB(item_guid, 0, fields, item_template))
|
||||
if (!item->LoadFromDB(item_guid, ObjectGuid::Empty, fields, item_template))
|
||||
{
|
||||
delete item;
|
||||
continue;
|
||||
@@ -348,7 +360,7 @@ void AuctionHouseMgr::LoadAuctions()
|
||||
continue;
|
||||
}
|
||||
|
||||
GetAuctionsMap(aItem->factionTemplateId)->AddAuction(aItem);
|
||||
GetAuctionsMapByHouseId(aItem->houseId)->AddAuction(aItem);
|
||||
count++;
|
||||
} while (result->NextRow());
|
||||
|
||||
@@ -361,13 +373,13 @@ void AuctionHouseMgr::LoadAuctions()
|
||||
void AuctionHouseMgr::AddAItem(Item* it)
|
||||
{
|
||||
ASSERT(it);
|
||||
ASSERT(mAitems.find(it->GetGUIDLow()) == mAitems.end());
|
||||
mAitems[it->GetGUIDLow()] = it;
|
||||
ASSERT(mAitems.find(it->GetGUID()) == mAitems.end());
|
||||
mAitems[it->GetGUID()] = it;
|
||||
}
|
||||
|
||||
bool AuctionHouseMgr::RemoveAItem(uint32 id, bool deleteFromDB)
|
||||
bool AuctionHouseMgr::RemoveAItem(ObjectGuid itemGuid, bool deleteFromDB)
|
||||
{
|
||||
ItemMap::iterator i = mAitems.find(id);
|
||||
ItemMap::iterator i = mAitems.find(itemGuid);
|
||||
if (i == mAitems.end())
|
||||
return false;
|
||||
|
||||
@@ -393,64 +405,32 @@ void AuctionHouseMgr::Update()
|
||||
|
||||
AuctionHouseEntry const* AuctionHouseMgr::GetAuctionHouseEntry(uint32 factionTemplateId)
|
||||
{
|
||||
uint32 houseid = 7; // goblin auction house
|
||||
uint32 houseid = AUCTIONHOUSE_NEUTRAL; // goblin auction house
|
||||
|
||||
if (!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION))
|
||||
{
|
||||
//FIXME: found way for proper auctionhouse selection by another way
|
||||
// AuctionHouse.dbc have faction field with _player_ factions associated with auction house races.
|
||||
// but no easy way convert creature faction to player race faction for specific city
|
||||
switch (factionTemplateId)
|
||||
{
|
||||
case 12:
|
||||
houseid = 1;
|
||||
break; // human
|
||||
case 29:
|
||||
houseid = 6;
|
||||
break; // orc, and generic for horde
|
||||
case 55:
|
||||
houseid = 2;
|
||||
break; // dwarf, and generic for alliance
|
||||
case 68:
|
||||
houseid = 4;
|
||||
break; // undead
|
||||
case 80:
|
||||
houseid = 3;
|
||||
break; // n-elf
|
||||
case 104:
|
||||
houseid = 5;
|
||||
break; // trolls
|
||||
case 120:
|
||||
houseid = 7;
|
||||
break; // booty bay, neutral
|
||||
case 474:
|
||||
houseid = 7;
|
||||
break; // gadgetzan, neutral
|
||||
case 855:
|
||||
houseid = 7;
|
||||
break; // everlook, neutral
|
||||
case 1604:
|
||||
houseid = 6;
|
||||
break; // b-elfs,
|
||||
default: // for unknown case
|
||||
{
|
||||
FactionTemplateEntry const* u_entry = sFactionTemplateStore.LookupEntry(factionTemplateId);
|
||||
if (!u_entry)
|
||||
houseid = 7; // goblin auction house
|
||||
else if (u_entry->ourMask & FACTION_MASK_ALLIANCE)
|
||||
houseid = 1; // human auction house
|
||||
else if (u_entry->ourMask & FACTION_MASK_HORDE)
|
||||
houseid = 6; // orc auction house
|
||||
else
|
||||
houseid = 7; // goblin auction house
|
||||
break;
|
||||
}
|
||||
}
|
||||
FactionTemplateEntry const* u_entry = sFactionTemplateStore.LookupEntry(factionTemplateId);
|
||||
if (!u_entry)
|
||||
houseid = AUCTIONHOUSE_NEUTRAL; // goblin auction house
|
||||
else if (u_entry->ourMask & FACTION_MASK_ALLIANCE)
|
||||
houseid = AUCTIONHOUSE_ALLIANCE; // human auction house
|
||||
else if (u_entry->ourMask & FACTION_MASK_HORDE)
|
||||
houseid = AUCTIONHOUSE_HORDE; // orc auction house
|
||||
else
|
||||
houseid = AUCTIONHOUSE_NEUTRAL; // goblin auction house
|
||||
}
|
||||
|
||||
return sAuctionHouseStore.LookupEntry(houseid);
|
||||
}
|
||||
|
||||
AuctionHouseEntry const* AuctionHouseMgr::GetAuctionHouseEntryFromHouse(uint8 houseId)
|
||||
{
|
||||
return (sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION)) ? sAuctionHouseStore.LookupEntry(AUCTIONHOUSE_NEUTRAL) : sAuctionHouseStore.LookupEntry(houseId);
|
||||
}
|
||||
|
||||
void AuctionHouseObject::AddAuction(AuctionEntry* auction)
|
||||
{
|
||||
ASSERT(auction);
|
||||
@@ -492,7 +472,7 @@ void AuctionHouseObject::Update()
|
||||
continue;
|
||||
|
||||
///- Either cancel the auction if there was no bidder
|
||||
if (auction->bidder == 0)
|
||||
if (!auction->bidder)
|
||||
{
|
||||
sAuctionMgr->SendAuctionExpiredMail(auction, trans);
|
||||
sScriptMgr->OnAuctionExpire(this, auction);
|
||||
@@ -511,7 +491,7 @@ void AuctionHouseObject::Update()
|
||||
///- In any case clear the auction
|
||||
auction->DeleteFromDB(trans);
|
||||
|
||||
sAuctionMgr->RemoveAItem(auction->item_guidlow);
|
||||
sAuctionMgr->RemoveAItem(auction->item_guid);
|
||||
RemoveAuction(auction);
|
||||
}
|
||||
CharacterDatabase.CommitTransaction(trans);
|
||||
@@ -522,7 +502,7 @@ void AuctionHouseObject::BuildListBidderItems(WorldPacket& data, Player* player,
|
||||
for (AuctionEntryMap::const_iterator itr = AuctionsMap.begin(); itr != AuctionsMap.end(); ++itr)
|
||||
{
|
||||
AuctionEntry* Aentry = itr->second;
|
||||
if (Aentry && Aentry->bidder == player->GetGUIDLow())
|
||||
if (Aentry && Aentry->bidder == player->GetGUID())
|
||||
{
|
||||
if (itr->second->BuildAuctionInfo(data))
|
||||
++count;
|
||||
@@ -537,7 +517,7 @@ void AuctionHouseObject::BuildListOwnerItems(WorldPacket& data, Player* player,
|
||||
for (AuctionEntryMap::const_iterator itr = AuctionsMap.begin(); itr != AuctionsMap.end(); ++itr)
|
||||
{
|
||||
AuctionEntry* Aentry = itr->second;
|
||||
if (Aentry && Aentry->owner == player->GetGUIDLow())
|
||||
if (Aentry && Aentry->owner == player->GetGUID())
|
||||
{
|
||||
if (Aentry->BuildAuctionInfo(data))
|
||||
++count;
|
||||
@@ -589,7 +569,7 @@ bool AuctionHouseObject::BuildListAuctionItems(WorldPacket& data, Player* player
|
||||
if (Aentry->expire_time < curTime)
|
||||
continue;
|
||||
|
||||
Item* item = sAuctionMgr->GetAItem(Aentry->item_guidlow);
|
||||
Item* item = sAuctionMgr->GetAItem(Aentry->item_guid);
|
||||
if (!item)
|
||||
continue;
|
||||
|
||||
@@ -693,10 +673,10 @@ bool AuctionHouseObject::BuildListAuctionItems(WorldPacket& data, Player* player
|
||||
//this function inserts to WorldPacket auction's data
|
||||
bool AuctionEntry::BuildAuctionInfo(WorldPacket& data) const
|
||||
{
|
||||
Item* item = sAuctionMgr->GetAItem(item_guidlow);
|
||||
Item* item = sAuctionMgr->GetAItem(item_guid);
|
||||
if (!item)
|
||||
{
|
||||
LOG_ERROR("server", "AuctionEntry::BuildAuctionInfo: Auction %u has a non-existent item: %u", Id, item_guidlow);
|
||||
LOG_ERROR("server", "AuctionEntry::BuildAuctionInfo: Auction %u has a non-existent item: %s", Id, item_guid.ToString().c_str());
|
||||
return false;
|
||||
}
|
||||
data << uint32(Id);
|
||||
@@ -714,13 +694,13 @@ bool AuctionEntry::BuildAuctionInfo(WorldPacket& data) const
|
||||
data << uint32(item->GetCount()); // item->count
|
||||
data << uint32(item->GetSpellCharges()); // item->charge FFFFFFF
|
||||
data << uint32(0); // Unknown
|
||||
data << uint64(owner); // Auction->owner
|
||||
data << owner; // Auction->owner
|
||||
data << uint32(startbid); // Auction->startbid (not sure if useful)
|
||||
data << uint32(bid ? GetAuctionOutBid() : 0);
|
||||
// Minimal outbid
|
||||
data << uint32(buyout); // Auction->buyout
|
||||
data << uint32((expire_time - time(nullptr)) * IN_MILLISECONDS); // time left
|
||||
data << uint64(bidder); // auction->bidder current
|
||||
data << uint32((expire_time - time(nullptr)) * IN_MILLISECONDS); // time left
|
||||
data << bidder; // auction->bidder current
|
||||
data << uint32(bid); // current bid
|
||||
return true;
|
||||
}
|
||||
@@ -749,12 +729,12 @@ void AuctionEntry::SaveToDB(SQLTransaction& trans) const
|
||||
{
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_AUCTION);
|
||||
stmt->setUInt32(0, Id);
|
||||
stmt->setUInt32(1, auctioneer);
|
||||
stmt->setUInt32(2, item_guidlow);
|
||||
stmt->setUInt32(3, owner);
|
||||
stmt->setUInt8(1, houseId);
|
||||
stmt->setUInt32(2, item_guid.GetCounter());
|
||||
stmt->setUInt32(3, owner.GetCounter());
|
||||
stmt->setUInt32 (4, buyout);
|
||||
stmt->setUInt32(5, uint32(expire_time));
|
||||
stmt->setUInt32(6, bidder);
|
||||
stmt->setUInt32(6, bidder.GetCounter());
|
||||
stmt->setUInt32 (7, bid);
|
||||
stmt->setUInt32 (8, startbid);
|
||||
stmt->setUInt32 (9, deposit);
|
||||
@@ -764,95 +744,35 @@ void AuctionEntry::SaveToDB(SQLTransaction& trans) const
|
||||
bool AuctionEntry::LoadFromDB(Field* fields)
|
||||
{
|
||||
Id = fields[0].GetUInt32();
|
||||
auctioneer = fields[1].GetUInt32();
|
||||
item_guidlow = fields[2].GetUInt32();
|
||||
houseId = fields[1].GetUInt8();
|
||||
item_guid = ObjectGuid::Create<HighGuid::Item>(fields[2].GetUInt32());
|
||||
item_template = fields[3].GetUInt32();
|
||||
itemCount = fields[4].GetUInt32();
|
||||
owner = fields[5].GetUInt32();
|
||||
owner = ObjectGuid::Create<HighGuid::Player>(fields[5].GetUInt32());
|
||||
buyout = fields[6].GetUInt32();
|
||||
expire_time = fields[7].GetUInt32();
|
||||
bidder = fields[8].GetUInt32();
|
||||
bidder = ObjectGuid::Create<HighGuid::Player>(fields[8].GetUInt32());
|
||||
bid = fields[9].GetUInt32();
|
||||
startbid = fields[10].GetUInt32();
|
||||
deposit = fields[11].GetUInt32();
|
||||
|
||||
CreatureData const* auctioneerData = sObjectMgr->GetCreatureData(auctioneer);
|
||||
if (!auctioneerData)
|
||||
{
|
||||
LOG_ERROR("server", "Auction %u has not a existing auctioneer (GUID : %u)", Id, auctioneer);
|
||||
return false;
|
||||
}
|
||||
|
||||
CreatureTemplate const* auctioneerInfo = sObjectMgr->GetCreatureTemplate(auctioneerData->id);
|
||||
if (!auctioneerInfo)
|
||||
{
|
||||
LOG_ERROR("server", "Auction %u has not a existing auctioneer (GUID : %u Entry: %u)", Id, auctioneer, auctioneerData->id);
|
||||
return false;
|
||||
}
|
||||
|
||||
factionTemplateId = auctioneerInfo->faction;
|
||||
auctionHouseEntry = AuctionHouseMgr::GetAuctionHouseEntry(factionTemplateId);
|
||||
auctionHouseEntry = AuctionHouseMgr::GetAuctionHouseEntryFromHouse(houseId);
|
||||
if (!auctionHouseEntry)
|
||||
{
|
||||
LOG_ERROR("server", "Auction %u has auctioneer (GUID : %u Entry: %u) with wrong faction %u", Id, auctioneer, auctioneerData->id, factionTemplateId);
|
||||
LOG_ERROR("server", "Auction %u has invalid house id %u", Id, houseId);
|
||||
return false;
|
||||
}
|
||||
|
||||
// check if sold item exists for guid
|
||||
// and item_template in fact (GetAItem will fail if problematic in result check in AuctionHouseMgr::LoadAuctionItems)
|
||||
if (!sAuctionMgr->GetAItem(item_guidlow))
|
||||
if (!sAuctionMgr->GetAItem(item_guid))
|
||||
{
|
||||
LOG_ERROR("server", "Auction %u has not a existing item : %u", Id, item_guidlow);
|
||||
LOG_ERROR("server", "Auction %u has not a existing item : %s", Id, item_guid.ToString().c_str());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AuctionEntry::LoadFromFieldList(Field* fields)
|
||||
{
|
||||
// Loads an AuctionEntry item from a field list. Unlike "LoadFromDB()", this one
|
||||
// does not require the AuctionEntryMap to have been loaded with items. It simply
|
||||
// acts as a wrapper to fill out an AuctionEntry struct from a field list
|
||||
|
||||
Id = fields[0].GetUInt32();
|
||||
auctioneer = fields[1].GetUInt32();
|
||||
item_guidlow = fields[2].GetUInt32();
|
||||
item_template = fields[3].GetUInt32();
|
||||
itemCount = fields[4].GetUInt32();
|
||||
owner = fields[5].GetUInt32();
|
||||
buyout = fields[6].GetUInt32();
|
||||
expire_time = fields[7].GetUInt32();
|
||||
bidder = fields[8].GetUInt32();
|
||||
bid = fields[9].GetUInt32();
|
||||
startbid = fields[10].GetUInt32();
|
||||
deposit = fields[11].GetUInt32();
|
||||
|
||||
CreatureData const* auctioneerData = sObjectMgr->GetCreatureData(auctioneer);
|
||||
if (!auctioneerData)
|
||||
{
|
||||
LOG_ERROR("server", "AuctionEntry::LoadFromFieldList() - Auction %u has not a existing auctioneer (GUID : %u)", Id, auctioneer);
|
||||
return false;
|
||||
}
|
||||
|
||||
CreatureTemplate const* auctioneerInfo = sObjectMgr->GetCreatureTemplate(auctioneerData->id);
|
||||
if (!auctioneerInfo)
|
||||
{
|
||||
LOG_ERROR("server", "AuctionEntry::LoadFromFieldList() - Auction %u has not a existing auctioneer (GUID : %u Entry: %u)", Id, auctioneer, auctioneerData->id);
|
||||
return false;
|
||||
}
|
||||
|
||||
factionTemplateId = auctioneerInfo->faction;
|
||||
auctionHouseEntry = AuctionHouseMgr::GetAuctionHouseEntry(factionTemplateId);
|
||||
|
||||
if (!auctionHouseEntry)
|
||||
{
|
||||
LOG_ERROR("server", "AuctionEntry::LoadFromFieldList() - Auction %u has auctioneer (GUID : %u Entry: %u) with wrong faction %u", Id, auctioneer, auctioneerData->id, factionTemplateId);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string AuctionEntry::BuildAuctionMailSubject(MailAuctionAnswers response) const
|
||||
{
|
||||
std::ostringstream strm;
|
||||
@@ -860,11 +780,11 @@ std::string AuctionEntry::BuildAuctionMailSubject(MailAuctionAnswers response) c
|
||||
return strm.str();
|
||||
}
|
||||
|
||||
std::string AuctionEntry::BuildAuctionMailBody(uint32 lowGuid, uint32 bid, uint32 buyout, uint32 deposit, uint32 cut)
|
||||
std::string AuctionEntry::BuildAuctionMailBody(ObjectGuid guid, uint32 bid, uint32 buyout, uint32 deposit, uint32 cut)
|
||||
{
|
||||
std::ostringstream strm;
|
||||
strm.width(16);
|
||||
strm << std::right << std::hex << MAKE_NEW_GUID(lowGuid, 0, HIGHGUID_PLAYER); // HIGHGUID_PLAYER always present, even for empty guids
|
||||
strm << guid.ToString();
|
||||
strm << std::dec << ':' << bid << ':' << buyout;
|
||||
strm << ':' << deposit << ':' << cut;
|
||||
return strm.str();
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "DatabaseEnv.h"
|
||||
#include "DBCStructure.h"
|
||||
#include "EventProcessor.h"
|
||||
#include "ObjectGuid.h"
|
||||
#include "WorldPacket.h"
|
||||
|
||||
class Item;
|
||||
@@ -50,35 +51,39 @@ enum MailAuctionAnswers
|
||||
AUCTION_SALE_PENDING = 6
|
||||
};
|
||||
|
||||
enum AuctionHouses
|
||||
{
|
||||
AUCTIONHOUSE_ALLIANCE = 2,
|
||||
AUCTIONHOUSE_HORDE = 6,
|
||||
AUCTIONHOUSE_NEUTRAL = 7
|
||||
};
|
||||
|
||||
struct AuctionEntry
|
||||
{
|
||||
uint32 Id;
|
||||
uint32 auctioneer; // creature low guid
|
||||
uint32 item_guidlow;
|
||||
uint8 houseId;
|
||||
ObjectGuid item_guid;
|
||||
uint32 item_template;
|
||||
uint32 itemCount;
|
||||
uint32 owner;
|
||||
ObjectGuid owner;
|
||||
uint32 startbid; //maybe useless
|
||||
uint32 bid;
|
||||
uint32 buyout;
|
||||
time_t expire_time;
|
||||
uint32 bidder;
|
||||
ObjectGuid bidder;
|
||||
uint32 deposit; //deposit can be calculated only when creating auction
|
||||
AuctionHouseEntry const* auctionHouseEntry; // in AuctionHouse.dbc
|
||||
uint32 factionTemplateId;
|
||||
|
||||
// helpers
|
||||
[[nodiscard]] uint32 GetHouseId() const { return auctionHouseEntry->houseId; }
|
||||
[[nodiscard]] uint32 GetHouseFaction() const { return auctionHouseEntry->faction; }
|
||||
[[nodiscard]] uint8 GetHouseId() const { return houseId; }
|
||||
[[nodiscard]] uint32 GetAuctionCut() const;
|
||||
[[nodiscard]] uint32 GetAuctionOutBid() const;
|
||||
bool BuildAuctionInfo(WorldPacket& data) const;
|
||||
void DeleteFromDB(SQLTransaction& trans) const;
|
||||
void SaveToDB(SQLTransaction& trans) const;
|
||||
bool LoadFromDB(Field* fields);
|
||||
bool LoadFromFieldList(Field* fields);
|
||||
[[nodiscard]] std::string BuildAuctionMailSubject(MailAuctionAnswers response) const;
|
||||
static std::string BuildAuctionMailBody(uint32 lowGuid, uint32 bid, uint32 buyout, uint32 deposit, uint32 cut);
|
||||
static std::string BuildAuctionMailBody(ObjectGuid guid, uint32 bid, uint32 buyout, uint32 deposit, uint32 cut);
|
||||
};
|
||||
|
||||
//this class is used as auctionhouse instance
|
||||
@@ -133,16 +138,17 @@ private:
|
||||
~AuctionHouseMgr();
|
||||
|
||||
public:
|
||||
typedef std::unordered_map<uint32, Item*> ItemMap;
|
||||
typedef std::unordered_map<ObjectGuid, Item*> ItemMap;
|
||||
|
||||
static AuctionHouseMgr* instance();
|
||||
|
||||
AuctionHouseObject* GetAuctionsMap(uint32 factionTemplateId);
|
||||
AuctionHouseObject* GetAuctionsMapByHouseId(uint8 auctionHouseId);
|
||||
AuctionHouseObject* GetBidsMap(uint32 factionTemplateId);
|
||||
|
||||
Item* GetAItem(uint32 id)
|
||||
Item* GetAItem(ObjectGuid itemGuid)
|
||||
{
|
||||
ItemMap::const_iterator itr = mAitems.find(id);
|
||||
ItemMap::const_iterator itr = mAitems.find(itemGuid);
|
||||
if (itr != mAitems.end())
|
||||
return itr->second;
|
||||
|
||||
@@ -159,6 +165,7 @@ public:
|
||||
|
||||
static uint32 GetAuctionDeposit(AuctionHouseEntry const* entry, uint32 time, Item* pItem, uint32 count);
|
||||
static AuctionHouseEntry const* GetAuctionHouseEntry(uint32 factionTemplateId);
|
||||
static AuctionHouseEntry const* GetAuctionHouseEntryFromHouse(uint8 houseId);
|
||||
|
||||
public:
|
||||
//load first auction items, because of check if item exists, when loading
|
||||
@@ -166,7 +173,7 @@ public:
|
||||
void LoadAuctions();
|
||||
|
||||
void AddAItem(Item* it);
|
||||
bool RemoveAItem(uint32 id, bool deleteFromDB = false);
|
||||
bool RemoveAItem(ObjectGuid itemGuid, bool deleteFromDB = false);
|
||||
|
||||
void Update();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user