Files
OldThink/Content.Server/_White/Other/ExamineSystem/ExamineSystem.cs

163 lines
5.7 KiB
C#
Raw Normal View History

using Content.Server.Access.Systems;
using Content.Shared.Access.Components;
using Content.Shared.Examine;
using Robust.Shared.Enums;
using Content.Shared.Humanoid;
using Content.Shared.IdentityManagement.Components;
using Content.Shared.Inventory;
using Content.Shared.PDA;
using Content.Shared._White;
using Robust.Server.GameObjects;
2023-08-29 19:29:13 +06:00
using Robust.Shared.Configuration;
using Robust.Shared.Console;
2024-01-23 08:43:11 +03:00
using Robust.Shared.Player;
namespace Content.Server._White.Other.ExamineSystem
{
//^.^
public sealed class ExamineSystem : EntitySystem
{
[Dependency] private readonly InventorySystem _inventorySystem = default!;
[Dependency] private readonly EntityManager _entityManager = default!;
[Dependency] private readonly IdCardSystem _idCard = default!;
[Dependency] private readonly IConsoleHost _consoleHost = default!;
2023-08-29 19:29:13 +06:00
[Dependency] private readonly INetConfigurationManager _netConfigManager = default!;
public override void Initialize()
{
SubscribeLocalEvent<ExaminableClothesComponent, ExaminedEvent>(HandleExamine);
}
private void SendNoticeMessage(ActorComponent actorComponent, string message)
2023-08-29 19:29:13 +06:00
{
var should = _netConfigManager.GetClientCVar(actorComponent.PlayerSession.ConnectedClient, WhiteCVars.LogChatActions);
if (should)
{
_consoleHost.RemoteExecuteCommand(actorComponent.PlayerSession, $"notice [font size=10][color=#aeabc4]{message}[/color][/font]");
2023-08-29 19:29:13 +06:00
}
}
private void HandleExamine(EntityUid uid, ExaminableClothesComponent comp, ExaminedEvent args)
{
var infoLines = new List<string>();
var name = Name(uid);
var ev = new SeeIdentityAttemptEvent();
RaiseLocalEvent(uid, ev);
if (ev.Cancelled)
{
2024-01-23 15:33:20 +03:00
if (_idCard.TryFindIdCard(uid, out var id) && !string.IsNullOrWhiteSpace(id.Comp.FullName))
{
2024-01-23 15:33:20 +03:00
name = id.Comp.FullName;
}
else
{
name = "неизвестный";
}
}
infoLines.Add($"Это же [bold]{name}[/bold]!");
var idInfoString = GetInfo(uid);
if (!string.IsNullOrEmpty(idInfoString))
{
infoLines.Add(idInfoString);
args.PushMarkup(idInfoString);
}
var slotLabels = new Dictionary<string, string>
{
{ "head", "head-" },
{ "eyes", "eyes-" },
{ "mask", "mask-" },
{ "neck", "neck-" },
{ "ears", "ears-" },
{ "jumpsuit", "jumpsuit-" },
{ "outerClothing", "outer-" },
{ "back", "back-" },
{ "gloves", "gloves-" },
{ "belt", "belt-" },
{ "shoes", "shoes-" }
};
foreach (var slotEntry in slotLabels)
{
var slotName = slotEntry.Key;
var slotLabel = slotEntry.Value;
if (_entityManager.TryGetComponent<HumanoidAppearanceComponent>(uid, out var appearanceComponent))
{
switch (appearanceComponent.Gender)
{
case Gender.Male:
slotLabel += "he";
break;
case Gender.Neuter:
slotLabel += "it";
break;
case Gender.Epicene:
slotLabel += "they";
break;
case Gender.Female:
slotLabel += "she";
break;
}
}
if (!_inventorySystem.TryGetSlotEntity(uid, slotName, out var slotEntity))
continue;
if (_entityManager.TryGetComponent<MetaDataComponent>(slotEntity, out var metaData))
{
var item = $"{Loc.GetString(slotLabel)} [bold]{metaData.EntityName}[/bold].";
args.PushMarkup(item);
infoLines.Add(item);
}
}
var combinedInfo = string.Join("\n", infoLines);
2023-09-30 16:32:22 +09:00
if (TryComp(args.Examiner, out ActorComponent? actorComponent))
{
SendNoticeMessage(actorComponent, combinedInfo);
}
}
private string GetInfo(EntityUid uid)
{
if (_inventorySystem.TryGetSlotEntity(uid, "id", out var idUid))
{
// PDA
if (EntityManager.TryGetComponent(idUid, out PdaComponent? pda) &&
TryComp(pda.ContainedId, out IdCardComponent? idCard))
{
return GetNameAndJob(idCard);
}
// ID Card
if (EntityManager.TryGetComponent(idUid, out IdCardComponent? id))
{
return GetNameAndJob(id);
}
}
return "";
}
private string GetNameAndJob(IdCardComponent id)
{
var jobSuffix = string.IsNullOrWhiteSpace(id.JobTitle) ? "" : $" ({id.JobTitle})";
var val = string.IsNullOrWhiteSpace(id.FullName)
? Loc.GetString("access-id-card-component-owner-name-job-title-text",
("jobSuffix", jobSuffix))
: Loc.GetString("access-id-card-component-owner-full-name-job-title-text",
("fullName", id.FullName),
("jobSuffix", jobSuffix));
return val;
}
}
}