Gravity (#841)
@@ -12,6 +12,7 @@ using Content.Client.UserInterface.Stylesheets;
|
||||
using Content.Shared.GameObjects.Components;
|
||||
using Content.Shared.GameObjects.Components.Cargo;
|
||||
using Content.Shared.GameObjects.Components.Chemistry;
|
||||
using Content.Shared.GameObjects.Components.Gravity;
|
||||
using Content.Shared.GameObjects.Components.Markers;
|
||||
using Content.Shared.GameObjects.Components.Research;
|
||||
using Content.Shared.GameObjects.Components.VendingMachines;
|
||||
@@ -161,6 +162,8 @@ namespace Content.Client
|
||||
factory.Register<SharedCargoConsoleComponent>();
|
||||
factory.Register<SharedReagentDispenserComponent>();
|
||||
|
||||
factory.Register<SharedGravityGeneratorComponent>();
|
||||
|
||||
prototypes.RegisterIgnore("material");
|
||||
prototypes.RegisterIgnore("reaction"); //Chemical reactions only needed by server. Reactions checks are server-side.
|
||||
prototypes.RegisterIgnore("barSign");
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
using System;
|
||||
using Content.Shared.GameObjects.Components.Gravity;
|
||||
using Robust.Client.GameObjects.Components.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Shared.GameObjects.Components.UserInterface;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.Gravity
|
||||
{
|
||||
public class GravityGeneratorBoundUserInterface: BoundUserInterface
|
||||
{
|
||||
private GravityGeneratorWindow _window;
|
||||
|
||||
public bool IsOn;
|
||||
|
||||
public GravityGeneratorBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base (owner, uiKey)
|
||||
{
|
||||
SendMessage(new SharedGravityGeneratorComponent.GeneratorStatusRequestMessage());
|
||||
}
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
base.Open();
|
||||
|
||||
IsOn = false;
|
||||
|
||||
_window = new GravityGeneratorWindow(this);
|
||||
|
||||
_window.Switch.OnPressed += (args) =>
|
||||
{
|
||||
SendMessage(new SharedGravityGeneratorComponent.SwitchGeneratorMessage(!IsOn));
|
||||
SendMessage(new SharedGravityGeneratorComponent.GeneratorStatusRequestMessage());
|
||||
};
|
||||
|
||||
_window.OpenCentered();
|
||||
}
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
base.UpdateState(state);
|
||||
|
||||
var castState = (SharedGravityGeneratorComponent.GeneratorState) state;
|
||||
IsOn = castState.On;
|
||||
_window.UpdateButton();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
if (!disposing) return;
|
||||
|
||||
_window?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public class GravityGeneratorWindow : SS14Window
|
||||
{
|
||||
public Label Status;
|
||||
|
||||
public Button Switch;
|
||||
|
||||
public GravityGeneratorBoundUserInterface Owner;
|
||||
|
||||
public GravityGeneratorWindow(GravityGeneratorBoundUserInterface gravityGeneratorInterface = null)
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
Owner = gravityGeneratorInterface;
|
||||
|
||||
Title = Loc.GetString("Gravity Generator Control");
|
||||
|
||||
var vBox = new VBoxContainer
|
||||
{
|
||||
CustomMinimumSize = new Vector2(250, 100)
|
||||
};
|
||||
Status = new Label
|
||||
{
|
||||
Text = Loc.GetString("Current Status: " + (Owner.IsOn ? "On" : "Off")),
|
||||
FontColorOverride = Owner.IsOn ? Color.ForestGreen : Color.Red
|
||||
};
|
||||
Switch = new Button
|
||||
{
|
||||
Text = Loc.GetString(Owner.IsOn ? "Turn Off" : "Turn On"),
|
||||
TextAlign = Label.AlignMode.Center,
|
||||
CustomMinimumSize = new Vector2(150, 60)
|
||||
};
|
||||
|
||||
vBox.AddChild(Status);
|
||||
vBox.AddChild(Switch);
|
||||
|
||||
Contents.AddChild(vBox);
|
||||
}
|
||||
|
||||
public void UpdateButton()
|
||||
{
|
||||
Status.Text = Loc.GetString("Current Status: " + (Owner.IsOn ? "On" : "Off"));
|
||||
Status.FontColorOverride = Owner.IsOn ? Color.ForestGreen : Color.Red;
|
||||
Switch.Text = Loc.GetString(Owner.IsOn ? "Turn Off" : "Turn On");
|
||||
}
|
||||
}
|
||||
}
|
||||
64
Content.IntegrationTests/Tests/GravityGridTest.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System.Threading.Tasks;
|
||||
using Content.Client.GameObjects.Components.Gravity;
|
||||
using Content.Server.GameObjects.Components.Gravity;
|
||||
using Content.Server.GameObjects.Components.Power;
|
||||
using NUnit.Framework;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Map;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Content.IntegrationTests.Tests
|
||||
{
|
||||
/// Tests the behavior of GravityGeneratorComponent,
|
||||
/// making sure that gravity is applied to the correct grids.
|
||||
[TestFixture]
|
||||
[TestOf(typeof(GravityGeneratorComponent))]
|
||||
public class GravityGridTest : ContentIntegrationTest
|
||||
{
|
||||
[Test]
|
||||
public async Task Test()
|
||||
{
|
||||
var server = StartServerDummyTicker();
|
||||
|
||||
IEntity generator = null;
|
||||
|
||||
IMapGrid grid1 = null;
|
||||
IMapGrid grid2 = null;
|
||||
|
||||
// Create grids
|
||||
server.Assert(() =>
|
||||
{
|
||||
var mapMan = IoCManager.Resolve<IMapManager>();
|
||||
|
||||
mapMan.CreateMap(new MapId(1));
|
||||
grid1 = mapMan.CreateGrid(new MapId(1));
|
||||
grid2 = mapMan.CreateGrid(new MapId(1));
|
||||
|
||||
var entityMan = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
generator = entityMan.SpawnEntity("GravityGenerator", new GridCoordinates(new Vector2(0, 0), grid2.Index));
|
||||
Assert.That(generator.HasComponent<GravityGeneratorComponent>());
|
||||
Assert.That(generator.HasComponent<PowerDeviceComponent>());
|
||||
var generatorComponent = generator.GetComponent<GravityGeneratorComponent>();
|
||||
var powerComponent = generator.GetComponent<PowerDeviceComponent>();
|
||||
Assert.AreEqual(generatorComponent.Status, GravityGeneratorStatus.Unpowered);
|
||||
powerComponent.ExternalPowered = true;
|
||||
});
|
||||
server.RunTicks(1);
|
||||
|
||||
server.Assert(() =>
|
||||
{
|
||||
var generatorComponent = generator.GetComponent<GravityGeneratorComponent>();
|
||||
|
||||
Assert.AreEqual(generatorComponent.Status, GravityGeneratorStatus.On);
|
||||
|
||||
Assert.That(!grid1.HasGravity);
|
||||
Assert.That(grid2.HasGravity);
|
||||
});
|
||||
|
||||
await server.WaitIdleAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
using Content.Server.GameObjects.Components.Damage;
|
||||
using Content.Server.GameObjects.Components.Interactable.Tools;
|
||||
using Content.Server.GameObjects.Components.Power;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Server.Interfaces;
|
||||
using Content.Shared.GameObjects.Components.Gravity;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.GameObjects.Components.UserInterface;
|
||||
using Robust.Server.GameObjects.EntitySystems;
|
||||
using Robust.Server.Interfaces.GameObjects;
|
||||
using Robust.Server.Interfaces.Player;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Gravity
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class GravityGeneratorComponent: SharedGravityGeneratorComponent, IAttackBy, IBreakAct, IAttackHand
|
||||
{
|
||||
private BoundUserInterface _userInterface;
|
||||
|
||||
private PowerDeviceComponent _powerDevice;
|
||||
|
||||
private SpriteComponent _sprite;
|
||||
|
||||
private bool _switchedOn;
|
||||
|
||||
private bool _intact;
|
||||
|
||||
private GravityGeneratorStatus _status;
|
||||
|
||||
public bool Powered => _powerDevice.Powered;
|
||||
|
||||
public bool SwitchedOn => _switchedOn;
|
||||
|
||||
public bool Intact => _intact;
|
||||
|
||||
public GravityGeneratorStatus Status => _status;
|
||||
|
||||
public bool NeedsUpdate
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (_status)
|
||||
{
|
||||
case GravityGeneratorStatus.On:
|
||||
return !(Powered && SwitchedOn && Intact);
|
||||
case GravityGeneratorStatus.Off:
|
||||
return SwitchedOn || !(Powered && Intact);
|
||||
case GravityGeneratorStatus.Unpowered:
|
||||
return SwitchedOn || Powered || !Intact;
|
||||
case GravityGeneratorStatus.Broken:
|
||||
return SwitchedOn || Powered || Intact;
|
||||
default:
|
||||
return true; // This _should_ be unreachable
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override string Name => "GravityGenerator";
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_userInterface = Owner.GetComponent<ServerUserInterfaceComponent>()
|
||||
.GetBoundUserInterface(GravityGeneratorUiKey.Key);
|
||||
_userInterface.OnReceiveMessage += HandleUIMessage;
|
||||
_powerDevice = Owner.GetComponent<PowerDeviceComponent>();
|
||||
_sprite = Owner.GetComponent<SpriteComponent>();
|
||||
_switchedOn = true;
|
||||
_intact = true;
|
||||
_status = GravityGeneratorStatus.On;
|
||||
UpdateState();
|
||||
}
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(ref _switchedOn, "switched_on", true);
|
||||
serializer.DataField(ref _intact, "intact", true);
|
||||
}
|
||||
|
||||
bool IAttackHand.AttackHand(AttackHandEventArgs eventArgs)
|
||||
{
|
||||
if (!eventArgs.User.TryGetComponent<IActorComponent>(out var actor))
|
||||
return false;
|
||||
if (Status != GravityGeneratorStatus.Off && Status != GravityGeneratorStatus.On)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
OpenUserInterface(actor.playerSession);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool AttackBy(AttackByEventArgs eventArgs)
|
||||
{
|
||||
if (!eventArgs.AttackWith.TryGetComponent<WelderComponent>(out var welder)) return false;
|
||||
if (welder.TryUse(5.0f))
|
||||
{
|
||||
// Repair generator
|
||||
var damagable = Owner.GetComponent<DamageableComponent>();
|
||||
var breakable = Owner.GetComponent<BreakableComponent>();
|
||||
damagable.HealAllDamage();
|
||||
breakable.broken = false;
|
||||
_intact = true;
|
||||
|
||||
var entitySystemManager = IoCManager.Resolve<IEntitySystemManager>();
|
||||
var notifyManager = IoCManager.Resolve<IServerNotifyManager>();
|
||||
|
||||
entitySystemManager.GetEntitySystem<AudioSystem>().Play("/Audio/items/welder2.ogg", Owner);
|
||||
notifyManager.PopupMessage(Owner, eventArgs.User, Loc.GetString("You repair the gravity generator with the welder"));
|
||||
|
||||
return true;
|
||||
} else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnBreak(BreakageEventArgs eventArgs)
|
||||
{
|
||||
_intact = false;
|
||||
_switchedOn = false;
|
||||
}
|
||||
|
||||
public void UpdateState()
|
||||
{
|
||||
if (!Intact)
|
||||
{
|
||||
MakeBroken();
|
||||
} else if (!Powered)
|
||||
{
|
||||
MakeUnpowered();
|
||||
} else if (!SwitchedOn)
|
||||
{
|
||||
MakeOff();
|
||||
} else
|
||||
{
|
||||
MakeOn();
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleUIMessage(ServerBoundUserInterfaceMessage message)
|
||||
{
|
||||
switch (message.Message)
|
||||
{
|
||||
case GeneratorStatusRequestMessage _:
|
||||
_userInterface.SetState(new GeneratorState(Status == GravityGeneratorStatus.On));
|
||||
break;
|
||||
case SwitchGeneratorMessage msg:
|
||||
_switchedOn = msg.On;
|
||||
UpdateState();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void OpenUserInterface(IPlayerSession playerSession)
|
||||
{
|
||||
_userInterface.Open(playerSession);
|
||||
}
|
||||
|
||||
private void MakeBroken()
|
||||
{
|
||||
_status = GravityGeneratorStatus.Broken;
|
||||
_sprite.LayerSetState(0, "broken");
|
||||
_sprite.LayerSetVisible(1, false);
|
||||
}
|
||||
|
||||
private void MakeUnpowered()
|
||||
{
|
||||
_status = GravityGeneratorStatus.Unpowered;
|
||||
_sprite.LayerSetState(0, "off");
|
||||
_sprite.LayerSetVisible(1, false);
|
||||
}
|
||||
|
||||
private void MakeOff()
|
||||
{
|
||||
_status = GravityGeneratorStatus.Off;
|
||||
_sprite.LayerSetState(0, "off");
|
||||
_sprite.LayerSetVisible(1, false);
|
||||
}
|
||||
|
||||
private void MakeOn()
|
||||
{
|
||||
_status = GravityGeneratorStatus.On;
|
||||
_sprite.LayerSetState(0, "on");
|
||||
_sprite.LayerSetVisible(1, true);
|
||||
}
|
||||
}
|
||||
|
||||
public enum GravityGeneratorStatus
|
||||
{
|
||||
Broken,
|
||||
Unpowered,
|
||||
Off,
|
||||
On
|
||||
}
|
||||
}
|
||||
@@ -90,6 +90,15 @@ namespace Content.Server.GameObjects.Components.Movement
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[ViewVariables]
|
||||
public float CurrentPushSpeed => 5.0f;
|
||||
|
||||
/// <inheritdoc />
|
||||
[ViewVariables]
|
||||
public float GrabRange => 0.2f;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Is the entity Sprinting (running)?
|
||||
/// </summary>
|
||||
|
||||
@@ -67,6 +67,14 @@ namespace Content.Server.GameObjects.Components.Movement
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[ViewVariables]
|
||||
public float CurrentPushSpeed => 5.0f;
|
||||
|
||||
/// <inheritdoc />
|
||||
[ViewVariables]
|
||||
public float GrabRange => 0.2f;
|
||||
|
||||
/// <summary>
|
||||
/// Is the entity Sprinting (running)?
|
||||
/// </summary>
|
||||
|
||||
@@ -34,6 +34,15 @@ namespace Content.Server.GameObjects.Components.Movement
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float CurrentWalkSpeed { get; set; } = 8;
|
||||
public float CurrentSprintSpeed { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
[ViewVariables]
|
||||
public float CurrentPushSpeed => 0.0f;
|
||||
|
||||
/// <inheritdoc />
|
||||
[ViewVariables]
|
||||
public float GrabRange => 0.0f;
|
||||
|
||||
public bool Sprinting { get; set; }
|
||||
public Vector2 VelocityDir { get; } = Vector2.Zero;
|
||||
public GridCoordinates LastPosition { get; set; }
|
||||
|
||||
134
Content.Server/GameObjects/EntitySystems/GravitySystem.cs
Normal file
@@ -0,0 +1,134 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Server.GameObjects.Components.Gravity;
|
||||
using Content.Server.GameObjects.Components.Mobs;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects.EntitySystems;
|
||||
using Robust.Server.Interfaces.Player;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Map;
|
||||
using Robust.Shared.Interfaces.Random;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Server.GameObjects.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class GravitySystem: EntitySystem
|
||||
{
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly IMapManager _mapManager;
|
||||
[Dependency] private readonly IPlayerManager _playerManager;
|
||||
[Dependency] private readonly IEntitySystemManager _entitySystemManager;
|
||||
[Dependency] private readonly IRobustRandom _random;
|
||||
#pragma warning restore 649
|
||||
|
||||
private const float GravityKick = 100.0f;
|
||||
|
||||
private const uint ShakeTimes = 10;
|
||||
|
||||
private Dictionary<GridId, uint> _gridsToShake;
|
||||
|
||||
private float internalTimer = 0.0f;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
EntityQuery = new TypeEntityQuery<GravityGeneratorComponent>();
|
||||
_gridsToShake = new Dictionary<GridId, uint>();
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
internalTimer += frameTime;
|
||||
var gridsWithGravity = new List<GridId>();
|
||||
foreach (var entity in RelevantEntities)
|
||||
{
|
||||
var generator = entity.GetComponent<GravityGeneratorComponent>();
|
||||
if (generator.NeedsUpdate)
|
||||
{
|
||||
generator.UpdateState();
|
||||
}
|
||||
if (generator.Status == GravityGeneratorStatus.On)
|
||||
{
|
||||
gridsWithGravity.Add(entity.Transform.GridID);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var grid in _mapManager.GetAllGrids())
|
||||
{
|
||||
if (grid.HasGravity && !gridsWithGravity.Contains(grid.Index))
|
||||
{
|
||||
grid.HasGravity = false;
|
||||
ScheduleGridToShake(grid.Index, ShakeTimes);
|
||||
} else if (!grid.HasGravity && gridsWithGravity.Contains(grid.Index))
|
||||
{
|
||||
grid.HasGravity = true;
|
||||
ScheduleGridToShake(grid.Index, ShakeTimes);
|
||||
}
|
||||
}
|
||||
|
||||
if (internalTimer > 0.2f)
|
||||
{
|
||||
ShakeGrids();
|
||||
internalTimer = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
private void ScheduleGridToShake(GridId gridId, uint shakeTimes)
|
||||
{
|
||||
if (!_gridsToShake.Keys.Contains(gridId))
|
||||
{
|
||||
_gridsToShake.Add(gridId, shakeTimes);
|
||||
}
|
||||
else
|
||||
{
|
||||
_gridsToShake[gridId] = shakeTimes;
|
||||
}
|
||||
// Play the gravity sound
|
||||
foreach (var player in _playerManager.GetAllPlayers())
|
||||
{
|
||||
if (player.AttachedEntity == null
|
||||
|| player.AttachedEntity.Transform.GridID != gridId) continue;
|
||||
_entitySystemManager.GetEntitySystem<AudioSystem>().Play("/Audio/effects/alert.ogg", player.AttachedEntity);
|
||||
}
|
||||
}
|
||||
|
||||
private void ShakeGrids()
|
||||
{
|
||||
// I have to copy this because C# doesn't allow changing collections while they're
|
||||
// getting enumerated.
|
||||
var gridsToShake = new Dictionary<GridId, uint>(_gridsToShake);
|
||||
foreach (var gridId in _gridsToShake.Keys)
|
||||
{
|
||||
if (_gridsToShake[gridId] == 0)
|
||||
{
|
||||
gridsToShake.Remove(gridId);
|
||||
continue;
|
||||
}
|
||||
ShakeGrid(gridId);
|
||||
gridsToShake[gridId] -= 1;
|
||||
}
|
||||
_gridsToShake = gridsToShake;
|
||||
}
|
||||
|
||||
private void ShakeGrid(GridId gridId)
|
||||
{
|
||||
foreach (var player in _playerManager.GetAllPlayers())
|
||||
{
|
||||
if (player.AttachedEntity == null
|
||||
|| player.AttachedEntity.Transform.GridID != gridId
|
||||
|| !player.AttachedEntity.TryGetComponent(out CameraRecoilComponent recoil))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
recoil.Kick(new Vector2(_random.NextFloat(), _random.NextFloat()) * GravityKick);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
using Content.Server.GameObjects.Components;
|
||||
using System;
|
||||
using System.Net;
|
||||
using Content.Server.GameObjects.Components;
|
||||
using Content.Server.GameObjects.Components.Mobs;
|
||||
using Content.Server.GameObjects.Components.Movement;
|
||||
using Content.Server.GameObjects.Components.Sound;
|
||||
@@ -15,6 +17,7 @@ using Robust.Server.Interfaces.Player;
|
||||
using Robust.Server.Interfaces.Timing;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Components;
|
||||
using Robust.Shared.GameObjects.Components.Transform;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Input;
|
||||
@@ -28,6 +31,7 @@ using Robust.Shared.Log;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
@@ -44,6 +48,7 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
[Dependency] private readonly IMapManager _mapManager;
|
||||
[Dependency] private readonly IRobustRandom _robustRandom;
|
||||
[Dependency] private readonly IConfigurationManager _configurationManager;
|
||||
[Dependency] private readonly IEntityManager _entityManager;
|
||||
#pragma warning restore 649
|
||||
|
||||
private AudioSystem _audioSystem;
|
||||
@@ -130,13 +135,43 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
}
|
||||
var mover = entity.GetComponent<IMoverComponent>();
|
||||
var physics = entity.GetComponent<PhysicsComponent>();
|
||||
|
||||
UpdateKinematics(entity.Transform, mover, physics);
|
||||
if (entity.TryGetComponent<CollidableComponent>(out var collider))
|
||||
{
|
||||
UpdateKinematics(entity.Transform, mover, physics, collider);
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateKinematics(entity.Transform, mover, physics);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateKinematics(ITransformComponent transform, IMoverComponent mover, PhysicsComponent physics)
|
||||
private void UpdateKinematics(ITransformComponent transform, IMoverComponent mover, PhysicsComponent physics, CollidableComponent collider = null)
|
||||
{
|
||||
bool weightless = false;
|
||||
|
||||
var tile = _mapManager.GetGrid(transform.GridID).GetTileRef(transform.GridPosition).Tile;
|
||||
|
||||
if ((!_mapManager.GetGrid(transform.GridID).HasGravity || tile.IsEmpty) && collider != null)
|
||||
{
|
||||
weightless = true;
|
||||
// No gravity: is our entity touching anything?
|
||||
var touching = false;
|
||||
foreach (var entity in _entityManager.GetEntitiesInRange(transform.Owner, mover.GrabRange, true))
|
||||
{
|
||||
if (entity.TryGetComponent<CollidableComponent>(out var otherCollider))
|
||||
{
|
||||
if (otherCollider.Owner == transform.Owner) continue; // Don't try to push off of yourself!
|
||||
touching |= ((collider.CollisionMask & otherCollider.CollisionLayer) != 0x0
|
||||
|| (otherCollider.CollisionMask & collider.CollisionLayer) != 0x0) // Ensure collision
|
||||
&& !entity.HasComponent<ItemComponent>(); // This can't be an item
|
||||
}
|
||||
}
|
||||
if (!touching)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (mover.VelocityDir.LengthSquared < 0.001 || !ActionBlockerSystem.CanMove(mover.Owner))
|
||||
{
|
||||
if (physics.LinearVelocity != Vector2.Zero)
|
||||
@@ -145,6 +180,13 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
}
|
||||
else
|
||||
{
|
||||
if (weightless)
|
||||
{
|
||||
physics.LinearVelocity = mover.VelocityDir * mover.CurrentPushSpeed;
|
||||
transform.LocalRotation = mover.VelocityDir.GetDir().ToAngle();
|
||||
return;
|
||||
}
|
||||
|
||||
physics.LinearVelocity = mover.VelocityDir * (mover.Sprinting ? mover.CurrentSprintSpeed : mover.CurrentWalkSpeed);
|
||||
transform.LocalRotation = mover.VelocityDir.GetDir().ToAngle();
|
||||
|
||||
|
||||
@@ -19,6 +19,17 @@ namespace Content.Server.Interfaces.GameObjects.Components.Movement
|
||||
/// </summary>
|
||||
float CurrentSprintSpeed { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The movement speed (m/s) of the entity when it pushes off of a solid object in zero gravity.
|
||||
/// </summary>
|
||||
float CurrentPushSpeed { get; }
|
||||
|
||||
/// <summary>
|
||||
/// How far an entity can reach (in meters) to grab hold of a solid object in zero gravity.
|
||||
/// </summary>
|
||||
float GrabRange { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Is the entity Sprinting (running)?
|
||||
/// </summary>
|
||||
|
||||
@@ -65,6 +65,14 @@ namespace Content.Server.Throw
|
||||
var spd = a / (1f / timing.TickRate); // acceleration is applied in 1 tick instead of 1 second, scale appropriately
|
||||
|
||||
physComp.LinearVelocity = angle.ToVec() * spd;
|
||||
|
||||
if (throwSourceEnt != null)
|
||||
{
|
||||
var p = throwSourceEnt.GetComponent<PhysicsComponent>();
|
||||
var playerAccel = 5 * throwForce / (float) Math.Max(0.001, p.Mass);
|
||||
p.LinearVelocity = Angle.FromDegrees(angle.Degrees + 180).ToVec()
|
||||
* playerAccel / (1f / timing.TickRate);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Components.UserInterface;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.GameObjects.Components.Gravity
|
||||
{
|
||||
public class SharedGravityGeneratorComponent: Component
|
||||
{
|
||||
public override string Name => "GravityGenerator";
|
||||
|
||||
public override uint? NetID => ContentNetIDs.GRAVITY_GENERATOR;
|
||||
|
||||
/// <summary>
|
||||
/// Sent to the server to set whether the generator should be on or off
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public class SwitchGeneratorMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
public bool On;
|
||||
|
||||
public SwitchGeneratorMessage(bool on)
|
||||
{
|
||||
On = on;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sent to the server when requesting the status of the generator
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public class GeneratorStatusRequestMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
public GeneratorStatusRequestMessage()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public class GeneratorState : BoundUserInterfaceState
|
||||
{
|
||||
public bool On;
|
||||
|
||||
public GeneratorState(bool on)
|
||||
{
|
||||
On = on;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum GravityGeneratorUiKey
|
||||
{
|
||||
Key
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,5 +42,6 @@
|
||||
public const uint PAPER = 1037;
|
||||
public const uint REAGENT_INJECTOR = 1038;
|
||||
public const uint GHOST = 1039;
|
||||
public const uint GRAVITY_GENERATOR = 1040;
|
||||
}
|
||||
}
|
||||
|
||||
BIN
Resources/Audio/effects/alert.ogg
Normal file
@@ -0,0 +1,36 @@
|
||||
- type: entity
|
||||
id: GravityGenerator
|
||||
name: Gravity Generator
|
||||
description: It's what keeps you to the floor.
|
||||
components:
|
||||
- type: Sprite
|
||||
sprite: Buildings/gravity_generator.rsi
|
||||
layers:
|
||||
- state: on
|
||||
- sprite: Buildings/gravity_generator_core.rsi
|
||||
state: activated
|
||||
shader: unshaded
|
||||
- type: Icon
|
||||
sprite: Buildings/gravity_generator.rsi
|
||||
state: on
|
||||
- type: SnapGrid
|
||||
offset: Center
|
||||
- type: PowerDevice
|
||||
load: 500
|
||||
- type: Collidable
|
||||
shapes:
|
||||
- !type:PhysShapeAabb
|
||||
bounds: "-1.5,-1.5,1.5,1.5"
|
||||
layer: 15
|
||||
- type: Clickable
|
||||
- type: InteractionOutline
|
||||
- type: Damageable
|
||||
- type: Breakable
|
||||
threshold: 150
|
||||
- type: GravityGenerator
|
||||
- type: UserInterface
|
||||
interfaces:
|
||||
- key: enum.GravityGeneratorUiKey.Key
|
||||
type: GravityGeneratorBoundUserInterface
|
||||
placement:
|
||||
mode: AlignTileAny
|
||||
BIN
Resources/Textures/Buildings/gravity_generator.rsi/broken.png
Normal file
|
After Width: | Height: | Size: 21 KiB |
23
Resources/Textures/Buildings/gravity_generator.rsi/meta.json
Executable file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"version":1,
|
||||
"size":{
|
||||
"x":96,
|
||||
"y":96
|
||||
},
|
||||
"license":"CC-BY-SA-3.0",
|
||||
"copyright":"Taken from https://github.com/tgstation/tgstation",
|
||||
"states":[
|
||||
{
|
||||
"name":"on",
|
||||
"directions": 1
|
||||
},
|
||||
{
|
||||
"name": "off",
|
||||
"directions": 1
|
||||
},
|
||||
{
|
||||
"name": "broken",
|
||||
"directions": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
BIN
Resources/Textures/Buildings/gravity_generator.rsi/off.png
Normal file
|
After Width: | Height: | Size: 18 KiB |
BIN
Resources/Textures/Buildings/gravity_generator.rsi/on.png
Executable file
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 684 B |
BIN
Resources/Textures/Buildings/gravity_generator_core.rsi/idle.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"version":1,
|
||||
"size":{
|
||||
"x":32,
|
||||
"y":32
|
||||
},
|
||||
"license":"CC-BY-SA-3.0",
|
||||
"copyright":"Taken from https://github.com/tgstation/tgstation",
|
||||
"states":[
|
||||
{
|
||||
"name": "activated",
|
||||
"directions": 1,
|
||||
"delays": [
|
||||
[0.1,
|
||||
0.1,
|
||||
0.1]
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
After Width: | Height: | Size: 1.1 KiB |