32 Trainer::Trainer(
uint32 trainerId,
Type type,
uint32 requirement, std::string greeting, std::vector<Spell> spells) : _trainerId(trainerId), _type(type), _requirement(requirement), _spells(
std::move(spells))
44 trainerList.
Greeting = GetGreeting(locale);
45 trainerList.
Spells.reserve(_spells.size());
46 for (
Spell const& trainerSpell : _spells)
53 bool primaryProfessionFirstRank =
false;
59 SpellInfo const* learnedSpellInfo =
sSpellMgr->GetSpellInfo(spellEffectInfo.TriggerSpell);
61 primaryProfessionFirstRank =
true;
64 trainerList.
Spells.emplace_back();
66 trainerListSpell.
SpellID = trainerSpell.SpellId;
68 trainerListSpell.
MoneyCost =
int32(trainerSpell.MoneyCost * reputationDiscount);
70 trainerListSpell.
PointCost[1] = (primaryProfessionFirstRank ? 1 : 0);
71 trainerListSpell.
ReqLevel = trainerSpell.ReqLevel;
72 trainerListSpell.
ReqSkillLine = trainerSpell.ReqSkillLine;
73 trainerListSpell.
ReqSkillRank = trainerSpell.ReqSkillRank;
74 std::copy(trainerSpell.ReqAbility.begin(), trainerSpell.ReqAbility.end(), trainerListSpell.
ReqAbility.begin());
82 if (!IsTrainerValidForPlayer(player))
85 Spell const* trainerSpell = GetSpell(spellId);
92 if (!CanTeachSpell(player, trainerSpell))
117 SendTeachSucceeded(npc, player, spellId);
122 auto itr = std::find_if(_spells.begin(), _spells.end(), [spellId](
Spell const& trainerSpell)
124 return trainerSpell.SpellId == spellId;
127 if (itr != _spells.end())
133 bool Trainer::CanTeachSpell(
Player const* player,
Spell const* trainerSpell)
const
135 SpellState state = GetSpellState(player, trainerSpell);
146 SpellInfo const* learnedSpellInfo =
sSpellMgr->GetSpellInfo(spellEffectInfo.TriggerSpell);
168 if (reqAbility && !player->
HasSpell(reqAbility))
176 bool hasLearnSpellEffect =
false;
177 bool knowsAllLearnedSpells =
true;
183 hasLearnSpellEffect =
true;
184 if (!player->
HasSpell(spellEffectInfo.TriggerSpell))
185 knowsAllLearnedSpells =
false;
187 if (
uint32 previousRankSpellId =
sSpellMgr->GetPrevSpellInChain(spellEffectInfo.TriggerSpell))
188 if (!player->
HasSpell(previousRankSpellId))
192 if (!hasLearnSpellEffect)
195 if (!player->
HasSpell(previousRankSpellId))
198 else if (knowsAllLearnedSpells)
202 for (
auto const& requirePair :
sSpellMgr->GetSpellsRequiredForSpellBounds(trainerSpell->
SpellId))
203 if (!player->
HasSpell(requirePair.second))
209 bool Trainer::IsTrainerValidForPlayer(
Player const* player)
const
211 if (!GetTrainerRequirement())
214 switch (GetTrainerType())
219 return player->
GetClass() == GetTrainerRequirement();
222 return player->
GetRace() == GetTrainerRequirement();
225 return player->
HasSpell(GetTrainerRequirement());
237 trainerBuyFailed.
SpellID = spellId;
246 trainerBuySucceeded.
SpellID = spellId;
252 if (_greeting[locale].empty())
255 return _greeting[locale];
260 _greeting[locale] = std::move(greeting);
@ SPELL_EFFECT_LEARN_SPELL
constexpr std::underlying_type< E >::type AsUnderlyingType(E enumValue)
static ObjectGuid GetGUID(Object const *o)
void LearnSpell(uint32 spell_id, bool dependent, uint32 fromSkill=0)
void SendDirectMessage(WorldPacket const *data) const
bool ModifyMoney(int32 amount, bool sendError=true)
bool IsSpellFitByClassAndRace(uint32 spell_id) const
float GetReputationPriceDiscount(Creature const *creature) const
bool HasEnoughMoney(uint32 amount) const
uint16 GetBaseSkillValue(uint32 skill) const
bool HasSpell(uint32 spell) const override
uint32 GetFreePrimaryProfessionPoints() const
bool IsPrimaryProfessionFirstRank() const
std::array< SpellEffectInfo, MAX_SPELL_EFFECTS > const & GetEffects() const
void SendPlaySpellVisualKit(uint32 id, uint32 type) const
SpellCastResult CastSpell(CastSpellTargetArg const &targets, uint32 spellId, CastSpellExtraArgs const &args={ })
int32 TrainerFailedReason
WorldPacket const * Write() override
WorldPacket const * Write() override
WorldPacket const * Write() override
std::vector< TrainerListSpell > Spells
std::array< uint32, 3 > ReqAbility
std::array< int32, 3 > ReqAbility
std::array< int32, 2 > PointCost