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>
This commit is contained in:
Арт
2023-08-15 03:23:40 +03:00
committed by GitHub
parent a13da27905
commit a7583eb525
7 changed files with 70 additions and 6 deletions

View File

@@ -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<GravityGeneratorComponent, ComponentShutdown>(OnComponentShutdown);
SubscribeLocalEvent<GravityGeneratorComponent, EntParentChangedMessage>(OnParentChanged); // Or just anchor changed?
SubscribeLocalEvent<GravityGeneratorComponent, InteractHandEvent>(OnInteractHand);
SubscribeLocalEvent<GravityGeneratorComponent, RefreshPartsEvent>(OnRefreshParts);
SubscribeLocalEvent<GravityGeneratorComponent, SharedGravityGeneratorComponent.SwitchGeneratorMessage>(
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);