BodySystem stuff 2: overused boogaloo (#1174)

Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
This commit is contained in:
GlassEclipse
2020-07-02 13:51:14 -05:00
committed by GitHub
parent 7d346ede28
commit 610ab8bf50
30 changed files with 1493 additions and 688 deletions

View File

@@ -1,153 +0,0 @@
using System;
using System.Collections.Generic;
using Content.Server.BodySystem;
using Content.Server.GameObjects.EntitySystems;
using Content.Server.Utility;
using Content.Shared.BodySystem;
using Content.Shared.GameObjects;
using Content.Shared.GameObjects.Components.Items;
using Robust.Server.GameObjects;
using Robust.Server.GameObjects.EntitySystems;
using Robust.Server.Interfaces.Player;
using Robust.Server.Player;
using Robust.Shared.Enums;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.Interfaces.Network;
using Robust.Shared.Interfaces.Physics;
using Robust.Shared.Interfaces.Timing;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Maths;
using Robust.Shared.Players;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Weapon.Melee
{
[RegisterComponent]
public class ServerSurgeryToolComponent : SharedSurgeryToolComponent, IAfterInteract
{
public HashSet<IPlayerSession> SubscribedSessions = new HashSet<IPlayerSession>();
private Dictionary<string, BodyPart> _surgeryOptionsCache = new Dictionary<string, BodyPart>();
private BodyManagerComponent _targetCache;
private IEntity _performerCache;
void IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
{
if (!InteractionChecks.InRangeUnobstructed(eventArgs)) return;
if (eventArgs.Target == null)
return;
if (eventArgs.Target.TryGetComponent<BodySystem.BodyManagerComponent>(out BodySystem.BodyManagerComponent bodyManager))
{
_surgeryOptionsCache.Clear();
var toSend = new Dictionary<string, string>();
foreach (var(key, value) in bodyManager.PartDictionary) {
if (value.SurgeryCheck(_surgeryToolClass))
{
_surgeryOptionsCache.Add(key, value);
toSend.Add(key, value.Name);
}
}
if (_surgeryOptionsCache.Count > 0)
{
OpenSurgeryUI(eventArgs.User);
UpdateSurgeryUI(eventArgs.User, toSend);
_performerCache = eventArgs.User;
_targetCache = bodyManager;
}
}
}
/// <summary>
/// Called after the user selects a surgery target.
/// </summary>
void PerformSurgery(SelectSurgeryUIMessage msg)
{
//TODO: sanity checks to see whether user is in range, body is still same, etc etc
if (!_surgeryOptionsCache.TryGetValue(msg.TargetSlot, out BodyPart target))
{
Logger.Debug("Error when trying to perform surgery on bodypart in slot " + msg.TargetSlot + ": it was not found!");
throw new InvalidOperationException();
}
if (!target.AttemptSurgery(_surgeryToolClass, _targetCache, _performerCache))
{
Logger.Debug("Error when trying to perform surgery on bodypart " + target.Name + "!");
throw new InvalidOperationException();
}
CloseSurgeryUI(_performerCache);
}
public void OpenSurgeryUI(IEntity character)
{
var user_session = character.GetComponent<BasicActorComponent>().playerSession;
SubscribeSession(user_session);
SendNetworkMessage(new OpenSurgeryUIMessage(), user_session.ConnectedClient);
}
public void UpdateSurgeryUI(IEntity character, Dictionary<string, string> options)
{
var user_session = character.GetComponent<BasicActorComponent>().playerSession;
if (user_session.AttachedEntity == null)
{
UnsubscribeSession(user_session);
return;
}
SendNetworkMessage(new UpdateSurgeryUIMessage(options), user_session.ConnectedClient);
}
public void CloseSurgeryUI(IEntity character)
{
var user_session = character.GetComponent<BasicActorComponent>().playerSession;
SubscribeSession(user_session);
SendNetworkMessage(new CloseSurgeryUIMessage(), user_session.ConnectedClient);
}
public override void HandleNetworkMessage(ComponentMessage message, INetChannel channel, ICommonSession session = null)
{
base.HandleNetworkMessage(message, channel, session);
if (session == null)
{
throw new ArgumentException(nameof(session));
}
switch (message)
{
case CloseSurgeryUIMessage msg:
UnsubscribeSession(session as IPlayerSession);
break;
case SelectSurgeryUIMessage msg:
PerformSurgery(msg);
break;
}
}
public void SubscribeSession(IPlayerSession session)
{
if (!SubscribedSessions.Contains(session))
{
session.PlayerStatusChanged += HandlePlayerSessionChangeEvent;
SubscribedSessions.Add(session);
}
}
public void UnsubscribeSession(IPlayerSession session)
{
if (SubscribedSessions.Contains(session))
{
SubscribedSessions.Remove(session);
SendNetworkMessage(new CloseSurgeryUIMessage(), session.ConnectedClient);
}
}
public void HandlePlayerSessionChangeEvent(object obj, SessionStatusEventArgs SSEA)
{
if (SSEA.NewStatus != SessionStatus.InGame)
{
UnsubscribeSession(SSEA.Session);
}
}
}
}

View File

@@ -0,0 +1,30 @@
using Content.Shared.BodySystem;
using Robust.Shared.Interfaces.GameObjects;
using System;
using System.Collections.Generic;
namespace Content.Server.BodySystem
{
/// <summary>
/// Interface representing an entity capable of performing surgery (performing operations on an <see cref="ISurgeryData"/> class).
/// For an example see <see cref="SurgeryToolComponent"/>, which inherits from this class.
/// </summary>
public interface ISurgeon
{
/// <summary>
/// How long it takes to perform a single surgery step (in seconds).
/// </summary>
public float BaseOperationTime { get; set; }
public delegate void MechanismRequestCallback(Mechanism target, IBodyPartContainer container, ISurgeon surgeon, IEntity performer);
/// <summary>
/// When performing a surgery, the <see cref="ISurgeryData"/> may sometimes require selecting from a set of Mechanisms to operate on.
/// This function is called in that scenario, and it is expected that you call the callback with one mechanism from the provided list.
/// </summary>
public void RequestMechanism(List<Mechanism> options, MechanismRequestCallback callback);
}
}

View File

@@ -0,0 +1,215 @@
using System;
using System.Collections.Generic;
using Content.Server.GameObjects.EntitySystems;
using Content.Shared.BodySystem;
using Content.Shared.GameObjects;
using Content.Shared.Interfaces;
using Robust.Server.GameObjects;
using Robust.Server.GameObjects.Components.UserInterface;
using Robust.Server.Interfaces.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Random;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Serialization;
namespace Content.Server.BodySystem
{
//TODO: add checks to close UI if user walks too far away from tool or target.
/// <summary>
/// Server-side component representing a generic tool capable of performing surgery. For instance, the scalpel.
/// </summary>
[RegisterComponent]
public class SurgeryToolComponent : Component, ISurgeon, IAfterInteract
{
public override string Name => "SurgeryTool";
public override uint? NetID => ContentNetIDs.SURGERY;
#pragma warning disable 649
[Dependency] private readonly ISharedNotifyManager _sharedNotifyManager;
#pragma warning restore 649
public float BaseOperationTime { get => _baseOperateTime; set => _baseOperateTime = value; }
private float _baseOperateTime;
private SurgeryType _surgeryType;
private HashSet<IPlayerSession> _subscribedSessions = new HashSet<IPlayerSession>();
private BoundUserInterface _userInterface;
private Dictionary<int, object> _optionsCache = new Dictionary<int, object>();
private IEntity _performerCache;
private BodyManagerComponent _bodyManagerComponentCache;
private ISurgeon.MechanismRequestCallback _callbackCache;
private int _idHash = 0;
public override void Initialize()
{
base.Initialize();
_userInterface = Owner.GetComponent<ServerUserInterfaceComponent>().GetBoundUserInterface(GenericSurgeryUiKey.Key);
_userInterface.OnReceiveMessage += UserInterfaceOnOnReceiveMessage;
}
void IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
{
if (eventArgs.Target == null)
return;
CloseAllSurgeryUIs();
_optionsCache.Clear();
_performerCache = null;
_bodyManagerComponentCache = null;
_callbackCache = null;
if (eventArgs.Target.TryGetComponent<BodyManagerComponent>(out BodyManagerComponent bodyManager)) //Attempt surgery on a BodyManagerComponent by sending a list of operatable BodyParts to the client to choose from
{
var toSend = new Dictionary<string, int>(); //Create dictionary to send to client (text to be shown : data sent back if selected)
foreach (var(key, value) in bodyManager.PartDictionary) { //For each limb in the target, add it to our cache if it is a valid option.
if (value.SurgeryCheck(_surgeryType))
{
_optionsCache.Add(_idHash, value);
toSend.Add(key + ": " + value.Name, _idHash++);
}
}
if (_optionsCache.Count > 0)
{
OpenSurgeryUI(eventArgs.User.GetComponent<BasicActorComponent>().playerSession);
UpdateSurgeryUIBodyPartRequest(eventArgs.User.GetComponent<BasicActorComponent>().playerSession, toSend);
_performerCache = eventArgs.User; //Also, cache the data.
_bodyManagerComponentCache = bodyManager;
}
else //If surgery cannot be performed, show message saying so.
{
_sharedNotifyManager.PopupMessage(eventArgs.Target, eventArgs.User, "You see no useful way to use the " + Owner.Name + ".");
}
}
else if (eventArgs.Target.TryGetComponent<DroppedBodyPartComponent>(out DroppedBodyPartComponent droppedBodyPart)) //Attempt surgery on a DroppedBodyPart - there's only one possible target so no need for selection UI
{
_performerCache = eventArgs.User;
if (droppedBodyPart.ContainedBodyPart == null) //Throw error if the DroppedBodyPart has no data in it.
{
Logger.Debug("Surgery was attempted on an IEntity with a DroppedBodyPartComponent that doesn't have a BodyPart in it!");
throw new InvalidOperationException("A DroppedBodyPartComponent exists without a BodyPart in it!");
}
if (droppedBodyPart.ContainedBodyPart.SurgeryCheck(_surgeryType)) //If surgery can be performed...
{
if (!droppedBodyPart.ContainedBodyPart.AttemptSurgery(_surgeryType, droppedBodyPart, this, eventArgs.User)) //...do the surgery.
{
Logger.Debug("Error when trying to perform surgery on bodypart " + eventArgs.User.Name + "!"); //Log error if the surgery fails somehow.
throw new InvalidOperationException();
}
}
else //If surgery cannot be performed, show message saying so.
{
_sharedNotifyManager.PopupMessage(eventArgs.Target, eventArgs.User,"You see no useful way to use the " + Owner.Name + ".");
}
}
}
public void RequestMechanism(List<Mechanism> options, ISurgeon.MechanismRequestCallback callback)
{
var toSend = new Dictionary<string, int> ();
foreach (Mechanism mechanism in options)
{
_optionsCache.Add(_idHash, mechanism);
toSend.Add(mechanism.Name, _idHash++);
}
if (_optionsCache.Count > 0)
{
OpenSurgeryUI(_performerCache.GetComponent<BasicActorComponent>().playerSession);
UpdateSurgeryUIMechanismRequest(_performerCache.GetComponent<BasicActorComponent>().playerSession, toSend);
_callbackCache = callback;
}
else
{
Logger.Debug("Error on callback from mechanisms: there were no viable options to choose from!");
throw new InvalidOperationException();
}
}
public void OpenSurgeryUI(IPlayerSession session)
{
_userInterface.Open(session);
}
public void UpdateSurgeryUIBodyPartRequest(IPlayerSession session, Dictionary<string, int> options)
{
_userInterface.SendMessage(new RequestBodyPartSurgeryUIMessage(options), session);
}
public void UpdateSurgeryUIMechanismRequest(IPlayerSession session, Dictionary<string, int> options)
{
_userInterface.SendMessage(new RequestMechanismSurgeryUIMessage(options), session);
}
public void CloseSurgeryUI(IPlayerSession session)
{
_userInterface.Close(session);
}
public void CloseAllSurgeryUIs()
{
_userInterface.CloseAll();
}
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="BodyPart">BodyParts</see> that can be operated on.
/// </summary>
private void HandleReceiveBodyPart(int key)
{
CloseSurgeryUI(_performerCache.GetComponent<BasicActorComponent>().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 object targetObject))
{
_sharedNotifyManager.PopupMessage(_bodyManagerComponentCache.Owner, _performerCache, "You see no useful way to use the " + Owner.Name + " anymore.");
}
BodyPart target = targetObject as BodyPart;
if (!target.AttemptSurgery(_surgeryType, _bodyManagerComponentCache, this, _performerCache))
{
_sharedNotifyManager.PopupMessage(_bodyManagerComponentCache.Owner, _performerCache, "You see no useful way to use the " + Owner.Name + " anymore.");
}
}
/// <summary>
/// Called after the client chooses from a list of possible <see cref="Mechanism">Mechanisms</see> 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 (!_optionsCache.TryGetValue(key, out object targetObject))
{
_sharedNotifyManager.PopupMessage(_bodyManagerComponentCache.Owner, _performerCache, "You see no useful way to use the " + Owner.Name + " anymore.");
}
Mechanism target = targetObject as Mechanism;
CloseSurgeryUI(_performerCache.GetComponent<BasicActorComponent>().playerSession);
_callbackCache(target, _bodyManagerComponentCache, this, _performerCache);
}
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataField(ref _surgeryType, "surgeryType", SurgeryType.Incision);
serializer.DataField(ref _baseOperateTime, "baseOperateTime", 5);
}
}
}

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Content.Shared.BodySystem;
using Content.Shared.Interfaces;
using Robust.Shared.Interfaces.GameObjects;
@@ -11,113 +12,188 @@ using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
using YamlDotNet.RepresentationModel;
namespace Content.Server.BodySystem {
namespace Content.Server.BodySystem
{
/// <summary>
/// Data class representing the surgery state of a biological entity.
/// </summary>
public class BiologicalSurgeryData : ISurgeryData {
public class BiologicalSurgeryData : ISurgeryData
{
protected bool _skinOpened = false;
protected bool _vesselsClamped = false;
protected bool _skinRetracted = false;
protected Mechanism _targetOrgan;
protected List<Mechanism> _disconnectedOrgans = new List<Mechanism>();
public BiologicalSurgeryData(BodyPart parent) : base(parent) { }
public override SurgeryAction GetSurgeryStep(SurgeryToolType toolType)
public override SurgeryAction GetSurgeryStep(SurgeryType toolType)
{
if (_skinOpened)
if (toolType == SurgeryType.Amputation)
{
if (_vesselsClamped)
{
if (_skinRetracted)
{
if (_targetOrgan != null && toolType == SurgeryToolType.VesselCompression)
return RemoveOrganSurgery;
if (toolType == SurgeryToolType.Incision) //_targetOrgan is potentially given a value by DisconnectOrganSurgery.
return DisconnectOrganSurgery;
else if (toolType == SurgeryToolType.Cauterization)
return CautizerizeIncisionSurgery;
}
else
{
if (toolType == SurgeryToolType.Retraction)
return RetractSkinSurgery;
else if (toolType == SurgeryToolType.Cauterization)
return CautizerizeIncisionSurgery;
}
}
else
{
if (toolType == SurgeryToolType.VesselCompression)
return ClampVesselsSurgery;
else if (toolType == SurgeryToolType.Cauterization)
return CautizerizeIncisionSurgery;
}
return RemoveBodyPartSurgery;
}
else
if (!_skinOpened) //Case: skin is normal.
{
if (toolType == SurgeryToolType.Incision)
if (toolType == SurgeryType.Incision)
return OpenSkinSurgery;
}
else if (!_vesselsClamped) //Case: skin is opened, but not clamped.
{
if (toolType == SurgeryType.VesselCompression)
return ClampVesselsSurgery;
else if (toolType == SurgeryType.Cauterization)
return CautizerizeIncisionSurgery;
}
else if (!_skinRetracted) //Case: skin is opened and clamped, but not retracted.
{
if (toolType == SurgeryType.Retraction)
return RetractSkinSurgery;
else if (toolType == SurgeryType.Cauterization)
return CautizerizeIncisionSurgery;
}
else //Case: skin is fully open.
{
if (_parent.Mechanisms.Count > 0 && toolType == SurgeryType.VesselCompression && (_disconnectedOrgans.Except(_parent.Mechanisms).Count() != 0 || _parent.Mechanisms.Except(_disconnectedOrgans).Count() != 0))
return LoosenOrganSurgery;
else if (_disconnectedOrgans.Count > 0 && toolType == SurgeryType.Incision)
return RemoveOrganSurgery;
else if (toolType == SurgeryType.Cauterization)
return CautizerizeIncisionSurgery;
}
return null;
}
protected void OpenSkinSurgery(BodyManagerComponent target, IEntity performer)
public override string GetDescription(IEntity target)
{
ILocalizationManager localizationManager = IoCManager.Resolve<ILocalizationManager>();
performer.PopupMessage(performer, localizationManager.GetString("Cut open the skin..."));
string toReturn = "";
if (_skinOpened && !_vesselsClamped) //Case: skin is opened, but not clamped.
{
toReturn += Loc.GetString("The skin on {0:their} {1} has an incision, but it is prone to bleeding.\n", target, _parent.Name);
}
else if (_skinOpened && _vesselsClamped && !_skinRetracted) //Case: skin is opened and clamped, but not retracted.
{
toReturn += Loc.GetString("The skin on {0:their} {1} has an incision, but it is not retracted.\n", target, _parent.Name);
}
else if (_skinOpened && _vesselsClamped && _skinRetracted) //Case: skin is fully open.
{
toReturn += Loc.GetString("There is an incision on {0:their} {1}.\n", target, _parent.Name);
foreach (Mechanism mechanism in _disconnectedOrgans)
{
toReturn += Loc.GetString("{0:their} {1} is loose.\n", target, mechanism.Name);
}
}
return toReturn;
}
public override bool CanInstallMechanism(Mechanism toBeInstalled)
{
return _skinOpened && _vesselsClamped && _skinRetracted;
}
public override bool CanAttachBodyPart(BodyPart toBeConnected)
{
return true;
//TODO: if a bodypart is disconnected, you should have to do some surgery to allow another bodypart to be attached.
}
protected void OpenSkinSurgery(IBodyPartContainer container, ISurgeon surgeon, IEntity performer)
{
performer.PopupMessage(performer, Loc.GetString("Cut open the skin..."));
//Delay?
_skinOpened = true;
}
protected void ClampVesselsSurgery(BodyManagerComponent target, IEntity performer)
protected void ClampVesselsSurgery(IBodyPartContainer container, ISurgeon surgeon, IEntity performer)
{
ILocalizationManager localizationManager = IoCManager.Resolve<ILocalizationManager>();
performer.PopupMessage(performer, localizationManager.GetString("Clamp the vessels..."));
performer.PopupMessage(performer, Loc.GetString("Clamp the vessels..."));
//Delay?
_vesselsClamped = true;
}
protected void RetractSkinSurgery(BodyManagerComponent target, IEntity performer)
protected void RetractSkinSurgery(IBodyPartContainer container, ISurgeon surgeon, IEntity performer)
{
ILocalizationManager localizationManager = IoCManager.Resolve<ILocalizationManager>();
performer.PopupMessage(performer, localizationManager.GetString("Retract the skin..."));
performer.PopupMessage(performer, Loc.GetString("Retract the skin..."));
//Delay?
_skinRetracted = true;
}
protected void CautizerizeIncisionSurgery(BodyManagerComponent target, IEntity performer)
protected void CautizerizeIncisionSurgery(IBodyPartContainer container, ISurgeon surgeon, IEntity performer)
{
ILocalizationManager localizationManager = IoCManager.Resolve<ILocalizationManager>();
performer.PopupMessage(performer, localizationManager.GetString("Cauterize the incision..."));
performer.PopupMessage(performer, Loc.GetString("Cauterize the incision..."));
//Delay?
_skinOpened = false;
_vesselsClamped = false;
_skinRetracted = false;
}
protected void DisconnectOrganSurgery(BodyManagerComponent target, IEntity performer)
protected void LoosenOrganSurgery(IBodyPartContainer container, ISurgeon surgeon, IEntity performer)
{
Mechanism mechanismTarget = null;
//TODO: figureout popup, right now it just takes the first organ available if there is one
if (_parent.Mechanisms.Count > 0)
mechanismTarget = _parent.Mechanisms[0];
if (mechanismTarget != null)
if (_parent.Mechanisms.Count <= 0)
return;
List<Mechanism> toSend = new List<Mechanism>();
foreach (Mechanism mechanism in _parent.Mechanisms)
{
ILocalizationManager localizationManager = IoCManager.Resolve<ILocalizationManager>();
performer.PopupMessage(performer, localizationManager.GetString("Detach the organ..."));
//Delay?
_targetOrgan = mechanismTarget;
if (!_disconnectedOrgans.Contains(mechanism))
toSend.Add(mechanism);
}
if (toSend.Count > 0)
surgeon.RequestMechanism(toSend, LoosenOrganSurgeryCallback);
}
public void LoosenOrganSurgeryCallback(Mechanism target, IBodyPartContainer container, ISurgeon surgeon, IEntity performer)
{
if (target != null && _parent.Mechanisms.Contains(target))
{
performer.PopupMessage(performer, Loc.GetString("Loosen the organ..."));
//Delay?
_disconnectedOrgans.Add(target);
}
}
protected void RemoveOrganSurgery(IBodyPartContainer container, ISurgeon surgeon, IEntity performer)
{
if (_disconnectedOrgans.Count <= 0)
return;
if (_disconnectedOrgans.Count == 1)
RemoveOrganSurgeryCallback(_disconnectedOrgans[0], container, surgeon, performer);
else
surgeon.RequestMechanism(_disconnectedOrgans, RemoveOrganSurgeryCallback);
}
protected void RemoveOrganSurgery(BodyManagerComponent target, IEntity performer)
public void RemoveOrganSurgeryCallback(Mechanism target, IBodyPartContainer container, ISurgeon surgeon, IEntity performer)
{
if (_targetOrgan != null)
if (target != null && _parent.Mechanisms.Contains(target))
{
ILocalizationManager localizationManager = IoCManager.Resolve<ILocalizationManager>();
performer.PopupMessage(performer, localizationManager.GetString("Remove the organ..."));
performer.PopupMessage(performer, Loc.GetString("Remove the organ..."));
//Delay?
_parent.DropMechanism(performer, _targetOrgan);
_parent.DropMechanism(performer, target);
_disconnectedOrgans.Remove(target);
}
}
protected void RemoveBodyPartSurgery(IBodyPartContainer container, ISurgeon surgeon, IEntity performer)
{
if (!(container is BodyManagerComponent)) //This surgery requires a DroppedBodyPartComponent.
return;
BodyManagerComponent bmTarget = (BodyManagerComponent) container;
performer.PopupMessage(performer, Loc.GetString("Saw off the limb!"));
//Delay?
bmTarget.DisconnectBodyPart(_parent, true);
}
}
}

View File

@@ -8,24 +8,31 @@ using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
using YamlDotNet.RepresentationModel;
namespace Content.Server.BodySystem {
namespace Content.Server.BodySystem
{
/// <summary>
/// This data class represents the state of a BodyPart in regards to everything surgery related - whether there's an incision on it, whether the bone is broken, etc.
/// This data class represents the state of a <see cref="BodyPart"/> in regards to everything surgery related - whether there's an incision on it, whether the bone is broken, etc.
/// </summary>
public abstract class ISurgeryData {
public abstract class ISurgeryData
{
/// <summary>
/// The BodyPart this surgeryData is attached to. The ISurgeryData class should not exist without a BodyPart that it represents, and will not work correctly without it.
/// The <see cref="BodyPart"/> this surgeryData is attached to. The ISurgeryData class should not exist without a <see cref="BodyPart"/> that it
/// represents, and will throw errors if it is null.
/// </summary>
protected BodyPart _parent;
/// <summary>
/// The BodyPartType of the parent PartType.
/// The <see cref="BodyPartType"/> of the parent <see cref="BodyPart"/>.
/// </summary>
protected BodyPartType _parentType => _parent.PartType;
public delegate void SurgeryAction(BodyManagerComponent target, IEntity performer);
public delegate void SurgeryAction(IBodyPartContainer container, ISurgeon surgeon, IEntity performer);
public ISurgeryData(BodyPart parent)
{
@@ -33,29 +40,44 @@ namespace Content.Server.BodySystem {
}
/// <summary>
/// Gets the delegate corresponding to the surgery step using the given SurgeryToolType. Returns null if no surgery step can be performed.
/// Returns the description of this current <see cref="BodyPart"/> to be shown upon observing the given entity.
/// </summary>
public abstract SurgeryAction GetSurgeryStep(SurgeryToolType toolType);
public abstract string GetDescription(IEntity target);
/// <summary>
/// Returns whether the given SurgeryToolType can be used to perform a surgery.
/// Returns whether a <see cref="Mechanism"/> can be installed into the <see cref="BodyPart"/> this ISurgeryData represents.
/// </summary>
public bool CheckSurgery(SurgeryToolType toolType)
public abstract bool CanInstallMechanism(Mechanism toBeInstalled);
/// <summary>
/// Returns whether the given <see cref="BodyPart"/> can be connected to the <see cref="BodyPart"/> this ISurgeryData represents.
/// </summary>
public abstract bool CanAttachBodyPart(BodyPart toBeConnected);
/// <summary>
/// Gets the delegate corresponding to the surgery step using the given <see cref="SurgeryType"/>. Returns null if no surgery step can be performed.
/// </summary>
public abstract SurgeryAction GetSurgeryStep(SurgeryType toolType);
/// <summary>
/// Returns whether the given <see cref="SurgeryType"/> can be used to perform a surgery on the BodyPart this <see cref="ISurgeryData"/> represents.
/// </summary>
public bool CheckSurgery(SurgeryType toolType)
{
return GetSurgeryStep(toolType) != null;
}
/// <summary>
/// Attempts to perform surgery with the given tooltype. Returns whether the operation was successful.
/// Attempts to perform surgery of the given <see cref="SurgeryType"/>. Returns whether the operation was successful.
/// </summary>
/// /// <param name="toolType">The SurgeryToolType used for this surgery.</param>
/// /// <param name="performer">The entity performing the surgery.</param>
public bool PerformSurgery(SurgeryToolType toolType, BodyManagerComponent target, IEntity performer)
/// <param name="surgeryType">The <see cref="SurgeryType"/> used for this surgery.</param>
/// <param name="performer">The entity performing the surgery.</param>
public bool PerformSurgery(SurgeryType surgeryType, IBodyPartContainer container, ISurgeon surgeon, IEntity performer)
{
SurgeryAction step = GetSurgeryStep(toolType);
SurgeryAction step = GetSurgeryStep(surgeryType);
if (step == null)
return false;
step(target, performer);
step(container, surgeon, performer);
return true;
}