TrinityCore
CreatureTextMgr.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 TRINITY_CREATURE_TEXT_MGR_H
19#define TRINITY_CREATURE_TEXT_MGR_H
20
21#include "Common.h"
22#include "SharedDefines.h"
23#include <map>
24#include <unordered_map>
25#include <vector>
26
27class Creature;
28class Player;
29class Unit;
30class WorldObject;
31class WorldPacket;
32
34{
41};
42
44{
45 Normal = 0,
46 ObjectSound = 1,
47 Max = 2,
48};
49
51{
55 std::string text;
65};
66
68{
69 std::vector<std::string> Text;
70};
71
73{
75
76 friend std::strong_ordering operator<=>(CreatureTextId const& left, CreatureTextId const& right) = default;
77
81};
82
83typedef std::vector<CreatureTextEntry> CreatureTextGroup; // texts in a group
84typedef std::unordered_map<uint8, CreatureTextGroup> CreatureTextHolder; // groups for a creature by groupid
85typedef std::unordered_map<uint32, CreatureTextHolder> CreatureTextMap; // all creatures by entry
86
87typedef std::map<CreatureTextId, CreatureTextLocale> LocaleCreatureTextMap;
88
90{
91 private:
94
95 public:
98
101
102 static CreatureTextMgr* instance();
103
104 void LoadCreatureTexts();
105 void LoadCreatureTextLocales();
106 CreatureTextMap const& GetTextMap() const { return mTextMap; }
107
108 static void SendSound(Creature* source, uint32 sound, ChatMsg msgType, WorldObject const* whisperTarget = nullptr, CreatureTextRange range = TEXT_RANGE_NORMAL, Team team = TEAM_OTHER, bool gmOnly = false, uint32 keyBroadcastTextId = 0, SoundKitPlayType playType = SoundKitPlayType::Normal);
109 static void SendEmote(Unit* source, Emote emote);
110
111 //if sent, returns the 'duration' of the text else 0 if error
112 uint32 SendChat(Creature* source, uint8 textGroup, WorldObject const* whisperTarget = nullptr, ChatMsg msgType = CHAT_MSG_ADDON, Language language = LANG_ADDON, CreatureTextRange range = TEXT_RANGE_NORMAL, uint32 sound = 0, SoundKitPlayType playType = SoundKitPlayType::Normal, Team team = TEAM_OTHER, bool gmOnly = false, Player* srcPlr = nullptr);
113 bool TextExist(uint32 sourceEntry, uint8 textGroup) const;
114 std::string GetLocalizedChatString(uint32 entry, uint8 gender, uint8 textGroup, uint32 id, LocaleConstant locale) const;
115
116 template <class Builder>
117 static void SendChatPacket(WorldObject* source, Builder const& builder, ChatMsg msgType, WorldObject const* whisperTarget = nullptr, CreatureTextRange range = TEXT_RANGE_NORMAL, Team team = TEAM_OTHER, bool gmOnly = false);
118
119 static float GetRangeForChatType(ChatMsg msgType);
120
121 private:
122 static void SendNonChatPacket(WorldObject* source, WorldPacket const* data, ChatMsg msgType, WorldObject const* whisperTarget, CreatureTextRange range, Team team, bool gmOnly);
123
126};
127
128#define sCreatureTextMgr CreatureTextMgr::instance()
129
130#endif
LocaleConstant
Definition: Common.h:48
std::vector< CreatureTextEntry > CreatureTextGroup
std::unordered_map< uint8, CreatureTextGroup > CreatureTextHolder
SoundKitPlayType
std::map< CreatureTextId, CreatureTextLocale > LocaleCreatureTextMap
std::unordered_map< uint32, CreatureTextHolder > CreatureTextMap
CreatureTextRange
@ TEXT_RANGE_ZONE
@ TEXT_RANGE_AREA
@ TEXT_RANGE_WORLD
@ TEXT_RANGE_PERSONAL
@ TEXT_RANGE_NORMAL
@ TEXT_RANGE_MAP
#define TC_GAME_API
Definition: Define.h:123
uint8_t uint8
Definition: Define.h:144
uint32_t uint32
Definition: Define.h:142
Language
@ LANG_ADDON
Emote
Team
@ TEAM_OTHER
ChatMsg
@ CHAT_MSG_ADDON
LocaleCreatureTextMap mLocaleTextMap
CreatureTextMgr & operator=(CreatureTextMgr const &)=delete
CreatureTextMgr & operator=(CreatureTextMgr &&)=delete
CreatureTextMap const & GetTextMap() const
CreatureTextMgr(CreatureTextMgr const &)=delete
CreatureTextMap mTextMap
CreatureTextMgr(CreatureTextMgr &&)=delete
Definition: Unit.h:627
SoundKitPlayType SoundPlayType
CreatureTextRange TextRange
friend std::strong_ordering operator<=>(CreatureTextId const &left, CreatureTextId const &right)=default
CreatureTextId(uint32 e, uint32 g, uint32 i)
std::vector< std::string > Text