Fix throwing.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Components;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.GameObjects.Components.Projectiles
|
||||
{
|
||||
public abstract class SharedProjectileComponent : Component, ICollideSpecial
|
||||
{
|
||||
private bool _ignoreShooter = true;
|
||||
public override string Name => "Projectile";
|
||||
public override uint? NetID => ContentNetIDs.PROJECTILE;
|
||||
|
||||
protected abstract EntityUid Shooter { get; }
|
||||
|
||||
public bool IgnoreShooter
|
||||
{
|
||||
get => _ignoreShooter;
|
||||
set
|
||||
{
|
||||
_ignoreShooter = value;
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
[NetSerializable, Serializable]
|
||||
protected class ProjectileComponentState : ComponentState
|
||||
{
|
||||
public ProjectileComponentState(uint netId, EntityUid shooter, bool ignoreShooter) : base(netId)
|
||||
{
|
||||
Shooter = shooter;
|
||||
IgnoreShooter = ignoreShooter;
|
||||
}
|
||||
|
||||
public EntityUid Shooter { get; }
|
||||
public bool IgnoreShooter { get; }
|
||||
}
|
||||
|
||||
public bool PreventCollide(IPhysBody collidedwith)
|
||||
{
|
||||
return IgnoreShooter && collidedwith.Owner.Uid == Shooter;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,6 +56,8 @@
|
||||
public const uint THIRST = 1050;
|
||||
|
||||
public const uint FLASHABLE = 1051;
|
||||
public const uint PROJECTILE = 1052;
|
||||
public const uint THROWN_ITEM = 1053;
|
||||
|
||||
// Net IDs for integration tests.
|
||||
public const uint PREDICTION_TEST = 10001;
|
||||
|
||||
@@ -24,6 +24,7 @@ namespace Content.Shared.Physics
|
||||
MapGrid = MapGridHelpers.CollisionGroup, // Map grids, like shuttles. This is the actual grid itself, not the walls or other entities connected to the grid.
|
||||
|
||||
MobMask = Impassable | MobImpassable | VaultImpassable | SmallImpassable,
|
||||
ThrownItem = MobImpassable | Impassable,
|
||||
// 32 possible groups
|
||||
AllMask = -1,
|
||||
}
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
using Robust.Shared.GameObjects.Components;
|
||||
using Robust.Shared.Interfaces.Physics;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Timers;
|
||||
|
||||
namespace Content.Shared.Physics
|
||||
{
|
||||
public class ThrowController: VirtualController
|
||||
{
|
||||
private float _throwTime;
|
||||
private PhysicsComponent _component;
|
||||
|
||||
public const float DefaultThrowTime = 0.25f;
|
||||
|
||||
public float ThrowTime
|
||||
{
|
||||
get => _throwTime;
|
||||
set => _throwTime = value;
|
||||
}
|
||||
|
||||
public override PhysicsComponent ControlledComponent
|
||||
{
|
||||
set => _component = value;
|
||||
}
|
||||
|
||||
public void StartThrow(Vector2 initialImpulse)
|
||||
{
|
||||
_component.Momentum = initialImpulse;
|
||||
_component.Status = BodyStatus.InAir;
|
||||
Timer.Spawn((int) (ThrowTime * 1000), StopThrow);
|
||||
}
|
||||
|
||||
public void StopThrow()
|
||||
{
|
||||
if (_component == null || _component.Owner.Deleted) return;
|
||||
if (IoCManager.Resolve<IPhysicsManager>().IsWeightless(_component.Owner.Transform.GridPosition))
|
||||
{
|
||||
Timer.Spawn((int) (ThrowTime * 1000), StopThrow);
|
||||
return;
|
||||
}
|
||||
_component.Status = BodyStatus.OnGround;
|
||||
_component.LinearVelocity = Vector2.Zero;
|
||||
}
|
||||
|
||||
public ThrowController()
|
||||
{
|
||||
ThrowTime = DefaultThrowTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user