Skip to content

Commit

Permalink
Add power requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
Erisfiregamer1 committed Jan 18, 2025
1 parent ed8c8de commit cbbc89f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Content.Shared/_Arcadis/Computer/ModularComputerComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ public sealed partial class ModularComputerComponent : Component

[DataField]
public SoundSpecifier? DiskInsertSound = new SoundPathSpecifier("/Audio/_Arcadis/computer_startup.ogg");

[DataField]

public bool RequiresPower = true;
}
15 changes: 14 additions & 1 deletion Content.Shared/_Arcadis/Computer/ModularComputerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Content.Shared.Examine;
using Content.Shared.Interaction;
using Robust.Shared.Timing;
using Content.Shared.Power.EntitySystems;

namespace Content.Shared._Arcadis.Computer;

Expand All @@ -28,6 +29,8 @@ public sealed class ModularComputerSystem : EntitySystem

[Dependency] private readonly IGameTiming _gameTiming = default!;

[Dependency] private readonly SharedPowerReceiverSystem _power = default!;

public string BlankDiskPrototype = "UnburnedDiskPrototype";
public override void Initialize()
{
Expand All @@ -49,6 +52,9 @@ private void OnExamined(EntityUid uid, ModularComputerComponent component, Exami
|| !_itemSlots.TryGetSlot(uid, component.DiskSlot, out var diskSlot, slots))
return;

if (component.RequiresPower && _power.IsPowered(uid) == false)
return;

if (diskSlot.Item == null || !TryComp(diskSlot.Item, out ComputerDiskComponent? diskComp))
{
args.PushMarkup(Loc.GetString("modular-computer-examine-no-disk"));
Expand All @@ -70,6 +76,12 @@ private void OnActivate(EntityUid uid, ModularComputerComponent component, Activ
|| !_itemSlots.TryGetSlot(uid, component.DiskSlot, out var diskSlot, slots))
return;

if (component.RequiresPower && _power.IsPowered(uid) == false)
{
_popupSystem.PopupPredicted(Loc.GetString("modular-computer-no-power"), uid, args.User);
return;
}

if (diskSlot.Item == null || !TryComp(diskSlot.Item, out ComputerDiskComponent? diskComp))
{
_popupSystem.PopupPredicted(Loc.GetString("modular-computer-no-program"), uid, args.User);
Expand All @@ -82,7 +94,8 @@ private void OnActivate(EntityUid uid, ModularComputerComponent component, Activ
return;
}

if (_netMan.IsServer) { // Has to run only on server or mispredict opens 2 seperate UIs. Very bad.
if (_netMan.IsServer) // Has to run only on server or mispredict opens 2 seperate UIs. Very bad.
{
var activateMsg = new ActivateInWorldEvent(args.User, diskComp.ProgramPrototypeEntity.Value, true);
RaiseLocalEvent(diskComp.ProgramPrototypeEntity.Value, activateMsg);
}
Expand Down
2 changes: 2 additions & 0 deletions Resources/Locale/en-US/_Arcadis/modularComputer.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ modular-computer-examine-no-disk = This computer doesn't have a program loaded.
modular-computer-examine-disk-error = This computer doesn't have a program loaded. An error on the display reports that the loaded disk has no program.
modular-computer-examine-has-program = This computer has the {$program} program loaded.
modular-computer-no-power = The computer is unpowered.
program-disk-no-program = This disk has no program burnt to it.
program-disk-error = This disk has a corrupted program burnt to it.
program-disk-has-program = This disk has the {$program} program burnt to it.
Expand Down

0 comments on commit cbbc89f

Please sign in to comment.