2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Singularity;
|
|
|
|
|
using Content.Shared.Singularity.Components;
|
2021-07-10 17:35:33 +02:00
|
|
|
using Content.Shared.Sound;
|
2020-10-28 19:19:47 +01:00
|
|
|
using Robust.Shared.Audio;
|
|
|
|
|
using Robust.Shared.GameObjects;
|
2021-12-03 11:43:03 +01:00
|
|
|
using Robust.Shared.IoC;
|
2021-03-21 09:12:03 -07:00
|
|
|
using Robust.Shared.Player;
|
2021-07-10 17:35:33 +02:00
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2021-05-28 10:44:13 +01:00
|
|
|
using Robust.Shared.ViewVariables;
|
2020-10-28 19:19:47 +01:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Singularity.Components
|
2020-10-28 19:19:47 +01:00
|
|
|
{
|
|
|
|
|
[RegisterComponent]
|
2021-06-24 04:48:11 +02:00
|
|
|
[ComponentReference(typeof(SharedSingularityComponent))]
|
2021-07-21 20:33:22 +10:00
|
|
|
public class ServerSingularityComponent : SharedSingularityComponent
|
2020-10-28 19:19:47 +01:00
|
|
|
{
|
2021-12-08 17:32:32 +01:00
|
|
|
[Dependency] private readonly IEntityManager _entMan = default!;
|
|
|
|
|
|
2021-06-24 04:48:11 +02:00
|
|
|
private SharedSingularitySystem _singularitySystem = default!;
|
|
|
|
|
|
2021-05-28 10:44:13 +01:00
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
2020-10-28 19:19:47 +01:00
|
|
|
public int Energy
|
|
|
|
|
{
|
|
|
|
|
get => _energy;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == _energy) return;
|
|
|
|
|
|
|
|
|
|
_energy = value;
|
|
|
|
|
if (_energy <= 0)
|
|
|
|
|
{
|
2021-12-08 17:32:32 +01:00
|
|
|
_entMan.DeleteEntity(Owner);
|
2020-10-28 19:19:47 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-24 04:48:11 +02:00
|
|
|
var level = _energy switch
|
2020-10-28 19:19:47 +01:00
|
|
|
{
|
2021-06-24 04:48:11 +02:00
|
|
|
>= 1500 => 6,
|
|
|
|
|
>= 1000 => 5,
|
|
|
|
|
>= 600 => 4,
|
|
|
|
|
>= 300 => 3,
|
|
|
|
|
>= 200 => 2,
|
|
|
|
|
< 200 => 1
|
2020-10-28 19:19:47 +01:00
|
|
|
};
|
2021-06-24 04:48:11 +02:00
|
|
|
_singularitySystem.ChangeSingularityLevel(this, level);
|
2020-10-28 19:19:47 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private int _energy = 180;
|
|
|
|
|
|
2021-05-28 10:44:13 +01:00
|
|
|
[ViewVariables]
|
2020-10-28 19:19:47 +01:00
|
|
|
public int EnergyDrain =>
|
|
|
|
|
Level switch
|
|
|
|
|
{
|
|
|
|
|
6 => 20,
|
|
|
|
|
5 => 15,
|
|
|
|
|
4 => 10,
|
|
|
|
|
3 => 5,
|
|
|
|
|
2 => 2,
|
|
|
|
|
1 => 1,
|
|
|
|
|
_ => 0
|
|
|
|
|
};
|
|
|
|
|
|
2021-08-23 00:54:03 +10:00
|
|
|
public float MoveAccumulator;
|
|
|
|
|
|
2021-05-28 10:44:13 +01:00
|
|
|
// This is an interesting little workaround.
|
|
|
|
|
// 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)]
|
2021-06-24 04:48:11 +02:00
|
|
|
public bool BeingDeletedByAnotherSingularity { get; set; }
|
2021-05-28 10:44:13 +01:00
|
|
|
|
2021-07-10 17:35:33 +02:00
|
|
|
[DataField("singularityFormingSound")] private SoundSpecifier _singularityFormingSound = new SoundPathSpecifier("/Audio/Effects/singularity_form.ogg");
|
|
|
|
|
[DataField("singularityCollapsingSound")] private SoundSpecifier _singularityCollapsingSound = new SoundPathSpecifier("/Audio/Effects/singularity_collapse.ogg");
|
|
|
|
|
|
2021-11-30 15:20:38 +01:00
|
|
|
public override ComponentState GetComponentState()
|
2021-03-09 04:33:41 -06:00
|
|
|
{
|
|
|
|
|
return new SingularityComponentState(Level);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-19 19:41:26 -07:00
|
|
|
protected override void Initialize()
|
2020-10-28 19:19:47 +01:00
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
2021-06-24 04:48:11 +02:00
|
|
|
_singularitySystem = EntitySystem.Get<SharedSingularitySystem>();
|
2021-03-31 12:41:23 -07:00
|
|
|
|
2020-10-28 19:19:47 +01:00
|
|
|
var audioParams = AudioParams.Default;
|
|
|
|
|
audioParams.Loop = true;
|
|
|
|
|
audioParams.MaxDistance = 20f;
|
|
|
|
|
audioParams.Volume = 5;
|
2021-07-31 19:52:33 +02:00
|
|
|
SoundSystem.Play(Filter.Pvs(Owner), _singularityFormingSound.GetSound(), Owner);
|
2020-10-28 19:19:47 +01:00
|
|
|
|
2021-06-24 04:48:11 +02:00
|
|
|
_singularitySystem.ChangeSingularityLevel(this, 1);
|
2020-10-28 19:19:47 +01:00
|
|
|
}
|
|
|
|
|
|
2021-10-23 10:49:59 +02:00
|
|
|
protected override void Shutdown()
|
2020-10-28 19:19:47 +01:00
|
|
|
{
|
2021-10-23 10:49:59 +02:00
|
|
|
base.Shutdown();
|
2021-12-08 17:32:32 +01:00
|
|
|
SoundSystem.Play(Filter.Pvs(Owner), _singularityCollapsingSound.GetSound(), _entMan.GetComponent<TransformComponent>(Owner).Coordinates);
|
2020-10-28 19:19:47 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|