Kill bobby 2.0 (#6023)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Content.Server.Body.Components;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Body.Components;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Content.Server.Body.Components;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Body.Components;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using Content.Server.Ghost;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Body.Part;
|
||||
@@ -16,8 +15,7 @@ namespace Content.Server.Body.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(SharedBodyComponent))]
|
||||
[ComponentReference(typeof(IGhostOnMove))]
|
||||
public class BodyComponent : SharedBodyComponent, IGhostOnMove
|
||||
public class BodyComponent : SharedBodyComponent
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entMan = default!;
|
||||
|
||||
|
||||
@@ -1,50 +1,34 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.UserInterface;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Body.Surgery;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Random.Helpers;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.Body.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(SharedBodyPartComponent))]
|
||||
public class BodyPartComponent : SharedBodyPartComponent, IAfterInteract
|
||||
public class BodyPartComponent : SharedBodyPartComponent
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entMan = default!;
|
||||
|
||||
private readonly Dictionary<int, object> _optionsCache = new();
|
||||
private SharedBodyComponent? _owningBodyCache;
|
||||
private int _idHash;
|
||||
private EntityUid? _surgeonCache;
|
||||
private Container _mechanismContainer = default!;
|
||||
|
||||
[ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(SurgeryUIKey.Key);
|
||||
|
||||
public override bool CanAddMechanism(SharedMechanismComponent mechanism)
|
||||
public override bool CanAddMechanism(MechanismComponent mechanism)
|
||||
{
|
||||
return base.CanAddMechanism(mechanism) &&
|
||||
_mechanismContainer.CanInsert(mechanism.Owner);
|
||||
}
|
||||
|
||||
protected override void OnAddMechanism(SharedMechanismComponent mechanism)
|
||||
protected override void OnAddMechanism(MechanismComponent mechanism)
|
||||
{
|
||||
base.OnAddMechanism(mechanism);
|
||||
|
||||
_mechanismContainer.Insert(mechanism.Owner);
|
||||
}
|
||||
|
||||
protected override void OnRemoveMechanism(SharedMechanismComponent mechanism)
|
||||
protected override void OnRemoveMechanism(MechanismComponent mechanism)
|
||||
{
|
||||
base.OnRemoveMechanism(mechanism);
|
||||
|
||||
@@ -65,156 +49,14 @@ namespace Content.Server.Body.Components
|
||||
{
|
||||
var entity = _entMan.SpawnEntity(mechanismId, _entMan.GetComponent<TransformComponent>(Owner).MapPosition);
|
||||
|
||||
if (!_entMan.TryGetComponent(entity, out SharedMechanismComponent? mechanism))
|
||||
if (!_entMan.TryGetComponent(entity, out MechanismComponent? mechanism))
|
||||
{
|
||||
Logger.Error($"Entity {mechanismId} does not have a {nameof(SharedMechanismComponent)} component.");
|
||||
Logger.Error($"Entity {mechanismId} does not have a {nameof(MechanismComponent)} component.");
|
||||
continue;
|
||||
}
|
||||
|
||||
TryAddMechanism(mechanism, true);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Startup()
|
||||
{
|
||||
base.Startup();
|
||||
|
||||
if (UserInterface != null)
|
||||
{
|
||||
UserInterface.OnReceiveMessage += OnUIMessage;
|
||||
}
|
||||
|
||||
foreach (var mechanism in Mechanisms)
|
||||
{
|
||||
mechanism.Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
async Task<bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
|
||||
{
|
||||
// TODO BODY
|
||||
if (eventArgs.Target == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
CloseAllSurgeryUIs();
|
||||
_optionsCache.Clear();
|
||||
_surgeonCache = null;
|
||||
_owningBodyCache = null;
|
||||
|
||||
if (_entMan.TryGetComponent(eventArgs.Target.Value, out SharedBodyComponent? body))
|
||||
{
|
||||
SendSlots(eventArgs, body);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void SendSlots(AfterInteractEventArgs eventArgs, SharedBodyComponent body)
|
||||
{
|
||||
// Create dictionary to send to client (text to be shown : data sent back if selected)
|
||||
var toSend = new Dictionary<string, int>();
|
||||
|
||||
// Here we are trying to grab a list of all empty BodySlots adjacent to an existing BodyPart that can be
|
||||
// attached to. i.e. an empty left hand slot, connected to an occupied left arm slot would be valid.
|
||||
foreach (var slot in body.EmptySlots)
|
||||
{
|
||||
if (slot.PartType != PartType)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (var connection in slot.Connections)
|
||||
{
|
||||
if (connection.Part == null ||
|
||||
!connection.Part.CanAttachPart(this))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
_optionsCache.Add(_idHash, slot);
|
||||
toSend.Add(slot.Id, _idHash++);
|
||||
}
|
||||
}
|
||||
|
||||
if (_optionsCache.Count > 0)
|
||||
{
|
||||
OpenSurgeryUI(_entMan.GetComponent<ActorComponent>(eventArgs.User).PlayerSession);
|
||||
BodyPartSlotRequest(_entMan.GetComponent<ActorComponent>(eventArgs.User).PlayerSession,
|
||||
toSend);
|
||||
_surgeonCache = eventArgs.User;
|
||||
_owningBodyCache = body;
|
||||
}
|
||||
else // If surgery cannot be performed, show message saying so.
|
||||
{
|
||||
eventArgs.Target?.PopupMessage(eventArgs.User,
|
||||
Loc.GetString("bodypart-component-no-way-to-install-message", ("partName", Owner)));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called after the client chooses from a list of possible
|
||||
/// BodyPartSlots to install the limb on.
|
||||
/// </summary>
|
||||
private void ReceiveBodyPartSlot(int key)
|
||||
{
|
||||
if (_surgeonCache == null ||
|
||||
!_entMan.TryGetComponent(_surgeonCache.Value, out ActorComponent? actor))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CloseSurgeryUI(actor.PlayerSession);
|
||||
|
||||
if (_owningBodyCache == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: sanity checks to see whether user is in range, user is still able-bodied, target is still the same, etc etc
|
||||
if (!_optionsCache.TryGetValue(key, out var targetObject))
|
||||
{
|
||||
_owningBodyCache.Owner.PopupMessage(_surgeonCache.Value,
|
||||
Loc.GetString("bodypart-component-no-way-to-attach-message", ("partName", Owner)));
|
||||
}
|
||||
|
||||
var target = (string) targetObject!;
|
||||
var message = _owningBodyCache.TryAddPart(target, this)
|
||||
? Loc.GetString("bodypart-component-attach-success-message",("partName", Owner))
|
||||
: Loc.GetString("bodypart-component-attach-fail-message",("partName", Owner));
|
||||
|
||||
_owningBodyCache.Owner.PopupMessage(_surgeonCache.Value, message);
|
||||
}
|
||||
|
||||
private void OpenSurgeryUI(IPlayerSession session)
|
||||
{
|
||||
UserInterface?.Open(session);
|
||||
}
|
||||
|
||||
private void BodyPartSlotRequest(IPlayerSession session, Dictionary<string, int> options)
|
||||
{
|
||||
UserInterface?.SendMessage(new RequestBodyPartSlotSurgeryUIMessage(options), session);
|
||||
}
|
||||
|
||||
private void CloseSurgeryUI(IPlayerSession session)
|
||||
{
|
||||
UserInterface?.Close(session);
|
||||
}
|
||||
|
||||
private void CloseAllSurgeryUIs()
|
||||
{
|
||||
UserInterface?.CloseAll();
|
||||
}
|
||||
|
||||
private void OnUIMessage(ServerBoundUserInterfaceMessage message)
|
||||
{
|
||||
switch (message.Message)
|
||||
{
|
||||
case ReceiveBodyPartSlotSurgeryUIMessage msg:
|
||||
ReceiveBodyPartSlot(msg.SelectedOptionId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,161 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.UserInterface;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Body.Surgery;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Popups;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.Body.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(SharedMechanismComponent))]
|
||||
public class MechanismComponent : SharedMechanismComponent, IAfterInteract
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entities = default!;
|
||||
|
||||
[ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(SurgeryUIKey.Key);
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
if (UserInterface != null)
|
||||
{
|
||||
UserInterface.OnReceiveMessage += OnUIMessage;
|
||||
}
|
||||
}
|
||||
|
||||
async Task<bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
|
||||
{
|
||||
if (eventArgs.Target == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
CloseAllSurgeryUIs();
|
||||
OptionsCache.Clear();
|
||||
PerformerCache = null;
|
||||
BodyCache = null;
|
||||
|
||||
if (_entities.TryGetComponent(eventArgs.Target.Value, out SharedBodyComponent? body))
|
||||
{
|
||||
SendBodyPartListToUser(eventArgs, body);
|
||||
}
|
||||
else if (_entities.TryGetComponent<SharedBodyPartComponent?>(eventArgs.Target.Value, out var part))
|
||||
{
|
||||
DebugTools.AssertNotNull(part);
|
||||
|
||||
if (!part.TryAddMechanism(this))
|
||||
{
|
||||
eventArgs.Target.Value.PopupMessage(eventArgs.User, Loc.GetString("mechanism-component-cannot-fit-message"));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void SendBodyPartListToUser(AfterInteractEventArgs eventArgs, SharedBodyComponent body)
|
||||
{
|
||||
// Create dictionary to send to client (text to be shown : data sent back if selected)
|
||||
var toSend = new Dictionary<string, int>();
|
||||
|
||||
foreach (var (part, slot) in body.Parts)
|
||||
{
|
||||
// For each limb in the target, add it to our cache if it is a valid option.
|
||||
if (part.CanAddMechanism(this))
|
||||
{
|
||||
OptionsCache.Add(IdHash, slot);
|
||||
toSend.Add(part + ": " + part.Name, IdHash++);
|
||||
}
|
||||
}
|
||||
|
||||
if (OptionsCache.Count > 0 &&
|
||||
_entities.TryGetComponent(eventArgs.User, out ActorComponent? actor))
|
||||
{
|
||||
OpenSurgeryUI(actor.PlayerSession);
|
||||
UpdateSurgeryUIBodyPartRequest(actor.PlayerSession, toSend);
|
||||
PerformerCache = eventArgs.User;
|
||||
BodyCache = body;
|
||||
}
|
||||
else // If surgery cannot be performed, show message saying so.
|
||||
{
|
||||
eventArgs.Target?.PopupMessage(eventArgs.User,
|
||||
Loc.GetString("mechanism-component-no-way-to-install-message", ("partName", Name: _entities.GetComponent<MetaDataComponent>(Owner).EntityName)));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called after the client chooses from a list of possible BodyParts that can be operated on.
|
||||
/// </summary>
|
||||
private void HandleReceiveBodyPart(int key)
|
||||
{
|
||||
if (PerformerCache == null ||
|
||||
!_entities.TryGetComponent(PerformerCache.Value, out ActorComponent? actor))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CloseSurgeryUI(actor.PlayerSession);
|
||||
|
||||
if (BodyCache == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: sanity checks to see whether user is in range, user is still able-bodied, target is still the same, etc etc
|
||||
if (!OptionsCache.TryGetValue(key, out var targetObject))
|
||||
{
|
||||
BodyCache.Owner.PopupMessage(PerformerCache.Value,
|
||||
Loc.GetString("mechanism-component-no-useful-way-to-use-message",("partName", Name: _entities.GetComponent<MetaDataComponent>(Owner).EntityName)));
|
||||
return;
|
||||
}
|
||||
|
||||
var target = (SharedBodyPartComponent) targetObject;
|
||||
var message = target.TryAddMechanism(this)
|
||||
? Loc.GetString("mechanism-component-jam-inside-message",("ownerName", Owner),("them", PerformerCache))
|
||||
: Loc.GetString("mechanism-component-cannot-fit-message");
|
||||
|
||||
BodyCache.Owner.PopupMessage(PerformerCache.Value, message);
|
||||
|
||||
// TODO: {1:theName}
|
||||
}
|
||||
|
||||
private void OpenSurgeryUI(IPlayerSession session)
|
||||
{
|
||||
UserInterface?.Open(session);
|
||||
}
|
||||
|
||||
private void UpdateSurgeryUIBodyPartRequest(IPlayerSession session, Dictionary<string, int> options)
|
||||
{
|
||||
UserInterface?.SendMessage(new RequestBodyPartSurgeryUIMessage(options), session);
|
||||
}
|
||||
|
||||
private void CloseSurgeryUI(IPlayerSession session)
|
||||
{
|
||||
UserInterface?.Close(session);
|
||||
}
|
||||
|
||||
private void CloseAllSurgeryUIs()
|
||||
{
|
||||
UserInterface?.CloseAll();
|
||||
}
|
||||
|
||||
private void OnUIMessage(ServerBoundUserInterfaceMessage message)
|
||||
{
|
||||
switch (message.Message)
|
||||
{
|
||||
case ReceiveBodyPartSurgeryUIMessage msg:
|
||||
HandleReceiveBodyPart(msg.SelectedOptionId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,372 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.DoAfter;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Body.Part;
|
||||
using Content.Shared.Body.Surgery;
|
||||
using Content.Shared.Popups;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using static Content.Shared.Body.Surgery.ISurgeryData;
|
||||
|
||||
namespace Content.Server.Body.Surgery
|
||||
{
|
||||
/// <summary>
|
||||
/// Data class representing the surgery state of a biological entity.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(ISurgeryData))]
|
||||
public class BiologicalSurgeryDataComponent : Component, ISurgeryData
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entMan = default!;
|
||||
|
||||
public override string Name => "BiologicalSurgeryData";
|
||||
|
||||
private readonly HashSet<SharedMechanismComponent> _disconnectedOrgans = new();
|
||||
|
||||
private bool SkinOpened { get; set; }
|
||||
|
||||
private bool SkinRetracted { get; set; }
|
||||
|
||||
private bool VesselsClamped { get; set; }
|
||||
|
||||
public SharedBodyPartComponent? Parent => _entMan.GetComponentOrNull<SharedBodyPartComponent>(Owner);
|
||||
|
||||
public BodyPartType? ParentType => Parent?.PartType;
|
||||
|
||||
private void AddDisconnectedOrgan(SharedMechanismComponent mechanism)
|
||||
{
|
||||
if (_disconnectedOrgans.Add(mechanism))
|
||||
{
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
private void RemoveDisconnectedOrgan(SharedMechanismComponent mechanism)
|
||||
{
|
||||
if (_disconnectedOrgans.Remove(mechanism))
|
||||
{
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<bool> SurgeryDoAfter(EntityUid performer)
|
||||
{
|
||||
if (!_entMan.HasComponent<DoAfterComponent>(performer))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var doAfterSystem = EntitySystem.Get<DoAfterSystem>();
|
||||
var target = Parent?.Body?.Owner ?? Owner;
|
||||
var args = new DoAfterEventArgs(performer, 3, target: target)
|
||||
{
|
||||
BreakOnUserMove = true,
|
||||
BreakOnTargetMove = true
|
||||
};
|
||||
|
||||
return await doAfterSystem.WaitDoAfter(args) == DoAfterStatus.Finished;
|
||||
}
|
||||
|
||||
private bool HasIncisionNotClamped()
|
||||
{
|
||||
return SkinOpened && !VesselsClamped;
|
||||
}
|
||||
|
||||
private bool HasClampedIncisionNotRetracted()
|
||||
{
|
||||
return SkinOpened && VesselsClamped && !SkinRetracted;
|
||||
}
|
||||
|
||||
private bool HasFullyOpenIncision()
|
||||
{
|
||||
return SkinOpened && VesselsClamped && SkinRetracted;
|
||||
}
|
||||
|
||||
public string GetDescription()
|
||||
{
|
||||
if (Parent == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
var toReturn = new StringBuilder();
|
||||
|
||||
if (HasIncisionNotClamped())
|
||||
{
|
||||
toReturn.Append(Loc.GetString("biological-surgery-data-component-has-incision-not-clamped-message",
|
||||
("owner", Owner),("bodyPart", Parent.Name)));
|
||||
}
|
||||
else if (HasClampedIncisionNotRetracted())
|
||||
{
|
||||
toReturn.AppendLine(Loc.GetString("biological-surgery-data-component-has-clamped-incision-not-retracted-message",
|
||||
("owner", Owner),("bodyPary", Parent.Name)));
|
||||
}
|
||||
else if (HasFullyOpenIncision())
|
||||
{
|
||||
toReturn.AppendLine(Loc.GetString("biological-surgery-data-component-has-fully-open-incision-message", ("owner", Owner), ("bodyPart", Parent.Name)) + "\n");
|
||||
foreach (var mechanism in _disconnectedOrgans)
|
||||
{
|
||||
toReturn.AppendLine(Loc.GetString("biological-surgery-data-component-part-is-loose-message",("owner", Owner), ("bodyPart", mechanism.Name)));
|
||||
}
|
||||
}
|
||||
|
||||
return toReturn.ToString();
|
||||
}
|
||||
|
||||
public bool CanAddMechanism(SharedMechanismComponent mechanism)
|
||||
{
|
||||
return Parent != null &&
|
||||
SkinOpened &&
|
||||
VesselsClamped &&
|
||||
SkinRetracted;
|
||||
}
|
||||
|
||||
public bool CanAttachBodyPart(SharedBodyPartComponent part)
|
||||
{
|
||||
return Parent != null;
|
||||
// TODO BODY if a part is disconnected, you should have to do some surgery to allow another body part to be attached.
|
||||
}
|
||||
|
||||
public SurgeryAction? GetSurgeryStep(SurgeryType toolType)
|
||||
{
|
||||
if (Parent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (toolType == SurgeryType.Amputation)
|
||||
{
|
||||
return RemoveBodyPartSurgery;
|
||||
}
|
||||
|
||||
if (!SkinOpened)
|
||||
{
|
||||
// Case: skin is normal.
|
||||
if (toolType == SurgeryType.Incision)
|
||||
{
|
||||
return OpenSkinSurgery;
|
||||
}
|
||||
}
|
||||
else if (!VesselsClamped)
|
||||
{
|
||||
// Case: skin is opened, but not clamped.
|
||||
switch (toolType)
|
||||
{
|
||||
case SurgeryType.VesselCompression:
|
||||
return ClampVesselsSurgery;
|
||||
case SurgeryType.Cauterization:
|
||||
return CauterizeIncisionSurgery;
|
||||
}
|
||||
}
|
||||
else if (!SkinRetracted)
|
||||
{
|
||||
// Case: skin is opened and clamped, but not retracted.
|
||||
switch (toolType)
|
||||
{
|
||||
case SurgeryType.Retraction:
|
||||
return RetractSkinSurgery;
|
||||
case SurgeryType.Cauterization:
|
||||
return CauterizeIncisionSurgery;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Case: skin is fully open.
|
||||
if (Parent.Mechanisms.Count > 0 &&
|
||||
toolType == SurgeryType.VesselCompression)
|
||||
{
|
||||
if (_disconnectedOrgans.Except(Parent.Mechanisms).Count() != 0 ||
|
||||
Parent.Mechanisms.Except(_disconnectedOrgans).Count() != 0)
|
||||
{
|
||||
return LoosenOrganSurgery;
|
||||
}
|
||||
}
|
||||
|
||||
if (_disconnectedOrgans.Count > 0 && toolType == SurgeryType.Incision)
|
||||
{
|
||||
return RemoveOrganSurgery;
|
||||
}
|
||||
|
||||
if (toolType == SurgeryType.Cauterization)
|
||||
{
|
||||
return CauterizeIncisionSurgery;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool CheckSurgery(SurgeryType toolType)
|
||||
{
|
||||
return GetSurgeryStep(toolType) != null;
|
||||
}
|
||||
|
||||
public bool PerformSurgery(SurgeryType surgeryType, IBodyPartContainer container, ISurgeon surgeon, EntityUid performer)
|
||||
{
|
||||
var step = GetSurgeryStep(surgeryType);
|
||||
|
||||
if (step == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
step(container, surgeon, performer);
|
||||
return true;
|
||||
}
|
||||
|
||||
private async void OpenSkinSurgery(IBodyPartContainer container, ISurgeon surgeon, EntityUid performer)
|
||||
{
|
||||
if (Parent == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
performer.PopupMessage(Loc.GetString("biological-surgery-data-component-open-skin-message"));
|
||||
|
||||
if (await SurgeryDoAfter(performer))
|
||||
{
|
||||
SkinOpened = true;
|
||||
}
|
||||
}
|
||||
|
||||
private async void ClampVesselsSurgery(IBodyPartContainer container, ISurgeon surgeon, EntityUid performer)
|
||||
{
|
||||
if (Parent == null) return;
|
||||
|
||||
performer.PopupMessage(Loc.GetString("biological-surgery-data-component-clamp-vessels-message"));
|
||||
|
||||
if (await SurgeryDoAfter(performer))
|
||||
{
|
||||
VesselsClamped = true;
|
||||
}
|
||||
}
|
||||
|
||||
private async void RetractSkinSurgery(IBodyPartContainer container, ISurgeon surgeon, EntityUid performer)
|
||||
{
|
||||
if (Parent == null) return;
|
||||
|
||||
performer.PopupMessage(Loc.GetString("biological-surgery-data-component-retract-skin-message"));
|
||||
|
||||
if (await SurgeryDoAfter(performer))
|
||||
{
|
||||
SkinRetracted = true;
|
||||
}
|
||||
}
|
||||
|
||||
private async void CauterizeIncisionSurgery(IBodyPartContainer container, ISurgeon surgeon, EntityUid performer)
|
||||
{
|
||||
if (Parent == null) return;
|
||||
|
||||
performer.PopupMessage(Loc.GetString("biological-surgery-data-component-cauterize-incision-message"));
|
||||
|
||||
if (await SurgeryDoAfter(performer))
|
||||
{
|
||||
SkinOpened = false;
|
||||
VesselsClamped = false;
|
||||
SkinRetracted = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void LoosenOrganSurgery(IBodyPartContainer container, ISurgeon surgeon, EntityUid performer)
|
||||
{
|
||||
if (Parent == null) return;
|
||||
if (Parent.Mechanisms.Count <= 0) return;
|
||||
|
||||
var toSend = new List<SharedMechanismComponent>();
|
||||
foreach (var mechanism in Parent.Mechanisms)
|
||||
{
|
||||
if (!_disconnectedOrgans.Contains(mechanism))
|
||||
{
|
||||
toSend.Add(mechanism);
|
||||
}
|
||||
}
|
||||
|
||||
if (toSend.Count > 0)
|
||||
{
|
||||
surgeon.RequestMechanism(toSend, LoosenOrganSurgeryCallback);
|
||||
}
|
||||
}
|
||||
|
||||
private async void LoosenOrganSurgeryCallback(SharedMechanismComponent? target, IBodyPartContainer container, ISurgeon surgeon,
|
||||
EntityUid performer)
|
||||
{
|
||||
if (Parent == null || target == null || !Parent.Mechanisms.Contains(target))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
performer.PopupMessage(Loc.GetString("biological-surgery-data-component-loosen-organ-message"));
|
||||
|
||||
if (!_entMan.HasComponent<DoAfterComponent>(performer))
|
||||
{
|
||||
AddDisconnectedOrgan(target);
|
||||
return;
|
||||
}
|
||||
|
||||
if (await SurgeryDoAfter(performer))
|
||||
{
|
||||
AddDisconnectedOrgan(target);
|
||||
}
|
||||
}
|
||||
|
||||
private void RemoveOrganSurgery(IBodyPartContainer container, ISurgeon surgeon, EntityUid performer)
|
||||
{
|
||||
if (Parent == null) return;
|
||||
|
||||
if (_disconnectedOrgans.Count <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_disconnectedOrgans.Count == 1)
|
||||
{
|
||||
RemoveOrganSurgeryCallback(_disconnectedOrgans.First(), container, surgeon, performer);
|
||||
}
|
||||
else
|
||||
{
|
||||
surgeon.RequestMechanism(_disconnectedOrgans, RemoveOrganSurgeryCallback);
|
||||
}
|
||||
}
|
||||
|
||||
private async void RemoveOrganSurgeryCallback(SharedMechanismComponent? target, IBodyPartContainer container, ISurgeon surgeon,
|
||||
EntityUid performer)
|
||||
{
|
||||
if (Parent == null || target == null || !Parent.Mechanisms.Contains(target))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
performer.PopupMessage(Loc.GetString("biological-surgery-data-component-remove-organ-message"));
|
||||
|
||||
if (!_entMan.HasComponent<DoAfterComponent>(performer))
|
||||
{
|
||||
Parent.RemoveMechanism(target, _entMan.GetComponent<TransformComponent>(performer).Coordinates);
|
||||
RemoveDisconnectedOrgan(target);
|
||||
return;
|
||||
}
|
||||
|
||||
if (await SurgeryDoAfter(performer))
|
||||
{
|
||||
Parent.RemoveMechanism(target, _entMan.GetComponent<TransformComponent>(performer).Coordinates);
|
||||
RemoveDisconnectedOrgan(target);
|
||||
}
|
||||
}
|
||||
|
||||
private async void RemoveBodyPartSurgery(IBodyPartContainer container, ISurgeon surgeon, EntityUid performer)
|
||||
{
|
||||
if (Parent == null) return;
|
||||
if (container is not SharedBodyComponent body) return;
|
||||
|
||||
performer.PopupMessage(Loc.GetString("biological-surgery-data-component-remove-bodypart-message"));
|
||||
|
||||
if (await SurgeryDoAfter(performer))
|
||||
{
|
||||
body.RemovePart(Parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,278 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Body.Components;
|
||||
using Content.Server.Body.Surgery.Messages;
|
||||
using Content.Server.UserInterface;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Body.Surgery;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Popups;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.Body.Surgery.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Server-side component representing a generic tool capable of performing surgery.
|
||||
/// For instance, the scalpel.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public class SurgeryToolComponent : Component, ISurgeon, IAfterInteract
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entities = default!;
|
||||
|
||||
public override string Name => "SurgeryTool";
|
||||
|
||||
private readonly Dictionary<int, object> _optionsCache = new();
|
||||
|
||||
[DataField("baseOperateTime")]
|
||||
private float _baseOperateTime = 5;
|
||||
|
||||
private ISurgeon.MechanismRequestCallback? _callbackCache;
|
||||
|
||||
private int _idHash;
|
||||
|
||||
[DataField("surgeryType")]
|
||||
private SurgeryType _surgeryType = SurgeryType.Incision;
|
||||
|
||||
[ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(SurgeryUIKey.Key);
|
||||
|
||||
public SharedBodyComponent? BodyCache { get; private set; }
|
||||
|
||||
public EntityUid? PerformerCache { get; private set; }
|
||||
|
||||
async Task<bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
|
||||
{
|
||||
if (eventArgs.Target == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_entities.TryGetComponent(eventArgs.User, out ActorComponent? actor))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
CloseAllSurgeryUIs();
|
||||
|
||||
// Attempt surgery on a body by sending a list of operable parts for the client to choose from
|
||||
if (_entities.TryGetComponent(eventArgs.Target.Value, out SharedBodyComponent? body))
|
||||
{
|
||||
// Create dictionary to send to client (text to be shown : data sent back if selected)
|
||||
var toSend = new Dictionary<string, int>();
|
||||
|
||||
foreach (var (part, slot) in body.Parts)
|
||||
{
|
||||
// For each limb in the target, add it to our cache if it is a valid option.
|
||||
if (part.SurgeryCheck(_surgeryType))
|
||||
{
|
||||
_optionsCache.Add(_idHash, part);
|
||||
toSend.Add(slot.Id + ": " + part.Name, _idHash++);
|
||||
}
|
||||
}
|
||||
|
||||
if (_optionsCache.Count > 0)
|
||||
{
|
||||
OpenSurgeryUI(actor.PlayerSession);
|
||||
UpdateSurgeryUIBodyPartRequest(actor.PlayerSession, toSend);
|
||||
PerformerCache = eventArgs.User; // Also, cache the data.
|
||||
BodyCache = body;
|
||||
}
|
||||
else // If surgery cannot be performed, show message saying so.
|
||||
{
|
||||
NotUsefulPopup();
|
||||
}
|
||||
}
|
||||
else if (_entities.TryGetComponent<SharedBodyPartComponent?>(eventArgs.Target.Value, out var part))
|
||||
{
|
||||
// Attempt surgery on a DroppedBodyPart - there's only one possible target so no need for selection UI
|
||||
PerformerCache = eventArgs.User;
|
||||
|
||||
// If surgery can be performed...
|
||||
if (!part.SurgeryCheck(_surgeryType))
|
||||
{
|
||||
NotUsefulPopup();
|
||||
return true;
|
||||
}
|
||||
|
||||
// ...do the surgery.
|
||||
if (part.AttemptSurgery(_surgeryType, part, this,
|
||||
eventArgs.User))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Log error if the surgery fails somehow.
|
||||
Logger.Debug($"Error when trying to perform surgery on ${nameof(SharedBodyPartComponent)} {_entities.GetComponent<MetaDataComponent>(eventArgs.User).EntityName}");
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public float BaseOperationTime { get => _baseOperateTime; set => _baseOperateTime = value; }
|
||||
|
||||
public void RequestMechanism(IEnumerable<SharedMechanismComponent> options, ISurgeon.MechanismRequestCallback callback)
|
||||
{
|
||||
var toSend = new Dictionary<string, int>();
|
||||
foreach (var mechanism in options)
|
||||
{
|
||||
_optionsCache.Add(_idHash, mechanism);
|
||||
toSend.Add(mechanism.Name, _idHash++);
|
||||
}
|
||||
|
||||
if (_optionsCache.Count > 0 && PerformerCache != null)
|
||||
{
|
||||
OpenSurgeryUI(_entities.GetComponent<ActorComponent>(PerformerCache.Value).PlayerSession);
|
||||
UpdateSurgeryUIMechanismRequest(_entities.GetComponent<ActorComponent>(PerformerCache.Value).PlayerSession,
|
||||
toSend);
|
||||
_callbackCache = callback;
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Debug("Error on callback from mechanisms: there were no viable options to choose from!");
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
if (UserInterface != null)
|
||||
{
|
||||
UserInterface.OnReceiveMessage += UserInterfaceOnOnReceiveMessage;
|
||||
}
|
||||
}
|
||||
|
||||
private void OpenSurgeryUI(IPlayerSession session)
|
||||
{
|
||||
UserInterface?.Open(session);
|
||||
|
||||
var message = new SurgeryWindowOpenMessage(this);
|
||||
|
||||
#pragma warning disable 618
|
||||
SendMessage(message);
|
||||
#pragma warning restore 618
|
||||
_entities.EventBus.RaiseEvent(EventSource.Local, message);
|
||||
}
|
||||
|
||||
private void UpdateSurgeryUIBodyPartRequest(IPlayerSession session, Dictionary<string, int> options)
|
||||
{
|
||||
UserInterface?.SendMessage(new RequestBodyPartSurgeryUIMessage(options), session);
|
||||
}
|
||||
|
||||
private void UpdateSurgeryUIMechanismRequest(IPlayerSession session, Dictionary<string, int> options)
|
||||
{
|
||||
UserInterface?.SendMessage(new RequestMechanismSurgeryUIMessage(options), session);
|
||||
}
|
||||
|
||||
private void ClearUIData()
|
||||
{
|
||||
_optionsCache.Clear();
|
||||
|
||||
PerformerCache = null;
|
||||
BodyCache = null;
|
||||
_callbackCache = null;
|
||||
}
|
||||
|
||||
private void CloseSurgeryUI(IPlayerSession session)
|
||||
{
|
||||
UserInterface?.Close(session);
|
||||
ClearUIData();
|
||||
}
|
||||
|
||||
public void CloseAllSurgeryUIs()
|
||||
{
|
||||
UserInterface?.CloseAll();
|
||||
ClearUIData();
|
||||
}
|
||||
|
||||
private void UserInterfaceOnOnReceiveMessage(ServerBoundUserInterfaceMessage message)
|
||||
{
|
||||
switch (message.Message)
|
||||
{
|
||||
case ReceiveBodyPartSurgeryUIMessage msg:
|
||||
HandleReceiveBodyPart(msg.SelectedOptionId);
|
||||
break;
|
||||
case ReceiveMechanismSurgeryUIMessage msg:
|
||||
HandleReceiveMechanism(msg.SelectedOptionId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called after the client chooses from a list of possible
|
||||
/// <see cref="SharedBodyPartComponent"/> that can be operated on.
|
||||
/// </summary>
|
||||
private void HandleReceiveBodyPart(int key)
|
||||
{
|
||||
if (PerformerCache == null ||
|
||||
!_entities.TryGetComponent(PerformerCache.Value, out ActorComponent? actor))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CloseSurgeryUI(actor.PlayerSession);
|
||||
// TODO: sanity checks to see whether user is in range, user is still able-bodied, target is still the same, etc etc
|
||||
if (!_optionsCache.TryGetValue(key, out var targetObject) ||
|
||||
BodyCache == null)
|
||||
{
|
||||
NotUsefulAnymorePopup();
|
||||
return;
|
||||
}
|
||||
|
||||
var target = (SharedBodyPartComponent) targetObject;
|
||||
|
||||
// TODO BODY Reconsider
|
||||
if (!target.AttemptSurgery(_surgeryType, BodyCache, this, PerformerCache.Value))
|
||||
{
|
||||
NotUsefulAnymorePopup();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called after the client chooses from a list of possible
|
||||
/// <see cref="SharedMechanismComponent"/> to choose from.
|
||||
/// </summary>
|
||||
private void HandleReceiveMechanism(int key)
|
||||
{
|
||||
// TODO: sanity checks to see whether user is in range, user is still able-bodied, target is still the same, etc etc
|
||||
if (BodyCache == null ||
|
||||
!_optionsCache.TryGetValue(key, out var targetObject) ||
|
||||
targetObject is not MechanismComponent target ||
|
||||
PerformerCache == null ||
|
||||
!_entities.TryGetComponent(PerformerCache.Value, out ActorComponent? actor))
|
||||
{
|
||||
NotUsefulAnymorePopup();
|
||||
return;
|
||||
}
|
||||
|
||||
CloseSurgeryUI(actor.PlayerSession);
|
||||
_callbackCache?.Invoke(target, BodyCache, this, PerformerCache.Value);
|
||||
}
|
||||
|
||||
private void NotUsefulPopup()
|
||||
{
|
||||
if (PerformerCache == null) return;
|
||||
|
||||
BodyCache?.Owner.PopupMessage(PerformerCache.Value,
|
||||
Loc.GetString("surgery-tool-component-not-useful-message", ("bodyPart", Owner)));
|
||||
}
|
||||
|
||||
private void NotUsefulAnymorePopup()
|
||||
{
|
||||
if (PerformerCache == null) return;
|
||||
|
||||
BodyCache?.Owner.PopupMessage(PerformerCache.Value,
|
||||
Loc.GetString("surgery-tool-component-not-useful-anymore-message", ("bodyPart", Owner)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.Body.Surgery.Messages;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.GameTicking;
|
||||
using Content.Shared.Interaction.Helpers;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.Body.Surgery.Components
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class SurgeryToolSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
||||
|
||||
private readonly HashSet<SurgeryToolComponent> _openSurgeryUIs = new();
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<RoundRestartCleanupEvent>(Reset);
|
||||
SubscribeLocalEvent<SurgeryWindowOpenMessage>(OnSurgeryWindowOpen);
|
||||
SubscribeLocalEvent<SurgeryWindowCloseMessage>(OnSurgeryWindowClose);
|
||||
}
|
||||
|
||||
public void Reset(RoundRestartCleanupEvent ev)
|
||||
{
|
||||
_openSurgeryUIs.Clear();
|
||||
}
|
||||
|
||||
private void OnSurgeryWindowOpen(SurgeryWindowOpenMessage ev)
|
||||
{
|
||||
_openSurgeryUIs.Add(ev.Tool);
|
||||
}
|
||||
|
||||
private void OnSurgeryWindowClose(SurgeryWindowCloseMessage ev)
|
||||
{
|
||||
_openSurgeryUIs.Remove(ev.Tool);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
foreach (var tool in _openSurgeryUIs)
|
||||
{
|
||||
if (tool.PerformerCache == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tool.BodyCache == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!_actionBlockerSystem.CanInteract(tool.PerformerCache.Value) ||
|
||||
!tool.PerformerCache.Value.InRangeUnobstructed(tool.BodyCache))
|
||||
{
|
||||
tool.CloseAllSurgeryUIs();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
using Content.Server.Body.Surgery.Components;
|
||||
|
||||
namespace Content.Server.Body.Surgery.Messages
|
||||
{
|
||||
public class SurgeryWindowCloseMessage
|
||||
{
|
||||
public SurgeryWindowCloseMessage(SurgeryToolComponent tool)
|
||||
{
|
||||
Tool = tool;
|
||||
}
|
||||
|
||||
public SurgeryToolComponent Tool { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using Content.Server.Body.Surgery.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.Body.Surgery.Messages
|
||||
{
|
||||
#pragma warning disable 618
|
||||
public class SurgeryWindowOpenMessage : ComponentMessage
|
||||
#pragma warning restore 618
|
||||
{
|
||||
public SurgeryWindowOpenMessage(SurgeryToolComponent tool)
|
||||
{
|
||||
Tool = tool;
|
||||
}
|
||||
|
||||
public SurgeryToolComponent Tool { get; }
|
||||
}
|
||||
}
|
||||
@@ -41,13 +41,13 @@ namespace Content.Server.Body.Systems
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a list of ValueTuples of <see cref="T"/> and SharedMechanismComponent on each mechanism
|
||||
/// Returns a list of ValueTuples of <see cref="T"/> and MechanismComponent on each mechanism
|
||||
/// in the given body.
|
||||
/// </summary>
|
||||
/// <param name="uid">The entity to check for the component on.</param>
|
||||
/// <param name="body">The body to check for mechanisms on.</param>
|
||||
/// <typeparam name="T">The component to check for.</typeparam>
|
||||
public IEnumerable<(T Comp, SharedMechanismComponent Mech)> GetComponentsOnMechanisms<T>(EntityUid uid,
|
||||
public IEnumerable<(T Comp, MechanismComponent Mech)> GetComponentsOnMechanisms<T>(EntityUid uid,
|
||||
SharedBodyComponent? body=null) where T : Component
|
||||
{
|
||||
if (!Resolve(uid, ref body))
|
||||
@@ -62,7 +62,7 @@ namespace Content.Server.Body.Systems
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get a list of ValueTuples of <see cref="T"/> and SharedMechanismComponent on each mechanism
|
||||
/// Tries to get a list of ValueTuples of <see cref="T"/> and MechanismComponent on each mechanism
|
||||
/// in the given body.
|
||||
/// </summary>
|
||||
/// <param name="uid">The entity to check for the component on.</param>
|
||||
@@ -71,7 +71,7 @@ namespace Content.Server.Body.Systems
|
||||
/// <typeparam name="T">The component to check for.</typeparam>
|
||||
/// <returns>Whether any were found.</returns>
|
||||
public bool TryGetComponentsOnMechanisms<T>(EntityUid uid,
|
||||
[NotNullWhen(true)] out IEnumerable<(T Comp, SharedMechanismComponent Mech)>? comps,
|
||||
[NotNullWhen(true)] out IEnumerable<(T Comp, MechanismComponent Mech)>? comps,
|
||||
SharedBodyComponent? body=null) where T: Component
|
||||
{
|
||||
if (!Resolve(uid, ref body))
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
using Content.Server.Body.Components;
|
||||
using Content.Server.Ghost;
|
||||
using Content.Server.Ghost.Components;
|
||||
using Content.Server.Mind.Components;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Body.Events;
|
||||
using Content.Shared.MobState.Components;
|
||||
using Content.Shared.Movement.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
@@ -14,12 +15,12 @@ namespace Content.Server.Body.Systems
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<BrainComponent, AddedToBodyEvent>((uid, component, args) => HandleMind((args.Body).Owner, uid));
|
||||
SubscribeLocalEvent<BrainComponent, AddedToPartEvent>((uid, component, args) => HandleMind((args.Part).Owner, uid));
|
||||
SubscribeLocalEvent<BrainComponent, AddedToPartInBodyEvent>((uid, component, args) => HandleMind((args.Body).Owner, uid));
|
||||
SubscribeLocalEvent<BrainComponent, AddedToBodyEvent>((uid, _, args) => HandleMind((args.Body).Owner, uid));
|
||||
SubscribeLocalEvent<BrainComponent, AddedToPartEvent>((uid, _, args) => HandleMind((args.Part).Owner, uid));
|
||||
SubscribeLocalEvent<BrainComponent, AddedToPartInBodyEvent>((uid, _, args) => HandleMind((args.Body).Owner, uid));
|
||||
SubscribeLocalEvent<BrainComponent, RemovedFromBodyEvent>(OnRemovedFromBody);
|
||||
SubscribeLocalEvent<BrainComponent, RemovedFromPartEvent>((uid, component, args) => HandleMind(uid, (args.Old).Owner));
|
||||
SubscribeLocalEvent<BrainComponent, RemovedFromPartInBodyEvent>((uid, component, args) => HandleMind((args.OldBody).Owner, uid));
|
||||
SubscribeLocalEvent<BrainComponent, RemovedFromPartEvent>((uid, _, args) => HandleMind(uid, (args.Old).Owner));
|
||||
SubscribeLocalEvent<BrainComponent, RemovedFromPartInBodyEvent>((uid, _, args) => HandleMind((args.OldBody).Owner, uid));
|
||||
}
|
||||
|
||||
private void OnRemovedFromBody(EntityUid uid, BrainComponent component, RemovedFromBodyEvent args)
|
||||
@@ -36,8 +37,9 @@ namespace Content.Server.Body.Systems
|
||||
EntityManager.EnsureComponent<MindComponent>(newEntity);
|
||||
var oldMind = EntityManager.EnsureComponent<MindComponent>(oldEntity);
|
||||
|
||||
if (!EntityManager.HasComponent<IGhostOnMove>(newEntity))
|
||||
EntityManager.AddComponent<GhostOnMoveComponent>(newEntity);
|
||||
EnsureComp<GhostOnMoveComponent>(newEntity);
|
||||
if (HasComp<BodyComponent>(newEntity))
|
||||
Comp<GhostOnMoveComponent>(newEntity).MustBeDead = true;
|
||||
|
||||
// TODO: This is an awful solution.
|
||||
if (!EntityManager.HasComponent<IMoverComponent>(newEntity))
|
||||
|
||||
@@ -57,7 +57,7 @@ public class LungSystem : EntitySystem
|
||||
|
||||
public void Gasp(EntityUid uid,
|
||||
LungComponent? lung=null,
|
||||
SharedMechanismComponent? mech=null)
|
||||
MechanismComponent? mech=null)
|
||||
{
|
||||
if (!Resolve(uid, ref lung, ref mech))
|
||||
return;
|
||||
@@ -76,7 +76,7 @@ public class LungSystem : EntitySystem
|
||||
|
||||
public void UpdateLung(EntityUid uid,
|
||||
LungComponent? lung=null,
|
||||
SharedMechanismComponent? mech=null)
|
||||
MechanismComponent? mech=null)
|
||||
{
|
||||
if (!Resolve(uid, ref lung, ref mech))
|
||||
return;
|
||||
@@ -128,7 +128,7 @@ public class LungSystem : EntitySystem
|
||||
/// </summary>
|
||||
public void Inhale(EntityUid uid, float frameTime,
|
||||
LungComponent? lung=null,
|
||||
SharedMechanismComponent? mech=null)
|
||||
MechanismComponent? mech=null)
|
||||
{
|
||||
if (!Resolve(uid, ref lung, ref mech))
|
||||
return;
|
||||
@@ -159,7 +159,7 @@ public class LungSystem : EntitySystem
|
||||
/// </summary>
|
||||
public void TakeGasFrom(EntityUid uid, float frameTime, GasMixture from,
|
||||
LungComponent? lung=null,
|
||||
SharedMechanismComponent? mech=null)
|
||||
MechanismComponent? mech=null)
|
||||
{
|
||||
if (!Resolve(uid, ref lung, ref mech))
|
||||
return;
|
||||
@@ -186,7 +186,7 @@ public class LungSystem : EntitySystem
|
||||
/// </summary>
|
||||
public void Exhale(EntityUid uid, float frameTime,
|
||||
LungComponent? lung=null,
|
||||
SharedMechanismComponent? mech=null)
|
||||
MechanismComponent? mech=null)
|
||||
{
|
||||
if (!Resolve(uid, ref lung, ref mech))
|
||||
return;
|
||||
@@ -204,7 +204,7 @@ public class LungSystem : EntitySystem
|
||||
/// </summary>
|
||||
public void PushGasTo(EntityUid uid, GasMixture to,
|
||||
LungComponent? lung=null,
|
||||
SharedMechanismComponent? mech=null)
|
||||
MechanismComponent? mech=null)
|
||||
{
|
||||
if (!Resolve(uid, ref lung, ref mech))
|
||||
return;
|
||||
|
||||
@@ -3,6 +3,7 @@ using Content.Server.Body.Components;
|
||||
using Content.Server.Chemistry.Components.SolutionManager;
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Shared.Administration.Logs;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Database;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Content.Server.Body.Components;
|
||||
using Content.Server.Chemistry.Components.SolutionManager;
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Content.Server.Chemistry.ReactionEffects;
|
||||
using Content.Server.Destructible.Thresholds.Behaviors;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
@@ -9,11 +9,13 @@ using Robust.Shared.Serialization.Manager.Attributes;
|
||||
namespace Content.Server.Ghost.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(IGhostOnMove))]
|
||||
public class GhostOnMoveComponent : Component,IGhostOnMove
|
||||
public class GhostOnMoveComponent : Component
|
||||
{
|
||||
public override string Name => "GhostOnMove";
|
||||
|
||||
[DataField("canReturn")] public bool CanReturn { get; set; } = true;
|
||||
|
||||
[DataField("mustBeDead")]
|
||||
public bool MustBeDead = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ using Content.Server.Visible;
|
||||
using Content.Server.Warps;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Ghost;
|
||||
using Content.Shared.MobState.Components;
|
||||
using Content.Shared.Movement.EntitySystems;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects;
|
||||
@@ -53,6 +54,7 @@ namespace Content.Server.Ghost
|
||||
// Let's not ghost if our mind is visiting...
|
||||
if (EntityManager.HasComponent<VisitingMindComponent>(uid)) return;
|
||||
if (!EntityManager.TryGetComponent<MindComponent>(uid, out var mind) || !mind.HasMind || mind.Mind!.IsVisitingEntity) return;
|
||||
if (component.MustBeDead && TryComp<MobStateComponent>(uid, out var state) && !state.IsDead()) return;
|
||||
|
||||
_ticker.OnGhostAttempt(mind.Mind!, component.CanReturn);
|
||||
}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
namespace Content.Server.Ghost
|
||||
{
|
||||
public interface IGhostOnMove
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Robust.Server.Player;
|
||||
using Content.Server.Mind.Commands;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
Reference in New Issue
Block a user