Remove IClientSingularityInstance, move visual effects to SingularityDistortionComponent (#4194)
* Remove IClientSingularityInstance * In and out 5 minute refactor * Component states for singularity distortion * Fix distortion states * Address reviews
This commit is contained in:
@@ -1,15 +1,10 @@
|
||||
#nullable enable
|
||||
using System.Linq;
|
||||
using Content.Server.Radiation;
|
||||
using Content.Shared.Singularity;
|
||||
using Content.Shared.Singularity.Components;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics.Collision;
|
||||
using Robust.Shared.Physics.Collision.Shapes;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Players;
|
||||
@@ -19,8 +14,11 @@ using Robust.Shared.ViewVariables;
|
||||
namespace Content.Server.Singularity.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(SharedSingularityComponent))]
|
||||
public class ServerSingularityComponent : SharedSingularityComponent, IStartCollide
|
||||
{
|
||||
private SharedSingularitySystem _singularitySystem = default!;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public int Energy
|
||||
{
|
||||
@@ -36,54 +34,20 @@ namespace Content.Server.Singularity.Components
|
||||
return;
|
||||
}
|
||||
|
||||
Level = _energy switch
|
||||
var level = _energy switch
|
||||
{
|
||||
var n when n >= 1500 => 6,
|
||||
var n when n >= 1000 => 5,
|
||||
var n when n >= 600 => 4,
|
||||
var n when n >= 300 => 3,
|
||||
var n when n >= 200 => 2,
|
||||
var n when n < 200 => 1,
|
||||
_ => 1
|
||||
>= 1500 => 6,
|
||||
>= 1000 => 5,
|
||||
>= 600 => 4,
|
||||
>= 300 => 3,
|
||||
>= 200 => 2,
|
||||
< 200 => 1
|
||||
};
|
||||
_singularitySystem.ChangeSingularityLevel(this, level);
|
||||
}
|
||||
}
|
||||
private int _energy = 180;
|
||||
|
||||
[ViewVariables]
|
||||
public int Level
|
||||
{
|
||||
get => _level;
|
||||
set
|
||||
{
|
||||
if (value == _level) return;
|
||||
if (value < 0) value = 0;
|
||||
if (value > 6) value = 6;
|
||||
|
||||
if ((_level > 1) && (value <= 1))
|
||||
{
|
||||
// Prevents it getting stuck (see SingularityController.MoveSingulo)
|
||||
if (_collidableComponent != null) _collidableComponent.LinearVelocity = Vector2.Zero;
|
||||
}
|
||||
_level = value;
|
||||
|
||||
if(_radiationPulseComponent != null) _radiationPulseComponent.RadsPerSecond = 10 * value;
|
||||
|
||||
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
|
||||
{
|
||||
appearance.SetData(SingularityVisuals.Level, _level);
|
||||
}
|
||||
|
||||
if (_collidableComponent != null && _collidableComponent.Fixtures.Any() && _collidableComponent.Fixtures[0].Shape is PhysShapeCircle circle)
|
||||
{
|
||||
circle.Radius = _level - 0.5f;
|
||||
}
|
||||
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
private int _level;
|
||||
|
||||
[ViewVariables]
|
||||
public int EnergyDrain =>
|
||||
Level switch
|
||||
@@ -101,11 +65,8 @@ namespace Content.Server.Singularity.Components
|
||||
// See, two singularities queuing deletion of each other at the same time will annihilate.
|
||||
// This is undesirable behaviour, so this flag allows the imperatively first one processed to take priority.
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool BeingDeletedByAnotherSingularity { get; set; } = false;
|
||||
public bool BeingDeletedByAnotherSingularity { get; set; }
|
||||
|
||||
private PhysicsComponent _collidableComponent = default!;
|
||||
private RadiationPulseComponent _radiationPulseComponent = default!;
|
||||
private SpriteComponent _spriteComponent = default!;
|
||||
private IPlayingAudioStream? _playingSound;
|
||||
|
||||
public override ComponentState GetComponentState(ICommonSession player)
|
||||
@@ -117,9 +78,7 @@ namespace Content.Server.Singularity.Components
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
Owner.EnsureComponent(out _radiationPulseComponent);
|
||||
Owner.EnsureComponent(out _collidableComponent);
|
||||
Owner.EnsureComponent(out _spriteComponent);
|
||||
_singularitySystem = EntitySystem.Get<SharedSingularitySystem>();
|
||||
|
||||
var audioParams = AudioParams.Default;
|
||||
audioParams.Loop = true;
|
||||
@@ -128,7 +87,7 @@ namespace Content.Server.Singularity.Components
|
||||
SoundSystem.Play(Filter.Pvs(Owner), "/Audio/Effects/singularity_form.ogg", Owner);
|
||||
Timer.Spawn(5200,() => _playingSound = SoundSystem.Play(Filter.Pvs(Owner), "/Audio/Effects/singularity.ogg", Owner, audioParams));
|
||||
|
||||
Level = 1;
|
||||
_singularitySystem.ChangeSingularityLevel(this, 1);
|
||||
}
|
||||
|
||||
public void Update(int seconds)
|
||||
@@ -155,7 +114,8 @@ namespace Content.Server.Singularity.Components
|
||||
return;
|
||||
}
|
||||
|
||||
if (otherEntity.HasComponent<ContainmentFieldComponent>() || (otherEntity.TryGetComponent<ContainmentFieldGeneratorComponent>(out var component) && component.CanRepell(Owner)))
|
||||
if (otherEntity.HasComponent<ContainmentFieldComponent>() ||
|
||||
(otherEntity.TryGetComponent<ContainmentFieldGeneratorComponent>(out var component) && component.CanRepell(Owner)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
using Content.Server.Singularity.Components;
|
||||
using Content.Shared.Singularity;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.Singularity.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class SingularitySystem : EntitySystem
|
||||
public class SingularitySystem : SharedSingularitySystem
|
||||
{
|
||||
private float _updateInterval = 1.0f;
|
||||
private float _accumulator;
|
||||
@@ -24,7 +24,6 @@ namespace Content.Server.Singularity.EntitySystems
|
||||
singularity.Update(1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user