Prevent projectiles from being affected by TryThrow() (#16185)
This commit is contained in:
@@ -8,7 +8,9 @@ using Content.Shared.Explosion;
|
|||||||
using Content.Shared.FixedPoint;
|
using Content.Shared.FixedPoint;
|
||||||
using Content.Shared.Maps;
|
using Content.Shared.Maps;
|
||||||
using Content.Shared.Physics;
|
using Content.Shared.Physics;
|
||||||
|
using Content.Shared.Projectiles;
|
||||||
using Content.Shared.Spawners.Components;
|
using Content.Shared.Spawners.Components;
|
||||||
|
using Content.Shared.Tag;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
using Robust.Shared.Map.Components;
|
using Robust.Shared.Map.Components;
|
||||||
using Robust.Shared.Physics;
|
using Robust.Shared.Physics;
|
||||||
@@ -199,7 +201,8 @@ public sealed partial class ExplosionSystem : EntitySystem
|
|||||||
EntityQuery<TransformComponent> xformQuery,
|
EntityQuery<TransformComponent> xformQuery,
|
||||||
EntityQuery<DamageableComponent> damageQuery,
|
EntityQuery<DamageableComponent> damageQuery,
|
||||||
EntityQuery<PhysicsComponent> physicsQuery,
|
EntityQuery<PhysicsComponent> physicsQuery,
|
||||||
LookupFlags flags)
|
EntityQuery<TagComponent> tagQuery,
|
||||||
|
EntityQuery<ProjectileComponent> projectileQuery)
|
||||||
{
|
{
|
||||||
var gridBox = new Box2(tile * grid.TileSize, (tile + 1) * grid.TileSize);
|
var gridBox = new Box2(tile * grid.TileSize, (tile + 1) * grid.TileSize);
|
||||||
|
|
||||||
@@ -217,7 +220,7 @@ public sealed partial class ExplosionSystem : EntitySystem
|
|||||||
// process those entities
|
// process those entities
|
||||||
foreach (var xform in list)
|
foreach (var xform in list)
|
||||||
{
|
{
|
||||||
ProcessEntity(xform.Owner, epicenter, damage, throwForce, id, damageQuery, physicsQuery, xform);
|
ProcessEntity(xform.Owner, epicenter, damage, throwForce, id, xform, damageQuery, physicsQuery, xformQuery, tagQuery, projectileQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
// process anchored entities
|
// process anchored entities
|
||||||
@@ -226,7 +229,7 @@ public sealed partial class ExplosionSystem : EntitySystem
|
|||||||
foreach (var entity in anchoredList)
|
foreach (var entity in anchoredList)
|
||||||
{
|
{
|
||||||
processed.Add(entity);
|
processed.Add(entity);
|
||||||
ProcessEntity(entity, epicenter, damage, throwForce, id, damageQuery, physicsQuery);
|
ProcessEntity(entity, epicenter, damage, throwForce, id, null, damageQuery, physicsQuery, xformQuery, tagQuery, projectileQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Walls and reinforced walls will break into girders. These girders will also be considered turf-blocking for
|
// Walls and reinforced walls will break into girders. These girders will also be considered turf-blocking for
|
||||||
@@ -260,7 +263,7 @@ public sealed partial class ExplosionSystem : EntitySystem
|
|||||||
{
|
{
|
||||||
// Here we only throw, no dealing damage. Containers n such might drop their entities after being destroyed, but
|
// Here we only throw, no dealing damage. Containers n such might drop their entities after being destroyed, but
|
||||||
// they should handle their own damage pass-through, with their own damage reduction calculation.
|
// they should handle their own damage pass-through, with their own damage reduction calculation.
|
||||||
ProcessEntity(xform.Owner, epicenter, null, throwForce, id, damageQuery, physicsQuery, xform);
|
ProcessEntity(xform.Owner, epicenter, null, throwForce, id, xform, damageQuery, physicsQuery, xformQuery, tagQuery, projectileQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
return !tileBlocked;
|
return !tileBlocked;
|
||||||
@@ -299,7 +302,8 @@ public sealed partial class ExplosionSystem : EntitySystem
|
|||||||
EntityQuery<TransformComponent> xformQuery,
|
EntityQuery<TransformComponent> xformQuery,
|
||||||
EntityQuery<DamageableComponent> damageQuery,
|
EntityQuery<DamageableComponent> damageQuery,
|
||||||
EntityQuery<PhysicsComponent> physicsQuery,
|
EntityQuery<PhysicsComponent> physicsQuery,
|
||||||
LookupFlags flags)
|
EntityQuery<TagComponent> tagQuery,
|
||||||
|
EntityQuery<ProjectileComponent> projectileQuery)
|
||||||
{
|
{
|
||||||
var gridBox = Box2.FromDimensions(tile * DefaultTileSize, (DefaultTileSize, DefaultTileSize));
|
var gridBox = Box2.FromDimensions(tile * DefaultTileSize, (DefaultTileSize, DefaultTileSize));
|
||||||
var worldBox = spaceMatrix.TransformBox(gridBox);
|
var worldBox = spaceMatrix.TransformBox(gridBox);
|
||||||
@@ -315,7 +319,7 @@ public sealed partial class ExplosionSystem : EntitySystem
|
|||||||
foreach (var xform in state.Item1)
|
foreach (var xform in state.Item1)
|
||||||
{
|
{
|
||||||
processed.Add(xform.Owner);
|
processed.Add(xform.Owner);
|
||||||
ProcessEntity(xform.Owner, epicenter, damage, throwForce, id, damageQuery, physicsQuery, xform);
|
ProcessEntity(xform.Owner, epicenter, damage, throwForce, id, xform, damageQuery, physicsQuery, xformQuery, tagQuery, projectileQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (throwForce <= 0)
|
if (throwForce <= 0)
|
||||||
@@ -329,7 +333,7 @@ public sealed partial class ExplosionSystem : EntitySystem
|
|||||||
|
|
||||||
foreach (var xform in list)
|
foreach (var xform in list)
|
||||||
{
|
{
|
||||||
ProcessEntity(xform.Owner, epicenter, null, throwForce, id, damageQuery, physicsQuery, xform);
|
ProcessEntity(xform.Owner, epicenter, null, throwForce, id, xform, damageQuery, physicsQuery, xformQuery, tagQuery, projectileQuery);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -375,9 +379,12 @@ public sealed partial class ExplosionSystem : EntitySystem
|
|||||||
DamageSpecifier? damage,
|
DamageSpecifier? damage,
|
||||||
float throwForce,
|
float throwForce,
|
||||||
string id,
|
string id,
|
||||||
|
TransformComponent? xform,
|
||||||
EntityQuery<DamageableComponent> damageQuery,
|
EntityQuery<DamageableComponent> damageQuery,
|
||||||
EntityQuery<PhysicsComponent> physicsQuery,
|
EntityQuery<PhysicsComponent> physicsQuery,
|
||||||
TransformComponent? xform = null)
|
EntityQuery<TransformComponent> transformQuery,
|
||||||
|
EntityQuery<TagComponent> tagQuery,
|
||||||
|
EntityQuery<ProjectileComponent> projectileQuery)
|
||||||
{
|
{
|
||||||
// damage
|
// damage
|
||||||
if (damage != null && damageQuery.TryGetComponent(uid, out var damageable))
|
if (damage != null && damageQuery.TryGetComponent(uid, out var damageable))
|
||||||
@@ -413,15 +420,22 @@ public sealed partial class ExplosionSystem : EntitySystem
|
|||||||
}
|
}
|
||||||
|
|
||||||
// throw
|
// throw
|
||||||
if (xform != null
|
if (xform != null // null implies anchored
|
||||||
&& !xform.Anchored
|
&& !xform.Anchored
|
||||||
&& throwForce > 0
|
&& throwForce > 0
|
||||||
&& !EntityManager.IsQueuedForDeletion(uid)
|
&& !EntityManager.IsQueuedForDeletion(uid)
|
||||||
&& physicsQuery.TryGetComponent(uid, out var physics)
|
&& physicsQuery.TryGetComponent(uid, out var physics)
|
||||||
&& physics.BodyType == BodyType.Dynamic)
|
&& physics.BodyType == BodyType.Dynamic)
|
||||||
{
|
{
|
||||||
// TODO purge throw helpers and pass in physics component
|
var pos = _transformSystem.GetWorldPosition(xform, transformQuery);
|
||||||
_throwingSystem.TryThrow(uid, xform.WorldPosition - epicenter.Position, throwForce);
|
_throwingSystem.TryThrow(
|
||||||
|
uid,
|
||||||
|
pos - epicenter.Position,
|
||||||
|
physics,
|
||||||
|
xform,
|
||||||
|
projectileQuery,
|
||||||
|
tagQuery,
|
||||||
|
throwForce);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO EXPLOSION puddle / flammable ignite?
|
// TODO EXPLOSION puddle / flammable ignite?
|
||||||
@@ -567,14 +581,14 @@ sealed class Explosion
|
|||||||
private readonly EntityQuery<TransformComponent> _xformQuery;
|
private readonly EntityQuery<TransformComponent> _xformQuery;
|
||||||
private readonly EntityQuery<PhysicsComponent> _physicsQuery;
|
private readonly EntityQuery<PhysicsComponent> _physicsQuery;
|
||||||
private readonly EntityQuery<DamageableComponent> _damageQuery;
|
private readonly EntityQuery<DamageableComponent> _damageQuery;
|
||||||
|
private readonly EntityQuery<ProjectileComponent> _projectileQuery;
|
||||||
|
private readonly EntityQuery<TagComponent> _tagQuery;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Total area that the explosion covers.
|
/// Total area that the explosion covers.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly int Area;
|
public readonly int Area;
|
||||||
|
|
||||||
private readonly LookupFlags _flags = LookupFlags.None;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// factor used to scale the tile break chances.
|
/// factor used to scale the tile break chances.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -625,14 +639,11 @@ sealed class Explosion
|
|||||||
_canCreateVacuum = canCreateVacuum;
|
_canCreateVacuum = canCreateVacuum;
|
||||||
_entMan = entMan;
|
_entMan = entMan;
|
||||||
|
|
||||||
// yeah this should be a cvar, but this is only temporary anyways
|
|
||||||
// see lookup todo
|
|
||||||
if (Area > 100)
|
|
||||||
_flags |= LookupFlags.Approximate;
|
|
||||||
|
|
||||||
_xformQuery = entMan.GetEntityQuery<TransformComponent>();
|
_xformQuery = entMan.GetEntityQuery<TransformComponent>();
|
||||||
_physicsQuery = entMan.GetEntityQuery<PhysicsComponent>();
|
_physicsQuery = entMan.GetEntityQuery<PhysicsComponent>();
|
||||||
_damageQuery = entMan.GetEntityQuery<DamageableComponent>();
|
_damageQuery = entMan.GetEntityQuery<DamageableComponent>();
|
||||||
|
_tagQuery = entMan.GetEntityQuery<TagComponent>();
|
||||||
|
_projectileQuery = entMan.GetEntityQuery<ProjectileComponent>();
|
||||||
|
|
||||||
if (spaceData != null)
|
if (spaceData != null)
|
||||||
{
|
{
|
||||||
@@ -773,7 +784,8 @@ sealed class Explosion
|
|||||||
_xformQuery,
|
_xformQuery,
|
||||||
_damageQuery,
|
_damageQuery,
|
||||||
_physicsQuery,
|
_physicsQuery,
|
||||||
_flags);
|
_tagQuery,
|
||||||
|
_projectileQuery);
|
||||||
|
|
||||||
// If the floor is not blocked by some dense object, damage the floor tiles.
|
// If the floor is not blocked by some dense object, damage the floor tiles.
|
||||||
if (canDamageFloor)
|
if (canDamageFloor)
|
||||||
@@ -794,7 +806,8 @@ sealed class Explosion
|
|||||||
_xformQuery,
|
_xformQuery,
|
||||||
_damageQuery,
|
_damageQuery,
|
||||||
_physicsQuery,
|
_physicsQuery,
|
||||||
_flags);
|
_tagQuery,
|
||||||
|
_projectileQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!MoveNext())
|
if (!MoveNext())
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using Content.Shared.Gravity;
|
using Content.Shared.Gravity;
|
||||||
using Content.Shared.Interaction;
|
using Content.Shared.Interaction;
|
||||||
using Content.Shared.Movement.Components;
|
using Content.Shared.Movement.Components;
|
||||||
|
using Content.Shared.Projectiles;
|
||||||
using Content.Shared.Tag;
|
using Content.Shared.Tag;
|
||||||
using Robust.Shared.Physics;
|
using Robust.Shared.Physics;
|
||||||
using Robust.Shared.Physics.Components;
|
using Robust.Shared.Physics.Components;
|
||||||
@@ -32,22 +33,49 @@ public sealed class ThrowingSystem : EntitySystem
|
|||||||
/// <param name="direction">A vector pointing from the entity to its destination.</param>
|
/// <param name="direction">A vector pointing from the entity to its destination.</param>
|
||||||
/// <param name="strength">How much the direction vector should be multiplied for velocity.</param>
|
/// <param name="strength">How much the direction vector should be multiplied for velocity.</param>
|
||||||
/// <param name="pushbackRatio">The ratio of impulse applied to the thrower - defaults to 10 because otherwise it's not enough to properly recover from getting spaced</param>
|
/// <param name="pushbackRatio">The ratio of impulse applied to the thrower - defaults to 10 because otherwise it's not enough to properly recover from getting spaced</param>
|
||||||
public void TryThrow(
|
public void TryThrow(EntityUid uid,
|
||||||
EntityUid uid,
|
|
||||||
Vector2 direction,
|
Vector2 direction,
|
||||||
float strength = 1.0f,
|
float strength = 1.0f,
|
||||||
EntityUid? user = null,
|
EntityUid? user = null,
|
||||||
float pushbackRatio = 5.0f,
|
float pushbackRatio = 5.0f)
|
||||||
PhysicsComponent? physics = null,
|
|
||||||
TransformComponent? transform = null,
|
|
||||||
EntityQuery<PhysicsComponent>? physicsQuery = null,
|
|
||||||
EntityQuery<TransformComponent>? xformQuery = null)
|
|
||||||
{
|
{
|
||||||
if (strength <= 0 || direction == Vector2.Infinity || direction == Vector2.NaN || direction == Vector2.Zero)
|
var physicsQuery = GetEntityQuery<PhysicsComponent>();
|
||||||
|
if (!physicsQuery.TryGetComponent(uid, out var physics))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
physicsQuery ??= GetEntityQuery<PhysicsComponent>();
|
var projectileQuery = GetEntityQuery<ProjectileComponent>();
|
||||||
if (physics == null && !physicsQuery.Value.TryGetComponent(uid, out physics))
|
var tagQuery = GetEntityQuery<TagComponent>();
|
||||||
|
|
||||||
|
TryThrow(
|
||||||
|
uid,
|
||||||
|
direction,
|
||||||
|
physics,
|
||||||
|
Transform(uid),
|
||||||
|
projectileQuery,
|
||||||
|
tagQuery,
|
||||||
|
strength,
|
||||||
|
user,
|
||||||
|
pushbackRatio);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tries to throw the entity if it has a physics component, otherwise does nothing.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="uid">The entity being thrown.</param>
|
||||||
|
/// <param name="direction">A vector pointing from the entity to its destination.</param>
|
||||||
|
/// <param name="strength">How much the direction vector should be multiplied for velocity.</param>
|
||||||
|
/// <param name="pushbackRatio">The ratio of impulse applied to the thrower - defaults to 10 because otherwise it's not enough to properly recover from getting spaced</param>
|
||||||
|
public void TryThrow(EntityUid uid,
|
||||||
|
Vector2 direction,
|
||||||
|
PhysicsComponent physics,
|
||||||
|
TransformComponent transform,
|
||||||
|
EntityQuery<ProjectileComponent> projectileQuery,
|
||||||
|
EntityQuery<TagComponent> tagQuery,
|
||||||
|
float strength = 1.0f,
|
||||||
|
EntityUid? user = null,
|
||||||
|
float pushbackRatio = 5.0f)
|
||||||
|
{
|
||||||
|
if (strength <= 0 || direction == Vector2.Infinity || direction == Vector2.NaN || direction == Vector2.Zero)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ((physics.BodyType & (BodyType.Dynamic | BodyType.KinematicController)) == 0x0)
|
if ((physics.BodyType & (BodyType.Dynamic | BodyType.KinematicController)) == 0x0)
|
||||||
@@ -56,20 +84,17 @@ public sealed class ThrowingSystem : EntitySystem
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (projectileQuery.HasComponent(uid))
|
||||||
|
return;
|
||||||
|
|
||||||
var comp = EnsureComp<ThrownItemComponent>(uid);
|
var comp = EnsureComp<ThrownItemComponent>(uid);
|
||||||
comp.Thrower = user;
|
comp.Thrower = user;
|
||||||
|
|
||||||
// Give it a l'il spin.
|
// Give it a l'il spin.
|
||||||
if (!_tagSystem.HasTag(uid, "NoSpinOnThrow"))
|
if (!tagQuery.TryGetComponent(uid, out var tag) || !_tagSystem.HasTag(tag, "NoSpinOnThrow"))
|
||||||
_physics.ApplyAngularImpulse(uid, ThrowAngularImpulse, body: physics);
|
_physics.ApplyAngularImpulse(uid, ThrowAngularImpulse, body: physics);
|
||||||
else
|
else
|
||||||
{
|
|
||||||
if (transform == null)
|
|
||||||
{
|
|
||||||
xformQuery ??= GetEntityQuery<TransformComponent>();
|
|
||||||
transform = xformQuery.Value.GetComponent(uid);
|
|
||||||
}
|
|
||||||
transform.LocalRotation = direction.ToWorldAngle() - Math.PI;
|
transform.LocalRotation = direction.ToWorldAngle() - Math.PI;
|
||||||
}
|
|
||||||
|
|
||||||
if (user != null)
|
if (user != null)
|
||||||
_interactionSystem.ThrownInteraction(user.Value, uid);
|
_interactionSystem.ThrownInteraction(user.Value, uid);
|
||||||
@@ -100,7 +125,7 @@ public sealed class ThrowingSystem : EntitySystem
|
|||||||
// Give thrower an impulse in the other direction
|
// Give thrower an impulse in the other direction
|
||||||
if (user != null &&
|
if (user != null &&
|
||||||
pushbackRatio > 0.0f &&
|
pushbackRatio > 0.0f &&
|
||||||
physicsQuery.Value.TryGetComponent(user.Value, out var userPhysics) &&
|
TryComp(user.Value, out PhysicsComponent? userPhysics) &&
|
||||||
_gravity.IsWeightless(user.Value, userPhysics))
|
_gravity.IsWeightless(user.Value, userPhysics))
|
||||||
{
|
{
|
||||||
var msg = new ThrowPushbackAttemptEvent();
|
var msg = new ThrowPushbackAttemptEvent();
|
||||||
|
|||||||
Reference in New Issue
Block a user