Core/Grids: Move packet sending functionality out of MessageDistDeliverer and into separate, customizable class and unify LocalizedPacketDo, LocalizedPacketListDo as generic localizable action
Port From (https://github.com/TrinityCore/TrinityCore/commit/fb66575d38d2ba7ffc24c29824fa75d7019de549)
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
using Framework.Constants;
|
||||
using Game.DataStorage;
|
||||
using Game.Entities;
|
||||
using Game.Maps;
|
||||
using Game.Networking;
|
||||
using Game.Networking.Packets;
|
||||
using System.Collections.Generic;
|
||||
@@ -26,8 +27,7 @@ namespace Game.Chat
|
||||
{
|
||||
public class MessageBuilder
|
||||
{
|
||||
public virtual ServerPacket Invoke(Locale locale = Locale.enUS) { return null; }
|
||||
public virtual void Invoke(List<ServerPacket> data, Locale locale = Locale.enUS) { }
|
||||
public virtual dynamic Invoke(Locale locale = Locale.enUS) { return default; }
|
||||
}
|
||||
|
||||
public class BroadcastTextBuilder : MessageBuilder
|
||||
@@ -42,12 +42,12 @@ namespace Game.Chat
|
||||
_achievementId = achievementId;
|
||||
}
|
||||
|
||||
public override ServerPacket Invoke(Locale locale)
|
||||
public override PacketSenderOwning<ChatPkt> Invoke(Locale locale = Locale.enUS)
|
||||
{
|
||||
BroadcastTextRecord bct = CliDB.BroadcastTextStorage.LookupByKey(_textId);
|
||||
var packet = new ChatPkt();
|
||||
packet.Initialize(_msgType, bct != null ? (Language)bct.LanguageID : Language.Universal, _source, _target, bct != null ? Global.DB2Mgr.GetBroadcastTextValue(bct, locale, _gender) : "", _achievementId, "", locale);
|
||||
return packet;
|
||||
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;
|
||||
@@ -69,11 +69,11 @@ namespace Game.Chat
|
||||
_target = target;
|
||||
}
|
||||
|
||||
public override ServerPacket Invoke(Locale locale)
|
||||
public override PacketSenderOwning<ChatPkt> Invoke(Locale locale)
|
||||
{
|
||||
var packet = new ChatPkt();
|
||||
packet.Initialize(_msgType, _language, _source, _target, _text, 0, "", locale);
|
||||
return packet;
|
||||
var chat = new PacketSenderOwning<ChatPkt>();
|
||||
chat.Data.Initialize(_msgType, _language, _source, _target, _text, 0, "", locale);
|
||||
return chat;
|
||||
}
|
||||
|
||||
WorldObject _source;
|
||||
@@ -94,18 +94,18 @@ namespace Game.Chat
|
||||
_args = args;
|
||||
}
|
||||
|
||||
public override ServerPacket Invoke(Locale locale)
|
||||
public override PacketSenderOwning<ChatPkt> Invoke(Locale locale)
|
||||
{
|
||||
ChatPkt packet = new();
|
||||
PacketSenderOwning<ChatPkt> chat = new();
|
||||
|
||||
string text = Global.ObjectMgr.GetCypherString(_textId, locale);
|
||||
|
||||
if (_args != null)
|
||||
packet.Initialize(_msgType, Language.Universal, _source, _target, string.Format(text, _args), 0, "", locale);
|
||||
chat.Data.Initialize(_msgType, Language.Universal, _source, _target, string.Format(text, _args), 0, "", locale);
|
||||
else
|
||||
packet.Initialize(_msgType, Language.Universal, _source, _target, text, 0, "", locale);
|
||||
chat.Data.Initialize(_msgType, Language.Universal, _source, _target, text, 0, "", locale);
|
||||
|
||||
return packet;
|
||||
return chat;
|
||||
}
|
||||
|
||||
WorldObject _source;
|
||||
|
||||
@@ -596,32 +596,33 @@ namespace Game
|
||||
public void Invoke(Player player)
|
||||
{
|
||||
Locale loc_idx = player.GetSession().GetSessionDbLocaleIndex();
|
||||
ServerPacket messageTemplate;
|
||||
PacketSenderOwning<ChatPkt> sender;
|
||||
|
||||
// create if not cached yet
|
||||
if (!_packetCache.ContainsKey(loc_idx))
|
||||
{
|
||||
messageTemplate = _builder.Invoke(loc_idx);
|
||||
_packetCache[loc_idx] = messageTemplate;
|
||||
sender = _builder.Invoke(loc_idx);
|
||||
_packetCache[loc_idx] = sender;
|
||||
}
|
||||
else
|
||||
messageTemplate = _packetCache[loc_idx];
|
||||
sender = _packetCache[loc_idx];
|
||||
|
||||
ChatPkt message = (ChatPkt)messageTemplate;
|
||||
switch (_msgType)
|
||||
{
|
||||
case ChatMsg.MonsterWhisper:
|
||||
case ChatMsg.RaidBossWhisper:
|
||||
ChatPkt message = sender.Data;
|
||||
message.SetReceiver(player, loc_idx);
|
||||
player.SendPacket(message);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
player.SendPacket(message);
|
||||
sender.Invoke(player);
|
||||
}
|
||||
|
||||
Dictionary<Locale, ServerPacket> _packetCache = new();
|
||||
Dictionary<Locale, PacketSenderOwning<ChatPkt>> _packetCache = new();
|
||||
MessageBuilder _builder;
|
||||
ChatMsg _msgType;
|
||||
}
|
||||
@@ -639,12 +640,12 @@ namespace Game
|
||||
_target = target;
|
||||
}
|
||||
|
||||
public override ServerPacket Invoke(Locale locale = Locale.enUS)
|
||||
public override PacketSenderOwning<ChatPkt> Invoke(Locale locale = Locale.enUS)
|
||||
{
|
||||
string text = Global.CreatureTextMgr.GetLocalizedChatString(_source.GetEntry(), _gender, _textGroup, _textId, locale);
|
||||
var packet = new ChatPkt();
|
||||
packet.Initialize(_msgType, _language, _source, _target, text, 0, "", locale);
|
||||
return packet;
|
||||
PacketSenderOwning<ChatPkt> chat = new();
|
||||
chat.Data.Initialize(_msgType, _language, _source, _target, text, 0, "", locale);
|
||||
return chat;
|
||||
}
|
||||
|
||||
WorldObject _source;
|
||||
@@ -670,12 +671,12 @@ namespace Game
|
||||
_target = target;
|
||||
}
|
||||
|
||||
public override ServerPacket Invoke(Locale loc_idx = Locale.enUS)
|
||||
public override PacketSenderOwning<ChatPkt> Invoke(Locale loc_idx = Locale.enUS)
|
||||
{
|
||||
string text = Global.CreatureTextMgr.GetLocalizedChatString(_source.GetEntry(), _gender, _textGroup, _textId, loc_idx);
|
||||
var packet = new ChatPkt();
|
||||
packet.Initialize(_msgType, _language, _talker, _target, text, 0, "", loc_idx);
|
||||
return packet;
|
||||
PacketSenderOwning<ChatPkt> chat = new();
|
||||
chat.Data.Initialize(_msgType, _language, _talker, _target, text, 0, "", loc_idx);
|
||||
return chat;
|
||||
}
|
||||
|
||||
WorldObject _source;
|
||||
|
||||
Reference in New Issue
Block a user