[11423] Support localization into auction sorting.

This commit is contained in:
VladimirMangos 2011-05-02 21:46:11 +04:00
parent 0b2f34f93b
commit b997f4925d
4 changed files with 49 additions and 18 deletions

View file

@ -377,6 +377,9 @@ void WorldSession::HandleAuctionSellItem(WorldPacket & recv_data)
AH->itemGuidLow = newItem->GetObjectGuid().GetCounter();
AH->itemTemplate = newItem->GetEntry();
AH->owner = pl->GetGUIDLow();
Utf8toWStr(pl->GetName(), AH->ownerName);
AH->startbid = bid;
AH->bidder = 0;
AH->bid = 0;
@ -748,7 +751,7 @@ void WorldSession::HandleAuctionListItems(WorldPacket & recv_data)
std::list<AuctionEntry*> auctions;
for (AuctionHouseObject::AuctionEntryMap::const_iterator itr = aucs->begin(); itr != aucs->end(); ++itr)
auctions.push_back(itr->second);
AuctionSorter sorter(Sort);
AuctionSorter sorter(Sort, GetPlayer());
auctions.sort(sorter);
// remove fake death

View file

@ -376,6 +376,9 @@ void AuctionHouseMgr::LoadAuctions()
AuctionEntry *auction;
typedef std::map<uint32, std::wstring> PlayerNames;
PlayerNames playerNames; // caching for load time
do
{
fields = result->Fetch();
@ -388,6 +391,18 @@ void AuctionHouseMgr::LoadAuctions()
auction->itemGuidLow = fields[2].GetUInt32();
auction->itemTemplate = fields[3].GetUInt32();
auction->owner = fields[4].GetUInt32();
std::wstring& plWName = playerNames[auction->owner];
if (plWName.empty())
{
std::string plName;
if (!sObjectMgr.GetPlayerNameByGUID(ObjectGuid(HIGHGUID_PLAYER, auction->owner), plName))
plName = sObjectMgr.GetMangosStringForDBCLocale(LANG_UNKNOWN);
Utf8toWStr(plName, plWName);
}
auction->ownerName = plWName;
auction->buyout = fields[5].GetUInt32();
auction->expireTime = fields[6].GetUInt32();
auction->moneyDeliveryTime = fields[7].GetUInt32();
@ -623,7 +638,7 @@ void AuctionHouseObject::BuildListOwnerItems(WorldPacket& data, Player* player,
}
}
int AuctionEntry::CompareAuctionEntry(uint32 column, const AuctionEntry *auc) const
int AuctionEntry::CompareAuctionEntry(uint32 column, const AuctionEntry *auc, Player* viewPlayer) const
{
switch (column)
{
@ -681,11 +696,27 @@ int AuctionEntry::CompareAuctionEntry(uint32 column, const AuctionEntry *auc) co
break;
case 5: // name = 5
{
Item *item1 = sAuctionMgr.GetAItem(itemGuidLow);
Item *item2 = sAuctionMgr.GetAItem(auc->itemGuidLow);
if (!item1 || !item2)
return 0;
return strcmp(item1->GetProto()->Name1, item2->GetProto()->Name1);
int32 loc_idx = viewPlayer->GetSession()->GetSessionDbLocaleIndex();
std::string name1, name2;
if (loc_idx >= 0)
{
if(ItemLocale const *il = sObjectMgr.GetItemLocale(itemTemplate))
name1 = il->Name[loc_idx];
if(ItemLocale const *il = sObjectMgr.GetItemLocale(auc->itemTemplate))
name2 = il->Name[loc_idx];
}
if (name1.empty())
if (ItemPrototype const* proto = ObjectMgr::GetItemPrototype(itemTemplate))
name1 = proto->Name1;
if (name2.empty())
if (ItemPrototype const* proto = ObjectMgr::GetItemPrototype(auc->itemTemplate))
name2 = proto->Name1;
std::wstring wname1, wname2;
Utf8toWStr(name1, wname1);
Utf8toWStr(name2, wname2);
return wname1.compare(wname2);
}
case 6: // minbidbuyout = 6
if (bid)
@ -711,13 +742,7 @@ int AuctionEntry::CompareAuctionEntry(uint32 column, const AuctionEntry *auc) co
}
break;
case 7: // seller = 7
{
Player* pl1 = sObjectMgr.GetPlayer(ObjectGuid(HIGHGUID_PLAYER, owner));
Player* pl2 = sObjectMgr.GetPlayer(ObjectGuid(HIGHGUID_PLAYER, auc->owner));
if (!pl1 || !pl2)
return 0;
return strcmp(pl1->GetName(), pl2->GetName());
}
return ownerName.compare(auc->ownerName);
case 8: // bid = 8
if (bid)
{
@ -770,7 +795,7 @@ bool AuctionSorter::operator()(const AuctionEntry *auc1, const AuctionEntry *auc
if (m_sort[i] == MAX_AUCTION_SORT) // end of sort
return false;
int res = auc1->CompareAuctionEntry(m_sort[i] & ~AUCTION_SORT_REVERSED, auc2);
int res = auc1->CompareAuctionEntry(m_sort[i] & ~AUCTION_SORT_REVERSED, auc2, m_viewPlayer);
// "equal" by used column
if (res == 0)
continue;

View file

@ -59,6 +59,7 @@ struct AuctionEntry
uint32 itemGuidLow;
uint32 itemTemplate;
uint32 owner;
std::wstring ownerName; // cache name for sorting
uint32 startbid; // maybe useless
uint32 bid;
uint32 buyout;
@ -78,7 +79,7 @@ struct AuctionEntry
void SaveToDB() const;
// -1,0,+1 order result
int CompareAuctionEntry(uint32 column, const AuctionEntry *auc) const;
int CompareAuctionEntry(uint32 column, const AuctionEntry *auc, Player* viewPlayer) const;
};
//this class is used as auctionhouse instance
@ -128,11 +129,13 @@ class AuctionHouseObject
class AuctionSorter
{
public:
AuctionSorter(uint8 *sort) : m_sort(sort) {}
AuctionSorter(AuctionSorter const& sorter) : m_sort(sorter.m_sort), m_viewPlayer(sorter.m_viewPlayer) {}
AuctionSorter(uint8 *sort, Player* viewPlayer) : m_sort(sort), m_viewPlayer(viewPlayer) {}
bool operator()(const AuctionEntry *auc1, const AuctionEntry *auc2) const;
private:
uint8* m_sort;
Player* m_viewPlayer;
};
class AuctionHouseMgr

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "11422"
#define REVISION_NR "11423"
#endif // __REVISION_NR_H__