This repository has been archived by the owner on Nov 1, 2024. It is now read-only.
forked from new-frontiers-14/frontier-station-14
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ivan Rubinov
committed
Jun 17, 2024
1 parent
ddd3449
commit 18c8dfc
Showing
14 changed files
with
872 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Content.Shared.Actions; | ||
using Robust.Shared.GameStates; | ||
using Robust.Shared.Prototypes; | ||
using Robust.Shared.Serialization; | ||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom; | ||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; | ||
|
||
namespace Content.Shared.LieDown; | ||
|
||
/// <summary> | ||
/// Makes the target to lie down. | ||
/// </summary> | ||
[Access(typeof(SharedLieDownSystem))] | ||
[RegisterComponent, NetworkedComponent()] | ||
public sealed partial class LyingDownComponent : Component | ||
{ | ||
/// <summary> | ||
/// The action to lie down or stand up. | ||
/// </summary> | ||
[DataField("make-to-stand-up-action", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))] | ||
public string? MakeToStandUpAction = "action-name-make-standup"; | ||
} | ||
|
||
[Serializable, NetSerializable] | ||
public sealed class ChangeStandingStateEvent : EntityEventArgs {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
using Content.Shared.Actions; | ||
using Content.Shared.Examine; | ||
using Content.Shared.IdentityManagement; | ||
using Content.Shared.Input; | ||
using Content.Shared.Interaction; | ||
using Content.Shared.Movement.Systems; | ||
using Content.Shared.Standing; | ||
using Content.Shared.Verbs; | ||
using Robust.Shared.Input.Binding; | ||
using Robust.Shared.IoC; | ||
using Robust.Shared.Player; | ||
|
||
namespace Content.Shared.LieDown | ||
{ | ||
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() | ||
{ | ||
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 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()); | ||
} | ||
|
||
/// <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)) | ||
{ | ||
TryStandUp(uid); | ||
} | ||
else | ||
{ | ||
TryLieDown(uid); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Update movement speed according to the lying state. | ||
/// </summary> | ||
private void OnRefresh(EntityUid uid, LyingDownComponent component, RefreshMovementSpeedModifiersEvent args) | ||
{ | ||
if (_standing.IsDown(uid)) | ||
{ | ||
args.ModifySpeed(0.4f, 0.4f); | ||
} | ||
else | ||
{ | ||
args.ModifySpeed(1f, 1f); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Change available to player actions. | ||
/// </summary> | ||
private void SwitchActions(EntityUid uid) | ||
{ | ||
var standingComponent = Comp<StandingStateComponent>(uid); | ||
_actions.AddAction(uid, ref standingComponent.ToggleActionEntity, standingComponent.ToggleAction); | ||
} | ||
|
||
/// <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); | ||
} | ||
|
||
/// <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 (args.Target == args.User) | ||
return; | ||
|
||
if (!_standing.IsDown(uid)) | ||
return; | ||
|
||
AlternativeVerb verb = new() | ||
{ | ||
Act = () => | ||
{ | ||
TryStandUp(uid); | ||
}, | ||
Text = Loc.GetString(component.MakeToStandUpAction!), | ||
Priority = 2 | ||
}; | ||
|
||
args.Verbs.Add(verb); | ||
} | ||
|
||
/// <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 TryStandUp(EntityUid uid) | ||
{ | ||
if (!_standing.IsDown(uid) || !_standing.Stand(uid)) | ||
return; | ||
|
||
Logger.Debug("{uid} tried to stand up", uid); | ||
|
||
RemCompDeferred<LyingDownComponent>(uid); | ||
} | ||
|
||
public void TryLieDown(EntityUid uid) | ||
{ | ||
if (_standing.IsDown(uid) || !_standing.Down(uid, false, false)) | ||
return; | ||
|
||
Logger.Debug("{uid} tried to lie down", uid); | ||
|
||
EnsureComp<LyingDownComponent>(uid); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
action-name-liedown = Lie down | ||
action-name-standup = Stand up | ||
action-name-make-standup = Make to stand up | ||
lying-down-examined = [color=lightblue]{CAPITALIZE(SUBJECT($target))} {CONJUGATE-BE($target)} is lying down.[/color] | ||
ui-options-function-lie-down-stand-up = Lie on the ground |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
action-name-liedown = Lie down | ||
action-name-standup = Stand up | ||
action-name-make-standup = Make to stand up | ||
lying-down-examined = [color=lightblue]{CAPITALIZE(SUBJECT($target))} {CONJUGATE-BE($target)} is lying down.[/color] | ||
ui-options-function-lie-down-stand-up = Lie on the ground |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.