Guitar Smashing (#17724)
This commit is contained in:
18
Content.Server/Damage/Components/DamageOnHitComponent.cs
Normal file
18
Content.Server/Damage/Components/DamageOnHitComponent.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using Content.Shared.Damage;
|
||||
|
||||
|
||||
// Damages the held item by a set amount when it hits someone. Can be used to make melee items limited-use.
|
||||
namespace Content.Server.Damage.Components;
|
||||
|
||||
[RegisterComponent]
|
||||
public sealed class DamageOnHitComponent : Component
|
||||
{
|
||||
[DataField("ignoreResistances")]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool IgnoreResistances = true;
|
||||
|
||||
[DataField("damage", required: true)]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public DamageSpecifier Damage = default!;
|
||||
}
|
||||
|
||||
22
Content.Server/Damage/Systems/DamageOnHitSystem.cs
Normal file
22
Content.Server/Damage/Systems/DamageOnHitSystem.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using Content.Server.Damage.Components;
|
||||
using Content.Shared.Damage;
|
||||
using Robust.Shared.Player;
|
||||
using Content.Shared.Weapons.Melee.Events;
|
||||
|
||||
namespace Content.Server.Damage.Systems;
|
||||
|
||||
public sealed class DamageOnHitSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<DamageOnHitComponent, MeleeHitEvent>(DamageItem);
|
||||
}
|
||||
// Looks for a hit, then damages the held item an appropriate amount.
|
||||
private void DamageItem(EntityUid uid, DamageOnHitComponent component, MeleeHitEvent args)
|
||||
{
|
||||
_damageableSystem.TryChangeDamage(uid, component.Damage, component.IgnoreResistances);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user