* Content side new physics structure

* BroadPhase outline done

* But we need to fix WorldAABB

* Fix static pvs AABB

* Fix import

* Rando fixes

* B is for balloon

* Change human mob hitbox to circle

* Decent movement

* Start adding friction to player controller

I think it's the best way to go about it to keep other objects somewhat consistent for physics.

* This baby can fit so many physics bugs in it.

* Slight mob mover optimisations.

* Player mover kinda works okay.

* Beginnings of testbed

* More testbed

* Circlestack bed

* Namespaces

* BB fixes

* Pull WorldAABB

* Joint pulling

* Semi-decent movement I guess.

* Pulling better

* Bullet controller + old movement

* im too dumb for this shit

* Use kinematic mob controller again

It's probably for the best TBH

* Stashed shitcode

* Remove SlipController

* In which movement code is entirely refactored

* Singularity fix

* Fix ApplyLinearImpulse

* MoveRelay fix

* Fix door collisions

* Disable subfloor collisions

Saves on broadphase a fair bit

* Re-implement ClimbController

* Zumzum's pressure

* Laggy item throwing

* Minor atmos change

* Some caching

* Optimise controllers

* Optimise CollideWith to hell and back

* Re-do throwing and tile friction

* Landing too

* Optimise controllers

* Move CCVars and other stuff swept is beautiful

* Cleanup a bunch of controllers

* Fix shooting and high pressure movement controller

* Flashing improvements

* Stuff and things

* Combat collisions

* Combat mode collisions

* Pulling distance joint again

* Cleanup physics interfaces

* More like scuffedularity

* Shit's fucked

* Haha tests go green

* Bigmoneycrab

Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
This commit is contained in:
metalgearsloth
2021-03-01 03:11:29 +11:00
committed by GitHub
parent 9deee05279
commit 3e64fd56a1
211 changed files with 2602 additions and 2562 deletions

View File

@@ -7,6 +7,7 @@ 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;
@@ -42,7 +43,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<IPhysicsComponent>())
if (!Owner.HasComponent<IPhysBody>())
{
return false;
}
@@ -74,8 +75,8 @@ namespace Content.Server.GameObjects.Components
return false;
}
var physics = Owner.GetComponent<IPhysicsComponent>();
physics.Anchored = true;
var physics = Owner.GetComponent<IPhysBody>();
physics.BodyType = BodyType.Static;
if (Owner.TryGetComponent(out PullableComponent? pullableComponent))
{
@@ -105,8 +106,8 @@ namespace Content.Server.GameObjects.Components
return false;
}
var physics = Owner.GetComponent<IPhysicsComponent>();
physics.Anchored = false;
var physics = Owner.GetComponent<IPhysBody>();
physics.BodyType = BodyType.Dynamic;
return true;
}
@@ -120,12 +121,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 IPhysicsComponent? physics))
if (!Owner.TryGetComponent(out IPhysBody? physics))
{
return false;
}
return physics.Anchored ?
return physics.BodyType == BodyType.Static ?
await TryUnAnchor(user, utilizing, force) :
await TryAnchor(user, utilizing, force);
}

View File

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

View File

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

View File

@@ -1,6 +1,14 @@
#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;
@@ -9,8 +17,16 @@ 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)]
@@ -27,6 +43,77 @@ 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,6 +7,7 @@ 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;
@@ -29,8 +30,6 @@ 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()
@@ -40,18 +39,16 @@ namespace Content.Server.GameObjects.Components.Chemistry
Owner.EnsureComponentWarn(out SolutionContainerComponent _);
}
public void Start(Vector2 dir, float velocity, EntityCoordinates target, float aliveTime)
public void Start(Vector2 dir, float speed, EntityCoordinates target, float aliveTime)
{
_running = true;
_target = target;
_direction = dir;
_velocity = velocity;
_aliveTime = aliveTime;
// Set Move
if (Owner.TryGetComponent(out IPhysicsComponent physics))
if (Owner.TryGetComponent(out PhysicsComponent physics))
{
var controller = physics.EnsureController<VaporController>();
controller.Move(_direction, _velocity);
physics.BodyStatus = BodyStatus.InAir;
physics.ApplyLinearImpulse(dir * speed);
}
}
@@ -72,7 +69,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
_timer += frameTime;
_reactTimer += frameTime;
if (_reactTimer >= ReactTime && Owner.TryGetComponent(out IPhysicsComponent physics))
if (_reactTimer >= ReactTime)
{
_reactTimer = 0;
var mapGrid = _mapManager.GetGrid(Owner.Transform.GridID);
@@ -90,12 +87,6 @@ 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)
@@ -127,26 +118,17 @@ namespace Content.Server.GameObjects.Components.Chemistry
return true;
}
void ICollideBehavior.CollideWith(IEntity collidedWith)
void ICollideBehavior.CollideWith(IPhysBody ourBody, IPhysBody otherBody)
{
if (!Owner.TryGetComponent(out SolutionContainerComponent contents))
return;
contents.Solution.DoEntityReaction(collidedWith, ReactionMethod.Touch);
contents.Solution.DoEntityReaction(otherBody.Entity, ReactionMethod.Touch);
// Check for collision with a impassable object (e.g. wall) and stop
if (collidedWith.TryGetComponent(out IPhysicsComponent physics))
if ((otherBody.CollisionLayer & (int) CollisionGroup.Impassable) != 0 && otherBody.Hard)
{
if ((physics.CollisionLayer & (int) CollisionGroup.Impassable) != 0 && physics.Hard)
{
if (Owner.TryGetComponent(out IPhysicsComponent coll))
{
var controller = coll.EnsureController<VaporController>();
controller.Stop();
}
Owner.Delete();
}
Owner.Delete();
}
}
}

View File

@@ -16,6 +16,7 @@ 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;
@@ -436,10 +437,10 @@ namespace Content.Server.GameObjects.Components.Construction
}
}
if (Owner.TryGetComponent(out IPhysicsComponent? physics) &&
entity.TryGetComponent(out IPhysicsComponent? otherPhysics))
if (Owner.TryGetComponent(out IPhysBody? physics) &&
entity.TryGetComponent(out IPhysBody? otherPhysics))
{
otherPhysics.Anchored = physics.Anchored;
otherPhysics.BodyType = physics.BodyType;
}
Owner.Delete();

View File

@@ -4,11 +4,13 @@ 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;
@@ -27,6 +29,8 @@ 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>
@@ -86,7 +90,7 @@ namespace Content.Server.GameObjects.Components.Conveyor
/// <returns>
/// The angle when taking into account if the conveyor is reversed
/// </returns>
private Angle GetAngle()
public Angle GetAngle()
{
var adjustment = _state == ConveyorState.Reversed ? MathHelper.Pi : 0;
var radians = MathHelper.DegreesToRadians(_angle);
@@ -94,7 +98,7 @@ namespace Content.Server.GameObjects.Components.Conveyor
return new Angle(Owner.Transform.LocalRotation.Theta + radians + adjustment);
}
private bool CanRun()
public bool CanRun()
{
if (State == ConveyorState.Off)
{
@@ -115,15 +119,16 @@ namespace Content.Server.GameObjects.Components.Conveyor
return true;
}
private bool CanMove(IEntity entity)
public 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 IPhysicsComponent? physics) ||
physics.Anchored)
if (!entity.TryGetComponent(out IPhysBody? physics) ||
physics.BodyType == BodyType.Static)
{
return false;
}
@@ -146,31 +151,6 @@ 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,6 +6,7 @@ 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;
@@ -46,16 +47,16 @@ namespace Content.Server.GameObjects.Components.Damage
serializer.DataField(this, x => x.StunMinimumDamage, "stunMinimumDamage", 10);
}
public void CollideWith(IEntity collidedWith)
public void CollideWith(IPhysBody ourBody, IPhysBody otherBody)
{
if (!Owner.TryGetComponent(out IPhysicsComponent physics) || !Owner.TryGetComponent(out IDamageableComponent damageable)) return;
if (!Owner.TryGetComponent(out IDamageableComponent damageable)) return;
var speed = physics.LinearVelocity.Length;
var speed = ourBody.LinearVelocity.Length;
if (speed < MinimumSpeed) return;
if(!string.IsNullOrEmpty(SoundHit))
EntitySystem.Get<AudioSystem>().PlayFromEntity(SoundHit, collidedWith, AudioHelpers.WithVariation(0.125f).WithVolume(-0.125f));
EntitySystem.Get<AudioSystem>().PlayFromEntity(SoundHit, otherBody.Entity, AudioHelpers.WithVariation(0.125f).WithVolume(-0.125f));
if ((_gameTiming.CurTime - _lastHit).TotalSeconds < DamageCooldown)
return;
@@ -67,7 +68,7 @@ namespace Content.Server.GameObjects.Components.Damage
if (Owner.TryGetComponent(out StunnableComponent stun) && _robustRandom.Prob(StunChance))
stun.Stun(StunSeconds);
damageable.ChangeDamage(Damage, damage, false, collidedWith);
damageable.ChangeDamage(Damage, damage, false, otherBody.Entity);
}
}
}

View File

@@ -10,6 +10,7 @@ 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;
@@ -80,7 +81,7 @@ namespace Content.Server.GameObjects.Components.Disposal
return false;
}
if (!entity.TryGetComponent(out IPhysicsComponent? physics) ||
if (!entity.TryGetComponent(out IPhysBody? physics) ||
!physics.CanCollide)
{
return false;
@@ -97,7 +98,7 @@ namespace Content.Server.GameObjects.Components.Disposal
return false;
}
if (entity.TryGetComponent(out IPhysicsComponent? physics))
if (entity.TryGetComponent(out IPhysBody? physics))
{
physics.CanCollide = false;
}
@@ -129,7 +130,7 @@ namespace Content.Server.GameObjects.Components.Disposal
foreach (var entity in _contents.ContainedEntities.ToArray())
{
if (entity.TryGetComponent(out IPhysicsComponent? physics))
if (entity.TryGetComponent(out IPhysBody? physics))
{
physics.CanCollide = true;
}

View File

@@ -26,6 +26,7 @@ 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;
@@ -142,7 +143,7 @@ namespace Content.Server.GameObjects.Components.Disposal
return false;
}
if (!entity.TryGetComponent(out IPhysicsComponent? physics) ||
if (!entity.TryGetComponent(out IPhysBody? physics) ||
!physics.CanCollide)
{
return false;

View File

@@ -16,6 +16,7 @@ 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;
@@ -33,8 +34,8 @@ namespace Content.Server.GameObjects.Components.Disposal
[ViewVariables]
public bool Anchored =>
!Owner.TryGetComponent(out IPhysicsComponent? physics) ||
physics.Anchored;
!Owner.TryGetComponent(out IPhysBody? physics) ||
physics.BodyType == BodyType.Static;
[ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(DisposalRouterUiKey.Key);

View File

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

View File

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

View File

@@ -15,6 +15,7 @@ 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;
@@ -372,7 +373,7 @@ namespace Content.Server.GameObjects.Components.Fluids
foreach (var entity in _snapGrid.GetInDir(direction))
{
if (entity.TryGetComponent(out IPhysicsComponent physics) &&
if (entity.TryGetComponent(out IPhysBody physics) &&
(physics.CollisionLayer & (int) CollisionGroup.Impassable) != 0)
{
puddle = default;

View File

@@ -27,6 +27,9 @@ 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
{
@@ -717,13 +720,13 @@ namespace Content.Server.GameObjects.Components.GUI
Dirty();
if (!message.Entity.TryGetComponent(out IPhysicsComponent? physics))
if (!message.Entity.TryGetComponent(out IPhysBody? physics))
{
return;
}
// set velocity to zero
physics.Stop();
physics.LinearVelocity = Vector2.Zero;
return;
}
}

View File

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

View File

@@ -1,6 +1,5 @@
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;
@@ -14,6 +13,7 @@ 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 IPhysicsComponent physics) &&
physics.Anchored)
if (Owner.TryGetComponent(out IPhysBody physics) &&
physics.BodyType == BodyType.Static)
{
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;
var throwForce = 1.0f;
float throwForce;
switch (eventArgs.Severity)
{
case ExplosionSeverity.Destruction:
throwForce = 3.0f;
throwForce = 30.0f;
break;
case ExplosionSeverity.Heavy:
throwForce = 2.0f;
throwForce = 20.0f;
break;
case ExplosionSeverity.Light:
throwForce = 1.0f;
default:
throwForce = 10.0f;
break;
}
Owner.Throw(throwForce, targetLocation, sourceLocation, true);
Owner.TryThrow(dirVec * throwForce);
}
}
}

View File

@@ -0,0 +1,49 @@
#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

@@ -0,0 +1,33 @@
#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,6 +4,7 @@ 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
{
@@ -30,7 +31,7 @@ namespace Content.Server.GameObjects.Components.Mobs.State
EntitySystem.Get<StandingStateSystem>().Down(entity);
if (entity.TryGetComponent(out IPhysicsComponent physics))
if (entity.TryGetComponent(out IPhysBody physics))
{
physics.CanCollide = false;
}
@@ -40,7 +41,7 @@ namespace Content.Server.GameObjects.Components.Mobs.State
{
base.ExitState(entity);
if (entity.TryGetComponent(out IPhysicsComponent physics))
if (entity.TryGetComponent(out IPhysBody physics))
{
physics.CanCollide = true;
}

View File

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

View File

@@ -13,6 +13,7 @@ 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;
@@ -164,9 +165,11 @@ namespace Content.Server.GameObjects.Components.Movement
var result = await EntitySystem.Get<DoAfterSystem>().DoAfter(doAfterEventArgs);
if (result != DoAfterStatus.Cancelled && entityToMove.TryGetComponent(out IPhysicsComponent body) && body.PhysicsShapes.Count >= 1)
if (result != DoAfterStatus.Cancelled && entityToMove.TryGetComponent(out PhysicsComponent body) && body.Fixtures.Count >= 1)
{
var direction = (Owner.Transform.WorldPosition - entityToMove.Transform.WorldPosition).Normalized;
var entityPos = entityToMove.Transform.WorldPosition;
var direction = (Owner.Transform.WorldPosition - entityPos).Normalized;
var endPoint = Owner.Transform.WorldPosition;
var climbMode = entityToMove.GetComponent<ClimbingComponent>();
@@ -174,14 +177,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(entityToMove.Transform.WorldPosition.X, endPoint.Y);
endPoint = new Vector2(entityPos.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, entityToMove.Transform.WorldPosition.Y);
endPoint = new Vector2(endPoint.X, entityPos.Y);
}
climbMode.TryMoveTo(entityToMove.Transform.WorldPosition, endPoint);
climbMode.TryMoveTo(entityPos, 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
@@ -209,9 +212,12 @@ namespace Content.Server.GameObjects.Components.Movement
var result = await EntitySystem.Get<DoAfterSystem>().DoAfter(doAfterEventArgs);
if (result != DoAfterStatus.Cancelled && user.TryGetComponent(out IPhysicsComponent body) && body.PhysicsShapes.Count >= 1)
if (result != DoAfterStatus.Cancelled && user.TryGetComponent(out PhysicsComponent body) && body.Fixtures.Count >= 1)
{
var direction = (Owner.Transform.WorldPosition - user.Transform.WorldPosition).Normalized;
// TODO: Remove the copy-paste code
var userPos = user.Transform.WorldPosition;
var direction = (Owner.Transform.WorldPosition - userPos).Normalized;
var endPoint = Owner.Transform.WorldPosition;
var climbMode = user.GetComponent<ClimbingComponent>();
@@ -226,7 +232,7 @@ namespace Content.Server.GameObjects.Components.Movement
endPoint = new Vector2(endPoint.X, user.Transform.WorldPosition.Y);
}
climbMode.TryMoveTo(user.Transform.WorldPosition, endPoint);
climbMode.TryMoveTo(userPos, endPoint);
var othersMessage = Loc.GetString("{0:theName} jumps onto {1:theName}!", user, Owner);
user.PopupMessageOtherClients(othersMessage);

View File

@@ -1,10 +1,13 @@
#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
{
@@ -12,23 +15,41 @@ namespace Content.Server.GameObjects.Components.Movement
[ComponentReference(typeof(SharedClimbingComponent))]
public class ClimbingComponent : SharedClimbingComponent
{
private bool _isClimbing;
private ClimbController? _climbController;
[Dependency] private readonly IGameTiming _gameTiming = default!;
public override bool IsClimbing
{
get => _isClimbing;
get => base.IsClimbing;
set
{
if (_isClimbing == value)
return;
if (!value)
base.IsClimbing = value;
if (value)
{
Body?.TryRemoveController<ClimbController>();
StartClimbTime = IoCManager.Resolve<IGameTiming>().CurTime;
EntitySystem.Get<ClimbSystem>().AddActiveClimber(this);
OwnerIsTransitioning = true;
}
else
{
EntitySystem.Get<ClimbSystem>().RemoveActiveClimber(this);
OwnerIsTransitioning = false;
}
_isClimbing = value;
Dirty();
}
}
protected override bool OwnerIsTransitioning
{
get => base.OwnerIsTransitioning;
set
{
if (value == base.OwnerIsTransitioning) return;
base.OwnerIsTransitioning = value;
Dirty();
}
}
@@ -51,38 +72,36 @@ namespace Content.Server.GameObjects.Components.Movement
/// </summary>
public void TryMoveTo(Vector2 from, Vector2 to)
{
if (Body == null)
return;
if (Body == null) return;
_climbController = Body.EnsureController<ClimbController>();
_climbController.TryMoveTo(from, to);
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;
});
}
public void Update()
{
if (!IsClimbing || Body == null)
return;
if (_climbController != null && (_climbController.IsBlocked || !_climbController.IsActive))
if (!IsClimbing || _gameTiming.CurTime < TimeSpan.FromSeconds(BufferTime) + StartClimbTime)
{
if (Body.TryRemoveController<ClimbController>())
{
_climbController = null;
}
return;
}
if (IsClimbing)
Body.WakeBody();
if (!IsOnClimbableThisFrame && IsClimbing && _climbController == null)
if (!IsOnClimbableThisFrame && IsClimbing)
IsClimbing = false;
IsOnClimbableThisFrame = false;
}
public override ComponentState GetComponentState(ICommonSession player)
{
return new ClimbModeComponentState(_isClimbing);
return new ClimbModeComponentState(_isClimbing, OwnerIsTransitioning);
}
}
}

View File

@@ -1,19 +0,0 @@
#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,6 +10,8 @@ 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;
@@ -19,8 +21,6 @@ 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,43 +39,19 @@ 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; } = (Vector2.Zero, Vector2.Zero);
public EntityCoordinates LastPosition { get; set; }
public float StepSoundDistance { get; set; }
public (Vector2 walking, Vector2 sprinting) VelocityDir { get; set; } = (Vector2.Zero, Vector2.Zero);
public void SetVelocityDirection(Direction direction, ushort subTick, bool enabled)
{
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);
}
VelocityDir = (CalcNewVelocity(direction, enabled), Vector2.Zero);
}
public void SetSprinting(ushort subTick, bool walking)

View File

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

View File

@@ -6,6 +6,7 @@ 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
@@ -15,9 +16,9 @@ namespace Content.Server.GameObjects.Components.PA
{
public override string Name => "ParticleProjectile";
private ParticleAcceleratorPowerState _state;
public void CollideWith(IEntity collidedWith)
public void CollideWith(IPhysBody ourBody, IPhysBody otherBody)
{
if (collidedWith.TryGetComponent<SingularityComponent>(out var singularityComponent))
if (otherBody.Entity.TryGetComponent<SingularityComponent>(out var singularityComponent))
{
var multiplier = _state switch
{
@@ -30,8 +31,8 @@ namespace Content.Server.GameObjects.Components.PA
};
singularityComponent.Energy += 10 * multiplier;
Owner.Delete();
}else if (collidedWith.TryGetComponent<SingularityGeneratorComponent>(out var singularityGeneratorComponent)
)
}
else if (otherBody.Entity.TryGetComponent<SingularityGeneratorComponent>(out var singularityGeneratorComponent))
{
singularityGeneratorComponent.Power += _state switch
{
@@ -55,7 +56,7 @@ namespace Content.Server.GameObjects.Components.PA
Logger.Error("ParticleProjectile tried firing, but it was spawned without a CollidableComponent");
return;
}
physicsComponent.Status = BodyStatus.InAir;
physicsComponent.BodyStatus = BodyStatus.InAir;
if (!Owner.TryGetComponent<ProjectileComponent>(out var projectileComponent))
{
@@ -81,7 +82,6 @@ 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,6 +5,7 @@ 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;
@@ -168,11 +169,11 @@ namespace Content.Server.GameObjects.Components.Portal
StartCooldown();
}
public void CollideWith(IEntity collidedWith)
public void CollideWith(IPhysBody ourBody, IPhysBody otherBody)
{
if (_onCooldown == false)
{
TryPortalEntity(collidedWith);
TryPortalEntity(otherBody.Entity);
}
}
}

View File

@@ -9,6 +9,7 @@ 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;
@@ -104,7 +105,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<IPhysicsComponent>() || entity.HasComponent<TeleporterComponent>())
if (entity.HasComponent<IPhysBody>() || entity.HasComponent<TeleporterComponent>())
{
return;
}
@@ -148,7 +149,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<IPhysicsComponent>() || entity.HasComponent<PortalComponent>())
if (entity.HasComponent<IPhysBody>() || entity.HasComponent<PortalComponent>())
{
return false;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -19,6 +19,7 @@ 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;
@@ -30,7 +31,7 @@ namespace Content.Server.GameObjects.Components.Recycling
{
public override string Name => "Recycler";
private readonly List<IEntity> _intersecting = new();
public List<IEntity> Intersecting { get; set; } = new();
/// <summary>
/// Whether or not sentient beings will be recycled
@@ -72,9 +73,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
@@ -93,7 +94,7 @@ namespace Content.Server.GameObjects.Components.Recycling
recyclable.Recycle(_efficiency);
}
private bool CanRun()
public bool CanRun()
{
if (Owner.TryGetComponent(out PowerReceiverComponent? receiver) &&
!receiver.Powered)
@@ -109,15 +110,15 @@ namespace Content.Server.GameObjects.Components.Recycling
return true;
}
private bool CanMove(IEntity entity)
public bool CanMove(IEntity entity)
{
if (entity == Owner)
{
return false;
}
if (!entity.TryGetComponent(out IPhysicsComponent? physics) ||
physics.Anchored)
if (!entity.TryGetComponent(out IPhysBody? physics) ||
physics.BodyType == BodyType.Static)
{
return false;
}
@@ -140,34 +141,6 @@ 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);
@@ -176,9 +149,9 @@ namespace Content.Server.GameObjects.Components.Recycling
serializer.DataField(ref _efficiency, "efficiency", 0.25f);
}
void ICollideBehavior.CollideWith(IEntity collidedWith)
void ICollideBehavior.CollideWith(IPhysBody ourBody, IPhysBody otherBody)
{
Recycle(collidedWith);
Recycle(otherBody.Entity);
}
SuicideKind ISuicideAct.Suicide(IEntity victim, IChatManager chat)

View File

@@ -4,6 +4,7 @@ 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
@@ -17,8 +18,8 @@ namespace Content.Server.GameObjects.Components.Rotatable
private void TryFlip(IEntity user)
{
if (Owner.TryGetComponent(out IPhysicsComponent? physics) &&
physics.Anchored)
if (Owner.TryGetComponent(out IPhysBody? physics) &&
physics.BodyType == BodyType.Static)
{
Owner.PopupMessage(user, Loc.GetString("It's stuck."));
return;

View File

@@ -4,6 +4,7 @@ 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;
@@ -28,9 +29,9 @@ namespace Content.Server.GameObjects.Components.Rotatable
private void TryRotate(IEntity user, Angle angle)
{
if (!RotateWhileAnchored && Owner.TryGetComponent(out IPhysicsComponent physics))
if (!RotateWhileAnchored && Owner.TryGetComponent(out IPhysBody physics))
{
if (physics.Anchored)
if (physics.BodyType == BodyType.Static)
{
Owner.PopupMessage(user, Loc.GetString("It's stuck."));
return;
@@ -45,7 +46,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 IPhysicsComponent physics) && physics.Anchored))
if (!ActionBlockerSystem.CanInteract(user) || (!component.RotateWhileAnchored && component.Owner.TryGetComponent(out IPhysBody physics) && physics.BodyType == BodyType.Static))
{
data.Visibility = VerbVisibility.Invisible;
return;
@@ -67,7 +68,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 IPhysicsComponent physics) && physics.Anchored))
if (!ActionBlockerSystem.CanInteract(user) || (!component.RotateWhileAnchored && component.Owner.TryGetComponent(out IPhysBody physics) && physics.BodyType == BodyType.Static))
{
data.Visibility = VerbVisibility.Invisible;
return;

View File

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

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,10 +90,12 @@ namespace Content.Server.GameObjects.Components.Singularity
/// <param name="toRepell">Entity to repell.</param>
public void TryRepell(IEntity repellFrom, IEntity toRepell)
{
if (!_fields.Contains(repellFrom) || !toRepell.TryGetComponent<IPhysicsComponent>(out var collidableComponent)) return;
// TODO: Fix this also it's fucking repel
if (!_fields.Contains(repellFrom) || !toRepell.TryGetComponent<IPhysBody>(out var collidableComponent)) return;
return;
var speed = 5;
var containmentFieldRepellController = collidableComponent.EnsureController<ContainmentFieldRepellController>();
//var containmentFieldRepellController = collidableComponent.EnsureController<ContainmentFieldRepellController>();
if (!CanRepell(toRepell))
{
@@ -106,22 +108,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,6 +10,7 @@ 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;
@@ -117,7 +118,7 @@ namespace Content.Server.GameObjects.Components.Singularity
var dirVec = direction.ToVec();
var ray = new CollisionRay(Owner.Transform.WorldPosition, dirVec, (int) CollisionGroup.MobMask);
var rawRayCastResults = _physicsManager.IntersectRay(Owner.Transform.MapID, ray, 4.5f, Owner, false);
var rawRayCastResults = EntitySystem.Get<SharedBroadPhaseSystem>().IntersectRay(Owner.Transform.MapID, ray, 4.5f, Owner, false);
var rayCastResults = rawRayCastResults as RayCastResults[] ?? rawRayCastResults.ToArray();
if(!rayCastResults.Any()) continue;
@@ -182,9 +183,9 @@ namespace Content.Server.GameObjects.Components.Singularity
}
}
public void CollideWith(IEntity collidedWith)
public void CollideWith(IPhysBody ourBody, IPhysBody otherBody)
{
if(collidedWith.HasComponent<EmitterBoltComponent>())
if (otherBody.Entity.HasComponent<EmitterBoltComponent>())
{
ReceivePower(4);
}

View File

@@ -254,7 +254,7 @@ namespace Content.Server.GameObjects.Components.Singularity
return;
}
physicsComponent.Status = BodyStatus.InAir;
physicsComponent.BodyStatus = BodyStatus.InAir;
if (!projectile.TryGetComponent<ProjectileComponent>(out var projectileComponent))
{
@@ -265,7 +265,6 @@ 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,6 +14,7 @@ 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;
@@ -38,7 +39,6 @@ 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.PhysicsShapes.Any() && _collidableComponent.PhysicsShapes[0] is PhysShapeCircle circle)
if(_collidableComponent != null && _collidableComponent.Fixtures.Any() && _collidableComponent.Fixtures[0].Shape is PhysShapeCircle circle)
{
circle.Radius = _level - 0.5f;
}
@@ -95,7 +95,6 @@ namespace Content.Server.GameObjects.Components.Singularity
_ => 0
};
private SingularityController? _singularityController;
private PhysicsComponent? _collidableComponent;
private SpriteComponent? _spriteComponent;
private RadiationPulseComponent? _radiationPulseComponent;
@@ -129,9 +128,6 @@ 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");
@@ -140,60 +136,18 @@ namespace Content.Server.GameObjects.Components.Singularity
Level = 1;
}
public void Update()
public void Update(int 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);
Energy -= EnergyDrain * seconds;
}
private readonly List<IEntity> _previousPulledEntities = new();
public void CleanupPulledEntities()
void ICollideBehavior.CollideWith(IPhysBody ourBody, IPhysBody otherBody)
{
foreach (var previousPulledEntity in _previousPulledEntities)
var otherEntity = otherBody.Entity;
if (otherEntity.TryGetComponent<IMapGridComponent>(out var mapGridComponent))
{
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))
foreach (var tile in mapGridComponent.Grid.GetTilesIntersecting(ourBody.GetWorldAABB()))
{
mapGridComponent.Grid.SetTile(tile.GridIndices, Tile.Empty);
Energy++;
@@ -201,14 +155,14 @@ namespace Content.Server.GameObjects.Components.Singularity
return;
}
if (entity.HasComponent<ContainmentFieldComponent>() || (entity.TryGetComponent<ContainmentFieldGeneratorComponent>(out var component) && component.CanRepell(Owner)))
if (otherEntity.HasComponent<ContainmentFieldComponent>() || (otherEntity.TryGetComponent<ContainmentFieldGeneratorComponent>(out var component) && component.CanRepell(Owner)))
{
return;
}
if (entity.IsInContainer()) return;
if (otherEntity.IsInContainer()) return;
entity.Delete();
otherEntity.Delete();
Energy++;
}
@@ -216,7 +170,6 @@ namespace Content.Server.GameObjects.Components.Singularity
{
_playingSound?.Stop();
_audioSystem.PlayAtCoords("/Audio/Effects/singularity_collapse.ogg", Owner.Transform.Coordinates);
CleanupPulledEntities();
base.OnRemove();
}
}

View File

@@ -5,6 +5,7 @@ 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;
@@ -29,7 +30,7 @@ namespace Content.Server.GameObjects.Components.Temperature
[ViewVariables] public float HeatCapacity {
get
{
if (Owner.TryGetComponent<IPhysicsComponent>(out var physics))
if (Owner.TryGetComponent<IPhysBody>(out var physics))
{
return SpecificHeat * physics.Mass;
}

View File

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

View File

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

View File

@@ -20,6 +20,7 @@ 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;
@@ -383,15 +384,14 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
projectileAngle = angle;
}
var physics = projectile.GetComponent<IPhysicsComponent>();
physics.Status = BodyStatus.InAir;
var physics = projectile.GetComponent<IPhysBody>();
physics.BodyStatus = BodyStatus.InAir;
var projectileComponent = projectile.GetComponent<ProjectileComponent>();
projectileComponent.IgnoreEntity(shooter);
projectile
.GetComponent<IPhysicsComponent>()
.EnsureController<BulletController>()
.GetComponent<IPhysBody>()
.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 = IoCManager.Resolve<IPhysicsManager>();
var physicsManager = EntitySystem.Get<SharedBroadPhaseSystem>();
var rayCastResults = physicsManager.IntersectRay(Owner.Transform.MapID, ray, hitscan.MaxLength, shooter, false).ToList();
if (rayCastResults.Count >= 1)

View File

@@ -10,6 +10,7 @@ using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
@@ -154,7 +155,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
var targetNode = _pathfindingSystem.GetNode(targetTile);
var collisionMask = 0;
if (entity.TryGetComponent(out IPhysicsComponent physics))
if (entity.TryGetComponent(out IPhysBody physics))
{
collisionMask = physics.CollisionMask;
}

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using Content.Server.GameObjects.Components.Access;
using Content.Server.GameObjects.Components.Movement;
using Robust.Shared.GameObjects;
using Robust.Shared.Physics;
namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
{
@@ -27,7 +28,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
public static ReachableArgs GetArgs(IEntity entity)
{
var collisionMask = 0;
if (entity.TryGetComponent(out IPhysicsComponent? physics))
if (entity.TryGetComponent(out IPhysBody? physics))
{
collisionMask = physics.CollisionMask;
}

View File

@@ -6,6 +6,7 @@ using Content.Server.GameObjects.Components.Doors;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Utility;
namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
@@ -40,7 +41,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
GenerateMask();
}
public static bool IsRelevant(IEntity entity, IPhysicsComponent physicsComponent)
public static bool IsRelevant(IEntity entity, IPhysBody physicsComponent)
{
if (entity.Transform.GridID == GridId.Invalid ||
(PathfindingSystem.TrackedCollisionLayers & physicsComponent.CollisionLayer) == 0)
@@ -256,7 +257,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
/// <param name="entity"></param>
/// TODO: These 2 methods currently don't account for a bunch of changes (e.g. airlock unpowered, wrenching, etc.)
/// TODO: Could probably optimise this slightly more.
public void AddEntity(IEntity entity, IPhysicsComponent physicsComponent)
public void AddEntity(IEntity entity, IPhysBody physicsComponent)
{
// If we're a door
if (entity.HasComponent<AirlockComponent>() || entity.HasComponent<ServerDoorComponent>())
@@ -275,7 +276,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
DebugTools.Assert((PathfindingSystem.TrackedCollisionLayers & physicsComponent.CollisionLayer) != 0);
if (!physicsComponent.Anchored)
if (physicsComponent.BodyType == BodyType.Static)
{
_physicsLayers.Add(entity, physicsComponent.CollisionLayer);
}

View File

@@ -11,6 +11,7 @@ using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Utility;
namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
@@ -29,7 +30,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
{
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
public IReadOnlyDictionary<GridId, Dictionary<Vector2i, PathfindingChunk>> Graph => _graph;
private readonly Dictionary<GridId, Dictionary<Vector2i, PathfindingChunk>> _graph = new();
@@ -81,7 +82,8 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
foreach (var update in _collidableUpdateQueue)
{
var entity = EntityManager.GetEntity(update.Owner);
if (!EntityManager.TryGetEntity(update.Owner, out var entity)) continue;
if (update.CanCollide)
{
HandleEntityAdd(entity);
@@ -262,7 +264,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
{
if (entity.Deleted ||
_lastKnownPositions.ContainsKey(entity) ||
!entity.TryGetComponent(out IPhysicsComponent physics) ||
!entity.TryGetComponent(out IPhysBody physics) ||
!PathfindingNode.IsRelevant(entity, physics))
{
return;
@@ -301,7 +303,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
{
// If we've moved to space or the likes then remove us.
if (moveEvent.Sender.Deleted ||
!moveEvent.Sender.TryGetComponent(out IPhysicsComponent physics) ||
!moveEvent.Sender.TryGetComponent(out IPhysBody physics) ||
!PathfindingNode.IsRelevant(moveEvent.Sender, physics) ||
moveEvent.NewPosition.GetGridId(EntityManager) == GridId.Invalid)
{
@@ -366,7 +368,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
public bool CanTraverse(IEntity entity, PathfindingNode node)
{
if (entity.TryGetComponent(out IPhysicsComponent physics) &&
if (entity.TryGetComponent(out IPhysBody physics) &&
(physics.CollisionMask & node.BlockedCollisionMask) != 0)
{
return false;

View File

@@ -13,6 +13,7 @@ using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
@@ -413,7 +414,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
var startTile = gridManager.GetTileRef(entity.Transform.Coordinates);
var endTile = gridManager.GetTileRef(steeringRequest.TargetGrid);
var collisionMask = 0;
if (entity.TryGetComponent(out IPhysicsComponent physics))
if (entity.TryGetComponent(out IPhysBody physics))
{
collisionMask = physics.CollisionMask;
}
@@ -599,7 +600,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
return Vector2.Zero;
}
if (target.TryGetComponent(out IPhysicsComponent physics))
if (target.TryGetComponent(out IPhysBody physics))
{
var targetDistance = (targetPos.Position - entityPos.Position);
targetPos = targetPos.Offset(physics.LinearVelocity * targetDistance);
@@ -617,7 +618,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
/// <returns></returns>
private Vector2 CollisionAvoidance(IEntity entity, Vector2 direction, ICollection<IEntity> ignoredTargets)
{
if (direction == Vector2.Zero || !entity.TryGetComponent(out IPhysicsComponent physics))
if (direction == Vector2.Zero || !entity.TryGetComponent(out IPhysBody physics))
{
return Vector2.Zero;
}
@@ -658,7 +659,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
// if we're moving in the same direction then ignore
// So if 2 entities are moving towards each other and both detect a collision they'll both move in the same direction
// i.e. towards the right
if (physicsEntity.TryGetComponent(out IPhysicsComponent otherPhysics) &&
if (physicsEntity.TryGetComponent(out IPhysBody otherPhysics) &&
Vector2.Dot(otherPhysics.LinearVelocity, direction) > 0)
{
continue;

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Content.Server.GameObjects.Components.Items.Storage;
@@ -25,6 +26,7 @@ using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Players;
namespace Content.Server.GameObjects.EntitySystems.Click
@@ -37,6 +39,8 @@ namespace Content.Server.GameObjects.EntitySystems.Click
{
[Dependency] private readonly IEntityManager _entityManager = default!;
private List<IThrowCollide> _throwCollide = new();
public override void Initialize()
{
SubscribeNetworkEvent<DragDropMessage>(HandleDragDropMessage);
@@ -602,28 +606,43 @@ namespace Content.Server.GameObjects.EntitySystems.Click
/// Calls ThrowCollide on all components that implement the IThrowCollide interface
/// on a thrown entity and the target entity it hit.
/// </summary>
public void ThrowCollideInteraction(IEntity user, IEntity thrown, IEntity target, EntityCoordinates location)
public void ThrowCollideInteraction(IEntity user, IPhysBody thrown, IPhysBody target)
{
var collideMsg = new ThrowCollideMessage(user, thrown, target, location);
// TODO: Just pass in the bodies directly
var collideMsg = new ThrowCollideMessage(user, thrown.Entity, target.Entity);
RaiseLocalEvent(collideMsg);
if (collideMsg.Handled)
{
return;
}
var eventArgs = new ThrowCollideEventArgs(user, thrown, target, location);
var eventArgs = new ThrowCollideEventArgs(user, thrown.Entity, target.Entity);
foreach (var comp in thrown.GetAllComponents<IThrowCollide>().ToArray())
foreach (var comp in thrown.Entity.GetAllComponents<IThrowCollide>())
{
if (thrown.Deleted) break;
comp.DoHit(eventArgs);
_throwCollide.Add(comp);
}
foreach (var comp in target.GetAllComponents<IThrowCollide>().ToArray())
foreach (var collide in _throwCollide)
{
if (target.Deleted) break;
comp.HitBy(eventArgs);
if (thrown.Entity.Deleted) break;
collide.DoHit(eventArgs);
}
_throwCollide.Clear();
foreach (var comp in target.Entity.GetAllComponents<IThrowCollide>())
{
_throwCollide.Add(comp);
}
foreach (var collide in _throwCollide)
{
if (target.Entity.Deleted) break;
collide.HitBy(eventArgs);
}
_throwCollide.Clear();
}
/// <summary>

View File

@@ -1,18 +1,39 @@
using Content.Server.GameObjects.Components.Movement;
using System.Collections.Generic;
using System.Linq;
using Content.Server.GameObjects.Components.Movement;
using Content.Shared.GameObjects.Components.Movement;
using Content.Shared.GameTicking;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
namespace Content.Server.GameObjects.EntitySystems
{
[UsedImplicitly]
internal sealed class ClimbSystem : EntitySystem
internal sealed class ClimbSystem : EntitySystem, IResettingEntitySystem
{
private readonly HashSet<ClimbingComponent> _activeClimbers = new();
public void AddActiveClimber(ClimbingComponent climbingComponent)
{
_activeClimbers.Add(climbingComponent);
}
public void RemoveActiveClimber(ClimbingComponent climbingComponent)
{
_activeClimbers.Remove(climbingComponent);
}
public override void Update(float frameTime)
{
foreach (var comp in ComponentManager.EntityQuery<ClimbingComponent>(true))
foreach (var climber in _activeClimbers.ToArray())
{
comp.Update();
climber.Update();
}
}
public void Reset()
{
_activeClimbers.Clear();
}
}
}

View File

@@ -1,18 +0,0 @@
using Content.Server.GameObjects.Components.Conveyor;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
namespace Content.Server.GameObjects.EntitySystems
{
[UsedImplicitly]
internal sealed class ConveyorSystem : EntitySystem
{
public override void Update(float frameTime)
{
foreach (var comp in ComponentManager.EntityQuery<ConveyorComponent>(true))
{
comp.Update(frameTime);
}
}
}
}

View File

@@ -1,11 +1,11 @@
using System;
using System.Linq;
using Content.Server.GameObjects.Components.GUI;
using Content.Server.GameObjects.Components.Items;
using Content.Server.GameObjects.Components.Items.Storage;
using Content.Server.GameObjects.Components.Stack;
using Content.Server.GameObjects.EntitySystems.Click;
using Content.Server.Interfaces.GameObjects.Components.Items;
using Content.Server.Throw;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Input;
using Content.Shared.Interfaces;
@@ -144,12 +144,12 @@ namespace Content.Server.GameObjects.EntitySystems
private bool HandleThrowItem(ICommonSession session, EntityCoordinates coords, EntityUid uid)
{
var plyEnt = ((IPlayerSession)session).AttachedEntity;
var playerEnt = ((IPlayerSession)session).AttachedEntity;
if (plyEnt == null || !plyEnt.IsValid())
if (playerEnt == null || !playerEnt.IsValid())
return false;
if (!plyEnt.TryGetComponent(out HandsComponent handsComp))
if (!playerEnt.TryGetComponent(out HandsComponent handsComp))
return false;
if (!handsComp.CanDrop(handsComp.ActiveHand))
@@ -168,14 +168,19 @@ namespace Content.Server.GameObjects.EntitySystems
else
{
stackComp.Use(1);
throwEnt = throwEnt.EntityManager.SpawnEntity(throwEnt.Prototype.ID, plyEnt.Transform.Coordinates);
throwEnt = throwEnt.EntityManager.SpawnEntity(throwEnt.Prototype.ID, playerEnt.Transform.Coordinates);
// can only throw one item at a time, regardless of what the prototype stack size is.
if (throwEnt.TryGetComponent<StackComponent>(out var newStackComp))
newStackComp.Count = 1;
}
throwEnt.ThrowTo(ThrowForce, coords, plyEnt.Transform.Coordinates, false, plyEnt);
var direction = coords.ToMapPos(EntityManager) - playerEnt.Transform.WorldPosition;
if (direction == Vector2.Zero) return true;
direction = direction.Normalized * MathF.Min(direction.Length, 8.0f);
throwEnt.TryThrow(direction * ThrowForce * 15);
return true;
}

View File

@@ -1,163 +0,0 @@
#nullable enable
using Content.Server.GameObjects.Components.GUI;
using Content.Server.GameObjects.Components.Items.Storage;
using Content.Server.GameObjects.Components.Mobs;
using Content.Server.GameObjects.Components.Sound;
using Content.Shared.Audio;
using Content.Shared.GameObjects.Components.Inventory;
using Content.Shared.GameObjects.Components.Movement;
using Content.Shared.GameObjects.Components.Tag;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Maps;
using Content.Shared.Physics;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
namespace Content.Server.GameObjects.EntitySystems
{
[UsedImplicitly]
internal class MoverSystem : SharedMoverSystem
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IRobustRandom _robustRandom = default!;
private AudioSystem _audioSystem = default!;
private const float StepSoundMoveDistanceRunning = 2;
private const float StepSoundMoveDistanceWalking = 1.5f;
/// <inheritdoc />
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<PlayerDetachedSystemMessage>(PlayerDetached);
_audioSystem = EntitySystemManager.GetEntitySystem<AudioSystem>();
UpdatesBefore.Add(typeof(PhysicsSystem));
}
public override void Update(float frameTime)
{
foreach (var (moverComponent, collidableComponent) in EntityManager.ComponentManager
.EntityQuery<IMoverComponent, IPhysicsComponent>(false))
{
var entity = moverComponent.Owner;
UpdateKinematics(entity.Transform, moverComponent, collidableComponent);
}
}
private void PlayerDetached(PlayerDetachedSystemMessage ev)
{
if (ev.Entity.TryGetComponent(out IPhysicsComponent? physics) &&
physics.TryGetController(out MoverController controller) &&
!ev.Entity.IsWeightless())
{
controller.StopMoving();
}
}
protected override void HandleFootsteps(IMoverComponent mover)
{
var transform = mover.Owner.Transform;
// Handle footsteps.
if (_mapManager.GridExists(mover.LastPosition.GetGridId(EntityManager)))
{
// Can happen when teleporting between grids.
if (!transform.Coordinates.TryDistance(EntityManager, mover.LastPosition, out var distance))
{
mover.LastPosition = transform.Coordinates;
return;
}
mover.StepSoundDistance += distance;
}
mover.LastPosition = transform.Coordinates;
float distanceNeeded;
if (mover.Sprinting)
{
distanceNeeded = StepSoundMoveDistanceRunning;
}
else
{
distanceNeeded = StepSoundMoveDistanceWalking;
}
if (mover.StepSoundDistance > distanceNeeded)
{
mover.StepSoundDistance = 0;
if (!mover.Owner.HasTag("FootstepSound"))
{
return;
}
if (mover.Owner.TryGetComponent<InventoryComponent>(out var inventory)
&& inventory.TryGetSlotItem<ItemComponent>(EquipmentSlotDefines.Slots.SHOES, out var item)
&& item.Owner.TryGetComponent<FootstepModifierComponent>(out var modifier))
{
modifier.PlayFootstep();
}
else
{
PlayFootstepSound(transform.Coordinates, mover.Sprinting);
}
}
}
private void PlayFootstepSound(EntityCoordinates coordinates, bool sprinting)
{
// Step one: figure out sound collection prototype.
var grid = _mapManager.GetGrid(coordinates.GetGridId(EntityManager));
var tile = grid.GetTileRef(coordinates);
// If the coordinates have a FootstepModifier component
// i.e. component that emit sound on footsteps emit that sound
string? soundCollectionName = null;
foreach (var maybeFootstep in grid.GetSnapGridCell(tile.GridIndices, SnapGridOffset.Center))
{
if (maybeFootstep.Owner.TryGetComponent(out FootstepModifierComponent? footstep))
{
soundCollectionName = footstep._soundCollectionName;
break;
}
}
// if there is no FootstepModifierComponent, determine sound based on tiles
if (soundCollectionName == null)
{
// Walking on a tile.
var def = (ContentTileDefinition) _tileDefinitionManager[tile.Tile.TypeId];
if (def.FootstepSounds == null)
{
// Nothing to play, oh well.
return;
}
soundCollectionName = def.FootstepSounds;
}
// Ok well we know the position of the
try
{
var soundCollection = _prototypeManager.Index<SoundCollectionPrototype>(soundCollectionName);
var file = _robustRandom.Pick(soundCollection.PickFiles);
_audioSystem.PlayAtCoords(file, coordinates, sprinting ? AudioParams.Default.WithVolume(0.75f) : null);
}
catch (UnknownPrototypeException)
{
// Shouldn't crash over a sound
Logger.ErrorS("sound", $"Unable to find sound collection for {soundCollectionName}");
}
}
}
}

View File

@@ -8,6 +8,7 @@ using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Broadphase;
using Robust.Shared.Random;
using Robust.Shared.Timing;
@@ -137,7 +138,7 @@ namespace Content.Server.GameObjects.EntitySystems
// Determine if the solar panel is occluded, and zero out coverage if so.
// FIXME: The "Opaque" collision group doesn't seem to work right now.
var ray = new CollisionRay(entity.Transform.WorldPosition, TowardsSun.ToVec(), (int) CollisionGroup.Opaque);
var rayCastResults = IoCManager.Resolve<IPhysicsManager>().IntersectRay(entity.Transform.MapID, ray, SunOcclusionCheckDistance, entity);
var rayCastResults = EntitySystem.Get<SharedBroadPhaseSystem>().IntersectRay(entity.Transform.MapID, ray, SunOcclusionCheckDistance, entity);
if (rayCastResults.Any())
coverage = 0;
}

View File

@@ -1,18 +0,0 @@
using Content.Server.GameObjects.Components.Recycling;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
namespace Content.Server.GameObjects.EntitySystems
{
[UsedImplicitly]
internal sealed class RecyclerSystem : EntitySystem
{
public override void Update(float frameTime)
{
foreach (var component in ComponentManager.EntityQuery<RecyclerComponent>(true))
{
component.Update(frameTime);
}
}
}
}

View File

@@ -7,36 +7,21 @@ namespace Content.Server.GameObjects.EntitySystems
[UsedImplicitly]
public class SingularitySystem : EntitySystem
{
private float curTimeSingulo;
private float curTimePull;
private float _accumulator;
public override void Update(float frameTime)
{
base.Update(frameTime);
curTimeSingulo += frameTime;
curTimePull += frameTime;
_accumulator += frameTime;
var shouldUpdate = curTimeSingulo >= 1f;
var shouldPull = curTimePull >= 0.2f;
if (!shouldUpdate && !shouldPull) return;
var singulos = ComponentManager.EntityQuery<SingularityComponent>(true);
if (curTimeSingulo >= 1f)
while (_accumulator > 1.0f)
{
curTimeSingulo -= 1f;
foreach (var singulo in singulos)
{
singulo.Update();
}
}
_accumulator -= 1.0f;
if (curTimePull >= 0.5f)
{
curTimePull -= 0.5f;
foreach (var singulo in singulos)
foreach (var singularity in ComponentManager.EntityQuery<SingularityComponent>())
{
singulo.PullUpdate();
singularity.Update(1);
}
}
}