Skip to content

Commit

Permalink
fix Shadowkin Dark visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
DEATHB4DEFEAT committed Oct 14, 2023
1 parent de8e261 commit 74ecef6
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Content.Server/SimpleStation14/Eye/EyeStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private void OnEyeStartup(EntityUid uid, EyeComponent component, ComponentStartu
if (_entityManager.HasComponent<GhostComponent>(uid))
component.VisibilityMask |= (uint) VisibilityFlags.AIEye;

_shadowkinPowerSystem.SetCanSeeInvisibility(uid, _entityManager.HasComponent<GhostComponent>(uid));
_shadowkinPowerSystem.SetVisibility(uid, _entityManager.HasComponent<GhostComponent>(uid));
}
}
}
Original file line number Diff line number Diff line change
@@ -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
{
/// <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" };
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -149,15 +153,21 @@ private void OnInvisStartup(EntityUid uid, ShadowkinDarkSwappedComponent compone
EnsureComp<PacifiedComponent>(uid);

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

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

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

component.Darken = false;

Expand All @@ -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<VisibilityComponent>(uid, out var visibility))
return;
var visibility = EnsureComp<VisibilityComponent>(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);
Expand All @@ -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<GhostComponent>(uid, out _))
_entity.RemoveComponent<StealthComponent>(uid);
_stealth.SetVisibility(uid, 1f, _entity.EnsureComponent<StealthComponent>(uid));
}
}

/// <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)
{
if (!_entity.TryGetComponent<ShadowkinDarkSwapPowerComponent>(uid, out var component))
return;

if (set)
{
if (_entity.TryGetComponent<NpcFactionMemberComponent>(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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public sealed class ShadowkinDarkSwappedComponent : Component
[DataField("darken"), ViewVariables(VVAccess.ReadWrite)]
public bool Darken = true;


/// <summary>
/// How far to dim nearby lights
/// </summary>
Expand Down
9 changes: 9 additions & 0 deletions Resources/Prototypes/SimpleStation14/factions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- type: npcFaction
id: ShadowkinDarkHostile
hostile:
- ShadowkinDarkFriendly

- type: npcFaction
id: ShadowkinDarkFriendly
hostile:
- ShadowkinDarkHostile

0 comments on commit 74ecef6

Please sign in to comment.