mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-16 21:17:39 +03:00
* Laws * positronic brain and PAI rewrite * MMI * MMI pt. 2 * borg brain transfer * Roleban support, Borg job (WIP), the end of mind shenaniganry * battery drain, item slot cleanup, alerts * visuals * fix this pt1 * fix this pt2 * Modules, Lingering Stacks, Better borg flashlight * Start on UI, fix battery alerts, expand activation/deactivation, low movement speed on no power. * sprotes * no zombie borgs * oh fuck yeah i love a good relay * charger * fix the tiniest of sprite issues * adjustable names * a functional UI???? * foobar * more modules * this shit for some reason * upstream * genericize selectable borg modules * upstream again * holy fucking shit * i love christ * proper construction * da job * AA borgs * and boom more shit * admin logs * laws redux * ok just do this rq * oh boy that looks like modules * oh shit research * testos passo * so much shit holy fuck * fuckit we SHIP * last minute snags * should've gotten me on a better day
109 lines
4.2 KiB
C#
109 lines
4.2 KiB
C#
using System.Linq;
|
|
using Content.Server.UserInterface;
|
|
using Content.Shared.Database;
|
|
using Content.Shared.NameIdentifier;
|
|
using Content.Shared.PowerCell.Components;
|
|
using Content.Shared.Preferences;
|
|
using Content.Shared.Silicons.Borgs;
|
|
using Content.Shared.Silicons.Borgs.Components;
|
|
|
|
namespace Content.Server.Silicons.Borgs;
|
|
|
|
/// <inheritdoc/>
|
|
public sealed partial class BorgSystem
|
|
{
|
|
public void InitializeUI()
|
|
{
|
|
SubscribeLocalEvent<BorgChassisComponent, BeforeActivatableUIOpenEvent>(OnBeforeBorgUiOpen);
|
|
SubscribeLocalEvent<BorgChassisComponent, BorgEjectBrainBuiMessage>(OnEjectBrainBuiMessage);
|
|
SubscribeLocalEvent<BorgChassisComponent, BorgEjectBatteryBuiMessage>(OnEjectBatteryBuiMessage);
|
|
SubscribeLocalEvent<BorgChassisComponent, BorgSetNameBuiMessage>(OnSetNameBuiMessage);
|
|
SubscribeLocalEvent<BorgChassisComponent, BorgRemoveModuleBuiMessage>(OnRemoveModuleBuiMessage);
|
|
}
|
|
|
|
private void OnBeforeBorgUiOpen(EntityUid uid, BorgChassisComponent component, BeforeActivatableUIOpenEvent args)
|
|
{
|
|
UpdateUI(uid, component);
|
|
}
|
|
|
|
private void OnEjectBrainBuiMessage(EntityUid uid, BorgChassisComponent component, BorgEjectBrainBuiMessage args)
|
|
{
|
|
if (args.Session.AttachedEntity is not { } attachedEntity || component.BrainEntity is not { } brain)
|
|
return;
|
|
|
|
_adminLog.Add(LogType.Action, LogImpact.Medium,
|
|
$"{ToPrettyString(attachedEntity):player} removed brain {ToPrettyString(brain)} from borg {ToPrettyString(uid)}");
|
|
component.BrainContainer.Remove(brain, EntityManager);
|
|
_hands.TryPickupAnyHand(attachedEntity, brain);
|
|
UpdateUI(uid, component);
|
|
}
|
|
|
|
private void OnEjectBatteryBuiMessage(EntityUid uid, BorgChassisComponent component, BorgEjectBatteryBuiMessage args)
|
|
{
|
|
if (args.Session.AttachedEntity is not { } attachedEntity ||
|
|
!TryComp<PowerCellSlotComponent>(uid, out var slotComp) ||
|
|
!Container.TryGetContainer(uid, slotComp.CellSlotId, out var container) ||
|
|
!container.ContainedEntities.Any())
|
|
{
|
|
return;
|
|
}
|
|
|
|
var ents = Container.EmptyContainer(container);
|
|
_hands.TryPickupAnyHand(attachedEntity, ents.First());
|
|
}
|
|
|
|
private void OnSetNameBuiMessage(EntityUid uid, BorgChassisComponent component, BorgSetNameBuiMessage args)
|
|
{
|
|
if (args.Session.AttachedEntity is not { } attachedEntity)
|
|
return;
|
|
|
|
if (args.Name.Length > HumanoidCharacterProfile.MaxNameLength ||
|
|
args.Name.Length == 0 ||
|
|
string.IsNullOrWhiteSpace(args.Name) ||
|
|
string.IsNullOrEmpty(args.Name))
|
|
{
|
|
return;
|
|
}
|
|
|
|
var name = args.Name.Trim();
|
|
if (TryComp<NameIdentifierComponent>(uid, out var identifier))
|
|
name = $"{name} {identifier.FullIdentifier}";
|
|
|
|
_metaData.SetEntityName(uid, name);
|
|
_adminLog.Add(LogType.Action, LogImpact.High, $"{ToPrettyString(attachedEntity):player} set borg \"{ToPrettyString(uid)}\"'s name to: {name}");
|
|
}
|
|
|
|
private void OnRemoveModuleBuiMessage(EntityUid uid, BorgChassisComponent component, BorgRemoveModuleBuiMessage args)
|
|
{
|
|
if (args.Session.AttachedEntity is not { } attachedEntity)
|
|
return;
|
|
|
|
if (!component.ModuleContainer.Contains(args.Module))
|
|
return;
|
|
|
|
_adminLog.Add(LogType.Action, LogImpact.Medium,
|
|
$"{ToPrettyString(attachedEntity):player} removed module {ToPrettyString(args.Module)} from borg {ToPrettyString(uid)}");
|
|
component.ModuleContainer.Remove(args.Module);
|
|
_hands.TryPickupAnyHand(attachedEntity, args.Module);
|
|
|
|
UpdateUI(uid, component);
|
|
}
|
|
|
|
public void UpdateUI(EntityUid uid, BorgChassisComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component))
|
|
return;
|
|
|
|
var chargePercent = 0f;
|
|
var hasBattery = false;
|
|
if (_powerCell.TryGetBatteryFromSlot(uid, out var battery))
|
|
{
|
|
hasBattery = true;
|
|
chargePercent = battery.Charge / battery.MaxCharge;
|
|
}
|
|
|
|
var state = new BorgBuiState(chargePercent, hasBattery);
|
|
_ui.TrySetUiState(uid, BorgUiKey.Key, state);
|
|
}
|
|
}
|