mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 13:37:47 +03:00
# Description
This PR adds a generic system which gives an entity the ability to fly.
Optionally increasing their speed in exchange for a continuous stamina
drain, which can, and **will** stamcrit them if left unchecked.
---
# Technical Details?
We normally dont have this section but I'd like to outline the changes
since I messed with quite a few systems:
- Introduces a `FlightComponent` which can be added to any entity in
YML, needs to be tied to an action with an event of type
`ToggleFlightEvent` This component holds properties for:
- Toggling animations on and off, either at the entity level or the
layer level.
- Altering shader animation properties
- Altering speed, stamina drain, sounds played, delay between sounds,
etc etc.
- Adds a `FlyingVisualizerSystem` that can take a given `AnimationKey`
which points to a shader, and optionally can apply it to either the
entire sprite, or a given layer.
- Adds a check in `SharedGravitySystem` for making the entity weightless
when it has the `FlightComponent` and is flying.
- Adds a check in `SharedCuffableSystem` to disable cuffing when the
target has the `FlightComponent` and is flying.
- Introduces a new field in the `StaminaComponent` which serves as a
dictionary for persistent drains, with the key being the source (UID) of
where it came from. The drains can also indicate if they should apply
the stamina slowdown or not (relevant for both this PR, and for an
eventual sprinting PR)
---
<details><summary><h1>Media</h1></summary>
<p>
[](https://youtu.be/Wndv9hYaZ_s
"Flight Demo")
</p>
</details>
---
# Changelog
🆑 Mocho
- add: Harpies are now able to fly on station for limited periods of
time, moving faster at the cost of stamina.
---------
Signed-off-by: gluesniffler <159397573+gluesniffler@users.noreply.github.com>
Co-authored-by: VMSolidus <evilexecutive@gmail.com>
64 lines
2.4 KiB
C#
64 lines
2.4 KiB
C#
using Content.Client.Flight.Components;
|
|
using Robust.Client.GameObjects;
|
|
using Robust.Client.Graphics;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
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 SpriteSystem _spriteSystem = default!;
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<FlightVisualsComponent, ComponentStartup>(OnStartup);
|
|
SubscribeLocalEvent<FlightVisualsComponent, ComponentShutdown>(OnShutdown);
|
|
SubscribeLocalEvent<FlightVisualsComponent, BeforePostShaderRenderEvent>(OnBeforeShaderPost);
|
|
}
|
|
|
|
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, FlightVisualsComponent comp, ComponentShutdown args)
|
|
{
|
|
AddShader(uid, null, comp.AnimateLayer, comp.TargetLayer);
|
|
}
|
|
|
|
private void AddShader(Entity<SpriteComponent?> entity, ShaderInstance? shader, bool animateLayer, int? layer)
|
|
{
|
|
if (!Resolve(entity, ref entity.Comp, false))
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// This function can be used to modify the shader's values while its running.
|
|
/// </summary>
|
|
private void OnBeforeShaderPost(EntityUid uid, FlightVisualsComponent comp, ref BeforePostShaderRenderEvent args)
|
|
{
|
|
SetValues(comp, comp.Speed, comp.Offset, comp.Multiplier);
|
|
}
|
|
|
|
private void SetValues(FlightVisualsComponent comp, float speed, float offset, float multiplier)
|
|
{
|
|
comp.Shader.SetParameter("Speed", speed);
|
|
comp.Shader.SetParameter("Offset", offset);
|
|
comp.Shader.SetParameter("Multiplier", multiplier);
|
|
}
|
|
} |