Skip to content

Commit

Permalink
work
Browse files Browse the repository at this point in the history
  • Loading branch information
rhailrake committed Dec 22, 2024
1 parent 5d10a1a commit b58de36
Show file tree
Hide file tree
Showing 10 changed files with 190 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Content.Client/Chat/UI/EmotesMenu.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public EmotesMenu()
foreach (var emote in emotes)
{
var player = _playerManager.LocalSession?.AttachedEntity;
if (emote.Category == EmoteCategory.Invalid ||
if (emote.Category == EmoteCategory.Invalid || emote.Category == EmoteCategory.Verb ||
emote.ChatTriggers.Count == 0 ||
!(player.HasValue && whitelistSystem.IsWhitelistPassOrNull(emote.Whitelist, player.Value)) ||
whitelistSystem.IsBlacklistPass(emote.Blacklist, player.Value))
Expand Down
40 changes: 40 additions & 0 deletions Content.Client/Standing/StandingStateSystem.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
using Content.Shared.Input;
using Content.Shared.Rotation;
using Content.Shared.Standing;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Shared.Input.Binding;
using Robust.Shared.Player;

namespace Content.Client.Standing;

public sealed class StandingStateSystem : SharedStandingStateSystem
{
[Dependency] private readonly AppearanceSystem _appearance = default!;
[Dependency] private readonly IEyeManager _eyeManager = default!;

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

CommandBinds.Builder
.Bind(ContentKeyFunctions.ToggleStanding, InputCmdHandler.FromDelegate(ToggleStanding))
.Register<SharedStandingStateSystem>();

SubscribeLocalEvent<RotationVisualsComponent, MoveEvent>(OnMove);
}

private void ToggleStanding(ICommonSession? session)
Expand All @@ -24,4 +32,36 @@ private void ToggleStanding(ICommonSession? session)

RaiseNetworkEvent(new ChangeLayingDownEvent());
}

private void OnMove(EntityUid uid, RotationVisualsComponent component, ref MoveEvent args)
{
if (!TryComp<SpriteComponent>(uid, out var sprite) ||
!TryComp<AppearanceComponent>(uid, out var appearance) ||
!TryComp<TransformComponent>(uid, out var transform) ||
component.DefaultRotation == 0)
return;

_appearance.TryGetData<RotationState>(uid, RotationVisuals.RotationState, out var state, appearance);

var rotation = transform.LocalRotation + _eyeManager.CurrentEye.Rotation;
if (rotation.GetDir() is Direction.East or Direction.North or Direction.NorthEast or Direction.SouthEast)
{
if (state != RotationState.Horizontal ||
sprite.Rotation != component.DefaultRotation)
return;

component.HorizontalRotation = Angle.FromDegrees(270);
sprite.Rotation = Angle.FromDegrees(270);

return;
}

if (state != RotationState.Horizontal ||
sprite.Rotation != Angle.FromDegrees(270))
return;

component.HorizontalRotation = component.DefaultRotation;

sprite.Rotation = component.DefaultRotation;
}
}
4 changes: 2 additions & 2 deletions Content.Client/_Sunrise/UserActions/Tabs/VerbsTabControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public sealed partial class VerbsTabControl : BaseTabControl
[Dependency] private readonly IGameTiming _gameTiming = default!;

private TimeSpan _lastVerbTime;
private static readonly TimeSpan VerbCooldown = TimeSpan.FromSeconds(1);
private static readonly TimeSpan VerbCooldown = TimeSpan.FromSeconds(0.5f);

public VerbsTabControl()
{
Expand Down Expand Up @@ -152,7 +152,7 @@ private bool IsVerbsAvailable(EmotePrototype emote, EntityUid player)
{
var whitelistSystem = _entManager.System<EntityWhitelistSystem>();

if (emote.Category == EmoteCategory.Invalid || emote.Category != EmoteCategory.Verb || emote.ChatTriggers.Count == 0)
if (emote.Category == EmoteCategory.Invalid || emote.Category != EmoteCategory.Verb)
return false;

if (!whitelistSystem.IsWhitelistPassOrNull(emote.Whitelist, player) ||
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Speech/EmotesMenuSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private void OnPlayEmote(PlayEmoteMessage msg, EntitySessionEventArgs args)
if (!player.HasValue)
return;

if (!_prototypeManager.TryIndex(msg.ProtoId, out var proto) || proto.ChatTriggers.Count == 0)
if (!_prototypeManager.TryIndex(msg.ProtoId, out var proto))
return;

_chat.TryEmoteWithChat(player.Value, msg.ProtoId);
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Standing/StandingStateSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private void OnChangeState(ChangeLayingDownEvent msg, EntitySessionEventArgs arg
if (standingStateComponent.CurrentState == StandingState.Laying)
TryStandUp(uid, standingStateComponent);
else
TryLieDown(uid, standingStateComponent);
Fall(uid);
}

private void FallOver(EntityUid uid, StandingStateComponent component, DropHandItemsEvent args)
Expand Down
18 changes: 18 additions & 0 deletions Content.Server/_Sunrise/Animations/EmoteAnimationSystem.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
using Content.Server.Chat.Systems;
using Content.Shared._Sunrise.Animations;
using Content.Shared.Chat.Prototypes;
using Content.Shared.Gravity;
using Content.Shared.Standing;
using Robust.Shared.GameStates;

namespace Content.Server._Sunrise.Animations;

public sealed class EmoteAnimationSystem : EntitySystem
{
[Dependency] private readonly SharedStandingStateSystem _sharedStanding = default!;
[Dependency] private readonly SharedGravitySystem _gravity = default!;

public override void Initialize()
{
SubscribeLocalEvent<EmoteAnimationComponent, ComponentGetState>(OnGetState);
Expand All @@ -28,6 +33,19 @@ private void OnEmote(EntityUid uid, EmoteAnimationComponent component, ref Emote

public void PlayEmoteAnimation(EntityUid uid, EmoteAnimationComponent component, string emoteId)
{
if (emoteId == "EmoteLay")
{
if (_gravity.IsWeightless(uid))
return;

if (_sharedStanding.IsDown(uid))
_sharedStanding.TryStandUp(uid);
else
_sharedStanding.TryLieDown(uid);

return;
}

component.AnimationId = emoteId;
Dirty(uid, component);
}
Expand Down
4 changes: 2 additions & 2 deletions Content.Shared/Mobs/Systems/MobStateSystem.Subscribers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ private void OnStateEnteredSubscribers(EntityUid target, MobStateComponent compo
_appearance.SetData(target, MobStateVisuals.State, MobState.Alive);
break;
case MobState.Critical:
_standing.Down(target);
_appearance.SetData(target, MobStateVisuals.State, MobState.Critical);
_standing.Down(target);
break;
case MobState.Dead:
EnsureComp<CollisionWakeComponent>(target);
_standing.Down(target);
_appearance.SetData(target, MobStateVisuals.State, MobState.Dead);
_standing.Down(target);
break;
case MobState.Invalid:
//unused;
Expand Down
114 changes: 110 additions & 4 deletions Content.Shared/Standing/SharedStandingStateSystem.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,41 @@
using Content.Shared.ActionBlocker;
using Content.Shared.Buckle;
using Content.Shared.Buckle.Components;
using Content.Shared.Damage.Systems;
using Content.Shared.DoAfter;
using Content.Shared.Hands.Components;
using Content.Shared.Humanoid;
using Content.Shared.Mobs;
using Content.Shared.Mobs.Systems;
using Content.Shared.Movement.Events;
using Content.Shared.Movement.Systems;
using Content.Shared.Physics;
using Content.Shared.Rotation;
using Content.Shared.Stunnable;
using Content.Shared.Throwing;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Network;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Systems;

namespace Content.Shared.Standing;

public abstract class SharedStandingStateSystem : EntitySystem
{
[Dependency] private readonly INetManager _net = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly MobStateSystem _mobState = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
[Dependency] private readonly MovementSpeedModifierSystem _movement = default!;
[Dependency] private readonly INetManager _net = default!;
[Dependency] private readonly SharedRotationVisualsSystem _rotation = default!;
[Dependency] private readonly SharedBuckleSystem _buckle = default!;
[Dependency] private readonly StaminaSystem _stamina = default!;
[Dependency] private readonly SharedStunSystem _stun = default!;
[Dependency] private readonly ThrowingSystem _throwing = default!;
[Dependency] private readonly ActionBlockerSystem _blocker = default!;

private const int StandingCollisionLayer = (int) CollisionGroup.MidImpassable;

Expand All @@ -32,6 +44,9 @@ public override void Initialize()
base.Initialize();

SubscribeLocalEvent<StandingStateComponent, StandUpDoAfterEvent>(OnStandUpDoAfter);
SubscribeLocalEvent<StandingStateComponent, DownDoAfterEvent>(OnDownDoAfter);
SubscribeLocalEvent<StandingStateComponent, MoveInputEvent>(OnMoveInput);
SubscribeLocalEvent<StandingStateComponent, UpdateCanMoveEvent >(UpdateCanMove);
SubscribeLocalEvent<StandingStateComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovementSpeed);
}

Expand All @@ -44,7 +59,39 @@ private void OnStandUpDoAfter(EntityUid uid, StandingStateComponent component, S
if (_mobState.IsIncapacitated(uid))
return;

Stand(uid, component);
Stand(uid);

args.Handled = true;
}

private void OnDownDoAfter(EntityUid uid, StandingStateComponent component, DownDoAfterEvent args)
{
if (args.Handled || args.Cancelled)
return;

Down(uid, dropHeldItems: false);

args.Handled = true;
}

private void UpdateCanMove(Entity<StandingStateComponent> ent, ref UpdateCanMoveEvent args)
{
if (!HasComp<HumanoidAppearanceComponent>(ent))
return;

if (IsStanding(ent))
return;

if (!TryComp<HandsComponent>(ent, out var handsComp))
return;

if (handsComp.CountFreeHands() < 1)
args.Cancel();
}

private void OnMoveInput(EntityUid uid, StandingStateComponent component, ref MoveInputEvent args)
{
_blocker.UpdateCanMove(uid);
}

private void OnRefreshMovementSpeed(EntityUid uid, StandingStateComponent component, RefreshMovementSpeedModifiersEvent args)
Expand Down Expand Up @@ -82,10 +129,46 @@ public bool TryLieDown(EntityUid uid, StandingStateComponent? standingState = nu
|| TerminatingOrDeleted(uid))
return false;

return Down(uid, dropHeldItems: false);
var args = new DoAfterArgs(EntityManager, uid, standingState.CycleTime, new DownDoAfterEvent(), uid)
{
BreakOnHandChange = false,
RequireCanInteract = false
};

return _doAfter.TryStartDoAfter(args);
}

public bool Stand(EntityUid uid,
public void Fall(EntityUid uid, float rollDistance = 3f, float rollSpeed = 6f)
{
if (!TryComp<PhysicsComponent>(uid, out var physics))
return;

var velocity = physics.LinearVelocity;
if (velocity.LengthSquared() < 0.1f)
{
Down(uid, dropHeldItems: false);
return;
}

var direction = velocity.Normalized();

Down(uid, dropHeldItems: true);
_stun.TryStun(uid, TimeSpan.FromSeconds(1.2f), true);
_stamina.TakeStaminaDamage(uid, 20);

_throwing.TryThrow(
uid,
direction * rollDistance,
rollSpeed,
friction: 5f,
compensateFriction: true,
animated: false,
playSound: true,
doSpin: false
);
}

public bool Stand(EntityUid uid,
StandingStateComponent? standingState = null,
AppearanceComponent? appearance = null,
bool force = false)
Expand All @@ -95,6 +178,9 @@ public bool Stand(EntityUid uid,

Resolve(uid, ref appearance, false);

if (TryComp<BuckleComponent>(uid, out var buckleComponent) && buckleComponent.Buckled)
_buckle.TryUnbuckle(uid, uid, buckleComp: buckleComponent);

if (IsStanding(uid, standingState))
return true;

Expand Down Expand Up @@ -141,6 +227,9 @@ public bool Down(EntityUid uid,

Resolve(uid, ref appearance, ref hands, false);

if (TryComp<BuckleComponent>(uid, out var buckleComponent) && buckleComponent.Buckled)
_buckle.TryUnbuckle(uid, uid, buckleComp: buckleComponent);

if (IsDown(uid, standingState))
return true;

Expand All @@ -158,6 +247,23 @@ public bool Down(EntityUid uid,

standingState.CurrentState = StandingState.Laying;
Dirty(uid, standingState);

var transform = Transform(uid);
var rotation = transform.LocalRotation;
_appearance.TryGetData<bool>(uid, BuckleVisuals.Buckled, out var buckled, appearance);

if (!buckled && (!_appearance.TryGetData<MobState>(uid, MobStateVisuals.State, out var state, appearance) ||
state is MobState.Alive))
{
if (rotation.GetDir() is Direction.East
or Direction.North
or Direction.NorthEast
or Direction.SouthEast)
_rotation.SetHorizontalAngle(uid, Angle.FromDegrees(270));
else
_rotation.ResetHorizontalAngle(uid);
}

RaiseLocalEvent(uid, new DownedEvent());

_appearance.SetData(uid, RotationVisuals.RotationState, RotationState.Horizontal, appearance);
Expand Down
4 changes: 3 additions & 1 deletion Content.Shared/Standing/StandingStateEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public sealed class DownedEvent : EntityEventArgs;
[Serializable, NetSerializable]
public sealed class ChangeLayingDownEvent : CancellableEntityEventArgs;


[Serializable, NetSerializable]
public sealed partial class StandUpDoAfterEvent : SimpleDoAfterEvent;

[Serializable, NetSerializable]
public sealed partial class DownDoAfterEvent : SimpleDoAfterEvent;
13 changes: 12 additions & 1 deletion Resources/Prototypes/_Sunrise/Actions/animations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@
- танцует
- кружится
- оборачивается
- танцует
- покружилась
- покружился

- type: emote
id: EmoteLay
category: Verb
name: Лечь/Встать
whitelist:
components:
- HumanoidAppearance
blacklist:
components:
- Ghost
- BorgChassis

0 comments on commit b58de36

Please sign in to comment.