Bows & arrows (#19771)
This commit is contained in:
@@ -29,6 +29,12 @@ public sealed partial class EmbeddableProjectileComponent : Component
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("removalTime"), AutoNetworkedField]
|
||||
public float? RemovalTime = 3f;
|
||||
|
||||
/// <summary>
|
||||
/// Whether this entity will embed when thrown, or only when shot as a projectile.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("embedOnThrow"), AutoNetworkedField]
|
||||
public bool EmbedOnThrow = true;
|
||||
|
||||
/// <summary>
|
||||
/// How far into the entity should we offset (0 is wherever we collided).
|
||||
/// </summary>
|
||||
|
||||
@@ -15,13 +15,14 @@ public sealed partial class ProjectileComponent : Component
|
||||
/// <summary>
|
||||
/// User that shot this projectile.
|
||||
/// </summary>
|
||||
[DataField("shooter"), AutoNetworkedField] public EntityUid Shooter;
|
||||
[DataField("shooter"), AutoNetworkedField]
|
||||
public EntityUid? Shooter;
|
||||
|
||||
/// <summary>
|
||||
/// Weapon used to shoot.
|
||||
/// </summary>
|
||||
[DataField("weapon"), AutoNetworkedField]
|
||||
public EntityUid Weapon;
|
||||
public EntityUid? Weapon;
|
||||
|
||||
[DataField("ignoreShooter"), AutoNetworkedField]
|
||||
public bool IgnoreShooter = true;
|
||||
@@ -41,5 +42,14 @@ public sealed partial class ProjectileComponent : Component
|
||||
[DataField("soundForce")]
|
||||
public bool ForceSound = false;
|
||||
|
||||
/// <summary>
|
||||
/// Whether this projectile will only collide with entities if it was shot from a gun (if <see cref="Weapon"/> is not null)
|
||||
/// </summary>
|
||||
[DataField("onlyCollideWhenShot")]
|
||||
public bool OnlyCollideWhenShot = false;
|
||||
|
||||
/// <summary>
|
||||
/// Whether this projectile has already damaged an entity.
|
||||
/// </summary>
|
||||
public bool DamagedEntity;
|
||||
}
|
||||
|
||||
@@ -73,6 +73,14 @@ public abstract partial class SharedProjectileSystem : EntitySystem
|
||||
_physics.SetBodyType(uid, BodyType.Dynamic, body: physics, xform: xform);
|
||||
_transform.AttachToGridOrMap(uid, xform);
|
||||
|
||||
// Reset whether the projectile has damaged anything if it successfully was removed
|
||||
if (TryComp<ProjectileComponent>(uid, out var projectile))
|
||||
{
|
||||
projectile.Shooter = null;
|
||||
projectile.Weapon = null;
|
||||
projectile.DamagedEntity = false;
|
||||
}
|
||||
|
||||
// Land it just coz uhhh yeah
|
||||
var landEv = new LandEvent(args.User, true);
|
||||
RaiseLocalEvent(uid, ref landEv);
|
||||
@@ -81,6 +89,9 @@ public abstract partial class SharedProjectileSystem : EntitySystem
|
||||
|
||||
private void OnEmbedThrowDoHit(EntityUid uid, EmbeddableProjectileComponent component, ThrowDoHitEvent args)
|
||||
{
|
||||
if (!component.EmbedOnThrow)
|
||||
return;
|
||||
|
||||
Embed(uid, args.Target, component);
|
||||
}
|
||||
|
||||
@@ -91,7 +102,7 @@ public abstract partial class SharedProjectileSystem : EntitySystem
|
||||
// Raise a specific event for projectiles.
|
||||
if (TryComp<ProjectileComponent>(uid, out var projectile))
|
||||
{
|
||||
var ev = new ProjectileEmbedEvent(projectile.Shooter, projectile.Weapon, args.Target);
|
||||
var ev = new ProjectileEmbedEvent(projectile.Shooter!.Value, projectile.Weapon!.Value, args.Target);
|
||||
RaiseLocalEvent(uid, ref ev);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user