Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 8 additions & 3 deletions Content.Server/_Scp/Fear/FearSystem.Fears.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public sealed partial class FearSystem

private readonly List<EntityUid> _hemophobiaBloodList = [];

private readonly List<Entity<MoodComponent>> _moodList = [];
private readonly HashSet<Entity<MoodComponent>> _moodSearchList = [];

private void InitializeFears()
{
SubscribeLocalEvent<MobStateChangedEvent>(OnMobStateChanged);
Expand All @@ -55,9 +58,11 @@ private void OnMobStateChanged(MobStateChangedEvent ev)
if (!activated)
return;

var whoSaw = _watching.GetAllEntitiesVisibleTo<MoodComponent>(ev.Target);
_moodList.Clear();
if (!_watching.TryGetAllEntitiesVisibleTo(ev.Target, _moodList, _moodSearchList, flags: LookupFlags.Dynamic))
return;

foreach (var uid in whoSaw)
foreach (var uid in _moodList)
{
AddNegativeMoodEffect(uid, MoodSomeoneDiedOnMyEyes);
}
Expand All @@ -80,7 +85,7 @@ private void UpdateHemophobia()
continue;

_hemophobiaBloodList.Clear();
var bloodAmount = _helpers.GetAroundSolutionVolume(uid, hemophobia.Reagent, in _hemophobiaBloodList);
var bloodAmount = _helpers.GetAroundSolutionVolume(uid, hemophobia.Reagent, _hemophobiaBloodList);
var requiredBloodAmount = hemophobia.BloodRequiredPerState[fear.State];

if (bloodAmount <= requiredBloodAmount)
Expand Down
11 changes: 6 additions & 5 deletions Content.Server/_Scp/Fear/FearSystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Linq;
using Content.Shared._Scp.Fear;
using Content.Shared._Scp.Fear;
using Content.Shared._Scp.Fear.Components;
using Content.Shared._Scp.Fear.Systems;
using Content.Shared._Sunrise.Mood;
Expand All @@ -18,6 +17,9 @@ public sealed partial class FearSystem : SharedFearSystem
private static readonly TimeSpan CalmDownCheckCooldown = TimeSpan.FromSeconds(1f);
private TimeSpan _nextCalmDownCheck = TimeSpan.Zero;

private readonly List<Entity<FearSourceComponent>> _fearSourceList = [];
private readonly HashSet<Entity<FearSourceComponent>> _fearSourceSearchList = [];

public override void Initialize()
{
base.Initialize();
Expand Down Expand Up @@ -80,11 +82,10 @@ public bool TryCalmDown(Entity<FearComponent> ent)
if (_activeFearEffects.HasComp(ent))
return false;

var visibleFearSources = _watching.GetAllVisibleTo<FearSourceComponent>(ent.Owner, ent.Comp.SeenBlockerLevel);

// Проверка на то, что мы в данный момент не смотрим на какую-то страшную сущность.
// Нельзя успокоиться, когда мы смотрим на источник страха.
if (visibleFearSources.Any())
_fearSourceList.Clear();
if (!_watching.TryGetAllEntitiesVisibleTo(ent.Owner, _fearSourceList, _fearSourceSearchList, ent.Comp.SeenBlockerLevel))
return false;

var newFearState = GetDecreasedLevel(ent.Comp.State);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ public sealed partial class ArtifactScp096MadnessComponent : Component
public float Radius = 12f;

[DataField]
public float Percent = 70f;
public float Percent = 0.7f;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Linq;
using Content.Server._Scp.Scp096;
using Content.Server._Scp.Scp096;
using Content.Server._Sunrise.Helpers;
using Content.Shared._Scp.Blinking;
using Content.Shared._Scp.Proximity;
using Content.Shared._Scp.Scp096.Main.Components;
using Content.Shared._Scp.ScpMask;
using Content.Shared._Scp.Watching;
Expand All @@ -19,23 +20,30 @@ public sealed class ArtifactScp096MadnessSystem : BaseXAESystem<ArtifactScp096Ma
[Dependency] private readonly SunriseHelpersSystem _helpers = default!;
[Dependency] private readonly IRobustRandom _random = default!;

private readonly List<Entity<BlinkableComponent>> _list = [];

protected override void OnActivated(Entity<ArtifactScp096MadnessComponent> ent, ref XenoArtifactNodeActivatedEvent args)
{
if (!_helpers.TryGetFirst<Scp096Component>(out var scp096))
return;

var targets = _watching.GetWatchers(ent.Owner)
.ToList()
.ShuffleRobust(_random)
.TakePercentage(ent.Comp.Percent);
_list.Clear();
if (!_watching.TryGetAllEntitiesVisibleTo(scp096.Value.Owner,
_list,
LineOfSightBlockerLevel.Solid,
LookupFlags.Dynamic))
return;

foreach (var target in targets)
_list.ShuffleRobust(_random).TakePercentage(ent.Comp.Percent);
foreach (var target in _list)
{
if (!_scp096.TryAddTarget(scp096.Value, target, true, true))
continue;

// TODO: Пофиксить разрыв маски много раз
_scpMask.TryTear(scp096.Value);
}

// TODO: Звук
}
}
6 changes: 3 additions & 3 deletions Content.Server/_Scp/Scp173/Scp173System.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private void OnStructureDamage(Entity<Scp173Component> uid, ref Scp173DamageStru
return;
}

if (Watching.IsWatched(uid.Owner))
if (Watching.IsWatched(uid))
{
var message = Loc.GetString("scp173-fast-movement-too-many-watchers");
_popup.PopupEntity(message, uid, uid, PopupType.LargeCaution);
Expand Down Expand Up @@ -185,7 +185,7 @@ private void OnClog(Entity<Scp173Component> ent, ref Scp173ClogAction args)
return;
}

if (Watching.IsWatched(ent.Owner))
if (Watching.IsWatched(ent))
{
var message = Loc.GetString("scp173-fast-movement-too-many-watchers");
_popup.PopupEntity(message, ent, ent, PopupType.LargeCaution);
Expand Down Expand Up @@ -253,7 +253,7 @@ private void OnFastMovement(Entity<Scp173Component> ent, ref Scp173FastMovementA
return;
}

if (Watching.IsWatched(ent.Owner, out var watchersCount) && watchersCount > ent.Comp.MaxWatchers)
if (Watching.IsWatched(ent, out var watchersCount) && watchersCount > ent.Comp.MaxWatchers)
{
var message = Loc.GetString("scp173-fast-movement-too-many-watchers");
_popup.PopupEntity(message, ent, ent, PopupType.LargeCaution);
Expand Down
12 changes: 7 additions & 5 deletions Content.Shared/_Scp/Blinking/SharedBlinkingSystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Linq;
using Content.Shared._Scp.Scp096.Main.Components;
using Content.Shared._Scp.Scp173;
using Content.Shared._Scp.Watching;
using Content.Shared._Sunrise.Random;
Expand All @@ -25,6 +24,9 @@ public abstract partial class SharedBlinkingSystem : EntitySystem
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly INetManager _net = default!;

private readonly HashSet<Entity<Scp173Component>> _scp173SearchList = [];
private readonly List<Entity<Scp173Component>> _scp173List = [];

public override void Initialize()
{
base.Initialize();
Expand Down Expand Up @@ -255,11 +257,11 @@ protected void UpdateAlert(Entity<BlinkableComponent> ent)
protected bool IsScpNearby(EntityUid player)
{
// Получаем всех Scp с механиками зрения, которые видят игрока
var allScp173InView = _watching.GetAllVisibleTo<Scp173Component>(player);
var allScp096InView = _watching.GetAllVisibleTo<Scp096Component>(player);
_scp173List.Clear();
if (!_watching.TryGetAllEntitiesVisibleTo(player, _scp173List, _scp173SearchList))
return false;

return allScp173InView.Any(e => _watching.CanBeWatched(player, e))
|| allScp096InView.Any(e => _watching.CanBeWatched(player, e));
return _scp173List.Any(e => _watching.CanBeWatched(player, e));
}
}

Expand Down
15 changes: 11 additions & 4 deletions Content.Shared/_Scp/Fear/Systems/SharedFearSystem.Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,23 @@ public abstract partial class SharedFearSystem

private const int GenericFearBasedScaleModifier = 2;

private readonly HashSet<Entity<FearSourceComponent>> _fearSourceSearchList = [];
private readonly List<Entity<FearSourceComponent>> _fearSourceList = [];

/// <summary>
/// Подсвечивает все сущности, которые вызывают страх.
/// Сущности, чей уровень страха при видимости отличается от текущего уровня страха не будет подсвечены.
/// </summary>
private void HighLightAllVisibleFears(Entity<FearComponent> ent)
{
var visibleFearSources =
_watching.GetAllEntitiesVisibleTo<FearSourceComponent>(ent.Owner, ent.Comp.SeenBlockerLevel);

foreach (var source in visibleFearSources)
_fearSourceList.Clear();
if (!_watching.TryGetAllEntitiesVisibleTo(ent.Owner,
_fearSourceList,
_fearSourceSearchList,
ent.Comp.SeenBlockerLevel))
return;

foreach (var source in _fearSourceList)
{
if (source.Comp.UponSeenState != ent.Comp.State)
continue;
Expand Down
2 changes: 1 addition & 1 deletion Content.Shared/_Scp/Fear/Systems/SharedFearSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private void OnProximityInRange(Entity<FearComponent> ent, ref ProximityInRangeT
return;

// Проверка на зрение, чтобы можно было закрыть глазки и было не страшно
if (!_watching.SimpleIsWatchedBy(args.Receiver, [ent]))
if (!_watching.SimpleIsWatchedBy(args.Receiver, ent))
return;

// Если текущий уровень страха выше, чем тот, что мы хотим поставить,
Expand Down
32 changes: 19 additions & 13 deletions Content.Shared/_Scp/Helpers/ScpHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,33 @@

namespace Content.Shared._Scp.Helpers;

// TODO: Использовать оптимизации GC после внедрения их в EyeWatchingSystem

public sealed class ScpHelpers : EntitySystem
{
[Dependency] private readonly EyeWatchingSystem _watching = default!;

private readonly HashSet<Entity<PuddleComponent>> _puddleSearchList = [];
private readonly List<Entity<PuddleComponent>> _puddleList = [];

/// <summary>
/// Получает суммарное количество реагента в зоне видимости сущности.
/// Возвращает количество реагентов.
/// </summary>
public FixedPoint2 GetAroundSolutionVolume(EntityUid uid,
ProtoId<ReagentPrototype> reagent,
in List<EntityUid> puddleList,
List<EntityUid> puddleList,
LineOfSightBlockerLevel lineOfSight = LineOfSightBlockerLevel.Transparent)
{
FixedPoint2 total = 0;
var puddles = _watching.GetAllEntitiesVisibleTo<PuddleComponent>(uid, lineOfSight);
_puddleList.Clear();
if (!_watching.TryGetAllEntitiesVisibleTo(uid, _puddleList, _puddleSearchList, lineOfSight, LookupFlags.Static))
return FixedPoint2.Zero;

foreach (var puddle in puddles)
FixedPoint2 total = 0;
foreach (var puddle in _puddleList)
{
if (!puddle.Comp.Solution.HasValue)
continue;

var solution = puddle.Comp.Solution.Value.Comp.Solution;

foreach (var (reagentId, quantity) in solution.Contents)
{
if (reagentId.Prototype != reagent)
Expand All @@ -53,10 +55,12 @@ public FixedPoint2 GetAroundSolutionVolume(EntityUid uid,
ProtoId<ReagentPrototype> reagent,
LineOfSightBlockerLevel lineOfSight = LineOfSightBlockerLevel.Transparent)
{
FixedPoint2 total = 0;
var puddles = _watching.GetAllEntitiesVisibleTo<PuddleComponent>(uid, lineOfSight);
_puddleList.Clear();
if (!_watching.TryGetAllEntitiesVisibleTo(uid, _puddleList, _puddleSearchList, lineOfSight, LookupFlags.Static))
return FixedPoint2.Zero;

foreach (var puddle in puddles)
FixedPoint2 total = 0;
foreach (var puddle in _puddleList)
{
if (!puddle.Comp.Solution.HasValue)
continue;
Expand All @@ -80,10 +84,12 @@ public bool IsAroundSolutionVolumeGreaterThan(EntityUid uid,
FixedPoint2 required,
LineOfSightBlockerLevel lineOfSight = LineOfSightBlockerLevel.Transparent)
{
FixedPoint2 total = 0;
var puddles = _watching.GetAllEntitiesVisibleTo<PuddleComponent>(uid, lineOfSight);
_puddleList.Clear();
if (!_watching.TryGetAllEntitiesVisibleTo(uid, _puddleList, _puddleSearchList, lineOfSight, LookupFlags.Static))
return false;

foreach (var puddle in puddles)
FixedPoint2 total = 0;
foreach (var puddle in _puddleList)
{
if (!puddle.Comp.Solution.HasValue)
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private void OnExamined(Entity<Scp106PhantomComponent> ent, ref ExaminedEvent ar
if (!_mob.IsAlive(args.Examiner))
return;

if (!_watching.SimpleIsWatchedBy(ent.Owner, [args.Examiner]))
if (!_watching.SimpleIsWatchedBy(ent.Owner, args.Examiner))
return;

// Ликвидируйся
Expand Down
Loading
Loading