Skip to content
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Content.Shared.Whitelist;
using Robust.Shared.GameStates;

namespace Content.Shared._Scp.Other.ScpRestrictMovementOnVisibility;

[RegisterComponent, NetworkedComponent]
public sealed partial class ScpRestrictMovementOnVisibilityComponent : Component
{
[DataField]
public EntityWhitelist? ContainersMoveWhitelist;

public EntityWhitelist? ContainersMoveBlacklist;

[DataField]
public float ContainmentRoomSearchRadius = 8f;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
using System.Diagnostics.CodeAnalysis;
using Content.Shared._Scp.Watching;
using Content.Shared.ActionBlocker;
using Content.Shared.Interaction.Events;
using Content.Shared.Movement.Events;
using Content.Shared.Storage.Components;
using Content.Shared.Whitelist;
using Robust.Shared.Containers;

namespace Content.Shared._Scp.Other.ScpRestrictMovementOnVisibility;

public sealed class SharedScpRestrictMovementOnVisibilitySystem : EntitySystem
{
[Dependency] private readonly EntityWhitelistSystem _whitelist = default!;
[Dependency] private readonly ActionBlockerSystem _blocker = default!;
[Dependency] private readonly EyeWatchingSystem _watching = default!;
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;

private EntityQuery<InsideEntityStorageComponent> _insideQuery;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<ScpRestrictMovementOnVisibilityComponent, AttackAttemptEvent>(OnAttackAttempt);

SubscribeLocalEvent<ScpRestrictMovementOnVisibilityComponent, ChangeDirectionAttemptEvent>(OnDirectionAttempt);
SubscribeLocalEvent<ScpRestrictMovementOnVisibilityComponent, UpdateCanMoveEvent>(OnMoveAttempt);
SubscribeLocalEvent<ScpRestrictMovementOnVisibilityComponent, MoveInputEvent>(OnMoveInput);
SubscribeLocalEvent<ScpRestrictMovementOnVisibilityComponent, MoveEvent>(OnMove);
}

public void OnAttackAttempt(Entity<ScpRestrictMovementOnVisibilityComponent> ent, ref AttackAttemptEvent args)
{
if (IsInContainer(ent, out _))
{
args.Cancel();
return;
}

if (_watching.IsWatchedByAny(ent, useTimeCompensation: true))
{
args.Cancel();
return;
}
}

public void OnDirectionAttempt(Entity<ScpRestrictMovementOnVisibilityComponent> ent, ref ChangeDirectionAttemptEvent args)
{
// В контейнере можно двигаться
if (IsInContainer(ent, out _))
return;

if (!_watching.IsWatchedByAny(ent, useTimeCompensation: true))
return;

args.Cancel();
}

public void OnMoveAttempt(Entity<ScpRestrictMovementOnVisibilityComponent> ent, ref UpdateCanMoveEvent args)
{
// В контейнере можно двигаться
if (IsInContainer(ent, out _))
return;

if (!_watching.IsWatchedByAny(ent, useTimeCompensation: true))
return;

args.Cancel();
}

public void OnMoveInput(Entity<ScpRestrictMovementOnVisibilityComponent> ent, ref MoveInputEvent args)
{
// Метод подвязанный на MoveInputEvent так же нужен, вместе с методом на MoveEvent
// Этот метод исправляет проблему, когда сущность должен мочь двинуться, но ему об этом никто не сказал
// То есть последний вопрос от сущности МОГУ ЛИ Я ДВИНУТЬСЯ был когда он еще мог двинуться, через MoveEvent
// Потом он перестал мочь, и следственно больше НЕ МОЖЕТ задать вопрос, может они двинуться
// Это фикслось в игре сменой направления спрайта мышкой
// Но данный метод как раз будет спрашивать у сущности, может ли он сдвинуться, когда как раз не двигается
_blocker.UpdateCanMove(ent);
}

public void OnMove(Entity<ScpRestrictMovementOnVisibilityComponent> ent, ref MoveEvent args)
{
_blocker.UpdateCanMove(ent);
}

public bool IsInContainer(Entity<ScpRestrictMovementOnVisibilityComponent> ent, [NotNullWhen(true)] out EntityUid? storage)
{
storage = null;

if (!_insideQuery.TryComp(ent, out var insideEntityStorageComponent))
return false;

if (!_containerSystem.TryGetContainingContainer(ent.Owner, out var container))
return false;

if (!_whitelist.CheckBoth(container.Owner, ent.Comp.ContainersMoveBlacklist, ent.Comp.ContainersMoveWhitelist))
return false;

storage = insideEntityStorageComponent.Storage;
return true;
}
}
70 changes: 1 addition & 69 deletions Content.Shared/_Scp/Scp173/SharedScp173System.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using Content.Shared._Scp.Blinking;
using Content.Shared._Scp.Containment.Cage;
Expand All @@ -7,8 +7,6 @@
using Content.Shared._Scp.Watching;
using Content.Shared.ActionBlocker;
using Content.Shared.DoAfter;
using Content.Shared.Interaction.Events;
using Content.Shared.Movement.Events;
using Content.Shared.Physics;
using Content.Shared.Popups;
using Content.Shared.Storage.Components;
Expand Down Expand Up @@ -39,79 +37,13 @@ public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<Scp173Component, AttackAttemptEvent>(OnAttackAttempt);

SubscribeLocalEvent<Scp173Component, ChangeDirectionAttemptEvent>(OnDirectionAttempt);
SubscribeLocalEvent<Scp173Component, UpdateCanMoveEvent>(OnMoveAttempt);
SubscribeLocalEvent<Scp173Component, MoveInputEvent>(OnMoveInput);
SubscribeLocalEvent<Scp173Component, MoveEvent>(OnMove);

SubscribeLocalEvent<Scp173Component, Scp173BlindAction>(OnStartedBlind);
SubscribeLocalEvent<Scp173Component, Scp173StartBlind>(OnBlind);

_insideQuery = GetEntityQuery<InsideEntityStorageComponent>();
_scpCageQuery = GetEntityQuery<ScpCageComponent>();
}

#region Movement

private void OnAttackAttempt(Entity<Scp173Component> ent, ref AttackAttemptEvent args)
{
if (IsInScpCage(ent, out _))
{
args.Cancel();
return;
}

if (Watching.IsWatchedByAny(ent, useTimeCompensation: true))
{
args.Cancel();
return;
}
}

private void OnDirectionAttempt(Entity<Scp173Component> ent, ref ChangeDirectionAttemptEvent args)
{
// В клетке можно двигаться
if (IsInScpCage(ent, out _))
return;

if (!Watching.IsWatchedByAny(ent, useTimeCompensation: true))
return;

args.Cancel();
}

private void OnMoveAttempt(Entity<Scp173Component> ent, ref UpdateCanMoveEvent args)
{
// В клетке можно двигаться
if (IsInScpCage(ent, out _))
return;

if (!Watching.IsWatchedByAny(ent, useTimeCompensation: true))
return;

args.Cancel();
}

private void OnMoveInput(Entity<Scp173Component> ent, ref MoveInputEvent args)
{
// Метод подвязанный на MoveInputEvent так же нужен, вместе с методом на MoveEvent
// Этот метод исправляет проблему, когда 173 должен мочь двинуться, но ему об этом никто не сказал
// То есть последний вопрос от 173 МОГУ ЛИ Я ДВИНУТЬСЯ был когда он еще мог двинуться, через MoveEvent
// Потом он перестал мочь, и следственно больше НЕ МОЖЕТ задать вопрос, может они двинуться
// Это фикслось в игре сменой направления спрайта мышкой
// Но данный метод как раз будет спрашивать у 173, может ли он сдвинуться, когда как раз не двигается
_blocker.UpdateCanMove(ent);
}

private void OnMove(Entity<Scp173Component> ent, ref MoveEvent args)
{
_blocker.UpdateCanMove(ent);
}

#endregion

#region Abillities

private void OnStartedBlind(Entity<Scp173Component> ent, ref Scp173BlindAction args)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- type: entity
- type: entity
parent:
- BaseScp
- MobCombat
Expand All @@ -19,6 +19,10 @@
- type: Scp
class: Euclid
- type: Scp173
- type: ScpRestrictMovementOnVisibility
containersMoveWhitelist:
components:
- ScpCage
- type: ShowBlinkable
- type: XenoArtifact
effectsTable: !type:GroupSelector
Expand Down
Loading