From 69f6f6249c214011a5f3ef5c8541f615cc7e498b Mon Sep 17 00:00:00 2001 From: Karrz1 <127596890+Karrz1@users.noreply.github.com> Date: Mon, 23 Nov 2026 22:18:35 +0000 Subject: [PATCH] Bots: hired bots (sellsword brokers) in the bot module, as their own part (Hire/) The hire brokers were in the world database without their code, so for a server built from this source the Sellsword Captains, Veteran Recruiters and Black Market Brokers did nothing. Here is the code, as it runs in the WoW Forever Bots repack, built so it can be left out or replaced: - Hire/: the brokers' gossip (npc_fb_hire_broker), the contracts (HireMgr), the rules (HirePolicy.h: prices, grades, upkeep, who must hire) and HireModule.cpp, which registers them. Hire/README.md explains the grades, the Playerbot.Hire.* settings, the commands and how another hire module plugs in. - HireHooks.h/.cpp and HireTypes.h: the one door between the bot module and hired bots. `.bot add`, `.bot call`, `.bot delete`, the Group Finder, companion upkeep, gear and the add-on ask Fleet::Hiring(); without a hire module the answer is "no hired bots" and companions are free as before. - CMake option PLAYERBOT_V2_HIRE (default on). Off: `.bot hire` and the brokers say there are no hired bots. - `.bot hire [on|off]`, the ForeverBots add-on's hired-bots-only view (ForeverBots_Hire.lua, /fb hire), the Playerbot.Hire.* settings in playerbot.conf.dist (Mode 0 = off by default). - SQL: the 39 brokers and their gossip menu (world, same files as the repack), the contracts table (sql/playerbot_v2/0037_hired_bots.sql, applied by the module at start). - tests/game/ClassicHirePolicy.cpp pins the rules. --- INSTALL-BOTS.md | 4 + ...26_10_31_20_world_forever_hire_brokers.sql | 184 +++++++++ ...01_20_world_forever_hire_broker_gossip.sql | 51 +++ sql/playerbot_v2/0037_hired_bots.sql | 27 ++ .../Addon/ForeverBots/ForeverBots.lua | 11 +- .../Addon/ForeverBots/ForeverBots.toc | 1 + .../Addon/ForeverBots/ForeverBots_Hire.lua | 62 +++ .../Addon/ForeverBots/Locale_ruRU.lua | 4 +- .../PlayerbotV2/Addon/ForeverBots/README.md | 2 + src/modules/PlayerbotV2/BOT_COMMANDS.md | 1 + src/modules/PlayerbotV2/CMakeLists.txt | 27 +- .../PlayerbotV2/Commands/cs_playerbot_v2.cpp | 152 ++++++- .../Fleet/BotPopulationManager.cpp | 61 +++ .../PlayerbotV2/Fleet/BotPopulationManager.h | 6 +- src/modules/PlayerbotV2/Hire/HireBroker.cpp | 266 +++++++++++++ src/modules/PlayerbotV2/Hire/HireBroker.h | 10 + src/modules/PlayerbotV2/Hire/HireMgr.cpp | 376 ++++++++++++++++++ src/modules/PlayerbotV2/Hire/HireMgr.h | 101 +++++ src/modules/PlayerbotV2/Hire/HireModule.cpp | 142 +++++++ src/modules/PlayerbotV2/Hire/HirePolicy.h | 229 +++++++++++ src/modules/PlayerbotV2/Hire/README.md | 114 ++++++ src/modules/PlayerbotV2/HireHooks.cpp | 62 +++ src/modules/PlayerbotV2/HireHooks.h | 109 +++++ src/modules/PlayerbotV2/HireTypes.h | 16 + src/modules/PlayerbotV2/INSTALL.md | 4 + src/modules/PlayerbotV2/LfgBotFill.cpp | 6 +- src/modules/PlayerbotV2/LfgBotFill.h | 2 +- .../PlayerbotV2/PlayerbotV2Scripts.cpp | 10 + src/modules/PlayerbotV2/Services.cpp | 3 + .../PlayerbotV2/Session/AddonControl.cpp | 24 ++ .../PlayerbotV2/conf/playerbot.conf.dist | 58 +++ tests/CMakeLists.txt | 1 + tests/game/ClassicHirePolicy.cpp | 153 +++++++ 33 files changed, 2261 insertions(+), 18 deletions(-) create mode 100644 sql/custom/world/2026_10_31_20_world_forever_hire_brokers.sql create mode 100644 sql/custom/world/2026_11_01_20_world_forever_hire_broker_gossip.sql create mode 100644 sql/playerbot_v2/0037_hired_bots.sql create mode 100644 src/modules/PlayerbotV2/Addon/ForeverBots/ForeverBots_Hire.lua create mode 100644 src/modules/PlayerbotV2/Hire/HireBroker.cpp create mode 100644 src/modules/PlayerbotV2/Hire/HireBroker.h create mode 100644 src/modules/PlayerbotV2/Hire/HireMgr.cpp create mode 100644 src/modules/PlayerbotV2/Hire/HireMgr.h create mode 100644 src/modules/PlayerbotV2/Hire/HireModule.cpp create mode 100644 src/modules/PlayerbotV2/Hire/HirePolicy.h create mode 100644 src/modules/PlayerbotV2/Hire/README.md create mode 100644 src/modules/PlayerbotV2/HireHooks.cpp create mode 100644 src/modules/PlayerbotV2/HireHooks.h create mode 100644 src/modules/PlayerbotV2/HireTypes.h create mode 100644 tests/game/ClassicHirePolicy.cpp diff --git a/INSTALL-BOTS.md b/INSTALL-BOTS.md index 8e82af7356..d3c6cfd029 100644 --- a/INSTALL-BOTS.md +++ b/INSTALL-BOTS.md @@ -72,6 +72,10 @@ console: `account set gmlevel 3 -1`). - Raids: add the bots, enter the instance, use the window's Pull and Release. A good Molten Core group is 4 tanks, 12 healers, 6 mages, 4 warlocks, 3 hunters, 5 rogues, 4 warriors. - Battlegrounds: queue yourself; bots fill the other places. +- Hired bots: a Sellsword Captain stands beside the innkeeper of 30 towns, a Veteran Recruiter in each capital and a + Black Market Broker in Gadgetzan, Booty Bay and Ratchet. Talk to one to hire a bot for gold (Veterans and Legends wear + raid and best-in-slot gear at the level cap). Free bots stay the default; `Playerbot.Hire.Mode = 1` makes the realm + hired bots only. Everything about them: `src/modules/PlayerbotV2/Hire/README.md`. ## Updating, removing, reporting problems diff --git a/sql/custom/world/2026_10_31_20_world_forever_hire_brokers.sql b/sql/custom/world/2026_10_31_20_world_forever_hire_brokers.sql new file mode 100644 index 0000000000..62e4e69411 --- /dev/null +++ b/sql/custom/world/2026_10_31_20_world_forever_hire_brokers.sql @@ -0,0 +1,184 @@ +-- The hire brokers move to entries 6110000-6110299 (and spawn guids 61100000-61100099): the client reads a creature entry in 23 bits, +-- so an entry of 9110000 arrived as 721392 (9110000 - 8388608) and the client showed an empty "Level 1" unit that cannot be talked to. +-- The first lines remove the rows of the old numbers where an earlier test build placed them. Safe to run again. +DELETE FROM `creature` WHERE `id` BETWEEN 9110000 AND 9110299; +DELETE FROM `creature_template_model` WHERE `CreatureID` BETWEEN 9110000 AND 9110299; +DELETE FROM `creature_template_difficulty` WHERE `Entry` BETWEEN 9110000 AND 9110299; +DELETE FROM `creature_template` WHERE `entry` BETWEEN 9110000 AND 9110299; + +-- Hired bots (Playerbot.Hire.*, src/modules/PlayerbotV2/Fleet/HireBroker.cpp): the hire brokers. Idea from Neylem (WoW Forever +-- Discord, 2026-10-29). Each stands beside the innkeeper of its town, 2.5 yards to the innkeeper's left and facing the same way, +-- placed from the innkeeper's own spawn in the 2026-10-14 world data; fine-tuned in game where a counter or wall is in the way. +-- 6110000-6110099 Sellsword Captain 15 Alliance and 15 Horde inns: Sellswords at the hirer's level +-- 6110100-6110199 Veteran Recruiter the six capitals: Sellswords, and Veterans (level cap, raid gear) +-- 6110200-6110299 Black Market Broker Gadgetzan, Booty Bay, Ratchet: Legends (level cap, best in slot), both factions +-- Faction and level tuning are the innkeeper's; the models are existing Classic guard and mercenary models. Gossip only (npcflag 1), +-- the menu is the script's; the brokers do nothing while Playerbot.Hire.Mode is 0 except hire Veterans and Legends on request. + +DELETE FROM `creature` WHERE `guid` BETWEEN 61100000 AND 61100099; +DELETE FROM `creature_template` WHERE `entry` BETWEEN 6110000 AND 6110299; +INSERT INTO `creature_template` (`entry`,`KillCredit1`,`KillCredit2`,`name`,`femaleName`,`subname`,`TitleAlt`,`IconName`,`RequiredExpansion`,`VignetteID`,`faction`,`npcflag`,`speed_walk`,`speed_run`,`scale`,`Classification`,`dmgschool`,`BaseAttackTime`,`RangeAttackTime`,`BaseVariance`,`RangeVariance`,`unit_class`,`unit_flags`,`unit_flags2`,`unit_flags3`,`family`,`trainer_class`,`type`,`VehicleId`,`AIName`,`MovementType`,`ExperienceModifier`,`RacialLeader`,`movementId`,`WidgetSetID`,`WidgetSetUnitConditionID`,`RegenHealth`,`CreatureImmunitiesId`,`flags_extra`,`ScriptName`,`StringId`,`VerifiedBuild`) VALUES +(6110000,0,0,'Brannock Ironhale','','Sellsword Captain',NULL,NULL,0,0,12,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- Goldshire +(6110001,0,0,'Thordin Coppervein','','Sellsword Captain',NULL,NULL,0,0,55,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- Kharanos +(6110002,0,0,'Hargan Stonefist','','Sellsword Captain',NULL,NULL,0,0,80,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- Dolanaar +(6110003,0,0,'Durgan Flintbeard','','Sellsword Captain',NULL,NULL,0,0,12,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- Lakeshire +(6110004,0,0,'Moran Gravelhand','','Sellsword Captain',NULL,NULL,0,0,12,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- Darkshire +(6110005,0,0,'Kelgar Anvilmar','','Sellsword Captain',NULL,NULL,0,0,55,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- Menethil Harbor +(6110006,0,0,'Bruni Hammerfell','','Sellsword Captain',NULL,NULL,0,0,12,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- Southshore +(6110007,0,0,'Gorvik Deepforge','','Sellsword Captain',NULL,NULL,0,0,80,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- Astranaar +(6110008,0,0,'Tharin Ironbrow','','Sellsword Captain',NULL,NULL,0,0,80,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- Auberdine +(6110009,0,0,'Belgrom Rockshield','','Sellsword Captain',NULL,NULL,0,0,894,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- Theramore +(6110010,0,0,'Rurik Stoutmantle','','Sellsword Captain',NULL,NULL,0,0,55,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- Thelsamar +(6110011,0,0,'Dagna Emberforge','','Sellsword Captain',NULL,NULL,0,0,80,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- Stonetalon Peak +(6110012,0,0,'Haldor Frostbeard','','Sellsword Captain',NULL,NULL,0,0,80,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- Nijel's Point +(6110013,0,0,'Brakka Ironsong','','Sellsword Captain',NULL,NULL,0,0,80,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- Feathermoon Stronghold +(6110014,0,0,'Fendrel Skyhammer','','Sellsword Captain',NULL,NULL,0,0,694,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- Aerie Peak +(6110015,0,0,'Mak''zar Bloodfist','','Sellsword Captain',NULL,NULL,0,0,29,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- Razor Hill +(6110016,0,0,'Torgal Ironhide','','Sellsword Captain',NULL,NULL,0,0,29,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- Bloodhoof Village +(6110017,0,0,'Kragosh Deadeye','','Sellsword Captain',NULL,NULL,0,0,68,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- Brill +(6110018,0,0,'Urzog Skullsplitter','','Sellsword Captain',NULL,NULL,0,0,29,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- The Crossroads +(6110019,0,0,'Gharn Blackmaw','','Sellsword Captain',NULL,NULL,0,0,68,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- The Sepulcher +(6110020,0,0,'Rokash Grimtusk','','Sellsword Captain',NULL,NULL,0,0,68,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- Tarren Mill +(6110021,0,0,'Drogar Warblade','','Sellsword Captain',NULL,NULL,0,0,29,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- Splintertree Post +(6110022,0,0,'Brakhar Stonejaw','','Sellsword Captain',NULL,NULL,0,0,29,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- Hammerfall +(6110023,0,0,'Zugrak Bonecleaver','','Sellsword Captain',NULL,NULL,0,0,29,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- Camp Taurajo +(6110024,0,0,'Nargash Swampfang','','Sellsword Captain',NULL,NULL,0,0,29,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- Stonard +(6110025,0,0,'Kurzog Dustmane','','Sellsword Captain',NULL,NULL,0,0,104,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- Freewind Post +(6110026,0,0,'Gorrak Stoneclaw','','Sellsword Captain',NULL,NULL,0,0,29,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- Sun Rock Retreat +(6110027,0,0,'Murgol Ashfist','','Sellsword Captain',NULL,NULL,0,0,29,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- Kargath +(6110028,0,0,'Vrakka Saltblade','','Sellsword Captain',NULL,NULL,0,0,104,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- Shadowprey Village +(6110029,0,0,'Grushak Ironjaw','','Sellsword Captain',NULL,NULL,0,0,29,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- Camp Mojache +(6110100,0,0,'Commander Ardrel Vaine','','Veteran Recruiter',NULL,NULL,0,0,12,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- Stormwind +(6110101,0,0,'Commander Haldrun Forgeheart','','Veteran Recruiter',NULL,NULL,0,0,55,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- Ironforge +(6110102,0,0,'Sentinel Commander Ilyara Moonblade','','Veteran Recruiter',NULL,NULL,0,0,80,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- Darnassus +(6110103,0,0,'Blood Guard Gor''thak','','Veteran Recruiter',NULL,NULL,0,0,29,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- Orgrimmar +(6110104,0,0,'Blood Guard Harnak Grimhoof','','Veteran Recruiter',NULL,NULL,0,0,104,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- Thunder Bluff +(6110105,0,0,'Deathguard Commander Morvane','','Veteran Recruiter',NULL,NULL,0,0,68,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- Undercity +(6110200,0,0,'Krixel Pocketlint','','Black Market Broker',NULL,NULL,0,0,474,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- Gadgetzan +(6110201,0,0,'Zazzo Silkpurse','','Black Market Broker',NULL,NULL,0,0,120,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0), -- Booty Bay +(6110202,0,0,'Nixxle Quickcoin','','Black Market Broker',NULL,NULL,0,0,69,1,1,1.14286,1,0,0,2000,2000,1,1,1,0,0,0,0,0,7,0,'',0,1,0,0,0,0,1,0,2,'npc_fb_hire_broker',NULL,0); -- Ratchet + +DELETE FROM `creature_template_model` WHERE `CreatureID` BETWEEN 6110000 AND 6110299; +INSERT INTO `creature_template_model` (`CreatureID`,`Idx`,`CreatureDisplayID`,`DisplayScale`,`Probability`,`VerifiedBuild`) VALUES +(6110000,0,1598,1,1,0), +(6110001,0,1598,1,1,0), +(6110002,0,1598,1,1,0), +(6110003,0,1598,1,1,0), +(6110004,0,1598,1,1,0), +(6110005,0,1598,1,1,0), +(6110006,0,1598,1,1,0), +(6110007,0,1598,1,1,0), +(6110008,0,1598,1,1,0), +(6110009,0,1598,1,1,0), +(6110010,0,1598,1,1,0), +(6110011,0,1598,1,1,0), +(6110012,0,1598,1,1,0), +(6110013,0,1598,1,1,0), +(6110014,0,1598,1,1,0), +(6110015,0,4259,1,1,0), +(6110016,0,4259,1,1,0), +(6110017,0,4259,1,1,0), +(6110018,0,4259,1,1,0), +(6110019,0,4259,1,1,0), +(6110020,0,4259,1,1,0), +(6110021,0,4259,1,1,0), +(6110022,0,4259,1,1,0), +(6110023,0,4259,1,1,0), +(6110024,0,4259,1,1,0), +(6110025,0,4259,1,1,0), +(6110026,0,4259,1,1,0), +(6110027,0,4259,1,1,0), +(6110028,0,4259,1,1,0), +(6110029,0,4259,1,1,0), +(6110100,0,3167,1,1,0), +(6110101,0,1598,1,1,0), +(6110102,0,2306,1,1,0), +(6110103,0,14360,1,1,0), +(6110104,0,2141,1,1,0), +(6110105,0,7117,1,1,0), +(6110200,0,7107,1,1,0), +(6110201,0,7107,1,1,0), +(6110202,0,7107,1,1,0); + +DELETE FROM `creature_template_difficulty` WHERE `Entry` BETWEEN 6110000 AND 6110299; +INSERT INTO `creature_template_difficulty` (`Entry`,`DifficultyID`,`LevelScalingDeltaMin`,`LevelScalingDeltaMax`,`ContentTuningID`,`HealthScalingExpansion`,`HealthModifier`,`ManaModifier`,`ArmorModifier`,`DamageModifier`,`CreatureDifficultyID`,`TypeFlags`,`TypeFlags2`,`TypeFlags3`,`LootID`,`PickPocketLootID`,`SkinLootID`,`GoldMin`,`GoldMax`,`StaticFlags1`,`StaticFlags2`,`StaticFlags3`,`StaticFlags4`,`StaticFlags5`,`StaticFlags6`,`StaticFlags7`,`StaticFlags8`,`VerifiedBuild`) VALUES +(6110000,0,0,0,73,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110001,0,0,0,74,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110002,0,0,0,72,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110003,0,0,0,10,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110004,0,0,0,13,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110005,0,0,0,15,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110006,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110007,0,0,0,12,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110008,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110009,0,0,0,23,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110010,0,0,0,9,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110011,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110012,0,0,0,19,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110013,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110014,0,0,0,20,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110015,0,0,0,70,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110016,0,0,0,71,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110017,0,0,0,75,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110018,0,0,0,3,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110019,0,0,0,7,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110020,0,0,0,11,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110021,0,0,0,12,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110022,0,0,0,17,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110023,0,0,0,16,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110024,0,0,0,31,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110025,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110026,0,0,0,14,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110027,0,0,0,27,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110028,0,0,0,19,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110029,0,0,0,22,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110100,0,0,0,864,11,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110101,0,0,0,868,11,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110102,0,0,0,876,11,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110103,0,0,0,866,11,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110104,0,0,0,865,11,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110105,0,0,0,867,11,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110200,0,0,0,28,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110201,0,0,0,24,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), +(6110202,0,0,0,3,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0); + +INSERT INTO `creature` (`guid`,`id`,`map`,`zoneId`,`areaId`,`spawnDifficulties`,`phaseUseFlags`,`PhaseId`,`PhaseGroup`,`terrainSwapMap`,`modelid`,`equipment_id`,`position_x`,`position_y`,`position_z`,`orientation`,`spawntimesecs`,`wander_distance`,`currentwaypoint`,`curHealthPct`,`MovementType`,`npcflag`,`unit_flags`,`unit_flags2`,`unit_flags3`,`ScriptName`,`StringId`,`VerifiedBuild`) VALUES +(61100000,6110000,0,0,0,'0',0,0,0,-1,0,0,-9462.921,13.705,57.046,3.0369,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- Goldshire, beside innkeeper 295 +(61100001,6110001,0,0,0,'0',0,0,0,-1,0,0,-5603.720,-532.528,399.737,2.1293,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- Kharanos, beside innkeeper 1247 +(61100002,6110002,1,0,0,'0',0,0,0,-1,0,0,9804.700,982.826,1313.980,4.7997,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- Dolanaar, beside innkeeper 6736 +(61100003,6110003,0,0,0,'0',0,0,0,-1,0,0,-9224.198,-2159.610,64.017,3.0543,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- Lakeshire, beside innkeeper 6727 +(61100004,6110004,0,0,0,'0',0,0,0,-1,0,0,-10514.057,-1162.783,28.116,4.0317,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- Darkshire, beside innkeeper 6790 +(61100005,6110005,0,0,0,'0',0,0,0,-1,0,0,-3828.907,-829.600,10.091,0.4014,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- Menethil Harbor, beside innkeeper 1464 +(61100006,6110006,0,0,0,'0',0,0,0,-1,0,0,-859.596,-570.707,11.264,1.5533,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- Southshore, beside innkeeper 2352 +(61100007,6110007,1,0,0,'0',0,0,0,-1,0,0,2779.835,-435.117,116.665,2.5831,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- Astranaar, beside innkeeper 6738 +(61100008,6110008,1,0,0,'0',0,0,0,-1,0,0,6404.119,516.098,8.726,1.2741,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- Auberdine, beside innkeeper 6737 +(61100009,6110009,1,0,0,'0',0,0,0,-1,0,0,-3618.127,-4472.325,14.329,2.2166,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- Theramore, beside innkeeper 6272 +(61100010,6110010,0,0,0,'0',0,0,0,-1,0,0,-5380.355,-2974.430,323.252,1.7802,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- Thelsamar, beside innkeeper 6734 +(61100011,6110011,1,0,0,'0',0,0,0,-1,0,0,2731.850,1496.601,237.593,4.0492,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- Stonetalon Peak, beside innkeeper 16458 +(61100012,6110012,1,0,0,'0',0,0,0,-1,0,0,255.876,1251.274,192.224,3.2463,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- Nijel's Point, beside innkeeper 11103 +(61100013,6110013,1,0,0,'0',0,0,0,-1,0,0,-4381.677,3291.948,13.627,0.0349,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- Feathermoon Stronghold, beside innkeeper 7736 +(61100014,6110014,0,0,0,'0',0,0,0,-1,0,0,397.098,-2096.599,131.562,4.9305,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- Aerie Peak, beside innkeeper 7744 +(61100015,6110015,1,0,0,'0',0,0,0,-1,0,0,342.527,-4687.540,16.541,4.1888,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- Razor Hill, beside innkeeper 6928 +(61100016,6110016,1,0,0,'0',0,0,0,-1,0,0,-2364.313,-345.044,-8.874,5.8468,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- Bloodhoof Village, beside innkeeper 6747 +(61100017,6110017,0,0,0,'0',0,0,0,-1,0,0,2270.944,242.896,34.340,3.7525,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- Brill, beside innkeeper 5688 +(61100018,6110018,1,0,0,'0',0,0,0,-1,0,0,-406.392,-2647.611,96.306,3.4383,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- The Crossroads, beside innkeeper 3934 +(61100019,6110019,0,0,0,'0',0,0,0,-1,0,0,513.217,1635.493,126.027,4.3110,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- The Sepulcher, beside innkeeper 6739 +(61100020,6110020,0,0,0,'0',0,0,0,-1,0,0,-6.942,-944.585,57.162,2.7415,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- Tarren Mill, beside innkeeper 2388 +(61100021,6110021,1,0,0,'0',0,0,0,-1,0,0,2339.973,-2568.630,102.857,2.2864,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- Splintertree Post, beside innkeeper 12196 +(61100022,6110022,0,0,0,'0',0,0,0,-1,0,0,-912.374,-3527.420,72.768,3.1416,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- Hammerfall, beside innkeeper 9501 +(61100023,6110023,1,0,0,'0',0,0,0,-1,0,0,-2378.457,-1994.528,96.788,1.0647,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- Camp Taurajo, beside innkeeper 7714 +(61100024,6110024,0,0,0,'0',0,0,0,-1,0,0,-10487.561,-3256.354,21.113,0.1047,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- Stonard, beside innkeeper 6930 +(61100025,6110025,1,0,0,'0',0,0,0,-1,0,0,-5478.623,-2458.052,89.367,0.3142,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- Freewind Post, beside innkeeper 11116 +(61100026,6110026,1,0,0,'0',0,0,0,-1,0,0,895.014,930.044,106.364,5.7072,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- Sun Rock Retreat, beside innkeeper 7731 +(61100027,6110027,0,0,0,'0',0,0,0,-1,0,0,-6648.213,-2151.050,245.352,3.9968,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- Kargath, beside innkeeper 9356 +(61100028,6110028,1,0,0,'0',0,0,0,-1,0,0,-1590.675,3149.020,46.578,4.1888,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- Shadowprey Village, beside innkeeper 11106 +(61100029,6110029,1,0,0,'0',0,0,0,-1,0,0,-4461.312,244.909,39.191,0.5061,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- Camp Mojache, beside innkeeper 7737 +(61100030,6110100,0,0,0,'0',0,0,0,-1,0,0,-8865.583,674.847,97.986,5.2011,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- Stormwind, beside innkeeper 6740 +(61100031,6110101,0,0,0,'0',0,0,0,-1,0,0,-4838.201,-856.703,501.997,4.8695,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- Ironforge, beside innkeeper 5111 +(61100032,6110102,1,0,0,'0',0,0,0,-1,0,0,10125.903,2223.285,1328.810,2.2166,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- Darnassus, beside innkeeper 6735 +(61100033,6110103,1,0,0,'0',0,0,0,-1,0,0,1633.053,-4441.688,15.517,2.7576,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- Orgrimmar, beside innkeeper 6929 +(61100034,6110104,1,0,0,'0',0,0,0,-1,0,0,-1301.605,40.606,129.292,0.5585,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- Thunder Bluff, beside innkeeper 6746 +(61100035,6110105,0,0,0,'0',0,0,0,-1,0,0,1634.669,220.940,-43.020,2.8449,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- Undercity, beside innkeeper 6741 +(61100036,6110200,1,0,0,'0',0,0,0,-1,0,0,-7161.278,-3842.547,8.848,1.9548,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- Gadgetzan, beside innkeeper 7733 +(61100037,6110201,0,0,0,'0',0,0,0,-1,0,0,-14455.842,493.675,15.213,3.9794,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0), -- Booty Bay, beside innkeeper 6807 +(61100038,6110202,1,0,0,'0',0,0,0,-1,0,0,-1049.351,-3662.397,23.968,6.0039,300,0,0,100,0,NULL,NULL,NULL,NULL,'',NULL,0); -- Ratchet, beside innkeeper 6791 diff --git a/sql/custom/world/2026_11_01_20_world_forever_hire_broker_gossip.sql b/sql/custom/world/2026_11_01_20_world_forever_hire_broker_gossip.sql new file mode 100644 index 0000000000..4830fa47f7 --- /dev/null +++ b/sql/custom/world/2026_11_01_20_world_forever_hire_broker_gossip.sql @@ -0,0 +1,51 @@ +-- Hire brokers (6110000-6110299): right-click opened nothing. The server sends a creature's NPC flags to each player through +-- Player::CanSeeGossipOn, which drops the gossip flag when the creature has no gossip menu in the database (creature_template_gossip +-- plus a gossip_menu row). The brokers had only their script menu, so every client got NPC flags 0: no talk cursor and no +-- CMSG_TALK_TO_GOSSIP (packet log, Goldshire, 2026-11-01 23:04). One shared menu, 6110000, with the broker's own text, npc_text 3959 +-- ("Greetings, $r."). The script still builds the options (npc_fb_hire_broker, menu id 6110000). Safe to run again. + +DELETE FROM `gossip_menu` WHERE `MenuID`=6110000; +INSERT INTO `gossip_menu` (`MenuID`,`TextID`,`VerifiedBuild`) VALUES +(6110000,3959,0); + +DELETE FROM `creature_template_gossip` WHERE `CreatureID` BETWEEN 6110000 AND 6110299; +INSERT INTO `creature_template_gossip` (`CreatureID`,`MenuID`,`VerifiedBuild`) VALUES +(6110000,6110000,0), +(6110001,6110000,0), +(6110002,6110000,0), +(6110003,6110000,0), +(6110004,6110000,0), +(6110005,6110000,0), +(6110006,6110000,0), +(6110007,6110000,0), +(6110008,6110000,0), +(6110009,6110000,0), +(6110010,6110000,0), +(6110011,6110000,0), +(6110012,6110000,0), +(6110013,6110000,0), +(6110014,6110000,0), +(6110015,6110000,0), +(6110016,6110000,0), +(6110017,6110000,0), +(6110018,6110000,0), +(6110019,6110000,0), +(6110020,6110000,0), +(6110021,6110000,0), +(6110022,6110000,0), +(6110023,6110000,0), +(6110024,6110000,0), +(6110025,6110000,0), +(6110026,6110000,0), +(6110027,6110000,0), +(6110028,6110000,0), +(6110029,6110000,0), +(6110100,6110000,0), +(6110101,6110000,0), +(6110102,6110000,0), +(6110103,6110000,0), +(6110104,6110000,0), +(6110105,6110000,0), +(6110200,6110000,0), +(6110201,6110000,0), +(6110202,6110000,0); diff --git a/sql/playerbot_v2/0037_hired_bots.sql b/sql/playerbot_v2/0037_hired_bots.sql new file mode 100644 index 0000000000..41438d4862 --- /dev/null +++ b/sql/playerbot_v2/0037_hired_bots.sql @@ -0,0 +1,27 @@ +-- Migration: 0037_hired_bots +-- Date: 2026-10-29 +-- Purpose: Hired bots (Playerbot.Hire.*, Fleet/HireMgr). In hired mode a player's companions are hired from a mercenary NPC for +-- gold instead of being made out of nothing; each hired bot keeps its grade, what was paid for it and how long its +-- upkeep is paid. A player chooses hired bots for their account when the server leaves it to them (Hire.Mode = 2). +-- +-- Columns (playerbot_v2_character): +-- hire_grade 0 = not hired (made before hired mode, or by a GM), 1 = Sellsword, 2 = Veteran, 3 = Legend +-- hire_price copper paid for the bot; its daily upkeep is Playerbot.Hire.UpkeepPct of this +-- hire_paid_until unix seconds; the upkeep is due again from then, the next time the bot is called +-- Table playerbot_v2_hire_pref: account_id, hired_only (1 = the account chose hired bots). +-- Reverts: yes (DROP COLUMN hire_grade, hire_price, hire_paid_until; DROP TABLE playerbot_v2_hire_pref). + +ALTER TABLE playerbot_v2_character + ADD COLUMN hire_grade TINYINT UNSIGNED NOT NULL DEFAULT 0, + ADD COLUMN hire_price BIGINT UNSIGNED NOT NULL DEFAULT 0, + ADD COLUMN hire_paid_until BIGINT UNSIGNED NOT NULL DEFAULT 0; + +CREATE TABLE IF NOT EXISTS playerbot_v2_hire_pref ( + account_id INT UNSIGNED NOT NULL, + hired_only TINYINT UNSIGNED NOT NULL DEFAULT 0, + PRIMARY KEY (account_id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +INSERT INTO playerbot_v2_schema_version (version, sha256) VALUES + (37, REPEAT('0', 64)) +ON DUPLICATE KEY UPDATE applied_at = CURRENT_TIMESTAMP; diff --git a/src/modules/PlayerbotV2/Addon/ForeverBots/ForeverBots.lua b/src/modules/PlayerbotV2/Addon/ForeverBots/ForeverBots.lua index 74fc2cdded..3961274d6d 100644 --- a/src/modules/PlayerbotV2/Addon/ForeverBots/ForeverBots.lua +++ b/src/modules/PlayerbotV2/Addon/ForeverBots/ForeverBots.lua @@ -1683,7 +1683,10 @@ function UI.BuildBots() SelectClass(1) local quick = Btn(botsPane, 0, 106, 117, 24, L["Quick party"], {}) quick:SetScript("OnClick", QuickParty) - Tip(quick, L["Quick party"], L["Fills your group with bots at your level: to five in the open world and 5-player dungeons, to the size of a bigger instance (10 in Upper Blackrock Spire) or raid."]) + Tip(quick, L["Quick party"], L["Fills your group with bots at your level: to five in the open world and 5-player dungeons, to the size of a bigger instance (10 in Upper Blackrock Spire) or raid. With hired bots on (/fb hire), your hired bots come; next to a mercenary broker the missing places are hired for gold."]) + -- hired bots only hides the class and role buttons (ForeverBots_Hire.lua) + Cmd.ns.addButtons = { roles = roleBtns, classes = classBtns, sel = selFS, pane = botsPane } + if Cmd.ns.Hire then Cmd.ns.Hire.Attach(botsPane) end gearBtn = Btn(botsPane, 121, 106, 117, 24, "", {}) gearBtn:SetScript("OnClick", function() local cur = ForeverBotsDB.gear or "match" @@ -3304,6 +3307,10 @@ SlashCmdList.FOREVERBOTS = function(msg) GroupOrder("flee") elseif verb == "quick" then QuickParty() + elseif verb == "hire" then + -- Hired bots (the server's Playerbot.Hire.Mode): no word shows whether you must hire and the prices here; on / off is your + -- own choice when the realm leaves it to each player. + ServerCommand((class == "on" or class == "off") and (".bot hire " .. class) or ".bot hire") elseif verb == "dungeon" or verb == "dungeons" then UI.DungeonQueue((class and class ~= "") and class or "list") elseif verb == "maintank" then @@ -3312,7 +3319,7 @@ SlashCmdList.FOREVERBOTS = function(msg) Toggle() else Print(L["unknown /fb word \"%s\" (add-on %s)"]:format(tostring(verb), UI.version or "?")) - Print("/fb opens the window; /fb add [tank|healer|dps]; /fb raidready; /fb call|dismiss|save|unsave|regear [name|all]; /fb delete ; /fb list; /fb fallback; /fb pullback; /fb rally; /fb formation circle|arrow|line|none; /fb spacing tight|close|spread; /fb distance <1-20>; /fb maintank [name]; /fb bot on|off; /fb tank |clear; /fb assign [role]|clear|list; /fb minimap on|off|reset; /fb scale <0.7-1.5>; /fb resume; /fb flee; /fb quick; /fb dungeon [name|any|leave|cancel]; /fb debug on|off; /fb perf [reset]; /fb part [name on|off]") + Print("/fb opens the window; /fb add [tank|healer|dps]; /fb raidready; /fb call|dismiss|save|unsave|regear [name|all]; /fb delete ; /fb list; /fb fallback; /fb pullback; /fb rally; /fb formation circle|arrow|line|none; /fb spacing tight|close|spread; /fb distance <1-20>; /fb maintank [name]; /fb bot on|off; /fb tank |clear; /fb assign [role]|clear|list; /fb minimap on|off|reset; /fb scale <0.7-1.5>; /fb resume; /fb flee; /fb quick; /fb hire [on|off]; /fb dungeon [name|any|leave|cancel]; /fb debug on|off; /fb perf [reset]; /fb part [name on|off]") end end UI.slash = SlashCmdList.FOREVERBOTS diff --git a/src/modules/PlayerbotV2/Addon/ForeverBots/ForeverBots.toc b/src/modules/PlayerbotV2/Addon/ForeverBots/ForeverBots.toc index 9eb4b1a8f1..777113b769 100644 --- a/src/modules/PlayerbotV2/Addon/ForeverBots/ForeverBots.toc +++ b/src/modules/PlayerbotV2/Addon/ForeverBots/ForeverBots.toc @@ -7,6 +7,7 @@ ## SavedVariables: ForeverBotsDB Locale_ruRU.lua +ForeverBots_Hire.lua ForeverBots.lua ForeverBots_Net.lua ForeverBots_Windows.lua diff --git a/src/modules/PlayerbotV2/Addon/ForeverBots/ForeverBots_Hire.lua b/src/modules/PlayerbotV2/Addon/ForeverBots/ForeverBots_Hire.lua new file mode 100644 index 0000000000..bd77560087 --- /dev/null +++ b/src/modules/PlayerbotV2/Addon/ForeverBots/ForeverBots_Hire.lua @@ -0,0 +1,62 @@ +--[[ +ForeverBots_Hire: hired bots only (the server's Playerbot.Hire.Mode, Karrz 2026-11-03). When the realm has hired NPC bots on, a +player cannot make bots of their own: the "Add a bot" class and role buttons on the Bots tab are hidden and a line says where +bots come from instead (the mercenary brokers). Quick party, Call saved and Raid ready stay: they bring the bots you hired. The +Group finder and the dungeon finder still bring bots for that group. The server says whether you must hire (HIRE_REQ / HIRE_RESP); +without the add-on message line nothing is hidden and the server refuses a .bot add itself. +]] + +local ADDON, ns = ... +-- Loaded before ForeverBots.lua (the Bots tab is built while that file loads), so the network and text tables are looked up late. +local function L(k) local t = ns.L; return t and t[k] or k end +local H = { must = false } +ns.Hire = H + +H.NOTE = "Hired bots only on this realm. Hire bots from a Sellsword Captain at an inn, a Veteran Recruiter in a capital or a Black Market Broker in Gadgetzan, Booty Bay or Ratchet. The Group finder and the dungeon finder still bring bots." + +-- HIRE_RESP: must hire 0/1, mode 0/1/2. +function H.Parse(fields) + fields = fields or {} + return fields[1] == "1", tonumber(fields[2] or "0") or 0 +end + +local function Apply() + local ui = ns.addButtons + if not ui then return end + local must = H.must + for _, cb in ipairs(ui.classes or {}) do cb:SetShown(not must) end + for _, rb in ipairs(ui.roles or {}) do + if must then rb:Hide() elseif rb.fbRole then rb:Show() end + end + if ui.sel then ui.sel:SetShown(not must) end + if not ui.note and ui.pane then + local note = ui.pane:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall") + note:SetPoint("TOPLEFT", ui.pane, "TOPLEFT", 2, -24) + note:SetWidth(234) + note:SetJustifyH("LEFT") + note:SetJustifyV("TOP") + note:SetText("|cffffd100" .. L(H.NOTE) .. "|r") + ui.note = note + end + if ui.note then ui.note:SetShown(must) end +end +H.Apply = Apply + +function H.Request() + local Net = ns.Net + if not (Net and Net.Ready()) then return end + Net.Request("HIRE_REQ", {}, function(fields) + if fields then + H.must, H.mode = H.Parse(fields) + Apply() + end + end) +end + +-- Called by the Bots tab when it is built: ask when the tab shows (the realm's setting can change with a .reload config). +function H.Attach(pane) + if not pane then return end + pane:HookScript("OnShow", function() H.Request() end) + Apply() + H.Request() +end diff --git a/src/modules/PlayerbotV2/Addon/ForeverBots/Locale_ruRU.lua b/src/modules/PlayerbotV2/Addon/ForeverBots/Locale_ruRU.lua index 906e32689f..215e4abdad 100644 --- a/src/modules/PlayerbotV2/Addon/ForeverBots/Locale_ruRU.lua +++ b/src/modules/PlayerbotV2/Addon/ForeverBots/Locale_ruRU.lua @@ -98,7 +98,7 @@ ForeverBotsLocale = { ["A new bot joins you at your level, wearing the gear chosen below."] = "Новый бот вашего уровня присоединяется к вам в выбранной ниже экипировке.", ["Pick the class, then a role below."] = "Выберите класс, затем роль ниже.", ["Quick party"] = "Быстрая группа", - ["Fills your group with bots at your level: to five in the open world and 5-player dungeons, to the size of a bigger instance (10 in Upper Blackrock Spire) or raid."] = "Заполняет группу ботами вашего уровня: до пяти в открытом мире и подземельях на 5 игроков, до размера большего подземелья (10 в Верхней части вершины Черной горы) или рейда.", + ["Fills your group with bots at your level: to five in the open world and 5-player dungeons, to the size of a bigger instance (10 in Upper Blackrock Spire) or raid. With hired bots on (/fb hire), your hired bots come; next to a mercenary broker the missing places are hired for gold."] = "Заполняет группу ботами вашего уровня: до пяти в открытом мире и подземельях на 5 игроков, до размера большего подземелья (10 в Верхней части вершины Черной горы) или рейда. Если включены наемники (/fb hire), приходят ваши нанятые боты; рядом с вербовщиком наемников недостающие места нанимаются за золото.", -- check ["Match my gear"] = "Как у меня", ["Best for their level"] = "Лучшее для уровня", ["Best in slot"] = "БиС", @@ -539,6 +539,8 @@ ForeverBotsLocale = { ["Delete"] = "Удалить", ["Deletes the bot's character for good (asks first)."] = "Навсегда удаляет персонажа бота (сначала спросит).", ["Details"] = "Сведения", + -- Hired bots only (ForeverBots_Hire.lua), 0.6.10 -- check + ["Hired bots only on this realm. Hire bots from a Sellsword Captain at an inn, a Veteran Recruiter in a capital or a Black Market Broker in Gadgetzan, Booty Bay or Ratchet. The Group finder and the dungeon finder still bring bots."] = "На этом сервере только наемные боты. Нанимайте ботов у капитана наемников в таверне, у вербовщика ветеранов в столице или у торговца черного рынка в Прибамбасске, Пиратской Бухте или Кабестане. Поиск группы и поиск подземелий по-прежнему приводят ботов.", -- Positions tab (ForeverBots_Place.lua), 0.6.12 -- check ["Positions"] = "Позиции", ["Arc"] = "Дуга", diff --git a/src/modules/PlayerbotV2/Addon/ForeverBots/README.md b/src/modules/PlayerbotV2/Addon/ForeverBots/README.md index cab3f7d2b1..72c12d262e 100644 --- a/src/modules/PlayerbotV2/Addon/ForeverBots/README.md +++ b/src/modules/PlayerbotV2/Addon/ForeverBots/README.md @@ -32,6 +32,8 @@ regroup, formation and spacing, tanks and markers), Assign a bot to an icon, You server answers in a system line. Secure buttons, so they work in combat. - One button per class and role: adds that bot (`.bot add `). It joins you at your level, geared, in your group. +- Hired bots only (0.6.10, the server's Playerbot.Hire.Mode): when you must hire, the class and role buttons are hidden and a + line says where to hire bots instead (HIRE_REQ / HIRE_RESP, ForeverBots_Hire.lua). Quick party, Call saved and Raid ready stay. - Orders to the group: Follow, Stay, Attack (your target), Resume; Pull (your tank bots open on your target, the rest join once it is engaged), Flee (break off and run to you), Come (teleport to you), Stop (stop attacking and return to normal), Release (after a wipe: every dead bot releases its spirit, runs back to its corpse as a ghost, diff --git a/src/modules/PlayerbotV2/BOT_COMMANDS.md b/src/modules/PlayerbotV2/BOT_COMMANDS.md index 0f18e0c83a..5974e0856b 100644 --- a/src/modules/PlayerbotV2/BOT_COMMANDS.md +++ b/src/modules/PlayerbotV2/BOT_COMMANDS.md @@ -69,6 +69,7 @@ The `.bot` commands for your own bots work for every account, no GM needed; each | `.bot dismiss ` | Removes it from your group and logs it out. Gear is kept. | | `.bot delete ` | Deletes the character for good (the addon asks first). Only bots made for you: one of your own characters summoned as a bot (`.playerbot summon`) is refused with a pointer to `.bot dismiss`. | | `.bot list` | Your companions, online or not (`saved` marks roster ones). | +| `.bot hire [on\|off]` | Hired bots (`Playerbot.Hire.Mode`). No word: whether you must hire and what one bot costs where you stand. `on` / `off`: your own choice when the realm leaves it to each player. With hired bots on, `.bot add`, Quick party and the Group finder bring a hired companion of yours that is not out; next to a broker they hire a Sellsword. Brokers sell by gossip: Sellsword Captains at inns and capitals, Veteran Recruiters in capitals (level cap), Black Market Brokers in Gadgetzan, Booty Bay and Ratchet (Legends, level cap). Wages: `Playerbot.Hire.UpkeepPct` of the price, on each day the bot is called. `.bot delete` ends a contract (no refund). | | `.bot regear ` | Re-rolls the equipment of online companions so they do not all wear the same pieces. Better pieces they wear stay; replaced ones go to the bags. | | `.bot world` | Status of the world-bot spawner (Playerbot.World.*), console too. | | `.bot population [off\|low\|medium\|high\|file]` | How many world bots the realm has, GM only, until the next restart (the launcher's Bots setting, `Bots.Size`, decides at every start; the add-on has no World bots tab since 0.6.13). Applies right away (a step down logs the world bots out first). It wins over `Bots.Size` and `Playerbot.World.Enable` until then; `file` hands back to the config files. No word: what it is now. Console too. | diff --git a/src/modules/PlayerbotV2/CMakeLists.txt b/src/modules/PlayerbotV2/CMakeLists.txt index ca64968a25..e1ed982eb7 100644 --- a/src/modules/PlayerbotV2/CMakeLists.txt +++ b/src/modules/PlayerbotV2/CMakeLists.txt @@ -171,6 +171,22 @@ add_library(playerbot-v2-api STATIC) CollectAndAddSourceFiles(playerbot-v2-api ${CMAKE_CURRENT_SOURCE_DIR}/Api) playerbot_v2_configure_sublib(playerbot-v2-api) +# --------------------------------------------------------------------------- +# Sub-library: Hire — hired bots: the Sellsword Captains, Veteran Recruiters and black-market brokers, their prices, upkeep, +# grade gear and health (Playerbot.Hire.* in playerbot.conf). The rest of the module asks it only through HireHooks.h, so it can +# be left out (-DPLAYERBOT_V2_HIRE=0): companions are then always free and the broker NPCs have no script. See Hire/README.md. +# --------------------------------------------------------------------------- +option(PLAYERBOT_V2_HIRE "Build hired bots (the hire brokers, Playerbot.Hire.*) into the bot module" 1) +if(PLAYERBOT_V2_HIRE AND NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/Hire/HireModule.cpp) + message(STATUS "Playerbot V2: Hire/ not found, hired bots are left out") + set(PLAYERBOT_V2_HIRE 0) +endif() +if(PLAYERBOT_V2_HIRE) + add_library(playerbot-v2-hire STATIC) + CollectAndAddSourceFiles(playerbot-v2-hire ${CMAKE_CURRENT_SOURCE_DIR}/Hire) + playerbot_v2_configure_sublib(playerbot-v2-hire) +endif() + # --------------------------------------------------------------------------- # Sub-library: Core — module entry point, script registration, the commands # (.playerbot, .bot, .w) and the Services aggregator. @@ -181,6 +197,7 @@ add_library(playerbot-v2-core STATIC ${CMAKE_CURRENT_SOURCE_DIR}/LfgBotFill.cpp ${CMAKE_CURRENT_SOURCE_DIR}/DungeonFinder.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Services.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/HireHooks.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Commands/cs_playerbot_v2.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Commands/cs_selftest.cpp ) @@ -191,9 +208,14 @@ target_sources(playerbot-v2-core ${CMAKE_CURRENT_SOURCE_DIR}/PlayerbotV2.h ${CMAKE_CURRENT_SOURCE_DIR}/LfgBotFill.h ${CMAKE_CURRENT_SOURCE_DIR}/Services.h + ${CMAKE_CURRENT_SOURCE_DIR}/HireHooks.h + ${CMAKE_CURRENT_SOURCE_DIR}/HireTypes.h ${CMAKE_CURRENT_SOURCE_DIR}/PCH.h ) playerbot_v2_configure_sublib(playerbot-v2-core) +if(PLAYERBOT_V2_HIRE) + target_compile_definitions(playerbot-v2-core PRIVATE PLAYERBOT_V2_HIRE=1) +endif() # --------------------------------------------------------------------------- # Umbrella INTERFACE library. The single name dependents reference; CMake @@ -226,6 +248,9 @@ set(PLAYERBOT_V2_SUBLIBS playerbot-v2-api playerbot-v2-core ) +if(PLAYERBOT_V2_HIRE) + list(APPEND PLAYERBOT_V2_SUBLIBS playerbot-v2-hire) +endif() if(MSVC OR APPLE) # Apple's ld64 also searches every archive until all symbols resolve, and CMake has no RESCAN link group for it target_link_libraries(playerbot-v2 INTERFACE ${PLAYERBOT_V2_SUBLIBS} game) @@ -272,4 +297,4 @@ if(COPY_CONF) endif() endif() -message(STATUS "Playerbot V2 module enabled (multi-library: 13 sub-libs)") +message(STATUS "Playerbot V2 module enabled (multi-library: 13 sub-libs; hired bots: ${PLAYERBOT_V2_HIRE})") diff --git a/src/modules/PlayerbotV2/Commands/cs_playerbot_v2.cpp b/src/modules/PlayerbotV2/Commands/cs_playerbot_v2.cpp index 136aedd420..98ae88aeaf 100644 --- a/src/modules/PlayerbotV2/Commands/cs_playerbot_v2.cpp +++ b/src/modules/PlayerbotV2/Commands/cs_playerbot_v2.cpp @@ -50,6 +50,9 @@ #include "DB2Stores.h" // .playerbot questrun: sMapStore #include "PlayerbotV2.h" #include "LfgBotFill.h" +#include "Fleet/AutoRaid.h" // a raid made for one more member may go back to a party +#include "HireHooks.h" // hired bots (Hire/ module): asked only through Fleet::Hiring() +#include "Bot/ClassTables.h" #include "StringFormat.h" #include "PlayerbotMovement.h" // BotMovement::SafeTeleport for GM summonall #include "RBAC.h" @@ -70,7 +73,6 @@ #include "Fleet/BotComposition.h" #include "Fleet/BotIdentityRegistry.h" #include "Fleet/BotPopulationManager.h" -#include "Fleet/AutoRaid.h" // a raid made for one more member may go back to a party #include "Fleet/BotSize.h" #include "Fleet/InstanceGroupCap.h" #include "Fleet/BotSetupPipeline.h" @@ -806,6 +808,7 @@ public: { "unsave", HandleBotUnsave, rbac::RBAC_PERM_JOIN_NORMAL_BG, Console::No }, { "delete", HandleBotDelete, rbac::RBAC_PERM_JOIN_NORMAL_BG, Console::No }, { "list", HandleBotList, rbac::RBAC_PERM_JOIN_NORMAL_BG, Console::No }, + { "hire", HandleBotHire, rbac::RBAC_PERM_JOIN_NORMAL_BG, Console::No }, { "language", HandleBotLanguage, rbac::RBAC_PERM_JOIN_NORMAL_BG, Console::No }, { "world", HandleBotWorld, rbac::RBAC_PERM_COMMAND_GM, Console::Yes }, // GM only: how many world bots the realm has (Off / Low / Medium / High), set in game until the next restart (the launcher's Bots setting decides at every start). @@ -1021,6 +1024,12 @@ public: return true; } + // .bot hire [on|off]: hired bots (Playerbot.Hire.*, the Hire/ module). Without the hire module built in it says there are none. + static bool HandleBotHire(ChatHandler* handler, Optional word) + { + return Playerbot::V2::Fleet::Hiring().HandleCommand(handler, std::move(word)); + } + // .bot lfg [tank|healer|dps]: fill the group's missing tank / healer / damage places now with level-matched companions // (the Group Finder does the same by itself when nobody joins a posted listing in time). The word is your own role. static bool HandleBotLfg(ChatHandler* handler, Optional ownRoleArg) @@ -1117,6 +1126,7 @@ public: Playerbot::Role role = Playerbot::Role::Unknown; uint8 race = 0; uint8 gender = uint8(urand(GENDER_MALE, GENDER_FEMALE)); + bool anyClass = false; for (Optional const* arg : { &arg2, &arg3, &arg4 }) { if (!*arg) @@ -1125,8 +1135,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, there are no hired bots, so the word is accepted and ignored. - if (word == "anyclass") { 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; } @@ -1135,16 +1145,93 @@ 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); } - // 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) + // 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) { + Playerbot::V2::Fleet::HireHooks const& hire = Playerbot::V2::Fleet::Hiring(); + 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(id); + if ((group && group->IsMember(guid)) || hire.RecentlyCalled(id, now) || hire.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`, the Group Finder bot fill and the hire brokers. `outMsg` is what the owner + // is told. In hired mode (Playerbot.Hire.*, Hire/HirePolicy.h, asked through HireHooks.h) nothing is made out of nothing: an idle companion of the account + // comes instead, or next to a broker a Sellsword is hired; `hireGrade` hires that grade from the broker beside `me`. + // `finder`: the Group Finder / dungeon finder fill (`.bot lfg`, `.bot dungeon`, a posted listing). It still works in hired mode + // (Karrz 2026-11-03: "you can still look for group"), but the bot is only lent: free, it stays with the group and is deleted + // when it leaves it, and it cannot be called on its own (HireHooks::SetLoaned). + static bool AddCompanionFor(Player* me, WorldSession* sess, uint8 cls, Playerbot::Role role, uint8 race, uint8 gender, + 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; + Playerbot::V2::Fleet::HireHooks& hire = Playerbot::V2::Fleet::Hiring(); + 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.BrokerNear(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; + // A broker near, the price at this level, the account's limits and the money (the hire module's rules). + if (hireGrade != Hire::Grade::None && !hire.CheckHire(me, hireGrade, price, outMsg)) + 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()) @@ -1168,6 +1255,16 @@ public: Playerbot::BotId const id = created.guid.GetCounter(); Playerbot::Services::Owners().SetOwner(id, sess->GetAccountId(), me->GetGUID().GetCounter()); + if (hireGrade != Hire::Grade::None) + { + // Paid and graded before the setup, so its first gear is its grade's. + hire.OnHired(me, id, hireGrade, price, pick.name, className); + } + else if (loan) + { + hire.SetLoaned(id, getMSTime()); + TC_LOG_INFO("playerbot.v2", "[hire] {} gets {} ({}) from the group finder, lent while it stays in the group", me->GetName(), pick.name, className); + } Playerbot::Services::Population().QueueCompanionSetup(id, me->GetGUID().GetCounter(), uint8(role)); auto const login = Playerbot::Services::SessionMgr().LoginBot(created.guid); if (!login.ok) @@ -1175,7 +1272,7 @@ public: outMsg = Trinity::StringFormat("Created {} but the login was refused ({}). Try `.bot call {}`.", pick.name, login.reason, pick.name); return false; } - outMsg = pick.name + " is on the way."; + outMsg = hireGrade == Hire::Grade::None ? pick.name + " is on the way." : hire.SignOnText(pick.name, hireGrade, price); return true; } @@ -1305,9 +1402,17 @@ public: Group const* myGroup = me->GetGroup(); uint32 members = myGroup ? myGroup->GetMembersCount() : 1; uint32 out = cap ? Playerbot::V2::Fleet::CompanionsOut(me) : 0; + Playerbot::V2::Fleet::HireHooks& hire = Playerbot::V2::Fleet::Hiring(); + bool const mustHire = hire.MustHire(me); for (Playerbot::BotId id : ids) { ObjectGuid const guid = ObjectGuid::Create(id); + // Hired bots only: a Group Finder bot was lent for that group and cannot be called back on its own. + if (mustHire && hire.IsLoaned(id) && !(myGroup && myGroup->IsMember(guid))) + { + handler->PSendSysMessage("%s came with the group finder and only plays in that group (hired bots only on this realm).", CompanionName(id).c_str()); + continue; + } if (cap && !ObjectAccessor::FindConnectedPlayer(guid)) { if (!inInstance && out >= cap) { ++refused; continue; } @@ -1318,6 +1423,12 @@ public: if (members >= cap) { ++refused; continue; } ++members; } + // A hired bot wants the day's wages before it comes (Playerbot.Hire.UpkeepPct; once a day, only on a day it is called). + if (std::string why; !hire.TakeUpkeep(me, id, CompanionName(id), why)) + { + handler->SendSysMessage(why.c_str()); + continue; + } Playerbot::Services::Population().QueueCompanionSetup(id, me->GetGUID().GetCounter(), uint8(Playerbot::Role::Unknown)); if (!ObjectAccessor::FindConnectedPlayer(guid) && !Playerbot::Services::SessionMgr().LoginBot(guid).ok) continue; @@ -1731,6 +1842,7 @@ public: group->RemoveMember(guid); Playerbot::Services::SessionMgr().LogoutBot(guid); Playerbot::Services::Population().QueueCompanionDelete(id); + Playerbot::V2::Fleet::Hiring().Forget(id); // a hired bot's contract ends with it, nothing is paid back handler->PSendSysMessage("%s is leaving and will be deleted.", CompanionName(id).c_str()); } return true; @@ -9549,7 +9661,25 @@ public: bool Playerbot::V2::AddCompanionForOwner(Player* owner, uint8 cls, Playerbot::Role role, std::string& msg) { return playerbot_v2_commandscript::AddCompanionFor(owner, owner->GetSession(), cls, role, 0, - uint8(urand(GENDER_MALE, GENDER_FEMALE)), "bot", msg); + uint8(urand(GENDER_MALE, GENDER_FEMALE)), "bot", msg, + Playerbot::V2::Fleet::Hire::Grade::None, /*finder*/ true); +} + +bool Playerbot::V2::HireCompanionForOwner(Player* owner, uint8 cls, Playerbot::Role role, Playerbot::V2::Fleet::Hire::Grade grade, + std::string const& className, std::string& msg) +{ + // The same room checks as `.bot add`: a full raid, the open-world companion cap, a full instance. + if (Group const* group = owner->GetGroup(); group && group->isRaidGroup() && group->IsFull()) + { msg = "Your raid is full."; return false; } + if (std::string full; Playerbot::V2::Fleet::CompanionSpawnFull(owner, 0, full)) + { msg = "No room: " + full + "."; return false; } + return playerbot_v2_commandscript::AddCompanionFor(owner, owner->GetSession(), cls, role, 0, + uint8(urand(GENDER_MALE, GENDER_FEMALE)), className, msg, grade); +} + +bool Playerbot::V2::CanHaveCompanionClass(Player const* owner, uint8 cls) +{ + return owner && playerbot_v2_commandscript::PickCompanionRace(owner, cls) != 0; } void AddSC_playerbot_v2_commandscript() diff --git a/src/modules/PlayerbotV2/Fleet/BotPopulationManager.cpp b/src/modules/PlayerbotV2/Fleet/BotPopulationManager.cpp index 8b35db68d2..e0dfb0a4e8 100644 --- a/src/modules/PlayerbotV2/Fleet/BotPopulationManager.cpp +++ b/src/modules/PlayerbotV2/Fleet/BotPopulationManager.cpp @@ -6,6 +6,8 @@ #include "../Util/SlowCall.h" #include "BotPopulationManager.h" #include "AutoRaid.h" // a raid made here for one more companion may go back to a party +#include "../HireHooks.h" +#include "CompanionDelete.h" // a finder loan bot is deleted like `.bot delete` #include "ClassicSpec.h" #include "SoakAnchors.h" #include "CompanionRole.h" @@ -1191,6 +1193,13 @@ bool BotPopulationManager::SetOwnerGearMode(uint32 account_id, uint8 requested_m RequestGearRefresh(bot); reply = std::string("gear mode ") + Gear::Owned::ModeName(mode) + (Gear::Owned::IsCapMode(mode) ? " (this applies at level " + std::to_string(MaxPlayerLevel()) + "; below that: match)" : ""); + // With hired bots on (Playerbot.Hire.Mode) a player who must hire gets each bot's grade gear, whatever mode is chosen + // (HireHooks::GearModeOverride): the choice is kept for when the rule is off, but say so instead of a plain "set" (Karrz 11-15, + // Naxx: T3 chosen and Regear pressed, the bots stayed in match gear and nothing said why). + bool const must_hire = requester ? Hiring().MustHire(requester) : Hiring().MustHireAccount(account_id); + if (must_hire && mode != GearMode::Match) + reply += ". Hired bots are on, so your bots wear the gear of their grade: Sellsword and your own bots match, Veteran best," + " Legend bis. For this mode set Playerbot.Hire.Mode = 0, or Playerbot.Hire.GmBypass = 1 for a GM, in zz-9-local.conf"; return true; } @@ -1266,6 +1275,7 @@ void BotPopulationManager::RunGearBackfill(uint32 now_ms) gear_scan_pos_ = 0; gear_regear_count_ = 0; Services::Registry().for_each([&](BotId id, BotRegistryEntry const&) { gear_scan_.push_back(id); }); + ReleaseOfflineLoans(now_ms); } const uint32 t0 = getMSTime(); while (gear_scan_pos_ < gear_scan_.size() && getMSTimeDiff(t0, getMSTime()) < kGearBudgetMs) @@ -1301,10 +1311,53 @@ void BotPopulationManager::RunGearBackfill(uint32 now_ms) } } +// Hired bots only (Playerbot.Hire.Mode): a Group Finder / dungeon finder bot is lent to its group (HireHooks::SetLoaned). Once it is +// out of its owner's group (left, dismissed, the owner went offline) it is deleted like `.bot delete`, so a free bot never becomes +// one to keep. True when it was taken back. +bool BotPopulationManager::ReleaseLoan(BotId id, Player* p, uint32 now_ms) +{ + HireHooks& hire = Hiring(); + if (!hire.IsLoaned(id) || !hire.LoanSettled(id, now_ms) || pending_companions_.contains(id) || pending_deletes_.contains(id)) + return false; + ObjectGuid const guid = ObjectGuid::Create(id); + if (p) + { + uint64 const owner_guid = Services::Owners().OwnerCharacter(id); + Player const* owner = owner_guid ? ObjectAccessor::FindConnectedPlayer(ObjectGuid::Create(owner_guid)) : nullptr; + Group* group = p->GetGroup(); + if (owner && group && group->IsMember(owner->GetGUID())) + return false; // still playing with the group it was lent to + } + if (!Fleet::MayDeleteCompanion(Services::Accounts().is_pool_account(sCharacterCache->GetCharacterAccountIdByGuid(guid)))) + { + hire.Forget(id); // never a player's own character; just not a loan any more + return false; + } + TC_LOG_INFO("playerbot.v2", "[hire] finder loan bot {} left its group: it goes", guid.ToString()); + if (p) + { + if (Group* group = p->GetGroup()) + group->RemoveMember(guid); + Services::SessionMgr().LogoutBot(guid); + } + QueueCompanionDelete(id); + hire.Forget(id); + return true; +} + +void BotPopulationManager::ReleaseOfflineLoans(uint32 now_ms) +{ + for (BotId id : Hiring().LoanedBots()) + if (!ObjectAccessor::FindConnectedPlayer(ObjectGuid::Create(id))) + ReleaseLoan(id, nullptr, now_ms); +} + void BotPopulationManager::CompanionUpkeep(BotId id, Player* p) { if (Services::Owners().OwnerCharacter(id) == 0 || IsPlayersOwnCharacter(p)) return; + if (ReleaseLoan(id, p, getMSTime())) + return; ::Playerbot::API api(p); api.learn_class_quest_spells_free(); api.learn_trainer_spells_free(); @@ -1333,6 +1386,8 @@ void BotPopulationManager::CompanionUpkeep(BotId id, Player* p) TC_LOG_INFO("playerbot.v2", "[Companion] {} one-time varied gear re-roll: {} slot(s) changed", p->GetName(), changed); } } + // A hired bot's grade health follows its level and gear (and a changed Playerbot.Hire..HealthPct after `.reload config`). + Hiring().ApplyHealth(p); } // A hunter's pet anywhere: out, dismissed or unsummoned for a moment, in an active or stable slot, or unslotted. @@ -1942,6 +1997,8 @@ void BotPopulationManager::FinishCompanionSetup(Player* bot, Player* owner, uint } } RegearNow(bot); + // A hired bot's grade health (Playerbot.Hire..HealthPct), on the health its new level and gear give it. + Hiring().ApplyHealth(bot); // GiveLevel fills health and mana for the new level, but the gear put on after it raises the pools again: three mages made for // the owner in UBRS (2026-10-29 09:28:31) stood at 18-19 % mana with their new L60 gear and were in the fight 12 s later, wanding. // A companion just levelled here joins rested. @@ -2321,6 +2378,10 @@ static Gear::Owned::GearMode CompanionGearMode(Player const* bot) uint32 const account = Services::Owners().GetOwner(bot->GetGUID().GetCounter()).account_id; if (!account) return Gear::Owned::GearMode::Match; + // A hired bot wears its grade's gear (Veteran best, Legend bis), a Sellsword or any companion of a player who must hire the + // normal companion gear, whatever the owner chose (Hire/HirePolicy.h). + if (int const hired = Hiring().GearModeOverride(bot->GetGUID().GetCounter(), account); hired >= 0) + return Gear::Owned::GearMode(hired); return Gear::Owned::EffectiveMode(Gear::Owned::GearMode(Services::Owners().OwnerGearMode(account)), Gear::OwnedAllowedModes(), bot->GetLevel() >= MaxPlayerLevel()); } diff --git a/src/modules/PlayerbotV2/Fleet/BotPopulationManager.h b/src/modules/PlayerbotV2/Fleet/BotPopulationManager.h index 1885d0a83b..db82eb4949 100644 --- a/src/modules/PlayerbotV2/Fleet/BotPopulationManager.h +++ b/src/modules/PlayerbotV2/Fleet/BotPopulationManager.h @@ -204,7 +204,11 @@ public: // each RunGearBackfill pass teaches it its new ranks, class-quest abilities and talents, and mends its gear. Runs // for every companion, whatever its gear. Cheap; no-op for any other bot. void CompanionUpkeep(BotId id, Player* p); - // A hunter companion's starter pet, granted once per bot (OwnerRegistry::StarterPetGranted). + // Hired bots only: a Group Finder loan bot out of its owner's group is deleted (HireHooks::SetLoaned). + bool ReleaseLoan(BotId id, Player* p, uint32 now_ms); + void ReleaseOfflineLoans(uint32 now_ms); + // A hunter companion's starter pet, granted once per bot (OwnerRegistry::StarterPetGranted). When it cannot be given yet (the bot is + // still on its way to the owner, in combat, mounted...) the bot waits in pending_pet_grants_ and is tried again every second. void GrantCompanionStarterPet(BotId id, Player* p); // Hunter companions whose pet grant answered "not now": bot -> first refused at (getMSTime). DrainPetGrants tries them again. std::unordered_map pending_pet_grants_; diff --git a/src/modules/PlayerbotV2/Hire/HireBroker.cpp b/src/modules/PlayerbotV2/Hire/HireBroker.cpp new file mode 100644 index 0000000000..9f822537bb --- /dev/null +++ b/src/modules/PlayerbotV2/Hire/HireBroker.cpp @@ -0,0 +1,266 @@ +#include "HireBroker.h" +#include "HireMgr.h" +#include "../Fleet/OwnerRegistry.h" +#include "../Services.h" +#include "../Bot/ClassTables.h" +#include "CharacterCache.h" +#include "Chat.h" +#include "Creature.h" +#include "GossipDef.h" +#include "Log.h" +#include "ObjectGuid.h" +#include "Player.h" +#include "ScriptMgr.h" +#include "ScriptedCreature.h" +#include "ScriptedGossip.h" +#include "SharedDefines.h" +#include "StringFormat.h" +#include "WorldSession.h" + +using namespace Playerbot::V2; +using namespace Playerbot::V2::Fleet; + +namespace { + +// Gossip actions: a grade's role menu, a role's class menu, a class hired. 1000 + grade * 100 + role * 20 + class stays under 2000. +constexpr uint32 kActionGrade = 1; // + grade (1..3): the role menu +constexpr uint32 kActionContracts = 5; // the player's hired bots, in chat +constexpr uint32 kActionOptIn = 6; // `.bot hire on|off` from the gossip (Hire.Mode = 2) +constexpr uint32 kActionRole = 10; // + grade * 10 + role (1..3): the class menu +constexpr uint32 kActionHire = 1000; // + grade * 100 + role * 20 + class + +// The gossip text: npc_text 3959, "Greetings, $r." (BroadcastText 6498). Not DEFAULT_GOSSIP_MESSAGE: its npc_text 16777215 points at +// BroadcastText 50429, a retail text the Classic client does not have, and the client then opens no gossip window at all (Goldshire, +// 2026-11-01: right-click on Brannock Ironhale opened nothing although his NPC flags and script were right). +constexpr uint32 kBrokerText = 3959; + +// The menu the client is shown: gossip menu 6110000 (the first broker entry), options 61100000 + their place in the menu. Every menu the +// Classic client opens carries a gossip menu id and positive option ids; a script menu left at menu 0 gets ids 0, -1, -2 ... from +// GossipMenu::AddMenuItem, the one difference left after right-click on Brannock Ironhale still opened nothing with a text the +// client has (Goldshire, 2026-11-01, dev build with npc_text 3959). The script builds the options; the menu itself must also be in the +// database (gossip_menu 6110000 -> npc_text 3959, creature_template_gossip for every broker), because the server hides the gossip NPC +// flag from a player when Player::CanSeeGossipOn finds no menu, and the client then shows no talk cursor and never sends the hello. +// The hello is logged (playerbot.v2, INFO) so Server.log shows whether a click reached the broker at all. +constexpr uint32 kBrokerMenu = 6110000; +constexpr int32 kBrokerOptionId = 61100000; + +void StartMenu(Player* player) +{ + ClearGossipMenuFor(player); + InitGossipMenuFor(player, kBrokerMenu); +} + +void AddOption(Player* player, std::string text, uint32 action, std::string confirm = {}, uint64 money = 0) +{ + GossipMenu& menu = player->PlayerTalkClass->GetGossipMenu(); + int32 const id = kBrokerOptionId + int32(menu.GetMenuItemCount()); + menu.AddMenuItem(id, -1, GossipOptionNpc::None, std::move(text), 0, GossipOptionFlags::None, {}, 0, 0, false, money, std::move(confirm), {}, {}, + GOSSIP_SENDER_MAIN, action); +} + +struct ClassInfo { uint8 cls; char const* name; bool tank, healer, dps; }; +constexpr ClassInfo kClasses[] = { + { CLASS_WARRIOR, "Warrior", true, false, true }, + { CLASS_PALADIN, "Paladin", true, true, true }, + { CLASS_HUNTER, "Hunter", false, false, true }, + { CLASS_ROGUE, "Rogue", false, false, true }, + { CLASS_PRIEST, "Priest", false, true, true }, + { CLASS_SHAMAN, "Shaman", false, true, true }, + { CLASS_MAGE, "Mage", false, false, true }, + { CLASS_WARLOCK, "Warlock", false, false, true }, + { CLASS_DRUID, "Druid", true, true, true }, +}; + +ClassInfo const* FindClass(uint8 cls) +{ + for (ClassInfo const& c : kClasses) + if (c.cls == cls) + return &c; + return nullptr; +} + +bool Plays(ClassInfo const& c, Playerbot::Role role) +{ + return role == Playerbot::Role::Tank ? c.tank : role == Playerbot::Role::Healer ? c.healer : c.dps; +} + +// Role index 1..3 in the gossip actions. +Playerbot::Role RoleOfIndex(uint32 i) +{ + return i == 1 ? Playerbot::Role::Tank : i == 2 ? Playerbot::Role::Healer : Playerbot::Role::Dps; +} + +char const* RoleWord(Playerbot::Role role) +{ + return role == Playerbot::Role::Tank ? "tank" : role == Playerbot::Role::Healer ? "healer" : "damage dealer"; +} + +std::string GradeOffer(Hire::Grade grade, uint64 price) +{ + switch (grade) + { + case Hire::Grade::Sellsword: return Trinity::StringFormat("I need a sellsword. ({} each)", Hire::MoneyText(price)); + case Hire::Grade::Veteran: return Trinity::StringFormat("I need a veteran raider. ({} each)", Hire::MoneyText(price)); + case Hire::Grade::Legend: return Trinity::StringFormat("I hear you know someone... legendary. ({} each)", Hire::MoneyText(price)); + default: return {}; + } +} + +// What the broker says when a hire goes through. +char const* HiredLine(Hire::Broker broker) +{ + switch (broker) + { + case Hire::Broker::BlackMarket: return "Pleasure doing business. No refunds, no questions, and you never saw me."; + case Hire::Broker::Capital: return "A fine choice. They have stood in the line before, they will not break."; + default: return "Done. Your new sword arm will meet you outside."; + } +} + +void Tell(Player* player, std::string const& text) +{ + if (player && player->GetSession()) + ChatHandler(player->GetSession()).SendSysMessage(text.c_str()); +} + +void ListContracts(Player* player) +{ + uint32 const account = player->GetSession()->GetAccountId(); + Hire::Prices const prices = HireMgr::ConfigPrices(); + uint32 n = 0; + for (Playerbot::BotId id : Playerbot::Services::Owners().BotsOwnedBy(account)) + { + CharacterCacheEntry const* entry = sCharacterCache->GetCharacterCacheByGuid(ObjectGuid::Create(id)); + if (!entry) + continue; + HireRecord const rec = HireMgr::Instance().RecordOf(id); + uint64 const upkeep = Hire::UpkeepFor(prices, rec.price); + ClassInfo const* c = FindClass(entry->Class); + Tell(player, Trinity::StringFormat("{}: level {} {} {}{}", entry->Name, uint32(entry->Level), c ? c->name : "", + Hire::GradeName(rec.grade), + upkeep ? " (" + Hire::MoneyText(upkeep) + " a day you call them)" : std::string())); + ++n; + } + if (!n) + Tell(player, "Nobody works for you yet."); +} + +} // namespace + +struct npc_fb_hire_broker : public ScriptedAI +{ + explicit npc_fb_hire_broker(Creature* creature) : ScriptedAI(creature) { } + + Hire::Broker BrokerKind() const { return Hire::BrokerOfEntry(me->GetEntry()); } + + void MainMenu(Player* player) + { + StartMenu(player); + Hire::Broker const broker = BrokerKind(); + for (Hire::Grade g : { Hire::Grade::Sellsword, Hire::Grade::Veteran, Hire::Grade::Legend }) + { + if (!Hire::BrokerSells(HireMgr::ConfigRules(), broker, g)) + continue; + if (uint64 const price = HireMgr::PriceHere(player, g)) + AddOption(player, GradeOffer(g, price), kActionGrade + uint32(g) - 1); + else + AddOption(player, Trinity::StringFormat("({} only sign on with level {} heroes.)", g == Hire::Grade::Legend ? "Legends" : "Veterans", + uint32(Playerbot::MaxPlayerLevel())), 0); + } + AddOption(player, "Who works for me?", kActionContracts); + if (HireMgr::ConfigMode() == Hire::Mode::PlayerChoice) + AddOption(player, + HireMgr::Instance().OptedIn(player->GetSession()->GetAccountId()) + ? "I'd rather gather my own company again. (Bots are free again.)" + : "From now on I only fight beside those I pay. (Hired bots only.)", + kActionOptIn); + TC_LOG_INFO("playerbot.v2", "[hire] {} talks to broker {} ({}): menu {} with {} options", player->GetName(), me->GetName(), me->GetEntry(), + kBrokerMenu, player->PlayerTalkClass->GetGossipMenu().GetMenuItemCount()); + SendGossipMenuFor(player, kBrokerText, me->GetGUID()); + } + + bool OnGossipHello(Player* player) override + { + MainMenu(player); + return true; + } + + bool OnGossipSelect(Player* player, uint32 /*menuId*/, uint32 gossipListId) override + { + uint32 const action = GetGossipActionFor(player, gossipListId); + StartMenu(player); + Hire::Broker const broker = BrokerKind(); + + if (action == kActionContracts) + { + CloseGossipMenuFor(player); + ListContracts(player); + return true; + } + if (action == kActionOptIn) + { + uint32 const account = player->GetSession()->GetAccountId(); + bool const on = !HireMgr::Instance().OptedIn(account); + HireMgr::Instance().SetOptedIn(account, on); + CloseGossipMenuFor(player); + Tell(player, on ? "Hired bots only: your companions now come from the brokers." : "Hired bots off: you can bring bots for free again."); + return true; + } + if (action >= kActionGrade && action < kActionGrade + 3) + { + Hire::Grade const grade = Hire::Grade(action - kActionGrade + 1); + if (!Hire::BrokerSells(HireMgr::ConfigRules(), broker, grade)) + return MainMenuAgain(player); + for (uint32 r = 1; r <= 3; ++r) + AddOption(player, Trinity::StringFormat("A {}.", RoleWord(RoleOfIndex(r))), kActionRole + uint32(grade) * 10 + r); + SendGossipMenuFor(player, kBrokerText, me->GetGUID()); + return true; + } + if (action >= kActionRole + 10 && action < kActionRole + 40) + { + Hire::Grade const grade = Hire::Grade((action - kActionRole) / 10); + uint32 const roleIndex = (action - kActionRole) % 10; + Playerbot::Role const role = RoleOfIndex(roleIndex); + uint64 const price = HireMgr::PriceHere(player, grade); + if (!Hire::BrokerSells(HireMgr::ConfigRules(), broker, grade) || !price || roleIndex < 1 || roleIndex > 3) + return MainMenuAgain(player); + for (ClassInfo const& c : kClasses) + if (Plays(c, role) && CanHaveCompanionClass(player, c.cls)) + AddOption(player, c.name, kActionHire + uint32(grade) * 100 + roleIndex * 20 + c.cls, + Trinity::StringFormat("Hire a {} {} ({})?", c.name, Hire::GradeName(grade), RoleWord(role)), price); + SendGossipMenuFor(player, kBrokerText, me->GetGUID()); + return true; + } + if (action >= kActionHire + 100 && action < kActionHire + 400) + { + uint32 const rest = action - kActionHire; + Hire::Grade const grade = Hire::Grade(rest / 100); + Playerbot::Role const role = RoleOfIndex((rest % 100) / 20); + ClassInfo const* c = FindClass(uint8(rest % 20)); + CloseGossipMenuFor(player); + if (!c || !Hire::BrokerSells(HireMgr::ConfigRules(), broker, grade) || !Plays(*c, role)) + return true; + std::string msg; + bool const ok = HireCompanionForOwner(player, c->cls, role, grade, c->name, msg); + if (!msg.empty()) + Tell(player, msg); + if (ok) + me->Say(HiredLine(broker), LANG_UNIVERSAL, player); + return true; + } + CloseGossipMenuFor(player); + return true; + } + +private: + bool MainMenuAgain(Player* player) + { + MainMenu(player); + return true; + } +}; + +void AddSC_playerbot_v2_hire_broker() +{ + RegisterCreatureAI(npc_fb_hire_broker); +} diff --git a/src/modules/PlayerbotV2/Hire/HireBroker.h b/src/modules/PlayerbotV2/Hire/HireBroker.h new file mode 100644 index 0000000000..535a15e32f --- /dev/null +++ b/src/modules/PlayerbotV2/Hire/HireBroker.h @@ -0,0 +1,10 @@ +// The hire brokers (Playerbot.Hire.*): Sellsword Captains at inns, Veteran Recruiters in the capitals, black-market brokers in +// Gadgetzan, Booty Bay and Ratchet. Their gossip hires a bot of the broker's grade; the hiring itself is `.bot add`'s +// (cs_playerbot_v2.cpp AddCompanionFor, through HireCompanionForOwner), so a hired bot is set up, geared and grouped like any companion. + +#pragma once + +#include "HirePolicy.h" +#include "../HireHooks.h" // HireCompanionForOwner, CanHaveCompanionClass: the bot module's side + +void AddSC_playerbot_v2_hire_broker(); diff --git a/src/modules/PlayerbotV2/Hire/HireMgr.cpp b/src/modules/PlayerbotV2/Hire/HireMgr.cpp new file mode 100644 index 0000000000..087423b28e --- /dev/null +++ b/src/modules/PlayerbotV2/Hire/HireMgr.cpp @@ -0,0 +1,376 @@ +#include "HireMgr.h" +#include "../Bot/ClassTables.h" +#include "../Bot/Gear/OwnedGearPolicy.h" +#include "Cell.h" +#include "CellImpl.h" +#include "Chat.h" +#include "Config.h" +#include "Creature.h" +#include "DatabaseEnv.h" +#include "GameTime.h" +#include "GridNotifiers.h" +#include "GridNotifiersImpl.h" +#include "Timer.h" +#include "Group.h" +#include "../Fleet/InstanceGroupCap.h" +#include "Log.h" +#include "ObjectAccessor.h" +#include "Player.h" +#include "../Services.h" +#include "WorldSession.h" +#include "../Fleet/OwnerRegistry.h" +#include +#include +#include +#include +#include + +namespace Playerbot::V2::Fleet { + +namespace { +auto& Db() { return CharacterDatabase; } + +uint64 PriceKey(char const* key, uint64 def) +{ + int64 const v = sConfigMgr->GetInt64Default(key, int64(def), true); + return v < 0 ? 0 : uint64(v); +} +} + +HireMgr& HireMgr::Instance() +{ + static HireMgr instance; + return instance; +} + +Hire::Mode HireMgr::ConfigMode() +{ + int32 const m = sConfigMgr->GetIntDefault("Playerbot.Hire.Mode", 0, true); + return (m == 1 || m == 2) ? Hire::Mode(m) : Hire::Mode::Off; +} + +Hire::Prices HireMgr::ConfigPrices() +{ + Hire::Prices p; + using Hire::Grade; + p.grade[uint8(Grade::Sellsword)].party = PriceKey("Playerbot.Hire.Sellsword.PartyPrice", p.grade[uint8(Grade::Sellsword)].party); + p.grade[uint8(Grade::Sellsword)].raid = PriceKey("Playerbot.Hire.Sellsword.RaidPrice", p.grade[uint8(Grade::Sellsword)].raid); + p.grade[uint8(Grade::Veteran)].party = PriceKey("Playerbot.Hire.Veteran.PartyPrice", p.grade[uint8(Grade::Veteran)].party); + p.grade[uint8(Grade::Veteran)].raid = PriceKey("Playerbot.Hire.Veteran.RaidPrice", p.grade[uint8(Grade::Veteran)].raid); + p.grade[uint8(Grade::Legend)].party = PriceKey("Playerbot.Hire.Legend.PartyPrice", p.grade[uint8(Grade::Legend)].party); + p.grade[uint8(Grade::Legend)].raid = PriceKey("Playerbot.Hire.Legend.RaidPrice", p.grade[uint8(Grade::Legend)].raid); + p.upkeep_pct = uint32(std::clamp(sConfigMgr->GetIntDefault("Playerbot.Hire.UpkeepPct", int32(p.upkeep_pct), true), 0, 1000)); + return p; +} + +Hire::Rules HireMgr::ConfigRules() +{ + Hire::Rules r; + using Hire::Grade; + struct GradeKeys { Grade grade; char const* gear; char const* health; }; + static constexpr GradeKeys kGrades[] = { + { Grade::Sellsword, "Playerbot.Hire.Sellsword.Gear", "Playerbot.Hire.Sellsword.HealthPct" }, + { Grade::Veteran, "Playerbot.Hire.Veteran.Gear", "Playerbot.Hire.Veteran.HealthPct" }, + { Grade::Legend, "Playerbot.Hire.Legend.Gear", "Playerbot.Hire.Legend.HealthPct" }, + }; + for (GradeKeys const& k : kGrades) + { + uint8 const g = uint8(k.grade); + std::string word = sConfigMgr->GetStringDefault(k.gear, "", true); + std::transform(word.begin(), word.end(), word.begin(), [](unsigned char c) { return char(std::tolower(c)); }); + Gear::Owned::GearMode mode; + if (!word.empty() && Gear::Owned::ParseGearMode(word, mode)) + r.gear_mode[g] = int(mode); + else if (!word.empty()) + TC_LOG_ERROR("playerbot.v2", "[hire] {} = \"{}\" is no gear mode (match, best, bis, t1, t2, t3): the default stays", k.gear, word); + int32 const pct = sConfigMgr->GetIntDefault(k.health, int32(r.health_pct[g]), true); + r.health_pct[g] = uint32(std::clamp(pct, int32(Hire::kMinHealthPct), int32(Hire::kMaxHealthPct))); + } + struct BrokerKey { Hire::Broker broker; char const* key; }; + static constexpr BrokerKey kBrokers[] = { + { Hire::Broker::Inn, "Playerbot.Hire.Inn.Sells" }, + { Hire::Broker::Capital, "Playerbot.Hire.Capital.Sells" }, + { Hire::Broker::BlackMarket, "Playerbot.Hire.BlackMarket.Sells" }, + }; + for (BrokerKey const& k : kBrokers) + { + // A missing line keeps the default; a line that is there (even empty or "none") is the server owner's list. + std::string const unset = "\x01"; + std::string const list = sConfigMgr->GetStringDefault(k.key, unset, true); + if (list != unset) + r.sells[uint8(k.broker)] = Hire::ParseGradeList(list); + } + return r; +} + +float HireMgr::BrokerRange() +{ + return std::clamp(sConfigMgr->GetFloatDefault("Playerbot.Hire.BrokerRange", 15.0f, true), 3.0f, 100.0f); +} + +uint32 HireMgr::MaxPerAccount() +{ + return uint32(std::max(sConfigMgr->GetIntDefault("Playerbot.Hire.MaxPerAccount", 0, true), 0)); +} + +uint32 HireMgr::LegendMaxPerAccount() +{ + return uint32(std::max(sConfigMgr->GetIntDefault("Playerbot.Hire.Legend.MaxPerAccount", 0, true), 0)); +} + +void HireMgr::LoadFromDb() +{ + auto rows = Db().Query("SELECT character_guid_low, hire_grade, hire_price, hire_paid_until FROM playerbot_v2_character WHERE hire_grade != 0"); + auto prefs = Db().Query("SELECT account_id FROM playerbot_v2_hire_pref WHERE hired_only != 0"); + std::unique_lock lk(mtx_); + hired_.clear(); + opted_in_.clear(); + loaned_.clear(); + if (rows) + do + { + Field* f = rows->Fetch(); + uint8 const g = f[1].GetUInt8(); + if (g == Hire::kLoanGradeDb) + { + loaned_[f[0].GetUInt64()] = 0; + continue; + } + if (g == 0 || g >= Hire::kGradeCount) + continue; + hired_[f[0].GetUInt64()] = HireRecord{ Hire::Grade(g), f[2].GetUInt64(), f[3].GetUInt64() }; + } while (rows->NextRow()); + if (prefs) + do { opted_in_.insert(prefs->Fetch()[0].GetUInt32()); } while (prefs->NextRow()); + TC_LOG_INFO("playerbot.v2", "[hire] mode={} hired bots={} finder loan bots={} accounts choosing hired bots={}", uint32(ConfigMode()), + hired_.size(), loaned_.size(), opted_in_.size()); +} + +bool HireMgr::OptedIn(uint32 account_id) const +{ + std::shared_lock lk(mtx_); + return opted_in_.contains(account_id); +} + +void HireMgr::SetOptedIn(uint32 account_id, bool on) +{ + { + std::unique_lock lk(mtx_); + if (on ? !opted_in_.insert(account_id).second : opted_in_.erase(account_id) == 0) + return; + } + Db().DirectPExecute("REPLACE INTO playerbot_v2_hire_pref (account_id, hired_only) VALUES ({}, {})", account_id, on ? 1 : 0); +} + +bool HireMgr::MustHire(Player const* player) const +{ + if (!player || !player->GetSession() || player->GetSession()->IsBot()) + return false; + bool const gm = player->GetSession()->GetSecurity() > SEC_PLAYER; + bool const bypass = sConfigMgr->GetBoolDefault("Playerbot.Hire.GmBypass", false, true); + return Hire::Required(ConfigMode(), OptedIn(player->GetSession()->GetAccountId()), gm, bypass); +} + +bool HireMgr::MustHireAccount(uint32 account_id) const +{ + if (!account_id) + return false; + return Hire::Required(ConfigMode(), OptedIn(account_id), false, false); +} + +HireRecord HireMgr::RecordOf(BotId bot) const +{ + std::shared_lock lk(mtx_); + auto const it = hired_.find(bot); + return it == hired_.end() ? HireRecord{} : it->second; +} + +void HireMgr::SetHired(BotId bot, Hire::Grade grade, uint64 price) +{ + uint64 const until = uint64(GameTime::GetGameTime()) + Hire::kDaySeconds; + { + std::unique_lock lk(mtx_); + hired_[bot] = HireRecord{ grade, price, until }; + } + Db().DirectPExecute("UPDATE playerbot_v2_character SET hire_grade = {}, hire_price = {}, hire_paid_until = {} WHERE character_guid_low = {}", + uint32(grade), price, until, bot); +} + +void HireMgr::Forget(BotId bot) +{ + { + std::unique_lock lk(mtx_); + bool const was_hired = hired_.erase(bot) != 0; + bool const was_loaned = loaned_.erase(bot) != 0; + if (!was_hired && !was_loaned) + return; + called_ms_.erase(bot); + } + Db().DirectPExecute("UPDATE playerbot_v2_character SET hire_grade = 0, hire_price = 0, hire_paid_until = 0 WHERE character_guid_low = {}", bot); +} + +void HireMgr::SetLoaned(BotId bot, uint32 now_ms) +{ + { + std::unique_lock lk(mtx_); + hired_.erase(bot); + loaned_[bot] = now_ms ? now_ms : 1; + } + Db().DirectPExecute("UPDATE playerbot_v2_character SET hire_grade = {}, hire_price = 0, hire_paid_until = 0 WHERE character_guid_low = {}", + uint32(Hire::kLoanGradeDb), bot); +} + +bool HireMgr::IsLoaned(BotId bot) const +{ + std::shared_lock lk(mtx_); + return loaned_.contains(bot); +} + +bool HireMgr::LoanSettled(BotId bot, uint32 now_ms) const +{ + std::shared_lock lk(mtx_); + auto const it = loaned_.find(bot); + return it != loaned_.end() && (it->second == 0 || getMSTimeDiff(it->second, now_ms) >= Hire::kLoanGraceMs); +} + +std::vector HireMgr::LoanedBots() const +{ + std::shared_lock lk(mtx_); + std::vector out; + out.reserve(loaned_.size()); + for (auto const& [id, _] : loaned_) + out.push_back(id); + return out; +} + +uint32 HireMgr::CountGrade(uint32 account_id, Hire::Grade grade) const +{ + uint32 n = 0; + for (BotId id : Services::Owners().BotsOwnedBy(account_id)) + if (RecordOf(id).grade == grade) + ++n; + return n; +} + +int HireMgr::GearModeOverride(BotId bot, uint32 owner_account) const +{ + Hire::Grade const grade = RecordOf(bot).grade; + if (grade == Hire::Grade::None && ConfigMode() == Hire::Mode::Off) + return -1; + bool must = MustHireAccount(owner_account); + // A GM's own companions keep the GM's gear choice (testing), as long as the GM is online to be asked. + if (must) + if (uint64 const owner_guid = Services::Owners().OwnerCharacter(bot)) + if (Player const* owner = ObjectAccessor::FindConnectedPlayer(ObjectGuid::Create(owner_guid))) + must = MustHire(owner); + return Hire::GearModeFor(ConfigRules(), grade, must); +} + +Creature* HireMgr::NearbyBroker(Player* player, Hire::Grade grade) const +{ + if (!player || !player->IsInWorld()) + return nullptr; + float const range = BrokerRange(); + Hire::Rules const rules = ConfigRules(); + std::list near; + Trinity::AnyUnitInObjectRangeCheck check(player, range); + Trinity::CreatureListSearcher searcher(player, near, check); + Cell::VisitGridObjects(player, searcher, range); + for (Creature* c : near) + if (c && c->IsAlive() && Hire::BrokerSells(rules, Hire::BrokerOfEntry(c->GetEntry()), grade)) + return c; + return nullptr; +} + +void HireMgr::ApplyHealth(Player* bot) +{ + if (!bot || !bot->IsInWorld()) + return; + BotId const id = bot->GetGUID().GetCounter(); + float given = 0.0f; + if (auto const it = health_bonus_.find(id); it != health_bonus_.end() && it->second.who == bot) + given = it->second.amount; + uint32 const pct = Hire::HealthPctFor(ConfigRules(), RecordOf(id).grade); + // The bot's health without the bonus, at its class, level and gear now (the bonus follows a level-up or new gear here). + float const normal = std::max(float(bot->GetMaxHealth()) - given, 1.0f); + float want = float(Hire::HealthBonusFor(uint64(normal), pct)); + if (normal + want < 1.0f) + want = 1.0f - normal; + if (std::abs(want - given) < 1.0f) + { + if (given == 0.0f) + health_bonus_.erase(id); + return; + } + bool const was_full = bot->IsAlive() && bot->GetHealth() >= bot->GetMaxHealth(); + if (given != 0.0f) + bot->HandleStatFlatModifier(UNIT_MOD_HEALTH, TOTAL_VALUE, given, false); + if (want != 0.0f) + bot->HandleStatFlatModifier(UNIT_MOD_HEALTH, TOTAL_VALUE, want, true); + if (was_full && !bot->IsInCombat()) + bot->SetFullHealth(); + if (want != 0.0f) + health_bonus_[id] = HealthBonus{ bot, want }; + else + health_bonus_.erase(id); + TC_LOG_DEBUG("playerbot.v2", "[hire] {} health {}% ({:+.0f}, max {})", bot->GetName(), pct, want, bot->GetMaxHealth()); +} + +bool HireMgr::RaidPlace(Player* player) +{ + if (!player) + return false; + if (Group const* g = player->GetGroup(); g && g->isRaidGroup()) + return true; + Map const* map = player->GetMap(); + return map && map->IsDungeon() && InstanceGroupCapFor(player) > 5; +} + +uint64 HireMgr::PriceHere(Player* player, Hire::Grade grade) +{ + if (!player) + return 0; + return Hire::PriceFor(ConfigPrices(), grade, player->GetLevel(), MaxPlayerLevel(), RaidPlace(player)); +} + +bool HireMgr::TakeUpkeep(Player* owner, BotId bot, std::string const& bot_name, std::string& why) +{ + HireRecord const rec = RecordOf(bot); + uint64 const now = uint64(GameTime::GetGameTime()); + if (rec.grade == Hire::Grade::None || !Hire::UpkeepDue(rec.paid_until, now) || !owner || !MustHire(owner)) + return true; + uint64 const fee = Hire::UpkeepFor(ConfigPrices(), rec.price); + if (fee && !owner->HasEnoughMoney(fee)) + { + why = bot_name + " wants a day's wages first (" + Hire::MoneyText(fee) + ")."; + return false; + } + if (fee) + owner->ModifyMoney(-int64(fee)); + uint64 const until = now + Hire::kDaySeconds; + { + std::unique_lock lk(mtx_); + if (auto it = hired_.find(bot); it != hired_.end()) + it->second.paid_until = until; + } + Db().DirectPExecute("UPDATE playerbot_v2_character SET hire_paid_until = {} WHERE character_guid_low = {}", until, bot); + if (fee && owner->GetSession()) + ChatHandler(owner->GetSession()).PSendSysMessage("You paid %s %s for today.", bot_name.c_str(), Hire::MoneyText(fee).c_str()); + TC_LOG_INFO("playerbot.v2", "[hire] {} paid {} copper upkeep for {}", owner->GetName(), fee, bot_name); + return true; +} + +void HireMgr::NoteCalled(BotId bot, uint32 now_ms) +{ + std::unique_lock lk(mtx_); + called_ms_[bot] = now_ms; +} + +bool HireMgr::RecentlyCalled(BotId bot, uint32 now_ms) const +{ + std::shared_lock lk(mtx_); + auto const it = called_ms_.find(bot); + return it != called_ms_.end() && now_ms - it->second < 30000u; +} + +} // namespace Playerbot::V2::Fleet diff --git a/src/modules/PlayerbotV2/Hire/HireMgr.h b/src/modules/PlayerbotV2/Hire/HireMgr.h new file mode 100644 index 0000000000..4dfb1f5aff --- /dev/null +++ b/src/modules/PlayerbotV2/Hire/HireMgr.h @@ -0,0 +1,101 @@ +// HireMgr - hired bots (Playerbot.Hire.*; the rules are HirePolicy.h). Keeps each hired bot's grade, what was paid for it and how +// long its upkeep is paid, and which accounts chose hired bots (Playerbot.Hire.Mode = 2). Stored in playerbot_v2_character +// (hire_grade, hire_price, hire_paid_until) and playerbot_v2_hire_pref, migration 0037. Reads from any thread, writes on the world +// thread (hiring, upkeep, `.bot hire on|off`). + +#pragma once + +#include "HirePolicy.h" +#include "../Bot/BotTypes.h" +#include +#include +#include +#include +#include + +class Creature; +class Player; + +namespace Playerbot::V2::Fleet { + +struct HireRecord +{ + Hire::Grade grade = Hire::Grade::None; + uint64 price = 0; // copper paid for the bot (its upkeep is a share of this) + uint64 paid_until = 0; // unix seconds; the upkeep is due again from then, the next time the bot is called +}; + +class HireMgr +{ +public: + static HireMgr& Instance(); + + void LoadFromDb(); + + // The server's settings, read from the config each call (a `.reload config` takes effect at once). + static Hire::Mode ConfigMode(); + static Hire::Prices ConfigPrices(); + // Each grade's gear and health and what each kind of broker sells (Playerbot.Hire..Gear / .HealthPct, .Sells). + static Hire::Rules ConfigRules(); + static float BrokerRange(); + static uint32 MaxPerAccount(); // 0 = no limit + static uint32 LegendMaxPerAccount(); // 0 = no limit + + // Whether `player` must hire companions instead of making them (Hire::Required with the player's choice and GM bypass). + bool MustHire(Player const* player) const; + // The same for the account owning a bot (its owner offline: the account's choice, no GM bypass). + bool MustHireAccount(uint32 account_id) const; + + bool OptedIn(uint32 account_id) const; + void SetOptedIn(uint32 account_id, bool on); + + HireRecord RecordOf(BotId bot) const; + // A bot was hired for `price`: its first day is paid. + void SetHired(BotId bot, Hire::Grade grade, uint64 price); + void Forget(BotId bot); + // Group Finder / dungeon finder bots of a player who must hire (Hire::kLoanGradeDb): free while they stay in that player's + // group, never called on their own, deleted when they leave it (BotPopulationManager::CompanionUpkeep / ReleaseLoans). + void SetLoaned(BotId bot, uint32 now_ms); + bool IsLoaned(BotId bot) const; + // A loan bot older than Hire::kLoanGraceMs (made before this start counts as old). + bool LoanSettled(BotId bot, uint32 now_ms) const; + std::vector LoanedBots() const; + uint32 CountGrade(uint32 account_id, Hire::Grade grade) const; + + // The gear mode a companion wears under hired mode (Gear::Owned::GearMode value), -1 when the owner's own choice stands. + int GearModeOverride(BotId bot, uint32 owner_account) const; + + // Gives a hired bot its grade's health (Playerbot.Hire..HealthPct) on top of what its class, level and gear give it, or + // takes an old bonus off again (the grade's percent changed, or the bot is no longer hired). Cheap when nothing changed; called + // when a companion is set up and on its regular upkeep. World thread. + void ApplyHealth(Player* bot); + + // The broker NPC within Playerbot.Hire.BrokerRange of `player` that sells `grade`, or nullptr. World thread. + Creature* NearbyBroker(Player* player, Hire::Grade grade) const; + // Whether a new bot for `player` fills a raid place: a raid group, or an instance for more than 5. + static bool RaidPlace(Player* player); + // The price `player` pays for one bot of `grade` here (0 = not for sale at this level). + static uint64 PriceHere(Player* player, Hire::Grade grade); + + // A companion of `owner` is being called: takes the day's upkeep when it is due. False (and `why` says so) when the owner cannot + // pay; the bot then stays home. World thread. + bool TakeUpkeep(Player* owner, BotId bot, std::string const& bot_name, std::string& why); + + // A hired bot that was just called by an add (Quick party sends one `.bot add` per place) is not picked again for the next + // place while it logs in. + void NoteCalled(BotId bot, uint32 now_ms); + bool RecentlyCalled(BotId bot, uint32 now_ms) const; + +private: + mutable std::shared_mutex mtx_; + std::unordered_map hired_; + std::unordered_set opted_in_; + std::unordered_map called_ms_; + std::unordered_map loaned_; // bot -> when it was lent (getMSTime), 0 = before this start + // The health given by ApplyHealth, per bot, with the Player it was given to (a bot that logged out and in again is a new Player + // object without it). World thread only. + struct HealthBonus { Player const* who = nullptr; float amount = 0.0f; }; + std::unordered_map health_bonus_; +}; + +} // namespace Playerbot::V2::Fleet diff --git a/src/modules/PlayerbotV2/Hire/HireModule.cpp b/src/modules/PlayerbotV2/Hire/HireModule.cpp new file mode 100644 index 0000000000..8059f47e55 --- /dev/null +++ b/src/modules/PlayerbotV2/Hire/HireModule.cpp @@ -0,0 +1,142 @@ +// HireModule - puts the hired bots in charge of the bot module's hire questions (HireHooks.h). Everything here forwards to HireMgr +// (the contracts) and HirePolicy (the rules); the broker NPCs are HireBroker.cpp. Registered by AddSC_playerbot_v2_hire, which the +// bot module's script loader calls when the module is built with PLAYERBOT_V2_HIRE (the default). + +#include "HireBroker.h" +#include "HireMgr.h" +#include "HirePolicy.h" +#include "../HireHooks.h" +#include "../Bot/ClassTables.h" +#include "../Fleet/OwnerRegistry.h" +#include "../Services.h" +#include "Chat.h" +#include "Log.h" +#include "Player.h" +#include "StringFormat.h" +#include "WorldSession.h" +#include + +namespace Playerbot::V2::Fleet { + +namespace { + +class HireModuleHooks final : public HireHooks +{ +public: + bool Built() const override { return true; } + + void LoadFromDb() override { HireMgr::Instance().LoadFromDb(); } + + Hire::Mode ConfigMode() const override { return HireMgr::ConfigMode(); } + + bool MustHire(Player const* player) const override { return HireMgr::Instance().MustHire(player); } + bool MustHireAccount(uint32 account_id) const override { return HireMgr::Instance().MustHireAccount(account_id); } + + void SetLoaned(BotId bot, uint32 now_ms) override { HireMgr::Instance().SetLoaned(bot, now_ms); } + bool IsLoaned(BotId bot) const override { return HireMgr::Instance().IsLoaned(bot); } + bool LoanSettled(BotId bot, uint32 now_ms) const override { return HireMgr::Instance().LoanSettled(bot, now_ms); } + std::vector LoanedBots() const override { return HireMgr::Instance().LoanedBots(); } + + void NoteCalled(BotId bot, uint32 now_ms) override { HireMgr::Instance().NoteCalled(bot, now_ms); } + bool RecentlyCalled(BotId bot, uint32 now_ms) const override { return HireMgr::Instance().RecentlyCalled(bot, now_ms); } + + bool BrokerNear(Player* player, Hire::Grade grade) const override { return HireMgr::Instance().NearbyBroker(player, grade) != nullptr; } + + bool CheckHire(Player* me, Hire::Grade grade, uint64& price, std::string& why) const override + { + HireMgr const& hire = HireMgr::Instance(); + price = 0; + if (!me || !me->GetSession()) + return false; + uint32 const account = me->GetSession()->GetAccountId(); + if (!hire.NearbyBroker(me, grade)) + { why = Trinity::StringFormat("There is nobody here who hires out a {}.", Hire::GradeName(grade)); return false; } + price = HireMgr::PriceHere(me, grade); + if (!price) + { why = Trinity::StringFormat("A {} only signs on with a level {} hero.", Hire::GradeName(grade), uint32(MaxPlayerLevel())); return false; } + if (uint32 const max = HireMgr::MaxPerAccount(); max && Services::Owners().BotsOwnedBy(account).size() >= max) + { why = Trinity::StringFormat("You have {} bots already, the most this realm allows. End a contract first.", max); return false; } + if (uint32 const max = HireMgr::LegendMaxPerAccount(); grade == Hire::Grade::Legend && max && hire.CountGrade(account, Hire::Grade::Legend) >= max) + { why = Trinity::StringFormat("The cartel hires out {} Legend(s) to one hero at a time.", max); return false; } + if (!me->HasEnoughMoney(price)) + { why = Trinity::StringFormat("You need {} to hire a {}.", Hire::MoneyText(price), Hire::GradeName(grade)); return false; } + return true; + } + + void OnHired(Player* me, BotId bot, Hire::Grade grade, uint64 price, std::string const& bot_name, std::string const& class_name) override + { + me->ModifyMoney(-int64(price)); + HireMgr::Instance().SetHired(bot, grade, price); + HireMgr::Instance().NoteCalled(bot, getMSTime()); + TC_LOG_INFO("playerbot.v2", "[hire] {} hired {} ({} {}) for {} copper", me->GetName(), bot_name, Hire::GradeName(grade), class_name, price); + } + + std::string SignOnText(std::string const& bot_name, Hire::Grade grade, uint64 price) const override + { + return Trinity::StringFormat("{} the {} signs on for {} and is on the way.", bot_name, Hire::GradeName(grade), Hire::MoneyText(price)); + } + + bool TakeUpkeep(Player* owner, BotId bot, std::string const& bot_name, std::string& why) override + { + return HireMgr::Instance().TakeUpkeep(owner, bot, bot_name, why); + } + + void Forget(BotId bot) override { HireMgr::Instance().Forget(bot); } + + void ApplyHealth(Player* bot) override { HireMgr::Instance().ApplyHealth(bot); } + + int GearModeOverride(BotId bot, uint32 owner_account) const override { return HireMgr::Instance().GearModeOverride(bot, owner_account); } + + // .bot hire [on|off]: no word: whether you must hire, and what one bot costs here. on / off: your own choice when the realm + // leaves it to each player (Hire.Mode = 2). + bool HandleCommand(ChatHandler* handler, Optional word) override + { + WorldSession* sess = handler->GetSession(); + Player* me = sess ? sess->GetPlayer() : nullptr; + if (!me) + { + handler->SetSentErrorMessage(true); + return false; + } + Hire::Mode const mode = HireMgr::ConfigMode(); + if (word) + { + std::string w = *word; + for (char& c : w) + c = char(std::tolower(static_cast(c))); + if (w != "on" && w != "off") + { + handler->SendSysMessage("Usage: .bot hire [on|off]"); + handler->SetSentErrorMessage(true); + return false; + } + if (mode != Hire::Mode::PlayerChoice) + { + handler->SendSysMessage(mode == Hire::Mode::Everyone ? "This realm has hired bots for everyone." : "Hired bots are off on this realm."); + handler->SetSentErrorMessage(true); + return false; + } + HireMgr::Instance().SetOptedIn(sess->GetAccountId(), w == "on"); + } + bool const must = HireMgr::Instance().MustHire(me); + std::string prices; + for (Hire::Grade g : { Hire::Grade::Sellsword, Hire::Grade::Veteran, Hire::Grade::Legend }) + if (uint64 const p = HireMgr::PriceHere(me, g)) + prices += Trinity::StringFormat("{}{} {}", prices.empty() ? "" : ", ", Hire::GradeName(g), Hire::MoneyText(p)); + handler->PSendSysMessage("Hired bots: %s. One bot costs %s here; upkeep %u%% a day you call it.", + must ? "on (your companions come from the brokers)" : "off (bots are free)", prices.c_str(), + HireMgr::ConfigPrices().upkeep_pct); + return true; + } +}; + +} // namespace + +} // namespace Playerbot::V2::Fleet + +void AddSC_playerbot_v2_hire() +{ + static Playerbot::V2::Fleet::HireModuleHooks hooks; + Playerbot::V2::Fleet::SetHireHooks(&hooks); + AddSC_playerbot_v2_hire_broker(); +} diff --git a/src/modules/PlayerbotV2/Hire/HirePolicy.h b/src/modules/PlayerbotV2/Hire/HirePolicy.h new file mode 100644 index 0000000000..3fccc61305 --- /dev/null +++ b/src/modules/PlayerbotV2/Hire/HirePolicy.h @@ -0,0 +1,229 @@ +// HirePolicy - the rules of hired bots (Playerbot.Hire.*), kept free of game types so tests/game/ClassicHirePolicy.cpp can pin them. +// +// In hired mode a player's companions are not made out of nothing: they are hired from a mercenary NPC for gold. Three grades: +// Sellsword every listed inn and the capitals, at the hirer's level, the normal companion gear (match). +// Veteran the capitals only, level cap only, raid gear up to Playerbot.Gear.MaxTier whatever the owner wears (best). +// Legend the black-market brokers of Gadgetzan, Booty Bay and Ratchet, level cap only, best in slot (bis). +// Prices are package prices at the level cap, as the server owner sets them: a 5-man (the 4 places beside the player) and a 40-man +// (39 places). One bot costs its package price divided by those places; a Sellsword below the cap costs (level / cap)^2 of that, +// never under kMinPriceCopper. Upkeep: a share of what was paid for the bot, once for each day the bot is called. + +#pragma once + +#include "../HireTypes.h" +#include +#include +#include +#include + +namespace Playerbot::V2::Fleet::Hire { + +// Grade, kGradeCount and Mode are in HireTypes.h (the bot module knows them without the hired bots built in). + +// What a broker NPC sells, from its creature entry (kBrokerEntryFirst.. in blocks of 100). +enum class Broker : uint8_t { None = 0, Inn = 1, Capital = 2, BlackMarket = 3 }; + +// (an entry travels in 23 bits to the client: nothing above 8388607 can be a creature the client lets you talk to) +constexpr uint32_t kBrokerEntryFirst = 6110000; // 6110000-6110099 inn, 6110100-6110199 capital, 6110200-6110299 black market +constexpr uint32_t kBrokerEntryLast = 6110299; +constexpr uint64_t kMinPriceCopper = 100; // 1 silver +constexpr uint32_t kPartyPlaces = 4; // the places beside the player in a 5-man +constexpr uint32_t kRaidPlaces = 39; // ... in a 40-man +constexpr uint32_t kDaySeconds = 86400; +// A Group Finder / dungeon finder bot made for a player who must hire: it plays with them for free while it stays in their group, +// cannot be called on its own and is deleted once it leaves the group (a loan, not a hire). Stored as this hire_grade value. +constexpr uint8_t kLoanGradeDb = 9; +constexpr uint32_t kLoanGraceMs = 120000; // a loan bot that is still logging in or joining is not taken back yet + +constexpr Broker BrokerOfEntry(uint32_t entry) +{ + if (entry < kBrokerEntryFirst || entry > kBrokerEntryLast) + return Broker::None; + return Broker(1 + (entry - kBrokerEntryFirst) / 100); +} + +// The grades each kind of broker sells by default: an inn Sellswords, a capital Sellswords and Veterans, the black market Legends. +// A server owner changes this with Playerbot.Hire..Sells (Rules below). +constexpr bool BrokerSells(Broker b, Grade g) +{ + switch (b) + { + case Broker::Inn: return g == Grade::Sellsword; + case Broker::Capital: return g == Grade::Sellsword || g == Grade::Veteran; + case Broker::BlackMarket: return g == Grade::Legend; + default: return false; + } +} + +// Veterans and Legends are level-cap only: raid gear means nothing below it, and a Legend hired at 15 for pocket money would grow +// into best-in-slot gear for free. +constexpr bool GradeForLevel(Grade g, uint32_t level, uint32_t cap) +{ + if (g == Grade::Sellsword) + return level >= 1; + return (g == Grade::Veteran || g == Grade::Legend) && level >= cap; +} + +// A grade's package prices at the level cap, in copper. +struct GradePrices +{ + uint64_t party = 0; // the 4 bots of a 5-man + uint64_t raid = 0; // the 39 bots of a 40-man +}; + +struct Prices +{ + GradePrices grade[kGradeCount] = { + {}, + { 10000, 200000 }, // Sellsword 1g / 20g + { 30000, 600000 }, // Veteran 3g / 60g + { 50000, 1000000 }, // Legend 5g / 100g + }; + uint32_t upkeep_pct = 25; // of the price paid, per day the bot is called; 0 = no upkeep +}; + +// The server owner's rules for each grade and broker (Playerbot.Hire..Gear / .HealthPct, Playerbot.Hire..Sells). The +// defaults are the built-in rules above, so a server without these lines plays as before. +struct Rules +{ + // Gear mode (Gear::Owned::GearMode value: 0 match, 1 best, 2 t1, 3 t2, 4 t3, 5 bis) each grade wears. + int gear_mode[kGradeCount] = { -1, 0, 1, 5 }; + // A hired bot's health in percent of what its class, level and gear give it (100 = normal). + uint32_t health_pct[kGradeCount] = { 100, 100, 100, 100 }; + // Bit (1 << grade) for each grade a kind of broker sells, by Broker value. + uint8_t sells[4] = { 0, 1u << 1, (1u << 1) | (1u << 2), 1u << 3 }; +}; + +constexpr uint32_t kMinHealthPct = 25; +constexpr uint32_t kMaxHealthPct = 1000; + +constexpr bool BrokerSells(Rules const& r, Broker b, Grade g) +{ + if (b == Broker::None || uint8_t(b) > 3 || g == Grade::None || uint8_t(g) >= kGradeCount) + return false; + return (r.sells[uint8_t(b)] >> uint8_t(g)) & 1u; +} + +constexpr uint32_t HealthPctFor(Rules const& r, Grade g) +{ + if (g == Grade::None || uint8_t(g) >= kGradeCount) + return 100; + return std::clamp(r.health_pct[uint8_t(g)], kMinHealthPct, kMaxHealthPct); +} + +// The extra (or, under 100%, missing) health of a bot whose class, level and gear give it `normal` health, at `pct` percent. +constexpr int64_t HealthBonusFor(uint64_t normal, uint32_t pct) +{ + pct = std::clamp(pct, kMinHealthPct, kMaxHealthPct); + return int64_t(normal) * (int64_t(pct) - 100) / 100; +} + +// A list of grade names ("sellsword, veteran"; commas or spaces, any case) as Rules::sells bits. "none" or an empty list = nothing. +// Unknown words are skipped. +inline uint8_t ParseGradeList(std::string_view list) +{ + uint8_t mask = 0; + size_t i = 0; + while (i <= list.size()) + { + size_t j = list.find_first_of(", ", i); + if (j == std::string_view::npos) + j = list.size(); + std::string w(list.substr(i, j - i)); + for (char& c : w) + if (c >= 'A' && c <= 'Z') + c = char(c - 'A' + 'a'); + if (w == "sellsword" || w == "sellswords") + mask |= 1u << uint8_t(Grade::Sellsword); + else if (w == "veteran" || w == "veterans") + mask |= 1u << uint8_t(Grade::Veteran); + else if (w == "legend" || w == "legends") + mask |= 1u << uint8_t(Grade::Legend); + i = j + 1; + } + return mask; +} + +// The price of one bot of grade `g` for a hirer of `level`; `raid` = the bot fills a raid place (a raid group, or an instance for +// more than 5). 0 = not for sale. +constexpr uint64_t PriceFor(Prices const& p, Grade g, uint32_t level, uint32_t cap, bool raid) +{ + if (g == Grade::None || uint8_t(g) >= kGradeCount || !GradeForLevel(g, level, cap) || cap == 0) + return 0; + GradePrices const& gp = p.grade[uint8_t(g)]; + uint64_t const package = raid ? gp.raid : gp.party; + uint64_t const places = raid ? kRaidPlaces : kPartyPlaces; + uint64_t one = package / places; + if (g == Grade::Sellsword && level < cap) + one = one * uint64_t(level) * uint64_t(level) / (uint64_t(cap) * uint64_t(cap)); + return std::max(one, kMinPriceCopper); +} + +// The day's upkeep for a bot that was hired for `paid` copper (0 = no upkeep: a bot owned before hired mode came on, or upkeep off). +constexpr uint64_t UpkeepFor(Prices const& p, uint64_t paid) +{ + if (!paid || !p.upkeep_pct) + return 0; + return std::max(paid * p.upkeep_pct / 100, kMinPriceCopper); +} + +// Whether a bot's upkeep is due when it is called at `now` (unix seconds): its paid day has run out. Days the bot is not called cost +// nothing; the next paid day runs a full day from the payment. +constexpr bool UpkeepDue(uint64_t paid_until, uint64_t now) { return paid_until != 0 && now >= paid_until; } + +// Whether the player must hire: hired mode is on for everyone, or the player chose it; a GM skips it when GmBypass is on. +constexpr bool Required(Mode mode, bool player_opted_in, bool is_gm, bool gm_bypass) +{ + if (is_gm && gm_bypass) + return false; + return mode == Mode::Everyone || (mode == Mode::PlayerChoice && player_opted_in); +} + +// The gear mode (Gear::Owned::GearMode value) a hired bot wears: a Veteran the raid gear (best = 1), a Legend best in slot +// (bis = 5). A Sellsword, or an owned bot of a player who must hire, wears match (0) whatever the owner chose; -1 = no rule (the +// owner's own choice stands). +constexpr int GearModeFor(Grade g, bool owner_must_hire) +{ + if (g == Grade::Legend) return 5; + if (g == Grade::Veteran) return 1; + if (g == Grade::Sellsword || owner_must_hire) return 0; + return -1; +} + +// The same with the server owner's gear for each grade (Playerbot.Hire..Gear). +constexpr int GearModeFor(Rules const& r, Grade g, bool owner_must_hire) +{ + if (g != Grade::None && uint8_t(g) < kGradeCount && r.gear_mode[uint8_t(g)] >= 0) + return r.gear_mode[uint8_t(g)]; + return owner_must_hire ? 0 : -1; +} + +constexpr char const* GradeName(Grade g) +{ + switch (g) + { + case Grade::Sellsword: return "Sellsword"; + case Grade::Veteran: return "Veteran"; + case Grade::Legend: return "Legend"; + default: return "Companion"; + } +} + +// "1g 25s", "75s", "12s 50c": gold, silver and copper, the parts that are not zero. +inline std::string MoneyText(uint64_t copper) +{ + uint64_t const g = copper / 10000, s = (copper / 100) % 100, c = copper % 100; + std::string out; + auto part = [&](uint64_t v, char const* unit) + { + if (!v) return; + if (!out.empty()) out += ' '; + out += std::to_string(v) + unit; + }; + part(g, "g"); + part(s, "s"); + part(c, "c"); + return out.empty() ? std::string("0c") : out; +} + +} // namespace Playerbot::V2::Fleet::Hire diff --git a/src/modules/PlayerbotV2/Hire/README.md b/src/modules/PlayerbotV2/Hire/README.md new file mode 100644 index 0000000000..d9719da7fc --- /dev/null +++ b/src/modules/PlayerbotV2/Hire/README.md @@ -0,0 +1,114 @@ +# Hired bots (sellswords) + +Bots you pay for. Next to the innkeeper of 30 towns stands a **Sellsword Captain**, in the six capitals a **Veteran +Recruiter**, and in Gadgetzan, Booty Bay and Ratchet a goblin **Black Market Broker**. Talk to one, pick a role and a class, +pay, and the bot walks out to join you. It is an ordinary companion from then on (`.bot call`, `.bot dismiss`, orders, the +ForeverBots add-on), it just cost gold, and it may want its wages. + +The idea came from Neylem on the WoW Forever Discord. + +## The three grades + +| Grade | Where | Who can hire | Gear (default) | Price at the level cap (default) | +|---|---|---|---|---| +| Sellsword | every listed inn and the capitals | any level, comes at your level | match: normal gear for its level, up to yours | 1g a bot in a 5-man (20g for a whole 40-man) | +| Veteran | the capitals | level cap only | best: raid gear up to `Playerbot.Gear.MaxTier` | 3g (60g) | +| Legend | Gadgetzan, Booty Bay, Ratchet (both factions) | level cap only | bis: best in slot | 5g (100g) | + +A Sellsword below the cap costs less: (your level / cap)², never under 1 silver. A bot for a raid place (a raid group, or an +instance for more than 5) costs the raid package price / 39, a party place the party price / 4. + +**Upkeep:** a hired bot wants a share of what you paid for it (25 % by default) once for each day you call it. A day it +stays home costs nothing. If you cannot pay, it stays home and says so. `.bot delete` ends the contract; nothing is paid back. + +## The realm's rule: `Playerbot.Hire.Mode` + +| Mode | What it means | +|---|---| +| `0` (default) | Bots are free as before (`.bot add`, Quick party, the Group finder). The brokers still hire out Veterans and Legends to anyone who wants the better gear. | +| `1` | Hired bots only, for everyone. Nobody makes bots out of nothing: `.bot add` and Quick party call a free companion you already have (same role, same class first), or hire a Sellsword when you stand next to a broker. The ForeverBots add-on hides its "Add a bot" buttons and says where bots come from. | +| `2` | Each player chooses: `.bot hire on` / `.bot hire off`, the broker's gossip, or the add-on's `/fb hire`. | + +With hired bots on, the Group finder and the dungeon finder (`.bot lfg`, `.bot dungeon`, a posted listing) still fill your +group for free, but those bots are only lent: they play in that group, cannot be called on their own, and go away once they +leave it. A listed bot group you join plays with you without becoming yours. Bots you owned before hired mode came on count +as Sellswords with no upkeep. World bots are not touched. + +`Playerbot.Hire.GmBypass = 1` lets GM accounts keep making free bots. On a realm of your own your account is usually a GM, +so it is 0 by default: the rule holds for you too. + +## Commands + +| Command | What it does | +|---|---| +| `.bot hire` | Whether you must hire, and what one bot of each grade costs where you stand. | +| `.bot hire on` / `off` | Your own choice, when the realm runs Mode 2. | +| `/fb hire [on\|off]` | The same from the ForeverBots add-on. | +| Broker gossip | Hire (grade, role, class), "Who works for me?" (your bots, their grade and daily wages), and the Mode 2 choice. | + +## Settings (playerbot.conf, `.reload config` takes them at once) + +All of these are described in `conf/playerbot.conf.dist` under "Hired bots". + +``` +Playerbot.Hire.Mode = 0 # 0 off, 1 everyone, 2 each player chooses +Playerbot.Hire.GmBypass = 0 +Playerbot.Hire.BrokerRange = 15 # yards: how close to a broker `.bot add` / Quick party hire +Playerbot.Hire.Sellsword.PartyPrice = 10000 # copper for the 4 bots of a 5-man, at the level cap +Playerbot.Hire.Sellsword.RaidPrice = 200000 # copper for the 39 bots of a 40-man +Playerbot.Hire.Veteran.PartyPrice = 30000 +Playerbot.Hire.Veteran.RaidPrice = 600000 +Playerbot.Hire.Legend.PartyPrice = 50000 +Playerbot.Hire.Legend.RaidPrice = 1000000 +Playerbot.Hire.UpkeepPct = 25 # 0 = no wages +Playerbot.Hire.MaxPerAccount = 0 # 0 = no limit +Playerbot.Hire.Legend.MaxPerAccount = 0 +Playerbot.Hire.Sellsword.Gear = "match" # match, best, bis, t1, t2, t3 +Playerbot.Hire.Veteran.Gear = "best" +Playerbot.Hire.Legend.Gear = "bis" +Playerbot.Hire.Sellsword.HealthPct = 100 # 25 to 1000: tougher (or weaker) mercenaries +Playerbot.Hire.Veteran.HealthPct = 100 +Playerbot.Hire.Legend.HealthPct = 100 +Playerbot.Hire.Inn.Sells = "sellsword" # what each kind of broker sells; "none" = nothing +Playerbot.Hire.Capital.Sells = "sellsword, veteran" +Playerbot.Hire.BlackMarket.Sells = "legend" +``` + +Some ideas: a hardcore realm with `Mode = 1` and `UpkeepPct = 50`; a raid-ready realm where Veterans wear `t2`; a goblin +cartel that sells Veterans and Legends (`BlackMarket.Sells = "veteran, legend"`) and nothing in the capitals. + +## Building + +Hired bots are part of the bot module and built in by default. They need nothing beyond `-DBUILD_PLAYERBOT_V2=1`. + +- `-DPLAYERBOT_V2_HIRE=0` leaves them out. Companions are then always free, `.bot hire` says there are none, and a broker + you talk to says the same (the NPCs are in the world database either way). +- The database parts come with the normal updates: + - `sql/custom/world/2026_10_31_20_world_forever_hire_brokers.sql`: the 39 brokers (entries 6110000-6110299, spawns + 61100000-61100099, each beside the town's innkeeper). + - `sql/custom/world/2026_11_01_20_world_forever_hire_broker_gossip.sql`: their gossip menu (6110000), without which the + client shows no talk cursor. + - `sql/playerbot_v2/0037_hired_bots.sql`: the contracts (characters database, applied by the module at start). + +## How it fits together (for developers) + +| File | What | +|---|---| +| `../HireTypes.h` | Grade and Mode, shared with the rest of the module. | +| `../HireHooks.h` | The only door between the bot module and hired bots. Every question the module asks (must this player hire? is this bot lent? take the wages, give the grade's health and gear) goes through `Fleet::Hiring()`. Without a hire module the answers are "no hired bots", so the module works the same as before. | +| `HirePolicy.h` | The rules (prices, grades, upkeep, who must hire), free of game types; pinned by `tests/game/ClassicHirePolicy.cpp`. | +| `HireMgr.*` | The contracts: grade, price paid, wages paid until, loans, the player's choice. | +| `HireBroker.*` | The broker NPCs' gossip (`npc_fb_hire_broker`). | +| `HireModule.cpp` | Puts the above in charge of `HireHooks` (`AddSC_playerbot_v2_hire`). | + +The hiring itself goes through `.bot add`'s own path (race, name, room checks, setup, login), so a hired bot is set up, geared +and grouped like any companion. + +**Writing your own:** derive from `Playerbot::V2::Fleet::HireHooks`, override what you need, and call `SetHireHooks` from +your module's `AddSC` function (build with `-DPLAYERBOT_V2_HIRE=0` so the two do not both register). The hooks can be asked +from any thread; everything that changes a player or money is called on the world thread. `HireCompanionForOwner` and +`CanHaveCompanionClass` in `HireHooks.h` are what a hire module may call back into the bot module. + +## Licence + +GPL-2.0, like TrinityCore and the rest of WoW Forever Bots (see `../NOTICE.md`). diff --git a/src/modules/PlayerbotV2/HireHooks.cpp b/src/modules/PlayerbotV2/HireHooks.cpp new file mode 100644 index 0000000000..5585df3345 --- /dev/null +++ b/src/modules/PlayerbotV2/HireHooks.cpp @@ -0,0 +1,62 @@ +#include "HireHooks.h" +#include "Chat.h" +#include "Creature.h" +#include "Player.h" +#include "ScriptMgr.h" +#include "ScriptedCreature.h" +#include "ScriptedGossip.h" +#include "WorldSession.h" +#include + +namespace Playerbot::V2::Fleet { + +namespace { +HireHooks& DefaultHooks() +{ + static HireHooks none; + return none; +} + +std::atomic g_hooks{ nullptr }; +} + +bool HireHooks::HandleCommand(ChatHandler* handler, Optional /*word*/) +{ + handler->SendSysMessage("There are no hired bots on this server: companions are free."); + handler->SetSentErrorMessage(true); + return false; +} + +HireHooks& Hiring() +{ + HireHooks* const h = g_hooks.load(std::memory_order_acquire); + return h ? *h : DefaultHooks(); +} + +void SetHireHooks(HireHooks* hooks) +{ + g_hooks.store(hooks, std::memory_order_release); +} + +} // namespace Playerbot::V2::Fleet + +// Built without the hire module (-DPLAYERBOT_V2_HIRE=0) the broker NPCs of the world database still stand at the inns: they say so +// instead of opening an empty window. +struct npc_fb_hire_broker_off : public ScriptedAI +{ + explicit npc_fb_hire_broker_off(Creature* creature) : ScriptedAI(creature) { } + + bool OnGossipHello(Player* player) override + { + CloseGossipMenuFor(player); + if (player->GetSession()) + ChatHandler(player->GetSession()).SendSysMessage("This server has no hired bots: companions are free (.bot add, or the ForeverBots add-on)."); + return true; + } +}; + +void AddSC_playerbot_v2_hire_off() +{ + // The database's script name for the brokers (Hire/HireBroker.cpp registers the real one under the same name). + new GenericCreatureScript("npc_fb_hire_broker"); +} diff --git a/src/modules/PlayerbotV2/HireHooks.h b/src/modules/PlayerbotV2/HireHooks.h new file mode 100644 index 0000000000..a7fbc639bd --- /dev/null +++ b/src/modules/PlayerbotV2/HireHooks.h @@ -0,0 +1,109 @@ +// HireHooks - the one place the bot module asks about hired bots. The bot module (`.bot add`, `.bot call`, the Group Finder, +// companion upkeep, gear, the add-on) never calls the hired bots directly: it asks Hiring(), and without a hire module that answers +// "no hired bots here" for everything, so bots are free as before. +// +// The hire module in Hire/ (CMake option PLAYERBOT_V2_HIRE, on by default) installs its HireHooks at script load +// (AddSC_playerbot_v2_hire). Another hire module can do the same: derive from HireHooks, override what it needs and call +// SetHireHooks once from its AddSC function. Only one is in charge; the last one set wins. +// +// Threads: Hiring() may be called from any thread. Every call that changes a Player or money is world thread only (marked below). + +#pragma once + +#include "HireTypes.h" +#include "Bot/BotTypes.h" +#include "Optional.h" +#include +#include + +class ChatHandler; +class Player; + +namespace Playerbot::V2::Fleet { + +class HireHooks +{ +public: + virtual ~HireHooks() = default; + + // True when a hire module is built in (the default hooks answer false). + virtual bool Built() const { return false; } + + // Loads the hire records; called once when the bot services start (after the owner registry). + virtual void LoadFromDb() { } + + // The realm's hire mode (Playerbot.Hire.Mode); Off without a hire module. + virtual Hire::Mode ConfigMode() const { return Hire::Mode::Off; } + + // Whether `player` must hire companions instead of making them (hired mode on for them, no GM bypass). + virtual bool MustHire(Player const* /*player*/) const { return false; } + // The same for the account owning a bot, its owner offline. + virtual bool MustHireAccount(uint32 /*account_id*/) const { return false; } + + // Group Finder / dungeon finder bots of a player who must hire are lent, not hired: free while they stay in that group. + virtual void SetLoaned(BotId /*bot*/, uint32 /*now_ms*/) { } + virtual bool IsLoaned(BotId /*bot*/) const { return false; } + // A loan bot old enough to be taken back when it is out of its group. + virtual bool LoanSettled(BotId /*bot*/, uint32 /*now_ms*/) const { return false; } + virtual std::vector LoanedBots() const { return {}; } + + // A companion that was just called by an add is not picked again for the next place while it logs in. + virtual void NoteCalled(BotId /*bot*/, uint32 /*now_ms*/) { } + virtual bool RecentlyCalled(BotId /*bot*/, uint32 /*now_ms*/) const { return false; } + + // Whether a broker that hires out `grade` stands near `player`. World thread. + virtual bool BrokerNear(Player* /*player*/, Hire::Grade /*grade*/) const { return false; } + + // Before a bot of `grade` is made for `me`: a broker near, the price at the player's level, the account's limits and the money. + // True with `price` set, or false with `why` for the player. Nothing is paid yet. World thread. + virtual bool CheckHire(Player* /*me*/, Hire::Grade /*grade*/, uint64& price, std::string& why) const + { + price = 0; + why = "There are no hired bots on this server."; + return false; + } + // The bot `bot` (named `bot_name`, a `class_name`) was made for `me` after CheckHire: take the money and keep the contract. + // Called before its setup, so its first gear is its grade's. World thread. + virtual void OnHired(Player* /*me*/, BotId /*bot*/, Hire::Grade /*grade*/, uint64 /*price*/, std::string const& /*bot_name*/, + std::string const& /*class_name*/) { } + // What the player is told when a hired bot is on the way. + virtual std::string SignOnText(std::string const& bot_name, Hire::Grade /*grade*/, uint64 /*price*/) const + { + return bot_name + " is on the way."; + } + + // A companion of `owner` is being called: takes the day's upkeep when it is due. False (and `why`) when the owner cannot pay; + // the bot then stays home. World thread. + virtual bool TakeUpkeep(Player* /*owner*/, BotId /*bot*/, std::string const& /*bot_name*/, std::string& /*why*/) { return true; } + + // The bot is deleted: its contract ends with it. + virtual void Forget(BotId /*bot*/) { } + + // Gives a hired bot its grade's health on top of what its class, level and gear give it. World thread. + virtual void ApplyHealth(Player* /*bot*/) { } + + // The gear mode (Gear::Owned::GearMode value) a companion wears under hired mode; -1 = the owner's own choice stands. + virtual int GearModeOverride(BotId /*bot*/, uint32 /*owner_account*/) const { return -1; } + + // `.bot hire [on|off]`. World thread. + virtual bool HandleCommand(ChatHandler* handler, Optional word); +}; + +// The hooks in charge: the hire module's, or the default ones (no hired bots). +HireHooks& Hiring(); +// Puts `hooks` in charge (nullptr = back to the default). The object must live until shutdown. Call it from an AddSC function. +void SetHireHooks(HireHooks* hooks); + +} // namespace Playerbot::V2::Fleet + +namespace Playerbot::V2 { + +// What a hire module may call in the bot module (cs_playerbot_v2.cpp). +// Makes one companion of `cls` and `grade` for `owner` through `.bot add`'s path (room checks, race, name, setup, login), after +// CheckHire and with OnHired; `msg` is what the owner is told. World thread. +bool HireCompanionForOwner(Player* owner, uint8 cls, Playerbot::Role role, Fleet::Hire::Grade grade, std::string const& className, + std::string& msg); +// Whether a race of the owner's faction can be a companion of class `cls` on this realm. +bool CanHaveCompanionClass(Player const* owner, uint8 cls); + +} // namespace Playerbot::V2 diff --git a/src/modules/PlayerbotV2/HireTypes.h b/src/modules/PlayerbotV2/HireTypes.h new file mode 100644 index 0000000000..63b04e2a7f --- /dev/null +++ b/src/modules/PlayerbotV2/HireTypes.h @@ -0,0 +1,16 @@ +// HireTypes - the words the bot module and the hired bots share (grades and the realm's hire mode). No game types here, so the +// policy tests and any other hire module can use them. The hired bots themselves live in Hire/ (see Hire/README.md). + +#pragma once + +#include + +namespace Playerbot::V2::Fleet::Hire { + +enum class Grade : uint8_t { None = 0, Sellsword = 1, Veteran = 2, Legend = 3 }; +constexpr uint8_t kGradeCount = 4; + +// Playerbot.Hire.Mode: 0 off (bots are free, as before), 1 hired bots for everyone, 2 each player chooses (`.bot hire on|off`). +enum class Mode : uint8_t { Off = 0, Everyone = 1, PlayerChoice = 2 }; + +} // namespace Playerbot::V2::Fleet::Hire diff --git a/src/modules/PlayerbotV2/INSTALL.md b/src/modules/PlayerbotV2/INSTALL.md index 7781d1fd73..8950331674 100644 --- a/src/modules/PlayerbotV2/INSTALL.md +++ b/src/modules/PlayerbotV2/INSTALL.md @@ -40,6 +40,10 @@ Without it `TRINITY_PLAYERBOT_V2` is undefined and the build fails in called unconditionally but declared only under that macro. If you see `error C3861: 'IsBot': identifier not found`, this flag is why. +Hired bots (the sellsword brokers at the inns, `Playerbot.Hire.*`) are built in +with the module. `-DPLAYERBOT_V2_HIRE=0` leaves them out; companions are then +always free. What they are and how to set them up: `Hire/README.md`. + ## 2. Install TrinityCore normally Create and populate `auth`, `characters` and `world` exactly as upstream diff --git a/src/modules/PlayerbotV2/LfgBotFill.cpp b/src/modules/PlayerbotV2/LfgBotFill.cpp index cec6666f3b..e26d43aa8e 100644 --- a/src/modules/PlayerbotV2/LfgBotFill.cpp +++ b/src/modules/PlayerbotV2/LfgBotFill.cpp @@ -19,6 +19,7 @@ #include "Bot/BotArchetype.h" #include "Bot/BotRegistry.h" #include "Fleet/BotGroupBuilder.h" +#include "HireHooks.h" #include "Fleet/InstanceGroupCap.h" #include "Fleet/OwnerRegistry.h" #include "GroupFinderListings.h" @@ -513,7 +514,10 @@ namespace for (GroupReference const& ref : group->GetMembers()) if (Player const* member = ref.GetSource(); member && member != human && !IsHuman(member)) { - Playerbot::Services::Owners().SetOwner(member->GetGUID().GetCounter(), human->GetSession()->GetAccountId(), 0); + // In hired mode (Playerbot.Hire.*) the group's bots play with the player but are nobody's to keep: they stay world bots, + // ordered as group members, so joining a listed group never becomes a free hire. + if (!Fleet::Hiring().MustHire(human)) + Playerbot::Services::Owners().SetOwner(member->GetGUID().GetCounter(), human->GetSession()->GetAccountId(), 0); ++bots; } TC_LOG_INFO("playerbot.v2", "[lfg] {} joined the listed bot group of {}: {} bot(s) are now their companions", human->GetName(), diff --git a/src/modules/PlayerbotV2/LfgBotFill.h b/src/modules/PlayerbotV2/LfgBotFill.h index 8bcc69ec69..f515027a70 100644 --- a/src/modules/PlayerbotV2/LfgBotFill.h +++ b/src/modules/PlayerbotV2/LfgBotFill.h @@ -33,7 +33,7 @@ bool LfgBotGroupCanTake(Player* member, Player* applicant); // A member (the leader) of a listed bot group that `applicant` (a player without a group) could join, for the dungeon on `map` // (0 = any) and about his level; nullptr when none. A channel LFG line is answered from it (Bot/ChannelChat.cpp). Player* LfgBotGroupMemberFor(Player* applicant, uint32 map); -// Creates one companion for the owner (shared with `.bot add`). +// Creates one companion for the owner (shared with `.bot add`). In hired mode it is a finder loan bot (HireHooks::SetLoaned). bool AddCompanionForOwner(Player* owner, uint8 cls, Playerbot::Role role, std::string& msg); // Fills the leader's group up to `size` now with level-matched companions (`.bot lfg` and the dungeon finder). `gap` is what was // missing; returns the bots started, `report` says why any could not be. diff --git a/src/modules/PlayerbotV2/PlayerbotV2Scripts.cpp b/src/modules/PlayerbotV2/PlayerbotV2Scripts.cpp index 43704c5ec8..26a5188f3c 100644 --- a/src/modules/PlayerbotV2/PlayerbotV2Scripts.cpp +++ b/src/modules/PlayerbotV2/PlayerbotV2Scripts.cpp @@ -39,6 +39,11 @@ #include void AddSC_playerbot_v2_commandscript(); +#ifdef PLAYERBOT_V2_HIRE +void AddSC_playerbot_v2_hire(); // Hire/HireModule.cpp: hired bots and their brokers (CMake PLAYERBOT_V2_HIRE) +#else +void AddSC_playerbot_v2_hire_off(); // HireHooks.cpp: the brokers say there are no hired bots here +#endif void AddSC_playerbot_v2_selftest_commandscript(); namespace @@ -581,6 +586,11 @@ void AddSC_playerbot_v2() new playerbot_v2_group(); new playerbot_v2_guild(); AddSC_playerbot_v2_commandscript(); +#ifdef PLAYERBOT_V2_HIRE + AddSC_playerbot_v2_hire(); +#else + AddSC_playerbot_v2_hire_off(); +#endif AddSC_playerbot_v2_selftest_commandscript(); PathGenerator::SetLiquidRouteCheck(&BotPathTouchesAvoidedLiquid); diff --git a/src/modules/PlayerbotV2/Services.cpp b/src/modules/PlayerbotV2/Services.cpp index eac4bcdb96..db3680ac91 100644 --- a/src/modules/PlayerbotV2/Services.cpp +++ b/src/modules/PlayerbotV2/Services.cpp @@ -254,6 +254,7 @@ std::unique_ptr MakeEmpyreanDomainArenaScript(); #include "Threading/TickScheduler.h" #include "Util/ConfigReader.h" #include "Diagnostics/PerfCounters.h" +#include "HireHooks.h" #include "Config.h" // sConfigMgr->GetFilename for resolving playerbot.conf next to worldserver.conf #include #include @@ -342,6 +343,8 @@ void Init() // also reads, so safe to load right after. h->owners = std::make_unique(); h->owners->LoadFromDb(); + // Hired bots (Playerbot.Hire.*, the Hire/ module when built in): grades, prices paid and upkeep, from the same character table. + V2::Fleet::Hiring().LoadFromDb(); // Dungeon script registry — pure in-memory, populated by // factories defined in Bot/Dungeon/Scripts/*.cpp. Empty registry // is fine — script-less dungeons fall back to generic logic. diff --git a/src/modules/PlayerbotV2/Session/AddonControl.cpp b/src/modules/PlayerbotV2/Session/AddonControl.cpp index 2969357ff5..8317aeaa0a 100644 --- a/src/modules/PlayerbotV2/Session/AddonControl.cpp +++ b/src/modules/PlayerbotV2/Session/AddonControl.cpp @@ -13,6 +13,7 @@ #include "Fleet/BotIdentityRegistry.h" #include "Fleet/BotPopulationManager.h" #include "Fleet/BotSize.h" +#include "HireHooks.h" #include "LfgBotFill.h" #include "Services.h" #include "Session/BotSessionMgr.h" @@ -891,6 +892,24 @@ void HandlePopReq(uint32 client_seq, WorldSession* sess, std::vector| +// ---------------------------------------------------------------------------- +void HandleHireReq(uint32 client_seq, WorldSession* sess) +{ + Player* me = sess ? sess->GetPlayer() : nullptr; + if (!me || !Services::Initialized()) + { + SendFields(sess, client_seq, "HIRE_RESP", {"0", "0"}); + return; + } + V2::Fleet::HireHooks const& hire = V2::Fleet::Hiring(); + bool const must = hire.MustHire(me); + SendFields(sess, client_seq, "HIRE_RESP", { must ? "1" : "0", std::to_string(uint32(hire.ConfigMode())) }); +} + // ---------------------------------------------------------------------------- // PLACE_REQ - the ForeverBots Positions tab: chosen bots stand in a shape at a spot // and stay there (BotCommandParser::PlaceBots, Bot/Placement.h). @@ -1683,6 +1702,10 @@ void DispatchAssembled(WorldSession* sess, uint32 seq, { HandlePopReq(seq, sess, fields); } + else if (mtype == "HIRE_REQ") + { + HandleHireReq(seq, sess); + } else if (mtype == "PLACE_REQ") { HandlePlaceReq(seq, sess, fields); @@ -1798,6 +1821,7 @@ bool OnAddonWhisper(Player* sender, Player* /*receiver*/, && mtype != "POP_REQ" && mtype != "BOT_TRADE_VIEW" && mtype != "BOT_TRADE_ACCEPT" + && mtype != "HIRE_REQ" && mtype != "ASSIGN_REQ") return false; } diff --git a/src/modules/PlayerbotV2/conf/playerbot.conf.dist b/src/modules/PlayerbotV2/conf/playerbot.conf.dist index f995e66fe9..1d70e6ab6d 100644 --- a/src/modules/PlayerbotV2/conf/playerbot.conf.dist +++ b/src/modules/PlayerbotV2/conf/playerbot.conf.dist @@ -847,6 +847,64 @@ Playerbot.Gear.Owned.OwnerSlack = 6 # The choice is kept per owner account (table playerbot_v2_owner_gear). World and battleground bots # ignore it. Example for a server that keeps raid tiers to be earned: AllowedModes = "match,best" Playerbot.OwnedGear.AllowedModes = "" + +# Hired bots: the Hire/ part of the module (src/modules/PlayerbotV2/Hire/README.md). Built in by default; a build with +# -DPLAYERBOT_V2_HIRE=0 leaves it out, these lines then do nothing and bots are always free. +# Playerbot.Hire.Mode hired bots (an idea from Neylem): 0 = off (default; .bot add, Quick party and the Group finder make bots for +# free), 1 = on for everyone, 2 = each player chooses (`.bot hire on|off`, the add-on's Settings, or a broker's +# gossip). With hired bots on, nothing is made out of nothing: a companion you already have that is not out +# comes instead (the same role, the same class first), and standing next to a broker a Sellsword is hired for +# you. Brokers: a Sellsword Captain at the inns and in the capitals (Sellsword: your level, normal companion +# gear), a Veteran Recruiter in the capitals (Veteran: level cap only, raid gear up to Playerbot.Gear.MaxTier +# whatever you wear), a Black Market Broker in Gadgetzan, Booty Bay and Ratchet (Legend: level cap only, best +# in slot). Bots you owned before hired mode came on count as Sellswords with no upkeep. World bots are not +# affected, and a listed Group finder group you join plays with you without becoming yours. +# Hired bots only (Karrz 2026-11-03): with it on the ForeverBots add-on hides its "Add a bot" buttons (the server +# says so in HIRE_RESP). The Group finder and the dungeon finder (`.bot lfg`, `.bot dungeon`, a posted listing) +# still fill the group for free, but those bots are only lent: they cannot be called on their own and are +# deleted once they leave that group. +# Playerbot.Hire.GmBypass 1 = a GM account (security above player) makes bots for free as before. Default 0 (since 0.1.29: on a +# local realm the player's own account is a GM, and hired bots only must hold for them too). +# Playerbot.Hire.BrokerRange yards from a broker in which `.bot add` and Quick party hire. Default 15. +# Playerbot.Hire..PartyPrice / RaidPrice copper, at the level cap: what the 4 bots of a 5-man / the 39 bots of a 40-man cost +# together. One bot costs the party price / 4, or the raid price / 39 in a raid group or an instance for +# more than 5. A Sellsword below the cap costs (level / cap)^2 of that, never under 1 silver. +# Defaults: Sellsword 1g / 20g, Veteran 3g / 60g, Legend 5g / 100g. +# Playerbot.Hire.UpkeepPct a hired bot's wages: this share of what was paid for it, once for each day it is called (a day it stays +# home costs nothing). A bot whose owner cannot pay stays home. 0 = no upkeep. Default 25. +# Playerbot.Hire.MaxPerAccount the most bots one account may own while it hires (0 = no limit). Default 0. +# Playerbot.Hire.Legend.MaxPerAccount the most Legends one account may hire (0 = no limit). Default 0. +# Playerbot.Hire..Gear the gear a hired bot of that grade wears: match (normal gear for its level, up to your own), +# best (raid gear up to Playerbot.Gear.MaxTier), bis (best in slot), t1 / t2 / t3 (that tier set). +# The raid modes only work at the level cap; below it the bot wears match. +# Defaults: Sellsword match, Veteran best, Legend bis. +# Playerbot.Hire..HealthPct a hired bot's health, in percent of what its class, level and gear give it (25 to 1000). +# Default 100 (normal health) for every grade. +# Playerbot.Hire..Sells the grades each kind of broker sells: Inn (the Sellsword Captains at the inns), Capital (the +# Veteran Recruiters in the capitals), BlackMarket (Gadgetzan, Booty Bay, Ratchet). A list of +# sellsword, veteran, legend; "none" = sells nothing. Defaults: Inn "sellsword", Capital +# "sellsword, veteran", BlackMarket "legend". Veterans and Legends still only sign on at the level cap. +Playerbot.Hire.Mode = 0 +Playerbot.Hire.GmBypass = 0 +Playerbot.Hire.BrokerRange = 15 +Playerbot.Hire.Sellsword.PartyPrice = 10000 +Playerbot.Hire.Sellsword.RaidPrice = 200000 +Playerbot.Hire.Veteran.PartyPrice = 30000 +Playerbot.Hire.Veteran.RaidPrice = 600000 +Playerbot.Hire.Legend.PartyPrice = 50000 +Playerbot.Hire.Legend.RaidPrice = 1000000 +Playerbot.Hire.UpkeepPct = 25 +Playerbot.Hire.MaxPerAccount = 0 +Playerbot.Hire.Legend.MaxPerAccount = 0 +Playerbot.Hire.Sellsword.Gear = "match" +Playerbot.Hire.Veteran.Gear = "best" +Playerbot.Hire.Legend.Gear = "bis" +Playerbot.Hire.Sellsword.HealthPct = 100 +Playerbot.Hire.Veteran.HealthPct = 100 +Playerbot.Hire.Legend.HealthPct = 100 +Playerbot.Hire.Inn.Sells = "sellsword" +Playerbot.Hire.Capital.Sells = "sellsword, veteran" +Playerbot.Hire.BlackMarket.Sells = "legend" # Scenario.DummyEntry the creature the damage_parity scenarios hit (`.playerbot scenario run damage_parity_`, finisher_sweep_, # talent_audit_): a creature_template entry that can be attacked and does nothing; the runner makes it level 63, # 3731 armor, 2 billion health. 0 (default): the first "Training Dummy" / "Target Dummy" template without a script. diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6a9947834f..888b1ef512 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -37,6 +37,7 @@ if(NOT BUILD_PLAYERBOT_V2) ClassicGuildAskText.cpp ClassicBotLocale.cpp ClassicCompanionLeash.cpp + ClassicHirePolicy.cpp ClassicMeleeReach.cpp ClassicFalseCombatEscape.cpp ClassicFollowDrop.cpp diff --git a/tests/game/ClassicHirePolicy.cpp b/tests/game/ClassicHirePolicy.cpp new file mode 100644 index 0000000000..1e0400ee73 --- /dev/null +++ b/tests/game/ClassicHirePolicy.cpp @@ -0,0 +1,153 @@ +/* + * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include "tc_catch2.h" + +#include "../../src/modules/PlayerbotV2/Hire/HirePolicy.h" + +using namespace Playerbot::V2::Fleet::Hire; + +// Karrz 2026-10-29: a complete legendary 40-man costs 100g, a legendary 5-man 5g, a blue (Veteran) 5-man 3g. +TEST_CASE("Package prices add up to what the server owner set", "[ClassicHirePolicy]") +{ + Prices const p; + CHECK(PriceFor(p, Grade::Legend, 60, 60, true) * kRaidPlaces <= 1000000); + CHECK(PriceFor(p, Grade::Legend, 60, 60, true) * kRaidPlaces > 1000000 - kRaidPlaces); + CHECK(PriceFor(p, Grade::Legend, 60, 60, false) * kPartyPlaces == 50000); + CHECK(PriceFor(p, Grade::Veteran, 60, 60, false) * kPartyPlaces == 30000); + CHECK(PriceFor(p, Grade::Sellsword, 60, 60, false) * kPartyPlaces == 10000); +} + +TEST_CASE("A Sellsword below the cap costs less, never under a silver", "[ClassicHirePolicy]") +{ + Prices const p; + uint64_t const at60 = PriceFor(p, Grade::Sellsword, 60, 60, false); + uint64_t const at40 = PriceFor(p, Grade::Sellsword, 40, 60, false); + uint64_t const at20 = PriceFor(p, Grade::Sellsword, 20, 60, false); + CHECK(at40 < at60); + CHECK(at20 < at40); + CHECK(at20 == 277); // 2500 x 400 / 3600 + CHECK(PriceFor(p, Grade::Sellsword, 1, 60, false) == kMinPriceCopper); +} + +TEST_CASE("Veterans and Legends are for the level cap only", "[ClassicHirePolicy]") +{ + Prices const p; + CHECK(PriceFor(p, Grade::Veteran, 59, 60, false) == 0); + CHECK(PriceFor(p, Grade::Legend, 15, 60, true) == 0); + CHECK(PriceFor(p, Grade::None, 60, 60, false) == 0); + CHECK(GradeForLevel(Grade::Sellsword, 1, 60)); +} + +TEST_CASE("Brokers sell their own grades", "[ClassicHirePolicy]") +{ + CHECK(BrokerOfEntry(6110000) == Broker::Inn); + CHECK(BrokerOfEntry(6110105) == Broker::Capital); + CHECK(BrokerOfEntry(6110202) == Broker::BlackMarket); + CHECK(BrokerOfEntry(6110300) == Broker::None); + CHECK(BrokerOfEntry(295) == Broker::None); + CHECK(BrokerSells(Broker::Inn, Grade::Sellsword)); + CHECK_FALSE(BrokerSells(Broker::Inn, Grade::Veteran)); + CHECK(BrokerSells(Broker::Capital, Grade::Veteran)); + CHECK_FALSE(BrokerSells(Broker::Capital, Grade::Legend)); + CHECK(BrokerSells(Broker::BlackMarket, Grade::Legend)); + CHECK_FALSE(BrokerSells(Broker::BlackMarket, Grade::Sellsword)); +} + +TEST_CASE("Upkeep is a quarter of the price, only on a day the bot is called", "[ClassicHirePolicy]") +{ + Prices const p; + CHECK(UpkeepFor(p, 25000) == 6250); + CHECK(UpkeepFor(p, 0) == 0); // owned before hired mode: free + CHECK(UpkeepFor(p, 200) == kMinPriceCopper); + Prices off; + off.upkeep_pct = 0; + CHECK(UpkeepFor(off, 25000) == 0); + CHECK_FALSE(UpkeepDue(0, 1000)); + CHECK_FALSE(UpkeepDue(2000, 1999)); + CHECK(UpkeepDue(2000, 2000)); +} + +TEST_CASE("Who must hire", "[ClassicHirePolicy]") +{ + CHECK_FALSE(Required(Mode::Off, true, false, true)); + CHECK(Required(Mode::Everyone, false, false, true)); + CHECK_FALSE(Required(Mode::Everyone, false, true, true)); // a GM testing + CHECK(Required(Mode::Everyone, false, true, false)); + CHECK(Required(Mode::PlayerChoice, true, false, true)); + CHECK_FALSE(Required(Mode::PlayerChoice, false, false, true)); +} + +TEST_CASE("The grade sets the gear", "[ClassicHirePolicy]") +{ + CHECK(GearModeFor(Grade::Legend, true) == 5); + CHECK(GearModeFor(Grade::Veteran, false) == 1); + CHECK(GearModeFor(Grade::Sellsword, false) == 0); + CHECK(GearModeFor(Grade::None, true) == 0); + CHECK(GearModeFor(Grade::None, false) == -1); +} + +TEST_CASE("Default rules are the built-in ones", "[ClassicHirePolicy]") +{ + Rules const r; + for (Broker b : { Broker::Inn, Broker::Capital, Broker::BlackMarket, Broker::None }) + for (Grade g : { Grade::None, Grade::Sellsword, Grade::Veteran, Grade::Legend }) + CHECK(BrokerSells(r, b, g) == BrokerSells(b, g)); + for (Grade g : { Grade::None, Grade::Sellsword, Grade::Veteran, Grade::Legend }) + for (bool must : { false, true }) + CHECK(GearModeFor(r, g, must) == GearModeFor(g, must)); + CHECK(HealthPctFor(r, Grade::Legend) == 100); + CHECK(HealthBonusFor(4000, 100) == 0); +} + +TEST_CASE("The server owner sets what brokers sell, gear and health", "[ClassicHirePolicy]") +{ + CHECK(ParseGradeList("sellsword, veteran") == ((1u << 1) | (1u << 2))); + CHECK(ParseGradeList("Legend") == (1u << 3)); + CHECK(ParseGradeList("legends sellswords") == ((1u << 1) | (1u << 3))); + CHECK(ParseGradeList("none") == 0); + CHECK(ParseGradeList("") == 0); + CHECK(ParseGradeList("dragon") == 0); + + Rules r; + r.sells[uint8_t(Broker::Inn)] = ParseGradeList("sellsword, legend"); + CHECK(BrokerSells(r, Broker::Inn, Grade::Legend)); + CHECK_FALSE(BrokerSells(r, Broker::Inn, Grade::Veteran)); + CHECK_FALSE(BrokerSells(r, Broker::None, Grade::Legend)); + + r.gear_mode[uint8_t(Grade::Veteran)] = 3; // t2 + CHECK(GearModeFor(r, Grade::Veteran, false) == 3); + CHECK(GearModeFor(r, Grade::None, false) == -1); + CHECK(GearModeFor(r, Grade::None, true) == 0); + + r.health_pct[uint8_t(Grade::Legend)] = 150; + CHECK(HealthPctFor(r, Grade::Legend) == 150); + CHECK(HealthBonusFor(4000, 150) == 2000); + CHECK(HealthBonusFor(4000, 50) == -2000); + CHECK(HealthBonusFor(4000, 1) == -3000); // never under kMinHealthPct (25%) + r.health_pct[uint8_t(Grade::Legend)] = 99999; + CHECK(HealthPctFor(r, Grade::Legend) == kMaxHealthPct); + CHECK(HealthPctFor(r, Grade::None) == 100); +} + +TEST_CASE("Money reads like the game's", "[ClassicHirePolicy]") +{ + CHECK(MoneyText(12500) == "1g 25s"); + CHECK(MoneyText(7500) == "75s"); + CHECK(MoneyText(1250) == "12s 50c"); + CHECK(MoneyText(0) == "0c"); +}