2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Gravity;
|
2020-05-02 15:02:52 +01:00
|
|
|
using JetBrains.Annotations;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-12-03 14:20:34 +01:00
|
|
|
using Robust.Shared.IoC;
|
2020-05-02 15:02:52 +01:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Gravity.EntitySystems
|
2020-05-02 15:02:52 +01:00
|
|
|
{
|
|
|
|
|
[UsedImplicitly]
|
2021-06-27 07:43:39 +02:00
|
|
|
internal sealed class GravitySystem : SharedGravitySystem
|
2020-05-02 15:02:52 +01:00
|
|
|
{
|
2021-06-27 07:43:39 +02:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
SubscribeLocalEvent<GravityComponent, ComponentInit>(HandleGravityInitialize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HandleGravityInitialize(EntityUid uid, GravityComponent component, ComponentInit args)
|
2020-05-02 15:02:52 +01:00
|
|
|
{
|
2021-06-27 07:43:39 +02:00
|
|
|
// Incase there's already a generator on the grid we'll just set it now.
|
2021-12-08 13:00:43 +01:00
|
|
|
var gridId = EntityManager.GetComponent<TransformComponent>(component.Owner).GridID;
|
2021-06-27 15:57:02 +10:00
|
|
|
GravityChangedMessage message;
|
2021-06-27 07:43:39 +02:00
|
|
|
|
2021-10-18 14:58:34 +02:00
|
|
|
foreach (var generator in EntityManager.EntityQuery<GravityGeneratorComponent>())
|
2020-05-02 15:02:52 +01:00
|
|
|
{
|
2021-12-08 13:00:43 +01:00
|
|
|
if (EntityManager.GetComponent<TransformComponent>(generator.Owner).GridID == gridId && generator.GravityActive)
|
2020-05-02 15:02:52 +01:00
|
|
|
{
|
2021-06-27 07:43:39 +02:00
|
|
|
component.Enabled = true;
|
2021-06-27 15:57:02 +10:00
|
|
|
message = new GravityChangedMessage(gridId, true);
|
|
|
|
|
RaiseLocalEvent(message);
|
2021-06-27 07:43:39 +02:00
|
|
|
return;
|
2020-05-02 15:02:52 +01:00
|
|
|
}
|
2021-06-27 07:43:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
component.Enabled = false;
|
2021-06-27 15:57:02 +10:00
|
|
|
message = new GravityChangedMessage(gridId, false);
|
|
|
|
|
RaiseLocalEvent(message);
|
2021-06-27 07:43:39 +02:00
|
|
|
}
|
2020-10-30 01:07:51 +01:00
|
|
|
|
2021-11-02 01:12:55 +01:00
|
|
|
public void EnableGravity(GravityComponent comp)
|
2020-10-30 01:07:51 +01:00
|
|
|
{
|
2021-06-27 07:43:39 +02:00
|
|
|
if (comp.Enabled) return;
|
|
|
|
|
comp.Enabled = true;
|
2020-10-30 01:07:51 +01:00
|
|
|
|
2021-12-08 13:00:43 +01:00
|
|
|
var gridId = EntityManager.GetComponent<TransformComponent>(comp.Owner).GridID;
|
2021-06-27 07:43:39 +02:00
|
|
|
var message = new GravityChangedMessage(gridId, true);
|
2020-10-30 01:07:51 +01:00
|
|
|
RaiseLocalEvent(message);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-02 01:12:55 +01:00
|
|
|
public void DisableGravity(GravityComponent comp)
|
2020-10-30 01:07:51 +01:00
|
|
|
{
|
2021-06-27 07:43:39 +02:00
|
|
|
if (!comp.Enabled) return;
|
|
|
|
|
comp.Enabled = false;
|
2020-10-30 01:07:51 +01:00
|
|
|
|
2021-12-08 13:00:43 +01:00
|
|
|
var gridId = EntityManager.GetComponent<TransformComponent>(comp.Owner).GridID;
|
2021-06-27 07:43:39 +02:00
|
|
|
var message = new GravityChangedMessage(gridId, false);
|
2020-10-30 01:07:51 +01:00
|
|
|
RaiseLocalEvent(message);
|
|
|
|
|
}
|
2020-05-02 15:02:52 +01:00
|
|
|
}
|
|
|
|
|
}
|