Use conditions to store progress for Ninja objectives (#20254)

* TryGetObjectiveComp

* helper function to get objective

* store N of jacked doors in condition

* store called in threat bool in condition

* store techs in steal research condition

* fix access

* remove unused transform system

* use popup from shared system

* fix formatting

* condition => obj everywhere

* i fogror to remove downloaded nodes from role

* change signature

* use query

* View Variables

* spider charge detonated => condition
This commit is contained in:
Slava0135
2023-10-10 09:32:10 +03:00
committed by GitHub
parent c35a018cad
commit 6f8c2b7e52
11 changed files with 76 additions and 88 deletions

View File

@@ -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
/// </summary>
private int Download(EntityUid uid, List<string> ids)
{
if (!_mind.TryGetRole<NinjaRoleComponent>(uid, out var role))
if (!_mind.TryGetObjectiveComp<StealResearchConditionComponent>(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<NinjaRoleComponent>(uid, out var role))
role.DoorsJacked++;
if (_mind.TryGetObjectiveComp<DoorjackConditionComponent>(uid, out var obj))
obj.DoorsJacked++;
}
/// <summary>
@@ -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<NinjaRoleComponent>(uid, out var role))
if (_mind.TryGetObjectiveComp<TerrorConditionComponent>(uid, out var obj))
{
role.CalledInThreat = true;
obj.CalledInThreat = true;
}
}
}