From 6d24db6999960bef57877abb893c4be63992c836 Mon Sep 17 00:00:00 2001 From: EricksOliveira Date: Sun, 27 Apr 2025 07:50:48 -0300 Subject: [PATCH] =?UTF-8?q?Introduction=20of=20the=20SafeLearn(spellId)=20?= =?UTF-8?q?lambda=20that=20checks=20if=20the=20bot=20=E2=80=A6=20(#1226)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Introduction of the SafeLearn(spellId) lambda that checks if the bot already knows the spell before learning it. This PR adds a safety check to the mount skill learning process in PlayerbotFactory::InitSkills, using a SafeLearn lambda to prevent the bot from trying to learn spells it already has. This fixes error messages like Duplicate entry when using the .bot init command. * Check the bank and avoid error * . * fix --- src/factory/PlayerbotFactory.cpp | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/factory/PlayerbotFactory.cpp b/src/factory/PlayerbotFactory.cpp index d8be6ff9..9152a4d0 100644 --- a/src/factory/PlayerbotFactory.cpp +++ b/src/factory/PlayerbotFactory.cpp @@ -2200,15 +2200,33 @@ void PlayerbotFactory::InitSkills() //uint32 maxValue = level * 5; //not used, line marked for removal. bot->UpdateSkillsForLevel(); - bot->SetSkill(SKILL_RIDING, 0, 0, 0); + auto SafeLearn = [this](uint32 spellId) + { + if (!bot->HasSpell(spellId)) + bot->learnSpell(spellId, false, true); // Avoid duplicate attempts in DB + }; + + // Define Riding skill according to level + if (bot->GetLevel() >= 70) + bot->SetSkill(SKILL_RIDING, 300, 300, 300); + else if (bot->GetLevel() >= 60) + bot->SetSkill(SKILL_RIDING, 225, 225, 225); + else if (bot->GetLevel() >= 40) + bot->SetSkill(SKILL_RIDING, 150, 150, 150); + else if (bot->GetLevel() >= 20) + bot->SetSkill(SKILL_RIDING, 75, 75, 75); + else + bot->SetSkill(SKILL_RIDING, 0, 0, 0); + + // Safe learning of mount spells if (bot->GetLevel() >= sPlayerbotAIConfig->useGroundMountAtMinLevel) - bot->learnSpell(33388); + SafeLearn(33388); // Apprentice if (bot->GetLevel() >= sPlayerbotAIConfig->useFastGroundMountAtMinLevel) - bot->learnSpell(33391); + SafeLearn(33391); // Journeyman if (bot->GetLevel() >= sPlayerbotAIConfig->useFlyMountAtMinLevel) - bot->learnSpell(34090); + SafeLearn(34090); // Expert if (bot->GetLevel() >= sPlayerbotAIConfig->useFastFlyMountAtMinLevel) - bot->learnSpell(34091); + SafeLearn(34091); // Artisan uint32 skillLevel = bot->GetLevel() < 40 ? 0 : 1; uint32 dualWieldLevel = bot->GetLevel() < 20 ? 0 : 1;