From 7b47d509e3a78a04b58f1b272f4b780c5c5b5ad3 Mon Sep 17 00:00:00 2001 From: Paradox Date: Fri, 6 Mar 2009 17:47:11 -0600 Subject: New AHBot plus AuctionHouse changes --HG-- branch : trunk --- src/game/AuctionHouse.cpp | 759 ------------------------------------- src/game/AuctionHouseBot.cpp | 631 +++++++++++++++++++++--------- src/game/AuctionHouseBot.h | 375 ++++++++++++++---- src/game/AuctionHouseHandler.cpp | 640 +++++++++++++++++++++++++++++++ src/game/AuctionHouseMgr.cpp | 685 +++++++++++++++++++++++++++++++++ src/game/AuctionHouseMgr.h | 170 +++++++++ src/game/AuctionHouseObject.h | 107 ------ src/game/CMakeLists.txt | 5 +- src/game/Chat.cpp | 1 + src/game/Chat.h | 1 + src/game/Level3.cpp | 191 ++++++++-- src/game/Makefile.am | 5 +- src/game/ObjectMgr.cpp | 361 +----------------- src/game/ObjectMgr.h | 45 --- src/game/PlayerDump.h | 22 -- src/game/World.cpp | 62 +-- src/game/WorldSession.h | 1 - src/shared/Database/DBCStores.cpp | 4 +- src/shared/Database/DBCStores.h | 1 + src/shared/Database/DBCStructure.h | 10 + src/shared/Database/DBCfmt.cpp | 1 + 21 files changed, 2424 insertions(+), 1653 deletions(-) delete mode 100644 src/game/AuctionHouse.cpp create mode 100644 src/game/AuctionHouseHandler.cpp create mode 100644 src/game/AuctionHouseMgr.cpp create mode 100644 src/game/AuctionHouseMgr.h delete mode 100644 src/game/AuctionHouseObject.h (limited to 'src') diff --git a/src/game/AuctionHouse.cpp b/src/game/AuctionHouse.cpp deleted file mode 100644 index 9fc448cf20b..00000000000 --- a/src/game/AuctionHouse.cpp +++ /dev/null @@ -1,759 +0,0 @@ -/* - * Copyright (C) 2005-2008 MaNGOS - * - * Copyright (C) 2008 Trinity - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "WorldPacket.h" -#include "WorldSession.h" -#include "Opcodes.h" -#include "Log.h" -#include "World.h" -#include "ObjectMgr.h" -#include "Player.h" -#include "UpdateMask.h" -#include "AuctionHouseObject.h" -#include "Util.h" -#include "AuctionHouseBot.h" - -//please DO NOT use iterator++, because it is slower than ++iterator!!! -//post-incrementation is always slower than pre-incrementation ! - -//void called when player click on auctioneer npc -void WorldSession::HandleAuctionHelloOpcode( WorldPacket & recv_data ) -{ - CHECK_PACKET_SIZE(recv_data,8); - - uint64 guid; //NPC guid - recv_data >> guid; - - Creature *unit = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid,UNIT_NPC_FLAG_AUCTIONEER); - if (!unit) - { - sLog.outDebug( "WORLD: HandleAuctionHelloOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) ); - return; - } - - // remove fake death - if(GetPlayer()->hasUnitState(UNIT_STAT_DIED)) - GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); - - SendAuctionHello(guid, unit); -} - -static uint8 AuctioneerFactionToLocation(uint32 faction) -{ - if(sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION)) - return 7; // neutral - - FactionTemplateEntry const* u_entry = sFactionTemplateStore.LookupEntry(faction); - if(!u_entry) - return 7; // neutral - - if(u_entry->ourMask & FACTION_MASK_ALLIANCE) - return 2; - else if(u_entry->ourMask & FACTION_MASK_HORDE) - return 6; - else - return 7; -} - -//this void causes that auction window is opened -void WorldSession::SendAuctionHello( uint64 guid, Creature* unit ) -{ - WorldPacket data( MSG_AUCTION_HELLO, 12 ); - data << (uint64) guid; - data << (uint32) AuctioneerFactionToLocation(unit->getFaction()); - SendPacket( &data ); -} - -//this function inserts to WorldPacket auction's data -bool WorldSession::SendAuctionInfo(WorldPacket & data, AuctionEntry* auction) -{ - Item *pItem = objmgr.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)? objmgr.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 ) -{ - WorldPacket data( SMSG_AUCTION_COMMAND_RESULT, 16 ); - data << auctionId; - data << Action; - data << ErrorCode; - if ( !ErrorCode && Action ) - data << bidError; //when bid, then send 0, once... - SendPacket(&data); -} - -//this function sends notification, if bidder is online -void WorldSession::SendAuctionBidderNotification( uint32 location, uint32 auctionId, uint64 bidder, uint32 bidSum, uint32 diff, uint32 item_template) -{ - WorldPacket data(SMSG_AUCTION_BIDDER_NOTIFICATION, (8*4)); - data << location; - data << auctionId; - data << (uint64) bidder; - data << bidSum; - data << (uint32) diff; - data << item_template; - data << (uint32) 0; - SendPacket(&data); -} - -//this void causes on client to display: "Your auction sold" -void WorldSession::SendAuctionOwnerNotification( AuctionEntry* auction) -{ - WorldPacket data(SMSG_AUCTION_OWNER_NOTIFICATION, (7*4)); - data << auction->Id; - data << auction->bid; - data << (uint32) 0; //unk - data << (uint32) 0; //unk - data << (uint32) 0; //unk - data << auction->item_template; - data << (uint32) 0; //unk - SendPacket(&data); -} - -//this function sends mail to old bidder -void WorldSession::SendAuctionOutbiddedMail(AuctionEntry *auction, uint32 newPrice) -{ - uint64 oldBidder_guid = MAKE_NEW_GUID(auction->bidder,0, HIGHGUID_PLAYER); - Player *oldBidder = objmgr.GetPlayer(oldBidder_guid); - - uint32 oldBidder_accId = 0; - if(!oldBidder) - oldBidder_accId = objmgr.GetPlayerAccountIdByGUID(oldBidder_guid); - - // old bidder exist - if(oldBidder || oldBidder_accId) - { - std::ostringstream msgAuctionOutbiddedSubject; - msgAuctionOutbiddedSubject << auction->item_template << ":0:" << AUCTION_OUTBIDDED; - - if (oldBidder && !_player) - oldBidder->GetSession()->SendAuctionBidderNotification( auction->location, auction->Id, AHBplayerGUID, newPrice, objmgr.GetAuctionOutBid(auction->bid), auction->item_template); - - if (oldBidder && _player) - oldBidder->GetSession()->SendAuctionBidderNotification( auction->location, auction->Id, _player->GetGUID(), newPrice, objmgr.GetAuctionOutBid(auction->bid), 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); - } -} - -//this function sends mail, when auction is canceled to old bidder -void WorldSession::SendAuctionCancelledToBidderMail( AuctionEntry* auction ) -{ - uint64 bidder_guid = MAKE_NEW_GUID(auction->bidder, 0, HIGHGUID_PLAYER); - Player *bidder = objmgr.GetPlayer(bidder_guid); - - uint32 bidder_accId = 0; - if(!bidder) - bidder_accId = objmgr.GetPlayerAccountIdByGUID(bidder_guid); - - // bidder exist - if(bidder || bidder_accId) - { - std::ostringstream msgAuctionCancelledSubject; - msgAuctionCancelledSubject << auction->item_template << ":0:" << AUCTION_CANCELLED_TO_BIDDER; - - WorldSession::SendMailTo(bidder, MAIL_AUCTION, MAIL_STATIONERY_AUCTION, auction->location, auction->bidder, msgAuctionCancelledSubject.str(), 0, NULL, auction->bid, 0, MAIL_CHECK_MASK_NONE); - } -} - -//this void creates new auction and adds auction to some auctionhouse -void WorldSession::HandleAuctionSellItem( WorldPacket & recv_data ) -{ - CHECK_PACKET_SIZE(recv_data,8+8+4+4+4); - - uint64 auctioneer, item; - uint32 etime, bid, buyout; - recv_data >> auctioneer >> item; - recv_data >> bid >> buyout >> etime; - Player *pl = GetPlayer(); - - if (!item || !bid || !etime) - return; //check for cheaters - - Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, auctioneer,UNIT_NPC_FLAG_AUCTIONEER); - if (!pCreature) - { - sLog.outDebug( "WORLD: HandleAuctionSellItem - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(auctioneer)) ); - return; - } - - // client send time in minutes, convert to common used sec time - etime *= MINUTE; - - // client understand only 3 auction time - switch(etime) - { - case 1*MIN_AUCTION_TIME: - case 2*MIN_AUCTION_TIME: - case 4*MIN_AUCTION_TIME: - break; - default: - return; - } - - // remove fake death - if(GetPlayer()->hasUnitState(UNIT_STAT_DIED)) - GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); - - Item *it = pl->GetItemByGuid( item ); - //do not allow to sell already auctioned items - if(objmgr.GetAItem(GUID_LOPART(item))) - { - sLog.outError("AuctionError, player %s is sending item id: %u, but item is already in another auction", pl->GetName(), GUID_LOPART(item)); - SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_INTERNAL_ERROR); - return; - } - // prevent sending bag with items (cheat: can be placed in bag after adding equiped empty bag to auction) - if(!it) - { - SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_ITEM_NOT_FOUND); - return; - } - - if(!it->CanBeTraded()) - { - SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_INTERNAL_ERROR); - return; - } - - if (it->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_CONJURED) || it->GetUInt32Value(ITEM_FIELD_DURATION)) - { - SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_INTERNAL_ERROR); - return; - } - - uint32 location = AuctioneerFactionToLocation(pCreature->getFaction()); - AuctionHouseObject * mAuctions; - mAuctions = objmgr.GetAuctionsMap( location ); - - //we have to take deposit : - uint32 deposit = objmgr.GetAuctionDeposit( location, etime, it ); - if ( pl->GetMoney() < deposit ) - { - SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_NOT_ENOUGHT_MONEY); - return; - } - - if( GetSecurity() > SEC_PLAYER && sWorld.getConfig(CONFIG_GM_LOG_TRADE) ) - { - sLog.outCommand(GetAccountId(),"GM %s (Account: %u) create auction: %s (Entry: %u Count: %u)", - GetPlayerName(),GetAccountId(),it->GetProto()->Name1,it->GetEntry(),it->GetCount()); - } - - pl->ModifyMoney( -int32(deposit) ); - - uint32 auction_time = uint32(etime * sWorld.getRate(RATE_AUCTION_TIME)); - - AuctionEntry *AH = new AuctionEntry; - AH->Id = objmgr.GenerateAuctionID(); - AH->auctioneer = GUID_LOPART(auctioneer); - AH->item_guidlow = GUID_LOPART(item); - AH->item_template = it->GetEntry(); - AH->owner = pl->GetGUIDLow(); - AH->startbid = bid; - AH->bidder = 0; - AH->bid = 0; - AH->buyout = buyout; - AH->time = time(NULL) + auction_time; - AH->deposit = deposit; - AH->location = location; - - sLog.outDetail("selling item %u to auctioneer %u with initial bid %u with buyout %u and with time %u (in sec) in location: %u", GUID_LOPART(item), GUID_LOPART(auctioneer), bid, buyout, auction_time, location); - mAuctions->AddAuction(AH); - - objmgr.AddAItem(it); - pl->MoveItemFromInventory( it->GetBagSlot(), it->GetSlot(), true); - - CharacterDatabase.BeginTransaction(); - it->DeleteFromInventoryDB(); - 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); - pl->SaveInventoryAndGoldToDB(); - CharacterDatabase.CommitTransaction(); - - SendAuctionCommandResult(AH->Id, AUCTION_SELL_ITEM, AUCTION_OK); -} - -//this function is called when client bids or buys out auction -void WorldSession::HandleAuctionPlaceBid( WorldPacket & recv_data ) -{ - CHECK_PACKET_SIZE(recv_data,8+4+4); - - uint64 auctioneer; - uint32 auctionId; - uint32 price; - recv_data >> auctioneer; - recv_data >> auctionId >> price; - - if (!auctionId || !price) - return; //check for cheaters - - Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, auctioneer,UNIT_NPC_FLAG_AUCTIONEER); - if (!pCreature) - { - sLog.outDebug( "WORLD: HandleAuctionPlaceBid - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(auctioneer)) ); - return; - } - - // remove fake death - if(GetPlayer()->hasUnitState(UNIT_STAT_DIED)) - GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); - - uint32 location = AuctioneerFactionToLocation(pCreature->getFaction()); - - AuctionHouseObject * mAuctions; - mAuctions = objmgr.GetAuctionsMap( location ); - - AuctionEntry *auction = mAuctions->GetAuction(auctionId); - Player *pl = GetPlayer(); - - if( !auction || auction->owner == pl->GetGUIDLow() ) - { - //you cannot bid your own auction: - SendAuctionCommandResult( 0, AUCTION_PLACE_BID, CANNOT_BID_YOUR_AUCTION_ERROR ); - return; - } - - // impossible have online own another character (use this for speedup check in case online owner) - Player* auction_owner = objmgr.GetPlayer(MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER)); - if( !auction_owner && objmgr.GetPlayerAccountIdByGUID(MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER)) == pl->GetSession()->GetAccountId()) - { - //you cannot bid your another character auction: - SendAuctionCommandResult( 0, AUCTION_PLACE_BID, CANNOT_BID_YOUR_AUCTION_ERROR ); - return; - } - - // cheating - if(price <= auction->bid) - return; - - // price too low for next bid if not buyout - if ((price < auction->buyout || auction->buyout == 0) && - price < auction->bid + objmgr.GetAuctionOutBid(auction->bid)) - { - //auction has already higher bid, client tests it! - return; - } - - if (price > pl->GetMoney()) - { - //you don't have enought money!, client tests! - //SendAuctionCommandResult(auction->auctionId, AUCTION_PLACE_BID, ???); - return; - } - - if ((price < auction->buyout) || (auction->buyout == 0)) - { - if (auction->bidder > 0) - { - if ( auction->bidder == pl->GetGUIDLow() ) - { - pl->ModifyMoney( -int32(price - auction->bid)); - } - else - { - // mail to last bidder and return money - SendAuctionOutbiddedMail( auction , price ); - pl->ModifyMoney( -int32(price) ); - } - } - else - { - pl->ModifyMoney( -int32(price) ); - } - auction->bidder = pl->GetGUIDLow(); - auction->bid = price; - - // after this update we should save player's money ... - CharacterDatabase.PExecute("UPDATE auctionhouse SET buyguid = '%u',lastbid = '%u' WHERE id = '%u'", auction->bidder, auction->bid, auction->Id); - - SendAuctionCommandResult(auction->Id, AUCTION_PLACE_BID, AUCTION_OK, 0 ); - } - else - { - //buyout: - if (pl->GetGUIDLow() == auction->bidder ) - { - pl->ModifyMoney(-int32(auction->buyout - auction->bid)); - } - else - { - pl->ModifyMoney(-int32(auction->buyout)); - if ( auction->bidder ) //buyout for bidded auction .. - { - SendAuctionOutbiddedMail( auction, auction->buyout ); - } - } - auction->bidder = pl->GetGUIDLow(); - auction->bid = auction->buyout; - - objmgr.SendAuctionSalePendingMail( auction ); - objmgr.SendAuctionSuccessfulMail( auction ); - objmgr.SendAuctionWonMail( auction ); - - SendAuctionCommandResult(auction->Id, AUCTION_PLACE_BID, AUCTION_OK); - - objmgr.RemoveAItem(auction->item_guidlow); - mAuctions->RemoveAuction(auction->Id); - CharacterDatabase.PExecute("DELETE FROM auctionhouse WHERE id = '%u'",auction->Id); - - delete auction; - } - CharacterDatabase.BeginTransaction(); - pl->SaveInventoryAndGoldToDB(); - CharacterDatabase.CommitTransaction(); -} - -//this void is called when auction_owner cancels his auction -void WorldSession::HandleAuctionRemoveItem( WorldPacket & recv_data ) -{ - CHECK_PACKET_SIZE(recv_data,8+4); - - uint64 auctioneer; - uint32 auctionId; - recv_data >> auctioneer; - recv_data >> auctionId; - //sLog.outDebug( "Cancel AUCTION AuctionID: %u", auctionId); - - Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, auctioneer,UNIT_NPC_FLAG_AUCTIONEER); - if (!pCreature) - { - sLog.outDebug( "WORLD: HandleAuctionRemoveItem - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(auctioneer)) ); - return; - } - - // remove fake death - if(GetPlayer()->hasUnitState(UNIT_STAT_DIED)) - GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); - - uint32 location = AuctioneerFactionToLocation(pCreature->getFaction()); - - AuctionHouseObject * mAuctions; - mAuctions = objmgr.GetAuctionsMap( location ); - - AuctionEntry *auction = mAuctions->GetAuction(auctionId); - Player *pl = GetPlayer(); - - if (auction && auction->owner == pl->GetGUIDLow()) - { - Item *pItem = objmgr.GetAItem(auction->item_guidlow); - if (pItem) - { - if (auction->bidder > 0) // If we have a bidder, we have to send him the money he paid - { - uint32 auctionCut = objmgr.GetAuctionCut( auction->location, auction->bid); - 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.. - SendAuctionCancelledToBidderMail( auction ); - pl->ModifyMoney( -int32(auctionCut) ); - } - // Return the item by mail - std::ostringstream msgAuctionCanceledOwner; - msgAuctionCanceledOwner << auction->item_template << ":0:" << AUCTION_CANCELED; - - MailItemsInfo mi; - mi.AddItem(auction->item_guidlow, auction->item_template, pItem); - - // item will deleted or added to received mail list - WorldSession::SendMailTo(pl, MAIL_AUCTION, MAIL_STATIONERY_AUCTION, auction->location, pl->GetGUIDLow(), msgAuctionCanceledOwner.str(), 0, &mi, 0, 0, MAIL_CHECK_MASK_NONE); - } - else - { - sLog.outError("Auction id: %u has non-existed item (item guid : %u)!!!", auction->Id, auction->item_guidlow); - SendAuctionCommandResult( 0, AUCTION_CANCEL, AUCTION_INTERNAL_ERROR ); - return; - } - } - else - { - SendAuctionCommandResult( 0, AUCTION_CANCEL, AUCTION_INTERNAL_ERROR ); - //this code isn't possible ... maybe there should be assert - sLog.outError("CHEATER : %u, he tried to cancel auction (id: %u) of another player, or auction is NULL", pl->GetGUIDLow(), auctionId ); - return; - } - - //inform player, that auction is removed - SendAuctionCommandResult( auction->Id, AUCTION_CANCEL, AUCTION_OK ); - // Now remove the auction - CharacterDatabase.BeginTransaction(); - CharacterDatabase.PExecute("DELETE FROM auctionhouse WHERE id = '%u'",auction->Id); - pl->SaveInventoryAndGoldToDB(); - CharacterDatabase.CommitTransaction(); - objmgr.RemoveAItem( auction->item_guidlow ); - mAuctions->RemoveAuction( auction->Id ); - delete auction; -} - -//called when player lists his bids -void WorldSession::HandleAuctionListBidderItems( WorldPacket & recv_data ) -{ - CHECK_PACKET_SIZE(recv_data,8+4+4); - - uint64 guid; //NPC guid - uint32 listfrom; //page of auctions - uint32 outbiddedCount; //count of outbidded auctions - - recv_data >> guid; - recv_data >> listfrom; // not used in fact (this list not have page control in client) - recv_data >> outbiddedCount; - if (recv_data.size() != (16 + outbiddedCount * 4 )) - { - sLog.outError("Client sent bad opcode!!! with count: %u and size : %d (mustbe: %d", outbiddedCount, recv_data.size(),(16 + outbiddedCount * 4 )); - outbiddedCount = 0; - } - - Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid,UNIT_NPC_FLAG_AUCTIONEER); - if (!pCreature) - { - sLog.outDebug( "WORLD: HandleAuctionListBidderItems - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) ); - return; - } - - // remove fake death - if(GetPlayer()->hasUnitState(UNIT_STAT_DIED)) - GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); - - uint32 location = AuctioneerFactionToLocation(pCreature->getFaction()); - AuctionHouseObject* mAuctions = objmgr.GetAuctionsMap( location ); - - WorldPacket data( SMSG_AUCTION_BIDDER_LIST_RESULT, (4+4+4) ); - Player *pl = GetPlayer(); - data << (uint32) 0; //add 0 as count - uint32 count = 0; - uint32 totalcount = 0; - while ( outbiddedCount > 0) //add all data, which client requires - { - --outbiddedCount; - uint32 outbiddedAuctionId; - recv_data >> outbiddedAuctionId; - AuctionEntry * auction = mAuctions->GetAuction( outbiddedAuctionId ); - if ( auction && SendAuctionInfo(data, auction)) - { - ++totalcount; - ++count; - } - } - for (AuctionHouseObject::AuctionEntryMap::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; - } - } - data.put( 0, count ); // add count to placeholder - data << totalcount; - data << (uint32)300; //unk 2.3.0 - SendPacket(&data); -} - -//this void sends player info about his auctions -void WorldSession::HandleAuctionListOwnerItems( WorldPacket & recv_data ) -{ - CHECK_PACKET_SIZE(recv_data,8+4); - - uint32 listfrom; - uint64 guid; - - recv_data >> guid; - recv_data >> listfrom; // not used in fact (this list not have page control in client) - - Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid,UNIT_NPC_FLAG_AUCTIONEER); - if (!pCreature) - { - sLog.outDebug( "WORLD: HandleAuctionListOwnerItems - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) ); - return; - } - - // remove fake death - if(GetPlayer()->hasUnitState(UNIT_STAT_DIED)) - GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); - - uint32 location = AuctioneerFactionToLocation(pCreature->getFaction()); - - AuctionHouseObject* mAuctions = objmgr.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::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; - } - } - data.put(0, count); - data << (uint32) totalcount; - data << (uint32) 0; - SendPacket(&data); -} - -//this void is called when player clicks on search button -void WorldSession::HandleAuctionListItems( WorldPacket & recv_data ) -{ - CHECK_PACKET_SIZE(recv_data,8+4+1+1+1+4+4+4+4+1); - - std::string searchedname, name; - uint8 levelmin, levelmax, usable, location; - uint32 count, totalcount, listfrom, auctionSlotID, auctionMainCategory, auctionSubCategory, quality; - uint64 guid; - - recv_data >> guid; - recv_data >> listfrom; // start, used for page control listing by 50 elements - recv_data >> searchedname; - - // recheck with known string size - CHECK_PACKET_SIZE(recv_data,8+4+(searchedname.size()+1)+1+1+4+4+4+4+1); - - recv_data >> levelmin >> levelmax; - recv_data >> auctionSlotID >> auctionMainCategory >> auctionSubCategory; - recv_data >> quality >> usable; - - Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid,UNIT_NPC_FLAG_AUCTIONEER); - if (!pCreature) - { - sLog.outDebug( "WORLD: HandleAuctionListItems - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) ); - return; - } - - // remove fake death - if(GetPlayer()->hasUnitState(UNIT_STAT_DIED)) - GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); - - location = AuctioneerFactionToLocation(pCreature->getFaction()); - AuctionHouseObject * mAuctions; - mAuctions = objmgr.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); - - WorldPacket data( SMSG_AUCTION_LIST_RESULT, (4+4+4) ); - count = 0; - totalcount = 0; - data << (uint32) 0; - - // converting string that we try to find to lower case - std::wstring wsearchedname; - if(!Utf8toWStr(searchedname,wsearchedname)) - return; - - wstrToLower(wsearchedname); - - for (AuctionHouseObject::AuctionEntryMap::iterator itr = mAuctions->GetAuctionsBegin();itr != mAuctions->GetAuctionsEnd();++itr) - { - AuctionEntry *Aentry = itr->second; - Item *item = objmgr.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 ) ) - { - name = proto->Name1; - - // 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(0, count); - data << (uint32) totalcount; - data << (uint32) 300; // unk 2.3.0 const? - SendPacket(&data); -} - diff --git a/src/game/AuctionHouseBot.cpp b/src/game/AuctionHouseBot.cpp index bd3b51af4d2..cb3244ee456 100644 --- a/src/game/AuctionHouseBot.cpp +++ b/src/game/AuctionHouseBot.cpp @@ -4,6 +4,7 @@ #include "Database/DatabaseEnv.h" #include "Item.h" #include "Log.h" +#include "AuctionHouseMgr.h" #include "ObjectMgr.h" #include "Player.h" #include "World.h" @@ -18,14 +19,20 @@ static bool debug_Out = sConfig.GetIntDefault("AuctionHouseBot.DEBUG", 0); static vector npcItems; static vector lootItems; -static vector whiteTradeGoods; -static vector greenTradeGoods; -static vector blueTradeGoods; -static vector purpleTradeGoods; -static vector whiteItems; -static vector greenItems; -static vector blueItems; -static vector purpleItems; +static vector greyTradeGoodsBin; +static vector whiteTradeGoodsBin; +static vector greenTradeGoodsBin; +static vector blueTradeGoodsBin; +static vector purpleTradeGoodsBin; +static vector orangeTradeGoodsBin; +static vector yellowTradeGoodsBin; +static vector greyItemsBin; +static vector whiteItemsBin; +static vector greenItemsBin; +static vector blueItemsBin; +static vector purpleItemsBin; +static vector orangeItemsBin; +static vector yellowItemsBin; static bool AHBSeller = 0; static bool AHBBuyer = 0; @@ -62,11 +69,23 @@ static void addNewAuctions(Player *AHBplayer, AHBConfig *config) { if (!AHBSeller) return; - AuctionHouseObject* auctionHouse = objmgr.GetAuctionsMap(config->GetAHID()); + AuctionHouseEntry const* ahEntry = auctionmgr.GetAuctionHouseEntry(config->GetAHFID()); + AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap(config->GetAHFID()); uint32 items = 0; uint32 minItems = config->GetMinItems(); uint32 maxItems = config->GetMaxItems(); uint32 auctions = auctionHouse->Getcount(); + uint32 AuctioneerGUID = 0; + switch (config->GetAHID()){ + case 2: + AuctioneerGUID = 79707; //Human in stormwind. + case 6: + AuctioneerGUID = 4656; //orc in Orgrimmar + case 7: + AuctioneerGUID = 23442; //goblin in GZ + default: + AuctioneerGUID = 23442; //default to neutral 7 + } if (auctions >= minItems) return; @@ -77,28 +96,45 @@ static void addNewAuctions(Player *AHBplayer, AHBConfig *config) else items = (maxItems - auctions); } - uint32 wtgbin = config->GetPercents(AHB_WHITE_TG); - uint32 gtgbin = config->GetPercents(AHB_GREEN_TG); - uint32 btgbin = config->GetPercents(AHB_BLUE_TG); - uint32 ptgbin = config->GetPercents(AHB_PURPLE_TG); - uint32 wibin = config->GetPercents(AHB_WHITE_I); - uint32 gibin = config->GetPercents(AHB_GREEN_I); - uint32 bibin = config->GetPercents(AHB_BLUE_I); - uint32 pibin = config->GetPercents(AHB_PURPLE_I); - uint32 total = wtgbin + gtgbin + btgbin + ptgbin + wibin + gibin + bibin + pibin; - - uint32 pItems = 0; - uint32 bItems = 0; - uint32 gItems = 0; - uint32 wItems = 0; - uint32 pTGoods = 0; - uint32 bTGoods = 0; - uint32 gTGoods = 0; - uint32 wTGoods = 0; + uint32 greyTGcount = config->GetPercents(AHB_GREY_TG); + uint32 whiteTGcount = config->GetPercents(AHB_WHITE_TG); + uint32 greenTGcount = config->GetPercents(AHB_GREEN_TG); + uint32 blueTGcount = config->GetPercents(AHB_BLUE_TG); + uint32 purpleTGcount = config->GetPercents(AHB_PURPLE_TG); + uint32 orangeTGcount = config->GetPercents(AHB_ORANGE_TG); + uint32 yellowTGcount = config->GetPercents(AHB_YELLOW_TG); + uint32 greyIcount = config->GetPercents(AHB_GREY_I); + uint32 whiteIcount = config->GetPercents(AHB_WHITE_I); + uint32 greenIcount = config->GetPercents(AHB_GREEN_I); + uint32 blueIcount = config->GetPercents(AHB_BLUE_I); + uint32 purpleIcount = config->GetPercents(AHB_PURPLE_I); + uint32 orangeIcount = config->GetPercents(AHB_ORANGE_I); + uint32 yellowIcount = config->GetPercents(AHB_YELLOW_I); + uint32 total = greyTGcount + whiteTGcount + greenTGcount + blueTGcount + + purpleTGcount + orangeTGcount + yellowTGcount + + whiteIcount + greenIcount + blueIcount + purpleIcount + + orangeIcount + yellowIcount; + + uint32 greyTGoods = 0; + uint32 whiteTGoods = 0; + uint32 greenTGoods = 0; + uint32 blueTGoods = 0; + uint32 purpleTGoods = 0; + uint32 orangeTGoods = 0; + uint32 yellowTGoods = 0; + + uint32 greyItems = 0; + uint32 whiteItems = 0; + uint32 greenItems = 0; + uint32 blueItems = 0; + uint32 purpleItems = 0; + uint32 orangeItems = 0; + uint32 yellowItems = 0; + for (AuctionHouseObject::AuctionEntryMap::iterator itr = auctionHouse->GetAuctionsBegin();itr != auctionHouse->GetAuctionsEnd();++itr) { AuctionEntry *Aentry = itr->second; - Item *item = objmgr.GetAItem(Aentry->item_guidlow); + Item *item = auctionmgr.GetAItem(Aentry->item_guidlow); if( item ) { ItemPrototype const *prototype = item->GetProto(); @@ -108,37 +144,51 @@ static void addNewAuctions(Player *AHBplayer, AHBConfig *config) { case 0: if (prototype->Class == ITEM_CLASS_TRADE_GOODS) - wTGoods = wTGoods + 1; + ++greyTGoods; else - wItems = wItems + 1; + ++greyItems; break; case 1: if (prototype->Class == ITEM_CLASS_TRADE_GOODS) - wTGoods = wTGoods + 1; + ++whiteTGoods; else - wItems = wItems + 1; + ++whiteItems; break; case 2: if (prototype->Class == ITEM_CLASS_TRADE_GOODS) - gTGoods = gTGoods + 1; + ++greenTGoods; else - gItems = gItems + 1; + ++greenItems; break; case 3: if (prototype->Class == ITEM_CLASS_TRADE_GOODS) - bTGoods = bTGoods + 1; + ++blueTGoods; else - bItems = bItems + 1; + ++blueItems; break; case 4: if (prototype->Class == ITEM_CLASS_TRADE_GOODS) - pTGoods = pTGoods + 1; + ++purpleTGoods; + else + ++purpleItems; + break; + + case 5: + if (prototype->Class == ITEM_CLASS_TRADE_GOODS) + ++orangeTGoods; else - pItems = pItems + 1; + ++orangeItems; + break; + + case 6: + if (prototype->Class == ITEM_CLASS_TRADE_GOODS) + ++yellowTGoods; + else + ++yellowItems; break; } } @@ -150,78 +200,132 @@ static void addNewAuctions(Player *AHBplayer, AHBConfig *config) uint32 itemID = 0; while (itemID == 0) { - uint32 choice = urand(1, 8); + uint32 choice = urand(0, 13); switch (choice) { + case 0: + { + if ((greyItemsBin.size() > 0) && (greyItems < greyIcount)) + { + itemID = greyItemsBin[urand(0, greyItemsBin.size() - 1)]; + ++greyItems; + break; + } + } case 1: { - if ((purpleItems.size() > 0) && (pItems < pibin)) + if ((whiteItemsBin.size() > 0) && (whiteItems < whiteIcount)) { - itemID = purpleItems[urand(0, purpleItems.size() - 1)]; - pItems = pItems + 1; - break; + itemID = whiteItemsBin[urand(0, whiteItemsBin.size() - 1)]; + ++whiteItems; + break; } } case 2: { - if ((blueItems.size() > 0) && (bItems < bibin)) + if ((greenItemsBin.size() > 0) && (greenItems < greenIcount)) { - itemID = blueItems[urand(0, blueItems.size() - 1)]; - bItems = bItems + 1; + itemID = greenItemsBin[urand(0, greenItemsBin.size() - 1)]; + ++greenItems; break; } } case 3: { - if ((greenItems.size() > 0) && (gItems < gibin)) + if ((blueItemsBin.size() > 0) && (blueItems < blueIcount)) { - itemID = greenItems[urand(0, greenItems.size() - 1)]; - gItems = gItems + 1; + itemID = blueItemsBin[urand(0, blueItemsBin.size() - 1)]; + ++blueItems; break; } } case 4: { - if ((whiteItems.size() > 0) && (wItems < wibin)) + if ((purpleItemsBin.size() > 0) && (purpleItems < purpleIcount)) { - itemID = whiteItems[urand(0, whiteItems.size() - 1)]; - wItems = wItems + 1; - break; + itemID = purpleItemsBin[urand(0, purpleItemsBin.size() - 1)]; + ++purpleItems; + break; } } case 5: { - if ((purpleTradeGoods.size() > 0) && (pTGoods < ptgbin)) + if ((orangeItemsBin.size() > 0) && (orangeItems < orangeIcount)) { - itemID = purpleTradeGoods[urand(0, purpleTradeGoods.size() - 1)]; - pTGoods = pTGoods + 1; - break; + itemID = orangeItemsBin[urand(0, orangeItemsBin.size() - 1)]; + ++orangeItems; + break; } } case 6: { - if ((blueTradeGoods.size() > 0) && (bTGoods < btgbin)) + if ((yellowItemsBin.size() > 0) && (yellowItems < yellowIcount)) { - itemID = blueTradeGoods[urand(0, blueTradeGoods.size() - 1)]; - bTGoods = bTGoods + 1; - break; + itemID = yellowItemsBin[urand(0, yellowItemsBin.size() - 1)]; + ++yellowItems; + break; } } case 7: { - if ((greenTradeGoods.size() > 0) && (gTGoods < gtgbin)) + if ((greyTradeGoodsBin.size() > 0) && (greyTGoods < greyTGcount)) { - itemID = greenTradeGoods[urand(0, greenTradeGoods.size() - 1)]; - gTGoods = gTGoods + 1; + itemID = whiteTradeGoodsBin[urand(0, whiteTradeGoodsBin.size() - 1)]; + ++greyTGoods; break; } } case 8: { - if ((whiteTradeGoods.size() > 0) && (wTGoods < wtgbin)) + if ((whiteTradeGoodsBin.size() > 0) && (whiteTGoods < whiteTGcount)) { - itemID = whiteTradeGoods[urand(0, whiteTradeGoods.size() - 1)]; - wTGoods = wTGoods + 1; + itemID = whiteTradeGoodsBin[urand(0, whiteTradeGoodsBin.size() - 1)]; + ++whiteTGoods; + break; + } + } + case 9: + { + if ((greenTradeGoodsBin.size() > 0) && (greenTGoods < greenTGcount)) + { + itemID = greenTradeGoodsBin[urand(0, greenTradeGoodsBin.size() - 1)]; + ++greenTGoods; + break; + } + } + case 10: + { + if ((blueTradeGoodsBin.size() > 0) && (blueTGoods < blueTGcount)) + { + itemID = blueTradeGoodsBin[urand(0, blueTradeGoodsBin.size() - 1)]; + ++blueTGoods; + break; + } + } + case 11: + { + if ((purpleTradeGoodsBin.size() > 0) && (purpleTGoods < purpleTGcount)) + { + itemID = purpleTradeGoodsBin[urand(0, purpleTradeGoodsBin.size() - 1)]; + ++purpleTGoods; + break; + } + } + case 12: + { + if ((orangeTradeGoodsBin.size() > 0) && (orangeTGoods < orangeTGcount)) + { + itemID = orangeTradeGoodsBin[urand(0, orangeTradeGoodsBin.size() - 1)]; + ++orangeTGoods; + break; + } + } + case 13: + { + if ((yellowTradeGoodsBin.size() > 0) && (yellowTGoods < yellowTGcount)) + { + itemID = yellowTradeGoodsBin[urand(0, yellowTradeGoodsBin.size() - 1)]; + ++yellowTGoods; break; } } @@ -270,6 +374,17 @@ static void addNewAuctions(Player *AHBplayer, AHBConfig *config) switch (prototype->Quality) { + case 0: + if (config->GetMaxStack(AHB_GREY) != 0) + { + stackCount = urand(1, minValue(item->GetMaxStackCount(), config->GetMaxStack(AHB_GREY))); + } + buyoutPrice *= urand(config->GetMinPrice(AHB_GREY), config->GetMaxPrice(AHB_GREY)) * stackCount; + buyoutPrice /= 100; + bidPrice = buyoutPrice * urand(config->GetMinBidPrice(AHB_GREY), config->GetMaxBidPrice(AHB_GREY)); + bidPrice /= 100; + break; + case 1: if (config->GetMaxStack(AHB_WHITE) != 0) { @@ -313,13 +428,33 @@ static void addNewAuctions(Player *AHBplayer, AHBConfig *config) bidPrice = buyoutPrice * urand(config->GetMinBidPrice(AHB_PURPLE), config->GetMaxBidPrice(AHB_PURPLE)); bidPrice /= 100; break; + case 5: + if (config->GetMaxStack(AHB_ORANGE) != 0) + { + stackCount = urand(1, minValue(item->GetMaxStackCount(), config->GetMaxStack(AHB_ORANGE))); + } + buyoutPrice *= urand(config->GetMinPrice(AHB_ORANGE), config->GetMaxPrice(AHB_ORANGE)) * stackCount; + buyoutPrice /= 100; + bidPrice = buyoutPrice * urand(config->GetMinBidPrice(AHB_ORANGE), config->GetMaxBidPrice(AHB_ORANGE)); + bidPrice /= 100; + break; + case 6: + if (config->GetMaxStack(AHB_YELLOW) != 0) + { + stackCount = urand(1, minValue(item->GetMaxStackCount(), config->GetMaxStack(AHB_YELLOW))); + } + buyoutPrice *= urand(config->GetMinPrice(AHB_YELLOW), config->GetMaxPrice(AHB_YELLOW)) * stackCount; + buyoutPrice /= 100; + bidPrice = buyoutPrice * urand(config->GetMinBidPrice(AHB_YELLOW), config->GetMaxBidPrice(AHB_YELLOW)); + bidPrice /= 100; + break; } item->SetCount(stackCount); AuctionEntry* auctionEntry = new AuctionEntry; auctionEntry->Id = objmgr.GenerateAuctionID(); - auctionEntry->auctioneer = 0; + auctionEntry->auctioneer = AuctioneerGUID; auctionEntry->item_guidlow = item->GetGUIDLow(); auctionEntry->item_template = item->GetEntry(); auctionEntry->owner = AHBplayer->GetGUIDLow(); @@ -328,31 +463,13 @@ static void addNewAuctions(Player *AHBplayer, AHBConfig *config) auctionEntry->bidder = 0; auctionEntry->bid = 0; auctionEntry->deposit = 0; - auctionEntry->location = config->GetAHID(); - auctionEntry->time = (time_t) (urand(config->GetMinTime(), config->GetMaxTime()) * 60 * 60 + time(NULL)); + auctionEntry->expire_time = (time_t) (urand(config->GetMinTime(), config->GetMaxTime()) * 60 * 60 + time(NULL)); + auctionEntry->auctionHouseEntry = ahEntry; item->SaveToDB(); item->RemoveFromUpdateQueueOf(AHBplayer); - objmgr.AddAItem(item); + auctionmgr.AddAItem(item); auctionHouse->AddAuction(auctionEntry); - - 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')", - auctionEntry->Id, - auctionEntry->auctioneer, - auctionEntry->item_guidlow, - auctionEntry->item_template, - auctionEntry->owner, - auctionEntry->buyout, - (uint64) auctionEntry->time, - auctionEntry->bidder, - auctionEntry->bid, - auctionEntry->startbid, - auctionEntry->deposit, - auctionEntry->location); + auctionEntry->SaveToDB(); } } @@ -362,7 +479,7 @@ static void addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *config, World return; // Fetches content of selected AH - AuctionHouseObject* auctionHouse = objmgr.GetAuctionsMap(config->GetAHID()); + AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap(config->GetAHFID()); AuctionHouseObject::AuctionEntryMap::iterator itr; itr = auctionHouse->GetAuctionsBegin(); @@ -395,11 +512,11 @@ static void addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *config, World // Choose random auction from possible auctions uint32 auctionID = possibleBids[urand(0, possibleBids.size() - 1)]; - // from auctionhouse.cpp, creates auction pointer & player pointer + // from auctionhousehandler.cpp, creates auction pointer & player pointer AuctionEntry* auction = auctionHouse->GetAuction(auctionID); // get exact item information - Item *pItem = objmgr.GetAItem(auction->item_guidlow); + Item *pItem = auctionmgr.GetAItem(auction->item_guidlow); if (!pItem) { sLog.outError("Item doesn't exists, perhaps bought already?"); @@ -410,16 +527,14 @@ static void addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *config, World ItemPrototype const* prototype = objmgr.GetItemPrototype(auction->item_template); // check which price we have to use, startbid or if it is bidded already - if(debug_Out) - {sLog.outError("Auction Number: %u", auction->Id);} - if(debug_Out) - {sLog.outError("Item Template: %u", auction->item_template);} - if(debug_Out) - {sLog.outError("Buy Price: %u", prototype->BuyPrice);} - if(debug_Out) - {sLog.outError("Sell Price: %u", prototype->SellPrice);} - if(debug_Out) - {sLog.outError("Quality: %u", prototype->Quality);} + if(debug_Out) + { + sLog.outError("Auction Number: %u", auction->Id); + sLog.outError("Item Template: %u", auction->item_template); + sLog.outError("Buy Price: %u", prototype->BuyPrice); + sLog.outError("Sell Price: %u", prototype->SellPrice); + sLog.outError("Quality: %u", prototype->Quality); + } uint32 currentprice; if(auction->bid) { @@ -480,6 +595,16 @@ static void addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *config, World { bidMax = prototype->SellPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_PURPLE); } + case 5: + if(currentprice < prototype->SellPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_ORANGE)) + { + bidMax = prototype->SellPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_ORANGE); + } + case 6: + if(currentprice < prototype->SellPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_YELLOW)) + { + bidMax = prototype->SellPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_YELLOW); + } break; default: // quality is something it shouldn't be, let's get out of here @@ -521,6 +646,16 @@ static void addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *config, World { bidMax = prototype->BuyPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_PURPLE); } + case 5: + if(currentprice < prototype->BuyPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_ORANGE)) + { + bidMax = prototype->BuyPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_ORANGE); + } + case 6: + if(currentprice < prototype->BuyPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_YELLOW)) + { + bidMax = prototype->BuyPrice * pItem->GetCount() * config->GetBuyerPrice(AHB_YELLOW); + } break; default: // quality is something it shouldn't be, let's get out of here @@ -564,9 +699,9 @@ static void addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *config, World {sLog.outError("bidprice: %u", bidprice);} // Check our bid is high enough to be valid. If not, correct it to minimum. - if((currentprice + objmgr.GetAuctionOutBid(currentprice)) > bidprice) + if((currentprice + auction->GetAuctionOutBid()) > bidprice) { - bidprice = currentprice + objmgr.GetAuctionOutBid(currentprice); + bidprice = currentprice + auction->GetAuctionOutBid(); if(debug_Out) {sLog.outError("bidprice(>): %u", bidprice);} } @@ -614,15 +749,15 @@ static void addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *config, World auction->bid = auction->buyout; // Send mails to buyer & seller - objmgr.SendAuctionSuccessfulMail( auction ); - objmgr.SendAuctionWonMail( auction ); + auctionmgr.SendAuctionSuccessfulMail( auction ); + auctionmgr.SendAuctionWonMail( auction ); // Remove item from auctionhouse - objmgr.RemoveAItem(auction->item_guidlow); + auctionmgr.RemoveAItem(auction->item_guidlow); // Remove auction auctionHouse->RemoveAuction(auction->Id); // Remove from database - CharacterDatabase.PExecute("DELETE FROM auctionhouse WHERE id = '%u'",auction->Id); + auction->DeleteFromDB(); delete auction; } @@ -641,7 +776,7 @@ void AuctionHouseBot() _AHBplayer.MinimalLoadFromDB(NULL, AHBplayerGUID); ObjectAccessor::Instance().AddObject(&_AHBplayer); - if(sConfig.GetIntDefault("AllowTwoSide.Interaction.Auction",0) == 0) + if(!sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION)) { addNewAuctions(&_AHBplayer, &AllianceConfig); if (((_newrun - _lastrun_a) > (AllianceConfig.GetBiddingInterval() * 60)) && (AllianceConfig.GetBidsPerInterval() > 0)) @@ -689,7 +824,7 @@ void AuctionHouseBotInit() Bind_When_Use = sConfig.GetBoolDefault("AuctionHouseBot.Bind_When_Use", 1); Bind_Quest_Item = sConfig.GetBoolDefault("AuctionHouseBot.Bind_Quest_Item", 0); - if(sConfig.GetBoolDefault("AllowTwoSide.Interaction.Auction",0) == 0) + if(!sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION)) { AuctionHouseBotLoadValues(&AllianceConfig); AuctionHouseBotLoadValues(&HordeConfig); @@ -796,7 +931,7 @@ void AuctionHouseBotInit() break; } - if ((prototype->Quality < 1) || (prototype->Quality > 4)) + if ((prototype->Quality < 0) || (prototype->Quality > 6)) continue; if (Vendor_Items == 0) @@ -848,58 +983,93 @@ void AuctionHouseBotInit() switch (prototype->Quality) { + case 0: + if (prototype->Class == ITEM_CLASS_TRADE_GOODS) + greyTradeGoodsBin.push_back(itemID); + else + greyItemsBin.push_back(itemID); + break; + case 1: if (prototype->Class == ITEM_CLASS_TRADE_GOODS) - whiteTradeGoods.push_back(itemID); + whiteTradeGoodsBin.push_back(itemID); else - whiteItems.push_back(itemID); + whiteItemsBin.push_back(itemID); break; case 2: if (prototype->Class == ITEM_CLASS_TRADE_GOODS) - greenTradeGoods.push_back(itemID); + greenTradeGoodsBin.push_back(itemID); else - greenItems.push_back(itemID); + greenItemsBin.push_back(itemID); break; case 3: if (prototype->Class == ITEM_CLASS_TRADE_GOODS) - blueTradeGoods.push_back(itemID); + blueTradeGoodsBin.push_back(itemID); else - blueItems.push_back(itemID); + blueItemsBin.push_back(itemID); break; case 4: if (prototype->Class == ITEM_CLASS_TRADE_GOODS) - purpleTradeGoods.push_back(itemID); + purpleTradeGoodsBin.push_back(itemID); + else + purpleItemsBin.push_back(itemID); + break; + + case 5: + if (prototype->Class == ITEM_CLASS_TRADE_GOODS) + orangeTradeGoodsBin.push_back(itemID); + else + orangeItemsBin.push_back(itemID); + break; + + case 6: + if (prototype->Class == ITEM_CLASS_TRADE_GOODS) + yellowTradeGoodsBin.push_back(itemID); else - purpleItems.push_back(itemID); + yellowItemsBin.push_back(itemID); break; } } - if ((whiteTradeGoods.size() == 0) && - (greenTradeGoods.size() == 0) && - (blueTradeGoods.size() == 0) && - (purpleTradeGoods.size() == 0) && - (whiteItems.size() == 0) && - (greenItems.size() == 0) && - (blueItems.size() == 0) && - (purpleItems.size() == 0)) + if ( + (greyTradeGoodsBin.size() == 0) && + (whiteTradeGoodsBin.size() == 0) && + (greenTradeGoodsBin.size() == 0) && + (blueTradeGoodsBin.size() == 0) && + (purpleTradeGoodsBin.size() == 0) && + (orangeTradeGoodsBin.size() == 0) && + (yellowTradeGoodsBin.size() == 0) && + (greyItemsBin.size() == 0) && + (whiteItemsBin.size() == 0) && + (greenItemsBin.size() == 0) && + (blueItemsBin.size() == 0) && + (purpleItemsBin.size() == 0) && + (orangeItemsBin.size() == 0) && + (yellowItemsBin.size() == 0) + ) { sLog.outString("AuctionHouseBot: No items"); AHBSeller = 0; } sLog.outString("AuctionHouseBot:"); - sLog.outString("loaded %d white trade goods", whiteTradeGoods.size()); - sLog.outString("loaded %d green trade goods", greenTradeGoods.size()); - sLog.outString("loaded %d blue trade goods", blueTradeGoods.size()); - sLog.outString("loaded %d purple trade goods", purpleTradeGoods.size()); - sLog.outString("loaded %d white items", whiteItems.size()); - sLog.outString("loaded %d green items", greenItems.size()); - sLog.outString("loaded %d blue items", blueItems.size()); - sLog.outString("loaded %d purple items", purpleItems.size()); + sLog.outString("loaded %d grey trade goods", greyTradeGoodsBin.size()); + sLog.outString("loaded %d white trade goods", whiteTradeGoodsBin.size()); + sLog.outString("loaded %d green trade goods", greenTradeGoodsBin.size()); + sLog.outString("loaded %d blue trade goods", blueTradeGoodsBin.size()); + sLog.outString("loaded %d purple trade goods", purpleTradeGoodsBin.size()); + sLog.outString("loaded %d orange trade goods", orangeTradeGoodsBin.size()); + sLog.outString("loaded %d yellow trade goods", yellowTradeGoodsBin.size()); + sLog.outString("loaded %d grey items", greyItemsBin.size()); + sLog.outString("loaded %d white items", whiteItemsBin.size()); + sLog.outString("loaded %d green items", greenItemsBin.size()); + sLog.outString("loaded %d blue items", blueItemsBin.size()); + sLog.outString("loaded %d purple items", purpleItemsBin.size()); + sLog.outString("loaded %d orange items", orangeItemsBin.size()); + sLog.outString("loaded %d yellow items", yellowItemsBin.size()); } sLog.outString("AuctionHouseBot by Paradox (original by ChrisK) has been loaded."); sLog.outString("AuctionHouseBot now includes AHBuyer by Kerbe and Paradox"); @@ -938,14 +1108,20 @@ void AuctionHouseBotCommands(uint32 command, uint32 ahMapID, uint32 col, char* a case AHB_PURPLE: color = "purple"; break; + case AHB_ORANGE: + color = "orange"; + break; + case AHB_YELLOW: + color = "yellow"; + break; default: break; } switch (command) { - case 0: //ahexpire + case 0: //ahexpire { - AuctionHouseObject* auctionHouse = objmgr.GetAuctionsMap(ahMapID); + AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap(config->GetAHFID()); AuctionHouseObject::AuctionEntryMap::iterator itr; itr = auctionHouse->GetAuctionsBegin(); @@ -953,40 +1129,40 @@ void AuctionHouseBotCommands(uint32 command, uint32 ahMapID, uint32 col, char* a while (itr != auctionHouse->GetAuctionsEnd()) { if (itr->second->owner == AHBplayerGUID) - itr->second->time = sWorld.GetGameTime(); + itr->second->expire_time = sWorld.GetGameTime(); ++itr; } }break; - case 1: //min items + case 1: //min items { char * param1 = strtok(args, " "); uint32 minItems = (uint32) strtoul(param1, NULL, 0); CharacterDatabase.PExecute("UPDATE auctionhousebot SET minitems = '%u' WHERE auctionhouse = '%u'", minItems, ahMapID); config->SetMinItems(minItems); }break; - case 2: //max items + case 2: //max items { char * param1 = strtok(args, " "); uint32 maxItems = (uint32) strtoul(param1, NULL, 0); CharacterDatabase.PExecute("UPDATE auctionhousebot SET maxitems = '%u' WHERE auctionhouse = '%u'", maxItems, ahMapID); config->SetMaxItems(maxItems); }break; - case 3: //min time + case 3: //min time { char * param1 = strtok(args, " "); uint32 minTime = (uint32) strtoul(param1, NULL, 0); CharacterDatabase.PExecute("UPDATE auctionhousebot SET mintime = '%u' WHERE auctionhouse = '%u'", minTime, ahMapID); config->SetMinTime(minTime); }break; - case 4: //max time + case 4: //max time { char * param1 = strtok(args, " "); uint32 maxTime = (uint32) strtoul(param1, NULL, 0); CharacterDatabase.PExecute("UPDATE auctionhousebot SET maxtime = '%u' WHERE auctionhouse = '%u'", maxTime, ahMapID); config->SetMaxTime(maxTime); }break; - case 5: //percentages + case 5: //percentages { char * param1 = strtok(args, " "); char * param2 = strtok(NULL, " "); @@ -996,49 +1172,67 @@ void AuctionHouseBotCommands(uint32 command, uint32 ahMapID, uint32 col, char* a char * param6 = strtok(NULL, " "); char * param7 = strtok(NULL, " "); char * param8 = strtok(NULL, " "); - uint32 wtg = (uint32) strtoul(param1, NULL, 0); - uint32 gtg = (uint32) strtoul(param2, NULL, 0); - uint32 btg = (uint32) strtoul(param3, NULL, 0); - uint32 ptg = (uint32) strtoul(param4, NULL, 0); - uint32 wi = (uint32) strtoul(param5, NULL, 0); - uint32 gi = (uint32) strtoul(param6, NULL, 0); - uint32 bi = (uint32) strtoul(param7, NULL, 0); - uint32 pi = (uint32) strtoul(param8, NULL, 0); + char * param9 = strtok(NULL, " "); + char * param10 = strtok(NULL, " "); + char * param11 = strtok(NULL, " "); + char * param12 = strtok(NULL, " "); + char * param13 = strtok(NULL, " "); + char * param14 = strtok(NULL, " "); + uint32 greytg = (uint32) strtoul(param1, NULL, 0); + uint32 whitetg = (uint32) strtoul(param2, NULL, 0); + uint32 greentg = (uint32) strtoul(param3, NULL, 0); + uint32 bluetg = (uint32) strtoul(param4, NULL, 0); + uint32 purpletg = (uint32) strtoul(param5, NULL, 0); + uint32 orangetg = (uint32) strtoul(param6, NULL, 0); + uint32 yellowtg = (uint32) strtoul(param7, NULL, 0); + uint32 greyi = (uint32) strtoul(param8, NULL, 0); + uint32 whitei = (uint32) strtoul(param9, NULL, 0); + uint32 greeni = (uint32) strtoul(param10, NULL, 0); + uint32 bluei = (uint32) strtoul(param11, NULL, 0); + uint32 purplei = (uint32) strtoul(param12, NULL, 0); + uint32 orangei = (uint32) strtoul(param13, NULL, 0); + uint32 yellowi = (uint32) strtoul(param14, NULL, 0); CharacterDatabase.BeginTransaction(); - CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentwhitetradegoods = '%u' WHERE auctionhouse = '%u'", wtg, ahMapID); - CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentgreentradegoods = '%u' WHERE auctionhouse = '%u'", gtg, ahMapID); - CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentbluetradegoods = '%u' WHERE auctionhouse = '%u'", btg, ahMapID); - CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentpurpletradegoods = '%u' WHERE auctionhouse = '%u'", ptg, ahMapID); - CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentwhiteitems = '%u' WHERE auctionhouse = '%u'", wi, ahMapID); - CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentgreenitems = '%u' WHERE auctionhouse = '%u'", gi, ahMapID); - CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentblueitems = '%u' WHERE auctionhouse = '%u'", bi, ahMapID); - CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentpurpleitems = '%u' WHERE auctionhouse = '%u'", pi, ahMapID); + CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentgreytradegoods = '%u' WHERE auctionhouse = '%u'", greytg, ahMapID); + CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentwhitetradegoods = '%u' WHERE auctionhouse = '%u'", whitetg, ahMapID); + CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentgreentradegoods = '%u' WHERE auctionhouse = '%u'", greentg, ahMapID); + CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentbluetradegoods = '%u' WHERE auctionhouse = '%u'", bluetg, ahMapID); + CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentpurpletradegoods = '%u' WHERE auctionhouse = '%u'", purpletg, ahMapID); + CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentorangetradegoods = '%u' WHERE auctionhouse = '%u'", orangetg, ahMapID); + CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentyellowtradegoods = '%u' WHERE auctionhouse = '%u'", yellowtg, ahMapID); + CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentgreyitems = '%u' WHERE auctionhouse = '%u'", greyi, ahMapID); + CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentwhiteitems = '%u' WHERE auctionhouse = '%u'", whitei, ahMapID); + CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentgreenitems = '%u' WHERE auctionhouse = '%u'", greeni, ahMapID); + CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentblueitems = '%u' WHERE auctionhouse = '%u'", bluei, ahMapID); + CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentpurpleitems = '%u' WHERE auctionhouse = '%u'", purplei, ahMapID); + CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentorangeitems = '%u' WHERE auctionhouse = '%u'", orangei, ahMapID); + CharacterDatabase.PExecute("UPDATE auctionhousebot SET percentyellowitems = '%u' WHERE auctionhouse = '%u'", yellowi, ahMapID); CharacterDatabase.CommitTransaction(); - config->SetPercentages(wtg, gtg, btg, ptg, wi, gi, bi, pi); + config->SetPercentages(greytg, whitetg, greentg, bluetg, purpletg, orangetg, yellowtg, greyi, whitei, greeni, bluei, purplei, orangei, yellowi); }break; - case 6: //min prices + case 6: //min prices { char * param1 = strtok(args, " "); uint32 minPrice = (uint32) strtoul(param1, NULL, 0); CharacterDatabase.PExecute("UPDATE auctionhousebot SET minprice%s = '%u' WHERE auctionhouse = '%u'",color.c_str(), minPrice, ahMapID); config->SetMinPrice(col, minPrice); }break; - case 7: //max prices + case 7: //max prices { char * param1 = strtok(args, " "); uint32 maxPrice = (uint32) strtoul(param1, NULL, 0); CharacterDatabase.PExecute("UPDATE auctionhousebot SET maxprice%s = '%u' WHERE auctionhouse = '%u'",color.c_str(), maxPrice, ahMapID); config->SetMaxPrice(col, maxPrice); }break; - case 8: //min bid price + case 8: //min bid price { char * param1 = strtok(args, " "); uint32 minBidPrice = (uint32) strtoul(param1, NULL, 0); CharacterDatabase.PExecute("UPDATE auctionhousebot SET minbidprice%s = '%u' WHERE auctionhouse = '%u'",color.c_str(), minBidPrice, ahMapID); config->SetMinBidPrice(col, minBidPrice); }break; - case 9: //max bid price + case 9: //max bid price { char * param1 = strtok(args, " "); uint32 maxBidPrice = (uint32) strtoul(param1, NULL, 0); @@ -1094,25 +1288,44 @@ void AuctionHouseBotLoadValues(AHBConfig *config) {sLog.outError("minTime = %u", config->GetMinTime()); sLog.outError("maxTime = %u", config->GetMaxTime());} //load percentages - uint32 wtg = CharacterDatabase.PQuery("SELECT percentwhitetradegoods FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32(); - uint32 gtg = CharacterDatabase.PQuery("SELECT percentgreentradegoods FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32(); - uint32 btg = CharacterDatabase.PQuery("SELECT percentbluetradegoods FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32(); - uint32 ptg = CharacterDatabase.PQuery("SELECT percentpurpletradegoods FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32(); - uint32 wi = CharacterDatabase.PQuery("SELECT percentwhiteitems FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32(); - uint32 gi = CharacterDatabase.PQuery("SELECT percentgreenitems FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32(); - uint32 bi = CharacterDatabase.PQuery("SELECT percentblueitems FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32(); - uint32 pi = CharacterDatabase.PQuery("SELECT percentpurpleitems FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32(); - config->SetPercentages(wtg, gtg, btg, ptg, wi, gi, bi, pi); + uint32 greytg = CharacterDatabase.PQuery("SELECT percentgreytradegoods FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32(); + uint32 whitetg = CharacterDatabase.PQuery("SELECT percentwhitetradegoods FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32(); + uint32 greentg = CharacterDatabase.PQuery("SELECT percentgreentradegoods FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32(); + uint32 bluetg = CharacterDatabase.PQuery("SELECT percentbluetradegoods FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32(); + uint32 purpletg = CharacterDatabase.PQuery("SELECT percentpurpletradegoods FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32(); + uint32 orangetg = CharacterDatabase.PQuery("SELECT percentorangetradegoods FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32(); + uint32 yellowtg = CharacterDatabase.PQuery("SELECT percentyellowtradegoods FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32(); + uint32 greyi = CharacterDatabase.PQuery("SELECT percentgreyitems FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32(); + uint32 whitei = CharacterDatabase.PQuery("SELECT percentwhiteitems FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32(); + uint32 greeni = CharacterDatabase.PQuery("SELECT percentgreenitems FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32(); + uint32 bluei = CharacterDatabase.PQuery("SELECT percentblueitems FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32(); + uint32 purplei = CharacterDatabase.PQuery("SELECT percentpurpleitems FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32(); + uint32 orangei = CharacterDatabase.PQuery("SELECT percentorangeitems FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32(); + uint32 yellowi = CharacterDatabase.PQuery("SELECT percentyellowitems FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32(); + config->SetPercentages(greytg, whitetg, greentg, bluetg, purpletg, orangetg, yellowtg, greyi, whitei, greeni, bluei, purplei, orangei, yellowi); if(debug_Out) - {sLog.outError("percentWhiteTradeGoods = %u", config->GetPercentages(AHB_WHITE_TG)); - sLog.outError("percentGreenTradeGoods = %u", config->GetPercentages(AHB_GREEN_TG)); - sLog.outError("percentBlueTradeGoods = %u", config->GetPercentages(AHB_BLUE_TG)); - sLog.outError("percentPurpleTradeGoods = %u", config->GetPercentages(AHB_PURPLE_TG)); - sLog.outError("percentWhiteItems = %u", config->GetPercentages(AHB_WHITE_I)); - sLog.outError("percentGreenItems = %u", config->GetPercentages(AHB_GREEN_I)); - sLog.outError("percentBlueItems = %u", config->GetPercentages(AHB_BLUE_I)); - sLog.outError("percentPurpleItems = %u", config->GetPercentages(AHB_PURPLE_I));} + { + sLog.outError("percentGreyTradeGoods = %u", config->GetPercentages(AHB_GREY_TG)); + sLog.outError("percentWhiteTradeGoods = %u", config->GetPercentages(AHB_WHITE_TG)); + sLog.outError("percentGreenTradeGoods = %u", config->GetPercentages(AHB_GREEN_TG)); + sLog.outError("percentBlueTradeGoods = %u", config->GetPercentages(AHB_BLUE_TG)); + sLog.outError("percentPurpleTradeGoods = %u", config->GetPercentages(AHB_PURPLE_TG)); + sLog.outError("percentOrangeTradeGoods = %u", config->GetPercentages(AHB_ORANGE_TG)); + sLog.outError("percentYellowTradeGoods = %u", config->GetPercentages(AHB_YELLOW_TG)); + sLog.outError("percentGreyItems = %u", config->GetPercentages(AHB_GREY_I)); + sLog.outError("percentWhiteItems = %u", config->GetPercentages(AHB_WHITE_I)); + sLog.outError("percentGreenItems = %u", config->GetPercentages(AHB_GREEN_I)); + sLog.outError("percentBlueItems = %u", config->GetPercentages(AHB_BLUE_I)); + sLog.outError("percentPurpleItems = %u", config->GetPercentages(AHB_PURPLE_I)); + sLog.outError("percentOrangeItems = %u", config->GetPercentages(AHB_ORANGE_I)); + sLog.outError("percentYellowItems = %u", config->GetPercentages(AHB_YELLOW_I)); + } //load min and max prices + config->SetMinPrice(AHB_GREY, CharacterDatabase.PQuery("SELECT minpricegrey FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32()); + config->SetMaxPrice(AHB_GREY, CharacterDatabase.PQuery("SELECT maxpricegrey FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32()); + if(debug_Out) + {sLog.outError("minPriceGrey = %u", config->GetMinPrice(AHB_GREY)); + sLog.outError("maxPriceGrey = %u", config->GetMaxPrice(AHB_GREY));} config->SetMinPrice(AHB_WHITE, CharacterDatabase.PQuery("SELECT minpricewhite FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32()); config->SetMaxPrice(AHB_WHITE, CharacterDatabase.PQuery("SELECT maxpricewhite FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32()); if(debug_Out) @@ -1133,7 +1346,23 @@ void AuctionHouseBotLoadValues(AHBConfig *config) if(debug_Out) {sLog.outError("minPricePurple = %u", config->GetMinPrice(AHB_PURPLE)); sLog.outError("maxPricePurple = %u", config->GetMaxPrice(AHB_PURPLE));} + config->SetMinPrice(AHB_ORANGE, CharacterDatabase.PQuery("SELECT minpriceorange FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32()); + config->SetMaxPrice(AHB_ORANGE, CharacterDatabase.PQuery("SELECT maxpriceorange FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32()); + if(debug_Out) + {sLog.outError("minPriceOrange = %u", config->GetMinPrice(AHB_ORANGE)); + sLog.outError("maxPriceOrange = %u", config->GetMaxPrice(AHB_ORANGE));} + config->SetMinPrice(AHB_YELLOW, CharacterDatabase.PQuery("SELECT minpriceyellow FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32()); + config->SetMaxPrice(AHB_YELLOW, CharacterDatabase.PQuery("SELECT maxpriceyellow FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32()); + if(debug_Out) + {sLog.outError("minPriceYellow = %u", config->GetMinPrice(AHB_YELLOW)); + sLog.outError("maxPriceYellow = %u", config->GetMaxPrice(AHB_YELLOW));} //load min and max bid prices + config->SetMinBidPrice(AHB_GREY, CharacterDatabase.PQuery("SELECT minbidpricegrey FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32()); + if(debug_Out) + {sLog.outError(",minBidPriceGrey = %u", config->GetMinBidPrice(AHB_GREY));} + config->SetMaxBidPrice(AHB_GREY, CharacterDatabase.PQuery("SELECT maxbidpricegrey FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32()); + if(debug_Out) + {sLog.outError("maxBidPriceGrey = %u", config->GetMaxBidPrice(AHB_GREY));} config->SetMinBidPrice(AHB_WHITE, CharacterDatabase.PQuery("SELECT minbidpricewhite FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32()); if(debug_Out) {sLog.outError(",minBidPriceWhite = %u", config->GetMinBidPrice(AHB_WHITE));} @@ -1158,7 +1387,22 @@ void AuctionHouseBotLoadValues(AHBConfig *config) config->SetMaxBidPrice(AHB_PURPLE, CharacterDatabase.PQuery("SELECT maxbidpricepurple FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32()); if(debug_Out) {sLog.outError("maxBidPricePurple = %u", config->GetMaxBidPrice(AHB_PURPLE));} + config->SetMinBidPrice(AHB_ORANGE, CharacterDatabase.PQuery("SELECT minbidpriceorange FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32()); + if(debug_Out) + {sLog.outError("minBidPriceOrange = %u", config->GetMinBidPrice(AHB_ORANGE));} + config->SetMaxBidPrice(AHB_ORANGE, CharacterDatabase.PQuery("SELECT maxbidpriceorange FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32()); + if(debug_Out) + {sLog.outError("maxBidPriceOrange = %u", config->GetMaxBidPrice(AHB_ORANGE));} + config->SetMinBidPrice(AHB_YELLOW, CharacterDatabase.PQuery("SELECT minbidpriceyellow FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32()); + if(debug_Out) + {sLog.outError("minBidPriceYellow = %u", config->GetMinBidPrice(AHB_YELLOW));} + config->SetMaxBidPrice(AHB_YELLOW, CharacterDatabase.PQuery("SELECT maxbidpriceyellow FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32()); + if(debug_Out) + {sLog.outError("maxBidPriceYellow = %u", config->GetMaxBidPrice(AHB_YELLOW));} //load max stacks + config->SetMaxStack(AHB_GREY, CharacterDatabase.PQuery("SELECT maxstackgrey FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32()); + if(debug_Out) + {sLog.outError("maxStackGrey = %u", config->GetMaxStack(AHB_GREY));} config->SetMaxStack(AHB_WHITE, CharacterDatabase.PQuery("SELECT maxstackwhite FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32()); if(debug_Out) {sLog.outError("maxStackWhite = %u", config->GetMaxStack(AHB_WHITE));} @@ -1171,6 +1415,12 @@ void AuctionHouseBotLoadValues(AHBConfig *config) config->SetMaxStack(AHB_PURPLE, CharacterDatabase.PQuery("SELECT maxstackpurple FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32()); if(debug_Out) {sLog.outError("maxStackPurple = %u", config->GetMaxStack(AHB_PURPLE));} + config->SetMaxStack(AHB_ORANGE, CharacterDatabase.PQuery("SELECT maxstackorange FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32()); + if(debug_Out) + {sLog.outError("maxStackOrange = %u", config->GetMaxStack(AHB_ORANGE));} + config->SetMaxStack(AHB_YELLOW, CharacterDatabase.PQuery("SELECT maxstackyellow FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32()); + if(debug_Out) + {sLog.outError("maxStackYellow = %u", config->GetMaxStack(AHB_YELLOW));} } if (AHBBuyer) { @@ -1180,12 +1430,18 @@ void AuctionHouseBotLoadValues(AHBConfig *config) config->SetBuyerPrice(AHB_GREEN, CharacterDatabase.PQuery("SELECT buyerpricegreen FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32()); config->SetBuyerPrice(AHB_BLUE, CharacterDatabase.PQuery("SELECT buyerpriceblue FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32()); config->SetBuyerPrice(AHB_PURPLE, CharacterDatabase.PQuery("SELECT buyerpricepurple FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32()); + config->SetBuyerPrice(AHB_ORANGE, CharacterDatabase.PQuery("SELECT buyerpriceorange FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32()); + config->SetBuyerPrice(AHB_YELLOW, CharacterDatabase.PQuery("SELECT buyerpriceyellow FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32()); if(debug_Out) - {sLog.outError("buyerPriceGrey = %u", config->GetBuyerPrice(AHB_GREY)); - sLog.outError("buyerPriceWhite = %u", config->GetBuyerPrice(AHB_WHITE)); - sLog.outError("buyerPriceGreen = %u", config->GetBuyerPrice(AHB_GREEN)); - sLog.outError("buyerPriceBlue = %u", config->GetBuyerPrice(AHB_BLUE)); - sLog.outError("buyerPricePurple = %u", config->GetBuyerPrice(AHB_PURPLE));} + { + sLog.outError("buyerPriceGrey = %u", config->GetBuyerPrice(AHB_GREY)); + sLog.outError("buyerPriceWhite = %u", config->GetBuyerPrice(AHB_WHITE)); + sLog.outError("buyerPriceGreen = %u", config->GetBuyerPrice(AHB_GREEN)); + sLog.outError("buyerPriceBlue = %u", config->GetBuyerPrice(AHB_BLUE)); + sLog.outError("buyerPricePurple = %u", config->GetBuyerPrice(AHB_PURPLE)); + sLog.outError("buyerPriceOrange = %u", config->GetBuyerPrice(AHB_ORANGE)); + sLog.outError("buyerPriceYellow = %u", config->GetBuyerPrice(AHB_YELLOW)); + } //load bidding interval config->SetBiddingInterval(CharacterDatabase.PQuery("SELECT buyerbiddinginterval FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetUInt32()); if(debug_Out) @@ -1196,4 +1452,3 @@ void AuctionHouseBotLoadValues(AHBConfig *config) {sLog.outError("buyerBidsPerInterval = %u", config->GetBidsPerInterval());} } } - diff --git a/src/game/AuctionHouseBot.h b/src/game/AuctionHouseBot.h index 3a224b8f752..8d5c067a354 100644 --- a/src/game/AuctionHouseBot.h +++ b/src/game/AuctionHouseBot.h @@ -8,16 +8,22 @@ #define AHB_GREEN 2 #define AHB_BLUE 3 #define AHB_PURPLE 4 +#define AHB_ORANGE 5 +#define AHB_YELLOW 6 #define AHB_GREY_TG 0 #define AHB_WHITE_TG 1 #define AHB_GREEN_TG 2 #define AHB_BLUE_TG 3 #define AHB_PURPLE_TG 4 -#define AHB_GREY_I 5 -#define AHB_WHITE_I 6 -#define AHB_GREEN_I 7 -#define AHB_BLUE_I 8 -#define AHB_PURPLE_I 9 +#define AHB_ORANGE_TG 5 +#define AHB_YELLOW_TG 6 +#define AHB_GREY_I 7 +#define AHB_WHITE_I 8 +#define AHB_GREEN_I 9 +#define AHB_BLUE_I 10 +#define AHB_PURPLE_I 11 +#define AHB_ORANGE_I 12 +#define AHB_YELLOW_I 13 #define AHBplayerAccount sConfig.GetIntDefault("AuctionHouseBot.Account", 0) #define AHBplayerGUID sConfig.GetIntDefault("AuctionHouseBot.GUID", 0) #define ItemsPerCycle sConfig.GetIntDefault("AuctionHouseBot.ItemsPerCycle", 200) @@ -28,18 +34,30 @@ class AHBConfig { private: uint32 AHID; + uint32 AHFID; uint32 minItems; uint32 maxItems; uint32 minTime; uint32 maxTime; + uint32 percentGreyTradeGoods; uint32 percentWhiteTradeGoods; uint32 percentGreenTradeGoods; uint32 percentBlueTradeGoods; uint32 percentPurpleTradeGoods; + uint32 percentOrangeTradeGoods; + uint32 percentYellowTradeGoods; + uint32 percentGreyItems; uint32 percentWhiteItems; uint32 percentGreenItems; uint32 percentBlueItems; uint32 percentPurpleItems; + uint32 percentOrangeItems; + uint32 percentYellowItems; + uint32 minPriceGrey; + uint32 maxPriceGrey; + uint32 minBidPriceGrey; + uint32 maxBidPriceGrey; + uint32 maxStackGrey; uint32 minPriceWhite; uint32 maxPriceWhite; uint32 minBidPriceWhite; @@ -60,27 +78,60 @@ class AHBConfig uint32 minBidPricePurple; uint32 maxBidPricePurple; uint32 maxStackPurple; + uint32 minPriceOrange; + uint32 maxPriceOrange; + uint32 minBidPriceOrange; + uint32 maxBidPriceOrange; + uint32 maxStackOrange; + uint32 minPriceYellow; + uint32 maxPriceYellow; + uint32 minBidPriceYellow; + uint32 maxBidPriceYellow; + uint32 maxStackYellow; uint32 buyerPriceGrey; uint32 buyerPriceWhite; uint32 buyerPriceGreen; uint32 buyerPriceBlue; uint32 buyerPricePurple; + uint32 buyerPriceOrange; + uint32 buyerPriceYellow; uint32 buyerBiddingInterval; uint32 buyerBidsPerInterval; - uint32 wtgp; - uint32 gtgp; - uint32 btgp; - uint32 ptgp; - uint32 wip; - uint32 gip; - uint32 bip; - uint32 pip; + uint32 greytgp; + uint32 whitetgp; + uint32 greentgp; + uint32 bluetgp; + uint32 purpletgp; + uint32 orangetgp; + uint32 yellowtgp; + uint32 greyip; + uint32 whiteip; + uint32 greenip; + uint32 blueip; + uint32 purpleip; + uint32 orangeip; + uint32 yellowip; public: AHBConfig(uint32 ahid) { AHID = ahid; + switch(ahid) + { + case 2: + AHFID = 55; + break; + case 6: + AHFID = 29; + break; + case 7: + AHFID = 120; + break; + default: + AHFID = 120; + break; + } } AHBConfig() { @@ -89,6 +140,10 @@ class AHBConfig { return AHID; } + uint32 GetAHFID() + { + return AHFID; + } void SetMinItems(uint32 value) { minItems = value; @@ -132,9 +187,9 @@ class AHBConfig { return maxTime; } - void SetPercentages(uint32 wtg, uint32 gtg, uint32 btg, uint32 ptg, uint32 wi, uint32 gi, uint32 bi, uint32 pi) + void SetPercentages(uint32 greytg, uint32 whitetg, uint32 greentg, uint32 bluetg, uint32 purpletg, uint32 orangetg, uint32 yellowtg, uint32 greyi, uint32 whitei, uint32 greeni, uint32 bluei, uint32 purplei, uint32 orangei, uint32 yellowi) { - uint32 totalPercent = wtg + gtg + btg + ptg + wi + gi + bi + pi; + uint32 totalPercent = greytg + whitetg + greentg + bluetg + purpletg + orangetg + yellowtg + greyi + whitei + greeni + bluei + purplei + orangei + yellowi; if (totalPercent == 0) { @@ -142,26 +197,35 @@ class AHBConfig } else if (totalPercent != 100) { - double scale = (double) 100 / (double) totalPercent; - - wtg = (uint32) (scale * (double) pi); - gtg = (uint32) (scale * (double) gtg); - btg = (uint32) (scale * (double) btg); - ptg = (uint32) (scale * (double) ptg); - wi = (uint32) (scale * (double) wi); - gi = (uint32) (scale * (double) gi); - bi = (uint32) (scale * (double) bi); - pi = 100 - wtg - gtg - btg - ptg - wi - gi - bi; - + greytg = 0; + whitetg = 27; + greentg = 12; + bluetg = 10; + purpletg = 1; + orangetg = 0; + yellowtg = 0; + greyi = 0; + whitei = 10; + greeni = 30; + bluei = 8; + purplei = 2; + orangei = 0; + yellowi = 0; } - percentWhiteTradeGoods = wtg; - percentGreenTradeGoods = gtg; - percentBlueTradeGoods = btg; - percentPurpleTradeGoods = ptg; - percentWhiteItems = wi; - percentGreenItems = gi; - percentBlueItems = bi; - percentPurpleItems = pi; + percentGreyTradeGoods = greytg; + percentWhiteTradeGoods = whitetg; + percentGreenTradeGoods = greentg; + percentBlueTradeGoods = bluetg; + percentPurpleTradeGoods = purpletg; + percentOrangeTradeGoods = orangetg; + percentYellowTradeGoods = yellowtg; + percentGreyItems = greyi; + percentWhiteItems = whitei; + percentGreenItems = greeni; + percentBlueItems = bluei; + percentPurpleItems = purplei; + percentOrangeItems = orangei; + percentYellowItems = yellowi; CalculatePercents(); } uint32 GetPercentages(uint32 color) @@ -169,7 +233,7 @@ class AHBConfig switch(color) { case AHB_GREY_TG: - return 0; + return percentGreyTradeGoods; break; case AHB_WHITE_TG: return percentWhiteTradeGoods; @@ -183,8 +247,14 @@ class AHBConfig case AHB_PURPLE_TG: return percentPurpleTradeGoods; break; + case AHB_ORANGE_TG: + return percentOrangeTradeGoods; + break; + case AHB_YELLOW_TG: + return percentYellowTradeGoods; + break; case AHB_GREY_I: - return 0; + return percentGreyItems; break; case AHB_WHITE_I: return percentWhiteItems; @@ -198,6 +268,12 @@ class AHBConfig case AHB_PURPLE_I: return percentPurpleItems; break; + case AHB_ORANGE_I: + return percentOrangeItems; + break; + case AHB_YELLOW_I: + return percentYellowItems; + break; default: return 0; break; @@ -208,6 +284,7 @@ class AHBConfig switch(color) { case AHB_GREY: + minPriceGrey = value; break; case AHB_WHITE: minPriceWhite = value; @@ -221,6 +298,12 @@ class AHBConfig case AHB_PURPLE: minPricePurple = value; break; + case AHB_ORANGE: + minPriceOrange = value; + break; + case AHB_YELLOW: + minPriceYellow = value; + break; default: break; } @@ -231,7 +314,12 @@ class AHBConfig { case AHB_GREY: { - return 0; + if (minPriceGrey == 0) + return 100; + else if (minPriceGrey > maxPriceGrey) + return maxPriceGrey; + else + return minPriceGrey; break; } case AHB_WHITE: @@ -274,6 +362,26 @@ class AHBConfig return minPricePurple; break; } + case AHB_ORANGE: + { + if (minPriceOrange == 0) + return 400; + else if (minPriceOrange > maxPriceOrange) + return maxPriceOrange; + else + return minPriceOrange; + break; + } + case AHB_YELLOW: + { + if (minPriceYellow == 0) + return 500; + else if (minPriceYellow > maxPriceYellow) + return maxPriceYellow; + else + return minPriceYellow; + break; + } default: { return 0; @@ -286,6 +394,7 @@ class AHBConfig switch(color) { case AHB_GREY: + maxPriceGrey = value; break; case AHB_WHITE: maxPriceWhite = value; @@ -299,6 +408,12 @@ class AHBConfig case AHB_PURPLE: maxPricePurple = value; break; + case AHB_ORANGE: + maxPriceOrange = value; + break; + case AHB_YELLOW: + maxPriceYellow = value; + break; default: break; } @@ -309,7 +424,10 @@ class AHBConfig { case AHB_GREY: { - return 0; + if (maxPriceGrey == 0) + return 150; + else + return maxPriceGrey; break; } case AHB_WHITE: @@ -344,6 +462,22 @@ class AHBConfig return maxPricePurple; break; } + case AHB_ORANGE: + { + if (maxPriceOrange == 0) + return 550; + else + return maxPriceOrange; + break; + } + case AHB_YELLOW: + { + if (maxPriceYellow == 0) + return 650; + else + return maxPriceYellow; + break; + } default: { return 0; @@ -356,6 +490,7 @@ class AHBConfig switch(color) { case AHB_GREY: + minBidPriceGrey = value; break; case AHB_WHITE: minBidPriceWhite = value; @@ -369,6 +504,12 @@ class AHBConfig case AHB_PURPLE: minBidPricePurple = value; break; + case AHB_ORANGE: + minBidPriceOrange = value; + break; + case AHB_YELLOW: + minBidPriceYellow = value; + break; default: break; } @@ -379,7 +520,10 @@ class AHBConfig { case AHB_GREY: { - return 0; + if (minBidPriceGrey > 100) + return 100; + else + return minBidPriceGrey; break; } case AHB_WHITE: @@ -414,6 +558,22 @@ class AHBConfig return minBidPricePurple; break; } + case AHB_ORANGE: + { + if (minBidPriceOrange > 100) + return 100; + else + return minBidPriceOrange; + break; + } + case AHB_YELLOW: + { + if (minBidPriceYellow > 100) + return 100; + else + return minBidPriceYellow; + break; + } default: { return 0; @@ -426,6 +586,7 @@ class AHBConfig switch(color) { case AHB_GREY: + maxBidPriceGrey = value; break; case AHB_WHITE: maxBidPriceWhite = value; @@ -439,6 +600,12 @@ class AHBConfig case AHB_PURPLE: maxBidPricePurple = value; break; + case AHB_ORANGE: + maxBidPriceOrange = value; + break; + case AHB_YELLOW: + maxBidPriceYellow = value; + break; default: break; } @@ -449,7 +616,10 @@ class AHBConfig { case AHB_GREY: { - return 0; + if (maxBidPriceGrey > 100) + return 100; + else + return maxBidPriceGrey; break; } case AHB_WHITE: @@ -484,6 +654,22 @@ class AHBConfig return maxBidPricePurple; break; } + case AHB_ORANGE: + { + if (maxBidPriceOrange > 100) + return 100; + else + return maxBidPriceOrange; + break; + } + case AHB_YELLOW: + { + if (maxBidPriceYellow > 100) + return 100; + else + return maxBidPriceYellow; + break; + } default: { return 0; @@ -496,6 +682,7 @@ class AHBConfig switch(color) { case AHB_GREY: + maxStackGrey = value; break; case AHB_WHITE: maxStackWhite = value; @@ -509,6 +696,12 @@ class AHBConfig case AHB_PURPLE: maxStackPurple = value; break; + case AHB_ORANGE: + maxStackOrange = value; + break; + case AHB_YELLOW: + maxStackYellow = value; + break; default: break; } @@ -519,7 +712,7 @@ class AHBConfig { case AHB_GREY: { - return 0; + return maxStackGrey; break; } case AHB_WHITE: @@ -542,6 +735,16 @@ class AHBConfig return maxStackPurple; break; } + case AHB_ORANGE: + { + return maxStackOrange; + break; + } + case AHB_YELLOW: + { + return maxStackYellow; + break; + } default: { return 0; @@ -568,6 +771,12 @@ class AHBConfig case AHB_PURPLE: buyerPricePurple = value; break; + case AHB_ORANGE: + buyerPriceOrange = value; + break; + case AHB_YELLOW: + buyerPriceYellow = value; + break; default: break; } @@ -591,6 +800,12 @@ class AHBConfig case AHB_PURPLE: return buyerPricePurple; break; + case AHB_ORANGE: + return buyerPriceOrange; + break; + case AHB_YELLOW: + return buyerPriceYellow; + break; default: return 0; break; @@ -606,62 +821,79 @@ class AHBConfig } void CalculatePercents() { - wtgp = (uint32) (((double)percentWhiteTradeGoods / 100.0) * maxItems); - gtgp = (uint32) (((double)percentGreenTradeGoods / 100.0) * maxItems); - btgp = (uint32) (((double)percentBlueTradeGoods / 100.0) * maxItems); - ptgp = (uint32) (((double)percentPurpleTradeGoods / 100.0) * maxItems); - wip = (uint32) (((double)percentWhiteItems / 100.0) * maxItems); - gip = (uint32) (((double)percentGreenItems / 100.0) * maxItems); - bip = (uint32) (((double)percentBlueItems / 100.0) * maxItems); - pip = (uint32) (((double)percentPurpleItems / 100.0) * maxItems); - uint32 total = wtgp + gtgp + btgp + ptgp + wip + gip + bip + pip; - if (total != maxItems) + greytgp = (uint32) (((double)percentGreyTradeGoods / 100.0) * maxItems); + whitetgp = (uint32) (((double)percentWhiteTradeGoods / 100.0) * maxItems); + greentgp = (uint32) (((double)percentGreenTradeGoods / 100.0) * maxItems); + bluetgp = (uint32) (((double)percentBlueTradeGoods / 100.0) * maxItems); + purpletgp = (uint32) (((double)percentPurpleTradeGoods / 100.0) * maxItems); + orangetgp = (uint32) (((double)percentOrangeTradeGoods / 100.0) * maxItems); + yellowtgp = (uint32) (((double)percentYellowTradeGoods / 100.0) * maxItems); + greyip = (uint32) (((double)percentGreyItems / 100.0) * maxItems); + whiteip = (uint32) (((double)percentWhiteItems / 100.0) * maxItems); + greenip = (uint32) (((double)percentGreenItems / 100.0) * maxItems); + blueip = (uint32) (((double)percentBlueItems / 100.0) * maxItems); + purpleip = (uint32) (((double)percentPurpleItems / 100.0) * maxItems); + orangeip = (uint32) (((double)percentOrangeItems / 100.0) * maxItems); + yellowip = (uint32) (((double)percentYellowItems / 100.0) * maxItems); + uint32 total = greytgp + whitetgp + greentgp + bluetgp + purpletgp + orangetgp + yellowtgp + greyip + whiteip + greenip + blueip + purpleip + orangeip + yellowip; + int32 diff = (maxItems - total); + if (diff < 0) + { + if ((whiteip - diff) > 0) + whiteip -= diff; + else if ((greenip - diff) > 0) + greenip -= diff; + } + else if (diff < 0) { - wtgp = (uint32) (maxItems * (double) wtgp); - gtgp = (uint32) (maxItems * (double) gtgp); - btgp = (uint32) (maxItems * (double) btgp); - ptgp = (uint32) (maxItems * (double) ptgp); - wip = (uint32) (maxItems * (double) wip); - gip = (uint32) (maxItems * (double) gip); - bip = (uint32) (maxItems * (double) bip); - pip = (maxItems - (wtgp + gtgp + btgp + ptgp + wip + gip + bip)); - total = wtgp + gtgp + btgp + ptgp + wip + gip + bip + pip; + whiteip += diff; } - //sLog.outString("%u %u %u %u %u %u %u %u", wtgp, gtgp, btgp, ptgp, wip, gip, bip, pip); } uint32 GetPercents(uint32 color) { switch(color) { case AHB_GREY_TG: - return 0; + return greytgp; break; case AHB_WHITE_TG: - return wtgp; + return whitetgp; break; case AHB_GREEN_TG: - return gtgp; + return greentgp; break; case AHB_BLUE_TG: - return btgp; + return bluetgp; break; case AHB_PURPLE_TG: - return ptgp; + return purpletgp; + break; + case AHB_ORANGE_TG: + return orangetgp; + break; + case AHB_YELLOW_TG: + return yellowtgp; break; case AHB_GREY_I: - return 0; + return greyip; break; case AHB_WHITE_I: - return wip; + return whiteip; break; case AHB_GREEN_I: - return gip; + return greenip; break; case AHB_BLUE_I: - return bip; + return blueip; break; case AHB_PURPLE_I: - return pip; + return purpleip; + break; + case AHB_ORANGE_I: + return orangeip; + break; + case AHB_YELLOW_I: + return yellowip; break; default: return 0; @@ -685,4 +917,3 @@ void AuctionHouseBotInit(); void AuctionHouseBotLoadValues(AHBConfig*); void AuctionHouseBotCommands(uint32, uint32, uint32, char*); #endif - diff --git a/src/game/AuctionHouseHandler.cpp b/src/game/AuctionHouseHandler.cpp new file mode 100644 index 00000000000..b36d1870b86 --- /dev/null +++ b/src/game/AuctionHouseHandler.cpp @@ -0,0 +1,640 @@ +/* + * Copyright (C) 2005-2008 MaNGOS + * + * Copyright (C) 2008-2009 Trinity + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "WorldPacket.h" +#include "WorldSession.h" +#include "Opcodes.h" +#include "Log.h" +#include "World.h" +#include "ObjectMgr.h" +#include "Player.h" +#include "UpdateMask.h" +#include "AuctionHouseMgr.h" +#include "Util.h" +#include "AuctionHouseBot.h" + +//please DO NOT use iterator++, because it is slower than ++iterator!!! +//post-incrementation is always slower than pre-incrementation ! + +//void called when player click on auctioneer npc +void WorldSession::HandleAuctionHelloOpcode( WorldPacket & recv_data ) +{ + CHECK_PACKET_SIZE(recv_data,8); + + uint64 guid; //NPC guid + recv_data >> guid; + + Creature *unit = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid,UNIT_NPC_FLAG_AUCTIONEER); + if (!unit) + { + sLog.outDebug( "WORLD: HandleAuctionHelloOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) ); + return; + } + + // remove fake death + if(GetPlayer()->hasUnitState(UNIT_STAT_DIED)) + GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); + + SendAuctionHello(guid, unit); +} + +//this void causes that auction window is opened +void WorldSession::SendAuctionHello( uint64 guid, Creature* unit ) +{ + AuctionHouseEntry const* ahEntry = AuctionHouseMgr::GetAuctionHouseEntry(unit->getFaction()); + if(!ahEntry) + return; + + WorldPacket data( MSG_AUCTION_HELLO, 12 ); + data << (uint64) guid; + data << (uint32) ahEntry->houseId; + SendPacket( &data ); +} + +//call this method when player bids, creates, or deletes auction +void WorldSession::SendAuctionCommandResult(uint32 auctionId, uint32 Action, uint32 ErrorCode, uint32 bidError ) +{ + WorldPacket data( SMSG_AUCTION_COMMAND_RESULT, 16 ); + data << auctionId; + data << Action; + data << ErrorCode; + if ( !ErrorCode && Action ) + data << bidError; //when bid, then send 0, once... + SendPacket(&data); +} + +//this function sends notification, if bidder is online +void WorldSession::SendAuctionBidderNotification( uint32 location, uint32 auctionId, uint64 bidder, uint32 bidSum, uint32 diff, uint32 item_template) +{ + WorldPacket data(SMSG_AUCTION_BIDDER_NOTIFICATION, (8*4)); + data << uint32(location); + data << uint32(auctionId); + data << uint64(bidder); + data << uint32(bidSum); + data << uint32(diff); + data << uint32(item_template); + data << uint32(0); + SendPacket(&data); +} + +//this void causes on client to display: "Your auction sold" +void WorldSession::SendAuctionOwnerNotification( AuctionEntry* auction) +{ + WorldPacket data(SMSG_AUCTION_OWNER_NOTIFICATION, (7*4)); + data << auction->Id; + data << auction->bid; + data << (uint32) 0; //unk + data << (uint32) 0; //unk + data << (uint32) 0; //unk + data << auction->item_template; + data << (uint32) 0; //unk + SendPacket(&data); +} + +//this function sends mail to old bidder +void WorldSession::SendAuctionOutbiddedMail(AuctionEntry *auction, uint32 newPrice) +{ + uint64 oldBidder_guid = MAKE_NEW_GUID(auction->bidder,0, HIGHGUID_PLAYER); + Player *oldBidder = objmgr.GetPlayer(oldBidder_guid); + + uint32 oldBidder_accId = 0; + if(!oldBidder) + oldBidder_accId = objmgr.GetPlayerAccountIdByGUID(oldBidder_guid); + + // old bidder exist + if(oldBidder || oldBidder_accId) + { + std::ostringstream msgAuctionOutbiddedSubject; + msgAuctionOutbiddedSubject << auction->item_template << ":0:" << AUCTION_OUTBIDDED; + + if (oldBidder && !_player) + oldBidder->GetSession()->SendAuctionBidderNotification( auction->GetHouseId(), auction->Id, AHBplayerGUID, newPrice, auction->GetAuctionOutBid(), auction->item_template); + + if (oldBidder && _player) + oldBidder->GetSession()->SendAuctionBidderNotification( auction->GetHouseId(), auction->Id, _player->GetGUID(), newPrice, auction->GetAuctionOutBid(), auction->item_template); + + WorldSession::SendMailTo(oldBidder, MAIL_AUCTION, MAIL_STATIONERY_AUCTION, auction->GetHouseId(), auction->bidder, msgAuctionOutbiddedSubject.str(), 0, NULL, auction->bid, 0, MAIL_CHECK_MASK_NONE); + } +} + +//this function sends mail, when auction is cancelled to old bidder +void WorldSession::SendAuctionCancelledToBidderMail( AuctionEntry* auction ) +{ + uint64 bidder_guid = MAKE_NEW_GUID(auction->bidder, 0, HIGHGUID_PLAYER); + Player *bidder = objmgr.GetPlayer(bidder_guid); + + uint32 bidder_accId = 0; + if(!bidder) + bidder_accId = objmgr.GetPlayerAccountIdByGUID(bidder_guid); + + // bidder exist + if(bidder || bidder_accId) + { + std::ostringstream msgAuctionCancelledSubject; + msgAuctionCancelledSubject << auction->item_template << ":0:" << AUCTION_CANCELLED_TO_BIDDER; + + WorldSession::SendMailTo(bidder, MAIL_AUCTION, MAIL_STATIONERY_AUCTION, auction->GetHouseId(), auction->bidder, msgAuctionCancelledSubject.str(), 0, NULL, auction->bid, 0, MAIL_CHECK_MASK_NONE); + } +} + +//this void creates new auction and adds auction to some auctionhouse +void WorldSession::HandleAuctionSellItem( WorldPacket & recv_data ) +{ + CHECK_PACKET_SIZE(recv_data,8+8+4+4+4); + + uint64 auctioneer, item; + uint32 etime, bid, buyout; + recv_data >> auctioneer >> item; + recv_data >> bid >> buyout >> etime; + Player *pl = GetPlayer(); + + if (!item || !bid || !etime) + return; //check for cheaters + + Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, auctioneer,UNIT_NPC_FLAG_AUCTIONEER); + if (!pCreature) + { + sLog.outDebug( "WORLD: HandleAuctionSellItem - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(auctioneer)) ); + return; + } + + AuctionHouseEntry const* auctionHouseEntry = AuctionHouseMgr::GetAuctionHouseEntry(pCreature->getFaction()); + if(!auctionHouseEntry) + { + sLog.outDebug( "WORLD: HandleAuctionSellItem - Unit (GUID: %u) has wrong faction.", uint32(GUID_LOPART(auctioneer)) ); + return; + } + + + // client send time in minutes, convert to common used sec time + etime *= MINUTE; + + // client understand only 3 auction time + switch(etime) + { + case 1*MIN_AUCTION_TIME: + case 2*MIN_AUCTION_TIME: + case 4*MIN_AUCTION_TIME: + break; + default: + return; + } + + // remove fake death + if(GetPlayer()->hasUnitState(UNIT_STAT_DIED)) + GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); + + Item *it = pl->GetItemByGuid( item ); + //do not allow to sell already auctioned items + if(auctionmgr.GetAItem(GUID_LOPART(item))) + { + sLog.outError("AuctionError, player %s is sending item id: %u, but item is already in another auction", pl->GetName(), GUID_LOPART(item)); + SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_INTERNAL_ERROR); + return; + } + // prevent sending bag with items (cheat: can be placed in bag after adding equiped empty bag to auction) + if(!it) + { + SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_ITEM_NOT_FOUND); + return; + } + + if(!it->CanBeTraded()) + { + SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_INTERNAL_ERROR); + return; + } + + if (it->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_CONJURED) || it->GetUInt32Value(ITEM_FIELD_DURATION)) + { + SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_INTERNAL_ERROR); + return; + } + + AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap( pCreature->getFaction() ); + + //we have to take deposit : + uint32 deposit = auctionmgr.GetAuctionDeposit( auctionHouseEntry, etime, it ); + if ( pl->GetMoney() < deposit ) + { + SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_NOT_ENOUGHT_MONEY); + return; + } + + if( GetSecurity() > SEC_PLAYER && sWorld.getConfig(CONFIG_GM_LOG_TRADE) ) + { + sLog.outCommand(GetAccountId(),"GM %s (Account: %u) create auction: %s (Entry: %u Count: %u)", + GetPlayerName(),GetAccountId(),it->GetProto()->Name1,it->GetEntry(),it->GetCount()); + } + + pl->ModifyMoney( -int32(deposit) ); + + uint32 auction_time = uint32(etime * sWorld.getRate(RATE_AUCTION_TIME)); + + AuctionEntry *AH = new AuctionEntry; + AH->Id = objmgr.GenerateAuctionID(); + if(sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION)) + AH->auctioneer = 23442; + else + AH->auctioneer = GUID_LOPART(auctioneer); + AH->item_guidlow = GUID_LOPART(item); + AH->item_template = it->GetEntry(); + AH->owner = pl->GetGUIDLow(); + AH->startbid = bid; + AH->bidder = 0; + AH->bid = 0; + AH->buyout = buyout; + AH->expire_time = time(NULL) + auction_time; + AH->deposit = deposit; + AH->auctionHouseEntry = auctionHouseEntry; + + sLog.outDetail("selling item %u to auctioneer %u with initial bid %u with buyout %u and with time %u (in sec) in auctionhouse %u", GUID_LOPART(item), AH->auctioneer, bid, buyout, auction_time, AH->GetHouseId()); + auctionHouse->AddAuction(AH); + + auctionmgr.AddAItem(it); + pl->MoveItemFromInventory( it->GetBagSlot(), it->GetSlot(), true); + + CharacterDatabase.BeginTransaction(); + it->DeleteFromInventoryDB(); + it->SaveToDB(); // recursive and not have transaction guard into self, not in inventiory and can be save standalone + AH->SaveToDB(); + pl->SaveInventoryAndGoldToDB(); + CharacterDatabase.CommitTransaction(); + + SendAuctionCommandResult(AH->Id, AUCTION_SELL_ITEM, AUCTION_OK); +} + +//this function is called when client bids or buys out auction +void WorldSession::HandleAuctionPlaceBid( WorldPacket & recv_data ) +{ + CHECK_PACKET_SIZE(recv_data,8+4+4); + + uint64 auctioneer; + uint32 auctionId; + uint32 price; + recv_data >> auctioneer; + recv_data >> auctionId >> price; + + if (!auctionId || !price) + return; //check for cheaters + + Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, auctioneer,UNIT_NPC_FLAG_AUCTIONEER); + if (!pCreature) + { + sLog.outDebug( "WORLD: HandleAuctionPlaceBid - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(auctioneer)) ); + return; + } + + // remove fake death + if(GetPlayer()->hasUnitState(UNIT_STAT_DIED)) + GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); + + AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap( pCreature->getFaction() ); + + AuctionEntry *auction = auctionHouse->GetAuction(auctionId); + Player *pl = GetPlayer(); + + if( !auction || auction->owner == pl->GetGUIDLow() ) + { + //you cannot bid your own auction: + SendAuctionCommandResult( 0, AUCTION_PLACE_BID, CANNOT_BID_YOUR_AUCTION_ERROR ); + return; + } + + // impossible have online own another character (use this for speedup check in case online owner) + Player* auction_owner = objmgr.GetPlayer(MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER)); + if( !auction_owner && objmgr.GetPlayerAccountIdByGUID(MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER)) == pl->GetSession()->GetAccountId()) + { + //you cannot bid your another character auction: + SendAuctionCommandResult( 0, AUCTION_PLACE_BID, CANNOT_BID_YOUR_AUCTION_ERROR ); + return; + } + + // cheating + if(price <= auction->bid) + return; + + // price too low for next bid if not buyout + if ((price < auction->buyout || auction->buyout == 0) && + price < auction->bid + auction->GetAuctionOutBid()) + { + //auction has already higher bid, client tests it! + return; + } + + if (price > pl->GetMoney()) + { + //you don't have enought money!, client tests! + //SendAuctionCommandResult(auction->auctionId, AUCTION_PLACE_BID, ???); + return; + } + + if ((price < auction->buyout) || (auction->buyout == 0)) + { + if (auction->bidder > 0) + { + if ( auction->bidder == pl->GetGUIDLow() ) + { + pl->ModifyMoney( -int32(price - auction->bid)); + } + else + { + // mail to last bidder and return money + SendAuctionOutbiddedMail( auction , price ); + pl->ModifyMoney( -int32(price) ); + } + } + else + { + pl->ModifyMoney( -int32(price) ); + } + auction->bidder = pl->GetGUIDLow(); + auction->bid = price; + + // after this update we should save player's money ... + CharacterDatabase.PExecute("UPDATE auctionhouse SET buyguid = '%u',lastbid = '%u' WHERE id = '%u'", auction->bidder, auction->bid, auction->Id); + + SendAuctionCommandResult(auction->Id, AUCTION_PLACE_BID, AUCTION_OK, 0 ); + } + else + { + //buyout: + if (pl->GetGUIDLow() == auction->bidder ) + { + pl->ModifyMoney(-int32(auction->buyout - auction->bid)); + } + else + { + pl->ModifyMoney(-int32(auction->buyout)); + if ( auction->bidder ) //buyout for bidded auction .. + { + SendAuctionOutbiddedMail( auction, auction->buyout ); + } + } + auction->bidder = pl->GetGUIDLow(); + auction->bid = auction->buyout; + + auctionmgr.SendAuctionSalePendingMail( auction ); + auctionmgr.SendAuctionSuccessfulMail( auction ); + auctionmgr.SendAuctionWonMail( auction ); + + SendAuctionCommandResult(auction->Id, AUCTION_PLACE_BID, AUCTION_OK); + + auctionmgr.RemoveAItem(auction->item_guidlow); + auctionHouse->RemoveAuction(auction->Id); + auction->DeleteFromDB(); + + delete auction; + } + CharacterDatabase.BeginTransaction(); + pl->SaveInventoryAndGoldToDB(); + CharacterDatabase.CommitTransaction(); +} + +//this void is called when auction_owner cancels his auction +void WorldSession::HandleAuctionRemoveItem( WorldPacket & recv_data ) +{ + CHECK_PACKET_SIZE(recv_data,8+4); + + uint64 auctioneer; + uint32 auctionId; + recv_data >> auctioneer; + recv_data >> auctionId; + //sLog.outDebug( "Cancel AUCTION AuctionID: %u", auctionId); + + Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, auctioneer,UNIT_NPC_FLAG_AUCTIONEER); + if (!pCreature) + { + sLog.outDebug( "WORLD: HandleAuctionRemoveItem - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(auctioneer)) ); + return; + } + + // remove fake death + if(GetPlayer()->hasUnitState(UNIT_STAT_DIED)) + GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); + + AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap( pCreature->getFaction() ); + + AuctionEntry *auction = auctionHouse->GetAuction(auctionId); + Player *pl = GetPlayer(); + + if (auction && auction->owner == pl->GetGUIDLow()) + { + Item *pItem = auctionmgr.GetAItem(auction->item_guidlow); + if (pItem) + { + if (auction->bidder > 0) // If we have a bidder, 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 + return; + //some auctionBidderNotification would be needed, but don't know that parts.. + SendAuctionCancelledToBidderMail( auction ); + pl->ModifyMoney( -int32(auctionCut) ); + } + // Return the item by mail + std::ostringstream msgAuctionCanceledOwner; + msgAuctionCanceledOwner << auction->item_template << ":0:" << AUCTION_CANCELED; + + MailItemsInfo mi; + mi.AddItem(auction->item_guidlow, auction->item_template, pItem); + + // item will deleted or added to received mail list + WorldSession::SendMailTo(pl, MAIL_AUCTION, MAIL_STATIONERY_AUCTION, auction->GetHouseId(), pl->GetGUIDLow(), msgAuctionCanceledOwner.str(), 0, &mi, 0, 0, MAIL_CHECK_MASK_NONE); + } + else + { + sLog.outError("Auction id: %u has non-existed item (item guid : %u)!!!", auction->Id, auction->item_guidlow); + SendAuctionCommandResult( 0, AUCTION_CANCEL, AUCTION_INTERNAL_ERROR ); + return; + } + } + else + { + SendAuctionCommandResult( 0, AUCTION_CANCEL, AUCTION_INTERNAL_ERROR ); + //this code isn't possible ... maybe there should be assert + sLog.outError("CHEATER : %u, he tried to cancel auction (id: %u) of another player, or auction is NULL", pl->GetGUIDLow(), auctionId ); + return; + } + + //inform player, that auction is removed + SendAuctionCommandResult( auction->Id, AUCTION_CANCEL, AUCTION_OK ); + // Now remove the auction + CharacterDatabase.BeginTransaction(); + auction->DeleteFromDB(); + pl->SaveInventoryAndGoldToDB(); + CharacterDatabase.CommitTransaction(); + auctionmgr.RemoveAItem( auction->item_guidlow ); + auctionHouse->RemoveAuction( auction->Id ); + delete auction; +} + +//called when player lists his bids +void WorldSession::HandleAuctionListBidderItems( WorldPacket & recv_data ) +{ + CHECK_PACKET_SIZE(recv_data,8+4+4); + + uint64 guid; //NPC guid + uint32 listfrom; //page of auctions + uint32 outbiddedCount; //count of outbidded auctions + + recv_data >> guid; + recv_data >> listfrom; // not used in fact (this list not have page control in client) + recv_data >> outbiddedCount; + if (recv_data.size() != (16 + outbiddedCount * 4 )) + { + sLog.outError("Client sent bad opcode!!! with count: %u and size : %d (mustbe: %d", outbiddedCount, recv_data.size(),(16 + outbiddedCount * 4 )); + outbiddedCount = 0; + } + + Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid,UNIT_NPC_FLAG_AUCTIONEER); + if (!pCreature) + { + sLog.outDebug( "WORLD: HandleAuctionListBidderItems - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) ); + return; + } + + // remove fake death + if(GetPlayer()->hasUnitState(UNIT_STAT_DIED)) + GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); + + AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap( pCreature->getFaction() ); + + WorldPacket data( SMSG_AUCTION_BIDDER_LIST_RESULT, (4+4+4) ); + Player *pl = GetPlayer(); + data << (uint32) 0; //add 0 as count + uint32 count = 0; + uint32 totalcount = 0; + while ( outbiddedCount > 0) //add all data, which client requires + { + --outbiddedCount; + uint32 outbiddedAuctionId; + recv_data >> outbiddedAuctionId; + AuctionEntry * auction = auctionHouse->GetAuction( outbiddedAuctionId ); + if ( auction && auction->BuildAuctionInfo(data)) + { + ++totalcount; + ++count; + } + } + + auctionHouse->BuildListBidderItems(data,pl,count,totalcount); + data.put( 0, count ); // add count to placeholder + data << totalcount; + data << (uint32)300; //unk 2.3.0 + SendPacket(&data); +} + +//this void sends player info about his auctions +void WorldSession::HandleAuctionListOwnerItems( WorldPacket & recv_data ) +{ + CHECK_PACKET_SIZE(recv_data,8+4); + + uint32 listfrom; + uint64 guid; + + recv_data >> guid; + recv_data >> listfrom; // not used in fact (this list not have page control in client) + + Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid,UNIT_NPC_FLAG_AUCTIONEER); + if (!pCreature) + { + sLog.outDebug( "WORLD: HandleAuctionListOwnerItems - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) ); + return; + } + + // remove fake death + if(GetPlayer()->hasUnitState(UNIT_STAT_DIED)) + GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); + + AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap( pCreature->getFaction() ); + + WorldPacket data( SMSG_AUCTION_OWNER_LIST_RESULT, (4+4+4) ); + data << (uint32) 0; // amount place holder + + uint32 count = 0; + uint32 totalcount = 0; + + auctionHouse->BuildListOwnerItems(data,_player,count,totalcount); + data.put(0, count); + data << (uint32) totalcount; + data << (uint32) 0; + SendPacket(&data); +} + +//this void is called when player clicks on search button +void WorldSession::HandleAuctionListItems( WorldPacket & recv_data ) +{ + CHECK_PACKET_SIZE(recv_data,8+4+1+1+1+4+4+4+4+1); + + std::string searchedname; + uint8 levelmin, levelmax, usable; + uint32 listfrom, auctionSlotID, auctionMainCategory, auctionSubCategory, quality; + uint64 guid; + + recv_data >> guid; + recv_data >> listfrom; // start, used for page control listing by 50 elements + recv_data >> searchedname; + + // recheck with known string size + CHECK_PACKET_SIZE(recv_data,8+4+(searchedname.size()+1)+1+1+4+4+4+4+1); + + recv_data >> levelmin >> levelmax; + recv_data >> auctionSlotID >> auctionMainCategory >> auctionSubCategory; + recv_data >> quality >> usable; + + Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid,UNIT_NPC_FLAG_AUCTIONEER); + if (!pCreature) + { + sLog.outDebug( "WORLD: HandleAuctionListItems - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) ); + return; + } + + // remove fake death + if(GetPlayer()->hasUnitState(UNIT_STAT_DIED)) + GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); + + AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap( pCreature->getFaction() ); + + //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); + + WorldPacket data( SMSG_AUCTION_LIST_RESULT, (4+4+4) ); + uint32 count = 0; + uint32 totalcount = 0; + data << (uint32) 0; + + // converting string that we try to find to lower case + std::wstring wsearchedname; + if(!Utf8toWStr(searchedname,wsearchedname)) + return; + + wstrToLower(wsearchedname); + + auctionHouse->BuildListAuctionItems(data,_player, + wsearchedname, listfrom, levelmin, levelmax, usable, + auctionSlotID, auctionMainCategory, auctionSubCategory, quality, + count,totalcount); + + data.put(0, count); + data << (uint32) totalcount; + data << (uint32) 300; // unk 2.3.0 const? + SendPacket(&data); +} + diff --git a/src/game/AuctionHouseMgr.cpp b/src/game/AuctionHouseMgr.cpp new file mode 100644 index 00000000000..1554013af99 --- /dev/null +++ b/src/game/AuctionHouseMgr.cpp @@ -0,0 +1,685 @@ +/* +* Copyright (C) 2005-2009 MaNGOS +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "Common.h" +#include "Database/DatabaseEnv.h" +#include "Database/DBCStores.h" +#include "Database/SQLStorage.h" +#include "ProgressBar.h" + +#include "AccountMgr.h" +#include "AuctionHouseMgr.h" +#include "Item.h" +#include "Language.h" +#include "Log.h" +#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() +{ +} + +AuctionHouseMgr::~AuctionHouseMgr() +{ + for(ItemMap::iterator itr = mAitems.begin(); itr != mAitems.end(); ++itr) + delete itr->second; +} + +AuctionHouseObject * AuctionHouseMgr::GetAuctionsMap( uint32 factionTemplateId ) +{ + if(sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION)) + return &mNeutralAuctions; + + // team have linked auction houses + FactionTemplateEntry const* u_entry = sFactionTemplateStore.LookupEntry(factionTemplateId); + if(!u_entry) + return &mNeutralAuctions; + else if(u_entry->ourMask & FACTION_MASK_ALLIANCE) + return &mAllianceAuctions; + else if(u_entry->ourMask & FACTION_MASK_HORDE) + return &mHordeAuctions; + else + return &mNeutralAuctions; +} + +uint32 AuctionHouseMgr::GetAuctionDeposit(AuctionHouseEntry const* entry, uint32 time, Item *pItem) +{ + uint32 deposit = pItem->GetProto()->SellPrice * pItem->GetCount() * (time / MIN_AUCTION_TIME ); + + return uint32(deposit * entry->depositPercent * 3 * sWorld.getRate(RATE_AUCTION_DEPOSIT) / 100.0f ); +} + +//does not clear ram +void AuctionHouseMgr::SendAuctionWonMail( AuctionEntry *auction ) +{ + Item *pItem = GetAItem(auction->item_guidlow); + if(!pItem) + return; + + uint64 bidder_guid = MAKE_NEW_GUID(auction->bidder, 0, HIGHGUID_PLAYER); + Player *bidder = objmgr.GetPlayer(bidder_guid); + + uint32 bidder_accId = 0; + + // data for gm.log + if( sWorld.getConfig(CONFIG_GM_LOG_TRADE) ) + { + uint32 bidder_security = 0; + std::string bidder_name; + if (bidder) + { + bidder_accId = bidder->GetSession()->GetAccountId(); + bidder_security = bidder->GetSession()->GetSecurity(); + bidder_name = bidder->GetName(); + } + else + { + bidder_accId = objmgr.GetPlayerAccountIdByGUID(bidder_guid); + bidder_security = accmgr.GetSecurity(bidder_accId); + + if(bidder_security > SEC_PLAYER ) // not do redundant DB requests + { + if(!objmgr.GetPlayerNameByGUID(bidder_guid,bidder_name)) + bidder_name = objmgr.GetTrinityStringForDBCLocale(LANG_UNKNOWN); + } + } + + if( bidder_security > SEC_PLAYER ) + { + std::string owner_name; + if(!objmgr.GetPlayerNameByGUID(auction->owner,owner_name)) + owner_name = objmgr.GetTrinityStringForDBCLocale(LANG_UNKNOWN); + + uint32 owner_accid = objmgr.GetPlayerAccountIdByGUID(auction->owner); + + sLog.outCommand(bidder_accId,"GM %s (Account: %u) won item in auction: %s (Entry: %u Count: %u) and pay money: %u. Original owner %s (Account: %u)", + bidder_name.c_str(),bidder_accId,pItem->GetProto()->Name1,pItem->GetEntry(),pItem->GetCount(),auction->bid,owner_name.c_str(),owner_accid); + } + } + else if(!bidder) + bidder_accId = objmgr.GetPlayerAccountIdByGUID(bidder_guid); + + // receiver exist + if(bidder || bidder_accId) + { + std::ostringstream msgAuctionWonSubject; + msgAuctionWonSubject << auction->item_template << ":0:" << AUCTION_WON; + + std::ostringstream msgAuctionWonBody; + msgAuctionWonBody.width(16); + msgAuctionWonBody << std::right << std::hex << auction->owner; + msgAuctionWonBody << std::dec << ":" << auction->bid << ":" << auction->buyout; + sLog.outDebug( "AuctionWon body string : %s", msgAuctionWonBody.str().c_str() ); + + //prepare mail data... : + uint32 itemTextId = objmgr.CreateItemText( msgAuctionWonBody.str() ); + + // set owner to bidder (to prevent delete item with sender char deleting) + // owner in `data` will set at mail receive and item extracting + CharacterDatabase.PExecute("UPDATE item_instance SET owner_guid = '%u' WHERE guid='%u'",auction->bidder,pItem->GetGUIDLow()); + CharacterDatabase.CommitTransaction(); + + MailItemsInfo mi; + mi.AddItem(auction->item_guidlow, auction->item_template, pItem); + + if (bidder) + bidder->GetSession()->SendAuctionBidderNotification( auction->GetHouseId(), auction->Id, bidder_guid, 0, 0, auction->item_template); + else + RemoveAItem(pItem->GetGUIDLow()); // we have to remove the item, before we delete it !! + + // will delete item or place to receiver mail list + WorldSession::SendMailTo(bidder, MAIL_AUCTION, MAIL_STATIONERY_AUCTION, auction->GetHouseId(), auction->bidder, msgAuctionWonSubject.str(), itemTextId, &mi, 0, 0, MAIL_CHECK_MASK_AUCTION); + } + // receiver not exist + else + { + CharacterDatabase.PExecute("DELETE FROM item_instance WHERE guid='%u'", pItem->GetGUIDLow()); + RemoveAItem(pItem->GetGUIDLow()); // we have to remove the item, before we delete it !! + delete pItem; + } +} + +void AuctionHouseMgr::SendAuctionSalePendingMail( AuctionEntry * auction ) +{ + uint64 owner_guid = MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER); + Player *owner = objmgr.GetPlayer(owner_guid); + + // owner exist (online or offline) + if(owner || objmgr.GetPlayerAccountIdByGUID(owner_guid)) + { + std::ostringstream msgAuctionSalePendingSubject; + msgAuctionSalePendingSubject << auction->item_template << ":0:" << AUCTION_SALE_PENDING; + + std::ostringstream msgAuctionSalePendingBody; + uint32 auctionCut = auction->GetAuctionCut(); + + time_t distrTime = time(NULL) + HOUR; + + msgAuctionSalePendingBody.width(16); + msgAuctionSalePendingBody << std::right << std::hex << auction->bidder; + msgAuctionSalePendingBody << std::dec << ":" << auction->bid << ":" << auction->buyout; + msgAuctionSalePendingBody << ":" << auction->deposit << ":" << auctionCut << ":0:"; + msgAuctionSalePendingBody << secsToTimeBitFields(distrTime); + + sLog.outDebug("AuctionSalePending body string : %s", msgAuctionSalePendingBody.str().c_str()); + + uint32 itemTextId = objmgr.CreateItemText( msgAuctionSalePendingBody.str() ); + + WorldSession::SendMailTo(owner, MAIL_AUCTION, MAIL_STATIONERY_AUCTION, auction->GetHouseId(), auction->owner, msgAuctionSalePendingSubject.str(), itemTextId, NULL, 0, 0, MAIL_CHECK_MASK_AUCTION); + } +} + +//call this method to send mail to auction owner, when auction is successful, it does not clear ram +void AuctionHouseMgr::SendAuctionSuccessfulMail( AuctionEntry * auction ) +{ + uint64 owner_guid = MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER); + Player *owner = objmgr.GetPlayer(owner_guid); + + uint32 owner_accId = 0; + if(!owner) + owner_accId = objmgr.GetPlayerAccountIdByGUID(owner_guid); + + // owner exist + if(owner || owner_accId) + { + std::ostringstream msgAuctionSuccessfulSubject; + msgAuctionSuccessfulSubject << auction->item_template << ":0:" << AUCTION_SUCCESSFUL; + + std::ostringstream auctionSuccessfulBody; + uint32 auctionCut = auction->GetAuctionCut(); + + auctionSuccessfulBody.width(16); + auctionSuccessfulBody << std::right << std::hex << auction->bidder; + auctionSuccessfulBody << std::dec << ":" << auction->bid << ":" << auction->buyout; + auctionSuccessfulBody << ":" << auction->deposit << ":" << auctionCut; + + sLog.outDebug("AuctionSuccessful body string : %s", auctionSuccessfulBody.str().c_str()); + + uint32 itemTextId = objmgr.CreateItemText( auctionSuccessfulBody.str() ); + + uint32 profit = auction->bid + auction->deposit - auctionCut; + + if (owner) + { + //send auction owner notification, bidder must be current! + owner->GetSession()->SendAuctionOwnerNotification( auction ); + } + + WorldSession::SendMailTo(owner, MAIL_AUCTION, MAIL_STATIONERY_AUCTION, auction->GetHouseId(), auction->owner, msgAuctionSuccessfulSubject.str(), itemTextId, NULL, profit, 0, MAIL_CHECK_MASK_AUCTION, HOUR); + } +} + +//does not clear ram +void AuctionHouseMgr::SendAuctionExpiredMail( AuctionEntry * auction ) +{ //return an item in auction to its owner by mail + Item *pItem = GetAItem(auction->item_guidlow); + if(!pItem) + { + sLog.outError("Auction item (GUID: %u) not found, and lost.",auction->item_guidlow); + return; + } + + uint64 owner_guid = MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER); + Player *owner = objmgr.GetPlayer(owner_guid); + + uint32 owner_accId = 0; + if(!owner) + owner_accId = objmgr.GetPlayerAccountIdByGUID(owner_guid); + + // owner exist + if(owner || owner_accId) + { + std::ostringstream subject; + subject << auction->item_template << ":0:" << AUCTION_EXPIRED; + + if ( owner ) + owner->GetSession()->SendAuctionOwnerNotification( auction ); + else + RemoveAItem(pItem->GetGUIDLow()); // we have to remove the item, before we delete it !! + + MailItemsInfo mi; + mi.AddItem(auction->item_guidlow, auction->item_template, pItem); + + // will delete item or place to receiver mail list + WorldSession::SendMailTo(owner, MAIL_AUCTION, MAIL_STATIONERY_AUCTION, auction->GetHouseId(), GUID_LOPART(owner_guid), subject.str(), 0, &mi, 0, 0, MAIL_CHECK_MASK_NONE); + } + // owner not found + else + { + CharacterDatabase.PExecute("DELETE FROM item_instance WHERE guid='%u'",pItem->GetGUIDLow()); + RemoveAItem(pItem->GetGUIDLow()); // we have to remove the item, before we delete it !! + delete pItem; + } +} + +void AuctionHouseMgr::LoadAuctionItems() +{ + // data needs to be at first place for Item::LoadFromDB + QueryResult *result = CharacterDatabase.Query( "SELECT data,itemguid,item_template FROM auctionhouse JOIN item_instance ON itemguid = guid" ); + + if( !result ) + { + barGoLink bar(1); + bar.step(); + sLog.outString(""); + sLog.outString(">> Loaded 0 auction items"); + return; + } + + barGoLink bar( result->GetRowCount() ); + + uint32 count = 0; + + Field *fields; + do + { + bar.step(); + + fields = result->Fetch(); + uint32 item_guid = fields[1].GetUInt32(); + uint32 item_template = fields[2].GetUInt32(); + + ItemPrototype const *proto = objmgr.GetItemPrototype(item_template); + + if(!proto) + { + sLog.outError( "ObjectMgr::LoadAuctionItems: Unknown item (GUID: %u id: #%u) in auction, skipped.", item_guid,item_template); + continue; + } + + Item *item = NewItemOrBag(proto); + + if(!item->LoadFromDB(item_guid,0, result)) + { + delete item; + continue; + } + AddAItem(item); + + ++count; + } + while( result->NextRow() ); + delete result; + + sLog.outString(); + sLog.outString( ">> Loaded %u auction items", count ); +} + +void AuctionHouseMgr::LoadAuctions() +{ + QueryResult *result = CharacterDatabase.Query("SELECT COUNT(*) FROM auctionhouse"); + if( !result ) + { + barGoLink bar(1); + bar.step(); + sLog.outString(""); + sLog.outString(">> Loaded 0 auctions. DB table `auctionhouse` is empty."); + return; + } + + Field *fields = result->Fetch(); + uint32 AuctionCount=fields[0].GetUInt32(); + delete result; + + if(!AuctionCount) + { + barGoLink bar(1); + bar.step(); + sLog.outString(""); + sLog.outString(">> Loaded 0 auctions. DB table `auctionhouse` is empty."); + return; + } + + result = CharacterDatabase.Query( "SELECT id,auctioneerguid,itemguid,item_template,itemowner,buyoutprice,time,buyguid,lastbid,startbid,deposit FROM auctionhouse" ); + if( !result ) + { + barGoLink bar(1); + bar.step(); + sLog.outString(""); + sLog.outString(">> Loaded 0 auctions. DB table `auctionhouse` is empty."); + return; + } + + barGoLink bar( AuctionCount ); + + AuctionEntry *aItem; + + do + { + fields = result->Fetch(); + + bar.step(); + + aItem = new AuctionEntry; + aItem->Id = fields[0].GetUInt32(); + aItem->auctioneer = fields[1].GetUInt32(); + aItem->item_guidlow = fields[2].GetUInt32(); + aItem->item_template = fields[3].GetUInt32(); + aItem->owner = fields[4].GetUInt32(); + aItem->buyout = fields[5].GetUInt32(); + aItem->expire_time = fields[6].GetUInt32(); + aItem->bidder = fields[7].GetUInt32(); + aItem->bid = fields[8].GetUInt32(); + aItem->startbid = fields[9].GetUInt32(); + aItem->deposit = fields[10].GetUInt32(); + + CreatureData const* auctioneerData = objmgr.GetCreatureData(aItem->auctioneer); + if(!auctioneerData) + { + aItem->DeleteFromDB(); + sLog.outError("Auction %u has not a existing auctioneer (GUID : %u)", aItem->Id, aItem->auctioneer); + delete aItem; + continue; + } + + CreatureInfo const* auctioneerInfo = objmgr.GetCreatureTemplate(auctioneerData->id); + if(!auctioneerInfo) + { + aItem->DeleteFromDB(); + sLog.outError("Auction %u has not a existing auctioneer (GUID : %u Entry: %u)", aItem->Id, aItem->auctioneer,auctioneerData->id); + delete aItem; + continue; + } + + aItem->auctionHouseEntry = AuctionHouseMgr::GetAuctionHouseEntry(auctioneerInfo->faction_A); + if(!aItem->auctionHouseEntry) + { + aItem->DeleteFromDB(); + sLog.outError("Auction %u has auctioneer (GUID : %u Entry: %u) with wrong faction %u", + aItem->Id, aItem->auctioneer,auctioneerData->id,auctioneerInfo->faction_A); + delete aItem; + continue; + } + + // check if sold item exists for guid + // and item_template in fact (GetAItem will fail if problematic in result check in ObjectMgr::LoadAuctionItems) + if ( !GetAItem( aItem->item_guidlow ) ) + { + aItem->DeleteFromDB(); + sLog.outError("Auction %u has not a existing item : %u", aItem->Id, aItem->item_guidlow); + delete aItem; + continue; + } + + GetAuctionsMap( auctioneerInfo->faction_A )->AddAuction(aItem); + + } while (result->NextRow()); + delete result; + + sLog.outString(); + sLog.outString( ">> Loaded %u auctions", AuctionCount ); +} + +void AuctionHouseMgr::AddAItem( Item* it ) +{ + ASSERT( it ); + ASSERT( mAitems.find(it->GetGUIDLow()) == mAitems.end()); + mAitems[it->GetGUIDLow()] = it; +} + +bool AuctionHouseMgr::RemoveAItem( uint32 id ) +{ + ItemMap::iterator i = mAitems.find(id); + if (i == mAitems.end()) + { + return false; + } + mAitems.erase(i); + return true; +} + +void AuctionHouseMgr::Update() +{ + mHordeAuctions.Update(); + mAllianceAuctions.Update(); + mNeutralAuctions.Update(); +} + +AuctionHouseEntry const* AuctionHouseMgr::GetAuctionHouseEntry(uint32 factionTemplateId) +{ + uint32 houseid = 7; // goblin auction house + + if(!sWorld.getConfig(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; + } + } + } + + return sAuctionHouseStore.LookupEntry(houseid); +} + +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 + itr->second->DeleteFromDB(); + 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 +{ + return uint32(auctionHouseEntry->cutPercent * bid * sWorld.getRate(RATE_AUCTION_CUT) / 100.f); +} + +/// 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; +} + +void AuctionEntry::DeleteFromDB() const +{ + //No SQL injection (Id is integer) + CharacterDatabase.PExecute("DELETE FROM auctionhouse WHERE id = '%u'",Id); +} + +void AuctionEntry::SaveToDB() const +{ + //No SQL injection (no strings) + CharacterDatabase.PExecute("INSERT INTO auctionhouse (id,auctioneerguid,itemguid,item_template,itemowner,buyoutprice,time,buyguid,lastbid,startbid,deposit) " + "VALUES ('%u', '%u', '%u', '%u', '%u', '%u', '" I64FMTD "', '%u', '%u', '%u', '%u')", + Id, auctioneer, item_guidlow, item_template, owner, buyout, (uint64)expire_time, bidder, bid, startbid, deposit); +} diff --git a/src/game/AuctionHouseMgr.h b/src/game/AuctionHouseMgr.h new file mode 100644 index 00000000000..cfc68497e47 --- /dev/null +++ b/src/game/AuctionHouseMgr.h @@ -0,0 +1,170 @@ +/* + * Copyright (C) 2005-2009 MaNGOS + * + * Copyright (C) 2008-2009 Trinity + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _AUCTION_HOUSE_MGR_H +#define _AUCTION_HOUSE_MGR_H + +#include "SharedDefines.h" +#include "Policies/Singleton.h" + +class Item; +class Player; +class WorldPacket; + +#define MIN_AUCTION_TIME (12*HOUR) + +enum AuctionError +{ + AUCTION_OK = 0, + AUCTION_INTERNAL_ERROR = 2, + AUCTION_NOT_ENOUGHT_MONEY = 3, + AUCTION_ITEM_NOT_FOUND = 4, + CANNOT_BID_YOUR_AUCTION_ERROR = 10 +}; + +enum AuctionAction +{ + AUCTION_SELL_ITEM = 0, + AUCTION_CANCEL = 1, + AUCTION_PLACE_BID = 2 +}; + +struct AuctionEntry +{ + uint32 Id; + uint32 auctioneer; // creature low guid + uint32 item_guidlow; + uint32 item_template; + uint32 owner; + uint32 startbid; //maybe useless + uint32 bid; + uint32 buyout; + time_t expire_time; + uint32 bidder; + uint32 deposit; //deposit can be calculated only when creating auction + AuctionHouseEntry const* auctionHouseEntry; // in AuctionHouse.dbc + + // helpers + uint32 GetHouseId() const { return auctionHouseEntry->houseId; } + uint32 GetHouseFaction() const { return auctionHouseEntry->faction; } + uint32 GetAuctionCut() const; + uint32 GetAuctionOutBid() const; + bool BuildAuctionInfo(WorldPacket & data) const; + void DeleteFromDB() const; + void SaveToDB() const; +}; + +//this class is used as auctionhouse instance +class AuctionHouseObject +{ + public: + AuctionHouseObject() {} + ~AuctionHouseObject() + { + for (AuctionEntryMap::iterator itr = AuctionsMap.begin(); itr != AuctionsMap.end(); ++itr) + delete itr->second; + } + + typedef std::map AuctionEntryMap; + + uint32 Getcount() { return AuctionsMap.size(); } + + AuctionEntryMap::iterator GetAuctionsBegin() {return AuctionsMap.begin();} + AuctionEntryMap::iterator GetAuctionsEnd() {return AuctionsMap.end();} + + void AddAuction(AuctionEntry *ah) + { + ASSERT( ah ); + AuctionsMap[ah->Id] = ah; + } + + AuctionEntry* GetAuction(uint32 id) const + { + AuctionEntryMap::const_iterator itr = AuctionsMap.find( id ); + return itr != AuctionsMap.end() ? itr->second : NULL; + } + + bool RemoveAuction(uint32 id) + { + 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; +}; + +class AuctionHouseMgr +{ + public: + AuctionHouseMgr(); + ~AuctionHouseMgr(); + + typedef UNORDERED_MAP ItemMap; + + AuctionHouseObject* GetAuctionsMap( uint32 factionTemplateId ); + + Item* GetAItem(uint32 id) + { + ItemMap::const_iterator itr = mAitems.find(id); + if (itr != mAitems.end()) + { + return itr->second; + } + return NULL; + } + + //auction messages + void SendAuctionWonMail( AuctionEntry * auction ); + void SendAuctionSalePendingMail( AuctionEntry * auction ); + void SendAuctionSuccessfulMail( AuctionEntry * auction ); + void SendAuctionExpiredMail( AuctionEntry * auction ); + static uint32 GetAuctionDeposit(AuctionHouseEntry const* entry, uint32 time, Item *pItem); + static AuctionHouseEntry const* GetAuctionHouseEntry(uint32 factionTemplateId); + + 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; + AuctionHouseObject mNeutralAuctions; + + ItemMap mAitems; +}; + +#define auctionmgr Trinity::Singleton::Instance() + +#endif diff --git a/src/game/AuctionHouseObject.h b/src/game/AuctionHouseObject.h deleted file mode 100644 index 83fd19d19c6..00000000000 --- a/src/game/AuctionHouseObject.h +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (C) 2005-2008 MaNGOS - * - * Copyright (C) 2008 Trinity - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef _AUCTION_HOUSE_H -#define _AUCTION_HOUSE_H - -#include "SharedDefines.h" - -#define MIN_AUCTION_TIME (12*HOUR) - -enum AuctionError -{ - AUCTION_OK = 0, - AUCTION_INTERNAL_ERROR = 2, - AUCTION_NOT_ENOUGHT_MONEY = 3, - AUCTION_ITEM_NOT_FOUND = 4, - CANNOT_BID_YOUR_AUCTION_ERROR = 10 -}; - -enum AuctionAction -{ - AUCTION_SELL_ITEM = 0, - AUCTION_CANCEL = 1, - AUCTION_PLACE_BID = 2 -}; - -struct AuctionEntry -{ - uint32 Id; - uint32 auctioneer; - uint32 item_guidlow; - uint32 item_template; - uint32 owner; - uint32 startbid; //maybe useless - uint32 bid; - uint32 buyout; - time_t time; - uint32 bidder; - uint32 deposit; //deposit can be calculated only when creating auction - uint32 location; -}; - -//this class is used as auctionhouse instance -class AuctionHouseObject -{ - public: - AuctionHouseObject() {} - ~AuctionHouseObject() - { - for (AuctionEntryMap::iterator itr = AuctionsMap.begin(); itr != AuctionsMap.end(); ++itr) - delete itr->second; - } - - typedef std::map AuctionEntryMap; - - uint32 Getcount() { return AuctionsMap.size(); } - - AuctionEntryMap::iterator GetAuctionsBegin() {return AuctionsMap.begin();} - AuctionEntryMap::iterator GetAuctionsEnd() {return AuctionsMap.end();} - - void AddAuction(AuctionEntry *ah) - { - ASSERT( ah ); - AuctionsMap[ah->Id] = ah; - } - - AuctionEntry* GetAuction(uint32 id) const - { - AuctionEntryMap::const_iterator itr = AuctionsMap.find( id ); - if( itr != AuctionsMap.end() ) - return itr->second; - return NULL; - } - - bool RemoveAuction(uint32 id) - { - AuctionEntryMap::iterator i = AuctionsMap.find(id); - if (i == AuctionsMap.end()) - { - return false; - } - AuctionsMap.erase(i); - return true; - } - - private: - AuctionEntryMap AuctionsMap; -}; -#endif - diff --git a/src/game/CMakeLists.txt b/src/game/CMakeLists.txt index bcd85792b04..1f8cd447449 100644 --- a/src/game/CMakeLists.txt +++ b/src/game/CMakeLists.txt @@ -12,10 +12,11 @@ SET(game_STAT_SRCS ArenaTeam.cpp ArenaTeam.h ArenaTeamHandler.cpp - AuctionHouse.cpp AuctionHouseBot.cpp AuctionHouseBot.h - AuctionHouseObject.h + AuctionHouseHandler.cpp + AuctionHouseMgr.cpp + AuctionHouseMgr.h Bag.cpp Bag.h BattleGround.cpp diff --git a/src/game/Chat.cpp b/src/game/Chat.cpp index e45266ad531..ee8d78383aa 100644 --- a/src/game/Chat.cpp +++ b/src/game/Chat.cpp @@ -300,6 +300,7 @@ ChatCommand * ChatHandler::getCommandTable() { "locales_npc_text", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadLocalesNpcTextCommand, "", NULL }, { "locales_page_text", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadLocalesPageTextCommand, "", NULL }, { "locales_quest", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadLocalesQuestCommand, "", NULL }, + { "auctions", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadAuctionsCommand, "", NULL }, { "waypoint_scripts", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadWpScriptsCommand, "", NULL }, { "gm_tickets", SEC_ADMINISTRATOR, true, &ChatHandler::HandleGMTicketReloadCommand, "", NULL }, diff --git a/src/game/Chat.h b/src/game/Chat.h index c35354b810f..c66d5e4dee7 100644 --- a/src/game/Chat.h +++ b/src/game/Chat.h @@ -275,6 +275,7 @@ class ChatHandler bool HandleReloadLocalesNpcTextCommand(const char* args); bool HandleReloadLocalesPageTextCommand(const char* args); bool HandleReloadLocalesQuestCommand(const char* args); + bool HandleReloadAuctionsCommand(const char* args); bool HandleInstanceListBindsCommand(const char* args); bool HandleInstanceUnbindCommand(const char* args); diff --git a/src/game/Level3.cpp b/src/game/Level3.cpp index 6c3ec1a9806..533f0707b47 100644 --- a/src/game/Level3.cpp +++ b/src/game/Level3.cpp @@ -1,7 +1,7 @@ /* -* Copyright (C) 2005-2008 MaNGOS +* Copyright (C) 2005-2009 MaNGOS * -* Copyright (C) 2008 Trinity +* Copyright (C) 2008-2009 Trinity * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,6 +24,7 @@ #include "WorldSession.h" #include "World.h" #include "ObjectMgr.h" +#include "AuctionHouseMgr.h" #include "AccountMgr.h" #include "PlayerDump.h" #include "SpellMgr.h" @@ -149,28 +150,42 @@ bool ChatHandler::HandleAHBotOptionsCommand(const char* args) char * param6 = strtok(NULL, " "); char * param7 = strtok(NULL, " "); char * param8 = strtok(NULL, " "); - if ((!ahMapIdStr) || (!param1) || (!param2) || (!param3) || (!param4) || (!param5) || (!param6) || (!param7) || (!param8)) - { - PSendSysMessage("Syntax is: ahbotoptions percentages $ahMapID (2, 6 or 7) $1 $2 $3 $4 $5 $6 $7 $8"); - PSendSysMessage("1 WhiteTradeGoods 2 GreenTradeGoods 3 BlueTradeGoods 4 PurpleTradeGoods"); - PSendSysMessage("5 WhiteItems 6 GreenItems 7 BlueItems 8 PurpleItems"); + char * param9 = strtok(NULL, " "); + char * param10 = strtok(NULL, " "); + char * param11 = strtok(NULL, " "); + char * param12 = strtok(NULL, " "); + char * param13 = strtok(NULL, " "); + char * param14 = strtok(NULL, " "); + if ((!ahMapIdStr) || (!param14)) + { + PSendSysMessage("Syntax is: ahbotoptions percentages $ahMapID (2, 6 or 7) $1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12 $13 $14"); + PSendSysMessage("1 GreyTradeGoods 2 WhiteTradeGoods 3 GreenTradeGoods 4 BlueTradeGoods 5 PurpleTradeGoods"); + PSendSysMessage("6 OrangeTradeGoods 7 YellowTradeGoods 8 GreyItems 9 WhiteItems 10 GreenItems 11 BlueItems"); + PSendSysMessage("12 PurpleItems 13 OrangeItems 14 YellowItems"); PSendSysMessage("The total must add up to 100%"); return false; } - uint32 wtg = (uint32) strtoul(param1, NULL, 0); - uint32 gtg = (uint32) strtoul(param2, NULL, 0); - uint32 btg = (uint32) strtoul(param3, NULL, 0); - uint32 ptg = (uint32) strtoul(param4, NULL, 0); - uint32 wi = (uint32) strtoul(param5, NULL, 0); - uint32 gi = (uint32) strtoul(param6, NULL, 0); - uint32 bi = (uint32) strtoul(param7, NULL, 0); - uint32 pi = (uint32) strtoul(param8, NULL, 0); - uint32 totalPercent = wtg + gtg + btg + ptg + wi + gi + bi + pi; + uint32 greytg = (uint32) strtoul(param1, NULL, 0); + uint32 whitetg = (uint32) strtoul(param2, NULL, 0); + uint32 greentg = (uint32) strtoul(param3, NULL, 0); + uint32 bluetg = (uint32) strtoul(param3, NULL, 0); + uint32 purpletg = (uint32) strtoul(param5, NULL, 0); + uint32 orangetg = (uint32) strtoul(param6, NULL, 0); + uint32 yellowtg = (uint32) strtoul(param7, NULL, 0); + uint32 greyi = (uint32) strtoul(param8, NULL, 0); + uint32 whitei = (uint32) strtoul(param9, NULL, 0); + uint32 greeni = (uint32) strtoul(param10, NULL, 0); + uint32 bluei = (uint32) strtoul(param11, NULL, 0); + uint32 purplei = (uint32) strtoul(param12, NULL, 0); + uint32 orangei = (uint32) strtoul(param13, NULL, 0); + uint32 yellowi = (uint32) strtoul(param14, NULL, 0); + uint32 totalPercent = greytg + whitetg + greentg + bluetg + purpletg + orangetg + yellowtg + greyi + whitei + greeni + bluei + purplei + orangei + yellowi; if ((totalPercent == 0) || (totalPercent != 100)) { - PSendSysMessage("Syntax is: ahbotoptions percentages $ahMapID (2, 6 or 7) $1 $2 $3 $4 $5 $6 $7 $8"); - PSendSysMessage("1 WhiteTradeGoods 2 GreenTradeGoods 3 BlueTradeGoods 4 PurpleTradeGoods"); - PSendSysMessage("5 WhiteItems 6 GreenItems 7 BlueItems 8 PurpleItems"); + PSendSysMessage("Syntax is: ahbotoptions percentages $ahMapID (2, 6 or 7) $1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12 $13 $14"); + PSendSysMessage("1 GreyTradeGoods 2 WhiteTradeGoods 3 GreenTradeGoods 4 BlueTradeGoods 5 PurpleTradeGoods"); + PSendSysMessage("6 OrangeTradeGoods 7 YellowTradeGoods 8 GreyItems 9 WhiteItems 10 GreenItems 11 BlueItems"); + PSendSysMessage("12 PurpleItems 13 OrangeItems 14 YellowItems"); PSendSysMessage("The total must add up to 100%"); return false; } @@ -191,6 +206,18 @@ bool ChatHandler::HandleAHBotOptionsCommand(const char* args) strcat(param, param7); strcat(param, " "); strcat(param, param8); + strcat(param, " "); + strcat(param, param9); + strcat(param, " "); + strcat(param, param10); + strcat(param, " "); + strcat(param, param11); + strcat(param, " "); + strcat(param, param12); + strcat(param, " "); + strcat(param, param13); + strcat(param, " "); + strcat(param, param14); AuctionHouseBotCommands(5, ahMapID, NULL, param); } else if (strncmp(opt,"minprice",l) == 0) @@ -199,10 +226,14 @@ bool ChatHandler::HandleAHBotOptionsCommand(const char* args) char * param2 = strtok(NULL, " "); if ((!ahMapIdStr) || (!param1) || (!param2)) { - PSendSysMessage("Syntax is: ahbotoptions minprice $ahMapID (2, 6 or 7) $color (white, green, blue or purple) $price"); + PSendSysMessage("Syntax is: ahbotoptions minprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $price"); return false; } - if (strncmp(param1,"white",l) == 0) + if (strncmp(param1,"grey",l) == 0) + { + AuctionHouseBotCommands(6, ahMapID, AHB_GREY, param2); + } + else if (strncmp(param1,"white",l) == 0) { AuctionHouseBotCommands(6, ahMapID, AHB_WHITE, param2); } @@ -214,13 +245,21 @@ bool ChatHandler::HandleAHBotOptionsCommand(const char* args) { AuctionHouseBotCommands(6, ahMapID, AHB_BLUE, param2); } - else if (strncmp(param1,"purple",l) == 0) + else if (strncmp(param1,"purple",l) == 0) { AuctionHouseBotCommands(6, ahMapID, AHB_PURPLE, param2); } + else if (strncmp(param1,"orange",l) == 0) + { + AuctionHouseBotCommands(6, ahMapID, AHB_ORANGE, param2); + } + else if (strncmp(param1,"yellow",l) == 0) + { + AuctionHouseBotCommands(6, ahMapID, AHB_YELLOW, param2); + } else { - PSendSysMessage("Syntax is: ahbotoptions minprice $ahMapID (2, 6 or 7) $color (white, green, blue or purple) $price"); + PSendSysMessage("Syntax is: ahbotoptions minprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $price"); return false; } } @@ -230,10 +269,14 @@ bool ChatHandler::HandleAHBotOptionsCommand(const char* args) char * param2 = strtok(NULL, " "); if ((!ahMapIdStr) || (!param1) || (!param2)) { - PSendSysMessage("Syntax is: ahbotoptions maxprice $ahMapID (2, 6 or 7) $color (white, green, blue or purple) $price"); + PSendSysMessage("Syntax is: ahbotoptions maxprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $price"); return false; } - if (strncmp(param1,"white",l) == 0) + if (strncmp(param1,"grey",l) == 0) + { + AuctionHouseBotCommands(7, ahMapID, AHB_GREY, param2); + } + else if (strncmp(param1,"white",l) == 0) { AuctionHouseBotCommands(7, ahMapID, AHB_WHITE, param2); } @@ -245,13 +288,21 @@ bool ChatHandler::HandleAHBotOptionsCommand(const char* args) { AuctionHouseBotCommands(7, ahMapID, AHB_BLUE, param2); } - else if (strncmp(param1,"purple",l) == 0) + else if (strncmp(param1,"purple",l) == 0) { AuctionHouseBotCommands(7, ahMapID, AHB_PURPLE, param2); } + else if (strncmp(param1,"orange",l) == 0) + { + AuctionHouseBotCommands(7, ahMapID, AHB_ORANGE, param2); + } + else if (strncmp(param1,"yellow",l) == 0) + { + AuctionHouseBotCommands(7, ahMapID, AHB_YELLOW, param2); + } else { - PSendSysMessage("Syntax is: ahbotoptions maxprice $ahMapID (2, 6 or 7) $color (white, green, blue or purple) $price"); + PSendSysMessage("Syntax is: ahbotoptions maxprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $price"); return false; } } @@ -261,7 +312,7 @@ bool ChatHandler::HandleAHBotOptionsCommand(const char* args) char * param2 = strtok(NULL, " "); if ((!ahMapIdStr) || (!param1) || (!param2)) { - PSendSysMessage("Syntax is: ahbotoptions minbidprice $ahMapID (2, 6 or 7) $color (white, green, blue or purple) $price"); + PSendSysMessage("Syntax is: ahbotoptions minbidprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $price"); return false; } uint32 minBidPrice = (uint32) strtoul(param2, NULL, 0); @@ -270,7 +321,11 @@ bool ChatHandler::HandleAHBotOptionsCommand(const char* args) PSendSysMessage("The min bid price multiplier must be between 1 and 100"); return false; } - if (strncmp(param1,"white",l) == 0) + if (strncmp(param1,"grey",l) == 0) + { + AuctionHouseBotCommands(8, ahMapID, AHB_GREY, param2); + } + else if (strncmp(param1,"white",l) == 0) { AuctionHouseBotCommands(8, ahMapID, AHB_WHITE, param2); } @@ -282,13 +337,21 @@ bool ChatHandler::HandleAHBotOptionsCommand(const char* args) { AuctionHouseBotCommands(8, ahMapID, AHB_BLUE, param2); } - else if (strncmp(param1,"purple",l) == 0) + else if (strncmp(param1,"purple",l) == 0) { AuctionHouseBotCommands(8, ahMapID, AHB_PURPLE, param2); } + else if (strncmp(param1,"orange",l) == 0) + { + AuctionHouseBotCommands(8, ahMapID, AHB_ORANGE, param2); + } + else if (strncmp(param1,"yellow",l) == 0) + { + AuctionHouseBotCommands(8, ahMapID, AHB_YELLOW, param2); + } else { - PSendSysMessage("Syntax is: ahbotoptions minbidprice $ahMapID (2, 6 or 7) $color (white, green, blue or purple) $price"); + PSendSysMessage("Syntax is: ahbotoptions minbidprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $price"); return false; } } @@ -298,7 +361,7 @@ bool ChatHandler::HandleAHBotOptionsCommand(const char* args) char * param2 = strtok(NULL, " "); if ((!ahMapIdStr) || (!param1) || (!param2)) { - PSendSysMessage("Syntax is: ahbotoptions maxbidprice $ahMapID (2, 6 or 7) $color (white, green, blue or purple) $price"); + PSendSysMessage("Syntax is: ahbotoptions maxbidprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $price"); return false; } uint32 maxBidPrice = (uint32) strtoul(param2, NULL, 0); @@ -307,7 +370,11 @@ bool ChatHandler::HandleAHBotOptionsCommand(const char* args) PSendSysMessage("The max bid price multiplier must be between 1 and 100"); return false; } - if (strncmp(param1,"white",l) == 0) + if (strncmp(param1,"grey",l) == 0) + { + AuctionHouseBotCommands(9, ahMapID, AHB_GREY, param2); + } + else if (strncmp(param1,"white",l) == 0) { AuctionHouseBotCommands(9, ahMapID, AHB_WHITE, param2); } @@ -319,13 +386,21 @@ bool ChatHandler::HandleAHBotOptionsCommand(const char* args) { AuctionHouseBotCommands(9, ahMapID, AHB_BLUE, param2); } - else if (strncmp(param1,"purple",l) == 0) + else if (strncmp(param1,"purple",l) == 0) { AuctionHouseBotCommands(9, ahMapID, AHB_PURPLE, param2); } + else if (strncmp(param1,"orange",l) == 0) + { + AuctionHouseBotCommands(9, ahMapID, AHB_ORANGE, param2); + } + else if (strncmp(param1,"yellow",l) == 0) + { + AuctionHouseBotCommands(9, ahMapID, AHB_YELLOW, param2); + } else { - PSendSysMessage("Syntax is: ahbotoptions max bidprice $ahMapID (2, 6 or 7) $color (white, green, blue or purple) $price"); + PSendSysMessage("Syntax is: ahbotoptions max bidprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $price"); return false; } } @@ -335,7 +410,7 @@ bool ChatHandler::HandleAHBotOptionsCommand(const char* args) char * param2 = strtok(NULL, " "); if ((!ahMapIdStr) || (!param1) || (!param2)) { - PSendSysMessage("Syntax is: ahbotoptions maxstack $ahMapID (2, 6 or 7) $color (white, green, blue or purple) $value"); + PSendSysMessage("Syntax is: ahbotoptions maxstack $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $value"); return false; } uint32 maxStack = (uint32) strtoul(param2, NULL, 0); @@ -344,7 +419,11 @@ bool ChatHandler::HandleAHBotOptionsCommand(const char* args) PSendSysMessage("maxstack can't be a negative number."); return false; } - if (strncmp(param1,"white",l) == 0) + if (strncmp(param1,"grey",l) == 0) + { + AuctionHouseBotCommands(10, ahMapID, AHB_GREY, param2); + } + else if (strncmp(param1,"white",l) == 0) { AuctionHouseBotCommands(10, ahMapID, AHB_WHITE, param2); } @@ -356,13 +435,21 @@ bool ChatHandler::HandleAHBotOptionsCommand(const char* args) { AuctionHouseBotCommands(10, ahMapID, AHB_BLUE, param2); } - else if (strncmp(param1,"purple",l) == 0) + else if (strncmp(param1,"purple",l) == 0) { AuctionHouseBotCommands(10, ahMapID, AHB_PURPLE, param2); } + else if (strncmp(param1,"orange",l) == 0) + { + AuctionHouseBotCommands(10, ahMapID, AHB_ORANGE, param2); + } + else if (strncmp(param1,"yellow",l) == 0) + { + AuctionHouseBotCommands(10, ahMapID, AHB_YELLOW, param2); + } else { - PSendSysMessage("Syntax is: ahbotoptions maxstack $ahMapID (2, 6 or 7) $color (white, green, blue or purple) $value"); + PSendSysMessage("Syntax is: ahbotoptions maxstack $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $value"); return false; } } @@ -375,7 +462,11 @@ bool ChatHandler::HandleAHBotOptionsCommand(const char* args) PSendSysMessage("Syntax is: ahbotoptions buyerprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue or purple) $price"); return false; } - if (strncmp(param1,"white",l) == 0) + if (strncmp(param1,"grey",l) == 0) + { + AuctionHouseBotCommands(11, ahMapID, AHB_GREY, param2); + } + else if (strncmp(param1,"white",l) == 0) { AuctionHouseBotCommands(11, ahMapID, AHB_WHITE, param2); } @@ -387,10 +478,18 @@ bool ChatHandler::HandleAHBotOptionsCommand(const char* args) { AuctionHouseBotCommands(11, ahMapID, AHB_BLUE, param2); } - else if (strncmp(param1,"purple",l) == 0) + else if (strncmp(param1,"purple",l) == 0) { AuctionHouseBotCommands(11, ahMapID, AHB_PURPLE, param2); } + else if (strncmp(param1,"orange",l) == 0) + { + AuctionHouseBotCommands(11, ahMapID, AHB_ORANGE, param2); + } + else if (strncmp(param1,"yellow",l) == 0) + { + AuctionHouseBotCommands(11, ahMapID, AHB_YELLOW, param2); + } else { PSendSysMessage("Syntax is: ahbotoptions buyerprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue or purple) $price"); @@ -1101,6 +1200,16 @@ bool ChatHandler::HandleLoadScriptsCommand(const char* args) return true; } +bool ChatHandler::HandleReloadAuctionsCommand(const char* args) +{ + ///- Reload dynamic data tables from the database + sLog.outString( "Re-Loading Auctions..." ); + auctionmgr.LoadAuctionItems(); + auctionmgr.LoadAuctions(); + SendGlobalGMSysMessage("Auctions reloaded."); + return true; +} + bool ChatHandler::HandleAccountSetGmLevelCommand(const char* args) { if(!*args) diff --git a/src/game/Makefile.am b/src/game/Makefile.am index ec9cbab40cb..a8a42d26a61 100644 --- a/src/game/Makefile.am +++ b/src/game/Makefile.am @@ -49,10 +49,11 @@ $(srcdir)/AnimalRandomMovementGenerator.h \ $(srcdir)/ArenaTeam.cpp \ $(srcdir)/ArenaTeam.h \ $(srcdir)/ArenaTeamHandler.cpp \ -$(srcdir)/AuctionHouse.cpp \ +$(srcdir)/AuctionHouseHandler.cpp \ $(srcdir)/AuctionHouseBot.cpp \ $(srcdir)/AuctionHouseBot.h \ -$(srcdir)/AuctionHouseObject.h \ +$(srcdir)/AuctionHouseMgr.cpp \ +$(srcdir)/AuctionHouseMgr.h \ $(srcdir)/Bag.cpp \ $(srcdir)/Bag.h \ $(srcdir)/BattleGround.cpp \ diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp index eef767b263e..a08c22450db 100644 --- a/src/game/ObjectMgr.cpp +++ b/src/game/ObjectMgr.cpp @@ -22,6 +22,7 @@ #include "Database/DatabaseEnv.h" #include "Database/SQLStorage.h" #include "Database/SQLStorageImpl.h" +#include "Policies/SingletonImp.h" #include "Log.h" #include "MapManager.h" @@ -35,7 +36,6 @@ #include "ArenaTeam.h" #include "Transports.h" #include "ProgressBar.h" -#include "Policies/SingletonImp.h" #include "Language.h" #include "GameEvent.h" #include "Spell.h" @@ -123,9 +123,9 @@ ObjectMgr::ObjectMgr() m_hiPetNumber = 1; m_ItemTextId = 1; m_mailid = 1; - m_auctionid = 1; m_guildId = 1; m_arenaTeamId = 1; + m_auctionid = 1; mGuildBankTabPrice.resize(GUILD_BANK_MAX_TABS); mGuildBankTabPrice[0] = 100; @@ -178,9 +178,6 @@ ObjectMgr::~ObjectMgr() for (CachePlayerInfoMap::iterator itr = m_mPlayerInfoMap.begin(); itr != m_mPlayerInfoMap.end(); ++itr) delete itr->second; - for(ItemMap::iterator itr = mAitems.begin(); itr != mAitems.end(); ++itr) - delete itr->second; - for (CacheVendorItemMap::iterator itr = m_mCacheVendorItemMap.begin(); itr != m_mCacheVendorItemMap.end(); ++itr) itr->second.Clear(); @@ -325,254 +322,6 @@ void ObjectMgr::RemoveArenaTeam(ArenaTeam* arenaTeam) mArenaTeamMap.erase( arenaTeam->GetId() ); } -AuctionHouseObject * ObjectMgr::GetAuctionsMap( uint32 location ) -{ - switch ( location ) - { - case 6: //horde - return & mHordeAuctions; - break; - case 2: //alliance - return & mAllianceAuctions; - break; - default: //neutral - return & mNeutralAuctions; - } -} - -uint32 ObjectMgr::GetAuctionCut(uint32 location, uint32 highBid) -{ - if (location == 7 && !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 ObjectMgr::GetAuctionDeposit(uint32 location, uint32 time, Item *pItem) -{ - float percentance; // in 0..1 - if ( location == 7 && !sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION)) - percentance = 0.75f; - else - percentance = 0.15f; - - percentance *= sWorld.getRate(RATE_AUCTION_DEPOSIT); - - 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 ObjectMgr::GetAuctionOutBid(uint32 currentBid) -{ - uint32 outbid = (currentBid / 100) * 5; - if (!outbid) - outbid = 1; - return outbid; -} - -//does not clear ram -void ObjectMgr::SendAuctionWonMail( AuctionEntry *auction ) -{ - Item *pItem = GetAItem(auction->item_guidlow); - if(!pItem) - return; - - uint64 bidder_guid = MAKE_NEW_GUID(auction->bidder, 0, HIGHGUID_PLAYER); - Player *bidder = GetPlayer(bidder_guid); - - uint32 bidder_accId = 0; - - // data for gm.log - if( sWorld.getConfig(CONFIG_GM_LOG_TRADE) ) - { - uint32 bidder_security = 0; - std::string bidder_name; - if (bidder) - { - bidder_accId = bidder->GetSession()->GetAccountId(); - bidder_security = bidder->GetSession()->GetSecurity(); - bidder_name = bidder->GetName(); - } - else - { - bidder_accId = GetPlayerAccountIdByGUID(bidder_guid); - bidder_security = accmgr.GetSecurity(bidder_accId); - - if(bidder_security > SEC_PLAYER ) // not do redundant DB requests - { - if(!GetPlayerNameByGUID(bidder_guid,bidder_name)) - bidder_name = GetTrinityStringForDBCLocale(LANG_UNKNOWN); - } - } - - if( bidder_security > SEC_PLAYER ) - { - std::string owner_name; - if(!GetPlayerNameByGUID(auction->owner,owner_name)) - owner_name = GetTrinityStringForDBCLocale(LANG_UNKNOWN); - - uint32 owner_accid = GetPlayerAccountIdByGUID(auction->owner); - - sLog.outCommand(bidder_accId,"GM %s (Account: %u) won item in auction: %s (Entry: %u Count: %u) and pay money: %u. Original owner %s (Account: %u)", - bidder_name.c_str(),bidder_accId,pItem->GetProto()->Name1,pItem->GetEntry(),pItem->GetCount(),auction->bid,owner_name.c_str(),owner_accid); - } - } - else if(!bidder) - bidder_accId = GetPlayerAccountIdByGUID(bidder_guid); - - // receiver exist - if(bidder || bidder_accId) - { - std::ostringstream msgAuctionWonSubject; - msgAuctionWonSubject << auction->item_template << ":0:" << AUCTION_WON; - - std::ostringstream msgAuctionWonBody; - msgAuctionWonBody.width(16); - msgAuctionWonBody << std::right << std::hex << auction->owner; - msgAuctionWonBody << std::dec << ":" << auction->bid << ":" << auction->buyout; - sLog.outDebug( "AuctionWon body string : %s", msgAuctionWonBody.str().c_str() ); - - //prepare mail data... : - uint32 itemTextId = CreateItemText( msgAuctionWonBody.str() ); - - // set owner to bidder (to prevent delete item with sender char deleting) - // owner in `data` will set at mail receive and item extracting - CharacterDatabase.PExecute("UPDATE item_instance SET owner_guid = '%u' WHERE guid='%u'",auction->bidder,pItem->GetGUIDLow()); - CharacterDatabase.CommitTransaction(); - - MailItemsInfo mi; - mi.AddItem(auction->item_guidlow, auction->item_template, pItem); - - if (bidder) - bidder->GetSession()->SendAuctionBidderNotification( auction->location, auction->Id, bidder_guid, 0, 0, auction->item_template); - else - RemoveAItem(pItem->GetGUIDLow()); // we have to remove the item, before we delete it !! - - // will delete item or place to receiver mail list - WorldSession::SendMailTo(bidder, MAIL_AUCTION, MAIL_STATIONERY_AUCTION, auction->location, auction->bidder, msgAuctionWonSubject.str(), itemTextId, &mi, 0, 0, MAIL_CHECK_MASK_AUCTION); - } - // receiver not exist - else - { - CharacterDatabase.PExecute("DELETE FROM item_instance WHERE guid='%u'", pItem->GetGUIDLow()); - RemoveAItem(pItem->GetGUIDLow()); // we have to remove the item, before we delete it !! - delete pItem; - } -} - -void ObjectMgr::SendAuctionSalePendingMail( AuctionEntry * auction ) -{ - uint64 owner_guid = MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER); - Player *owner = GetPlayer(owner_guid); - - // owner exist (online or offline) - if(owner || GetPlayerAccountIdByGUID(owner_guid)) - { - std::ostringstream msgAuctionSalePendingSubject; - msgAuctionSalePendingSubject << auction->item_template << ":0:" << AUCTION_SALE_PENDING; - - std::ostringstream msgAuctionSalePendingBody; - uint32 auctionCut = GetAuctionCut(auction->location, auction->bid); - - time_t distrTime = time(NULL) + HOUR; - - msgAuctionSalePendingBody.width(16); - msgAuctionSalePendingBody << std::right << std::hex << auction->bidder; - msgAuctionSalePendingBody << std::dec << ":" << auction->bid << ":" << auction->buyout; - msgAuctionSalePendingBody << ":" << auction->deposit << ":" << auctionCut << ":0:"; - msgAuctionSalePendingBody << secsToTimeBitFields(distrTime); - - sLog.outDebug("AuctionSalePending body string : %s", msgAuctionSalePendingBody.str().c_str()); - - uint32 itemTextId = CreateItemText( msgAuctionSalePendingBody.str() ); - - WorldSession::SendMailTo(owner, MAIL_AUCTION, MAIL_STATIONERY_AUCTION, auction->location, auction->owner, msgAuctionSalePendingSubject.str(), itemTextId, NULL, 0, 0, MAIL_CHECK_MASK_AUCTION); - } -} - -//call this method to send mail to auction owner, when auction is successful, it does not clear ram -void ObjectMgr::SendAuctionSuccessfulMail( AuctionEntry * auction ) -{ - uint64 owner_guid = MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER); - Player *owner = GetPlayer(owner_guid); - - uint32 owner_accId = 0; - if(!owner) - owner_accId = GetPlayerAccountIdByGUID(owner_guid); - - // owner exist - if(owner || owner_accId) - { - std::ostringstream msgAuctionSuccessfulSubject; - msgAuctionSuccessfulSubject << auction->item_template << ":0:" << AUCTION_SUCCESSFUL; - - std::ostringstream auctionSuccessfulBody; - uint32 auctionCut = GetAuctionCut(auction->location, auction->bid); - - auctionSuccessfulBody.width(16); - auctionSuccessfulBody << std::right << std::hex << auction->bidder; - auctionSuccessfulBody << std::dec << ":" << auction->bid << ":" << auction->buyout; - auctionSuccessfulBody << ":" << auction->deposit << ":" << auctionCut; - - sLog.outDebug("AuctionSuccessful body string : %s", auctionSuccessfulBody.str().c_str()); - - uint32 itemTextId = CreateItemText( auctionSuccessfulBody.str() ); - - uint32 profit = auction->bid + auction->deposit - auctionCut; - - if (owner) - { - //send auction owner notification, bidder must be current! - owner->GetSession()->SendAuctionOwnerNotification( auction ); - } - - WorldSession::SendMailTo(owner, MAIL_AUCTION, MAIL_STATIONERY_AUCTION, auction->location, auction->owner, msgAuctionSuccessfulSubject.str(), itemTextId, NULL, profit, 0, MAIL_CHECK_MASK_AUCTION, HOUR); - } -} - -//does not clear ram -void ObjectMgr::SendAuctionExpiredMail( AuctionEntry * auction ) -{ //return an item in auction to its owner by mail - Item *pItem = GetAItem(auction->item_guidlow); - if(!pItem) - { - sLog.outError("Auction item (GUID: %u) not found, and lost.",auction->item_guidlow); - return; - } - - uint64 owner_guid = MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER); - Player *owner = GetPlayer(owner_guid); - - uint32 owner_accId = 0; - if(!owner) - owner_accId = GetPlayerAccountIdByGUID(owner_guid); - - // owner exist - if(owner || owner_accId) - { - std::ostringstream subject; - subject << auction->item_template << ":0:" << AUCTION_EXPIRED; - - if ( owner ) - owner->GetSession()->SendAuctionOwnerNotification( auction ); - else - RemoveAItem(pItem->GetGUIDLow()); // we have to remove the item, before we delete it !! - - MailItemsInfo mi; - mi.AddItem(auction->item_guidlow, auction->item_template, pItem); - - // will delete item or place to receiver mail list - WorldSession::SendMailTo(owner, MAIL_AUCTION, MAIL_STATIONERY_AUCTION, auction->location, GUID_LOPART(owner_guid), subject.str(), 0, &mi, 0, 0, MAIL_CHECK_MASK_NONE); - } - // owner not found - else - { - CharacterDatabase.PExecute("DELETE FROM item_instance WHERE guid='%u'",pItem->GetGUIDLow()); - RemoveAItem(pItem->GetGUIDLow()); // we have to remove the item, before we delete it !! - delete pItem; - } -} - CreatureInfo const* ObjectMgr::GetCreatureTemplate(uint32 id) { return sCreatureStorage.LookupEntry(id); @@ -1498,65 +1247,6 @@ uint32 ObjectMgr::GetPlayerAccountIdByPlayerName(const std::string& name) const return 0; } -void ObjectMgr::LoadAuctions() -{ - QueryResult *result = CharacterDatabase.Query("SELECT COUNT(*) FROM auctionhouse"); - if( !result ) - return; - - Field *fields = result->Fetch(); - uint32 AuctionCount=fields[0].GetUInt32(); - delete result; - - if(!AuctionCount) - return; - - result = CharacterDatabase.Query( "SELECT id,auctioneerguid,itemguid,item_template,itemowner,buyoutprice,time,buyguid,lastbid,startbid,deposit,location FROM auctionhouse" ); - if( !result ) - return; - - barGoLink bar( AuctionCount ); - - AuctionEntry *aItem; - - do - { - fields = result->Fetch(); - - bar.step(); - - aItem = new AuctionEntry; - aItem->Id = fields[0].GetUInt32(); - aItem->auctioneer = fields[1].GetUInt32(); - aItem->item_guidlow = fields[2].GetUInt32(); - aItem->item_template = fields[3].GetUInt32(); - aItem->owner = fields[4].GetUInt32(); - aItem->buyout = fields[5].GetUInt32(); - aItem->time = fields[6].GetUInt32(); - aItem->bidder = fields[7].GetUInt32(); - aItem->bid = fields[8].GetUInt32(); - aItem->startbid = fields[9].GetUInt32(); - aItem->deposit = fields[10].GetUInt32(); - aItem->location = fields[11].GetUInt8(); - //check if sold item exists - if ( GetAItem( aItem->item_guidlow ) ) - { - GetAuctionsMap( aItem->location )->AddAuction(aItem); - } - else - { - CharacterDatabase.PExecute("DELETE FROM auctionhouse WHERE id = '%u'",aItem->Id); - sLog.outError("Auction %u has not a existing item : %u", aItem->Id, aItem->item_guidlow); - delete aItem; - } - } while (result->NextRow()); - delete result; - - sLog.outString(); - sLog.outString( ">> Loaded %u auctions", AuctionCount ); - sLog.outString(); -} - void ObjectMgr::LoadItemLocales() { mItemLocaleMap.clear(); // need for reload case @@ -1932,53 +1622,6 @@ void ObjectMgr::LoadItemPrototypes() sItemStore.Clear(); } -void ObjectMgr::LoadAuctionItems() -{ - QueryResult *result = CharacterDatabase.Query( "SELECT itemguid,item_template FROM auctionhouse" ); - - if( !result ) - return; - - barGoLink bar( result->GetRowCount() ); - - uint32 count = 0; - - Field *fields; - do - { - bar.step(); - - fields = result->Fetch(); - uint32 item_guid = fields[0].GetUInt32(); - uint32 item_template = fields[1].GetUInt32(); - - ItemPrototype const *proto = GetItemPrototype(item_template); - - if(!proto) - { - sLog.outError( "ObjectMgr::LoadAuctionItems: Unknown item (GUID: %u id: #%u) in auction, skipped.", item_guid,item_template); - continue; - } - - Item *item = NewItemOrBag(proto); - - if(!item->LoadFromDB(item_guid,0)) - { - delete item; - continue; - } - AddAItem(item); - - ++count; - } - while( result->NextRow() ); - - delete result; - - sLog.outString(); - sLog.outString( ">> Loaded %u auction items", count ); -} - void ObjectMgr::LoadPetLevelInfo() { // Loading levels data diff --git a/src/game/ObjectMgr.h b/src/game/ObjectMgr.h index dc71843a735..72497170b3a 100644 --- a/src/game/ObjectMgr.h +++ b/src/game/ObjectMgr.h @@ -34,7 +34,6 @@ #include "ItemPrototype.h" #include "NPCHandler.h" #include "Database/DatabaseEnv.h" -#include "AuctionHouseObject.h" #include "Mail.h" #include "Map.h" #include "ObjectAccessor.h" @@ -368,42 +367,6 @@ class ObjectMgr return sInstanceTemplate.LookupEntry(map); } - Item* GetAItem(uint32 id) - { - ItemMap::const_iterator itr = mAitems.find(id); - if (itr != mAitems.end()) - { - return itr->second; - } - return NULL; - } - void AddAItem(Item* it) - { - ASSERT( it ); - ASSERT( mAitems.find(it->GetGUIDLow()) == mAitems.end()); - mAitems[it->GetGUIDLow()] = it; - } - bool RemoveAItem(uint32 id) - { - ItemMap::iterator i = mAitems.find(id); - if (i == mAitems.end()) - { - return false; - } - mAitems.erase(i); - return true; - } - AuctionHouseObject * GetAuctionsMap( uint32 location ); - - //auction messages - void SendAuctionWonMail( AuctionEntry * auction ); - void SendAuctionSalePendingMail( AuctionEntry * auction ); - void SendAuctionSuccessfulMail( AuctionEntry * auction ); - void SendAuctionExpiredMail( AuctionEntry * auction ); - static uint32 GetAuctionCut( uint32 location, uint32 highBid ); - static uint32 GetAuctionDeposit(uint32 location, uint32 time, Item *pItem); - static uint32 GetAuctionOutBid(uint32 currentBid); - PetLevelInfo const* GetPetLevelInfo(uint32 creature_id, uint32 level) const; PlayerClassInfo const* GetPlayerClassInfo(uint32 class_) const @@ -577,9 +540,6 @@ class ObjectMgr void LoadItemTexts(); void LoadPageTexts(); - //load first auction items, because of check if item exists, when loading - void LoadAuctionItems(); - void LoadAuctions(); void LoadPlayerInfo(); void LoadPetLevelInfo(); void LoadExplorationBaseXP(); @@ -847,14 +807,9 @@ class ObjectMgr ArenaTeamMap mArenaTeamMap; ItemMap mItems; - ItemMap mAitems; ItemTextMap mItemTexts; - AuctionHouseObject mHordeAuctions; - AuctionHouseObject mAllianceAuctions; - AuctionHouseObject mNeutralAuctions; - QuestAreaTriggerMap mQuestAreaTriggerMap; BattleMastersMap mBattleMastersMap; TavernAreaTriggerSet mTavernAreaTriggerSet; diff --git a/src/game/PlayerDump.h b/src/game/PlayerDump.h index 2fbdf513ce5..211a000103d 100644 --- a/src/game/PlayerDump.h +++ b/src/game/PlayerDump.h @@ -20,28 +20,6 @@ #ifndef _PLAYER_DUMP_H #define _PLAYER_DUMP_H -/* -#include "Log.h" -#include "Object.h" -#include "Bag.h" -#include "Creature.h" -#include "Player.h" -#include "DynamicObject.h" -#include "GameObject.h" -#include "Corpse.h" -#include "QuestDef.h" -#include "Path.h" -#include "ItemPrototype.h" -#include "NPCHandler.h" -#include "Database/DatabaseEnv.h" -#include "AuctionHouseObject.h" -#include "Mail.h" -#include "Map.h" -#include "ObjectAccessor.h" -#include "ObjectDefines.h" -#include "Policies/Singleton.h" -#include "Database/SQLStorage.h" -*/ #include #include #include diff --git a/src/game/World.cpp b/src/game/World.cpp index 9a2caa078ce..1ef570fe0d7 100644 --- a/src/game/World.cpp +++ b/src/game/World.cpp @@ -37,6 +37,7 @@ #include "SkillDiscovery.h" #include "World.h" #include "AccountMgr.h" +#include "AuctionHouseMgr.h" #include "ObjectMgr.h" #include "SpellMgr.h" #include "Chat.h" @@ -278,7 +279,7 @@ bool World::HasRecentlyDisconnected(WorldSession* session) if(!session) return false; if(uint32 tolerance = getConfig(CONFIG_INTERVAL_DISCONNECT_TOLERANCE)) - { + { for(DisconnectMap::iterator i = m_disconnects.begin(); i != m_disconnects.end(); ++i) { if(difftime(i->second, time(NULL)) < tolerance) @@ -624,7 +625,7 @@ void World::LoadConfigSettings(bool reload) m_configs[CONFIG_ALLOW_TWO_SIDE_INTERACTION_CHANNEL] = sConfig.GetBoolDefault("AllowTwoSide.Interaction.Channel",false); m_configs[CONFIG_ALLOW_TWO_SIDE_INTERACTION_GROUP] = sConfig.GetBoolDefault("AllowTwoSide.Interaction.Group",false); m_configs[CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD] = sConfig.GetBoolDefault("AllowTwoSide.Interaction.Guild",false); - m_configs[CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION] = sConfig.GetBoolDefault("AllowTwoSide.Interaction.Auction",false); + m_configs[CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION] = sConfig.GetBoolDefault("AllowTwoSide.Interaction.Auction",false); m_configs[CONFIG_ALLOW_TWO_SIDE_INTERACTION_MAIL] = sConfig.GetBoolDefault("AllowTwoSide.Interaction.Mail",false); m_configs[CONFIG_ALLOW_TWO_SIDE_WHO_LIST] = sConfig.GetBoolDefault("AllowTwoSide.WhoList", false); m_configs[CONFIG_ALLOW_TWO_SIDE_ADD_FRIEND] = sConfig.GetBoolDefault("AllowTwoSide.AddFriend", false); @@ -1268,8 +1269,8 @@ void World::SetInitialWorldSettings() ///- Load dynamic data tables from the database sLog.outString( "Loading Auctions..." ); - objmgr.LoadAuctionItems(); - objmgr.LoadAuctions(); + auctionmgr.LoadAuctionItems(); + auctionmgr.LoadAuctions(); sLog.outString( "Loading Guilds..." ); objmgr.LoadGuilds(); @@ -1513,7 +1514,7 @@ void World::Update(time_t diff) if (m_timers[WUPDATE_AUCTIONS].Passed()) { AuctionHouseBot(); - m_timers[WUPDATE_AUCTIONS].Reset(); + m_timers[WUPDATE_AUCTIONS].Reset(); ///- Update mails (return old mails with item, or delete them) //(tested... works on win) @@ -1522,55 +1523,8 @@ void World::Update(time_t diff) mail_timer = 0; objmgr.ReturnOrDeleteOldMails(true); } - - AuctionHouseObject* AuctionMap; - for (int i = 0; i < 3; i++) - { - switch (i) - { - case 0: - AuctionMap = objmgr.GetAuctionsMap( 6 );//horde - break; - case 1: - AuctionMap = objmgr.GetAuctionsMap( 2 );//alliance - break; - case 2: - AuctionMap = objmgr.GetAuctionsMap( 7 );//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) - { - objmgr.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 - objmgr.SendAuctionSuccessfulMail( itr->second ); - objmgr.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); - objmgr.RemoveAItem(itr->second->item_guidlow); - delete itr->second; - AuctionMap->RemoveAuction(itr->first); - } - } - } + ///-Handle expired auctions + auctionmgr.Update(); } RecordTimeDiff(NULL); diff --git a/src/game/WorldSession.h b/src/game/WorldSession.h index d9fa35f3208..1461d47fd2b 100644 --- a/src/game/WorldSession.h +++ b/src/game/WorldSession.h @@ -164,7 +164,6 @@ class TRINITY_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 ); diff --git a/src/shared/Database/DBCStores.cpp b/src/shared/Database/DBCStores.cpp index 67b806cd632..2031457ceaf 100644 --- a/src/shared/Database/DBCStores.cpp +++ b/src/shared/Database/DBCStores.cpp @@ -36,6 +36,7 @@ static AreaFlagByAreaID sAreaFlagByAreaID; static AreaFlagByMapID sAreaFlagByMapID; // for instances without generated *.map files DBCStorage sAreaTriggerStore(AreaTriggerEntryfmt); +DBCStorage sAuctionHouseStore(AuctionHouseEntryfmt); DBCStorage sBankBagSlotPricesStore(BankBagSlotPricesEntryfmt); DBCStorage sBattlemasterListStore(BattlemasterListEntryfmt); DBCStorage sCharStartOutfitStore(CharStartOutfitEntryfmt); @@ -178,7 +179,7 @@ void LoadDBCStores(const std::string& dataPath) { std::string dbcPath = dataPath+"dbc/"; - const uint32 DBCFilesCount = 56; + const uint32 DBCFilesCount = 57; barGoLink bar( DBCFilesCount ); @@ -202,6 +203,7 @@ void LoadDBCStores(const std::string& dataPath) } LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAreaTriggerStore, dbcPath,"AreaTrigger.dbc"); + LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAuctionHouseStore, dbcPath,"AuctionHouse.dbc"); LoadDBC(availableDbcLocales,bar,bad_dbc_files,sBankBagSlotPricesStore, dbcPath,"BankBagSlotPrices.dbc"); LoadDBC(availableDbcLocales,bar,bad_dbc_files,sBattlemasterListStore, dbcPath,"BattlemasterList.dbc"); LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCharStartOutfitStore, dbcPath,"CharStartOutfit.dbc"); diff --git a/src/shared/Database/DBCStores.h b/src/shared/Database/DBCStores.h index dd255894ded..4ad275653e7 100644 --- a/src/shared/Database/DBCStores.h +++ b/src/shared/Database/DBCStores.h @@ -134,6 +134,7 @@ class DBCStorage extern DBCStorage sAreaStore;// recommend access using functions extern DBCStorage sAreaTriggerStore; +extern DBCStorage sAuctionHouseStore; extern DBCStorage sBankBagSlotPricesStore; extern DBCStorage sBattlemasterListStore; //extern DBCStorage sChatChannelsStore; -- accessed using function, no usable index diff --git a/src/shared/Database/DBCStructure.h b/src/shared/Database/DBCStructure.h index 2f51f1d6579..95703f9b778 100644 --- a/src/shared/Database/DBCStructure.h +++ b/src/shared/Database/DBCStructure.h @@ -65,6 +65,16 @@ struct AreaTriggerEntry float box_orientation; // 9 extent rotation by about z axis }; +struct AuctionHouseEntry +{ + uint32 houseId; // 0 index + uint32 faction; // 1 id of faction.dbc for player factions associated with city + uint32 depositPercent; // 2 1/3 from real + uint32 cutPercent; // 3 + //char* name[16]; // 4-19 + // 20 string flag, unused +}; + struct BankBagSlotPricesEntry { uint32 ID; diff --git a/src/shared/Database/DBCfmt.cpp b/src/shared/Database/DBCfmt.cpp index cab781692f0..14cf6486933 100644 --- a/src/shared/Database/DBCfmt.cpp +++ b/src/shared/Database/DBCfmt.cpp @@ -19,6 +19,7 @@ */ const char AreaTableEntryfmt[]="iiinixxxxxissssssssssssssssxixxxxxx"; +const char AuctionHouseEntryfmt[]="niiixxxxxxxxxxxxxxxxx"; const char AreaTriggerEntryfmt[]="niffffffff"; const char BankBagSlotPricesEntryfmt[]="ni"; const char BattlemasterListEntryfmt[]="niiixxxxxiiiixxssssssssssssssssxx"; -- cgit v1.2.3