Skip to content
Open
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
19 changes: 18 additions & 1 deletion Content.Server/Station/Systems/StationJobsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Content.Server._DVA.Station.Events; // DeltaV - AutomaticSpareIdSystem

namespace Content.Server.Station.Systems;

Expand Down Expand Up @@ -111,6 +112,12 @@ public bool TryAssignJob(EntityUid station, string jobPrototypeId, NetUserId net

stationJobs.PlayerJobs.TryAdd(netUserId, new());
stationJobs.PlayerJobs[netUserId].Add(jobPrototypeId);

// DeltaV START - AutomaticSpareIdSystem: Raise an event when a player takes a job
var jobAddedEvent = new PlayerJobAddedEvent(netUserId, jobPrototypeId);
RaiseLocalEvent(station, ref jobAddedEvent, false);
// DeltaV END

return true;
}

Expand Down Expand Up @@ -207,7 +214,17 @@ public bool TryRemovePlayerJobs(EntityUid station,
if (!Resolve(station, ref jobsComponent, false))
return false;

return jobsComponent.PlayerJobs.Remove(userId);
// DeltaV START - AutomaticSpareIdSystem: Raise an event when a player loses jobs
if (jobsComponent.PlayerJobs.Remove(userId, out var jobs))
{
var jobsRemovedEvent = new PlayerJobsRemovedEvent(userId, jobs);
RaiseLocalEvent(station, ref jobsRemovedEvent, false);
return true;
}
return false;

// return jobsComponent.PlayerJobs.Remove(userId);
// DeltaV END
}

/// <inheritdoc cref="TrySetJobSlot(Robust.Shared.GameObjects.EntityUid,string,int,bool,Content.Server.Station.Components.StationJobsComponent?)"/>
Expand Down
7 changes: 7 additions & 0 deletions Content.Server/_DVA/Cabinet/DVSpareIDSafeComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Content.Server._DVA.Cabinet;

/// <summary>
/// Component that marks an entity as a spare ID safe. Is interacted with by DVAutomaticSpareIdSystem to unlock the safe when there is no captain present.
/// </summary>
[RegisterComponent]
public sealed partial class DVSpareIDSafeComponent : Component;
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
using Content.Server._DVA.Station.Systems;
using Content.Shared.Access;
using Content.Shared.Roles;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;

namespace Content.Server._DVA.Station.Components;

public enum AutomaticSpareIdState
{
RoundStart,
Alerted,
AwaitingUnlock,
Unlocked,
CaptainPresent,
WarOps
}

[RegisterComponent, Access(typeof(DVAutomaticSpareIdSystem)), AutoGenerateComponentPause]
public sealed partial class DVAutomaticSpareIdComponent : Component
{
/// <summary>
/// The current state of the automatic spare ID system
/// </summary>
[DataField]
public AutomaticSpareIdState State = AutomaticSpareIdState.RoundStart;

/// <summary>
/// Timeout before an action is taken if the state doesn't change
/// </summary>
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer)), AutoPausedField]
public TimeSpan? Timeout;

/// <summary>
/// The job considered as Captain for the automatic spare ID system
/// </summary>
[DataField]
public ProtoId<JobPrototype> CaptainJob = "Captain";

/// <summary>
/// The access that the spare ID safe will be extended to have if it is automatically unlocked
/// if there is no captain
/// </summary>
[DataField]
public ProtoId<AccessLevelPrototype> GrantAccessToCommand = "Command";

/// <summary>
/// The access that the spare ID safe will be extended to have if it is automatically unlocked
/// if there is a captain
/// </summary>
[DataField]
public ProtoId<AccessLevelPrototype> GrantAccessToCaptain = "Captain";

/// <summary>
/// Message for when a Captain joins after the system has alerted about their absence
/// </summary>
[DataField]
public LocId CaptainPresentAfterAlertsMessage = "captain-arrived-revoke-aco-announcement";

/// <summary>
/// Message for when the system alerts but isn't going to automatically unlock
/// </summary>
[DataField]
public LocId AlertedMessage = "no-captain-request-aco-vote-announcement";

/// <summary>
/// Message for when the system alerts and will automatically unlock
/// </summary>
[DataField]
public LocId AwaitingUnlockMessage = "no-captain-request-aco-vote-with-aa-announcement";

/// <summary>
/// Message for when the system alerts automatically unlock
/// </summary>
[DataField]
public LocId UnlockedMessage = "no-captain-aa-unlocked-announcement";

/// <summary>
/// The amount of time in which that the spare ID will unlock after nuclear operatives declare war.
/// </summary>
[DataField]
public TimeSpan WarOpsUnlockDelay = TimeSpan.FromSeconds(15);

/// <summary>
/// Message that will be displayed to the station when there is no captain and war ops is declared.
/// </summary>
[DataField]
public LocId WarOpsUnlockedMessageACO = "spare-id-warops-no-captain";

/// <summary>
/// Message that will be displayed to the station when there is a captain and war ops is declared.
/// </summary>
[DataField]
public LocId WarOpsUnlockedMessageCaptain = "spare-id-warops-captain";
Comment thread
JustTNE marked this conversation as resolved.
}
9 changes: 9 additions & 0 deletions Content.Server/_DVA/Station/Events/PlayerJobAddedEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Robust.Shared.Network;

namespace Content.Server._DVA.Station.Events;

/// <summary>
/// Event is raised when a player takes a job.
/// </summary>
[ByRefEvent]
public record struct PlayerJobAddedEvent(NetUserId Player, string JobPrototypeId);
11 changes: 11 additions & 0 deletions Content.Server/_DVA/Station/Events/PlayerJobsRemovedEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Robust.Shared.Network;
using Robust.Shared.Prototypes;
using Content.Shared.Roles;

namespace Content.Server._DVA.Station.Events;

/// <summary>
/// Event is raised when a player loses jobs.
/// </summary>
[ByRefEvent]
public record struct PlayerJobsRemovedEvent(NetUserId Player, List<ProtoId<JobPrototype>> PlayerJobs);
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Diagnostics;
using Content.Server._DVA.Station.Components;
using Content.Server._DVA.Station.Systems;
using Content.Server.Administration;
using Content.Shared.Administration;
using Robust.Shared.Toolshed;
using Robust.Shared.Toolshed.Errors;
using Robust.Shared.Utility;

namespace Robust.Shared._DVA.Station.Systems;

[ToolshedCommand(Name = "spareid"), AdminCommand(AdminFlags.Spawn)]
public sealed partial class DVAutomaticSpareIdSystemCommand : ToolshedCommand
{
[Dependency] private IEntityManager _entityManager = default!;
private DVAutomaticSpareIdSystem? _automaticSpareIdSystem;

[CommandImplementation("unlock")]
public void Unlock(IInvocationContext ctx, [PipedArgument] EntityUid stationUid, bool doAnnouncement)
{
_automaticSpareIdSystem ??= GetSys<DVAutomaticSpareIdSystem>();
if (!_entityManager.TryGetComponent<DVAutomaticSpareIdComponent>(stationUid, out var spareId))
{
ctx.ReportError(new AutomaticSpareIdSystemMissing());
return;
}
_automaticSpareIdSystem.ForceUnlock((stationUid, spareId), null, doAnnouncement ? "command-spareid-unlock-announcement" : null);
}
}

public record struct AutomaticSpareIdSystemMissing : IConError
{
public FormattedMessage DescribeInner()
{
return FormattedMessage.FromMarkupOrThrow("This command doesn't function if there is no automatic spare ID system. Common usage: stations:get | spareid:unlock true");
}

public string? Expression { get; set; }
public Vector2i? IssueSpan { get; set; }
public StackTrace? Trace { get; set; }
}
Loading
Loading