diff options
author | pete318 <pete318@hotmail.com> | 2015-09-27 21:27:23 +0100 |
---|---|---|
committer | r00ty <pete318@hotmail.com> | 2015-09-28 22:26:23 +0200 |
commit | 01ae5c4bf6bce7e2a9a0621eb8edcf0197bc3d2c (patch) | |
tree | af09d9126eb633bf75cd387396a5349dac8a2081 /src | |
parent | fcc6ef6b1881196bbcebf5949fe682056b366b46 (diff) |
Auction house changes:
- Stop storing guid for auctioneer.
- Store instead house ID
- No separate ID for various houses. Only Horde, Alliance and Neutral.
- Removed non-needed faction checks.
- Use enum for auction house IDs
NOTE: This will expire all current auctions and return item to player (or
award to high bidder) in order to prepare database for the changes.
Diffstat (limited to 'src')
5 files changed, 76 insertions, 66 deletions
diff --git a/src/server/database/Database/Implementation/CharacterDatabase.cpp b/src/server/database/Database/Implementation/CharacterDatabase.cpp index 6494f92b522..cc5b3771e1e 100644 --- a/src/server/database/Database/Implementation/CharacterDatabase.cpp +++ b/src/server/database/Database/Implementation/CharacterDatabase.cpp @@ -127,8 +127,8 @@ void CharacterDatabaseConnection::DoPrepareStatements() PrepareStatement(CHAR_SEL_CHARACTER_ACTIONS_SPEC, "SELECT button, action, type FROM character_action WHERE guid = ? AND spec = ? ORDER BY button", CONNECTION_SYNCH); PrepareStatement(CHAR_SEL_MAILITEMS, "SELECT creatorGuid, giftCreatorGuid, count, duration, charges, flags, enchantments, randomPropertyId, durability, playedTime, text, item_guid, itemEntry, owner_guid FROM mail_items mi JOIN item_instance ii ON mi.item_guid = ii.guid WHERE mail_id = ?", CONNECTION_SYNCH); PrepareStatement(CHAR_SEL_AUCTION_ITEMS, "SELECT creatorGuid, giftCreatorGuid, count, duration, charges, flags, enchantments, randomPropertyId, durability, playedTime, text, itemguid, itemEntry FROM auctionhouse ah JOIN item_instance ii ON ah.itemguid = ii.guid", CONNECTION_SYNCH); - PrepareStatement(CHAR_SEL_AUCTIONS, "SELECT id, auctioneerguid, itemguid, itemEntry, count, itemowner, buyoutprice, time, buyguid, lastbid, startbid, deposit FROM auctionhouse ah INNER JOIN item_instance ii ON ii.guid = ah.itemguid", CONNECTION_SYNCH); - PrepareStatement(CHAR_INS_AUCTION, "INSERT INTO auctionhouse (id, auctioneerguid, itemguid, itemowner, buyoutprice, time, buyguid, lastbid, startbid, deposit) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", CONNECTION_ASYNC); + PrepareStatement(CHAR_SEL_AUCTIONS, "SELECT id, houseid, itemguid, itemEntry, count, itemowner, buyoutprice, time, buyguid, lastbid, startbid, deposit FROM auctionhouse ah INNER JOIN item_instance ii ON ii.guid = ah.itemguid", CONNECTION_SYNCH); + PrepareStatement(CHAR_INS_AUCTION, "INSERT INTO auctionhouse (id, houseid, itemguid, itemowner, buyoutprice, time, buyguid, lastbid, startbid, deposit) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", CONNECTION_ASYNC); PrepareStatement(CHAR_DEL_AUCTION, "DELETE FROM auctionhouse WHERE id = ?", CONNECTION_ASYNC); PrepareStatement(CHAR_UPD_AUCTION_BID, "UPDATE auctionhouse SET buyguid = ?, lastbid = ? WHERE id = ?", CONNECTION_ASYNC); PrepareStatement(CHAR_INS_MAIL, "INSERT INTO mail(id, messageType, stationery, mailTemplateId, sender, receiver, subject, body, has_items, expire_time, deliver_time, money, cod, checked) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", CONNECTION_ASYNC); diff --git a/src/server/game/AuctionHouse/AuctionHouseMgr.cpp b/src/server/game/AuctionHouse/AuctionHouseMgr.cpp index 265eb6f38ba..96a4fd42f5e 100644 --- a/src/server/game/AuctionHouse/AuctionHouseMgr.cpp +++ b/src/server/game/AuctionHouse/AuctionHouseMgr.cpp @@ -61,6 +61,19 @@ AuctionHouseObject* AuctionHouseMgr::GetAuctionsMap(uint32 factionTemplateId) return &mNeutralAuctions; } +AuctionHouseObject* AuctionHouseMgr::GetAuctionsMapByHouseId(uint8 auctionHouseId) +{ + if (sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION)) + return &mNeutralAuctions; + + switch(auctionHouseId) + { + case AUCTIONHOUSE_ALLIANCE : return &mAllianceAuctions; + case AUCTIONHOUSE_HORDE : return &mHordeAuctions; + default : return &mNeutralAuctions; + } +} + uint32 AuctionHouseMgr::GetAuctionDeposit(AuctionHouseEntry const* entry, uint32 time, Item* pItem, uint32 count) { uint32 MSV = pItem->GetTemplate()->SellPrice; @@ -342,7 +355,7 @@ void AuctionHouseMgr::LoadAuctions() continue; } - GetAuctionsMap(aItem->factionTemplateId)->AddAuction(aItem); + GetAuctionsMapByHouseId(aItem->houseId)->AddAuction(aItem); ++count; } while (result->NextRow()); @@ -385,44 +398,32 @@ void AuctionHouseMgr::Update() AuctionHouseEntry const* AuctionHouseMgr::GetAuctionHouseEntry(uint32 factionTemplateId) { - uint32 houseid = 7; // goblin auction house + uint32 houseid = AUCTIONHOUSE_NEUTRAL; // goblin auction house if (!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION)) { // FIXME: found way for proper auctionhouse selection by another way // AuctionHouse.dbc have faction field with _player_ factions associated with auction house races. // but no easy way convert creature faction to player race faction for specific city - switch (factionTemplateId) - { - case 12: houseid = 1; break; // human - case 29: houseid = 6; break; // orc, and generic for horde - case 55: houseid = 2; break; // dwarf, and generic for alliance - case 68: houseid = 4; break; // undead - case 80: houseid = 3; break; // n-elf - case 104: houseid = 5; break; // trolls - case 120: houseid = 7; break; // booty bay, neutral - case 474: houseid = 7; break; // gadgetzan, neutral - case 855: houseid = 7; break; // everlook, neutral - case 1604: houseid = 6; break; // b-elfs, - default: // for unknown case - { - FactionTemplateEntry const* u_entry = sFactionTemplateStore.LookupEntry(factionTemplateId); - if (!u_entry) - houseid = 7; // goblin auction house - else if (u_entry->ourMask & FACTION_MASK_ALLIANCE) - houseid = 1; // human auction house - else if (u_entry->ourMask & FACTION_MASK_HORDE) - houseid = 6; // orc auction house - else - houseid = 7; // goblin auction house - break; - } - } + FactionTemplateEntry const* u_entry = sFactionTemplateStore.LookupEntry(factionTemplateId); + if (!u_entry) + houseid = AUCTIONHOUSE_NEUTRAL; // goblin auction house + else if (u_entry->ourMask & FACTION_MASK_ALLIANCE) + houseid = AUCTIONHOUSE_ALLIANCE; // human auction house + else if (u_entry->ourMask & FACTION_MASK_HORDE) + houseid = AUCTIONHOUSE_HORDE; // orc auction house + else + houseid = AUCTIONHOUSE_NEUTRAL; // goblin auction house } return sAuctionHouseStore.LookupEntry(houseid); } +AuctionHouseEntry const* AuctionHouseMgr::GetAuctionHouseEntryFromHouse(uint8 houseId) +{ + return (sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION)) ? sAuctionHouseStore.LookupEntry(AUCTIONHOUSE_NEUTRAL) : sAuctionHouseStore.LookupEntry(houseId); +} + void AuctionHouseObject::AddAuction(AuctionEntry* auction) { ASSERT(auction); @@ -687,7 +688,7 @@ void AuctionEntry::SaveToDB(SQLTransaction& trans) const { PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_AUCTION); stmt->setUInt32(0, Id); - stmt->setUInt32(1, auctioneer); + stmt->setUInt8(1, houseId); stmt->setUInt32(2, itemGUIDLow); stmt->setUInt32(3, owner); stmt->setUInt32(4, buyout); @@ -702,7 +703,7 @@ void AuctionEntry::SaveToDB(SQLTransaction& trans) const bool AuctionEntry::LoadFromDB(Field* fields) { Id = fields[0].GetUInt32(); - auctioneer = fields[1].GetUInt32(); + houseId = fields[1].GetUInt8(); itemGUIDLow = fields[2].GetUInt32(); itemEntry = fields[3].GetUInt32(); itemCount = fields[4].GetUInt32(); @@ -714,25 +715,10 @@ bool AuctionEntry::LoadFromDB(Field* fields) startbid = fields[10].GetUInt32(); deposit = fields[11].GetUInt32(); - CreatureData const* auctioneerData = sObjectMgr->GetCreatureData(auctioneer); - if (!auctioneerData) - { - TC_LOG_ERROR("misc", "Auction %u has not a existing auctioneer (GUID : %u)", Id, auctioneer); - return false; - } - - CreatureTemplate const* auctioneerInfo = sObjectMgr->GetCreatureTemplate(auctioneerData->id); - if (!auctioneerInfo) - { - TC_LOG_ERROR("misc", "Auction %u has not a existing auctioneer (GUID : %u Entry: %u)", Id, auctioneer, auctioneerData->id); - return false; - } - - factionTemplateId = auctioneerInfo->faction; - auctionHouseEntry = AuctionHouseMgr::GetAuctionHouseEntry(factionTemplateId); + auctionHouseEntry = AuctionHouseMgr::GetAuctionHouseEntryFromHouse(houseId); if (!auctionHouseEntry) { - TC_LOG_ERROR("misc", "Auction %u has auctioneer (GUID : %u Entry: %u) with wrong faction %u", Id, auctioneer, auctioneerData->id, factionTemplateId); + TC_LOG_ERROR("misc", "Auction %u has invalid house id %u", Id, houseId); return false; } diff --git a/src/server/game/AuctionHouse/AuctionHouseMgr.h b/src/server/game/AuctionHouse/AuctionHouseMgr.h index d67c8143996..f05d8583329 100644 --- a/src/server/game/AuctionHouse/AuctionHouseMgr.h +++ b/src/server/game/AuctionHouse/AuctionHouseMgr.h @@ -61,10 +61,17 @@ enum MailAuctionAnswers AUCTION_SALE_PENDING = 6 }; +enum AuctionHouses +{ + AUCTIONHOUSE_ALLIANCE = 2, + AUCTIONHOUSE_HORDE = 6, + AUCTIONHOUSE_NEUTRAL = 7 +}; + struct AuctionEntry { uint32 Id; - uint32 auctioneer; // creature low guid + uint8 houseId; uint32 itemGUIDLow; uint32 itemEntry; uint32 itemCount; @@ -76,11 +83,9 @@ struct AuctionEntry uint32 bidder; uint32 deposit; //deposit can be calculated only when creating auction AuctionHouseEntry const* auctionHouseEntry; // in AuctionHouse.dbc - uint32 factionTemplateId; // helpers - uint32 GetHouseId() const { return auctionHouseEntry->houseId; } - uint32 GetHouseFaction() const { return auctionHouseEntry->faction; } + uint8 GetHouseId() const { return houseId; } uint32 GetAuctionCut() const; uint32 GetAuctionOutBid() const; bool BuildAuctionInfo(WorldPacket & data) const; @@ -148,6 +153,7 @@ class AuctionHouseMgr typedef std::unordered_map<uint32, Item*> ItemMap; AuctionHouseObject* GetAuctionsMap(uint32 factionTemplateId); + AuctionHouseObject* GetAuctionsMapByHouseId(uint8 auctionHouseId); AuctionHouseObject* GetBidsMap(uint32 factionTemplateId); Item* GetAItem(uint32 id) @@ -169,7 +175,7 @@ class AuctionHouseMgr static uint32 GetAuctionDeposit(AuctionHouseEntry const* entry, uint32 time, Item* pItem, uint32 count); static AuctionHouseEntry const* GetAuctionHouseEntry(uint32 factionTemplateId); - + static AuctionHouseEntry const* GetAuctionHouseEntryFromHouse(uint8 houseId); public: //load first auction items, because of check if item exists, when loading diff --git a/src/server/game/AuctionHouseBot/AuctionHouseBotSeller.cpp b/src/server/game/AuctionHouseBot/AuctionHouseBotSeller.cpp index e6164b77005..22dc5bb0bd0 100644 --- a/src/server/game/AuctionHouseBot/AuctionHouseBotSeller.cpp +++ b/src/server/game/AuctionHouseBot/AuctionHouseBotSeller.cpp @@ -906,15 +906,17 @@ void AuctionBotSeller::AddNewAuctions(SellerConfiguration& config) items = sAuctionBotConfig->GetItemPerCycleNormal(); uint32 houseid = 0; - uint32 auctioneer = 0; switch (config.GetHouseType()) { case AUCTION_HOUSE_ALLIANCE: - houseid = 1; auctioneer = 79707; break; + houseid = AUCTIONHOUSE_ALLIANCE; + break; case AUCTION_HOUSE_HORDE: - houseid = 6; auctioneer = 4656; break; + houseid = AUCTIONHOUSE_HORDE; + break; default: - houseid = 7; auctioneer = 23442; break; + houseid = AUCTIONHOUSE_NEUTRAL; + break; } AuctionHouseEntry const* ahEntry = sAuctionHouseStore.LookupEntry(houseid); @@ -995,7 +997,7 @@ void AuctionBotSeller::AddNewAuctions(SellerConfiguration& config) auctionEntry->itemEntry = item->GetEntry(); auctionEntry->startbid = bidPrice; auctionEntry->buyout = buyoutPrice; - auctionEntry->auctioneer = auctioneer; + auctionEntry->houseId = houseid; auctionEntry->bidder = 0; auctionEntry->bid = 0; auctionEntry->deposit = sAuctionMgr->GetAuctionDeposit(ahEntry, etime, item, stackCount); diff --git a/src/server/game/Handlers/AuctionHouseHandler.cpp b/src/server/game/Handlers/AuctionHouseHandler.cpp index aa51b19a659..0293901c9e3 100644 --- a/src/server/game/Handlers/AuctionHouseHandler.cpp +++ b/src/server/game/Handlers/AuctionHouseHandler.cpp @@ -154,7 +154,6 @@ void WorldSession::HandleAuctionSellItem(WorldPacket& recvData) return; } - Creature* creature = GetPlayer()->GetNPCIfCanInteractWith(auctioneer, UNIT_NPC_FLAG_AUCTIONEER); if (!creature) { @@ -259,9 +258,26 @@ void WorldSession::HandleAuctionSellItem(WorldPacket& recvData) AuctionEntry* AH = new AuctionEntry(); if (sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION)) - AH->auctioneer = 23442; ///@TODO - HARDCODED DB GUID, BAD BAD BAD + AH->houseId = AUCTIONHOUSE_NEUTRAL; else - AH->auctioneer = auctioneer.GetCounter(); + { + CreatureData const* auctioneerData = sObjectMgr->GetCreatureData(creature->GetSpawnId()); + if (!auctioneerData) + { + TC_LOG_ERROR("misc", "Data for auctioneer not found (%s)", auctioneer.ToString().c_str()); + return; + } + + CreatureTemplate const* auctioneerInfo = sObjectMgr->GetCreatureTemplate(auctioneerData->id); + if (!auctioneerInfo) + { + TC_LOG_ERROR("misc", "Non existing auctioneer (%s)", auctioneer.ToString().c_str()); + return; + } + + const AuctionHouseEntry* AHEntry = sAuctionMgr->GetAuctionHouseEntry(auctioneerInfo->faction); + AH->houseId = AHEntry->houseId; + } // Required stack size of auction matches to current item stack size, just move item to auctionhouse if (itemsCount == 1 && item->GetCount() == count[0]) @@ -285,8 +301,8 @@ void WorldSession::HandleAuctionSellItem(WorldPacket& recvData) AH->deposit = deposit; AH->auctionHouseEntry = auctionHouseEntry; - TC_LOG_INFO("network", "CMSG_AUCTION_SELL_ITEM: Player %s (guid %d) is selling item %s entry %u (guid %d) to auctioneer %u with count %u with initial bid %u with buyout %u and with time %u (in sec) in auctionhouse %u", - _player->GetName().c_str(), _player->GetGUID().GetCounter(), item->GetTemplate()->Name1.c_str(), item->GetEntry(), item->GetGUID().GetCounter(), AH->auctioneer, item->GetCount(), bid, buyout, auctionTime, AH->GetHouseId()); + TC_LOG_INFO("network", "CMSG_AUCTION_SELL_ITEM: Player %s (guid %d) is selling item %s entry %u (guid %d) with count %u with initial bid %u with buyout %u and with time %u (in sec) in auctionhouse %u", + _player->GetName().c_str(), _player->GetGUID().GetCounter(), item->GetTemplate()->Name1.c_str(), item->GetEntry(), item->GetGUID().GetCounter(), item->GetCount(), bid, buyout, auctionTime, AH->GetHouseId()); sAuctionMgr->AddAItem(item); auctionHouse->AddAuction(AH); @@ -333,8 +349,8 @@ void WorldSession::HandleAuctionSellItem(WorldPacket& recvData) AH->deposit = deposit; AH->auctionHouseEntry = auctionHouseEntry; - TC_LOG_INFO("network", "CMSG_AUCTION_SELL_ITEM: Player %s (guid %d) is selling item %s entry %u (guid %d) to auctioneer %u with count %u with initial bid %u with buyout %u and with time %u (in sec) in auctionhouse %u", - _player->GetName().c_str(), _player->GetGUID().GetCounter(), newItem->GetTemplate()->Name1.c_str(), newItem->GetEntry(), newItem->GetGUID().GetCounter(), AH->auctioneer, newItem->GetCount(), bid, buyout, auctionTime, AH->GetHouseId()); + TC_LOG_INFO("network", "CMSG_AUCTION_SELL_ITEM: Player %s (guid %d) is selling item %s entry %u (guid %d) with count %u with initial bid %u with buyout %u and with time %u (in sec) in auctionhouse %u", + _player->GetName().c_str(), _player->GetGUID().GetCounter(), newItem->GetTemplate()->Name1.c_str(), newItem->GetEntry(), newItem->GetGUID().GetCounter(), newItem->GetCount(), bid, buyout, auctionTime, AH->GetHouseId()); sAuctionMgr->AddAItem(newItem); auctionHouse->AddAuction(AH); |