-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Battery draining seems to be broken right now, reporting 0 charge at all times. Will fix soon.
- Loading branch information
1 parent
e4cd838
commit 3420c0e
Showing
11 changed files
with
182 additions
and
91 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
Content.Server/SimpleStation14/Power/Components/RandomBatteryChargeComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace Content.Server.SimpleStation14.Power.Components; | ||
|
||
[RegisterComponent] | ||
public class RandomBatteryChargeComponent : Component | ||
{ | ||
/// <summary> | ||
/// The minimum and maximum max charge the battery can have. | ||
/// </summary> | ||
[DataField("batteryMaxMinMax")] | ||
public Vector2 BatteryMaxMinMax = (0.85f, 1.15f); | ||
|
||
/// <summary> | ||
/// The minimum and maximum current charge the battery can have. | ||
/// </summary> | ||
[DataField("batteryChargeMinMax")] | ||
public Vector2 BatteryChargeMinMax = (1f, 1f); | ||
|
||
/// <summary> | ||
/// True if the current charge is based on the preexisting current charge, or false if it's based on the max charge. | ||
/// </summary> | ||
[DataField("basedOnMaxCharge")] | ||
public bool BasedOnMaxCharge = false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
Content.Server/SimpleStation14/Power/Systems/RandomBatteryChargeSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using Content.Server.Power.Components; | ||
using Content.Server.Power.EntitySystems; | ||
using Content.Server.SimpleStation14.Power.Components; | ||
using Robust.Shared.Random; | ||
using Robust.Shared.Utility; | ||
|
||
namespace Content.Server.SimpleStation14.Power.Systems; | ||
|
||
public sealed class RandomBatteryFillSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly BatterySystem _battery = default!; | ||
[Dependency] private readonly IRobustRandom _random = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<RandomBatteryChargeComponent, ComponentInit>(OnBatteryInit); | ||
} | ||
|
||
private void OnBatteryInit(EntityUid uid, RandomBatteryChargeComponent component, ComponentInit args) | ||
{ | ||
var batteryComp = Comp<BatteryComponent>(uid); | ||
DebugTools.AssertNotNull(batteryComp); | ||
|
||
if (batteryComp == null) | ||
return; | ||
|
||
var (minMaxMod, maxMaxMod) = component.BatteryMaxMinMax; | ||
var (minChargeMod, maxChargeMod) = component.BatteryChargeMinMax; | ||
|
||
var newMax = batteryComp.MaxCharge * _random.NextFloat(minMaxMod, maxMaxMod); | ||
float newCharge; | ||
|
||
if (component.BasedOnMaxCharge) | ||
newCharge = newMax * _random.NextFloat(minChargeMod, maxChargeMod); | ||
else | ||
newCharge = batteryComp.CurrentCharge * _random.NextFloat(minChargeMod, maxChargeMod); | ||
|
||
_battery.SetMaxCharge(uid, newMax); | ||
_battery.SetCharge(uid, newCharge); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.