blinding networking (#12937)

This commit is contained in:
Rane
2022-12-10 15:26:17 -05:00
committed by GitHub
parent 819853bffa
commit 2b69854ed7
2 changed files with 29 additions and 0 deletions

View File

@@ -1,4 +1,5 @@
using Robust.Shared.GameStates; using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
namespace Content.Shared.Eye.Blinding namespace Content.Shared.Eye.Blinding
{ {
@@ -41,4 +42,15 @@ namespace Content.Shared.Eye.Blinding
/// </description> /// </description>
public bool GraceFrame = false; public bool GraceFrame = false;
} }
[Serializable, NetSerializable]
public sealed class BlindableComponentState : ComponentState
{
public readonly int Sources;
public BlindableComponentState(int sources)
{
Sources = sources;
}
}
} }

View File

@@ -14,6 +14,10 @@ namespace Content.Shared.Eye.Blinding
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
SubscribeLocalEvent<BlindableComponent, ComponentGetState>(OnGetBlindableState);
SubscribeLocalEvent<BlindableComponent, ComponentHandleState>(OnHandleBlindableState);
SubscribeLocalEvent<BlindfoldComponent, GotEquippedEvent>(OnEquipped); SubscribeLocalEvent<BlindfoldComponent, GotEquippedEvent>(OnEquipped);
SubscribeLocalEvent<BlindfoldComponent, GotUnequippedEvent>(OnUnequipped); SubscribeLocalEvent<BlindfoldComponent, GotUnequippedEvent>(OnUnequipped);
@@ -28,6 +32,19 @@ namespace Content.Shared.Eye.Blinding
SubscribeLocalEvent<BlindableComponent, RejuvenateEvent>(OnRejuvenate); SubscribeLocalEvent<BlindableComponent, RejuvenateEvent>(OnRejuvenate);
} }
private void OnGetBlindableState(EntityUid uid, BlindableComponent component, ref ComponentGetState args)
{
args.State = new BlindableComponentState(component.Sources);
}
private void OnHandleBlindableState(EntityUid uid, BlindableComponent component, ref ComponentHandleState args)
{
if (args.Current is not BlindableComponentState cast)
return;
component.Sources = cast.Sources;
}
private void OnEquipped(EntityUid uid, BlindfoldComponent component, GotEquippedEvent args) private void OnEquipped(EntityUid uid, BlindfoldComponent component, GotEquippedEvent args)
{ {
if (!TryComp<ClothingComponent>(uid, out var clothing) || clothing.Slots == SlotFlags.PREVENTEQUIP) // we live in a society if (!TryComp<ClothingComponent>(uid, out var clothing) || clothing.Slots == SlotFlags.PREVENTEQUIP) // we live in a society