Files
tbd-station-14/Content.Shared/Electrocution/SharedElectrocutionSystem.cs
Fildrance 4bcf3c3c0e Station AI ability to electricute doors (#32012)
* Boom! Emergency access!

* Emergency access sound

* locale

* Updated sounds

* bleh

* Door electrify base

* feat: popups on attempt to activate AI action when wires cut

* refactor: use SharedApcPowerReceiverComponent to check if AI can interact with door

* refactor: added icon and sound for door overcharge

* meta.json should use tabs not spaces

* refactor: extracted sounds for airlock overcharge to static field in system

* refactor: cleanup, ScarKy0 mentions for resources

* refactor: removed unused textures

* feat: now notification is displayed when AI attempting to interact with door which have wire cut

* StationAiWhitelistComponent is properly gating  BUI OnMessageAttempt, SharedPowerReceiverSystem.IsPowered is now used to check if device powered

* refactor: use PlayLocal to play electrify sound only for AI player

* refactor: SetBoltsDown now uses TrySetBoltDown, checks for power.

* bolts now check for power using SharedPowerReceiverSystem

* electrify localization and louder electrify sounds

* extracted ShowDeviceNotRespondingPopup, reverted airlocks not opening/closing when ai wire was cut

* refactor: cleanup

* New sprites and fixes

* Copyright

* even more sprite changes

* refactore: cleanup, rename overcharge => electrify

---------

Co-authored-by: ScarKy0 <scarky0@onet.eu>
Co-authored-by: pa.pecherskij <pa.pecherskij@interfax.ru>
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
2024-09-27 17:22:17 +10:00

63 lines
2.8 KiB
C#

using Content.Shared.Inventory;
using Content.Shared.StatusEffect;
namespace Content.Shared.Electrocution
{
public abstract class SharedElectrocutionSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<InsulatedComponent, ElectrocutionAttemptEvent>(OnInsulatedElectrocutionAttempt);
// as long as legally distinct electric-mice are never added, this should be fine (otherwise a mouse-hat will transfer it's power to the wearer).
SubscribeLocalEvent<InsulatedComponent, InventoryRelayedEvent<ElectrocutionAttemptEvent>>((e, c, ev) => OnInsulatedElectrocutionAttempt(e, c, ev.Args));
}
public void SetInsulatedSiemensCoefficient(EntityUid uid, float siemensCoefficient, InsulatedComponent? insulated = null)
{
if (!Resolve(uid, ref insulated))
return;
insulated.Coefficient = siemensCoefficient;
Dirty(uid, insulated);
}
/// <summary>
/// Sets electrified value of component and marks dirty if required.
/// </summary>
public void SetElectrified(Entity<ElectrifiedComponent> ent, bool value)
{
if (ent.Comp.Enabled == value)
{
return;
}
ent.Comp.Enabled = value;
Dirty(ent, ent.Comp);
}
/// <param name="uid">Entity being electrocuted.</param>
/// <param name="sourceUid">Source entity of the electrocution.</param>
/// <param name="shockDamage">How much shock damage the entity takes.</param>
/// <param name="time">How long the entity will be stunned.</param>
/// <param name="refresh">Should <paramref>time</paramref> be refreshed (instead of accumilated) if the entity is already electrocuted?</param>
/// <param name="siemensCoefficient">How insulated the entity is from the shock. 0 means completely insulated, and 1 means no insulation.</param>
/// <param name="statusEffects">Status effects to apply to the entity.</param>
/// <param name="ignoreInsulation">Should the electrocution bypass the Insulated component?</param>
/// <returns>Whether the entity <see cref="uid"/> was stunned by the shock.</returns>
public virtual bool TryDoElectrocution(
EntityUid uid, EntityUid? sourceUid, int shockDamage, TimeSpan time, bool refresh, float siemensCoefficient = 1f,
StatusEffectsComponent? statusEffects = null, bool ignoreInsulation = false)
{
// only done serverside
return false;
}
private void OnInsulatedElectrocutionAttempt(EntityUid uid, InsulatedComponent insulated, ElectrocutionAttemptEvent args)
{
args.SiemensCoefficient *= insulated.Coefficient;
}
}
}