Revert "Physics (#3452)"

This reverts commit 3e64fd56a1.
This commit is contained in:
Pieter-Jan Briers
2021-02-28 18:49:48 +01:00
parent eddec5fcce
commit 1eb0fbd8d0
211 changed files with 2560 additions and 2600 deletions

View File

@@ -7,7 +7,6 @@ using Content.Server.Utility;
using Content.Shared.GameObjects.Components.Interactable;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.Physics;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
@@ -43,7 +42,7 @@ namespace Content.Server.GameObjects.Components
/// <returns>true if it is valid, false otherwise</returns>
private async Task<bool> Valid(IEntity user, IEntity? utilizing, [NotNullWhen(true)] bool force = false)
{
if (!Owner.HasComponent<IPhysBody>())
if (!Owner.HasComponent<IPhysicsComponent>())
{
return false;
}
@@ -75,8 +74,8 @@ namespace Content.Server.GameObjects.Components
return false;
}
var physics = Owner.GetComponent<IPhysBody>();
physics.BodyType = BodyType.Static;
var physics = Owner.GetComponent<IPhysicsComponent>();
physics.Anchored = true;
if (Owner.TryGetComponent(out PullableComponent? pullableComponent))
{
@@ -106,8 +105,8 @@ namespace Content.Server.GameObjects.Components
return false;
}
var physics = Owner.GetComponent<IPhysBody>();
physics.BodyType = BodyType.Dynamic;
var physics = Owner.GetComponent<IPhysicsComponent>();
physics.Anchored = false;
return true;
}
@@ -121,12 +120,12 @@ namespace Content.Server.GameObjects.Components
/// <returns>true if toggled, false otherwise</returns>
private async Task<bool> TryToggleAnchor(IEntity user, IEntity? utilizing = null, bool force = false)
{
if (!Owner.TryGetComponent(out IPhysBody? physics))
if (!Owner.TryGetComponent(out IPhysicsComponent? physics))
{
return false;
}
return physics.BodyType == BodyType.Static ?
return physics.Anchored ?
await TryUnAnchor(user, utilizing, force) :
await TryAnchor(user, utilizing, force);
}

View File

@@ -15,7 +15,6 @@ using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Physics;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
@@ -135,19 +134,19 @@ namespace Content.Server.GameObjects.Components.Atmos
}
var entity = Owner.EntityManager.GetEntity(uid);
var physics = Owner.GetComponent<IPhysBody>();
var otherPhysics = entity.GetComponent<IPhysBody>();
var physics = Owner.GetComponent<IPhysicsComponent>();
var otherPhysics = entity.GetComponent<IPhysicsComponent>();
if (!physics.GetWorldAABB().Intersects(otherPhysics.GetWorldAABB()))
if (!physics.WorldAABB.Intersects(otherPhysics.WorldAABB))
{
_collided.Remove(uid);
}
}
}
public void CollideWith(IPhysBody ourBody, IPhysBody otherBody)
public void CollideWith(IEntity collidedWith)
{
if (!otherBody.Entity.TryGetComponent(out FlammableComponent otherFlammable))
if (!collidedWith.TryGetComponent(out FlammableComponent otherFlammable))
return;
if (!FireSpread || !otherFlammable.FireSpread)

View File

@@ -13,7 +13,6 @@ using Content.Shared.Interfaces.GameObjects.Components;
using Content.Shared.Atmos;
using Content.Shared.GameObjects.EntitySystems.ActionBlocker;
using Robust.Server.GameObjects;
using Robust.Shared.Physics;
namespace Content.Server.GameObjects.Components.Atmos
{
@@ -41,7 +40,7 @@ namespace Content.Server.GameObjects.Components.Atmos
public GasMixture Air { get; set; } = default!;
[ViewVariables]
public bool Anchored => !Owner.TryGetComponent<IPhysBody>(out var physics) || physics.BodyType == BodyType.Static;
public bool Anchored => !Owner.TryGetComponent<IPhysicsComponent>(out var physics) || physics.Anchored;
/// <summary>
/// The floor connector port that the canister is attached to.
@@ -78,7 +77,7 @@ namespace Content.Server.GameObjects.Components.Atmos
public override void Initialize()
{
base.Initialize();
if (Owner.TryGetComponent<IPhysBody>(out var physics))
if (Owner.TryGetComponent<IPhysicsComponent>(out var physics))
{
AnchorUpdate();
}

View File

@@ -1,14 +1,6 @@
#nullable enable
using System;
using System.Diagnostics.CodeAnalysis;
using Content.Shared.Atmos;
using Content.Shared.GameObjects.Components.Mobs.State;
using Content.Shared.Physics;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Random;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
@@ -17,16 +9,8 @@ namespace Content.Server.GameObjects.Components.Atmos
[RegisterComponent]
public class MovedByPressureComponent : Component
{
[Dependency] private readonly IRobustRandom _robustRandom = default!;
public override string Name => "MovedByPressure";
private const float MoveForcePushRatio = 1f;
private const float MoveForceForcePushRatio = 1f;
private const float ProbabilityOffset = 25f;
private const float ProbabilityBasePercent = 10f;
private const float ThrowForce = 100f;
[ViewVariables(VVAccess.ReadWrite)]
public bool Enabled { get; set; } = true;
[ViewVariables(VVAccess.ReadWrite)]
@@ -43,77 +27,6 @@ namespace Content.Server.GameObjects.Components.Atmos
serializer.DataField(this, x => PressureResistance, "pressureResistance", 1f);
serializer.DataField(this, x => MoveResist, "moveResist", 100f);
}
public void ExperiencePressureDifference(int cycle, float pressureDifference, AtmosDirection direction,
float pressureResistanceProbDelta, EntityCoordinates throwTarget)
{
if (!Owner.TryGetComponent(out PhysicsComponent? physics))
return;
physics.WakeBody();
// TODO ATMOS stuns?
var transform = physics.Owner.Transform;
var maxForce = MathF.Sqrt(pressureDifference) * 2.25f;
var moveProb = 100f;
if (PressureResistance > 0)
moveProb = MathF.Abs((pressureDifference / PressureResistance * ProbabilityBasePercent) -
ProbabilityOffset);
if (moveProb > ProbabilityOffset && _robustRandom.Prob(MathF.Min(moveProb / 100f, 1f))
&& !float.IsPositiveInfinity(MoveResist)
&& (!physics.Anchored
&& (maxForce >= (MoveResist * MoveForcePushRatio)))
|| (physics.Anchored && (maxForce >= (MoveResist * MoveForceForcePushRatio))))
{
if (physics.Owner.HasComponent<IMobStateComponent>())
{
physics.BodyStatus = BodyStatus.InAir;
foreach (var fixture in physics.Fixtures)
{
fixture.CollisionMask &= ~(int) CollisionGroup.VaultImpassable;
}
Owner.SpawnTimer(2000, () =>
{
if (Deleted || !Owner.TryGetComponent(out PhysicsComponent? physicsComponent)) return;
// Uhh if you get race conditions good luck buddy.
if (physicsComponent.Owner.HasComponent<IMobStateComponent>())
{
physicsComponent.BodyStatus = BodyStatus.OnGround;
}
foreach (var fixture in physics.Fixtures)
{
fixture.CollisionMask |= (int) CollisionGroup.VaultImpassable;
}
});
}
if (maxForce > ThrowForce)
{
// Vera please fix ;-;
if (throwTarget != EntityCoordinates.Invalid)
{
var moveForce = maxForce * MathHelper.Clamp(moveProb, 0, 100) / 15f;
var pos = ((throwTarget.Position - transform.Coordinates.Position).Normalized + direction.ToDirection().ToVec()).Normalized;
physics.ApplyLinearImpulse(pos * moveForce);
}
else
{
var moveForce = MathF.Min(maxForce * MathHelper.Clamp(moveProb, 0, 100) / 2500f, 20f);
physics.ApplyLinearImpulse(direction.ToDirection().ToVec() * moveForce);
}
LastHighPressureMovementAirCycle = cycle;
}
}
}
}
public static class MovedByPressureExtensions

View File

@@ -7,7 +7,6 @@ using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
@@ -30,6 +29,8 @@ namespace Content.Server.GameObjects.Components.Chemistry
private float _timer;
private EntityCoordinates _target;
private bool _running;
private Vector2 _direction;
private float _velocity;
private float _aliveTime;
public override void Initialize()
@@ -39,16 +40,18 @@ namespace Content.Server.GameObjects.Components.Chemistry
Owner.EnsureComponentWarn(out SolutionContainerComponent _);
}
public void Start(Vector2 dir, float speed, EntityCoordinates target, float aliveTime)
public void Start(Vector2 dir, float velocity, EntityCoordinates target, float aliveTime)
{
_running = true;
_target = target;
_direction = dir;
_velocity = velocity;
_aliveTime = aliveTime;
// Set Move
if (Owner.TryGetComponent(out PhysicsComponent physics))
if (Owner.TryGetComponent(out IPhysicsComponent physics))
{
physics.BodyStatus = BodyStatus.InAir;
physics.ApplyLinearImpulse(dir * speed);
var controller = physics.EnsureController<VaporController>();
controller.Move(_direction, _velocity);
}
}
@@ -69,7 +72,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
_timer += frameTime;
_reactTimer += frameTime;
if (_reactTimer >= ReactTime)
if (_reactTimer >= ReactTime && Owner.TryGetComponent(out IPhysicsComponent physics))
{
_reactTimer = 0;
var mapGrid = _mapManager.GetGrid(Owner.Transform.GridID);
@@ -87,6 +90,12 @@ namespace Content.Server.GameObjects.Components.Chemistry
if(!_reached && _target.TryDistance(Owner.EntityManager, Owner.Transform.Coordinates, out var distance) && distance <= 0.5f)
{
_reached = true;
if (Owner.TryGetComponent(out IPhysicsComponent coll))
{
var controller = coll.EnsureController<VaporController>();
controller.Stop();
}
}
if (contents.CurrentVolume == 0 || _timer > _aliveTime)
@@ -118,17 +127,26 @@ namespace Content.Server.GameObjects.Components.Chemistry
return true;
}
void ICollideBehavior.CollideWith(IPhysBody ourBody, IPhysBody otherBody)
void ICollideBehavior.CollideWith(IEntity collidedWith)
{
if (!Owner.TryGetComponent(out SolutionContainerComponent contents))
return;
contents.Solution.DoEntityReaction(otherBody.Entity, ReactionMethod.Touch);
contents.Solution.DoEntityReaction(collidedWith, ReactionMethod.Touch);
// Check for collision with a impassable object (e.g. wall) and stop
if ((otherBody.CollisionLayer & (int) CollisionGroup.Impassable) != 0 && otherBody.Hard)
if (collidedWith.TryGetComponent(out IPhysicsComponent physics))
{
Owner.Delete();
if ((physics.CollisionLayer & (int) CollisionGroup.Impassable) != 0 && physics.Hard)
{
if (Owner.TryGetComponent(out IPhysicsComponent coll))
{
var controller = coll.EnsureController<VaporController>();
controller.Stop();
}
Owner.Delete();
}
}
}
}

View File

@@ -16,7 +16,6 @@ using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Log;
using Robust.Shared.Physics;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
@@ -437,10 +436,10 @@ namespace Content.Server.GameObjects.Components.Construction
}
}
if (Owner.TryGetComponent(out IPhysBody? physics) &&
entity.TryGetComponent(out IPhysBody? otherPhysics))
if (Owner.TryGetComponent(out IPhysicsComponent? physics) &&
entity.TryGetComponent(out IPhysicsComponent? otherPhysics))
{
otherPhysics.BodyType = physics.BodyType;
otherPhysics.Anchored = physics.Anchored;
}
Owner.Delete();

View File

@@ -4,13 +4,11 @@ using Content.Server.GameObjects.Components.MachineLinking;
using Content.Server.GameObjects.Components.Power.ApcNetComponents;
using Content.Shared.GameObjects.Components.Conveyor;
using Content.Shared.GameObjects.Components.MachineLinking;
using Content.Shared.GameObjects.Components.Movement;
using Content.Shared.Physics;
using Robust.Server.GameObjects;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
@@ -29,8 +27,6 @@ namespace Content.Server.GameObjects.Components.Conveyor
[ViewVariables(VVAccess.ReadWrite)]
private Angle _angle;
public float Speed => _speed;
/// <summary>
/// The amount of units to move the entity by per second.
/// </summary>
@@ -90,7 +86,7 @@ namespace Content.Server.GameObjects.Components.Conveyor
/// <returns>
/// The angle when taking into account if the conveyor is reversed
/// </returns>
public Angle GetAngle()
private Angle GetAngle()
{
var adjustment = _state == ConveyorState.Reversed ? MathHelper.Pi : 0;
var radians = MathHelper.DegreesToRadians(_angle);
@@ -98,7 +94,7 @@ namespace Content.Server.GameObjects.Components.Conveyor
return new Angle(Owner.Transform.LocalRotation.Theta + radians + adjustment);
}
public bool CanRun()
private bool CanRun()
{
if (State == ConveyorState.Off)
{
@@ -119,16 +115,15 @@ namespace Content.Server.GameObjects.Components.Conveyor
return true;
}
public bool CanMove(IEntity entity)
private bool CanMove(IEntity entity)
{
// TODO We should only check status InAir or Static or MapGrid or /mayber/ container
if (entity == Owner)
{
return false;
}
if (!entity.TryGetComponent(out IPhysBody? physics) ||
physics.BodyType == BodyType.Static)
if (!entity.TryGetComponent(out IPhysicsComponent? physics) ||
physics.Anchored)
{
return false;
}
@@ -151,6 +146,31 @@ namespace Content.Server.GameObjects.Components.Conveyor
return true;
}
public void Update(float frameTime)
{
if (!CanRun())
{
return;
}
var intersecting = Owner.EntityManager.GetEntitiesIntersecting(Owner, true);
var direction = GetAngle().ToVec();
foreach (var entity in intersecting)
{
if (!CanMove(entity))
{
continue;
}
if (entity.TryGetComponent(out IPhysicsComponent? physics))
{
var controller = physics.EnsureController<ConveyedController>();
controller.Move(direction, _speed, entity.Transform.WorldPosition - Owner.Transform.WorldPosition);
}
}
}
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);

View File

@@ -6,7 +6,6 @@ using Content.Shared.GameObjects.Components.Damage;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Physics;
using Robust.Shared.Random;
using Robust.Shared.Serialization;
using Robust.Shared.Timing;
@@ -47,16 +46,16 @@ namespace Content.Server.GameObjects.Components.Damage
serializer.DataField(this, x => x.StunMinimumDamage, "stunMinimumDamage", 10);
}
public void CollideWith(IPhysBody ourBody, IPhysBody otherBody)
public void CollideWith(IEntity collidedWith)
{
if (!Owner.TryGetComponent(out IDamageableComponent damageable)) return;
if (!Owner.TryGetComponent(out IPhysicsComponent physics) || !Owner.TryGetComponent(out IDamageableComponent damageable)) return;
var speed = ourBody.LinearVelocity.Length;
var speed = physics.LinearVelocity.Length;
if (speed < MinimumSpeed) return;
if(!string.IsNullOrEmpty(SoundHit))
EntitySystem.Get<AudioSystem>().PlayFromEntity(SoundHit, otherBody.Entity, AudioHelpers.WithVariation(0.125f).WithVolume(-0.125f));
EntitySystem.Get<AudioSystem>().PlayFromEntity(SoundHit, collidedWith, AudioHelpers.WithVariation(0.125f).WithVolume(-0.125f));
if ((_gameTiming.CurTime - _lastHit).TotalSeconds < DamageCooldown)
return;
@@ -68,7 +67,7 @@ namespace Content.Server.GameObjects.Components.Damage
if (Owner.TryGetComponent(out StunnableComponent stun) && _robustRandom.Prob(StunChance))
stun.Stun(StunSeconds);
damageable.ChangeDamage(Damage, damage, false, otherBody.Entity);
damageable.ChangeDamage(Damage, damage, false, collidedWith);
}
}
}

View File

@@ -10,7 +10,6 @@ using Robust.Server.GameObjects;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
@@ -81,7 +80,7 @@ namespace Content.Server.GameObjects.Components.Disposal
return false;
}
if (!entity.TryGetComponent(out IPhysBody? physics) ||
if (!entity.TryGetComponent(out IPhysicsComponent? physics) ||
!physics.CanCollide)
{
return false;
@@ -98,7 +97,7 @@ namespace Content.Server.GameObjects.Components.Disposal
return false;
}
if (entity.TryGetComponent(out IPhysBody? physics))
if (entity.TryGetComponent(out IPhysicsComponent? physics))
{
physics.CanCollide = false;
}
@@ -130,7 +129,7 @@ namespace Content.Server.GameObjects.Components.Disposal
foreach (var entity in _contents.ContainedEntities.ToArray())
{
if (entity.TryGetComponent(out IPhysBody? physics))
if (entity.TryGetComponent(out IPhysicsComponent? physics))
{
physics.CanCollide = true;
}

View File

@@ -26,7 +26,6 @@ using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Log;
using Robust.Shared.Physics;
using Robust.Shared.Serialization;
using Robust.Shared.Timing;
using Robust.Shared.ViewVariables;
@@ -143,7 +142,7 @@ namespace Content.Server.GameObjects.Components.Disposal
return false;
}
if (!entity.TryGetComponent(out IPhysBody? physics) ||
if (!entity.TryGetComponent(out IPhysicsComponent? physics) ||
!physics.CanCollide)
{
return false;

View File

@@ -16,7 +16,6 @@ using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.ViewVariables;
using static Content.Shared.GameObjects.Components.Disposal.SharedDisposalRouterComponent;
@@ -34,8 +33,8 @@ namespace Content.Server.GameObjects.Components.Disposal
[ViewVariables]
public bool Anchored =>
!Owner.TryGetComponent(out IPhysBody? physics) ||
physics.BodyType == BodyType.Static;
!Owner.TryGetComponent(out IPhysicsComponent? physics) ||
physics.Anchored;
[ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(DisposalRouterUiKey.Key);

View File

@@ -28,7 +28,6 @@ using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Log;
using Robust.Shared.Physics;
using Robust.Shared.Random;
using Robust.Shared.Serialization;
using Robust.Shared.Timing;
@@ -140,7 +139,7 @@ namespace Content.Server.GameObjects.Components.Disposal
if (!base.CanInsert(entity))
return false;
if (!entity.TryGetComponent(out IPhysBody? physics) ||
if (!entity.TryGetComponent(out IPhysicsComponent? physics) ||
!physics.CanCollide)
{
if (entity.TryGetComponent(out IMobStateComponent? state) && state.IsDead())

View File

@@ -1,4 +1,4 @@
#nullable enable
#nullable enable
using System;
using System.Linq;
using System.Threading;
@@ -25,7 +25,6 @@ using Robust.Shared.Log;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Players;
using Robust.Shared.Physics.Broadphase;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
using Timer = Robust.Shared.Timing.Timer;
@@ -39,7 +38,7 @@ namespace Content.Server.GameObjects.Components.Doors
{
[ComponentDependency]
private readonly IDoorCheck? _doorCheck = null;
public override DoorState State
{
get => base.State;
@@ -203,7 +202,7 @@ namespace Content.Server.GameObjects.Components.Doors
}
}
void ICollideBehavior.CollideWith(IPhysBody ourBody, IPhysBody otherBody)
void ICollideBehavior.CollideWith(IEntity entity)
{
if (State != DoorState.Closed)
{
@@ -217,9 +216,9 @@ namespace Content.Server.GameObjects.Components.Doors
// Disabled because it makes it suck hard to walk through double doors.
if (otherBody.Entity.HasComponent<IBody>())
if (entity.HasComponent<IBody>())
{
if (!otherBody.Entity.TryGetComponent<IMoverComponent>(out var mover)) return;
if (!entity.TryGetComponent<IMoverComponent>(out var mover)) return;
/*
// TODO: temporary hack to fix the physics system raising collision events akwardly.
@@ -232,7 +231,7 @@ namespace Content.Server.GameObjects.Components.Doors
TryOpen(entity);
*/
TryOpen(otherBody.Entity);
TryOpen(entity);
}
}
@@ -309,7 +308,7 @@ namespace Content.Server.GameObjects.Components.Doors
{
return _doorCheck.OpenCheck();
}
return true;
}
@@ -413,14 +412,18 @@ namespace Content.Server.GameObjects.Components.Doors
{
var safety = SafetyCheck();
if (safety && Owner.TryGetComponent(out PhysicsComponent? physicsComponent))
if (safety && PhysicsComponent != null)
{
var broadPhaseSystem = EntitySystem.Get<SharedBroadPhaseSystem>();
var physics = IoCManager.Resolve<IPhysicsManager>();
// Use this version so we can ignore the CanCollide being false
foreach(var e in broadPhaseSystem.GetCollidingEntities(physicsComponent.Entity.Transform.MapID, physicsComponent.GetWorldAABB()))
foreach(var e in physics.GetCollidingEntities(Owner.Transform.MapID, PhysicsComponent.WorldAABB))
{
if ((physicsComponent.CollisionMask & e.CollisionLayer) != 0 && broadPhaseSystem.IntersectionPercent(physicsComponent, e) > 0.01f) return true;
if (e.CanCollide &&
((PhysicsComponent.CollisionMask & e.CollisionLayer) != 0x0 ||
(PhysicsComponent.CollisionLayer & e.CollisionMask) != 0x0))
{
return true;
}
}
}
return false;
@@ -449,7 +452,7 @@ namespace Content.Server.GameObjects.Components.Doors
OnPartialClose();
await Timer.Delay(CloseTimeTwo, _stateChangeCancelTokenSource.Token);
if (Occludes && Owner.TryGetComponent(out OccluderComponent? occluder))
{
occluder.Enabled = true;
@@ -492,25 +495,26 @@ namespace Content.Server.GameObjects.Components.Doors
return false;
}
var doorAABB = PhysicsComponent.GetWorldAABB();
var doorAABB = PhysicsComponent.WorldAABB;
var hitsomebody = false;
// Crush
foreach (var e in collidingentities)
{
if (!e.Entity.TryGetComponent(out StunnableComponent? stun)
|| !e.Entity.TryGetComponent(out IDamageableComponent? damage))
if (!e.TryGetComponent(out StunnableComponent? stun)
|| !e.TryGetComponent(out IDamageableComponent? damage)
|| !e.TryGetComponent(out IPhysicsComponent? otherBody))
{
continue;
}
var percentage = e.GetWorldAABB().IntersectPercentage(doorAABB);
var percentage = otherBody.WorldAABB.IntersectPercentage(doorAABB);
if (percentage < 0.1f)
continue;
hitsomebody = true;
CurrentlyCrushing.Add(e.Entity.Uid);
CurrentlyCrushing.Add(e.Uid);
damage.ChangeDamage(DamageType.Blunt, DoorCrushDamage, false, Owner);
stun.Paralyze(DoorStunTime);

View File

@@ -1,21 +1,22 @@
#nullable enable
using Content.Shared.Interfaces.GameObjects.Components;
using Content.Server.GameObjects.Components.Explosion;
using Robust.Shared.GameObjects;
using System.Threading.Tasks;
using Robust.Shared.Serialization;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using Content.Server.GameObjects.Components.Items;
using Content.Server.GameObjects.Components.Trigger.TimerTrigger;
using Content.Shared.GameObjects.Components.Explosion;
using Content.Shared.Interfaces.GameObjects.Components;
using Content.Server.Throw;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Content.Shared.GameObjects.Components.Explosion;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Random;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Explosion
namespace Content.Server.GameObjects.Components.Explosives
{
[RegisterComponent]
public sealed class ClusterFlashComponent : Component, IInteractUsing, IUse
@@ -116,13 +117,10 @@ namespace Content.Server.GameObjects.Components.Explosion
var angleMin = segmentAngle * thrownCount;
var angleMax = segmentAngle * (thrownCount + 1);
var angle = Angle.FromDegrees(random.Next(angleMin, angleMax));
// var distance = random.NextFloat() * _throwDistance;
var distance = (float)random.NextFloat() * _throwDistance;
var target = new EntityCoordinates(Owner.Uid, angle.ToVec().Normalized * distance);
delay += random.Next(550, 900);
thrownCount++;
// TODO: Suss out throw strength
grenade.TryThrow(angle.ToVec().Normalized * 50);
grenade.Throw(0.5f, target, grenade.Transform.Coordinates);
grenade.SpawnTimer(delay, () =>
{
@@ -134,6 +132,9 @@ namespace Content.Server.GameObjects.Components.Explosion
useTimer.Trigger(eventArgs.User);
}
});
delay += random.Next(550, 900);
thrownCount++;
}
Owner.Delete();
@@ -148,7 +149,7 @@ namespace Content.Server.GameObjects.Components.Explosion
if (_unspawnedCount > 0)
{
_unspawnedCount--;
grenade = Owner.EntityManager.SpawnEntity(_fillPrototype, Owner.Transform.MapPosition);
grenade = Owner.EntityManager.SpawnEntity(_fillPrototype, Owner.Transform.Coordinates);
return true;
}

View File

@@ -15,7 +15,6 @@ using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Random;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
@@ -373,7 +372,7 @@ namespace Content.Server.GameObjects.Components.Fluids
foreach (var entity in _snapGrid.GetInDir(direction))
{
if (entity.TryGetComponent(out IPhysBody physics) &&
if (entity.TryGetComponent(out IPhysicsComponent physics) &&
(physics.CollisionLayer & (int) CollisionGroup.Impassable) != 0)
{
puddle = default;

View File

@@ -27,9 +27,6 @@ using Robust.Shared.Maths;
using Robust.Shared.Network;
using Robust.Shared.Players;
using Robust.Shared.ViewVariables;
using Robust.Shared.Map;
using Robust.Shared.Network;
using Robust.Shared.Physics;
namespace Content.Server.GameObjects.Components.GUI
{
@@ -720,13 +717,13 @@ namespace Content.Server.GameObjects.Components.GUI
Dirty();
if (!message.Entity.TryGetComponent(out IPhysBody? physics))
if (!message.Entity.TryGetComponent(out IPhysicsComponent? physics))
{
return;
}
// set velocity to zero
physics.LinearVelocity = Vector2.Zero;
physics.Stop();
return;
}
}

View File

@@ -17,7 +17,6 @@ using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Serialization;
using Robust.Shared.Timing;
using Robust.Shared.ViewVariables;
@@ -227,7 +226,7 @@ namespace Content.Server.GameObjects.Components.Items.Storage
private void ModifyComponents()
{
if (!_isCollidableWhenOpen && Owner.TryGetComponent<IPhysBody>(out var physics))
if (!_isCollidableWhenOpen && Owner.TryGetComponent<IPhysicsComponent>(out var physics))
{
if (Open)
{
@@ -253,10 +252,10 @@ namespace Content.Server.GameObjects.Components.Items.Storage
protected virtual bool AddToContents(IEntity entity)
{
if (entity == Owner) return false;
if (entity.TryGetComponent(out IPhysBody? entityPhysicsComponent))
if (entity.TryGetComponent(out IPhysicsComponent? entityPhysicsComponent))
{
if(MaxSize < entityPhysicsComponent.GetWorldAABB().Size.X
|| MaxSize < entityPhysicsComponent.GetWorldAABB().Size.Y)
if(MaxSize < entityPhysicsComponent.WorldAABB.Size.X
|| MaxSize < entityPhysicsComponent.WorldAABB.Size.Y)
{
return false;
}
@@ -286,7 +285,7 @@ namespace Content.Server.GameObjects.Components.Items.Storage
if(Contents.Remove(contained))
{
contained.Transform.WorldPosition = ContentsDumpPosition();
if (contained.TryGetComponent<IPhysBody>(out var physics))
if (contained.TryGetComponent<IPhysicsComponent>(out var physics))
{
physics.CanCollide = true;
}

View File

@@ -1,5 +1,6 @@
using Content.Server.GameObjects.Components.GUI;
using Content.Server.Interfaces.GameObjects.Components.Items;
using Content.Server.Throw;
using Content.Shared.GameObjects;
using Content.Shared.GameObjects.Components.Items;
using Content.Shared.GameObjects.Components.Storage;
@@ -13,7 +14,6 @@ using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Players;
using Robust.Shared.Physics;
using Robust.Shared.Serialization;
namespace Content.Server.GameObjects.Components.Items.Storage
@@ -87,8 +87,8 @@ namespace Content.Server.GameObjects.Components.Items.Storage
return false;
}
if (Owner.TryGetComponent(out IPhysBody physics) &&
physics.BodyType == BodyType.Static)
if (Owner.TryGetComponent(out IPhysicsComponent physics) &&
physics.Anchored)
{
return false;
}
@@ -141,22 +141,22 @@ namespace Content.Server.GameObjects.Components.Items.Storage
var targetLocation = eventArgs.Target.Transform.Coordinates;
var dirVec = (targetLocation.ToMapPos(Owner.EntityManager) - sourceLocation.ToMapPos(Owner.EntityManager)).Normalized;
float throwForce;
var throwForce = 1.0f;
switch (eventArgs.Severity)
{
case ExplosionSeverity.Destruction:
throwForce = 30.0f;
throwForce = 3.0f;
break;
case ExplosionSeverity.Heavy:
throwForce = 20.0f;
throwForce = 2.0f;
break;
default:
throwForce = 10.0f;
case ExplosionSeverity.Light:
throwForce = 1.0f;
break;
}
Owner.TryThrow(dirVec * throwForce);
Owner.Throw(throwForce, targetLocation, sourceLocation, true);
}
}
}

View File

@@ -1,49 +0,0 @@
#nullable enable
using Content.Server.GameObjects.Components.Items.Storage;
using Content.Server.GameObjects.EntitySystems.Click;
using Content.Shared.GameObjects.Components.Mobs.State;
using Robust.Shared.GameObjects;
using Robust.Shared.Log;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
namespace Content.Server.GameObjects.Components.Items
{
internal static class ThrowHelper
{
/// <summary>
/// Tries to throw the entity if it has a physics component, otherwise does nothing.
/// </summary>
/// <param name="entity"></param>
/// <param name="direction">Will use the vector's magnitude as the strength of the impulse</param>
internal static void TryThrow(this IEntity entity, Vector2 direction, IEntity? user = null)
{
if (direction == Vector2.Zero || !entity.TryGetComponent(out PhysicsComponent? physicsComponent))
{
return;
}
if (physicsComponent.BodyType == BodyType.Static)
{
Logger.Warning("Tried to throw entity {entity} but can't throw static bodies!");
return;
}
if (entity.HasComponent<IMobStateComponent>())
{
Logger.Warning("Throwing not supported for mobs!");
return;
}
if (entity.HasComponent<ItemComponent>())
{
entity.EnsureComponent<ThrownItemComponent>().Thrower = user;
if (user != null)
EntitySystem.Get<InteractionSystem>().ThrownInteraction(user, entity);
}
physicsComponent.ApplyLinearImpulse(direction);
}
}
}

View File

@@ -1,33 +0,0 @@
#nullable enable
using Content.Server.GameObjects.EntitySystems.Click;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Physics;
namespace Content.Server.GameObjects.Components.Items
{
[RegisterComponent]
public class ThrownItemComponent : Component, ICollideBehavior
{
public override string Name => "ThrownItem";
public IEntity? Thrower { get; set; }
public override void HandleMessage(ComponentMessage message, IComponent? component)
{
base.HandleMessage(message, component);
switch (message)
{
case PhysicsSleepCompMessage:
EntitySystem.Get<InteractionSystem>().LandInteraction(Thrower, Owner, Owner.Transform.Coordinates);
IoCManager.Resolve<IComponentManager>().RemoveComponent(Owner.Uid, this);
break;
}
}
public void CollideWith(IPhysBody ourBody, IPhysBody otherBody)
{
EntitySystem.Get<InteractionSystem>().ThrowCollideInteraction(Thrower, ourBody, otherBody);
}
}
}

View File

@@ -4,7 +4,6 @@ using Content.Shared.GameObjects.Components.Mobs;
using Content.Shared.GameObjects.Components.Mobs.State;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Physics;
namespace Content.Server.GameObjects.Components.Mobs.State
{
@@ -31,7 +30,7 @@ namespace Content.Server.GameObjects.Components.Mobs.State
EntitySystem.Get<StandingStateSystem>().Down(entity);
if (entity.TryGetComponent(out IPhysBody physics))
if (entity.TryGetComponent(out IPhysicsComponent physics))
{
physics.CanCollide = false;
}
@@ -41,7 +40,7 @@ namespace Content.Server.GameObjects.Components.Mobs.State
{
base.ExitState(entity);
if (entity.TryGetComponent(out IPhysBody physics))
if (entity.TryGetComponent(out IPhysicsComponent physics))
{
physics.CanCollide = true;
}

View File

@@ -14,9 +14,8 @@ using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Movement
{
[RegisterComponent]
[ComponentReference(typeof(IMobMoverComponent))]
public class AiControllerComponent : Component, IMobMoverComponent, IMoverComponent
[RegisterComponent, ComponentReference(typeof(IMoverComponent))]
public class AiControllerComponent : Component, IMoverComponent
{
private float _visionRadius;
@@ -108,7 +107,8 @@ namespace Content.Server.GameObjects.Components.Movement
/// <inheritdoc />
[ViewVariables]
public float GrabRange { get; set; } = 0.2f;
public float GrabRange => 0.2f;
/// <summary>
/// Is the entity Sprinting (running)?

View File

@@ -13,7 +13,6 @@ using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Log;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
@@ -165,11 +164,9 @@ namespace Content.Server.GameObjects.Components.Movement
var result = await EntitySystem.Get<DoAfterSystem>().DoAfter(doAfterEventArgs);
if (result != DoAfterStatus.Cancelled && entityToMove.TryGetComponent(out PhysicsComponent body) && body.Fixtures.Count >= 1)
if (result != DoAfterStatus.Cancelled && entityToMove.TryGetComponent(out IPhysicsComponent body) && body.PhysicsShapes.Count >= 1)
{
var entityPos = entityToMove.Transform.WorldPosition;
var direction = (Owner.Transform.WorldPosition - entityPos).Normalized;
var direction = (Owner.Transform.WorldPosition - entityToMove.Transform.WorldPosition).Normalized;
var endPoint = Owner.Transform.WorldPosition;
var climbMode = entityToMove.GetComponent<ClimbingComponent>();
@@ -177,14 +174,14 @@ namespace Content.Server.GameObjects.Components.Movement
if (MathF.Abs(direction.X) < 0.6f) // user climbed mostly vertically so lets make it a clean straight line
{
endPoint = new Vector2(entityPos.X, endPoint.Y);
endPoint = new Vector2(entityToMove.Transform.WorldPosition.X, endPoint.Y);
}
else if (MathF.Abs(direction.Y) < 0.6f) // user climbed mostly horizontally so lets make it a clean straight line
{
endPoint = new Vector2(endPoint.X, entityPos.Y);
endPoint = new Vector2(endPoint.X, entityToMove.Transform.WorldPosition.Y);
}
climbMode.TryMoveTo(entityPos, endPoint);
climbMode.TryMoveTo(entityToMove.Transform.WorldPosition, endPoint);
// we may potentially need additional logic since we're forcing a player onto a climbable
// there's also the cases where the user might collide with the person they are forcing onto the climbable that i haven't accounted for
@@ -212,12 +209,9 @@ namespace Content.Server.GameObjects.Components.Movement
var result = await EntitySystem.Get<DoAfterSystem>().DoAfter(doAfterEventArgs);
if (result != DoAfterStatus.Cancelled && user.TryGetComponent(out PhysicsComponent body) && body.Fixtures.Count >= 1)
if (result != DoAfterStatus.Cancelled && user.TryGetComponent(out IPhysicsComponent body) && body.PhysicsShapes.Count >= 1)
{
// TODO: Remove the copy-paste code
var userPos = user.Transform.WorldPosition;
var direction = (Owner.Transform.WorldPosition - userPos).Normalized;
var direction = (Owner.Transform.WorldPosition - user.Transform.WorldPosition).Normalized;
var endPoint = Owner.Transform.WorldPosition;
var climbMode = user.GetComponent<ClimbingComponent>();
@@ -232,7 +226,7 @@ namespace Content.Server.GameObjects.Components.Movement
endPoint = new Vector2(endPoint.X, user.Transform.WorldPosition.Y);
}
climbMode.TryMoveTo(userPos, endPoint);
climbMode.TryMoveTo(user.Transform.WorldPosition, endPoint);
var othersMessage = Loc.GetString("{0:theName} jumps onto {1:theName}!", user, Owner);
user.PopupMessageOtherClients(othersMessage);

View File

@@ -1,13 +1,10 @@
#nullable enable
using System;
using Content.Server.GameObjects.EntitySystems;
using Content.Shared.GameObjects.Components.Buckle;
using Content.Shared.GameObjects.Components.Movement;
using Content.Shared.Physics;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Players;
using Robust.Shared.Timing;
namespace Content.Server.GameObjects.Components.Movement
{
@@ -15,41 +12,23 @@ namespace Content.Server.GameObjects.Components.Movement
[ComponentReference(typeof(SharedClimbingComponent))]
public class ClimbingComponent : SharedClimbingComponent
{
[Dependency] private readonly IGameTiming _gameTiming = default!;
private bool _isClimbing;
private ClimbController? _climbController;
public override bool IsClimbing
{
get => base.IsClimbing;
get => _isClimbing;
set
{
if (_isClimbing == value)
return;
base.IsClimbing = value;
if (value)
if (!value)
{
StartClimbTime = IoCManager.Resolve<IGameTiming>().CurTime;
EntitySystem.Get<ClimbSystem>().AddActiveClimber(this);
OwnerIsTransitioning = true;
}
else
{
EntitySystem.Get<ClimbSystem>().RemoveActiveClimber(this);
OwnerIsTransitioning = false;
Body?.TryRemoveController<ClimbController>();
}
Dirty();
}
}
protected override bool OwnerIsTransitioning
{
get => base.OwnerIsTransitioning;
set
{
if (value == base.OwnerIsTransitioning) return;
base.OwnerIsTransitioning = value;
_isClimbing = value;
Dirty();
}
}
@@ -72,36 +51,38 @@ namespace Content.Server.GameObjects.Components.Movement
/// </summary>
public void TryMoveTo(Vector2 from, Vector2 to)
{
if (Body == null) return;
if (Body == null)
return;
var velocity = (to - from).Length;
if (velocity <= 0.0f) return;
Body.ApplyLinearImpulse((to - from).Normalized * velocity * 400);
OwnerIsTransitioning = true;
Owner.SpawnTimer((int) (BufferTime * 1000), () =>
{
if (Deleted) return;
OwnerIsTransitioning = false;
});
_climbController = Body.EnsureController<ClimbController>();
_climbController.TryMoveTo(from, to);
}
public void Update()
{
if (!IsClimbing || _gameTiming.CurTime < TimeSpan.FromSeconds(BufferTime) + StartClimbTime)
{
if (!IsClimbing || Body == null)
return;
if (_climbController != null && (_climbController.IsBlocked || !_climbController.IsActive))
{
if (Body.TryRemoveController<ClimbController>())
{
_climbController = null;
}
}
if (!IsOnClimbableThisFrame && IsClimbing)
if (IsClimbing)
Body.WakeBody();
if (!IsOnClimbableThisFrame && IsClimbing && _climbController == null)
IsClimbing = false;
IsOnClimbableThisFrame = false;
}
public override ComponentState GetComponentState(ICommonSession player)
{
return new ClimbModeComponentState(_isClimbing, OwnerIsTransitioning);
return new ClimbModeComponentState(_isClimbing);
}
}
}

View File

@@ -0,0 +1,19 @@
#nullable enable
using Content.Shared.GameObjects.Components.Movement;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
namespace Content.Server.GameObjects.Components.Movement
{
/// <summary>
/// Moves the entity based on input from a KeyBindingInputComponent.
/// </summary>
[RegisterComponent]
[ComponentReference(typeof(IMoverComponent))]
public class PlayerInputMoverComponent : SharedPlayerInputMoverComponent
{
public override EntityCoordinates LastPosition { get; set; }
public override float StepSoundDistance { get; set; }
}
}

View File

@@ -10,8 +10,6 @@ using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
@@ -21,6 +19,8 @@ namespace Content.Server.GameObjects.Components.Movement
[ComponentReference(typeof(IMoverComponent))]
internal class ShuttleControllerComponent : Component, IMoverComponent
{
[Dependency] private readonly IMapManager _mapManager = default!;
private bool _movingUp;
private bool _movingDown;
private bool _movingLeft;
@@ -39,19 +39,43 @@ namespace Content.Server.GameObjects.Components.Movement
public override string Name => "ShuttleController";
public bool IgnorePaused => false;
[ViewVariables(VVAccess.ReadWrite)]
public float CurrentWalkSpeed { get; } = 8;
public float CurrentSprintSpeed => 0;
/// <inheritdoc />
[ViewVariables]
public float CurrentPushSpeed => 0.0f;
/// <inheritdoc />
[ViewVariables]
public float GrabRange => 0.0f;
public bool Sprinting => false;
public (Vector2 walking, Vector2 sprinting) VelocityDir { get; set; } = (Vector2.Zero, Vector2.Zero);
public (Vector2 walking, Vector2 sprinting) VelocityDir { get; } = (Vector2.Zero, Vector2.Zero);
public EntityCoordinates LastPosition { get; set; }
public float StepSoundDistance { get; set; }
public void SetVelocityDirection(Direction direction, ushort subTick, bool enabled)
{
VelocityDir = (CalcNewVelocity(direction, enabled), Vector2.Zero);
var gridId = Owner.Transform.GridID;
if (_mapManager.TryGetGrid(gridId, out var grid) &&
Owner.EntityManager.TryGetEntity(grid.GridEntityId, out var gridEntity))
{
//TODO: Switch to shuttle component
if (!gridEntity.TryGetComponent(out IPhysicsComponent? physics))
{
physics = gridEntity.AddComponent<PhysicsComponent>();
physics.Mass = 1;
physics.CanCollide = true;
physics.PhysicsShapes.Add(new PhysShapeGrid(grid));
}
var controller = physics.EnsureController<ShuttleController>();
controller.Push(CalcNewVelocity(direction, enabled), CurrentWalkSpeed);
}
}
public void SetSprinting(ushort subTick, bool walking)

View File

@@ -5,7 +5,6 @@ using System.Linq;
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Physics;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
@@ -39,7 +38,7 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
/// </summary>
public bool Connectable => !_deleting && Anchored;
private bool Anchored => !Owner.TryGetComponent<IPhysBody>(out var physics) || physics.BodyType == BodyType.Static;
private bool Anchored => !Owner.TryGetComponent<IPhysicsComponent>(out var physics) || physics.Anchored;
/// <summary>
/// Prevents a node from being used by other nodes while midway through removal.

View File

@@ -6,7 +6,6 @@ using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Log;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Timing;
namespace Content.Server.GameObjects.Components.PA
@@ -16,9 +15,9 @@ namespace Content.Server.GameObjects.Components.PA
{
public override string Name => "ParticleProjectile";
private ParticleAcceleratorPowerState _state;
public void CollideWith(IPhysBody ourBody, IPhysBody otherBody)
public void CollideWith(IEntity collidedWith)
{
if (otherBody.Entity.TryGetComponent<SingularityComponent>(out var singularityComponent))
if (collidedWith.TryGetComponent<SingularityComponent>(out var singularityComponent))
{
var multiplier = _state switch
{
@@ -31,8 +30,8 @@ namespace Content.Server.GameObjects.Components.PA
};
singularityComponent.Energy += 10 * multiplier;
Owner.Delete();
}
else if (otherBody.Entity.TryGetComponent<SingularityGeneratorComponent>(out var singularityGeneratorComponent))
}else if (collidedWith.TryGetComponent<SingularityGeneratorComponent>(out var singularityGeneratorComponent)
)
{
singularityGeneratorComponent.Power += _state switch
{
@@ -56,7 +55,7 @@ namespace Content.Server.GameObjects.Components.PA
Logger.Error("ParticleProjectile tried firing, but it was spawned without a CollidableComponent");
return;
}
physicsComponent.BodyStatus = BodyStatus.InAir;
physicsComponent.Status = BodyStatus.InAir;
if (!Owner.TryGetComponent<ProjectileComponent>(out var projectileComponent))
{
@@ -82,6 +81,7 @@ namespace Content.Server.GameObjects.Components.PA
spriteComponent.LayerSetState(0, $"particle{suffix}");
physicsComponent
.EnsureController<BulletController>()
.LinearVelocity = angle.ToVec() * 20f;
Owner.Transform.LocalRotation = new Angle(angle + Angle.FromDegrees(180));

View File

@@ -5,7 +5,6 @@ using Content.Shared.GameObjects.Components.Portal;
using Content.Shared.GameObjects.Components.Tag;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Physics;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
@@ -169,11 +168,11 @@ namespace Content.Server.GameObjects.Components.Portal
StartCooldown();
}
public void CollideWith(IPhysBody ourBody, IPhysBody otherBody)
public void CollideWith(IEntity collidedWith)
{
if (_onCooldown == false)
{
TryPortalEntity(otherBody.Entity);
TryPortalEntity(collidedWith);
}
}
}

View File

@@ -9,7 +9,6 @@ using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Random;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
@@ -105,7 +104,7 @@ namespace Content.Server.GameObjects.Components.Portal
{
// Added this component to avoid stacking portals and causing shenanigans
// TODO: Doesn't do a great job of stopping stacking portals for directed
if (entity.HasComponent<IPhysBody>() || entity.HasComponent<TeleporterComponent>())
if (entity.HasComponent<IPhysicsComponent>() || entity.HasComponent<TeleporterComponent>())
{
return;
}
@@ -149,7 +148,7 @@ namespace Content.Server.GameObjects.Components.Portal
// TODO: Check the user's spot? Upside is no stacking TPs but downside is they can't unstuck themselves from walls.
foreach (var entity in _serverEntityManager.GetEntitiesIntersecting(user.Transform.MapID, target))
{
if (entity.HasComponent<IPhysBody>() || entity.HasComponent<PortalComponent>())
if (entity.HasComponent<IPhysicsComponent>() || entity.HasComponent<PortalComponent>())
{
return false;
}

View File

@@ -7,7 +7,6 @@ using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Physics;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
@@ -22,7 +21,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents
{
[Dependency] private readonly IServerEntityManager _serverEntityManager = default!;
[ViewVariables] [ComponentDependency] private readonly IPhysBody? _physicsComponent = null;
[ViewVariables] [ComponentDependency] private readonly IPhysicsComponent? _physicsComponent = null;
public override string Name => "PowerReceiver";
@@ -51,7 +50,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents
/// </summary>
public bool Connectable => Anchored;
private bool Anchored => _physicsComponent == null || _physicsComponent.BodyType == BodyType.Static;
private bool Anchored => _physicsComponent == null || _physicsComponent.Anchored;
[ViewVariables]
public bool NeedsProvider { get; private set; } = true;
@@ -99,7 +98,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents
}
}
public override void OnRemove()
public override void OnRemove()
{
_provider.RemoveReceiver(this);
base.OnRemove();

View File

@@ -5,7 +5,6 @@ using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
using System;
using Robust.Shared.Physics;
namespace Content.Server.GameObjects.Components.Projectiles
{
@@ -37,9 +36,9 @@ namespace Content.Server.GameObjects.Components.Projectiles
_solutionContainer = Owner.EnsureComponent<SolutionContainerComponent>();
}
void ICollideBehavior.CollideWith(IPhysBody ourBody, IPhysBody otherBody)
void ICollideBehavior.CollideWith(IEntity entity)
{
if (!otherBody.Entity.TryGetComponent<BloodstreamComponent>(out var bloodstream))
if (!entity.TryGetComponent<BloodstreamComponent>(out var bloodstream))
return;
var solution = _solutionContainer.Solution;

View File

@@ -1,6 +1,5 @@
using Content.Server.GameObjects.Components.Explosion;
using Robust.Shared.GameObjects;
using Robust.Shared.Physics;
namespace Content.Server.GameObjects.Components.Projectiles
{
@@ -16,12 +15,18 @@ namespace Content.Server.GameObjects.Components.Projectiles
Owner.EnsureComponent<ExplosiveComponent>();
}
void ICollideBehavior.CollideWith(IPhysBody ourBody, IPhysBody otherBody)
void ICollideBehavior.CollideWith(IEntity entity)
{
if (Owner.TryGetComponent(out ExplosiveComponent explosive))
{
explosive.Explosion();
}
}
// Projectile should handle the deleting
void ICollideBehavior.PostCollide(int collisionCount)
{
return;
}
}
}

View File

@@ -1,6 +1,5 @@
using Content.Server.GameObjects.Components.Weapon;
using Robust.Shared.GameObjects;
using Robust.Shared.Physics;
using Robust.Shared.Serialization;
namespace Content.Server.GameObjects.Components.Projectiles
@@ -32,15 +31,20 @@ namespace Content.Server.GameObjects.Components.Projectiles
Owner.EnsureComponent<ProjectileComponent>();
}
void ICollideBehavior.CollideWith(IPhysBody ourBody, IPhysBody otherBody)
void ICollideBehavior.CollideWith(IEntity entity)
{
if (_flashed)
{
return;
}
FlashableComponent.FlashAreaHelper(Owner, _range, _duration);
_flashed = true;
}
// Projectile should handle the deleting
void ICollideBehavior.PostCollide(int collisionCount)
{
return;
}
}
}

View File

@@ -7,7 +7,6 @@ using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Serialization;
using Robust.Shared.Timing;

View File

@@ -5,7 +5,6 @@ using Content.Shared.GameObjects.Components.Damage;
using Content.Shared.GameObjects.Components.Projectiles;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Physics;
using Robust.Shared.Players;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
@@ -13,7 +12,7 @@ using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Projectiles
{
[RegisterComponent]
public class ProjectileComponent : SharedProjectileComponent, ICollideBehavior, IPostCollide
public class ProjectileComponent : SharedProjectileComponent, ICollideBehavior
{
protected override EntityUid Shooter => _shooter;
@@ -28,14 +27,15 @@ namespace Content.Server.GameObjects.Components.Projectiles
set => _damages = value;
}
private bool _damagedEntity = false;
public bool DeleteOnCollide => _deleteOnCollide;
private bool _deleteOnCollide;
// Get that juicy FPS hit sound
private string _soundHit;
private string _soundHitSpecies;
private bool _damagedEntity;
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
@@ -58,27 +58,39 @@ namespace Content.Server.GameObjects.Components.Projectiles
Dirty();
}
private bool _internalDeleteOnCollide;
/// <summary>
/// Applies the damage when our projectile collides with its victim
/// Applies the damage when our projectile collides with its victim
/// </summary>
void ICollideBehavior.CollideWith(IPhysBody ourBody, IPhysBody otherBody)
/// <param name="entity"></param>
void ICollideBehavior.CollideWith(IEntity entity)
{
// This is so entities that shouldn't get a collision are ignored.
if (!otherBody.Hard || _damagedEntity)
if (_damagedEntity)
{
return;
}
if (otherBody.Entity.TryGetComponent(out IDamageableComponent damage) && _soundHitSpecies != null)
// This is so entities that shouldn't get a collision are ignored.
if (entity.TryGetComponent(out IPhysicsComponent otherPhysics) && otherPhysics.Hard == false)
{
EntitySystem.Get<AudioSystem>().PlayAtCoords(_soundHitSpecies, otherBody.Entity.Transform.Coordinates);
_internalDeleteOnCollide = false;
return;
}
else if (_soundHit != null)
else
{
EntitySystem.Get<AudioSystem>().PlayAtCoords(_soundHit, otherBody.Entity.Transform.Coordinates);
_internalDeleteOnCollide = true;
}
if (damage != null)
if (_soundHitSpecies != null && entity.HasComponent<IDamageableComponent>())
{
EntitySystem.Get<AudioSystem>().PlayAtCoords(_soundHitSpecies, entity.Transform.Coordinates);
} else if (_soundHit != null)
{
EntitySystem.Get<AudioSystem>().PlayAtCoords(_soundHit, entity.Transform.Coordinates);
}
if (entity.TryGetComponent(out IDamageableComponent damage))
{
Owner.EntityManager.TryGetEntity(_shooter, out var shooter);
@@ -90,17 +102,17 @@ namespace Content.Server.GameObjects.Components.Projectiles
_damagedEntity = true;
}
// Damaging it can delete it
if (!otherBody.Entity.Deleted && otherBody.Entity.TryGetComponent(out CameraRecoilComponent recoilComponent))
if (!entity.Deleted && entity.TryGetComponent(out CameraRecoilComponent recoilComponent)
&& Owner.TryGetComponent(out IPhysicsComponent ownPhysics))
{
var direction = ourBody.LinearVelocity.Normalized;
var direction = ownPhysics.LinearVelocity.Normalized;
recoilComponent.Kick(direction);
}
}
void IPostCollide.PostCollide(IPhysBody ourBody, IPhysBody otherBody)
void ICollideBehavior.PostCollide(int collideCount)
{
if (_damagedEntity) Owner.Delete();
if (collideCount > 0 && DeleteOnCollide && _internalDeleteOnCollide) Owner.Delete();
}
public override ComponentState GetComponentState(ICommonSession player)

View File

@@ -1,6 +1,5 @@
using Content.Server.GameObjects.Components.Mobs;
using Robust.Shared.GameObjects;
using Robust.Shared.Physics;
using Robust.Shared.Serialization;
namespace Content.Server.GameObjects.Components.Projectiles
@@ -33,14 +32,16 @@ namespace Content.Server.GameObjects.Components.Projectiles
Owner.EnsureComponentWarn(out ProjectileComponent _);
}
void ICollideBehavior.CollideWith(IPhysBody ourBody, IPhysBody otherBody)
void ICollideBehavior.CollideWith(IEntity entity)
{
if (otherBody.Entity.TryGetComponent(out StunnableComponent stunnableComponent))
if (entity.TryGetComponent(out StunnableComponent stunnableComponent))
{
stunnableComponent.Stun(_stunAmount);
stunnableComponent.Knockdown(_knockdownAmount);
stunnableComponent.Slowdown(_slowdownAmount);
}
}
void ICollideBehavior.PostCollide(int collidedCount) {}
}
}

View File

@@ -0,0 +1,118 @@
using Content.Server.GameObjects.EntitySystems.Click;
using Content.Shared.GameObjects;
using Content.Shared.Physics;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
namespace Content.Server.GameObjects.Components.Projectiles
{
[RegisterComponent]
internal class ThrownItemComponent : ProjectileComponent, ICollideBehavior
{
public const float DefaultThrowTime = 0.25f;
private bool _shouldCollide = true;
private bool _shouldStop = false;
public override string Name => "ThrownItem";
public override uint? NetID => ContentNetIDs.THROWN_ITEM;
/// <summary>
/// User who threw the item.
/// </summary>
public IEntity User { get; set; }
void ICollideBehavior.CollideWith(IEntity entity)
{
if (!_shouldCollide || entity.Deleted) return;
if (entity.TryGetComponent(out PhysicsComponent collid))
{
if (!collid.Hard) // ignore non hard
return;
_shouldStop = true; // hit something hard => stop after this collision
// Raise an event.
EntitySystem.Get<InteractionSystem>().ThrowCollideInteraction(User, Owner, entity, Owner.Transform.Coordinates);
}
// Stop colliding with mobs, this mimics not having enough velocity to do damage
// after impacting the first object.
// For realism this should actually be changed when the velocity of the object is less than a threshold.
// This would allow ricochets off walls, and weird gravity effects from slowing the object.
if (!Owner.Deleted && Owner.TryGetComponent(out IPhysicsComponent body) && body.PhysicsShapes.Count >= 1)
{
_shouldCollide = false;
}
}
private void StopThrow()
{
if (Deleted)
{
return;
}
if (Owner.TryGetComponent(out IPhysicsComponent body) && body.PhysicsShapes.Count >= 1)
{
body.PhysicsShapes[0].CollisionMask &= (int) ~CollisionGroup.ThrownItem;
if (body.TryGetController(out ThrownController controller))
{
controller.LinearVelocity = Vector2.Zero;
}
body.Status = BodyStatus.OnGround;
Owner.RemoveComponent<ThrownItemComponent>();
EntitySystem.Get<InteractionSystem>().LandInteraction(User, Owner, Owner.Transform.Coordinates);
}
}
void ICollideBehavior.PostCollide(int collideCount)
{
if (_shouldStop && collideCount > 0)
{
StopThrow();
}
}
public void StartThrow(Vector2 direction, float speed)
{
var comp = Owner.GetComponent<IPhysicsComponent>();
comp.Status = BodyStatus.InAir;
var controller = comp.EnsureController<ThrownController>();
controller.Push(direction, speed);
EntitySystem.Get<AudioSystem>()
.PlayFromEntity("/Audio/Effects/toss.ogg", Owner);
StartStopTimer();
}
private void StartStopTimer()
{
Owner.SpawnTimer((int) (DefaultThrowTime * 1000), MaybeStopThrow);
}
private void MaybeStopThrow()
{
if (Deleted)
{
return;
}
if (IoCManager.Resolve<IPhysicsManager>().IsWeightless(Owner.Transform.Coordinates))
{
StartStopTimer();
return;
}
StopThrow();
}
}
}

View File

@@ -5,7 +5,6 @@ using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.GameObjects.Verbs;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Physics;
namespace Content.Server.GameObjects.Components.Pulling
{
@@ -32,15 +31,15 @@ namespace Content.Server.GameObjects.Components.Pulling
}
if (!user.HasComponent<ISharedHandsComponent>() ||
!user.TryGetComponent(out IPhysBody? userPhysics) ||
!component.Owner.TryGetComponent(out IPhysBody? targetPhysics) ||
targetPhysics.BodyType == BodyType.Static)
!user.TryGetComponent(out IPhysicsComponent? userPhysics) ||
!component.Owner.TryGetComponent(out IPhysicsComponent? targetPhysics) ||
targetPhysics.Anchored)
{
return;
}
data.Visibility = VerbVisibility.Visible;
data.Text = component.Puller == userPhysics.Entity
data.Text = component.Puller == userPhysics
? Loc.GetString("Stop pulling")
: Loc.GetString("Pull");
}

View File

@@ -19,7 +19,6 @@ using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
@@ -31,7 +30,7 @@ namespace Content.Server.GameObjects.Components.Recycling
{
public override string Name => "Recycler";
public List<IEntity> Intersecting { get; set; } = new();
private readonly List<IEntity> _intersecting = new();
/// <summary>
/// Whether or not sentient beings will be recycled
@@ -73,9 +72,9 @@ namespace Content.Server.GameObjects.Components.Recycling
private void Recycle(IEntity entity)
{
if (!Intersecting.Contains(entity))
if (!_intersecting.Contains(entity))
{
Intersecting.Add(entity);
_intersecting.Add(entity);
}
// TODO: Prevent collision with recycled items
@@ -94,7 +93,7 @@ namespace Content.Server.GameObjects.Components.Recycling
recyclable.Recycle(_efficiency);
}
public bool CanRun()
private bool CanRun()
{
if (Owner.TryGetComponent(out PowerReceiverComponent? receiver) &&
!receiver.Powered)
@@ -110,15 +109,15 @@ namespace Content.Server.GameObjects.Components.Recycling
return true;
}
public bool CanMove(IEntity entity)
private bool CanMove(IEntity entity)
{
if (entity == Owner)
{
return false;
}
if (!entity.TryGetComponent(out IPhysBody? physics) ||
physics.BodyType == BodyType.Static)
if (!entity.TryGetComponent(out IPhysicsComponent? physics) ||
physics.Anchored)
{
return false;
}
@@ -141,6 +140,34 @@ namespace Content.Server.GameObjects.Components.Recycling
return true;
}
public void Update(float frameTime)
{
if (!CanRun())
{
_intersecting.Clear();
return;
}
var direction = Vector2.UnitX;
for (var i = _intersecting.Count - 1; i >= 0; i--)
{
var entity = _intersecting[i];
if (entity.Deleted || !CanMove(entity) || !Owner.EntityManager.IsIntersecting(Owner, entity))
{
_intersecting.RemoveAt(i);
continue;
}
if (entity.TryGetComponent(out IPhysicsComponent? physics))
{
var controller = physics.EnsureController<ConveyedController>();
controller.Move(direction, frameTime, entity.Transform.WorldPosition - Owner.Transform.WorldPosition);
}
}
}
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
@@ -149,9 +176,9 @@ namespace Content.Server.GameObjects.Components.Recycling
serializer.DataField(ref _efficiency, "efficiency", 0.25f);
}
void ICollideBehavior.CollideWith(IPhysBody ourBody, IPhysBody otherBody)
void ICollideBehavior.CollideWith(IEntity collidedWith)
{
Recycle(otherBody.Entity);
Recycle(collidedWith);
}
SuicideKind ISuicideAct.Suicide(IEntity victim, IChatManager chat)

View File

@@ -4,7 +4,6 @@ using Content.Shared.GameObjects.Verbs;
using Content.Shared.Interfaces;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Physics;
using Robust.Shared.Serialization;
namespace Content.Server.GameObjects.Components.Rotatable
@@ -18,8 +17,8 @@ namespace Content.Server.GameObjects.Components.Rotatable
private void TryFlip(IEntity user)
{
if (Owner.TryGetComponent(out IPhysBody? physics) &&
physics.BodyType == BodyType.Static)
if (Owner.TryGetComponent(out IPhysicsComponent? physics) &&
physics.Anchored)
{
Owner.PopupMessage(user, Loc.GetString("It's stuck."));
return;

View File

@@ -4,7 +4,6 @@ using Content.Shared.Interfaces;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
@@ -29,9 +28,9 @@ namespace Content.Server.GameObjects.Components.Rotatable
private void TryRotate(IEntity user, Angle angle)
{
if (!RotateWhileAnchored && Owner.TryGetComponent(out IPhysBody physics))
if (!RotateWhileAnchored && Owner.TryGetComponent(out IPhysicsComponent physics))
{
if (physics.BodyType == BodyType.Static)
if (physics.Anchored)
{
Owner.PopupMessage(user, Loc.GetString("It's stuck."));
return;
@@ -46,7 +45,7 @@ namespace Content.Server.GameObjects.Components.Rotatable
{
protected override void GetData(IEntity user, RotatableComponent component, VerbData data)
{
if (!ActionBlockerSystem.CanInteract(user) || (!component.RotateWhileAnchored && component.Owner.TryGetComponent(out IPhysBody physics) && physics.BodyType == BodyType.Static))
if (!ActionBlockerSystem.CanInteract(user) || (!component.RotateWhileAnchored && component.Owner.TryGetComponent(out IPhysicsComponent physics) && physics.Anchored))
{
data.Visibility = VerbVisibility.Invisible;
return;
@@ -68,7 +67,7 @@ namespace Content.Server.GameObjects.Components.Rotatable
{
protected override void GetData(IEntity user, RotatableComponent component, VerbData data)
{
if (!ActionBlockerSystem.CanInteract(user) || (!component.RotateWhileAnchored && component.Owner.TryGetComponent(out IPhysBody physics) && physics.BodyType == BodyType.Static))
if (!ActionBlockerSystem.CanInteract(user) || (!component.RotateWhileAnchored && component.Owner.TryGetComponent(out IPhysicsComponent physics) && physics.Anchored))
{
data.Visibility = VerbVisibility.Invisible;
return;

View File

@@ -1,6 +1,5 @@
#nullable enable
using Robust.Shared.GameObjects;
using Robust.Shared.Physics;
namespace Content.Server.GameObjects.Components.Singularity
{
@@ -10,7 +9,7 @@ namespace Content.Server.GameObjects.Components.Singularity
public override string Name => "ContainmentField";
public ContainmentFieldConnection? Parent;
public void CollideWith(IPhysBody ourBody, IPhysBody otherBody)
public void CollideWith(IEntity collidedWith)
{
if (Parent == null)
{
@@ -18,7 +17,7 @@ namespace Content.Server.GameObjects.Components.Singularity
return;
}
Parent.TryRepell(Owner, otherBody.Entity);
Parent.TryRepell(Owner, collidedWith);
}
}
}

View File

@@ -1,11 +1,11 @@
using System;
using System.Collections.Generic;
using System.Threading;
using Content.Shared.Physics;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Timer = Robust.Shared.Timing.Timer;
namespace Content.Server.GameObjects.Components.Singularity
@@ -90,12 +90,10 @@ namespace Content.Server.GameObjects.Components.Singularity
/// <param name="toRepell">Entity to repell.</param>
public void TryRepell(IEntity repellFrom, IEntity toRepell)
{
// TODO: Fix this also it's fucking repel
if (!_fields.Contains(repellFrom) || !toRepell.TryGetComponent<IPhysBody>(out var collidableComponent)) return;
if (!_fields.Contains(repellFrom) || !toRepell.TryGetComponent<IPhysicsComponent>(out var collidableComponent)) return;
return;
var speed = 5;
//var containmentFieldRepellController = collidableComponent.EnsureController<ContainmentFieldRepellController>();
var containmentFieldRepellController = collidableComponent.EnsureController<ContainmentFieldRepellController>();
if (!CanRepell(toRepell))
{
@@ -108,22 +106,22 @@ namespace Content.Server.GameObjects.Components.Singularity
{
if (repellFrom.Transform.WorldPosition.X.CompareTo(toRepell.Transform.WorldPosition.X) > 0)
{
//containmentFieldRepellController.Repell(Direction.West, speed);
containmentFieldRepellController.Repell(Direction.West, speed);
}
else
{
//containmentFieldRepellController.Repell(Direction.East, speed);
containmentFieldRepellController.Repell(Direction.East, speed);
}
}
else
{
if (repellFrom.Transform.WorldPosition.Y.CompareTo(toRepell.Transform.WorldPosition.Y) > 0)
{
//containmentFieldRepellController.Repell(Direction.South, speed);
containmentFieldRepellController.Repell(Direction.South, speed);
}
else
{
//containmentFieldRepellController.Repell(Direction.North, speed);
containmentFieldRepellController.Repell(Direction.North, speed);
}
}

View File

@@ -10,7 +10,6 @@ using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Broadphase;
using Robust.Shared.ViewVariables;
using Robust.Server.GameObjects;
@@ -118,7 +117,7 @@ namespace Content.Server.GameObjects.Components.Singularity
var dirVec = direction.ToVec();
var ray = new CollisionRay(Owner.Transform.WorldPosition, dirVec, (int) CollisionGroup.MobMask);
var rawRayCastResults = EntitySystem.Get<SharedBroadPhaseSystem>().IntersectRay(Owner.Transform.MapID, ray, 4.5f, Owner, false);
var rawRayCastResults = _physicsManager.IntersectRay(Owner.Transform.MapID, ray, 4.5f, Owner, false);
var rayCastResults = rawRayCastResults as RayCastResults[] ?? rawRayCastResults.ToArray();
if(!rayCastResults.Any()) continue;
@@ -183,9 +182,9 @@ namespace Content.Server.GameObjects.Components.Singularity
}
}
public void CollideWith(IPhysBody ourBody, IPhysBody otherBody)
public void CollideWith(IEntity collidedWith)
{
if (otherBody.Entity.HasComponent<EmitterBoltComponent>())
if(collidedWith.HasComponent<EmitterBoltComponent>())
{
ReceivePower(4);
}

View File

@@ -254,7 +254,7 @@ namespace Content.Server.GameObjects.Components.Singularity
return;
}
physicsComponent.BodyStatus = BodyStatus.InAir;
physicsComponent.Status = BodyStatus.InAir;
if (!projectile.TryGetComponent<ProjectileComponent>(out var projectileComponent))
{
@@ -265,6 +265,7 @@ namespace Content.Server.GameObjects.Components.Singularity
projectileComponent.IgnoreEntity(Owner);
physicsComponent
.EnsureController<BulletController>()
.LinearVelocity = Owner.Transform.WorldRotation.ToVec() * 20f;
projectile.Transform.LocalRotation = Owner.Transform.WorldRotation;

View File

@@ -14,7 +14,6 @@ using Robust.Shared.Log;
using Robust.Shared.Maths;
using Robust.Shared.Map;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Dynamics.Shapes;
using Robust.Shared.Random;
using Robust.Shared.Timing;
@@ -39,6 +38,7 @@ namespace Content.Server.GameObjects.Components.Singularity
_energy = value;
if (_energy <= 0)
{
if(_singularityController != null) _singularityController.LinearVelocity = Vector2.Zero;
_spriteComponent?.LayerSetVisible(0, false);
Owner.Delete();
@@ -75,7 +75,7 @@ namespace Content.Server.GameObjects.Components.Singularity
_spriteComponent?.LayerSetRSI(0, "Effects/Singularity/singularity_" + _level + ".rsi");
_spriteComponent?.LayerSetState(0, "singularity_" + _level);
if(_collidableComponent != null && _collidableComponent.Fixtures.Any() && _collidableComponent.Fixtures[0].Shape is PhysShapeCircle circle)
if(_collidableComponent != null && _collidableComponent.PhysicsShapes.Any() && _collidableComponent.PhysicsShapes[0] is PhysShapeCircle circle)
{
circle.Radius = _level - 0.5f;
}
@@ -95,6 +95,7 @@ namespace Content.Server.GameObjects.Components.Singularity
_ => 0
};
private SingularityController? _singularityController;
private PhysicsComponent? _collidableComponent;
private SpriteComponent? _spriteComponent;
private RadiationPulseComponent? _radiationPulseComponent;
@@ -128,6 +129,9 @@ namespace Content.Server.GameObjects.Components.Singularity
Logger.Error("SingularityComponent was spawned without SpriteComponent");
}
_singularityController = _collidableComponent?.EnsureController<SingularityController>();
if(_singularityController!=null)_singularityController.ControlledComponent = _collidableComponent;
if (!Owner.TryGetComponent(out _radiationPulseComponent))
{
Logger.Error("SingularityComponent was spawned without RadiationPulseComponent");
@@ -136,18 +140,60 @@ namespace Content.Server.GameObjects.Components.Singularity
Level = 1;
}
public void Update(int seconds)
public void Update()
{
Energy -= EnergyDrain * seconds;
Energy -= EnergyDrain;
if(Level == 1) return;
//pushing
var pushVector = new Vector2((_random.Next(-10, 10)), _random.Next(-10, 10));
while (pushVector.X == 0 && pushVector.Y == 0)
{
pushVector = new Vector2((_random.Next(-10, 10)), _random.Next(-10, 10));
}
_singularityController?.Push(pushVector.Normalized, 2);
}
void ICollideBehavior.CollideWith(IPhysBody ourBody, IPhysBody otherBody)
private readonly List<IEntity> _previousPulledEntities = new();
public void CleanupPulledEntities()
{
var otherEntity = otherBody.Entity;
if (otherEntity.TryGetComponent<IMapGridComponent>(out var mapGridComponent))
foreach (var previousPulledEntity in _previousPulledEntities)
{
foreach (var tile in mapGridComponent.Grid.GetTilesIntersecting(ourBody.GetWorldAABB()))
if(previousPulledEntity.Deleted) continue;
if (!previousPulledEntity.TryGetComponent<PhysicsComponent>(out var collidableComponent)) continue;
var controller = collidableComponent.EnsureController<SingularityPullController>();
controller.StopPull();
}
_previousPulledEntities.Clear();
}
public void PullUpdate()
{
CleanupPulledEntities();
var entitiesToPull = Owner.EntityManager.GetEntitiesInRange(Owner.Transform.Coordinates, Level * 10);
foreach (var entity in entitiesToPull)
{
if (!entity.TryGetComponent<PhysicsComponent>(out var collidableComponent)) continue;
if (entity.HasComponent<GhostComponent>()) continue;
var controller = collidableComponent.EnsureController<SingularityPullController>();
if(Owner.Transform.Coordinates.EntityId != entity.Transform.Coordinates.EntityId) continue;
var vec = (Owner.Transform.Coordinates - entity.Transform.Coordinates).Position;
if (vec == Vector2.Zero) continue;
var speed = 10 / vec.Length * Level;
controller.Pull(vec.Normalized, speed);
_previousPulledEntities.Add(entity);
}
}
void ICollideBehavior.CollideWith(IEntity entity)
{
if (_collidableComponent == null) return; //how did it even collide then? :D
if (entity.TryGetComponent<IMapGridComponent>(out var mapGridComponent))
{
foreach (var tile in mapGridComponent.Grid.GetTilesIntersecting(((IPhysBody) _collidableComponent).WorldAABB))
{
mapGridComponent.Grid.SetTile(tile.GridIndices, Tile.Empty);
Energy++;
@@ -155,14 +201,14 @@ namespace Content.Server.GameObjects.Components.Singularity
return;
}
if (otherEntity.HasComponent<ContainmentFieldComponent>() || (otherEntity.TryGetComponent<ContainmentFieldGeneratorComponent>(out var component) && component.CanRepell(Owner)))
if (entity.HasComponent<ContainmentFieldComponent>() || (entity.TryGetComponent<ContainmentFieldGeneratorComponent>(out var component) && component.CanRepell(Owner)))
{
return;
}
if (otherEntity.IsInContainer()) return;
if (entity.IsInContainer()) return;
otherEntity.Delete();
entity.Delete();
Energy++;
}
@@ -170,6 +216,7 @@ namespace Content.Server.GameObjects.Components.Singularity
{
_playingSound?.Stop();
_audioSystem.PlayAtCoords("/Audio/Effects/singularity_collapse.ogg", Owner.Transform.Coordinates);
CleanupPulledEntities();
base.OnRemove();
}
}

View File

@@ -5,7 +5,6 @@ using Content.Shared.Atmos;
using Content.Shared.Damage;
using Content.Shared.GameObjects.Components.Damage;
using Robust.Shared.GameObjects;
using Robust.Shared.Physics;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
@@ -30,7 +29,7 @@ namespace Content.Server.GameObjects.Components.Temperature
[ViewVariables] public float HeatCapacity {
get
{
if (Owner.TryGetComponent<IPhysBody>(out var physics))
if (Owner.TryGetComponent<IPhysicsComponent>(out var physics))
{
return SpecificHeat * physics.Mass;
}

View File

@@ -1,6 +1,5 @@
using System;
using Content.Shared.GameObjects.Components.Weapons;
using Content.Shared.Physics;
using Content.Shared.Utility;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
@@ -32,17 +31,18 @@ namespace Content.Server.GameObjects.Components.Weapon
public static void FlashAreaHelper(IEntity source, float range, float duration, string sound = null)
{
foreach (var entity in source.EntityManager.GetEntitiesInRange(source.Transform.Coordinates, range))
foreach (var entity in IoCManager.Resolve<IEntityManager>().GetEntitiesInRange(source.Transform.Coordinates, range))
{
if (!entity.TryGetComponent(out FlashableComponent flashable) ||
!source.InRangeUnobstructed(entity, range, CollisionGroup.Opaque)) continue;
if (!source.InRangeUnobstructed(entity, range, popup: true))
continue;
flashable.Flash(duration);
if(entity.TryGetComponent(out FlashableComponent flashable))
flashable.Flash(duration);
}
if (!string.IsNullOrEmpty(sound))
{
EntitySystem.Get<AudioSystem>().PlayAtCoords(sound, source.Transform.Coordinates);
IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<AudioSystem>().PlayAtCoords(sound, source.Transform.Coordinates);
}
}
}

View File

@@ -12,7 +12,6 @@ using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Broadphase;
using Robust.Shared.Serialization;
using Robust.Shared.Timing;
using Robust.Shared.ViewVariables;
@@ -197,13 +196,10 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
for (var i = 0; i < increments; i++)
{
var castAngle = new Angle(baseAngle + increment * i);
var res = EntitySystem.Get<SharedBroadPhaseSystem>().IntersectRay(mapId,
new CollisionRay(position, castAngle.ToVec(),
(int) (CollisionGroup.Impassable | CollisionGroup.MobImpassable)), Range, ignore).ToList();
if (res.Count != 0)
var res = _physicsManager.IntersectRay(mapId, new CollisionRay(position, castAngle.ToWorldVec(), (int) (CollisionGroup.Impassable|CollisionGroup.MobImpassable)), Range, ignore).FirstOrDefault();
if (res.HitEntity != null)
{
resSet.Add(res[0].HitEntity);
resSet.Add(res.HitEntity);
}
}

View File

@@ -20,7 +20,6 @@ using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Broadphase;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Serialization;
@@ -384,14 +383,15 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
projectileAngle = angle;
}
var physics = projectile.GetComponent<IPhysBody>();
physics.BodyStatus = BodyStatus.InAir;
var physics = projectile.GetComponent<IPhysicsComponent>();
physics.Status = BodyStatus.InAir;
var projectileComponent = projectile.GetComponent<ProjectileComponent>();
projectileComponent.IgnoreEntity(shooter);
projectile
.GetComponent<IPhysBody>()
.GetComponent<IPhysicsComponent>()
.EnsureController<BulletController>()
.LinearVelocity = projectileAngle.ToVec() * velocity;
projectile.Transform.LocalRotation = projectileAngle + MathHelper.PiOver2;
@@ -421,7 +421,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
private void FireHitscan(IEntity shooter, HitscanComponent hitscan, Angle angle)
{
var ray = new CollisionRay(Owner.Transform.Coordinates.ToMapPos(Owner.EntityManager), angle.ToVec(), (int) hitscan.CollisionMask);
var physicsManager = EntitySystem.Get<SharedBroadPhaseSystem>();
var physicsManager = IoCManager.Resolve<IPhysicsManager>();
var rayCastResults = physicsManager.IntersectRay(Owner.Transform.MapID, ray, hitscan.MaxLength, shooter, false).ToList();
if (rayCastResults.Count >= 1)