* Add art assets for cloning

* Added a 'Scan DNA' button to the medical scanner

* Made the UI update unconditional for the medical scanner until checks for power changes are in place

* Update Medical scanner to reflect powered status and fix #1774

* added a 'scan dna' button the the medical scanner that will add the contained bodies Uid to a list in CloningSystem, fixed an issue with the menu not populating if the scanner starts in an unpowered state

* Add disabling logic to 'Scan DNA' button on medical scanner

* Removed un-used libraries

* changed scan dna button to Scan and Save DNA

* Added cloning machine code infrastructure copied from Medical Scanner

* Added a list to cloning menu containing some numbers

* Cloning Machine UI sends a message to the cloning component with the entityUID

* New scans now show up in cloning pod menu

* fixed cloning machine collision shape

* cloning machine can now spawn the right player profile assuming the attatched entity is still correct.

* refactored cloning system to use a map of integer ids to player Minds

* Added a return to body cloning loop for the ghost

* Fixed warning for _playerManager being possibly null, added TODO note for ghost return to body button acting as a toggle

* removed #nullable from cloningMachineWindow"

* Trying to get rid of nullable error

* fix CloningMachine to not initilize with it's owner components

* updated CloningMachine server component to play nice with the new nullable rules

* replace flag with eventBus message for sending a ghosts mind to a clone body

* Refactor cloning so that a popup option is used to get user consent for cloning

* Refactoring

* Reverting unused changes for cloning component

* Added proper cloning pod sprites and a visualizer so 'idle' and 'cloning' states are properly reflected

* added missing robust toolbox contents

* Added cloning NoMind State and made cloning take time

* Added cloning progress bar and mind status indicator to cloning pod

* Added missing localization calls, removeed 'returned to cloned body' from ghostUI

* Added unsubscribe for cloningStartedMessage in Mindcomponent.cs OnRemove

* Added eject button to cloningMachine and clamped the cloning progress bar to 100%

* Added condition to eject body on cloningmachine so bodies can't be ejected until cloning is done

* Add click-dragOn functionality to the medical scanner for things with a bodyManager

* Messed with scan query so it doesn't fail on dead bodies as long as Mind still owns the mob

* refactored clonning scan check on medical scanner so it doesn't do a linq query

* merge with rogue toolbox

* Change the name of Cloning Machine to the less generic Cloning Pod

* Changed Cloning Pod so it pauses cloning while the power is out

* Removed the evil LocalizationManager from the cloning menus and used the static Loc instead

* removed localization dependency from bound accpetCloning user interface

* Removed Ilocalization dependency I accidentally added to ghost ui

* Update Content.Client/GameObjects/Components/MedicalScanner/MedicalScannerComponent.cs

Co-authored-by: Exp <theexp111@gmail.com>

* Changed null check to tryget in case for cloning UiButton.Clone

* Parameterized Cloning time on serverside component

* tried to reset Robust toolbox module to current master

* Added null check to ghost client component message handling, unsubscribe to the mind component listening to the cloning question ui, fixed _clonningProgress typo, moved CloningPod component dependencies to actually be dependencies, removed un-needed disposals of cloning windows, added disposals missing in boundUserInterfaces.

* Reset submodule

* corrected exception for cloning pod visualizer to refer to cloning pod state and not medical scanner state

* Fix typo

* Unsubscribe from onUiReceiveMessage in mindcomponent in the onRemove function, not the acceptcloningui function

* unsubscribe from OnUiReceiveMessage in CloningPodComponent

* unssubscribe from ghostreturn message in cloningpodComponent onRemove

Co-authored-by: Exp <theexp111@gmail.com>
Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
This commit is contained in:
SoulSloth
2020-09-02 06:07:54 -04:00
committed by GitHub
parent 95665d184f
commit e40e3fa267
36 changed files with 1276 additions and 37 deletions

View File

@@ -0,0 +1,45 @@
using Content.Shared.GameObjects.Components;
using JetBrains.Annotations;
using Robust.Client.GameObjects.Components.UserInterface;
namespace Content.Client.GameObjects.Components
{
[UsedImplicitly]
public class AcceptCloningBoundUserInterface : BoundUserInterface
{
public AcceptCloningBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey)
{
}
private AcceptCloningWindow _window;
protected override void Open()
{
base.Open();
_window = new AcceptCloningWindow();
_window.OnClose += Close;
_window.DenyButton.OnPressed += _ => _window.Close();
_window.ConfirmButton.OnPressed += _ =>
{
SendMessage(
new SharedAcceptCloningComponent.UiButtonPressedMessage(
SharedAcceptCloningComponent.UiButton.Accept));
_window.Close();
};
_window.OpenCentered();
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
_window?.Dispose();
}
}
}
}

View File

@@ -0,0 +1,50 @@
#nullable enable
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.Localization;
namespace Content.Client.GameObjects.Components
{
public sealed class AcceptCloningWindow : SS14Window
{
public readonly Button DenyButton;
public readonly Button ConfirmButton;
public AcceptCloningWindow()
{
Title = Loc.GetString("Cloning Machine");
Contents.AddChild(new VBoxContainer
{
Children =
{
new VBoxContainer
{
Children =
{
(new Label
{
Text = Loc.GetString("You are being cloned! Transfer your soul to the clone body?")
}),
new HBoxContainer
{
Children =
{
(ConfirmButton = new Button
{
Text = Loc.GetString("Yes"),
}),
(DenyButton = new Button
{
Text = Loc.GetString("No"),
})
}
},
}
},
}
});
}
}
}

View File

@@ -2,6 +2,7 @@
using System.Linq;
using Content.Client.GameObjects.Components.Mobs;
using Content.Client.UserInterface;
using Content.Shared.GameObjects.Components.Mobs;
using Content.Shared.Input;
using Robust.Client.GameObjects;
using Robust.Client.Interfaces.Input;

View File

@@ -1,8 +1,10 @@
#nullable enable
using Content.Client.GameObjects.Components.Disposal;
using Content.Client.GameObjects.Components.MedicalScanner;
using Content.Client.Interfaces.GameObjects.Components.Interaction;
using Content.Shared.GameObjects.Components.Body;
using Content.Shared.GameObjects.Components.Damage;
using Content.Shared.GameObjects.Components.Medical;
using Robust.Client.Interfaces.GameObjects.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
@@ -21,7 +23,13 @@ namespace Content.Client.GameObjects.Components.Body
public bool ClientCanDropOn(CanDropEventArgs eventArgs)
{
return eventArgs.Target.HasComponent<DisposalUnitComponent>();
if (
eventArgs.Target.HasComponent<DisposalUnitComponent>()||
eventArgs.Target.HasComponent<MedicalScannerComponent>())
{
return true;
}
return false;
}
public bool ClientCanDrag(CanDragEventArgs eventArgs)

View File

@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using Content.Shared.GameObjects.Components.Medical;
using JetBrains.Annotations;
using Robust.Client.GameObjects.Components.UserInterface;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.UserInterface;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using static Content.Shared.GameObjects.Components.Medical.SharedCloningPodComponent;
namespace Content.Client.GameObjects.Components.CloningPod
{
[UsedImplicitly]
public class CloningPodBoundUserInterface : BoundUserInterface
{
public CloningPodBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey)
{
}
private CloningPodWindow _window;
protected override void Open()
{
base.Open();
_window = new CloningPodWindow(new Dictionary<int, string>());
_window.OnClose += Close;
_window.CloneButton.OnPressed += _ =>
{
if (_window.SelectedScan != null)
{
SendMessage(new CloningPodUiButtonPressedMessage(UiButton.Clone, (int) _window.SelectedScan));
}
};
_window.EjectButton.OnPressed += _ =>
{
SendMessage(new CloningPodUiButtonPressedMessage(UiButton.Eject, null));
};
_window.OpenCentered();
}
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
_window.Populate((CloningPodBoundUserInterfaceState) state);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
_window?.Dispose();
}
}
}
}

View File

@@ -0,0 +1,41 @@
using System;
using Content.Shared.GameObjects.Components.Medical;
using Robust.Client.GameObjects;
using Robust.Client.Interfaces.GameObjects.Components;
using static Content.Shared.GameObjects.Components.Medical.SharedCloningPodComponent;
using static Content.Shared.GameObjects.Components.Medical.SharedCloningPodComponent.CloningPodStatus;
namespace Content.Client.GameObjects.Components.CloningPod
{
public class CloningPodVisualizer : AppearanceVisualizer
{
public override void OnChangeData(AppearanceComponent component)
{
base.OnChangeData(component);
var sprite = component.Owner.GetComponent<ISpriteComponent>();
if (!component.TryGetData(CloningPodVisuals.Status, out CloningPodStatus status)) return;
sprite.LayerSetState(CloningPodVisualLayers.Machine, StatusToMachineStateId(status));
}
private string StatusToMachineStateId(CloningPodStatus status)
{
//TODO: implement NoMind for if the mind is not yet in the body
//TODO: Find a use for GORE POD
switch (status)
{
case Cloning: return "pod_1";
case NoMind: return "pod_e";
case Gore: return "pod_g";
case Idle: return "pod_0";
default:
throw new ArgumentOutOfRangeException(nameof(status), status, "unknown CloningPodStatus");
}
}
public enum CloningPodVisualLayers
{
Machine,
}
}
}

View File

@@ -0,0 +1,442 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.Localization;
using Robust.Shared.Maths;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
using Robust.Shared.Localization;
using static Content.Shared.GameObjects.Components.Medical.SharedCloningPodComponent;
namespace Content.Client.GameObjects.Components.CloningPod
{
public sealed class CloningPodWindow : SS14Window
{
private Dictionary<int, string> _scanManager;
private readonly VBoxContainer _mainVBox;
private readonly ScanListContainer _scanList;
private readonly LineEdit _searchBar;
private readonly Button _clearButton;
public readonly Button CloneButton;
public readonly Button EjectButton;
private readonly CloningScanButton _measureButton;
private CloningScanButton? _selectedButton;
private Label _progressLabel;
private readonly ProgressBar _cloningProgressBar;
private Label _mindState;
protected override Vector2 ContentsMinimumSize => _mainVBox?.CombinedMinimumSize ?? Vector2.Zero;
private CloningPodBoundUserInterfaceState _lastUpdate = null!;
// List of scans that are visible based on current filter criteria.
private readonly Dictionary<int, string> _filteredScans = new Dictionary<int, string>();
// The indices of the visible scans last time UpdateVisibleScans was ran.
// This is inclusive, so end is the index of the last scan, not right after it.
private (int start, int end) _lastScanIndices;
public int? SelectedScan;
protected override Vector2? CustomSize => (250, 300);
public CloningPodWindow(
Dictionary<int, string> scanManager)
{
_scanManager = scanManager;
Title = Loc.GetString("Cloning Machine");
Contents.AddChild(_mainVBox = new VBoxContainer
{
Children =
{
new HBoxContainer
{
Children =
{
(_searchBar = new LineEdit
{
SizeFlagsHorizontal = SizeFlags.FillExpand,
PlaceHolder = Loc.GetString("Search")
}),
(_clearButton = new Button
{
Disabled = true,
Text = Loc.GetString("Clear"),
})
}
},
new ScrollContainer
{
CustomMinimumSize = new Vector2(200.0f, 0.0f),
SizeFlagsVertical = SizeFlags.FillExpand,
Children =
{
(_scanList = new ScanListContainer())
}
},
new VBoxContainer
{
Children =
{
(CloneButton = new Button
{
Text = Loc.GetString("Clone")
})
}
},
(_measureButton = new CloningScanButton {Visible = false}),
(_cloningProgressBar = new ProgressBar
{
CustomMinimumSize = (200, 20),
SizeFlagsHorizontal = SizeFlags.Fill,
MinValue = 0,
MaxValue = 10,
Page = 0,
Value = 0.5f,
Children =
{
(_progressLabel = new Label())
}
}),
(EjectButton = new Button
{
Text = Loc.GetString("Eject Body")
}),
new HBoxContainer
{
Children =
{
new Label()
{
Text = Loc.GetString("Neural Interface: ")
},
(_mindState = new Label()
{
Text = Loc.GetString("No Activity"),
FontColorOverride = Color.Red
}),
}
}
}
});
_searchBar.OnTextChanged += OnSearchBarTextChanged;
_clearButton.OnPressed += OnClearButtonPressed;
BuildEntityList();
_searchBar.GrabKeyboardFocus();
}
public void Populate(CloningPodBoundUserInterfaceState state)
{
//Ignore useless updates or we can't interact with the UI
//TODO: come up with a better comparision, probably write a comparator because '.Equals' doesn't work
if (_lastUpdate == null || _lastUpdate.MindIdName.Count != state.MindIdName.Count)
{
_scanManager = state.MindIdName;
BuildEntityList();
_lastUpdate = state;
}
var percentage = state.Progress / _cloningProgressBar.MaxValue * 100;
_progressLabel.Text = $"{percentage:0}%";
_cloningProgressBar.Value = state.Progress;
_mindState.Text = Loc.GetString(state.MindPresent ? "Consciousness Detected" : "No Activity");
_mindState.FontColorOverride = state.MindPresent ? Color.Green : Color.Red;
}
private void OnSearchBarTextChanged(LineEdit.LineEditEventArgs args)
{
BuildEntityList(args.Text);
_clearButton.Disabled = string.IsNullOrEmpty(args.Text);
}
private void OnClearButtonPressed(BaseButton.ButtonEventArgs args)
{
_searchBar.Clear();
BuildEntityList("");
}
private void BuildEntityList(string? searchStr = null)
{
_filteredScans.Clear();
_scanList.RemoveAllChildren();
// Reset last scan indices so it automatically updates the entire list.
_lastScanIndices = (0, -1);
_scanList.RemoveAllChildren();
_selectedButton = null;
searchStr = searchStr?.ToLowerInvariant();
foreach (var scan in _scanManager)
{
if (searchStr != null && !_doesScanMatchSearch(scan.Value, searchStr))
{
continue;
}
_filteredScans.Add(scan.Key, scan.Value);
}
//TODO: set up sort
//_filteredScans.Sort((a, b) => string.Compare(a.ToString(), b.ToString(), StringComparison.Ordinal));
_scanList.TotalItemCount = _filteredScans.Count;
}
private void UpdateVisibleScans()
{
// Update visible buttons in the scan list.
// Calculate index of first scan to render based on current scroll.
var height = _measureButton.CombinedMinimumSize.Y + ScanListContainer.Separation;
var offset = -_scanList.Position.Y;
var startIndex = (int) Math.Floor(offset / height);
_scanList.ItemOffset = startIndex;
var (prevStart, prevEnd) = _lastScanIndices;
// Calculate index of final one.
var endIndex = startIndex - 1;
var spaceUsed = -height; // -height instead of 0 because else it cuts off the last button.
while (spaceUsed < _scanList.Parent!.Height)
{
spaceUsed += height;
endIndex += 1;
}
endIndex = Math.Min(endIndex, _filteredScans.Count - 1);
if (endIndex == prevEnd && startIndex == prevStart)
{
// Nothing changed so bye.
return;
}
_lastScanIndices = (startIndex, endIndex);
// Delete buttons at the start of the list that are no longer visible (scrolling down).
for (var i = prevStart; i < startIndex && i <= prevEnd; i++)
{
var control = (CloningScanButton) _scanList.GetChild(0);
DebugTools.Assert(control.Index == i);
_scanList.RemoveChild(control);
}
// Delete buttons at the end of the list that are no longer visible (scrolling up).
for (var i = prevEnd; i > endIndex && i >= prevStart; i--)
{
var control = (CloningScanButton) _scanList.GetChild(_scanList.ChildCount - 1);
DebugTools.Assert(control.Index == i);
_scanList.RemoveChild(control);
}
var array = _filteredScans.ToArray();
// Create buttons at the start of the list that are now visible (scrolling up).
for (var i = Math.Min(prevStart - 1, endIndex); i >= startIndex; i--)
{
InsertEntityButton(array[i], true, i);
}
// Create buttons at the end of the list that are now visible (scrolling down).
for (var i = Math.Max(prevEnd + 1, startIndex); i <= endIndex; i++)
{
InsertEntityButton(array[i], false, i);
}
}
// Create a spawn button and insert it into the start or end of the list.
private void InsertEntityButton(KeyValuePair<int, string> scan, bool insertFirst, int index)
{
var button = new CloningScanButton
{
Scan = scan.Value,
Id = scan.Key,
Index = index // We track this index purely for debugging.
};
button.ActualButton.OnToggled += OnItemButtonToggled;
var entityLabelText = scan.Value;
button.EntityLabel.Text = entityLabelText;
if (scan.Key == SelectedScan)
{
_selectedButton = button;
_selectedButton.ActualButton.Pressed = true;
}
//TODO: replace with body's face
/*var tex = IconComponent.GetScanIcon(scan, resourceCache);
var rect = button.EntityTextureRect;
if (tex != null)
{
rect.Texture = tex.Default;
}
else
{
rect.Dispose();
}
rect.Dispose();
*/
_scanList.AddChild(button);
if (insertFirst)
{
button.SetPositionInParent(0);
}
}
private static bool _doesScanMatchSearch(string scan, string searchStr)
{
return scan.ToLowerInvariant().Contains(searchStr);
}
private void OnItemButtonToggled(BaseButton.ButtonToggledEventArgs args)
{
var item = (CloningScanButton) args.Button.Parent!;
if (_selectedButton == item)
{
_selectedButton = null;
SelectedScan = null;
return;
}
else if (_selectedButton != null)
{
_selectedButton.ActualButton.Pressed = false;
}
_selectedButton = null;
SelectedScan = null;
_selectedButton = item;
SelectedScan = item.Id;
}
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
UpdateVisibleScans();
}
private class ScanListContainer : Container
{
// Quick and dirty container to do virtualization of the list.
// Basically, get total item count and offset to put the current buttons at.
// Get a constant minimum height and move the buttons in the list up to match the scrollbar.
private int _totalItemCount;
private int _itemOffset;
public int TotalItemCount
{
get => _totalItemCount;
set
{
_totalItemCount = value;
MinimumSizeChanged();
}
}
public int ItemOffset
{
get => _itemOffset;
set
{
_itemOffset = value;
UpdateLayout();
}
}
public const float Separation = 2;
protected override Vector2 CalculateMinimumSize()
{
if (ChildCount == 0)
{
return Vector2.Zero;
}
var first = GetChild(0);
var (minX, minY) = first.CombinedMinimumSize;
return (minX, minY * TotalItemCount + (TotalItemCount - 1) * Separation);
}
protected override void LayoutUpdateOverride()
{
if (ChildCount == 0)
{
return;
}
var first = GetChild(0);
var height = first.CombinedMinimumSize.Y;
var offset = ItemOffset * height + (ItemOffset - 1) * Separation;
foreach (var child in Children)
{
FitChildInBox(child, UIBox2.FromDimensions(0, offset, Width, height));
offset += Separation + height;
}
}
}
[DebuggerDisplay("cloningbutton {" + nameof(Index) + "}")]
private class CloningScanButton : Control
{
public string Scan { get; set; } = default!;
public int Id { get; set; }
public Button ActualButton { get; private set; }
public Label EntityLabel { get; private set; }
public TextureRect EntityTextureRect { get; private set; }
public int Index { get; set; }
public CloningScanButton()
{
AddChild(ActualButton = new Button
{
SizeFlagsHorizontal = SizeFlags.FillExpand,
SizeFlagsVertical = SizeFlags.FillExpand,
ToggleMode = true,
});
AddChild(new HBoxContainer
{
Children =
{
(EntityTextureRect = new TextureRect
{
CustomMinimumSize = (32, 32),
SizeFlagsHorizontal = SizeFlags.ShrinkCenter,
SizeFlagsVertical = SizeFlags.ShrinkCenter,
Stretch = TextureRect.StretchMode.KeepAspectCentered,
CanShrink = true
}),
(EntityLabel = new Label
{
SizeFlagsVertical = SizeFlags.ShrinkCenter,
SizeFlagsHorizontal = SizeFlags.FillExpand,
Text = "",
ClipText = true
})
}
});
}
}
}
}

View File

@@ -0,0 +1,13 @@
using Content.Shared.GameObjects.Components.Medical;
using Robust.Shared.GameObjects;
namespace Content.Client.GameObjects.Components.MedicalScanner
{
[RegisterComponent]
[ComponentReference(typeof(SharedMedicalScannerComponent))]
public class MedicalScannerComponent : SharedMedicalScannerComponent
{
}
}

View File

@@ -24,7 +24,7 @@ namespace Content.Client.GameObjects.Components.MedicalScanner
{
(ScanButton = new Button
{
Text = "Scan and Save DNA"
Text = Loc.GetString("Scan and Save DNA")
}),
(_diagnostics = new Label
{

View File

@@ -18,8 +18,7 @@ namespace Content.Client.GameObjects.Components.Observer
private GhostGui _gui;
[ViewVariables(VVAccess.ReadOnly)]
public bool CanReturnToBody { get; private set; } = true;
[ViewVariables(VVAccess.ReadOnly)] public bool CanReturnToBody { get; private set; } = true;
private bool _isAttached;
@@ -51,7 +50,8 @@ namespace Content.Client.GameObjects.Components.Observer
base.Initialize();
if (Owner.TryGetComponent(out SpriteComponent component))
component.Visible = _playerManager.LocalPlayer.ControlledEntity?.HasComponent<GhostComponent>() ?? false;
component.Visible =
_playerManager.LocalPlayer.ControlledEntity?.HasComponent<GhostComponent>() ?? false;
}
public override void HandleMessage(ComponentMessage message, IComponent component)
@@ -98,7 +98,6 @@ namespace Content.Client.GameObjects.Components.Observer
{
_gui?.Update();
}
}
}
}

View File

@@ -9,6 +9,7 @@
"Breakable",
"Pickaxe",
"Interactable",
"CloningPod",
"Destructible",
"Temperature",
"Explosive",
@@ -58,7 +59,6 @@
"AccessReader",
"IdCardConsole",
"Airlock",
"MedicalScanner",
"WirePlacer",
"Drink",
"Food",

View File

@@ -2,12 +2,14 @@ using Content.Client.GameObjects.Components.Observer;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
namespace Content.Client.UserInterface
{
public class GhostGui : Control
{
public Button ReturnToBody = new Button(){Text = "Return to body"};
public readonly Button ReturnToBody = new Button() {Text = Loc.GetString("Return to body")};
private GhostComponent _owner;
public GhostGui(GhostComponent owner)

View File

@@ -0,0 +1,235 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Content.Server.GameObjects.Components.Mobs;
using Content.Server.GameObjects.Components.Observer;
using Content.Server.GameObjects.Components.Power.ApcNetComponents;
using Content.Server.GameObjects.EntitySystems;
using Content.Server.Interfaces;
using Content.Server.Mobs;
using Content.Server.Utility;
using Content.Shared.GameObjects.Components.Damage;
using Content.Shared.GameObjects.Components.Medical;
using Content.Shared.Interfaces.GameObjects.Components;
using Content.Shared.Preferences;
using Robust.Server.GameObjects;
using Robust.Server.GameObjects.Components.Container;
using Robust.Server.GameObjects.Components.UserInterface;
using Robust.Server.Interfaces.GameObjects;
using Robust.Server.Interfaces.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Network;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Medical
{
[RegisterComponent]
[ComponentReference(typeof(IActivate))]
public class CloningPodComponent : SharedCloningPodComponent, IActivate
{
[Dependency] private readonly IServerPreferencesManager _prefsManager = null!;
[Dependency] private readonly IEntityManager _entityManager = null!;
[Dependency] private readonly IPlayerManager _playerManager = null!;
[ViewVariables]
private bool Powered => !Owner.TryGetComponent(out PowerReceiverComponent? receiver) || receiver.Powered;
[ViewVariables]
private BoundUserInterface? UserInterface =>
Owner.GetUIOrNull(CloningPodUIKey.Key);
private ContainerSlot _bodyContainer = default!;
private Mind? _capturedMind;
private CloningPodStatus _status;
private float _cloningProgress = 0;
private float _cloningTime;
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataField(ref _cloningTime, "cloningTime", 10f);
}
public override void Initialize()
{
base.Initialize();
if (UserInterface != null)
{
UserInterface.OnReceiveMessage += OnUiReceiveMessage;
}
_bodyContainer = ContainerManagerComponent.Ensure<ContainerSlot>($"{Name}-bodyContainer", Owner);
//TODO: write this so that it checks for a change in power events for GORE POD cases
var newState = GetUserInterfaceState();
UserInterface?.SetState(newState);
UpdateUserInterface();
Owner.EntityManager.EventBus.SubscribeEvent<GhostComponent.GhostReturnMessage>(EventSource.Local, this,
HandleGhostReturn);
}
public void Update(float frametime)
{
if (_bodyContainer.ContainedEntity != null &&
Powered)
{
_cloningProgress += frametime;
_cloningProgress = MathHelper.Clamp(_cloningProgress, 0f, _cloningTime);
}
if (_cloningProgress >= _cloningTime &&
_bodyContainer.ContainedEntity != null &&
_capturedMind?.Session.AttachedEntity == _bodyContainer.ContainedEntity &&
Powered)
{
_bodyContainer.Remove(_bodyContainer.ContainedEntity);
_capturedMind = null;
_cloningProgress = 0f;
_status = CloningPodStatus.Idle;
UpdateAppearance();
}
UpdateUserInterface();
}
public override void OnRemove()
{
if (UserInterface != null)
{
UserInterface.OnReceiveMessage -= OnUiReceiveMessage;
}
Owner.EntityManager.EventBus.UnsubscribeEvent<GhostComponent.GhostReturnMessage>(EventSource.Local, this);
base.OnRemove();
}
private void UpdateUserInterface()
{
if (!Powered) return;
UserInterface?.SetState(GetUserInterfaceState());
}
private CloningPodBoundUserInterfaceState GetUserInterfaceState()
{
return new CloningPodBoundUserInterfaceState(CloningSystem.getIdToUser(), _cloningProgress,
(_status == CloningPodStatus.Cloning));
}
private void UpdateAppearance()
{
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
{
appearance.SetData(CloningPodVisuals.Status, _status);
}
}
public void Activate(ActivateEventArgs eventArgs)
{
if (!Powered ||
!eventArgs.User.TryGetComponent(out IActorComponent? actor))
{
return;
}
UserInterface?.Open(actor.playerSession);
}
private async void OnUiReceiveMessage(ServerBoundUserInterfaceMessage obj)
{
if (!(obj.Message is CloningPodUiButtonPressedMessage message)) return;
switch (message.Button)
{
case UiButton.Clone:
if (message.ScanId == null) return;
if (_bodyContainer.ContainedEntity != null ||
!CloningSystem.Minds.TryGetValue(message.ScanId.Value, out var mind))
{
return;
}
var dead =
mind.OwnedEntity.TryGetComponent<IDamageableComponent>(out var damageable) &&
damageable.CurrentDamageState == DamageState.Dead;
if (!dead) return;
var mob = _entityManager.SpawnEntity("HumanMob_Content", Owner.Transform.MapPosition);
var client = _playerManager
.GetPlayersBy(x => x.SessionId == mind.SessionId).First();
mob.GetComponent<HumanoidAppearanceComponent>()
.UpdateFromProfile(GetPlayerProfileAsync(client.Name).Result);
mob.Name = GetPlayerProfileAsync(client.Name).Result.Name;
_bodyContainer.Insert(mob);
_capturedMind = mind;
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local,
new CloningStartedMessage(_capturedMind));
_status = CloningPodStatus.NoMind;
UpdateAppearance();
break;
case UiButton.Eject:
if (_bodyContainer.ContainedEntity == null || _cloningProgress < _cloningTime) break;
_bodyContainer.Remove(_bodyContainer.ContainedEntity!);
_capturedMind = null;
_cloningProgress = 0f;
_status = CloningPodStatus.Idle;
UpdateAppearance();
break;
default:
throw new ArgumentOutOfRangeException();
}
}
public class CloningStartedMessage : EntitySystemMessage
{
public CloningStartedMessage(Mind capturedMind)
{
CapturedMind = capturedMind;
}
public Mind CapturedMind { get; }
}
private async Task<HumanoidCharacterProfile> GetPlayerProfileAsync(string username)
{
return (HumanoidCharacterProfile) (await _prefsManager.GetPreferencesAsync(username))
.SelectedCharacter;
}
private void HandleGhostReturn(GhostComponent.GhostReturnMessage message)
{
if (message.Sender == _capturedMind)
{
//If the captured mind is in a ghost, we want to get rid of it.
_capturedMind.VisitingEntity?.Delete();
//Transfer the mind to the new mob
_capturedMind.TransferTo(_bodyContainer.ContainedEntity);
_status = CloningPodStatus.Cloning;
UpdateAppearance();
}
}
}
}

View File

@@ -1,9 +1,14 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using Content.Server.GameObjects.Components.Body;
using Content.Server.GameObjects.Components.Mobs;
using Content.Server.GameObjects.Components.Power.ApcNetComponents;
using Content.Server.GameObjects.EntitySystems;
using Content.Server.Players;
using Content.Server.Utility;
using Content.Shared.Damage;
using Content.Shared.GameObjects.Components.Damage;
using Content.Shared.GameObjects.Components.Medical;
using Content.Shared.GameObjects.EntitySystems;
@@ -13,21 +18,24 @@ using Robust.Server.GameObjects;
using Robust.Server.GameObjects.Components.Container;
using Robust.Server.GameObjects.Components.UserInterface;
using Robust.Server.Interfaces.GameObjects;
using Robust.Server.Interfaces.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Maths;
using Content.Shared.Damage;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Maths;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Medical
{
[RegisterComponent]
[ComponentReference(typeof(IActivate))]
public class MedicalScannerComponent : SharedMedicalScannerComponent, IActivate
public class MedicalScannerComponent : SharedMedicalScannerComponent, IActivate, IDragDropOn
{
private ContainerSlot _bodyContainer = default!;
private readonly Vector2 _ejectOffset = new Vector2(-0.5f, 0f);
[Dependency] private readonly IPlayerManager _playerManager = null!;
public bool IsOccupied => _bodyContainer.ContainedEntity != null;
[ViewVariables]
@@ -68,13 +76,12 @@ namespace Content.Server.GameObjects.Components.Medical
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
{
appearance?.SetData(MedicalScannerVisuals.Status, MedicalScannerStatus.Open);
};
}
return EmptyUIState;
}
if (!body.TryGetComponent(out IDamageableComponent? damageable) ||
damageable.CurrentDamageState == DamageState.Dead)
if (!body.TryGetComponent(out IDamageableComponent? damageable))
{
return EmptyUIState;
}
@@ -82,7 +89,14 @@ namespace Content.Server.GameObjects.Components.Medical
var classes = new Dictionary<DamageClass, int>(damageable.DamageClasses);
var types = new Dictionary<DamageType, int>(damageable.DamageTypes);
return new MedicalScannerBoundUserInterfaceState(body.Uid, classes, types, CloningSystem.HasUid(body.Uid));
if (_bodyContainer.ContainedEntity?.Uid == null)
{
return new MedicalScannerBoundUserInterfaceState(body.Uid, classes, types, true);
}
return new MedicalScannerBoundUserInterfaceState(body.Uid, classes, types,
CloningSystem.HasDnaScan(_bodyContainer.ContainedEntity.GetComponent<MindComponent>().Mind));
}
private void UpdateUserInterface()
@@ -207,22 +221,41 @@ namespace Content.Server.GameObjects.Components.Medical
private void OnUiReceiveMessage(ServerBoundUserInterfaceMessage obj)
{
if (!(obj.Message is UiButtonPressedMessage message))
{
return;
}
if (!(obj.Message is UiButtonPressedMessage message)) return;
switch (message.Button)
{
case UiButton.ScanDNA:
if (_bodyContainer.ContainedEntity != null)
{
CloningSystem.AddToScannedUids(_bodyContainer.ContainedEntity.Uid);
//TODO: Show a 'ERROR: Body is completely devoid of soul' if no Mind owns the entity.
CloningSystem.AddToDnaScans(_playerManager
.GetPlayersBy(playerSession =>
{
var mindOwnedMob = playerSession.ContentData()?.Mind?.OwnedEntity;
return mindOwnedMob != null && mindOwnedMob ==
_bodyContainer.ContainedEntity;
}).Single()
.ContentData()
?.Mind);
}
break;
default:
throw new ArgumentOutOfRangeException();
}
}
public bool CanDragDropOn(DragDropEventArgs eventArgs)
{
return eventArgs.Dropped.HasComponent<BodyManagerComponent>();
}
public bool DragDropOn(DragDropEventArgs eventArgs)
{
_bodyContainer.Insert(eventArgs.Dropped);
return true;
}
}
}

View File

@@ -1,9 +1,16 @@
#nullable enable
using System;
using Content.Server.GameObjects.Components.Body;
using Content.Server.GameObjects.Components.Medical;
using Content.Server.GameObjects.Components.Observer;
using Content.Server.Interfaces.GameTicking;
using Content.Server.Mobs;
using Content.Server.Utility;
using Content.Shared.GameObjects.Components;
using Content.Shared.GameObjects.Components.Damage;
using Content.Shared.GameObjects.Components.Mobs;
using Content.Shared.GameObjects.EntitySystems;
using Robust.Server.GameObjects.Components.UserInterface;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Map;
@@ -14,6 +21,7 @@ using Robust.Shared.Serialization;
using Robust.Shared.Timers;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
using Serilog.Debugging;
namespace Content.Server.GameObjects.Components.Mobs
{
@@ -50,6 +58,45 @@ namespace Content.Server.GameObjects.Components.Mobs
set => _showExamineInfo = value;
}
[ViewVariables]
private BoundUserInterface? UserInterface =>
Owner.GetUIOrNull(SharedAcceptCloningComponent.AcceptCloningUiKey.Key);
public override void Initialize()
{
base.Initialize();
Owner.EntityManager.EventBus.SubscribeEvent<CloningPodComponent.CloningStartedMessage>(
EventSource.Local, this,
HandleCloningStartedMessage);
if (UserInterface != null)
{
UserInterface.OnReceiveMessage += OnUiAcceptCloningMessage;
}
}
private void HandleCloningStartedMessage(CloningPodComponent.CloningStartedMessage ev)
{
if (ev.CapturedMind == Mind)
{
UserInterface?.Open(Mind.Session);
}
}
private void OnUiAcceptCloningMessage(ServerBoundUserInterfaceMessage obj)
{
if (!(obj.Message is SharedAcceptCloningComponent.UiButtonPressedMessage message)) return;
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new GhostComponent.GhostReturnMessage(Mind));
}
public override void OnRemove()
{
base.OnRemove();
Owner.EntityManager.EventBus.UnsubscribeEvent<CloningPodComponent.CloningStartedMessage>(EventSource.Local, this);
if (UserInterface != null) UserInterface.OnReceiveMessage -= OnUiAcceptCloningMessage;
}
/// <summary>
/// Don't call this unless you know what the hell you're doing.
/// Use <see cref="Mind.TransferTo(IEntity)"/> instead.
@@ -133,13 +180,19 @@ namespace Content.Server.GameObjects.Components.Mobs
if (!HasMind)
{
message.AddMarkup(!dead
? $"[color=red]" + Loc.GetString("{0:They} {0:are} totally catatonic. The stresses of life in deep-space must have been too much for {0:them}. Any recovery is unlikely.", Owner) + "[/color]"
? $"[color=red]" +
Loc.GetString(
"{0:They} {0:are} totally catatonic. The stresses of life in deep-space must have been too much for {0:them}. Any recovery is unlikely.",
Owner) + "[/color]"
: $"[color=purple]" + Loc.GetString("{0:Their} soul has departed.", Owner) + "[/color]");
}
else if (Mind?.Session == null)
{
if(!dead)
message.AddMarkup("[color=yellow]" + Loc.GetString("{0:They} {0:have} a blank, absent-minded stare and appears completely unresponsive to anything. {0:They} may snap out of it soon.", Owner) + "[/color]");
if (!dead)
message.AddMarkup("[color=yellow]" +
Loc.GetString(
"{0:They} {0:have} a blank, absent-minded stare and appears completely unresponsive to anything. {0:They} may snap out of it soon.",
Owner) + "[/color]");
}
}
}

View File

@@ -1,4 +1,6 @@
using Content.Server.Players;
using Content.Server.GameObjects.Components.Mobs;
using Content.Server.Mobs;
using Content.Server.Players;
using Content.Shared.GameObjects.Components.Observer;
using Robust.Server.GameObjects;
using Robust.Server.GameObjects.Components;
@@ -31,7 +33,7 @@ namespace Content.Server.GameObjects.Components.Observer
{
base.Initialize();
Owner.EnsureComponent<VisibilityComponent>().Layer = (int)VisibilityFlags.Ghost;
Owner.EnsureComponent<VisibilityComponent>().Layer = (int) VisibilityFlags.Ghost;
}
public override ComponentState GetComponentState() => new GhostComponentState(CanReturnToBody);
@@ -43,18 +45,19 @@ namespace Content.Server.GameObjects.Components.Observer
switch (message)
{
case PlayerAttachedMsg msg:
msg.NewPlayer.VisibilityMask |= (int)VisibilityFlags.Ghost;
msg.NewPlayer.VisibilityMask |= (int) VisibilityFlags.Ghost;
Dirty();
break;
case PlayerDetachedMsg msg:
msg.OldPlayer.VisibilityMask &= ~(int)VisibilityFlags.Ghost;
msg.OldPlayer.VisibilityMask &= ~(int) VisibilityFlags.Ghost;
break;
default:
break;
}
}
public override void HandleNetworkMessage(ComponentMessage message, INetChannel netChannel, ICommonSession session = null)
public override void HandleNetworkMessage(ComponentMessage message, INetChannel netChannel,
ICommonSession session = null)
{
base.HandleNetworkMessage(message, netChannel, session);
@@ -67,10 +70,29 @@ namespace Content.Server.GameObjects.Components.Observer
actor.playerSession.ContentData().Mind.UnVisit();
Owner.Delete();
}
break;
case ReturnToCloneComponentMessage reenter:
if (Owner.TryGetComponent(out VisitingMindComponent mind))
{
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new GhostReturnMessage(mind.Mind));
}
break;
default:
break;
}
}
public class GhostReturnMessage : EntitySystemMessage
{
public GhostReturnMessage(Mind sender)
{
Sender = sender;
}
public Mind Sender { get; }
}
}
}

View File

@@ -1,24 +1,42 @@
using System.Collections.Generic;
using System.Linq;
using Content.Server.GameObjects.Components.Medical;
using Content.Server.Mobs;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Content.Shared.GameObjects.Components.Medical;
using Microsoft.AspNetCore.Server.Kestrel.Core;
namespace Content.Server.GameObjects.EntitySystems
{
internal sealed class CloningSystem : EntitySystem
{
public static List<EntityUid> scannedUids = new List<EntityUid>();
public static void AddToScannedUids(EntityUid uid)
public override void Update(float frameTime)
{
if (!scannedUids.Contains(uid))
foreach (var comp in ComponentManager.EntityQuery<CloningPodComponent>())
{
scannedUids.Add(uid);
comp.Update(frameTime);
}
}
public static bool HasUid(EntityUid uid)
public static Dictionary<int, Mind> Minds = new Dictionary<int, Mind>();
public static void AddToDnaScans(Mind mind)
{
return scannedUids.Contains(uid);
if (!Minds.ContainsValue(mind))
{
Minds.Add(Minds.Count(), mind);
}
}
public static bool HasDnaScan(Mind mind)
{
return Minds.ContainsValue(mind);
}
public static Dictionary<int, string> getIdToUser()
{
return Minds.ToDictionary(m => m.Key, m => m.Value.CharacterName);
}
}
}

View File

@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.UserInterface;
using Robust.Shared.Serialization;
namespace Content.Shared.GameObjects.Components.Medical
{
public class SharedCloningPodComponent : Component
{
public override string Name => "CloningPod";
[Serializable, NetSerializable]
public class CloningPodBoundUserInterfaceState : BoundUserInterfaceState
{
public readonly Dictionary<int, string> MindIdName;
public readonly float Progress;
public readonly bool MindPresent;
public CloningPodBoundUserInterfaceState(Dictionary<int, string> mindIdName, float progress, bool mindPresent)
{
MindIdName = mindIdName;
Progress = progress;
MindPresent = mindPresent;
}
}
[Serializable, NetSerializable]
public enum CloningPodUIKey
{
Key
}
[Serializable, NetSerializable]
public enum CloningPodVisuals
{
Status
}
[Serializable, NetSerializable]
public enum CloningPodStatus
{
Idle,
Cloning,
Gore,
NoMind
}
[Serializable, NetSerializable]
public enum UiButton
{
Clone,
Eject
}
[Serializable, NetSerializable]
public class CloningPodUiButtonPressedMessage : BoundUserInterfaceMessage
{
public readonly UiButton Button;
public readonly int? ScanId;
public CloningPodUiButtonPressedMessage(UiButton button, int? scanId)
{
Button = button;
ScanId = scanId;
}
}
}
}

View File

@@ -35,4 +35,11 @@ namespace Content.Shared.GameObjects.Components.Observer
{
public ReturnToBodyComponentMessage() => Directed = true;
}
[Serializable, NetSerializable]
public class ReturnToCloneComponentMessage : ComponentMessage
{
public ReturnToCloneComponentMessage() => Directed = true;
}
}

View File

@@ -0,0 +1,36 @@
using System;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.UserInterface;
using Robust.Shared.Serialization;
namespace Content.Shared.GameObjects.Components
{
public class SharedAcceptCloningComponent : Component
{
public override string Name => "AcceptCloning";
[Serializable, NetSerializable]
public enum AcceptCloningUiKey
{
Key
}
[Serializable, NetSerializable]
public enum UiButton
{
Accept
}
[Serializable, NetSerializable]
public class UiButtonPressedMessage : BoundUserInterfaceMessage
{
public readonly UiButton Button;
public UiButtonPressedMessage(UiButton button)
{
Button = button;
}
}
}
}

View File

@@ -0,0 +1,44 @@
- type: entity
id: CloningPod
name: Cloning Pod
description: A Cloning Pod. 50% reliable.
components:
- type: Sprite
netsync: false
sprite: Objects/Specific/Medical/cloning.rsi
layers:
- state: pod_0
map: ["enum.CloningPodVisualLayers.Machine"]
- type: PowerReceiver
- type: Icon
sprite: Objects/Specific/Medical/cloning.rsi
state: pod_0
- type: Anchorable
- type: Clickable
- type: InteractionOutline
- type: Collidable
shapes:
- !type:PhysShapeAabb
bounds: "-0.5,-0.25,0.5,0.25"
layer:
- Opaque
- Impassable
- MobImpassable
- VaultImpassable
IsScrapingFloor: true
- type: Physics
mass: 25
anchored: true
- type: SnapGrid
offset: Center
- type: CloningPod
cloningTime: 10.0
- type: Destructible
deadThreshold: 100
- type: Appearance
visuals:
- type: CloningPodVisualizer
- type: UserInterface
interfaces:
- key: enum.CloningPodUIKey.Key
type: CloningPodBoundUserInterface

View File

@@ -92,7 +92,7 @@
state: r_foot
- map: ["enum.HumanoidVisualLayers.Handcuffs"]
color: "#ffffff"
sprite: Objects/Misc/handcuffs.rsi
sprite: Objects/Misc/handcuffs.rsi
state: body-overlay-2
visible: false
- map: ["enum.Slots.IDCARD"]
@@ -169,6 +169,8 @@
interfaces:
- key: enum.StrippingUiKey.Key
type: StrippableBoundUserInterface
- key: enum.AcceptCloningUiKey.Key
type: AcceptCloningBoundUserInterface
- type: entity
@@ -230,7 +232,7 @@
state: r_hand
- map: ["enum.HumanoidVisualLayers.Handcuffs"]
color: "#ffffff"
sprite: Objects/Misc/handcuffs.rsi
sprite: Objects/Misc/handcuffs.rsi
state: body-overlay-2
visible: false
- map: ["enum.Slots.IDCARD"]

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@@ -0,0 +1,56 @@
{
"version": 1,
"size": {
"x": 32,
"y": 32
},
"license": "CC BY-SA 3.0",
"copyright": "Taken from https://github.com/tgstation/tgstation at commit 9bebd81ae0b0a7f952b59886a765c681205de31f",
"states": [
{
"name": "pod_0",
"directions": 1,
"delays": [
[
1.0
]
]
},
{
"name": "pod_1",
"directions": 1,
"delays": [
[
0.2,
0.2,
0.2,
0.2
]
]
},
{
"name": "pod_e",
"directions": 1,
"delays": [
[
0.2,
0.2,
0.2,
0.2
]
]
},
{
"name": "pod_g",
"directions": 1,
"delays": [
[
0.2,
0.2,
0.2,
0.2
]
]
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB