TrinityCore
Loading...
Searching...
No Matches
ChatTextBuilder.cpp
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#include "ChatTextBuilder.h"
19#include "ChatPackets.h"
20#include "ObjectMgr.h"
21#include <cstdarg>
22
24{
25 BroadcastTextEntry const* bct = sObjectMgr->GetBroadcastText(_textId);
27 chat.Initialize(_msgType, bct ? Language(bct->LanguageID) : LANG_UNIVERSAL, _source, _target, bct ? bct->GetText(locale, _gender) : "", _achievementId, "", locale);
28 chat.Write();
29
30 *data = chat.Move();
31
32 return chat.TargetGUIDPos;
33}
34
36{
38 chat.Initialize(_msgType, _language, _source, _target, _text, 0, "", locale);
39 chat.Write();
40
41 data = chat.Move();
42}
43
45{
46 char const* text = sObjectMgr->GetTrinityString(_textId, locale);
47
49 chat.Initialize(_msgType, LANG_UNIVERSAL, _source, _target, "", 0, "", locale);
50
51 if (_args)
52 {
53 // we need copy va_list before use or original va_list will corrupted
54 va_list ap;
55 va_copy(ap, *_args);
56
57 static size_t const BufferSize = 2048;
58 char strBuffer[BufferSize];
59 vsnprintf(strBuffer, BufferSize, text, ap);
60 va_end(ap);
61
62 chat.ChatText = strBuffer;
63 }
64 else
65 chat.ChatText = text;
66
67 chat.Write();
68
69 data = chat.Move();
70}
LocaleConstant
Definition Common.h:48
#define sObjectMgr
Definition ObjectMgr.h:1721
Language
@ LANG_UNIVERSAL
size_t operator()(WorldPacket &data, LocaleConstant locale) const
void operator()(WorldPacket &data, LocaleConstant locale) const
void operator()(WorldPacket &data, LocaleConstant locale) const
void Initialize(ChatMsg chatType, Language language, WorldObject const *sender, WorldObject const *receiver, std::string_view message, uint32 achievementId=0, std::string_view channelName="", LocaleConstant locale=DEFAULT_LOCALE, std::string_view addonPrefix="")
WorldPacket const * Write() override
WorldPacket && Move()
Definition Packet.h:53
std::string const & GetText(LocaleConstant locale=DEFAULT_LOCALE, uint8 gender=GENDER_MALE, bool forceGender=false) const
Definition ObjectMgr.h:490