Bots: Add a bot brings the class you picked

With hired bots on, ".bot add <class> <role>" called any free companion
of that role when none of the picked class was free. Picking a Shaman
healer brought a Priest, a Paladin tank brought a Warrior or a Druid,
so the raid filled with the wrong classes.

Now only a free companion of the picked class comes; if there is none,
a Sellsword of that class is hired at a broker, or the message names
the class. Quick party still takes any free bot of the role (it picks
the classes itself) and says so with the new word "anyclass".
Add-on 0.6.21.

(cherry picked from commit 200e7ebeef55996a11d4c8b155717bdc92ade1ce)
This commit is contained in:
Karrz1
2026-11-11 23:43:45 +00:00
parent 241dc86a09
commit 7c70f336ff
3 changed files with 99 additions and 11 deletions
@@ -518,9 +518,10 @@ local function DeleteTarget()
if dialog then dialog.data = name end
end
local function AddBot(class, role)
local function AddBot(class, role, anyClass)
if role then
ServerCommand(".bot add " .. class .. " " .. role)
-- "anyclass" (Quick party only): with hired bots, a free one of that role may come in another class.
ServerCommand(".bot add " .. class .. " " .. role .. (anyClass and " anyclass" or ""))
else
ServerCommand(".bot add " .. class)
end
@@ -1067,9 +1068,9 @@ local function SendGear()
return g == "match"
end
local function AddBotWithGear(class, role)
local function AddBotWithGear(class, role, anyClass)
local sent = SendGear()
AddBot(class, role)
AddBot(class, role, anyClass)
if not sent and C_Timer and C_Timer.After then
-- no group yet: the first bot makes one, so the gear word follows once it exists (it applies to the next bots)
C_Timer.After(2.5, function() Auto(SendGear) end)
@@ -1135,15 +1136,15 @@ local function QuickParty()
-- The first bot is said straight from the click and makes the group; the rest follow a moment apart from a timer, where
-- chat is blocked, so they run under Auto() and go out one by one as addon messages (ServerCommand, Cmd.Queue).
local roster = QuickPartyRoster(size, free)
AddBotWithGear(roster[1][1], roster[1][2])
AddBotWithGear(roster[1][1], roster[1][2], true)
if roster[2] and C_Timer and C_Timer.After then
C_Timer.After(0.4, function()
Auto(function()
for i = 2, #roster do AddBotWithGear(roster[i][1], roster[i][2]) end
for i = 2, #roster do AddBotWithGear(roster[i][1], roster[i][2], true) end
end)
end)
else
for i = 2, #roster do AddBotWithGear(roster[i][1], roster[i][2]) end
for i = 2, #roster do AddBotWithGear(roster[i][1], roster[i][2], true) end
end
end
@@ -2,7 +2,7 @@
## Title: WoW Forever Bots
## Notes: One-click PlayerbotV2 companions: add a bot of any class and role, call, dismiss and command your bots.
## Author: Karrz
## Version: 0.6.20
## Version: 0.6.21
## IconTexture: Interface\AddOns\ForeverBots\Textures\mono_fb64.tga
## SavedVariables: ForeverBotsDB
@@ -981,6 +981,7 @@ public:
Playerbot::Role role = Playerbot::Role::Unknown;
uint8 race = 0;
uint8 gender = uint8(urand(GENDER_MALE, GENDER_FEMALE));
bool anyClass = false;
for (Optional<std::string> const* arg : { &arg2, &arg3, &arg4 })
{
if (!*arg)
@@ -989,6 +990,8 @@ public:
bool is_role = false;
Playerbot::Role const r = ParseRoleWord(word, is_role);
if (is_role) { role = r; continue; }
// "anyclass": the add-on's Quick party picks the classes itself, so with hired bots any free one of the role may come.
if (word == "anyclass") { anyClass = true; continue; }
if (word == "male" || word == "m") { gender = GENDER_MALE; continue; }
if (word == "female" || word == "f") { gender = GENDER_FEMALE; continue; }
if (uint8 const parsed = ParseRace(word); parsed && IsClassicRace(parsed)) { race = parsed; continue; }
@@ -997,16 +1000,100 @@ public:
}
std::string outMsg;
bool const ok = AddCompanionFor(me, sess, cls, role, race, gender, class_arg, outMsg);
handler->SendSysMessage(outMsg.c_str());
bool const ok = AddCompanionFor(me, sess, cls, role, race, gender, class_arg, outMsg,
Playerbot::V2::Fleet::Hire::Grade::None, /*finder*/ false, anyClass);
if (!outMsg.empty()) // a hired companion that was called instead has said so itself
handler->SendSysMessage(outMsg.c_str());
return ok ? true : Refuse(handler);
}
// A companion of `me`'s account that is not out (not in the group, not called a moment ago) for `role`, the same class first:
// in hired mode it comes instead of a new bot. 0 = none. Another class of the same role comes only with `anyClass` (Quick
// party): a player who picked a class gets that class (the owner 2026-11-09: Shaman and Paladin bots picked in the add-on,
// Priests, Warriors and Druids came instead).
static Playerbot::BotId IdleHiredCompanion(Player* me, WorldSession* sess, uint8 cls, Playerbot::Role role, bool anyClass)
{
using Playerbot::V2::Fleet::HireMgr;
uint32 const now = getMSTime();
Group const* group = me->GetGroup();
Playerbot::BotId fallback = 0;
for (Playerbot::BotId id : CompanionsMatching(sess, "all"))
{
ObjectGuid const guid = ObjectGuid::Create<HighGuid::Player>(id);
if ((group && group->IsMember(guid)) || HireMgr::Instance().RecentlyCalled(id, now) || HireMgr::Instance().IsLoaned(id))
continue; // (a Group Finder loan bot only plays inside the group it was made for)
if (Player const* online = ObjectAccessor::FindConnectedPlayer(guid); online && online->GetGroup())
continue; // out with someone else of the account
// A companion bound to another character of the account stays with that character: called for this one it joined, the
// group check (CompanionGroupHygiene) found its owner character missing and sent it away a second later, and it came at
// that character's level (the owner 2026-11-07: his main's level 60 companions for his level 33 alt).
if (uint64 const ownerChar = Playerbot::Services::Owners().GetOwner(id).player_guid; ownerChar != 0 && ownerChar != me->GetGUID().GetCounter())
continue;
Playerbot::Role const declared = Playerbot::Services::Owners().DeclaredRole(id);
if (role != Playerbot::Role::Unknown && declared != role)
continue;
CharacterCacheEntry const* entry = sCharacterCache->GetCharacterCacheByGuid(guid);
if (!entry)
continue;
// A companion above the caller's level would come at its own level (bots are levelled up to the owner, never down): a
// fitting one is hired instead (the owner 2026-11-07: an account-wide level 60 companion joined his level 33 character).
if (entry->Level > me->GetLevel())
continue;
if (entry->Class == cls)
return id;
if (anyClass && !fallback && role != Playerbot::Role::Unknown)
fallback = id;
}
return fallback;
}
// Creates one companion of `cls` (race 0 = pick one) for `me` and logs it in; it joins the owner's group through the
// normal companion setup. Shared by `.bot add` and the Group Finder bot fill. `outMsg` is what the owner is told.
static bool AddCompanionFor(Player* me, WorldSession* sess, uint8 cls, Playerbot::Role role, uint8 race, uint8 gender,
std::string const& className, std::string& outMsg)
std::string const& className, std::string& outMsg,
Playerbot::V2::Fleet::Hire::Grade hireGrade = Playerbot::V2::Fleet::Hire::Grade::None,
bool finder = false, bool anyClass = false)
{
namespace Hire = Playerbot::V2::Fleet::Hire;
using Playerbot::V2::Fleet::HireMgr;
HireMgr& hire = HireMgr::Instance();
bool const loan = finder && hireGrade == Hire::Grade::None && hire.MustHire(me);
if (!loan && hireGrade == Hire::Grade::None && hire.MustHire(me))
{
if (Playerbot::BotId const idle = IdleHiredCompanion(me, sess, cls, role, anyClass))
{
hire.NoteCalled(idle, getMSTime());
ChatHandler handler(sess);
outMsg.clear();
return CallCompanions(&handler, CompanionName(idle), false);
}
if (!hire.NearbyBroker(me, Hire::Grade::Sellsword))
{
char const* const roleWord = role == Playerbot::Role::Tank ? "tank" : role == Playerbot::Role::Healer ? "healer" : "fighter";
// A picked class is named: "no hired shaman healer free", not "no hired healer free" while a Priest healer sits idle.
std::string const what = anyClass ? std::string(roleWord)
: className + (role == Playerbot::Role::Unknown ? "" : role == Playerbot::Role::Dps ? " dps" : " " + std::string(roleWord));
outMsg = Trinity::StringFormat("Hired bots only on this realm: you have no hired {} free. Hire one from a Sellsword Captain at an inn or in a capital city (the Group Finder and the dungeon finder still bring bots).", what);
return false;
}
hireGrade = Hire::Grade::Sellsword;
}
uint64 price = 0;
if (hireGrade != Hire::Grade::None)
{
if (!hire.NearbyBroker(me, hireGrade))
{ outMsg = Trinity::StringFormat("There is nobody here who hires out a {}.", Hire::GradeName(hireGrade)); return false; }
price = HireMgr::PriceHere(me, hireGrade);
if (!price)
{ outMsg = Trinity::StringFormat("A {} only signs on with a level {} hero.", Hire::GradeName(hireGrade), uint32(Playerbot::MaxPlayerLevel())); return false; }
if (uint32 const max = HireMgr::MaxPerAccount(); max && Playerbot::Services::Owners().BotsOwnedBy(sess->GetAccountId()).size() >= max)
{ outMsg = Trinity::StringFormat("You have {} bots already, the most this realm allows. End a contract first.", max); return false; }
if (uint32 const max = HireMgr::LegendMaxPerAccount(); hireGrade == Hire::Grade::Legend && max && hire.CountGrade(sess->GetAccountId(), Hire::Grade::Legend) >= max)
{ outMsg = Trinity::StringFormat("The cartel hires out {} Legend(s) to one hero at a time.", max); return false; }
if (!me->HasEnoughMoney(price))
{ outMsg = Trinity::StringFormat("You need {} to hire a {}.", Hire::MoneyText(price), Hire::GradeName(hireGrade)); return false; }
}
if (race && !Playerbot::V2::BotComposition::IsLegalRaceClass(race, cls))
{ outMsg = "That race can't be a " + className + "."; return false; }
if (race && Player::TeamForRace(race) != me->GetTeam())