Skip to content

Commit 030b84c

Browse files
deltanedasIsNotAcceptable
authored andcommitted
Reapply "Port WWDP's Alert Level Locks for gunsafes (BohdanNovikov0207#48)" (BohdanNovikov0207#72) (BohdanNovikov0207#104)
* Reapply "Port WWDP's Alert Level Locks for gunsafes (BohdanNovikov0207#48)" (BohdanNovikov0207#72) This reverts commit 83bc10b2c28a6d81a8b35b9df319be1299eada9d. * cleanup and more prediction --------- Co-authored-by: deltanedas <@deltanedas:kde.org>
1 parent 5684a2f commit 030b84c

File tree

9 files changed

+166
-10
lines changed

9 files changed

+166
-10
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
using Content.Shared._White.Lockers;
2+
3+
namespace Content.Client._White.Lockers;
4+
5+
public sealed class StationAlertLevelLockSystem : SharedStationAlertLevelLockSystem;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using Content.Server.AlertLevel;
2+
using Content.Server.Station.Systems;
3+
using Content.Shared._White.Lockers;
4+
5+
namespace Content.Server._White.Lockers;
6+
7+
public sealed class StationAlertLevelLockSystem : SharedStationAlertLevelLockSystem
8+
{
9+
[Dependency] private readonly AlertLevelSystem _level = default!;
10+
[Dependency] private readonly StationSystem _station = default!;
11+
12+
public override void Initialize()
13+
{
14+
base.Initialize();
15+
16+
SubscribeLocalEvent<StationAlertLevelLockComponent, MapInitEvent>(OnInit);
17+
SubscribeLocalEvent<AlertLevelChangedEvent>(OnAlertChanged);
18+
}
19+
20+
public void OnInit(Entity<StationAlertLevelLockComponent> ent, ref MapInitEvent args)
21+
{
22+
// for non-station mapped safes don't lock them because that's chuddy
23+
if (_station.GetOwningStation(ent.Owner) is not {} station)
24+
{
25+
ent.Comp.Enabled = false;
26+
Dirty(ent);
27+
return;
28+
}
29+
30+
ent.Comp.StationId = station;
31+
ent.Comp.Enabled = true;
32+
33+
CheckAlertLevels(ent, _level.GetLevel(station));
34+
Dirty(ent);
35+
}
36+
37+
private void OnAlertChanged(AlertLevelChangedEvent args)
38+
{
39+
var query = EntityQueryEnumerator<StationAlertLevelLockComponent>();
40+
while (query.MoveNext(out var uid, out var comp))
41+
{
42+
var station = args.Station;
43+
if (station != comp.StationId)
44+
continue;
45+
46+
CheckAlertLevels((uid, comp), args.AlertLevel);
47+
}
48+
}
49+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using Content.Shared.Emag.Systems;
2+
using Content.Shared.Examine;
3+
using Content.Shared.Lock;
4+
using Content.Shared.Popups;
5+
using System.Linq;
6+
7+
namespace Content.Shared._White.Lockers;
8+
9+
public abstract class SharedStationAlertLevelLockSystem : EntitySystem
10+
{
11+
[Dependency] private readonly SharedPopupSystem _popup = default!;
12+
13+
public override void Initialize()
14+
{
15+
base.Initialize();
16+
17+
SubscribeLocalEvent<StationAlertLevelLockComponent, LockToggleAttemptEvent>(OnLockToggleAttempt);
18+
SubscribeLocalEvent<StationAlertLevelLockComponent, GotEmaggedEvent>(OnEmagged);
19+
SubscribeLocalEvent<StationAlertLevelLockComponent, ExaminedEvent>(OnExamined);
20+
}
21+
22+
private void OnLockToggleAttempt(Entity<StationAlertLevelLockComponent> ent, ref LockToggleAttemptEvent args)
23+
{
24+
if (!TryComp<LockComponent>(ent, out var lockComp))
25+
return;
26+
27+
var locking = !lockComp.Locked; // Allow locking even if the alert level is wrong
28+
if (!ent.Comp.Enabled || !ent.Comp.Locked || locking)
29+
return;
30+
31+
_popup.PopupClient(Loc.GetString("access-failed-wrong-station-alert-level"), ent.Owner, args.User);
32+
33+
args.Cancelled = true;
34+
}
35+
36+
private void OnEmagged(Entity<StationAlertLevelLockComponent> ent, ref GotEmaggedEvent args)
37+
{
38+
// don't waste multiple emag charges
39+
if (!ent.Comp.Enabled)
40+
return;
41+
42+
args.Handled = true;
43+
ent.Comp.Enabled = false;
44+
Dirty(ent);
45+
}
46+
47+
private void OnExamined(Entity<StationAlertLevelLockComponent> ent, ref ExaminedEvent args)
48+
{
49+
if (!ent.Comp.Enabled || ent.Comp.LockedAlertLevels.Count == 0)
50+
return;
51+
52+
var levels = string.Join(", ", ent.Comp.LockedAlertLevels.Select( s => Loc.GetString($"alert-level-{s}").ToLower()));
53+
54+
args.PushMarkup(Loc.GetString("station-alert-level-lock-examined", ("levels", levels)));
55+
}
56+
57+
protected void CheckAlertLevels(Entity<StationAlertLevelLockComponent> ent, string newAlertLevel)
58+
{
59+
ent.Comp.Locked = ent.Comp.LockedAlertLevels.Contains(newAlertLevel);
60+
Dirty(ent);
61+
}
62+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Robust.Shared.GameStates;
2+
3+
namespace Content.Shared._White.Lockers;
4+
5+
[RegisterComponent, NetworkedComponent, Access(typeof(SharedStationAlertLevelLockSystem))]
6+
[AutoGenerateComponentState]
7+
public sealed partial class StationAlertLevelLockComponent : Component
8+
{
9+
[DataField, AutoNetworkedField]
10+
public bool Enabled = true;
11+
12+
[DataField, AutoNetworkedField]
13+
public bool Locked = true;
14+
15+
[DataField]
16+
public HashSet<string> LockedAlertLevels = new();
17+
18+
[DataField, AutoNetworkedField]
19+
public EntityUid? StationId;
20+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
station-alert-level-lock-examined = It can not be unlocked at certain station alert levels: {$levels}.
2+
access-failed-wrong-station-alert-level = It won't open at this station alert level!

Resources/Prototypes/Catalog/Fills/Lockers/security.yml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,10 @@
310310
amount: 8
311311

312312
- type: entity
313-
parent: [GunSafeBaseSecure, BaseSecurityContraband]
313+
parent: [GunSafeBaseSecure, BaseSecurityContraband, AlertLevelLock] # WWDP
314314
id: GunSafeRifleLecter
315315
name: lecter safe
316+
suffix: Alert Level Lock # WWDP
316317
components:
317318
- type: EntityTableContainerFill
318319
containers:
@@ -329,9 +330,10 @@
329330
amount: 4
330331

331332
- type: entity
332-
parent: [GunSafeBaseSecure, BaseSecurityContraband]
333+
parent: [GunSafeBaseSecure, BaseSecurityContraband, AlertLevelLock] # WWDP
333334
id: GunSafeSubMachineGunDrozd
334335
name: drozd safe
336+
suffix: Alert Level Lock # WWDP
335337
components:
336338
- type: EntityTableContainerFill
337339
containers:
@@ -348,9 +350,10 @@
348350
amount: 4
349351

350352
- type: entity
351-
parent: [GunSafeBaseSecure, BaseSecurityContraband]
353+
parent: [GunSafeBaseSecure, BaseSecurityContraband, AlertLevelLock] # WWDP
352354
id: GunSafeShotgunEnforcer
353355
name: enforcer safe
356+
suffix: Alert Level Lock # WWDP
354357
components:
355358
- type: EntityTableContainerFill
356359
containers:
@@ -367,9 +370,10 @@
367370
amount: 4
368371

369372
- type: entity
370-
parent: [GunSafeBaseSecure, BaseSecurityContraband]
373+
parent: [GunSafeBaseSecure, BaseSecurityContraband, AlertLevelLock] # WWDP
371374
id: GunSafeShotgunKammerer
372375
name: kammerer safe
376+
suffix: Alert Level Lock # WWDP
373377
components:
374378
- type: EntityTableContainerFill
375379
containers:
@@ -387,9 +391,9 @@
387391

388392
- type: entity
389393
id: GunSafeSubMachineGunWt550
390-
suffix: Wt550
391-
parent: [GunSafeBaseSecure, BaseSecurityContraband]
394+
parent: [GunSafeBaseSecure, BaseSecurityContraband, AlertLevelLock] # WWDP
392395
name: wt550 safe
396+
suffix: Alert Level Lock # WWDP
393397
components:
394398
- type: EntityTableContainerFill
395399
containers:
@@ -406,9 +410,10 @@
406410
amount: 4
407411

408412
- type: entity
409-
parent: [GunSafeBaseSecure, BaseSecurityContraband]
413+
parent: [GunSafeBaseSecure, BaseSecurityContraband, AlertLevelLock] # WWDP
410414
id: GunSafeLaserCarbine
411415
name: laser safe
416+
suffix: Alert Level Lock # WWDP
412417
components:
413418
- type: EntityTableContainerFill
414419
containers:

Resources/Prototypes/Entities/Structures/Storage/Closets/Lockers/lockers.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,9 @@
461461
components:
462462
- type: AccessReader
463463
access: [["Armory"]]
464+
- type: Damageable # WWDP
465+
damageContainer: StructuralInorganic
466+
damageModifierSet: StructuralMetallicStrong
464467

465468
# Genpop Storage
466469
- type: entity

Resources/Prototypes/Entities/Structures/Storage/glass_box.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@
156156

157157
- type: entity
158158
id: GlassBoxLaserFilled
159-
parent: GlassBoxLaser
160-
suffix: AntiqueLaser, Filled
159+
parent: [GlassBoxLaser, AlertLevelLock] # WWDP
160+
suffix: AntiqueLaser, Filled, Alert Level Lock # WWDP
161161
components:
162162
- type: ContainerFill
163163
containers:
@@ -255,4 +255,4 @@
255255
min: 2
256256
max: 5
257257
- !type:DoActsBehavior
258-
acts: ["Destruction"]
258+
acts: ["Destruction"]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
- type: entity
2+
abstract: true
3+
id: AlertLevelLock
4+
components:
5+
- type: StationAlertLevelLock
6+
lockedAlertLevels:
7+
- green
8+
- blue
9+
- yellow
10+
- violet

0 commit comments

Comments
 (0)