removes componentdependencies (#6160)

This commit is contained in:
Paul Ritter
2022-01-15 03:26:37 +01:00
committed by GitHub
parent 46405ec165
commit 9e1607722d
33 changed files with 257 additions and 274 deletions

View File

@@ -3,6 +3,7 @@ using Content.Shared.Cuffs.Components;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
@@ -15,7 +16,7 @@ namespace Content.Client.Cuffs.Components
[ViewVariables]
private string? _currentRSI;
[ViewVariables] [ComponentDependency] private readonly SpriteComponent? _spriteComponent = null;
[Dependency] private readonly IEntityManager _entityManager = default!;
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
{
@@ -26,10 +27,10 @@ namespace Content.Client.Cuffs.Components
CanStillInteract = cuffState.CanStillInteract;
if (_spriteComponent != null)
if (_entityManager.TryGetComponent<SpriteComponent>(Owner, out var spriteComponent))
{
_spriteComponent.LayerSetVisible(HumanoidVisualLayers.Handcuffs, cuffState.NumHandsCuffed > 0);
_spriteComponent.LayerSetColor(HumanoidVisualLayers.Handcuffs, cuffState.Color);
spriteComponent.LayerSetVisible(HumanoidVisualLayers.Handcuffs, cuffState.NumHandsCuffed > 0);
spriteComponent.LayerSetColor(HumanoidVisualLayers.Handcuffs, cuffState.Color);
if (cuffState.NumHandsCuffed > 0)
{
@@ -39,12 +40,12 @@ namespace Content.Client.Cuffs.Components
if (_currentRSI != null)
{
_spriteComponent.LayerSetState(HumanoidVisualLayers.Handcuffs, new RSI.StateId(cuffState.IconState), new ResourcePath(_currentRSI));
spriteComponent.LayerSetState(HumanoidVisualLayers.Handcuffs, new RSI.StateId(cuffState.IconState), new ResourcePath(_currentRSI));
}
}
else
{
_spriteComponent.LayerSetState(HumanoidVisualLayers.Handcuffs, new RSI.StateId(cuffState.IconState)); // TODO: safety check to see if RSI contains the state?
spriteComponent.LayerSetState(HumanoidVisualLayers.Handcuffs, new RSI.StateId(cuffState.IconState)); // TODO: safety check to see if RSI contains the state?
}
}
}
@@ -53,8 +54,8 @@ namespace Content.Client.Cuffs.Components
protected override void OnRemove()
{
base.OnRemove();
_spriteComponent?.LayerSetVisible(HumanoidVisualLayers.Handcuffs, false);
if (_entityManager.TryGetComponent<SpriteComponent>(Owner, out var spriteComponent))
spriteComponent.LayerSetVisible(HumanoidVisualLayers.Handcuffs, false);
}
}
}

View File

@@ -23,9 +23,9 @@ namespace Content.Server.Arcade.Components
public override string Name => "BlockGameArcade";
[ComponentDependency] private readonly ApcPowerReceiverComponent? _powerReceiverComponent = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
private bool Powered => _powerReceiverComponent?.Powered ?? false;
private bool Powered => _entityManager.TryGetComponent<ApcPowerReceiverComponent>(Owner, out var powerReceiverComponent) && powerReceiverComponent.Powered;
private BoundUserInterface? UserInterface => Owner.GetUIOrNull(BlockGameUiKey.Key);
private BlockGame? _game;

View File

@@ -30,10 +30,8 @@ namespace Content.Server.Arcade.Components
{
[Dependency] private readonly IRobustRandom _random = null!;
[ComponentDependency] private readonly ApcPowerReceiverComponent? _powerReceiverComponent = default!;
[ComponentDependency] private readonly WiresComponent? _wiresComponent = default!;
private bool Powered => _powerReceiverComponent != null && _powerReceiverComponent.Powered;
[Dependency] private readonly IEntityManager _entityManager = default!;
private bool Powered => _entityManager.TryGetComponent<ApcPowerReceiverComponent>(Owner, out var powerReceiverComponent) && powerReceiverComponent.Powered;
[ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(SpaceVillainArcadeUiKey.Key);
[ViewVariables] private bool _overflowFlag;
@@ -84,9 +82,9 @@ namespace Content.Server.Arcade.Components
_game ??= new SpaceVillainGame(this);
if (_wiresComponent?.IsPanelOpen == true)
if (_entityManager.TryGetComponent<WiresComponent>(Owner, out var wiresComponent) && wiresComponent.IsPanelOpen)
{
_wiresComponent.OpenInterface(actor.PlayerSession);
wiresComponent.OpenInterface(actor.PlayerSession);
}
else
{
@@ -205,13 +203,15 @@ namespace Content.Server.Arcade.Components
public void IndicatorUpdate()
{
_wiresComponent?.SetStatus(Indicators.HealthManager,
if (!_entityManager.TryGetComponent<WiresComponent>(Owner, out var wiresComponent)) return;
wiresComponent.SetStatus(Indicators.HealthManager,
new SharedWiresComponent.StatusLightData(Color.Purple,
_playerInvincibilityFlag || _enemyInvincibilityFlag
? SharedWiresComponent.StatusLightState.BlinkingSlow
: SharedWiresComponent.StatusLightState.On,
"MNGR"));
_wiresComponent?.SetStatus(Indicators.HealthLimiter,
wiresComponent.SetStatus(Indicators.HealthLimiter,
new SharedWiresComponent.StatusLightData(Color.Red,
_overflowFlag
? SharedWiresComponent.StatusLightState.BlinkingSlow

View File

@@ -43,7 +43,7 @@ namespace Content.Server.Atmos.Components
private int _integrity = 3;
[ComponentDependency] private readonly ItemActionsComponent? _itemActions = null;
[Dependency] private readonly IEntityManager _entityManager = default!;
[ViewVariables] private BoundUserInterface? _userInterface;
@@ -190,8 +190,8 @@ namespace Content.Server.Atmos.Components
CanConnectInternals = IsFunctional && internals != null
});
if (internals == null) return;
_itemActions?.GrantOrUpdate(ItemActionType.ToggleInternals, IsFunctional, IsConnected);
if (internals == null || !_entityManager.TryGetComponent<ItemActionsComponent>(Owner, out var itemActions)) return;
itemActions.GrantOrUpdate(ItemActionType.ToggleInternals, IsFunctional, IsConnected);
}
private void UserInterfaceOnOnReceiveMessage(ServerBoundUserInterfaceMessage message)

View File

@@ -8,6 +8,7 @@ using Content.Server.VendingMachines; // TODO: Move this out of vending machines
using Content.Server.WireHacking;
using Content.Shared.Atmos.Monitor.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Network;
using Robust.Shared.ViewVariables;
@@ -19,10 +20,7 @@ namespace Content.Server.Atmos.Monitor.Components
[RegisterComponent]
public class AirAlarmComponent : Component, IWires
{
[ComponentDependency] public readonly ApcPowerReceiverComponent? DeviceRecvComponent = default!;
[ComponentDependency] public readonly AtmosMonitorComponent? AtmosMonitorComponent = default!;
[ComponentDependency] public readonly DeviceNetworkComponent? DeviceNetComponent = default!;
[ComponentDependency] public readonly WiresComponent? WiresComponent = null;
[Dependency] private readonly IEntityManager _entMan = default!;
private AirAlarmSystem? _airAlarmSystem;
@@ -79,7 +77,7 @@ namespace Content.Server.Atmos.Monitor.Components
if (_airAlarmSystem == null)
_airAlarmSystem = EntitySystem.Get<AirAlarmSystem>();
if (WiresComponent == null) return;
if (!_entMan.TryGetComponent<WiresComponent>(Owner, out var wires)) return;
var pwrLightState = (PowerPulsed, PowerCut) switch {
(true, false) => StatusLightState.BlinkingFast,
@@ -91,7 +89,7 @@ namespace Content.Server.Atmos.Monitor.Components
var accessLight = new StatusLightData(
Color.Green,
WiresComponent.IsWireCut(Wires.Access) ? StatusLightState.Off : StatusLightState.On,
wires.IsWireCut(Wires.Access) ? StatusLightState.Off : StatusLightState.On,
"ACC"
);
@@ -103,17 +101,17 @@ namespace Content.Server.Atmos.Monitor.Components
var syncLightState = StatusLightState.BlinkingSlow;
if (AtmosMonitorComponent != null && !AtmosMonitorComponent.NetEnabled)
if (_entMan.TryGetComponent<AtmosMonitorComponent>(Owner, out var atmosMonitorComponent) && !atmosMonitorComponent.NetEnabled)
syncLightState = StatusLightState.Off;
else if (DeviceData.Count != 0)
syncLightState = StatusLightState.On;
var syncLight = new StatusLightData(Color.Orange, syncLightState, "NET");
WiresComponent.SetStatus(AirAlarmWireStatus.Power, powerLight);
WiresComponent.SetStatus(AirAlarmWireStatus.Access, accessLight);
WiresComponent.SetStatus(AirAlarmWireStatus.Panic, panicLight);
WiresComponent.SetStatus(AirAlarmWireStatus.DeviceSync, syncLight);
wires.SetStatus(AirAlarmWireStatus.Power, powerLight);
wires.SetStatus(AirAlarmWireStatus.Access, accessLight);
wires.SetStatus(AirAlarmWireStatus.Panic, panicLight);
wires.SetStatus(AirAlarmWireStatus.DeviceSync, syncLight);
}
private bool _powerCut;
@@ -140,14 +138,14 @@ namespace Content.Server.Atmos.Monitor.Components
private void SetPower()
{
if (DeviceRecvComponent != null
&& WiresComponent != null)
DeviceRecvComponent.PowerDisabled = PowerPulsed || PowerCut;
if (_entMan.TryGetComponent<ApcPowerReceiverComponent>(Owner, out var receiverComponent)
&& _entMan.HasComponent<WiresComponent>(Owner))
receiverComponent.PowerDisabled = PowerPulsed || PowerCut;
}
public void WiresUpdate(WiresUpdateEventArgs args)
{
if (DeviceNetComponent == null) return;
if (!_entMan.TryGetComponent<DeviceNetworkComponent>(Owner, out var deviceNetworkComponent)) return;
if (_airAlarmSystem == null)
_airAlarmSystem = EntitySystem.Get<AirAlarmSystem>();
@@ -167,7 +165,7 @@ namespace Content.Server.Atmos.Monitor.Components
break;
case Wires.Panic:
if (CurrentMode != AirAlarmMode.Panic)
_airAlarmSystem.SetMode(Owner, DeviceNetComponent.Address, AirAlarmMode.Panic, true, false);
_airAlarmSystem.SetMode(Owner, deviceNetworkComponent.Address, AirAlarmMode.Panic, true, false);
break;
case Wires.DeviceSync:
_airAlarmSystem.SyncAllDevices(Owner);
@@ -184,14 +182,14 @@ namespace Content.Server.Atmos.Monitor.Components
break;
case Wires.Panic:
if (CurrentMode == AirAlarmMode.Panic)
_airAlarmSystem.SetMode(Owner, DeviceNetComponent.Address, AirAlarmMode.Filtering, true, false);
_airAlarmSystem.SetMode(Owner, deviceNetworkComponent.Address, AirAlarmMode.Filtering, true, false);
break;
case Wires.Access:
FullAccess = false;
break;
case Wires.DeviceSync:
if (AtmosMonitorComponent != null)
AtmosMonitorComponent.NetEnabled = true;
if (_entMan.TryGetComponent<AtmosMonitorComponent>(Owner, out var atmosMonitorComponent))
atmosMonitorComponent.NetEnabled = true;
break;
}
@@ -201,10 +199,10 @@ namespace Content.Server.Atmos.Monitor.Components
{
case Wires.DeviceSync:
DeviceData.Clear();
if (AtmosMonitorComponent != null)
if (_entMan.TryGetComponent<AtmosMonitorComponent>(Owner, out var atmosMonitorComponent))
{
AtmosMonitorComponent.NetworkAlarmStates.Clear();
AtmosMonitorComponent.NetEnabled = false;
atmosMonitorComponent.NetworkAlarmStates.Clear();
atmosMonitorComponent.NetEnabled = false;
}
break;

View File

@@ -16,12 +16,6 @@ namespace Content.Server.Atmos.Monitor.Components
{
public override string Name => "AtmosMonitor";
// Requires power. No logic related to this will be performed here, however,
// save for ensuring that the data is valid upon set.
// This is how the system discovers entities that are alarmable.
[ComponentDependency] public readonly ApcPowerReceiverComponent? PowerRecvComponent = default!;
[ComponentDependency] public readonly AtmosDeviceComponent? AtmosDeviceComponent = default!;
// Whether this monitor can send alarms,
// or recieve atmos command events.
//

View File

@@ -9,6 +9,7 @@ using Content.Shared.Atmos.Monitor;
using Content.Shared.Atmos.Monitor.Components;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Maths;
using static Content.Shared.Wires.SharedWiresComponent;
@@ -20,9 +21,7 @@ namespace Content.Server.Atmos.Monitor.Components
[RegisterComponent]
public class FireAlarmComponent : Component, IWires
{
[ComponentDependency] public readonly ApcPowerReceiverComponent? DeviceRecvComponent = default!;
[ComponentDependency] public readonly AtmosMonitorComponent? AtmosMonitorComponent = default!;
[ComponentDependency] public readonly WiresComponent? WiresComponent = null;
[Dependency] private readonly IEntityManager _entMan = default!;
private AtmosMonitorSystem? _atmosMonitorSystem;
@@ -69,9 +68,8 @@ namespace Content.Server.Atmos.Monitor.Components
private void SetPower()
{
if (DeviceRecvComponent != null
&& WiresComponent != null)
DeviceRecvComponent.PowerDisabled = PowerPulsed || PowerCut;
if (_entMan.TryGetComponent<ApcPowerReceiverComponent>(Owner, out var receiverComponent) && _entMan.HasComponent<WiresComponent>(Owner))
receiverComponent.PowerDisabled = PowerPulsed || PowerCut;
}
@@ -87,7 +85,7 @@ namespace Content.Server.Atmos.Monitor.Components
public void UpdateWires()
{
if (WiresComponent == null) return;
if (!_entMan.TryGetComponent<WiresComponent>(Owner, out var wiresComponent)) return;
var powerLight = new StatusLightData(Color.Yellow, StatusLightState.On, "POWR");
@@ -98,14 +96,14 @@ namespace Content.Server.Atmos.Monitor.Components
var syncLight = new StatusLightData(Color.Orange, StatusLightState.On, "NET");
if (AtmosMonitorComponent != null)
if (!AtmosMonitorComponent.NetEnabled)
if (_entMan.TryGetComponent<AtmosMonitorComponent>(Owner, out var atmosMonitorComponent))
if (!atmosMonitorComponent.NetEnabled)
syncLight = new StatusLightData(Color.Orange, StatusLightState.Off, "NET");
else if (AtmosMonitorComponent.HighestAlarmInNetwork == AtmosMonitorAlarmType.Danger)
else if (atmosMonitorComponent.HighestAlarmInNetwork == AtmosMonitorAlarmType.Danger)
syncLight = new StatusLightData(Color.Orange, StatusLightState.BlinkingFast, "NET");
WiresComponent.SetStatus(FireAlarmWireStatus.Power, powerLight);
WiresComponent.SetStatus(FireAlarmWireStatus.Alarm, syncLight);
wiresComponent.SetStatus(FireAlarmWireStatus.Power, powerLight);
wiresComponent.SetStatus(FireAlarmWireStatus.Alarm, syncLight);
}
public void WiresUpdate(WiresUpdateEventArgs args)
@@ -127,8 +125,8 @@ namespace Content.Server.Atmos.Monitor.Components
_powerPulsedCancel.Token);
break;
case Wires.Alarm:
if (AtmosMonitorComponent != null)
_atmosMonitorSystem.Alert(Owner, AtmosMonitorAlarmType.Danger);
if (_entMan.TryGetComponent<AtmosMonitorComponent>(Owner, out var atmosMonitorComponent))
_atmosMonitorSystem.Alert(Owner, AtmosMonitorAlarmType.Danger, monitor: atmosMonitorComponent);
break;
}
@@ -142,8 +140,8 @@ namespace Content.Server.Atmos.Monitor.Components
PowerCut = false;
break;
case Wires.Alarm:
if (AtmosMonitorComponent != null)
AtmosMonitorComponent.NetEnabled = true;
if (_entMan.TryGetComponent<AtmosMonitorComponent>(Owner, out var atmosMonitorComponent))
atmosMonitorComponent.NetEnabled = true;
break;
}
@@ -155,8 +153,8 @@ namespace Content.Server.Atmos.Monitor.Components
PowerCut = true;
break;
case Wires.Alarm:
if (AtmosMonitorComponent != null)
AtmosMonitorComponent.NetEnabled = false;
if (_entMan.TryGetComponent<AtmosMonitorComponent>(Owner, out var atmosMonitorComponent))
atmosMonitorComponent.NetEnabled = false;
break;
}

View File

@@ -392,7 +392,7 @@ namespace Content.Server.Atmos.Monitor.Systems
// _airAlarmDataSystem.UpdateDeviceData(uid, args.SenderAddress, data);
//
_uiSystem.TrySendUiMessage(uid, SharedAirAlarmInterfaceKey.Key, new AirAlarmUpdateDeviceDataMessage(args.SenderAddress, data));
if (controller.WiresComponent != null) controller.UpdateWires();
if (HasComp<WiresComponent>(uid)) controller.UpdateWires();
if (!controller.DeviceData.TryAdd(args.SenderAddress, data))
controller.DeviceData[args.SenderAddress] = data;

View File

@@ -98,10 +98,10 @@ namespace Content.Server.Atmos.Monitor.Systems
private void OnAtmosMonitorStartup(EntityUid uid, AtmosMonitorComponent component, ComponentStartup args)
{
if (component.PowerRecvComponent == null
&& component.AtmosDeviceComponent != null)
if (!HasComp<ApcPowerReceiverComponent>(uid)
&& TryComp<AtmosDeviceComponent>(uid, out var atmosDeviceComponent))
{
_atmosDeviceSystem.LeaveAtmosphere(component.AtmosDeviceComponent);
_atmosDeviceSystem.LeaveAtmosphere(atmosDeviceComponent);
return;
}
@@ -204,28 +204,29 @@ namespace Content.Server.Atmos.Monitor.Systems
private void OnPowerChangedEvent(EntityUid uid, AtmosMonitorComponent component, PowerChangedEvent args)
{
if (!args.Powered)
if (TryComp<AtmosDeviceComponent>(uid, out var atmosDeviceComponent))
{
if (component.AtmosDeviceComponent != null
&& component.AtmosDeviceComponent.JoinedGrid != null)
if (!args.Powered)
{
_atmosDeviceSystem.LeaveAtmosphere(component.AtmosDeviceComponent);
component.TileGas = null;
}
if (atmosDeviceComponent.JoinedGrid != null)
{
_atmosDeviceSystem.LeaveAtmosphere(atmosDeviceComponent);
component.TileGas = null;
}
// clear memory when power cycled
component.LastAlarmState = AtmosMonitorAlarmType.Normal;
component.NetworkAlarmStates.Clear();
}
else if (args.Powered)
{
if (component.AtmosDeviceComponent != null
&& component.AtmosDeviceComponent.JoinedGrid == null)
// clear memory when power cycled
component.LastAlarmState = AtmosMonitorAlarmType.Normal;
component.NetworkAlarmStates.Clear();
}
else if (args.Powered)
{
_atmosDeviceSystem.JoinAtmosphere(component.AtmosDeviceComponent);
var coords = Transform(component.Owner).Coordinates;
var air = _atmosphereSystem.GetTileMixture(coords);
component.TileGas = air;
if (atmosDeviceComponent.JoinedGrid == null)
{
_atmosDeviceSystem.JoinAtmosphere(atmosDeviceComponent);
var coords = Transform(component.Owner).Coordinates;
var air = _atmosphereSystem.GetTileMixture(coords);
component.TileGas = air;
}
}
}
@@ -238,8 +239,8 @@ namespace Content.Server.Atmos.Monitor.Systems
private void OnFireEvent(EntityUid uid, AtmosMonitorComponent component, TileFireEvent args)
{
if (component.PowerRecvComponent == null
|| !component.PowerRecvComponent.Powered)
if (!TryComp<ApcPowerReceiverComponent>(uid, out var powerReceiverComponent)
|| !powerReceiverComponent.Powered)
return;
// if we're monitoring for atmos fire, then we make it similar to a smoke detector
@@ -261,15 +262,15 @@ namespace Content.Server.Atmos.Monitor.Systems
private void OnAtmosUpdate(EntityUid uid, AtmosMonitorComponent component, AtmosDeviceUpdateEvent args)
{
if (component.PowerRecvComponent == null
|| !component.PowerRecvComponent.Powered)
if (!TryComp<ApcPowerReceiverComponent>(uid, out var powerReceiverComponent)
|| !powerReceiverComponent.Powered)
return;
// can't hurt
// (in case something is making AtmosDeviceUpdateEvents
// outside the typical device loop)
if (component.AtmosDeviceComponent == null
|| component.AtmosDeviceComponent.JoinedGrid == null)
if (!TryComp<AtmosDeviceComponent>(uid, out var atmosDeviceComponent)
|| atmosDeviceComponent.JoinedGrid == null)
return;
// if we're not monitoring atmos, don't bother

View File

@@ -46,7 +46,6 @@ namespace Content.Server.Botany.Components
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IEntityManager _entMan = default!;
[ComponentDependency] private readonly AppearanceComponent? _appearanceComponent = default!;
public override string Name => "PlantHolder";
@@ -583,50 +582,50 @@ namespace Content.Server.Botany.Components
{
_updateSpriteAfterUpdate = false;
if (_appearanceComponent == null)
if (!_entMan.TryGetComponent<AppearanceComponent>(Owner, out var appearanceComponent))
return;
if (Seed != null)
{
if (DrawWarnings)
_appearanceComponent.SetData(PlantHolderVisuals.HealthLight, Health <= (Seed.Endurance / 2f));
appearanceComponent.SetData(PlantHolderVisuals.HealthLight, Health <= (Seed.Endurance / 2f));
if (Dead)
{
_appearanceComponent.SetData(PlantHolderVisuals.Plant,
appearanceComponent.SetData(PlantHolderVisuals.Plant,
new SpriteSpecifier.Rsi(Seed.PlantRsi, "dead"));
}
else if (Harvest)
{
_appearanceComponent.SetData(PlantHolderVisuals.Plant,
appearanceComponent.SetData(PlantHolderVisuals.Plant,
new SpriteSpecifier.Rsi(Seed.PlantRsi, "harvest"));
}
else if (Age < Seed.Maturation)
{
var growthStage = Math.Max(1, (int) ((Age * Seed.GrowthStages) / Seed.Maturation));
_appearanceComponent.SetData(PlantHolderVisuals.Plant,
appearanceComponent.SetData(PlantHolderVisuals.Plant,
new SpriteSpecifier.Rsi(Seed.PlantRsi, $"stage-{growthStage}"));
_lastProduce = Age;
}
else
{
_appearanceComponent.SetData(PlantHolderVisuals.Plant,
appearanceComponent.SetData(PlantHolderVisuals.Plant,
new SpriteSpecifier.Rsi(Seed.PlantRsi, $"stage-{Seed.GrowthStages}"));
}
}
else
{
_appearanceComponent.SetData(PlantHolderVisuals.Plant, SpriteSpecifier.Invalid);
_appearanceComponent.SetData(PlantHolderVisuals.HealthLight, false);
appearanceComponent.SetData(PlantHolderVisuals.Plant, SpriteSpecifier.Invalid);
appearanceComponent.SetData(PlantHolderVisuals.HealthLight, false);
}
if (!DrawWarnings) return;
_appearanceComponent.SetData(PlantHolderVisuals.WaterLight, WaterLevel <= 10);
_appearanceComponent.SetData(PlantHolderVisuals.NutritionLight, NutritionLevel <= 2);
_appearanceComponent.SetData(PlantHolderVisuals.AlertLight,
appearanceComponent.SetData(PlantHolderVisuals.WaterLight, WaterLevel <= 10);
appearanceComponent.SetData(PlantHolderVisuals.NutritionLight, NutritionLevel <= 2);
appearanceComponent.SetData(PlantHolderVisuals.AlertLight,
WeedLevel >= 5 || PestLevel >= 5 || Toxins >= 40 || ImproperHeat || ImproperLight || ImproperPressure ||
_missingGas > 0);
_appearanceComponent.SetData(PlantHolderVisuals.HarvestLight, Harvest);
appearanceComponent.SetData(PlantHolderVisuals.HarvestLight, Harvest);
}
public void CheckForDivergence(bool modified)

View File

@@ -12,8 +12,6 @@ namespace Content.Server.Botany.Components
[RegisterComponent]
public class SeedExtractorComponent : Component, IInteractUsing
{
[ComponentDependency] private readonly ApcPowerReceiverComponent? _powerReceiver = default!;
[Dependency] private readonly IEntityManager _entMan = default!;
[Dependency] private readonly IRobustRandom _random = default!;
@@ -25,7 +23,7 @@ namespace Content.Server.Botany.Components
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
{
if (!_powerReceiver?.Powered ?? false)
if (!_entMan.TryGetComponent<ApcPowerReceiverComponent>(Owner, out var powerReceiverComponent) || !powerReceiverComponent.Powered)
return false;
if (_entMan.TryGetComponent(eventArgs.Using, out ProduceComponent? produce) && produce.Seed != null)

View File

@@ -11,6 +11,7 @@ using Content.Shared.Popups;
using Content.Shared.Pulling.Components;
using Content.Shared.Standing;
using Content.Shared.Stunnable;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
@@ -34,9 +35,6 @@ namespace Content.Server.Buckle.Components
[Dependency] private readonly IEntityManager _entMan = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[ComponentDependency] public readonly AppearanceComponent? Appearance = null;
[ComponentDependency] private readonly MobStateComponent? _mobState = null;
[DataField("size")]
private int _size = 100;
@@ -234,7 +232,8 @@ namespace Content.Server.Buckle.Components
return false;
}
Appearance?.SetData(BuckleVisuals.Buckled, true);
if(_entMan.TryGetComponent<AppearanceComponent>(Owner, out var appearance))
appearance.SetData(BuckleVisuals.Buckled, true);
ReAttach(strap);
@@ -324,10 +323,11 @@ namespace Content.Server.Buckle.Components
xform.Coordinates = oldBuckledXform.Coordinates.Offset(oldBuckledTo.UnbuckleOffset);
}
Appearance?.SetData(BuckleVisuals.Buckled, false);
if(_entMan.TryGetComponent<AppearanceComponent>(Owner, out var appearance))
appearance.SetData(BuckleVisuals.Buckled, false);
if (_entMan.HasComponent<KnockedDownComponent>(Owner)
|| (_mobState?.IsIncapacitated() ?? false))
| _entMan.TryGetComponent<MobStateComponent>(Owner, out var mobState) && mobState.IsIncapacitated())
{
EntitySystem.Get<StandingStateSystem>().Down(Owner);
}
@@ -336,7 +336,7 @@ namespace Content.Server.Buckle.Components
EntitySystem.Get<StandingStateSystem>().Stand(Owner);
}
_mobState?.CurrentState?.EnterState(Owner, _entMan);
mobState?.CurrentState?.EnterState(Owner, _entMan);
UpdateBuckleStatus();
@@ -397,9 +397,9 @@ namespace Content.Server.Buckle.Components
if (BuckledTo != null &&
_entMan.GetComponent<TransformComponent>(BuckledTo.Owner).LocalRotation.GetCardinalDir() == Direction.North &&
BuckledTo.SpriteComponent != null)
_entMan.TryGetComponent<SpriteComponent>(BuckledTo.Owner, out var spriteComponent))
{
drawDepth = BuckledTo.SpriteComponent.DrawDepth - 1;
drawDepth = spriteComponent.DrawDepth - 1;
}
return new BuckleComponentState(Buckled, drawDepth, LastEntityBuckledTo, DontCollide);

View File

@@ -20,7 +20,7 @@ namespace Content.Server.Buckle.Components
[ComponentReference(typeof(SharedStrapComponent))]
public class StrapComponent : SharedStrapComponent, IInteractHand, ISerializationHooks, IDestroyAct
{
[ComponentDependency] public readonly SpriteComponent? SpriteComponent = null;
[Dependency] private readonly IEntityManager _entityManager = default!;
private readonly HashSet<EntityUid> _buckledEntities = new();
@@ -153,7 +153,8 @@ namespace Content.Server.Buckle.Components
_occupiedSize += buckle.Size;
buckle.Appearance?.SetData(StrapVisuals.RotationAngle, _rotation);
if(_entityManager.TryGetComponent<AppearanceComponent>(buckle.Owner, out var appearanceComponent))
appearanceComponent.SetData(StrapVisuals.RotationAngle, _rotation);
// Update the visuals of the strap object
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<AppearanceComponent>(Owner, out var appearance))

View File

@@ -14,6 +14,7 @@ namespace Content.Server.Climbing.Components
public class ClimbingComponent : SharedClimbingComponent
{
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
public override bool IsClimbing
{
@@ -73,7 +74,7 @@ namespace Content.Server.Climbing.Components
/// </summary>
public void TryMoveTo(Vector2 from, Vector2 to)
{
if (Body == null) return;
if (!_entityManager.TryGetComponent<PhysicsComponent>(Owner, out var physicsComponent)) return;
var velocity = (to - from).Length;
@@ -82,7 +83,7 @@ namespace Content.Server.Climbing.Components
// Since there are bodies with different masses:
// mass * 5 seems enough to move entity
// instead of launching cats like rockets against the walls with constant impulse value.
Body.ApplyLinearImpulse((to - from).Normalized * velocity * Body.Mass * 5);
physicsComponent.ApplyLinearImpulse((to - from).Normalized * velocity * physicsComponent.Mass * 5);
OwnerIsTransitioning = true;
EntitySystem.Get<ClimbSystem>().UnsetTransitionBoolAfterBufferTime(Owner, this);

View File

@@ -20,9 +20,7 @@ namespace Content.Server.Clothing.Components
[ComponentReference(typeof(SharedMagbootsComponent))]
public sealed class MagbootsComponent : SharedMagbootsComponent, IActivate
{
[ComponentDependency] private SharedItemComponent? _item = null;
[ComponentDependency] private ItemActionsComponent? _itemActions = null;
[ComponentDependency] private SpriteComponent? _sprite = null;
[Dependency] private readonly IEntityManager _entMan = default!;
private bool _on;
@@ -40,10 +38,12 @@ namespace Content.Server.Clothing.Components
EntitySystem.Get<MagbootsSystem>().UpdateMagbootEffects(container.Owner, Owner, true, this);
}
_itemActions?.Toggle(ItemActionType.ToggleMagboots, On);
if (_item != null)
_item.EquippedPrefix = On ? "on" : null;
_sprite?.LayerSetState(0, On ? "icon-on" : "icon");
if(_entMan.TryGetComponent<ItemActionsComponent>(Owner, out var itemActions))
itemActions.Toggle(ItemActionType.ToggleMagboots, On);
if (_entMan.TryGetComponent<SharedItemComponent>(Owner, out var item))
item.EquippedPrefix = On ? "on" : null;
if(_entMan.TryGetComponent<SpriteComponent>(Owner, out var sprite))
sprite.LayerSetState(0, On ? "icon-on" : "icon");
OnChanged();
Dirty();
}

View File

@@ -23,20 +23,10 @@ namespace Content.Server.Doors.Components
[RegisterComponent]
public class AirlockComponent : Component, IWires
{
[Dependency] private readonly IEntityManager _entityManager = default!;
public override string Name => "Airlock";
[ComponentDependency]
public readonly ServerDoorComponent? DoorComponent = null;
[ComponentDependency]
public readonly AppearanceComponent? AppearanceComponent = null;
[ComponentDependency]
public readonly ApcPowerReceiverComponent? ReceiverComponent = null;
[ComponentDependency]
public readonly WiresComponent? WiresComponent = null;
/// <summary>
/// Sound to play when the bolts on the airlock go up.
/// </summary>
@@ -98,7 +88,7 @@ namespace Content.Server.Doors.Components
private bool BoltLightsVisible
{
get => _boltLightsWirePulsed && BoltsDown && IsPowered()
&& DoorComponent != null && DoorComponent.State == SharedDoorComponent.DoorState.Closed;
&& _entityManager.TryGetComponent<ServerDoorComponent>(Owner, out var doorComponent) && doorComponent.State == SharedDoorComponent.DoorState.Closed;
set
{
_boltLightsWirePulsed = value;
@@ -122,9 +112,10 @@ namespace Content.Server.Doors.Components
{
base.Initialize();
if (ReceiverComponent != null && AppearanceComponent != null)
if (_entityManager.TryGetComponent<ApcPowerReceiverComponent>(Owner, out var receiverComponent) &&
_entityManager.TryGetComponent<AppearanceComponent>(Owner, out var appearanceComponent))
{
AppearanceComponent.SetData(DoorVisuals.Powered, ReceiverComponent.Powered);
appearanceComponent.SetData(DoorVisuals.Powered, receiverComponent.Powered);
}
}
@@ -140,23 +131,23 @@ namespace Content.Server.Doors.Components
public bool IsPowered()
{
return ReceiverComponent == null || ReceiverComponent.Powered;
return _entityManager.TryGetComponent<ApcPowerReceiverComponent>(Owner, out var receiverComponent) && receiverComponent.Powered;
}
public void UpdateBoltLightStatus()
{
if (AppearanceComponent != null)
if (_entityManager.TryGetComponent<AppearanceComponent>(Owner, out var appearanceComponent))
{
AppearanceComponent.SetData(DoorVisuals.BoltLights, BoltLightsVisible);
appearanceComponent.SetData(DoorVisuals.BoltLights, BoltLightsVisible);
}
}
public void UpdateWiresStatus()
{
if (WiresComponent == null) return;
if (_entityManager.TryGetComponent<WiresComponent>(Owner, out var wiresComponent)) return;
var mainPowerCut = WiresComponent.IsWireCut(Wires.MainPower);
var backupPowerCut = WiresComponent.IsWireCut(Wires.BackupPower);
var mainPowerCut = wiresComponent.IsWireCut(Wires.MainPower);
var backupPowerCut = wiresComponent.IsWireCut(Wires.BackupPower);
var statusLightState = PowerWiresPulsed ? StatusLightState.BlinkingFast : StatusLightState.On;
StatusLightData powerLight;
if (mainPowerCut && backupPowerCut)
@@ -190,42 +181,42 @@ namespace Content.Server.Doors.Components
new StatusLightData(Color.Red, Safety ? StatusLightState.On : StatusLightState.Off, "SAFETY");
WiresComponent.SetStatus(AirlockWireStatus.PowerIndicator, powerLight);
WiresComponent.SetStatus(AirlockWireStatus.BoltIndicator, boltStatus);
WiresComponent.SetStatus(AirlockWireStatus.BoltLightIndicator, boltLightsStatus);
WiresComponent.SetStatus(AirlockWireStatus.AIControlIndicator, new StatusLightData(Color.Purple, StatusLightState.BlinkingSlow, "AI CTRL"));
WiresComponent.SetStatus(AirlockWireStatus.TimingIndicator, timingStatus);
WiresComponent.SetStatus(AirlockWireStatus.SafetyIndicator, safetyStatus);
wiresComponent.SetStatus(AirlockWireStatus.PowerIndicator, powerLight);
wiresComponent.SetStatus(AirlockWireStatus.BoltIndicator, boltStatus);
wiresComponent.SetStatus(AirlockWireStatus.BoltLightIndicator, boltLightsStatus);
wiresComponent.SetStatus(AirlockWireStatus.AIControlIndicator, new StatusLightData(Color.Purple, StatusLightState.BlinkingSlow, "AI CTRL"));
wiresComponent.SetStatus(AirlockWireStatus.TimingIndicator, timingStatus);
wiresComponent.SetStatus(AirlockWireStatus.SafetyIndicator, safetyStatus);
}
private void UpdatePowerCutStatus()
{
if (ReceiverComponent == null)
if (!_entityManager.TryGetComponent<ApcPowerReceiverComponent>(Owner, out var receiverComponent))
{
return;
}
if (PowerWiresPulsed)
{
ReceiverComponent.PowerDisabled = true;
receiverComponent.PowerDisabled = true;
return;
}
if (WiresComponent == null)
if (!_entityManager.TryGetComponent<WiresComponent>(Owner, out var wiresComponent))
{
return;
}
ReceiverComponent.PowerDisabled =
WiresComponent.IsWireCut(Wires.MainPower) &&
WiresComponent.IsWireCut(Wires.BackupPower);
receiverComponent.PowerDisabled =
wiresComponent.IsWireCut(Wires.MainPower) &&
wiresComponent.IsWireCut(Wires.BackupPower);
}
private void PowerDeviceOnOnPowerStateChanged(PowerChangedMessage e)
{
if (AppearanceComponent != null)
if (_entityManager.TryGetComponent<AppearanceComponent>(Owner, out var appearanceComponent))
{
AppearanceComponent.SetData(DoorVisuals.Powered, e.Powered);
appearanceComponent.SetData(DoorVisuals.Powered, e.Powered);
}
// BoltLights also got out
@@ -290,7 +281,7 @@ namespace Content.Server.Doors.Components
public void WiresUpdate(WiresUpdateEventArgs args)
{
if (DoorComponent == null)
if (!_entityManager.TryGetComponent<ServerDoorComponent>(Owner, out var doorComponent))
{
return;
}
@@ -328,7 +319,7 @@ namespace Content.Server.Doors.Components
break;
case Wires.Timing:
AutoCloseDelayModifier = 0.5f;
DoorComponent.RefreshAutoClose();
doorComponent.RefreshAutoClose();
break;
case Wires.Safety:
Safety = !Safety;
@@ -351,7 +342,7 @@ namespace Content.Server.Doors.Components
break;
case Wires.Timing:
AutoClose = true;
DoorComponent.RefreshAutoClose();
doorComponent.RefreshAutoClose();
break;
case Wires.Safety:
Safety = true;
@@ -371,7 +362,7 @@ namespace Content.Server.Doors.Components
break;
case Wires.Timing:
AutoClose = false;
DoorComponent.RefreshAutoClose();
doorComponent.RefreshAutoClose();
break;
case Wires.Safety:
Safety = false;

View File

@@ -18,9 +18,6 @@ namespace Content.Server.Doors.Components
public override string Name => "Firelock";
[ComponentDependency]
public readonly ServerDoorComponent? DoorComponent = null;
/// <summary>
/// Pry time modifier to be used when the firelock is currently closed due to fire or pressure.
/// </summary>
@@ -30,9 +27,9 @@ namespace Content.Server.Doors.Components
public bool EmergencyPressureStop()
{
if (DoorComponent != null && DoorComponent.State == SharedDoorComponent.DoorState.Open && DoorComponent.CanCloseGeneric())
if (_entMan.TryGetComponent<ServerDoorComponent>(Owner, out var doorComp) && doorComp.State == SharedDoorComponent.DoorState.Open && doorComp.CanCloseGeneric())
{
DoorComponent.Close();
doorComp.Close();
if (_entMan.TryGetComponent(Owner, out AirtightComponent? airtight))
{
EntitySystem.Get<AirtightSystem>().SetAirblocked(airtight, true);

View File

@@ -24,6 +24,7 @@ using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager.Attributes;
@@ -557,19 +558,19 @@ namespace Content.Server.Doors.Components
/// <returns>True if we crushed somebody, false if we did not.</returns>
private bool TryCrush()
{
if (PhysicsComponent == null)
if (!_entMan.TryGetComponent(Owner, out PhysicsComponent physicsComponent) || physicsComponent is not IPhysBody body)
{
return false;
}
var collidingentities = PhysicsComponent.GetCollidingEntities(Vector2.Zero, false);
var collidingentities = body.GetCollidingEntities(Vector2.Zero, false);
if (!collidingentities.Any())
{
return false;
}
var doorAABB = PhysicsComponent.GetWorldAABB();
var doorAABB = body.GetWorldAABB();
var hitsomebody = false;
// Crush

View File

@@ -1,5 +1,6 @@
using Content.Server.Doors.Components;
using Content.Server.Power.Components;
using Content.Server.WireHacking;
using Content.Shared.Doors;
using Content.Shared.Popups;
using Robust.Server.GameObjects;
@@ -29,9 +30,9 @@ namespace Content.Server.Doors.Systems
private void OnPowerChanged(EntityUid uid, AirlockComponent component, PowerChangedEvent args)
{
if (component.AppearanceComponent != null)
if (TryComp<AppearanceComponent>(uid, out var appearanceComponent))
{
component.AppearanceComponent.SetData(DoorVisuals.Powered, args.Powered);
appearanceComponent.SetData(DoorVisuals.Powered, args.Powered);
}
// BoltLights also got out
@@ -41,9 +42,9 @@ namespace Content.Server.Doors.Systems
private void OnStateChanged(EntityUid uid, AirlockComponent component, DoorStateChangedEvent args)
{
// Only show the maintenance panel if the airlock is closed
if (component.WiresComponent != null)
if (TryComp<WiresComponent>(uid, out var wiresComponent))
{
component.WiresComponent.IsPanelVisible =
wiresComponent.IsPanelVisible =
component.OpenPanelVisible
|| args.State != SharedDoorComponent.DoorState.Open;
}
@@ -87,10 +88,10 @@ namespace Content.Server.Doors.Systems
private void OnDoorClickShouldActivate(EntityUid uid, AirlockComponent component, DoorClickShouldActivateEvent args)
{
if (component.WiresComponent != null && component.WiresComponent.IsPanelOpen &&
if (TryComp<WiresComponent>(uid, out var wiresComponent) && wiresComponent.IsPanelOpen &&
EntityManager.TryGetComponent(args.Args.User, out ActorComponent? actor))
{
component.WiresComponent.OpenInterface(actor.PlayerSession);
wiresComponent.OpenInterface(actor.PlayerSession);
args.Handled = true;
}
}

View File

@@ -50,7 +50,7 @@ namespace Content.Server.Doors.Systems
private void OnBeforeDoorPry(EntityUid uid, FirelockComponent component, BeforeDoorPryEvent args)
{
if (component.DoorComponent == null || component.DoorComponent.State != SharedDoorComponent.DoorState.Closed)
if (!TryComp<ServerDoorComponent>(uid, out var doorComponent) || doorComponent.State != SharedDoorComponent.DoorState.Closed)
{
return;
}
@@ -81,12 +81,12 @@ namespace Content.Server.Doors.Systems
private void OnAtmosAlarm(EntityUid uid, FirelockComponent component, AtmosMonitorAlarmEvent args)
{
if (component.DoorComponent == null) return;
if (!TryComp<ServerDoorComponent>(uid, out var doorComponent)) return;
if (args.HighestNetworkType == AtmosMonitorAlarmType.Normal)
{
if (component.DoorComponent.State == SharedDoorComponent.DoorState.Closed)
component.DoorComponent.Open();
if (doorComponent.State == SharedDoorComponent.DoorState.Closed)
doorComponent.Open();
}
else if (args.HighestNetworkType == AtmosMonitorAlarmType.Danger)
{

View File

@@ -32,11 +32,5 @@ namespace Content.Server.Light.Components
/// Sound played when you ignite the matchstick.
/// </summary>
[DataField("igniteSound", required: true)] public SoundSpecifier IgniteSound = default!;
/// <summary>
/// Point light component. Gives matches a glow in dark effect.
/// </summary>
[ComponentDependency]
public readonly PointLightComponent? PointLightComponent = default!;
}
}

View File

@@ -6,6 +6,7 @@ using Content.Shared.Interaction;
using Content.Shared.Item;
using Content.Shared.Smoking;
using Content.Shared.Temperature;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
@@ -85,9 +86,9 @@ namespace Content.Server.Light.EntitySystems
{
component.CurrentState = value;
if (component.PointLightComponent != null)
if (TryComp<PointLightComponent>(component.Owner, out var pointLightComponent))
{
component.PointLightComponent.Enabled = component.CurrentState == SmokableState.Lit;
pointLightComponent.Enabled = component.CurrentState == SmokableState.Lit;
}
if (EntityManager.TryGetComponent(component.Owner, out SharedItemComponent? item))

View File

@@ -50,16 +50,16 @@ namespace Content.Server.Morgue.Components
void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
{
if (Appearance == null) return;
if (_entities.TryGetComponent<AppearanceComponent>(Owner, out var appearance)) return;
if (inDetailsRange)
{
if (Appearance.TryGetData(CrematoriumVisuals.Burning, out bool isBurning) && isBurning)
if (appearance.TryGetData(CrematoriumVisuals.Burning, out bool isBurning) && isBurning)
{
message.AddMarkup(Loc.GetString("crematorium-entity-storage-component-on-examine-details-is-burning", ("owner", Owner)) + "\n");
}
if (Appearance.TryGetData(MorgueVisuals.HasContents, out bool hasContents) && hasContents)
if (appearance.TryGetData(MorgueVisuals.HasContents, out bool hasContents) && hasContents)
{
message.AddMarkup(Loc.GetString("crematorium-entity-storage-component-on-examine-details-has-contents"));
}
@@ -96,7 +96,8 @@ namespace Content.Server.Morgue.Components
if (Open)
CloseStorage();
Appearance?.SetData(CrematoriumVisuals.Burning, true);
if(_entities.TryGetComponent(Owner, out AppearanceComponent appearanceComponent))
appearanceComponent.SetData(CrematoriumVisuals.Burning, true);
Cooking = true;
SoundSystem.Play(Filter.Pvs(Owner), _crematingSound.GetSound(), Owner);
@@ -108,8 +109,8 @@ namespace Content.Server.Morgue.Components
{
if (_entities.Deleted(Owner))
return;
Appearance?.SetData(CrematoriumVisuals.Burning, false);
if(_entities.TryGetComponent(Owner, out appearanceComponent))
appearanceComponent.SetData(CrematoriumVisuals.Burning, false);
Cooking = false;
if (Contents.ContainedEntities.Count > 0)

View File

@@ -56,13 +56,11 @@ namespace Content.Server.Morgue.Components
[DataField("occupantHasSoulAlarmSound")]
private SoundSpecifier _occupantHasSoulAlarmSound = new SoundPathSpecifier("/Audio/Weapons/Guns/EmptyAlarm/smg_empty_alarm.ogg");
[ViewVariables]
[ComponentDependency] protected readonly AppearanceComponent? Appearance = null;
protected override void Initialize()
{
base.Initialize();
Appearance?.SetData(MorgueVisuals.Open, false);
if(_entMan.TryGetComponent<AppearanceComponent>(Owner, out var appearance))
appearance.SetData(MorgueVisuals.Open, false);
TrayContainer = Owner.EnsureContainer<ContainerSlot>("morgue_tray", out _);
}
@@ -97,10 +95,13 @@ namespace Content.Server.Morgue.Components
protected override void OpenStorage()
{
Appearance?.SetData(MorgueVisuals.Open, true);
Appearance?.SetData(MorgueVisuals.HasContents, false);
Appearance?.SetData(MorgueVisuals.HasMob, false);
Appearance?.SetData(MorgueVisuals.HasSoul, false);
if (_entMan.TryGetComponent<AppearanceComponent>(Owner, out var appearance))
{
appearance.SetData(MorgueVisuals.Open, true);
appearance.SetData(MorgueVisuals.HasContents, false);
appearance.SetData(MorgueVisuals.HasMob, false);
appearance.SetData(MorgueVisuals.HasSoul, false);
}
if (_tray == null)
{
@@ -131,16 +132,21 @@ namespace Content.Server.Morgue.Components
if (!hasSoul && _entMan.TryGetComponent<ActorComponent?>(entity, out var actor) && actor.PlayerSession != null)
hasSoul = true;
}
Appearance?.SetData(MorgueVisuals.HasContents, count > 0);
Appearance?.SetData(MorgueVisuals.HasMob, hasMob);
Appearance?.SetData(MorgueVisuals.HasSoul, hasSoul);
if (_entMan.TryGetComponent<AppearanceComponent>(Owner, out var appearance))
{
appearance.SetData(MorgueVisuals.HasContents, count > 0);
appearance.SetData(MorgueVisuals.HasMob, hasMob);
appearance.SetData(MorgueVisuals.HasSoul, hasSoul);
}
}
protected override void CloseStorage()
{
base.CloseStorage();
Appearance?.SetData(MorgueVisuals.Open, false);
if (_entMan.TryGetComponent<AppearanceComponent>(Owner, out var appearance))
appearance.SetData(MorgueVisuals.Open, false);
CheckContents();
if (_tray != null)
@@ -168,7 +174,8 @@ namespace Content.Server.Morgue.Components
{
CheckContents();
if (DoSoulBeep && Appearance != null && Appearance.TryGetData(MorgueVisuals.HasSoul, out bool hasSoul) && hasSoul)
if (DoSoulBeep && _entMan.TryGetComponent<AppearanceComponent>(Owner, out var appearance) &&
appearance.TryGetData(MorgueVisuals.HasSoul, out bool hasSoul) && hasSoul)
{
SoundSystem.Play(Filter.Pvs(Owner), _occupantHasSoulAlarmSound.GetSound(), Owner);
}
@@ -176,19 +183,19 @@ namespace Content.Server.Morgue.Components
void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
{
if (Appearance == null) return;
if (!_entMan.TryGetComponent<AppearanceComponent>(Owner, out var appearance)) return;
if (inDetailsRange)
{
if (Appearance.TryGetData(MorgueVisuals.HasSoul, out bool hasSoul) && hasSoul)
if (appearance.TryGetData(MorgueVisuals.HasSoul, out bool hasSoul) && hasSoul)
{
message.AddMarkup(Loc.GetString("morgue-entity-storage-component-on-examine-details-body-has-soul"));
}
else if (Appearance.TryGetData(MorgueVisuals.HasMob, out bool hasMob) && hasMob)
else if (appearance.TryGetData(MorgueVisuals.HasMob, out bool hasMob) && hasMob)
{
message.AddMarkup(Loc.GetString("morgue-entity-storage-component-on-examine-details-body-has-no-soul"));
}
else if (Appearance.TryGetData(MorgueVisuals.HasContents, out bool hasContents) && hasContents)
else if (appearance.TryGetData(MorgueVisuals.HasContents, out bool hasContents) && hasContents)
{
message.AddMarkup(Loc.GetString("morgue-entity-storage-component-on-examine-details-has-contents"));
}

View File

@@ -59,8 +59,6 @@ namespace Content.Server.Power.Components
public BatteryComponent? Battery => _entMan.TryGetComponent(Owner, out BatteryComponent? batteryComponent) ? batteryComponent : null;
[ComponentDependency] private AccessReaderComponent? _accessReader = null;
protected override void Initialize()
{
base.Initialize();
@@ -92,7 +90,7 @@ namespace Content.Server.Power.Components
return;
var accessSystem = EntitySystem.Get<AccessReaderSystem>();
if (_accessReader == null || accessSystem.IsAllowed(_accessReader, attached))
if (_entMan.TryGetComponent<AccessReaderComponent>(Owner, out var accessReaderComponent) || accessSystem.IsAllowed(accessReaderComponent, attached))
{
MainBreakerEnabled = !MainBreakerEnabled;
_entMan.GetComponent<PowerNetworkBatteryComponent>(Owner).CanDischarge = MainBreakerEnabled;

View File

@@ -1,5 +1,6 @@
using Content.Shared.Examine;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
@@ -13,19 +14,18 @@ namespace Content.Server.Power.Components
{
public override string Name => "ExaminableBattery";
[ViewVariables]
[ComponentDependency] private BatteryComponent? _battery = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
{
if (_battery == null)
if (_entityManager.TryGetComponent<BatteryComponent>(Owner, out var batteryComponent))
return;
if (inDetailsRange)
{
var effectiveMax = _battery.MaxCharge;
var effectiveMax = batteryComponent.MaxCharge;
if (effectiveMax == 0)
effectiveMax = 1;
var chargeFraction = _battery.CurrentCharge / effectiveMax;
var chargeFraction = batteryComponent.CurrentCharge / effectiveMax;
var chargePercentRounded = (int) (chargeFraction * 100);
message.AddMarkup(
Loc.GetString(

View File

@@ -58,9 +58,6 @@ namespace Content.Server.Singularity.Components
}
}
[ComponentDependency] private readonly PhysicsComponent? _collidableComponent = default;
[ComponentDependency] private readonly PointLightComponent? _pointLightComponent = default;
private Tuple<Direction, ContainmentFieldConnection>? _connection1;
private Tuple<Direction, ContainmentFieldConnection>? _connection2;
@@ -69,7 +66,7 @@ namespace Content.Server.Singularity.Components
public void OnAnchoredChanged()
{
if(_collidableComponent?.BodyType != BodyType.Static)
if(_entMan.TryGetComponent<PhysicsComponent>(Owner, out var physicsComponent) && physicsComponent.BodyType != BodyType.Static)
{
_connection1?.Item2.Dispose();
_connection2?.Item2.Dispose();
@@ -91,7 +88,7 @@ namespace Content.Server.Singularity.Components
private bool TryGenerateFieldConnection([NotNullWhen(true)] ref Tuple<Direction, ContainmentFieldConnection>? propertyFieldTuple)
{
if (propertyFieldTuple != null) return false;
if(_collidableComponent?.BodyType != BodyType.Static) return false;
if(_entMan.TryGetComponent<PhysicsComponent>(Owner, out var physicsComponent) && physicsComponent.BodyType != BodyType.Static) return false;
foreach (var direction in new[] {Direction.North, Direction.East, Direction.South, Direction.West})
{
@@ -166,10 +163,10 @@ namespace Content.Server.Singularity.Components
public void UpdateConnectionLights()
{
if (_pointLightComponent != null)
if (_entMan.TryGetComponent<PointLightComponent>(Owner, out var pointLightComponent))
{
bool hasAnyConnection = (_connection1 != null) || (_connection2 != null);
_pointLightComponent.Enabled = hasAnyConnection;
pointLightComponent.Enabled = hasAnyConnection;
}
}

View File

@@ -13,10 +13,6 @@ namespace Content.Server.Singularity.Components
[RegisterComponent]
public class EmitterComponent : Component
{
[ComponentDependency] public readonly AppearanceComponent? Appearance = default;
[ComponentDependency] public readonly AccessReaderComponent? AccessReader = default;
[ComponentDependency] public readonly PowerConsumerComponent? PowerConsumer = default;
public override string Name => "Emitter";
public CancellationTokenSource? TimerCancel;

View File

@@ -16,6 +16,7 @@ namespace Content.Server.Singularity.Components
public class RadiationCollectorComponent : Component, IInteractHand, IRadiationAct
{
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IEntityManager _entMan = default!;
public override string Name => "RadiationCollector";
private bool _enabled;
@@ -32,8 +33,6 @@ namespace Content.Server.Singularity.Components
}
}
[ComponentDependency] private readonly BatteryComponent? _batteryComponent = default!;
bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs)
{
var curTime = _gameTiming.CurTime;
@@ -66,9 +65,9 @@ namespace Content.Server.Singularity.Components
// But the previous logic would also make the radiation collectors never ever stop providing energy.
// And since frameTime was used there, I'm assuming that this is what the intent was.
// This still won't stop things being potentially hilarously unbalanced though.
if (_batteryComponent != null)
if (_entMan.TryGetComponent<BatteryComponent>(Owner, out var batteryComponent))
{
_batteryComponent!.CurrentCharge += frameTime * radiation.RadsPerSecond * 3000f;
batteryComponent.CurrentCharge += frameTime * radiation.RadsPerSecond * 3000f;
}
}

View File

@@ -1,6 +1,7 @@
using System;
using System.Threading;
using Content.Server.Administration.Logs;
using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems;
using Content.Server.Projectiles.Components;
using Content.Server.Singularity.Components;
@@ -94,7 +95,7 @@ namespace Content.Server.Singularity.EntitySystems
public void SwitchOff(EmitterComponent component)
{
component.IsOn = false;
if (component.PowerConsumer != null) component.PowerConsumer.DrawRate = 0;
if (TryComp<PowerConsumerComponent>(component.Owner, out var powerConsumer)) powerConsumer.DrawRate = 0;
PowerOff(component);
UpdateAppearance(component);
}
@@ -102,7 +103,7 @@ namespace Content.Server.Singularity.EntitySystems
public void SwitchOn(EmitterComponent component)
{
component.IsOn = true;
if (component.PowerConsumer != null) component.PowerConsumer.DrawRate = component.PowerUseActive;
if (TryComp<PowerConsumerComponent>(component.Owner, out var powerConsumer)) powerConsumer.DrawRate = component.PowerUseActive;
// Do not directly PowerOn().
// OnReceivedPowerChanged will get fired due to DrawRate change which will turn it on.
UpdateAppearance(component);
@@ -149,7 +150,8 @@ namespace Content.Server.Singularity.EntitySystems
// and thus not firing
DebugTools.Assert(component.IsPowered);
DebugTools.Assert(component.IsOn);
DebugTools.Assert(component.PowerConsumer != null && (component.PowerConsumer.DrawRate <= component.PowerConsumer.ReceivedPower));
DebugTools.Assert(TryComp<PowerConsumerComponent>(component.Owner, out var powerConsumer) &&
powerConsumer.DrawRate <= powerConsumer.ReceivedPower);
Fire(component);
@@ -205,7 +207,7 @@ namespace Content.Server.Singularity.EntitySystems
private void UpdateAppearance(EmitterComponent component)
{
if (component.Appearance == null)
if (!TryComp<AppearanceComponent>(component.Owner, out var appearanceComponent))
{
return;
}
@@ -224,7 +226,7 @@ namespace Content.Server.Singularity.EntitySystems
state = EmitterVisualState.Off;
}
component.Appearance.SetData(EmitterVisuals.VisualState, state);
appearanceComponent.SetData(EmitterVisuals.VisualState, state);
}
}
}

View File

@@ -3,6 +3,7 @@ using Content.Shared.ActionBlocker;
using Content.Shared.Physics;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.IoC;
using Robust.Shared.Physics;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
@@ -12,15 +13,17 @@ namespace Content.Shared.Climbing
[NetworkedComponent()]
public abstract class SharedClimbingComponent : Component
{
[Dependency] private readonly IEntityManager _entMan = default!;
public sealed override string Name => "Climbing";
protected bool IsOnClimbableThisFrame
{
get
{
if (Body == null) return false;
if (!_entMan.TryGetComponent<PhysicsComponent>(Owner, out var physicsComponent)) return false;
foreach (var entity in Body.GetBodiesIntersecting())
foreach (var entity in physicsComponent.GetBodiesIntersecting())
{
if ((entity.CollisionLayer & (int) CollisionGroup.SmallImpassable) != 0) return true;
}
@@ -37,22 +40,20 @@ namespace Content.Shared.Climbing
{
if (_ownerIsTransitioning == value) return;
_ownerIsTransitioning = value;
if (Body == null) return;
if (!_entMan.TryGetComponent<PhysicsComponent>(Owner, out var physicsComponent)) return;
if (value)
{
Body.BodyType = BodyType.Dynamic;
physicsComponent.BodyType = BodyType.Dynamic;
}
else
{
Body.BodyType = BodyType.KinematicController;
physicsComponent.BodyType = BodyType.KinematicController;
}
}
}
private bool _ownerIsTransitioning = false;
[ComponentDependency] protected PhysicsComponent? Body;
protected TimeSpan StartClimbTime = TimeSpan.Zero;
/// <summary>
@@ -78,9 +79,9 @@ namespace Content.Shared.Climbing
private void ToggleSmallPassable(bool value)
{
// Hope the mob has one fixture
if (Body == null || Body.Deleted) return;
if (!_entMan.TryGetComponent<PhysicsComponent>(Owner, out var physicsComponent) || physicsComponent.Deleted) return;
foreach (var fixture in Body.Fixtures)
foreach (var fixture in physicsComponent.Fixtures)
{
if (value)
{

View File

@@ -16,15 +16,11 @@ namespace Content.Shared.Doors
{
public override string Name => "Door";
[ComponentDependency]
protected readonly AppearanceComponent? AppearanceComponent = null;
[ComponentDependency]
protected readonly IPhysBody? PhysicsComponent = null;
[Dependency]
protected readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IEntityManager _entMan = default!;
[ViewVariables]
private DoorState _state = DoorState.Closed;
/// <summary>
@@ -104,7 +100,10 @@ namespace Content.Shared.Doors
protected void SetAppearance(DoorVisualState state)
{
AppearanceComponent?.SetData(DoorVisuals.VisualState, state);
if (_entMan.TryGetComponent<AppearanceComponent>(Owner, out var appearanceComponent))
{
appearanceComponent.SetData(DoorVisuals.VisualState, state);
}
}
/// <summary>
@@ -112,9 +111,9 @@ namespace Content.Shared.Doors
/// </summary>
protected virtual void OnPartialOpen()
{
if (PhysicsComponent != null)
if (_entMan.TryGetComponent<PhysicsComponent>(Owner, out var physicsComponent))
{
PhysicsComponent.CanCollide = false;
physicsComponent.CanCollide = false;
}
// we can't be crushing anyone anymore, since we're opening
CurrentlyCrushing.Clear();
@@ -125,9 +124,9 @@ namespace Content.Shared.Doors
/// </summary>
protected virtual void OnPartialClose()
{
if (PhysicsComponent != null)
if (_entMan.TryGetComponent<PhysicsComponent>(Owner, out var physicsComponent))
{
PhysicsComponent.CanCollide = true;
physicsComponent.CanCollide = true;
}
}

View File

@@ -38,8 +38,7 @@ namespace Content.Shared.Movement.Components
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[ComponentDependency] private readonly MovementSpeedModifierComponent? _movementSpeed = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
public override string Name => "PlayerInputMover";
@@ -53,9 +52,17 @@ namespace Content.Shared.Movement.Components
[ViewVariables]
public Angle LastGridAngle { get; set; } = new(0);
public float CurrentWalkSpeed => _movementSpeed?.CurrentWalkSpeed ?? MovementSpeedModifierComponent.DefaultBaseWalkSpeed;
public float CurrentWalkSpeed =>
_entityManager.TryGetComponent<MovementSpeedModifierComponent>(Owner,
out var movementSpeedModifierComponent)
? movementSpeedModifierComponent.CurrentWalkSpeed
: MovementSpeedModifierComponent.DefaultBaseWalkSpeed;
public float CurrentSprintSpeed => _movementSpeed?.CurrentSprintSpeed ?? MovementSpeedModifierComponent.DefaultBaseSprintSpeed;
public float CurrentSprintSpeed =>
_entityManager.TryGetComponent<MovementSpeedModifierComponent>(Owner,
out var movementSpeedModifierComponent)
? movementSpeedModifierComponent.CurrentSprintSpeed
: MovementSpeedModifierComponent.DefaultBaseSprintSpeed;
public bool Sprinting => !HasFlag(_heldMoveButtons, MoveButtons.Walk);