You can now rig power cells to explode.
VERY funny.
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
using Content.Shared.GameObjects.Components.Power;
|
||||
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;
|
||||
@@ -8,6 +11,8 @@ using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Power
|
||||
{
|
||||
/// <summary>
|
||||
@@ -16,13 +21,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 +49,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 +96,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
|
||||
|
||||
Reference in New Issue
Block a user