using Robust.Server.GameObjects.Components.UserInterface; using Robust.Server.Interfaces.GameObjects; using Robust.Shared.GameObjects; using System.Collections.Generic; using Content.Shared.BodySystem; using Content.Shared.Interfaces.GameObjects.Components; namespace Content.Server.BodySystem { [RegisterComponent] [ComponentReference(typeof(IActivate))] public class BodyScannerComponent : Component, IActivate { public sealed override string Name => "BodyScanner"; private BoundUserInterface _userInterface; public override void Initialize() { base.Initialize(); _userInterface = Owner.GetComponent().GetBoundUserInterface(BodyScannerUiKey.Key); _userInterface.OnReceiveMessage += UserInterfaceOnOnReceiveMessage; } private void UserInterfaceOnOnReceiveMessage(ServerBoundUserInterfaceMessage serverMsg) { } void IActivate.Activate(ActivateEventArgs eventArgs) { if (!eventArgs.User.TryGetComponent(out IActorComponent actor)) { return; } if (actor.playerSession.AttachedEntity.TryGetComponent(out BodyManagerComponent attempt)) { _userInterface.SetState(PrepareBodyScannerInterfaceState(attempt.Template, attempt.PartDictionary)); } _userInterface.Open(actor.playerSession); } /// /// Copy BodyTemplate and BodyPart data into a common data class that the client can read. /// private BodyScannerInterfaceState PrepareBodyScannerInterfaceState(BodyTemplate template, Dictionary bodyParts) { Dictionary partsData = new Dictionary(); foreach (var(slotname, bpart) in bodyParts) { List mechanismData = new List(); foreach (var mech in bpart.Mechanisms) { mechanismData.Add(new BodyScannerMechanismData(mech.Name, mech.Description, mech.RSIPath, mech.RSIState, mech.MaxDurability, mech.CurrentDurability)); } partsData.Add(slotname, new BodyScannerBodyPartData(bpart.Name, bpart.RSIPath, bpart.RSIState, bpart.MaxDurability, bpart.CurrentDurability, mechanismData)); } BodyScannerTemplateData templateData = new BodyScannerTemplateData(template.Name, template.Slots); return new BodyScannerInterfaceState(partsData, templateData); } } }