From 397e74079bf38eb6611583caf639600db10938b2 Mon Sep 17 00:00:00 2001 From: Spatison <137375981+Spatison@users.noreply.github.com> Date: Tue, 30 Jul 2024 03:13:05 +0300 Subject: [PATCH] Fix (#513) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: Ботинки клоуна сново работают * fix: Световое копье теперь исчезает если его передать --- .../Animations}/WaddleAnimationSystem.cs | 89 ++++--------------- .../Animations/WaddleAnimationSystem.cs | 16 ++++ .../_White/OfferItem/OfferItemSystem.cs | 12 ++- .../EntitySystems}/WaddleClothingSystem.cs | 6 +- .../SharedWaddledAnimationSystem.cs | 47 ++++++++++ .../Animations}/WaddleAnimationComponent.cs | 26 ++---- .../HardlightSpear/HardlightSpearSystem.cs | 7 ++ .../_White/OfferItem/SharedOfferItemSystem.cs | 8 ++ 8 files changed, 115 insertions(+), 96 deletions(-) rename Content.Client/{Movement/Systems => _White/Animations}/WaddleAnimationSystem.cs (50%) create mode 100644 Content.Server/_White/Animations/WaddleAnimationSystem.cs rename {Content.Client/Clothing/Systems => Content.Shared/Clothing/EntitySystems}/WaddleClothingSystem.cs (88%) create mode 100644 Content.Shared/_White/Animations/SharedWaddledAnimationSystem.cs rename Content.Shared/{Movement/Components => _White/Animations}/WaddleAnimationComponent.cs (70%) diff --git a/Content.Client/Movement/Systems/WaddleAnimationSystem.cs b/Content.Client/_White/Animations/WaddleAnimationSystem.cs similarity index 50% rename from Content.Client/Movement/Systems/WaddleAnimationSystem.cs rename to Content.Client/_White/Animations/WaddleAnimationSystem.cs index e6a88cb485..23657821f3 100644 --- a/Content.Client/Movement/Systems/WaddleAnimationSystem.cs +++ b/Content.Client/_White/Animations/WaddleAnimationSystem.cs @@ -1,89 +1,37 @@ using System.Numerics; -using Content.Client.Gravity; -using Content.Shared.Rotation; +using Content.Shared._White.Animations; using Content.Shared.Movement.Components; -using Content.Shared.Movement.Events; using Robust.Client.Animations; using Robust.Client.GameObjects; using Robust.Shared.Animations; -using Robust.Shared.Timing; -namespace Content.Client.Movement.Systems; +namespace Content.Client._White.Animations; -public sealed class WaddleAnimationSystem : EntitySystem +public sealed class WaddleAnimationSystem : SharedWaddledAnimationSystem { [Dependency] private readonly AnimationPlayerSystem _animation = default!; - [Dependency] private readonly GravitySystem _gravity = default!; - [Dependency] private readonly IGameTiming _timing = default!; - [Dependency] private readonly AppearanceSystem _appearance = default!; // WD EDIT public override void Initialize() { - SubscribeLocalEvent(OnMovementInput); - SubscribeLocalEvent(OnStartedWalking); - SubscribeLocalEvent(OnStoppedWalking); SubscribeLocalEvent(OnAnimationCompleted); + + SubscribeAllEvent(ev => PlayAnimation(GetEntity(ev.User))); + SubscribeAllEvent(ev => StopAnimation(GetEntity(ev.User))); } - private void OnMovementInput(EntityUid entity, WaddleAnimationComponent component, MoveInputEvent args) + protected override void PlayAnimation(EntityUid uid) { - // Prediction mitigation. Prediction means that MoveInputEvents are spammed repeatedly, even though you'd assume - // they're once-only for the user actually doing something. As such do nothing if we're just repeating this FoR. - if (!_timing.IsFirstTimePredicted) - { - return; - } - - // WD EDIT - _appearance.TryGetData(entity, RotationVisuals.RotationState, out var state); - if (state is RotationState.Horizontal) - return; - // WD EDIT - - if (!args.HasDirectionalMovement && component.IsCurrentlyWaddling) - { - component.IsCurrentlyWaddling = false; - - var stopped = new StoppedWaddlingEvent(entity); - - RaiseLocalEvent(entity, ref stopped); - - return; - } - - // Only start waddling if we're not currently AND we're actually moving. - if (component.IsCurrentlyWaddling || !args.HasDirectionalMovement) + if (!Timing.IsFirstTimePredicted) return; - component.IsCurrentlyWaddling = true; - - var started = new StartedWaddlingEvent(entity); - - RaiseLocalEvent(entity, ref started); - } - - private void OnStartedWalking(EntityUid uid, WaddleAnimationComponent component, StartedWaddlingEvent args) - { - if (_animation.HasRunningAnimation(uid, component.KeyName)) - { + if (!TryComp(uid, out var component)) return; - } if (!TryComp(uid, out var mover)) - { return; - } - if (_gravity.IsWeightless(uid)) - { + if (_animation.HasRunningAnimation(uid, component.KeyName)) return; - } - - // WD EDIT - _appearance.TryGetData(uid, RotationVisuals.RotationState, out var state); - if (TryComp(uid, out var sprite) && TryComp(uid, out var rotat) && state is RotationState.Horizontal) - return; - // WD EDIT var tumbleIntensity = component.LastStep ? 360 - component.TumbleIntensity : component.TumbleIntensity; var len = mover.Sprinting ? component.AnimationLength * component.RunAnimationLengthMultiplier : component.AnimationLength; @@ -126,14 +74,15 @@ public sealed class WaddleAnimationSystem : EntitySystem _animation.Play(uid, anim, component.KeyName); } - private void OnStoppedWalking(EntityUid uid, WaddleAnimationComponent component, StoppedWaddlingEvent args) + protected override void StopAnimation(EntityUid uid) { - _animation.Stop(uid, component.KeyName); + if (!TryComp(uid, out var component)) + return; if (!TryComp(uid, out var sprite)) - { return; - } + + _animation.Stop(uid, component.KeyName); sprite.Offset = new Vector2(); sprite.Rotation = Angle.FromDegrees(0); @@ -142,13 +91,9 @@ public sealed class WaddleAnimationSystem : EntitySystem private void OnAnimationCompleted(EntityUid uid, WaddleAnimationComponent component, AnimationCompletedEvent args) { - if (args.Key is not "Waddle") // WD EDIT - { - component.IsCurrentlyWaddling = false; + if (args.Key != component.KeyName) return; - } - var started = new StartedWaddlingEvent(uid); - RaiseLocalEvent(uid, ref started); + PlayAnimation(uid); } } diff --git a/Content.Server/_White/Animations/WaddleAnimationSystem.cs b/Content.Server/_White/Animations/WaddleAnimationSystem.cs new file mode 100644 index 0000000000..c7ebdf5d75 --- /dev/null +++ b/Content.Server/_White/Animations/WaddleAnimationSystem.cs @@ -0,0 +1,16 @@ +using Content.Shared._White.Animations; + +namespace Content.Server._White.Animations; + +public sealed class WaddleAnimationSystem : SharedWaddledAnimationSystem +{ + protected override void PlayAnimation(EntityUid user) + { + RaiseNetworkEvent(new StartedWaddlingEvent(GetNetEntity(user))); + } + + protected override void StopAnimation(EntityUid user) + { + RaiseNetworkEvent(new StoppedWaddlingEvent(GetNetEntity(user))); + } +} diff --git a/Content.Server/_White/OfferItem/OfferItemSystem.cs b/Content.Server/_White/OfferItem/OfferItemSystem.cs index 23df303bea..c4a10f7c3e 100644 --- a/Content.Server/_White/OfferItem/OfferItemSystem.cs +++ b/Content.Server/_White/OfferItem/OfferItemSystem.cs @@ -69,12 +69,18 @@ public sealed class OfferItemSystem : SharedOfferItemSystem _popup.PopupEntity(Loc.GetString("offer-item-give", ("item", Identity.Entity(offerItem.Item.Value, EntityManager)), - ("target", Identity.Entity(uid, EntityManager))), component.Target.Value, component.Target.Value); + ("target", Identity.Entity(uid, EntityManager))), + component.Target.Value, + component.Target.Value); _popup.PopupEntity(Loc.GetString("offer-item-give-other", ("user", Identity.Entity(component.Target.Value, EntityManager)), ("item", Identity.Entity(offerItem.Item.Value, EntityManager)), - ("target", Identity.Entity(uid, EntityManager))) - , component.Target.Value, Filter.PvsExcept(component.Target.Value, entityManager: EntityManager), true); + ("target", Identity.Entity(uid, EntityManager))), + component.Target.Value, + Filter.PvsExcept(component.Target.Value, entityManager: EntityManager), + true); + + RaiseLocalEvent(offerItem.Item.Value, new HandedEvent(component.Target.Value, uid)); } offerItem.Item = null; diff --git a/Content.Client/Clothing/Systems/WaddleClothingSystem.cs b/Content.Shared/Clothing/EntitySystems/WaddleClothingSystem.cs similarity index 88% rename from Content.Client/Clothing/Systems/WaddleClothingSystem.cs rename to Content.Shared/Clothing/EntitySystems/WaddleClothingSystem.cs index b8ac3c207b..b9c3ae08a9 100644 --- a/Content.Client/Clothing/Systems/WaddleClothingSystem.cs +++ b/Content.Shared/Clothing/EntitySystems/WaddleClothingSystem.cs @@ -1,8 +1,8 @@ -using Content.Shared.Clothing.Components; -using Content.Shared.Movement.Components; +using Content.Shared._White.Animations; +using Content.Shared.Clothing.Components; using Content.Shared.Inventory.Events; -namespace Content.Client.Clothing.Systems; +namespace Content.Shared.Clothing.EntitySystems; public sealed class WaddleClothingSystem : EntitySystem { diff --git a/Content.Shared/_White/Animations/SharedWaddledAnimationSystem.cs b/Content.Shared/_White/Animations/SharedWaddledAnimationSystem.cs new file mode 100644 index 0000000000..2ade3a167a --- /dev/null +++ b/Content.Shared/_White/Animations/SharedWaddledAnimationSystem.cs @@ -0,0 +1,47 @@ +using Content.Shared.Movement.Events; +using Content.Shared.Standing.Systems; +using Robust.Shared.Timing; + +namespace Content.Shared._White.Animations; + +public abstract class SharedWaddledAnimationSystem : EntitySystem +{ + [Dependency] protected readonly IGameTiming Timing = default!; + [Dependency] private readonly SharedStandingStateSystem _standingState = default!; + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnMovementInput); + } + + private void OnMovementInput(EntityUid uid, WaddleAnimationComponent component, MoveInputEvent args) + { + if (!Timing.IsFirstTimePredicted) + return; + + if (_standingState.IsDown(uid)) + return; + + if (!args.HasDirectionalMovement && component.IsCurrentlyWaddling) + { + component.IsCurrentlyWaddling = false; + + StopAnimation(uid); + + return; + } + + if (component.IsCurrentlyWaddling || !args.HasDirectionalMovement) + return; + + component.IsCurrentlyWaddling = true; + + PlayAnimation(uid); + } + + protected abstract void PlayAnimation(EntityUid user); + + protected abstract void StopAnimation(EntityUid user); +} diff --git a/Content.Shared/Movement/Components/WaddleAnimationComponent.cs b/Content.Shared/_White/Animations/WaddleAnimationComponent.cs similarity index 70% rename from Content.Shared/Movement/Components/WaddleAnimationComponent.cs rename to Content.Shared/_White/Animations/WaddleAnimationComponent.cs index c43ef3042e..b2cab95ad1 100644 --- a/Content.Shared/Movement/Components/WaddleAnimationComponent.cs +++ b/Content.Shared/_White/Animations/WaddleAnimationComponent.cs @@ -1,30 +1,20 @@ using System.Numerics; +using Robust.Shared.Serialization; -namespace Content.Shared.Movement.Components; +namespace Content.Shared._White.Animations; -/// -/// Declares that an entity has started to waddle like a duck/clown. -/// -/// The newly be-waddled. -[ByRefEvent] -public record struct StartedWaddlingEvent(EntityUid Entity) +[Serializable, NetSerializable] +public sealed class StartedWaddlingEvent(NetEntity user) : EntityEventArgs { - public EntityUid Entity = Entity; + public NetEntity User = user; } -/// -/// Declares that an entity has stopped waddling like a duck/clown. -/// -/// The former waddle-er. -[ByRefEvent] -public record struct StoppedWaddlingEvent(EntityUid Entity) +[Serializable, NetSerializable] +public sealed class StoppedWaddlingEvent(NetEntity user) : EntityEventArgs { - public EntityUid Entity = Entity; + public NetEntity User = user; } -/// -/// Defines something as having a waddle animation when it moves. -/// [RegisterComponent] public sealed partial class WaddleAnimationComponent : Component { diff --git a/Content.Shared/_White/HardlightSpear/HardlightSpearSystem.cs b/Content.Shared/_White/HardlightSpear/HardlightSpearSystem.cs index e75a2bed10..008d7780d0 100644 --- a/Content.Shared/_White/HardlightSpear/HardlightSpearSystem.cs +++ b/Content.Shared/_White/HardlightSpear/HardlightSpearSystem.cs @@ -1,4 +1,5 @@ using System.Linq; +using Content.Shared._White.OfferItem; using Content.Shared.Body.Components; using Content.Shared.Hands.EntitySystems; using Content.Shared.Implants.Components; @@ -30,6 +31,7 @@ public sealed class HardlightSpearSystem : EntitySystem SubscribeLocalEvent(OnLand); SubscribeLocalEvent(OnDrop); + SubscribeLocalEvent(OnHanded); SubscribeLocalEvent(OnInsert); SubscribeLocalEvent(OnPickupAttempt); SubscribeLocalEvent(OnPreventCollision); @@ -96,4 +98,9 @@ public sealed class HardlightSpearSystem : EntitySystem if (!HasComp(args.Container.Owner)) EnsureComp(uid); } + + private void OnHanded(EntityUid uid, HardlightSpearComponent component, ref HandedEvent args) + { + EnsureComp(uid); + } } diff --git a/Content.Shared/_White/OfferItem/SharedOfferItemSystem.cs b/Content.Shared/_White/OfferItem/SharedOfferItemSystem.cs index 4a471028cc..1c754c85cb 100644 --- a/Content.Shared/_White/OfferItem/SharedOfferItemSystem.cs +++ b/Content.Shared/_White/OfferItem/SharedOfferItemSystem.cs @@ -156,3 +156,11 @@ public abstract partial class SharedOfferItemSystem : EntitySystem return entity != null && Resolve(entity.Value, ref component, false) && component.IsInOfferMode; } } + +[Serializable] +public sealed class HandedEvent(EntityUid user, EntityUid target) : EntityEventArgs +{ + public EntityUid User = user; + public EntityUid Target = target; +} +