Files
OldThink/Content.Server/_White/Cult/Structures/RunicDoorSystem.cs

144 lines
4.9 KiB
C#
Raw Normal View History

using Content.Server.Cuffs;
using Content.Server.Doors.Systems;
using Content.Shared._White.Chaplain;
2024-01-27 15:19:52 +03:00
using Content.Shared.Doors;
using Content.Shared.Humanoid;
using Content.Shared.Stunnable;
using Content.Shared._White.Cult.Components;
using Content.Shared._White.Cult.Systems;
using Content.Shared.Cuffs.Components;
using Content.Shared.Doors.Components;
using Content.Shared.Mobs.Systems;
using Content.Shared.Prying.Components;
using Content.Shared.Weapons.Melee.Components;
using Content.Shared.Weapons.Melee.Events;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Physics.Components;
2024-01-27 15:19:52 +03:00
using Robust.Shared.Physics.Systems;
2024-01-29 01:02:37 +07:00
using CultistComponent = Content.Shared._White.Cult.Components.CultistComponent;
2024-01-27 15:19:52 +03:00
namespace Content.Server._White.Cult.Structures;
2024-01-27 15:19:52 +03:00
public sealed class RunicDoorSystem : EntitySystem
{
[Dependency] private readonly DoorSystem _doorSystem = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly SharedStunSystem _stunSystem = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly OccluderSystem _occluder = default!;
[Dependency] private readonly MobStateSystem _mobState = default!;
[Dependency] private readonly CuffableSystem _cuffable = default!;
[Dependency] private readonly HolyWeaponSystem _holyWeapon = default!;
2024-01-27 15:19:52 +03:00
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<RunicDoorComponent, BeforeDoorOpenedEvent>(OnBeforeDoorOpened);
SubscribeLocalEvent<RunicDoorComponent, BeforeDoorClosedEvent>(OnBeforeDoorClosed);
// SubscribeLocalEvent<RunicDoorComponent, AttackedEvent>(OnGetAttacked);
SubscribeLocalEvent<RunicDoorComponent, ConcealEvent>(OnConceal);
SubscribeLocalEvent<RunicDoorComponent, BeforePryEvent>(OnBeforePry);
}
private void OnBeforePry(Entity<RunicDoorComponent> ent, ref BeforePryEvent args)
{
args.Cancelled = true;
}
private void OnConceal(Entity<RunicDoorComponent> ent, ref ConcealEvent args)
{
if (!TryComp(ent, out MetaDataComponent? meta))
return;
if (TryComp(ent, out PhysicsComponent? physics))
_occluder.SetEnabled(ent, args.Conceal && physics.CanCollide, meta: meta);
if (TryComp(ent, out DoorComponent? door))
{
door.Occludes = args.Conceal;
Dirty(ent, door, meta);
}
if (!TryComp(ent, out MeleeSoundComponent? meleeSound) || meleeSound.SoundGroups == null)
return;
meleeSound.SoundGroups["Brute"] = args.Conceal
? new SoundPathSpecifier("/Audio/Weapons/smash.ogg")
: new SoundCollectionSpecifier("GlassSmash");
Dirty(ent, meleeSound, meta);
}
private void OnGetAttacked(Entity<RunicDoorComponent> ent, ref AttackedEvent args)
{
if (!HasComp<HolyWeaponComponent>(args.Used) || !TryComp<DoorComponent>(ent, out var doorComp) ||
doorComp.State is not DoorState.Closed)
return;
_audio.PlayPvs(new SoundPathSpecifier("/Audio/Magic/knock.ogg"), ent);
_doorSystem.StartOpening(ent, doorComp);
2024-01-27 15:19:52 +03:00
}
private void OnBeforeDoorOpened(EntityUid uid, RunicDoorComponent component, BeforeDoorOpenedEvent args)
{
args.Uncancel();
if (!args.User.HasValue)
{
return;
}
if (!Process(uid, args.User.Value))
{
args.Cancel();
}
}
private void OnBeforeDoorClosed(EntityUid uid, RunicDoorComponent component, BeforeDoorClosedEvent args)
{
args.Uncancel();
if (!args.User.HasValue)
{
return;
}
if (!Process(uid, args.User.Value))
{
args.Cancel();
}
}
private bool Process(EntityUid airlock, EntityUid user)
{
if (HasComp<CultistComponent>(user) || HasComp<ConstructComponent>(user))
{
return true;
}
// _doorSystem.Deny(airlock);
2024-01-27 15:19:52 +03:00
if (!HasComp<HumanoidAppearanceComponent>(user) || _holyWeapon.IsHoldingHolyWeapon(user) ||
TryComp(airlock, out ConcealableComponent? concealable) && concealable.Concealed)
2024-01-27 15:19:52 +03:00
return false;
var direction = Transform(user).MapPosition.Position - Transform(airlock).MapPosition.Position;
2024-01-28 08:28:30 +03:00
var impulseVector = direction * 2000;
2024-01-27 15:19:52 +03:00
_physics.ApplyLinearImpulse(user, impulseVector);
_stunSystem.TryParalyze(user, TimeSpan.FromSeconds(3), true);
return false;
}
public bool CanBumpOpen(EntityUid uid, EntityUid otherUid)
{
return !HasComp<RunicDoorComponent>(uid) || !HasComp<ConstructComponent>(otherUid) &&
(!HasComp<CultistComponent>(otherUid) || !_mobState.IsAlive(otherUid) ||
TryComp(otherUid, out CuffableComponent? cuffable) && _cuffable.GetAllCuffs(cuffable).Count > 0);
}
2024-01-28 08:28:30 +03:00
}