Skip to content

Commit

Permalink
I accidentally sent the DeltaV legacy version of these
Browse files Browse the repository at this point in the history
  • Loading branch information
VMSolidus committed May 3, 2024
1 parent 1566ee5 commit c832f5f
Show file tree
Hide file tree
Showing 10 changed files with 469 additions and 256 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
using Content.Shared.Actions;
using Content.Shared.Actions.ActionTypes;
using Content.Shared.StatusEffect;
using Content.Shared.Abilities.Psionics;
using Content.Shared.Damage;
using Content.Shared.Revenant.Components;
using Content.Server.Guardian;
using Content.Server.Bible.Components;
using Content.Server.Popups;
using Robust.Shared.Prototypes;
using Robust.Shared.Player;
using Robust.Shared.Random;
using Robust.Shared.Timing;
using Content.Shared.Actions.Events;
using Robust.Shared.Audio.Systems;

namespace Content.Server.Abilities.Psionics
{
public sealed class DispelPowerSystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly StatusEffectsSystem _statusEffects = default!;
[Dependency] private readonly SharedActionsSystem _actions = default!;
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
Expand All @@ -25,7 +23,6 @@ public sealed class DispelPowerSystem : EntitySystem
[Dependency] private readonly SharedPsionicAbilitiesSystem _psionics = default!;
[Dependency] private readonly SharedAudioSystem _audioSystem = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;


public override void Initialize()
Expand All @@ -45,36 +42,46 @@ public override void Initialize()

private void OnInit(EntityUid uid, DispelPowerComponent component, ComponentInit args)
{
if (!_prototypeManager.TryIndex<EntityTargetActionPrototype>("Dispel", out var action))
return;

component.DispelPowerAction = new EntityTargetAction(action);
if (action.UseDelay != null)
component.DispelPowerAction.Cooldown = (_gameTiming.CurTime, _gameTiming.CurTime + (TimeSpan) action.UseDelay);
_actions.AddAction(uid, component.DispelPowerAction, null);

if (TryComp<PsionicComponent>(uid, out var psionic) && psionic.PsionicAbility == null)
psionic.PsionicAbility = component.DispelPowerAction;
_actions.AddAction(uid, ref component.DispelActionEntity, component.DispelActionId );
_actions.TryGetActionData( component.DispelActionEntity, out var actionData );
if (actionData is { UseDelay: not null })
_actions.StartUseDelay(component.DispelActionEntity);
if (TryComp<PsionicComponent>(uid, out var psionic))
{
psionic.ActivePowers.Add(component);
psionic.PsychicFeedback.Add(component.DispelFeedback);
//It's fully intended that Dispel doesn't increase Amplification, and instead heavily spikes Dampening
//Antimage archetype.
psionic.Dampening += 1f;
}
}

private void OnShutdown(EntityUid uid, DispelPowerComponent component, ComponentShutdown args)
{
if (_prototypeManager.TryIndex<EntityTargetActionPrototype>("Dispel", out var action))
_actions.RemoveAction(uid, new EntityTargetAction(action), null);
_actions.RemoveAction(uid, component.DispelActionEntity);

if (TryComp<PsionicComponent>(uid, out var psionic))
{
psionic.ActivePowers.Remove(component);
psionic.PsychicFeedback.Remove(component.DispelFeedback);
psionic.Dampening -= 1f;
}
}

private void OnPowerUsed(DispelPowerActionEvent args)
{
if (HasComp<PsionicInsulationComponent>(args.Target))
return;
if (!TryComp<PsionicComponent>(args.Performer, out var psionic) || !HasComp<PsionicComponent>(args.Target))
return;

var ev = new DispelledEvent();
RaiseLocalEvent(args.Target, ev, false);

if (ev.Handled)
{
args.Handled = true;
_psionics.LogPowerUsed(args.Performer, "dispel");
_psionics.LogPowerUsed(args.Performer, "dispel", (int) MathF.Round(psionic.Dampening * -2), (int) MathF.Round(psionic.Dampening * -4));
}
}

Expand All @@ -83,14 +90,14 @@ private void OnDispelled(EntityUid uid, DispellableComponent component, Dispelle
QueueDel(uid);
Spawn("Ash", Transform(uid).Coordinates);
_popupSystem.PopupCoordinates(Loc.GetString("psionic-burns-up", ("item", uid)), Transform(uid).Coordinates, Filter.Pvs(uid), true, Shared.Popups.PopupType.MediumCaution);
_audioSystem.Play("/Audio/Effects/lightburn.ogg", Filter.Pvs(uid), uid, true);
_audioSystem.PlayEntity("/Audio/Effects/lightburn.ogg", Filter.Pvs(uid), uid, true);
args.Handled = true;
}

private void OnDmgDispelled(EntityUid uid, DamageOnDispelComponent component, DispelledEvent args)
{
var damage = component.Damage;
var modifier = (1 + component.Variance) - (_random.NextFloat(0, component.Variance * 2));
var modifier = 1 + component.Variance - _random.NextFloat(0, component.Variance * 2);

damage *= modifier;
DealDispelDamage(uid, damage);
Expand All @@ -100,7 +107,7 @@ private void OnDmgDispelled(EntityUid uid, DamageOnDispelComponent component, Di
private void OnGuardianDispelled(EntityUid uid, GuardianComponent guardian, DispelledEvent args)
{
if (TryComp<GuardianHostComponent>(guardian.Host, out var host))
_guardianSystem.ToggleGuardian(guardian.Host, host);
_guardianSystem.ToggleGuardian(guardian.Host.Value, host);

DealDispelDamage(uid);
args.Handled = true;
Expand All @@ -127,7 +134,7 @@ public void DealDispelDamage(EntityUid uid, DamageSpecifier? damage = null)
return;

_popupSystem.PopupCoordinates(Loc.GetString("psionic-burn-resist", ("item", uid)), Transform(uid).Coordinates, Filter.Pvs(uid), true, Shared.Popups.PopupType.SmallCaution);
_audioSystem.Play("/Audio/Effects/lightburn.ogg", Filter.Pvs(uid), uid, true);
_audioSystem.PlayEntity("/Audio/Effects/lightburn.ogg", Filter.Pvs(uid), uid, true);

if (damage == null)
{
Expand All @@ -137,8 +144,5 @@ public void DealDispelDamage(EntityUid uid, DamageSpecifier? damage = null)
_damageableSystem.TryChangeDamage(uid, damage, true, true);
}
}

public sealed class DispelPowerActionEvent : EntityTargetActionEvent {}

public sealed class DispelledEvent : HandledEntityEventArgs {}
}
Original file line number Diff line number Diff line change
@@ -1,55 +1,90 @@
using Content.Shared.Actions;
using Content.Shared.Actions.ActionTypes;
using Content.Shared.Actions.Events;
using Content.Shared.Abilities.Psionics;
using Content.Shared.StatusEffect;
using Content.Shared.DoAfter;
using Content.Shared.Examine;
using static Content.Shared.Examine.ExamineSystemShared;
using Content.Shared.Popups;
using Robust.Shared.Prototypes;
using Robust.Shared.Player;
using Robust.Server.Audio;
using Robust.Shared.Audio;
using Robust.Shared.Timing;
using Robust.Shared.Player;
using Content.Server.DoAfter;
using Content.Shared.Psionics.Events;
using Content.Server.Psionics;

namespace Content.Server.Abilities.Psionics
{
public sealed class MetapsionicPowerSystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly StatusEffectsSystem _statusEffects = default!;
[Dependency] private readonly SharedActionsSystem _actions = default!;
[Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly SharedPopupSystem _popups = default!;
[Dependency] private readonly SharedPsionicAbilitiesSystem _psionics = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly DoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly AudioSystem _audioSystem = default!;


public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<MetapsionicPowerComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<MetapsionicPowerComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<MetapsionicPowerComponent, MetapsionicPowerActionEvent>(OnPowerUsed);
SubscribeLocalEvent<MetapsionicPowerComponent, WideMetapsionicPowerActionEvent>(OnWidePowerUsed);
SubscribeLocalEvent<FocusedMetapsionicPowerActionEvent>(OnFocusedPowerUsed);
SubscribeLocalEvent<MetapsionicPowerComponent, FocusedMetapsionicDoAfterEvent>(OnDoAfter);
}

private void OnInit(EntityUid uid, MetapsionicPowerComponent component, ComponentInit args)
{
if (!_prototypeManager.TryIndex<InstantActionPrototype>("MetapsionicPulse", out var metapsionicPulse))
if (!TryComp(uid, out ActionsComponent? comp))
return;
_actions.AddAction(uid, ref component.ActionWideMetapsionicEntity, component.ActionWideMetapsionic, component: comp);
_actions.AddAction(uid, ref component.ActionFocusedMetapsionicEntity, component.ActionFocusedMetapsionic, component: comp);
_actions.TryGetActionData(component.ActionWideMetapsionicEntity, out var actionData);
if (actionData is { UseDelay: not null })
{
_actions.StartUseDelay(component.ActionWideMetapsionicEntity);
_actions.StartUseDelay(component.ActionFocusedMetapsionicEntity);
}
if (TryComp<PsionicComponent>(uid, out var psionic))
{
psionic.ActivePowers.Add(component);
psionic.PsychicFeedback.Add(component.MetapsionicFeedback);
psionic.Amplification += 0.1f;
psionic.Dampening += 0.5f;
}

component.MetapsionicPowerAction = new InstantAction(metapsionicPulse);
if (metapsionicPulse.UseDelay != null)
component.MetapsionicPowerAction.Cooldown = (_gameTiming.CurTime, _gameTiming.CurTime + (TimeSpan) metapsionicPulse.UseDelay);
_actions.AddAction(uid, component.MetapsionicPowerAction, null);
}

if (TryComp<PsionicComponent>(uid, out var psionic) && psionic.PsionicAbility == null)
psionic.PsionicAbility = component.MetapsionicPowerAction;
private void UpdateActions(EntityUid uid, MetapsionicPowerComponent? component = null)
{
if (!Resolve(uid, ref component))
return;
_actions.StartUseDelay(component.ActionWideMetapsionicEntity);
_actions.StartUseDelay(component.ActionFocusedMetapsionicEntity);
}

private void OnShutdown(EntityUid uid, MetapsionicPowerComponent component, ComponentShutdown args)
{
if (_prototypeManager.TryIndex<InstantActionPrototype>("MetapsionicPulse", out var metapsionicPulse))
_actions.RemoveAction(uid, new InstantAction(metapsionicPulse), null);
_actions.RemoveAction(uid, component.ActionWideMetapsionicEntity);
_actions.RemoveAction(uid, component.ActionFocusedMetapsionicEntity);

if (TryComp<PsionicComponent>(uid, out var psionic))
{
psionic.ActivePowers.Remove(component);
psionic.PsychicFeedback.Remove(component.MetapsionicFeedback);
psionic.Amplification -= 0.1f;
psionic.Dampening -= 0.5f;
}
}

private void OnPowerUsed(EntityUid uid, MetapsionicPowerComponent component, MetapsionicPowerActionEvent args)
private void OnWidePowerUsed(EntityUid uid, MetapsionicPowerComponent component, WideMetapsionicPowerActionEvent args)
{
if (!TryComp<PsionicComponent>(uid, out var psionic))
return;

foreach (var entity in _lookup.GetEntitiesInRange(uid, component.Range))
{
if (HasComp<PsionicComponent>(entity) && entity != uid && !HasComp<PsionicInsulationComponent>(entity) &&
Expand All @@ -61,11 +96,80 @@ private void OnPowerUsed(EntityUid uid, MetapsionicPowerComponent component, Met
}
}
_popups.PopupEntity(Loc.GetString("metapsionic-pulse-failure"), uid, uid, PopupType.Large);
_psionics.LogPowerUsed(uid, "metapsionic pulse", 2, 4);
_psionics.LogPowerUsed(uid, "metapsionic pulse", (int) MathF.Round(psionic.Amplification / psionic.Dampening * 2), (int) MathF.Round(psionic.Amplification / psionic.Dampening * 4));
UpdateActions(uid, component);
args.Handled = true;
}

private void OnFocusedPowerUsed(FocusedMetapsionicPowerActionEvent args)
{
if (!TryComp<PsionicComponent>(args.Performer, out var psionic))
return;

if (HasComp<PsionicInsulationComponent>(args.Target))
return;

if (!TryComp<MetapsionicPowerComponent>(args.Performer, out var component))
return;

var ev = new FocusedMetapsionicDoAfterEvent(_gameTiming.CurTime);

_doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager, args.Performer, component.UseDelay, ev, args.Performer, args.Target, args.Performer)
{
BlockDuplicate = true,
BreakOnUserMove = true,
BreakOnTargetMove = true,
BreakOnDamage = true,
}, out var doAfterId);

component.DoAfter = doAfterId;

_popups.PopupEntity(Loc.GetString("focused-metapsionic-pulse-begin", ("entity", args.Performer)),
args.Performer,
// TODO: Use LoS-based Filter when one is available.
Filter.Pvs(args.Performer).RemoveWhereAttachedEntity(entity => !ExamineSystemShared.InRangeUnOccluded(args.Performer, entity, ExamineRange, null)),
true,
PopupType.Medium);

_audioSystem.PlayPvs(component.SoundUse, component.Owner, AudioParams.Default.WithVolume(8f).WithMaxDistance(1.5f).WithRolloffFactor(3.5f));
_psionics.LogPowerUsed(args.Performer, "focused metapsionic pulse", (int) MathF.Round(psionic.Amplification / psionic.Dampening * 3), (int) MathF.Round(psionic.Amplification / psionic.Dampening * 6));
args.Handled = true;

UpdateActions(args.Performer, component);
}
}

public sealed class MetapsionicPowerActionEvent : InstantActionEvent {}
private void OnDoAfter(EntityUid uid, MetapsionicPowerComponent component, FocusedMetapsionicDoAfterEvent args)
{
if (!TryComp<PsionicComponent>(args.Target, out var psychic))
return;

component.DoAfter = null;

if (args.Target == null) return;

if (args.Target == uid)
{
_popups.PopupEntity(Loc.GetString("metapulse-self", ("entity", args.Target)), uid, uid, PopupType.LargeCaution);
return;
}

if (!HasComp<PotentialPsionicComponent>(args.Target))
{
_popups.PopupEntity(Loc.GetString("no-powers", ("entity", args.Target)), uid, uid, PopupType.LargeCaution);
return;
}

if (HasComp<PotentialPsionicComponent>(args.Target) & !HasComp<PsionicComponent>(args.Target))
{
_popups.PopupEntity(Loc.GetString("psychic-potential", ("entity", args.Target)), uid, uid, PopupType.LargeCaution);
return;
}

foreach (var psychicFeedback in psychic.PsychicFeedback)
{
_popups.PopupEntity(Loc.GetString(psychicFeedback, ("entity", args.Target)), uid, uid, PopupType.LargeCaution);
}

}
}
}
Loading

0 comments on commit c832f5f

Please sign in to comment.