Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -6,6 +6,7 @@ namespace Content.Server._Scp.Blinking.ReducedBlinking;

public sealed class ReducedBlinkingSystem : SharedReducedBlinkingSystem
{
[Dependency] private readonly SharedBlinkingSystem _blinking = default!;
[Dependency] private readonly PopupSystem _popup = default!;

public override void Initialize()
Expand Down Expand Up @@ -59,17 +60,21 @@ private void OnUserStartup(Entity<ActiveReducedBlinkingUserComponent> ent, ref C
if (!TryComp<BlinkableComponent>(ent, out var blinkable))
return;

blinkable.BlinkingInterval += ent.Comp.BlinkingBonusDuration;
DirtyField(ent.Owner, blinkable, nameof(BlinkableComponent.BlinkingInterval));
blinkable.BlinkingIntervalBonus += ent.Comp.BlinkingIntervalBonus;
DirtyField(ent.Owner, blinkable, nameof(BlinkableComponent.BlinkingIntervalBonus));
}

private void OnUserShutdown(Entity<ActiveReducedBlinkingUserComponent> ent, ref ComponentShutdown _)
{
if (!TryComp<BlinkableComponent>(ent, out var blinkable))
return;

blinkable.BlinkingInterval -= ent.Comp.BlinkingBonusDuration;
DirtyField(ent.Owner, blinkable, nameof(BlinkableComponent.BlinkingInterval));
blinkable.BlinkingIntervalBonus -= ent.Comp.BlinkingIntervalBonus;
if (blinkable.BlinkingIntervalBonus < TimeSpan.Zero)
blinkable.BlinkingIntervalBonus = TimeSpan.Zero;

DirtyField(ent.Owner, blinkable, nameof(BlinkableComponent.BlinkingIntervalBonus));
_blinking.ResetBlink(ent.Owner, predicted: false);

_popup.PopupEntity(Loc.GetString("eye-droplets-end"), ent, ent);
}
Expand Down
12 changes: 12 additions & 0 deletions Content.Shared/_Scp/Blinking/BlinkableComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ public sealed partial class BlinkableComponent : Component
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer)), AutoNetworkedField]
public TimeSpan BlinkingIntervalVariance = TimeSpan.FromSeconds(4f);

/// <summary>
/// Привыкание к средствам, которые помогают не моргать.
/// </summary>
[ViewVariables, AutoNetworkedField]
public float ReducedBlinkingTolerance = 0f;

/// <summary>
/// Накопительный бонус к интервалу между морганиями.
/// </summary>
[ViewVariables, AutoNetworkedField]
public TimeSpan BlinkingIntervalBonus;

/// <summary>
/// Время следующего моргания.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Content.Shared._Scp.Blinking.ReducedBlinking;
public sealed partial class ActiveReducedBlinkingUserComponent : Component
{
[DataField(required:true), AutoNetworkedField]
public TimeSpan BlinkingBonusDuration;
public TimeSpan BlinkingIntervalBonus;

[ViewVariables]
public TimeSpan FirstBonusEndTime;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Content.Shared.DoAfter;
using Content.Shared._Sunrise.Random;
using Content.Shared.DoAfter;
using Content.Shared.IdentityManagement;
using Content.Shared.Interaction;
using Content.Shared.Popups;
Expand All @@ -12,16 +13,23 @@ namespace Content.Shared._Scp.Blinking.ReducedBlinking;

// TODO: Переделать на химикат и дать возможно варить, используя реагент 173 и нечто из синтезатора реагентов.
// TODO: Добавить звук закапывания капель.
// TODO: Анхардкод: Перенос значений в компоненты
public abstract class SharedReducedBlinkingSystem : EntitySystem
{
[Dependency] private readonly SharedBlinkingSystem _blinking = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
[Dependency] private readonly UseDelaySystem _useDelay = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly RandomPredictedSystem _random = default!;
[Dependency] private readonly INetManager _net = default!;
[Dependency] protected readonly IGameTiming Timing = default!;

private const float ToleranceReduceUseLimit = 90.0f;
private const float MinReducedBlinkingEffectiveness = 0.15f;
private const float MinToleranceIncrease = 15f;
private const float MaxToleranceIncrease = 25f;

public override void Initialize()
{
base.Initialize();
Expand Down Expand Up @@ -67,21 +75,39 @@ private void OnSuccess(Entity<ReducedBlinkingComponent> ent, ref EyeDropletsUsed
return;
}

blinkable.AdditionalBlinkingTime = ent.Comp.FirstBlinkingBonusTime;
DirtyField(target, blinkable, nameof(BlinkableComponent.AdditionalBlinkingTime));
_blinking.ResetBlink(target);
_useDelay.TryResetDelay(ent);
if (blinkable.ReducedBlinkingTolerance >= ToleranceReduceUseLimit)
{
_popup.PopupPredicted(Loc.GetString("eye-droplets-tolerance-too-high"), ent, ent, PopupType.LargeCaution);
return;
}

var effectiveness = GetReducedBlinkingEffectiveness(blinkable.ReducedBlinkingTolerance);

var firstBonusTime = ent.Comp.FirstBlinkingBonusTime * effectiveness;
var otherBonusTime = ent.Comp.OtherBlinkingBonusTime * effectiveness;
var bonusDuration = ent.Comp.OtherBlinkingBonusDuration * effectiveness;

var comp = new ActiveReducedBlinkingUserComponent
{
BlinkingBonusDuration = ent.Comp.OtherBlinkingBonusDuration,
FirstBonusEndTime = Timing.CurTime + ent.Comp.FirstBlinkingBonusTime,
AllBonusEndTime = Timing.CurTime + ent.Comp.OtherBlinkingBonusTime,
BlinkingIntervalBonus = bonusDuration,
FirstBonusEndTime = Timing.CurTime + firstBonusTime,
AllBonusEndTime = Timing.CurTime + otherBonusTime,
};

AddComp(target, comp, true);
Dirty(target, comp);

blinkable.AdditionalBlinkingTime += firstBonusTime;
blinkable.ReducedBlinkingTolerance = MathF.Min(
100f,
blinkable.ReducedBlinkingTolerance + _random.NextFloatForEntity(target, MinToleranceIncrease, MaxToleranceIncrease));

DirtyField(target, blinkable, nameof(BlinkableComponent.AdditionalBlinkingTime));
DirtyField(target, blinkable, nameof(BlinkableComponent.ReducedBlinkingTolerance));

_blinking.ResetBlink(target);
_useDelay.TryResetDelay(ent);

if (ent.Comp.UseSound != null)
_audio.PlayPredicted(ent.Comp.UseSound, ent, target);

Expand All @@ -94,6 +120,12 @@ private void OnSuccess(Entity<ReducedBlinkingComponent> ent, ref EyeDropletsUsed
if (ent.Comp.UsageCount <= 0 && _net.IsServer)
QueueDel(ent);
}

private static float GetReducedBlinkingEffectiveness(float tolerance)
{
var normalized = Math.Clamp(tolerance / 100f, 0f, 1f);
return 1f - normalized * (1f - MinReducedBlinkingEffectiveness);
}
}

[Serializable, NetSerializable]
Expand Down
25 changes: 24 additions & 1 deletion Content.Shared/_Scp/Blinking/SharedBlinkingSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using Content.Shared._Scp.Blinking.ReducedBlinking;
using Content.Shared._Scp.Helpers;
using Content.Shared._Scp.Scp173;
using Content.Shared._Scp.Watching;
Expand All @@ -12,6 +13,7 @@

namespace Content.Shared._Scp.Blinking;

// TODO: Анхардкод: Перенос значений в компоненты
// TODO: Избавиться от членения на EyeClosing и Blinking.
// Они слишком сильно переплетаются, чтобы их так разделять.
// Вместо этого разделить систему на апдейт + обработку ивентов | API + хелперы + ивенты
Expand All @@ -23,7 +25,10 @@ public abstract partial class SharedBlinkingSystem : EntitySystem
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly INetManager _net = default!;

private const float ReducedBlinkingToleranceDecayPerSecond = 0.05f;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial | 💤 Low value

Hardcoded константа при наличии TODO о переносе значений в компоненты.

На строке 16 есть TODO-комментарий "Анхардкод: Перенос значений в компоненты". Новая константа ReducedBlinkingToleranceDecayPerSecond добавлена как hardcoded значение в системе. Для будущей гибкости рассмотрите возможность переноса этого значения в BlinkableComponent как [DataField].

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Content.Shared/_Scp/Blinking/SharedBlinkingSystem.cs` at line 28, There is a
TODO comment on line 16 about moving hardcoded values to components, but the new
constant ReducedBlinkingToleranceDecayPerSecond is being added as a hardcoded
value instead. To align with the stated goal and improve flexibility, remove the
hardcoded constant definition and add this value as a [DataField] property in
the BlinkableComponent class instead. This way the blinking tolerance decay rate
can be configured per component rather than being a fixed system-wide constant.


protected EntityQuery<BlinkableComponent> BlinkableQuery;
protected EntityQuery<ActiveReducedBlinkingUserComponent> ActiveReducedBlinkingQuery;

public override void Initialize()
{
Expand All @@ -37,6 +42,7 @@ public override void Initialize()
InitializeEyeClosing();

BlinkableQuery = GetEntityQuery<BlinkableComponent>();
ActiveReducedBlinkingQuery = GetEntityQuery<ActiveReducedBlinkingUserComponent>();
}

#region Event handlers
Expand Down Expand Up @@ -110,6 +116,19 @@ public override void Update(float frameTime)
var query = EntityQueryEnumerator<BlinkableComponent>();
while (query.MoveNext(out var uid, out var blinkableComponent))
{
if (blinkableComponent.ReducedBlinkingTolerance > 0f)
{
if (!ActiveReducedBlinkingQuery.HasComp(uid))
{
blinkableComponent.ReducedBlinkingTolerance = MathF.Max(
0f,
blinkableComponent.ReducedBlinkingTolerance - ReducedBlinkingToleranceDecayPerSecond * frameTime
);

DirtyField(uid, blinkableComponent, nameof(BlinkableComponent.ReducedBlinkingTolerance));
}
}

var blinkableEntity = (uid, blinkableComponent);

if (TryOpenEyes(blinkableEntity))
Expand Down Expand Up @@ -156,7 +175,11 @@ public void SetNextBlink(Entity<BlinkableComponent?> ent, TimeSpan interval, Tim
if (interval < TimeSpan.Zero)
interval = TimeSpan.Zero;

ent.Comp.NextBlink = _timing.CurTime + interval + variance.Value + ent.Comp.AdditionalBlinkingTime;
var nextBlinkDelay = interval + variance.Value + ent.Comp.BlinkingIntervalBonus + ent.Comp.AdditionalBlinkingTime;
if (nextBlinkDelay < TimeSpan.Zero)
nextBlinkDelay = TimeSpan.Zero;

ent.Comp.NextBlink = _timing.CurTime + nextBlinkDelay;
ent.Comp.AdditionalBlinkingTime = TimeSpan.Zero;

if (!predicted)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
eye-droplets-failed = Глаза { $name } должны быть открыты
eye-droplets-used = { $name } закапывает капли себе в глаза
eye-droplets-first-bonus-end = Глаза начинают пересыхать, придется начать моргать
eye-droplets-tolerance-too-high = Кажется, что мои глаза привыкли к каплям!
Comment thread
WardexOfficial marked this conversation as resolved.
eye-droplets-end = Глаза пересохли, кажется капли выветрились!
close-eye-phrase-1 = Моргаю!
close-eye-phrase-2 = Моргаю!!
Expand Down
Loading