Merge branch 'master-upstream' into expl_int_analyzer
# Conflicts: # Content.Server/GameObjects/Components/Body/Part/BodyPartComponent.cs # Content.Server/GameObjects/Components/Botany/PlantHolderComponent.cs # Content.Server/GameObjects/Components/Chemistry/PillComponent.cs # Content.Server/GameObjects/Components/Interactable/TilePryingComponent.cs # Content.Server/GameObjects/Components/Items/FloorTileItemComponent.cs # Content.Server/GameObjects/Components/Items/RCD/RCDAmmoComponent.cs # Content.Server/GameObjects/Components/Items/RCD/RCDComponent.cs # Content.Server/GameObjects/Components/Medical/HealingComponent.cs # Content.Server/GameObjects/Components/Power/WirePlacerComponent.cs # Content.Shared/Chemistry/Solution.cs
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
#nullable enable
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Power.AME
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#nullable enable
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
using Content.Server.GameObjects.Components.Interactable;
|
||||
@@ -28,14 +29,13 @@ namespace Content.Server.GameObjects.Components.Power.AME
|
||||
|
||||
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs args)
|
||||
{
|
||||
if (!args.User.TryGetComponent(out IHandsComponent hands))
|
||||
if (!args.User.TryGetComponent<IHandsComponent>(out var hands))
|
||||
{
|
||||
Owner.PopupMessage(args.User, Loc.GetString("You have no hands."));
|
||||
return true;
|
||||
}
|
||||
|
||||
var activeHandEntity = hands.GetActiveHand.Owner;
|
||||
if (activeHandEntity.TryGetComponent<ToolComponent>(out var multitool) && multitool.Qualities == ToolQuality.Multitool)
|
||||
if (args.Using.TryGetComponent<ToolComponent>(out var multitool) && multitool.Qualities == ToolQuality.Multitool)
|
||||
{
|
||||
|
||||
var mapGrid = _mapManager.GetGrid(args.ClickLocation.GetGridId(_serverEntityManager));
|
||||
|
||||
@@ -179,6 +179,10 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents
|
||||
return ApcExternalPowerState.None;
|
||||
}
|
||||
var consumer = batteryStorage.Consumer;
|
||||
|
||||
if (consumer == null)
|
||||
return ApcExternalPowerState.None;
|
||||
|
||||
if (consumer.ReceivedPower == 0 && consumer.DrawRate != 0)
|
||||
{
|
||||
return ApcExternalPowerState.None;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
|
||||
#nullable enable
|
||||
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Power.ApcNetComponents
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
@@ -20,7 +20,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents
|
||||
|
||||
void UpdateReceiverLoad(int oldLoad, int newLoad);
|
||||
|
||||
public IEntity ProviderOwner { get; }
|
||||
public IEntity? ProviderOwner { get; }
|
||||
|
||||
public bool HasApcPower { get; }
|
||||
}
|
||||
@@ -172,7 +172,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents
|
||||
public void AddReceiver(PowerReceiverComponent receiver) { }
|
||||
public void RemoveReceiver(PowerReceiverComponent receiver) { }
|
||||
public void UpdateReceiverLoad(int oldLoad, int newLoad) { }
|
||||
public IEntity ProviderOwner => default;
|
||||
public IEntity? ProviderOwner => default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
@@ -63,7 +64,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
|
||||
/// </summary>
|
||||
public void UpdateState()
|
||||
{
|
||||
if (!Owner.TryGetComponent(out PowerReceiverComponent receiver))
|
||||
if (!Owner.TryGetComponent(out PowerReceiverComponent? receiver))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -83,7 +84,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
|
||||
|
||||
public void OnUpdate(float frameTime)
|
||||
{
|
||||
if (Owner.Deleted || !Owner.TryGetComponent(out BatteryComponent battery))
|
||||
if (Owner.Deleted || !Owner.TryGetComponent(out BatteryComponent? battery))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -101,7 +102,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
|
||||
battery.CurrentCharge += _chargingWattage * frameTime * _chargingEfficiency;
|
||||
if (battery.BatteryState == BatteryState.Full)
|
||||
{
|
||||
if (Owner.TryGetComponent(out PowerReceiverComponent receiver))
|
||||
if (Owner.TryGetComponent(out PowerReceiverComponent? receiver))
|
||||
{
|
||||
receiver.Load = 1;
|
||||
}
|
||||
@@ -113,12 +114,12 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
|
||||
|
||||
private void TurnOff()
|
||||
{
|
||||
if (Owner.TryGetComponent(out SpriteComponent sprite))
|
||||
if (Owner.TryGetComponent(out SpriteComponent? sprite))
|
||||
{
|
||||
sprite.LayerSetState(0, "emergency_light_off");
|
||||
}
|
||||
|
||||
if (Owner.TryGetComponent(out PointLightComponent light))
|
||||
if (Owner.TryGetComponent(out PointLightComponent? light))
|
||||
{
|
||||
light.Enabled = false;
|
||||
}
|
||||
@@ -126,18 +127,18 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
|
||||
|
||||
private void TurnOn()
|
||||
{
|
||||
if (Owner.TryGetComponent(out SpriteComponent sprite))
|
||||
if (Owner.TryGetComponent(out SpriteComponent? sprite))
|
||||
{
|
||||
sprite.LayerSetState(0, "emergency_light_on");
|
||||
}
|
||||
|
||||
if (Owner.TryGetComponent(out PointLightComponent light))
|
||||
if (Owner.TryGetComponent(out PointLightComponent? light))
|
||||
{
|
||||
light.Enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override void HandleMessage(ComponentMessage message, IComponent component)
|
||||
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
||||
{
|
||||
base.HandleMessage(message, component);
|
||||
switch (message)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
@@ -41,8 +42,8 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
|
||||
/// <summary>
|
||||
/// Invoked whenever the state of the light bulb changes.
|
||||
/// </summary>
|
||||
public event EventHandler<EventArgs> OnLightBulbStateChange;
|
||||
public event EventHandler<EventArgs> OnLightColorChange;
|
||||
public event EventHandler<EventArgs>? OnLightBulbStateChange;
|
||||
public event EventHandler<EventArgs?>? OnLightColorChange;
|
||||
|
||||
private Color _color = Color.White;
|
||||
|
||||
@@ -106,7 +107,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
|
||||
|
||||
public void UpdateColor()
|
||||
{
|
||||
if (!Owner.TryGetComponent(out SpriteComponent sprite))
|
||||
if (!Owner.TryGetComponent(out SpriteComponent? sprite))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
#nullable enable
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.GameObjects.Components.GUI;
|
||||
@@ -41,16 +42,16 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
|
||||
[ViewVariables] private bool _on;
|
||||
|
||||
private LightBulbType BulbType = LightBulbType.Tube;
|
||||
[ViewVariables] private ContainerSlot _lightBulbContainer;
|
||||
[ViewVariables] private ContainerSlot _lightBulbContainer = default!;
|
||||
|
||||
[ViewVariables]
|
||||
private LightBulbComponent LightBulb
|
||||
private LightBulbComponent? LightBulb
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_lightBulbContainer.ContainedEntity == null) return null;
|
||||
|
||||
_lightBulbContainer.ContainedEntity.TryGetComponent(out LightBulbComponent bulb);
|
||||
_lightBulbContainer.ContainedEntity.TryGetComponent(out LightBulbComponent? bulb);
|
||||
|
||||
return bulb;
|
||||
}
|
||||
@@ -65,12 +66,12 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
|
||||
|
||||
bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs)
|
||||
{
|
||||
if (!eventArgs.User.TryGetComponent(out IDamageableComponent damageableComponent))
|
||||
if (!eventArgs.User.TryGetComponent(out IDamageableComponent? damageableComponent))
|
||||
{
|
||||
Eject();
|
||||
return false;
|
||||
}
|
||||
if(eventArgs.User.TryGetComponent(out HeatResistanceComponent heatResistanceComponent))
|
||||
if(eventArgs.User.TryGetComponent(out HeatResistanceComponent? heatResistanceComponent))
|
||||
{
|
||||
if(CanBurn(heatResistanceComponent.GetHeatResistance()))
|
||||
{
|
||||
@@ -83,6 +84,9 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
|
||||
|
||||
bool CanBurn(int heatResistance)
|
||||
{
|
||||
if (LightBulb == null)
|
||||
return false;
|
||||
|
||||
return _lightState && heatResistance < LightBulb.BurningTemperature;
|
||||
}
|
||||
|
||||
@@ -108,7 +112,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
|
||||
private bool InsertBulb(IEntity bulb)
|
||||
{
|
||||
if (LightBulb != null) return false;
|
||||
if (!bulb.TryGetComponent(out LightBulbComponent lightBulb)) return false;
|
||||
if (!bulb.TryGetComponent(out LightBulbComponent? lightBulb)) return false;
|
||||
if (lightBulb.Type != BulbType) return false;
|
||||
|
||||
var inserted = _lightBulbContainer.Insert(bulb);
|
||||
@@ -135,7 +139,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
|
||||
|
||||
if (!_lightBulbContainer.Remove(bulb.Owner)) return;
|
||||
|
||||
if (!user.TryGetComponent(out HandsComponent hands)
|
||||
if (!user.TryGetComponent(out HandsComponent? hands)
|
||||
|| !hands.PutInHand(bulb.Owner.GetComponent<ItemComponent>()))
|
||||
bulb.Owner.Transform.Coordinates = user.Transform.Coordinates;
|
||||
}
|
||||
@@ -149,7 +153,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
|
||||
/// <summary>
|
||||
/// For attaching UpdateLight() to events.
|
||||
/// </summary>
|
||||
public void UpdateLight(object sender, EventArgs e)
|
||||
public void UpdateLight(object? sender, EventArgs? e)
|
||||
{
|
||||
UpdateLight();
|
||||
}
|
||||
@@ -212,7 +216,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
|
||||
_lightBulbContainer = ContainerManagerComponent.Ensure<ContainerSlot>("light_bulb", Owner);
|
||||
}
|
||||
|
||||
public override void HandleMessage(ComponentMessage message, IComponent component)
|
||||
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
||||
{
|
||||
base.HandleMessage(message, component);
|
||||
switch (message)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Content.Server.GameObjects.Components.Weapon.Ranged.Barrels;
|
||||
#nullable enable
|
||||
using Content.Server.GameObjects.Components.Weapon.Ranged.Barrels;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System.Linq;
|
||||
#nullable enable
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Content.Server.GameObjects.Components.NodeContainer;
|
||||
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
|
||||
using Robust.Shared.GameObjects;
|
||||
@@ -15,7 +17,7 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
|
||||
[ViewVariables]
|
||||
public TNetType Net { get => _net; set => SetNet(value); }
|
||||
private TNetType _net;
|
||||
private TNetType _net = default!; //set in OnAdd()
|
||||
|
||||
protected abstract TNetType NullNet { get; }
|
||||
|
||||
@@ -68,7 +70,7 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
|
||||
protected abstract void RemoveSelfFromNet(TNetType net);
|
||||
|
||||
private bool TryFindNet(out TNetType foundNet)
|
||||
private bool TryFindNet([NotNullWhen(true)] out TNetType? foundNet)
|
||||
{
|
||||
if (Owner.TryGetComponent<NodeContainerComponent>(out var container))
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
#nullable enable
|
||||
using System;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization;
|
||||
@@ -53,7 +54,7 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
/// <summary>
|
||||
/// If sufficient charge is avaiable on the battery, use it. Otherwise, don't.
|
||||
/// </summary>
|
||||
public bool TryUseCharge(float chargeToUse)
|
||||
public virtual bool TryUseCharge(float chargeToUse)
|
||||
{
|
||||
if (chargeToUse >= CurrentCharge)
|
||||
{
|
||||
@@ -66,7 +67,7 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
}
|
||||
}
|
||||
|
||||
public float UseCharge(float toDeduct)
|
||||
public virtual float UseCharge(float toDeduct)
|
||||
{
|
||||
var chargeChangedBy = Math.Min(CurrentCharge, toDeduct);
|
||||
CurrentCharge -= chargeChangedBy;
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
using Content.Shared.GameObjects.Components.Power;
|
||||
#nullable enable
|
||||
using System;
|
||||
using Content.Server.Explosions;
|
||||
using Content.Server.GameObjects.Components.Chemistry;
|
||||
using Content.Shared.GameObjects.Components.Power;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Shared.Utility;
|
||||
using Robust.Server.GameObjects;
|
||||
@@ -16,13 +20,15 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(BatteryComponent))]
|
||||
public class PowerCellComponent : BatteryComponent, IExamine
|
||||
public class PowerCellComponent : BatteryComponent, IExamine, ISolutionChange
|
||||
{
|
||||
public override string Name => "PowerCell";
|
||||
|
||||
[ViewVariables] public PowerCellSize CellSize => _cellSize;
|
||||
private PowerCellSize _cellSize = PowerCellSize.Small;
|
||||
|
||||
[ViewVariables] public bool IsRigged { get; private set; }
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
@@ -42,9 +48,41 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
UpdateVisuals();
|
||||
}
|
||||
|
||||
public override bool TryUseCharge(float chargeToUse)
|
||||
{
|
||||
if (IsRigged)
|
||||
{
|
||||
Explode();
|
||||
return false;
|
||||
}
|
||||
|
||||
return base.TryUseCharge(chargeToUse);
|
||||
}
|
||||
|
||||
public override float UseCharge(float toDeduct)
|
||||
{
|
||||
if (IsRigged)
|
||||
{
|
||||
Explode();
|
||||
return 0;
|
||||
}
|
||||
|
||||
return base.UseCharge(toDeduct);
|
||||
}
|
||||
|
||||
private void Explode()
|
||||
{
|
||||
var heavy = (int) Math.Ceiling(Math.Sqrt(CurrentCharge) / 60);
|
||||
var light = (int) Math.Ceiling(Math.Sqrt(CurrentCharge) / 30);
|
||||
|
||||
CurrentCharge = 0;
|
||||
Owner.SpawnExplosion(0, heavy, light, light*2);
|
||||
Owner.Delete();
|
||||
}
|
||||
|
||||
private void UpdateVisuals()
|
||||
{
|
||||
if (Owner.TryGetComponent(out AppearanceComponent appearance))
|
||||
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
|
||||
{
|
||||
appearance.SetData(PowerCellVisuals.ChargeLevel, GetLevel(CurrentCharge / MaxCharge));
|
||||
}
|
||||
@@ -57,11 +95,18 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
|
||||
void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
|
||||
{
|
||||
if(inDetailsRange)
|
||||
if (inDetailsRange)
|
||||
{
|
||||
message.AddMarkup(Loc.GetString($"The charge indicator reads {CurrentCharge / MaxCharge * 100:F0} %."));
|
||||
}
|
||||
}
|
||||
|
||||
void ISolutionChange.SolutionChanged(SolutionChangeEventArgs eventArgs)
|
||||
{
|
||||
IsRigged = Owner.TryGetComponent(out SolutionContainerComponent? solution)
|
||||
&& solution.Solution.ContainsReagent("chem.Phoron", out var phoron)
|
||||
&& phoron >= 5;
|
||||
}
|
||||
}
|
||||
|
||||
public enum PowerCellSize
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
|
||||
#nullable enable
|
||||
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Power.PowerNetComponents
|
||||
{
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
#nullable enable
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.ComponentDependencies;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using System;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Power.PowerNetComponents
|
||||
{
|
||||
@@ -13,10 +16,10 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents
|
||||
public override string Name => "BatteryDischarger";
|
||||
|
||||
[ViewVariables]
|
||||
private BatteryComponent _battery;
|
||||
[ComponentDependency] private BatteryComponent? _battery = default!;
|
||||
|
||||
[ViewVariables]
|
||||
private PowerSupplierComponent _supplier;
|
||||
[ComponentDependency] private PowerSupplierComponent? _supplier = default!;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public int ActiveSupplyRate { get => _activeSupplyRate; set => SetActiveSupplyRate(value); }
|
||||
@@ -31,14 +34,16 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_battery = Owner.EnsureComponent<BatteryComponent>();
|
||||
_supplier = Owner.EnsureComponent<PowerSupplierComponent>();
|
||||
Owner.EnsureComponentWarn<BatteryComponent>();
|
||||
Owner.EnsureComponentWarn<PowerSupplierComponent>();
|
||||
UpdateSupplyRate();
|
||||
}
|
||||
|
||||
public void Update(float frameTime)
|
||||
{
|
||||
if (_battery == null)
|
||||
return;
|
||||
|
||||
//Simplified implementation - if the battery is empty, and charge is being added to the battery
|
||||
//at a lower rate that this is using it, the charge is used without creating power supply.
|
||||
_battery.CurrentCharge -= ActiveSupplyRate * frameTime;
|
||||
@@ -47,6 +52,9 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents
|
||||
|
||||
private void UpdateSupplyRate()
|
||||
{
|
||||
if (_battery == null)
|
||||
return;
|
||||
|
||||
if (_battery.BatteryState == BatteryState.Empty)
|
||||
{
|
||||
SetSupplierSupplyRate(0);
|
||||
@@ -59,6 +67,9 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents
|
||||
|
||||
private void SetSupplierSupplyRate(int newSupplierSupplyRate)
|
||||
{
|
||||
if (_supplier == null)
|
||||
return;
|
||||
|
||||
if (_supplier.SupplyRate != newSupplierSupplyRate)
|
||||
{
|
||||
_supplier.SupplyRate = newSupplierSupplyRate;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
#nullable enable
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.ComponentDependencies;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
@@ -17,10 +19,12 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents
|
||||
private int _activeDrawRate;
|
||||
|
||||
[ViewVariables]
|
||||
private BatteryComponent _battery;
|
||||
[ComponentDependency] private BatteryComponent? _battery = default!;
|
||||
|
||||
[ViewVariables]
|
||||
public PowerConsumerComponent Consumer { get; private set; }
|
||||
public PowerConsumerComponent? Consumer => _consumer;
|
||||
|
||||
[ComponentDependency] private PowerConsumerComponent? _consumer = default!;
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
@@ -31,21 +35,26 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_battery = Owner.EnsureComponent<BatteryComponent>();
|
||||
Consumer = Owner.EnsureComponent<PowerConsumerComponent>();
|
||||
Owner.EnsureComponentWarn<BatteryComponent>();
|
||||
Owner.EnsureComponentWarn<PowerConsumerComponent>();
|
||||
UpdateDrawRate();
|
||||
}
|
||||
|
||||
public void Update(float frameTime)
|
||||
{
|
||||
if (_consumer == null || _battery == null)
|
||||
return;
|
||||
|
||||
//Simplified implementation - If a frame adds more power to a partially full battery than it can hold, the power is lost.
|
||||
_battery.CurrentCharge += Consumer.ReceivedPower * frameTime;
|
||||
_battery.CurrentCharge += _consumer.ReceivedPower * frameTime;
|
||||
UpdateDrawRate();
|
||||
}
|
||||
|
||||
private void UpdateDrawRate()
|
||||
{
|
||||
if (_battery == null)
|
||||
return;
|
||||
|
||||
if (_battery.BatteryState == BatteryState.Full)
|
||||
{
|
||||
SetConsumerDraw(0);
|
||||
@@ -58,9 +67,12 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents
|
||||
|
||||
private void SetConsumerDraw(int newConsumerDrawRate)
|
||||
{
|
||||
if (Consumer.DrawRate != newConsumerDrawRate)
|
||||
if (_consumer == null)
|
||||
return;
|
||||
|
||||
if (_consumer.DrawRate != newConsumerDrawRate)
|
||||
{
|
||||
Consumer.DrawRate = newConsumerDrawRate;
|
||||
_consumer.DrawRate = newConsumerDrawRate;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
#nullable enable
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Power.PowerNetComponents
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
|
||||
using Robust.Shared.GameObjects;
|
||||
@@ -34,7 +35,7 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents
|
||||
public int ReceivedPower { get => _receivedPower; set => SetReceivedPower(value); }
|
||||
private int _receivedPower;
|
||||
|
||||
public event EventHandler<ReceivedPowerChangedEventArgs> OnReceivedPowerChanged;
|
||||
public event EventHandler<ReceivedPowerChangedEventArgs>? OnReceivedPowerChanged;
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
|
||||
#nullable enable
|
||||
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Threading;
|
||||
using Content.Server.Utility;
|
||||
using Content.Shared.GameObjects.Components;
|
||||
using Content.Shared.GameObjects.Components.Doors;
|
||||
using Content.Shared.GameObjects.Components.Singularity;
|
||||
using Content.Shared.Interfaces;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.ComponentDependencies;
|
||||
using Robust.Shared.GameObjects.Components;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Timing;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Log;
|
||||
using Timer = Robust.Shared.Timers.Timer;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Power.PowerNetComponents
|
||||
{
|
||||
@@ -27,19 +25,9 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents
|
||||
private bool _enabled;
|
||||
private TimeSpan _coolDownEnd;
|
||||
|
||||
private PhysicsComponent _collidableComponent;
|
||||
[ComponentDependency] private readonly PhysicsComponent? _collidableComponent = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
if (!Owner.TryGetComponent(out _collidableComponent))
|
||||
{
|
||||
Logger.Error("RadiationCollectorComponent created with no CollidableComponent");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public override void HandleMessage(ComponentMessage message, IComponent component)
|
||||
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
||||
{
|
||||
base.HandleMessage(message, component);
|
||||
switch (message)
|
||||
@@ -52,7 +40,8 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents
|
||||
|
||||
private void OnAnchoredChanged()
|
||||
{
|
||||
if(_collidableComponent.Anchored) Owner.SnapToGrid();
|
||||
if(_collidableComponent != null && _collidableComponent.Anchored)
|
||||
Owner.SnapToGrid();
|
||||
}
|
||||
|
||||
bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs)
|
||||
@@ -99,7 +88,7 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents
|
||||
|
||||
protected void SetAppearance(RadiationCollectorVisualState state)
|
||||
{
|
||||
if (Owner.TryGetComponent(out AppearanceComponent appearance))
|
||||
if (Owner.TryGetComponent<AppearanceComponent>(out var appearance))
|
||||
{
|
||||
appearance.SetData(RadiationCollectorVisuals.VisualState, state);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
#nullable enable
|
||||
using System;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Robust.Server.GameObjects;
|
||||
@@ -62,7 +63,7 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents
|
||||
|
||||
private void UpdateSupply()
|
||||
{
|
||||
if (Owner.TryGetComponent(out PowerSupplierComponent supplier))
|
||||
if (Owner.TryGetComponent<PowerSupplierComponent>(out var supplier))
|
||||
{
|
||||
supplier.SupplyRate = (int) (_maxSupply * _coverage);
|
||||
}
|
||||
@@ -72,7 +73,7 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
Owner.EnsureComponentWarn(out PowerSupplierComponent _);
|
||||
Owner.EnsureComponentWarn<PowerSupplierComponent>();
|
||||
|
||||
UpdateSupply();
|
||||
}
|
||||
@@ -86,7 +87,9 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents
|
||||
|
||||
public void OnBreak(BreakageEventArgs args)
|
||||
{
|
||||
var sprite = Owner.GetComponent<SpriteComponent>();
|
||||
if (!Owner.TryGetComponent<SpriteComponent>(out var sprite))
|
||||
return;
|
||||
|
||||
sprite.LayerSetState(0, "broken");
|
||||
MaxSupply = 0;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Threading.Tasks;
|
||||
#nullable enable
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.GameObjects.Components.Interactable;
|
||||
using Content.Server.GameObjects.Components.Stack;
|
||||
using Content.Shared.GameObjects.Components.Interactable;
|
||||
@@ -18,7 +19,7 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
public override string Name => "Wire";
|
||||
|
||||
[ViewVariables]
|
||||
private string _wireDroppedOnCutPrototype;
|
||||
private string? _wireDroppedOnCutPrototype;
|
||||
|
||||
/// <summary>
|
||||
/// Checked by <see cref="WirePlacerComponent"/> to determine if there is
|
||||
@@ -37,7 +38,10 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
|
||||
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
|
||||
{
|
||||
if (!eventArgs.Using.TryGetComponent(out ToolComponent tool)) return false;
|
||||
if (_wireDroppedOnCutPrototype == null)
|
||||
return false;
|
||||
|
||||
if (!eventArgs.Using.TryGetComponent<ToolComponent>(out var tool)) return false;
|
||||
if (!await tool.UseTool(eventArgs.User, Owner, 0.25f, ToolQuality.Cutting)) return false;
|
||||
|
||||
Owner.Delete();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Content.Server.GameObjects.Components.Stack;
|
||||
#nullable enable
|
||||
using Content.Server.GameObjects.Components.Stack;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Content.Shared.Utility;
|
||||
using Robust.Server.Interfaces.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Components.Transform;
|
||||
using Robust.Shared.Interfaces.Map;
|
||||
@@ -21,7 +21,7 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
public override string Name => "WirePlacer";
|
||||
|
||||
[ViewVariables]
|
||||
private string _wirePrototypeID;
|
||||
private string? _wirePrototypeID;
|
||||
|
||||
[ViewVariables]
|
||||
private WireType _blockingWireType;
|
||||
@@ -34,25 +34,29 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
async Task IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
|
||||
async Task<bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
|
||||
{
|
||||
if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true)) return;
|
||||
if (_wirePrototypeID == null)
|
||||
return true;
|
||||
if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true))
|
||||
return true;
|
||||
if(!_mapManager.TryGetGrid(eventArgs.ClickLocation.GetGridId(Owner.EntityManager), out var grid))
|
||||
return;
|
||||
return true;
|
||||
var snapPos = grid.SnapGridCellFor(eventArgs.ClickLocation, SnapGridOffset.Center);
|
||||
var snapCell = grid.GetSnapGridCell(snapPos, SnapGridOffset.Center);
|
||||
if(grid.GetTileRef(snapPos).Tile.IsEmpty)
|
||||
return;
|
||||
return true;
|
||||
foreach (var snapComp in snapCell)
|
||||
{
|
||||
if (snapComp.Owner.TryGetComponent<WireComponent>(out var wire) && wire.WireType == _blockingWireType)
|
||||
{
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (Owner.TryGetComponent(out StackComponent stack) && !stack.Use(1))
|
||||
return;
|
||||
if (Owner.TryGetComponent<StackComponent>(out var stack) && !stack.Use(1))
|
||||
return true;
|
||||
Owner.EntityManager.SpawnEntity(_wirePrototypeID, grid.GridTileToLocal(snapPos));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user