From 45681f15d2958bfb8781dfdd9ddb8e75123c8e5f Mon Sep 17 00:00:00 2001 From: Finket Date: Mon, 6 Nov 2023 15:56:06 +0200 Subject: [PATCH] Port PR189 changes directly --- .../Systems/ShadowkinPowerSystem.DarkSwap.cs | 31 +++++++++---------- .../Systems/ShadowkinPowerSystem.Darken.cs | 6 ++-- .../Systems/ShadowkinPowerSystem.Rest.cs | 15 +++++---- .../Systems/ShadowkinPowerSystem.Teleport.cs | 18 ++++++----- .../Shadowkin/Systems/ShadowkinSystem.cs | 23 +++++++++++--- .../Entities/Objects/Devices/pda.yml | 1 + .../Entities/Objects/Misc/fluff_lights.yml | 1 + .../Entities/Objects/Tools/flashlights.yml | 1 + .../Structures/Lighting/base_lighting.yml | 2 +- 9 files changed, 60 insertions(+), 38 deletions(-) diff --git a/Content.Server/SimpleStation14/Species/Shadowkin/Systems/ShadowkinPowerSystem.DarkSwap.cs b/Content.Server/SimpleStation14/Species/Shadowkin/Systems/ShadowkinPowerSystem.DarkSwap.cs index 1214539a74..1eeab47d39 100644 --- a/Content.Server/SimpleStation14/Species/Shadowkin/Systems/ShadowkinPowerSystem.DarkSwap.cs +++ b/Content.Server/SimpleStation14/Species/Shadowkin/Systems/ShadowkinPowerSystem.DarkSwap.cs @@ -15,7 +15,9 @@ 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!; @@ -28,38 +30,50 @@ public sealed class ShadowkinDarkSwapSystem : EntitySystem [Dependency] private readonly SharedActionsSystem _actions = default!; [Dependency] private readonly IPrototypeManager _prototype = default!; [Dependency] private readonly MagicSystem _magic = default!; + public override void Initialize() { base.Initialize(); + SubscribeLocalEvent(Startup); SubscribeLocalEvent(Shutdown); + SubscribeLocalEvent(DarkSwap); + SubscribeLocalEvent(OnInvisStartup); SubscribeLocalEvent(OnInvisShutdown); } + + private void Startup(EntityUid uid, ShadowkinDarkSwapPowerComponent component, ComponentStartup args) { _actions.AddAction(uid, new InstantAction(_prototype.Index("ShadowkinDarkSwap")), null); } + private void Shutdown(EntityUid uid, ShadowkinDarkSwapPowerComponent component, ComponentShutdown args) { _actions.RemoveAction(uid, new InstantAction(_prototype.Index("ShadowkinDarkSwap"))); } + + private void DarkSwap(EntityUid uid, ShadowkinDarkSwapPowerComponent component, ShadowkinDarkSwapEvent args) { // Need power to drain power if (!_entity.HasComponent(args.Performer)) return; + // Don't activate abilities if handcuffed // TODO: Something like the Psionic Headcage to disable powers for Shadowkin if (_entity.HasComponent(args.Performer)) return; + + var hasComp = _entity.HasComponent(args.Performer); + SetDarkened( args.Performer, !hasComp, !hasComp, - !hasComp, true, args.StaminaCostOn, args.PowerCostOn, @@ -77,7 +91,6 @@ public void SetDarkened( EntityUid performer, bool addComp, bool invisible, - bool pacify, bool darken, float staminaCostOn, float powerCostOn, @@ -98,9 +111,7 @@ public void SetDarkened( { var comp = _entity.EnsureComponent(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); @@ -117,13 +128,9 @@ public void SetDarkened( if (args != null) args.Handled = true; } - private void OnInvisStartup(EntityUid uid, ShadowkinDarkSwappedComponent component, ComponentStartup args) { EnsureComp(uid); - if (component.Pacify) - EnsureComp(uid); - if (component.Invisible) SetCanSeeInvisibility(uid, true); } @@ -142,13 +149,9 @@ private void OnInvisShutdown(EntityUid uid, ShadowkinDarkSwappedComponent compon } component.DarkenedLights.Clear(); } - public void SetCanSeeInvisibility(EntityUid uid, bool set) { var visibility = _entity.EnsureComponent(uid); - if (!TryComp(uid, out var visibility)) - return; - if (set) { if (_entity.TryGetComponent(uid, out EyeComponent? eye)) @@ -158,9 +161,7 @@ public void SetCanSeeInvisibility(EntityUid uid, bool set) _visibility.AddLayer(uid, visibility, (int) VisibilityFlags.DarkSwapInvisibility, false); _visibility.RemoveLayer(uid, visibility, (int) VisibilityFlags.Normal, false); _visibility.RefreshVisibility(uid); - if (!_entity.TryGetComponent(uid, out var _)) - if (!_entity.TryGetComponent(uid, out _)) _stealth.SetVisibility(uid, 0.8f, _entity.EnsureComponent(uid)); } else @@ -172,9 +173,7 @@ public void SetCanSeeInvisibility(EntityUid uid, bool set) _visibility.RemoveLayer(uid, visibility, (int) VisibilityFlags.DarkSwapInvisibility, false); _visibility.AddLayer(uid, visibility, (int) VisibilityFlags.Normal, false); _visibility.RefreshVisibility(uid); - if (!_entity.TryGetComponent(uid, out var _)) - if (!_entity.TryGetComponent(uid, out _)) _entity.RemoveComponent(uid); } } diff --git a/Content.Server/SimpleStation14/Species/Shadowkin/Systems/ShadowkinPowerSystem.Darken.cs b/Content.Server/SimpleStation14/Species/Shadowkin/Systems/ShadowkinPowerSystem.Darken.cs index cfec6173d4..9f2ea18ede 100644 --- a/Content.Server/SimpleStation14/Species/Shadowkin/Systems/ShadowkinPowerSystem.Darken.cs +++ b/Content.Server/SimpleStation14/Species/Shadowkin/Systems/ShadowkinPowerSystem.Darken.cs @@ -78,7 +78,7 @@ public override void Update(float frameTime) if (!_entity.TryGetComponent(light, out ShadowkinLightComponent? shadowkinLight)) continue; // Not powered, undo changes - if (!_entity.TryGetComponent(light, out PoweredLightComponent? powered) || !powered.On) + if (_entity.TryGetComponent(light, out PoweredLightComponent? powered) && !powered.On) { ResetLight(pointLight, shadowkinLight); continue; @@ -98,10 +98,10 @@ public override void Update(float frameTime) shadowkin.DarkenedLights.Remove(light); continue; } - // 10% chance to remove the attached entity so it can become another Shadowkin's light + // 3% chance to remove the attached entity so it can become another Shadowkin's light if (shadowkinLight.AttachedEntity == uid) { - if (_random.Prob(0.1f)) + if (_random.Prob(0.03f)) shadowkinLight.AttachedEntity = EntityUid.Invalid; } diff --git a/Content.Server/SimpleStation14/Species/Shadowkin/Systems/ShadowkinPowerSystem.Rest.cs b/Content.Server/SimpleStation14/Species/Shadowkin/Systems/ShadowkinPowerSystem.Rest.cs index 837d037ce9..d2ff89af3c 100644 --- a/Content.Server/SimpleStation14/Species/Shadowkin/Systems/ShadowkinPowerSystem.Rest.cs +++ b/Content.Server/SimpleStation14/Species/Shadowkin/Systems/ShadowkinPowerSystem.Rest.cs @@ -3,6 +3,7 @@ using Content.Shared.Actions; using Content.Shared.Actions.ActionTypes; using Content.Shared.Bed.Sleep; +using Content.Shared.Cuffs.Components; using Content.Shared.SimpleStation14.Species.Shadowkin.Components; using Robust.Shared.Prototypes; @@ -15,14 +16,10 @@ public sealed class ShadowkinRestSystem : EntitySystem [Dependency] private readonly SharedActionsSystem _actions = default!; [Dependency] private readonly ShadowkinPowerSystem _power = default!; - private InstantAction _action = default!; - public override void Initialize() { base.Initialize(); - _action = new InstantAction(_prototype.Index("ShadowkinRest")); - SubscribeLocalEvent(OnStartup); SubscribeLocalEvent(OnShutdown); @@ -32,19 +29,25 @@ public override void Initialize() private void OnStartup(EntityUid uid, ShadowkinRestPowerComponent component, ComponentStartup args) { - _actions.AddAction(uid, _action, uid); + _actions.AddAction(uid, new InstantAction(_prototype.Index("ShadowkinRest")), null); } private void OnShutdown(EntityUid uid, ShadowkinRestPowerComponent component, ComponentShutdown args) { - _actions.RemoveAction(uid, _action); + _actions.RemoveAction(uid, new InstantAction(_prototype.Index("ShadowkinRest"))); } private void Rest(EntityUid uid, ShadowkinRestPowerComponent component, ShadowkinRestEvent args) { + // Need power to modify power if (!_entity.HasComponent(args.Performer)) return; + // Rest is a funny ability, keep it :) + // // Don't activate abilities if handcuffed + // if (_entity.HasComponent(args.Performer)) + // return; + // Now doing what you weren't before component.IsResting = !component.IsResting; diff --git a/Content.Server/SimpleStation14/Species/Shadowkin/Systems/ShadowkinPowerSystem.Teleport.cs b/Content.Server/SimpleStation14/Species/Shadowkin/Systems/ShadowkinPowerSystem.Teleport.cs index d4c17aa2ae..094c2ab8f0 100644 --- a/Content.Server/SimpleStation14/Species/Shadowkin/Systems/ShadowkinPowerSystem.Teleport.cs +++ b/Content.Server/SimpleStation14/Species/Shadowkin/Systems/ShadowkinPowerSystem.Teleport.cs @@ -4,6 +4,7 @@ using Content.Server.SimpleStation14.Species.Shadowkin.Events; using Content.Shared.Actions; using Content.Shared.Actions.ActionTypes; +using Content.Shared.Cuffs.Components; using Content.Shared.Damage.Systems; using Content.Shared.Pulling.Components; using Content.Shared.SimpleStation14.Species.Shadowkin.Components; @@ -24,14 +25,10 @@ public sealed class ShadowkinTeleportSystem : EntitySystem [Dependency] private readonly IPrototypeManager _prototype = default!; [Dependency] private readonly MagicSystem _magic = default!; - private WorldTargetAction _action = default!; - public override void Initialize() { base.Initialize(); - _action = new WorldTargetAction(_prototype.Index("ShadowkinTeleport")); - SubscribeLocalEvent(Startup); SubscribeLocalEvent(Shutdown); @@ -41,19 +38,24 @@ public override void Initialize() private void Startup(EntityUid uid, ShadowkinTeleportPowerComponent component, ComponentStartup args) { - _actions.AddAction(uid, _action, uid); + _actions.AddAction(uid, new WorldTargetAction(_prototype.Index("ShadowkinTeleport")), null); } private void Shutdown(EntityUid uid, ShadowkinTeleportPowerComponent component, ComponentShutdown args) { - _actions.RemoveAction(uid, _action); + _actions.RemoveAction(uid, new WorldTargetAction(_prototype.Index("ShadowkinTeleport"))); } private void Teleport(EntityUid uid, ShadowkinTeleportPowerComponent component, ShadowkinTeleportEvent args) { - if (args.Handled || - !_entity.TryGetComponent(args.Performer, out var comp)) + // Need power to drain power + if (!_entity.TryGetComponent(args.Performer, out var comp)) + return; + + // Don't activate abilities if handcuffed + // TODO: Something like the Psionic Headcage to disable powers for Shadowkin + if (_entity.HasComponent(args.Performer)) return; diff --git a/Content.Server/SimpleStation14/Species/Shadowkin/Systems/ShadowkinSystem.cs b/Content.Server/SimpleStation14/Species/Shadowkin/Systems/ShadowkinSystem.cs index bceabbb95b..12d89f6ab3 100644 --- a/Content.Server/SimpleStation14/Species/Shadowkin/Systems/ShadowkinSystem.cs +++ b/Content.Server/SimpleStation14/Species/Shadowkin/Systems/ShadowkinSystem.cs @@ -2,6 +2,8 @@ using Content.Server.Mind; using Content.Server.Mind.Components; using Content.Server.SimpleStation14.Species.Shadowkin.Events; +using Content.Shared.Bed.Sleep; +using Content.Shared.Cuffs.Components; using Content.Shared.Examine; using Content.Shared.IdentityManagement; using Content.Shared.Interaction; @@ -89,14 +91,20 @@ public override void Update(float frameTime) // Update power level for all shadowkin while (query.MoveNext(out var uid, out var shadowkin)) { - // Skip if the shadowkin is dead or catatonic + // Ensure dead or critical shadowkin aren't swapped, skip them if (_mobState.IsDead(uid) || - !_entity.System().TryGetMind(uid, out var mind) || + _mobState.IsCritical(uid)) + { + _entity.RemoveComponent(uid); + continue; + } + + // Don't update things for ssd shadowkin + if (!_entity.System().TryGetMind(uid, out var mind) || mind.Session == null) continue; var oldPowerLevel = _power.GetLevelName(shadowkin.PowerLevel); - _power.TryUpdatePowerLevel(uid, frameTime); if (oldPowerLevel != _power.GetLevelName(shadowkin.PowerLevel)) @@ -107,6 +115,11 @@ public override void Update(float frameTime) // I can't figure out how to get this to go to the 100% filled state in the above if statement 😢 _power.UpdateAlert(uid, true, shadowkin.PowerLevel); + // Don't randomly activate abilities if handcuffed + // TODO: Something like the Psionic Headcage to disable powers for Shadowkin + if (_entity.HasComponent(uid)) + continue; + #region MaxPower // Check if they're at max power if (shadowkin.PowerLevel >= ShadowkinComponent.PowerThresholds[ShadowkinPowerThreshold.Max]) @@ -149,7 +162,9 @@ public override void Update(float frameTime) ( ShadowkinComponent.PowerThresholds[ShadowkinPowerThreshold.Tired] + ShadowkinComponent.PowerThresholds[ShadowkinPowerThreshold.Okay] - ) / 2f + ) / 2f && + // Don't sleep if asleep + !_entity.HasComponent(uid) ) { // If so, start the timer diff --git a/Resources/Prototypes/Entities/Objects/Devices/pda.yml b/Resources/Prototypes/Entities/Objects/Devices/pda.yml index 5d384624c0..0e9360b76b 100644 --- a/Resources/Prototypes/Entities/Objects/Devices/pda.yml +++ b/Resources/Prototypes/Entities/Objects/Devices/pda.yml @@ -51,6 +51,7 @@ - idcard - Belt - type: UnpoweredFlashlight + - type: ShadowkinLight - type: PointLight enabled: false radius: 1.5 diff --git a/Resources/Prototypes/Entities/Objects/Misc/fluff_lights.yml b/Resources/Prototypes/Entities/Objects/Misc/fluff_lights.yml index 77b321f951..34fd8913d3 100644 --- a/Resources/Prototypes/Entities/Objects/Misc/fluff_lights.yml +++ b/Resources/Prototypes/Entities/Objects/Misc/fluff_lights.yml @@ -40,6 +40,7 @@ sprite: Objects/Misc/Lights/lights.rsi size: 20 heldPrefix: off + - type: ShadowkinLight - type: PointLight enabled: false radius: 3 diff --git a/Resources/Prototypes/Entities/Objects/Tools/flashlights.yml b/Resources/Prototypes/Entities/Objects/Tools/flashlights.yml index c43ffc830c..8339d5c3f0 100644 --- a/Resources/Prototypes/Entities/Objects/Tools/flashlights.yml +++ b/Resources/Prototypes/Entities/Objects/Tools/flashlights.yml @@ -57,6 +57,7 @@ map: [ "light" ] - type: Item sprite: Objects/Tools/flashlight.rsi + - type: ShadowkinLight - type: PointLight enabled: false mask: /Textures/Effects/LightMasks/cone.png diff --git a/Resources/Prototypes/Entities/Structures/Lighting/base_lighting.yml b/Resources/Prototypes/Entities/Structures/Lighting/base_lighting.yml index 2ac32ef54a..3472a810e1 100644 --- a/Resources/Prototypes/Entities/Structures/Lighting/base_lighting.yml +++ b/Resources/Prototypes/Entities/Structures/Lighting/base_lighting.yml @@ -29,6 +29,7 @@ - state: on map: ["enum.PoweredLightLayers.Base"] state: on + - type: ShadowkinLight - type: PointLight radius: 10 energy: 0.8 @@ -107,7 +108,6 @@ components: - type: Sprite state: off - - type: ShadowkinLight - type: PointLight enabled: true - type: PoweredLight