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