Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Psionic System Cleanup #703

Merged
Merged
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
48 changes: 16 additions & 32 deletions Content.Server/Abilities/Psionics/PsionicAbilitiesSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand All @@ -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<PsionicComponent>(uid))
if (Deleted(uid)
|| HasComp<PsionicComponent>(uid))
return;

//Don't know if this will work. New mind state vs old.
if (!TryComp<MindContainerComponent>(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<PsionicAwaitingPlayerComponent>(uid);
return;
Expand All @@ -65,18 +56,16 @@ public void AddPsionics(EntityUid uid, bool warn = true)
if (!_mindSystem.TryGetSession(mind, out var client))
return;

if (warn && TryComp<ActorComponent>(uid, out var actor))
if (warn && HasComp<ActorComponent>(uid))
_euiManager.OpenEui(new AcceptPsionicsEui(uid, this), client);
else
AddRandomPsionicPower(uid);
}

public void AddPsionics(EntityUid uid, string powerComp)
{
if (Deleted(uid))
return;

if (HasComp<PsionicComponent>(uid))
if (Deleted(uid)
|| HasComp<PsionicComponent>(uid))
return;

AddComp<PsionicComponent>(uid);
Expand All @@ -93,7 +82,7 @@ public void AddRandomPsionicPower(EntityUid uid)

if (!_prototypeManager.TryIndex<WeightedRandomPrototype>("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;
}

Expand All @@ -108,15 +97,13 @@ public void AddRandomPsionicPower(EntityUid uid)

public void RemovePsionics(EntityUid uid)
{
if (!TryComp<PsionicComponent>(uid, out var psionic))
return;

if (!psionic.Removable)
if (!TryComp<PsionicComponent>(uid, out var psionic)
|| !psionic.Removable)
return;

if (!_prototypeManager.TryIndex<WeightedRandomPrototype>("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;
}

Expand All @@ -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");

Expand Down
41 changes: 9 additions & 32 deletions Content.Server/Psionics/PsionicsSystem.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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!;
Expand All @@ -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()
Expand Down Expand Up @@ -90,46 +83,32 @@ private void OnMeleeHit(EntityUid uid, AntiPsionicWeaponComponent component, Mel

private void OnInit(EntityUid uid, PsionicComponent component, ComponentInit args)
{
if (!component.Removable)
return;

if (!TryComp<NpcFactionMemberComponent>(uid, out var factions))
return;

if (_npcFactonSystem.ContainsFaction(uid, "GlimmerMonster", factions))
if (!component.Removable
|| !TryComp<NpcFactionMemberComponent>(uid, out var factions)
|| _npcFactonSystem.ContainsFaction(uid, "GlimmerMonster", factions))
return;

_npcFactonSystem.AddFaction(uid, "PsionicInterloper");
}

private void OnRemove(EntityUid uid, PsionicComponent component, ComponentRemove args)
{
if (!TryComp<NpcFactionMemberComponent>(uid, out var factions))
if (!HasComp<NpcFactionMemberComponent>(uid))
return;

_npcFactonSystem.RemoveFaction(uid, "PsionicInterloper");
}

private void OnStamHit(EntityUid uid, AntiPsionicWeaponComponent component, TakeStaminaDamageEvent args)
{
var bonus = false;

if (HasComp<PsionicComponent>(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<PsionicComponent>(uid))
return;

if (!_cfg.GetCVar(CCVars.PsionicRollsEnabled))
if (HasComp<PsionicComponent>(uid)
|| !_cfg.GetCVar(CCVars.PsionicRollsEnabled))
return;

var chance = component.Chance;
Expand All @@ -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);
Expand Down
Loading