Skip to content

Commit

Permalink
Merge pull request #13 from Eagle-0/Grabintent
Browse files Browse the repository at this point in the history
Grabintent
  • Loading branch information
Eagle-0 authored Aug 28, 2024
2 parents eff0a2b + 3b97a83 commit 3c9c996
Show file tree
Hide file tree
Showing 41 changed files with 1,321 additions and 164 deletions.
1 change: 0 additions & 1 deletion Content.Client/Buckle/BuckleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ private void OnAppearanceChange(EntityUid uid, BuckleComponent component, ref Ap
!buckled ||
args.Sprite == null)
{
_rotationVisualizerSystem.SetHorizontalAngle((uid, rotVisuals), rotVisuals.DefaultRotation);
return;
}

Expand Down
9 changes: 9 additions & 0 deletions Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Numerics;
using Content.Client.Stylesheets;
using Content.Client.Options.UI.Tabs;
using Content.Shared._White;
using Content.Shared.CCVar;
using Content.Shared.Input;
using Robust.Client.AutoGenerated;
Expand Down Expand Up @@ -103,6 +105,12 @@ private void HandleStaticStorageUI(BaseButton.ButtonToggledEventArgs args)
_cfg.SaveToFile();
}

private void HandleToggleAutoGetUp(BaseButton.ButtonToggledEventArgs args) // WD EDIT
{
_cfg.SetCVar(WhiteCVars.AutoGetUp, args.Pressed);
_cfg.SaveToFile();
}

public KeyRebindTab()
{
IoCManager.InjectDependencies(this);
Expand Down Expand Up @@ -186,6 +194,7 @@ void AddCheckBox(string checkBoxName, bool currentState, Action<BaseButton.Butto
AddButton(ContentKeyFunctions.OfferItem);
AddButton(ContentKeyFunctions.SaveItemLocation);
AddButton(ContentKeyFunctions.ToggleStanding);
AddCheckBox("ui-options-function-auto-get-up", _cfg.GetCVar(WhiteCVars.AutoGetUp), HandleToggleAutoGetUp); // WD EDIT

AddHeader("ui-options-header-interaction-adv");
AddButton(ContentKeyFunctions.SmartEquipBackpack);
Expand Down
82 changes: 82 additions & 0 deletions Content.Client/_White/Standing/LayingDownSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using Content.Shared._White.Standing;
using Content.Shared.Buckle;
using Content.Shared.Rotation;
using Content.Shared.Standing;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Shared.Timing;

namespace Content.Client._White.Standing;

public sealed class LayingDownSystem : SharedLayingDownSystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IEyeManager _eyeManager = default!;
[Dependency] private readonly StandingStateSystem _standing = default!;
[Dependency] private readonly AnimationPlayerSystem _animation = default!;
[Dependency] private readonly SharedBuckleSystem _buckle = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<LayingDownComponent, MoveEvent>(OnMovementInput);

SubscribeNetworkEvent<CheckAutoGetUpEvent>(OnCheckAutoGetUp);
}

private void OnMovementInput(EntityUid uid, LayingDownComponent component, MoveEvent args)
{
if (!_timing.IsFirstTimePredicted)
return;

if (!_standing.IsDown(uid))
return;

if (_buckle.IsBuckled(uid))
return;

if (_animation.HasRunningAnimation(uid, "rotate"))
return;

if (!TryComp<TransformComponent>(uid, out var transform)
|| !TryComp<SpriteComponent>(uid, out var sprite)
|| !TryComp<RotationVisualsComponent>(uid, out var rotationVisuals))
{
return;
}

var rotation = transform.LocalRotation + (_eyeManager.CurrentEye.Rotation - (transform.LocalRotation - transform.WorldRotation));

if (rotation.GetDir() is Direction.SouthEast or Direction.East or Direction.NorthEast or Direction.North)
{
rotationVisuals.HorizontalRotation = Angle.FromDegrees(270);
sprite.Rotation = Angle.FromDegrees(270);
return;
}

rotationVisuals.HorizontalRotation = Angle.FromDegrees(90);
sprite.Rotation = Angle.FromDegrees(90);
}

private void OnCheckAutoGetUp(CheckAutoGetUpEvent ev, EntitySessionEventArgs args)
{
if (!_timing.IsFirstTimePredicted)
return;

var uid = GetEntity(ev.User);

if (!TryComp<TransformComponent>(uid, out var transform) || !TryComp<RotationVisualsComponent>(uid, out var rotationVisuals))
return;

var rotation = transform.LocalRotation + (_eyeManager.CurrentEye.Rotation - (transform.LocalRotation - transform.WorldRotation));

if (rotation.GetDir() is Direction.SouthEast or Direction.East or Direction.NorthEast or Direction.North)
{
rotationVisuals.HorizontalRotation = Angle.FromDegrees(270);
return;
}

rotationVisuals.HorizontalRotation = Angle.FromDegrees(90);
}
}
2 changes: 1 addition & 1 deletion Content.Server/Alert/Click/StopPulling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void AlertClicked(EntityUid player)
if (entManager.TryGetComponent(player, out PullerComponent? puller) &&
entManager.TryGetComponent(puller.Pulling, out PullableComponent? pullableComp))
{
ps.TryStopPull(puller.Pulling.Value, pullableComp, user: player);
ps.TryLowerGrabStage(puller.Pulling.Value, player, true);
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion Content.Server/Body/Systems/RespiratorSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using Content.Shared.Database;
using Content.Shared.Mobs.Systems;
using Content.Shared.Mood;
using Content.Shared.Movement.Pulling.Components;
using Content.Shared.Movement.Pulling.Systems;
using JetBrains.Annotations;
using Robust.Shared.Timing;

Expand Down Expand Up @@ -51,6 +53,13 @@ private void OnUnpaused(Entity<RespiratorComponent> ent, ref EntityUnpausedEvent
ent.Comp.NextUpdate += args.PausedTime;
}

public bool CanBreathe(EntityUid uid)
{
if (TryComp<PullableComponent>(uid, out var pullable) && pullable.GrabStage == GrabStage.Suffocate)
return false;
return true;
}

public override void Update(float frameTime)
{
base.Update(frameTime);
Expand Down Expand Up @@ -83,7 +92,7 @@ public override void Update(float frameTime)
}
}

if (respirator.Saturation < respirator.SuffocationThreshold)
if (respirator.Saturation < respirator.SuffocationThreshold || !CanBreathe(uid))
{
if (_gameTiming.CurTime >= respirator.LastGaspPopupTime + respirator.GaspPopupCooldown)
{
Expand Down
24 changes: 23 additions & 1 deletion Content.Server/Hands/Systems/HandsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Content.Shared.Body.Part;
using Content.Shared.CombatMode;
using Content.Shared.Explosion;
using Content.Shared.Hands;
using Content.Shared.Hands.Components;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Input;
Expand Down Expand Up @@ -88,7 +89,7 @@ private void OnDisarmed(EntityUid uid, HandsComponent component, DisarmedEvent a

// Break any pulls
if (TryComp(uid, out PullerComponent? puller) && TryComp(puller.Pulling, out PullableComponent? pullable))
_pullingSystem.TryStopPull(puller.Pulling.Value, pullable);
_pullingSystem.TryStopPull(puller.Pulling.Value, pullable, ignoreGrab: true);

if (!_handsSystem.TryDrop(uid, component.ActiveHand!, null, checkActionBlocker: false))
return;
Expand Down Expand Up @@ -168,6 +169,18 @@ private bool HandleThrowItem(ICommonSession? playerSession, EntityCoordinates co
if (playerSession?.AttachedEntity is not {Valid: true} player || !Exists(player))
return false;

if (TryGetActiveItem(player, out var item) && TryComp<VirtualItemComponent>(item, out var virtComp))
{
var userEv = new VirtualItemDropAttemptEvent(virtComp.BlockingEntity, player, item.Value, true);
RaiseLocalEvent(player, userEv);

var targEv = new VirtualItemDropAttemptEvent(virtComp.BlockingEntity, player, item.Value, true);
RaiseLocalEvent(virtComp.BlockingEntity, targEv);

if (userEv.Cancelled || targEv.Cancelled)
return false;
}

return ThrowHeldItem(player, coordinates);
}

Expand Down Expand Up @@ -211,6 +224,15 @@ hands.ActiveHandEntity is not { } throwEnt ||
var ev = new BeforeThrowEvent(throwEnt, direction, throwStrength, player);
RaiseLocalEvent(player, ref ev);

if (TryComp<VirtualItemComponent>(throwEnt, out var virt))
{
var userEv = new VirtualItemThrownEvent(virt.BlockingEntity, player, throwEnt, direction);
RaiseLocalEvent(player, userEv);

var targEv = new VirtualItemThrownEvent(virt.BlockingEntity, player, throwEnt, direction);
RaiseLocalEvent(virt.BlockingEntity, targEv);
}

if (ev.Cancelled)
return true;

Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Implants/SubdermalImplantSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private void OnScramImplant(EntityUid uid, SubdermalImplantComponent component,
// We need stop the user from being pulled so they don't just get "attached" with whoever is pulling them.
// This can for example happen when the user is cuffed and being pulled.
if (TryComp<PullableComponent>(ent, out var pull) && _pullingSystem.IsPulled(ent, pull))
_pullingSystem.TryStopPull(ent, pull);
_pullingSystem.TryStopPull(ent, pull, ignoreGrab: true);

var xform = Transform(ent);
var targetCoords = SelectRandomTileInRange(xform, implant.TeleportRadius);
Expand Down
14 changes: 0 additions & 14 deletions Content.Server/Standing/LayingDownComponent.cs

This file was deleted.

97 changes: 12 additions & 85 deletions Content.Server/Standing/LayingDownSystem.cs
Original file line number Diff line number Diff line change
@@ -1,101 +1,28 @@
using Content.Shared.ActionBlocker;
using Content.Shared.Input;
using Content.Shared.Movement.Systems;
using Content.Shared.Popups;
using Content.Shared.Standing;
using Robust.Shared.Input.Binding;
using Robust.Shared.Player;
using Robust.Shared.Timing;
using Content.Shared._White;
using Content.Shared._White.Standing;
using Robust.Shared.Configuration;

namespace Content.Server.Standing;

/// <remarks>Unfortunately cannot be shared because some standing conditions are server-side only</remarks>
public sealed class LayingDownSystem : EntitySystem
public sealed class LayingDownSystem : SharedLayingDownSystem // WD EDIT
{
[Dependency] private readonly ActionBlockerSystem _actionBlocker = default!;
[Dependency] private readonly MovementSpeedModifierSystem _movement = default!;
[Dependency] private readonly SharedPopupSystem _popups = default!;
[Dependency] private readonly Shared.Standing.StandingStateSystem _standing = default!; // WHY IS THERE TWO DIFFERENT STANDING SYSTEMS?!
[Dependency] private readonly IGameTiming _timing = default!;

[Dependency] private readonly INetConfigurationManager _cfg = default!;

public override void Initialize()
{
CommandBinds.Builder
.Bind(ContentKeyFunctions.ToggleStanding, InputCmdHandler.FromDelegate(ToggleStanding, handle: false, outsidePrediction: false))
.Register<LayingDownSystem>();

SubscribeLocalEvent<LayingDownComponent, StoodEvent>(DoRefreshMovementSpeed);
SubscribeLocalEvent<LayingDownComponent, DownedEvent>(DoRefreshMovementSpeed);
SubscribeLocalEvent<LayingDownComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovementSpeed);
SubscribeLocalEvent<LayingDownComponent, EntParentChangedMessage>(OnParentChanged);
}

public override void Shutdown()
{
base.Shutdown();

CommandBinds.Unregister<LayingDownSystem>();
}
base.Initialize();

private void DoRefreshMovementSpeed(EntityUid uid, LayingDownComponent component, object args)
{
_movement.RefreshMovementSpeedModifiers(uid);
SubscribeNetworkEvent<CheckAutoGetUpEvent>(OnCheckAutoGetUp);
}

private void OnRefreshMovementSpeed(EntityUid uid, LayingDownComponent component, RefreshMovementSpeedModifiersEvent args)
private void OnCheckAutoGetUp(CheckAutoGetUpEvent ev, EntitySessionEventArgs args)
{
if (TryComp<StandingStateComponent>(uid, out var standingState) && standingState.Standing)
return;
var uid = GetEntity(ev.User);

args.ModifySpeed(component.DownedSpeedMultiplier, component.DownedSpeedMultiplier, bypassImmunity: true);
}

private void OnParentChanged(EntityUid uid, LayingDownComponent component, EntParentChangedMessage args)
{
// If the entity is not on a grid, try to make it stand up to avoid issues
if (!TryComp<StandingStateComponent>(uid, out var standingState)
|| standingState.Standing
|| Transform(uid).GridUid != null)
if (!TryComp(uid, out LayingDownComponent? layingDown))
return;

_standing.Stand(uid, standingState);
}

private void ToggleStanding(ICommonSession? session)
{
if (session is not { AttachedEntity: { Valid: true } uid } playerSession
|| !Exists(uid)
|| !TryComp<StandingStateComponent>(uid, out var standingState)
|| !TryComp<LayingDownComponent>(uid, out var layingDown))
return;

// If successful, show popup to self and others. Otherwise, only to self.
if (ToggleStandingImpl(uid, standingState, layingDown, out var popupBranch))
{
_popups.PopupEntity(Loc.GetString($"laying-comp-{popupBranch}-other", ("entity", uid)), uid, Filter.PvsExcept(uid), true);
layingDown.NextToggleAttempt = _timing.CurTime + layingDown.Cooldown;
}

_popups.PopupEntity(Loc.GetString($"laying-comp-{popupBranch}-self", ("entity", uid)), uid, uid);
}

private bool ToggleStandingImpl(EntityUid uid, StandingStateComponent standingState, LayingDownComponent layingDown, out string popupBranch)
{
var success = layingDown.NextToggleAttempt <= _timing.CurTime;

if (_standing.IsDown(uid, standingState))
{
success = success && _standing.Stand(uid, standingState, force: false);
popupBranch = success ? "stand-success" : "stand-fail";
}
else
{
success = success && Transform(uid).GridUid != null; // Do not allow laying down when not on a surface.
success = success && _standing.Down(uid, standingState: standingState, playSound: true, dropHeldItems: false);
popupBranch = success ? "lay-success" : "lay-fail";
}

return success;
layingDown.AutoGetUp = _cfg.GetClientCVar(args.SenderSession.Channel, WhiteCVars.AutoGetUp);
Dirty(uid, layingDown);
}
}
6 changes: 3 additions & 3 deletions Content.Server/Traits/Assorted/LayingDownModifierSystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Content.Server.Traits.Assorted;
using Content.Server.Standing;
using Content.Shared._White.Standing;

namespace Content.Shared.Traits.Assorted.Systems;

Expand All @@ -16,7 +16,7 @@ private void OnStartup(EntityUid uid, LayingDownModifierComponent component, Com
if (!TryComp<LayingDownComponent>(uid, out var layingDown))
return;

layingDown.Cooldown *= component.LayingDownCooldownMultiplier;
layingDown.DownedSpeedMultiplier *= component.DownedSpeedMultiplierMultiplier;
layingDown.StandingUpTime *= component.LayingDownCooldownMultiplier;
layingDown.SpeedModify *= component.DownedSpeedMultiplierMultiplier;
}
}
2 changes: 1 addition & 1 deletion Content.Shared/Administration/AdminFrozenSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private void OnStartup(EntityUid uid, AdminFrozenComponent component, ComponentS
{
if (TryComp<PullableComponent>(uid, out var pullable))
{
_pulling.TryStopPull(uid, pullable);
_pulling.TryStopPull(uid, pullable, ignoreGrab: true);
}

UpdateCanMove(uid, component, args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private void OnAnchorComplete(EntityUid uid, AnchorableComponent component, TryA

if (TryComp<PullableComponent>(uid, out var pullable) && pullable.Puller != null)
{
_pulling.TryStopPull(uid, pullable);
_pulling.TryStopPull(uid, pullable, ignoreGrab: true);
}

// TODO: Anchoring snaps rn anyway!
Expand Down
Loading

0 comments on commit 3c9c996

Please sign in to comment.