From cfa9bc5812003a2119366611773e9446f1231f0f Mon Sep 17 00:00:00 2001 From: gluesniffler Date: Sat, 14 Sep 2024 15:02:30 -0400 Subject: [PATCH] Is this thing even working --- Content.Client/Flight/FlightSystem.cs | 98 ++++---- .../Flight/FlyingVisualizerSystem.cs | 9 +- Content.Server/Flight/FlightSystem.cs | 223 +++++++++--------- .../Damage/Components/StaminaComponent.cs | 4 +- .../Damage/Systems/StaminaSystem.cs | 16 +- Content.Shared/Flight/Events.cs | 40 ++-- Content.Shared/Flight/FlightComponent.cs | 167 +++++++------ Content.Shared/Flight/SharedFlightSystem.cs | 152 ++++++------ .../Gravity/SharedFloatingVisualizerSystem.cs | 9 +- .../Locale/en-US/flight/flight_system.ftl | 3 +- 10 files changed, 350 insertions(+), 371 deletions(-) diff --git a/Content.Client/Flight/FlightSystem.cs b/Content.Client/Flight/FlightSystem.cs index cf8000d99bc..bd1a6767bd9 100644 --- a/Content.Client/Flight/FlightSystem.cs +++ b/Content.Client/Flight/FlightSystem.cs @@ -3,71 +3,65 @@ using Content.Shared.Flight.Events; using Content.Client.Flight.Components; -namespace Content.Client.Flight +namespace Content.Client.Flight; +public sealed class FlightSystem : SharedFlightSystem { - public sealed class FlightSystem : SharedFlightSystem + [Dependency] private readonly IEntityManager _entityManager = default!; + public override void Initialize() { - [Dependency] private readonly IEntityManager _entityManager = default!; - public override void Initialize() - { - base.Initialize(); - - SubscribeNetworkEvent(OnFlight); + base.Initialize(); - } + SubscribeNetworkEvent(OnFlight); - private void OnFlight(FlightEvent args) - { - Logger.Debug("Starting onFlight!"); - var uid = GetEntity(args.Uid); - if (!_entityManager.TryGetComponent(uid, out SpriteComponent? sprite) - || !args.IsAnimated - || !_entityManager.TryGetComponent(uid, out FlightComponent? flight)) - return; + } + private void OnFlight(FlightEvent args) + { + var uid = GetEntity(args.Uid); + if (!_entityManager.TryGetComponent(uid, out SpriteComponent? sprite) + || !args.IsAnimated + || !_entityManager.TryGetComponent(uid, out FlightComponent? flight)) + return; - int? targetLayer = null; - if (flight.IsLayerAnimated && flight.Layer is not null) - { - targetLayer = GetAnimatedLayer(uid, flight.Layer, sprite); - if (targetLayer == null) - return; - } - if (args.IsFlying && args.IsAnimated && flight.AnimationKey != "default") - { - var comp = new FlightVisualsComponent - { - AnimateLayer = flight.IsLayerAnimated, - AnimationKey = flight.AnimationKey, - Multiplier = flight.ShaderMultiplier, - Offset = flight.ShaderOffset, - Speed = flight.ShaderSpeed, - TargetLayer = targetLayer, - }; - AddComp(uid, comp); - } - if (!args.IsFlying) - RemComp(uid); + int? targetLayer = null; + if (flight.IsLayerAnimated && flight.Layer is not null) + { + targetLayer = GetAnimatedLayer(uid, flight.Layer, sprite); + if (targetLayer == null) + return; } - public int? GetAnimatedLayer(EntityUid uid, string targetLayer, SpriteComponent? sprite = null) + if (args.IsFlying && args.IsAnimated && flight.AnimationKey != "default") { - if (!Resolve(uid, ref sprite)) - return null; - - int index = 0; - foreach (var layer in sprite.AllLayers) + var comp = new FlightVisualsComponent { - // This feels like absolute shitcode, isn't there a better way to check for it? - if (layer.Rsi?.Path.ToString() == targetLayer) - { - return index; - } - index++; - } + AnimateLayer = flight.IsLayerAnimated, + AnimationKey = flight.AnimationKey, + Multiplier = flight.ShaderMultiplier, + Offset = flight.ShaderOffset, + Speed = flight.ShaderSpeed, + TargetLayer = targetLayer, + }; + AddComp(uid, comp); + } + if (!args.IsFlying) + RemComp(uid); + } + public int? GetAnimatedLayer(EntityUid uid, string targetLayer, SpriteComponent? sprite = null) + { + if (!Resolve(uid, ref sprite)) return null; + + int index = 0; + foreach (var layer in sprite.AllLayers) + { + // This feels like absolute shitcode, isn't there a better way to check for it? + if (layer.Rsi?.Path.ToString() == targetLayer) + return index; + index++; } + return null; } } \ No newline at end of file diff --git a/Content.Client/Flight/FlyingVisualizerSystem.cs b/Content.Client/Flight/FlyingVisualizerSystem.cs index 51dfc70f147..6dde6cf5638 100644 --- a/Content.Client/Flight/FlyingVisualizerSystem.cs +++ b/Content.Client/Flight/FlyingVisualizerSystem.cs @@ -38,21 +38,20 @@ private void AddShader(Entity entity, ShaderInstance? shader, return; if (!animateLayer) - { entity.Comp.PostShader = shader; - } if (animateLayer && layer is not null) - { entity.Comp.LayerSetShader(layer.Value, shader); - } + entity.Comp.GetScreenTexture = shader is not null; entity.Comp.RaiseShaderEvent = shader is not null; } + /// + /// This function can be used to modify the shader's values while its running. + /// 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); } diff --git a/Content.Server/Flight/FlightSystem.cs b/Content.Server/Flight/FlightSystem.cs index 3da9951433f..e056fc24ec0 100644 --- a/Content.Server/Flight/FlightSystem.cs +++ b/Content.Server/Flight/FlightSystem.cs @@ -10,142 +10,149 @@ using Content.Shared.Zombies; using Robust.Shared.Audio.Systems; -namespace Content.Server.Flight +namespace Content.Server.Flight; +public sealed class FlightSystem : SharedFlightSystem { - public sealed class FlightSystem : SharedFlightSystem + [Dependency] private readonly SharedAudioSystem _audio = default!; + [Dependency] private readonly SharedDoAfterSystem _doAfter = default!; + [Dependency] private readonly SharedPopupSystem _popupSystem = default!; + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnToggleFlight); + SubscribeLocalEvent(OnFlightDoAfter); + SubscribeLocalEvent(OnMobStateChangedEvent); + SubscribeLocalEvent(OnZombified); + SubscribeLocalEvent(OnKnockedDown); + SubscribeLocalEvent(OnStunned); + SubscribeLocalEvent(OnSleep); + } + public override void Update(float frameTime) { - [Dependency] private readonly SharedAudioSystem _audio = default!; - [Dependency] private readonly SharedDoAfterSystem _doAfter = default!; - [Dependency] private readonly SharedPopupSystem _popupSystem = default!; + base.Update(frameTime); - public override void Initialize() + var query = EntityQueryEnumerator(); + while (query.MoveNext(out var uid, out var component)) { - base.Initialize(); - - SubscribeLocalEvent(OnToggleFlight); - SubscribeLocalEvent(OnFlightDoAfter); - SubscribeLocalEvent(OnMobStateChangedEvent); - SubscribeLocalEvent(OnZombified); - SubscribeLocalEvent(OnKnockedDown); - SubscribeLocalEvent(OnStunned); - SubscribeLocalEvent(OnSleep); - } - public override void Update(float frameTime) - { - base.Update(frameTime); + if (!component.On) + continue; - var query = EntityQueryEnumerator(); - while (query.MoveNext(out var uid, out var component)) - { - if (!component.On) - continue; + component.TimeUntilFlap -= frameTime; - component.TimeUntilFlap -= frameTime; + if (component.TimeUntilFlap > 0f) + continue; - if (component.TimeUntilFlap <= 0f) - { - _audio.PlayPvs(component.FlapSound, uid); - component.TimeUntilFlap = component.FlapInterval; - } - } - } + _audio.PlayPvs(component.FlapSound, uid); + component.TimeUntilFlap = component.FlapInterval; - #region Core Functions - private void OnToggleFlight(EntityUid uid, FlightComponent component, ToggleFlightEvent args) - { - // If the user isnt flying, we check for conditionals and initiate a doafter. - if (!component.On) - { - if (CanFly(uid, component)) - { - var doAfterArgs = new DoAfterArgs(EntityManager, uid, component.ActivationDelay, new FlightDoAfterEvent(), uid, target: uid) - { - BlockDuplicate = true, - BreakOnTargetMove = true, - BreakOnUserMove = true, - BreakOnDamage = true, - NeedHand = true - }; - - if (!_doAfter.TryStartDoAfter(doAfterArgs)) - { - return; - } - } - } - else - { - ToggleActive(uid, false, component); - } } + } - private void OnFlightDoAfter(EntityUid uid, FlightComponent component, FlightDoAfterEvent args) + #region Core Functions + private void OnToggleFlight(EntityUid uid, FlightComponent component, ToggleFlightEvent args) + { + // If the user isnt flying, we check for conditionals and initiate a doafter. + if (!component.On) { - if (args.Handled || args.Cancelled) + if (!CanFly(uid, component)) return; - ToggleActive(uid, true, component); - args.Handled = true; + var doAfterArgs = new DoAfterArgs(EntityManager, + uid, component.ActivationDelay, + new FlightDoAfterEvent(), uid, target: uid) + { + BlockDuplicate = true, + BreakOnTargetMove = true, + BreakOnUserMove = true, + BreakOnDamage = true, + NeedHand = true + }; + + if (!_doAfter.TryStartDoAfter(doAfterArgs)) + return; } + else + ToggleActive(uid, false, component); + } - #endregion - - #region Conditionals + private void OnFlightDoAfter(EntityUid uid, FlightComponent component, FlightDoAfterEvent args) + { + if (args.Handled || args.Cancelled) + return; - private bool CanFly(EntityUid uid, FlightComponent component) - { - var cuffed = TryComp(uid, out var cuffableComp) && !cuffableComp.CanStillInteract; - var zombified = TryComp(uid, out var _); + ToggleActive(uid, true, component); + args.Handled = true; + } - // Tell the user that they can not fly. - if (cuffed || zombified) - { - _popupSystem.PopupEntity(Loc.GetString("no-flight-while-restrained"), uid, uid, PopupType.Medium); - return false; - } + #endregion - return true; - } + #region Conditionals - private void OnMobStateChangedEvent(EntityUid uid, FlightComponent component, MobStateChangedEvent args) + private bool CanFly(EntityUid uid, FlightComponent component) + { + if (TryComp(uid, out var cuffableComp) && !cuffableComp.CanStillInteract) { - if (component.On && args.NewMobState is MobState.Critical or MobState.Dead) - ToggleActive(args.Target, false, component); + _popupSystem.PopupEntity(Loc.GetString("no-flight-while-restrained"), uid, uid, PopupType.Medium); + return false; } - private void OnZombified(EntityUid uid, FlightComponent component, ref EntityZombifiedEvent args) + if (HasComp(uid)) { - if (component.On) - { - ToggleActive(args.Target, false, component); - if (TryComp(uid, out var stamina)) - Dirty(uid, stamina); - } + _popupSystem.PopupEntity(Loc.GetString("no-flight-while-zombified"), uid, uid, PopupType.Medium); + return false; } + return true; + } - private void OnKnockedDown(EntityUid uid, FlightComponent component, ref KnockedDownEvent args) - { - if (component.On) - ToggleActive(uid, false, component); - } + private void OnMobStateChangedEvent(EntityUid uid, FlightComponent component, MobStateChangedEvent args) + { + if (!component.On + || args.NewMobState is MobState.Critical or MobState.Dead) + return; - private void OnStunned(EntityUid uid, FlightComponent component, ref StunnedEvent args) - { - if (component.On) - ToggleActive(uid, false, component); - } + ToggleActive(args.Target, false, component); + } - private void OnSleep(EntityUid uid, FlightComponent component, ref SleepStateChangedEvent args) - { - if (args.FellAsleep && component.On) - { - ToggleActive(uid, false, component); - if (TryComp(uid, out var stamina)) - Dirty(uid, stamina); - } - } + private void OnZombified(EntityUid uid, FlightComponent component, ref EntityZombifiedEvent args) + { + if (!component.On) + return; + + ToggleActive(args.Target, false, component); + if (!TryComp(uid, out var stamina)) + return; + Dirty(uid, stamina); + } + + private void OnKnockedDown(EntityUid uid, FlightComponent component, ref KnockedDownEvent args) + { + if (!component.On) + return; + + ToggleActive(uid, false, component); + } + + private void OnStunned(EntityUid uid, FlightComponent component, ref StunnedEvent args) + { + if (!component.On) + return; + + ToggleActive(uid, false, component); + } + + private void OnSleep(EntityUid uid, FlightComponent component, ref SleepStateChangedEvent args) + { + if (!component.On + || !args.FellAsleep) + return; - #endregion + ToggleActive(uid, false, component); + if (!TryComp(uid, out var stamina)) + return; + Dirty(uid, stamina); } + #endregion } \ No newline at end of file diff --git a/Content.Shared/Damage/Components/StaminaComponent.cs b/Content.Shared/Damage/Components/StaminaComponent.cs index 7a935f61902..b78fe978090 100644 --- a/Content.Shared/Damage/Components/StaminaComponent.cs +++ b/Content.Shared/Damage/Components/StaminaComponent.cs @@ -41,9 +41,9 @@ public sealed partial class StaminaComponent : Component /// /// 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. + /// DrainRate how much it changes per tick, and ModifiesSpeed if it should slow down the user. /// - [DataField("activeDrains"), AutoNetworkedField] + [DataField, AutoNetworkedField] public Dictionary ActiveDrains = new(); /// diff --git a/Content.Shared/Damage/Systems/StaminaSystem.cs b/Content.Shared/Damage/Systems/StaminaSystem.cs index 763cf65c572..e4840a6630b 100644 --- a/Content.Shared/Damage/Systems/StaminaSystem.cs +++ b/Content.Shared/Damage/Systems/StaminaSystem.cs @@ -342,9 +342,7 @@ public void ToggleStaminaDrain(EntityUid target, float drainRate, bool enabled, EnsureComp(target); } else - { stamina.ActiveDrains.Remove(actualSource); - } Dirty(target, stamina); } @@ -368,12 +366,13 @@ public override void Update(float frameTime) continue; } if (comp.ActiveDrains.Count > 0) - { foreach (var (source, (drainRate, modifiesSpeed)) in comp.ActiveDrains) - { - TakeStaminaDamage(uid, drainRate * frameTime, comp, source: source, visual: false, allowsSlowdown: modifiesSpeed); - } - } + 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. var nextUpdate = comp.NextUpdate; @@ -390,9 +389,8 @@ public override void Update(float frameTime) comp.NextUpdate += TimeSpan.FromSeconds(1f); // If theres no active drains, recover stamina. if (comp.ActiveDrains.Count == 0) - { TakeStaminaDamage(uid, -comp.Decay, comp); - } + Dirty(uid, comp); } } diff --git a/Content.Shared/Flight/Events.cs b/Content.Shared/Flight/Events.cs index f9bf1306387..6666971b539 100644 --- a/Content.Shared/Flight/Events.cs +++ b/Content.Shared/Flight/Events.cs @@ -1,30 +1,24 @@ using Robust.Shared.Serialization; using Content.Shared.DoAfter; -namespace Content.Shared.Flight.Events -{ - [Serializable, NetSerializable] - public sealed partial class DashDoAfterEvent : SimpleDoAfterEvent - { - } +namespace Content.Shared.Flight.Events; - [Serializable, NetSerializable] - public sealed partial class FlightDoAfterEvent : SimpleDoAfterEvent - { - } +[Serializable, NetSerializable] +public sealed partial class DashDoAfterEvent : SimpleDoAfterEvent { } + +[Serializable, NetSerializable] +public sealed partial class FlightDoAfterEvent : SimpleDoAfterEvent { } - [Serializable, NetSerializable] - public sealed class FlightEvent : EntityEventArgs +[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) { - 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; - } + Uid = uid; + IsFlying = isFlying; + IsAnimated = isAnimated; } - -} \ No newline at end of file +} diff --git a/Content.Shared/Flight/FlightComponent.cs b/Content.Shared/Flight/FlightComponent.cs index a3067fff068..d250744544d 100644 --- a/Content.Shared/Flight/FlightComponent.cs +++ b/Content.Shared/Flight/FlightComponent.cs @@ -3,108 +3,99 @@ using Robust.Shared.Prototypes; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; -namespace Content.Shared.Flight +namespace Content.Shared.Flight; + +/// +/// Adds an action that allows the user to become temporarily +/// weightless at the cost of stamina and hand usage. +/// +[RegisterComponent, NetworkedComponent(), AutoGenerateComponentState] +public sealed partial class FlightComponent : Component { - /// - /// Adds an action that allows the user to become temporarily - /// weightless at the cost of stamina and hand usage. - /// - [RegisterComponent, NetworkedComponent(), AutoGenerateComponentState] - public sealed partial class FlightComponent : Component - { - [DataField("toggleAction", customTypeSerializer: typeof(PrototypeIdSerializer))] - public string? ToggleAction = "ActionToggleFlight"; - - [DataField, AutoNetworkedField] - public EntityUid? ToggleActionEntity; - - /// - /// Is the user flying right now? - /// - - [DataField("on"), AutoNetworkedField] - public bool On; - - /// - /// Stamina drain per second when flying - /// - - [DataField("staminaDrainRate"), AutoNetworkedField] - public float StaminaDrainRate = 6.0f; - - /// - /// DoAfter delay until the user becomes weightless. - /// - - [DataField("activationDelay"), AutoNetworkedField] - public float ActivationDelay = 1.0f; + [DataField(customTypeSerializer: typeof(PrototypeIdSerializer))] + public string? ToggleAction = "ActionToggleFlight"; - /// - /// Speed modifier while in flight - /// + [DataField, AutoNetworkedField] + public EntityUid? ToggleActionEntity; - [DataField("speedModifier"), AutoNetworkedField] - public float SpeedModifier = 2.0f; - - /// - /// Path to a sound specifier or collection for the noises made during flight - /// + /// + /// Is the user flying right now? + /// + [DataField, AutoNetworkedField] + public bool On; - [DataField("flapSound")] - public SoundSpecifier FlapSound = new SoundCollectionSpecifier("WingFlaps"); + /// + /// Stamina drain per second when flying + /// + [DataField, AutoNetworkedField] + public float StaminaDrainRate = 6.0f; - /// - /// Is the flight animated? - /// + /// + /// DoAfter delay until the user becomes weightless. + /// + [DataField, AutoNetworkedField] + public float ActivationDelay = 1.0f; - [DataField("isAnimated")] - public bool IsAnimated = true; + /// + /// Speed modifier while in flight + /// + [DataField, AutoNetworkedField] + public float SpeedModifier = 2.0f; - /// - /// Does the animation animate a layer?. - /// + /// + /// Path to a sound specifier or collection for the noises made during flight + /// + [DataField] + public SoundSpecifier FlapSound = new SoundCollectionSpecifier("WingFlaps"); - [DataField("isLayerAnimated")] - public bool IsLayerAnimated = false; + /// + /// Is the flight animated? + /// + [DataField] + public bool IsAnimated = true; - /// - /// Which RSI layer path does this animate? - /// + /// + /// Does the animation animate a layer?. + /// + [DataField] + public bool IsLayerAnimated; - [DataField("layer")] - public string? Layer; + /// + /// Which RSI layer path does this animate? + /// + [DataField] + public string? Layer; - /// - /// Whats the speed of the shader? - /// - [DataField("speed")] - public float ShaderSpeed = 6.0f; + /// + /// Whats the speed of the shader? + /// + [DataField] + public float ShaderSpeed = 6.0f; - /// - /// How much are the values in the shader's calculations multiplied by? - /// - [DataField("multiplier")] - public float ShaderMultiplier = 0.01f; + /// + /// How much are the values in the shader's calculations multiplied by? + /// + [DataField] + public float ShaderMultiplier = 0.01f; - /// - /// What is the offset on the shader? - /// - [DataField("offset")] - public float ShaderOffset = 0.25f; + /// + /// What is the offset on the shader? + /// + [DataField] + public float ShaderOffset = 0.25f; - /// - /// What animation does the flight use? - /// + /// + /// What animation does the flight use? + /// - [DataField("animationKey")] - public string AnimationKey = "default"; + [DataField] + public string AnimationKey = "default"; - /// - /// Time between sounds being played - /// - [DataField("flapInterval")] - public float FlapInterval = 1.0f; + /// + /// Time between sounds being played + /// + [DataField] + public float FlapInterval = 1.0f; - public float TimeUntilFlap; - } -} \ No newline at end of file + public float TimeUntilFlap; +} diff --git a/Content.Shared/Flight/SharedFlightSystem.cs b/Content.Shared/Flight/SharedFlightSystem.cs index 8f986729885..281c6d70f08 100644 --- a/Content.Shared/Flight/SharedFlightSystem.cs +++ b/Content.Shared/Flight/SharedFlightSystem.cs @@ -1,4 +1,3 @@ - using Content.Shared.Actions; using Content.Shared.Movement.Systems; using Content.Shared.Damage.Systems; @@ -8,103 +7,98 @@ using Content.Shared.Inventory.VirtualItem; using Content.Shared.Flight.Events; -namespace Content.Shared.Flight +namespace Content.Shared.Flight; +public abstract class SharedFlightSystem : EntitySystem { - public abstract class SharedFlightSystem : EntitySystem - { - [Dependency] private readonly SharedActionsSystem _actionsSystem = default!; - [Dependency] private readonly SharedVirtualItemSystem _virtualItem = default!; - [Dependency] private readonly StaminaSystem _staminaSystem = default!; - [Dependency] private readonly SharedHandsSystem _hands = default!; - [Dependency] private readonly MovementSpeedModifierSystem _movementSpeed = default!; + [Dependency] private readonly SharedActionsSystem _actionsSystem = default!; + [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() - { - base.Initialize(); + public override void Initialize() + { + base.Initialize(); - SubscribeLocalEvent(OnStartup); - SubscribeLocalEvent(OnShutdown); - SubscribeLocalEvent(OnRefreshMoveSpeed); - } + SubscribeLocalEvent(OnStartup); + SubscribeLocalEvent(OnShutdown); + SubscribeLocalEvent(OnRefreshMoveSpeed); + } - #region Core Functions - private void OnStartup(EntityUid uid, FlightComponent component, ComponentStartup args) - { - _actionsSystem.AddAction(uid, ref component.ToggleActionEntity, component.ToggleAction); - } + #region Core Functions + private void OnStartup(EntityUid uid, FlightComponent component, ComponentStartup args) + { + _actionsSystem.AddAction(uid, ref component.ToggleActionEntity, component.ToggleAction); + } - private void OnShutdown(EntityUid uid, FlightComponent component, ComponentShutdown args) - { - _actionsSystem.RemoveAction(uid, component.ToggleActionEntity); - } + private void OnShutdown(EntityUid uid, FlightComponent component, ComponentShutdown args) + { + _actionsSystem.RemoveAction(uid, component.ToggleActionEntity); + } - public void ToggleActive(EntityUid uid, bool active, FlightComponent component) - { - component.On = active; - component.TimeUntilFlap = 0f; - _actionsSystem.SetToggled(component.ToggleActionEntity, component.On); - RaiseNetworkEvent(new FlightEvent(GetNetEntity(uid), component.On, component.IsAnimated)); - _staminaSystem.ToggleStaminaDrain(uid, component.StaminaDrainRate, active, false); - _movementSpeed.RefreshMovementSpeedModifiers(uid); - UpdateHands(uid, active); - Dirty(uid, component); - } + public void ToggleActive(EntityUid uid, bool active, FlightComponent component) + { + component.On = active; + component.TimeUntilFlap = 0f; + _actionsSystem.SetToggled(component.ToggleActionEntity, component.On); + RaiseNetworkEvent(new FlightEvent(GetNetEntity(uid), component.On, component.IsAnimated)); + _staminaSystem.ToggleStaminaDrain(uid, component.StaminaDrainRate, active, false); + _movementSpeed.RefreshMovementSpeedModifiers(uid); + UpdateHands(uid, active); + Dirty(uid, component); + } - private void UpdateHands(EntityUid uid, bool flying) - { - if (!TryComp(uid, out var handsComponent)) - return; + private void UpdateHands(EntityUid uid, bool flying) + { + if (!TryComp(uid, out var handsComponent)) + return; - if (flying) - BlockHands(uid, handsComponent); - else - FreeHands(uid); - } + if (flying) + BlockHands(uid, handsComponent); + else + FreeHands(uid); + } - private void BlockHands(EntityUid uid, HandsComponent handsComponent) + private void BlockHands(EntityUid uid, HandsComponent handsComponent) + { + var freeHands = 0; + foreach (var hand in _hands.EnumerateHands(uid, handsComponent)) { - var freeHands = 0; - foreach (var hand in _hands.EnumerateHands(uid, handsComponent)) + if (hand.HeldEntity == null) { - if (hand.HeldEntity == null) - { - freeHands++; - continue; - } - - // Is this entity removable? (they might have handcuffs on) - if (HasComp(hand.HeldEntity) && hand.HeldEntity != uid) - continue; - - _hands.DoDrop(uid, hand, true, handsComponent); freeHands++; - if (freeHands == 2) - break; + continue; } - if (_virtualItem.TrySpawnVirtualItemInHand(uid, uid, out var virtItem1)) - EnsureComp(virtItem1.Value); - if (_virtualItem.TrySpawnVirtualItemInHand(uid, uid, out var virtItem2)) - EnsureComp(virtItem2.Value); - } + // Is this entity removable? (they might have handcuffs on) + if (HasComp(hand.HeldEntity) && hand.HeldEntity != uid) + continue; - private void FreeHands(EntityUid uid) - { - _virtualItem.DeleteInHandsMatching(uid, uid); + _hands.DoDrop(uid, hand, true, handsComponent); + freeHands++; + if (freeHands == 2) + break; } + if (_virtualItem.TrySpawnVirtualItemInHand(uid, uid, out var virtItem1)) + EnsureComp(virtItem1.Value); - private void OnRefreshMoveSpeed(EntityUid uid, FlightComponent component, RefreshMovementSpeedModifiersEvent args) - { - Logger.Debug("Refreshing movement speed!"); - if (!component.On) - return; - - args.ModifySpeed(component.SpeedModifier, component.SpeedModifier); - } + if (_virtualItem.TrySpawnVirtualItemInHand(uid, uid, out var virtItem2)) + EnsureComp(virtItem2.Value); + } - #endregion + private void FreeHands(EntityUid uid) + { + _virtualItem.DeleteInHandsMatching(uid, uid); } - public sealed partial class ToggleFlightEvent : InstantActionEvent + + private void OnRefreshMoveSpeed(EntityUid uid, FlightComponent component, RefreshMovementSpeedModifiersEvent args) { + 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 1b8e47d44a3..8fe9e00e7eb 100644 --- a/Content.Shared/Gravity/SharedFloatingVisualizerSystem.cs +++ b/Content.Shared/Gravity/SharedFloatingVisualizerSystem.cs @@ -71,10 +71,11 @@ private void OnFlight(FlightEvent args) return; floating.CanFloat = args.IsFlying; - if (args.IsFlying && args.IsAnimated) - { - FloatAnimation(uid, floating.Offset, floating.AnimationKey, floating.AnimationTime); - } + if (!args.IsFlying + || !args.IsAnimated) + return; + + FloatAnimation(uid, floating.Offset, floating.AnimationKey, floating.AnimationTime); } private void OnEntParentChanged(EntityUid uid, FloatingVisualsComponent component, ref EntParentChangedMessage args) diff --git a/Resources/Locale/en-US/flight/flight_system.ftl b/Resources/Locale/en-US/flight/flight_system.ftl index 129a3bbc7a0..12693cc8467 100644 --- a/Resources/Locale/en-US/flight/flight_system.ftl +++ b/Resources/Locale/en-US/flight/flight_system.ftl @@ -1 +1,2 @@ -no-flight-while-restrained = You can't fly right now. \ No newline at end of file +no-flight-while-restrained = You can't fly right now. +no-flight-while-zombified = You can't use your wings right now. \ No newline at end of file