Moves ShootProjectile to shared (#24007)
This commit is contained in:
@@ -313,26 +313,6 @@ public sealed partial class GunSystem : SharedGunSystem
|
|||||||
ShootProjectile(uid, mapDirection, gunVelocity, gunUid, user, gun.ProjectileSpeed);
|
ShootProjectile(uid, mapDirection, gunVelocity, gunUid, user, gun.ProjectileSpeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ShootProjectile(EntityUid uid, Vector2 direction, Vector2 gunVelocity, EntityUid gunUid, EntityUid? user = null, float speed = 20f)
|
|
||||||
{
|
|
||||||
var physics = EnsureComp<PhysicsComponent>(uid);
|
|
||||||
Physics.SetBodyStatus(physics, BodyStatus.InAir);
|
|
||||||
|
|
||||||
var targetMapVelocity = gunVelocity + direction.Normalized() * speed;
|
|
||||||
var currentMapVelocity = Physics.GetMapLinearVelocity(uid, physics);
|
|
||||||
var finalLinear = physics.LinearVelocity + targetMapVelocity - currentMapVelocity;
|
|
||||||
Physics.SetLinearVelocity(uid, finalLinear, body: physics);
|
|
||||||
|
|
||||||
if (user != null)
|
|
||||||
{
|
|
||||||
var projectile = EnsureComp<ProjectileComponent>(uid);
|
|
||||||
Projectiles.SetShooter(uid, projectile, user.Value);
|
|
||||||
projectile.Weapon = gunUid;
|
|
||||||
}
|
|
||||||
|
|
||||||
TransformSystem.SetWorldRotation(uid, direction.ToWorldAngle());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a linear spread of angles between start and end.
|
/// Gets a linear spread of angles between start and end.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Numerics;
|
||||||
using Content.Shared.ActionBlocker;
|
using Content.Shared.ActionBlocker;
|
||||||
using Content.Shared.Actions;
|
using Content.Shared.Actions;
|
||||||
using Content.Shared.Administration.Logs;
|
using Content.Shared.Administration.Logs;
|
||||||
@@ -374,6 +375,26 @@ public abstract partial class SharedGunSystem : EntitySystem
|
|||||||
EntityUid? user = null,
|
EntityUid? user = null,
|
||||||
bool throwItems = false);
|
bool throwItems = false);
|
||||||
|
|
||||||
|
public void ShootProjectile(EntityUid uid, Vector2 direction, Vector2 gunVelocity, EntityUid gunUid, EntityUid? user = null, float speed = 20f)
|
||||||
|
{
|
||||||
|
var physics = EnsureComp<PhysicsComponent>(uid);
|
||||||
|
Physics.SetBodyStatus(physics, BodyStatus.InAir);
|
||||||
|
|
||||||
|
var targetMapVelocity = gunVelocity + direction.Normalized() * speed;
|
||||||
|
var currentMapVelocity = Physics.GetMapLinearVelocity(uid, physics);
|
||||||
|
var finalLinear = physics.LinearVelocity + targetMapVelocity - currentMapVelocity;
|
||||||
|
Physics.SetLinearVelocity(uid, finalLinear, body: physics);
|
||||||
|
|
||||||
|
if (user != null)
|
||||||
|
{
|
||||||
|
var projectile = EnsureComp<ProjectileComponent>(uid);
|
||||||
|
Projectiles.SetShooter(uid, projectile, user.Value);
|
||||||
|
projectile.Weapon = gunUid;
|
||||||
|
}
|
||||||
|
|
||||||
|
TransformSystem.SetWorldRotation(uid, direction.ToWorldAngle());
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract void Popup(string message, EntityUid? uid, EntityUid? user);
|
protected abstract void Popup(string message, EntityUid? uid, EntityUid? user);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user