mirror of
https://github.com/mangosfour/server.git
synced 2025-12-15 01:37:00 +00:00
[11391] Auction: multi sell, sale pending list and other fixes.
This commit is contained in:
parent
730a907252
commit
e39a8b55a0
8 changed files with 415 additions and 256 deletions
|
|
@ -76,10 +76,10 @@ uint32 AuctionHouseMgr::GetAuctionDeposit(AuctionHouseEntry const* entry, uint32
|
|||
return uint32(deposit * sWorld.getConfig(CONFIG_FLOAT_RATE_AUCTION_DEPOSIT));
|
||||
}
|
||||
|
||||
//does not clear ram
|
||||
// does not clear ram
|
||||
void AuctionHouseMgr::SendAuctionWonMail( AuctionEntry *auction )
|
||||
{
|
||||
Item *pItem = GetAItem(auction->item_guidlow);
|
||||
Item *pItem = GetAItem(auction->itemGuidLow);
|
||||
if(!pItem)
|
||||
return;
|
||||
|
||||
|
|
@ -127,11 +127,16 @@ void AuctionHouseMgr::SendAuctionWonMail( AuctionEntry *auction )
|
|||
else if (!bidder)
|
||||
bidder_accId = sObjectMgr.GetPlayerAccountIdByGUID(bidder_guid);
|
||||
|
||||
ObjectGuid ownerGuid = ObjectGuid(HIGHGUID_PLAYER, auction->owner);
|
||||
Player* auction_owner = sObjectMgr.GetPlayer(ownerGuid);
|
||||
if(auction_owner)
|
||||
auction_owner->GetSession()->SendAuctionOwnerNotification( auction );
|
||||
|
||||
// receiver exist
|
||||
if(bidder || bidder_accId)
|
||||
{
|
||||
std::ostringstream msgAuctionWonSubject;
|
||||
msgAuctionWonSubject << auction->item_template << ":0:" << AUCTION_WON;
|
||||
msgAuctionWonSubject << auction->itemTemplate << ":0:" << AUCTION_WON;
|
||||
|
||||
std::ostringstream msgAuctionWonBody;
|
||||
msgAuctionWonBody.width(16);
|
||||
|
|
@ -146,7 +151,7 @@ void AuctionHouseMgr::SendAuctionWonMail( AuctionEntry *auction )
|
|||
|
||||
if (bidder)
|
||||
{
|
||||
bidder->GetSession()->SendAuctionBidderNotification( auction->GetHouseId(), auction->Id, bidder_guid, 0, 0, auction->item_template);
|
||||
bidder->GetSession()->SendAuctionBidderNotification(auction);
|
||||
// FIXME: for offline player need also
|
||||
bidder->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_WON_AUCTIONS, 1);
|
||||
}
|
||||
|
|
@ -176,7 +181,7 @@ void AuctionHouseMgr::SendAuctionSalePendingMail( AuctionEntry * auction )
|
|||
if(owner || sObjectMgr.GetPlayerAccountIdByGUID(owner_guid))
|
||||
{
|
||||
std::ostringstream msgAuctionSalePendingSubject;
|
||||
msgAuctionSalePendingSubject << auction->item_template << ":0:" << AUCTION_SALE_PENDING;
|
||||
msgAuctionSalePendingSubject << auction->itemTemplate << ":0:" << AUCTION_SALE_PENDING;
|
||||
|
||||
std::ostringstream msgAuctionSalePendingBody;
|
||||
uint32 auctionCut = auction->GetAuctionCut();
|
||||
|
|
@ -196,7 +201,7 @@ void AuctionHouseMgr::SendAuctionSalePendingMail( AuctionEntry * auction )
|
|||
}
|
||||
}
|
||||
|
||||
//call this method to send mail to auction owner, when auction is successful, it does not clear ram
|
||||
// call this method to send mail to auction owner, when auction is successful, it does not clear ram
|
||||
void AuctionHouseMgr::SendAuctionSuccessfulMail( AuctionEntry * auction )
|
||||
{
|
||||
ObjectGuid owner_guid = ObjectGuid(HIGHGUID_PLAYER, auction->owner);
|
||||
|
|
@ -210,7 +215,7 @@ void AuctionHouseMgr::SendAuctionSuccessfulMail( AuctionEntry * auction )
|
|||
if(owner || owner_accId)
|
||||
{
|
||||
std::ostringstream msgAuctionSuccessfulSubject;
|
||||
msgAuctionSuccessfulSubject << auction->item_template << ":0:" << AUCTION_SUCCESSFUL;
|
||||
msgAuctionSuccessfulSubject << auction->itemTemplate << ":0:" << AUCTION_SUCCESSFUL;
|
||||
|
||||
std::ostringstream auctionSuccessfulBody;
|
||||
uint32 auctionCut = auction->GetAuctionCut();
|
||||
|
|
@ -226,26 +231,24 @@ void AuctionHouseMgr::SendAuctionSuccessfulMail( AuctionEntry * auction )
|
|||
|
||||
if (owner)
|
||||
{
|
||||
//FIXME: what do if owner offline
|
||||
// FIXME: what do if owner offline
|
||||
owner->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_GOLD_EARNED_BY_AUCTIONS, profit);
|
||||
owner->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_AUCTION_SOLD, auction->bid);
|
||||
//send auction owner notification, bidder must be current!
|
||||
owner->GetSession()->SendAuctionOwnerNotification( auction );
|
||||
}
|
||||
|
||||
MailDraft(msgAuctionSuccessfulSubject.str(), auctionSuccessfulBody.str())
|
||||
.SetMoney(profit)
|
||||
.SendMailTo(MailReceiver(owner, owner_guid), auction, MAIL_CHECK_MASK_COPIED, HOUR);
|
||||
.SendMailTo(MailReceiver(owner, owner_guid), auction, MAIL_CHECK_MASK_COPIED);
|
||||
}
|
||||
}
|
||||
|
||||
//does not clear ram
|
||||
// does not clear ram
|
||||
void AuctionHouseMgr::SendAuctionExpiredMail( AuctionEntry * auction )
|
||||
{ //return an item in auction to its owner by mail
|
||||
Item *pItem = GetAItem(auction->item_guidlow);
|
||||
{ // return an item in auction to its owner by mail
|
||||
Item *pItem = GetAItem(auction->itemGuidLow);
|
||||
if(!pItem)
|
||||
{
|
||||
sLog.outError("Auction item (GUID: %u) not found, and lost.",auction->item_guidlow);
|
||||
sLog.outError("Auction item (GUID: %u) not found, and lost.", auction->itemGuidLow);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -260,7 +263,7 @@ void AuctionHouseMgr::SendAuctionExpiredMail( AuctionEntry * auction )
|
|||
if(owner || owner_accId)
|
||||
{
|
||||
std::ostringstream subject;
|
||||
subject << auction->item_template << ":0:" << AUCTION_EXPIRED << ":0:0";
|
||||
subject << auction->itemGuidLow << ":0:" << AUCTION_EXPIRED << ":0:0";
|
||||
|
||||
if ( owner )
|
||||
owner->GetSession()->SendAuctionOwnerNotification( auction );
|
||||
|
|
@ -359,7 +362,7 @@ void AuctionHouseMgr::LoadAuctions()
|
|||
return;
|
||||
}
|
||||
|
||||
result = CharacterDatabase.Query( "SELECT id,houseid,itemguid,item_template,itemowner,buyoutprice,time,buyguid,lastbid,startbid,deposit FROM auction" );
|
||||
result = CharacterDatabase.Query( "SELECT id,houseid,itemguid,item_template,itemowner,buyoutprice,time,moneyTime,buyguid,lastbid,startbid,deposit FROM auction" );
|
||||
if( !result )
|
||||
{
|
||||
barGoLink bar(1);
|
||||
|
|
@ -382,24 +385,25 @@ void AuctionHouseMgr::LoadAuctions()
|
|||
auction = new AuctionEntry;
|
||||
auction->Id = fields[0].GetUInt32();
|
||||
uint32 houseid = fields[1].GetUInt32();
|
||||
auction->item_guidlow = fields[2].GetUInt32();
|
||||
auction->item_template = fields[3].GetUInt32();
|
||||
auction->itemGuidLow = fields[2].GetUInt32();
|
||||
auction->itemTemplate = fields[3].GetUInt32();
|
||||
auction->owner = fields[4].GetUInt32();
|
||||
auction->buyout = fields[5].GetUInt32();
|
||||
auction->expire_time = fields[6].GetUInt32();
|
||||
auction->bidder = fields[7].GetUInt32();
|
||||
auction->bid = fields[8].GetUInt32();
|
||||
auction->startbid = fields[9].GetUInt32();
|
||||
auction->deposit = fields[10].GetUInt32();
|
||||
auction->expireTime = fields[6].GetUInt32();
|
||||
auction->moneyDeliveryTime = fields[7].GetUInt32();
|
||||
auction->bidder = fields[8].GetUInt32();
|
||||
auction->bid = fields[9].GetUInt32();
|
||||
auction->startbid = fields[10].GetUInt32();
|
||||
auction->deposit = fields[11].GetUInt32();
|
||||
auction->auctionHouseEntry = NULL; // init later
|
||||
|
||||
// check if sold item exists for guid
|
||||
// and item_template in fact (GetAItem will fail if problematic in result check in AuctionHouseMgr::LoadAuctionItems)
|
||||
Item* pItem = GetAItem(auction->item_guidlow);
|
||||
Item* pItem = GetAItem(auction->itemGuidLow);
|
||||
if (!pItem)
|
||||
{
|
||||
auction->DeleteFromDB();
|
||||
sLog.outError("Auction %u has not a existing item : %u, deleted", auction->Id, auction->item_guidlow);
|
||||
sLog.outError("Auction %u has not a existing item : %u, deleted", auction->Id, auction->itemGuidLow);
|
||||
delete auction;
|
||||
continue;
|
||||
}
|
||||
|
|
@ -413,14 +417,14 @@ void AuctionHouseMgr::LoadAuctions()
|
|||
|
||||
// Attempt send item back to owner
|
||||
std::ostringstream msgAuctionCanceledOwner;
|
||||
msgAuctionCanceledOwner << auction->item_template << ":0:" << AUCTION_CANCELED << ":0:0";
|
||||
msgAuctionCanceledOwner << auction->itemTemplate << ":0:" << AUCTION_CANCELED << ":0:0";
|
||||
|
||||
// item will deleted or added to received mail list
|
||||
MailDraft(msgAuctionCanceledOwner.str(), "") // TODO: fix body
|
||||
.AddItem(pItem)
|
||||
.SendMailTo(MailReceiver(ObjectGuid(HIGHGUID_PLAYER, auction->owner)), auction, MAIL_CHECK_MASK_COPIED);
|
||||
|
||||
RemoveAItem(auction->item_guidlow);
|
||||
RemoveAItem(auction->itemGuidLow);
|
||||
auction->DeleteFromDB();
|
||||
delete auction;
|
||||
|
||||
|
|
@ -543,32 +547,46 @@ void AuctionHouseObject::Update()
|
|||
time_t curTime = sWorld.GetGameTime();
|
||||
///- Handle expired auctions
|
||||
AuctionEntryMap::iterator next;
|
||||
for (AuctionEntryMap::iterator itr = AuctionsMap.begin(); itr != AuctionsMap.end();itr = next)
|
||||
for (AuctionEntryMap::iterator itr = AuctionsMap.begin(); itr != AuctionsMap.end(); itr = next)
|
||||
{
|
||||
next = itr;
|
||||
++next;
|
||||
if (curTime > (itr->second->expire_time))
|
||||
{
|
||||
///- Either cancel the auction if there was no bidder
|
||||
if (itr->second->bidder == 0)
|
||||
{
|
||||
sAuctionMgr.SendAuctionExpiredMail( itr->second );
|
||||
}
|
||||
///- Or perform the transaction
|
||||
else
|
||||
{
|
||||
//we should send an "item sold" message if the seller is online
|
||||
//we send the item to the winner
|
||||
//we send the money to the seller
|
||||
sAuctionMgr.SendAuctionSuccessfulMail( itr->second );
|
||||
sAuctionMgr.SendAuctionWonMail( itr->second );
|
||||
}
|
||||
|
||||
///- In any case clear the auction
|
||||
itr->second->DeleteFromDB();
|
||||
sAuctionMgr.RemoveAItem(itr->second->item_guidlow);
|
||||
delete itr->second;
|
||||
RemoveAuction(itr->first);
|
||||
if (itr->second->moneyDeliveryTime)
|
||||
{
|
||||
if (curTime > itr->second->moneyDeliveryTime)
|
||||
{
|
||||
sAuctionMgr.SendAuctionSuccessfulMail( itr->second );
|
||||
|
||||
itr->second->DeleteFromDB();
|
||||
sAuctionMgr.RemoveAItem(itr->second->itemGuidLow);
|
||||
delete itr->second;
|
||||
RemoveAuction(itr->first);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (curTime > itr->second->expireTime)
|
||||
{
|
||||
///- Either cancel the auction if there was no bidder
|
||||
if (itr->second->bidder == 0)
|
||||
{
|
||||
sAuctionMgr.SendAuctionExpiredMail( itr->second );
|
||||
}
|
||||
///- Or perform the transaction
|
||||
else
|
||||
{
|
||||
itr->second->moneyDeliveryTime = time(NULL) + HOUR;
|
||||
sAuctionMgr.SendAuctionWonMail( itr->second );
|
||||
continue;
|
||||
}
|
||||
|
||||
///- In any case clear the auction
|
||||
itr->second->DeleteFromDB();
|
||||
sAuctionMgr.RemoveAItem(itr->second->itemGuidLow);
|
||||
delete itr->second;
|
||||
RemoveAuction(itr->first);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -578,6 +596,8 @@ void AuctionHouseObject::BuildListBidderItems(WorldPacket& data, Player* player,
|
|||
for (AuctionEntryMap::const_iterator itr = AuctionsMap.begin();itr != AuctionsMap.end();++itr)
|
||||
{
|
||||
AuctionEntry *Aentry = itr->second;
|
||||
if(Aentry->moneyDeliveryTime)
|
||||
continue;
|
||||
if( Aentry && Aentry->bidder == player->GetGUIDLow() )
|
||||
{
|
||||
if (itr->second->BuildAuctionInfo(data))
|
||||
|
|
@ -592,6 +612,8 @@ void AuctionHouseObject::BuildListOwnerItems(WorldPacket& data, Player* player,
|
|||
for (AuctionEntryMap::const_iterator itr = AuctionsMap.begin();itr != AuctionsMap.end();++itr)
|
||||
{
|
||||
AuctionEntry *Aentry = itr->second;
|
||||
if(Aentry->moneyDeliveryTime)
|
||||
continue;
|
||||
if( Aentry && Aentry->owner == player->GetGUIDLow() )
|
||||
{
|
||||
if(Aentry->BuildAuctionInfo(data))
|
||||
|
|
@ -611,7 +633,9 @@ void AuctionHouseObject::BuildListAuctionItems(WorldPacket& data, Player* player
|
|||
for (AuctionEntryMap::const_iterator itr = AuctionsMap.begin();itr != AuctionsMap.end();++itr)
|
||||
{
|
||||
AuctionEntry *Aentry = itr->second;
|
||||
Item *item = sAuctionMgr.GetAItem(Aentry->item_guidlow);
|
||||
if(Aentry->moneyDeliveryTime)
|
||||
continue;
|
||||
Item *item = sAuctionMgr.GetAItem(Aentry->itemGuidLow);
|
||||
if (!item)
|
||||
continue;
|
||||
|
||||
|
|
@ -662,10 +686,45 @@ void AuctionHouseObject::BuildListAuctionItems(WorldPacket& data, Player* player
|
|||
}
|
||||
}
|
||||
|
||||
//this function inserts to WorldPacket auction's data
|
||||
void AuctionHouseObject::BuildListPendingSales(WorldPacket& data, Player* player, uint32& count)
|
||||
{
|
||||
for (AuctionEntryMap::const_iterator itr = AuctionsMap.begin(); itr != AuctionsMap.end(); ++itr)
|
||||
{
|
||||
AuctionEntry *Aentry = itr->second;
|
||||
if(!Aentry->moneyDeliveryTime)
|
||||
continue;
|
||||
if( Aentry && Aentry->owner == player->GetGUIDLow() )
|
||||
{
|
||||
Item *pItem = sAuctionMgr.GetAItem(Aentry->itemGuidLow);
|
||||
if (!pItem)
|
||||
{
|
||||
sLog.outError("Auction: item with guid %u doesn't exist!", Aentry->itemGuidLow);
|
||||
continue;
|
||||
}
|
||||
|
||||
std::ostringstream str1;
|
||||
str1 << Aentry->itemTemplate << ":" << pItem->GetItemRandomPropertyId() << ":" << AUCTION_SUCCESSFUL << ":" << Aentry->Id << ":" << pItem->GetCount();
|
||||
|
||||
std::ostringstream str2;
|
||||
str2.width(16);
|
||||
str2 << std::right << std::hex << Aentry->bidder << std::dec << ":";
|
||||
str2 << Aentry->bid << ":" << Aentry->buyout << ":" << Aentry->deposit << ":" << Aentry->GetAuctionCut();
|
||||
|
||||
data << str1.str(); // string "%d:%d:%d:%d:%d" -> itemId, ItemRandomPropertyId, 2, auctionId, unk1 (stack size?, unused)
|
||||
data << str2.str(); // string "%16I64X:%d:%d:%d:%d" -> bidderGuid, bid, buyout, deposit, auctionCut
|
||||
data << uint32(97250); // unk1
|
||||
data << uint32(68); // unk2
|
||||
float timeLeft = float(Aentry->moneyDeliveryTime - time(NULL)) / float(DAY);
|
||||
data << float(timeLeft); // time left
|
||||
++count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// this function inserts to WorldPacket auction's data
|
||||
bool AuctionEntry::BuildAuctionInfo(WorldPacket & data) const
|
||||
{
|
||||
Item *pItem = sAuctionMgr.GetAItem(item_guidlow);
|
||||
Item *pItem = sAuctionMgr.GetAItem(itemGuidLow);
|
||||
if (!pItem)
|
||||
{
|
||||
sLog.outError("auction to item, that doesn't exist !!!!");
|
||||
|
|
@ -681,19 +740,18 @@ bool AuctionEntry::BuildAuctionInfo(WorldPacket & data) const
|
|||
data << uint32(pItem->GetEnchantmentCharges(EnchantmentSlot(i)));
|
||||
}
|
||||
|
||||
data << uint32(pItem->GetItemRandomPropertyId()); //random item property id
|
||||
data << uint32(pItem->GetItemSuffixFactor()); //SuffixFactor
|
||||
data << uint32(pItem->GetCount()); //item->count
|
||||
data << uint32(pItem->GetSpellCharges()); //item->charge FFFFFFF
|
||||
data << uint32(0); //Unknown
|
||||
data << ObjectGuid(HIGHGUID_PLAYER, 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(NULL))*IN_MILLISECONDS);//time left
|
||||
data << ObjectGuid(HIGHGUID_PLAYER, bidder); //auction->bidder current
|
||||
data << uint32(bid); //current bid
|
||||
data << uint32(pItem->GetItemRandomPropertyId()); // random item property id
|
||||
data << uint32(pItem->GetItemSuffixFactor()); // SuffixFactor
|
||||
data << uint32(pItem->GetCount()); // item->count
|
||||
data << uint32(pItem->GetSpellCharges()); // item->charge FFFFFFF
|
||||
data << uint32(0); // item flags (dynamic?) (0x04 no lockId?)
|
||||
data << ObjectGuid(HIGHGUID_PLAYER, 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((expireTime-time(NULL))*IN_MILLISECONDS);// time left
|
||||
data << ObjectGuid(HIGHGUID_PLAYER, bidder); // auction->bidder current
|
||||
data << uint32(bid); // current bid
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -720,7 +778,7 @@ void AuctionEntry::DeleteFromDB() const
|
|||
void AuctionEntry::SaveToDB() const
|
||||
{
|
||||
//No SQL injection (no strings)
|
||||
CharacterDatabase.PExecute("INSERT INTO auction (id,houseid,itemguid,item_template,itemowner,buyoutprice,time,buyguid,lastbid,startbid,deposit) "
|
||||
"VALUES ('%u', '%u', '%u', '%u', '%u', '%u', '" UI64FMTD "', '%u', '%u', '%u', '%u')",
|
||||
Id, auctionHouseEntry->houseId, item_guidlow, item_template, owner, buyout, (uint64)expire_time, bidder, bid, startbid, deposit);
|
||||
CharacterDatabase.PExecute("INSERT INTO auction (id,houseid,itemguid,item_template,itemowner,buyoutprice,time,moneyTime,buyguid,lastbid,startbid,deposit) "
|
||||
"VALUES ('%u', '%u', '%u', '%u', '%u', '%u', '" UI64FMTD "', '" UI64FMTD "', '%u', '%u', '%u', '%u')",
|
||||
Id, auctionHouseEntry->houseId, itemGuidLow, itemTemplate, owner, buyout, (uint64)expireTime, (uint64)moneyDeliveryTime, bidder, bid, startbid, deposit);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue