CatStation/Content.Server/Foldable/FoldableSystem.cs
Morbo fe139a9e93
Fork sync (#40)
* Fix use delay (#6031)

* Add small railing corner (#6036)

* Add more chat filters (#6034)

* Xeno improvements (#6032)

* Automatic changelog update

* Removed capsaicin oil from the chem dispenser (#6042)

* Automatic changelog update

* Add ability to resist out of welded lockers and locked closets (#5958)

* Enable lighting of Cigars with IsHotEvent

Subscribed to IsHotEvent in ThrusterSystem, added AfterInteractEvent to SmokingSystem.Cigar which will set SmokableState to Lit if IsHotEvent returns true

This should mean that cigs/Cigars should light on anything hot

* Revert "Enable lighting of Cigars with IsHotEvent"

This reverts commit db896e1f80940892a87d34aa7182b9c605fa53bc.

* Add the ability to kick your way out of welded or locked closets

Added a ResistLocker component/system that hooks into OnRelayMove to begin resisting out of lockers so that players aren't stuck in lockers forever

Also added check to EntityStorageComponent to not print out welded shut message if the entity attempting to open the locker is inside of it.

* Changes based on review

minor formatting changes

make components passed into AttemptResist nullable and resolve them inside of the function

Remove incorrectly named .ftl file

* Changes based on review

Ditched async DoAfter
Used PopupSystem over User.PopupMessage

Added Cancel token to ResistLockerComponent

Subscribed to EntRemovedFromContainer event to cancel DoAfter if the player is removed from a container

* I am in formatting hell, apparently

* Changes based on review

Added TryComp for the EntityStorageComponent instead of the event passed one

* Changes based on review

* Apply suggestions from code review

Co-authored-by: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com>

* Formatting changes based on review

* Shuffle functions around in LockSystem to properly trigger visualizer

Moved all the unlocking logic to a Lock method inside of LockSystem and TryUnlock calls this method if the user passes all of the access checks

* Formatting, replacing Resolve with TryComp and making AttemptResist arguments optional

Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com>

* Check if the player is inside THE container not A container

me no read good

* ok ok I give my code is bad

Co-authored-by: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com>
Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com>

* Automatic changelog update

* Make smoking cool again. (#6046)

* Automatic changelog update

* Fixes minor issues with Reach and Dart. (#6035)

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>

* Automatic changelog update

* Adds filled versions of coloured wardrobes (#6012)

* Automatic changelog update

* Add content to radiation closets and medicine lockers (#6006)

* Automatic changelog update

* Interrupt do-afters when the user gets incapacitated. (#6059)

* Fix foldable-pickup interactions. (#6057)

Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Co-authored-by: Delete69 <95458399+Delete69@users.noreply.github.com>
Co-authored-by: ZeroDayDaemon <60460608+ZeroDayDaemon@users.noreply.github.com>
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Co-authored-by: PJBot <pieterjan.briers+bot@gmail.com>
Co-authored-by: Rane <60792108+Elijahrane@users.noreply.github.com>
Co-authored-by: JustinTime <41876089+JustinTether@users.noreply.github.com>
Co-authored-by: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com>
Co-authored-by: LittleBuilderJane <63973502+LittleBuilderJane@users.noreply.github.com>
Co-authored-by: Lamrr <96937466+Lamrr@users.noreply.github.com>
2022-01-07 20:25:22 +03:00

110 lines
3.7 KiB
C#

using System.Linq;
using Content.Server.Buckle.Components;
using Content.Server.Storage.Components;
using Content.Shared.Foldable;
using Content.Shared.Verbs;
using JetBrains.Annotations;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
namespace Content.Server.Foldable
{
[UsedImplicitly]
public sealed class FoldableSystem : SharedFoldableSystem
{
[Dependency] private SharedContainerSystem _container = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<FoldableComponent, StorageOpenAttemptEvent>(OnFoldableOpenAttempt);
SubscribeLocalEvent<FoldableComponent, GetAlternativeVerbsEvent>(AddFoldVerb);
}
private void OnFoldableOpenAttempt(EntityUid uid, FoldableComponent component, StorageOpenAttemptEvent args)
{
if (component.IsFolded)
args.Cancel();
}
public bool TryToggleFold(FoldableComponent comp)
{
return TrySetFolded(comp, !comp.IsFolded);
}
public bool CanToggleFold(EntityUid uid, FoldableComponent? fold = null)
{
if (!Resolve(uid, ref fold))
return false;
// Can't un-fold in hands / inventory
if (_container.IsEntityInContainer(uid))
return false;
// If an entity is buckled to the object we can't pick it up or fold it
if (TryComp(uid, out StrapComponent? strap) && strap.BuckledEntities.Any())
return false;
// Also check if this entity is "open" (e.g., body bags)
return !TryComp(uid, out EntityStorageComponent? storage) || !storage.Open;
}
/// <summary>
/// Try to fold/unfold
/// </summary>
/// <param name="comp"></param>
/// <param name="state">Folded state we want</param>
/// <returns>True if successful</returns>
public bool TrySetFolded(FoldableComponent comp, bool state)
{
if (state == comp.IsFolded)
return false;
if (!CanToggleFold(comp.Owner, comp))
return false;
SetFolded(comp, state);
return true;
}
/// <summary>
/// Set the folded state of the given <see cref="FoldableComponent"/>
/// </summary>
/// <param name="component"></param>
/// <param name="folded">If true, the component will become folded, else unfolded</param>
public override void SetFolded(FoldableComponent component, bool folded)
{
base.SetFolded(component, folded);
// You can't buckle an entity to a folded object
if (TryComp(component.Owner, out StrapComponent? strap))
strap.Enabled = !component.IsFolded;
}
#region Verb
private void AddFoldVerb(EntityUid uid, FoldableComponent component, GetAlternativeVerbsEvent args)
{
if (!args.CanAccess || !args.CanInteract || !CanToggleFold(uid, component))
return;
Verb verb = new()
{
Act = () => TryToggleFold(component),
Text = component.IsFolded ? Loc.GetString("unfold-verb") : Loc.GetString("fold-verb"),
IconTexture = "/Textures/Interface/VerbIcons/fold.svg.192dpi.png",
// If the object is unfolded and they click it, they want to fold it, if it's folded, they want to pick it up
Priority = component.IsFolded ? 0 : 2,
};
args.Verbs.Add(verb);
}
#endregion
}
}