Add power sinks (#8020)

Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
Veritius
2022-05-12 23:12:35 +10:00
committed by GitHub
parent 6cb2a01723
commit 656ec38f99
8 changed files with 133 additions and 1 deletions

View File

@@ -348,7 +348,8 @@ namespace Content.Client.Entry
"HealthAnalyzer",
"Thirst",
"CanEscapeInventory",
"Wires"
"PowerSink",
"Wires",
};
}
}

View File

@@ -0,0 +1,8 @@
namespace Content.Server.PowerSink
{
/// <summary>
/// Absorbs power up to its capacity when anchored then explodes.
/// </summary>
[RegisterComponent]
public sealed class PowerSinkComponent : Component {}
}

View File

@@ -0,0 +1,56 @@
using Content.Server.Explosion.EntitySystems;
using Content.Server.Power.Components;
using Content.Shared.Body.Events;
using Content.Shared.Examine;
using Robust.Shared.Utility;
namespace Content.Server.PowerSink
{
public sealed class PowerSinkSystem : EntitySystem
{
[Dependency] private readonly ExplosionSystem _explosionSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<PowerSinkComponent, ExaminedEvent>(OnExamine);
}
private void OnExamine(EntityUid uid, PowerSinkComponent component, ExaminedEvent args)
{
if (!args.IsInDetailsRange || !TryComp<PowerConsumerComponent>(uid, out var consumer))
return;
var drainAmount = (int) consumer.NetworkLoad.ReceivingPower / 1000;
args.PushMarkup(
Loc.GetString(
"powersink-examine-drain-amount",
("amount", drainAmount),
("markupDrainColor", "orange"))
);
}
public override void Update(float frameTime)
{
var toRemove = new RemQueue<(PowerSinkComponent Sink, BatteryComponent Battery)>();
// Realistically it's gonna be like <5 per station.
foreach (var (comp, networkLoad, battery, xform) in EntityManager.EntityQuery<PowerSinkComponent, PowerConsumerComponent, BatteryComponent, TransformComponent>())
{
if (!xform.Anchored) continue;
battery.CurrentCharge += networkLoad.NetworkLoad.ReceivingPower / 1000;
if (battery.CurrentCharge < battery.MaxCharge) continue;
toRemove.Add((comp, battery));
}
foreach (var (comp, battery) in toRemove)
{
_explosionSystem.QueueExplosion(comp.Owner, "Default", 5 * (battery.MaxCharge / 2500000), 0.5f, 10, canCreateVacuum: false);
EntityManager.RemoveComponent(comp.Owner, comp);
}
}
}
}

View File

@@ -0,0 +1 @@
powersink-examine-drain-amount = The power sink is draining [color={$markupDrainColor}]{$amount} kW[/color].

View File

@@ -255,6 +255,12 @@
itemId: ClothingBackpackDuffelSyndicateFilledMedical
price: 5
- type : uplinkListing
id: UplinkPowerSink
category: Tools
itemId: PowerSink
price: 5
- type: uplinkListing
id: UplinkCarpDehydrated
category: Tools

View File

@@ -0,0 +1,46 @@
- type: entity
id: PowerSink
parent: BaseMachine
name: power sink
description: Drains immense amounts of electricity from the grid.
components:
- type: Item
size: 150
- type: NodeContainer
examinable: true
nodes:
input:
!type:CableDeviceNode
nodeGroupID: HVPower
- type: Transform
anchored: true
- type: Physics
- type: Fixtures
fixtures:
- shape:
!type:PhysShapeAabb
bounds: "-0.40,-0.40,0.40,0.40"
mass: 15
mask:
- MachineMask
layer:
- MachineLayer
- type: Destructible
thresholds:
- trigger:
!type:DamageTrigger
damage: 25
behaviors:
- !type:DoActsBehavior
acts: [ "Destruction" ]
- type: PowerSink
- type: Battery
maxCharge: 7500000
- type: ExaminableBattery
- type: PowerConsumer
voltage: High
drawRate: 1000000
- type: Sprite
netsync: false
sprite: Objects/Power/powersink.rsi
state: powersink

View File

@@ -0,0 +1,14 @@
{
"version": 1,
"license": "CC-BY-NC-SA-3.0",
"copyright": "Taken from goonstation at commit https://github.com/goonstation/goonstation/commit/17c4392b75abd87a0f740e116c44dd4c7dfff6f7",
"size": {
"x": 32,
"y": 32
},
"states": [
{
"name": "powersink"
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB