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:
@@ -2,25 +2,43 @@ using System;
|
||||
using Content.Shared.NetIDs;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Shared.Singularity.Components
|
||||
{
|
||||
|
||||
public abstract class SharedSingularityComponent : Component
|
||||
{
|
||||
public override string Name => "Singularity";
|
||||
public override uint? NetID => ContentNetIDs.SINGULARITY;
|
||||
|
||||
[DataField("deleteFixture")] public string? DeleteFixtureId { get; } = default;
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
protected sealed class SingularityComponentState : ComponentState
|
||||
/// <summary>
|
||||
/// Changed by <see cref="SharedSingularitySystem.ChangeSingularityLevel"/>
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public int Level { get; set; }
|
||||
|
||||
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
||||
{
|
||||
public int Level { get; }
|
||||
|
||||
public SingularityComponentState(int level) : base(ContentNetIDs.SINGULARITY)
|
||||
if (curState is not SingularityComponentState state)
|
||||
{
|
||||
Level = level;
|
||||
return;
|
||||
}
|
||||
|
||||
EntitySystem.Get<SharedSingularitySystem>().ChangeSingularityLevel(this, state.Level);
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class SingularityComponentState : ComponentState
|
||||
{
|
||||
public int Level { get; }
|
||||
|
||||
public SingularityComponentState(int level) : base(ContentNetIDs.SINGULARITY)
|
||||
{
|
||||
Level = level;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using Content.Shared.NetIDs;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Shared.Singularity.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class SingularityDistortionComponent : Component
|
||||
{
|
||||
public override string Name => "SingularityDistortion";
|
||||
public override uint? NetID => ContentNetIDs.SINGULARITY_DISTORTION;
|
||||
|
||||
[DataField("intensity")]
|
||||
private float _intensity = 0.25f;
|
||||
|
||||
[DataField("falloff")]
|
||||
private float _falloff = 2;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float Intensity
|
||||
{
|
||||
get => _intensity;
|
||||
set => this.SetAndDirtyIfChanged(ref _intensity, value);
|
||||
}
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float Falloff
|
||||
{
|
||||
get => _falloff;
|
||||
set => this.SetAndDirtyIfChanged(ref _falloff, value);
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState(ICommonSession player)
|
||||
{
|
||||
return new SingularityDistortionComponentState(Intensity, Falloff);
|
||||
}
|
||||
|
||||
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
||||
{
|
||||
base.HandleComponentState(curState, nextState);
|
||||
|
||||
if (curState is not SingularityDistortionComponentState state)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Intensity = state.Intensity;
|
||||
Falloff = state.Falloff;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public class SingularityDistortionComponentState : ComponentState
|
||||
{
|
||||
public SingularityDistortionComponentState(float intensity, float falloff) : base(ContentNetIDs.SINGULARITY_DISTORTION)
|
||||
{
|
||||
Intensity = intensity;
|
||||
Falloff = falloff;
|
||||
}
|
||||
|
||||
public float Intensity { get; }
|
||||
public float Falloff { get; }
|
||||
}
|
||||
}
|
||||
90
Content.Shared/Singularity/SharedSingularitySystem.cs
Normal file
90
Content.Shared/Singularity/SharedSingularitySystem.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using Content.Shared.Radiation;
|
||||
using Content.Shared.Singularity.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics.Collision.Shapes;
|
||||
|
||||
namespace Content.Shared.Singularity
|
||||
{
|
||||
public abstract class SharedSingularitySystem : EntitySystem
|
||||
{
|
||||
private float GetFalloff(int level)
|
||||
{
|
||||
return level switch
|
||||
{
|
||||
0 => 9999f,
|
||||
1 => 6.4f,
|
||||
2 => 7.0f,
|
||||
3 => 8.0f,
|
||||
4 => 10.0f,
|
||||
5 => 12.0f,
|
||||
6 => 12.0f,
|
||||
_ => -1.0f
|
||||
};
|
||||
}
|
||||
|
||||
private float GetIntensity(int level)
|
||||
{
|
||||
return level switch
|
||||
{
|
||||
0 => 0.0f,
|
||||
1 => 2.7f,
|
||||
2 => 14.4f,
|
||||
3 => 47.2f,
|
||||
4 => 180.0f,
|
||||
5 => 600.0f,
|
||||
6 => 800.0f,
|
||||
_ => -1.0f
|
||||
};
|
||||
}
|
||||
|
||||
public void ChangeSingularityLevel(SharedSingularityComponent singularity, int value)
|
||||
{
|
||||
if (value == singularity.Level)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
value = Math.Clamp(value, 0, 6);
|
||||
|
||||
var physics = singularity.Owner.GetComponentOrNull<PhysicsComponent>();
|
||||
|
||||
if (singularity.Level > 1 && value <= 1)
|
||||
{
|
||||
// Prevents it getting stuck (see SingularityController.MoveSingulo)
|
||||
if (physics != null)
|
||||
{
|
||||
physics.LinearVelocity = Vector2.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
singularity.Level = value;
|
||||
|
||||
if (singularity.Owner.TryGetComponent(out SharedRadiationPulseComponent? pulse))
|
||||
{
|
||||
pulse.RadsPerSecond = 10 * value;
|
||||
}
|
||||
|
||||
if (singularity.Owner.TryGetComponent(out SharedAppearanceComponent? appearance))
|
||||
{
|
||||
appearance.SetData(SingularityVisuals.Level, value);
|
||||
}
|
||||
|
||||
if (physics != null &&
|
||||
singularity.DeleteFixtureId != null &&
|
||||
physics.GetFixture(singularity.DeleteFixtureId) is {Shape: PhysShapeCircle circle})
|
||||
{
|
||||
circle.Radius = value - 0.5f;
|
||||
}
|
||||
|
||||
if (singularity.Owner.TryGetComponent(out SingularityDistortionComponent? distortion))
|
||||
{
|
||||
distortion.Falloff = GetFalloff(value);
|
||||
distortion.Intensity = GetIntensity(value);
|
||||
}
|
||||
|
||||
singularity.Dirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user