Skip to content

Commit

Permalink
Harpy flight release!
Browse files Browse the repository at this point in the history
  • Loading branch information
gluesniffler committed Sep 14, 2024
1 parent a1c7e6d commit d6bcd08
Show file tree
Hide file tree
Showing 19 changed files with 97 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// How long does the animation last
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -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<FlyingVisualsComponent>(uid);
RemComp<FlightVisualsComponent>(uid);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
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;

/// <summary>
/// Handles offsetting an entity while flying
/// </summary>
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<FlyingVisualsComponent, ComponentStartup>(OnStartup);
SubscribeLocalEvent<FlyingVisualsComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<FlyingVisualsComponent, BeforePostShaderRenderEvent>(OnBeforeShaderPost);
SubscribeLocalEvent<FlightVisualsComponent, ComponentStartup>(OnStartup);
SubscribeLocalEvent<FlightVisualsComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<FlightVisualsComponent, BeforePostShaderRenderEvent>(OnBeforeShaderPost);
}

private void OnStartup(EntityUid uid, FlyingVisualsComponent comp, ComponentStartup args)
private void OnStartup(EntityUid uid, FlightVisualsComponent comp, ComponentStartup args)
{
comp.Shader = _protoMan.Index<ShaderPrototype>(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);
}
Expand All @@ -47,15 +46,20 @@ private void AddShader(Entity<SpriteComponent?> 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);
}
}
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion Content.Shared/Cuffs/SharedCuffableSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions Content.Shared/Damage/Components/StaminaComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ public sealed partial class StaminaComponent : Component
public float CritThreshold = 100f;

/// <summary>
/// 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.
/// </summary>
[DataField("activeDrains"), AutoNetworkedField]
public Dictionary<EntityUid, float> ActiveDrains = new();
public Dictionary<EntityUid, (float DrainRate, bool ModifiesSpeed)> ActiveDrains = new();

/// <summary>
/// How long will this mob be stunned for?
Expand Down
14 changes: 7 additions & 7 deletions Content.Shared/Damage/Systems/StaminaSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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<StaminaComponent>(target, out var stamina))
return;
Expand All @@ -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<ActiveStaminaComponent>(target);
}
else
Expand Down Expand Up @@ -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.
Expand Down
21 changes: 0 additions & 21 deletions Content.Shared/DeltaV/Harpy/Events.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Serialization;
using Content.Shared.DoAfter;

Expand All @@ -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;
}
}

}
30 changes: 30 additions & 0 deletions Content.Shared/Flight/Events.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/// <summary>
/// Adds an action that allows the user to become temporarily
Expand All @@ -30,7 +30,7 @@ public sealed partial class FlightComponent : Component
/// </summary>

[DataField("staminaDrainRate"), AutoNetworkedField]
public float StaminaDrainRate = 2.0f;
public float StaminaDrainRate = 6.0f;

/// <summary>
/// DoAfter delay until the user becomes weightless.
Expand All @@ -43,7 +43,7 @@ public sealed partial class FlightComponent : Component
/// Speed modifier while in flight
/// </summary>

[DataField("activationDelay"), AutoNetworkedField]
[DataField("speedModifier"), AutoNetworkedField]
public float SpeedModifier = 2.0f;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@
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
{
[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()
Expand All @@ -25,7 +24,7 @@ public override void Initialize()

SubscribeLocalEvent<FlightComponent, ComponentStartup>(OnStartup);
SubscribeLocalEvent<FlightComponent, ComponentShutdown>(OnShutdown);
// Move out to client: SubscribeLocalEvent<FlightComponent, AnimationCompletedEvent>(OnAnimationCompleted);
SubscribeLocalEvent<FlightComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMoveSpeed);
}

#region Core Functions
Expand All @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Content.Shared/Gravity/SharedFloatingVisualizerSystem.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion Content.Shared/Gravity/SharedGravitySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
6 changes: 3 additions & 3 deletions Resources/Prototypes/Entities/Mobs/Species/harpy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit d6bcd08

Please sign in to comment.