From 31e3c02aad4fdb435b9682d42df90e27ef9af96b Mon Sep 17 00:00:00 2001 From: VMSolidus Date: Fri, 9 Aug 2024 16:41:18 -0400 Subject: [PATCH] Psionic System Cleanup (#703) # Description Just some regular cleanup of PsionicSystem and PsionicAbilitiesSystem. No refactoring today, just cleanup. Tomorrow I will serialize this shit, assuming this gets merged. No media because there's nothing to show. No changelog because this isn't playerfacing. --- .../Psionics/PsionicAbilitiesSystem.cs | 48 +++++++------------ Content.Server/Psionics/PsionicsSystem.cs | 41 ++++------------ 2 files changed, 25 insertions(+), 64 deletions(-) diff --git a/Content.Server/Abilities/Psionics/PsionicAbilitiesSystem.cs b/Content.Server/Abilities/Psionics/PsionicAbilitiesSystem.cs index ee16aaccfb6..e59696aa904 100644 --- a/Content.Server/Abilities/Psionics/PsionicAbilitiesSystem.cs +++ b/Content.Server/Abilities/Psionics/PsionicAbilitiesSystem.cs @@ -6,13 +6,9 @@ using Content.Server.EUI; using Content.Server.Psionics; using Content.Server.Mind; -using Content.Shared.Mind; -using Content.Shared.Mind.Components; using Content.Shared.StatusEffect; using Robust.Shared.Random; using Robust.Shared.Prototypes; -using Robust.Server.GameObjects; -using Robust.Server.Player; using Robust.Shared.Player; namespace Content.Server.Abilities.Psionics @@ -22,13 +18,14 @@ public sealed class PsionicAbilitiesSystem : EntitySystem [Dependency] private readonly IComponentFactory _componentFactory = default!; [Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly SharedActionsSystem _actionsSystem = default!; - [Dependency] private readonly IPlayerManager _playerManager = default!; [Dependency] private readonly EuiManager _euiManager = default!; [Dependency] private readonly StatusEffectsSystem _statusEffectsSystem = default!; [Dependency] private readonly GlimmerSystem _glimmerSystem = default!; [Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly MindSystem _mindSystem = default!; + private ISawmill _sawmill = default!; + public override void Initialize() { base.Initialize(); @@ -46,17 +43,11 @@ private void OnPlayerAttached(EntityUid uid, PsionicAwaitingPlayerComponent comp public void AddPsionics(EntityUid uid, bool warn = true) { - if (Deleted(uid)) - return; - - if (HasComp(uid)) + if (Deleted(uid) + || HasComp(uid)) return; - //Don't know if this will work. New mind state vs old. - if (!TryComp(uid, out var mindContainer) || - !_mindSystem.TryGetMind(uid, out _, out var mind )) - //|| - //!_mindSystem.TryGetMind(uid, out var mind, mindContainer)) + if (!_mindSystem.TryGetMind(uid, out _, out var mind)) { EnsureComp(uid); return; @@ -65,7 +56,7 @@ public void AddPsionics(EntityUid uid, bool warn = true) if (!_mindSystem.TryGetSession(mind, out var client)) return; - if (warn && TryComp(uid, out var actor)) + if (warn && HasComp(uid)) _euiManager.OpenEui(new AcceptPsionicsEui(uid, this), client); else AddRandomPsionicPower(uid); @@ -73,10 +64,8 @@ public void AddPsionics(EntityUid uid, bool warn = true) public void AddPsionics(EntityUid uid, string powerComp) { - if (Deleted(uid)) - return; - - if (HasComp(uid)) + if (Deleted(uid) + || HasComp(uid)) return; AddComp(uid); @@ -93,7 +82,7 @@ public void AddRandomPsionicPower(EntityUid uid) if (!_prototypeManager.TryIndex("RandomPsionicPowerPool", out var pool)) { - Logger.Error("Can't index the random psionic power pool!"); + _sawmill.Error("Can't index the random psionic power pool!"); return; } @@ -108,15 +97,13 @@ public void AddRandomPsionicPower(EntityUid uid) public void RemovePsionics(EntityUid uid) { - if (!TryComp(uid, out var psionic)) - return; - - if (!psionic.Removable) + if (!TryComp(uid, out var psionic) + || !psionic.Removable) return; if (!_prototypeManager.TryIndex("RandomPsionicPowerPool", out var pool)) { - Logger.Error("Can't index the random psionic power pool!"); + _sawmill.Error("Can't index the random psionic power pool!"); return; } @@ -127,13 +114,10 @@ public void RemovePsionics(EntityUid uid) if (EntityManager.TryGetComponent(uid, comp.GetType(), out var psionicPower)) RemComp(uid, psionicPower); } - if (psionic.PsionicAbility != null){ - _actionsSystem.TryGetActionData( psionic.PsionicAbility, out var psiAbility ); - if (psiAbility != null){ - var owner = psiAbility.Owner; - _actionsSystem.RemoveAction(uid, psiAbility.Owner); - } - } + if (psionic.PsionicAbility != null + && _actionsSystem.TryGetActionData(psionic.PsionicAbility, out var psiAbility) + && psiAbility is not null) + _actionsSystem.RemoveAction(uid, psionic.PsionicAbility); _statusEffectsSystem.TryAddStatusEffect(uid, "Stutter", TimeSpan.FromMinutes(5), false, "StutteringAccent"); diff --git a/Content.Server/Psionics/PsionicsSystem.cs b/Content.Server/Psionics/PsionicsSystem.cs index 33505e3f6fc..fb5d18f2843 100644 --- a/Content.Server/Psionics/PsionicsSystem.cs +++ b/Content.Server/Psionics/PsionicsSystem.cs @@ -1,19 +1,15 @@ using Content.Shared.Abilities.Psionics; using Content.Shared.StatusEffect; -using Content.Shared.Mobs; using Content.Shared.Psionics.Glimmer; using Content.Shared.Weapons.Melee.Events; using Content.Shared.Damage.Events; -using Content.Shared.IdentityManagement; using Content.Shared.CCVar; using Content.Server.Abilities.Psionics; using Content.Server.Chat.Systems; using Content.Server.Electrocution; using Content.Server.NPC.Components; using Content.Server.NPC.Systems; -using Robust.Shared.Audio; using Robust.Shared.Audio.Systems; -using Robust.Shared.Player; using Robust.Shared.Configuration; using Robust.Shared.Random; @@ -27,7 +23,6 @@ public sealed class PsionicsSystem : EntitySystem [Dependency] private readonly ElectrocutionSystem _electrocutionSystem = default!; [Dependency] private readonly MindSwapPowerSystem _mindSwapPowerSystem = default!; [Dependency] private readonly GlimmerSystem _glimmerSystem = default!; - [Dependency] private readonly ChatSystem _chat = default!; [Dependency] private readonly NpcFactionSystem _npcFactonSystem = default!; [Dependency] private readonly IConfigurationManager _cfg = default!; [Dependency] private readonly SharedAudioSystem _audio = default!; @@ -41,9 +36,7 @@ public override void Update(float frameTime) { base.Update(frameTime); foreach (var roller in _rollers) - { RollPsionics(roller.uid, roller.component, false); - } _rollers.Clear(); } public override void Initialize() @@ -90,13 +83,9 @@ private void OnMeleeHit(EntityUid uid, AntiPsionicWeaponComponent component, Mel private void OnInit(EntityUid uid, PsionicComponent component, ComponentInit args) { - if (!component.Removable) - return; - - if (!TryComp(uid, out var factions)) - return; - - if (_npcFactonSystem.ContainsFaction(uid, "GlimmerMonster", factions)) + if (!component.Removable + || !TryComp(uid, out var factions) + || _npcFactonSystem.ContainsFaction(uid, "GlimmerMonster", factions)) return; _npcFactonSystem.AddFaction(uid, "PsionicInterloper"); @@ -104,7 +93,7 @@ private void OnInit(EntityUid uid, PsionicComponent component, ComponentInit arg private void OnRemove(EntityUid uid, PsionicComponent component, ComponentRemove args) { - if (!TryComp(uid, out var factions)) + if (!HasComp(uid)) return; _npcFactonSystem.RemoveFaction(uid, "PsionicInterloper"); @@ -112,24 +101,14 @@ private void OnRemove(EntityUid uid, PsionicComponent component, ComponentRemove private void OnStamHit(EntityUid uid, AntiPsionicWeaponComponent component, TakeStaminaDamageEvent args) { - var bonus = false; - if (HasComp(args.Target)) - bonus = true; - - if (!bonus) - return; - - - args.FlatModifier += component.PsychicStaminaDamage; + args.FlatModifier += component.PsychicStaminaDamage; } public void RollPsionics(EntityUid uid, PotentialPsionicComponent component, bool applyGlimmer = true, float multiplier = 1f) { - if (HasComp(uid)) - return; - - if (!_cfg.GetCVar(CCVars.PsionicRollsEnabled)) + if (HasComp(uid) + || !_cfg.GetCVar(CCVars.PsionicRollsEnabled)) return; var chance = component.Chance; @@ -154,10 +133,8 @@ public void RollPsionics(EntityUid uid, PotentialPsionicComponent component, boo public void RerollPsionics(EntityUid uid, PotentialPsionicComponent? psionic = null, float bonusMuliplier = 1f) { - if (!Resolve(uid, ref psionic, false)) - return; - - if (psionic.Rerolled) + if (!Resolve(uid, ref psionic, false) + || psionic.Rerolled) return; RollPsionics(uid, psionic, multiplier: bonusMuliplier);