Files
OldThink/Content.Server/Speech/EntitySystems/MeleeSpeechSystem.cs

77 lines
1.8 KiB
C#
Raw Normal View History

2023-05-23 11:12:30 -07:00
using Content.Server.Administration.Logs;
using Content.Shared.Speech.Components;
using Content.Shared.Speech.EntitySystems;
2023-05-23 11:12:30 -07:00
using Content.Shared.Database;
namespace Content.Server.Speech.EntitySystems;
public sealed class MeleeSpeechSystem : SharedMeleeSpeechSystem
{
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<MeleeSpeechComponent, MeleeSpeechBattlecryChangedMessage>(OnBattlecryChanged);
}
private void OnBattlecryChanged(EntityUid uid, MeleeSpeechComponent comp, MeleeSpeechBattlecryChangedMessage args)
{
if (!TryComp<MeleeSpeechComponent>(uid, out var meleeSpeechUser))
2023-05-23 11:12:30 -07:00
return;
string battlecry = args.Battlecry;
if (battlecry.Length > comp.MaxBattlecryLength)
battlecry = battlecry[..comp.MaxBattlecryLength];
TryChangeBattlecry(uid, battlecry, meleeSpeechUser);
2023-05-23 11:12:30 -07:00
}
/// <summary>
/// Attempts to change the battlecry of an entity.
/// Returns true/false.
/// </summary>
/// <remarks>
/// If provided with a player's EntityUid to the player parameter, adds the change to the admin logs.
/// </remarks>
public bool TryChangeBattlecry(EntityUid uid, string? battlecry, MeleeSpeechComponent? meleeSpeechComp = null)
{
if (!Resolve(uid, ref meleeSpeechComp))
2023-05-23 11:12:30 -07:00
return false;
if (!string.IsNullOrWhiteSpace(battlecry))
{
battlecry = battlecry.Trim();
2023-05-23 11:12:30 -07:00
}
else
{
battlecry = null;
}
if (meleeSpeechComp.Battlecry == battlecry)
return true;
2023-05-23 11:12:30 -07:00
meleeSpeechComp.Battlecry = battlecry;
Dirty(meleeSpeechComp);
_adminLogger.Add(LogType.ItemConfigure, LogImpact.Medium, $" {ToPrettyString(uid):entity}'s battlecry has been changed to {battlecry}");
return true;
}
}