* move spider charge target from role * shorter field names * remove ninja role comment * remove unused systems in SpaceNinjaSystem * GenericAntagObjectivesAddedEvent * check if warp point is on same map * remove unnecessary import * add missing loc when spider charge has no target * a * remove spider charge target requirement comp * inline SpiderChargeTitle * allow planting charge without objective * remove map check * fix role check when planting * obj.Target * Fix merge --------- Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
119 lines
4.2 KiB
C#
119 lines
4.2 KiB
C#
using Content.Server.Objectives.Components;
|
|
using Content.Server.Warps;
|
|
using Content.Shared.Objectives.Components;
|
|
using Content.Shared.Mind;
|
|
using Content.Shared.Ninja.Components;
|
|
using Robust.Shared.Random;
|
|
using Content.Server.Roles;
|
|
|
|
namespace Content.Server.Objectives.Systems;
|
|
|
|
/// <summary>
|
|
/// Handles the objective conditions that hard depend on ninja.
|
|
/// Survive is handled by <see cref="SurviveConditionSystem"/> since it works without being a ninja.
|
|
/// </summary>
|
|
public sealed class NinjaConditionsSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly MetaDataSystem _metaData = default!;
|
|
[Dependency] private readonly NumberObjectiveSystem _number = default!;
|
|
[Dependency] private readonly SharedMindSystem _mind = default!;
|
|
[Dependency] private readonly IRobustRandom _random = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
SubscribeLocalEvent<DoorjackConditionComponent, ObjectiveGetProgressEvent>(OnDoorjackGetProgress);
|
|
|
|
SubscribeLocalEvent<SpiderChargeConditionComponent, RequirementCheckEvent>(OnSpiderChargeRequirementCheck);
|
|
SubscribeLocalEvent<SpiderChargeConditionComponent, ObjectiveAfterAssignEvent>(OnSpiderChargeAfterAssign);
|
|
SubscribeLocalEvent<SpiderChargeConditionComponent, ObjectiveGetProgressEvent>(OnSpiderChargeGetProgress);
|
|
|
|
SubscribeLocalEvent<StealResearchConditionComponent, ObjectiveGetProgressEvent>(OnStealResearchGetProgress);
|
|
|
|
SubscribeLocalEvent<TerrorConditionComponent, ObjectiveGetProgressEvent>(OnTerrorGetProgress);
|
|
}
|
|
|
|
// doorjack
|
|
|
|
private void OnDoorjackGetProgress(EntityUid uid, DoorjackConditionComponent comp, ref ObjectiveGetProgressEvent args)
|
|
{
|
|
args.Progress = DoorjackProgress(comp, _number.GetTarget(uid));
|
|
}
|
|
|
|
private float DoorjackProgress(DoorjackConditionComponent comp, int target)
|
|
{
|
|
// prevent divide-by-zero
|
|
if (target == 0)
|
|
return 1f;
|
|
|
|
return MathF.Min(comp.DoorsJacked / (float) target, 1f);
|
|
}
|
|
|
|
// spider charge
|
|
private void OnSpiderChargeRequirementCheck(EntityUid uid, SpiderChargeConditionComponent comp, ref RequirementCheckEvent args)
|
|
{
|
|
if (args.Cancelled || !HasComp<NinjaRoleComponent>(args.MindId))
|
|
{
|
|
return;
|
|
}
|
|
|
|
// choose spider charge detonation point
|
|
var warps = new List<EntityUid>();
|
|
var query = EntityQueryEnumerator<BombingTargetComponent, WarpPointComponent>();
|
|
while (query.MoveNext(out var warpUid, out _, out var warp))
|
|
{
|
|
if (warp.Location != null)
|
|
{
|
|
warps.Add(warpUid);
|
|
}
|
|
}
|
|
|
|
if (warps.Count <= 0)
|
|
{
|
|
args.Cancelled = true;
|
|
return;
|
|
}
|
|
comp.Target = _random.Pick(warps);
|
|
}
|
|
|
|
private void OnSpiderChargeAfterAssign(EntityUid uid, SpiderChargeConditionComponent comp, ref ObjectiveAfterAssignEvent args)
|
|
{
|
|
string title;
|
|
if (comp.Target == null || !TryComp<WarpPointComponent>(comp.Target, out var warp) || warp.Location == null)
|
|
{
|
|
// this should never really happen but eh
|
|
title = Loc.GetString("objective-condition-spider-charge-title-no-target");
|
|
}
|
|
else
|
|
{
|
|
title = Loc.GetString("objective-condition-spider-charge-title", ("location", warp.Location));
|
|
}
|
|
_metaData.SetEntityName(uid, title, args.Meta);
|
|
}
|
|
|
|
private void OnSpiderChargeGetProgress(EntityUid uid, SpiderChargeConditionComponent comp, ref ObjectiveGetProgressEvent args)
|
|
{
|
|
args.Progress = comp.Detonated ? 1f : 0f;
|
|
}
|
|
|
|
// steal research
|
|
|
|
private void OnStealResearchGetProgress(EntityUid uid, StealResearchConditionComponent comp, ref ObjectiveGetProgressEvent args)
|
|
{
|
|
args.Progress = StealResearchProgress(comp, _number.GetTarget(uid));
|
|
}
|
|
|
|
private float StealResearchProgress(StealResearchConditionComponent comp, int target)
|
|
{
|
|
// prevent divide-by-zero
|
|
if (target == 0)
|
|
return 1f;
|
|
|
|
return MathF.Min(comp.DownloadedNodes.Count / (float) target, 1f);
|
|
}
|
|
|
|
private void OnTerrorGetProgress(EntityUid uid, TerrorConditionComponent comp, ref ObjectiveGetProgressEvent args)
|
|
{
|
|
args.Progress = comp.CalledInThreat ? 1f : 0f;
|
|
}
|
|
}
|