Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
Final fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Rubinov committed Jun 20, 2024
1 parent d6ab3d8 commit 14fd1c9
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 162 deletions.
254 changes: 127 additions & 127 deletions Content.Shared/LieDown/SharedLieDownSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,163 +9,163 @@
using Robust.Shared.Input.Binding;
using Robust.Shared.Player;

namespace Content.Shared.LieDown
namespace Content.Shared.LieDown;

public class SharedLieDownSystem : EntitySystem
{
public class SharedLieDownSystem : EntitySystem
[Dependency] private readonly SharedActionsSystem _actions = default!;
[Dependency] private readonly MovementSpeedModifierSystem _movement = default!;
[Dependency] private readonly StandingStateSystem _standing = default!;

public override void Initialize()
{
[Dependency] private readonly SharedActionsSystem _actions = default!;
[Dependency] private readonly MovementSpeedModifierSystem _movement = default!;
[Dependency] private readonly StandingStateSystem _standing = default!;
SubscribeLocalEvent<LyingDownComponent, InteractHandEvent>(OnInteractHand);
SubscribeLocalEvent<LyingDownComponent, GetVerbsEvent<AlternativeVerb>>(AddStandUpVerb);
SubscribeLocalEvent<LyingDownComponent, ExaminedEvent>(OnExamined);
SubscribeLocalEvent<LyingDownComponent, RefreshMovementSpeedModifiersEvent>(OnRefresh);

SubscribeLocalEvent<LyingDownComponent, ComponentStartup>(OnComponentStartup);
SubscribeLocalEvent<LyingDownComponent, ComponentShutdown>(OnComponentShutdown);

// Bind keybinds to lie down action
SubscribeNetworkEvent<ChangeStandingStateEvent>(OnChangeAction);
CommandBinds.Builder
.Bind(ContentKeyFunctions.LieDownStandUp, InputCmdHandler.FromDelegate(ChangeLyingState))
.Register<SharedLieDownSystem>();
}

public override void Initialize()
{
SubscribeLocalEvent<LyingDownComponent, InteractHandEvent>(OnInteractHand);
SubscribeLocalEvent<LyingDownComponent, GetVerbsEvent<AlternativeVerb>>(AddStandUpVerb);
SubscribeLocalEvent<LyingDownComponent, ExaminedEvent>(OnExamined);
SubscribeLocalEvent<LyingDownComponent, RefreshMovementSpeedModifiersEvent>(OnRefresh);

SubscribeLocalEvent<LyingDownComponent, ComponentStartup>(OnComponentStartup);
SubscribeLocalEvent<LyingDownComponent, ComponentShutdown>(OnComponentShutdown);

// Bind keybinds to lie down action
SubscribeNetworkEvent<ChangeStandingStateEvent>(OnChangeAction);
CommandBinds.Builder
.Bind(ContentKeyFunctions.LieDownStandUp, InputCmdHandler.FromDelegate(ChangeLyingState))
.Register<SharedLieDownSystem>();
}
private void OnComponentShutdown(EntityUid uid, LyingDownComponent component, ComponentShutdown args)
{
SwitchActions(uid);
_movement.RefreshMovementSpeedModifiers(uid);
}

private void OnComponentShutdown(EntityUid uid, LyingDownComponent component, ComponentShutdown args)
{
SwitchActions(uid);
_movement.RefreshMovementSpeedModifiers(uid);
}
private void OnComponentStartup(EntityUid uid, LyingDownComponent component, ComponentStartup args)
{
SwitchActions(uid);
_movement.RefreshMovementSpeedModifiers(uid);
}

/// <summary>
/// Send an update event when player pressed keybind.
/// </summary>
private void ChangeLyingState(ICommonSession? session)
{
RaiseNetworkEvent(new ChangeStandingStateEvent());
}

private void OnComponentStartup(EntityUid uid, LyingDownComponent component, ComponentStartup args)
/// <summary>
/// Process player event, that pressed keybind.
/// </summary>
private void OnChangeAction(ChangeStandingStateEvent msg, EntitySessionEventArgs args)
{
if (!args.SenderSession.AttachedEntity.HasValue)
return;

var uid = args.SenderSession.AttachedEntity.Value;
if (_standing.IsDown(uid))
{
SwitchActions(uid);
_movement.RefreshMovementSpeedModifiers(uid);
TryStandUp(uid);
}

/// <summary>
/// Send an update event when player pressed keybind.
/// </summary>
private void ChangeLyingState(ICommonSession? session)
else
{
RaiseNetworkEvent(new ChangeStandingStateEvent());
TryLieDown(uid);
}
}

/// <summary>
/// Process player event, that pressed keybind.
/// </summary>
private void OnChangeAction(ChangeStandingStateEvent msg, EntitySessionEventArgs args)
/// <summary>
/// Update movement speed according to the lying state.
/// </summary>
private void OnRefresh(EntityUid uid, LyingDownComponent component, RefreshMovementSpeedModifiersEvent args)
{
if (_standing.IsDown(uid))
{
if (!args.SenderSession.AttachedEntity.HasValue)
return;

var uid = args.SenderSession.AttachedEntity.Value;
if (_standing.IsDown(uid))
{
TryStandUp(uid);
}
else
{
TryLieDown(uid);
}
args.ModifySpeed(0f, 0f);
}

/// <summary>
/// Update movement speed according to the lying state.
/// </summary>
private void OnRefresh(EntityUid uid, LyingDownComponent component, RefreshMovementSpeedModifiersEvent args)
else
{
if (_standing.IsDown(uid))
{
args.ModifySpeed(0.1f, 0.1f);
}
else
{
args.ModifySpeed(1f, 1f);
}
args.ModifySpeed(1f, 1f);
}
}

/// <summary>
/// Change available to player actions.
/// </summary>
private void SwitchActions(EntityUid uid)
/// <summary>
/// Change available to player actions.
/// </summary>
private void SwitchActions(EntityUid uid)
{
var standingComponent = Comp<StandingStateComponent>(uid);
if (_standing.IsDown(uid))
{
var standingComponent = Comp<StandingStateComponent>(uid);
if (_standing.IsDown(uid))
{
_actions.AddAction(uid, ref standingComponent.StandUpActionEntity, standingComponent.StandUpAction);
_actions.RemoveAction(uid, standingComponent.LieDownActionEntity);
}
else
{
_actions.AddAction(uid, ref standingComponent.LieDownActionEntity, standingComponent.LieDownAction);
_actions.RemoveAction(uid, standingComponent.StandUpActionEntity);
}
_actions.AddAction(uid, ref standingComponent.StandUpActionEntity, standingComponent.StandUpAction);
_actions.RemoveAction(uid, standingComponent.LieDownActionEntity);
}

/// <summary>
/// When interacting with a lying down person, add ability to make him stand up.
/// </summary>
private void OnInteractHand(EntityUid uid, LyingDownComponent component, InteractHandEvent args)
else
{
TryStandUp(args.Target);
_actions.AddAction(uid, ref standingComponent.LieDownActionEntity, standingComponent.LieDownAction);
_actions.RemoveAction(uid, standingComponent.StandUpActionEntity);
}
}

/// <summary>
/// Add a verb to player menu to make him stand up.
/// </summary>
private void AddStandUpVerb(EntityUid uid, LyingDownComponent component, GetVerbsEvent<AlternativeVerb> args)
{
if (!args.CanInteract || !args.CanAccess)
return;
/// <summary>
/// When interacting with a lying down person, add ability to make him stand up.
/// </summary>
private void OnInteractHand(EntityUid uid, LyingDownComponent component, InteractHandEvent args)
{
TryStandUp(args.Target);
}

if (args.Target == args.User)
return;
/// <summary>
/// Add a verb to player menu to make him stand up.
/// </summary>
private void AddStandUpVerb(EntityUid uid, LyingDownComponent component, GetVerbsEvent<AlternativeVerb> args)
{
if (!args.CanInteract || !args.CanAccess)
return;

if (!_standing.IsDown(uid))
return;
if (args.Target == args.User)
return;

AlternativeVerb verb = new()
{
Act = () =>
{
TryStandUp(uid);
},
Text = Loc.GetString(component.MakeToStandUpAction!),
Priority = 2
};

args.Verbs.Add(verb);
}
if (!_standing.IsDown(uid))
return;

/// <summary>
/// If somebody examined a lying down person, add description.
/// </summary>
private void OnExamined(EntityUid uid, LyingDownComponent component, ExaminedEvent args)
AlternativeVerb verb = new()
{
if (args.IsInDetailsRange && _standing.IsDown(uid))
Act = () =>
{
args.PushMarkup(Loc.GetString("lying-down-examined", ("target", Identity.Entity(uid, EntityManager))));
}
}
TryStandUp(uid);
},
Text = Loc.GetString(component.MakeToStandUpAction!),
Priority = 2
};

public void TryStandUp(EntityUid uid)
{
if (!_standing.IsDown(uid) || !_standing.Stand(uid))
return;
args.Verbs.Add(verb);
}

RemCompDeferred<LyingDownComponent>(uid);
/// <summary>
/// If somebody examined a lying down person, add description.
/// </summary>
private void OnExamined(EntityUid uid, LyingDownComponent component, ExaminedEvent args)
{
if (args.IsInDetailsRange && _standing.IsDown(uid))
{
args.PushMarkup(Loc.GetString("lying-down-examined", ("target", Identity.Entity(uid, EntityManager))));
}
}

public void TryLieDown(EntityUid uid)
{
if (_standing.IsDown(uid) || !_standing.Down(uid, false, false))
return;
public void TryStandUp(EntityUid uid)
{
if (!_standing.IsDown(uid) || !_standing.Stand(uid))
return;

EnsureComp<LyingDownComponent>(uid);
}
RemCompDeferred<LyingDownComponent>(uid);
}

public void TryLieDown(EntityUid uid)
{
if (_standing.IsDown(uid) || !_standing.Down(uid, false, false))
return;

EnsureComp<LyingDownComponent>(uid);
}
}

69 changes: 35 additions & 34 deletions Content.Shared/Standing/StandingStateComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,40 @@
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;

namespace Content.Shared.Standing
namespace Content.Shared.Standing;


[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
[Access(typeof(StandingStateSystem))]
public sealed partial class StandingStateComponent : Component
{
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
[Access(typeof(StandingStateSystem))]
public sealed partial class StandingStateComponent : Component
{
[ViewVariables(VVAccess.ReadWrite)]
[DataField]
public SoundSpecifier DownSound { get; private set; } = new SoundCollectionSpecifier("BodyFall");

[DataField, AutoNetworkedField]
public bool Standing = true;

/// <summary>
/// List of fixtures that had their collision mask changed when the entity was downed.
/// Required for re-adding the collision mask.
/// </summary>
[DataField, AutoNetworkedField]
public List<string> ChangedFixtures = new();

[DataField]
public EntProtoId LieDownAction = "ActionLieDown";

[DataField, AutoNetworkedField]
public EntityUid? LieDownActionEntity;

[DataField("stand-up-action")]
public EntProtoId StandUpAction = "ActionStandUp";

[DataField, AutoNetworkedField]
public EntityUid? StandUpActionEntity;
}

public sealed partial class LieDownActionEvent : InstantActionEvent {}
public sealed partial class StandUpActionEvent : InstantActionEvent {}
[ViewVariables(VVAccess.ReadWrite)]
[DataField]
public SoundSpecifier DownSound { get; private set; } = new SoundCollectionSpecifier("BodyFall");

[DataField, AutoNetworkedField]
public bool Standing = true;

/// <summary>
/// List of fixtures that had their collision mask changed when the entity was downed.
/// Required for re-adding the collision mask.
/// </summary>
[DataField, AutoNetworkedField]
public List<string> ChangedFixtures = new();

[DataField]
public EntProtoId LieDownAction = "ActionLieDown";

[DataField, AutoNetworkedField]
public EntityUid? LieDownActionEntity;

[DataField("stand-up-action")]
public EntProtoId StandUpAction = "ActionStandUp";

[DataField, AutoNetworkedField]
public EntityUid? StandUpActionEntity;
}

public sealed partial class LieDownActionEvent : InstantActionEvent {}
public sealed partial class StandUpActionEvent : InstantActionEvent {}

6 changes: 5 additions & 1 deletion Resources/keybinds.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 1 # Not used right now, whatever.
version: 1 # Not used right now, whatever.
binds:
- function: UIClick
type: State
Expand Down Expand Up @@ -540,3 +540,7 @@ binds:
- function: Hotbar9
type: State
key: Num9
- function: LieDownStandUp
type: State
key: Z
mod1: Shift

0 comments on commit 14fd1c9

Please sign in to comment.