Compare commits

...

11 Commits

Author SHA1 Message Date
SaW
1f7b831422 Slots 2025-11-19 21:34:54 +01:00
SaW
4af85d3a14 Final 2025-11-01 21:58:09 +01:00
SaW
f9fce01282 bot to player 2025-10-30 22:01:34 +01:00
SaW
3577acebd4 Restore original behavior
Restores original behavior before this was touched 9mo ago.
2025-10-30 21:58:28 +01:00
SaW
ade388cba0 Combine if member & isAssist 2025-10-28 18:26:51 +01:00
SaW
1848fb553a FIX: Refactor/restore ..AssistOfIndex Functions
FIX: Refactor/restore IsAssistTankOfIndex, IsRangedDpsAssistantOfIndex, and IsHealAssistantOfIndex to improve readability, and modernize the approach using std::vector.

- Restores their original behavior, previously incorrectly optimized in https://github.com/mod-playerbots/mod-playerbots/pull/865
- Removed redundant double group iteration
- Refactored as per original PR's intent
- +Index/member validity check
2025-10-27 21:17:52 +01:00
bash
7237b154e0 Added intelliJ project folder on exclusion list (#1764) 2025-10-25 00:54:27 +02:00
NoxMax
c3fd97b6c0 Fix: Prevent addClass bots from getting realm firsts (#1745)
* Random/Addclass bots cannot get first achievements

* Use firsts achievement flags
2025-10-23 20:10:35 +02:00
Alex Dcnh
286213eb8b Fix Playerbots won't fly #1753 (#1761) 2025-10-23 01:33:22 +02:00
SaW
6e1c9114df FIX: part of logic in picking quest reward (#1752)
* FIX: part of logic in picking reward

Avoids dereferencing begin() after confirming the set is empty.

* Update TalkToQuestGiverAction.cpp
2025-10-21 10:36:10 +02:00
bash
7e810f8174 Update README.md (#1750) 2025-10-20 21:46:51 +02:00
6 changed files with 170 additions and 139 deletions

3
.gitignore vendored
View File

@@ -48,4 +48,5 @@ local.properties
.loadpath
.project
.cproject
.vscode
.vscode
.idea

View File

@@ -93,6 +93,9 @@ The [Playerbots Wiki](https://github.com/mod-playerbots/mod-playerbots/wiki) con
- **What platforms are supported?** We support Ubuntu, Windows, and macOS. Other Linux distros may work, but will not receive support.
- **Why isn't my source compiling?** Please ensure that you are compiling with the required [custom branch of AzerothCore](https://github.com/mod-playerbots/azerothcore-wotlk/tree/Playerbot). Additionally, please [check the build status of our CI](https://github.com/mod-playerbots/mod-playerbots/actions). If the latest build is failing, rever to the last successful commit until we address the issue.
## Code standards
- https://www.azerothcore.org/wiki/cpp-code-standards
## Addons
Typically, bots are controlled via chat commands. For larger bot groups, this can be unwieldy. As an alternative, community members have developed client Add-Ons to allow controlling bots through the in-game UI. We recommend you check out their projects:

View File

@@ -1769,80 +1769,6 @@ bool PlayerbotAI::IsCombo(Player* player)
(player->getClass() == CLASS_DRUID && player->HasAura(768)); // cat druid
}
bool PlayerbotAI::IsRangedDps(Player* player, bool bySpec) { return IsRanged(player, bySpec) && IsDps(player, bySpec); }
bool PlayerbotAI::IsHealAssistantOfIndex(Player* player, int index)
{
Group* group = player->GetGroup();
if (!group)
{
return false;
}
int counter = 0;
for (GroupReference* ref = group->GetFirstMember(); ref; ref = ref->next())
{
Player* member = ref->GetSource();
if (!member)
{
continue;
}
if (IsHeal(member)) // Check if the member is a healer
{
bool isAssistant = group->IsAssistant(member->GetGUID());
// Check if the index matches for both assistant and non-assistant healers
if ((isAssistant && index == counter) || (!isAssistant && index == counter))
{
return player == member;
}
counter++;
}
}
return false;
}
bool PlayerbotAI::IsRangedDpsAssistantOfIndex(Player* player, int index)
{
Group* group = player->GetGroup();
if (!group)
{
return false;
}
int counter = 0;
for (GroupReference* ref = group->GetFirstMember(); ref; ref = ref->next())
{
Player* member = ref->GetSource();
if (!member)
{
continue;
}
if (IsRangedDps(member)) // Check if the member is a ranged DPS
{
bool isAssistant = group->IsAssistant(member->GetGUID());
// Check the index for both assistant and non-assistant ranges
if ((isAssistant && index == counter) || (!isAssistant && index == counter))
{
return player == member;
}
counter++;
}
}
return false;
}
bool PlayerbotAI::HasAggro(Unit* unit)
{
if (!unit)
@@ -2186,7 +2112,6 @@ bool PlayerbotAI::IsMainTank(Player* player)
}
ObjectGuid mainTank = ObjectGuid();
Group::MemberSlotList const& slots = group->GetMemberSlots();
for (Group::member_citerator itr = slots.begin(); itr != slots.end(); ++itr)
{
@@ -2298,50 +2223,109 @@ uint32 PlayerbotAI::GetGroupTankNum(Player* player)
return result;
}
bool PlayerbotAI::IsHealAssistantOfIndex(Player* player, int index)
{
Group* group = player->GetGroup();
if (!group)
return false;
Group::MemberSlotList const& slots = group->GetMemberSlots();
int counter = 0;
for (GroupReference* ref = group->GetFirstMember(); ref; ref = ref->next())
{
Player* member = ref->GetSource();
if (member && group->IsAssistant(member->GetGUID()) && IsHeal(member))
{
if (index == counter)
return player == member;
counter++;
}
}
// Non-assistants
for (GroupReference* ref = group->GetFirstMember(); ref; ref = ref->next())
{
Player* member = ref->GetSource();
if (member && !group->IsAssistant(member->GetGUID()) && IsHeal(member))
{
if (index == counter)
return player == member;
counter++;
}
}
return false;
}
bool PlayerbotAI::IsRangedDps(Player* player, bool bySpec) { return IsRanged(player, bySpec) && IsDps(player, bySpec); }
bool PlayerbotAI::IsRangedDpsAssistantOfIndex(Player* player, int index)
{
Group* group = player->GetGroup();
if (!group)
return false;
Group::MemberSlotList const& slots = group->GetMemberSlots();
int counter = 0;
for (GroupReference* ref = group->GetFirstMember(); ref; ref = ref->next())
{
Player* member = ref->GetSource();
if (member && group->IsAssistant(member->GetGUID()) && IsRangedDps(member))
{
if (index == counter)
return player == member;
counter++;
}
}
// Non-assistants
for (GroupReference* ref = group->GetFirstMember(); ref; ref = ref->next())
{
Player* member = ref->GetSource();
if (member && !group->IsAssistant(member->GetGUID()) && IsRangedDps(member))
{
if (index == counter)
return player == member;
counter++;
}
}
return false;
}
bool PlayerbotAI::IsAssistTank(Player* player) { return IsTank(player) && !IsMainTank(player); }
bool PlayerbotAI::IsAssistTankOfIndex(Player* player, int index)
{
Group* group = player->GetGroup();
if (!group)
{
return false;
}
Group::MemberSlotList const& slots = group->GetMemberSlots();
int counter = 0;
for (GroupReference* ref = group->GetFirstMember(); ref; ref = ref->next())
{
Player* member = ref->GetSource();
if (!member)
{
continue;
}
if (group->IsAssistant(member->GetGUID()) && IsAssistTank(member))
if (member && group->IsAssistant(member->GetGUID()) && IsAssistTank(member))
{
if (index == counter)
{
return player == member;
}
counter++;
}
}
// not enough
// Non-assistants
for (GroupReference* ref = group->GetFirstMember(); ref; ref = ref->next())
{
Player* member = ref->GetSource();
if (!member)
{
continue;
}
if (!group->IsAssistant(member->GetGUID()) && IsAssistTank(member))
if (member && !group->IsAssistant(member->GetGUID()) && IsAssistTank(member))
{
if (index == counter)
{
return player == member;
}
counter++;
}
}

View File

@@ -220,7 +220,8 @@ public:
bool OnPlayerBeforeAchievementComplete(Player* player, AchievementEntry const* achievement) override
{
if (sRandomPlayerbotMgr->IsRandomBot(player) && (achievement->flags == 256 || achievement->flags == 768))
if ((sRandomPlayerbotMgr->IsRandomBot(player) || sRandomPlayerbotMgr->IsAddclassBot(player)) &&
(achievement->flags & (ACHIEVEMENT_FLAG_REALM_FIRST_REACH | ACHIEVEMENT_FLAG_REALM_FIRST_KILL)))
{
return false;
}

View File

@@ -199,7 +199,8 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle,
{
VehicleSeatEntry const* seat = vehicle->GetSeatForPassenger(bot);
Unit* vehicleBase = vehicle->GetBase();
generatePath = vehicleBase->CanFly();
// If the mover (vehicle) can fly, we DO NOT want an mmaps path (2D ground) => disable pathfinding
generatePath = !vehicleBase || !vehicleBase->CanFly();
if (!vehicleBase || !seat || !seat->CanControl()) // is passenger and cant move anyway
return false;
@@ -207,14 +208,20 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle,
if (distance > 0.01f)
{
MotionMaster& mm = *vehicleBase->GetMotionMaster(); // need to move vehicle, not bot
// Disable ground pathing if the bot/master/vehicle are flying
auto isFlying = [](Unit* u){ return u && (u->HasUnitMovementFlag(MOVEMENTFLAG_FLYING) || u->IsInFlight()); };
bool allowPathVeh = generatePath;
Unit* masterVeh = botAI ? botAI->GetMaster() : nullptr;
if (isFlying(vehicleBase) || isFlying(bot) || isFlying(masterVeh))
allowPathVeh = false;
mm.Clear();
if (!backwards)
{
mm.MovePoint(0, x, y, z, FORCED_MOVEMENT_NONE, 0.0f, 0.0f, generatePath);
mm.MovePoint(0, x, y, z, FORCED_MOVEMENT_NONE, 0.0f, 0.0f, allowPathVeh);
}
else
{
mm.MovePointBackwards(0, x, y, z, generatePath);
mm.MovePointBackwards(0, x, y, z, allowPathVeh);
}
float speed = backwards ? vehicleBase->GetSpeed(MOVE_RUN_BACK) : vehicleBase->GetSpeed(MOVE_RUN);
float delay = 1000.0f * (distance / speed);
@@ -241,15 +248,22 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle,
// bot->CastStop();
// botAI->InterruptSpell();
// }
MotionMaster& mm = *bot->GetMotionMaster();
// No ground pathfinding if the bot/master are flying => allow true 3D (Z) movement
auto isFlying = [](Unit* u){ return u && (u->HasUnitMovementFlag(MOVEMENTFLAG_FLYING) || u->IsInFlight()); };
bool allowPath = generatePath;
Unit* master = botAI ? botAI->GetMaster() : nullptr;
if (isFlying(bot) || isFlying(master))
allowPath = false;
mm.Clear();
if (!backwards)
{
mm.MovePoint(0, x, y, z, FORCED_MOVEMENT_NONE, 0.0f, 0.0f, generatePath);
mm.MovePoint(0, x, y, z, FORCED_MOVEMENT_NONE, 0.0f, 0.0f, allowPath);
}
else
{
mm.MovePointBackwards(0, x, y, z, generatePath);
mm.MovePointBackwards(0, x, y, z, allowPath);
}
float delay = 1000.0f * MoveDelay(distance, backwards);
if (lessDelay)
@@ -282,16 +296,23 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle,
// bot->CastStop();
// botAI->InterruptSpell();
// }
MotionMaster& mm = *bot->GetMotionMaster();
G3D::Vector3 endP = path.back();
// No ground pathfinding if the bot/master are flying => allow true 3D (Z) movement
auto isFlying = [](Unit* u){ return u && (u->HasUnitMovementFlag(MOVEMENTFLAG_FLYING) || u->IsInFlight()); };
bool allowPath = generatePath;
Unit* master = botAI ? botAI->GetMaster() : nullptr;
if (isFlying(bot) || isFlying(master))
allowPath = false;
mm.Clear();
if (!backwards)
{
mm.MovePoint(0, x, y, z, FORCED_MOVEMENT_NONE, 0.0f, 0.0f, generatePath);
mm.MovePoint(0, x, y, z, FORCED_MOVEMENT_NONE, 0.0f, 0.0f, allowPath);
}
else
{
mm.MovePointBackwards(0, x, y, z, generatePath);
mm.MovePointBackwards(0, x, y, z, allowPath);
}
float delay = 1000.0f * MoveDelay(distance, backwards);
if (lessDelay)
@@ -1013,18 +1034,49 @@ void MovementAction::UpdateMovementState()
bot->GetMapWaterOrGroundLevel(bot->GetPositionX(), bot->GetPositionY(), bot->GetPositionZ()) + 1.0f;
// Keep bot->SendMovementFlagUpdate() withing the if statements to not intefere with bot behavior on ground/(shallow) waters
if (!bot->HasUnitMovementFlag(MOVEMENTFLAG_FLYING) &&
bot->HasAuraType(SPELL_AURA_MOD_INCREASE_MOUNTED_FLIGHT_SPEED) && !onGround)
{
bot->AddUnitMovementFlag(MOVEMENTFLAG_FLYING);
bot->SendMovementFlagUpdate();
}
else if (bot->HasUnitMovementFlag(MOVEMENTFLAG_FLYING) &&
(!bot->HasAuraType(SPELL_AURA_MOD_INCREASE_MOUNTED_FLIGHT_SPEED) || onGround))
bool hasFlightAura = bot->HasAuraType(SPELL_AURA_MOD_INCREASE_MOUNTED_FLIGHT_SPEED) || bot->HasAuraType(SPELL_AURA_FLY);
if (hasFlightAura)
{
bot->RemoveUnitMovementFlag(MOVEMENTFLAG_FLYING);
bot->SendMovementFlagUpdate();
bool changed = false;
if (!bot->HasUnitMovementFlag(MOVEMENTFLAG_CAN_FLY))
{
bot->AddUnitMovementFlag(MOVEMENTFLAG_CAN_FLY);
changed = true;
}
if (!bot->HasUnitMovementFlag(MOVEMENTFLAG_DISABLE_GRAVITY))
{
bot->AddUnitMovementFlag(MOVEMENTFLAG_DISABLE_GRAVITY);
changed = true;
}
if (!bot->HasUnitMovementFlag(MOVEMENTFLAG_FLYING))
{
bot->AddUnitMovementFlag(MOVEMENTFLAG_FLYING);
changed = true;
}
if (changed)
bot->SendMovementFlagUpdate();
}
else if (!hasFlightAura)
{
bool changed = false;
if (bot->HasUnitMovementFlag(MOVEMENTFLAG_FLYING))
{
bot->RemoveUnitMovementFlag(MOVEMENTFLAG_FLYING);
changed = true;
}
if (bot->HasUnitMovementFlag(MOVEMENTFLAG_DISABLE_GRAVITY))
{
bot->RemoveUnitMovementFlag(MOVEMENTFLAG_DISABLE_GRAVITY);
changed = true;
}
if (bot->HasUnitMovementFlag(MOVEMENTFLAG_CAN_FLY))
{
bot->RemoveUnitMovementFlag(MOVEMENTFLAG_CAN_FLY);
changed = true;
}
if (changed)
bot->SendMovementFlagUpdate();
}
// See if the bot is currently slowed, rooted, or otherwise unable to move
@@ -1122,13 +1174,6 @@ bool MovementAction::Follow(Unit* target, float distance, float angle)
if (!target)
return false;
if (!bot->InBattleground() && sServerFacade->IsDistanceLessOrEqualThan(sServerFacade->GetDistance2d(bot, target),
sPlayerbotAIConfig->followDistance))
{
// botAI->TellError("No need to follow");
return false;
}
/*
if (!bot->InBattleground()
&& sServerFacade->IsDistanceLessOrEqualThan(sServerFacade->GetDistance2d(bot, target->GetPositionX(),
@@ -1246,21 +1291,17 @@ bool MovementAction::Follow(Unit* target, float distance, float angle)
return MoveTo(target, sPlayerbotAIConfig->followDistance);
}
if (sServerFacade->IsDistanceLessOrEqualThan(sServerFacade->GetDistance2d(bot, target),
sPlayerbotAIConfig->followDistance))
{
// botAI->TellError("No need to follow");
return false;
}
if (target->IsFriendlyTo(bot) && bot->IsMounted() && AI_VALUE(GuidVector, "all targets").empty())
distance += angle;
if (!bot->InBattleground() && sServerFacade->IsDistanceLessOrEqualThan(sServerFacade->GetDistance2d(bot, target),
sPlayerbotAIConfig->followDistance))
// Do not cancel follow if the 2D distance is short but the Z still differs (e.g., master above).
float dz1 = fabs(bot->GetPositionZ() - target->GetPositionZ());
if (!bot->InBattleground()
&& sServerFacade->IsDistanceLessOrEqualThan(sServerFacade->GetDistance2d(bot, target), sPlayerbotAIConfig->followDistance)
&& dz1 < sPlayerbotAIConfig->contactDistance)
{
// botAI->TellError("No need to follow");
return false;
return false; // truly in range (2D and Z) => no need to move
}
bot->HandleEmoteCommand(0);

View File

@@ -205,17 +205,18 @@ void TalkToQuestGiverAction::RewardMultipleItem(Quest const* quest, Object* ques
}
else
{
// Try to pick the usable item. If multiple list usable rewards.
// Try to pick the usable item. If multiple, list usable rewards.
bestIds = BestRewards(quest);
if (!bestIds.empty())
{
if (bestIds.size() > 1)
AskToSelectReward(quest, out, true);
}
else
else if (!bestIds.empty())
{
// Pick the first item
ItemTemplate const* item = sObjectMgr->GetItemTemplate(quest->RewardChoiceItemId[*bestIds.begin()]);
bot->RewardQuest(quest, *bestIds.begin(), questGiver, true);
uint32 firstId = *bestIds.begin();
ItemTemplate const* item = sObjectMgr->GetItemTemplate(quest->RewardChoiceItemId[firstId]);
bot->RewardQuest(quest, firstId, questGiver, true);
out << "Rewarded " << ChatHelper::FormatItem(item);
}