Files

124 lines
4.2 KiB
C#
Raw Permalink Normal View History

using System.Diagnostics;
using Content.Shared._White.Cult.Structures;
using Content.Shared._White.Keyhole.Components;
using Content.Shared._White.Keyhole;
using Content.Shared.DoAfter;
using Content.Shared.Doors.Components;
using Content.Shared.Interaction;
using Content.Shared.Popups;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Random;
namespace Content.Server._White.Keyhole;
public sealed class KeyholeSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
public override void Initialize()
{
SubscribeLocalEvent<KeyComponent, ComponentInit>(OnKeyInit);
SubscribeLocalEvent<KeyComponent, AfterInteractEvent>(OnKeyInsert);
SubscribeLocalEvent<KeyholeComponent, KeyInsertDoAfterEvent>(OnDoAfter);
}
private void OnKeyInit(EntityUid uid, KeyComponent component, ComponentInit ev)
{
2024-04-10 09:57:42 +07:00
component.FormId ??= _random.Next(1000);
}
private void OnKeyInsert(EntityUid uid, KeyComponent component, AfterInteractEvent ev)
{
if (!ev.Target.HasValue)
{
return;
}
2024-04-10 09:57:42 +07:00
Debug.Assert(component.FormId != null);
if (TryComp<KeyformComponent>(ev.Target, out var keyformComponent))
{
OnKeyInsertForm(uid, component, keyformComponent, ev.Target.Value, ev.User);
return;
}
if (!TryComp<KeyholeComponent>(ev.Target, out var keyholeComponent) || !CanLock(ev.Target.Value))
return;
if (keyholeComponent.FormId != null && keyholeComponent.FormId != component.FormId)
{
_popupSystem.PopupEntity(Loc.GetString("door-keyhole-different-form"), ev.Target.Value);
return;
}
var doAfterEventArgs =
new DoAfterArgs(EntityManager, ev.User, keyholeComponent.Delay,
new KeyInsertDoAfterEvent(component.FormId.Value), ev.Target, ev.Used)
{
Merge remote-tracking branch 'origin/master' into upstream # Conflicts: # Content.Server/Antag/AntagSelectionSystem.cs # Content.Server/Changeling/ChangelingRuleSystem.cs # Content.Server/Changeling/ChangelingSystem.Abilities.cs # Content.Server/Doors/Systems/DoorSystem.cs # Content.Server/GameTicking/Rules/NukeopsRuleSystem.cs # Content.Server/GameTicking/Rules/RevolutionaryRuleSystem.cs # Content.Server/GameTicking/Rules/TraitorRuleSystem.cs # Content.Server/GameTicking/Rules/ZombieRuleSystem.cs # Content.Server/Holosign/HolosignSystem.cs # Content.Server/Revenant/EntitySystems/RevenantSystem.Abilities.cs # Content.Server/_White/Cult/GameRule/CultRuleComponent.cs # Content.Server/_White/Cult/GameRule/CultRuleSystem.cs # Content.Server/_White/Cult/Runes/Systems/CultSystem.Rune.cs # Content.Server/_White/Keyhole/KeyholeSystem.cs # Content.Server/_White/MeatyOre/MeatyOreStoreSystem.cs # Content.Shared/Projectiles/SharedProjectileSystem.cs # Content.Shared/Weapons/Melee/SharedMeleeWeaponSystem.cs # Content.Shared/_White/Keyhole/Components/KeyBaseComponent.cs # Resources/Locale/ru-RU/White/stuff.ftl/runes-entities.ftl # Resources/Locale/ru-RU/_white/cult/blood-spear.ftl # Resources/Locale/ru-RU/_white/cult/bolt-barrage.ftl # Resources/Locale/ru-RU/_white/cult/cult.ftl # Resources/Locale/ru-RU/_white/cult/gui.ftl # Resources/Locale/ru-RU/cult/cult-structure.ftl # Resources/Locale/ru-RU/cult/pylon.ftl # Resources/Maps/White/Scoupidia.yml # Resources/Maps/White/Void.yml # Resources/Maps/White/WonderBox.yml # Resources/Prototypes/Actions/types.yml # Resources/Prototypes/Atmospherics/gases.yml # Resources/Prototypes/Catalog/Cargo/cargo_atmospherics.yml # Resources/Prototypes/Catalog/Cargo/cargo_vending.yml # Resources/Prototypes/Catalog/Fills/Lockers/dressers.yml # Resources/Prototypes/Catalog/Fills/Lockers/heads.yml # Resources/Prototypes/Catalog/Fills/Lockers/misc.yml # Resources/Prototypes/Catalog/uplink_catalog.yml # Resources/Prototypes/Entities/Clothing/OuterClothing/armor.yml # Resources/Prototypes/Entities/Objects/Misc/subdermal_implants.yml # Resources/Prototypes/Entities/Objects/Tools/jaws_of_life.yml # Resources/Prototypes/Entities/Objects/Weapons/Melee/sledgehammer.yml # Resources/Prototypes/Entities/Objects/Weapons/Melee/sword.yml # Resources/Prototypes/Entities/Structures/Doors/Airlocks/base_assembly.yml # Resources/Prototypes/Entities/Structures/Doors/Airlocks/base_structureairlocks.yml # Resources/Prototypes/Entities/Structures/Doors/Firelocks/firelock.yml # Resources/Prototypes/Entities/Structures/Doors/Firelocks/frame.yml # Resources/Prototypes/Entities/Structures/Doors/SecretDoor/secret_door.yml # Resources/Prototypes/Entities/Structures/Doors/Windoors/assembly.yml # Resources/Prototypes/Entities/Structures/Doors/Windoors/base_structurewindoors.yml # Resources/Prototypes/Entities/Structures/Furniture/dresser.yml # Resources/Prototypes/Entities/Structures/Lighting/base_lighting.yml # Resources/Prototypes/Entities/Structures/Power/cable_terminal.yml # Resources/Prototypes/Entities/Structures/Walls/grille.yml # Resources/Prototypes/Entities/Structures/Walls/walls.yml # Resources/Prototypes/Entities/Structures/stairs.yml # Resources/Prototypes/_White/Entities/Objects/Misc/books.yml
2024-04-13 13:59:00 +07:00
BreakOnMove = true,
BreakOnDamage = true
};
_doAfter.TryStartDoAfter(doAfterEventArgs);
}
private bool CanLock(EntityUid uid)
{
return !HasComp<RunicDoorComponent>(uid) && TryComp<DoorComponent>(uid, out var doorComponent) &&
doorComponent.State == DoorState.Closed;
}
private void OnDoAfter(EntityUid uid, KeyholeComponent component, KeyInsertDoAfterEvent args)
{
if (args.Handled || args.Cancelled || !CanLock(uid))
return;
Debug.Assert(component.FormId == null || component.FormId == args.FormId);
component.FormId = args.FormId;
Lock(uid, component, args.User);
args.Handled = true;
}
private void Lock(EntityUid uid, KeyholeComponent component, EntityUid user)
{
var sound = component.Locked ? component.UnlockSound : component.LockSound;
var message = Loc.GetString(component.Locked ? "key-unlock-message" : "key-lock-message", ("name", user),
("door", uid));
var audioParams = new AudioParams().WithVolume(-5f);
_audio.PlayPvs(sound, user, audioParams);
_popupSystem.PopupEntity(message, uid);
component.Locked = !component.Locked;
}
private void OnKeyInsertForm(EntityUid uid, KeyComponent keyComponent, KeyformComponent keyformComponent, EntityUid keyform, EntityUid user)
{
if (!keyformComponent.IsUsed)
{
keyformComponent.FormId ??= keyComponent.FormId;
_appearance.SetData(keyform, KeyformVisuals.IsUsed, true);
_audio.PlayPvs(keyformComponent.PressSound, uid);
_popupSystem.PopupEntity(Loc.GetString("key-pressed-in-keyform-message-first", ("user", user), ("key", uid)), uid);
keyformComponent.IsUsed = true;
}
else
{
keyComponent.FormId = keyformComponent.FormId;
_popupSystem.PopupEntity(Loc.GetString("key-pressed-in-keyform-message", ("user", user), ("key", uid)), uid);
}
}
}