From d6bcd08bb0f3d6c6fdad6c5e52fe485b8b1ff3c6 Mon Sep 17 00:00:00 2001 From: gluesniffler Date: Sat, 14 Sep 2024 12:01:19 -0400 Subject: [PATCH] Harpy flight release! --- .../Components/FlightVisualsComponent.cs} | 4 +-- .../{DeltaV/Harpy => Flight}/FlightSystem.cs | 18 +++++----- .../FlyingVisualizerSystem.cs} | 34 ++++++++++-------- .../DeltaV/Harpy/FlyingVisualizerSystem.cs | 0 .../{DeltaV/Harpy => Flight}/FlightSystem.cs | 5 +-- Content.Shared/Cuffs/SharedCuffableSystem.cs | 2 +- .../Damage/Components/StaminaComponent.cs | 6 ++-- .../Damage/Systems/StaminaSystem.cs | 14 ++++---- Content.Shared/DeltaV/Harpy/Events.cs | 21 ----------- Content.Shared/Flight/Events.cs | 30 ++++++++++++++++ .../Harpy => Flight}/FlightComponent.cs | 6 ++-- .../Harpy => Flight}/SharedFlightSystem.cs | 21 +++++++---- .../Gravity/SharedFloatingVisualizerSystem.cs | 2 +- Content.Shared/Gravity/SharedGravitySystem.cs | 2 +- .../Entities/Mobs/Species/harpy.yml | 6 ++-- .../Interface/Actions/dash_flight.png | Bin .../Actions/flight.rsi/flight_off.png | Bin .../Actions/flight.rsi/flight_on.png | Bin .../Interface/Actions/flight.rsi/meta.json | 0 19 files changed, 97 insertions(+), 74 deletions(-) rename Content.Client/{DeltaV/Harpy/Components/FlyingVisualsComponent.cs => Flight/Components/FlightVisualsComponent.cs} (89%) rename Content.Client/{DeltaV/Harpy => Flight}/FlightSystem.cs (88%) rename Content.Client/{DeltaV/Harpy/FlyingVisualsSystem.cs => Flight/FlyingVisualizerSystem.cs} (57%) delete mode 100644 Content.Server/DeltaV/Harpy/FlyingVisualizerSystem.cs rename Content.Server/{DeltaV/Harpy => Flight}/FlightSystem.cs (98%) create mode 100644 Content.Shared/Flight/Events.cs rename Content.Shared/{DeltaV/Harpy => Flight}/FlightComponent.cs (95%) rename Content.Shared/{DeltaV/Harpy => Flight}/SharedFlightSystem.cs (85%) rename Resources/Textures/{DeltaV => }/Interface/Actions/dash_flight.png (100%) rename Resources/Textures/{DeltaV => }/Interface/Actions/flight.rsi/flight_off.png (100%) rename Resources/Textures/{DeltaV => }/Interface/Actions/flight.rsi/flight_on.png (100%) rename Resources/Textures/{DeltaV => }/Interface/Actions/flight.rsi/meta.json (100%) diff --git a/Content.Client/DeltaV/Harpy/Components/FlyingVisualsComponent.cs b/Content.Client/Flight/Components/FlightVisualsComponent.cs similarity index 89% rename from Content.Client/DeltaV/Harpy/Components/FlyingVisualsComponent.cs rename to Content.Client/Flight/Components/FlightVisualsComponent.cs index 634aa1576e2..b91ed5c451f 100644 --- a/Content.Client/DeltaV/Harpy/Components/FlyingVisualsComponent.cs +++ b/Content.Client/Flight/Components/FlightVisualsComponent.cs @@ -1,10 +1,10 @@ using Robust.Client.Graphics; using Robust.Shared.GameStates; -namespace Content.Client.DeltaV.Harpy.Components; +namespace Content.Client.Flight.Components; [RegisterComponent] -public sealed partial class FlyingVisualsComponent : Component +public sealed partial class FlightVisualsComponent : Component { /// /// How long does the animation last diff --git a/Content.Client/DeltaV/Harpy/FlightSystem.cs b/Content.Client/Flight/FlightSystem.cs similarity index 88% rename from Content.Client/DeltaV/Harpy/FlightSystem.cs rename to Content.Client/Flight/FlightSystem.cs index d9c29076a52..49738a24997 100644 --- a/Content.Client/DeltaV/Harpy/FlightSystem.cs +++ b/Content.Client/Flight/FlightSystem.cs @@ -1,9 +1,9 @@ using Robust.Client.GameObjects; -using Content.Shared.DeltaV.Harpy; -using Content.Shared.DeltaV.Harpy.Events; -using Content.Client.DeltaV.Harpy.Components; +using Content.Shared.Flight; +using Content.Shared.Flight.Events; +using Content.Client.Flight.Components; -namespace Content.Client.DeltaV.Harpy +namespace Content.Client.Flight { public sealed class FlightSystem : SharedFlightSystem { @@ -36,20 +36,20 @@ private void OnFlight(FlightEvent args) if (args.IsFlying && args.IsAnimated && flight.AnimationKey != "default") { - var comp = new FlyingVisualsComponent + var comp = new FlightVisualsComponent { - AnimationKey = flight.AnimationKey, AnimateLayer = flight.IsLayerAnimated, - TargetLayer = targetLayer, - Speed = flight.ShaderSpeed, + AnimationKey = flight.AnimationKey, Multiplier = flight.ShaderMultiplier, Offset = flight.ShaderOffset, + Speed = flight.ShaderSpeed, + TargetLayer = targetLayer, }; AddComp(uid, comp); } if (!args.IsFlying) { - RemComp(uid); + RemComp(uid); } } diff --git a/Content.Client/DeltaV/Harpy/FlyingVisualsSystem.cs b/Content.Client/Flight/FlyingVisualizerSystem.cs similarity index 57% rename from Content.Client/DeltaV/Harpy/FlyingVisualsSystem.cs rename to Content.Client/Flight/FlyingVisualizerSystem.cs index cdd771a3b68..1b0157c203e 100644 --- a/Content.Client/DeltaV/Harpy/FlyingVisualsSystem.cs +++ b/Content.Client/Flight/FlyingVisualizerSystem.cs @@ -1,10 +1,9 @@ -using Content.Client.DeltaV.Harpy.Components; +using Content.Client.Flight.Components; using Robust.Client.GameObjects; using Robust.Client.Graphics; using Robust.Shared.Prototypes; -using Robust.Shared.Random; -namespace Content.Client.DeltaV.Harpy; +namespace Content.Client.Flight; /// /// Handles offsetting an entity while flying @@ -12,23 +11,23 @@ namespace Content.Client.DeltaV.Harpy; public sealed class FlyingVisualizerSystem : EntitySystem { [Dependency] private readonly IPrototypeManager _protoMan = default!; - [Dependency] private readonly IRobustRandom _random = default!; - [Dependency] private readonly IEntityManager _entityManager = default!; + [Dependency] private readonly SpriteSystem _spriteSystem = default!; public override void Initialize() { base.Initialize(); - SubscribeLocalEvent(OnStartup); - SubscribeLocalEvent(OnShutdown); - SubscribeLocalEvent(OnBeforeShaderPost); + SubscribeLocalEvent(OnStartup); + SubscribeLocalEvent(OnShutdown); + SubscribeLocalEvent(OnBeforeShaderPost); } - private void OnStartup(EntityUid uid, FlyingVisualsComponent comp, ComponentStartup args) + private void OnStartup(EntityUid uid, FlightVisualsComponent comp, ComponentStartup args) { comp.Shader = _protoMan.Index(comp.AnimationKey).InstanceUnique(); AddShader(uid, comp.Shader, comp.AnimateLayer, comp.TargetLayer); + SetValues(comp, comp.Speed, comp.Offset, comp.Multiplier); } - private void OnShutdown(EntityUid uid, FlyingVisualsComponent comp, ComponentShutdown args) + private void OnShutdown(EntityUid uid, FlightVisualsComponent comp, ComponentShutdown args) { AddShader(uid, null, comp.AnimateLayer, comp.TargetLayer); } @@ -47,15 +46,20 @@ private void AddShader(Entity entity, ShaderInstance? shader, { entity.Comp.LayerSetShader(layer.Value, shader); } - entity.Comp.GetScreenTexture = shader is not null; entity.Comp.RaiseShaderEvent = shader is not null; } - private void OnBeforeShaderPost(EntityUid uid, FlyingVisualsComponent comp, ref BeforePostShaderRenderEvent args) + private void OnBeforeShaderPost(EntityUid uid, FlightVisualsComponent comp, ref BeforePostShaderRenderEvent args) + { + // This function can be used to modify the shader's values while its running. + SetValues(comp, comp.Speed, comp.Offset, comp.Multiplier); + } + + private void SetValues(FlightVisualsComponent comp, float speed, float offset, float multiplier) { - comp.Shader.SetParameter("Speed", comp.Speed); - comp.Shader.SetParameter("Offset", comp.Offset); - comp.Shader.SetParameter("Multiplier", comp.Multiplier); + comp.Shader.SetParameter("Speed", speed); + comp.Shader.SetParameter("Offset", offset); + comp.Shader.SetParameter("Multiplier", multiplier); } } diff --git a/Content.Server/DeltaV/Harpy/FlyingVisualizerSystem.cs b/Content.Server/DeltaV/Harpy/FlyingVisualizerSystem.cs deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/Content.Server/DeltaV/Harpy/FlightSystem.cs b/Content.Server/Flight/FlightSystem.cs similarity index 98% rename from Content.Server/DeltaV/Harpy/FlightSystem.cs rename to Content.Server/Flight/FlightSystem.cs index 107bcac87e6..3da9951433f 100644 --- a/Content.Server/DeltaV/Harpy/FlightSystem.cs +++ b/Content.Server/Flight/FlightSystem.cs @@ -2,14 +2,15 @@ using Content.Shared.Cuffs.Components; using Content.Shared.Damage.Components; using Content.Shared.DoAfter; +using Content.Shared.Flight; +using Content.Shared.Flight.Events; using Content.Shared.Mobs; using Content.Shared.Popups; using Content.Shared.Stunnable; using Content.Shared.Zombies; using Robust.Shared.Audio.Systems; -using Content.Shared.DeltaV.Harpy.Events; -namespace Content.Shared.DeltaV.Harpy +namespace Content.Server.Flight { public sealed class FlightSystem : SharedFlightSystem { diff --git a/Content.Shared/Cuffs/SharedCuffableSystem.cs b/Content.Shared/Cuffs/SharedCuffableSystem.cs index 3097eacb96a..d9e3cbef013 100644 --- a/Content.Shared/Cuffs/SharedCuffableSystem.cs +++ b/Content.Shared/Cuffs/SharedCuffableSystem.cs @@ -7,7 +7,7 @@ using Content.Shared.Contests; using Content.Shared.Cuffs.Components; using Content.Shared.Database; -using Content.Shared.DeltaV.Harpy; +using Content.Shared.Flight; using Content.Shared.DoAfter; using Content.Shared.Hands; using Content.Shared.Hands.Components; diff --git a/Content.Shared/Damage/Components/StaminaComponent.cs b/Content.Shared/Damage/Components/StaminaComponent.cs index 7ee54411f2f..dd70d0c5b17 100644 --- a/Content.Shared/Damage/Components/StaminaComponent.cs +++ b/Content.Shared/Damage/Components/StaminaComponent.cs @@ -40,11 +40,11 @@ public sealed partial class StaminaComponent : Component public float CritThreshold = 100f; /// - /// A dictionary of active stamina drains, with the key being the source of the drain - /// and the value being the drain rate per second. + /// A dictionary of active stamina drains, with the key being the source of the drain, + /// DrainRate how much it changes per tick, and modifiesSpeed if it should slow down the user. /// [DataField("activeDrains"), AutoNetworkedField] - public Dictionary ActiveDrains = new(); + public Dictionary ActiveDrains = new(); /// /// How long will this mob be stunned for? diff --git a/Content.Shared/Damage/Systems/StaminaSystem.cs b/Content.Shared/Damage/Systems/StaminaSystem.cs index ed924c9c6c7..b9a91328543 100644 --- a/Content.Shared/Damage/Systems/StaminaSystem.cs +++ b/Content.Shared/Damage/Systems/StaminaSystem.cs @@ -258,7 +258,7 @@ public bool TryTakeStamina(EntityUid uid, float value, StaminaComponent? compone } public void TakeStaminaDamage(EntityUid uid, float value, StaminaComponent? component = null, - EntityUid? source = null, EntityUid? with = null, bool visual = true, SoundSpecifier? sound = null) + EntityUid? source = null, EntityUid? with = null, bool visual = true, SoundSpecifier? sound = null, bool? allowsSlowdown = true) { if (!Resolve(uid, ref component, false) || value == 0) @@ -284,8 +284,8 @@ public void TakeStaminaDamage(EntityUid uid, float value, StaminaComponent? comp if (component.NextUpdate < nextUpdate) component.NextUpdate = nextUpdate; } - - _movementSpeed.RefreshMovementSpeedModifiers(uid); + if (allowsSlowdown == true) + _movementSpeed.RefreshMovementSpeedModifiers(uid); SetStaminaAlert(uid, component); if (!component.Critical) @@ -328,7 +328,7 @@ public void TakeStaminaDamage(EntityUid uid, float value, StaminaComponent? comp } } - public void ToggleStaminaDrain(EntityUid target, float drainRate, bool enabled, EntityUid? source = null) + public void ToggleStaminaDrain(EntityUid target, float drainRate, bool enabled, bool modifiesSpeed, EntityUid? source = null) { if (!TryComp(target, out var stamina)) return; @@ -338,7 +338,7 @@ public void ToggleStaminaDrain(EntityUid target, float drainRate, bool enabled, if (enabled) { - stamina.ActiveDrains[actualSource] = drainRate; + stamina.ActiveDrains[actualSource] = (drainRate, modifiesSpeed); EnsureComp(target); } else @@ -369,9 +369,9 @@ public override void Update(float frameTime) } if (comp.ActiveDrains.Count > 0) { - foreach (var (source, drainRate) in comp.ActiveDrains) + foreach (var (source, (drainRate, modifiesSpeed)) in comp.ActiveDrains) { - TakeStaminaDamage(uid, drainRate * frameTime, comp, source: source, visual: false); + TakeStaminaDamage(uid, drainRate * frameTime, comp, source: source, visual: false, allowsSlowdown: modifiesSpeed); } } // Shouldn't need to consider paused time as we're only iterating non-paused stamina components. diff --git a/Content.Shared/DeltaV/Harpy/Events.cs b/Content.Shared/DeltaV/Harpy/Events.cs index d740ad45aaa..ab848f765da 100644 --- a/Content.Shared/DeltaV/Harpy/Events.cs +++ b/Content.Shared/DeltaV/Harpy/Events.cs @@ -1,5 +1,3 @@ -using Robust.Shared.GameObjects; -using Robust.Shared.Map; using Robust.Shared.Serialization; using Content.Shared.DoAfter; @@ -10,23 +8,4 @@ public sealed partial class DashDoAfterEvent : SimpleDoAfterEvent { } - [Serializable, NetSerializable] - public sealed partial class FlightDoAfterEvent : SimpleDoAfterEvent - { - } - - [Serializable, NetSerializable] - public sealed class FlightEvent : EntityEventArgs - { - public NetEntity Uid { get; } - public bool IsFlying { get; } - public bool IsAnimated { get; } - public FlightEvent(NetEntity uid, bool isFlying, bool isAnimated) - { - Uid = uid; - IsFlying = isFlying; - IsAnimated = isAnimated; - } - } - } diff --git a/Content.Shared/Flight/Events.cs b/Content.Shared/Flight/Events.cs new file mode 100644 index 00000000000..df0e13e2526 --- /dev/null +++ b/Content.Shared/Flight/Events.cs @@ -0,0 +1,30 @@ +using Robust.Shared.Serialization; +using Content.Shared.DoAfter; + +namespace Content.Shared.Flight.Events +{ + [Serializable, NetSerializable] + public sealed partial class DashDoAfterEvent : SimpleDoAfterEvent + { + } + + [Serializable, NetSerializable] + public sealed partial class FlightDoAfterEvent : SimpleDoAfterEvent + { + } + + [Serializable, NetSerializable] + public sealed class FlightEvent : EntityEventArgs + { + public NetEntity Uid { get; } + public bool IsFlying { get; } + public bool IsAnimated { get; } + public FlightEvent(NetEntity uid, bool isFlying, bool isAnimated) + { + Uid = uid; + IsFlying = isFlying; + IsAnimated = isAnimated; + } + } + +} diff --git a/Content.Shared/DeltaV/Harpy/FlightComponent.cs b/Content.Shared/Flight/FlightComponent.cs similarity index 95% rename from Content.Shared/DeltaV/Harpy/FlightComponent.cs rename to Content.Shared/Flight/FlightComponent.cs index 013caee6e8b..a3067fff068 100644 --- a/Content.Shared/DeltaV/Harpy/FlightComponent.cs +++ b/Content.Shared/Flight/FlightComponent.cs @@ -3,7 +3,7 @@ using Robust.Shared.Prototypes; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; -namespace Content.Shared.DeltaV.Harpy +namespace Content.Shared.Flight { /// /// Adds an action that allows the user to become temporarily @@ -30,7 +30,7 @@ public sealed partial class FlightComponent : Component /// [DataField("staminaDrainRate"), AutoNetworkedField] - public float StaminaDrainRate = 2.0f; + public float StaminaDrainRate = 6.0f; /// /// DoAfter delay until the user becomes weightless. @@ -43,7 +43,7 @@ public sealed partial class FlightComponent : Component /// Speed modifier while in flight /// - [DataField("activationDelay"), AutoNetworkedField] + [DataField("speedModifier"), AutoNetworkedField] public float SpeedModifier = 2.0f; /// diff --git a/Content.Shared/DeltaV/Harpy/SharedFlightSystem.cs b/Content.Shared/Flight/SharedFlightSystem.cs similarity index 85% rename from Content.Shared/DeltaV/Harpy/SharedFlightSystem.cs rename to Content.Shared/Flight/SharedFlightSystem.cs index 44a57456a1c..f69e2df2ed8 100644 --- a/Content.Shared/DeltaV/Harpy/SharedFlightSystem.cs +++ b/Content.Shared/Flight/SharedFlightSystem.cs @@ -6,9 +6,9 @@ using Content.Shared.Hands.EntitySystems; using Content.Shared.Interaction.Components; using Content.Shared.Inventory.VirtualItem; -using Content.Shared.DeltaV.Harpy.Events; +using Content.Shared.Flight.Events; -namespace Content.Shared.DeltaV.Harpy +namespace Content.Shared.Flight { public abstract class SharedFlightSystem : EntitySystem { @@ -16,7 +16,6 @@ public abstract class SharedFlightSystem : EntitySystem [Dependency] private readonly SharedVirtualItemSystem _virtualItem = default!; [Dependency] private readonly StaminaSystem _staminaSystem = default!; [Dependency] private readonly SharedHandsSystem _hands = default!; - [Dependency] private readonly MovementSpeedModifierSystem _movementSpeed = default!; public override void Initialize() @@ -25,7 +24,7 @@ public override void Initialize() SubscribeLocalEvent(OnStartup); SubscribeLocalEvent(OnShutdown); - // Move out to client: SubscribeLocalEvent(OnAnimationCompleted); + SubscribeLocalEvent(OnRefreshMoveSpeed); } #region Core Functions @@ -44,9 +43,9 @@ public void ToggleActive(EntityUid uid, bool active, FlightComponent component) component.On = active; component.TimeUntilFlap = 0f; _actionsSystem.SetToggled(component.ToggleActionEntity, component.On); - // Triggers the flight animation RaiseNetworkEvent(new FlightEvent(GetNetEntity(uid), component.On, component.IsAnimated)); - _staminaSystem.ToggleStaminaDrain(uid, component.StaminaDrainRate, active); + _staminaSystem.ToggleStaminaDrain(uid, component.StaminaDrainRate, active, false); + _movementSpeed.RefreshMovementSpeedModifiers(uid); UpdateHands(uid, active); Dirty(uid, component); } @@ -93,6 +92,16 @@ private void FreeHands(EntityUid uid) { _virtualItem.DeleteInHandsMatching(uid, uid); } + + private void OnRefreshMoveSpeed(EntityUid uid, FlightComponent component, RefreshMovementSpeedModifiersEvent args) + { + Logger.Debug("Refreshing movement speed!"); + if (!component.On) + return; + + args.ModifySpeed(component.SpeedModifier, component.SpeedModifier); + } + #endregion } public sealed partial class ToggleFlightEvent : InstantActionEvent diff --git a/Content.Shared/Gravity/SharedFloatingVisualizerSystem.cs b/Content.Shared/Gravity/SharedFloatingVisualizerSystem.cs index ce30c58c3eb..6aecd0e9c25 100644 --- a/Content.Shared/Gravity/SharedFloatingVisualizerSystem.cs +++ b/Content.Shared/Gravity/SharedFloatingVisualizerSystem.cs @@ -1,6 +1,6 @@ using System.Numerics; using Robust.Shared.Map; -using Content.Shared.DeltaV.Harpy.Events; +using Content.Shared.Flight.Events; namespace Content.Shared.Gravity; diff --git a/Content.Shared/Gravity/SharedGravitySystem.cs b/Content.Shared/Gravity/SharedGravitySystem.cs index 5f1f28df651..8d22c1beaeb 100644 --- a/Content.Shared/Gravity/SharedGravitySystem.cs +++ b/Content.Shared/Gravity/SharedGravitySystem.cs @@ -8,7 +8,7 @@ using Robust.Shared.Physics.Components; using Robust.Shared.Serialization; using Robust.Shared.Timing; -using Content.Shared.DeltaV.Harpy; +using Content.Shared.Flight; namespace Content.Shared.Gravity { diff --git a/Resources/Prototypes/Entities/Mobs/Species/harpy.yml b/Resources/Prototypes/Entities/Mobs/Species/harpy.yml index c5ebd069eaa..03a3867e4c5 100644 --- a/Resources/Prototypes/Entities/Mobs/Species/harpy.yml +++ b/Resources/Prototypes/Entities/Mobs/Species/harpy.yml @@ -212,8 +212,8 @@ components: - type: InstantAction checkCanInteract: false - icon: { sprite: DeltaV/Interface/Actions/flight.rsi, state: flight_off } - iconOn: { sprite : DeltaV/Interface/Actions/flight.rsi, state: flight_on } + icon: { sprite: Interface/Actions/flight.rsi, state: flight_off } + iconOn: { sprite : Interface/Actions/flight.rsi, state: flight_on } event: !type:ToggleFlightEvent - type: entity @@ -227,5 +227,5 @@ range: 16 itemIconStyle: BigAction checkCanAccess: false - icon: DeltaV/Interface/Actions/dash_flight.png + icon: Interface/Actions/dash_flight.png event: !type:ActivateDashEvent \ No newline at end of file diff --git a/Resources/Textures/DeltaV/Interface/Actions/dash_flight.png b/Resources/Textures/Interface/Actions/dash_flight.png similarity index 100% rename from Resources/Textures/DeltaV/Interface/Actions/dash_flight.png rename to Resources/Textures/Interface/Actions/dash_flight.png diff --git a/Resources/Textures/DeltaV/Interface/Actions/flight.rsi/flight_off.png b/Resources/Textures/Interface/Actions/flight.rsi/flight_off.png similarity index 100% rename from Resources/Textures/DeltaV/Interface/Actions/flight.rsi/flight_off.png rename to Resources/Textures/Interface/Actions/flight.rsi/flight_off.png diff --git a/Resources/Textures/DeltaV/Interface/Actions/flight.rsi/flight_on.png b/Resources/Textures/Interface/Actions/flight.rsi/flight_on.png similarity index 100% rename from Resources/Textures/DeltaV/Interface/Actions/flight.rsi/flight_on.png rename to Resources/Textures/Interface/Actions/flight.rsi/flight_on.png diff --git a/Resources/Textures/DeltaV/Interface/Actions/flight.rsi/meta.json b/Resources/Textures/Interface/Actions/flight.rsi/meta.json similarity index 100% rename from Resources/Textures/DeltaV/Interface/Actions/flight.rsi/meta.json rename to Resources/Textures/Interface/Actions/flight.rsi/meta.json