Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 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
2 changes: 1 addition & 1 deletion Content.Client/_Scp/Blinking/BlinkingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private void OnEyesStateChanged(EntityEyesStateChanged ev)

var ent = GetEntity(ev.NetEntity);

if (!TryComp<BlinkableComponent>(ent, out var blinkable))
if (!BlinkableQuery.TryComp(ent, out var blinkable))
return;

if (ev.NewState == EyesState.Closed)
Expand Down
3 changes: 1 addition & 2 deletions Content.Client/_Scp/Fear/FearSystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Content.Shared._Scp.Fear;
using Content.Shared._Scp.Fear.Components;
using Content.Shared._Scp.Fear.Components;
using Content.Shared._Scp.Fear.Systems;
using Content.Shared._Sunrise.Heartbeat;
using Robust.Client.Audio;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public override void Initialize()

Overlay = new GrainOverlay();

SubscribeLocalEvent<GrainOverlayComponent, ShaderAdditionalStrengthChanged>(OnAdditionalStrengthChanged);
SubscribeLocalEvent<GrainOverlayComponent, AfterAutoHandleStateEvent>(OnAdditionalStrengthChanged);

_cfg.OnValueChanged(ScpCCVars.GrainToggleOverlay, ToggleGrainOverlay);
_cfg.OnValueChanged(ScpCCVars.GrainStrength, SetBaseStrength);
Expand All @@ -44,7 +44,7 @@ protected override void OnPlayerAttached(Entity<GrainOverlayComponent> ent, ref
SetBaseStrength(_cfg.GetCVar(ScpCCVars.GrainStrength));
}

private void OnAdditionalStrengthChanged(Entity<GrainOverlayComponent> ent, ref ShaderAdditionalStrengthChanged args)
private void OnAdditionalStrengthChanged(Entity<GrainOverlayComponent> ent, ref AfterAutoHandleStateEvent args)
{
if (_player.LocalEntity != ent)
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public override void Initialize()
DisableOnCompatibilityMode = false;
Overlay = new VignetteOverlay();

SubscribeLocalEvent<VignetteOverlayComponent, ShaderAdditionalStrengthChanged>(OnAdditionalStrengthChanged);
SubscribeLocalEvent<VignetteOverlayComponent, AfterAutoHandleStateEvent>(OnAdditionalStrengthChanged);
}

private void OnAdditionalStrengthChanged(Entity<VignetteOverlayComponent> ent,
ref ShaderAdditionalStrengthChanged args)
ref AfterAutoHandleStateEvent args)
{
if (_player.LocalEntity != ent)
return;
Expand Down
1 change: 0 additions & 1 deletion Content.Server/_Scp/Fear/FearSystem.EntityEffects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ private void InitializeEntityEffects()
private void OnExecuteCalmDown(Entity<FearComponent> ent, ref EntityEffectEvent<CalmDownEffect> args)
{
ent.Comp.NextTimeDecreaseFearLevel -= args.Effect.SpeedUpBy;
Dirty(ent);
}
}
16 changes: 12 additions & 4 deletions Content.Server/_Scp/Fear/FearSystem.Fears.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Runtime.InteropServices;
using Content.Server._Scp.Shaders.Highlighting;
using Content.Server._Sunrise.Mood;
using Content.Shared._Scp.Blinking;
using Content.Shared._Scp.Fear;
using Content.Shared._Scp.Fear.Components;
using Content.Shared._Scp.Fear.Components.Fears;
Expand Down Expand Up @@ -52,13 +52,21 @@ private void OnMobStateChanged(MobStateChangedEvent ev)
var toggleUsed = new ItemToggledEvent(false, activated, null);
RaiseLocalEvent(ev.Target, ref toggleUsed);

// Если activated = true, значит человек умер.
// Поэтому код ниже требует true, так как реализует логику для смерти.
if (!activated)
return;

var whoSaw = _watching.GetAllEntitiesVisibleTo<MoodComponent>(ev.Target);
using var realWatchers = ListPoolEntity<BlinkableComponent>.Rent();
if (!_watching.TryGetWatchers(ev.Target, realWatchers.Value, flags: LookupFlags.Dynamic))
return;

foreach (var uid in whoSaw)
foreach (var uid in realWatchers.Value)
{
// Убийца не будет печалиться смерти убитого
if (uid.Owner == ev.Origin)
continue;

AddNegativeMoodEffect(uid, MoodSomeoneDiedOnMyEyes);
}
}
Expand All @@ -80,7 +88,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
36 changes: 0 additions & 36 deletions Content.Server/_Scp/Fear/FearSystem.Gameplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,10 @@ namespace Content.Server._Scp.Fear;
public sealed partial class FearSystem
{
[Dependency] private readonly ChatSystem _chat = default!;
[Dependency] private readonly StandingStateSystem _standing = default!;
[Dependency] private readonly IRobustRandom _random = default!;

private static readonly ProtoId<EmotePrototype> ScreamProtoId = "Scream";

private void InitializeGameplay()
{
// TODO: Перенести это на отдельный компонент, чтобы не перебирать всех потенциально пугающихся.
SubscribeLocalEvent<FearComponent, MoveInputEvent>(OnMove);
}

/// <summary>
/// Обрабатывает событие хождения.
/// Реализует случайное падение во время сильного страха
/// </summary>
private void OnMove(Entity<FearComponent> ent, ref MoveInputEvent args)
{
if (ent.Comp.State < ent.Comp.FallOffRequiredState)
return;

if (_timing.CurTime < ent.Comp.FallOffNextCheckTime)
return;

var percentNormalized = PercentToNormalized(ent.Comp.FallOffChance);
SetNextFallOffTime(ent); // Даже если не прокнет, то время все равно должно устанавливаться

if (!_random.Prob(percentNormalized))
return;

_standing.Down(ent, force: true);
}

/// <summary>
/// Пытается закричать, если увиденный объект настолько страшный.
/// </summary>
Expand All @@ -55,12 +27,4 @@ protected override void TryScream(Entity<FearComponent> ent)

_chat.TryEmoteWithChat(ent, ScreamProtoId);
}

/// <summary>
/// Устанавливает следующее время возможности запнуться.
/// </summary>
private void SetNextFallOffTime(Entity<FearComponent> ent)
{
ent.Comp.FallOffNextCheckTime = _timing.CurTime + ent.Comp.FallOffCheckInterval;
}
}
4 changes: 3 additions & 1 deletion Content.Server/_Scp/Fear/FearSystem.SoundEffects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ protected override void StartBreathing(Entity<FearActiveSoundEffectsComponent> e

var audio = _audio.PlayGlobal(BreathingSound, ent, audioParams);
ent.Comp.BreathingAudioStream = audio?.Entity;
DirtyField(ent, ent.Comp, nameof(FearActiveSoundEffectsComponent.BreathingAudioStream));
}

private void StopBreathing(Entity<FearActiveSoundEffectsComponent> ent)
protected override void StopBreathing(Entity<FearActiveSoundEffectsComponent> ent)
{
ent.Comp.BreathingAudioStream = _audio.Stop(ent.Comp.BreathingAudioStream);
DirtyField(ent, ent.Comp, nameof(FearActiveSoundEffectsComponent.BreathingAudioStream));
}
}
10 changes: 4 additions & 6 deletions Content.Server/_Scp/Fear/FearSystem.Traits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ private void OnStuporFearStateChanged(Entity<FearStuporComponent> ent, ref FearS
if (args.NewState < ent.Comp.RequiredState)
return;

var normalizedChance = PercentToNormalized(ent.Comp.Chance);
if (!_random.Prob(normalizedChance))
if (!_random.Prob(ent.Comp.Chance))
return;

_statusEffects.TryAddStatusEffectDuration(ent, FearStuporComponent.StatusEffect, ent.Comp.StuporTime);
_statusEffects.TryAddStatusEffectDuration(ent, ent.Comp.StatusEffect, ent.Comp.StuporTime);
}

private void OnStutteringFearStateChanged(Entity<FearStutteringComponent> ent, ref FearStateChangedEvent args)
Expand Down Expand Up @@ -63,10 +62,9 @@ private void OnFaintingFearStateChanged(Entity<FearFaintingComponent> ent, ref F
if (args.NewState < ent.Comp.RequiredState)
return;

var percentNormalized = PercentToNormalized(ent.Comp.Chance);
if (!_random.Prob(percentNormalized))
if (!_random.Prob(ent.Comp.Chance))
return;

_statusEffects.TryAddStatusEffectDuration(ent, FearFaintingComponent.StatusEffect, ent.Comp.Time);
_statusEffects.TryAddStatusEffectDuration(ent, ent.Comp.StatusEffect, ent.Comp.Time);
}
}
30 changes: 9 additions & 21 deletions Content.Server/_Scp/Fear/FearSystem.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
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;
using Content.Shared.GameTicking;
using Content.Shared.Mobs.Components;
using Content.Shared.Rejuvenate;
using Robust.Shared.Timing;
Expand All @@ -13,22 +13,19 @@ public sealed partial class FearSystem : SharedFearSystem
{
[Dependency] private readonly IGameTiming _timing = default!;

private EntityQuery<FearActiveSoundEffectsComponent> _activeFearEffects;

private static readonly TimeSpan CalmDownCheckCooldown = TimeSpan.FromSeconds(1f);
private TimeSpan _nextCalmDownCheck = TimeSpan.Zero;

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

SubscribeLocalEvent<RoundRestartCleanupEvent>(OnCleanUp);

InitializeSoundEffects();
InitializeFears();
InitializeGameplay();
InitializeTraits();
InitializeEntityEffects();

_activeFearEffects = GetEntityQuery<FearActiveSoundEffectsComponent>();
}

public override void Update(float frameTime)
Expand All @@ -49,13 +46,13 @@ private void UpdateCalmDown()
// Проходимся по людям с компонентом страха и уменьшаем уровень страха со временем
while (query.MoveNext(out var uid, out var fear, out var mob))
{
if (!_mob.IsAlive(uid, mob))
if (fear.State == FearState.None)
continue;

if (fear.State == FearState.None)
if (!_mob.IsAlive(uid, mob))
continue;

if (fear.NextTimeDecreaseFearLevel > _timing.CurTime)
if (_timing.CurTime < fear.NextTimeDecreaseFearLevel)
continue;

var entity = (uid, fear);
Expand All @@ -75,16 +72,9 @@ private void UpdateCalmDown()
/// </summary>
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())
if (_watching.TryGetAnyEntitiesVisibleTo<FearSourceComponent>(ent.Owner, ent.Comp.SeenBlockerLevel))
return false;

var newFearState = GetDecreasedLevel(ent.Comp.State);
Expand Down Expand Up @@ -124,10 +114,8 @@ private void RemoveMoodEffects(EntityUid uid)
RaiseLocalEvent(uid, new MoodRemoveEffectEvent(MoodHemophobicBleeding));
}

protected override void Clear()
private void OnCleanUp(RoundRestartCleanupEvent args)
{
base.Clear();

_nextHemophobiaCheck = TimeSpan.Zero;
_nextCalmDownCheck = TimeSpan.Zero;
}
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,9 +1,9 @@
using System.Linq;
using Content.Server._Scp.Scp096;
using Content.Server._Sunrise.Helpers;
using Content.Shared._Scp.Blinking;
using Content.Shared._Scp.Scp096.Main.Components;
using Content.Shared._Scp.ScpMask;
using Content.Shared._Scp.Watching;
using Content.Shared._Sunrise.Helpers;
using Content.Shared.Xenoarchaeology.Artifact;
using Content.Shared.Xenoarchaeology.Artifact.XAE;
Expand All @@ -15,7 +15,7 @@ public sealed class ArtifactScp096MadnessSystem : BaseXAESystem<ArtifactScp096Ma
{
[Dependency] private readonly ScpMaskSystem _scpMask = default!;
[Dependency] private readonly Scp096System _scp096 = default!;
[Dependency] private readonly EyeWatchingSystem _watching = default!;
[Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly SunriseHelpersSystem _helpers = default!;
[Dependency] private readonly IRobustRandom _random = default!;

Expand All @@ -24,7 +24,7 @@ protected override void OnActivated(Entity<ArtifactScp096MadnessComponent> ent,
if (!_helpers.TryGetFirst<Scp096Component>(out var scp096))
return;

var targets = _watching.GetWatchers(ent.Owner)
var targets = _lookup.GetEntitiesInRange<BlinkableComponent>(Transform(scp096.Value).Coordinates, ent.Comp.Radius, LookupFlags.Dynamic)
.ToList()
.ShuffleRobust(_random)
.TakePercentage(ent.Comp.Percent);
Expand All @@ -37,5 +37,7 @@ protected override void OnActivated(Entity<ArtifactScp096MadnessComponent> ent,
// 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.IsWatchedByAny(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.IsWatchedByAny(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.TryGetWatchers(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
Loading
Loading