mirror of
https://github.com/mangosfour/server.git
synced 2025-12-13 13:37:05 +00:00
[11705] Allow have auction bid generated by server
Some code cleanups also. Fir generation bids can be used auction->UpdateBid(price) call without player pointer.
This commit is contained in:
parent
0f0fa22607
commit
cda3a95fc2
5 changed files with 95 additions and 84 deletions
|
|
@ -120,12 +120,13 @@ void WorldSession::SendAuctionOwnerNotification(AuctionEntry* auction)
|
|||
data << uint32(auction->bid); // if 0, client shows ERR_AUCTION_EXPIRED_S, else ERR_AUCTION_SOLD_S (works only when guid==0)
|
||||
data << uint32(auction->GetAuctionOutBid()); // AuctionOutBid?
|
||||
|
||||
ObjectGuid guid = ObjectGuid();
|
||||
ObjectGuid bidder_guid = ObjectGuid();
|
||||
if (!auction->moneyDeliveryTime) // not sold yet
|
||||
guid = ObjectGuid(HIGHGUID_PLAYER, auction->bidder);// bidder==0 and moneyDeliveryTime==0 for expired auctions, so it will show error message properly
|
||||
bidder_guid = ObjectGuid(HIGHGUID_PLAYER, auction->bidder);
|
||||
|
||||
// if guid!=0, client updates auctions with new bid, outbid and bidderGuid, else it shows error messages as described above
|
||||
data << guid; // bidder guid
|
||||
// bidder==0 and moneyDeliveryTime==0 for expired auctions, and client shows error messages as described above
|
||||
// if bidder!=0 client updates auctions with new bid, outbid and bidderGuid
|
||||
data << bidder_guid; // bidder guid
|
||||
data << uint32(auction->itemTemplate); // item entry
|
||||
data << uint32(auction->itemRandomPropertyId);
|
||||
|
||||
|
|
@ -154,7 +155,7 @@ void WorldSession::SendAuctionOutbiddedMail(AuctionEntry *auction)
|
|||
Player *oldBidder = sObjectMgr.GetPlayer(oldBidder_guid);
|
||||
|
||||
uint32 oldBidder_accId = 0;
|
||||
if(!oldBidder)
|
||||
if(!oldBidder && oldBidder_guid)
|
||||
oldBidder_accId = sObjectMgr.GetPlayerAccountIdByGUID(oldBidder_guid);
|
||||
|
||||
// old bidder exist
|
||||
|
|
@ -179,7 +180,7 @@ void WorldSession::SendAuctionCancelledToBidderMail(AuctionEntry* auction)
|
|||
Player *bidder = sObjectMgr.GetPlayer(bidder_guid);
|
||||
|
||||
uint32 bidder_accId = 0;
|
||||
if (!bidder)
|
||||
if (!bidder && bidder_guid)
|
||||
bidder_accId = sObjectMgr.GetPlayerAccountIdByGUID(bidder_guid);
|
||||
|
||||
// bidder exist
|
||||
|
|
@ -415,10 +416,6 @@ void WorldSession::HandleAuctionPlaceBid(WorldPacket & recv_data)
|
|||
return;
|
||||
}
|
||||
|
||||
// cheating
|
||||
if (price < auction->startbid)
|
||||
return;
|
||||
|
||||
// cheating or client lags
|
||||
if (price <= auction->bid)
|
||||
{
|
||||
|
|
@ -443,57 +440,16 @@ void WorldSession::HandleAuctionPlaceBid(WorldPacket & recv_data)
|
|||
return;
|
||||
}
|
||||
|
||||
if ((price < auction->buyout) || (auction->buyout == 0))// bid
|
||||
{
|
||||
if (pl->GetGUIDLow() == auction->bidder)
|
||||
{
|
||||
pl->ModifyMoney(-int32(price - auction->bid));
|
||||
}
|
||||
else
|
||||
{
|
||||
pl->ModifyMoney(-int32(price));
|
||||
if (auction->bidder) // return money to old bidder if present
|
||||
SendAuctionOutbiddedMail(auction);
|
||||
}
|
||||
// cheating
|
||||
if (price < auction->startbid)
|
||||
return;
|
||||
|
||||
auction->bidder = pl->GetGUIDLow();
|
||||
auction->bid = price;
|
||||
SendAuctionCommandResult(auction, AUCTION_BID_PLACED, AUCTION_OK);
|
||||
|
||||
SendAuctionCommandResult(auction, AUCTION_BID_PLACED, AUCTION_OK);
|
||||
|
||||
if (auction_owner)
|
||||
auction_owner->GetSession()->SendAuctionOwnerNotification(auction);
|
||||
|
||||
GetPlayer()->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_AUCTION_BID, price);
|
||||
|
||||
// after this update we should save player's money ...
|
||||
CharacterDatabase.PExecute("UPDATE auction SET buyguid = '%u', lastbid = '%u' WHERE id = '%u'", auction->bidder, auction->bid, auction->Id);
|
||||
}
|
||||
else // buyout
|
||||
{
|
||||
if (pl->GetGUIDLow() == auction->bidder)
|
||||
{
|
||||
pl->ModifyMoney(-int32(auction->buyout - auction->bid));
|
||||
}
|
||||
else
|
||||
{
|
||||
pl->ModifyMoney(-int32(auction->buyout));
|
||||
if (auction->bidder) // return money to old bidder if present
|
||||
SendAuctionOutbiddedMail(auction);
|
||||
}
|
||||
|
||||
auction->bidder = pl->GetGUIDLow();
|
||||
auction->bid = auction->buyout;
|
||||
|
||||
SendAuctionCommandResult(auction, AUCTION_BID_PLACED, AUCTION_OK);
|
||||
|
||||
auction->AuctionBidWinning();
|
||||
|
||||
GetPlayer()->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_AUCTION_BID, auction->buyout);
|
||||
}
|
||||
CharacterDatabase.BeginTransaction();
|
||||
pl->SaveInventoryAndGoldToDB();
|
||||
CharacterDatabase.CommitTransaction();
|
||||
if (auction->UpdateBid(price, pl))
|
||||
pl->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_AUCTION_BID, price);
|
||||
else
|
||||
pl->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_AUCTION_BID, auction->buyout);
|
||||
}
|
||||
|
||||
// this void is called when auction_owner cancels his auction
|
||||
|
|
@ -536,13 +492,15 @@ void WorldSession::HandleAuctionRemoveItem(WorldPacket & recv_data)
|
|||
return;
|
||||
}
|
||||
|
||||
if (auction->bidder > 0) // If we have a bidder, we have to send him the money he paid
|
||||
if (auction->bid) // If we have a bid, we have to send him the money he paid
|
||||
{
|
||||
uint32 auctionCut = auction->GetAuctionCut();
|
||||
if (pl->GetMoney() < auctionCut) // player doesn't have enough money, maybe message needed
|
||||
if (pl->GetMoney() < auctionCut) // player doesn't have enough money, maybe message needed
|
||||
return;
|
||||
|
||||
SendAuctionCancelledToBidderMail(auction);
|
||||
if (auction->bidder) // if auction have real existed bidder send mail
|
||||
SendAuctionCancelledToBidderMail(auction);
|
||||
|
||||
pl->ModifyMoney(-int32(auctionCut));
|
||||
}
|
||||
// Return the item by mail
|
||||
|
|
@ -550,7 +508,7 @@ void WorldSession::HandleAuctionRemoveItem(WorldPacket & recv_data)
|
|||
msgAuctionCanceledOwner << auction->itemTemplate << ":0:" << AUCTION_CANCELED << ":0:0";
|
||||
|
||||
// item will deleted or added to received mail list
|
||||
MailDraft(msgAuctionCanceledOwner.str(), "") // TODO: fix body
|
||||
MailDraft(msgAuctionCanceledOwner.str(), "") // TODO: fix body
|
||||
.AddItem(pItem)
|
||||
.SendMailTo(pl, auction, MAIL_CHECK_MASK_COPIED);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue