mirror of
https://github.com/mangosfour/server.git
synced 2025-12-14 16:37:01 +00:00
More auction related code refactoring,
This commit is contained in:
parent
7c3ab4b453
commit
4fd34bf101
5 changed files with 233 additions and 201 deletions
|
|
@ -78,41 +78,6 @@ void WorldSession::SendAuctionHello( uint64 guid, Creature* unit )
|
|||
SendPacket( &data );
|
||||
}
|
||||
|
||||
//this function inserts to WorldPacket auction's data
|
||||
bool WorldSession::SendAuctionInfo(WorldPacket & data, AuctionEntry* auction)
|
||||
{
|
||||
Item *pItem = auctionmgr.GetAItem(auction->item_guidlow);
|
||||
if (!pItem)
|
||||
{
|
||||
sLog.outError("auction to item, that doesn't exist !!!!");
|
||||
return false;
|
||||
}
|
||||
data << (uint32) auction->Id;
|
||||
data << (uint32) pItem->GetEntry();
|
||||
|
||||
for (uint8 i = 0; i < MAX_INSPECTED_ENCHANTMENT_SLOT; i++)
|
||||
{
|
||||
data << (uint32) pItem->GetEnchantmentId(EnchantmentSlot(i));
|
||||
data << (uint32) pItem->GetEnchantmentDuration(EnchantmentSlot(i));
|
||||
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 << (uint64) auction->owner; //Auction->owner
|
||||
data << (uint32) auction->startbid; //Auction->startbid (not sure if useful)
|
||||
data << (uint32) ((auction->bid)? auctionmgr.GetAuctionOutBid(auction->bid) : 0);
|
||||
//minimal outbid
|
||||
data << (uint32) auction->buyout; //auction->buyout
|
||||
data << (uint32) (auction->time - time(NULL)) * 1000; //time left
|
||||
data << (uint64) auction->bidder; //auction->bidder current
|
||||
data << (uint32) auction->bid; //current bid
|
||||
return true;
|
||||
}
|
||||
|
||||
//call this method when player bids, creates, or deletes auction
|
||||
void WorldSession::SendAuctionCommandResult(uint32 auctionId, uint32 Action, uint32 ErrorCode, uint32 bidError )
|
||||
{
|
||||
|
|
@ -170,7 +135,7 @@ void WorldSession::SendAuctionOutbiddedMail(AuctionEntry *auction, uint32 newPri
|
|||
msgAuctionOutbiddedSubject << auction->item_template << ":0:" << AUCTION_OUTBIDDED;
|
||||
|
||||
if (oldBidder)
|
||||
oldBidder->GetSession()->SendAuctionBidderNotification( auction->location, auction->Id, _player->GetGUID(), newPrice, auctionmgr.GetAuctionOutBid(auction->bid), auction->item_template);
|
||||
oldBidder->GetSession()->SendAuctionBidderNotification( auction->location, auction->Id, _player->GetGUID(), newPrice, auction->GetAuctionOutBid(), auction->item_template);
|
||||
|
||||
WorldSession::SendMailTo(oldBidder, MAIL_AUCTION, MAIL_STATIONERY_AUCTION, auction->location, auction->bidder, msgAuctionOutbiddedSubject.str(), 0, NULL, auction->bid, 0, MAIL_CHECK_MASK_NONE);
|
||||
}
|
||||
|
|
@ -294,7 +259,7 @@ void WorldSession::HandleAuctionSellItem( WorldPacket & recv_data )
|
|||
AH->bidder = 0;
|
||||
AH->bid = 0;
|
||||
AH->buyout = buyout;
|
||||
AH->time = time(NULL) + auction_time;
|
||||
AH->expire_time = time(NULL) + auction_time;
|
||||
AH->deposit = deposit;
|
||||
AH->location = location;
|
||||
|
||||
|
|
@ -309,7 +274,7 @@ void WorldSession::HandleAuctionSellItem( WorldPacket & recv_data )
|
|||
it->SaveToDB(); // recursive and not have transaction guard into self, not in inventiory and can be save standalone
|
||||
CharacterDatabase.PExecute("INSERT INTO auctionhouse (id,auctioneerguid,itemguid,item_template,itemowner,buyoutprice,time,buyguid,lastbid,startbid,deposit,location) "
|
||||
"VALUES ('%u', '%u', '%u', '%u', '%u', '%u', '" I64FMTD "', '%u', '%u', '%u', '%u', '%u')",
|
||||
AH->Id, AH->auctioneer, AH->item_guidlow, AH->item_template, AH->owner, AH->buyout, (uint64)AH->time, AH->bidder, AH->bid, AH->startbid, AH->deposit, AH->location);
|
||||
AH->Id, AH->auctioneer, AH->item_guidlow, AH->item_template, AH->owner, AH->buyout, (uint64)AH->expire_time, AH->bidder, AH->bid, AH->startbid, AH->deposit, AH->location);
|
||||
pl->SaveInventoryAndGoldToDB();
|
||||
CharacterDatabase.CommitTransaction();
|
||||
|
||||
|
|
@ -371,7 +336,7 @@ void WorldSession::HandleAuctionPlaceBid( WorldPacket & recv_data )
|
|||
|
||||
// price too low for next bid if not buyout
|
||||
if ((price < auction->buyout || auction->buyout == 0) &&
|
||||
price < auction->bid + auctionmgr.GetAuctionOutBid(auction->bid))
|
||||
price < auction->bid + auction->GetAuctionOutBid())
|
||||
{
|
||||
//auction has already higher bid, client tests it!
|
||||
return;
|
||||
|
|
@ -483,7 +448,7 @@ void WorldSession::HandleAuctionRemoveItem( WorldPacket & recv_data )
|
|||
{
|
||||
if (auction->bidder > 0) // If we have a bidder, we have to send him the money he paid
|
||||
{
|
||||
uint32 auctionCut = auctionmgr.GetAuctionCut( auction->location, auction->bid);
|
||||
uint32 auctionCut = auction->GetAuctionCut();
|
||||
if ( pl->GetMoney() < auctionCut ) //player doesn't have enough money, maybe message needed
|
||||
return;
|
||||
//some auctionBidderNotification would be needed, but don't know that parts..
|
||||
|
|
@ -557,7 +522,7 @@ void WorldSession::HandleAuctionListBidderItems( WorldPacket & recv_data )
|
|||
GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
|
||||
|
||||
AuctionLocation location = AuctioneerFactionToLocation(pCreature->getFaction());
|
||||
AuctionHouseObject* mAuctions = auctionmgr.GetAuctionsMap( location );
|
||||
AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap( location );
|
||||
|
||||
WorldPacket data( SMSG_AUCTION_BIDDER_LIST_RESULT, (4+4+4) );
|
||||
Player *pl = GetPlayer();
|
||||
|
|
@ -569,23 +534,15 @@ void WorldSession::HandleAuctionListBidderItems( WorldPacket & recv_data )
|
|||
--outbiddedCount;
|
||||
uint32 outbiddedAuctionId;
|
||||
recv_data >> outbiddedAuctionId;
|
||||
AuctionEntry * auction = mAuctions->GetAuction( outbiddedAuctionId );
|
||||
if ( auction && SendAuctionInfo(data, auction))
|
||||
AuctionEntry * auction = auctionHouse->GetAuction( outbiddedAuctionId );
|
||||
if ( auction && auction->BuildAuctionInfo(data))
|
||||
{
|
||||
++totalcount;
|
||||
++count;
|
||||
}
|
||||
}
|
||||
for (AuctionHouseObject::AuctionEntryMap::const_iterator itr = mAuctions->GetAuctionsBegin();itr != mAuctions->GetAuctionsEnd();++itr)
|
||||
{
|
||||
AuctionEntry *Aentry = itr->second;
|
||||
if( Aentry && Aentry->bidder == pl->GetGUIDLow() )
|
||||
{
|
||||
if (SendAuctionInfo(data, itr->second))
|
||||
++count;
|
||||
++totalcount;
|
||||
}
|
||||
}
|
||||
|
||||
auctionHouse->BuildListBidderItems(data,pl,count,totalcount);
|
||||
data.put<uint32>( 0, count ); // add count to placeholder
|
||||
data << totalcount;
|
||||
data << (uint32)300; //unk 2.3.0
|
||||
|
|
@ -616,23 +573,15 @@ void WorldSession::HandleAuctionListOwnerItems( WorldPacket & recv_data )
|
|||
|
||||
AuctionLocation location = AuctioneerFactionToLocation(pCreature->getFaction());
|
||||
|
||||
AuctionHouseObject* mAuctions = auctionmgr.GetAuctionsMap( location );
|
||||
AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap( location );
|
||||
|
||||
WorldPacket data( SMSG_AUCTION_OWNER_LIST_RESULT, (4+4+4) );
|
||||
data << (uint32) 0; // amount place holder
|
||||
|
||||
uint32 count = 0;
|
||||
uint32 totalcount = 0;
|
||||
for (AuctionHouseObject::AuctionEntryMap::const_iterator itr = mAuctions->GetAuctionsBegin();itr != mAuctions->GetAuctionsEnd();++itr)
|
||||
{
|
||||
AuctionEntry *Aentry = itr->second;
|
||||
if( Aentry && Aentry->owner == _player->GetGUIDLow() )
|
||||
{
|
||||
if(SendAuctionInfo(data, itr->second))
|
||||
++count;
|
||||
++totalcount;
|
||||
}
|
||||
}
|
||||
|
||||
auctionHouse->BuildListOwnerItems(data,_player,count,totalcount);
|
||||
data.put<uint32>(0, count);
|
||||
data << (uint32) totalcount;
|
||||
data << (uint32) 0;
|
||||
|
|
@ -672,7 +621,7 @@ void WorldSession::HandleAuctionListItems( WorldPacket & recv_data )
|
|||
GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
|
||||
|
||||
AuctionLocation location = AuctioneerFactionToLocation(pCreature->getFaction());
|
||||
AuctionHouseObject * mAuctions = auctionmgr.GetAuctionsMap( location );
|
||||
AuctionHouseObject * auctionHouse = auctionmgr.GetAuctionsMap( location );
|
||||
|
||||
//sLog.outDebug("Auctionhouse search guid: " I64FMTD ", list from: %u, searchedname: %s, levelmin: %u, levelmax: %u, auctionSlotID: %u, auctionMainCategory: %u, auctionSubCategory: %u, quality: %u, usable: %u", guid, listfrom, searchedname.c_str(), levelmin, levelmax, auctionSlotID, auctionMainCategory, auctionSubCategory, quality, usable);
|
||||
|
||||
|
|
@ -688,62 +637,11 @@ void WorldSession::HandleAuctionListItems( WorldPacket & recv_data )
|
|||
|
||||
wstrToLower(wsearchedname);
|
||||
|
||||
for (AuctionHouseObject::AuctionEntryMap::const_iterator itr = mAuctions->GetAuctionsBegin();itr != mAuctions->GetAuctionsEnd();++itr)
|
||||
{
|
||||
AuctionEntry *Aentry = itr->second;
|
||||
Item *item = auctionmgr.GetAItem(Aentry->item_guidlow);
|
||||
if( item )
|
||||
{
|
||||
ItemPrototype const *proto = item->GetProto();
|
||||
if( proto )
|
||||
{
|
||||
if( auctionMainCategory == (0xffffffff) || proto->Class == auctionMainCategory )
|
||||
{
|
||||
if( auctionSubCategory == (0xffffffff) || proto->SubClass == auctionSubCategory )
|
||||
{
|
||||
if( auctionSlotID == (0xffffffff) || proto->InventoryType == auctionSlotID )
|
||||
{
|
||||
if( quality == (0xffffffff) || proto->Quality == quality )
|
||||
{
|
||||
if( usable == (0x00) || _player->CanUseItem( item ) == EQUIP_ERR_OK )
|
||||
{
|
||||
if( ( levelmin == (0x00) || proto->RequiredLevel >= levelmin ) && ( levelmax == (0x00) || proto->RequiredLevel <= levelmax ) )
|
||||
{
|
||||
std::string name = proto->Name1;
|
||||
auctionHouse->BuildListAuctionItems(data,_player,
|
||||
wsearchedname, listfrom, levelmin, levelmax, usable,
|
||||
auctionSlotID, auctionMainCategory, auctionSubCategory, quality,
|
||||
count,totalcount);
|
||||
|
||||
// local name
|
||||
int loc_idx = GetSessionDbLocaleIndex();
|
||||
if ( loc_idx >= 0 )
|
||||
{
|
||||
ItemLocale const *il = objmgr.GetItemLocale(proto->ItemId);
|
||||
if (il)
|
||||
{
|
||||
if (il->Name.size() > size_t(loc_idx) && !il->Name[loc_idx].empty())
|
||||
name = il->Name[loc_idx];
|
||||
}
|
||||
}
|
||||
|
||||
if(name.empty())
|
||||
continue;
|
||||
|
||||
if( wsearchedname.empty() || Utf8FitTo(name, wsearchedname) )
|
||||
{
|
||||
if ((count < 50) && (totalcount >= listfrom))
|
||||
{
|
||||
++count;
|
||||
SendAuctionInfo( data, Aentry);
|
||||
}
|
||||
++totalcount;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
data.put<uint32>(0, count);
|
||||
data << (uint32) totalcount;
|
||||
data << (uint32) 300; // unk 2.3.0 const?
|
||||
|
|
|
|||
|
|
@ -29,13 +29,13 @@
|
|||
#include "ObjectMgr.h"
|
||||
#include "Player.h"
|
||||
#include "World.h"
|
||||
#include "WorldPacket.h"
|
||||
#include "WorldSession.h"
|
||||
|
||||
#include "Policies/SingletonImp.h"
|
||||
|
||||
INSTANTIATE_SINGLETON_1( AuctionHouseMgr );
|
||||
|
||||
|
||||
AuctionHouseMgr::AuctionHouseMgr()
|
||||
{
|
||||
}
|
||||
|
|
@ -61,14 +61,6 @@ AuctionHouseObject * AuctionHouseMgr::GetAuctionsMap( AuctionLocation location )
|
|||
}
|
||||
}
|
||||
|
||||
uint32 AuctionHouseMgr::GetAuctionCut(AuctionLocation location, uint32 highBid)
|
||||
{
|
||||
if (location == AUCTION_NEUTRAL && !sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION))
|
||||
return (uint32) (0.15f * highBid * sWorld.getRate(RATE_AUCTION_CUT));
|
||||
else
|
||||
return (uint32) (0.05f * highBid * sWorld.getRate(RATE_AUCTION_CUT));
|
||||
}
|
||||
|
||||
uint32 AuctionHouseMgr::GetAuctionDeposit(AuctionLocation location, uint32 time, Item *pItem)
|
||||
{
|
||||
float percentance; // in 0..1
|
||||
|
|
@ -82,15 +74,6 @@ uint32 AuctionHouseMgr::GetAuctionDeposit(AuctionLocation location, uint32 time,
|
|||
return uint32( percentance * pItem->GetProto()->SellPrice * pItem->GetCount() * (time / MIN_AUCTION_TIME ) );
|
||||
}
|
||||
|
||||
/// the sum of outbid is (1% from current bid)*5, if bid is very small, it is 1c
|
||||
uint32 AuctionHouseMgr::GetAuctionOutBid(uint32 currentBid)
|
||||
{
|
||||
uint32 outbid = (currentBid / 100) * 5;
|
||||
if (!outbid)
|
||||
outbid = 1;
|
||||
return outbid;
|
||||
}
|
||||
|
||||
//does not clear ram
|
||||
void AuctionHouseMgr::SendAuctionWonMail( AuctionEntry *auction )
|
||||
{
|
||||
|
|
@ -193,7 +176,7 @@ void AuctionHouseMgr::SendAuctionSalePendingMail( AuctionEntry * auction )
|
|||
msgAuctionSalePendingSubject << auction->item_template << ":0:" << AUCTION_SALE_PENDING;
|
||||
|
||||
std::ostringstream msgAuctionSalePendingBody;
|
||||
uint32 auctionCut = GetAuctionCut(auction->location, auction->bid);
|
||||
uint32 auctionCut = auction->GetAuctionCut();
|
||||
|
||||
time_t distrTime = time(NULL) + HOUR;
|
||||
|
||||
|
|
@ -228,7 +211,7 @@ void AuctionHouseMgr::SendAuctionSuccessfulMail( AuctionEntry * auction )
|
|||
msgAuctionSuccessfulSubject << auction->item_template << ":0:" << AUCTION_SUCCESSFUL;
|
||||
|
||||
std::ostringstream auctionSuccessfulBody;
|
||||
uint32 auctionCut = GetAuctionCut(auction->location, auction->bid);
|
||||
uint32 auctionCut = auction->GetAuctionCut();
|
||||
|
||||
auctionSuccessfulBody.width(16);
|
||||
auctionSuccessfulBody << std::right << std::hex << auction->bidder;
|
||||
|
|
@ -399,7 +382,7 @@ void AuctionHouseMgr::LoadAuctions()
|
|||
aItem->item_template = fields[3].GetUInt32();
|
||||
aItem->owner = fields[4].GetUInt32();
|
||||
aItem->buyout = fields[5].GetUInt32();
|
||||
aItem->time = fields[6].GetUInt32();
|
||||
aItem->expire_time = fields[6].GetUInt32();
|
||||
aItem->bidder = fields[7].GetUInt32();
|
||||
aItem->bid = fields[8].GetUInt32();
|
||||
aItem->startbid = fields[9].GetUInt32();
|
||||
|
|
@ -453,3 +436,187 @@ bool AuctionHouseMgr::RemoveAItem( uint32 id )
|
|||
mAitems.erase(i);
|
||||
return true;
|
||||
}
|
||||
|
||||
void AuctionHouseMgr::Update()
|
||||
{
|
||||
mHordeAuctions.Update();
|
||||
mAllianceAuctions.Update();
|
||||
mNeutralAuctions.Update();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
next = itr;
|
||||
++next;
|
||||
if (curTime > (itr->second->expire_time))
|
||||
{
|
||||
///- Either cancel the auction if there was no bidder
|
||||
if (itr->second->bidder == 0)
|
||||
{
|
||||
auctionmgr.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
|
||||
auctionmgr.SendAuctionSuccessfulMail( itr->second );
|
||||
auctionmgr.SendAuctionWonMail( itr->second );
|
||||
}
|
||||
|
||||
///- In any case clear the auction
|
||||
//No SQL injection (Id is integer)
|
||||
CharacterDatabase.PExecute("DELETE FROM auctionhouse WHERE id = '%u'",itr->second->Id);
|
||||
auctionmgr.RemoveAItem(itr->second->item_guidlow);
|
||||
delete itr->second;
|
||||
RemoveAuction(itr->first);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AuctionHouseObject::BuildListBidderItems(WorldPacket& data, Player* player, uint32& count, uint32& totalcount)
|
||||
{
|
||||
for (AuctionEntryMap::const_iterator itr = AuctionsMap.begin();itr != AuctionsMap.end();++itr)
|
||||
{
|
||||
AuctionEntry *Aentry = itr->second;
|
||||
if( Aentry && Aentry->bidder == player->GetGUIDLow() )
|
||||
{
|
||||
if (itr->second->BuildAuctionInfo(data))
|
||||
++count;
|
||||
++totalcount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AuctionHouseObject::BuildListOwnerItems(WorldPacket& data, Player* player, uint32& count, uint32& totalcount)
|
||||
{
|
||||
for (AuctionEntryMap::const_iterator itr = AuctionsMap.begin();itr != AuctionsMap.end();++itr)
|
||||
{
|
||||
AuctionEntry *Aentry = itr->second;
|
||||
if( Aentry && Aentry->owner == player->GetGUIDLow() )
|
||||
{
|
||||
if(Aentry->BuildAuctionInfo(data))
|
||||
++count;
|
||||
++totalcount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AuctionHouseObject::BuildListAuctionItems(WorldPacket& data, Player* player,
|
||||
std::wstring const& wsearchedname, uint32 listfrom, uint32 levelmin, uint32 levelmax, uint32 usable,
|
||||
uint32 inventoryType, uint32 itemClass, uint32 itemSubClass, uint32 quality,
|
||||
uint32& count, uint32& totalcount)
|
||||
{
|
||||
int loc_idx = player->GetSession()->GetSessionDbLocaleIndex();
|
||||
|
||||
for (AuctionEntryMap::const_iterator itr = AuctionsMap.begin();itr != AuctionsMap.end();++itr)
|
||||
{
|
||||
AuctionEntry *Aentry = itr->second;
|
||||
Item *item = auctionmgr.GetAItem(Aentry->item_guidlow);
|
||||
if (!item)
|
||||
continue;
|
||||
|
||||
ItemPrototype const *proto = item->GetProto();
|
||||
|
||||
if (itemClass != (0xffffffff) && proto->Class != itemClass)
|
||||
continue;
|
||||
|
||||
if (itemSubClass != (0xffffffff) && proto->SubClass != itemSubClass)
|
||||
continue;
|
||||
|
||||
if (inventoryType != (0xffffffff) && proto->InventoryType != inventoryType)
|
||||
continue;
|
||||
|
||||
if (quality != (0xffffffff) && proto->Quality != quality)
|
||||
continue;
|
||||
|
||||
if( levelmin != (0x00) && (proto->RequiredLevel < levelmin || levelmax != (0x00) && proto->RequiredLevel > levelmax ) )
|
||||
continue;
|
||||
|
||||
if( usable != (0x00) && player->CanUseItem( item ) != EQUIP_ERR_OK )
|
||||
continue;
|
||||
|
||||
std::string name = proto->Name1;
|
||||
if(name.empty())
|
||||
continue;
|
||||
|
||||
// local name
|
||||
if ( loc_idx >= 0 )
|
||||
{
|
||||
ItemLocale const *il = objmgr.GetItemLocale(proto->ItemId);
|
||||
if (il)
|
||||
{
|
||||
if (il->Name.size() > size_t(loc_idx) && !il->Name[loc_idx].empty())
|
||||
name = il->Name[loc_idx];
|
||||
}
|
||||
}
|
||||
|
||||
if( !wsearchedname.empty() && !Utf8FitTo(name, wsearchedname) )
|
||||
continue;
|
||||
|
||||
if ((count < 50) && (totalcount >= listfrom))
|
||||
{
|
||||
++count;
|
||||
Aentry->BuildAuctionInfo(data);
|
||||
}
|
||||
++totalcount;
|
||||
}
|
||||
}
|
||||
|
||||
//this function inserts to WorldPacket auction's data
|
||||
bool AuctionEntry::BuildAuctionInfo(WorldPacket & data) const
|
||||
{
|
||||
Item *pItem = auctionmgr.GetAItem(item_guidlow);
|
||||
if (!pItem)
|
||||
{
|
||||
sLog.outError("auction to item, that doesn't exist !!!!");
|
||||
return false;
|
||||
}
|
||||
data << (uint32) Id;
|
||||
data << (uint32) pItem->GetEntry();
|
||||
|
||||
for (uint8 i = 0; i < MAX_INSPECTED_ENCHANTMENT_SLOT; i++)
|
||||
{
|
||||
data << (uint32) pItem->GetEnchantmentId(EnchantmentSlot(i));
|
||||
data << (uint32) pItem->GetEnchantmentDuration(EnchantmentSlot(i));
|
||||
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 << (uint64) 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))* 1000; //time left
|
||||
data << (uint64) bidder; //auction->bidder current
|
||||
data << (uint32) bid; //current bid
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32 AuctionEntry::GetAuctionCut() const
|
||||
{
|
||||
if (location == AUCTION_NEUTRAL && !sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION))
|
||||
return (uint32) (0.15f * bid * sWorld.getRate(RATE_AUCTION_CUT));
|
||||
else
|
||||
return (uint32) (0.05f * bid * sWorld.getRate(RATE_AUCTION_CUT));
|
||||
}
|
||||
|
||||
/// the sum of outbid is (1% from current bid)*5, if bid is very small, it is 1c
|
||||
uint32 AuctionEntry::GetAuctionOutBid() const
|
||||
{
|
||||
uint32 outbid = (bid / 100) * 5;
|
||||
if (!outbid)
|
||||
outbid = 1;
|
||||
return outbid;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@
|
|||
#include "Policies/Singleton.h"
|
||||
|
||||
class Item;
|
||||
class Player;
|
||||
class WorldPacket;
|
||||
|
||||
#define MIN_AUCTION_TIME (12*HOUR)
|
||||
|
||||
|
|
@ -61,10 +63,15 @@ struct AuctionEntry
|
|||
uint32 startbid; //maybe useless
|
||||
uint32 bid;
|
||||
uint32 buyout;
|
||||
time_t time;
|
||||
time_t expire_time;
|
||||
uint32 bidder;
|
||||
uint32 deposit; //deposit can be calculated only when creating auction
|
||||
AuctionLocation location;
|
||||
|
||||
// helpers
|
||||
uint32 GetAuctionCut() const;
|
||||
uint32 GetAuctionOutBid() const;
|
||||
bool BuildAuctionInfo(WorldPacket & data) const;
|
||||
};
|
||||
|
||||
//this class is used as auctionhouse instance
|
||||
|
|
@ -82,9 +89,6 @@ class AuctionHouseObject
|
|||
|
||||
uint32 Getcount() { return AuctionsMap.size(); }
|
||||
|
||||
AuctionEntryMap::iterator GetAuctionsBegin() {return AuctionsMap.begin();}
|
||||
AuctionEntryMap::iterator GetAuctionsEnd() {return AuctionsMap.end();}
|
||||
|
||||
void AddAuction(AuctionEntry *ah)
|
||||
{
|
||||
ASSERT( ah );
|
||||
|
|
@ -102,6 +106,15 @@ class AuctionHouseObject
|
|||
return AuctionsMap.erase(id) ? true : false;
|
||||
}
|
||||
|
||||
void Update();
|
||||
|
||||
void BuildListBidderItems(WorldPacket& data, Player* player, uint32& count, uint32& totalcount);
|
||||
void BuildListOwnerItems(WorldPacket& data, Player* player, uint32& count, uint32& totalcount);
|
||||
void BuildListAuctionItems(WorldPacket& data, Player* player,
|
||||
std::wstring const& searchedname, uint32 listfrom, uint32 levelmin, uint32 levelmax, uint32 usable,
|
||||
uint32 inventoryType, uint32 itemClass, uint32 itemSubClass, uint32 quality,
|
||||
uint32& count, uint32& totalcount);
|
||||
|
||||
private:
|
||||
AuctionEntryMap AuctionsMap;
|
||||
};
|
||||
|
|
@ -126,22 +139,23 @@ class AuctionHouseMgr
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void AddAItem(Item* it);
|
||||
|
||||
bool RemoveAItem(uint32 id);
|
||||
|
||||
//auction messages
|
||||
void SendAuctionWonMail( AuctionEntry * auction );
|
||||
void SendAuctionSalePendingMail( AuctionEntry * auction );
|
||||
void SendAuctionSuccessfulMail( AuctionEntry * auction );
|
||||
void SendAuctionExpiredMail( AuctionEntry * auction );
|
||||
static uint32 GetAuctionCut( AuctionLocation location, uint32 highBid );
|
||||
static uint32 GetAuctionDeposit(AuctionLocation location, uint32 time, Item *pItem);
|
||||
static uint32 GetAuctionOutBid(uint32 currentBid);
|
||||
|
||||
public:
|
||||
//load first auction items, because of check if item exists, when loading
|
||||
void LoadAuctionItems();
|
||||
void LoadAuctions();
|
||||
|
||||
void AddAItem(Item* it);
|
||||
bool RemoveAItem(uint32 id);
|
||||
|
||||
void Update();
|
||||
|
||||
private:
|
||||
AuctionHouseObject mHordeAuctions;
|
||||
AuctionHouseObject mAllianceAuctions;
|
||||
|
|
|
|||
|
|
@ -1472,54 +1472,8 @@ void World::Update(uint32 diff)
|
|||
objmgr.ReturnOrDeleteOldMails(true);
|
||||
}
|
||||
|
||||
AuctionHouseObject* AuctionMap;
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
AuctionMap = auctionmgr.GetAuctionsMap(AUCTION_HORDE);
|
||||
break;
|
||||
case 1:
|
||||
AuctionMap = auctionmgr.GetAuctionsMap(AUCTION_ALLIANCE);
|
||||
break;
|
||||
case 2:
|
||||
AuctionMap = auctionmgr.GetAuctionsMap(AUCTION_NEUTRAL);
|
||||
break;
|
||||
}
|
||||
|
||||
///- Handle expired auctions
|
||||
AuctionHouseObject::AuctionEntryMap::iterator itr,next;
|
||||
for (itr = AuctionMap->GetAuctionsBegin(); itr != AuctionMap->GetAuctionsEnd();itr = next)
|
||||
{
|
||||
next = itr;
|
||||
++next;
|
||||
if (m_gameTime > (itr->second->time))
|
||||
{
|
||||
///- Either cancel the auction if there was no bidder
|
||||
if (itr->second->bidder == 0)
|
||||
{
|
||||
auctionmgr.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
|
||||
auctionmgr.SendAuctionSuccessfulMail( itr->second );
|
||||
auctionmgr.SendAuctionWonMail( itr->second );
|
||||
}
|
||||
|
||||
///- In any case clear the auction
|
||||
//No SQL injection (Id is integer)
|
||||
CharacterDatabase.PExecute("DELETE FROM auctionhouse WHERE id = '%u'",itr->second->Id);
|
||||
auctionmgr.RemoveAItem(itr->second->item_guidlow);
|
||||
delete itr->second;
|
||||
AuctionMap->RemoveAuction(itr->first);
|
||||
}
|
||||
}
|
||||
}
|
||||
///- Handle expired auctions
|
||||
auctionmgr.Update();
|
||||
}
|
||||
|
||||
/// <li> Handle session updates when the timer has passed
|
||||
|
|
|
|||
|
|
@ -180,7 +180,6 @@ class MANGOS_DLL_SPEC WorldSession
|
|||
void SendAuctionCommandResult( uint32 auctionId, uint32 Action, uint32 ErrorCode, uint32 bidError = 0);
|
||||
void SendAuctionBidderNotification( uint32 location, uint32 auctionId, uint64 bidder, uint32 bidSum, uint32 diff, uint32 item_template);
|
||||
void SendAuctionOwnerNotification( AuctionEntry * auction );
|
||||
bool SendAuctionInfo(WorldPacket & data, AuctionEntry* auction);
|
||||
void SendAuctionOutbiddedMail( AuctionEntry * auction, uint32 newPrice );
|
||||
void SendAuctionCancelledToBidderMail( AuctionEntry* auction );
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue