Criminal record hud icons (#25192)
* Security hud shows icon based on criminal record status * Criminal status now linked to name instead of identity * parole loc * Test fix * review changes * Check station records instead of storing names on criminal record consoles. * cleanup * more cleanup * review changes * change outdated comments * rename * review changes * remove event subscription * replaced event with trycomp * default value
This commit is contained in:
@@ -134,7 +134,7 @@ namespace Content.Server.Administration.Systems
|
||||
return value ?? null;
|
||||
}
|
||||
|
||||
private void OnIdentityChanged(IdentityChangedEvent ev)
|
||||
private void OnIdentityChanged(ref IdentityChangedEvent ev)
|
||||
{
|
||||
if (!TryComp<ActorComponent>(ev.CharacterEntity, out var actor))
|
||||
return;
|
||||
|
||||
@@ -12,6 +12,8 @@ using Content.Shared.StationRecords;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Player;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Shared.IdentityManagement;
|
||||
using Content.Shared.Security.Components;
|
||||
|
||||
namespace Content.Server.CriminalRecords.Systems;
|
||||
|
||||
@@ -71,7 +73,8 @@ public sealed class CriminalRecordsConsoleSystem : SharedCriminalRecordsConsoleS
|
||||
private void OnChangeStatus(Entity<CriminalRecordsConsoleComponent> ent, ref CriminalRecordChangeStatus msg)
|
||||
{
|
||||
// prevent malf client violating wanted/reason nullability
|
||||
if ((msg.Status == SecurityStatus.Wanted) != (msg.Reason != null))
|
||||
if (msg.Status == SecurityStatus.Wanted != (msg.Reason != null) &&
|
||||
msg.Status == SecurityStatus.Suspected != (msg.Reason != null))
|
||||
return;
|
||||
|
||||
if (!CheckSelected(ent, msg.Session, out var mob, out var key))
|
||||
@@ -105,7 +108,7 @@ public sealed class CriminalRecordsConsoleSystem : SharedCriminalRecordsConsoleS
|
||||
|
||||
var name = RecordName(key.Value);
|
||||
var officer = Loc.GetString("criminal-records-console-unknown-officer");
|
||||
if (_idCard.TryFindIdCard(mob.Value, out var id) && id.Comp.FullName is {} fullName)
|
||||
if (_idCard.TryFindIdCard(mob.Value, out var id) && id.Comp.FullName is { } fullName)
|
||||
officer = fullName;
|
||||
|
||||
(string, object)[] args;
|
||||
@@ -117,20 +120,32 @@ public sealed class CriminalRecordsConsoleSystem : SharedCriminalRecordsConsoleS
|
||||
// figure out which radio message to send depending on transition
|
||||
var statusString = (oldStatus, msg.Status) switch
|
||||
{
|
||||
// going from wanted or detained on the spot
|
||||
// person has been detained
|
||||
(_, SecurityStatus.Detained) => "detained",
|
||||
// person did something sus
|
||||
(_, SecurityStatus.Suspected) => "suspected",
|
||||
// released on parole
|
||||
(_, SecurityStatus.Paroled) => "paroled",
|
||||
// prisoner did their time
|
||||
(SecurityStatus.Detained, SecurityStatus.None) => "released",
|
||||
// going from wanted to none, must have been a mistake
|
||||
(_, SecurityStatus.None) => "not-wanted",
|
||||
// going from none or detained, AOS or prisonbreak / lazy secoff never set them to released and they reoffended
|
||||
(_, SecurityStatus.Discharged) => "released",
|
||||
// going from any other state to wanted, AOS or prisonbreak / lazy secoff never set them to released and they reoffended
|
||||
(_, SecurityStatus.Wanted) => "wanted",
|
||||
// person is no longer sus
|
||||
(SecurityStatus.Suspected, SecurityStatus.None) => "not-suspected",
|
||||
// going from wanted to none, must have been a mistake
|
||||
(SecurityStatus.Wanted, SecurityStatus.None) => "not-wanted",
|
||||
// criminal status removed
|
||||
(SecurityStatus.Detained, SecurityStatus.None) => "released",
|
||||
// criminal is no longer on parole
|
||||
(SecurityStatus.Paroled, SecurityStatus.None) => "not-parole",
|
||||
// this is impossible
|
||||
_ => "not-wanted"
|
||||
};
|
||||
_radio.SendRadioMessage(ent, Loc.GetString($"criminal-records-console-{statusString}", args), ent.Comp.SecurityChannel, ent);
|
||||
_radio.SendRadioMessage(ent, Loc.GetString($"criminal-records-console-{statusString}", args),
|
||||
ent.Comp.SecurityChannel, ent);
|
||||
|
||||
UpdateUserInterface(ent);
|
||||
UpdateCriminalIdentity(name, msg.Status);
|
||||
}
|
||||
|
||||
private void OnAddHistory(Entity<CriminalRecordsConsoleComponent> ent, ref CriminalRecordAddHistory msg)
|
||||
@@ -177,7 +192,7 @@ public sealed class CriminalRecordsConsoleSystem : SharedCriminalRecordsConsoleS
|
||||
var listing = _stationRecords.BuildListing((owningStation.Value, stationRecords), console.Filter);
|
||||
|
||||
var state = new CriminalRecordsConsoleState(listing, console.Filter);
|
||||
if (console.ActiveKey is {} id)
|
||||
if (console.ActiveKey is { } id)
|
||||
{
|
||||
// get records to display when a crewmember is selected
|
||||
var key = new StationRecordKey(id, owningStation.Value);
|
||||
@@ -198,7 +213,7 @@ public sealed class CriminalRecordsConsoleSystem : SharedCriminalRecordsConsoleS
|
||||
{
|
||||
key = null;
|
||||
mob = null;
|
||||
if (session.AttachedEntity is not {} user)
|
||||
if (session.AttachedEntity is not { } user)
|
||||
return false;
|
||||
|
||||
if (!_access.IsAllowed(user, ent))
|
||||
@@ -207,11 +222,11 @@ public sealed class CriminalRecordsConsoleSystem : SharedCriminalRecordsConsoleS
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ent.Comp.ActiveKey is not {} id)
|
||||
if (ent.Comp.ActiveKey is not { } id)
|
||||
return false;
|
||||
|
||||
// checking the console's station since the user might be off-grid using on-grid console
|
||||
if (_station.GetOwningStation(ent) is not {} station)
|
||||
if (_station.GetOwningStation(ent) is not { } station)
|
||||
return false;
|
||||
|
||||
key = new StationRecordKey(id, station);
|
||||
@@ -229,4 +244,29 @@ public sealed class CriminalRecordsConsoleSystem : SharedCriminalRecordsConsoleS
|
||||
|
||||
return record.Name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the new identity's name has a criminal record attached to it, and gives the entity the icon that
|
||||
/// belongs to the status if it does.
|
||||
/// </summary>
|
||||
public void CheckNewIdentity(EntityUid uid)
|
||||
{
|
||||
var name = Identity.Name(uid, EntityManager);
|
||||
var xform = Transform(uid);
|
||||
var station = _station.GetStationInMap(xform.MapID);
|
||||
|
||||
if (station != null && _stationRecords.GetRecordByName(station.Value, name) is { } id)
|
||||
{
|
||||
if (_stationRecords.TryGetRecord<CriminalRecord>(new StationRecordKey(id, station.Value),
|
||||
out var record))
|
||||
{
|
||||
if (record.Status != SecurityStatus.None)
|
||||
{
|
||||
SetCriminalIcon(name, record.Status, uid);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
RemComp<CriminalRecordComponent>(uid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Content.Server.Access.Systems;
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.CriminalRecords.Systems;
|
||||
using Content.Server.Humanoid;
|
||||
using Content.Shared.Clothing;
|
||||
using Content.Shared.Database;
|
||||
@@ -25,6 +26,7 @@ public class IdentitySystem : SharedIdentitySystem
|
||||
[Dependency] private readonly MetaDataSystem _metaData = default!;
|
||||
[Dependency] private readonly SharedContainerSystem _container = default!;
|
||||
[Dependency] private readonly HumanoidAppearanceSystem _humanoid = default!;
|
||||
[Dependency] private readonly CriminalRecordsConsoleSystem _criminalRecordsConsole = default!;
|
||||
|
||||
private HashSet<EntityUid> _queuedIdentityUpdates = new();
|
||||
|
||||
@@ -107,7 +109,9 @@ public class IdentitySystem : SharedIdentitySystem
|
||||
_metaData.SetEntityName(ident, name);
|
||||
|
||||
_adminLog.Add(LogType.Identity, LogImpact.Medium, $"{ToPrettyString(uid)} changed identity to {name}");
|
||||
RaiseLocalEvent(new IdentityChangedEvent(uid, ident));
|
||||
var identityChangedEvent = new IdentityChangedEvent(uid, ident);
|
||||
RaiseLocalEvent(uid, ref identityChangedEvent);
|
||||
SetIdentityCriminalIcon(uid);
|
||||
}
|
||||
|
||||
private string GetIdentityName(EntityUid target, IdentityRepresentation representation)
|
||||
@@ -118,6 +122,16 @@ public class IdentitySystem : SharedIdentitySystem
|
||||
return representation.ToStringKnown(!ev.Cancelled);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When the identity of a person is changed, searches the criminal records to see if the name of the new identity
|
||||
/// has a record. If the new name has a criminal status attached to it, the person will get the criminal status
|
||||
/// until they change identity again.
|
||||
/// </summary>
|
||||
private void SetIdentityCriminalIcon(EntityUid uid)
|
||||
{
|
||||
_criminalRecordsConsole.CheckNewIdentity(uid);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an 'identity representation' of an entity, with their true name being the entity name
|
||||
/// and their 'presumed name' and 'presumed job' being the name/job on their ID card, if they have one.
|
||||
@@ -159,15 +173,3 @@ public class IdentitySystem : SharedIdentitySystem
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public sealed class IdentityChangedEvent : EntityEventArgs
|
||||
{
|
||||
public EntityUid CharacterEntity;
|
||||
public EntityUid IdentityEntity;
|
||||
|
||||
public IdentityChangedEvent(EntityUid characterEntity, EntityUid identityEntity)
|
||||
{
|
||||
CharacterEntity = characterEntity;
|
||||
IdentityEntity = identityEntity;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user