Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Criminal Record Refactor #4

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 15 additions & 56 deletions Content.Client/Overlays/ShowCriminalRecordIconsSystem.cs
Original file line number Diff line number Diff line change
@@ -1,80 +1,39 @@
using Content.Shared.Access.Components;
using Content.Shared.Access.Systems;
using Content.Shared.IdentityManagement.Components;
using Content.Shared.Overlays;
using Content.Shared.PDA;
using Content.Shared.Security.Components;
using Content.Shared.SS220.CriminalRecords;
using Content.Shared.StatusIcon;
using Content.Shared.StatusIcon.Components;
using Robust.Shared.Prototypes;
using Content.Shared.Examine;

namespace Content.Client.Overlays;

public sealed class ShowCriminalRecordIconsSystem : EquipmentHudSystem<ShowCriminalRecordIconsComponent>
{
[Dependency] private readonly IPrototypeManager _prototype = default!;
[Dependency] private readonly AccessReaderSystem _accessReader = default!;
[Dependency] private readonly IPrototypeManager _prototypeMan = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<IdentityComponent, GetStatusIconsEvent>(OnGetStatusIconsEvent); // 220 secincons fix
SubscribeLocalEvent<CriminalRecordComponent, GetStatusIconsEvent>(OnGetStatusIconsEvent);
SubscribeLocalEvent<CriminalRecordComponent, ExaminedEvent>(OnStatusExamine);
}

private void OnGetStatusIconsEvent(EntityUid uid, IdentityComponent _, ref GetStatusIconsEvent ev) // 220 secincons fix
private void OnGetStatusIconsEvent(EntityUid uid, CriminalRecordComponent component, ref GetStatusIconsEvent ev)
{
if (!IsActive || ev.InContainer)
if (!IsActive)
return;

//SS220 Criminal-Records begin

// WizDen code, no longer needed
// if (_prototype.TryIndex<StatusIconPrototype>(component.StatusIcon.Id, out var iconPrototype))
// ev.StatusIcons.Add(iconPrototype);

string? securityRecordType = null;
if (_accessReader.FindAccessItemsInventory(uid, out var items))
{
foreach (var item in items)
{
// ID Card
if (TryComp(item, out IdCardComponent? id))
{
securityRecordType = id.CurrentSecurityRecord?.RecordType; //SS220 Criminal-Records
break;
}

// PDA
if (TryComp(item, out PdaComponent? pda)
&& pda.ContainedId != null
&& TryComp(pda.ContainedId, out id))
{
securityRecordType = id.CurrentSecurityRecord?.RecordType; //SS220 Criminal-Records
break;
}
}
}
if (_prototype.TryIndex(component.StatusIcon, out var iconPrototype))
ev.StatusIcons.Add(iconPrototype);
}
// Start 220 CriminalRecords
private void OnStatusExamine(Entity<CriminalRecordComponent> ent, ref ExaminedEvent args)
{
if (!IsActive)
return;

if (securityRecordType != null)
{
if (_prototypeMan.TryIndex<CriminalStatusPrototype>(securityRecordType, out var criminalStatus))
{
if (criminalStatus.StatusIcon.HasValue)
{
if (_prototypeMan.TryIndex(criminalStatus.StatusIcon, out var secIcon))
ev.StatusIcons.Add(secIcon);
else
Log.Error($"Invalid security status icon prototype: {secIcon}");
}
}
else
{
Log.Error($"Invalid security status prototype: {criminalStatus}");
}
}
//SS220 Criminal-Records end
args.PushMarkup($"[color=#FF0000][bold]Причина: {ent.Comp.Reason}[/bold][/color]");
}
// End 220 CriminalRecords
}
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ public void CheckNewIdentity(EntityUid uid)
if (record.Status != SecurityStatus.None)
{
_criminalRecords.SetCriminalIcon(name, record.Status, uid);
_criminalRecords.SetCriminalReason(name, record.Reason, uid); // 220 CriminalRecords
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public void OverwriteStatus(StationRecordKey key, CriminalRecord record, Securit

var name = _records.RecordName(key);
if (name != string.Empty)
UpdateCriminalIdentity(name, status);
// UpdateCriminalIdentity(name, status);
UpdateCriminalIdentity(name, status, reason); // 220 CriminalRecords

_records.Synchronize(key);
}
Expand Down
132 changes: 66 additions & 66 deletions Content.Server/SS220/CriminalRecords/CriminalRecordSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,77 +33,77 @@ public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<StatusIconComponent, ExaminedEvent>(OnStatusExamine);
// SubscribeLocalEvent<StatusIconComponent, ExaminedEvent>(OnStatusExamine);
}

// TheArturZh 25.09.2023 22:15
// TODO: bad code. make it use InventoryRelayedEvent. Create separate components for examining and for examined subscription.
// no pohuy prosto zaebalsya(
private void OnStatusExamine(EntityUid uid, StatusIconComponent comp, ExaminedEvent args)
{
var scannerOn = false;
if (_inventory.TryGetSlotEntity(args.Examiner, "eyes", out var ent))
{
if (HasComp<ShowCriminalRecordIconsComponent>(ent))
{
scannerOn = true;
}
}

if (!scannerOn)
return;

CriminalRecord? record = null;

if (_accessReader.FindAccessItemsInventory(uid, out var items))
{
foreach (var item in items)
{
// ID Card
if (TryComp(item, out IdCardComponent? id))
{
if (id.CurrentSecurityRecord != null)
{
record = id.CurrentSecurityRecord;
break;
}
}

// PDA
if (TryComp(item, out PdaComponent? pda)
&& pda.ContainedId != null
&& TryComp(pda.ContainedId, out id))
{
if (id.CurrentSecurityRecord != null)
{
record = id.CurrentSecurityRecord;
break;
}
}
}
}

//SS220 Criminal-Records begin
if (record != null)
{
var msg = new FormattedMessage();

if (record.RecordType == null)
{
msg.AddMarkup("[bold]Без статуса: [/bold]");
}
else
{
if (_prototype.TryIndex<CriminalStatusPrototype>(record.RecordType, out var statusType))
{
msg.AddMarkup($"[color={statusType.Color.ToHex()}][bold]{statusType.Name}:[/bold][/color] ");
}
}

msg.AddText(record.Message);
args.PushMessage(msg);
}
}
// private void OnStatusExamine(EntityUid uid, StatusIconComponent comp, ExaminedEvent args)
// {
// var scannerOn = false;
// if (_inventory.TryGetSlotEntity(args.Examiner, "eyes", out var ent))
// {
// if (HasComp<ShowCriminalRecordIconsComponent>(ent))
// {
// scannerOn = true;
// }
// }

// if (!scannerOn)
// return;

// CriminalRecord? record = null;

// if (_accessReader.FindAccessItemsInventory(uid, out var items))
// {
// foreach (var item in items)
// {
// // ID Card
// if (TryComp(item, out IdCardComponent? id))
// {
// if (id.CurrentSecurityRecord != null)
// {
// record = id.CurrentSecurityRecord;
// break;
// }
// }

// // PDA
// if (TryComp(item, out PdaComponent? pda)
// && pda.ContainedId != null
// && TryComp(pda.ContainedId, out id))
// {
// if (id.CurrentSecurityRecord != null)
// {
// record = id.CurrentSecurityRecord;
// break;
// }
// }
// }
// }

// //SS220 Criminal-Records begin
// if (record != null)
// {
// var msg = new FormattedMessage();

// if (record.RecordType == null)
// {
// msg.AddMarkup("[bold]Без статуса: [/bold]");
// }
// else
// {
// if (_prototype.TryIndex<CriminalStatusPrototype>(record.RecordType, out var statusType))
// {
// msg.AddMarkup($"[color={statusType.Color.ToHex()}][bold]{statusType.Name}:[/bold][/color] ");
// }
// }

// msg.AddText(record.Message);
// args.PushMessage(msg);
// }
// }

public CriminalRecordCatalog EnsureRecordCatalog(GeneralStationRecord record)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public abstract class SharedCriminalRecordsSystem : EntitySystem
/// Any entity that has a the name of the record that was just changed as their visible name will get their icon
/// updated with the new status, if the record got removed their icon will be removed too.
/// </summary>
public void UpdateCriminalIdentity(string name, SecurityStatus status)
// public void UpdateCriminalIdentity(string name, SecurityStatus status)
public void UpdateCriminalIdentity(string name, SecurityStatus status, string? reason) // 220 CriminalRecords
{
var query = EntityQueryEnumerator<IdentityComponent>();

Expand All @@ -23,7 +24,12 @@ public void UpdateCriminalIdentity(string name, SecurityStatus status)
if (status == SecurityStatus.None)
RemComp<CriminalRecordComponent>(uid);
else
// Start 220 CriminalRecords
{
SetCriminalIcon(name, status, uid);
SetCriminalReason(name, reason, uid);
}
// End 220 CriminalRecords
}
}

Expand All @@ -49,4 +55,13 @@ public void SetCriminalIcon(string name, SecurityStatus status, EntityUid charac
if (previousIcon != record.StatusIcon)
Dirty(characterUid, record);
}

public void SetCriminalReason(string name, string? reason, EntityUid characterUid)
{
if (TryComp<CriminalRecordComponent>(characterUid, out var record))
{
if (reason != null)
record.Reason = reason;
}
}
}
5 changes: 5 additions & 0 deletions Content.Shared/Security/Components/CriminalRecordComponent.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Content.Shared.StatusIcon;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Content.Shared.CriminalRecords;

namespace Content.Shared.Security.Components;

Expand All @@ -12,4 +13,8 @@ public sealed partial class CriminalRecordComponent : Component
/// </summary>
[DataField, AutoNetworkedField]
public ProtoId<StatusIconPrototype> StatusIcon = "SecurityIconWanted";
// 220 Criminal Records
[DataField, AutoNetworkedField]
public string Reason = "Не указана";
// 220 Criminal Records
}
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,13 @@
name: criminal records computer
description: This can be used to check criminal records. Only security can modify them.
components:
# - type: CriminalRecordsConsole #SS220 Criminal-Records (remove comp)
# - type: UserInterface
# interfaces:
# enum.CriminalRecordsConsoleKey.Key:
# type: CriminalRecordsConsoleBoundUserInterface
# - type: ActivatableUI
# key: enum.CriminalRecordsConsoleKey.Key
- type: CriminalRecordsConsole
- type: UserInterface
interfaces:
enum.CriminalRecordsConsoleKey.Key:
type: CriminalRecordsConsoleBoundUserInterface
- type: ActivatableUI
key: enum.CriminalRecordsConsoleKey.Key
- type: Sprite
layers:
- map: ["computerLayerBody"]
Expand All @@ -324,51 +324,27 @@
radius: 1.5
energy: 1.6
color: "#1f8c28"
#SS220 Criminal-Records begin
- type: Computer
board: CriminalRecordsComputerCircuitboard
- type: AccessReader
access: [ [ "Brig" ] ] #So IAA can have access too
- type: CriminalRecordsConsole220
- type: UserInterface
interfaces:
enum.CriminalRecordsUiKey.Key:
type: CriminalRecordsBoundUserInterface
- type: ActivatableUI
key: enum.CriminalRecordsUiKey.Key
access: [["Security"]]
- type: GuideHelp
guides:
- Forensics
#SS220 Criminal-Records end
- type: Computer
board: CriminalRecordsComputerCircuitboard
# - type: AccessReader
# access: [["Security"]]
# - type: GuideHelp
# guides:
# - CriminalRecords
- CriminalRecords

- type: entity
parent: BaseComputer
id: ComputerStationRecords
name: station records computer
description: This can be used to check station records.
components:
#SS220 Criminal-Records begin
# - type: GeneralStationRecordConsole
- type: CriminalRecordsConsole220
isSecurity: false
- type: GeneralStationRecordConsole
- type: UserInterface
interfaces:
enum.CriminalRecordsUiKey.Key:
type: CriminalRecordsBoundUserInterface
enum.GeneralStationRecordConsoleKey.Key:
type: GeneralStationRecordConsoleBoundUserInterface
- type: ActivatableUI
key: enum.CriminalRecordsUiKey.Key
# - type: UserInterface
# interfaces:
# enum.GeneralStationRecordConsoleKey.Key:
# type: GeneralStationRecordConsoleBoundUserInterface
# - type: ActivatableUI
# key: enum.GeneralStationRecordConsoleKey.Key
#SS220 Criminal-Records end
key: enum.GeneralStationRecordConsoleKey.Key
- type: PointLight
radius: 1.5
energy: 1.6
Expand Down
Loading
Loading