Better robotics console (#38023)

This commit is contained in:
Samuka-C
2025-08-11 15:57:39 -03:00
committed by GitHub
parent 47d7db0665
commit ed6f906e6f
6 changed files with 102 additions and 15 deletions

View File

@@ -95,6 +95,9 @@ public sealed class RoboticsConsoleSystem : SharedRoboticsConsoleSystem
private void OnDisable(Entity<RoboticsConsoleComponent> ent, ref RoboticsConsoleDisableMessage args)
{
if (!ent.Comp.AllowBorgControl)
return;
if (_lock.IsLocked(ent.Owner))
return;
@@ -112,6 +115,9 @@ public sealed class RoboticsConsoleSystem : SharedRoboticsConsoleSystem
private void OnDestroy(Entity<RoboticsConsoleComponent> ent, ref RoboticsConsoleDestroyMessage args)
{
if (!ent.Comp.AllowBorgControl)
return;
if (_lock.IsLocked(ent.Owner))
return;
@@ -139,7 +145,7 @@ public sealed class RoboticsConsoleSystem : SharedRoboticsConsoleSystem
private void UpdateUserInterface(Entity<RoboticsConsoleComponent> ent)
{
var state = new RoboticsConsoleState(ent.Comp.Cyborgs);
var state = new RoboticsConsoleState(ent.Comp.Cyborgs, ent.Comp.AllowBorgControl);
_ui.SetUiState(ent.Owner, RoboticsConsoleUiKey.Key, state);
}
}

View File

@@ -1,4 +1,9 @@
using Content.Shared.Containers.ItemSlots;
using Content.Shared.DeviceNetwork;
using Content.Shared.Damage;
using Content.Shared.FixedPoint;
using Content.Shared.Mobs;
using Content.Shared.Mobs.Systems;
using Content.Shared.Movement.Components;
using Content.Shared.Popups;
using Content.Shared.Robotics;
@@ -14,6 +19,9 @@ namespace Content.Server.Silicons.Borgs;
public sealed partial class BorgSystem
{
[Dependency] private readonly EmagSystem _emag = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly MobThresholdSystem _mobThresholdSystem = default!;
[Dependency] private readonly ItemSlotsSystem _itemSlotsSystem = default!;
private void InitializeTransponder()
{
@@ -28,7 +36,7 @@ public sealed partial class BorgSystem
var query = EntityQueryEnumerator<BorgTransponderComponent, BorgChassisComponent, DeviceNetworkComponent, MetaDataComponent>();
while (query.MoveNext(out var uid, out var comp, out var chassis, out var device, out var meta))
{
if (comp.NextDisable is {} nextDisable && now >= nextDisable)
if (comp.NextDisable is { } nextDisable && now >= nextDisable)
DoDisable((uid, comp, chassis, meta));
if (now < comp.NextBroadcast)
@@ -38,13 +46,17 @@ public sealed partial class BorgSystem
if (_powerCell.TryGetBatteryFromSlot(uid, out var battery))
charge = battery.CurrentCharge / battery.MaxCharge;
var hasBrain = chassis.BrainEntity != null && !comp.FakeDisabled;
var hpPercent = CalcHP(uid);
// checks if it has a brain and if the brain is not a empty MMI (gives false anyway if the fake disable is true)
var hasBrain = CheckBrain(chassis.BrainEntity) && !comp.FakeDisabled;
var canDisable = comp.NextDisable == null && !comp.FakeDisabling;
var data = new CyborgControlData(
comp.Sprite,
comp.Name,
meta.EntityName,
charge,
hpPercent,
chassis.ModuleCount,
hasBrain,
canDisable);
@@ -70,7 +82,7 @@ public sealed partial class BorgSystem
return;
}
if (ent.Comp2.BrainEntity is not {} brain)
if (ent.Comp2.BrainEntity is not { } brain)
return;
var message = Loc.GetString(ent.Comp1.DisabledPopup, ("name", Name(ent, ent.Comp3)));
@@ -151,4 +163,40 @@ public sealed partial class BorgSystem
{
ent.Comp.Name = name;
}
/// <summary>
/// Returns a ratio between 0 and 1, 1 when they have no damage and 0 whenever they are crit (or more damaged)
/// </summary>
private float CalcHP(EntityUid uid)
{
if (!TryComp<DamageableComponent>(uid, out var damageable))
return 1;
if (!_mobState.IsAlive(uid))
return 0;
if (!_mobThresholdSystem.TryGetThresholdForState(uid, MobState.Critical, out var threshold))
{
Log.Error($"Borg({ToPrettyString(uid)}), doesn't have critical threshold.");
return 1;
}
return 1 - ((FixedPoint2)(damageable.TotalDamage / threshold)).Float();
}
/// <summary>
/// Returns true if the borg has a brain
/// </summary>
private bool CheckBrain(EntityUid? brainEntity)
{
if (brainEntity == null)
return false;
// if the brainEntity.Value has the component MMIComponent then it is a MMI,
// in that case it trys to get the "brain" of the MMI, if it is null the MMI is empty and so it returns false
if (TryComp<MMIComponent>(brainEntity.Value, out var mmi) && _itemSlotsSystem.GetItemOrNull(brainEntity.Value, mmi.BrainSlotId) == null)
return false;
return true;
}
}