From 74ecef69e832167c453d405a7c5490e372ee1fdd Mon Sep 17 00:00:00 2001 From: DEATHB4DEFEAT Date: Fri, 13 Oct 2023 17:56:17 -0700 Subject: [PATCH] fix Shadowkin Dark visibility --- .../SimpleStation14/Eye/EyeStartup.cs | 2 +- .../ShadowkinDarkSwapPowerComponent.cs | 12 ++++ .../Systems/ShadowkinPowerSystem.DarkSwap.cs | 63 ++++++++++++++++--- .../ShadowkinDarkSwappedComponent.cs | 1 + .../Prototypes/SimpleStation14/factions.yml | 9 +++ 5 files changed, 76 insertions(+), 11 deletions(-) create mode 100644 Resources/Prototypes/SimpleStation14/factions.yml diff --git a/Content.Server/SimpleStation14/Eye/EyeStartup.cs b/Content.Server/SimpleStation14/Eye/EyeStartup.cs index 4691b8d37f..5e0fffe9f5 100644 --- a/Content.Server/SimpleStation14/Eye/EyeStartup.cs +++ b/Content.Server/SimpleStation14/Eye/EyeStartup.cs @@ -25,7 +25,7 @@ private void OnEyeStartup(EntityUid uid, EyeComponent component, ComponentStartu if (_entityManager.HasComponent(uid)) component.VisibilityMask |= (uint) VisibilityFlags.AIEye; - _shadowkinPowerSystem.SetCanSeeInvisibility(uid, _entityManager.HasComponent(uid)); + _shadowkinPowerSystem.SetVisibility(uid, _entityManager.HasComponent(uid)); } } } diff --git a/Content.Server/SimpleStation14/Species/Shadowkin/Components/ShadowkinDarkSwapPowerComponent.cs b/Content.Server/SimpleStation14/Species/Shadowkin/Components/ShadowkinDarkSwapPowerComponent.cs index c53326b5e7..7438609cc0 100644 --- a/Content.Server/SimpleStation14/Species/Shadowkin/Components/ShadowkinDarkSwapPowerComponent.cs +++ b/Content.Server/SimpleStation14/Species/Shadowkin/Components/ShadowkinDarkSwapPowerComponent.cs @@ -1,7 +1,19 @@ +using Content.Server.NPC.Components; +using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List; + namespace Content.Server.SimpleStation14.Species.Shadowkin.Components; [RegisterComponent] public sealed class ShadowkinDarkSwapPowerComponent : Component { + /// + /// Factions temporarily deleted from the entity while swapped + /// + public List SuppressedFactions = new(); + /// + /// Factions temporarily added to the entity while swapped + /// + [DataField("factions", customTypeSerializer: typeof(PrototypeIdListSerializer))] + public List AddedFactions = new() { "ShadowkinDarkFriendly" }; } diff --git a/Content.Server/SimpleStation14/Species/Shadowkin/Systems/ShadowkinPowerSystem.DarkSwap.cs b/Content.Server/SimpleStation14/Species/Shadowkin/Systems/ShadowkinPowerSystem.DarkSwap.cs index 7ba38ca5ea..1ce14583ef 100644 --- a/Content.Server/SimpleStation14/Species/Shadowkin/Systems/ShadowkinPowerSystem.DarkSwap.cs +++ b/Content.Server/SimpleStation14/Species/Shadowkin/Systems/ShadowkinPowerSystem.DarkSwap.cs @@ -1,5 +1,8 @@ +using System.Linq; using Content.Server.Ghost.Components; using Content.Server.Magic; +using Content.Server.NPC.Components; +using Content.Server.NPC.Systems; using Content.Server.SimpleStation14.Species.Shadowkin.Components; using Content.Server.SimpleStation14.Species.Shadowkin.Events; using Content.Server.Visible; @@ -30,6 +33,7 @@ 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() { @@ -149,7 +153,10 @@ private void OnInvisStartup(EntityUid uid, ShadowkinDarkSwappedComponent compone EnsureComp(uid); if (component.Invisible) - SetCanSeeInvisibility(uid, true); + { + SetVisibility(uid, true); + SuppressFactions(uid, true); + } } private void OnInvisShutdown(EntityUid uid, ShadowkinDarkSwappedComponent component, ComponentShutdown args) @@ -157,7 +164,10 @@ private void OnInvisShutdown(EntityUid uid, ShadowkinDarkSwappedComponent compon RemComp(uid); if (component.Invisible) - SetCanSeeInvisibility(uid, false); + { + SetVisibility(uid, false); + SuppressFactions(uid, false); + } component.Darken = false; @@ -174,17 +184,14 @@ private void OnInvisShutdown(EntityUid uid, ShadowkinDarkSwappedComponent compon } - public void SetCanSeeInvisibility(EntityUid uid, bool set) + public void SetVisibility(EntityUid uid, bool set) { - if (!TryComp(uid, out var visibility)) - return; + var visibility = EnsureComp(uid); 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); @@ -196,16 +203,52 @@ public void SetCanSeeInvisibility(EntityUid uid, bool set) else { if (_entity.TryGetComponent(uid, out EyeComponent? eye)) - { 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(uid, out _)) - _entity.RemoveComponent(uid); + _stealth.SetVisibility(uid, 1f, _entity.EnsureComponent(uid)); + } + } + + /// + /// Remove existing factions on the entity and move them to the power component to add back when removed from The Dark + /// + /// Entity to modify factions for + /// Add or remove the factions + public void SuppressFactions(EntityUid uid, bool set) + { + if (!_entity.TryGetComponent(uid, out var component)) + return; + + if (set) + { + if (_entity.TryGetComponent(uid, out var factions)) + { + component.SuppressedFactions = factions.Factions.ToList(); + + foreach (var faction in factions.Factions) + _factions.RemoveFaction(uid, faction); + + foreach (var faction in component.AddedFactions) + _factions.AddFaction(uid, faction); + } + } + else + { + if (!component.SuppressedFactions.Any()) + return; + + foreach (var faction in component.SuppressedFactions) + _factions.AddFaction(uid, faction); + + foreach (var faction in component.AddedFactions) + _factions.RemoveFaction(uid, faction); + + component.SuppressedFactions.Clear(); } } } diff --git a/Content.Shared/SimpleStation14/Species/Shadowkin/Components/ShadowkinDarkSwappedComponent.cs b/Content.Shared/SimpleStation14/Species/Shadowkin/Components/ShadowkinDarkSwappedComponent.cs index 4c93bbc496..22bb0b52b3 100644 --- a/Content.Shared/SimpleStation14/Species/Shadowkin/Components/ShadowkinDarkSwappedComponent.cs +++ b/Content.Shared/SimpleStation14/Species/Shadowkin/Components/ShadowkinDarkSwappedComponent.cs @@ -23,6 +23,7 @@ public sealed class ShadowkinDarkSwappedComponent : Component [DataField("darken"), ViewVariables(VVAccess.ReadWrite)] public bool Darken = true; + /// /// How far to dim nearby lights /// diff --git a/Resources/Prototypes/SimpleStation14/factions.yml b/Resources/Prototypes/SimpleStation14/factions.yml new file mode 100644 index 0000000000..28871238b0 --- /dev/null +++ b/Resources/Prototypes/SimpleStation14/factions.yml @@ -0,0 +1,9 @@ +- type: npcFaction + id: ShadowkinDarkHostile + hostile: + - ShadowkinDarkFriendly + +- type: npcFaction + id: ShadowkinDarkFriendly + hostile: + - ShadowkinDarkHostile