You can now rig power cells to explode.

VERY funny.
This commit is contained in:
Pieter-Jan Briers
2021-01-24 16:21:18 +01:00
parent 436694e376
commit 526c3d1ebf
4 changed files with 61 additions and 7 deletions

View File

@@ -53,7 +53,7 @@ namespace Content.Server.GameObjects.Components.Power
/// <summary> /// <summary>
/// If sufficient charge is avaiable on the battery, use it. Otherwise, don't. /// If sufficient charge is avaiable on the battery, use it. Otherwise, don't.
/// </summary> /// </summary>
public bool TryUseCharge(float chargeToUse) public virtual bool TryUseCharge(float chargeToUse)
{ {
if (chargeToUse >= CurrentCharge) if (chargeToUse >= CurrentCharge)
{ {
@@ -66,7 +66,7 @@ namespace Content.Server.GameObjects.Components.Power
} }
} }
public float UseCharge(float toDeduct) public virtual float UseCharge(float toDeduct)
{ {
var chargeChangedBy = Math.Min(CurrentCharge, toDeduct); var chargeChangedBy = Math.Min(CurrentCharge, toDeduct);
CurrentCharge -= chargeChangedBy; CurrentCharge -= chargeChangedBy;

View File

@@ -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.GameObjects.EntitySystems;
using Content.Shared.Utility; using Content.Shared.Utility;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
@@ -8,6 +11,8 @@ using Robust.Shared.Serialization;
using Robust.Shared.Utility; using Robust.Shared.Utility;
using Robust.Shared.ViewVariables; using Robust.Shared.ViewVariables;
#nullable enable
namespace Content.Server.GameObjects.Components.Power namespace Content.Server.GameObjects.Components.Power
{ {
/// <summary> /// <summary>
@@ -16,13 +21,15 @@ namespace Content.Server.GameObjects.Components.Power
/// </summary> /// </summary>
[RegisterComponent] [RegisterComponent]
[ComponentReference(typeof(BatteryComponent))] [ComponentReference(typeof(BatteryComponent))]
public class PowerCellComponent : BatteryComponent, IExamine public class PowerCellComponent : BatteryComponent, IExamine, ISolutionChange
{ {
public override string Name => "PowerCell"; public override string Name => "PowerCell";
[ViewVariables] public PowerCellSize CellSize => _cellSize; [ViewVariables] public PowerCellSize CellSize => _cellSize;
private PowerCellSize _cellSize = PowerCellSize.Small; private PowerCellSize _cellSize = PowerCellSize.Small;
[ViewVariables] public bool IsRigged { get; private set; }
public override void ExposeData(ObjectSerializer serializer) public override void ExposeData(ObjectSerializer serializer)
{ {
base.ExposeData(serializer); base.ExposeData(serializer);
@@ -42,9 +49,41 @@ namespace Content.Server.GameObjects.Components.Power
UpdateVisuals(); 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() private void UpdateVisuals()
{ {
if (Owner.TryGetComponent(out AppearanceComponent appearance)) if (Owner.TryGetComponent(out AppearanceComponent? appearance))
{ {
appearance.SetData(PowerCellVisuals.ChargeLevel, GetLevel(CurrentCharge / MaxCharge)); appearance.SetData(PowerCellVisuals.ChargeLevel, GetLevel(CurrentCharge / MaxCharge));
} }
@@ -62,6 +101,13 @@ namespace Content.Server.GameObjects.Components.Power
message.AddMarkup(Loc.GetString($"The charge indicator reads {CurrentCharge / MaxCharge * 100:F0} %.")); 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 public enum PowerCellSize

View File

@@ -169,7 +169,11 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
// Multiply the entity's damage / whatever by the percentage of charge the shot has. // Multiply the entity's damage / whatever by the percentage of charge the shot has.
IEntity entity; IEntity entity;
var chargeChange = Math.Min(capacitor.CurrentCharge, _baseFireCost); var chargeChange = Math.Min(capacitor.CurrentCharge, _baseFireCost);
capacitor.UseCharge(chargeChange); if (capacitor.UseCharge(chargeChange) < _lowerChargeLimit)
{
// Handling of funny exploding cells.
return null;
}
var energyRatio = chargeChange / _baseFireCost; var energyRatio = chargeChange / _baseFireCost;
if (_ammoContainer.ContainedEntity != null) if (_ammoContainer.ContainedEntity != null)

View File

@@ -15,6 +15,10 @@
- type: PowerCell - type: PowerCell
- type: Sprite - type: Sprite
netsync: false netsync: false
- type: SolutionContainer
maxVol: 5
caps: AddTo, RemoveFrom
- type: entity - type: entity
id: PowerCellSmallBase id: PowerCellSmallBase