Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Penlight-Fixes #900

Merged
merged 6 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 36 additions & 8 deletions Content.Server/Medical/PenLightSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Content.Server.DoAfter;
using Content.Server.Popups;
using Content.Server.PowerCell;
using Content.Shared.Damage;
using Content.Shared.DoAfter;
Expand All @@ -7,6 +8,7 @@
using Content.Shared.Eye.Blinding.Components;
using Content.Shared.Interaction;
using Content.Shared.Medical;
using Content.Shared.Mobs.Components;
using Content.Shared.Mobs.Systems;
using Content.Shared.Traits.Assorted.Components;
using Robust.Server.GameObjects;
Expand All @@ -22,28 +24,31 @@ public sealed class PenLightSystem : EntitySystem
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly DoAfterSystem _doAfter = default!;
[Dependency] private readonly PowerCellSystem _powerCell = default!;
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;

/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<PenLightComponent, AfterInteractEvent>(OnAfterInteract);
SubscribeLocalEvent<PenLightComponent, PenLightDoAfterEvent>(OnDoAfter);
}

private void OnAfterInteract(EntityUid uid, PenLightComponent component, AfterInteractEvent args)
private void OnAfterInteract(EntityUid uid, PenLightComponent component, ref AfterInteractEvent args)
{
if (args.Handled
|| args.Target is not { } target)
if (args.Handled
|| args.Target is not {} target)
return;
if (target == null || !args.CanReach || !HasComp<MobStateComponent>(target) || !_powerCell.HasDrawCharge(uid, user: args.User))
SleepyScarecrow marked this conversation as resolved.
Show resolved Hide resolved
return;

args.Handled = TryStartExam(uid, target, args.User, component);
}

private void OnDoAfter(Entity<PenLightComponent> uid, ref PenLightDoAfterEvent args)
{
if (args.Handled
|| args.Cancelled
|| args.Target == null
if (args.Handled
|| args.Cancelled
|| args.Target == null
|| !_powerCell.HasDrawCharge(uid, user: args.User))
return;

Expand All @@ -52,6 +57,13 @@ private void OnDoAfter(Entity<PenLightComponent> uid, ref PenLightDoAfterEvent a
args.Handled = true;
}

/// <summary>
/// Checks if the PointLight component is enabled.
/// </summary>
private bool IsLightEnabled(EntityUid uid)
{
return TryComp<PointLightComponent>(uid, out var pointLight) && pointLight.Enabled;
}

/// <summary>
/// Actually handles the exam interaction.
Expand All @@ -61,6 +73,18 @@ public bool TryStartExam(EntityUid uid, EntityUid target, EntityUid user, PenLig
if (!Resolve(uid, ref component))
return false;

if (!IsLightEnabled(uid))
{
if (user != null)
_popup.PopupEntity(Loc.GetString("penlight-off"), uid, user);
return false;
}
// can't examine your own eyes, dingus
if (user == target)
{
_popup.PopupEntity(Loc.GetString("penlight-cannot-examine-self"), uid, user);
return false;
}
return _doAfter.TryStartDoAfter(new DoAfterArgs(EntityManager, user, component.ExamSpeed, new PenLightDoAfterEvent(),
uid, target, uid)
{
Expand All @@ -73,7 +97,7 @@ public bool TryStartExam(EntityUid uid, EntityUid target, EntityUid user, PenLig
}
private void OpenUserInterface(EntityUid user, EntityUid penlight)
{
if (!TryComp<ActorComponent>(user, out var actor)
if (!TryComp<ActorComponent>(user, out var actor)
|| !_uiSystem.TryGetUi(penlight, PenLightUiKey.Key, out var ui))
return;

Expand All @@ -88,6 +112,10 @@ private void Diagnose(EntityUid penlight, EntityUid target)
if (!_uiSystem.TryGetUi(penlight, PenLightUiKey.Key, out var ui)
|| !HasComp<EyeComponent>(target))
return;

if (!HasComp<DamageableComponent>(target))
return;
SleepyScarecrow marked this conversation as resolved.
Show resolved Hide resolved

// Blind
var blind = _entityManager.HasComponent<PermanentBlindnessComponent>(target);

Expand Down
1 change: 1 addition & 0 deletions Content.Shared/Medical/PenLightComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Content.Shared.Medical;
[RegisterComponent, NetworkedComponent, AutoGenerateComponentPause]
public sealed partial class PenLightComponent : Component
{

/// <summary>
/// Cooldown Time, exams take a bit
/// </summary>
Expand Down
5 changes: 3 additions & 2 deletions Resources/Locale/en-US/medical/components/penlight.ftl
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
penlight-off = The pen light is off.
penlight-cannot-examine-self = You cannot examine your own eyes.
pen-light-exam-title = Pen Light
pen-light-window-entity-eyes-text = {$entityName}'s conditions:
pen-light-window-no-patient-data-text = No patient data.
pen-light-window-entity-unknown-text = unknown

pen-light-exam-blind-text = The patient's eyes are glassy and unfocused. They can't follow the light at all.
pen-light-exam-drunk-text = The patient's eyes are slow to follow the light, droopy.
pen-light-exam-eyedamage-text = The patient's eyes are partially focused, though they struggle to look at the light for too long.
pen-light-exam-drunk-text = There's a clear delay between moving the light and the patient's eyes following.
pen-light-exam-eyedamage-text = The patient's eyes have dark spots within the pupil, evident when the light is shone in them.
pen-light-exam-hallucinating-text = The patient's eyes are wandering around, with dilated pupils. They don't focus on the light.
pen-light-exam-healthy-text = The patient follows the light perfectly with no stuttering.
Loading