Skip to content

Commit

Permalink
Port PR130 changes directly
Browse files Browse the repository at this point in the history
  • Loading branch information
vaketola committed Nov 6, 2023
1 parent 530dcde commit 487d34b
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 46 deletions.
10 changes: 10 additions & 0 deletions Content.Server/Magic/Events/ISpeakSpell.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Content.Server.Magic.Events;

public interface ISpeakSpell // The speak n spell interface
{
/// <summary>
/// Localized string spoken by the caster when casting this spell.
/// </summary>
public string? Speech { get; }
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Content.Server.SimpleStation14.Species.Shadowkin.Events;
/// <summary>
/// Raised when the shadowkin teleport action is used.
/// </summary>
public sealed class ShadowkinTeleportEvent : WorldTargetActionEvent, ISpeakSpell
public sealed partial class ShadowkinTeleportEvent : WorldTargetActionEvent, ISpeakSpell
{
[DataField("sound")]
public SoundSpecifier Sound = new SoundPathSpecifier("/Audio/SimpleStation14/Effects/Shadowkin/Powers/teleport.ogg");
Expand All @@ -30,7 +30,7 @@ public sealed class ShadowkinTeleportEvent : WorldTargetActionEvent, ISpeakSpell
/// <summary>
/// Raised when the shadowkin darkSwap action is used.
/// </summary>
public sealed class ShadowkinDarkSwapEvent : InstantActionEvent, ISpeakSpell
public sealed partial class ShadowkinDarkSwapEvent : InstantActionEvent, ISpeakSpell
{
[DataField("soundOn")]
public SoundSpecifier SoundOn = new SoundPathSpecifier("/Audio/SimpleStation14/Effects/Shadowkin/Powers/darkswapon.ogg");
Expand Down Expand Up @@ -80,7 +80,7 @@ public sealed class ShadowkinDarkSwapAttemptEvent : CancellableEntityEventArgs
}


public sealed class ShadowkinRestEvent: InstantActionEvent
public sealed partial class ShadowkinRestEvent: InstantActionEvent
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Content.Shared.Actions;
using Content.Shared.Actions.ActionTypes;
using Content.Shared.CombatMode.Pacification;
using Content.Shared.Cuffs.Components;
using Content.Shared.Damage.Systems;
using Content.Shared.SimpleStation14.Species.Shadowkin.Components;
using Content.Shared.SimpleStation14.Species.Shadowkin.Events;
Expand All @@ -14,9 +15,7 @@
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.Prototypes;

namespace Content.Server.SimpleStation14.Species.Shadowkin.Systems;

public sealed class ShadowkinDarkSwapSystem : EntitySystem
{
[Dependency] private readonly ShadowkinPowerSystem _power = default!;
Expand All @@ -29,44 +28,38 @@ public sealed class ShadowkinDarkSwapSystem : EntitySystem
[Dependency] private readonly SharedActionsSystem _actions = default!;
[Dependency] private readonly IPrototypeManager _prototype = default!;
[Dependency] private readonly MagicSystem _magic = default!;

private InstantAction _action = default!;

public override void Initialize()
{
base.Initialize();

_action = new InstantAction(_prototype.Index<InstantActionPrototype>("ShadowkinDarkSwap"));

SubscribeLocalEvent<ShadowkinDarkSwapPowerComponent, ComponentStartup>(Startup);
SubscribeLocalEvent<ShadowkinDarkSwapPowerComponent, ComponentShutdown>(Shutdown);

SubscribeLocalEvent<ShadowkinDarkSwapPowerComponent, ShadowkinDarkSwapEvent>(DarkSwap);

SubscribeLocalEvent<ShadowkinDarkSwappedComponent, ComponentStartup>(OnInvisStartup);
SubscribeLocalEvent<ShadowkinDarkSwappedComponent, ComponentShutdown>(OnInvisShutdown);
}


private void Startup(EntityUid uid, ShadowkinDarkSwapPowerComponent component, ComponentStartup args)
{
_actions.AddAction(uid, _action, uid);
_actions.AddAction(uid, new InstantAction(_prototype.Index<InstantActionPrototype>("ShadowkinDarkSwap")), null);
}

private void Shutdown(EntityUid uid, ShadowkinDarkSwapPowerComponent component, ComponentShutdown args)
{
_actions.RemoveAction(uid, _action);
_actions.RemoveAction(uid, new InstantAction(_prototype.Index<InstantActionPrototype>("ShadowkinDarkSwap")));
}


private void DarkSwap(EntityUid uid, ShadowkinDarkSwapPowerComponent component, ShadowkinDarkSwapEvent args)
{
// Need power to drain power
if (!_entity.HasComponent<ShadowkinComponent>(args.Performer))
return;
// Don't activate abilities if handcuffed
// TODO: Something like the Psionic Headcage to disable powers for Shadowkin
if (_entity.HasComponent<HandcuffComponent>(args.Performer))
return;
var hasComp = _entity.HasComponent<ShadowkinDarkSwappedComponent>(args.Performer);

SetDarkened(
args.Performer,
!hasComp,
!hasComp,
!hasComp,
true,
args.StaminaCostOn,
args.PowerCostOn,
Expand All @@ -75,19 +68,16 @@ private void DarkSwap(EntityUid uid, ShadowkinDarkSwapPowerComponent component,
args.StaminaCostOff,
args.PowerCostOff,
args.SoundOff,
args.VolumeOff
args.VolumeOff,
args
);

_magic.Speak(args);

args.Handled = true;
_magic.Speak(args, false);
}


public void SetDarkened(
EntityUid performer,
bool addComp,
bool invisible,
bool pacify,
bool darken,
float staminaCostOn,
float powerCostOn,
Expand All @@ -96,86 +86,81 @@ public void SetDarkened(
float staminaCostOff,
float powerCostOff,
SoundSpecifier soundOff,
float volumeOff
float volumeOff,
ShadowkinDarkSwapEvent? args
)
{
var ev = new ShadowkinDarkSwapAttemptEvent();
var ev = new ShadowkinDarkSwapAttemptEvent(performer);
RaiseLocalEvent(ev);
if (ev.Cancelled)
return;

if (addComp)
{
var comp = _entity.EnsureComponent<ShadowkinDarkSwappedComponent>(performer);
comp.Invisible = invisible;
comp.Pacify = pacify;
comp.Darken = darken;

RaiseNetworkEvent(new ShadowkinDarkSwappedEvent(performer, true));

_audio.PlayPvs(soundOn, performer, AudioParams.Default.WithVolume(volumeOn));

_power.TryAddPowerLevel(performer, -powerCostOn);
_stamina.TakeStaminaDamage(performer, staminaCostOn);
}
else
{
_entity.RemoveComponent<ShadowkinDarkSwappedComponent>(performer);
RaiseNetworkEvent(new ShadowkinDarkSwappedEvent(performer, false));

_audio.PlayPvs(soundOff, performer, AudioParams.Default.WithVolume(volumeOff));

_power.TryAddPowerLevel(performer, -powerCostOff);
_stamina.TakeStaminaDamage(performer, staminaCostOff);
}
if (args != null)
args.Handled = true;
}


private void OnInvisStartup(EntityUid uid, ShadowkinDarkSwappedComponent component, ComponentStartup args)
{
EnsureComp<PacifiedComponent>(uid);
if (component.Pacify)
EnsureComp<PacifiedComponent>(uid);

if (component.Invisible)
SetCanSeeInvisibility(uid, true);
}

private void OnInvisShutdown(EntityUid uid, ShadowkinDarkSwappedComponent component, ComponentShutdown args)
{
RemComp<PacifiedComponent>(uid);

if (component.Invisible)
SetCanSeeInvisibility(uid, false);

component.Darken = false;

foreach (var light in component.DarkenedLights.ToArray())
{
if (!_entity.TryGetComponent<PointLightComponent>(light, out var pointLight) ||
!_entity.TryGetComponent<ShadowkinLightComponent>(light, out var shadowkinLight))
continue;

_darken.ResetLight(pointLight, shadowkinLight);
}

component.DarkenedLights.Clear();
}


public void SetCanSeeInvisibility(EntityUid uid, bool set)
{
var visibility = _entity.EnsureComponent<VisibilityComponent>(uid);
if (!TryComp<VisibilityComponent>(uid, out var visibility))
return;

if (set)
{
if (_entity.TryGetComponent(uid, out EyeComponent? eye))
{
eye.VisibilityMask |= (uint) VisibilityFlags.DarkSwapInvisibility;
}

_visibility.AddLayer(uid, visibility, (int) VisibilityFlags.DarkSwapInvisibility, false);
_visibility.RemoveLayer(uid, visibility, (int) VisibilityFlags.Normal, false);
_visibility.RefreshVisibility(uid);

if (!_entity.TryGetComponent<GhostComponent>(uid, out var _))
if (!_entity.TryGetComponent<GhostComponent>(uid, out _))
_stealth.SetVisibility(uid, 0.8f, _entity.EnsureComponent<StealthComponent>(uid));
}
else
Expand All @@ -184,12 +169,12 @@ public void SetCanSeeInvisibility(EntityUid uid, bool set)
{
eye.VisibilityMask &= ~(uint) VisibilityFlags.DarkSwapInvisibility;
}

_visibility.RemoveLayer(uid, visibility, (int) VisibilityFlags.DarkSwapInvisibility, false);
_visibility.AddLayer(uid, visibility, (int) VisibilityFlags.Normal, false);
_visibility.RefreshVisibility(uid);

if (!_entity.TryGetComponent<GhostComponent>(uid, out var _))
if (!_entity.TryGetComponent<GhostComponent>(uid, out _))
_entity.RemoveComponent<StealthComponent>(uid);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ public sealed partial class ShadowkinDarkSwappedComponent : Component
[DataField("invisible")]
public bool Invisible = true;

/// <summary>
/// If it should be pacified
/// </summary>
[DataField("pacify")]
public bool Pacify = true;

/// <summary>
/// If it should dim nearby lights
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
sounds:
Male: MaleSlime
Female: FemaleSlime
Unsexed: UnisexSlime
Unsexed: MaleSlime
- type: CombatMode
canDisarm: true
- type: MindContainer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
components:
- type: ShadowkinDarkSwapped
invisible: false
pacify: false
darken: true
range: 4
- type: Sprite
Expand Down

0 comments on commit 487d34b

Please sign in to comment.