From ddabab35ea7ab30abeb15a72d01f3797f3a2c743 Mon Sep 17 00:00:00 2001 From: Rinary Date: Fri, 1 Nov 2024 16:37:15 +0200 Subject: [PATCH] upd charge system --- Content.Server/_Sunrise/Synth/SynthSystem.cs | 38 +++++++------------ .../_Sunrise/Entities/Mobs/Player/synth.yml | 9 +++++ .../_Sunrise/Entities/Mobs/Species/synth.yml | 2 +- 3 files changed, 23 insertions(+), 26 deletions(-) diff --git a/Content.Server/_Sunrise/Synth/SynthSystem.cs b/Content.Server/_Sunrise/Synth/SynthSystem.cs index 16bf67619d7..f40522a13b7 100644 --- a/Content.Server/_Sunrise/Synth/SynthSystem.cs +++ b/Content.Server/_Sunrise/Synth/SynthSystem.cs @@ -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; @@ -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; @@ -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!; @@ -54,9 +56,6 @@ public sealed class SynthSystem : SharedSynthSystem private ISawmill _sawmill = default!; - [ValidatePrototypeId] - private const string SynthChargeAlert = "SynthCharge"; - public override void Initialize() { base.Initialize(); @@ -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(content, out var PowerCellComp)) { - if (!TryComp(partOrgan.Id, out batteryComponent)) - continue; - - battery = partOrgan.Id; - + powercell = content; + powercellComponent = PowerCellComp; + return true; } } @@ -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); diff --git a/Resources/Prototypes/_Sunrise/Entities/Mobs/Player/synth.yml b/Resources/Prototypes/_Sunrise/Entities/Mobs/Player/synth.yml index 62ee882fe7a..2e49ec6c79f 100644 --- a/Resources/Prototypes/_Sunrise/Entities/Mobs/Player/synth.yml +++ b/Resources/Prototypes/_Sunrise/Entities/Mobs/Player/synth.yml @@ -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 \ No newline at end of file diff --git a/Resources/Prototypes/_Sunrise/Entities/Mobs/Species/synth.yml b/Resources/Prototypes/_Sunrise/Entities/Mobs/Species/synth.yml index f1c72781e1d..b7f5ad5febc 100644 --- a/Resources/Prototypes/_Sunrise/Entities/Mobs/Species/synth.yml +++ b/Resources/Prototypes/_Sunrise/Entities/Mobs/Species/synth.yml @@ -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