Electrocution. (#4958)
Co-authored-by: Pieter-Jan Briers <pieterjan.briers@gmail.com>
This commit is contained in:
committed by
GitHub
parent
66a3d5bf29
commit
ed3bf94a3b
10
Content.Shared/Electrocution/ElectrocutedComponent.cs
Normal file
10
Content.Shared/Electrocution/ElectrocutedComponent.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Shared.Electrocution
|
||||
{
|
||||
[RegisterComponent]
|
||||
public sealed class ElectrocutedComponent : Component
|
||||
{
|
||||
public override string Name => "Electrocuted";
|
||||
}
|
||||
}
|
||||
32
Content.Shared/Electrocution/ElectrocutionEvents.cs
Normal file
32
Content.Shared/Electrocution/ElectrocutionEvents.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Shared.Electrocution
|
||||
{
|
||||
public class ElectrocutionAttemptEvent : CancellableEntityEventArgs
|
||||
{
|
||||
public readonly EntityUid TargetUid;
|
||||
public readonly EntityUid? SourceUid;
|
||||
public float SiemensCoefficient = 1f;
|
||||
|
||||
public ElectrocutionAttemptEvent(EntityUid targetUid, EntityUid? sourceUid, float siemensCoefficient)
|
||||
{
|
||||
TargetUid = targetUid;
|
||||
SourceUid = sourceUid;
|
||||
SiemensCoefficient = siemensCoefficient;
|
||||
}
|
||||
}
|
||||
|
||||
public class ElectrocutedEvent : EntityEventArgs
|
||||
{
|
||||
public readonly EntityUid TargetUid;
|
||||
public readonly EntityUid? SourceUid;
|
||||
public readonly float SiemensCoefficient;
|
||||
|
||||
public ElectrocutedEvent(EntityUid targetUid, EntityUid? sourceUid, float siemensCoefficient)
|
||||
{
|
||||
TargetUid = targetUid;
|
||||
SourceUid = sourceUid;
|
||||
SiemensCoefficient = siemensCoefficient;
|
||||
}
|
||||
}
|
||||
}
|
||||
35
Content.Shared/Electrocution/InsulatedComponent.cs
Normal file
35
Content.Shared/Electrocution/InsulatedComponent.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using Robust.Shared.Analyzers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Shared.Electrocution
|
||||
{
|
||||
[Friend(typeof(SharedElectrocutionSystem))]
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
public class InsulatedComponent : Component
|
||||
{
|
||||
public override string Name => "Insulated";
|
||||
|
||||
/// <summary>
|
||||
/// Siemens coefficient. Zero means completely insulated.
|
||||
/// </summary>
|
||||
[DataField("coefficient")]
|
||||
public float SiemensCoefficient { get; set; } = 0f;
|
||||
}
|
||||
|
||||
// Technically, people could cheat and figure out which budget insulated gloves are gud and which ones are bad.
|
||||
// We might want to rethink this a little bit.
|
||||
[NetSerializable, Serializable]
|
||||
public class InsulatedComponentState : ComponentState
|
||||
{
|
||||
public float SiemensCoefficient { get; private set; }
|
||||
|
||||
public InsulatedComponentState(float siemensCoefficient)
|
||||
{
|
||||
SiemensCoefficient = siemensCoefficient;
|
||||
}
|
||||
}
|
||||
}
|
||||
45
Content.Shared/Electrocution/SharedElectrocutionSystem.cs
Normal file
45
Content.Shared/Electrocution/SharedElectrocutionSystem.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Electrocution
|
||||
{
|
||||
public abstract class SharedElectrocutionSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<InsulatedComponent, ElectrocutionAttemptEvent>(OnInsulatedElectrocutionAttempt);
|
||||
SubscribeLocalEvent<InsulatedComponent, ComponentGetState>(OnInsulatedGetState);
|
||||
SubscribeLocalEvent<InsulatedComponent, ComponentHandleState>(OnInsulatedHandleState);
|
||||
}
|
||||
|
||||
public void SetInsulatedSiemensCoefficient(EntityUid uid, float siemensCoefficient, InsulatedComponent? insulated = null)
|
||||
{
|
||||
if (!Resolve(uid, ref insulated))
|
||||
return;
|
||||
|
||||
insulated.SiemensCoefficient = siemensCoefficient;
|
||||
insulated.Dirty();
|
||||
}
|
||||
|
||||
private void OnInsulatedElectrocutionAttempt(EntityUid uid, InsulatedComponent insulated, ElectrocutionAttemptEvent args)
|
||||
{
|
||||
args.SiemensCoefficient *= insulated.SiemensCoefficient;
|
||||
}
|
||||
|
||||
private void OnInsulatedGetState(EntityUid uid, InsulatedComponent insulated, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new InsulatedComponentState(insulated.SiemensCoefficient);
|
||||
}
|
||||
|
||||
private void OnInsulatedHandleState(EntityUid uid, InsulatedComponent insulated, ref ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is not InsulatedComponentState state)
|
||||
return;
|
||||
|
||||
insulated.SiemensCoefficient = state.SiemensCoefficient;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user