fish-station/Content.Server/Access/Systems/AgentIDCardSystem.cs
Vigers Ray d791eb37bd Merge remote-tracking branch 'space-wizards/master'
# Conflicts:
#	.github/CODEOWNERS
#	Content.Client/Options/UI/Tabs/AccessibilityTab.xaml
#	Content.Client/UserInterface/Systems/Chat/Widgets/ChatBox.xaml.cs
#	Content.Server/Access/Systems/AgentIDCardSystem.cs
#	Content.Server/Clothing/Systems/ChameleonClothingSystem.cs
#	Content.Server/Entry/IgnoredComponents.cs
#	Content.Shared/Access/Systems/SharedIdCardSystem.cs
#	Content.Shared/Clothing/EntitySystems/SharedChameleonClothingSystem.cs
#	Content.Shared/Inventory/InventorySystem.Relay.cs
#	Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.ChamberMagazine.cs
#	Resources/Locale/en-US/_strings/atmos/atmos-pipe-layers.ftl
#	Resources/Locale/en-US/_strings/chat/highlights.ftl
#	Resources/Locale/en-US/_strings/implant/chameleon-controller.ftl
#	Resources/Locale/en-US/_strings/prototypes/roles/antags.ftl
#	Resources/Locale/en-US/_strings/reagents/absinthe.ftl
#	Resources/Prototypes/Entities/Clothing/OuterClothing/vests.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Guns/SMGs/smgs.yml
#	Resources/Prototypes/Entities/Structures/Wallmounts/air_alarm.yml
#	Resources/Prototypes/Entities/Structures/Wallmounts/mirror.yml
#	Resources/Prototypes/Entities/Structures/cryogenic_sleep_unit.yml
#	Resources/Prototypes/Recipes/Lathes/categories.yml
#	Resources/Prototypes/Roles/Jobs/CentComm/cburn.yml
#	Resources/Prototypes/Roles/Jobs/CentComm/official.yml
#	Resources/Prototypes/Roles/Jobs/Civilian/chaplain.yml
#	Resources/Prototypes/Roles/Jobs/Civilian/lawyer.yml
#	Resources/Prototypes/Roles/Jobs/Command/head_of_personnel.yml
#	Resources/Prototypes/Roles/Jobs/Engineering/chief_engineer.yml
#	Resources/Prototypes/Roles/Jobs/Medical/chief_medical_officer.yml
#	Resources/Prototypes/Roles/Jobs/Medical/paramedic.yml
#	Resources/Prototypes/Roles/Jobs/Science/research_director.yml
#	Resources/Prototypes/Roles/Jobs/Security/head_of_security.yml
#	Resources/Prototypes/Roles/Jobs/Security/security_cadet.yml
#	Resources/Prototypes/Roles/Jobs/Security/security_officer.yml
#	Resources/Prototypes/Roles/Jobs/Security/warden.yml
#	Resources/Textures/Structures/Doors/secret_door.rsi/assembly.png
#	Resources/Textures/Structures/Doors/secret_door.rsi/closed.png
#	Resources/Textures/Structures/Doors/secret_door.rsi/closing.png
#	Resources/Textures/Structures/Doors/secret_door.rsi/meta.json
#	Resources/Textures/Structures/Doors/secret_door.rsi/open.png
#	Resources/Textures/Structures/Doors/secret_door.rsi/opening.png
#	Resources/Textures/Structures/Wallmounts/air_monitors.rsi/alarm0.png
#	Resources/Textures/Structures/Wallmounts/air_monitors.rsi/alarm1.png
#	Resources/Textures/Structures/Wallmounts/air_monitors.rsi/alarm2.png
#	Resources/migration.yml
2025-06-04 13:39:57 +03:00

167 lines
7.2 KiB
C#

using Content.Server.Access.Components;
using Content.Server.Popups;
using Content.Shared.UserInterface;
using Content.Shared.Access.Components;
using Content.Shared.Access.Systems;
using Content.Shared.Interaction;
using Content.Shared.StatusIcon;
using Robust.Server.GameObjects;
using Robust.Shared.Prototypes;
using Content.Shared.Roles;
using System.Diagnostics.CodeAnalysis;
using Content.Server.Clothing.Systems;
using Content.Shared._Sunrise.Biocode;
using Content.Server.Implants;
using Content.Shared.Implants;
using Content.Shared.Inventory;
using Content.Shared.PDA;
namespace Content.Server.Access.Systems
{
public sealed class AgentIDCardSystem : SharedAgentIdCardSystem
{
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly IdCardSystem _cardSystem = default!;
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly ChameleonClothingSystem _chameleon = default!;
[Dependency] private readonly ChameleonControllerSystem _chamController = default!;
[Dependency] private readonly BiocodeSystem _biocodeSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<AgentIDCardComponent, AfterInteractEvent>(OnAfterInteract);
// BUI
SubscribeLocalEvent<AgentIDCardComponent, AfterActivatableUIOpenEvent>(AfterUIOpen);
SubscribeLocalEvent<AgentIDCardComponent, AgentIDCardNameChangedMessage>(OnNameChanged);
SubscribeLocalEvent<AgentIDCardComponent, AgentIDCardJobChangedMessage>(OnJobChanged);
SubscribeLocalEvent<AgentIDCardComponent, AgentIDCardJobIconChangedMessage>(OnJobIconChanged);
SubscribeLocalEvent<AgentIDCardComponent, InventoryRelayedEvent<ChameleonControllerOutfitSelectedEvent>>(OnChameleonControllerOutfitChangedItem);
}
private void OnChameleonControllerOutfitChangedItem(Entity<AgentIDCardComponent> ent, ref InventoryRelayedEvent<ChameleonControllerOutfitSelectedEvent> args)
{
if (!TryComp<IdCardComponent>(ent, out var idCardComp))
return;
_prototypeManager.TryIndex(args.Args.ChameleonOutfit.Job, out var jobProto);
var jobIcon = args.Args.ChameleonOutfit.Icon ?? jobProto?.Icon;
var jobName = args.Args.ChameleonOutfit.Name ?? jobProto?.Name ?? "";
if (jobIcon != null)
_cardSystem.TryChangeJobIcon(ent, _prototypeManager.Index(jobIcon.Value), idCardComp);
if (jobName != "")
_cardSystem.TryChangeJobTitle(ent, Loc.GetString(jobName), idCardComp);
// If you have forced departments use those over the jobs actual departments.
if (args.Args.ChameleonOutfit?.Departments?.Count > 0)
_cardSystem.TryChangeJobDepartment(ent, args.Args.ChameleonOutfit.Departments, idCardComp);
else if (jobProto != null)
_cardSystem.TryChangeJobDepartment(ent, jobProto, idCardComp);
// Ensure that you chameleon IDs in PDAs correctly. Yes this is sus...
// There is one weird interaction: If the job / icon don't match the PDAs job the chameleon will be updated
// to the PDAs IDs sprite but the icon and job title will not match. There isn't a way to get around this
// really as there is no tie between job -> pda or pda -> job.
var idSlotGear = _chamController.GetGearForSlot(args, "id");
if (idSlotGear == null)
return;
var proto = _prototypeManager.Index(idSlotGear);
if (!proto.TryGetComponent<PdaComponent>(out var comp, EntityManager.ComponentFactory))
return;
_chameleon.SetSelectedPrototype(ent, comp.IdCard);
}
private void OnAfterInteract(EntityUid uid, AgentIDCardComponent component, AfterInteractEvent args)
{
if (args.Target == null || !args.CanReach || !TryComp<AccessComponent>(args.Target, out var targetAccess) || !HasComp<IdCardComponent>(args.Target))
return;
// Sunrise-Start
if (TryComp<BiocodeComponent>(uid, out var biocodedComponent))
{
if (!_biocodeSystem.CanUse(args.User, biocodedComponent.Factions))
return;
}
// Sunrise-End
if (!TryComp<AccessComponent>(uid, out var access) || !HasComp<IdCardComponent>(uid))
return;
var beforeLength = access.Tags.Count;
access.Tags.UnionWith(targetAccess.Tags);
var addedLength = access.Tags.Count - beforeLength;
_popupSystem.PopupEntity(Loc.GetString("agent-id-new", ("number", addedLength), ("card", args.Target)), args.Target.Value, args.User);
if (addedLength > 0)
Dirty(uid, access);
}
private void AfterUIOpen(EntityUid uid, AgentIDCardComponent component, AfterActivatableUIOpenEvent args)
{
if (!_uiSystem.HasUi(uid, AgentIDCardUiKey.Key))
return;
if (!TryComp<IdCardComponent>(uid, out var idCard))
return;
var state = new AgentIDCardBoundUserInterfaceState(idCard.FullName ?? "", idCard.LocalizedJobTitle ?? "", idCard.JobIcon);
_uiSystem.SetUiState(uid, AgentIDCardUiKey.Key, state);
}
private void OnJobChanged(EntityUid uid, AgentIDCardComponent comp, AgentIDCardJobChangedMessage args)
{
if (!TryComp<IdCardComponent>(uid, out var idCard))
return;
_cardSystem.TryChangeJobTitle(uid, args.Job, idCard);
}
private void OnNameChanged(EntityUid uid, AgentIDCardComponent comp, AgentIDCardNameChangedMessage args)
{
if (!TryComp<IdCardComponent>(uid, out var idCard))
return;
_cardSystem.TryChangeFullName(uid, args.Name, idCard);
}
private void OnJobIconChanged(EntityUid uid, AgentIDCardComponent comp, AgentIDCardJobIconChangedMessage args)
{
if (!TryComp<IdCardComponent>(uid, out var idCard))
return;
if (!_prototypeManager.TryIndex(args.JobIconId, out var jobIcon))
return;
_cardSystem.TryChangeJobIcon(uid, jobIcon, idCard);
if (TryFindJobProtoFromIcon(jobIcon, out var job))
{
_cardSystem.TryChangeJobColor(uid, _cardSystem.GetJobColor(_prototypeManager, job), job.RadioIsBold);
_cardSystem.TryChangeJobDepartment(uid, job, idCard); // Sunrise-Edit
}
}
private bool TryFindJobProtoFromIcon(JobIconPrototype jobIcon, [NotNullWhen(true)] out JobPrototype? job)
{
foreach (var jobPrototype in _prototypeManager.EnumeratePrototypes<JobPrototype>())
{
if (jobPrototype.Icon == jobIcon.ID)
{
job = jobPrototype;
return true;
}
}
job = null;
return false;
}
}
}