Make throwable star damage stamina (#23527)
* feat(star.yml): make throwable star damage stamina * feat(Components): add new StaminaTresholdDamageOnEmbedComponent * feat(SharedProjectileSystem): update system with new events to change stamins treshold on embeed projectile remove / add * feat(StaminaSystem): update system with new subscriptions * feat(throwing_stars): update yml with new component * feat(StaminaDamageOnEmbed): add stamina damage on embeed * cleanup unused / ajust numbers * fix(StaminaSystem / OnEmbedComponent ) apply requested changes * Rest of the review * another warning --------- Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
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;
|
||||
}
|
||||
@@ -55,8 +55,11 @@ public sealed partial class StaminaSystem : EntitySystem
|
||||
SubscribeLocalEvent<StaminaComponent, DisarmedEvent>(OnDisarmed);
|
||||
SubscribeLocalEvent<StaminaComponent, RejuvenateEvent>(OnRejuvenate);
|
||||
|
||||
SubscribeLocalEvent<StaminaDamageOnEmbedComponent, EmbedEvent>(OnProjectileEmbed);
|
||||
|
||||
SubscribeLocalEvent<StaminaDamageOnCollideComponent, ProjectileHitEvent>(OnProjectileHit);
|
||||
SubscribeLocalEvent<StaminaDamageOnCollideComponent, ThrowDoHitEvent>(OnThrowHit);
|
||||
|
||||
SubscribeLocalEvent<StaminaDamageOnHitComponent, MeleeHitEvent>(OnMeleeHit);
|
||||
}
|
||||
|
||||
@@ -114,7 +117,7 @@ public sealed partial class StaminaSystem : EntitySystem
|
||||
component.StaminaDamage = 0;
|
||||
RemComp<ActiveStaminaComponent>(uid);
|
||||
SetStaminaAlert(uid, component);
|
||||
Dirty(component);
|
||||
Dirty(uid, component);
|
||||
}
|
||||
|
||||
private void OnDisarmed(EntityUid uid, StaminaComponent component, DisarmedEvent args)
|
||||
@@ -192,6 +195,14 @@ public sealed partial class StaminaSystem : EntitySystem
|
||||
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);
|
||||
|
||||
15
Content.Shared/Projectiles/EmbedEvent.cs
Normal file
15
Content.Shared/Projectiles/EmbedEvent.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
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;
|
||||
}
|
||||
@@ -4,4 +4,4 @@ namespace Content.Shared.Projectiles;
|
||||
/// 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);
|
||||
|
||||
@@ -96,22 +96,22 @@ public abstract partial class SharedProjectileSystem : EntitySystem
|
||||
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);
|
||||
@@ -121,13 +121,13 @@ public abstract partial class SharedProjectileSystem : EntitySystem
|
||||
|
||||
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)
|
||||
|
||||
@@ -36,6 +36,10 @@
|
||||
types:
|
||||
Slash: 8
|
||||
Piercing: 10
|
||||
- type: StaminaDamageOnCollide
|
||||
damage: 45
|
||||
- type: StaminaDamageOnEmbed
|
||||
damage: 10
|
||||
|
||||
- type: entity
|
||||
parent: ThrowingStar
|
||||
|
||||
Reference in New Issue
Block a user