Skip to content

Commit

Permalink
upd charge system
Browse files Browse the repository at this point in the history
  • Loading branch information
Rinary1 committed Nov 1, 2024
1 parent 35ebcfb commit ddabab3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 26 deletions.
38 changes: 13 additions & 25 deletions Content.Server/_Sunrise/Synth/SynthSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Content.Shared.Mobs.Components;
using Content.Shared.Movement.Systems;
using Content.Shared.Popups;
using Content.Shared.PowerCell;
using Content.Shared.Rejuvenate;
using Content.Shared.Rounding;
using Content.Shared.Stunnable;
Expand All @@ -26,6 +27,7 @@
using Content.Shared.Verbs;
using Robust.Shared.Utility;
using Robust.Server.GameObjects;
using Robust.Server.Containers;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
Expand All @@ -37,9 +39,9 @@ public sealed class SynthSystem : SharedSynthSystem
{
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly AlertsSystem _alerts = default!;
[Dependency] private readonly SharedAudioSystem _audioSystem = default!;
[Dependency] private readonly BatterySystem _batterySystem = default!;
[Dependency] private readonly ContainerSystem _containerSystem = default!;
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
[Dependency] private readonly BodySystem _bodySystem = default!;
[Dependency] private readonly MovementSpeedModifierSystem _movementSpeedModifier = default!;
Expand All @@ -54,9 +56,6 @@ public sealed class SynthSystem : SharedSynthSystem

private ISawmill _sawmill = default!;

[ValidatePrototypeId<AlertPrototype>]
private const string SynthChargeAlert = "SynthCharge";

public override void Initialize()
{
base.Initialize();
Expand Down Expand Up @@ -230,29 +229,22 @@ private void OnDrain(EntityUid uid, EntityUid user, SynthComponent component)
_doAfter.TryStartDoAfter(doAfterArgs);
}

private bool TryGetBattery(EntityUid uid, [NotNullWhen(true)] out EntityUid? battery, [NotNullWhen(true)] out BatteryComponent? batteryComponent)
private bool TryGetBattery(EntityUid uid, [NotNullWhen(true)] out EntityUid? powercell, [NotNullWhen(true)] out PowerCellComponent? powercellComponent)
{
battery = null;
batteryComponent = null;
powercell = null;
powercellComponent = null;

var bodyContainers = _bodySystem.GetBodyContainers(uid);

foreach (var container in bodyContainers)
if (_containerSystem.TryGetContainer(uid, "cell_slot", out var container) && container.ContainedEntities.Count > 0)
{
if (container.ID != "body_root_part")
continue;

foreach (var containerContainedEntity in container.ContainedEntities)
foreach (var content in container.ContainedEntities)
{
var partOrgans = _bodySystem.GetPartOrgans(containerContainedEntity);

foreach (var partOrgan in partOrgans)
if (TryComp<PowerCellComponent>(content, out var PowerCellComp))
{
if (!TryComp(partOrgan.Id, out batteryComponent))
continue;

battery = partOrgan.Id;

powercell = content;
powercellComponent = PowerCellComp;

return true;
}
}
Expand Down Expand Up @@ -310,10 +302,6 @@ private bool TryChangeEnergy(EntityUid uid, FixedPoint2 delta, SynthComponent? c
if (!TryGetBattery(uid, out var battery, out var batteryComponent))
return false;

var severity = ContentHelpers.RoundToNearestLevels(MathF.Max(0f, component.Energy.Float()), component.MaxEnergy.Float(), 4);

_alerts.ShowAlert(uid, SynthChargeAlert, (short) severity);

var newEnergy = FixedPoint2.Clamp(component.Energy + delta, 0, component.MaxEnergy);

_batterySystem.SetCharge(battery.Value, newEnergy.Float(), batteryComponent);
Expand Down
9 changes: 9 additions & 0 deletions Resources/Prototypes/_Sunrise/Entities/Mobs/Player/synth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,12 @@
- type: NpcFactionMember
factions:
- NanoTrasen
- type: ContainerFill
containers:
synth_brain:
- PositronicBrain
- type: ItemSlots
slots:
cell_slot:
name: power-cell-slot-component-slot-name-default
startingItem: PowerCellMedium
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@
- type: ActivatableUIRequiresPanel
- type: ContainerContainer
containers:
borg_brain: !type:ContainerSlot { }
synth_brain: !type:ContainerSlot { }
cell_slot: !type:ContainerSlot { }
borg_module: !type:Container { }
part-container: !type:Container
Expand Down

0 comments on commit ddabab3

Please sign in to comment.