mirror of
https://github.com/wega-team/ss14-wega.git
synced 2026-06-09 10:06:49 +02:00
22a547c7c8
* Replace usages of EntityQuery with dependency injected ones in Content.Server * Remove unused EntityQuery dependencies * Restore CheckPressureAndFire override method * Revert EntityQuery refactor changes to DisposalTubeSystem.cs & DisposableSystem.cs * Infer Transform/Metadata directly instead of passing (#43479) * Resolve RA0049, RA0051 errors (#43479) * Resolve RA0049, RA0051 errors (#43479) * Apply suggestions from code review Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> --------- Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
105 lines
3.5 KiB
C#
105 lines
3.5 KiB
C#
using Content.Server.Objectives.Components;
|
|
using Content.Server.Shuttles.Components;
|
|
using Content.Server.Shuttles.Systems;
|
|
using Content.Shared.Cuffs.Components;
|
|
using Content.Shared.Humanoid;
|
|
using Content.Shared.Mind;
|
|
using Content.Shared.Mobs.Components;
|
|
using Content.Shared.Mobs.Systems;
|
|
using Content.Shared.Objectives.Components;
|
|
using Content.Shared.Roles;
|
|
using Robust.Shared.Player;
|
|
|
|
namespace Content.Server.Objectives.Systems;
|
|
|
|
public sealed partial class HijackShuttleConditionSystem : EntitySystem
|
|
{
|
|
[Dependency] private EmergencyShuttleSystem _emergencyShuttle = default!;
|
|
[Dependency] private SharedMindSystem _mind = default!;
|
|
[Dependency] private SharedRoleSystem _role = default!;
|
|
[Dependency] private MobStateSystem _mobState = default!;
|
|
|
|
[Dependency] private EntityQuery<HumanoidProfileComponent> _humanoidsQuery = default!;
|
|
[Dependency] private EntityQuery<CuffableComponent> _cuffableQuery = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<HijackShuttleConditionComponent, ObjectiveGetProgressEvent>(OnGetProgress);
|
|
}
|
|
|
|
private void OnGetProgress(EntityUid uid, HijackShuttleConditionComponent comp, ref ObjectiveGetProgressEvent args)
|
|
{
|
|
args.Progress = GetProgress(args.MindId, args.Mind);
|
|
}
|
|
|
|
private float GetProgress(EntityUid mindId, MindComponent mind)
|
|
{
|
|
// Not escaping alive if you're deleted/dead
|
|
if (mind.OwnedEntity == null || _mind.IsCharacterDeadIc(mind))
|
|
return 0f;
|
|
|
|
// You're not escaping if you're restrained!
|
|
if (TryComp<CuffableComponent>(mind.OwnedEntity, out var cuffed) && cuffed.CuffedHandCount > 0)
|
|
return 0f;
|
|
|
|
// There no emergency shuttles
|
|
if (!_emergencyShuttle.EmergencyShuttleArrived)
|
|
return 0f;
|
|
|
|
// Check hijack for each emergency shuttle
|
|
foreach (var stationData in EntityQuery<StationEmergencyShuttleComponent>())
|
|
{
|
|
if (stationData.EmergencyShuttle == null)
|
|
continue;
|
|
|
|
if (IsShuttleHijacked(stationData.EmergencyShuttle.Value, mindId))
|
|
return 1f;
|
|
}
|
|
|
|
return 0f;
|
|
}
|
|
|
|
private bool IsShuttleHijacked(EntityUid shuttleGridId, EntityUid mindId)
|
|
{
|
|
var gridPlayers = Filter.BroadcastGrid(shuttleGridId).Recipients;
|
|
|
|
var agentOnShuttle = false;
|
|
foreach (var player in gridPlayers)
|
|
{
|
|
if (player.AttachedEntity == null ||
|
|
!_mind.TryGetMind(player.AttachedEntity.Value, out var crewMindId, out _))
|
|
continue;
|
|
|
|
if (mindId == crewMindId)
|
|
{
|
|
agentOnShuttle = true;
|
|
continue;
|
|
}
|
|
|
|
var isHumanoid = _humanoidsQuery.HasComponent(player.AttachedEntity.Value);
|
|
if (!isHumanoid) // Only humanoids count as enemies
|
|
continue;
|
|
|
|
var isAntagonist = _role.MindIsAntagonist(mindId);
|
|
if (isAntagonist) // Allow antagonist
|
|
continue;
|
|
|
|
var isPersonIncapacitated = _mobState.IsIncapacitated(player.AttachedEntity.Value);
|
|
if (isPersonIncapacitated) // Allow dead and crit
|
|
continue;
|
|
|
|
var isPersonCuffed =
|
|
_cuffableQuery.TryGetComponent(player.AttachedEntity.Value, out var cuffed)
|
|
&& cuffed.CuffedHandCount > 0;
|
|
if (isPersonCuffed) // Allow handcuffed
|
|
continue;
|
|
|
|
return false;
|
|
}
|
|
|
|
return agentOnShuttle;
|
|
}
|
|
}
|