Add pulling (#1409)
* Initial framework for pulling. * Make it possible to pull items via (temporary) keybind Ctrl+Click, make items follow the player correctly. * Make other objects pullable, implement functionality for moving an object being pulled, make only one object able to be pulled at a time. * Make sure that MoveTo won't allow collisions with the player * Update everything to work with the new physics engine * Update Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs Co-authored-by: ComicIronic <comicironic@gmail.com> * Physics update and convert to direct type casts * Add notnull checks * Add pull keybinds to the tutorial window * Move PullController to shared * Fix pulled items getting left behind * Fix moving pulled objects into walls * Remove flooring of coordinates when moving pulled objects * Add missing null check in PutInHand * Change pulling keybind to control and throwing to alt * Change PhysicsComponent references to IPhysicsComponent * Add trying to pull a pulled entity disabling the pull * Add pulled status effect * Fix merge conflicts * Merge fixes * Make players pullable * Fix being able to pull yourself * Change pull moving to use a velocity * Update pulled and pulling icons to not be buckle A tragedy * Make pulled and pulling icons more consistent * Remove empty not pulled and not pulling images * Pulled icon update * Pulled icon update * Add clicking pulling status effect to stop the pull * Fix spacewalking when pulling * Merge conflict fixes * Add a pull verb * Fix nullable error * Add pulling through the entity drop down menu Co-authored-by: Jackson Lewis <inquisitivepenguin@protonmail.com> Co-authored-by: ComicIronic <comicironic@gmail.com>
This commit is contained in:
114
Content.Shared/Physics/PullController.cs
Normal file
114
Content.Shared/Physics/PullController.cs
Normal file
@@ -0,0 +1,114 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using Content.Shared.GameObjects.Components.Items;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Robust.Shared.GameObjects.Components;
|
||||
using Robust.Shared.Interfaces.Map;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
|
||||
namespace Content.Shared.Physics
|
||||
{
|
||||
public class PullController : VirtualController
|
||||
{
|
||||
private const float DistBeforePull = 1.0f;
|
||||
|
||||
private const float DistBeforeStopPull = SharedInteractionSystem.InteractionRange;
|
||||
|
||||
private ICollidableComponent? _puller;
|
||||
|
||||
public bool GettingPulled => _puller != null;
|
||||
|
||||
private GridCoordinates? _movingTo;
|
||||
|
||||
public ICollidableComponent? Puller => _puller;
|
||||
|
||||
public void StartPull(ICollidableComponent? pull)
|
||||
{
|
||||
_puller = pull;
|
||||
}
|
||||
|
||||
public void StopPull()
|
||||
{
|
||||
_puller = null;
|
||||
ControlledComponent?.TryRemoveController<PullController>();
|
||||
}
|
||||
|
||||
public void TryMoveTo(GridCoordinates from, GridCoordinates to)
|
||||
{
|
||||
if (_puller == null || ControlledComponent == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
|
||||
if (!from.InRange(mapManager, to, SharedInteractionSystem.InteractionRange))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var dist = _puller.Owner.Transform.GridPosition.Position - to.Position;
|
||||
|
||||
if (Math.Sqrt(dist.LengthSquared) > DistBeforeStopPull ||
|
||||
Math.Sqrt(dist.LengthSquared) < 0.25f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_movingTo = to;
|
||||
}
|
||||
|
||||
public override void UpdateBeforeProcessing()
|
||||
{
|
||||
if (_puller == null || ControlledComponent == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Are we outside of pulling range?
|
||||
var dist = _puller.Owner.Transform.WorldPosition - ControlledComponent.Owner.Transform.WorldPosition;
|
||||
|
||||
if (dist.Length > DistBeforeStopPull)
|
||||
{
|
||||
_puller.Owner.GetComponent<ISharedHandsComponent>().StopPull();
|
||||
}
|
||||
else if (_movingTo.HasValue)
|
||||
{
|
||||
var diff = _movingTo.Value.Position - ControlledComponent.Owner.Transform.GridPosition.Position;
|
||||
LinearVelocity = diff.Normalized * 5;
|
||||
}
|
||||
else if (dist.Length > DistBeforePull)
|
||||
{
|
||||
LinearVelocity = dist.Normalized * _puller.LinearVelocity.Length * 1.1f;
|
||||
}
|
||||
else
|
||||
{
|
||||
LinearVelocity = Vector2.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateAfterProcessing()
|
||||
{
|
||||
base.UpdateAfterProcessing();
|
||||
|
||||
if (ControlledComponent == null)
|
||||
{
|
||||
_movingTo = null;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_movingTo == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (ControlledComponent.Owner.Transform.GridPosition.Position.EqualsApprox(_movingTo.Value.Position, 0.01))
|
||||
{
|
||||
_movingTo = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user