2 using Microsoft.Xna.Framework;
41 private static readonly
string dateTimeFormatLongTimePattern = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern;
45 new Color(190, 198, 205),
46 new Color(204, 74, 78),
47 new Color(136, 177, 255),
48 new Color(157, 225, 160),
49 new Color(238, 208, 0),
50 new Color(64, 240, 89),
51 new Color(255, 255, 255),
52 new Color(255, 255, 255),
53 new Color(255, 128, 0)
58 private string translatedText;
65 if (translatedText.IsNullOrEmpty())
67 translatedText = TextManager.Get(
Text).Fallback(
Text).Value;
70 return translatedText;
74 if (translatedText.IsNullOrEmpty())
76 translatedText = TextManager.GetServerMessage(
Text).Value;
79 return translatedText;
98 private Color? customTextColor =
null;
105 return (Color)customTextColor;
107 set { customTextColor = value; }
112 return $
"[{DateTime.Now.ToString(dateTimeFormatLongTimePattern)}] ";
144 customTextColor = textColor;
149 return new ChatMessage(senderName, text, type, sender, client ??
GameMain.
NetworkMember?.ConnectedClients?.Find(c => c.Character !=
null && c.Character == sender), changeType, textColor);
154 messageWithoutCommand = message;
156 int separatorIndex = message.IndexOf(
";");
157 if (separatorIndex == -1)
return "";
164 command = message.Substring(0, separatorIndex);
165 command = command.Trim();
173 messageWithoutCommand = message.Substring(separatorIndex + 1, message.Length - separatorIndex - 1).TrimStart();
184 if (listener ==
null || sender ==
null)
191 if (dist > range) {
return 1.0f; }
195 if (sourceHull != listenerHull && obstructionMultiplier >= 1.0f)
197 if ((sourceHull ==
null || !sourceHull.
GetConnectedHulls(includingThis:
false, searchDepth: 2, ignoreClosedGaps:
true).Contains(listenerHull)) &&
200 dist = (dist + 100f) * obstructionMultiplier;
203 if (dist > range) {
return 1.0f; }
222 if (garbleAmount < 0.3f)
return text;
223 if (garbleAmount >= 1.0f)
return "";
225 int startIndex = Math.Max(text.IndexOf(
':') + 1, 1);
227 StringBuilder sb =
new StringBuilder(text.Length);
228 for (
int i = 0; i < text.Length; i++)
230 sb.Append((i > startIndex && Rand.Range(0.0f, 1.0f) < garbleAmount) ?
'-' : text[i]);
233 return sb.ToString();
238 if (sender ==
null) {
return ""; }
249 if (receiver !=
null && !receiver.
IsDead)
266 var receiverRadio = receiverItem.GetComponent<
WifiComponent>();
268 if (!receiverRadio.CanReceive(senderRadio)) {
continue; }
270 string msg =
ApplyDistanceEffect(receiverItem, senderItem, message, senderRadio.Range, obstructionMultiplier: 0);
291 Encoding.UTF8.GetBytes(
Text).Length + 2;
306 foreach (
Item item
in sender.Inventory.AllItems)
309 if (wifiComponent ==
null || !wifiComponent.LinkToChat || !wifiComponent.CanTransmit(ignoreJamming) || !sender.HasEquippedItem(item)) {
continue; }
310 if (radio ==
null || wifiComponent.Range > radio.Range)
312 radio = wifiComponent;
315 return radio?.
Item !=
null;
bool HasEquippedItem(Item item, InvSlotType? slotType=null, Func< InvSlotType, bool > predicate=null)
CharacterInventory Inventory
virtual Vector2 WorldPosition
virtual Vector2 SimPosition
static NetworkMember NetworkMember
static Hull FindHull(Vector2 position, Hull guess=null, bool useWorldCoordinates=true, bool inclusive=true)
Returns the hull which contains the point (or null if it isn't inside any)
IEnumerable< Hull > GetConnectedHulls(bool includingThis, int? searchDepth=null, bool ignoreClosedGaps=false)
virtual IEnumerable< Item > AllItems
All items contained in the inventory. Stacked items are returned as individual instances....
int EstimateLengthBytesClient()
static string ApplyDistanceEffect(string text, float garbleAmount)
string ApplyDistanceEffect(Character listener)
ChatMessage(string senderName, string text, ChatMessageType type, Entity sender, Client client, PlayerConnectionChangeType changeType=PlayerConnectionChangeType.None, Color? textColor=null)
static string GetChatMessageCommand(string message, out string messageWithoutCommand)
static string ApplyDistanceEffect(string message, ChatMessageType type, Character sender, Character receiver)
const int MaxMessagesPerPacket
static bool CanUseRadio(Character sender, out WifiComponent radio, bool ignoreJamming=false)
const float SpeakRangeVOIP
This is shorter than the text chat speak range, because the voice chat is still intelligible (just qu...
static Color[] MessageColor
static ChatMessage Create(string senderName, string text, ChatMessageType type, Entity sender, Client client=null, PlayerConnectionChangeType changeType=PlayerConnectionChangeType.None, Color? textColor=null)
readonly string SenderName
static string GetTimeStamp()
PlayerConnectionChangeType ChangeType
static string ApplyDistanceEffect(Entity listener, Entity sender, string text, float range, float obstructionMultiplier=2.0f)
static float GetGarbleAmount(Entity listener, Entity sender, float range, float obstructionMultiplier=2.0f)
How much messages sent by sender should get garbled. Takes the distance between the entities and opt...
readonly Client SenderClient
Character SenderCharacter
static bool CanUseRadio(Character sender, bool ignoreJamming=false)
static Body CheckVisibility(Vector2 rayStart, Vector2 rayEnd, bool ignoreLevel=false, bool ignoreSubs=false, bool ignoreSensors=true, bool ignoreDisabledWalls=true, bool ignoreBranches=true, Predicate< Fixture > blocksVisibilityPredicate=null)
Check visibility between two points (in sim units).
PlayerConnectionChangeType