Skip to content

Commit

Permalink
Glimmer update
Browse files Browse the repository at this point in the history
  • Loading branch information
Rxup committed Jul 12, 2024
1 parent d119ef4 commit d99e94e
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 74 deletions.
125 changes: 69 additions & 56 deletions Content.Server/Backmen/Psionics/Glimmer/GlimmerReactiveSystem.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Content.Server.Backmen.Audio;
using Content.Server.CartridgeLoader.Cartridges;
using Content.Server.Power.Components;
using Content.Server.Electrocution;
using Content.Server.Lightning;
using Content.Server.Explosion.EntitySystems;
using Content.Server.Ghost;
using Content.Server.Revenant.EntitySystems;
using Content.Server.GameTicking;
using Content.Shared.Audio;
using Content.Shared.Backmen.Psionics.Glimmer;
using Content.Shared.Construction.EntitySystems;
Expand All @@ -15,6 +15,8 @@
using Content.Shared.Damage;
using Content.Shared.Destructible;
using Content.Shared.Construction.Components;
using Content.Shared.MassMedia.Components;
using Content.Shared.MassMedia.Systems;
using Robust.Shared.Audio;
using Robust.Shared.Random;
using Robust.Shared.Physics.Components;
Expand All @@ -39,11 +41,12 @@ public sealed class GlimmerReactiveSystem : EntitySystem
[Dependency] private readonly EntityLookupSystem _entityLookupSystem = default!;
[Dependency] private readonly AnchorableSystem _anchorableSystem = default!;
[Dependency] private readonly SharedDestructibleSystem _destructibleSystem = default!;
[Dependency] private readonly GhostSystem _ghostSystem = default!;
[Dependency] private readonly RevenantSystem _revenantSystem = default!;
//[Dependency] private readonly GhostSystem _ghostSystem = default!;
//[Dependency] private readonly RevenantSystem _revenantSystem = default!;
[Dependency] private readonly MapSystem _mapSystem = default!;
[Dependency] private readonly SharedTransformSystem _transformSystem = default!;
[Dependency] private readonly SharedPointLightSystem _pointLightSystem = default!;
[Dependency] private readonly GameTicker _ticker = default!;


public float Accumulator = 0;
Expand All @@ -52,14 +55,10 @@ public sealed class GlimmerReactiveSystem : EntitySystem
public GlimmerTier LastGlimmerTier = GlimmerTier.Minimal;
public bool GhostsVisible = false;

private ISawmill _sawmill = default!;

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

_sawmill = Logger.GetSawmill("glimmer.reactive");

SubscribeLocalEvent<RoundRestartCleanupEvent>(Reset);

SubscribeLocalEvent<SharedGlimmerReactiveComponent, MapInitEvent>(OnMapInit);
Expand All @@ -81,8 +80,10 @@ public override void Initialize()
/// <param name="glimmerTierDelta">The number of steps in tier
/// difference since last update. This can be zero for the sake of
/// toggling the enabled states.</param>
private void UpdateEntityState(EntityUid uid, SharedGlimmerReactiveComponent component,
GlimmerTier currentGlimmerTier, int glimmerTierDelta)
private void UpdateEntityState(EntityUid uid,
SharedGlimmerReactiveComponent component,
GlimmerTier currentGlimmerTier,
int glimmerTierDelta)
{
var isEnabled = true;

Expand Down Expand Up @@ -134,11 +135,11 @@ private void OnMapInit(EntityUid uid, SharedGlimmerReactiveComponent component,
{
if (component.RequiresApcPower && !HasComp<ApcPowerReceiverComponent>(uid))
{
_sawmill.Warning($"{ToPrettyString(uid)} had RequiresApcPower set to true but no ApcPowerReceiverComponent was found on init.");
Log.Warning($"{ToPrettyString(uid)} had RequiresApcPower set to true but no ApcPowerReceiverComponent was found on init.");
}

if (component.ModulatesPointLight && !HasComp<PointLightComponent>(uid))
_sawmill.Warning($"{ToPrettyString(uid)} had ModulatesPointLight set to true but no PointLightComponent was found on init.");
Log.Warning($"{ToPrettyString(uid)} had ModulatesPointLight set to true but no PointLightComponent was found on init.");

UpdateEntityState(uid, component, LastGlimmerTier, (int) LastGlimmerTier);
}
Expand Down Expand Up @@ -166,7 +167,8 @@ private void OnPowerChanged(EntityUid uid, SharedGlimmerReactiveComponent compon
/// <summary>
/// Enable / disable special effects from higher tiers.
/// </summary>
private void OnTierChanged(EntityUid uid, SharedGlimmerReactiveComponent component,
private void OnTierChanged(EntityUid uid,
SharedGlimmerReactiveComponent component,
GlimmerTierChangedEvent args)
{
if (!TryComp<ApcPowerReceiverComponent>(uid, out var receiver))
Expand All @@ -186,7 +188,8 @@ private void OnTierChanged(EntityUid uid, SharedGlimmerReactiveComponent compone
}
}

private void AddShockVerb(EntityUid uid, SharedGlimmerReactiveComponent component,
private void AddShockVerb(EntityUid uid,
SharedGlimmerReactiveComponent component,
GetVerbsEvent<AlternativeVerb> args)
{
if (!args.CanAccess || !args.CanInteract)
Expand Down Expand Up @@ -385,21 +388,63 @@ public override void Update(float frameTime)
var glimmerTierDelta = (int) currentGlimmerTier - (int) LastGlimmerTier;
var ev = new GlimmerTierChangedEvent(LastGlimmerTier, currentGlimmerTier, glimmerTierDelta);

var reactives = EntityQueryEnumerator<SharedGlimmerReactiveComponent>();
while (reactives.MoveNext(out var owner, out var reactive))
var reactiv = EntityQueryEnumerator<SharedGlimmerReactiveComponent>();
while (reactiv.MoveNext(out var owner, out var reactive))
{
UpdateEntityState(owner, reactive, currentGlimmerTier, glimmerTierDelta);
RaiseLocalEvent(owner, ev);
}

var wrappedMessage = Loc.GetString(
"glimmer-change-notification",
("last", LastGlimmerTier),
("now", currentGlimmerTier),
("delta", glimmerTierDelta > 0 ? $"+{glimmerTierDelta}" : glimmerTierDelta)
);
LastGlimmerTier = currentGlimmerTier;

var stationNews = EntityQueryEnumerator<StationNewsComponent>();
while (stationNews.MoveNext(out var station, out var stationNewsComponent))
{
var article = new NewsArticle();
article.Author = Loc.GetString("ent-SophicScribe");
article.Title = wrappedMessage;
article.Content = currentGlimmerTier switch
{
GlimmerTier.Minimal => Loc.GetString("glimmer-reading-minimal"),
GlimmerTier.Low => Loc.GetString("glimmer-reading-low"),
GlimmerTier.Moderate => Loc.GetString("glimmer-reading-moderate"),
GlimmerTier.High => Loc.GetString("glimmer-reading-high"),
GlimmerTier.Dangerous => Loc.GetString("glimmer-reading-dangerous"),
_ => Loc.GetString("glimmer-reading-critical"),
};
article.ShareTime = _ticker.RoundDuration();
stationNewsComponent.Articles.Add(article);
var args = new NewsArticlePublishedEvent(article);
var query = EntityQueryEnumerator<NewsReaderCartridgeComponent>();
while (query.MoveNext(out var readerUid, out _))
{
RaiseLocalEvent(readerUid, ref args);
}
}
}

var reactives = EntityQueryEnumerator<SharedGlimmerReactiveComponent,TransformComponent>();
while (reactives.MoveNext(out var owner, out _, out var transformComponent))
{
if (currentGlimmerTier == GlimmerTier.Critical)
BeamRandomNearProber(owner, 1, 12);

if (currentGlimmerTier is GlimmerTier.Critical or GlimmerTier.Dangerous && !transformComponent.Anchored)
AnchorOrExplode(owner);

}

/*
if (currentGlimmerTier == GlimmerTier.Critical)
{
_ghostSystem.MakeVisible(true);
_revenantSystem.MakeVisible(true);
GhostsVisible = true;
//_ghostSystem.MakeVisible(true);
//_revenantSystem.MakeVisible(true);
//GhostsVisible = true;
var reactives = EntityQueryEnumerator<SharedGlimmerReactiveComponent>();
while (reactives.MoveNext(out var owner, out _))
{
Expand All @@ -408,45 +453,13 @@ public override void Update(float frameTime)
}
else if (GhostsVisible == true)
{
_ghostSystem.MakeVisible(false);
_revenantSystem.MakeVisible(false);
GhostsVisible = false;
}
//_ghostSystem.MakeVisible(false);
//_revenantSystem.MakeVisible(false);
//GhostsVisible = false;
}*/

Accumulator = 0;
}
}
}

/// <summary>
/// This event is fired when the broader glimmer tier has changed,
/// not on every single adjustment to the glimmer count.
///
/// <see cref="GlimmerSystem.GetGlimmerTier"/> has the exact
/// values corresponding to tiers.
/// </summary>
public sealed class GlimmerTierChangedEvent : EntityEventArgs
{
/// <summary>
/// What was the last glimmer tier before this event fired?
/// </summary>
public readonly GlimmerTier LastTier;

/// <summary>
/// What is the current glimmer tier?
/// </summary>
public readonly GlimmerTier CurrentTier;

/// <summary>
/// What is the change in tiers between the last and current tier?
/// </summary>
public readonly int TierDelta;

public GlimmerTierChangedEvent(GlimmerTier lastTier, GlimmerTier currentTier, int tierDelta)
{
LastTier = lastTier;
CurrentTier = currentTier;
TierDelta = tierDelta;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public sealed class PassiveGlimmerReductionSystem : EntitySystem
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly GlimmerMonitorCartridgeSystem _cartridgeSys = default!;
//[Dependency] private readonly GlimmerMonitorCartridgeSystem _cartridgeSys = default!;

/// List of glimmer values spaced by minute.
public List<int> GlimmerValues = new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public sealed class GlimmerStructuresSystem : EntitySystem
{
[Dependency] private readonly PowerReceiverSystem _powerReceiverSystem = default!;
[Dependency] private readonly GlimmerSystem _glimmerSystem = default!;
private EntityQuery<ApcPowerReceiverComponent> _apcPower;

public override void Initialize()
{
Expand All @@ -22,6 +23,8 @@ public override void Initialize()

SubscribeLocalEvent<GlimmerSourceComponent, AnomalyPulseEvent>(OnAnomalyPulse);
SubscribeLocalEvent<GlimmerSourceComponent, AnomalySupercriticalEvent>(OnAnomalySupercritical);

_apcPower = GetEntityQuery<ApcPowerReceiverComponent>();
}

private void OnAnomalyVesselPowerChanged(EntityUid uid, AnomalyVesselComponent component, ref PowerChangedEvent args)
Expand All @@ -44,7 +47,7 @@ private void OnAnomalyPulse(EntityUid uid, GlimmerSourceComponent component, ref
// needs to be made in the future. I suggest a GlimmerAnomaly
// component.

if (TryComp<AnomalyComponent>(uid, out var anomaly))
if (TryComp<AnomalyComponent>(args.Anomaly, out var anomaly))
_glimmerSystem.Glimmer += (int) (5f * anomaly.Severity);
}

Expand All @@ -59,25 +62,26 @@ public override void Update(float frameTime)
var q = EntityQueryEnumerator<GlimmerSourceComponent>();
while (q.MoveNext(out var owner, out var source))
{
if (!_powerReceiverSystem.IsPowered(owner))
continue;

if (!source.Active)
continue;

source.Accumulator += frameTime;

if (source.Accumulator > source.SecondsPerGlimmer)
if (source.Accumulator <= source.SecondsPerGlimmer)
continue;

if (_apcPower.TryComp(owner, out var powerReceiverComponent) && !_powerReceiverSystem.IsPowered(owner,powerReceiverComponent))
continue;

source.Accumulator -= source.SecondsPerGlimmer;

if (source.AddToGlimmer)
{
_glimmerSystem.Glimmer++;
}
else
{
source.Accumulator -= source.SecondsPerGlimmer;
if (source.AddToGlimmer)
{
_glimmerSystem.Glimmer++;
}
else
{
_glimmerSystem.Glimmer--;
}
_glimmerSystem.Glimmer--;
}
}
}
Expand Down
12 changes: 9 additions & 3 deletions Content.Server/Backmen/StationEvents/Events/FreeProberRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected override void Started(EntityUid uid, FreeProberRuleComponent component

List<Entity<TransformComponent>> possibleSpawns = new();

var query = EntityQueryEnumerator<GlimmerSourceComponent,TransformComponent, MetaDataComponent>();
var query = EntityQueryEnumerator<GlimmerSourceComponent, TransformComponent, MetaDataComponent>();
while (query.MoveNext(out var glimmerSource, out var glimmerSourceComponent, out var transformComponent, out var metaDataComponent))
{
// skip anomaly in templates
Expand All @@ -45,7 +45,10 @@ protected override void Started(EntityUid uid, FreeProberRuleComponent component
var station = _stationSystem.GetOwningStation(glimmerSource, transformComponent);

// skip spawn on salvages!
if (station == null || !HasComp<StationEventEligibleComponent>(station))
if (station == null ||
!HasComp<StationEventEligibleComponent>(station) ||
transformComponent.GridUid == null ||
!HasComp<BecomesStationComponent>(transformComponent.GridUid))
continue;

if (glimmerSourceComponent is { AddToGlimmer: true, Active: true })
Expand All @@ -66,7 +69,10 @@ protected override void Started(EntityUid uid, FreeProberRuleComponent component
var station = _stationSystem.GetOwningStation(battery, transformComponent);

// skip spawn on salvages!
if (station == null || !HasComp<StationEventEligibleComponent>(station))
if (station == null ||
!HasComp<StationEventEligibleComponent>(station) ||
transformComponent.GridUid == null ||
!HasComp<BecomesStationComponent>(transformComponent.GridUid))
continue;

possibleSpawns.Add((battery,transformComponent));
Expand Down
36 changes: 36 additions & 0 deletions Content.Shared/Backmen/Psionics/Glimmer/GlimmerTierChangedEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Robust.Shared.Serialization;

namespace Content.Shared.Backmen.Psionics.Glimmer;

/// <summary>
/// This event is fired when the broader glimmer tier has changed,
/// not on every single adjustment to the glimmer count.
///
/// <see cref="GlimmerSystem.GetGlimmerTier"/> has the exact
/// values corresponding to tiers.
/// </summary>
[Serializable, NetSerializable]
public sealed class GlimmerTierChangedEvent : EntityEventArgs
{
/// <summary>
/// What was the last glimmer tier before this event fired?
/// </summary>
public readonly GlimmerTier LastTier;

/// <summary>
/// What is the current glimmer tier?
/// </summary>
public readonly GlimmerTier CurrentTier;

/// <summary>
/// What is the change in tiers between the last and current tier?
/// </summary>
public readonly int TierDelta;

public GlimmerTierChangedEvent(GlimmerTier lastTier, GlimmerTier currentTier, int tierDelta)
{
LastTier = lastTier;
CurrentTier = currentTier;
TierDelta = tierDelta;
}
}
1 change: 1 addition & 0 deletions Resources/Locale/ru-RU/backmen/abilities/psionic.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ action-name-telegnosis = Телегноз
action-description-telegnosis = Создайте телегностическую проекцию, чтобы удаленно наблюдать за происходящим.
action-name-psionic-regeneration = Псионическая регенерация
action-description-psionic-regeneration = Доведите свой естественный метаболизм до предела, чтобы усилить способность вашего организма к регенерации.
glimmer-change-notification = Уровень сияния изменился с { $last } до { $now } ( { $delta } )
glimmer-report = Текущий уровень сияния: { $level }Ψ.
glimmer-event-report-generic = Ноосферический разряд не обнаружен. Уровень сияния снизился на { $decrease } до { $level }Ψ.
glimmer-event-report-signatures = Проявились новые псионические сигнатуры. Уровень сияния снизился на { $decrease } до { $level }Ψ.
Expand Down

0 comments on commit d99e94e

Please sign in to comment.