mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-25 01:27:06 +03:00
# Description Adds a CVAR that when enabled, allows entities to crawl under tables/flaps by lowering their DrawDepth, which in turn protects them from being targeted for projectiles while crawling. Additionally tables and plastic flaps were given collision properties along with reduced damage thresholds, so guns can target & destroy them easily if your mouse is on top of them. --- <h1>Media</h1> <p> https://github.com/user-attachments/assets/77a04198-11cb-4895-bf2d-6f82b7f2bb5b </p> </details> --- # Changelog 🆑 - add: Adds an optional server variable which allows entities to crawl under tables. - tweak: Tables and plastic flaps are less resistant to damage, and can now be targeted by guns by aiming on top of them. --------- Signed-off-by: gluesniffler <159397573+gluesniffler@users.noreply.github.com> Co-authored-by: VMSolidus <evilexecutive@gmail.com>
176 lines
5.4 KiB
C#
176 lines
5.4 KiB
C#
|
|
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.Standing;
|
|
using Content.Shared.Stunnable;
|
|
using Content.Shared.Zombies;
|
|
using Robust.Shared.Audio.Systems;
|
|
|
|
namespace Content.Server.Flight;
|
|
public sealed class FlightSystem : SharedFlightSystem
|
|
{
|
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
|
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
|
|
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
|
|
[Dependency] private readonly StandingStateSystem _standing = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<FlightComponent, ToggleFlightEvent>(OnToggleFlight);
|
|
SubscribeLocalEvent<FlightComponent, FlightDoAfterEvent>(OnFlightDoAfter);
|
|
SubscribeLocalEvent<FlightComponent, MobStateChangedEvent>(OnMobStateChangedEvent);
|
|
SubscribeLocalEvent<FlightComponent, EntityZombifiedEvent>(OnZombified);
|
|
SubscribeLocalEvent<FlightComponent, KnockedDownEvent>(OnKnockedDown);
|
|
SubscribeLocalEvent<FlightComponent, StunnedEvent>(OnStunned);
|
|
SubscribeLocalEvent<FlightComponent, DownedEvent>(OnDowned);
|
|
SubscribeLocalEvent<FlightComponent, SleepStateChangedEvent>(OnSleep);
|
|
}
|
|
public override void Update(float frameTime)
|
|
{
|
|
base.Update(frameTime);
|
|
|
|
var query = EntityQueryEnumerator<FlightComponent>();
|
|
while (query.MoveNext(out var uid, out var component))
|
|
{
|
|
if (!component.On)
|
|
continue;
|
|
|
|
component.TimeUntilFlap -= frameTime;
|
|
|
|
if (component.TimeUntilFlap > 0f)
|
|
continue;
|
|
|
|
_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))
|
|
return;
|
|
|
|
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)
|
|
{
|
|
if (args.Handled || args.Cancelled)
|
|
return;
|
|
|
|
ToggleActive(uid, true, component);
|
|
args.Handled = true;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Conditionals
|
|
|
|
private bool CanFly(EntityUid uid, FlightComponent component)
|
|
{
|
|
if (TryComp<CuffableComponent>(uid, out var cuffableComp) && !cuffableComp.CanStillInteract)
|
|
{
|
|
_popupSystem.PopupEntity(Loc.GetString("no-flight-while-restrained"), uid, uid, PopupType.Medium);
|
|
return false;
|
|
}
|
|
|
|
if (HasComp<ZombieComponent>(uid))
|
|
{
|
|
_popupSystem.PopupEntity(Loc.GetString("no-flight-while-zombified"), uid, uid, PopupType.Medium);
|
|
return false;
|
|
}
|
|
|
|
if (HasComp<StandingStateComponent>(uid) && _standing.IsDown(uid))
|
|
{
|
|
_popupSystem.PopupEntity(Loc.GetString("no-flight-while-lying"), uid, uid, PopupType.Medium);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
private void OnMobStateChangedEvent(EntityUid uid, FlightComponent component, MobStateChangedEvent args)
|
|
{
|
|
if (!component.On
|
|
|| args.NewMobState is MobState.Critical or MobState.Dead)
|
|
return;
|
|
|
|
ToggleActive(args.Target, false, component);
|
|
}
|
|
|
|
private void OnZombified(EntityUid uid, FlightComponent component, ref EntityZombifiedEvent args)
|
|
{
|
|
if (!component.On)
|
|
return;
|
|
|
|
ToggleActive(args.Target, false, component);
|
|
if (!TryComp<StaminaComponent>(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 OnDowned(EntityUid uid, FlightComponent component, ref DownedEvent 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;
|
|
|
|
ToggleActive(uid, false, component);
|
|
if (!TryComp<StaminaComponent>(uid, out var stamina))
|
|
return;
|
|
|
|
Dirty(uid, stamina);
|
|
}
|
|
#endregion
|
|
} |