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

773 #78

Closed
Closed

773 #78

Show file tree
Hide file tree
Changes from all 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
13 changes: 13 additions & 0 deletions Content.Shared/ADT/Glasses/GlassesComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Robust.Shared.GameStates;

namespace Content.Shared.Traits.Assorted;

/// <summary>
/// This is used for making something blind forever.
/// </summary>
[RegisterComponent, NetworkedComponent]
public sealed partial class GlassesComponent : Component
{

}

49 changes: 49 additions & 0 deletions Content.Shared/ADT/Glasses/GlassesSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using Content.Shared.Damage.Components;
using Content.Shared.Examine;
using Content.Shared.Eye.Blinding.Components;
using Content.Shared.Eye.Blinding.Systems;
using Content.Shared.IdentityManagement;
using Robust.Shared.Network;
using Content.Shared.Inventory.Events;
using Content.Shared.Inventory;
using Content.Shared.Traits.Assorted;

namespace Content.Shared.Traits.Assorted;

/// <summary>
/// This handles permanent blindness, both the examine and the actual effect.
/// </summary>
public sealed class GlassesSystem : EntitySystem
{
[Dependency] private readonly INetManager _net = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly BlindableSystem _blinding = default!;

/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<GlassesComponent, GotEquippedEvent>(Equipped);
SubscribeLocalEvent<GlassesComponent, GotUnequippedEvent>(Unequipped);

}

private void Equipped(EntityUid uid, GlassesComponent component, ref GotEquippedEvent args)
{
if (!TryComp<MyopiaComponent>(args.Equipee, out var myopia))
return;
myopia.Active = false;
if (!TryComp<BlindableComponent>(args.Equipee, out var blindable))
return;
_blinding.AdjustEyeDamage((args.Equipee, blindable), -myopia.EyeDamage);
}

private void Unequipped(EntityUid uid, GlassesComponent component, ref GotUnequippedEvent args)
{
if (!TryComp<MyopiaComponent>(args.Equipee, out var myopia))
return;
myopia.Active = true;
if (!TryComp<BlindableComponent>(args.Equipee, out var blindable))
return;
_blinding.AdjustEyeDamage((args.Equipee, blindable), myopia.EyeDamage);
}
}
16 changes: 16 additions & 0 deletions Content.Shared/ADT/Traits/Assorted/MyopiaComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Robust.Shared.GameStates;

namespace Content.Shared.Traits.Assorted;

/// <summary>
/// This is used for making something blind forever.
/// </summary>
[RegisterComponent, NetworkedComponent]
public sealed partial class MyopiaComponent : Component
{
[DataField]
public int EyeDamage = 3;

public bool Active = true;
}

52 changes: 52 additions & 0 deletions Content.Shared/ADT/Traits/Assorted/MyopiaSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Content.Shared.Damage.Components;
using Content.Shared.Examine;
using Content.Shared.Eye.Blinding.Components;
using Content.Shared.Eye.Blinding.Systems;
using Content.Shared.IdentityManagement;
using Robust.Shared.Network;

namespace Content.Shared.Traits.Assorted;

/// <summary>
/// This handles permanent blindness, both the examine and the actual effect.
/// </summary>
public sealed class MyopiaSystem : EntitySystem
{
[Dependency] private readonly INetManager _net = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly BlindableSystem _blinding = default!;

/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<MyopiaComponent, ComponentStartup>(OnStartup);
SubscribeLocalEvent<MyopiaComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<MyopiaComponent, EyeDamageChangedEvent>(OnDamageChanged);

}

private void OnStartup(EntityUid uid, MyopiaComponent component, ComponentStartup args)
{
if (!TryComp<BlindableComponent>(uid, out var blindable))
return;
_blinding.AdjustEyeDamage((uid, blindable), component.EyeDamage);
}

private void OnShutdown(EntityUid uid, MyopiaComponent component, ComponentShutdown args)
{
if (!TryComp<BlindableComponent>(uid, out var blindable))
return;
_blinding.AdjustEyeDamage((uid, blindable), -component.EyeDamage);
}

private void OnDamageChanged(EntityUid uid, MyopiaComponent component, ref EyeDamageChangedEvent args)
{
if (!TryComp<BlindableComponent>(uid, out var blindable))
return;
if (!component.Active)
return;
if (blindable.EyeDamage < component.EyeDamage)
_blinding.AdjustEyeDamage((uid, blindable), (component.EyeDamage - blindable.EyeDamage));

}
}
1 change: 1 addition & 0 deletions Resources/Prototypes/Entities/Clothing/Eyes/glasses.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
name: glasses
description: A pair of spectacular spectacles with prescription lenses.
components:
- type: Glasses
- type: Sprite
sprite: Clothing/Eyes/Glasses/glasses.rsi
- type: Clothing
Expand Down
Loading