Emp Flashlight (#5)

* EmpFlashlight added

* Using namespace cleared

* Code Review problems solved
This commit is contained in:
Ivan
2024-08-23 05:53:41 +03:00
committed by GitHub
parent 0d8fdc6b8b
commit 932f1f6c7e
7 changed files with 117 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
using Content.Server._White.EmpFlashlight;
using Content.Server.Emp;
namespace Content.Server._White.EmpFlashlight;
/// <summary>
/// Upon being triggered will EMP target.
/// </summary>
[RegisterComponent]
[Access(typeof(EmpOnHitSystem))]
public sealed partial class EmpOnHitComponent: Component
{
[DataField("range"), ViewVariables(VVAccess.ReadWrite)]
public float Range = 1.0f;
[DataField("energyConsumption"), ViewVariables(VVAccess.ReadWrite)]
public float EnergyConsumption;
[DataField("disableDuration"), ViewVariables(VVAccess.ReadWrite)]
public float DisableDuration = 60f;
}

View File

@@ -0,0 +1,52 @@
using Content.Shared.Weapons.Melee.Events;
using Content.Server.Emp;
using Content.Shared.Charges.Systems;
using Content.Shared.Charges.Components;
namespace Content.Server._White.EmpFlashlight;
public sealed class EmpOnHitSystem : EntitySystem
{
[Dependency] private readonly EmpSystem _emp = default!;
[Dependency] private readonly SharedChargesSystem _charges = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<EmpOnHitComponent, MeleeHitEvent>(HandleEmpHit);
}
public bool TryEmpHit(EntityUid uid, EmpOnHitComponent comp, MeleeHitEvent args)
{
if (!TryComp<LimitedChargesComponent>(uid, out LimitedChargesComponent? charges))
return false;
if (_charges.IsEmpty(uid, charges))
return false;
if (args.HitEntities.Count > 0)
{
_charges.UseCharge(uid,charges);
return true;
}
return false;
}
private void HandleEmpHit(EntityUid uid, EmpOnHitComponent comp, MeleeHitEvent args)
{
if (!TryEmpHit(uid, comp, args))
return;
foreach (var affected in args.HitEntities)
{
_emp.EmpPulse(_transform.GetMapCoordinates(affected), comp.Range, comp.EnergyConsumption, comp.DisableDuration);
}
args.Handled = true;
}
}

View File

@@ -0,0 +1,2 @@
uplink-emp-flashlight-name = Emp Flashlight
uplink-emp-flashlight-desc = A rechargeable device disguised as a flashlight designed to disrupt electronic systems. Useful for disrupting communications, security's energy weapons, and APCs when you're in a tight spot.

View File

@@ -0,0 +1,2 @@
ent-FlashlightEmp = Фонарик
.desc = Он озаряет путь к свободе.

View File

@@ -0,0 +1,2 @@
uplink-emp-flashlight-name = Электромагнитный фонарик
uplink-emp-flashlight-desc = Замаскированное под фонарик устройство. При ударе выпускает ЭМИ, поражающий электрические устройства.

View File

@@ -0,0 +1,9 @@
- type: listing
id: UplinkEmpFlashlight
name: uplink-emp-flashlight-name
description: uplink-emp-flashlight-desc
productEntity: FlashlightEmp
cost:
Telecrystal: 3
categories:
- UplinkUtility

View File

@@ -0,0 +1,26 @@
- type: entity
parent: FlashlightLantern
id: FlashlightEmp
name: flashlight
description: It lights the way to freedom.
suffix: EMP
components:
- type: ItemSlots
slots:
cell_slot:
name: power-cell-clot-component-spot-name-default
startingItem: PowerCellHigh
- type: MeleeWeapon
wideAnimationRotation: -135
damage:
types:
Blunt: 12
angle: 60
animation: WeaponArcThrust
- type: EmpOnHit
range: 0.1
energyConsumption: 100000
disableDuration: 100
- type: LimitedCharges
- type: AutoRecharge
rechargeDuration: 60