Skip to content

Commit

Permalink
Port PR189 changes directly
Browse files Browse the repository at this point in the history
  • Loading branch information
vaketola committed Nov 6, 2023
1 parent dab0059 commit 45681f1
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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!;
Expand All @@ -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<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, new InstantAction(_prototype.Index<InstantActionPrototype>("ShadowkinDarkSwap")), null);
}

private void Shutdown(EntityUid uid, ShadowkinDarkSwapPowerComponent component, ComponentShutdown args)
{
_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 @@ -77,7 +91,6 @@ public void SetDarkened(
EntityUid performer,
bool addComp,
bool invisible,
bool pacify,
bool darken,
float staminaCostOn,
float powerCostOn,
Expand All @@ -98,9 +111,7 @@ public void SetDarkened(
{
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);
Expand All @@ -117,13 +128,9 @@ public void SetDarkened(
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);
}
Expand All @@ -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<VisibilityComponent>(uid);
if (!TryComp<VisibilityComponent>(uid, out var visibility))
return;

if (set)
{
if (_entity.TryGetComponent(uid, out EyeComponent? eye))
Expand All @@ -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<GhostComponent>(uid, out var _))
if (!_entity.TryGetComponent<GhostComponent>(uid, out _))
_stealth.SetVisibility(uid, 0.8f, _entity.EnsureComponent<StealthComponent>(uid));
}
else
Expand All @@ -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<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 @@ -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;
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<InstantActionPrototype>("ShadowkinRest"));

SubscribeLocalEvent<ShadowkinRestPowerComponent, ComponentStartup>(OnStartup);
SubscribeLocalEvent<ShadowkinRestPowerComponent, ComponentShutdown>(OnShutdown);

Expand All @@ -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<InstantActionPrototype>("ShadowkinRest")), null);
}

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

private void Rest(EntityUid uid, ShadowkinRestPowerComponent component, ShadowkinRestEvent args)
{
// Need power to modify power
if (!_entity.HasComponent<ShadowkinComponent>(args.Performer))
return;

// Rest is a funny ability, keep it :)
// // Don't activate abilities if handcuffed
// if (_entity.HasComponent<HandcuffComponent>(args.Performer))
// return;

// Now doing what you weren't before
component.IsResting = !component.IsResting;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<WorldTargetActionPrototype>("ShadowkinTeleport"));

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

Expand All @@ -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<WorldTargetActionPrototype>("ShadowkinTeleport")), null);
}

private void Shutdown(EntityUid uid, ShadowkinTeleportPowerComponent component, ComponentShutdown args)
{
_actions.RemoveAction(uid, _action);
_actions.RemoveAction(uid, new WorldTargetAction(_prototype.Index<WorldTargetActionPrototype>("ShadowkinTeleport")));
}


private void Teleport(EntityUid uid, ShadowkinTeleportPowerComponent component, ShadowkinTeleportEvent args)
{
if (args.Handled ||
!_entity.TryGetComponent<ShadowkinComponent>(args.Performer, out var comp))
// Need power to drain power
if (!_entity.TryGetComponent<ShadowkinComponent>(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<HandcuffComponent>(args.Performer))
return;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<MindSystem>().TryGetMind(uid, out var mind) ||
_mobState.IsCritical(uid))
{
_entity.RemoveComponent<ShadowkinDarkSwappedComponent>(uid);
continue;
}

// Don't update things for ssd shadowkin
if (!_entity.System<MindSystem>().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))
Expand All @@ -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<HandcuffComponent>(uid))
continue;

#region MaxPower
// Check if they're at max power
if (shadowkin.PowerLevel >= ShadowkinComponent.PowerThresholds[ShadowkinPowerThreshold.Max])
Expand Down Expand Up @@ -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<SleepingComponent>(uid)
)
{
// If so, start the timer
Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/Entities/Objects/Devices/pda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
- idcard
- Belt
- type: UnpoweredFlashlight
- type: ShadowkinLight
- type: PointLight
enabled: false
radius: 1.5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
sprite: Objects/Misc/Lights/lights.rsi
size: 20
heldPrefix: off
- type: ShadowkinLight
- type: PointLight
enabled: false
radius: 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
- state: on
map: ["enum.PoweredLightLayers.Base"]
state: on
- type: ShadowkinLight
- type: PointLight
radius: 10
energy: 0.8
Expand Down Expand Up @@ -107,7 +108,6 @@
components:
- type: Sprite
state: off
- type: ShadowkinLight
- type: PointLight
enabled: true
- type: PoweredLight
Expand Down

0 comments on commit 45681f1

Please sign in to comment.