From a7583eb525abaa67c035948045a9e2f604fe6608 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82?= <123451459+JustArt1m@users.noreply.github.com> Date: Tue, 15 Aug 2023 03:23:40 +0300 Subject: [PATCH] Construct and upgrade mini gravity generator (#18568) * Construct and upgrade mini gravity generator Now the mini gravity generator can be assembled/disassembled, the necessary machine board has been added to ShuttleCraft technology. Now it is possible to destroy the mini gravity generator and improve its components, thereby increasing the maximum charge of the generator. * Test with empty OnRefreshParts Perhaps this will help to get rid of the error during the test... * Revert "Test with empty OnRefreshParts" This reverts commit 5f32e15d66a4cb0d8df7578593867062be7872d8. * Test without OnRefreshParts Let's check if the problem is multiple inheritance. * Revert "Test without OnRefreshParts" This reverts commit d319757aa15a8ebec1237e552213e80eb8042790. * Enabled by default Maybe this will solve the problem, and maybe not... * Swapped the components ApcPowerReciver and GravityGenerator The previous "solution" did not give results, perhaps this time it will work.... * Revert "Swapped the components ApcPowerReciver and GravityGenerator" This reverts commit 38759ca5a3465908b97d1d7e6ca583f8e9a97afb. * Brought everything back to the beginning * One parent in generator prototype, test * Revert "One parent in generator prototype, test" This reverts commit f7275b5d53234d9f66e8b4df0692596e14d82c95. * Test without switchedOn and charge * Revert "Test without switchedOn and charge" This reverts commit 3916de8cc68e488098e6adc1e6b13e00d3f0e1a1. * Revert "Revert "Test without switchedOn and charge"" This reverts commit 3d95efbfd4cb358b5c04a2302a377d51eb5f34cc. * Update Resources/Prototypes/Entities/Structures/Machines/gravity_generator.yml --------- Co-authored-by: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> --- .../Gravity/GravityGeneratorComponent.cs | 10 +++++++- .../Gravity/GravityGeneratorSystem.cs | 14 ++++++++--- .../Circuitboards/Machine/production.yml | 16 ++++++++++++ .../Structures/Machines/gravity_generator.yml | 25 +++++++++++++++++-- .../Entities/Structures/Machines/lathe.yml | 1 + .../Prototypes/Recipes/Lathes/electronics.yml | 9 +++++++ Resources/Prototypes/Research/industrial.yml | 1 + 7 files changed, 70 insertions(+), 6 deletions(-) diff --git a/Content.Server/Gravity/GravityGeneratorComponent.cs b/Content.Server/Gravity/GravityGeneratorComponent.cs index 2ed325e52c..511fd49bdd 100644 --- a/Content.Server/Gravity/GravityGeneratorComponent.cs +++ b/Content.Server/Gravity/GravityGeneratorComponent.cs @@ -1,4 +1,6 @@ -using Content.Shared.Gravity; +using Content.Shared.Gravity; +using Content.Shared.Construction.Prototypes; +using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; namespace Content.Server.Gravity { @@ -29,9 +31,15 @@ namespace Content.Server.Gravity [DataField("intact")] public bool Intact { get; set; } = true; + [DataField("maxCharge")] + public float MaxCharge { get; set; } = 1; + // 0 -> 1 [ViewVariables(VVAccess.ReadWrite)] [DataField("charge")] public float Charge { get; set; } = 1; + [DataField("machinePartMaxChargeMultiplier", customTypeSerializer: typeof(PrototypeIdSerializer))] + public string MachinePartMaxChargeMultiplier = "Capacitor"; + /// /// Is the gravity generator currently "producing" gravity? /// diff --git a/Content.Server/Gravity/GravityGeneratorSystem.cs b/Content.Server/Gravity/GravityGeneratorSystem.cs index 930f2a8d4c..ad745ffa5d 100644 --- a/Content.Server/Gravity/GravityGeneratorSystem.cs +++ b/Content.Server/Gravity/GravityGeneratorSystem.cs @@ -7,6 +7,7 @@ using Content.Shared.Interaction; using Robust.Server.GameObjects; using Robust.Server.Player; using Robust.Shared.Players; +using Content.Server.Construction; namespace Content.Server.Gravity { @@ -26,6 +27,7 @@ namespace Content.Server.Gravity SubscribeLocalEvent(OnComponentShutdown); SubscribeLocalEvent(OnParentChanged); // Or just anchor changed? SubscribeLocalEvent(OnInteractHand); + SubscribeLocalEvent(OnRefreshParts); SubscribeLocalEvent( OnSwitchGenerator); } @@ -84,11 +86,11 @@ namespace Content.Server.Gravity var active = gravGen.GravityActive; var lastCharge = gravGen.Charge; - gravGen.Charge = Math.Clamp(gravGen.Charge + frameTime * chargeRate, 0, 1); + gravGen.Charge = Math.Clamp(gravGen.Charge + frameTime * chargeRate, 0, gravGen.MaxCharge); if (chargeRate > 0) { // Charging. - if (MathHelper.CloseTo(gravGen.Charge, 1) && !gravGen.GravityActive) + if (MathHelper.CloseTo(gravGen.Charge, gravGen.MaxCharge) && !gravGen.GravityActive) { gravGen.GravityActive = true; } @@ -158,7 +160,7 @@ namespace Content.Server.Gravity if (!_uiSystem.IsUiOpen(component.Owner, SharedGravityGeneratorComponent.GravityGeneratorUiKey.Key)) return; - var chargeTarget = chargeRate < 0 ? 0 : 1; + var chargeTarget = chargeRate < 0 ? 0 : component.MaxCharge; short chargeEta; var atTarget = false; if (MathHelper.CloseTo(component.Charge, chargeTarget)) @@ -255,6 +257,12 @@ namespace Content.Server.Gravity } } + private void OnRefreshParts(EntityUid uid, GravityGeneratorComponent component, RefreshPartsEvent args) + { + var maxChargeMultipler = args.PartRatings[component.MachinePartMaxChargeMultiplier]; + component.MaxCharge = maxChargeMultipler * 1; + } + private void MakeBroken(EntityUid uid, GravityGeneratorComponent component, AppearanceComponent? appearance) { _ambientSoundSystem.SetAmbience(component.Owner, false); diff --git a/Resources/Prototypes/Entities/Objects/Devices/Circuitboards/Machine/production.yml b/Resources/Prototypes/Entities/Objects/Devices/Circuitboards/Machine/production.yml index 5f4fced02f..defb13df04 100644 --- a/Resources/Prototypes/Entities/Objects/Devices/Circuitboards/Machine/production.yml +++ b/Resources/Prototypes/Entities/Objects/Devices/Circuitboards/Machine/production.yml @@ -941,3 +941,19 @@ Steel: 5 CableHV: 5 Cable: 2 + +- type: entity + parent: BaseMachineCircuitboard + id: MiniGravityGeneratorCircuitboard + name: mini gravity generator machine board + description: A machine printed circuit board for a mini gravity generator. + components: + - type: MachineBoard + prototype: GravityGeneratorMini + requirements: + Capacitor: 4 + MatterBin: 3 + materialRequirements: + Steel: 5 + CableHV: 5 + Uranium: 2 \ No newline at end of file diff --git a/Resources/Prototypes/Entities/Structures/Machines/gravity_generator.yml b/Resources/Prototypes/Entities/Structures/Machines/gravity_generator.yml index 9d1bf03efc..2658f68dfe 100644 --- a/Resources/Prototypes/Entities/Structures/Machines/gravity_generator.yml +++ b/Resources/Prototypes/Entities/Structures/Machines/gravity_generator.yml @@ -12,7 +12,6 @@ range: 7 sound: path: /Audio/Ambience/Objects/gravity_gen_hum.ogg - - type: Sprite sprite: Structures/Machines/gravity_generator.rsi layers: @@ -77,7 +76,7 @@ - type: entity id: GravityGeneratorMini - parent: GravityGenerator + parent: [ GravityGenerator, ConstructibleMachine ] name: mini gravity generator description: It's what keeps you to the floor, now in fun size. components: @@ -104,6 +103,28 @@ - LargeMobMask layer: - WallLayer + - type: Destructible + thresholds: + - trigger: + !type:DamageTrigger + damage: 500 + behaviors: + - !type:DoActsBehavior + acts: ["Destruction"] + - !type:PlaySoundBehavior + sound: + path: /Audio/Effects/metalbreak.ogg + - !type:SpawnEntitiesBehavior + spawn: + MachineFrameDestroyed: + min: 1 + max: 1 + - type: WiresPanel + - type: Wires + BoardName: "MiniGravityGenerator" + LayoutId: MiniGravityGenerator + - type: Machine + board: MiniGravityGeneratorCircuitboard - type: ApcPowerReceiver powerLoad: 500 - type: GravityGenerator diff --git a/Resources/Prototypes/Entities/Structures/Machines/lathe.yml b/Resources/Prototypes/Entities/Structures/Machines/lathe.yml index 49efcb3711..ada5159197 100644 --- a/Resources/Prototypes/Entities/Structures/Machines/lathe.yml +++ b/Resources/Prototypes/Entities/Structures/Machines/lathe.yml @@ -347,6 +347,7 @@ - EmitterCircuitboard - ThrusterMachineCircuitboard - GyroscopeMachineCircuitboard + - MiniGravityGeneratorCircuitboard - GasRecyclerMachineCircuitboard - SeedExtractorMachineCircuitboard - AnalysisComputerCircuitboard diff --git a/Resources/Prototypes/Recipes/Lathes/electronics.yml b/Resources/Prototypes/Recipes/Lathes/electronics.yml index 8a5a5a2996..e9dcd8f181 100644 --- a/Resources/Prototypes/Recipes/Lathes/electronics.yml +++ b/Resources/Prototypes/Recipes/Lathes/electronics.yml @@ -661,3 +661,12 @@ materials: Steel: 100 Glass: 900 + +- type: latheRecipe + id: MiniGravityGeneratorCircuitboard + result: MiniGravityGeneratorCircuitboard + completetime: 6 + materials: + Steel: 100 + Glass: 900 + Gold: 100 diff --git a/Resources/Prototypes/Research/industrial.yml b/Resources/Prototypes/Research/industrial.yml index c262b067b6..5ea36788ec 100644 --- a/Resources/Prototypes/Research/industrial.yml +++ b/Resources/Prototypes/Research/industrial.yml @@ -129,6 +129,7 @@ - RadarConsoleCircuitboard - ThrusterMachineCircuitboard - GyroscopeMachineCircuitboard + - MiniGravityGeneratorCircuitboard - type: technology id: RipleyAPLU