Player chat component. Stores a replicated chat string and timer, exposes helper properties for presence and owner name, and a Say method that validates, sets the chat and pushes an event log message to MansionGame.
using Sandbox;
namespace BrickJam;
public sealed partial class Player
{
/// <summary>Current chat line shown above this player's head; replicated from the owner.</summary>
[Sync] public string ChatMessage { get; set; }
[Sync] public TimeUntil ChatMessageTime { get; set; }
public bool HasChatMessage => !string.IsNullOrEmpty( ChatMessage ) && ChatMessageTime > 0f;
public string OwnerName => Network.Owner?.DisplayName ?? "player";
/// <summary>
/// Send a chat message. Called on the owning client; the synced <see cref="ChatMessage"/> drives
/// the speech bubble for everyone, and the line is broadcast to the event log. Replaces the legacy
/// <c>[ConCmd.Server] SendMessage</c> + <c>_sendMessage</c>/<c>_addEventlog</c> ClientRpcs.
/// </summary>
public void Say( string message )
{
if ( string.IsNullOrWhiteSpace( message ) || message.Length > 200 )
return;
ChatMessage = message;
ChatMessageTime = 6f;
MansionGame.Instance?.ShowEventlog( $"<gray>{OwnerName}</> said \"{message}\".", 15f );
}
}