2023-10-19 12:34:31 -07:00
|
|
|
using System.Linq;
|
2022-08-07 20:21:56 -03:00
|
|
|
using Content.Server.Administration.Logs;
|
2022-02-12 17:53:54 -07:00
|
|
|
using Content.Server.Kitchen.Components;
|
|
|
|
|
using Content.Server.Popups;
|
|
|
|
|
using Content.Shared.Access;
|
2021-12-16 23:42:02 +13:00
|
|
|
using Content.Shared.Access.Components;
|
|
|
|
|
using Content.Shared.Access.Systems;
|
2022-08-07 20:21:56 -03:00
|
|
|
using Content.Shared.Database;
|
2022-07-09 02:09:52 -07:00
|
|
|
using Content.Shared.Popups;
|
2022-02-12 17:53:54 -07:00
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
using Robust.Shared.Random;
|
2024-06-14 22:00:00 -05:00
|
|
|
using Content.Server.Kitchen.EntitySystems;
|
2021-10-22 05:31:07 +03:00
|
|
|
|
2023-12-09 23:38:50 -06:00
|
|
|
namespace Content.Server.Access.Systems;
|
|
|
|
|
|
|
|
|
|
public sealed class IdCardSystem : SharedIdCardSystem
|
2021-10-22 05:31:07 +03:00
|
|
|
{
|
2023-12-09 23:38:50 -06:00
|
|
|
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
|
|
|
|
[Dependency] private readonly IRobustRandom _random = default!;
|
|
|
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
|
|
|
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
2024-06-14 22:00:00 -05:00
|
|
|
[Dependency] private readonly MicrowaveSystem _microwave = default!;
|
2021-12-30 22:56:10 +01:00
|
|
|
|
2023-12-09 23:38:50 -06:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
2024-09-03 16:01:38 +03:00
|
|
|
|
2023-12-09 23:38:50 -06:00
|
|
|
SubscribeLocalEvent<IdCardComponent, BeingMicrowavedEvent>(OnMicrowaved);
|
|
|
|
|
}
|
2021-10-22 05:31:07 +03:00
|
|
|
|
2023-12-09 23:38:50 -06:00
|
|
|
private void OnMicrowaved(EntityUid uid, IdCardComponent component, BeingMicrowavedEvent args)
|
|
|
|
|
{
|
2024-06-14 22:00:00 -05:00
|
|
|
if (!component.CanMicrowave || !TryComp<MicrowaveComponent>(args.Microwave, out var micro) || micro.Broken)
|
|
|
|
|
return;
|
2024-05-17 01:48:22 -07:00
|
|
|
|
2023-12-09 23:38:50 -06:00
|
|
|
if (TryComp<AccessComponent>(uid, out var access))
|
2022-02-12 17:53:54 -07:00
|
|
|
{
|
2023-12-09 23:38:50 -06:00
|
|
|
float randomPick = _random.NextFloat();
|
2024-06-14 22:00:00 -05:00
|
|
|
|
2023-12-09 23:38:50 -06:00
|
|
|
// if really unlucky, burn card
|
|
|
|
|
if (randomPick <= 0.15f)
|
2022-02-12 17:53:54 -07:00
|
|
|
{
|
2023-12-09 23:38:50 -06:00
|
|
|
TryComp(uid, out TransformComponent? transformComponent);
|
|
|
|
|
if (transformComponent != null)
|
2022-02-19 19:07:13 -06:00
|
|
|
{
|
2023-12-09 23:38:50 -06:00
|
|
|
_popupSystem.PopupCoordinates(Loc.GetString("id-card-component-microwave-burnt", ("id", uid)),
|
|
|
|
|
transformComponent.Coordinates, PopupType.Medium);
|
|
|
|
|
EntityManager.SpawnEntity("FoodBadRecipe",
|
|
|
|
|
transformComponent.Coordinates);
|
2022-02-19 19:07:13 -06:00
|
|
|
}
|
2022-12-19 21:53:20 -06:00
|
|
|
_adminLogger.Add(LogType.Action, LogImpact.Medium,
|
2023-12-09 23:38:50 -06:00
|
|
|
$"{ToPrettyString(args.Microwave)} burnt {ToPrettyString(uid):entity}");
|
|
|
|
|
EntityManager.QueueDeleteEntity(uid);
|
|
|
|
|
return;
|
2022-02-12 17:53:54 -07:00
|
|
|
}
|
2024-06-14 22:00:00 -05:00
|
|
|
|
|
|
|
|
//Explode if the microwave can't handle it
|
|
|
|
|
if (!micro.CanMicrowaveIdsSafely)
|
|
|
|
|
{
|
|
|
|
|
_microwave.Explode((args.Microwave, micro));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-09 23:38:50 -06:00
|
|
|
// If they're unlucky, brick their ID
|
|
|
|
|
if (randomPick <= 0.25f)
|
2022-08-29 22:38:00 -04:00
|
|
|
{
|
2023-12-09 23:38:50 -06:00
|
|
|
_popupSystem.PopupEntity(Loc.GetString("id-card-component-microwave-bricked", ("id", uid)), uid);
|
2022-08-29 22:38:00 -04:00
|
|
|
|
2023-12-09 23:38:50 -06:00
|
|
|
access.Tags.Clear();
|
2024-02-13 22:48:39 +01:00
|
|
|
Dirty(uid, access);
|
2023-12-09 23:38:50 -06:00
|
|
|
|
|
|
|
|
_adminLogger.Add(LogType.Action, LogImpact.Medium,
|
|
|
|
|
$"{ToPrettyString(args.Microwave)} cleared access on {ToPrettyString(uid):entity}");
|
2022-08-29 22:38:00 -04:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-12-09 23:38:50 -06:00
|
|
|
_popupSystem.PopupEntity(Loc.GetString("id-card-component-microwave-safe", ("id", uid)), uid, PopupType.Medium);
|
2022-08-29 22:38:00 -04:00
|
|
|
}
|
2021-10-24 19:28:25 +11:00
|
|
|
|
2023-12-09 23:38:50 -06:00
|
|
|
// Give them a wonderful new access to compensate for everything
|
|
|
|
|
var random = _random.Pick(_prototypeManager.EnumeratePrototypes<AccessLevelPrototype>().ToArray());
|
2022-08-07 20:21:56 -03:00
|
|
|
|
2023-12-09 23:38:50 -06:00
|
|
|
access.Tags.Add(random.ID);
|
2024-02-13 22:48:39 +01:00
|
|
|
Dirty(uid, access);
|
2023-12-09 23:38:50 -06:00
|
|
|
|
|
|
|
|
_adminLogger.Add(LogType.Action, LogImpact.Medium,
|
|
|
|
|
$"{ToPrettyString(args.Microwave)} added {random.ID} access to {ToPrettyString(uid):entity}");
|
2024-06-14 22:00:00 -05:00
|
|
|
|
2021-10-22 05:31:07 +03:00
|
|
|
}
|
2023-12-09 23:38:50 -06:00
|
|
|
}
|
2021-10-22 05:31:07 +03:00
|
|
|
}
|