Skip to content

Commit

Permalink
[11423] Support localization into auction sorting.
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirMangos committed May 2, 2011
1 parent f3d7894 commit c6d0037
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 18 deletions.
5 changes: 4 additions & 1 deletion src/game/AuctionHouseHandler.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
53 changes: 39 additions & 14 deletions src/game/AuctionHouseMgr.cpp
Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand All @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions src/game/AuctionHouseMgr.h
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "11422"
#define REVISION_NR "11423"
#endif // __REVISION_NR_H__

3 comments on commit c6d0037

@Denno
Copy link

@Denno Denno commented on c6d0037 May 3, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vladimir, Can be better so to make? :D

http://paste2.org/p/1396759

@Denno
Copy link

@Denno Denno commented on c6d0037 May 3, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

@VladimirMangos
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In [11428]. Thank you.

Please sign in to comment.