-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
97 additions
and
1 deletion.
There are no files selected for viewing
6 changes: 5 additions & 1 deletion
6
Content.Server/_SSS/SuspicionGameRule/Components/SuspicionRadarComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
namespace Content.Server._SSS.SuspicionGameRule.Components; | ||
|
||
[RegisterComponent] | ||
public sealed partial class SuspicionRadarComponent : Component; | ||
public sealed partial class SuspicionRadarComponent : Component | ||
{ | ||
[DataField] | ||
public bool ShowTraitors { get; set; } = true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using Content.Server._SSS.SuspicionGameRule.Components; | ||
using Content.Server.Mind; | ||
using Content.Server.Roles; | ||
using Content.Shared._SSS.RadarOverlay; | ||
using Content.Shared.Implants.Components; | ||
using Content.Shared.Mobs; | ||
using Content.Shared.Mobs.Systems; | ||
using Robust.Server.GameObjects; | ||
using Robust.Server.Player; | ||
|
||
namespace Content.Server._SSS; | ||
|
||
public sealed class SuspicionRadarSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly RoleSystem _roleSystem = default!; | ||
[Dependency] private readonly MindSystem _mindSystem = default!; | ||
[Dependency] private readonly MobStateSystem _mobStateSystem = default!; | ||
[Dependency] private readonly TransformSystem _transformSystem = default!; | ||
[Dependency] private readonly IPlayerManager _playerManager = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<SubdermalImplantComponent, PingRadarImplantEvent>(OnPing); | ||
SubscribeLocalEvent<MobStateChangedEvent>(OnMobStateChanged); | ||
} | ||
|
||
private void OnMobStateChanged(MobStateChangedEvent ev) | ||
{ | ||
if (ev.NewMobState is not (MobState.Dead or MobState.Critical)) | ||
return; | ||
|
||
if (!_playerManager.TryGetSessionByEntity(ev.Target, out var session)) | ||
return; | ||
|
||
RaiseNetworkEvent(new OnRadarOverlayToggledEvent(false), session); | ||
} | ||
|
||
private void OnPing(EntityUid implantUid, SubdermalImplantComponent implant, PingRadarImplantEvent args) | ||
{ | ||
var players = EntityQueryEnumerator<SuspicionPlayerComponent>(); | ||
var radarInfo = new List<RadarInfo>(); | ||
var uid = implant.ImplantedEntity; | ||
if (uid == null) | ||
{ | ||
Log.Error($"Implant {implantUid} has no implanted entity."); // how | ||
return; | ||
} | ||
|
||
if (!_playerManager.TryGetSessionByEntity(uid.Value, out var session)) | ||
{ | ||
Log.Error($"Failed to locate player session for radar ping."); | ||
return; | ||
} | ||
|
||
var component = Comp<SuspicionRadarComponent>(implantUid); | ||
|
||
RaiseNetworkEvent(new OnRadarOverlayToggledEvent(true), session); | ||
|
||
while (players.MoveNext(out var player, out var playerComponent)) | ||
{ | ||
if (player == uid) | ||
continue; | ||
|
||
if (_mobStateSystem.IsDead(player)) | ||
continue; | ||
|
||
var mind = _mindSystem.GetMind(player); | ||
if (mind == null) | ||
continue; | ||
|
||
if (!_roleSystem.MindHasRole<SuspicionRoleComponent>(mind.Value, out var role)) | ||
continue; | ||
|
||
var roleComp = role.Value.Comp2; | ||
var position = _transformSystem.GetWorldPosition(player); | ||
|
||
var color = roleComp.Role switch | ||
{ | ||
SuspicionRole.Traitor when component.ShowTraitors => Color.Red, | ||
SuspicionRole.Detective => Color.Blue, | ||
_ => Color.Green | ||
}; | ||
|
||
radarInfo.Add(new RadarInfo(color, position)); | ||
} | ||
|
||
RaiseNetworkEvent(new RadarOverlayUpdatedEvent(radarInfo.ToArray()), session); | ||
args.Handled = true; | ||
} | ||
} |