diff --git a/Content.Server/Ninja/Systems/NinjaGlovesSystem.cs b/Content.Server/Ninja/Systems/NinjaGlovesSystem.cs index 119aaa7434..d84a728775 100644 --- a/Content.Server/Ninja/Systems/NinjaGlovesSystem.cs +++ b/Content.Server/Ninja/Systems/NinjaGlovesSystem.cs @@ -1,16 +1,10 @@ using Content.Server.Communications; -using Content.Server.DoAfter; using Content.Server.Mind; using Content.Server.Ninja.Events; -using Content.Server.Power.Components; -using Content.Server.Roles; +using Content.Server.Objectives.Components; using Content.Shared.Communications; -using Content.Shared.DoAfter; -using Content.Shared.Interaction.Components; -using Content.Shared.Interaction.Events; using Content.Shared.Ninja.Components; using Content.Shared.Ninja.Systems; -using Content.Shared.Popups; using Content.Shared.Research.Components; using Content.Shared.Toggleable; @@ -94,7 +88,7 @@ public sealed class NinjaGlovesSystem : SharedNinjaGlovesSystem EnsureComp(user); // prevent calling in multiple threats by toggling gloves after - if (_mind.TryGetRole(user, out var role) && !role.CalledInThreat) + if (_mind.TryGetObjectiveComp(user, out var obj) && !obj.CalledInThreat) { var hacker = EnsureComp(user); var rule = _ninja.NinjaRule(user); diff --git a/Content.Server/Ninja/Systems/SpaceNinjaSystem.cs b/Content.Server/Ninja/Systems/SpaceNinjaSystem.cs index 0cc3aea266..8f19850c70 100644 --- a/Content.Server/Ninja/Systems/SpaceNinjaSystem.cs +++ b/Content.Server/Ninja/Systems/SpaceNinjaSystem.cs @@ -1,12 +1,8 @@ using Content.Server.Administration.Commands; using Content.Server.Communications; using Content.Server.Chat.Managers; -using Content.Server.StationEvents.Components; using Content.Server.GameTicking; -using Content.Server.GameTicking.Rules; using Content.Server.GameTicking.Rules.Components; -using Content.Server.Ghost.Roles.Events; -using Content.Server.Objectives; using Content.Server.Power.Components; using Content.Server.Power.EntitySystems; using Content.Server.PowerCell; @@ -23,16 +19,12 @@ using Content.Shared.Mind.Components; using Content.Shared.Ninja.Components; using Content.Shared.Ninja.Systems; using Content.Shared.Popups; -using Content.Shared.Roles; -using Content.Shared.PowerCell.Components; using Content.Shared.Rounding; using Robust.Shared.Audio; -using Robust.Shared.GameObjects; -using Robust.Shared.Physics.Components; using Robust.Shared.Player; using Robust.Shared.Random; using System.Diagnostics.CodeAnalysis; -using System.Linq; +using Content.Server.Objectives.Components; namespace Content.Server.Ninja.Systems; @@ -57,8 +49,6 @@ public sealed class SpaceNinjaSystem : SharedSpaceNinjaSystem [Dependency] private readonly RoleSystem _role = default!; [Dependency] private readonly SharedAudioSystem _audio = default!; [Dependency] private readonly SharedMindSystem _mind = default!; - [Dependency] private readonly SharedPopupSystem _popup = default!; - [Dependency] private readonly SharedTransformSystem _transform = default!; [Dependency] private readonly StealthClothingSystem _stealthClothing = default!; public override void Initialize() @@ -85,12 +75,12 @@ public sealed class SpaceNinjaSystem : SharedSpaceNinjaSystem /// private int Download(EntityUid uid, List ids) { - if (!_mind.TryGetRole(uid, out var role)) + if (!_mind.TryGetObjectiveComp(uid, out var obj)) return 0; - var oldCount = role.DownloadedNodes.Count; - role.DownloadedNodes.UnionWith(ids); - var newCount = role.DownloadedNodes.Count; + var oldCount = obj.DownloadedNodes.Count; + obj.DownloadedNodes.UnionWith(ids); + var newCount = obj.DownloadedNodes.Count; return newCount - oldCount; } @@ -124,7 +114,7 @@ public sealed class SpaceNinjaSystem : SharedSpaceNinjaSystem if (GetNinjaBattery(uid, out _, out var battery)) { - var severity = ContentHelpers.RoundToLevels(MathF.Max(0f, battery.CurrentCharge), battery.MaxCharge, 8); + var severity = ContentHelpers.RoundToLevels(MathF.Max(0f, battery.CurrentCharge), battery.MaxCharge, 8); _alerts.ShowAlert(uid, AlertType.SuitPower, (short) severity); } else @@ -205,7 +195,7 @@ public sealed class SpaceNinjaSystem : SharedSpaceNinjaSystem if (ninja.Suit == null) return; - float wattage = _suit.SuitWattage(ninja.Suit.Value); + float wattage = Suit.SuitWattage(ninja.Suit.Value); SetSuitPowerAlert(uid, ninja); if (!TryUseCharge(uid, wattage * frameTime)) @@ -225,11 +215,11 @@ public sealed class SpaceNinjaSystem : SharedSpaceNinjaSystem return; // this popup is serverside since door emag logic is serverside (power funnies) - _popup.PopupEntity(Loc.GetString("ninja-doorjack-success", ("target", Identity.Entity(args.Target, EntityManager))), uid, uid, PopupType.Medium); + Popup.PopupEntity(Loc.GetString("ninja-doorjack-success", ("target", Identity.Entity(args.Target, EntityManager))), uid, uid, PopupType.Medium); // handle greentext - if (_mind.TryGetRole(uid, out var role)) - role.DoorsJacked++; + if (_mind.TryGetObjectiveComp(uid, out var obj)) + obj.DoorsJacked++; } /// @@ -242,14 +232,14 @@ public sealed class SpaceNinjaSystem : SharedSpaceNinjaSystem ? Loc.GetString("ninja-research-steal-fail") : Loc.GetString("ninja-research-steal-success", ("count", gained), ("server", args.Target)); - _popup.PopupEntity(str, uid, uid, PopupType.Medium); + Popup.PopupEntity(str, uid, uid, PopupType.Medium); } private void OnThreatCalledIn(EntityUid uid, SpaceNinjaComponent comp, ref ThreatCalledInEvent args) { - if (_mind.TryGetRole(uid, out var role)) + if (_mind.TryGetObjectiveComp(uid, out var obj)) { - role.CalledInThreat = true; + obj.CalledInThreat = true; } } } diff --git a/Content.Server/Ninja/Systems/SpiderChargeSystem.cs b/Content.Server/Ninja/Systems/SpiderChargeSystem.cs index 3ffc2a8ff3..6f3c3b3f9d 100644 --- a/Content.Server/Ninja/Systems/SpiderChargeSystem.cs +++ b/Content.Server/Ninja/Systems/SpiderChargeSystem.cs @@ -1,5 +1,6 @@ using Content.Server.Explosion.EntitySystems; using Content.Server.Mind; +using Content.Server.Objectives.Components; using Content.Server.Popups; using Content.Server.Roles; using Content.Server.Sticky.Events; @@ -69,10 +70,10 @@ public sealed class SpiderChargeSystem : EntitySystem /// private void OnExplode(EntityUid uid, SpiderChargeComponent comp, TriggerEvent args) { - if (comp.Planter == null || !_mind.TryGetRole(comp.Planter.Value, out var role)) + if (comp.Planter == null || !_mind.TryGetObjectiveComp(comp.Planter.Value, out var obj)) return; // assumes the target was destroyed, that the charge wasn't moved somehow - role.SpiderChargeDetonated = true; + obj.SpiderChargeDetonated = true; } } diff --git a/Content.Server/Objectives/Components/DoorjackConditionComponent.cs b/Content.Server/Objectives/Components/DoorjackConditionComponent.cs index 714a70d8b9..470680ae6d 100644 --- a/Content.Server/Objectives/Components/DoorjackConditionComponent.cs +++ b/Content.Server/Objectives/Components/DoorjackConditionComponent.cs @@ -1,4 +1,5 @@ using Content.Server.Objectives.Systems; +using Content.Shared.Ninja.Systems; namespace Content.Server.Objectives.Components; @@ -6,7 +7,9 @@ namespace Content.Server.Objectives.Components; /// Objective condition that requires the player to be a ninja and have doorjacked at least a random number of airlocks. /// Requires to function. /// -[RegisterComponent, Access(typeof(NinjaConditionsSystem))] +[RegisterComponent, Access(typeof(NinjaConditionsSystem), typeof(SharedSpaceNinjaSystem))] public sealed partial class DoorjackConditionComponent : Component { + [DataField("doorsJacked"), ViewVariables(VVAccess.ReadWrite)] + public int DoorsJacked; } diff --git a/Content.Server/Objectives/Components/SpiderChargeConditionComponent.cs b/Content.Server/Objectives/Components/SpiderChargeConditionComponent.cs index 4fbe8572cd..1c6f22ed57 100644 --- a/Content.Server/Objectives/Components/SpiderChargeConditionComponent.cs +++ b/Content.Server/Objectives/Components/SpiderChargeConditionComponent.cs @@ -1,3 +1,4 @@ +using Content.Server.Ninja.Systems; using Content.Server.Objectives.Systems; namespace Content.Server.Objectives.Components; @@ -5,7 +6,9 @@ namespace Content.Server.Objectives.Components; /// /// Requires that the player is a ninja and blew up their spider charge at its target location. /// -[RegisterComponent, Access(typeof(NinjaConditionsSystem))] +[RegisterComponent, Access(typeof(NinjaConditionsSystem), typeof(SpiderChargeSystem))] public sealed partial class SpiderChargeConditionComponent : Component { + [DataField("spiderChargeDetonated"), ViewVariables(VVAccess.ReadWrite)] + public bool SpiderChargeDetonated; } diff --git a/Content.Server/Objectives/Components/StealResearchConditionComponent.cs b/Content.Server/Objectives/Components/StealResearchConditionComponent.cs index 736a2e74b6..26710ed7cc 100644 --- a/Content.Server/Objectives/Components/StealResearchConditionComponent.cs +++ b/Content.Server/Objectives/Components/StealResearchConditionComponent.cs @@ -1,4 +1,5 @@ using Content.Server.Objectives.Systems; +using Content.Shared.Ninja.Systems; namespace Content.Server.Objectives.Components; @@ -6,7 +7,9 @@ namespace Content.Server.Objectives.Components; /// Objective condition that requires the player to be a ninja and have stolen at least a random number of technologies. /// Requires to function. /// -[RegisterComponent, Access(typeof(NinjaConditionsSystem))] +[RegisterComponent, Access(typeof(NinjaConditionsSystem), typeof(SharedSpaceNinjaSystem))] public sealed partial class StealResearchConditionComponent : Component { + [DataField("downloadedNodes"), ViewVariables(VVAccess.ReadWrite)] + public HashSet DownloadedNodes = new(); } diff --git a/Content.Server/Objectives/Components/TerrorConditionComponent.cs b/Content.Server/Objectives/Components/TerrorConditionComponent.cs index c94e3b424d..acd3218ad4 100644 --- a/Content.Server/Objectives/Components/TerrorConditionComponent.cs +++ b/Content.Server/Objectives/Components/TerrorConditionComponent.cs @@ -1,11 +1,17 @@ using Content.Server.Objectives.Systems; +using Content.Shared.Ninja.Systems; namespace Content.Server.Objectives.Components; /// /// Requires that the player is a ninja and has called in a threat. /// -[RegisterComponent, Access(typeof(NinjaConditionsSystem))] +[RegisterComponent, Access(typeof(NinjaConditionsSystem), typeof(SharedSpaceNinjaSystem))] public sealed partial class TerrorConditionComponent : Component { + /// + /// Whether the comms console has been hacked + /// + [DataField("calledInThreat"), ViewVariables(VVAccess.ReadWrite)] + public bool CalledInThreat; } diff --git a/Content.Server/Objectives/Systems/NinjaConditionsSystem.cs b/Content.Server/Objectives/Systems/NinjaConditionsSystem.cs index 8e03ef201d..eaf97e97e0 100644 --- a/Content.Server/Objectives/Systems/NinjaConditionsSystem.cs +++ b/Content.Server/Objectives/Systems/NinjaConditionsSystem.cs @@ -2,7 +2,6 @@ using Content.Server.Roles; using Content.Server.Objectives.Components; using Content.Server.Warps; using Content.Shared.Objectives.Components; -using Robust.Shared.GameObjects; namespace Content.Server.Objectives.Systems; @@ -31,22 +30,16 @@ public sealed class NinjaConditionsSystem : EntitySystem private void OnDoorjackGetProgress(EntityUid uid, DoorjackConditionComponent comp, ref ObjectiveGetProgressEvent args) { - args.Progress = DoorjackProgress(args.MindId, _number.GetTarget(uid)); + args.Progress = DoorjackProgress(comp, _number.GetTarget(uid)); } - private float DoorjackProgress(EntityUid mindId, int target) + private float DoorjackProgress(DoorjackConditionComponent comp, int target) { // prevent divide-by-zero if (target == 0) return 1f; - if (!TryComp(mindId, out var role)) - return 0f; - - if (role.DoorsJacked >= target) - return 1f; - - return (float) role.DoorsJacked / (float) target; + return MathF.Min(comp.DoorsJacked / (float) target, 1f); } // spider charge @@ -58,7 +51,7 @@ public sealed class NinjaConditionsSystem : EntitySystem private void OnSpiderChargeGetProgress(EntityUid uid, SpiderChargeConditionComponent comp, ref ObjectiveGetProgressEvent args) { - args.Progress = TryComp(args.MindId, out var role) && role.SpiderChargeDetonated ? 1f : 0f; + args.Progress = comp.SpiderChargeDetonated ? 1f : 0f; } private string SpiderChargeTitle(EntityUid mindId) @@ -79,28 +72,20 @@ public sealed class NinjaConditionsSystem : EntitySystem private void OnStealResearchGetProgress(EntityUid uid, StealResearchConditionComponent comp, ref ObjectiveGetProgressEvent args) { - args.Progress = StealResearchProgress(args.MindId, _number.GetTarget(uid)); + args.Progress = StealResearchProgress(comp, _number.GetTarget(uid)); } - private float StealResearchProgress(EntityUid mindId, int target) + private float StealResearchProgress(StealResearchConditionComponent comp, int target) { // prevent divide-by-zero if (target == 0) return 1f; - if (!TryComp(mindId, out var role)) - return 0f; - - if (role.DownloadedNodes.Count >= target) - return 1f; - - return (float) role.DownloadedNodes.Count / (float) target; + return MathF.Min(comp.DownloadedNodes.Count / (float) target, 1f); } - // terror - private void OnTerrorGetProgress(EntityUid uid, TerrorConditionComponent comp, ref ObjectiveGetProgressEvent args) { - args.Progress = TryComp(args.MindId, out var role) && role.CalledInThreat ? 1f : 0f; + args.Progress = comp.CalledInThreat ? 1f : 0f; } } diff --git a/Content.Server/Roles/NinjaRoleComponent.cs b/Content.Server/Roles/NinjaRoleComponent.cs index aa9e1cfa32..dcc55d0fb4 100644 --- a/Content.Server/Roles/NinjaRoleComponent.cs +++ b/Content.Server/Roles/NinjaRoleComponent.cs @@ -8,33 +8,9 @@ namespace Content.Server.Roles; [RegisterComponent] public sealed partial class NinjaRoleComponent : AntagonistRoleComponent { - /// - /// Number of doors that have been doorjacked, used for objective - /// - [DataField("doorsJacked")] - public int DoorsJacked; - - /// - /// Research nodes that have been downloaded, used for objective - /// - [DataField("downloadedNodes")] - public HashSet DownloadedNodes = new(); - /// /// Warp point that the spider charge has to target /// [DataField("spiderChargeTarget")] public EntityUid? SpiderChargeTarget; - - /// - /// Whether the spider charge has been detonated on the target, used for objective - /// - [DataField("spiderChargeDetonated")] - public bool SpiderChargeDetonated; - - /// - /// Whether the comms console has been hacked, used for objective - /// - [DataField("calledInThreat")] - public bool CalledInThreat; } diff --git a/Content.Shared/Mind/SharedMindSystem.cs b/Content.Shared/Mind/SharedMindSystem.cs index b7cd30e962..be11d8a2ad 100644 --- a/Content.Shared/Mind/SharedMindSystem.cs +++ b/Content.Shared/Mind/SharedMindSystem.cs @@ -292,6 +292,33 @@ public abstract class SharedMindSystem : EntitySystem return true; } + public bool TryGetObjectiveComp(EntityUid uid, [NotNullWhen(true)] out T? objective) where T : Component + { + if (TryGetMind(uid, out var mindId, out var mind) && TryGetObjectiveComp(mindId, out objective, mind)) + { + return true; + } + objective = default; + return false; + } + + public bool TryGetObjectiveComp(EntityUid mindId, [NotNullWhen(true)] out T? objective, MindComponent? mind = null) where T : Component + { + if (Resolve(mindId, ref mind)) + { + var query = GetEntityQuery(); + foreach (var uid in mind.AllObjectives) + { + if (query.TryGetComponent(uid, out objective)) + { + return true; + } + } + } + objective = default; + return false; + } + public bool TryGetSession(EntityUid? mindId, [NotNullWhen(true)] out ICommonSession? session) { session = null; diff --git a/Content.Shared/Ninja/Systems/SharedSpaceNinjaSystem.cs b/Content.Shared/Ninja/Systems/SharedSpaceNinjaSystem.cs index d8ff07c27a..fbcb4efe48 100644 --- a/Content.Shared/Ninja/Systems/SharedSpaceNinjaSystem.cs +++ b/Content.Shared/Ninja/Systems/SharedSpaceNinjaSystem.cs @@ -11,8 +11,8 @@ namespace Content.Shared.Ninja.Systems; /// public abstract class SharedSpaceNinjaSystem : EntitySystem { - [Dependency] protected readonly SharedNinjaSuitSystem _suit = default!; - [Dependency] protected readonly SharedPopupSystem _popup = default!; + [Dependency] protected readonly SharedNinjaSuitSystem Suit = default!; + [Dependency] protected readonly SharedPopupSystem Popup = default!; public override void Initialize() { @@ -74,7 +74,7 @@ public abstract class SharedSpaceNinjaSystem : EntitySystem { if (comp.Suit != null && TryComp(comp.Suit, out var stealthClothing) && stealthClothing.Enabled) { - _suit.RevealNinja(comp.Suit.Value, uid, null, stealthClothing); + Suit.RevealNinja(comp.Suit.Value, uid, null, stealthClothing); } } @@ -83,7 +83,7 @@ public abstract class SharedSpaceNinjaSystem : EntitySystem /// private void OnShotAttempted(EntityUid uid, SpaceNinjaComponent comp, ref ShotAttemptedEvent args) { - _popup.PopupClient(Loc.GetString("gun-disabled"), uid, uid); + Popup.PopupClient(Loc.GetString("gun-disabled"), uid, uid); args.Cancel(); } }