aaa3964d49
Port From (https://github.com/TrinityCore/TrinityCore/commit/fb66575d38d2ba7ffc24c29824fa75d7019de549)
118 lines
3.9 KiB
C#
118 lines
3.9 KiB
C#
/*
|
|
* Copyright (C) 2012-2020 CypherCore <http://github.com/CypherCore>
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
using Framework.Constants;
|
|
using Game.DataStorage;
|
|
using Game.Entities;
|
|
using Game.Maps;
|
|
using Game.Networking;
|
|
using Game.Networking.Packets;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Game.Chat
|
|
{
|
|
public class MessageBuilder
|
|
{
|
|
public virtual dynamic Invoke(Locale locale = Locale.enUS) { return default; }
|
|
}
|
|
|
|
public class BroadcastTextBuilder : MessageBuilder
|
|
{
|
|
public BroadcastTextBuilder(WorldObject obj, ChatMsg msgtype, uint textId, Gender gender, WorldObject target = null, uint achievementId = 0)
|
|
{
|
|
_source = obj;
|
|
_msgType = msgtype;
|
|
_textId = textId;
|
|
_gender = gender;
|
|
_target = target;
|
|
_achievementId = achievementId;
|
|
}
|
|
|
|
public override PacketSenderOwning<ChatPkt> Invoke(Locale locale = Locale.enUS)
|
|
{
|
|
BroadcastTextRecord bct = CliDB.BroadcastTextStorage.LookupByKey(_textId);
|
|
var chat = new PacketSenderOwning<ChatPkt>();
|
|
chat.Data.Initialize(_msgType, bct != null ? (Language)bct.LanguageID : Language.Universal, _source, _target, bct != null ? Global.DB2Mgr.GetBroadcastTextValue(bct, locale, _gender) : "", _achievementId, "", locale);
|
|
return chat;
|
|
}
|
|
|
|
WorldObject _source;
|
|
ChatMsg _msgType;
|
|
uint _textId;
|
|
Gender _gender;
|
|
WorldObject _target;
|
|
uint _achievementId;
|
|
}
|
|
|
|
public class CustomChatTextBuilder : MessageBuilder
|
|
{
|
|
public CustomChatTextBuilder(WorldObject obj, ChatMsg msgType, string text, Language language = Language.Universal, WorldObject target = null)
|
|
{
|
|
_source = obj;
|
|
_msgType = msgType;
|
|
_text = text;
|
|
_language = language;
|
|
_target = target;
|
|
}
|
|
|
|
public override PacketSenderOwning<ChatPkt> Invoke(Locale locale)
|
|
{
|
|
var chat = new PacketSenderOwning<ChatPkt>();
|
|
chat.Data.Initialize(_msgType, _language, _source, _target, _text, 0, "", locale);
|
|
return chat;
|
|
}
|
|
|
|
WorldObject _source;
|
|
ChatMsg _msgType;
|
|
string _text;
|
|
Language _language;
|
|
WorldObject _target;
|
|
}
|
|
|
|
class CypherStringChatBuilder : MessageBuilder
|
|
{
|
|
public CypherStringChatBuilder(WorldObject obj, ChatMsg msgType, CypherStrings textId, WorldObject target = null, object[] args = null)
|
|
{
|
|
_source = obj;
|
|
_msgType = msgType;
|
|
_textId = textId;
|
|
_target = target;
|
|
_args = args;
|
|
}
|
|
|
|
public override PacketSenderOwning<ChatPkt> Invoke(Locale locale)
|
|
{
|
|
PacketSenderOwning<ChatPkt> chat = new();
|
|
|
|
string text = Global.ObjectMgr.GetCypherString(_textId, locale);
|
|
|
|
if (_args != null)
|
|
chat.Data.Initialize(_msgType, Language.Universal, _source, _target, string.Format(text, _args), 0, "", locale);
|
|
else
|
|
chat.Data.Initialize(_msgType, Language.Universal, _source, _target, text, 0, "", locale);
|
|
|
|
return chat;
|
|
}
|
|
|
|
WorldObject _source;
|
|
ChatMsg _msgType;
|
|
CypherStrings _textId;
|
|
WorldObject _target;
|
|
object[] _args;
|
|
}
|
|
}
|