aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMeji <alvaromegias_46@hotmail.com>2021-11-25 20:56:37 +0100
committerGitHub <noreply@github.com>2021-11-25 20:56:37 +0100
commitb02f382ed78b784d547c68cdbbb681148708d7d0 (patch)
treeab0409ead450f7261d4b21f81ae2df126f5f2698 /src
parent93c668ac50a529876054212dfef6544f70259035 (diff)
Core/Trainers: Implemented learning battle pets from trainers (#27312)
Diffstat (limited to 'src')
-rw-r--r--src/server/game/Entities/Creature/Trainer.cpp38
1 files changed, 35 insertions, 3 deletions
diff --git a/src/server/game/Entities/Creature/Trainer.cpp b/src/server/game/Entities/Creature/Trainer.cpp
index 73aab6e4151..c30ce80787d 100644
--- a/src/server/game/Entities/Creature/Trainer.cpp
+++ b/src/server/game/Entities/Creature/Trainer.cpp
@@ -16,11 +16,13 @@
*/
#include "Trainer.h"
+#include "BattlePetMgr.h"
#include "Creature.h"
#include "NPCPackets.h"
#include "Player.h"
#include "SpellInfo.h"
#include "SpellMgr.h"
+#include "WorldSession.h"
namespace Trainer
{
@@ -72,6 +74,19 @@ namespace Trainer
return;
}
+ bool sendSpellVisual = true;
+ BattlePetSpeciesEntry const* speciesEntry = sSpellMgr->GetBattlePetSpecies(trainerSpell->SpellId);
+ if (speciesEntry)
+ {
+ if (player->GetSession()->GetBattlePetMgr()->HasMaxPetCount(speciesEntry))
+ {
+ // Don't send any error to client (intended)
+ return;
+ }
+
+ sendSpellVisual = false;
+ }
+
float reputationDiscount = player->GetReputationPriceDiscount(npc);
int64 moneyCost = int64(trainerSpell->MoneyCost * reputationDiscount);
if (!player->HasEnoughMoney(moneyCost))
@@ -82,14 +97,31 @@ namespace Trainer
player->ModifyMoney(-moneyCost);
- npc->SendPlaySpellVisualKit(179, 0, 0); // 53 SpellCastDirected
- player->SendPlaySpellVisualKit(362, 1, 0); // 113 EmoteSalute
+ if (sendSpellVisual)
+ {
+ npc->SendPlaySpellVisualKit(179, 0, 0); // 53 SpellCastDirected
+ player->SendPlaySpellVisualKit(362, 1, 0); // 113 EmoteSalute
+ }
// learn explicitly or cast explicitly
if (trainerSpell->IsCastable())
+ {
player->CastSpell(player, trainerSpell->SpellId, true);
+ }
else
- player->LearnSpell(trainerSpell->SpellId, false);
+ {
+ bool dependent = false;
+
+ if (speciesEntry)
+ {
+ player->GetSession()->GetBattlePetMgr()->AddPet(speciesEntry->ID, BattlePetMgr::SelectPetDisplay(speciesEntry), BattlePetMgr::RollPetBreed(speciesEntry->ID), BattlePetMgr::GetDefaultPetQuality(speciesEntry->ID));
+ // If the spell summons a battle pet, we fake that it has been learned and the battle pet is added
+ // marking as dependent prevents saving the spell to database (intended)
+ dependent = true;
+ }
+
+ player->LearnSpell(trainerSpell->SpellId, dependent);
+ }
}
Spell const* Trainer::GetSpell(uint32 spellId) const