Skip to content

Commit

Permalink
[PlayerBot] Fix some stylistic logic display. pt2
Browse files Browse the repository at this point in the history
  • Loading branch information
billy1arm committed Aug 21, 2024
1 parent 6fed3dd commit d3c2be7
Show file tree
Hide file tree
Showing 25 changed files with 1,020 additions and 1,011 deletions.
1,216 changes: 608 additions & 608 deletions src/modules/Bots/CMakeLists.txt

Large diffs are not rendered by default.

99 changes: 54 additions & 45 deletions src/modules/Bots/ahbot/AhBot.cpp

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion src/modules/Bots/ahbot/AhBot.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,3 @@ namespace ahbot
};

#define auctionbot MaNGOS::Singleton<ahbot::AhBot>::Instance()

46 changes: 23 additions & 23 deletions src/modules/Bots/ahbot/AhBotConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,32 @@ bool AhBotConfig::Initialize()
return false;
}

enabled = config.GetBoolDefault("AhBot.Enabled", true);
enabled = config.GetBoolDefault("AhBot.Enabled", false);

if (!enabled)
if (enabled)
{
guid = (uint64)config.GetIntDefault("AhBot.GUID", 0);
updateInterval = config.GetIntDefault("AhBot.UpdateIntervalInSeconds", 300);
historyDays = config.GetIntDefault("AhBot.History.Days", 30);
itemBuyMinInterval = config.GetIntDefault("AhBot.ItemBuyMinInterval", 600);
itemBuyMaxInterval = config.GetIntDefault("AhBot.ItemBuyMaxInterval", 7200);
itemSellMinInterval = config.GetIntDefault("AhBot.ItemSellMinInterval", 600);
itemSellMaxInterval = config.GetIntDefault("AhBot.ItemSellMaxInterval", 7200);
maxSellInterval = config.GetIntDefault("AhBot.MaxSellInterval", 3600 * 8);
alwaysAvailableMoney = config.GetIntDefault("AhBot.AlwaysAvailableMoney", 200000);
priceMultiplier = config.GetFloatDefault("AhBot.PriceMultiplier", 1.0f);
defaultMinPrice = config.GetIntDefault("AhBot.DefaultMinPrice", 20);
maxItemLevel = config.GetIntDefault("AhBot.MaxItemLevel", 199);
maxRequiredLevel = config.GetIntDefault("AhBot.MaxRequiredLevel", 80);
stackReducePrice = config.GetIntDefault("AhBot.StackReducePrice", 1000000);
priceQualityMultiplier = config.GetFloatDefault("AhBot.PriceQualityMultiplier", 1.0f);
underPriceProbability = config.GetFloatDefault("AhBot.UnderPriceProbability", 0.05f);
LoadSet<set<uint32> >(config.GetStringDefault("AhBot.IgnoreItemIds", "49283,52200,8494,6345,6891,2460,37164,34835"), ignoreItemIds);
sendmail = config.GetBoolDefault("AhBot.SendMail", true);
}
else
{
sLog.outString("AhBot is Disabled in ahbot.conf");
}

guid = (uint64)config.GetIntDefault("AhBot.GUID", 0);
updateInterval = config.GetIntDefault("AhBot.UpdateIntervalInSeconds", 300);
historyDays = config.GetIntDefault("AhBot.History.Days", 30);
itemBuyMinInterval = config.GetIntDefault("AhBot.ItemBuyMinInterval", 600);
itemBuyMaxInterval = config.GetIntDefault("AhBot.ItemBuyMaxInterval", 7200);
itemSellMinInterval = config.GetIntDefault("AhBot.ItemSellMinInterval", 600);
itemSellMaxInterval = config.GetIntDefault("AhBot.ItemSellMaxInterval", 7200);
maxSellInterval = config.GetIntDefault("AhBot.MaxSellInterval", 3600 * 8);
alwaysAvailableMoney = config.GetIntDefault("AhBot.AlwaysAvailableMoney", 200000);
priceMultiplier = config.GetFloatDefault("AhBot.PriceMultiplier", 1.0f);
defaultMinPrice = config.GetIntDefault("AhBot.DefaultMinPrice", 20);
maxItemLevel = config.GetIntDefault("AhBot.MaxItemLevel", 199);
maxRequiredLevel = config.GetIntDefault("AhBot.MaxRequiredLevel", 80);
stackReducePrice = config.GetIntDefault("AhBot.StackReducePrice", 1000000);
priceQualityMultiplier = config.GetFloatDefault("AhBot.PriceQualityMultiplier", 1.0f);
underPriceProbability = config.GetFloatDefault("AhBot.UnderPriceProbability", 0.05f);
LoadSet<set<uint32> >(config.GetStringDefault("AhBot.IgnoreItemIds", "49283,52200,8494,6345,6891,2460,37164,34835"), ignoreItemIds);
sendmail = config.GetBoolDefault("AhBot.SendMail", true);


return enabled;
}
36 changes: 18 additions & 18 deletions src/modules/Bots/ahbot/Category.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,23 +330,23 @@ namespace ahbot

class QualityCategoryWrapper : public Category
{
public:
QualityCategoryWrapper(Category* category, uint32 quality);

public:
virtual bool Contains(ItemPrototype const* proto);
virtual uint32 GetMaxAllowedAuctionCount();
virtual string GetName() { return category->GetName(); }
virtual string GetDisplayName() { return combinedName; }
virtual string GetLabel() { return category->GetLabel(); }
virtual uint32 GetMaxAllowedItemAuctionCount(ItemPrototype const* proto);
virtual uint32 GetStackCount(ItemPrototype const* proto) { return category->GetStackCount(proto); }
virtual PricingStrategy* GetPricingStrategy() { return category->GetPricingStrategy(); }
virtual uint32 GetSkillId() { return category->GetSkillId(); }

private:
uint32 quality;
Category* category;
string combinedName;
public:
QualityCategoryWrapper(Category* category, uint32 quality);

public:
virtual bool Contains(ItemPrototype const* proto);
virtual uint32 GetMaxAllowedAuctionCount();
virtual string GetName() { return category->GetName(); }
virtual string GetDisplayName() { return combinedName; }
virtual string GetLabel() { return category->GetLabel(); }
virtual uint32 GetMaxAllowedItemAuctionCount(ItemPrototype const* proto);
virtual uint32 GetStackCount(ItemPrototype const* proto) { return category->GetStackCount(proto); }
virtual PricingStrategy* GetPricingStrategy() { return category->GetPricingStrategy(); }
virtual uint32 GetSkillId() { return category->GetSkillId(); }

private:
uint32 quality;
Category* category;
string combinedName;
};
};
2 changes: 1 addition & 1 deletion src/modules/Bots/ahbot/ItemBag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void AvailableItemsBag::Load()
{
set<uint32> vendorItems;

QueryResult* results = WorldDatabase.PQuery("SELECT item FROM npc_vendor where maxcount = 0");
QueryResult* results = WorldDatabase.PQuery("SELECT `item` FROM `npc_vendor` WHERE `maxcount` = 0");
if (results != NULL)
{
do
Expand Down
37 changes: 19 additions & 18 deletions src/modules/Bots/ahbot/PricingStrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ double PricingStrategy::GetMarketPrice(uint32 itemId, uint32 auctionHouse)
{
double marketPrice = 0;

QueryResult* results = CharacterDatabase.PQuery("SELECT price FROM ahbot_price WHERE item = '%u' AND auction_house = '%u'", itemId, auctionHouse);
QueryResult* results = CharacterDatabase.PQuery("SELECT `price` FROM `ahbot_price` WHERE `item` = '%u' AND `auction_house` = '%u'", itemId, auctionHouse);
if (results)
{
marketPrice = results->Fetch()[0].GetFloat();
Expand Down Expand Up @@ -97,19 +97,19 @@ double PricingStrategy::GetRarityPriceMultiplier(uint32 itemId)
double result = 1.0;

QueryResult* results = WorldDatabase.PQuery(
"select max(ChanceOrQuestChance) from ( "
"select ChanceOrQuestChance from gameobject_loot_template where item = '%u' "
"SELECT MAX(`ChanceOrQuestChance`) FROM ( "
"SELECT `ChanceOrQuestChance` FROM `gameobject_loot_template` WHERE `item` = '%u' "
//"union select ChanceOrQuestChance from spell_loot_template where item = '%u' "
"union select ChanceOrQuestChance from disenchant_loot_template where item = '%u' "
"union select ChanceOrQuestChance from fishing_loot_template where item = '%u' "
"union select ChanceOrQuestChance from item_loot_template where item = '%u' "
//"union select ChanceOrQuestChance from milling_loot_template where item = '%u' "
"union select ChanceOrQuestChance from pickpocketing_loot_template where item = '%u' "
//"union select ChanceOrQuestChance from prospecting_loot_template where item = '%u' "
"union select ChanceOrQuestChance from reference_loot_template where item = '%u' "
"union select ChanceOrQuestChance from skinning_loot_template where item = '%u' "
"union select ChanceOrQuestChance from creature_loot_template where item = '%u' "
"union select 0 "
"UNION SELECT `ChanceOrQuestChance` FROM `disenchant_loot_template` WHERE `item` = '%u' "
"UNION SELECT `ChanceOrQuestChance` FROM `fishing_loot_template` WHERE `item` = '%u' "
"UNION SELECT `ChanceOrQuestChance` FROM `item_loot_template` WHERE `item` = '%u' "
//"union select ChanceOrQuestChance from milling_loot_template where `item` = '%u' "
"UNION SELECT `ChanceOrQuestChance` FROM `pickpocketing_loot_template` WHERE `item` = '%u' "
//"union select ChanceOrQuestChance from prospecting_loot_template where `item` = '%u' "
"UNION SELECT `ChanceOrQuestChance` FROM `reference_loot_template` WHERE `item` = '%u' "
"UNION SELECT `ChanceOrQuestChance` FROM `skinning_loot_template` WHERE `item` = '%u' "
"UNION SELECT `ChanceOrQuestChance` FROM `creature_loot_template` WHERE `item` = '%u' "
"UNION SELECT 0 "
") a",
itemId,itemId,itemId,itemId,itemId,itemId,itemId,itemId,itemId,itemId,itemId);

Expand All @@ -135,7 +135,7 @@ double PricingStrategy::GetCategoryPriceMultiplier(uint32 untilTime, uint32 auct
double result = 1.0;

QueryResult* results = CharacterDatabase.PQuery(
"SELECT count(*) FROM (SELECT round(buytime/3600/24/5) as days FROM ahbot_history WHERE category = '%s' AND won = '1' AND buytime <= '%u' AND auction_house = '%u' group by days) q",
"SELECT COUNT(*) FROM (SELECT ROUND(`buytime`/3600/24/5) AS days FROM `ahbot_history` WHERE `category` = '%s' AND `won` = '1' AND `buytime` <= '%u' AND `auction_house` = '%u' GROUP BY `days`) q",
category->GetName().c_str(), untilTime, AhBot::factions[auctionHouse]);
if (results)
{
Expand Down Expand Up @@ -165,7 +165,7 @@ double PricingStrategy::GetItemPriceMultiplier(ItemPrototype const* proto, uint3
double result = 1.0;

QueryResult* results = CharacterDatabase.PQuery(
"SELECT count(*) FROM (SELECT round(buytime/3600/24/5) as days FROM ahbot_history WHERE won = '1' AND item = '%u' AND buytime <= '%u' AND auction_house = '%u' group by days) q",
"SELECT count(*) FROM (SELECT ROUND(`buytime`/3600/24/5) AS `days` FROM `ahbot_history` WHERE `won` = '1' AND `item` = '%u' AND `buytime` <= '%u' AND `auction_house` = '%u' GROUP BY `days`) q",
proto->ItemId, untilTime, AhBot::factions[auctionHouse]);
if (results)
{
Expand Down Expand Up @@ -214,7 +214,7 @@ uint32 PricingStrategy::GetDefaultBuyPrice(ItemPrototype const* proto)
double result = 1.0;

QueryResult* results = WorldDatabase.PQuery(
"select max(QuestLevel), max(MinLevel) from quest_template where ReqItemId1 = %u or ReqItemId2 = %u or ReqItemId3 = %u or ReqItemId4 = %u",
"SELECT MAX(`QuestLevel`), MAX(`MinLevel`) FROM `quest_template` WHERE `ReqItemId1` = %u OR `ReqItemId2` = %u OR `ReqItemId3` = %u OR `ReqItemId4` = %u",
proto->ItemId, proto->ItemId, proto->ItemId, proto->ItemId);
if (results)
{
Expand All @@ -223,10 +223,11 @@ uint32 PricingStrategy::GetDefaultBuyPrice(ItemPrototype const* proto)
delete results;
}
}
if (!price) price = sAhBotConfig.defaultMinPrice * level * level / 40;
if (!price)
{
price = max(price, (uint32)100);
price = sAhBotConfig.defaultMinPrice * level * level / 40;
}
price = max(price, (uint32)100);

return price;
}
Expand Down
8 changes: 4 additions & 4 deletions src/modules/Bots/ahbot/TradeCategory.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ namespace ahbot
virtual bool Contains(ItemPrototype const* proto)
{
return Trade::Contains(proto) &&
proto->SubClass != ITEM_SUBCLASS_PARTS &&
proto->SubClass != ITEM_SUBCLASS_DEVICES &&
proto->SubClass != ITEM_SUBCLASS_EXPLOSIVES;
proto->SubClass != ITEM_SUBCLASS_PARTS &&
proto->SubClass != ITEM_SUBCLASS_DEVICES &&
proto->SubClass != ITEM_SUBCLASS_EXPLOSIVES;
}

virtual string GetName() { return "othertrade"; }
virtual string GetName() { return "OtherTrade"; }
virtual string GetLabel() { return "devices and explosives"; }
};
};
6 changes: 3 additions & 3 deletions src/modules/Bots/playerbot/ChatHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ static bool substrContainsInMap(string searchTerm, map<string, T> searchIn)
{
string term = i->first;
if (term.size() > 1 && searchTerm.find(term) != string::npos)
{
return true;
}
{
return true;
}
}

return false;
Expand Down
18 changes: 9 additions & 9 deletions src/modules/Bots/playerbot/FleeManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ void FleeManager::calculateDistanceToPlayers(FleePoint *point)
{
Group* group = bot->GetGroup();
if (!group)
{
return;
}
{
return;
}

for (GroupReference *gref = group->GetFirstMember(); gref; gref = gref->next())
{
Player* player = gref->getSource();
if(player == bot)
{
continue;
}
{
continue;
}

float d = player->GetDistance2d(point->x, point->y);
point->toAllPlayers.probe(d);
Expand Down Expand Up @@ -51,9 +51,9 @@ void FleeManager::calculateDistanceToCreatures(FleePoint *point)
{
Unit* unit = bot->GetPlayerbotAI()->GetUnit(*i);
if (!unit)
{
continue;
}
{
continue;
}

float d = unit->GetDistance2d(point->x, point->y);
distance.probe(d);
Expand Down
12 changes: 6 additions & 6 deletions src/modules/Bots/playerbot/FleeManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ namespace ai
public:
void probe(float d) {
if (min < 0 || min > d)
{
min = d;
}
{
min = d;
}

if (max < 0 || max < d)
{
max = d;
}
{
max = d;
}
}
};

Expand Down
6 changes: 3 additions & 3 deletions src/modules/Bots/playerbot/LootObjectStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ void LootTargetList::shrink(time_t fromTime)
erase(i++);
}
else
{
++i;
}
{
++i;
}
}
}

Expand Down
17 changes: 7 additions & 10 deletions src/modules/Bots/playerbot/PlayerbotAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ void PlayerbotAI::HandleTeleportAck()
{
WorldPacket p = WorldPacket(MSG_MOVE_TELEPORT_ACK, 8 + 4 + 4);
p << bot->GetObjectGuid();
p << (uint32) 0; // supposed to be flags? not used currently
p << (uint32) time(0); // time - not currently used
p << (uint32)0; // supposed to be flags? not used currently
p << (uint32)time(0); // time - not currently used
bot->GetSession()->HandleMoveTeleportAckOpcode(p);
}
else if (bot->IsBeingTeleportedFar())
Expand Down Expand Up @@ -420,13 +420,13 @@ void PlayerbotAI::ChangeEngine(BotState type)
switch (type)
{
case BOT_STATE_COMBAT:
sLog.outDebug( "=== %s COMBAT ===", bot->GetName());
sLog.outDebug("=== %s COMBAT ===", bot->GetName());
break;
case BOT_STATE_NON_COMBAT:
sLog.outDebug( "=== %s NON-COMBAT ===", bot->GetName());
sLog.outDebug("=== %s NON-COMBAT ===", bot->GetName());
break;
case BOT_STATE_DEAD:
sLog.outDebug( "=== %s DEAD ===", bot->GetName());
sLog.outDebug("=== %s DEAD ===", bot->GetName());
break;
}
}
Expand Down Expand Up @@ -882,7 +882,6 @@ bool PlayerbotAI::HasAura(uint32 spellId, const Unit* unit)
return false;
}


bool PlayerbotAI::HasAnyAuraOf(Unit* player, ...)
{
if (!player)
Expand Down Expand Up @@ -1090,7 +1089,6 @@ bool PlayerbotAI::CastSpell(uint32 spellId, Unit* target)
targets.setUnitTarget(target);
}


if (pSpellInfo->Effect[0] == SPELL_EFFECT_OPEN_LOCK ||
pSpellInfo->Effect[0] == SPELL_EFFECT_SKINNING)
{
Expand Down Expand Up @@ -1241,7 +1239,7 @@ bool PlayerbotAI::IsInterruptableSpellCasting(Unit* target, string spell)
}

if ((spellInfo->Effect[i] == SPELL_EFFECT_INTERRUPT_CAST) &&
!target->IsImmuneToSpellEffect(spellInfo, (SpellEffectIndex)i, true))
!target->IsImmuneToSpellEffect(spellInfo, (SpellEffectIndex)i, true))
return true;
}

Expand Down Expand Up @@ -1285,7 +1283,6 @@ bool PlayerbotAI::HasAuraToDispel(Unit* target, uint32 dispelType)
}



#ifndef WIN32
inline int strcmpi(const char* s1, const char* s2)
{
Expand Down Expand Up @@ -1315,7 +1312,7 @@ bool PlayerbotAI::canDispel(const SpellEntry* entry, uint32 dispelType)
bool IsAlliance(uint8 race)
{
return race == RACE_HUMAN || race == RACE_DWARF || race == RACE_NIGHTELF || race == RACE_DRAENEI ||
race == RACE_GNOME;
race == RACE_GNOME;
}

bool PlayerbotAI::IsOpposing(Player* player)
Expand Down
6 changes: 3 additions & 3 deletions src/modules/Bots/playerbot/PlayerbotAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ namespace ai
public:
void probe(float value, void* p) {
if (!param || minValue >= value) {
{
minValue = value;
}
{
minValue = value;
}
param = p;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/modules/Bots/playerbot/PlayerbotAIBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void PlayerbotAIBase::SetNextCheckDelay(const uint32 delay)

if (nextAICheckDelay > sPlayerbotAIConfig.globalCoolDown)
{
sLog.outDebug( "set next check delay: %d", nextAICheckDelay);
sLog.outDebug("set next check delay: %d", nextAICheckDelay);
}
}

Expand All @@ -50,7 +50,7 @@ void PlayerbotAIBase::IncreaseNextCheckDelay(uint32 delay)

if (nextAICheckDelay > sPlayerbotAIConfig.globalCoolDown)
{
sLog.outDebug( "increase next check delay: %d", nextAICheckDelay);
sLog.outDebug("increase next check delay: %d", nextAICheckDelay);
}
}

Expand Down
Loading

0 comments on commit d3c2be7

Please sign in to comment.