Files
tbd-station-14/Content.Server/Doors/Systems/DoorSystem.cs
deltanedas c1cda0dbf8 [Antag] add space ninja as midround antag (#14069)
* start of space ninja midround antag

* suit has powercell, can be upgraded only (not replaced with equal or worse battery)

* add doorjacking to ninja gloves, power cell, doorjack objective (broken), tweaks

* 💀

* add basic suit power display that uses stamina rsi

* add draining apc/sub/smes - no wires yet

* add research downloading

* ninja starts implanted, move some stuff to yaml

* add Automated field to OnUseTimerTrigger

* implement spider charge and objective

* fix client crash when taking suit off, some refactor

* add survive condition and tweak locale

* add comms console icon for objective

* add calling in a threat - currently revenant and dragon

* combine all glove abilities

* locale

* spark sounds when draining, refactoring

* toggle is actually toggle now

* prevent crash if disabling stealth with outline

* add antag ctrl for ninja, hopefully show greentext

* fix greentext and some other things

* disabling gloves if taken off or suit taken off

* basic energy katana, change ninja loadout

* recallable katana, refactoring

* start of dash - not done yet

* katana dashing ability

* merge upstream + compiling, make AutomatedTimer its own component

* docs and stuff

* partial refactor of glove abilities, still need to move handling

* make dooremaggedevent by ref

* move bunch of stuff to shared - broken

* clean ninja antag verb

* doc

* mark rule config fields as required

* fix client crash

* wip systems refactor

* big refactor of systems

* fuck

* make TryDoElectrocution callable from shared

* finish refactoring?

* no guns

* start with internals on

* clean up glove abilities, add range check

* create soap, in place of ninja throwing stars

* add emp suit ability

* able to eat chefs stolen food in space

* stuff, tell client when un/cloaked but there is bug with gloves

* fix prediction breaking gloves on client

* ninja soap despawns after a minute

* ninja spawns outside the station now, with gps + station coords to navigate

* add cooldown to stun ability

* cant use glove abilities in combat mode

* require empty hand to use glove abilities

* use ghost role spawner

* Update Content.Server/Ninja/Systems/NinjaSuitSystem.cs

Co-authored-by: keronshb <54602815+keronshb@users.noreply.github.com>

* some review changes

* show powercell charge on examine

* new is needed

* address some reviews

* ninja starts with jetpack, i hope

* partial feedback

* uhh

* pro

* remove pirate from threats list

* use doafter refactor

* pro i gave skeleton jetpack

* some stuff

* use auto gen state

* mr handy

* use EntityQueryEnumerator

* cleanup

* spider charge target anti-troll

* mmmmmm

---------

Co-authored-by: deltanedas <deltanedas@laptop>
Co-authored-by: deltanedas <user@zenith>
Co-authored-by: deltanedas <@deltanedas:kde.org>
Co-authored-by: keronshb <54602815+keronshb@users.noreply.github.com>
2023-04-17 01:33:27 -06:00

314 lines
12 KiB
C#

using Content.Server.Access;
using Content.Server.Atmos.Components;
using Content.Server.Atmos.EntitySystems;
using Content.Server.Construction;
using Content.Server.Tools.Systems;
using Content.Shared.Access.Components;
using Content.Shared.Access.Systems;
using Content.Shared.Database;
using Content.Shared.Doors;
using Content.Shared.Doors.Components;
using Content.Shared.Doors.Systems;
using Content.Shared.Emag.Systems;
using Content.Shared.Interaction;
using Content.Shared.Tools.Components;
using Content.Shared.Verbs;
using Robust.Shared.Audio;
using Robust.Shared.Containers;
using System.Linq;
using Content.Server.Power.EntitySystems;
using Content.Shared.Tools;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Events;
using Content.Shared.DoAfter;
namespace Content.Server.Doors.Systems;
public sealed class DoorSystem : SharedDoorSystem
{
[Dependency] private readonly AccessReaderSystem _accessReaderSystem = default!;
[Dependency] private readonly AirlockSystem _airlock = default!;
[Dependency] private readonly AirtightSystem _airtightSystem = default!;
[Dependency] private readonly ConstructionSystem _constructionSystem = default!;
[Dependency] private readonly SharedToolSystem _toolSystem = default!;
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<DoorComponent, InteractUsingEvent>(OnInteractUsing, after: new[] { typeof(ConstructionSystem) });
// Mob prying doors
SubscribeLocalEvent<DoorComponent, GetVerbsEvent<AlternativeVerb>>(OnDoorAltVerb);
SubscribeLocalEvent<DoorComponent, DoorPryDoAfterEvent>(OnPryFinished);
SubscribeLocalEvent<DoorComponent, WeldableAttemptEvent>(OnWeldAttempt);
SubscribeLocalEvent<DoorComponent, WeldableChangedEvent>(OnWeldChanged);
SubscribeLocalEvent<DoorComponent, GotEmaggedEvent>(OnEmagged);
}
protected override void OnActivate(EntityUid uid, DoorComponent door, ActivateInWorldEvent args)
{
// TODO once access permissions are shared, move this back to shared.
if (args.Handled || !door.ClickOpen)
return;
TryToggleDoor(uid, door, args.User);
args.Handled = true;
}
protected override void SetCollidable(
EntityUid uid,
bool collidable,
DoorComponent? door = null,
PhysicsComponent? physics = null,
OccluderComponent? occluder = null)
{
if (!Resolve(uid, ref door))
return;
if (door.ChangeAirtight && TryComp(uid, out AirtightComponent? airtight))
_airtightSystem.SetAirblocked(uid, airtight, collidable);
// Pathfinding / AI stuff.
RaiseLocalEvent(new AccessReaderChangeEvent(uid, collidable));
base.SetCollidable(uid, collidable, door, physics, occluder);
}
// TODO AUDIO PREDICT Figure out a better way to handle sound and prediction. For now, this works well enough?
//
// Currently a client will predict when a door is going to close automatically. So any client in PVS range can just
// play their audio locally. Playing it server-side causes an odd delay, while in shared it causes double-audio.
//
// But if we just do that, then if a door is closed prematurely as the result of an interaction (i.e., using "E" on
// an open door), then the audio would only be played for the client performing the interaction.
//
// So we do this:
// - Play audio client-side IF the closing is being predicted (auto-close or predicted interaction)
// - Server assumes automated closing is predicted by clients and does not play audio unless otherwise specified.
// - Major exception is player interactions, which other players cannot predict
// - In that case, send audio to all players, except possibly the interacting player if it was a predicted
// interaction.
/// <summary>
/// Selectively send sound to clients, taking care to not send the double-audio.
/// </summary>
/// <param name="uid">The audio source</param>
/// <param name="soundSpecifier">The sound</param>
/// <param name="audioParams">The audio parameters.</param>
/// <param name="predictingPlayer">The user (if any) that instigated an interaction</param>
/// <param name="predicted">Whether this interaction would have been predicted. If the predicting player is null,
/// this assumes it would have been predicted by all players in PVS range.</param>
protected override void PlaySound(EntityUid uid, SoundSpecifier soundSpecifier, AudioParams audioParams, EntityUid? predictingPlayer, bool predicted)
{
// If this sound would have been predicted by all clients, do not play any audio.
if (predicted && predictingPlayer == null)
return;
if (predicted)
Audio.PlayPredicted(soundSpecifier, uid, predictingPlayer, audioParams);
else
Audio.PlayPvs(soundSpecifier, uid, audioParams);
}
#region DoAfters
/// <summary>
/// Weld or pry open a door.
/// </summary>
private void OnInteractUsing(EntityUid uid, DoorComponent door, InteractUsingEvent args)
{
if (args.Handled)
return;
if (!TryComp(args.Used, out ToolComponent? tool))
return;
if (tool.Qualities.Contains(door.PryingQuality))
{
args.Handled = TryPryDoor(uid, args.Used, args.User, door);
}
}
private void OnWeldAttempt(EntityUid uid, DoorComponent component, WeldableAttemptEvent args)
{
if (component.CurrentlyCrushing.Count > 0)
{
args.Cancel();
return;
}
if (component.State != DoorState.Closed && component.State != DoorState.Welded)
{
args.Cancel();
}
}
private void OnWeldChanged(EntityUid uid, DoorComponent component, WeldableChangedEvent args)
{
if (component.State == DoorState.Closed)
SetState(uid, DoorState.Welded, component);
else if (component.State == DoorState.Welded)
SetState(uid, DoorState.Closed, component);
}
private void OnDoorAltVerb(EntityUid uid, DoorComponent component, GetVerbsEvent<AlternativeVerb> args)
{
if (!args.CanInteract || !args.CanAccess)
return;
if (!TryComp<ToolComponent>(args.User, out var tool) || !tool.Qualities.Contains(component.PryingQuality))
return;
args.Verbs.Add(new AlternativeVerb()
{
Text = Loc.GetString("door-pry"),
Impact = LogImpact.Low,
Act = () => TryPryDoor(uid, args.User, args.User, component, true),
});
}
/// <summary>
/// Pry open a door. This does not check if the user is holding the required tool.
/// </summary>
public bool TryPryDoor(EntityUid target, EntityUid tool, EntityUid user, DoorComponent door, bool force = false)
{
if (door.State == DoorState.Welded)
return false;
if (!force)
{
var canEv = new BeforeDoorPryEvent(user, tool);
RaiseLocalEvent(target, canEv, false);
if (canEv.Cancelled)
// mark handled, as airlock component will cancel after generating a pop-up & you don't want to pry a tile
// under a windoor.
return true;
}
var modEv = new DoorGetPryTimeModifierEvent(user);
RaiseLocalEvent(target, modEv, false);
_toolSystem.UseTool(tool, user, target, modEv.PryTimeModifier * door.PryTime, door.PryingQuality, new DoorPryDoAfterEvent());
return true; // we might not actually succeeded, but a do-after has started
}
private void OnPryFinished(EntityUid uid, DoorComponent door, DoAfterEvent args)
{
if (args.Cancelled)
return;
if (door.State == DoorState.Closed)
StartOpening(uid, door);
else if (door.State == DoorState.Open)
StartClosing(uid, door);
}
#endregion
/// <summary>
/// Does the user have the permissions required to open this door?
/// </summary>
public override bool HasAccess(EntityUid uid, EntityUid? user = null, AccessReaderComponent? access = null)
{
// TODO network AccessComponent for predicting doors
// if there is no "user" we skip the access checks. Access is also ignored in some game-modes.
if (user == null || AccessType == AccessTypes.AllowAll)
return true;
// If the door is on emergency access we skip the checks.
if (TryComp<AirlockComponent>(uid, out var airlock) && airlock.EmergencyAccess)
return true;
if (!Resolve(uid, ref access, false))
return true;
var isExternal = access.AccessLists.Any(list => list.Contains("External"));
return AccessType switch
{
// Some game modes modify access rules.
AccessTypes.AllowAllIdExternal => !isExternal || _accessReaderSystem.IsAllowed(user.Value, access),
AccessTypes.AllowAllNoExternal => !isExternal,
_ => _accessReaderSystem.IsAllowed(user.Value, access)
};
}
/// <summary>
/// Open a door if a player or door-bumper (PDA, ID-card) collide with the door. Sadly, bullets no longer
/// generate "access denied" sounds as you fire at a door.
/// </summary>
protected override void HandleCollide(EntityUid uid, DoorComponent door, ref StartCollideEvent args)
{
// TODO ACCESS READER move access reader to shared and predict door opening/closing
// Then this can be moved to the shared system without mispredicting.
if (!door.BumpOpen)
return;
if (door.State != DoorState.Closed)
return;
var otherUid = args.OtherFixture.Body.Owner;
if (Tags.HasTag(otherUid, "DoorBumpOpener"))
TryOpen(uid, door, otherUid);
}
private void OnEmagged(EntityUid uid, DoorComponent door, ref GotEmaggedEvent args)
{
if(TryComp<AirlockComponent>(uid, out var airlockComponent))
{
if (airlockComponent.BoltsDown || !this.IsPowered(uid, EntityManager))
return;
if (door.State == DoorState.Closed)
{
SetState(uid, DoorState.Emagging, door);
PlaySound(uid, door.SparkSound, AudioParams.Default.WithVolume(8), args.UserUid, false);
var emagged = new DoorEmaggedEvent(args.UserUid);
RaiseLocalEvent(uid, ref emagged);
args.Handled = true;
}
}
}
public override void StartOpening(EntityUid uid, DoorComponent? door = null, EntityUid? user = null, bool predicted = false)
{
if (!Resolve(uid, ref door))
return;
var lastState = door.State;
SetState(uid, DoorState.Opening, door);
if (door.OpenSound != null)
PlaySound(uid, door.OpenSound, AudioParams.Default.WithVolume(-5), user, predicted);
if(lastState == DoorState.Emagging && TryComp<AirlockComponent>(uid, out var airlockComponent))
_airlock.SetBoltsWithAudio(uid, airlockComponent, !airlockComponent.BoltsDown);
}
protected override void CheckDoorBump(DoorComponent component, PhysicsComponent body)
{
if (component.BumpOpen)
{
foreach (var other in PhysicsSystem.GetContactingEntities(body, approximate: true))
{
if (Tags.HasTag(other.Owner, "DoorBumpOpener") &&
TryOpen(component.Owner, component, other.Owner, false, quiet: true)) break;
}
}
}
}
public sealed class PryFinishedEvent : EntityEventArgs { }
public sealed class PryCancelledEvent : EntityEventArgs { }
/// <summary>
/// Event raised when a door is emagged, either with an emag or a Space Ninja's doorjack ability.
/// Used to track doors for ninja's objective.
/// </summary>
[ByRefEvent]
public readonly record struct DoorEmaggedEvent(EntityUid UserUid);