Skip to content

Allow bot to trade only with money earned from trade/giving by admins. #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions conf/mod_ahbot.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@
# Number of Items to Add/Remove from the AH during mass operations
# Default 200
#
# AuctionHouseBot.NoGoldGeneration
# Makes the bot not generate any gold. It will keep track of sales and only buy from players if he has enough gold.
# The starting gold of the bot can be set by adding gold to the character
# Default 0 (False)
#
# AuctionHouseBot.GoldWalletID
# Wallet ID to track money for buying or selling
# Default 0
#
###############################################################################

AuctionHouseBot.DEBUG = 0
Expand All @@ -50,6 +59,8 @@ AuctionHouseBot.UseBuyPriceForBuyer = 0
AuctionHouseBot.Account = 0
AuctionHouseBot.GUID = 0
AuctionHouseBot.ItemsPerCycle = 200
AuctionHouseBot.NoGoldGeneration = 0
AuctionHouseBot.GoldWalletID = 0

###############################################################################
# AUCTION HOUSE BOT FILTERS PART 1
Expand Down
10 changes: 10 additions & 0 deletions sql/world/base/mod_auctionhousebot.sql
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ CREATE TABLE `mod_auctionhousebot` (
PRIMARY KEY (`auctionhouse`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS `mod_auctionhousebot_gold`;
CREATE TABLE `mod_auctionhousebot_gold` (
`id` int(11) NOT NULL DEFAULT '0' COMMENT 'Wallet ID',
`gold` bigint(8) unsigned NOT NULL DEFAULT '0' COMMENT 'Gold in wallet',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `mod_auctionhousebot_gold` (`id`, `gold`)
VALUES (0, 20000);

DROP TABLE IF EXISTS `mod_auctionhousebot_disabled_items`;
CREATE TABLE `mod_auctionhousebot_disabled_items` (
`item` mediumint(8) unsigned NOT NULL,
Expand Down
78 changes: 75 additions & 3 deletions src/AuctionHouseBot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,34 +651,64 @@ void AuctionHouseBot::addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *con
sLog->outString("-------------------------------------------------");
}


// Check whether we do normal bid, or buyout
if ((bidprice < auction->buyout) || (auction->buyout == 0))
{

if (UseAHBplayerGold && !AHBotHasEnoughMoney(bidprice))
{
//We dont have enough money for this so get out of here
if (debug_Out)
{
sLog->outString("-------------------------------------------------");
sLog->outString("AHBuyer: AHBot Has not enough money for bid; Needed: %u has: %lu", bidprice, AHBotGetCurrentMoney());
sLog->outString("-------------------------------------------------");
}
continue;
}
bool alreadyBided = false;
if (auction->bidder > 0)
{
if (auction->bidder == AHBplayer->GetGUIDLow())
{
//pl->ModifyMoney(-int32(price - auction->bid));
alreadyBided = true;
}
else
{
// mail to last bidder and return money
SQLTransaction trans = CharacterDatabase.BeginTransaction();
sAuctionMgr->SendAuctionOutbiddedMail(auction , bidprice, session->GetPlayer(), trans);
CharacterDatabase.CommitTransaction(trans);
//pl->ModifyMoney(-int32(price));
}
}

auction->bidder = AHBplayer->GetGUIDLow();
auction->bid = bidprice;

if (UseAHBplayerGold)
{
AHBotChangeMoney(-int32(bidprice - (alreadyBided ? currentprice : 0)));
}

// Saving auction into database
CharacterDatabase.PExecute("UPDATE auctionhouse SET buyguid = '%u',lastbid = '%u' WHERE id = '%u'", auction->bidder, auction->bid, auction->Id);
}
else
{

if (UseAHBplayerGold && !AHBotHasEnoughMoney(auction->buyout))
{
//We dont have enough money for this so get out of here
if (debug_Out)
{
sLog->outString("-------------------------------------------------");
sLog->outString("AHBuyer: AHBot Has not enough money for buyout; Needed: %u has: %lu", auction->buyout, AHBotGetCurrentMoney());
sLog->outString("-------------------------------------------------");
}
continue;
}

SQLTransaction trans = CharacterDatabase.BeginTransaction();
//buyout
if ((auction->bidder) && (AHBplayer->GetGUIDLow() != auction->bidder))
Expand All @@ -688,6 +718,13 @@ void AuctionHouseBot::addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *con
auction->bidder = AHBplayer->GetGUIDLow();
auction->bid = auction->buyout;

//Remove money for chatacter
if (UseAHBplayerGold)
{
AHBotChangeMoney(-int32(auction->buyout));
}


// Send mails to buyer & seller
//sAuctionMgr->SendAuctionSalePendingMail(auction, trans);
sAuctionMgr->SendAuctionSuccessfulMail(auction, trans);
Expand Down Expand Up @@ -742,6 +779,7 @@ void AuctionHouseBot::Update()
addNewAuctionBuyerBotBid(&_AHBplayer, &NeutralConfig, &_session);
_lastrun_n = _newrun;
}

sObjectAccessor->RemoveObject(&_AHBplayer);
}

Expand Down Expand Up @@ -1331,7 +1369,8 @@ void AuctionHouseBot::InitializeConfiguration()
AHBplayerAccount = sConfigMgr->GetIntDefault("AuctionHouseBot.Account", 0);
AHBplayerGUID = sConfigMgr->GetIntDefault("AuctionHouseBot.GUID", 0);
ItemsPerCycle = sConfigMgr->GetIntDefault("AuctionHouseBot.ItemsPerCycle", 200);

UseAHBplayerGold = sConfigMgr->GetBoolDefault("AuctionHouseBot.NoGoldGeneration", false);
WalletID = sConfigMgr->GetIntDefault("AuctionHouseBot.GoldWalletID", 0);
//Begin Filters

Vendor_Items = sConfigMgr->GetBoolDefault("AuctionHouseBot.VendorItems", false);
Expand Down Expand Up @@ -1665,6 +1704,39 @@ void AuctionHouseBot::Commands(uint32 command, uint32 ahMapID, uint32 col, char*
}
}


void AuctionHouseBot::AHBotChangeMoney(int32 amount)
{
//Update the databse
uint64 currentGold = AHBotGetCurrentMoney();
if (amount < 0)
currentGold = currentGold > uint32(-amount) ? currentGold + amount : 0;
else
{
if (currentGold < uint32((0x7FFFFFFFFFFFFFFF-1) - amount))
currentGold += + amount;
}

WorldDatabase.PExecute("INSERT INTO mod_auctionhousebot_gold (id, gold) values(%u, %lu) ON DUPLICATE KEY UPDATE gold = %lu", WalletID, currentGold, currentGold);
}


bool AuctionHouseBot::AHBotHasEnoughMoney(uint32 amount)
{
return AHBotGetCurrentMoney() >= amount;
}


uint64 AuctionHouseBot::AHBotGetCurrentMoney()
{
QueryResult querry = WorldDatabase.PQuery("SELECT gold FROM mod_auctionhousebot_gold WHERE id = '%lu'", WalletID);
if (!querry || querry->GetRowCount() == 0)
{
return 0;
}
return querry->Fetch()->GetUInt64();
}

void AuctionHouseBot::LoadValues(AHBConfig *config)
{
if (debug_Out)
Expand Down
8 changes: 8 additions & 0 deletions src/AuctionHouseBot.h
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,7 @@ class AuctionHouseBot
uint32 AHBplayerAccount;
uint32 AHBplayerGUID;
uint32 ItemsPerCycle;
bool UseAHBplayerGold;

//Begin Filters

Expand Down Expand Up @@ -1229,6 +1230,9 @@ class AuctionHouseBot
time_t _lastrun_h;
time_t _lastrun_n;

//Gold
uint32 WalletID;

inline uint32 minValue(uint32 a, uint32 b) { return a <= b ? a : b; };
void addNewAuctions(Player *AHBplayer, AHBConfig *config);
void addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *config, WorldSession *session);
Expand All @@ -1251,7 +1255,11 @@ class AuctionHouseBot
void DecrementItemCounts(AuctionEntry* ah, uint32 itemEntry);
void IncrementItemCounts(AuctionEntry* ah);
void Commands(uint32, uint32, uint32, char*);
bool GetUseAHBplayerGold() const { return UseAHBplayerGold; }
uint32 GetAHBplayerGUID() { return AHBplayerGUID; };
void AHBotChangeMoney(int32 amount);
bool AHBotHasEnoughMoney(uint32 amount);
uint64 AHBotGetCurrentMoney();
};

#define auctionbot AuctionHouseBot::instance()
Expand Down
29 changes: 26 additions & 3 deletions src/AuctionHouseBotScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*/

#include "ScriptMgr.h"
#include "Player.h"
#include "AuctionHouseBot.h"
#include "Player.h"

class AHBot_WorldScript : public WorldScript
{
Expand All @@ -28,13 +28,22 @@ class AHBot_AuctionHouseScript : public AuctionHouseScript
public:
AHBot_AuctionHouseScript() : AuctionHouseScript("AHBot_AuctionHouseScript") { }

void OnBeforeAuctionHouseMgrSendAuctionSuccessfulMail(AuctionHouseMgr* /*auctionHouseMgr*/, AuctionEntry* /*auction*/, Player* owner, uint32& /*owner_accId*/, uint32& /*profit*/, bool& sendNotification, bool& updateAchievementCriteria, bool& /*sendMail*/) override
void OnBeforeAuctionHouseMgrSendAuctionSuccessfulMail(AuctionHouseMgr* /*auctionHouseMgr*/, AuctionEntry* auction, Player* owner, uint32& /*owner_accId*/, uint32& profit, bool& sendNotification, bool& updateAchievementCriteria, bool& /*sendMail*/) override
{
if (owner && owner->GetGUIDLow() == auctionbot->GetAHBplayerGUID())
{
sendNotification = false;
updateAchievementCriteria = false;
if (auctionbot->GetUseAHBplayerGold())
{
auctionbot->AHBotChangeMoney(profit);
}
}
else if (!owner && auction->owner == auctionbot->GetAHBplayerGUID() && auctionbot->GetUseAHBplayerGold())
{
auctionbot->AHBotChangeMoney(profit);
}

}

void OnBeforeAuctionHouseMgrSendAuctionExpiredMail(AuctionHouseMgr* /*auctionHouseMgr*/, AuctionEntry* /*auction*/, Player* owner, uint32& /*owner_accId*/, bool& sendNotification, bool& /*sendMail*/) override
Expand All @@ -43,10 +52,24 @@ class AHBot_AuctionHouseScript : public AuctionHouseScript
sendNotification = false;
}

void OnBeforeAuctionHouseMgrSendAuctionOutbiddedMail(AuctionHouseMgr* /*auctionHouseMgr*/, AuctionEntry* auction, Player* oldBidder, uint32& /*oldBidder_accId*/, Player* newBidder, uint32& newPrice, bool& /*sendNotification*/, bool& /*sendMail*/) override
void OnBeforeAuctionHouseMgrSendAuctionOutbiddedMail(AuctionHouseMgr* /*auctionHouseMgr*/, AuctionEntry* auction, Player* oldBidder, uint32& /*oldBidder_accId*/, Player* newBidder, uint32& newPrice, bool& sendNotification, bool& /*sendMail*/) override
{
if (oldBidder && !newBidder)
oldBidder->GetSession()->SendAuctionBidderNotification(auction->GetHouseId(), auction->Id, auctionbot->GetAHBplayerGUID(), newPrice, auction->GetAuctionOutBid(), auction->item_template);


if (auctionbot->GetUseAHBplayerGold())
{
if (oldBidder && oldBidder->GetGUIDLow() == auctionbot->GetAHBplayerGUID() && newBidder != oldBidder)
{
sendNotification = false;
auctionbot->AHBotChangeMoney(auction->bid);
}
else if (!oldBidder && auction->bidder == auctionbot->GetAHBplayerGUID() && newBidder && newBidder->GetGUIDLow() != auctionbot->GetAHBplayerGUID())
{
auctionbot->AHBotChangeMoney(auction->bid);
}
}
}

void OnAuctionAdd(AuctionHouseObject* /*ah*/, AuctionEntry* auction) override
Expand Down