add throwing star (#18700)
Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
|
using Robust.Shared.Audio;
|
||||||
using Robust.Shared.GameStates;
|
using Robust.Shared.GameStates;
|
||||||
|
|
||||||
namespace Content.Shared.Projectiles;
|
namespace Content.Shared.Projectiles;
|
||||||
@@ -33,4 +34,10 @@ public sealed partial class EmbeddableProjectileComponent : Component
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[ViewVariables(VVAccess.ReadWrite), DataField("offset"), AutoNetworkedField]
|
[ViewVariables(VVAccess.ReadWrite), DataField("offset"), AutoNetworkedField]
|
||||||
public Vector2 Offset = Vector2.Zero;
|
public Vector2 Offset = Vector2.Zero;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sound to play after embedding into a hit target.
|
||||||
|
/// </summary>
|
||||||
|
[ViewVariables(VVAccess.ReadWrite), DataField("sound"), AutoNetworkedField]
|
||||||
|
public SoundSpecifier? Sound;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using Content.Shared.Projectiles;
|
|||||||
using Content.Shared.Sound.Components;
|
using Content.Shared.Sound.Components;
|
||||||
using Content.Shared.Throwing;
|
using Content.Shared.Throwing;
|
||||||
using Content.Shared.Weapons.Ranged.Components;
|
using Content.Shared.Weapons.Ranged.Components;
|
||||||
|
using Robust.Shared.Audio;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
using Robust.Shared.Network;
|
using Robust.Shared.Network;
|
||||||
using Robust.Shared.Physics;
|
using Robust.Shared.Physics;
|
||||||
@@ -13,145 +14,151 @@ using Robust.Shared.Physics.Events;
|
|||||||
using Robust.Shared.Physics.Systems;
|
using Robust.Shared.Physics.Systems;
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
|
|
||||||
namespace Content.Shared.Projectiles
|
namespace Content.Shared.Projectiles;
|
||||||
|
|
||||||
|
public abstract class SharedProjectileSystem : EntitySystem
|
||||||
{
|
{
|
||||||
public abstract class SharedProjectileSystem : EntitySystem
|
public const string ProjectileFixture = "projectile";
|
||||||
|
|
||||||
|
[Dependency] private readonly INetManager _netManager = default!;
|
||||||
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||||
|
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
|
||||||
|
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
||||||
|
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||||
|
|
||||||
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
public const string ProjectileFixture = "projectile";
|
base.Initialize();
|
||||||
|
|
||||||
[Dependency] private readonly INetManager _netManager = default!;
|
SubscribeLocalEvent<ProjectileComponent, PreventCollideEvent>(PreventCollision);
|
||||||
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
|
SubscribeLocalEvent<EmbeddableProjectileComponent, ProjectileHitEvent>(OnEmbedProjectileHit);
|
||||||
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
SubscribeLocalEvent<EmbeddableProjectileComponent, ThrowDoHitEvent>(OnEmbedThrowDoHit);
|
||||||
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
SubscribeLocalEvent<EmbeddableProjectileComponent, ActivateInWorldEvent>(OnEmbedActivate);
|
||||||
|
SubscribeLocalEvent<EmbeddableProjectileComponent, RemoveEmbeddedProjectileEvent>(OnEmbedRemove);
|
||||||
|
}
|
||||||
|
|
||||||
public override void Initialize()
|
private void OnEmbedActivate(EntityUid uid, EmbeddableProjectileComponent component, ActivateInWorldEvent args)
|
||||||
|
{
|
||||||
|
// Nuh uh
|
||||||
|
if (component.RemovalTime == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (args.Handled || !TryComp<PhysicsComponent>(uid, out var physics) || physics.BodyType != BodyType.Static)
|
||||||
|
return;
|
||||||
|
|
||||||
|
args.Handled = true;
|
||||||
|
|
||||||
|
_doAfter.TryStartDoAfter(new DoAfterArgs(args.User, component.RemovalTime.Value,
|
||||||
|
new RemoveEmbeddedProjectileEvent(), eventTarget: uid, target: uid)
|
||||||
{
|
{
|
||||||
base.Initialize();
|
DistanceThreshold = SharedInteractionSystem.InteractionRange,
|
||||||
SubscribeLocalEvent<ProjectileComponent, PreventCollideEvent>(PreventCollision);
|
});
|
||||||
SubscribeLocalEvent<EmbeddableProjectileComponent, ProjectileHitEvent>(OnEmbedProjectileHit);
|
}
|
||||||
SubscribeLocalEvent<EmbeddableProjectileComponent, ThrowDoHitEvent>(OnEmbedThrowDoHit);
|
|
||||||
SubscribeLocalEvent<EmbeddableProjectileComponent, ActivateInWorldEvent>(OnEmbedActivate);
|
private void OnEmbedRemove(EntityUid uid, EmbeddableProjectileComponent component, RemoveEmbeddedProjectileEvent args)
|
||||||
SubscribeLocalEvent<EmbeddableProjectileComponent, RemoveEmbeddedProjectileEvent>(OnEmbedRemove);
|
{
|
||||||
|
// Whacky prediction issues.
|
||||||
|
if (args.Cancelled || _netManager.IsClient)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (component.DeleteOnRemove)
|
||||||
|
{
|
||||||
|
QueueDel(uid);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnEmbedActivate(EntityUid uid, EmbeddableProjectileComponent component, ActivateInWorldEvent args)
|
var xform = Transform(uid);
|
||||||
|
TryComp<PhysicsComponent>(uid, out var physics);
|
||||||
|
_physics.SetBodyType(uid, BodyType.Dynamic, body: physics, xform: xform);
|
||||||
|
_transform.AttachToGridOrMap(uid, xform);
|
||||||
|
|
||||||
|
// Land it just coz uhhh yeah
|
||||||
|
var landEv = new LandEvent(args.User, true);
|
||||||
|
RaiseLocalEvent(uid, ref landEv);
|
||||||
|
_physics.WakeBody(uid, body: physics);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnEmbedThrowDoHit(EntityUid uid, EmbeddableProjectileComponent component, ThrowDoHitEvent args)
|
||||||
|
{
|
||||||
|
Embed(uid, args.Target, component);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnEmbedProjectileHit(EntityUid uid, EmbeddableProjectileComponent component, ref ProjectileHitEvent args)
|
||||||
|
{
|
||||||
|
Embed(uid, args.Target, component);
|
||||||
|
|
||||||
|
// Raise a specific event for projectiles.
|
||||||
|
if (TryComp<ProjectileComponent>(uid, out var projectile))
|
||||||
{
|
{
|
||||||
// Nuh uh
|
var ev = new ProjectileEmbedEvent(projectile.Shooter, projectile.Weapon, args.Target);
|
||||||
if (component.RemovalTime == null)
|
RaiseLocalEvent(uid, ref ev);
|
||||||
return;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (args.Handled || !TryComp<PhysicsComponent>(uid, out var physics) || physics.BodyType != BodyType.Static)
|
private void Embed(EntityUid uid, EntityUid target, EmbeddableProjectileComponent component)
|
||||||
return;
|
{
|
||||||
|
TryComp<PhysicsComponent>(uid, out var physics);
|
||||||
|
_physics.SetLinearVelocity(uid, Vector2.Zero, body: physics);
|
||||||
|
_physics.SetBodyType(uid, BodyType.Static, body: physics);
|
||||||
|
var xform = Transform(uid);
|
||||||
|
_transform.SetParent(uid, xform, target);
|
||||||
|
|
||||||
args.Handled = true;
|
if (component.Offset != Vector2.Zero)
|
||||||
|
{
|
||||||
_doAfter.TryStartDoAfter(new DoAfterArgs(args.User, component.RemovalTime.Value,
|
_transform.SetLocalPosition(xform, xform.LocalPosition + xform.LocalRotation.RotateVec(component.Offset));
|
||||||
new RemoveEmbeddedProjectileEvent(), eventTarget: uid, target: uid)
|
|
||||||
{
|
|
||||||
DistanceThreshold = SharedInteractionSystem.InteractionRange,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnEmbedRemove(EntityUid uid, EmbeddableProjectileComponent component, RemoveEmbeddedProjectileEvent args)
|
if (component.Sound != null)
|
||||||
{
|
{
|
||||||
// Whacky prediction issues.
|
_audio.PlayPredicted(component.Sound, uid, null);
|
||||||
if (args.Cancelled || _netManager.IsClient)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (component.DeleteOnRemove)
|
|
||||||
{
|
|
||||||
QueueDel(uid);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var xform = Transform(uid);
|
|
||||||
TryComp<PhysicsComponent>(uid, out var physics);
|
|
||||||
_physics.SetBodyType(uid, BodyType.Dynamic, body: physics, xform: xform);
|
|
||||||
_transform.AttachToGridOrMap(uid, xform);
|
|
||||||
|
|
||||||
// Land it just coz uhhh yeah
|
|
||||||
var landEv = new LandEvent(args.User, true);
|
|
||||||
RaiseLocalEvent(uid, ref landEv);
|
|
||||||
_physics.WakeBody(uid, body: physics);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void OnEmbedThrowDoHit(EntityUid uid, EmbeddableProjectileComponent component, ThrowDoHitEvent args)
|
private void PreventCollision(EntityUid uid, ProjectileComponent component, ref PreventCollideEvent args)
|
||||||
|
{
|
||||||
|
if (component.IgnoreShooter && args.OtherEntity == component.Shooter)
|
||||||
{
|
{
|
||||||
Embed(uid, args.Target, component);
|
args.Cancelled = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void OnEmbedProjectileHit(EntityUid uid, EmbeddableProjectileComponent component, ref ProjectileHitEvent args)
|
public void SetShooter(ProjectileComponent component, EntityUid uid)
|
||||||
{
|
{
|
||||||
Embed(uid, args.Target, component);
|
if (component.Shooter == uid)
|
||||||
|
return;
|
||||||
|
|
||||||
// Raise a specific event for projectiles.
|
component.Shooter = uid;
|
||||||
if (TryComp<ProjectileComponent>(uid, out var projectile))
|
Dirty(uid, component);
|
||||||
{
|
|
||||||
var ev = new ProjectileEmbedEvent(projectile.Shooter, projectile.Weapon, args.Target);
|
|
||||||
RaiseLocalEvent(uid, ref ev);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Embed(EntityUid uid, EntityUid target, EmbeddableProjectileComponent component)
|
|
||||||
{
|
|
||||||
TryComp<PhysicsComponent>(uid, out var physics);
|
|
||||||
_physics.SetLinearVelocity(uid, Vector2.Zero, body: physics);
|
|
||||||
_physics.SetBodyType(uid, BodyType.Static, body: physics);
|
|
||||||
var xform = Transform(uid);
|
|
||||||
_transform.SetParent(uid, xform, target);
|
|
||||||
|
|
||||||
if (component.Offset != Vector2.Zero)
|
|
||||||
{
|
|
||||||
_transform.SetLocalPosition(xform, xform.LocalPosition + xform.LocalRotation.RotateVec(component.Offset));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void PreventCollision(EntityUid uid, ProjectileComponent component, ref PreventCollideEvent args)
|
|
||||||
{
|
|
||||||
if (component.IgnoreShooter && args.OtherEntity == component.Shooter)
|
|
||||||
{
|
|
||||||
args.Cancelled = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetShooter(ProjectileComponent component, EntityUid uid)
|
|
||||||
{
|
|
||||||
if (component.Shooter == uid)
|
|
||||||
return;
|
|
||||||
|
|
||||||
component.Shooter = uid;
|
|
||||||
Dirty(uid, component);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
|
||||||
private sealed class RemoveEmbeddedProjectileEvent : DoAfterEvent
|
|
||||||
{
|
|
||||||
public override DoAfterEvent Clone() => this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public sealed class ImpactEffectEvent : EntityEventArgs
|
private sealed class RemoveEmbeddedProjectileEvent : DoAfterEvent
|
||||||
{
|
{
|
||||||
public string Prototype;
|
public override DoAfterEvent Clone() => this;
|
||||||
public EntityCoordinates Coordinates;
|
|
||||||
|
|
||||||
public ImpactEffectEvent(string prototype, EntityCoordinates coordinates)
|
|
||||||
{
|
|
||||||
Prototype = prototype;
|
|
||||||
Coordinates = coordinates;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Raised when entity is just about to be hit with projectile but can reflect it
|
|
||||||
/// </summary>
|
|
||||||
[ByRefEvent]
|
|
||||||
public record struct ProjectileReflectAttemptEvent(EntityUid ProjUid, ProjectileComponent Component, bool Cancelled);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Raised when projectile hits other entity
|
|
||||||
/// </summary>
|
|
||||||
[ByRefEvent]
|
|
||||||
public readonly record struct ProjectileHitEvent(EntityUid Target);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Serializable, NetSerializable]
|
||||||
|
public sealed class ImpactEffectEvent : EntityEventArgs
|
||||||
|
{
|
||||||
|
public string Prototype;
|
||||||
|
public EntityCoordinates Coordinates;
|
||||||
|
|
||||||
|
public ImpactEffectEvent(string prototype, EntityCoordinates coordinates)
|
||||||
|
{
|
||||||
|
Prototype = prototype;
|
||||||
|
Coordinates = coordinates;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Raised when entity is just about to be hit with projectile but can reflect it
|
||||||
|
/// </summary>
|
||||||
|
[ByRefEvent]
|
||||||
|
public record struct ProjectileReflectAttemptEvent(EntityUid ProjUid, ProjectileComponent Component, bool Cancelled);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Raised when projectile hits other entity
|
||||||
|
/// </summary>
|
||||||
|
[ByRefEvent]
|
||||||
|
public readonly record struct ProjectileHitEvent(EntityUid Target);
|
||||||
|
|||||||
@@ -19,3 +19,12 @@
|
|||||||
copyright: "User Mystovski on freesound.org. Modified by LankLTE on github."
|
copyright: "User Mystovski on freesound.org. Modified by LankLTE on github."
|
||||||
source: "https://freesound.org/people/Mystovski/sounds/201111/"
|
source: "https://freesound.org/people/Mystovski/sounds/201111/"
|
||||||
|
|
||||||
|
- files: ["genhit3.ogg"]
|
||||||
|
license: "CC-BY-SA-3.0"
|
||||||
|
copyright: "Taken from tgstation."
|
||||||
|
source: "https://github.com/tgstation/tgstation/blob/a7f525bce9a359ab5282fc754078cd4b5678a006/sound/weapons/genhit3.ogg"
|
||||||
|
|
||||||
|
- files: ["star_hit.ogg"]
|
||||||
|
license: "CC-BY-SA-3.0"
|
||||||
|
copyright: "Based on genhit3.ogg from tgstation, modified by deltanedas on github."
|
||||||
|
source: "https://github.com/deltanedas"
|
||||||
|
|||||||
BIN
Resources/Audio/Weapons/star_hit.ogg
Normal file
BIN
Resources/Audio/Weapons/star_hit.ogg
Normal file
Binary file not shown.
@@ -0,0 +1,26 @@
|
|||||||
|
- type: entity
|
||||||
|
parent: BaseItem
|
||||||
|
id: ThrowingStar
|
||||||
|
name: throwing star
|
||||||
|
description: An ancient weapon still used to this day, due to its ease of lodging itself into its victim's body parts.
|
||||||
|
components:
|
||||||
|
- type: Sprite
|
||||||
|
sprite: Objects/Weapons/Throwable/throwing_star.rsi
|
||||||
|
state: icon
|
||||||
|
- type: Fixtures
|
||||||
|
fixtures:
|
||||||
|
fix1:
|
||||||
|
shape: !type:PhysShapeCircle
|
||||||
|
radius: 0.2
|
||||||
|
density: 5
|
||||||
|
mask:
|
||||||
|
- ItemMask
|
||||||
|
restitution: 0.3
|
||||||
|
friction: 0.2
|
||||||
|
- type: EmbeddableProjectile
|
||||||
|
sound: /Audio/Weapons/star_hit.ogg
|
||||||
|
- type: DamageOtherOnHit
|
||||||
|
damage:
|
||||||
|
types:
|
||||||
|
Slash: 8
|
||||||
|
Piercing: 10
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 676 B |
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"version": 1,
|
||||||
|
"license": "CC0-1.0",
|
||||||
|
"copyright": "Created for SS14 by deltanedas (github)",
|
||||||
|
"size": {
|
||||||
|
"x": 32,
|
||||||
|
"y": 32
|
||||||
|
},
|
||||||
|
"states": [
|
||||||
|
{
|
||||||
|
"name": "icon"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user