From b82885af388086dbc621f27155ae411e3c2d9f29 Mon Sep 17 00:00:00 2001
From: deltanedas <39013340+deltanedas@users.noreply.github.com>
Date: Tue, 13 Jun 2023 06:37:53 +0000
Subject: [PATCH] make salvage magnets upgradable with capacitors (#16763)
Co-authored-by: deltanedas <@deltanedas:kde.org>
---
.../Salvage/SalvageMagnetComponent.cs | 52 ++++++++++++-------
Content.Server/Salvage/SalvageSystem.cs | 16 ++++++
.../Salvage/SharedSalvageMagnetComponent.cs | 18 ++++++-
.../Locale/en-US/salvage/salvage-system.ftl | 2 +
.../Circuitboards/Machine/production.yml | 15 ++++++
.../Entities/Structures/Machines/salvage.yml | 50 ++++++++----------
6 files changed, 105 insertions(+), 48 deletions(-)
diff --git a/Content.Server/Salvage/SalvageMagnetComponent.cs b/Content.Server/Salvage/SalvageMagnetComponent.cs
index 7020631c6a..69b0cbdf5d 100644
--- a/Content.Server/Salvage/SalvageMagnetComponent.cs
+++ b/Content.Server/Salvage/SalvageMagnetComponent.cs
@@ -6,90 +6,104 @@ using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototy
namespace Content.Server.Salvage
{
///
- /// A salvage magnet.
+ /// A salvage magnet.
///
[NetworkedComponent, RegisterComponent]
[Access(typeof(SalvageSystem))]
public sealed class SalvageMagnetComponent : SharedSalvageMagnetComponent
{
///
- /// Offset relative to magnet used as centre of the placement circle.
+ /// Offset relative to magnet used as centre of the placement circle.
///
[ViewVariables(VVAccess.ReadWrite)]
[DataField("offset")]
public Vector2 Offset = Vector2.Zero; // TODO: Maybe specify a direction, and find the nearest edge of the magnets grid the salvage can fit at
///
- /// Minimum distance from the offset position that will be used as a salvage's spawnpoint.
+ /// Minimum distance from the offset position that will be used as a salvage's spawnpoint.
///
[ViewVariables(VVAccess.ReadWrite)]
[DataField("offsetRadiusMin")]
- public float OffsetRadiusMin = 0f;
+ public float OffsetRadiusMin = 24f;
///
- /// Maximum distance from the offset position that will be used as a salvage's spawnpoint.
+ /// Maximum distance from the offset position that will be used as a salvage's spawnpoint.
///
[ViewVariables(VVAccess.ReadWrite)]
[DataField("offsetRadiusMax")]
- public float OffsetRadiusMax = 0f;
+ public float OffsetRadiusMax = 48f;
///
- /// The entity attached to the magnet
+ /// The entity attached to the magnet
///
[ViewVariables(VVAccess.ReadOnly)]
[DataField("attachedEntity")]
public EntityUid? AttachedEntity = null;
///
- /// Current state of this magnet
+ /// Current state of this magnet
///
[ViewVariables(VVAccess.ReadOnly)]
[DataField("magnetState")]
public MagnetState MagnetState = MagnetState.Inactive;
///
- /// How long it takes for the magnet to pull in the debris
+ /// How long it takes for the magnet to pull in the debris
+ ///
+ [ViewVariables(VVAccess.ReadWrite)]
+ [DataField("baseAttachingTime")]
+ public TimeSpan BaseAttachingTime = TimeSpan.FromSeconds(30);
+
+ ///
+ /// How long it actually takes for the magnet to pull in the debris
///
[ViewVariables(VVAccess.ReadWrite)]
[DataField("attachingTime")]
- public TimeSpan AttachingTime = TimeSpan.FromSeconds(10);
+ public TimeSpan AttachingTime = TimeSpan.FromSeconds(30);
///
- /// How long the magnet can hold the debris until it starts losing the lock
+ /// How long the magnet can hold the debris until it starts losing the lock
///
[ViewVariables(VVAccess.ReadWrite)]
[DataField("holdTime")]
- public TimeSpan HoldTime = TimeSpan.FromSeconds(10);
+ public TimeSpan HoldTime = TimeSpan.FromSeconds(240);
///
- /// How long the magnet can hold the debris while losing the lock
+ /// How long the magnet can hold the debris while losing the lock
///
[ViewVariables(VVAccess.ReadWrite)]
[DataField("detachingTime")]
- public TimeSpan DetachingTime = TimeSpan.FromSeconds(10);
+ public TimeSpan DetachingTime = TimeSpan.FromSeconds(30);
///
- /// How long the magnet has to cool down after use
+ /// How long the magnet has to cool down for after use
+ ///
+ [ViewVariables(VVAccess.ReadWrite)]
+ [DataField("baseCooldownTime")]
+ public TimeSpan BaseCooldownTime = TimeSpan.FromSeconds(60);
+
+ ///
+ /// How long the magnet actually has to cool down for after use
///
[ViewVariables(VVAccess.ReadWrite)]
[DataField("cooldownTime")]
- public TimeSpan CooldownTime = TimeSpan.FromSeconds(10);
+ public TimeSpan CooldownTime = TimeSpan.FromSeconds(60);
[DataField("salvageChannel", customTypeSerializer: typeof(PrototypeIdSerializer))]
public string SalvageChannel = "Supply";
///
- /// Current how much charge the magnet currently has
+ /// Current how much charge the magnet currently has
///
public int ChargeRemaining = 5;
///
- /// How much capacity the magnet can hold
+ /// How much capacity the magnet can hold
///
public int ChargeCapacity = 5;
///
- /// Used as a guard to prevent spamming the appearance system
+ /// Used as a guard to prevent spamming the appearance system
///
public int PreviousCharge = 5;
diff --git a/Content.Server/Salvage/SalvageSystem.cs b/Content.Server/Salvage/SalvageSystem.cs
index d5ac0ab798..c74933b02a 100644
--- a/Content.Server/Salvage/SalvageSystem.cs
+++ b/Content.Server/Salvage/SalvageSystem.cs
@@ -1,3 +1,4 @@
+using Content.Server.Construction;
using Content.Server.GameTicking;
using Content.Server.Radio.Components;
using Content.Server.Radio.EntitySystems;
@@ -61,6 +62,8 @@ namespace Content.Server.Salvage
_sawmill = Logger.GetSawmill("salvage");
SubscribeLocalEvent(OnInteractHand);
+ SubscribeLocalEvent(OnRefreshParts);
+ SubscribeLocalEvent(OnUpgradeExamine);
SubscribeLocalEvent(OnExamined);
SubscribeLocalEvent(OnMagnetRemoval);
SubscribeLocalEvent(OnGridRemoval);
@@ -169,6 +172,19 @@ namespace Content.Server.Salvage
component.MagnetState = MagnetState.Inactive;
}
+ private void OnRefreshParts(EntityUid uid, SalvageMagnetComponent component, RefreshPartsEvent args)
+ {
+ var rating = args.PartRatings[component.MachinePartDelay] - 1;
+ var factor = MathF.Pow(component.PartRatingDelay, rating);
+ component.AttachingTime = component.BaseAttachingTime * factor;
+ component.CooldownTime = component.BaseCooldownTime * factor;
+ }
+
+ private void OnUpgradeExamine(EntityUid uid, SalvageMagnetComponent component, UpgradeExamineEvent args)
+ {
+ args.AddPercentageUpgrade("salvage-system-magnet-delay-upgrade", (float) (component.CooldownTime / component.BaseCooldownTime));
+ }
+
private void OnExamined(EntityUid uid, SalvageMagnetComponent component, ExaminedEvent args)
{
var gotGrid = false;
diff --git a/Content.Shared/Salvage/SharedSalvageMagnetComponent.cs b/Content.Shared/Salvage/SharedSalvageMagnetComponent.cs
index fac5870d2d..c0dd76d133 100644
--- a/Content.Shared/Salvage/SharedSalvageMagnetComponent.cs
+++ b/Content.Shared/Salvage/SharedSalvageMagnetComponent.cs
@@ -1,8 +1,24 @@
+using Content.Shared.Construction.Prototypes;
+using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
+using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Shared.Salvage;
-public abstract class SharedSalvageMagnetComponent : Component {}
+public abstract class SharedSalvageMagnetComponent : Component
+{
+ ///
+ /// The machine part that affects the attaching and cooldown times
+ ///
+ [DataField("machinePartDelay", customTypeSerializer: typeof(PrototypeIdSerializer)), ViewVariables(VVAccess.ReadWrite)]
+ public string MachinePartDelay = "Capacitor";
+
+ ///
+ /// A multiplier applied to the attaching and cooldown times for each level of
+ ///
+ [DataField("partRatingDelay"), ViewVariables(VVAccess.ReadWrite)]
+ public float PartRatingDelay = 0.75f;
+}
[Serializable, NetSerializable]
public enum SalvageMagnetVisuals : byte
diff --git a/Resources/Locale/en-US/salvage/salvage-system.ftl b/Resources/Locale/en-US/salvage/salvage-system.ftl
index f341fa0d24..1da79800d8 100644
--- a/Resources/Locale/en-US/salvage/salvage-system.ftl
+++ b/Resources/Locale/en-US/salvage/salvage-system.ftl
@@ -19,3 +19,5 @@ salvage-system-magnet-examined-active = The salvage magnet is holding salvage in
}
salvage-system-magnet-examined-releasing = The salvage magnet is releasing the salvage.
salvage-system-magnet-examined-cooling-down = The salvage magnet is cooling down. It will be ready in: {$timeLeft} seconds.
+salvage-system-magnet-delay-upgrade = Attaching/cooldown delay
+
diff --git a/Resources/Prototypes/Entities/Objects/Devices/Circuitboards/Machine/production.yml b/Resources/Prototypes/Entities/Objects/Devices/Circuitboards/Machine/production.yml
index b9a5139252..2bb112f83f 100644
--- a/Resources/Prototypes/Entities/Objects/Devices/Circuitboards/Machine/production.yml
+++ b/Resources/Prototypes/Entities/Objects/Devices/Circuitboards/Machine/production.yml
@@ -879,3 +879,18 @@
materialRequirements:
Steel: 1
Cable: 2
+
+- type: entity
+ parent: BaseMachineCircuitboard
+ id: SalvageMagnetMachineCircuitboard
+ name: salvage magnet machine board
+ description: A machine printed circuit board for a salvage magnet.
+ components:
+ - type: MachineBoard
+ prototype: SalvageMagnet
+ requirements:
+ Capacitor: 4
+ materialRequirements:
+ Steel: 5
+ CableHV: 5
+ Cable: 2
diff --git a/Resources/Prototypes/Entities/Structures/Machines/salvage.yml b/Resources/Prototypes/Entities/Structures/Machines/salvage.yml
index 21248846a8..56c6689b3e 100644
--- a/Resources/Prototypes/Entities/Structures/Machines/salvage.yml
+++ b/Resources/Prototypes/Entities/Structures/Machines/salvage.yml
@@ -1,28 +1,28 @@
- type: entity
+ parent: [ BaseMachinePowered, ConstructibleMachine ]
id: SalvageMagnet
- parent: BaseMachinePowered
name: salvage magnet
- description: "Pulls in salvage."
+ description: Pulls in salvage.
components:
- type: Sprite
sprite: Structures/Machines/salvage.rsi
layers:
- - state: salvage-magnet
- - state: salvage-magnet-ready
- visible: false
- map: [ "ready" ]
- - state: salvage-magnet-ready-blinking
- visible: false
- map: [ "readyBlinking" ]
- - state: salvage-magnet-unready
- visible: false
- map: [ "unready" ]
- - state: salvage-magnet-unready-blinking
- visible: false
- map: [ "unreadyBlinking" ]
- - state: salvage-magnet-o4
- map: ["chargeState"]
- shader: unshaded
+ - state: salvage-magnet
+ - state: salvage-magnet-ready
+ visible: false
+ map: [ "ready" ]
+ - state: salvage-magnet-ready-blinking
+ visible: false
+ map: [ "readyBlinking" ]
+ - state: salvage-magnet-unready
+ visible: false
+ map: [ "unready" ]
+ - state: salvage-magnet-unready-blinking
+ visible: false
+ map: [ "unreadyBlinking" ]
+ - state: salvage-magnet-o4
+ map: ["chargeState"]
+ shader: unshaded
- type: Appearance
- type: GenericVisualizer
visuals:
@@ -58,25 +58,19 @@
channels:
- Supply
- type: SalvageMagnet
- offset: 0, 0
- offsetRadiusMin: 24
- offsetRadiusMax: 48
- attachingTime: 30
- holdTime: 240
- detachingTime: 30
- cooldownTime: 60
- type: ApcPowerReceiver
powerLoad: 2500 # TODO change this to a HV power draw that really hits the grid hard WHEN active
+ - type: Machine
+ board: SalvageMagnetMachineCircuitboard
# For Knightship
- type: entity
- id: SalvageLocator
parent: SalvageMagnet
+ id: SalvageLocator
name: salvage locator
- description: "Locates salvage."
+ description: Locates salvage.
components:
- type: SalvageMagnet
- offset: 0, 0
offsetRadiusMin: 12
offsetRadiusMax: 48
- type: ApcPowerReceiver