From 863d8e860185ac795742338a8065b3a1dea18e5d Mon Sep 17 00:00:00 2001 From: Segonist <74138556+Segonist@users.noreply.github.com> Date: Wed, 31 May 2023 15:48:55 +0200 Subject: [PATCH] constructable rechargers (#16367) --- .../Power/Components/ChargerComponent.cs | 28 ++++++- .../Power/EntitySystems/ChargerSystem.cs | 16 +++- .../Locale/en-US/power/components/charger.ftl | 3 +- .../Circuitboards/Machine/production.yml | 32 ++++++++ .../Entities/Structures/Machines/lathe.yml | 2 + .../Entities/Structures/Power/chargers.yml | 77 ++++++++++++++++++- .../Prototypes/Recipes/Lathes/electronics.yml | 16 ++++ 7 files changed, 169 insertions(+), 5 deletions(-) diff --git a/Content.Server/Power/Components/ChargerComponent.cs b/Content.Server/Power/Components/ChargerComponent.cs index 12265dce6e..569bc0f2f8 100644 --- a/Content.Server/Power/Components/ChargerComponent.cs +++ b/Content.Server/Power/Components/ChargerComponent.cs @@ -1,4 +1,6 @@ +using Content.Shared.Construction.Prototypes; using Content.Shared.Power; +using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; namespace Content.Server.Power.Components { @@ -8,8 +10,32 @@ namespace Content.Server.Power.Components [ViewVariables] public CellChargerStatus Status; + /// + /// The charge rate of the charger, in watts + /// + [DataField("chargeRate")] - public int ChargeRate = 20; + public float ChargeRate = 20.0f; + + /// + /// The charge rate with no machine upgrades + /// + + [DataField("baseChargeRate")] + public float BaseChargeRate = 20.0f; + + /// + /// The machine part that affects the charge rate multiplier of the charger + /// + [DataField("machinePartChargeRateModifier", customTypeSerializer: typeof(PrototypeIdSerializer))] + public string MachinePartChargeRateModifier = "Capacitor"; + + /// + /// A value used to scale the charge rate multiplier + /// with the corresponding part rating. + /// + [DataField("partRatingChargeRateModifier")] + public float PartRatingChargeRateModifier = 1.5f; [DataField("slotId", required: true)] public string SlotId = string.Empty; diff --git a/Content.Server/Power/EntitySystems/ChargerSystem.cs b/Content.Server/Power/EntitySystems/ChargerSystem.cs index f208c8729b..4fbac94ee0 100644 --- a/Content.Server/Power/EntitySystems/ChargerSystem.cs +++ b/Content.Server/Power/EntitySystems/ChargerSystem.cs @@ -1,11 +1,12 @@ +using Content.Server.Construction; using Content.Server.Power.Components; using Content.Server.PowerCell; using Content.Shared.Containers.ItemSlots; using Content.Shared.Examine; +using Content.Shared.Power; using Content.Shared.PowerCell.Components; using JetBrains.Annotations; using Robust.Shared.Containers; -using Content.Shared.Power; using System.Diagnostics.CodeAnalysis; namespace Content.Server.Power.EntitySystems; @@ -20,6 +21,8 @@ internal sealed class ChargerSystem : EntitySystem public override void Initialize() { SubscribeLocalEvent(OnStartup); + SubscribeLocalEvent(OnRefreshParts); + SubscribeLocalEvent(OnUpgradeExamine); SubscribeLocalEvent(OnPowerChanged); SubscribeLocalEvent(OnInserted); SubscribeLocalEvent(OnRemoved); @@ -51,6 +54,17 @@ internal sealed class ChargerSystem : EntitySystem } } + private void OnRefreshParts(EntityUid uid, ChargerComponent component, RefreshPartsEvent args) + { + var modifierRating = args.PartRatings[component.MachinePartChargeRateModifier]; + component.ChargeRate = component.BaseChargeRate * MathF.Pow(component.PartRatingChargeRateModifier, modifierRating - 1); + } + + private void OnUpgradeExamine(EntityUid uid, ChargerComponent component, UpgradeExamineEvent args) + { + args.AddPercentageUpgrade("charger-component-charge-rate", component.ChargeRate / component.BaseChargeRate); + } + private void OnPowerChanged(EntityUid uid, ChargerComponent component, ref PowerChangedEvent args) { UpdateStatus(uid, component); diff --git a/Resources/Locale/en-US/power/components/charger.ftl b/Resources/Locale/en-US/power/components/charger.ftl index 252d682da1..4c6f820f90 100644 --- a/Resources/Locale/en-US/power/components/charger.ftl +++ b/Resources/Locale/en-US/power/components/charger.ftl @@ -1 +1,2 @@ -charger-examine = Charges [color={$color}]{$chargeRate}W[/color] per second. \ No newline at end of file +charger-examine = Charges [color={$color}]{$chargeRate}W[/color] per second. +charger-component-charge-rate = Charge rate diff --git a/Resources/Prototypes/Entities/Objects/Devices/Circuitboards/Machine/production.yml b/Resources/Prototypes/Entities/Objects/Devices/Circuitboards/Machine/production.yml index 32fd09dc7a..6738d9212c 100644 --- a/Resources/Prototypes/Entities/Objects/Devices/Circuitboards/Machine/production.yml +++ b/Resources/Prototypes/Entities/Objects/Devices/Circuitboards/Machine/production.yml @@ -450,6 +450,38 @@ requirements: Capacitor: 5 +- type: entity + id: CellRechargerCircuitboard + parent: BaseMachineCircuitboard + name: cell recharger machine board + description: A machine printed circuit board for a cell recharger. + components: + - type: Sprite + sprite: Objects/Misc/module.rsi + state: charger_APC + - type: MachineBoard + prototype: PowerCellRecharger + requirements: + Capacitor: 2 + materialRequirements: + Cable: 5 + +- type: entity + id: WeaponCapacitorRechargerCircuitboard + parent: BaseMachineCircuitboard + name: recharger machine board + description: A machine printed circuit board for a recharger. + components: + - type: Sprite + sprite: Objects/Misc/module.rsi + state: charger_APC + - type: MachineBoard + prototype: WeaponCapacitorRecharger + requirements: + Capacitor: 2 + materialRequirements: + CableMV: 5 + - type: entity id: SubstationMachineCircuitboard parent: BaseMachineCircuitboard diff --git a/Resources/Prototypes/Entities/Structures/Machines/lathe.yml b/Resources/Prototypes/Entities/Structures/Machines/lathe.yml index bccf2aa988..9f3dc0fc6b 100644 --- a/Resources/Prototypes/Entities/Structures/Machines/lathe.yml +++ b/Resources/Prototypes/Entities/Structures/Machines/lathe.yml @@ -109,6 +109,8 @@ - APCElectronics - SMESMachineCircuitboard - SubstationMachineCircuitboard + - CellRechargerCircuitboard + - WeaponCapacitorRechargerCircuitboard - type: StaticPrice price: 800 diff --git a/Resources/Prototypes/Entities/Structures/Power/chargers.yml b/Resources/Prototypes/Entities/Structures/Power/chargers.yml index 3120d6860a..e54b3286fd 100644 --- a/Resources/Prototypes/Entities/Structures/Power/chargers.yml +++ b/Resources/Prototypes/Entities/Structures/Power/chargers.yml @@ -1,13 +1,13 @@ - type: entity name: cell recharger id: PowerCellRecharger + parent: ConstructibleMachine placement: mode: SnapgridCenter components: - type: Transform anchored: true - type: Sprite - netsync: false sprite: Structures/Power/cell_recharger.rsi drawdepth: SmallObjects snapCardinals: true @@ -21,6 +21,8 @@ slotId: charger_slot - type: ApcPowerReceiver - type: ExtensionCableReceiver + - type: Machine + board: CellRechargerCircuitboard - type: Appearance - type: PowerChargerVisuals - type: Anchorable @@ -70,6 +72,8 @@ - type: ContainerContainer containers: charger_slot: !type:ContainerSlot + machine_board: !type:Container + machine_parts: !type:Container - type: entity name: recharger @@ -78,6 +82,8 @@ components: - type: Sprite sprite: Structures/Power/recharger.rsi + - type: Machine + board: WeaponCapacitorRechargerCircuitboard - type: Charger slotId: charger_slot - type: ItemSlots @@ -93,10 +99,77 @@ - type: entity name: wall recharger id: WallWeaponCapacitorRecharger - parent: WeaponCapacitorRecharger + placement: + mode: SnapgridCenter components: - type: Sprite sprite: Structures/Power/wall_recharger.rsi + drawdepth: SmallObjects + snapCardinals: true + layers: + - map: ["enum.PowerChargerVisualLayers.Base"] + state: "empty" + - map: ["enum.PowerChargerVisualLayers.Light"] + state: "light-off" + shader: "unshaded" - type: WallMount - type: Charger chargeRate: 25 + slotId: charger_slot + - type: Transform + anchored: true + - type: ApcPowerReceiver + - type: ExtensionCableReceiver + - type: Appearance + - type: PowerChargerVisuals + - type: Anchorable + - type: Pullable + - type: Clickable + - type: InteractionOutline + - type: Damageable + damageContainer: Inorganic + damageModifierSet: Metallic + - type: Destructible + thresholds: + - trigger: + !type:DamageTrigger + damage: 80 + behaviors: + - !type:DoActsBehavior + acts: [ "Destruction" ] + - trigger: + !type:DamageTrigger + damage: 40 + behaviors: + - !type:EmptyAllContainersBehaviour + - !type:DoActsBehavior + acts: [ "Destruction" ] + - !type:PlaySoundBehavior + sound: + path: /Audio/Effects/metalbreak.ogg + - type: Physics + bodyType: Static + - type: Fixtures + fixtures: + fix1: + shape: + !type:PhysShapeAabb + bounds: "-0.10,-0.10,0.10,0.10" + density: 500 + mask: + - TabletopMachineMask + - type: ItemSlots + slots: + charger_slot: + ejectOnInteract: true + whitelist: + components: + - HitscanBatteryAmmoProvider + - ProjectileBatteryAmmoProvider + - Stunbaton + - type: ContainerContainer + containers: + charger_slot: !type:ContainerSlot + machine_board: !type:Container + machine_parts: !type:Container + diff --git a/Resources/Prototypes/Recipes/Lathes/electronics.yml b/Resources/Prototypes/Recipes/Lathes/electronics.yml index 57a37653c7..f48f4dc1e1 100644 --- a/Resources/Prototypes/Recipes/Lathes/electronics.yml +++ b/Resources/Prototypes/Recipes/Lathes/electronics.yml @@ -14,6 +14,22 @@ Steel: 50 Plastic: 300 +- type: latheRecipe + id: CellRechargerCircuitboard + result: CellRechargerCircuitboard + completetime: 2 + materials: + Steel: 50 + Plastic: 50 + +- type: latheRecipe + id: WeaponCapacitorRechargerCircuitboard + result: WeaponCapacitorRechargerCircuitboard + completetime: 2 + materials: + Steel: 50 + Plastic: 50 + - type: latheRecipe id: DoorElectronics result: DoorElectronics