TrinityCore
Trainer.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef Trainer_h__
19#define Trainer_h__
20
21#include "Common.h"
22#include <array>
23#include <string>
24#include <vector>
25
26class Creature;
27class ObjectMgr;
28class Player;
29
30namespace Trainer
31{
32 enum class Type : uint32
33 {
34 None = 0,
35 Talent = 1,
36 Tradeskill = 2,
37 Pet = 3,
38 };
39
40 enum class SpellState : uint8
41 {
42 Known = 0,
43 Available = 1,
44 Unavailable = 2
45 };
46
47 enum class FailReason : uint32
48 {
49 Unavailable = 0,
51 };
52
53 struct Spell
54 {
59 std::array<uint32, 3> ReqAbility = { };
61
62 bool IsCastable() const;
63 };
64
65 class Trainer
66 {
67 public:
68 Trainer(uint32 id, Type type, std::string_view greeting, std::vector<Spell> spells);
69
70 void SendSpells(Creature const* npc, Player* player, LocaleConstant locale) const;
71 void TeachSpell(Creature const* npc, Player* player, uint32 spellId) const;
72
73 private:
74 Spell const* GetSpell(uint32 spellId) const;
75 bool CanTeachSpell(Player const* player, Spell const* trainerSpell) const;
76 SpellState GetSpellState(Player const* player, Spell const* trainerSpell) const;
77 void SendTeachFailure(Creature const* npc, Player const* player, uint32 spellId, FailReason reason) const;
78 std::string const& GetGreeting(LocaleConstant locale) const;
79
80 friend ObjectMgr;
81 void AddGreetingLocale(LocaleConstant locale, std::string_view greeting);
82
85 std::vector<Spell> _spells;
86 std::array<std::string, TOTAL_LOCALES> _greeting;
87 };
88}
89
90#endif // Trainer_h__
LocaleConstant
Definition: Common.h:48
uint8_t uint8
Definition: Define.h:144
uint32_t uint32
Definition: Define.h:142
Definition: Pet.h:40
std::vector< Spell > _spells
Definition: Trainer.h:85
uint32 _id
Definition: Trainer.h:83
friend ObjectMgr
Definition: Trainer.h:80
std::array< std::string, TOTAL_LOCALES > _greeting
Definition: Trainer.h:86
SpellState
Definition: Trainer.h:41
FailReason
Definition: Trainer.h:48
uint32 ReqSkillLine
Definition: Trainer.h:57
std::array< uint32, 3 > ReqAbility
Definition: Trainer.h:59
uint8 ReqLevel
Definition: Trainer.h:60
bool IsCastable() const
Definition: Trainer.cpp:31
uint32 ReqSkillRank
Definition: Trainer.h:58
uint32 SpellId
Definition: Trainer.h:55
uint32 MoneyCost
Definition: Trainer.h:56