Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/codestyle_cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
triage:
runs-on: ubuntu-latest
name: C++
if: github.repository == 'mod-playerbots/mod-playerbots' && !github.event.pull_request.draft
if: github.event.pull_request.draft == false
steps:
- uses: actions/checkout@v4
- name: Setup python
Expand Down
File renamed without changes.
File renamed without changes.
10 changes: 7 additions & 3 deletions src/AiFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,12 @@ void AiFactory::AddDefaultCombatStrategies(Player* player, PlayerbotAI* const fa

break;
}
if (PlayerbotAI::IsTank(player, true)) {
if (PlayerbotAI::IsTank(player, true))
{
engine->addStrategy("tank face", false);
}
if (PlayerbotAI::IsMelee(player, true) && PlayerbotAI::IsDps(player, true)) {
if (PlayerbotAI::IsMelee(player, true) && PlayerbotAI::IsDps(player, true))
{
engine->addStrategy("behind", false);
}
if (PlayerbotAI::IsHeal(player, true))
Expand Down Expand Up @@ -706,7 +708,9 @@ void AiFactory::AddDefaultNonCombatStrategies(Player* player, PlayerbotAI* const
// {
// // nonCombatEngine->addStrategy("travel");
// nonCombatEngine->addStrategy("rpg");
// } else {
// }
// else
// {
// nonCombatEngine->addStrategy("move random");
// }

Expand Down
5 changes: 2 additions & 3 deletions src/BroadcastHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ bool BroadcastHelper::BroadcastToChannelWithGlobalChance(PlayerbotAI* ai, std::s
return false;
}

for (const auto& pair : toChannels)
for (auto const& pair : toChannels)
{
uint32 roll = urand(1, 100);
uint32 chance = pair.second;
Expand Down Expand Up @@ -166,7 +166,7 @@ bool BroadcastHelper::BroadcastToChannelWithGlobalChance(PlayerbotAI* ai, std::s
return false;
}

bool BroadcastHelper::BroadcastLootingItem(PlayerbotAI* ai, Player* bot, const ItemTemplate *proto)
bool BroadcastHelper::BroadcastLootingItem(PlayerbotAI* ai, Player* bot, ItemTemplate const* proto)
{
if (!sPlayerbotAIConfig->enableBroadcasts)
return false;
Expand Down Expand Up @@ -410,7 +410,6 @@ bool BroadcastHelper::BroadcastQuestUpdateComplete(PlayerbotAI* ai, Player* bot,
placeholders["%my_race"] = ai->GetChatHelper()->FormatRace(bot->getRace());
placeholders["%my_level"] = std::to_string(bot->GetLevel());


return BroadcastToChannelWithGlobalChance(
ai,
BOT_TEXT2("broadcast_quest_update_complete", placeholders),
Expand Down
4 changes: 2 additions & 2 deletions src/ChatFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ class SpecChatFilter : public ChatFilter
bool ParseSpecPrefix(const std::string& message, std::string& specPrefix, std::string& rest)
{
std::string msgLower = ToLower(message);
for (const auto& entry : specTabNames)
for (auto const& entry : specTabNames)
{
std::string prefix = "@" + entry.second;
if (msgLower.find(ToLower(prefix)) == 0)
Expand Down Expand Up @@ -555,7 +555,7 @@ class AggroByChatFilter : public ChatFilter
const float radius = 100.0f;
GuidVector npcs = botAI->GetAiObjectContext()->GetValue<GuidVector>("nearest npcs")->Get();
bool match = false;
for (const auto& guid : npcs)
for (auto const& guid : npcs)
{
Creature* c = botAI->GetCreature(guid);
if (!c)
Expand Down
9 changes: 6 additions & 3 deletions src/ChatHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,11 @@ ItemWithRandomProperty ChatHelper::parseItemWithRandomProperty(std::string const

while (currentPos < text.length()) {
size_t nextColon = text.find(':', currentPos);
if (nextColon == std::string::npos) {
if (nextColon == std::string::npos)
{
size_t hTag = text.find("|h", currentPos);
if (hTag != std::string::npos) {
if (hTag != std::string::npos)
{
params.push_back(text.substr(currentPos, hTag - currentPos));
}
break;
Expand All @@ -341,7 +343,8 @@ ItemWithRandomProperty ChatHelper::parseItemWithRandomProperty(std::string const
currentPos = nextColon + 1;
}

if (params.size() >= 6) {
if (params.size() >= 6)
{
res.randomPropertyId = atoi(params[5].c_str());
}

Expand Down
2 changes: 1 addition & 1 deletion src/GuildTaskMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ void GuildTaskMgr::SendCompletionMessage(Player* player, std::string const verb)
void GuildTaskMgr::CheckKillTaskInternal(Player* player, Unit* victim)
{
ObjectGuid::LowType owner = player->GetGUID().GetCounter();
if (victim->GetTypeId() != TYPEID_UNIT)
if (victim->IsCreature())

Copilot AI Nov 2, 2025

Copy link

Choose a reason for hiding this comment

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

Logic error: the function returns early if the victim IS a creature, but then tries to cast it to Creature*. This should be if (!victim->IsCreature()) to check if the victim is NOT a creature.

Suggested change
if (victim->IsCreature())
if (!victim->IsCreature())

Copilot uses AI. Check for mistakes.

Copilot AI Nov 4, 2025

Copy link

Choose a reason for hiding this comment

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

The logic appears to be inverted. The original code checked if (victim->GetTypeId() != TYPEID_UNIT) which returned early if the victim was NOT a unit. The new code with IsCreature() returns early if the victim IS a creature, which is the opposite behavior. This should be if (!victim->IsCreature()).

Suggested change
if (victim->IsCreature())
if (!victim->IsCreature())

Copilot uses AI. Check for mistakes.
return;

Creature* creature = reinterpret_cast<Creature*>(victim);
Expand Down
37 changes: 21 additions & 16 deletions src/PlayerbotAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1442,22 +1442,22 @@ void PlayerbotAI::ApplyInstanceStrategies(uint32 mapId, bool tellMaster)
switch (mapId)
{
case 249:
strategyName = "onyxia"; // Onyxia's Lair
strategyName = "onyxia"; // Onyxia's Lair
break;
case 409:
strategyName = "mc"; // Molten Core
strategyName = "mc"; // Molten Core
break;
case 469:
strategyName = "bwl"; // Blackwing Lair
strategyName = "bwl"; // Blackwing Lair
break;
case 509:
strategyName = "aq20"; // Ruins of Ahn'Qiraj
strategyName = "aq20"; // Ruins of Ahn'Qiraj
break;
case 532:
strategyName = "karazhan"; // Karazhan
break;
case 533:
strategyName = "naxx"; // Naxxramas
strategyName = "naxx"; // Naxxramas
break;
case 544:
strategyName = "magtheridon"; // Magtheridon's Lair
Expand Down Expand Up @@ -3097,8 +3097,10 @@ bool PlayerbotAI::CanCastSpell(uint32 spellid, Unit* target, bool checkHasSpell,
SpellCastResult result = spell->CheckCast(true);
delete spell;

// if (!sPlayerbotAIConfig->logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster())) {
// if (result != SPELL_FAILED_NOT_READY && result != SPELL_CAST_OK) {
// if (!sPlayerbotAIConfig->logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
// {
// if (result != SPELL_FAILED_NOT_READY && result != SPELL_CAST_OK)
// {
// LOG_DEBUG("playerbots", "CanCastSpell - target name: {}, spellid: {}, bot name: {}, result: {}",
// target->GetName(), spellid, bot->GetName(), result);
// }
Expand All @@ -3121,7 +3123,6 @@ bool PlayerbotAI::CanCastSpell(uint32 spellid, Unit* target, bool checkHasSpell,
default:
if (!sPlayerbotAIConfig->logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
{
// if (result != SPELL_FAILED_NOT_READY && result != SPELL_CAST_OK) {
LOG_DEBUG("playerbots",
"CanCastSpell Check Failed. - target name: {}, spellid: {}, bot name: {}, result: {}",
target->GetName(), spellid, bot->GetName(), result);
Expand Down Expand Up @@ -3304,7 +3305,8 @@ bool PlayerbotAI::CastSpell(uint32 spellId, Unit* target, Item* itemTarget)

if (bot->IsFlying() || bot->HasUnitState(UNIT_STATE_IN_FLIGHT))
{
// if (!sPlayerbotAIConfig->logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster())) {
// if (!sPlayerbotAIConfig->logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
// {
// LOG_DEBUG("playerbots", "Spell cast is flying - target name: {}, spellid: {}, bot name: {}}",
// target->GetName(), spellId, bot->GetName());
// }
Expand Down Expand Up @@ -3349,7 +3351,8 @@ bool PlayerbotAI::CastSpell(uint32 spellId, Unit* target, Item* itemTarget)
{
bot->GetTradeData()->SetSpell(spellId);
delete spell;
// if (!sPlayerbotAIConfig->logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster())) {
// if (!sPlayerbotAIConfig->logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
// {
// LOG_DEBUG("playerbots", "Spell cast no item - target name: {}, spellid: {}, bot name: {}",
// target->GetName(), spellId, bot->GetName());
// }
Expand Down Expand Up @@ -3418,7 +3421,8 @@ bool PlayerbotAI::CastSpell(uint32 spellId, Unit* target, Item* itemTarget)

// spell->m_targets.SetUnitTarget(target);
// SpellCastResult spellSuccess = spell->CheckCast(true);
// if (!sPlayerbotAIConfig->logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster())) {
// if (!sPlayerbotAIConfig->logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
// {
// LOG_DEBUG("playerbots", "Spell cast result - target name: {}, spellid: {}, bot name: {}, result: {}",
// target->GetName(), spellId, bot->GetName(), spellSuccess);
// }
Expand All @@ -3429,7 +3433,8 @@ bool PlayerbotAI::CastSpell(uint32 spellId, Unit* target, Item* itemTarget)

if (result != SPELL_CAST_OK)
{
// if (!sPlayerbotAIConfig->logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster())) {
// if (!sPlayerbotAIConfig->logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
// {
// LOG_DEBUG("playerbots", "Spell cast failed. - target name: {}, spellid: {}, bot name: {}, result: {}",
// target->GetName(), spellId, bot->GetName(), result);
// }
Expand Down Expand Up @@ -3496,7 +3501,8 @@ bool PlayerbotAI::CastSpell(uint32 spellId, Unit* target, Item* itemTarget)
// {
// spell->cancel();
// delete spell;
// if (!sPlayerbotAIConfig->logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster())) {
// if (!sPlayerbotAIConfig->logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
// {
// LOG_DEBUG("playerbots", "Spell cast loot - target name: {}, spellid: {}, bot name: {}",
// target->GetName(), spellId, bot->GetName());
// }
Expand Down Expand Up @@ -4727,7 +4733,6 @@ uint32 PlayerbotAI::GetEquipGearScore(Player* player)
sum += gearScore[i];
}


if (count)
{
uint32 res = uint32(sum / count);
Expand Down Expand Up @@ -5264,7 +5269,7 @@ Item* PlayerbotAI::FindOpenableItem() const
return FindItemInInventory(
[this](ItemTemplate const* itemTemplate) -> bool
{
return (itemTemplate->Flags & ITEM_FLAG_HAS_LOOT) &&
return itemTemplate->HasFlag(ITEM_FLAG_HAS_LOOT) &&
(itemTemplate->LockID == 0 || !this->bot->GetItemByEntry(itemTemplate->ItemId)->IsLocked());
});
}
Expand Down Expand Up @@ -5415,7 +5420,7 @@ Item* PlayerbotAI::FindOilFor(Item* weapon) const

if (prioritizedOils)
{
for (const auto& id : *prioritizedOils)
for (auto const& id : *prioritizedOils)
{
oil = FindConsumable(id);
if (oil)
Expand Down
2 changes: 1 addition & 1 deletion src/PlayerbotAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ class PlayerbotAI : public PlayerbotAIBase
Player* GetBot() { return bot; }
Player* GetMaster() { return master; }
Player* FindNewMaster();

// Checks if the bot is really a player. Players always have themselves as master.
bool IsRealPlayer() { return master ? (master == bot) : false; }
// Bot has a master that is a player.
Expand Down
3 changes: 2 additions & 1 deletion src/PlayerbotMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1736,7 +1736,8 @@ PlayerbotAI* PlayerbotsMgr::GetPlayerbotAI(Player* player)
{
return nullptr;
}
// if (player->GetSession()->isLogingOut() || player->IsDuringRemoveFromWorld()) {
// if (player->GetSession()->isLogingOut() || player->IsDuringRemoveFromWorld())
// {
// return nullptr;
// }
auto itr = _playerbotsAIMap.find(player->GetGUID());
Expand Down
11 changes: 5 additions & 6 deletions src/RandomItemMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ void RandomItemMgr::BuildItemInfoCache()
continue;
}

if (proto->Flags & ITEM_FLAG_DEPRECATED)
if (proto->HasFlag(ITEM_FLAG_DEPRECATED))
{
itemForTest.insert(proto->ItemId);
continue;
Expand Down Expand Up @@ -1072,10 +1072,10 @@ void RandomItemMgr::BuildItemInfoCache()
// cacheInfo.team = TEAM_NEUTRAL;

// // check faction
// if (proto->Flags2 & ITEM_FLAG2_FACTION_HORDE)
// if (proto->HasFlag2(ITEM_FLAG2_FACTION_HORDE))
// cacheInfo.team = TEAM_HORDE;

// if (proto->Flags2 & ITEM_FLAG2_FACTION_ALLIANCE)
// if (proto->HasFlag2(ITEM_FLAG2_FACTION_ALLIANCE))
// cacheInfo.team = TEAM_ALLIANCE;

// if (cacheInfo.team == TEAM_NEUTRAL && proto->AllowableRace > 1 && proto->AllowableRace < 8388607)
Expand All @@ -1099,7 +1099,7 @@ void RandomItemMgr::BuildItemInfoCache()

// // check item source

// if (proto->Flags & ITEM_FLAG_NO_DISENCHANT)
// if (proto->HasFlag(ITEM_FLAG_NO_DISENCHANT))
// {
// cacheInfo.source = ITEM_SOURCE_PVP;
// LOG_DEBUG("playerbots", "Item: {}, source: PvP Reward", proto->ItemId);
Expand Down Expand Up @@ -1367,7 +1367,7 @@ uint32 RandomItemMgr::CalculateStatWeight(uint8 playerclass, uint8 spec, ItemTem
}

// check item spells
for (const auto& spellData : proto->Spells)
for (auto const& spellData : proto->Spells)
{
// no spell
if (!spellData.SpellId)
Expand Down Expand Up @@ -2374,7 +2374,6 @@ void RandomItemMgr::BuildPotionCache()
if (proto->Duration & 0x80000000)
continue;


if (proto->AllowableClass != -1)
continue;

Expand Down
Loading
Loading