Bots: no riding and no mounts below level 40 (#98)
Reason: bots made by earlier builds, or taught by a retail trainer pass, could hold riding skill and mounts below level 40, and riding 150 at levels 40 to 59. Why: vanilla gives riding at level 40 (75, the normal mount) and at 60 (150, the swift mount); the rule was spread over the setup code and the login correction. Fix: Bot/World/RidingTier.h is the one rule (none below 40, 75 from 40, 150 from 60). Setup uses it, and the login correction removes the riding skill and every mount spell from a bot under level 40 (vanilla realm only). Unit test in tests/game/ClassicRidingTier.cpp.
This commit is contained in:
@@ -71,6 +71,8 @@
|
||||
#include "GossipDef.h"
|
||||
#include "QuestDef.h"
|
||||
#include "ObjectMgr.h"
|
||||
#include "Bot/ClassTables.h" // IsVanillaRealm()
|
||||
#include "Bot/World/RidingTier.h"
|
||||
#include "DB2Stores.h"
|
||||
#include "ReputationMgr.h"
|
||||
#include "LFGMgr.h"
|
||||
@@ -9383,9 +9385,35 @@ bool API::RaceMountSpells(uint8 race, uint32& normal, uint32& swift)
|
||||
|
||||
uint32 API::learn_riding_free()
|
||||
{
|
||||
if (!p_ || p_->GetLevel() < 40) return 0;
|
||||
if (!p_) return 0;
|
||||
uint32 changed = 0;
|
||||
uint16 const target = p_->GetLevel() >= 60 ? 150 : 75;
|
||||
::Playerbot::V2::World::RidingFix const fix = ::Playerbot::V2::World::PlanRiding(p_->GetLevel(), p_->GetSkillValue(SKILL_RIDING));
|
||||
// Below level 40 a bot has no riding and no mount (a bot of an earlier build, or a retail trainer pass, may have both).
|
||||
if (fix.strip_mounts)
|
||||
{
|
||||
if (!::Playerbot::IsVanillaRealm())
|
||||
return 0;
|
||||
auto isMountSpell = [](SpellInfo const* info) { return info && info->HasAura(SPELL_AURA_MOUNTED); };
|
||||
std::vector<uint32> doomed;
|
||||
for (auto const& [spellId, spell] : p_->GetSpellMap())
|
||||
if (spell.state != PLAYERSPELL_REMOVED && (isMountSpell(sSpellMgr->GetSpellInfo(spellId, DIFFICULTY_NONE)) ||
|
||||
spellId == 33388u || spellId == 33391u || spellId == 34090u || spellId == 34091u || spellId == 90265u)) // Apprentice to Master Riding
|
||||
doomed.push_back(spellId);
|
||||
if (!doomed.empty())
|
||||
p_->RemoveAurasByType(SPELL_AURA_MOUNTED);
|
||||
for (uint32 spellId : doomed)
|
||||
{
|
||||
p_->RemoveSpell(spellId, false, false);
|
||||
++changed;
|
||||
}
|
||||
if (p_->HasSkill(SKILL_RIDING))
|
||||
{
|
||||
p_->SetSkill(SKILL_RIDING, 0, 0, 0);
|
||||
++changed;
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
uint16 const target = fix.skill;
|
||||
// A bot a retail trainer pass raised past its level's tier (Journeyman at 40) goes back to the vanilla tier, tier spells included.
|
||||
if (p_->GetSkillValue(SKILL_RIDING) > target)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
// Vanilla riding for a bot, in one place: no riding below level 40, Apprentice (skill 75 and the race's normal mount) from 40, Journeyman (150 and the
|
||||
// swift mount) from 60. The realm's own data agrees (trainer spell 33388 needs level 40, 33391 level 60). Pure: tested in tests/game/ClassicRidingTier.cpp.
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace Playerbot::V2::World {
|
||||
|
||||
constexpr std::uint8_t kApprenticeRidingLevel = 40;
|
||||
constexpr std::uint8_t kJourneymanRidingLevel = 60;
|
||||
|
||||
constexpr std::uint16_t RidingSkillForLevel(std::uint8_t level)
|
||||
{
|
||||
return level >= kJourneymanRidingLevel ? 150 : level >= kApprenticeRidingLevel ? 75 : 0;
|
||||
}
|
||||
|
||||
// What a bot of `level` that holds riding `skill` needs: the skill target (0 = no riding at all), and whether its mounts and riding spells go.
|
||||
struct RidingFix
|
||||
{
|
||||
std::uint16_t skill = 0; // the skill the bot should hold
|
||||
bool set_skill = false; // its skill differs from `skill` (raise it, lower it, or remove it at 0)
|
||||
bool strip_mounts = false; // below 40: every mount spell and riding tier spell goes
|
||||
};
|
||||
|
||||
constexpr RidingFix PlanRiding(std::uint8_t level, std::uint16_t skill)
|
||||
{
|
||||
RidingFix fix;
|
||||
fix.skill = RidingSkillForLevel(level);
|
||||
fix.set_skill = skill != fix.skill;
|
||||
fix.strip_mounts = fix.skill == 0;
|
||||
return fix;
|
||||
}
|
||||
|
||||
} // namespace Playerbot::V2::World
|
||||
@@ -718,25 +718,9 @@ bool BotSetupPipeline::DoLearnProfessions(Player* bot)
|
||||
|
||||
bool BotSetupPipeline::DoAcquireMount(Player* bot)
|
||||
{
|
||||
// Classic 1.60: vanilla riding is level 40 (Apprentice, 60% mount) and 60
|
||||
// (Journeyman, 100% epic mount). The retail tiers below would hand a L20
|
||||
// bot Apprentice Riding and a L60 bot Expert flying. learn_riding_free
|
||||
// sets the riding skill and teaches the race's vanilla mount (what
|
||||
// `.bot add` companions and the gear backfill use); below 40 it does
|
||||
// nothing. Hunters still get their pet below.
|
||||
bool const vanilla = ::Playerbot::IsVanillaRealm();
|
||||
if (vanilla)
|
||||
::Playerbot::API(bot).learn_riding_free();
|
||||
else if (bot->GetLevel() < 20)
|
||||
return true; // gated
|
||||
|
||||
// Train the riding *skill* (Apprentice / Journeyman / Expert / Artisan /
|
||||
// Master) at the level-appropriate tier. This is a skill, not a racial
|
||||
// mount spell — the spell IDs are documented Blizzard skill-tier IDs
|
||||
// that have been stable across many patches.
|
||||
uint32 riding_spell = vanilla ? 0 : World::RidingSpellForLevel(bot->GetLevel());
|
||||
if (riding_spell && !bot->HasSpell(riding_spell))
|
||||
bot->LearnSpell(riding_spell, false);
|
||||
// Riding has one rule (Bot/World/RidingTier.h): none below 40, Apprentice (75, the race's normal mount) from 40, Journeyman (150, the swift mount)
|
||||
// from 60. learn_riding_free applies it, and takes it away again from a bot that holds more than its level allows.
|
||||
::Playerbot::API(bot).learn_riding_free();
|
||||
|
||||
// We intentionally do NOT pre-grant the racial mount via LearnSpell.
|
||||
// Racial mount spell IDs drift across patches and were previously
|
||||
|
||||
@@ -2762,6 +2762,15 @@ void Module::OnPlayerLogin(Player* p)
|
||||
// Bots taught by an earlier build can carry other classes' trainer spells (a rogue with Judgement): drop them at login.
|
||||
if (uint32 const removed = ::Playerbot::API(p).purge_foreign_class_spells())
|
||||
TC_LOG_INFO("playerbot.v2", "[levelup] {} lost {} spells of other classes at login", p->GetName(), removed);
|
||||
// Vanilla riding (Bot/World/RidingTier.h): none below 40, 75 and a normal mount from 40, 150 and the swift mount from 60. A bot made by an earlier build can hold
|
||||
// more (150 at 40-59, riding and mounts under 40): one correction at login. The call changes nothing for a bot that is already right, so it is one-shot by itself.
|
||||
if (::Playerbot::IsVanillaRealm())
|
||||
{
|
||||
uint32 const riding_before = p->GetSkillValue(SKILL_RIDING);
|
||||
if (uint32 const changed = ::Playerbot::API(p).learn_riding_free())
|
||||
TC_LOG_INFO("playerbot.v2", "[riding] {} L{} corrected at login: skill {} -> {}, {} change(s)", p->GetName(), uint32(p->GetLevel()), riding_before,
|
||||
uint32(p->GetSkillValue(SKILL_RIDING)), changed);
|
||||
}
|
||||
// INFO-level so the operator can see which bots actually attached bot logic
|
||||
// when bringing up a fresh worldserver / spawning via .playerbot login.
|
||||
// The DEBUG history can be inspected via /history or /inspect later.
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "tc_catch2.h"
|
||||
|
||||
#include "../../src/modules/PlayerbotV2/Bot/World/RidingTier.h"
|
||||
|
||||
using namespace Playerbot::V2::World;
|
||||
|
||||
TEST_CASE("Riding skill by level: none below 40, 75 from 40, 150 from 60", "[ClassicRidingTier]")
|
||||
{
|
||||
CHECK(RidingSkillForLevel(1) == 0);
|
||||
CHECK(RidingSkillForLevel(29) == 0);
|
||||
CHECK(RidingSkillForLevel(39) == 0);
|
||||
CHECK(RidingSkillForLevel(40) == 75);
|
||||
CHECK(RidingSkillForLevel(59) == 75);
|
||||
CHECK(RidingSkillForLevel(60) == 150);
|
||||
}
|
||||
|
||||
TEST_CASE("A bot under level 40 loses its riding skill and its mounts", "[ClassicRidingTier]")
|
||||
{
|
||||
RidingFix const had150 = PlanRiding(29, 150); // Radoslaw: level 29, riding 150/150
|
||||
CHECK(had150.skill == 0);
|
||||
CHECK(had150.set_skill);
|
||||
CHECK(had150.strip_mounts);
|
||||
RidingFix const had75 = PlanRiding(15, 75);
|
||||
CHECK(had75.set_skill);
|
||||
CHECK(had75.strip_mounts);
|
||||
RidingFix const none = PlanRiding(15, 0); // nothing to change
|
||||
CHECK_FALSE(none.set_skill);
|
||||
CHECK(none.strip_mounts); // still no mounts below 40
|
||||
}
|
||||
|
||||
TEST_CASE("A bot at level 40-59 goes from 150 to 75 and keeps its mounts", "[ClassicRidingTier]")
|
||||
{
|
||||
RidingFix const fix = PlanRiding(45, 150);
|
||||
CHECK(fix.skill == 75);
|
||||
CHECK(fix.set_skill);
|
||||
CHECK_FALSE(fix.strip_mounts);
|
||||
CHECK_FALSE(PlanRiding(45, 75).set_skill);
|
||||
CHECK(PlanRiding(40, 0).skill == 75); // a new 40 gets the skill
|
||||
CHECK(PlanRiding(40, 0).set_skill);
|
||||
CHECK_FALSE(PlanRiding(60, 150).set_skill);
|
||||
}
|
||||
Reference in New Issue
Block a user