Merge remote-tracking branch 'upstream/master' into 20-10-30-admins

This commit is contained in:
Pieter-Jan Briers
2020-11-10 16:59:17 +01:00
473 changed files with 5588 additions and 3584 deletions

View File

@@ -1,9 +1,9 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using Content.Server.Administration;
using Content.Server.GameObjects.Components.Movement;
using Content.Shared;
using Content.Shared.Administration;
using Content.Shared.GameObjects.Components.Movement;
using JetBrains.Annotations;
@@ -44,7 +44,6 @@ namespace Content.Server.GameObjects.EntitySystems.AI
public override void Initialize()
{
base.Initialize();
_configurationManager.RegisterCVar("ai.maxupdates", 64);
SubscribeLocalEvent<SleepAiMessage>(HandleAiSleep);
var processors = _reflectionManager.GetAllChildren<AiLogicProcessor>();
@@ -60,7 +59,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI
/// <inheritdoc />
public override void Update(float frameTime)
{
var cvarMaxUpdates = _configurationManager.GetCVar<int>("ai.maxupdates");
var cvarMaxUpdates = _configurationManager.GetCVar(CCVars.AIMaxUpdates);
if (cvarMaxUpdates <= 0)
return;

View File

@@ -328,9 +328,16 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
return;
}
var newGridId = moveEvent.NewPosition.GetGridId(_entityManager);
if (newGridId == GridId.Invalid)
{
HandleEntityRemove(moveEvent.Sender);
return;
}
// The pathfinding graph is tile-based so first we'll check if they're on a different tile and if we need to update.
// If you get entities bigger than 1 tile wide you'll need some other system so god help you.
var newTile = _mapManager.GetGrid(moveEvent.NewPosition.GetGridId(_entityManager)).GetTileRef(moveEvent.NewPosition);
var newTile = _mapManager.GetGrid(newGridId).GetTileRef(moveEvent.NewPosition);
if (oldNode == null || oldNode.TileRef == newTile)
{

View File

@@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Content.Server.GameObjects.Components.Atmos;
using Content.Server.Atmos;
using Content.Shared;
using Content.Shared.Atmos;
using Content.Shared.GameObjects.EntitySystems.Atmos;
using JetBrains.Annotations;
@@ -47,7 +48,6 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos
_atmosphereSystem = Get<AtmosphereSystem>();
_playerManager.PlayerStatusChanged += OnPlayerStatusChanged;
_configManager.RegisterCVar("net.atmosdbgoverlaytickrate", 3.0f);
}
public override void Shutdown()
@@ -89,7 +89,7 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos
public override void Update(float frameTime)
{
AccumulatedFrameTime += frameTime;
_updateCooldown = 1 / _configManager.GetCVar<float>("net.atmosdbgoverlaytickrate");
_updateCooldown = 1 / _configManager.GetCVar(CCVars.NetAtmosDebugOverlayTickRate);
if (AccumulatedFrameTime < _updateCooldown)
{

View File

@@ -4,12 +4,14 @@ using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using Content.Server.GameObjects.Components.Atmos;
using Content.Shared;
using Content.Shared.Atmos;
using Content.Shared.GameObjects.EntitySystems.Atmos;
using Content.Shared.GameTicking;
using JetBrains.Annotations;
using Robust.Server.Interfaces.Player;
using Robust.Server.Player;
using Robust.Shared;
using Robust.Shared.Enums;
using Robust.Shared.Interfaces.Configuration;
using Robust.Shared.Interfaces.GameObjects;
@@ -65,7 +67,6 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos
_atmosphereSystem = Get<AtmosphereSystem>();
_playerManager.PlayerStatusChanged += OnPlayerStatusChanged;
_mapManager.OnGridRemoved += OnGridRemoved;
_configManager.RegisterCVar("net.gasoverlaytickrate", 3.0f);
}
public override void Shutdown()
@@ -228,14 +229,14 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos
public override void Update(float frameTime)
{
AccumulatedFrameTime += frameTime;
_updateCooldown = 1 / _configManager.GetCVar<float>("net.gasoverlaytickrate");
_updateCooldown = 1 / _configManager.GetCVar(CCVars.NetGasOverlayTickRate);
if (AccumulatedFrameTime < _updateCooldown)
{
return;
}
_updateRange = _configManager.GetCVar<float>("net.maxupdaterange") + RangeOffset;
_updateRange = _configManager.GetCVar(CVars.NetMaxUpdateRange) + RangeOffset;
// TODO: So in the worst case scenario we still have to send a LOT of tile data per tick if there's a fire.
// If we go with say 15 tile radius then we have up to 900 tiles to update per tick.

View File

@@ -1,7 +1,12 @@
using Content.Server.GameObjects.Components.Buckle;
#nullable enable
using Content.Server.GameObjects.Components.Buckle;
using Content.Server.GameObjects.Components.Strap;
using Content.Server.GameObjects.EntitySystems.Click;
using JetBrains.Annotations;
using Robust.Server.GameObjects.EntitySystemMessages;
using Robust.Server.GameObjects.EntitySystems;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects.Components.Transform;
using Robust.Shared.GameObjects.Systems;
namespace Content.Server.GameObjects.EntitySystems
@@ -15,13 +20,84 @@ namespace Content.Server.GameObjects.EntitySystems
UpdatesAfter.Add(typeof(InteractionSystem));
UpdatesAfter.Add(typeof(InputSystem));
SubscribeLocalEvent<MoveEvent>(MoveEvent);
SubscribeLocalEvent<EntInsertedIntoContainerMessage>(ContainerModified);
SubscribeLocalEvent<EntRemovedFromContainerMessage>(ContainerModified);
}
public override void Update(float frameTime)
public override void Shutdown()
{
foreach (var buckle in ComponentManager.EntityQuery<BuckleComponent>())
base.Shutdown();
UnsubscribeLocalEvent<MoveEvent>();
}
private void MoveEvent(MoveEvent ev)
{
if (!ev.Sender.TryGetComponent(out BuckleComponent? buckle))
{
buckle.Update();
return;
}
var strap = buckle.BuckledTo;
if (strap == null)
{
return;
}
var strapPosition = strap.Owner.Transform.Coordinates.Offset(buckle.BuckleOffset);
if (ev.NewPosition.InRange(EntityManager, strapPosition, 0.2f))
{
return;
}
buckle.TryUnbuckle(buckle.Owner, true);
}
private void ContainerModified(ContainerModifiedMessage message)
{
// Not returning is necessary in case an entity has both a buckle and strap component
if (message.Entity.TryGetComponent(out BuckleComponent? buckle))
{
ContainerModifiedReAttach(buckle, buckle.BuckledTo);
}
if (message.Entity.TryGetComponent(out StrapComponent? strap))
{
foreach (var buckledEntity in strap.BuckledEntities)
{
if (!buckledEntity.TryGetComponent(out BuckleComponent? buckled))
{
continue;
}
ContainerModifiedReAttach(buckled, strap);
}
}
}
private void ContainerModifiedReAttach(BuckleComponent buckle, StrapComponent? strap)
{
if (strap == null)
{
return;
}
var contained = ContainerHelpers.TryGetContainer(buckle.Owner, out var ownContainer);
var strapContained = ContainerHelpers.TryGetContainer(strap.Owner, out var strapContainer);
if (contained != strapContained || ownContainer != strapContainer)
{
buckle.TryUnbuckle(buckle.Owner, true);
return;
}
if (!contained)
{
buckle.ReAttach(strap);
}
}
}

View File

@@ -156,7 +156,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
private bool HandleWideAttack(ICommonSession session, EntityCoordinates coords, EntityUid uid)
{
// client sanitization
if (!_mapManager.GridExists(coords.GetGridId(_entityManager)))
if (!coords.IsValid(_entityManager))
{
Logger.InfoS("system.interaction", $"Invalid Coordinates: client={session}, coords={coords}");
return true;
@@ -211,7 +211,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
private bool HandleClientUseItemInHand(ICommonSession session, EntityCoordinates coords, EntityUid uid)
{
// client sanitization
if (!_mapManager.GridExists(coords.GetGridId(_entityManager)))
if (!coords.IsValid(_entityManager))
{
Logger.InfoS("system.interaction", $"Invalid Coordinates: client={session}, coords={coords}");
return true;
@@ -242,7 +242,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
private bool HandleTryPullObject(ICommonSession session, EntityCoordinates coords, EntityUid uid)
{
// client sanitization
if (!_mapManager.GridExists(coords.GetGridId(_entityManager)))
if (!coords.IsValid(_entityManager))
{
Logger.InfoS("system.interaction", $"Invalid Coordinates for pulling: client={session}, coords={coords}");
return false;
@@ -303,7 +303,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
}
// Verify player is on the same map as the entity he clicked on
if (_mapManager.GetGrid(coordinates.GetGridId(EntityManager)).ParentMapId != playerTransform.MapID)
if (coordinates.GetMapId(_entityManager) != playerTransform.MapID)
{
Logger.WarningS("system.interaction",
$"Player named {player.Name} clicked on a map he isn't located on");

View File

@@ -20,6 +20,7 @@ using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Random;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Log;
using Robust.Shared.Maths;
using Robust.Shared.Players;
using Robust.Shared.Prototypes;
@@ -306,8 +307,18 @@ namespace Content.Server.GameObjects.EntitySystems
private async void HandleStartItemConstruction(TryStartItemConstructionMessage ev, EntitySessionEventArgs args)
{
var constructionPrototype = _prototypeManager.Index<ConstructionPrototype>(ev.PrototypeName);
var constructionGraph = _prototypeManager.Index<ConstructionGraphPrototype>(constructionPrototype.Graph);
if (!_prototypeManager.TryIndex(ev.PrototypeName, out ConstructionPrototype constructionPrototype))
{
Logger.Error($"Tried to start construction of invalid recipe '{ev.PrototypeName}'!");
return;
}
if (!_prototypeManager.TryIndex(constructionPrototype.Graph, out ConstructionGraphPrototype constructionGraph))
{
Logger.Error($"Invalid construction graph '{constructionPrototype.Graph}' in recipe '{ev.PrototypeName}'!");
return;
}
var startNode = constructionGraph.Nodes[constructionPrototype.StartNode];
var targetNode = constructionGraph.Nodes[constructionPrototype.TargetNode];
var pathFind = constructionGraph.Path(startNode.Name, targetNode.Name);
@@ -352,8 +363,20 @@ namespace Content.Server.GameObjects.EntitySystems
private async void HandleStartStructureConstruction(TryStartStructureConstructionMessage ev, EntitySessionEventArgs args)
{
var constructionPrototype = _prototypeManager.Index<ConstructionPrototype>(ev.PrototypeName);
var constructionGraph = _prototypeManager.Index<ConstructionGraphPrototype>(constructionPrototype.Graph);
if (!_prototypeManager.TryIndex(ev.PrototypeName, out ConstructionPrototype constructionPrototype))
{
Logger.Error($"Tried to start construction of invalid recipe '{ev.PrototypeName}'!");
RaiseNetworkEvent(new AckStructureConstructionMessage(ev.Ack));
return;
}
if (!_prototypeManager.TryIndex(constructionPrototype.Graph, out ConstructionGraphPrototype constructionGraph))
{
Logger.Error($"Invalid construction graph '{constructionPrototype.Graph}' in recipe '{ev.PrototypeName}'!");
RaiseNetworkEvent(new AckStructureConstructionMessage(ev.Ack));
return;
}
var startNode = constructionGraph.Nodes[constructionPrototype.StartNode];
var targetNode = constructionGraph.Nodes[constructionPrototype.TargetNode];
var pathFind = constructionGraph.Path(startNode.Name, targetNode.Name);

View File

@@ -1,27 +1,16 @@
using Content.Server.Interfaces;
using Content.Server.Interfaces;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.IoC;
namespace Content.Server.GameObjects.EntitySystems.DeviceNetwork
{
public class DeviceNetworkSystem : EntitySystem
internal sealed class DeviceNetworkSystem : EntitySystem
{
private IDeviceNetwork _network;
public override void Initialize()
{
base.Initialize();
_network = IoCManager.Resolve<IDeviceNetwork>();
}
[Dependency] private readonly IDeviceNetwork _network = default!;
public override void Update(float frameTime)
{
base.Update(frameTime);
if (_network == null)
return;
//(ノ°Д°)ノ︵ ┻━┻
_network.Update();
}
}

View File

@@ -1,28 +0,0 @@
using Content.Shared.GameObjects.Components.Body.Behavior;
using Content.Shared.GameObjects.EntitySystems;
using JetBrains.Annotations;
using Robust.Shared.GameObjects.Systems;
namespace Content.Server.GameObjects.EntitySystems
{
[UsedImplicitly]
public class HeartSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
UpdatesBefore.Add(typeof(MetabolismSystem));
}
public override void Update(float frameTime)
{
base.Update(frameTime);
foreach (var heart in ComponentManager.EntityQuery<SharedHeartBehaviorComponent>())
{
heart.Update(frameTime);
}
}
}
}

View File

@@ -1,28 +0,0 @@
using Content.Shared.GameObjects.Components.Body.Behavior;
using Content.Shared.GameObjects.EntitySystems;
using JetBrains.Annotations;
using Robust.Shared.GameObjects.Systems;
namespace Content.Server.GameObjects.EntitySystems
{
[UsedImplicitly]
public class LungSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
UpdatesBefore.Add(typeof(MetabolismSystem));
}
public override void Update(float frameTime)
{
base.Update(frameTime);
foreach (var lung in ComponentManager.EntityQuery<SharedLungBehaviorComponent>())
{
lung.Update(frameTime);
}
}
}
}

View File

@@ -0,0 +1,45 @@
using System.Linq;
using Content.Server.GameObjects.Components.NodeContainer;
using Content.Server.GameObjects.Components.NodeContainer.Nodes;
using JetBrains.Annotations;
using Robust.Shared.GameObjects.Components.Transform;
using Robust.Shared.GameObjects.Systems;
namespace Content.Server.GameObjects.EntitySystems
{
[UsedImplicitly]
public class NodeContainerSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<RotateEvent>(RotateEvent);
}
public override void Shutdown()
{
base.Shutdown();
UnsubscribeLocalEvent<RotateEvent>();
}
private void RotateEvent(RotateEvent ev)
{
if (!ev.Sender.TryGetComponent(out NodeContainerComponent container))
{
return;
}
if (ev.NewRotation == ev.OldRotation)
{
return;
}
foreach (var rotatableNode in container.Nodes.OfType<IRotatableNode>())
{
rotatableNode.RotateEvent(ev);
}
}
}
}

View File

@@ -6,6 +6,7 @@ using Content.Server.Players;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Input;
using Content.Shared.Interfaces;
using Content.Shared.Utility;
using JetBrains.Annotations;
using Robust.Server.GameObjects.Components;
using Robust.Server.Interfaces.Player;
@@ -75,9 +76,9 @@ namespace Content.Server.GameObjects.EntitySystems
}
}
public bool InRange(EntityCoordinates from, EntityCoordinates to)
public bool InRange(IEntity pointer, EntityCoordinates coordinates)
{
return from.InRange(EntityManager, to, 15);
return pointer.InRangeUnOccluded(coordinates, 15, e => e == pointer);
}
public bool TryPoint(ICommonSession? session, EntityCoordinates coords, EntityUid uid)
@@ -100,7 +101,7 @@ namespace Content.Server.GameObjects.EntitySystems
return false;
}
if (!InRange(coords, player.Transform.Coordinates))
if (!InRange(player, coords))
{
player.PopupMessage(Loc.GetString("You can't reach there!"));
return false;

View File

@@ -1,6 +1,7 @@
using System.Collections.Generic;
using Content.Server.Administration;
using Content.Server.GameObjects.Components.MachineLinking;
using Content.Server.GameObjects.EntitySystems.Click;
using Content.Shared.Administration;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
@@ -27,7 +28,7 @@ namespace Content.Server.GameObjects.EntitySystems
_transmitters = new Dictionary<NetUserId, SignalTransmitterComponent>();
}
public void SignalLinkerKeybind(NetUserId id, bool? enable)
public bool SignalLinkerKeybind(NetUserId id, bool? enable)
{
if (enable == null)
{
@@ -38,13 +39,13 @@ namespace Content.Server.GameObjects.EntitySystems
{
if (_transmitters.ContainsKey(id))
{
return;
return true;
}
if (_transmitters.Count == 0)
{
CommandBinds.Builder
.Bind(EngineKeyFunctions.Use, new PointerInputCmdHandler(HandleUse))
.BindBefore(EngineKeyFunctions.Use, new PointerInputCmdHandler(HandleUse), typeof(InteractionSystem))
.Register<SignalLinkerSystem>();
}
@@ -55,7 +56,7 @@ namespace Content.Server.GameObjects.EntitySystems
{
if (!_transmitters.ContainsKey(id))
{
return;
return false;
}
_transmitters.Remove(id);
@@ -64,6 +65,7 @@ namespace Content.Server.GameObjects.EntitySystems
CommandBinds.Unregister<SignalLinkerSystem>();
}
}
return enable == true;
}
private bool HandleUse(ICommonSession session, EntityCoordinates coords, EntityUid uid)
@@ -132,7 +134,8 @@ namespace Content.Server.GameObjects.EntitySystems
return;
}
system.SignalLinkerKeybind(player.UserId, enable);
var ret = system.SignalLinkerKeybind(player.UserId, enable);
shell.SendText(player, ret ? "Enabled" : "Disabled");
}
}
}

View File

@@ -4,11 +4,13 @@ using System.Text;
using Content.Server.GameTicking;
using Content.Server.Interfaces.GameTicking;
using Content.Server.StationEvents;
using Content.Shared;
using Content.Shared.GameTicking;
using JetBrains.Annotations;
using Robust.Server.Console;
using Robust.Server.Interfaces.Player;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.Configuration;
using Robust.Shared.Interfaces.Network;
using Robust.Shared.Interfaces.Random;
using Robust.Shared.Interfaces.Reflection;
@@ -23,6 +25,7 @@ namespace Content.Server.GameObjects.EntitySystems.StationEvents
// Somewhat based off of TG's implementation of events
public sealed class StationEventSystem : EntitySystem, IResettingEntitySystem
{
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
[Dependency] private readonly IServerNetManager _netManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IGameTicker _gameTicker = default!;
@@ -164,6 +167,9 @@ namespace Content.Server.GameObjects.EntitySystems.StationEvents
_stationEvents.Add(stationEvent);
}
// Can't just check debug / release for a default given mappers need to use release mode
// As such we'll always pause it by default.
_configurationManager.OnValueChanged(CCVars.EventsEnabled, value => Enabled = value, true);
_netManager.RegisterNetMessage<MsgGetStationEvents>(nameof(MsgGetStationEvents), GetEventReceived);
}

View File

@@ -1,5 +1,6 @@
using System.Collections.Generic;
using Content.Server.GameObjects.Components.Mobs;
using Content.Shared.Alert;
using Content.Shared.GameObjects.Components.Mobs;
using Content.Shared.GameObjects.EntitySystemMessages.Gravity;
using Content.Shared.GameTicking;
@@ -19,7 +20,7 @@ namespace Content.Server.GameObjects.EntitySystems
{
[Dependency] private readonly IMapManager _mapManager = default!;
private readonly Dictionary<GridId, List<ServerStatusEffectsComponent>> _statuses = new Dictionary<GridId, List<ServerStatusEffectsComponent>>();
private readonly Dictionary<GridId, List<ServerAlertsComponent>> _alerts = new Dictionary<GridId, List<ServerAlertsComponent>>();
public override void Initialize()
{
@@ -31,15 +32,15 @@ namespace Content.Server.GameObjects.EntitySystems
public void Reset()
{
_statuses.Clear();
_alerts.Clear();
}
public void AddStatus(ServerStatusEffectsComponent status)
public void AddAlert(ServerAlertsComponent status)
{
var gridId = status.Owner.Transform.GridID;
var statuses = _statuses.GetOrNew(gridId);
var alerts = _alerts.GetOrNew(gridId);
statuses.Add(status);
alerts.Add(status);
if (_mapManager.TryGetGrid(status.Owner.Transform.GridID, out var grid))
{
@@ -54,10 +55,10 @@ namespace Content.Server.GameObjects.EntitySystems
}
}
public void RemoveStatus(ServerStatusEffectsComponent status)
public void RemoveAlert(ServerAlertsComponent status)
{
var grid = status.Owner.Transform.GridID;
if (!_statuses.TryGetValue(grid, out var statuses))
if (!_alerts.TryGetValue(grid, out var statuses))
{
return;
}
@@ -67,7 +68,7 @@ namespace Content.Server.GameObjects.EntitySystems
private void GravityChanged(GravityChangedMessage ev)
{
if (!_statuses.TryGetValue(ev.Grid.Index, out var statuses))
if (!_alerts.TryGetValue(ev.Grid.Index, out var statuses))
{
return;
}
@@ -88,19 +89,19 @@ namespace Content.Server.GameObjects.EntitySystems
}
}
private void AddWeightless(ServerStatusEffectsComponent status)
private void AddWeightless(ServerAlertsComponent status)
{
status.ChangeStatusEffect(StatusEffect.Weightless, "/Textures/Interface/StatusEffects/Weightless/weightless.png", null);
status.ShowAlert(AlertType.Weightless);
}
private void RemoveWeightless(ServerStatusEffectsComponent status)
private void RemoveWeightless(ServerAlertsComponent status)
{
status.RemoveStatusEffect(StatusEffect.Weightless);
status.ClearAlert(AlertType.Weightless);
}
private void EntParentChanged(EntParentChangedMessage ev)
{
if (!ev.Entity.TryGetComponent(out ServerStatusEffectsComponent status))
if (!ev.Entity.TryGetComponent(out ServerAlertsComponent status))
{
return;
}
@@ -110,14 +111,14 @@ namespace Content.Server.GameObjects.EntitySystems
{
var oldGrid = mapGrid.GridIndex;
if (_statuses.TryGetValue(oldGrid, out var oldStatuses))
if (_alerts.TryGetValue(oldGrid, out var oldStatuses))
{
oldStatuses.Remove(status);
}
}
var newGrid = ev.Entity.Transform.GridID;
var newStatuses = _statuses.GetOrNew(newGrid);
var newStatuses = _alerts.GetOrNew(newGrid);
newStatuses.Add(status);
}