diff --git a/Content.Server/Psionics/Glimmer/GlimmerCommands.cs b/Content.Server/Psionics/Glimmer/GlimmerCommands.cs index 744f4cdb9a8..9e05886adca 100644 --- a/Content.Server/Psionics/Glimmer/GlimmerCommands.cs +++ b/Content.Server/Psionics/Glimmer/GlimmerCommands.cs @@ -27,10 +27,8 @@ public sealed class GlimmerSetCommand : IConsoleCommand public async void Execute(IConsoleShell shell, string argStr, string[] args) { - if (args.Length != 1) - return; - - if (!int.TryParse(args[0], out var glimmerValue)) + if (args.Length != 1 + || !int.TryParse(args[0], out var glimmerValue)) return; var entMan = IoCManager.Resolve(); diff --git a/Content.Server/Psionics/Glimmer/GlimmerReactiveSystem.cs b/Content.Server/Psionics/Glimmer/GlimmerReactiveSystem.cs index da3b07d6dab..c72d8f49698 100644 --- a/Content.Server/Psionics/Glimmer/GlimmerReactiveSystem.cs +++ b/Content.Server/Psionics/Glimmer/GlimmerReactiveSystem.cs @@ -3,12 +3,10 @@ using Content.Server.Electrocution; using Content.Server.Lightning; using Content.Server.Explosion.EntitySystems; -using Content.Server.Construction; using Content.Server.Ghost; using Content.Server.Revenant.EntitySystems; using Content.Shared.Audio; using Content.Shared.Construction.EntitySystems; -using Content.Shared.Coordinates.Helpers; using Content.Shared.GameTicking; using Content.Shared.Psionics.Glimmer; using Content.Shared.Verbs; @@ -16,14 +14,12 @@ using Content.Shared.Damage; using Content.Shared.Destructible; using Content.Shared.Construction.Components; -using Content.Shared.Mind; using Content.Shared.Mind.Components; using Content.Shared.Weapons.Melee.Components; using Robust.Shared.Audio; using Robust.Shared.Audio.Systems; using Robust.Shared.Map; using Robust.Shared.Random; -using Robust.Shared.Physics.Components; using Robust.Shared.Utility; namespace Content.Server.Psionics.Glimmer @@ -39,13 +35,12 @@ public sealed class GlimmerReactiveSystem : EntitySystem [Dependency] private readonly LightningSystem _lightning = default!; [Dependency] private readonly ExplosionSystem _explosionSystem = default!; [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 IMapManager _mapManager = default!; [Dependency] private readonly SharedTransformSystem _transformSystem = default!; [Dependency] private readonly SharedPointLightSystem _pointLightSystem = default!; + [Dependency] private readonly ISawmill _sawmill = default!; public float Accumulator = 0; public const float UpdateFrequency = 15f; @@ -78,35 +73,28 @@ private void UpdateEntityState(EntityUid uid, SharedGlimmerReactiveComponent com { var isEnabled = true; - if (component.RequiresApcPower) - if (TryComp(uid, out ApcPowerReceiverComponent? apcPower)) - isEnabled = apcPower.Powered; + if (component.RequiresApcPower + && TryComp(uid, out ApcPowerReceiverComponent? apcPower)) + isEnabled = apcPower.Powered; _appearanceSystem.SetData(uid, GlimmerReactiveVisuals.GlimmerTier, isEnabled ? currentGlimmerTier : GlimmerTier.Minimal); - // update ambient sound + // Update ambient sound if (TryComp(uid, out GlimmerSoundComponent? glimmerSound) && TryComp(uid, out AmbientSoundComponent? ambientSoundComponent) - && glimmerSound.GetSound(currentGlimmerTier, out SoundSpecifier? spec)) + && glimmerSound.GetSound(currentGlimmerTier, out SoundSpecifier? spec) + && spec != null) + _sharedAmbientSoundSystem.SetSound(uid, spec, ambientSoundComponent); + + // Update point light + if (component.ModulatesPointLight + && _pointLightSystem.TryGetLight(uid, out var pointLight)) { - if (spec != null) - _sharedAmbientSoundSystem.SetSound(uid, spec, ambientSoundComponent); + _pointLightSystem.SetEnabled(uid, isEnabled ? currentGlimmerTier != GlimmerTier.Minimal : false, pointLight); + _pointLightSystem.SetEnergy(uid, pointLight.Energy + glimmerTierDelta * component.GlimmerToLightEnergyFactor, pointLight); + _pointLightSystem.SetRadius(uid, pointLight.Radius + glimmerTierDelta * component.GlimmerToLightRadiusFactor, pointLight); } - if (component.ModulatesPointLight) //SharedPointLightComponent is now being fetched via TryGetLight. - if (_pointLightSystem.TryGetLight(uid, out var pointLight)) - { - _pointLightSystem.SetEnabled(uid, isEnabled ? currentGlimmerTier != GlimmerTier.Minimal : false, pointLight); - // The light energy and radius are kept updated even when off - // to prevent the need to store additional state. - // - // Note that this doesn't handle edge cases where the - // PointLightComponent is removed while the - // GlimmerReactiveComponent is still present. - _pointLightSystem.SetEnergy(uid, pointLight.Energy + glimmerTierDelta * component.GlimmerToLightEnergyFactor, pointLight); - _pointLightSystem.SetRadius(uid, pointLight.Radius + glimmerTierDelta * component.GlimmerToLightRadiusFactor, pointLight); - } - } /// @@ -117,7 +105,7 @@ private void UpdateEntityState(EntityUid uid, SharedGlimmerReactiveComponent com private void OnMapInit(EntityUid uid, SharedGlimmerReactiveComponent component, MapInitEvent args) { if (component.RequiresApcPower && !HasComp(uid)) - Logger.Warning($"{ToPrettyString(uid)} had RequiresApcPower set to true but no ApcPowerReceiverComponent was found on init."); + _sawmill.Warning($"{ToPrettyString(uid)} had RequiresApcPower set to true but no ApcPowerReceiverComponent was found on init."); UpdateEntityState(uid, component, LastGlimmerTier, (int) LastGlimmerTier); } @@ -157,7 +145,8 @@ private void OnTierChanged(EntityUid uid, SharedGlimmerReactiveComponent compone receiver.PowerDisabled = false; receiver.NeedsPower = false; - } else + } + else { receiver.NeedsPower = true; } @@ -165,13 +154,10 @@ private void OnTierChanged(EntityUid uid, SharedGlimmerReactiveComponent compone private void AddShockVerb(EntityUid uid, SharedGlimmerReactiveComponent component, GetVerbsEvent args) { - if(!args.CanAccess || !args.CanInteract) - return; - - if (!TryComp(uid, out var receiver)) - return; - - if (receiver.NeedsPower) + if (!args.CanAccess + || !args.CanInteract + || !TryComp(uid, out var receiver) + || receiver.NeedsPower) return; AlternativeVerb verb = new() @@ -181,7 +167,7 @@ private void AddShockVerb(EntityUid uid, SharedGlimmerReactiveComponent componen _sharedAudioSystem.PlayPvs(component.ShockNoises, args.User); _electrocutionSystem.TryDoElectrocution(args.User, null, _glimmerSystem.Glimmer / 200, TimeSpan.FromSeconds((float) _glimmerSystem.Glimmer / 100), false); }, - Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/Spare/poweronoff.svg.192dpi.png")), + Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/VerbIcons/Spare/poweronoff.svg.192dpi.png")), Text = Loc.GetString("power-switch-component-toggle-verb"), Priority = -3 }; @@ -190,10 +176,8 @@ private void AddShockVerb(EntityUid uid, SharedGlimmerReactiveComponent componen private void OnDamageChanged(EntityUid uid, SharedGlimmerReactiveComponent component, DamageChangedEvent args) { - if (args.Origin == null) - return; - - if (!_random.Prob((float) _glimmerSystem.Glimmer / 1000)) + if (args.Origin == null + || !_random.Prob((float) _glimmerSystem.Glimmer / 1000)) return; var tier = _glimmerSystem.GetGlimmerTier(); @@ -222,27 +206,23 @@ private void OnDestroyed(EntityUid uid, SharedGlimmerReactiveComponent component private void OnUnanchorAttempt(EntityUid uid, SharedGlimmerReactiveComponent component, UnanchorAttemptEvent args) { - if (_glimmerSystem.GetGlimmerTier() >= GlimmerTier.Dangerous) - { - _sharedAudioSystem.PlayPvs(component.ShockNoises, args.User); - _electrocutionSystem.TryDoElectrocution(args.User, null, _glimmerSystem.Glimmer / 200, TimeSpan.FromSeconds((float) _glimmerSystem.Glimmer / 100), false); - args.Cancel(); - } + if (_glimmerSystem.GetGlimmerTier() < GlimmerTier.Dangerous) + return; + + _sharedAudioSystem.PlayPvs(component.ShockNoises, args.User); + _electrocutionSystem.TryDoElectrocution(args.User, null, _glimmerSystem.Glimmer / 200, TimeSpan.FromSeconds((float) _glimmerSystem.Glimmer / 100), false); + args.Cancel(); } public void BeamRandomNearProber(EntityUid prober, int targets, float range = 10f) { List targetList = new(); - foreach (var target in _entityLookupSystem.GetComponentsInRange(_transformSystem.GetMapCoordinates(prober), range)) - { - if (target.AllowedEffects.Contains("Electrocution")) - targetList.Add(target.Owner); - } + foreach (var (target, status) in _entityLookupSystem.GetEntitiesInRange(_transformSystem.GetMapCoordinates(prober), range)) + if (status.AllowedEffects.Contains("Electrocution")) + targetList.Add(target); - foreach(var reactive in _entityLookupSystem.GetComponentsInRange(_transformSystem.GetMapCoordinates(prober), range)) - { - targetList.Add(reactive.Owner); - } + foreach (var reactive in _entityLookupSystem.GetEntitiesInRange(_transformSystem.GetMapCoordinates(prober), range)) + targetList.Add(reactive); _random.Shuffle(targetList); foreach (var target in targetList) @@ -257,10 +237,9 @@ public void BeamRandomNearProber(EntityUid prober, int targets, float range = 10 private void Beam(EntityUid prober, EntityUid target, GlimmerTier tier, bool obeyCD = true) { - if (obeyCD && BeamCooldown != 0) - return; - - if (Deleted(prober) || Deleted(target)) + if (obeyCD && BeamCooldown != 0 + || Deleted(prober) + || Deleted(target)) return; var lxform = Transform(prober); @@ -293,47 +272,27 @@ private void Beam(EntityUid prober, EntityUid target, GlimmerTier tier, bool obe private void AnchorOrExplode(EntityUid uid) { - var xform = Transform(uid); - if (xform.Anchored) - return; - - if (!TryComp(uid, out var physics)) - return; - - var coordinates = xform.Coordinates; - var gridUid = xform.GridUid; - - if (_mapManager.TryGetGrid(gridUid, out var grid)) - { - var tileIndices = grid.TileIndicesFor(coordinates); + if (Transform(uid).GridUid is null) + _destructibleSystem.DestroyEntity(uid); - if (_anchorableSystem.TileFree(grid, tileIndices, physics.CollisionLayer, physics.CollisionMask) && - _transformSystem.AnchorEntity(uid, xform)) - { - return; - } - } - - // Wasn't able to get a grid or a free tile, so explode. - _destructibleSystem.DestroyEntity(uid); + if (HasComp(uid)) + _transformSystem.AnchorEntity(uid, Transform(uid)); } private void OnMeleeThrowOnHitAttempt(Entity ent, ref AttemptMeleeThrowOnHitEvent args) { - var (uid, _) = ent; - if (_glimmerSystem.GetGlimmerTier() < GlimmerTier.Dangerous) return; args.Cancelled = true; args.Handled = true; - _lightning.ShootRandomLightnings(uid, 10, 2, "SuperchargedLightning", 2, false); + _lightning.ShootRandomLightnings(ent, 10, 2, "SuperchargedLightning", 2, false); // Check if the parent of the user is alive, which will be the case if the user is an item and is being held. var zapTarget = _transformSystem.GetParentUid(args.User); if (TryComp(zapTarget, out _)) - _electrocutionSystem.TryDoElectrocution(zapTarget, uid, 5, TimeSpan.FromSeconds(3), true, + _electrocutionSystem.TryDoElectrocution(zapTarget, ent, 5, TimeSpan.FromSeconds(3), true, ignoreInsulation: true); } @@ -360,7 +319,8 @@ public override void Update(float frameTime) var currentGlimmerTier = _glimmerSystem.GetGlimmerTier(); var reactives = EntityQuery(); - if (currentGlimmerTier != LastGlimmerTier) { + if (currentGlimmerTier != LastGlimmerTier) + { var glimmerTierDelta = (int) currentGlimmerTier - (int) LastGlimmerTier; var ev = new GlimmerTierChangedEvent(LastGlimmerTier, currentGlimmerTier, glimmerTierDelta); @@ -378,10 +338,9 @@ public override void Update(float frameTime) _revenantSystem.MakeVisible(true); GhostsVisible = true; foreach (var reactive in reactives) - { BeamRandomNearProber(reactive.Owner, 1, 12); - } - } else if (GhostsVisible == true) + } + else if (GhostsVisible == true) { _ghostSystem.MakeVisible(false); _revenantSystem.MakeVisible(false); diff --git a/Content.Server/Psionics/Glimmer/PassiveGlimmerReductionSystem.cs b/Content.Server/Psionics/Glimmer/PassiveGlimmerReductionSystem.cs index f0da85ce453..57c74398b08 100644 --- a/Content.Server/Psionics/Glimmer/PassiveGlimmerReductionSystem.cs +++ b/Content.Server/Psionics/Glimmer/PassiveGlimmerReductionSystem.cs @@ -4,7 +4,6 @@ using Content.Shared.CCVar; using Content.Shared.Psionics.Glimmer; using Content.Shared.GameTicking; -using Content.Server.CartridgeLoader.Cartridges; namespace Content.Server.Psionics.Glimmer { @@ -17,7 +16,6 @@ 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!; /// List of glimmer values spaced by minute. public List GlimmerValues = new(); diff --git a/Content.Server/Psionics/Glimmer/Structures/GlimmerSourceComponent.cs b/Content.Server/Psionics/Glimmer/Structures/GlimmerSourceComponent.cs index 5babb6c446d..c7db2a5229f 100644 --- a/Content.Server/Psionics/Glimmer/Structures/GlimmerSourceComponent.cs +++ b/Content.Server/Psionics/Glimmer/Structures/GlimmerSourceComponent.cs @@ -6,22 +6,22 @@ namespace Content.Server.Psionics.Glimmer /// public sealed partial class GlimmerSourceComponent : Component { - [DataField("accumulator")] + [DataField] public float Accumulator = 0f; - [DataField("active")] + [DataField] public bool Active = true; /// /// Since glimmer is an int, we'll do it like this. /// - [DataField("secondsPerGlimmer")] + [DataField] public float SecondsPerGlimmer = 10f; /// /// True if it produces glimmer, false if it subtracts it. /// - [DataField("addToGlimmer")] + [DataField] public bool AddToGlimmer = true; } } diff --git a/Content.Server/Psionics/Glimmer/Structures/GlimmerStructuresSystem.cs b/Content.Server/Psionics/Glimmer/Structures/GlimmerStructuresSystem.cs index 75125569cb5..8694147dc0e 100644 --- a/Content.Server/Psionics/Glimmer/Structures/GlimmerStructuresSystem.cs +++ b/Content.Server/Psionics/Glimmer/Structures/GlimmerStructuresSystem.cs @@ -58,10 +58,8 @@ public override void Update(float frameTime) base.Update(frameTime); foreach (var source in EntityQuery()) { - if (!_powerReceiverSystem.IsPowered(source.Owner)) - continue; - - if (!source.Active) + if (!_powerReceiverSystem.IsPowered(source.Owner) + || !source.Active) continue; source.Accumulator += frameTime; @@ -70,13 +68,9 @@ public override void Update(float frameTime) { source.Accumulator -= source.SecondsPerGlimmer; if (source.AddToGlimmer) - { _glimmerSystem.Glimmer++; - } else - { _glimmerSystem.Glimmer--; - } } } }