mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 13:37:47 +03:00
# Description Due to some inherent limitations of maintenance, code review, and me having both severely crippling ADHD and a lifelong adderal dependency, I've made the executive decision to break apart the Psionic Refactor into a multitude of smaller, bite sized PRs. I'm keeping the original Psionic Refactor PR open, because I'm going to need it for code reference to keep track of the changes I had originally worked on, but I need to essentially restart the entire refactor from scratch, and approach it from a new angle that's going to make everything actually way easier. I also need to be able to work on each available system individually wherever possible, and this fact is most readily shown by how the Lightning Refactor and Oracle Refactor were both done separately. To start off, this PR is ONLY moving all of the relevant psionics code to core folders, and nothing more. I'm doing this first so that I can immediately cut down massively on the "Files Changed" with the simplest, most basic change necessary to start my work. No changelog because this isn't player facing, and no media because there's literally nothing to show.
118 lines
4.4 KiB
C#
118 lines
4.4 KiB
C#
using Content.Shared.Actions;
|
|
using Content.Shared.Administration.Logs;
|
|
using Content.Shared.Mobs;
|
|
using Content.Shared.Mobs.Components;
|
|
using Content.Shared.Popups;
|
|
using Content.Shared.Psionics.Glimmer;
|
|
using Robust.Shared.Random;
|
|
using Robust.Shared.Serialization;
|
|
|
|
namespace Content.Shared.Abilities.Psionics
|
|
{
|
|
public sealed class SharedPsionicAbilitiesSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly SharedActionsSystem _actions = default!;
|
|
[Dependency] private readonly EntityLookupSystem _lookup = default!;
|
|
[Dependency] private readonly SharedPopupSystem _popups = default!;
|
|
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
|
|
[Dependency] private readonly GlimmerSystem _glimmerSystem = default!;
|
|
[Dependency] private readonly IRobustRandom _robustRandom = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<PsionicsDisabledComponent, ComponentInit>(OnInit);
|
|
SubscribeLocalEvent<PsionicsDisabledComponent, ComponentShutdown>(OnShutdown);
|
|
SubscribeLocalEvent<PsionicComponent, PsionicPowerUsedEvent>(OnPowerUsed);
|
|
|
|
SubscribeLocalEvent<PsionicComponent, MobStateChangedEvent>(OnMobStateChanged);
|
|
}
|
|
|
|
private void OnPowerUsed(EntityUid uid, PsionicComponent component, PsionicPowerUsedEvent args)
|
|
{
|
|
foreach (var entity in _lookup.GetEntitiesInRange(uid, 10f))
|
|
{
|
|
if (HasComp<MetapsionicPowerComponent>(entity) && entity != uid && !(TryComp<PsionicInsulationComponent>(entity, out var insul) && !insul.Passthrough))
|
|
{
|
|
_popups.PopupEntity(Loc.GetString("metapsionic-pulse-power", ("power", args.Power)), entity, entity, PopupType.LargeCaution);
|
|
args.Handled = true;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnInit(EntityUid uid, PsionicsDisabledComponent component, ComponentInit args)
|
|
{
|
|
SetPsionicsThroughEligibility(uid);
|
|
}
|
|
|
|
private void OnShutdown(EntityUid uid, PsionicsDisabledComponent component, ComponentShutdown args)
|
|
{
|
|
SetPsionicsThroughEligibility(uid);
|
|
}
|
|
|
|
private void OnMobStateChanged(EntityUid uid, PsionicComponent component, MobStateChangedEvent args)
|
|
{
|
|
SetPsionicsThroughEligibility(uid);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Checks whether the entity is eligible to use its psionic ability. This should be run after anything that could effect psionic eligibility.
|
|
/// </summary>
|
|
public void SetPsionicsThroughEligibility(EntityUid uid)
|
|
{
|
|
PsionicComponent? component = null;
|
|
if (!Resolve(uid, ref component, false))
|
|
return;
|
|
|
|
if (component.PsionicAbility == null)
|
|
return;
|
|
|
|
_actions.TryGetActionData( component.PsionicAbility, out var actionData );
|
|
|
|
if (actionData == null)
|
|
return;
|
|
|
|
_actions.SetEnabled(actionData.Owner, IsEligibleForPsionics(uid));
|
|
}
|
|
|
|
private bool IsEligibleForPsionics(EntityUid uid)
|
|
{
|
|
return !HasComp<PsionicInsulationComponent>(uid)
|
|
&& (!TryComp<MobStateComponent>(uid, out var mobstate) || mobstate.CurrentState == MobState.Alive);
|
|
}
|
|
|
|
public void LogPowerUsed(EntityUid uid, string power, int minGlimmer = 8, int maxGlimmer = 12)
|
|
{
|
|
_adminLogger.Add(Database.LogType.Psionics, Database.LogImpact.Medium, $"{ToPrettyString(uid):player} used {power}");
|
|
var ev = new PsionicPowerUsedEvent(uid, power);
|
|
RaiseLocalEvent(uid, ev, false);
|
|
|
|
_glimmerSystem.Glimmer += _robustRandom.Next(minGlimmer, maxGlimmer);
|
|
}
|
|
}
|
|
|
|
public sealed class PsionicPowerUsedEvent : HandledEntityEventArgs
|
|
{
|
|
public EntityUid User { get; }
|
|
public string Power = string.Empty;
|
|
|
|
public PsionicPowerUsedEvent(EntityUid user, string power)
|
|
{
|
|
User = user;
|
|
Power = power;
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
[NetSerializable]
|
|
public sealed class PsionicsChangedEvent : EntityEventArgs
|
|
{
|
|
public readonly NetEntity Euid;
|
|
public PsionicsChangedEvent(NetEntity euid)
|
|
{
|
|
Euid = euid;
|
|
}
|
|
}
|
|
}
|