From a3127748d1685f78cdca991d562559cd868fb189 Mon Sep 17 00:00:00 2001
From: AJCM-git <60196617+AJCM-git@users.noreply.github.com>
Date: Mon, 8 Jan 2024 20:15:00 -0400
Subject: [PATCH] Fixes ninja not being able to use abilities (#23748)
* Fixes ninja not being able to use abilities
* This was for testing
---
.../Ninja/Systems/NinjaSuitSystem.cs | 53 +++++++++++++------
.../Ninja/Systems/SpaceNinjaSystem.cs | 10 ----
.../Ninja/Components/NinjaSuitComponent.cs | 11 +++-
.../Ninja/Systems/SharedNinjaSuitSystem.cs | 23 +++++---
.../Locale/en-US/ninja/ninja-actions.ftl | 2 +
5 files changed, 62 insertions(+), 37 deletions(-)
diff --git a/Content.Server/Ninja/Systems/NinjaSuitSystem.cs b/Content.Server/Ninja/Systems/NinjaSuitSystem.cs
index 2aa08e0492..04095b549c 100644
--- a/Content.Server/Ninja/Systems/NinjaSuitSystem.cs
+++ b/Content.Server/Ninja/Systems/NinjaSuitSystem.cs
@@ -1,14 +1,13 @@
using Content.Server.Emp;
using Content.Server.Ninja.Events;
-using Content.Server.Popups;
using Content.Server.Power.Components;
using Content.Server.PowerCell;
using Content.Shared.Clothing.EntitySystems;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Ninja.Components;
using Content.Shared.Ninja.Systems;
+using Content.Shared.Popups;
using Content.Shared.PowerCell.Components;
-using Content.Shared.Timing;
using Robust.Shared.Containers;
namespace Content.Server.Ninja.Systems;
@@ -21,7 +20,6 @@ public sealed class NinjaSuitSystem : SharedNinjaSuitSystem
[Dependency] private readonly EmpSystem _emp = default!;
[Dependency] private readonly SharedHandsSystem _hands = default!;
[Dependency] private readonly SpaceNinjaSystem _ninja = default!;
- [Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly PowerCellSystem _powerCell = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
@@ -93,10 +91,16 @@ public sealed class NinjaSuitSystem : SharedNinjaSuitSystem
// need 1 second of charge to turn on stealth
var chargeNeeded = SuitWattage(uid, comp);
// being attacked while cloaked gives no power message since it overloads the power supply or something
- if (!_ninja.GetNinjaBattery(user, out var _, out var battery) || battery.CurrentCharge < chargeNeeded
- || !TryComp(user, out UseDelayComponent? useDelay) || UseDelay.IsDelayed((user, useDelay)))
+ if (!_ninja.GetNinjaBattery(user, out _, out var battery) || battery.CurrentCharge < chargeNeeded)
{
- _popup.PopupEntity(Loc.GetString("ninja-no-power"), user, user);
+ Popup.PopupEntity(Loc.GetString("ninja-no-power"), user, user);
+ args.Cancel();
+ return;
+ }
+
+ if (comp.DisableCooldown > GameTiming.CurTime)
+ {
+ Popup.PopupEntity(Loc.GetString("ninja-suit-cooldown"), user, user, PopupType.Medium);
args.Cancel();
return;
}
@@ -108,10 +112,15 @@ public sealed class NinjaSuitSystem : SharedNinjaSuitSystem
{
args.Handled = true;
var user = args.Performer;
- if (!_ninja.TryUseCharge(user, comp.ThrowingStarCharge)
- || !TryComp(user, out UseDelayComponent? useDelay) || UseDelay.IsDelayed((user, useDelay)))
+ if (!_ninja.TryUseCharge(user, comp.ThrowingStarCharge))
+ {
+ Popup.PopupEntity(Loc.GetString("ninja-no-power"), user, user);
+ return;
+ }
+
+ if (comp.DisableCooldown > GameTiming.CurTime)
{
- _popup.PopupEntity(Loc.GetString("ninja-no-power"), user, user);
+ Popup.PopupEntity(Loc.GetString("ninja-suit-cooldown"), user, user, PopupType.Medium);
return;
}
@@ -130,11 +139,16 @@ public sealed class NinjaSuitSystem : SharedNinjaSuitSystem
var katana = ninja.Katana.Value;
var coords = _transform.GetWorldPosition(katana);
var distance = (_transform.GetWorldPosition(user) - coords).Length();
- var chargeNeeded = (float) distance * comp.RecallCharge;
- if (!_ninja.TryUseCharge(user, chargeNeeded)
- || !TryComp(user, out UseDelayComponent? useDelay) || UseDelay.IsDelayed((user, useDelay)))
+ var chargeNeeded = distance * comp.RecallCharge;
+ if (!_ninja.TryUseCharge(user, chargeNeeded))
{
- _popup.PopupEntity(Loc.GetString("ninja-no-power"), user, user);
+ Popup.PopupEntity(Loc.GetString("ninja-no-power"), user, user);
+ return;
+ }
+
+ if (comp.DisableCooldown > GameTiming.CurTime)
+ {
+ Popup.PopupEntity(Loc.GetString("ninja-suit-cooldown"), user, user, PopupType.Medium);
return;
}
@@ -142,17 +156,22 @@ public sealed class NinjaSuitSystem : SharedNinjaSuitSystem
var message = _hands.TryPickupAnyHand(user, katana)
? "ninja-katana-recalled"
: "ninja-hands-full";
- _popup.PopupEntity(Loc.GetString(message), user, user);
+ Popup.PopupEntity(Loc.GetString(message), user, user);
}
private void OnEmp(EntityUid uid, NinjaSuitComponent comp, NinjaEmpEvent args)
{
args.Handled = true;
var user = args.Performer;
- if (!_ninja.TryUseCharge(user, comp.EmpCharge)
- || !TryComp(user, out UseDelayComponent? useDelay) || UseDelay.IsDelayed((user, useDelay)))
+ if (!_ninja.TryUseCharge(user, comp.EmpCharge))
+ {
+ Popup.PopupEntity(Loc.GetString("ninja-no-power"), user, user);
+ return;
+ }
+
+ if (comp.DisableCooldown > GameTiming.CurTime)
{
- _popup.PopupEntity(Loc.GetString("ninja-no-power"), user, user);
+ Popup.PopupEntity(Loc.GetString("ninja-suit-cooldown"), user, user, PopupType.Medium);
return;
}
diff --git a/Content.Server/Ninja/Systems/SpaceNinjaSystem.cs b/Content.Server/Ninja/Systems/SpaceNinjaSystem.cs
index a1b1032105..716c98372c 100644
--- a/Content.Server/Ninja/Systems/SpaceNinjaSystem.cs
+++ b/Content.Server/Ninja/Systems/SpaceNinjaSystem.cs
@@ -1,7 +1,5 @@
-using Content.Server.Administration.Commands;
using Content.Server.Communications;
using Content.Server.Chat.Managers;
-using Content.Server.GameTicking;
using Content.Server.GameTicking.Rules.Components;
using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems;
@@ -15,18 +13,13 @@ using Content.Shared.Clothing.EntitySystems;
using Content.Shared.Doors.Components;
using Content.Shared.IdentityManagement;
using Content.Shared.Mind;
-using Content.Shared.Mind.Components;
using Content.Shared.Ninja.Components;
using Content.Shared.Ninja.Systems;
using Content.Shared.Popups;
using Content.Shared.Rounding;
-using Robust.Shared.Audio;
-using Robust.Shared.Player;
using Robust.Shared.Random;
using System.Diagnostics.CodeAnalysis;
-using System.Linq;
using Content.Server.Objectives.Components;
-using Robust.Shared.Audio.Systems;
namespace Content.Server.Ninja.Systems;
@@ -43,13 +36,10 @@ public sealed class SpaceNinjaSystem : SharedSpaceNinjaSystem
{
[Dependency] private readonly AlertsSystem _alerts = default!;
[Dependency] private readonly BatterySystem _battery = default!;
- [Dependency] private readonly GameTicker _gameTicker = default!;
- [Dependency] private readonly GenericAntagSystem _genericAntag = default!;
[Dependency] private readonly IChatManager _chatMan = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly PowerCellSystem _powerCell = default!;
[Dependency] private readonly RoleSystem _role = default!;
- [Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedMindSystem _mind = default!;
[Dependency] private readonly StealthClothingSystem _stealthClothing = default!;
diff --git a/Content.Shared/Ninja/Components/NinjaSuitComponent.cs b/Content.Shared/Ninja/Components/NinjaSuitComponent.cs
index 381728ae28..b6fac57b0b 100644
--- a/Content.Shared/Ninja/Components/NinjaSuitComponent.cs
+++ b/Content.Shared/Ninja/Components/NinjaSuitComponent.cs
@@ -4,6 +4,7 @@ using Robust.Shared.Audio;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
+using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.Utility;
@@ -35,12 +36,18 @@ public sealed partial class NinjaSuitComponent : Component
public SoundSpecifier RevealSound = new SoundPathSpecifier("/Audio/Effects/chime.ogg");
///
- /// How long to disable all abilities for when revealed.
- /// This adds a UseDelay to the ninja so it should not be set by anything else.
+ /// How long to disable all abilities when revealed.
+ /// Normally, ninjas are revealed when attacking or getting damaged.
///
[DataField("disableTime")]
public TimeSpan DisableTime = TimeSpan.FromSeconds(5);
+ ///
+ /// Time at which we will be able to use our abilities again
+ ///
+ [DataField(customTypeSerializer: typeof(TimeOffsetSerializer))]
+ public TimeSpan DisableCooldown;
+
///
/// The action id for creating throwing stars.
///
diff --git a/Content.Shared/Ninja/Systems/SharedNinjaSuitSystem.cs b/Content.Shared/Ninja/Systems/SharedNinjaSuitSystem.cs
index 20d003a61b..1449157538 100644
--- a/Content.Shared/Ninja/Systems/SharedNinjaSuitSystem.cs
+++ b/Content.Shared/Ninja/Systems/SharedNinjaSuitSystem.cs
@@ -3,8 +3,9 @@ using Content.Shared.Clothing.Components;
using Content.Shared.Clothing.EntitySystems;
using Content.Shared.Inventory.Events;
using Content.Shared.Ninja.Components;
-using Content.Shared.Timing;
+using Content.Shared.Popups;
using Robust.Shared.Audio.Systems;
+using Robust.Shared.Timing;
namespace Content.Shared.Ninja.Systems;
@@ -13,22 +14,25 @@ namespace Content.Shared.Ninja.Systems;
///
public abstract class SharedNinjaSuitSystem : EntitySystem
{
+ [Dependency] protected readonly IGameTiming GameTiming = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedNinjaGlovesSystem _gloves = default!;
[Dependency] private readonly SharedSpaceNinjaSystem _ninja = default!;
- [Dependency] protected readonly StealthClothingSystem StealthClothing = default!;
- [Dependency] protected readonly UseDelaySystem UseDelay = default!;
[Dependency] private readonly ActionContainerSystem _actionContainer = default!;
+ [Dependency] protected readonly SharedPopupSystem Popup = default!;
+ [Dependency] protected readonly StealthClothingSystem StealthClothing = default!;
public override void Initialize()
{
base.Initialize();
+ SubscribeLocalEvent(OnMapInit);
+ SubscribeLocalEvent(OnEntityUnpaused);
+
SubscribeLocalEvent(OnEquipped);
SubscribeLocalEvent(OnGetItemActions);
SubscribeLocalEvent(OnAddStealthAction);
SubscribeLocalEvent(OnUnequipped);
- SubscribeLocalEvent(OnMapInit);
}
private void OnMapInit(EntityUid uid, NinjaSuitComponent component, MapInitEvent args)
@@ -39,6 +43,11 @@ public abstract class SharedNinjaSuitSystem : EntitySystem
Dirty(uid, component);
}
+ private void OnEntityUnpaused(Entity ent, ref EntityUnpausedEvent args)
+ {
+ ent.Comp.DisableCooldown += args.PausedTime;
+ }
+
///
/// Call the shared and serverside code for when a ninja equips the suit.
///
@@ -110,10 +119,8 @@ public abstract class SharedNinjaSuitSystem : EntitySystem
// previously cloaked, disable abilities for a short time
_audio.PlayPredicted(comp.RevealSound, uid, user);
- // all abilities check for a usedelay on the ninja
- var useDelay = EnsureComp(user);
- UseDelay.SetDelay((user, useDelay), comp.DisableTime);
- UseDelay.TryResetDelay((user, useDelay));
+ Popup.PopupClient(Loc.GetString("ninja-revealed"), user, user, PopupType.MediumCaution);
+ comp.DisableCooldown = GameTiming.CurTime + comp.DisableTime;
}
// TODO: modify PowerCellDrain
diff --git a/Resources/Locale/en-US/ninja/ninja-actions.ftl b/Resources/Locale/en-US/ninja/ninja-actions.ftl
index b15a4118e9..b42da33a29 100644
--- a/Resources/Locale/en-US/ninja/ninja-actions.ftl
+++ b/Resources/Locale/en-US/ninja/ninja-actions.ftl
@@ -1,4 +1,6 @@
ninja-no-power = Not enough charge in suit battery!
+ninja-revealed = You have been revealed!
+ninja-suit-cooldown = The suit needs time to recuperate from the last attack.
ninja-research-steal-fail = No new research nodes were stolen...
ninja-research-steal-success = Stole {$count} new nodes from {THE($server)}.
--
2.51.2