Skip to content

Commit

Permalink
Revert "Add some shadowkin improvements progress"
Browse files Browse the repository at this point in the history
This reverts commit a9c37e6.
  • Loading branch information
vaketola committed Nov 7, 2023
1 parent ad29f04 commit 3da460f
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 224 deletions.
Original file line number Diff line number Diff line change
@@ -1,51 +1,7 @@
using Content.Server.NPC.Components;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;

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

[RegisterComponent]
public sealed partial class ShadowkinDarkSwapPowerComponent : Component
{
public EntityUid? ActionShadowkinDarkSwap { get; set; }

/// <summary>
/// Factions temporarily deleted from the entity while swapped
/// </summary>
public List<string> SuppressedFactions = new();
/// <summary>
/// Factions temporarily added to the entity while swapped
/// </summary>
[DataField("factions", customTypeSerializer: typeof(PrototypeIdListSerializer<NpcFactionPrototype>))]
public List<string> AddedFactions = new() { "ShadowkinDarkFriendly" };

/// <summary>
/// If the entity should be sent to the dark
/// </summary>
[DataField("invisible")]
public bool Invisible = true;

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

/// <summary>
/// If the entity should dim nearby lights when swapped
/// </summary>
[DataField("darken"), ViewVariables(VVAccess.ReadWrite)]
public bool Darken = true;

/// <summary>
/// How far to dim nearby lights
/// </summary>
[DataField("range"), ViewVariables(VVAccess.ReadWrite)]
public float DarkenRange = 5f;

/// <summary>
/// How fast to refresh nearby light dimming in seconds
/// Without this performance would be significantly worse
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public float DarkenRate = 0.084f; // 1/12th of a second
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public sealed partial class ShadowkinDarkSwapEvent : InstantActionEvent, ISpeakS

public sealed class ShadowkinDarkSwapAttemptEvent : CancellableEntityEventArgs
{
public EntityUid Performer;
EntityUid Performer;

public ShadowkinDarkSwapAttemptEvent(EntityUid performer)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using System.Linq;
using Content.Server.Ghost.Components;
using Content.Server.Ghost.Components;
using Content.Server.Magic;
using Content.Server.SimpleStation14.Species.Shadowkin.Components;
using Content.Server.SimpleStation14.Species.Shadowkin.Events;
using Content.Server.Visible;
using Content.Server.NPC.Systems;
using Content.Server.NPC.Components;
using Content.Shared.Actions;
using Content.Shared.CombatMode.Pacification;
using Content.Shared.Cuffs.Components;
Expand All @@ -19,7 +16,6 @@
using Robust.Shared.Audio;
using Robust.Shared.Prototypes;


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

public sealed class ShadowkinDarkSwapSystem : EntitySystem
Expand All @@ -34,7 +30,6 @@ public sealed class ShadowkinDarkSwapSystem : EntitySystem
[Dependency] private readonly SharedActionsSystem _actions = default!;
[Dependency] private readonly IPrototypeManager _prototype = default!;
[Dependency] private readonly MagicSystem _magic = default!;
[Dependency] private readonly NpcFactionSystem _factions = default!;

public override void Initialize()
{
Expand All @@ -49,10 +44,12 @@ public override void Initialize()
SubscribeLocalEvent<ShadowkinDarkSwappedComponent, ComponentShutdown>(OnInvisShutdown);
}


private void Startup(EntityUid uid, ShadowkinDarkSwapPowerComponent component, ComponentStartup args)
{
var componentActionShadowkinDarkSwap = component.ActionShadowkinDarkSwap;
_actions.AddAction(uid, ref componentActionShadowkinDarkSwap, "ActionShadowkinDarkSwap");
// _actions.AddAction(uid, "ActionShadowkinDarkSwap");
}

private void Shutdown(EntityUid uid, ShadowkinDarkSwapPowerComponent component, ComponentShutdown args)
Expand All @@ -67,239 +64,124 @@ private void DarkSwap(EntityUid uid, ShadowkinDarkSwapPowerComponent component,
if (!_entity.HasComponent<ShadowkinComponent>(args.Performer))
return;

// Don't activate abilities if specially handcuffed
if (_entity.TryGetComponent<HandcuffComponent>(args.Performer, out var cuffs) && cuffs.AntiShadowkin)
// 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,
!_entity.HasComponent<ShadowkinDarkSwappedComponent>(args.Performer),
!hasComp,
!hasComp,
true,
args.StaminaCostOn,
args.PowerCostOn,
args.SoundOn,
args.VolumeOn,
args.StaminaCostOff,
args.PowerCostOff,
args.SoundOff,
args.VolumeOff,
args,
args.StaminaCostOn,
args.PowerCostOn,
args.StaminaCostOff,
args.PowerCostOff
args
);

_magic.Speak(args, false);
}


/// <summary>
/// Handles the effects of darkswapping
/// </summary>
/// <param name="performer">The entity being modified</param>
/// <param name="addComp">Is the entity swapping in to or out of The Dark?</param>
/// <param name="soundOn">Sound for the darkswapping</param>
/// <param name="volumeOn">Volume for the on sound</param>
/// <param name="soundOff">Sound for the un swapping</param>
/// <param name="volumeOff">Volume for the off sound</param>
/// <param name="staminaCostOn">Stamina cost for darkswapping</param>
/// <param name="powerCostOn">Power cost for darkswapping</param>
/// <param name="staminaCostOff">Stamina cost for un swapping</param>
/// <param name="powerCostOff">Power cost for un swapping</param>
/// <param name="args">If from an event, handle it</param>
public void SetDarkened(
EntityUid performer,
bool addComp,
SoundSpecifier? soundOn,
float? volumeOn,
SoundSpecifier? soundOff,
float? volumeOff,
ShadowkinDarkSwapEvent? args,
float staminaCostOn = 0,
float powerCostOn = 0,
float staminaCostOff = 0,
float powerCostOff = 0
bool invisible,
bool darken,
float staminaCostOn,
float powerCostOn,
SoundSpecifier soundOn,
float volumeOn,
float staminaCostOff,
float powerCostOff,
SoundSpecifier soundOff,
float volumeOff,
ShadowkinDarkSwapEvent? args
)
{
// Ask other systems if we can DarkSwap
var ev = new ShadowkinDarkSwapAttemptEvent(performer);
RaiseLocalEvent(ev);
if (ev.Cancelled)
return;

// We require the power component to DarkSwap
if (!_entity.TryGetComponent<ShadowkinDarkSwapPowerComponent>(performer, out var power))
return;

if (addComp) // Into The Dark
if (addComp)
{
// Add the DarkSwapped component and set variables to match the power component
var comp = _entity.EnsureComponent<ShadowkinDarkSwappedComponent>(performer);
comp.Invisible = power.Invisible;
comp.Pacify = power.Pacify;
comp.Darken = power.Darken;
comp.DarkenRange = power.DarkenRange;
comp.DarkenRate = power.DarkenRate;

// Tell other systems we've DarkSwapped
comp.Invisible = invisible;
comp.Darken = darken;
RaiseNetworkEvent(new ShadowkinDarkSwappedEvent(performer, true));

// Play a sound if we have one
if (soundOn != null)
_audio.PlayPvs(soundOn, performer, AudioParams.Default.WithVolume(volumeOn ?? 5f));

// Drain power and stamina if we have a cost
_audio.PlayPvs(soundOn, performer, AudioParams.Default.WithVolume(volumeOn));
_power.TryAddPowerLevel(performer, -powerCostOn);
_stamina.TakeStaminaDamage(performer, staminaCostOn);
}
else // Out of The Dark
else
{
// Remove the DarkSwapped component, the rest is handled in the shutdown event
_entity.RemoveComponent<ShadowkinDarkSwappedComponent>(performer);

// Tell other systems we've un DarkSwapped
RaiseNetworkEvent(new ShadowkinDarkSwappedEvent(performer, false));

// Play a sound if we have one
if (soundOff != null)
_audio.PlayPvs(soundOff, performer, AudioParams.Default.WithVolume(volumeOff ?? 5f));

// Drain power and stamina if we have a cost
_audio.PlayPvs(soundOff, performer, AudioParams.Default.WithVolume(volumeOff));
_power.TryAddPowerLevel(performer, -powerCostOff);
_stamina.TakeStaminaDamage(performer, staminaCostOff);
}

// If we have an event, mark it as handled
if (args != null)
args.Handled = true;
}


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

EnsureComp<PacifiedComponent>(uid);
if (component.Invisible)
{
SetVisibility(uid, true, true, true);
SuppressFactions(uid, true);
}
SetCanSeeInvisibility(uid, true);
}

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

if (component.Invisible)
{
SetVisibility(uid, false, false, false);
SuppressFactions(uid, false);
}

// Prevent more updates while we're cleaning up
SetCanSeeInvisibility(uid, false);
component.Darken = false;

// In case more updates occur for some reason, create a copy of the list to prevent error
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);
}

// Clear the original array
component.DarkenedLights.Clear();
}

// Commented out eye and ghost stuff until ported
/// <summary>
/// Makes the specified entity able to see Shadowkin invisibility.
/// </summary>
/// <param name="uid">Entity to modify</param>
/// <param name="set">Whether the entity can see invisibility</param>
/// <param name="invisibility">Should the entity be moved to another visibility layer?</param>
/// <param name="stealth">(Only gets considered if set is true) Adds stealth to the entity</param>
public void SetVisibility(EntityUid uid, bool set, bool invisibility, bool stealth)
public void SetCanSeeInvisibility(EntityUid uid, bool set)
{
// We require the visibility component for this to work
var visibility = _entity.EnsureComponent<VisibilityComponent>(uid);

if (set) // Invisible
if (set)
{
// Allow the entity to see DarkSwapped entities
/*if (_entity.TryGetComponent(uid, out EyeComponent? eye))
eye.VisibilityMask |= (uint) VisibilityFlags.DarkSwapInvisibility;*/

// Make other entities unable to see the entity unless also DarkSwapped
if (invisibility)
{
_visibility.AddLayer(uid, visibility, (int) VisibilityFlags.DarkSwapInvisibility, false);
_visibility.RemoveLayer(uid, visibility, (int) VisibilityFlags.Normal, false);
}
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 not a ghost, add a stealth shader to the entity
if (!_entity.TryGetComponent<GhostComponent>(uid, out _) && stealth)
if (!_entity.TryGetComponent<GhostComponent>(uid, out var _))
_stealth.SetVisibility(uid, 0.8f, _entity.EnsureComponent<StealthComponent>(uid));
}
else // Visible
else
{
// Remove the ability to see DarkSwapped entities
/*if (_entity.TryGetComponent(uid, out EyeComponent? eye))
eye.VisibilityMask &= ~(uint) VisibilityFlags.DarkSwapInvisibility;*/

// Make other entities able to see the entity again
if (invisibility)
{
_visibility.RemoveLayer(uid, visibility, (int) VisibilityFlags.DarkSwapInvisibility, false);
_visibility.AddLayer(uid, visibility, (int) VisibilityFlags.Normal, false);
}
// eye.VisibilityMask &= ~(uint) VisibilityFlags.DarkSwapInvisibility;
}*/
_visibility.RemoveLayer(uid, visibility, (int) VisibilityFlags.DarkSwapInvisibility, false);
_visibility.AddLayer(uid, visibility, (int) VisibilityFlags.Normal, false);
_visibility.RefreshVisibility(uid);

// Remove the stealth shader from the entity
if (!_entity.TryGetComponent<GhostComponent>(uid, out _))
_stealth.SetEnabled(uid, false);
}
}

/// <summary>
/// Remove existing factions on the entity and move them to the power component to add back when removed from The Dark
/// </summary>
/// <param name="uid">Entity to modify factions for</param>
/// <param name="set">Add or remove the factions</param>
public void SuppressFactions(EntityUid uid, bool set)
{
// We require the power component to keep track of the factions
if (!_entity.TryGetComponent<ShadowkinDarkSwapPowerComponent>(uid, out var component))
return;

if (set)
{
if (!_entity.TryGetComponent<NpcFactionMemberComponent>(uid, out var factions))
return;

// Copy the suppressed factions to the power component
component.SuppressedFactions = factions.Factions.ToList();

// Remove the factions from the entity
foreach (var faction in factions.Factions)
_factions.RemoveFaction(uid, faction);

// Add status factions for The Dark to the entity
foreach (var faction in component.AddedFactions)
_factions.AddFaction(uid, faction);
}
else
{
// Remove the status factions from the entity
foreach (var faction in component.AddedFactions)
_factions.RemoveFaction(uid, faction);

// Add the factions back to the entity
foreach (var faction in component.SuppressedFactions)
_factions.AddFaction(uid, faction);

component.SuppressedFactions.Clear();
if (!_entity.TryGetComponent<GhostComponent>(uid, out var _))
_entity.RemoveComponent<StealthComponent>(uid);
}
}
}
Loading

0 comments on commit 3da460f

Please sign in to comment.