Skip to content

Commit

Permalink
Restore AutoWakeUpComponent function (new-frontiers-14#2540)
Browse files Browse the repository at this point in the history
* Restore AutoWakeUpComponent function

* AutoWakeUp: cure drowsiness
  • Loading branch information
whatston3 authored Dec 10, 2024
1 parent cc69ddd commit 0c94a1c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
13 changes: 0 additions & 13 deletions Content.Shared/Bed/Sleep/AutoWakeUpComponent.cs

This file was deleted.

23 changes: 23 additions & 0 deletions Content.Shared/Bed/Sleep/SleepingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using Robust.Shared.Audio.Systems;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
using Content.Shared._NF.Bed.Sleep; // Frontier

namespace Content.Shared.Bed.Sleep;

Expand Down Expand Up @@ -261,6 +262,10 @@ public bool TrySleeping(Entity<MobStateComponent?> ent)
return false;

EnsureComp<SleepingComponent>(ent);
// Frontier: set auto-wakeup time
if (TryComp<AutoWakeUpComponent>(ent, out var autoWakeUp))
autoWakeUp.NextWakeUp = _gameTiming.CurTime + autoWakeUp.Length;
// End Frontier: auto-wakeup
return true;
}

Expand Down Expand Up @@ -317,6 +322,24 @@ public void OnEmoteAttempt(Entity<SleepingComponent> ent, ref EmoteAttemptEvent
{
args.Cancel();
}

/// <summary>
/// Frontier: handle auto-wakeup
/// </summary>
public override void Update(float frameTime)
{
var query = EntityQueryEnumerator<AutoWakeUpComponent, SleepingComponent>();
var curTime = _gameTiming.CurTime;
while (query.MoveNext(out var uid, out var wakeUp, out var sleeping))
{
if (curTime >= wakeUp.NextWakeUp)
{
Wake((uid, sleeping));
_statusEffectsSystem.TryRemoveStatusEffect(uid, "Drowsiness");
}
}
}

}


Expand Down
19 changes: 19 additions & 0 deletions Content.Shared/_NF/Bed/AutoWakeUpComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Robust.Shared.GameStates;

namespace Content.Shared._NF.Bed.Sleep;

/// <summary>
/// Frontier - Added to AI to allow auto waking up after 5 secs.
/// </summary>
[NetworkedComponent, RegisterComponent]
[AutoGenerateComponentState, AutoGenerateComponentPause(Dirty = true)]
public sealed partial class AutoWakeUpComponent : Component
{
// The length of time, in seconds, to sleep
[DataField]
public TimeSpan Length = TimeSpan.FromSeconds(5);

[ViewVariables]
[AutoNetworkedField, AutoPausedField]
public TimeSpan NextWakeUp = TimeSpan.Zero;
}

0 comments on commit 0c94a1c

Please sign in to comment.