--- /dev/null
+using Content.Shared.Damage.Systems;
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Damage.Components;
+
+/// <summary>
+/// Applies stamina damage when embeds in an entity.
+/// </summary>
+[RegisterComponent]
+[NetworkedComponent]
+[AutoGenerateComponentState]
+[Access(typeof(StaminaSystem))]
+public sealed partial class StaminaDamageOnEmbedComponent : Component
+{
+ [ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
+ public float Damage = 10f;
+}
SubscribeLocalEvent<StaminaComponent, DisarmedEvent>(OnDisarmed);
SubscribeLocalEvent<StaminaComponent, RejuvenateEvent>(OnRejuvenate);
+ SubscribeLocalEvent<StaminaDamageOnEmbedComponent, EmbedEvent>(OnProjectileEmbed);
+
SubscribeLocalEvent<StaminaDamageOnCollideComponent, ProjectileHitEvent>(OnProjectileHit);
SubscribeLocalEvent<StaminaDamageOnCollideComponent, ThrowDoHitEvent>(OnThrowHit);
+
SubscribeLocalEvent<StaminaDamageOnHitComponent, MeleeHitEvent>(OnMeleeHit);
}
component.StaminaDamage = 0;
RemComp<ActiveStaminaComponent>(uid);
SetStaminaAlert(uid, component);
- Dirty(component);
+ Dirty(uid, component);
}
private void OnDisarmed(EntityUid uid, StaminaComponent component, DisarmedEvent args)
OnCollide(uid, component, args.Target);
}
+ private void OnProjectileEmbed(EntityUid uid, StaminaDamageOnEmbedComponent component, ref EmbedEvent args)
+ {
+ if (!TryComp<StaminaComponent>(args.Embedded, out var stamina))
+ return;
+
+ TakeStaminaDamage(args.Embedded, component.Damage, stamina, source: uid);
+ }
+
private void OnThrowHit(EntityUid uid, StaminaDamageOnCollideComponent component, ThrowDoHitEvent args)
{
OnCollide(uid, component, args.Target);
--- /dev/null
+namespace Content.Shared.Projectiles;
+
+/// <summary>
+/// Raised directed on an entity when it embeds in another entity.
+/// </summary>
+[ByRefEvent]
+public readonly record struct EmbedEvent(EntityUid? Shooter, EntityUid Embedded)
+{
+ public readonly EntityUid? Shooter = Shooter;
+
+ /// <summary>
+ /// Entity that is embedded in.
+ /// </summary>
+ public readonly EntityUid Embedded = Embedded;
+}
/// Raised directed on an entity when it embeds into something.
/// </summary>
[ByRefEvent]
-public readonly record struct ProjectileEmbedEvent(EntityUid Shooter, EntityUid Weapon, EntityUid Embedded);
+public readonly record struct ProjectileEmbedEvent(EntityUid? Shooter, EntityUid Weapon, EntityUid Embedded);
if (!component.EmbedOnThrow)
return;
- Embed(uid, args.Target, component);
+ Embed(uid, args.Target, null, component);
}
private void OnEmbedProjectileHit(EntityUid uid, EmbeddableProjectileComponent component, ref ProjectileHitEvent args)
{
- Embed(uid, args.Target, component);
+ Embed(uid, args.Target, args.Shooter, component);
// Raise a specific event for projectiles.
- if (TryComp<ProjectileComponent>(uid, out var projectile))
+ if (TryComp(uid, out ProjectileComponent? projectile))
{
var ev = new ProjectileEmbedEvent(projectile.Shooter!.Value, projectile.Weapon!.Value, args.Target);
RaiseLocalEvent(uid, ref ev);
}
}
- private void Embed(EntityUid uid, EntityUid target, EmbeddableProjectileComponent component)
+ private void Embed(EntityUid uid, EntityUid target, EntityUid? user, EmbeddableProjectileComponent component)
{
TryComp<PhysicsComponent>(uid, out var physics);
_physics.SetLinearVelocity(uid, Vector2.Zero, body: physics);
if (component.Offset != Vector2.Zero)
{
- _transform.SetLocalPosition(xform, xform.LocalPosition + xform.LocalRotation.RotateVec(component.Offset));
+ _transform.SetLocalPosition(uid, xform.LocalPosition + xform.LocalRotation.RotateVec(component.Offset),
+ xform);
}
- if (component.Sound != null)
- {
- _audio.PlayPredicted(component.Sound, uid, null);
- }
+ _audio.PlayPredicted(component.Sound, uid, null);
+ var ev = new EmbedEvent(user, target);
+ RaiseLocalEvent(uid, ref ev);
}
private void PreventCollision(EntityUid uid, ProjectileComponent component, ref PreventCollideEvent args)
types:
Slash: 8
Piercing: 10
+ - type: StaminaDamageOnCollide
+ damage: 45
+ - type: StaminaDamageOnEmbed
+ damage: 10
- type: entity
parent: ThrowingStar