Files
tbd-station-14/Content.Server/GameTicking/Rules/KillCalloutRuleSystem.cs
Nemanja 161fd6c83c Mega Antag Refactor (#25786)
* Mega Antag Refactor

* last minute delta save

* more workshopping

* more shit

* ok tested this for once

* okkkkk sure

* generic delays for starting rules

* well darn

* nukies partially

* ouagh

* ballin' faded and smonkin wed

* obliterated the diff

* Spread my arms and soak up congratulations

* I've got plenty of love, but nothing to show for it

* but there’s too much sunlight
Shining on my laptop monitor, so I
Can’t see anything with any amount of clarity

* ok this junk

* OOK!

* fubar

* most of sloth's review

* oh boy

* eek

* hell yea!

* ASDFJASDJFvsakcvjkzjnhhhyh
2024-04-25 11:31:45 +10:00

101 lines
3.6 KiB
C#

using Content.Server.Chat.Managers;
using Content.Server.GameTicking.Components;
using Content.Server.GameTicking.Rules.Components;
using Content.Server.KillTracking;
using Content.Shared.Chat;
using Robust.Server.Player;
using Robust.Shared.Player;
using Robust.Shared.Random;
namespace Content.Server.GameTicking.Rules;
/// <summary>
/// This handles calling out kills from <see cref="KillTrackingSystem"/>
/// </summary>
public sealed class KillCalloutRuleSystem : GameRuleSystem<KillCalloutRuleComponent>
{
[Dependency] private readonly IChatManager _chatManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IRobustRandom _random = default!;
/// <inheritdoc/>
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<KillReportedEvent>(OnKillReported);
}
private void OnKillReported(ref KillReportedEvent ev)
{
var query = EntityQueryEnumerator<KillCalloutRuleComponent, GameRuleComponent>();
while (query.MoveNext(out var uid, out var kill, out var rule))
{
if (!GameTicker.IsGameRuleActive(uid, rule))
continue;
var callout = GetCallout(kill, ev);
_chatManager.ChatMessageToAll(ChatChannel.Server, callout, callout, uid, false, true, Color.OrangeRed);
}
}
private string GetCallout(KillCalloutRuleComponent component, KillReportedEvent ev)
{
// Do the humiliation callouts if you kill yourself or die from bleeding out or something lame.
if (ev.Primary is KillEnvironmentSource || ev.Suicide)
{
var selfCallout = $"{component.SelfKillCalloutPrefix}{_random.Next(component.SelfKillCalloutAmount)}";
return Loc.GetString(selfCallout,
("victim", GetCalloutName(ev.Entity)));
}
var primary = GetCalloutName(ev.Primary);
var killerString = primary;
if (ev.Assist != null)
{
var secondary = GetCalloutName(ev.Assist);
killerString = Loc.GetString("death-match-assist",
("primary", primary), ("secondary", secondary));
}
var callout = $"{component.KillCalloutPrefix}{_random.Next(component.KillCalloutAmount)}";
return Loc.GetString(callout, ("killer", killerString),
("victim", GetCalloutName(ev.Entity)));
}
private string GetCalloutName(KillSource source)
{
switch (source)
{
case KillPlayerSource player:
if (!_playerManager.TryGetSessionById(player.PlayerId, out var session))
break;
if (session.AttachedEntity == null)
break;
return Loc.GetString("death-match-name-player",
("name", MetaData(session.AttachedEntity.Value).EntityName),
("username", session.Name));
case KillNpcSource npc:
if (Deleted(npc.NpcEnt))
return string.Empty;
return Loc.GetString("death-match-name-npc", ("name", MetaData(npc.NpcEnt).EntityName));
}
return string.Empty;
}
private string GetCalloutName(EntityUid source)
{
if (TryComp<ActorComponent>(source, out var actorComp))
{
return Loc.GetString("death-match-name-player",
("name", MetaData(source).EntityName),
("username", actorComp.PlayerSession.Name));
}
return Loc.GetString("death-match-name-npc", ("name", MetaData(source).EntityName));
}
}