Skip to content

Commit

Permalink
Sleeping inside bags (#882)
Browse files Browse the repository at this point in the history
* Implemented amimir

* Don't show popup if the pseudo-item is not inside a bag
  • Loading branch information
Mnemotechnician authored Jan 15, 2024
1 parent 428bada commit ddc744a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Content.Server.Item.PseudoItem;

/// <summary>
/// Signifies that pseudo-item creatures can sleep inside the container to which this component was added.
/// </summary>
[RegisterComponent]
public sealed partial class AllowsSleepInsideComponent : Component
{
}
23 changes: 23 additions & 0 deletions Content.Server/Nyanotrasen/Item/PseudoItem/PseudoItemSystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using Content.Server.Actions;
using Content.Server.Bed.Sleep;
using Content.Server.DoAfter;
using Content.Server.Popups;
using Content.Server.Storage.EntitySystems;
using Content.Shared.Bed.Sleep;
using Content.Shared.DoAfter;
using Content.Shared.Hands;
using Content.Shared.IdentityManagement;
Expand All @@ -18,6 +22,8 @@ public sealed class PseudoItemSystem : EntitySystem
[Dependency] private readonly ItemSystem _itemSystem = default!;
[Dependency] private readonly DoAfterSystem _doAfter = default!;
[Dependency] private readonly TagSystem _tagSystem = default!;
[Dependency] private readonly ActionsSystem _actions = default!; // Frontier
[Dependency] private readonly PopupSystem _popup = default!; // Frontier

[ValidatePrototypeId<TagPrototype>]
private const string PreventTag = "PreventLabel";
Expand All @@ -32,6 +38,7 @@ public override void Initialize()
SubscribeLocalEvent<PseudoItemComponent, DropAttemptEvent>(OnDropAttempt);
SubscribeLocalEvent<PseudoItemComponent, PseudoItemInsertDoAfterEvent>(OnDoAfter);
SubscribeLocalEvent<PseudoItemComponent, ContainerGettingInsertedAttemptEvent>(OnInsertAttempt);
SubscribeLocalEvent<PseudoItemComponent, TryingToSleepEvent>(OnTrySleeping); // Frontier
}

private void AddInsertVerb(EntityUid uid, PseudoItemComponent component, GetVerbsEvent<InnateVerb> args)
Expand Down Expand Up @@ -96,6 +103,10 @@ private void OnEntRemoved(EntityUid uid, PseudoItemComponent component, EntGotRe

RemComp<ItemComponent>(uid);
component.Active = false;

// Frontier
if (component.SleepAction is { Valid: true })
_actions.RemoveAction(uid, component.SleepAction);
}

private void OnGettingPickedUpAttempt(EntityUid uid, PseudoItemComponent component,
Expand Down Expand Up @@ -142,6 +153,10 @@ public bool TryInsert(EntityUid storageUid, EntityUid toInsert, PseudoItemCompon
return false;
}

// Frontier
if (HasComp<AllowsSleepInsideComponent>(storageUid))
_actions.AddAction(toInsert, ref component.SleepAction, SleepingSystem.SleepActionId, toInsert);

component.Active = true;
return true;
}
Expand Down Expand Up @@ -171,4 +186,12 @@ private void OnInsertAttempt(EntityUid uid, PseudoItemComponent component,
// This hopefully shouldn't trigger, but this is a failsafe just in case so we dont bluespace them cats
args.Cancel();
}

// Frontier - show a popup when a pseudo-item falls asleep inside a bag.
private void OnTrySleeping(EntityUid uid, PseudoItemComponent component, TryingToSleepEvent args)
{
var parent = Transform(uid).ParentUid;
if (!HasComp<SleepingComponent>(uid) && parent is { Valid: true } && HasComp<AllowsSleepInsideComponent>(parent))
_popup.PopupEntity(Loc.GetString("popup-sleep-in-bag", ("entity", uid)), uid);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ public sealed partial class PseudoItemComponent : Component, ITransferredByCloni
public int Size = 120;

public bool Active = false;

[DataField]
public EntityUid? SleepAction;
}
1 change: 1 addition & 0 deletions Resources/Locale/en-US/_NF/actions/sleep.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
popup-sleep-in-bag = {THE($entity)} curls up and falls asleep.
1 change: 1 addition & 0 deletions Resources/Prototypes/Entities/Clothing/Back/backpacks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
# to prevent bag open/honk spam
- type: UseDelay
delay: 0.5
- type: AllowsSleepInside

- type: entity
parent: ClothingBackpack
Expand Down

0 comments on commit ddc744a

Please sign in to comment.