Merge branch 'master' into 2020-08-19-firelocks
This commit is contained in:
@@ -29,7 +29,7 @@ namespace Content.Server.GameObjects.Components
|
||||
{
|
||||
var random = IoCManager.Resolve<IRobustRandom>();
|
||||
var rand = random.Next(100);
|
||||
// Let's not pad ourselves on the back too hard.
|
||||
// Let's not pat ourselves on the back too hard.
|
||||
// 1% chance of zumos
|
||||
if (rand == 0) Type = PlaqueType.Zumos;
|
||||
// 9% FEA
|
||||
|
||||
@@ -0,0 +1,543 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Content.Server.Body;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Server.Interfaces.GameObjects.Components.Interaction;
|
||||
using Content.Shared.Body.Part.Properties.Movement;
|
||||
using Content.Shared.Body.Part.Properties.Other;
|
||||
using Content.Shared.GameObjects.Components.Body;
|
||||
using Content.Shared.GameObjects.Components.Damage;
|
||||
using Content.Shared.GameObjects.Components.Movement;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Body
|
||||
{
|
||||
public partial class BodyManagerComponent
|
||||
{
|
||||
private readonly Dictionary<string, IBodyPart> _parts = new Dictionary<string, IBodyPart>();
|
||||
|
||||
[ViewVariables] public BodyPreset Preset { get; private set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// All <see cref="IBodyPart"></see> with <see cref="LegProperty"></see>
|
||||
/// that are currently affecting move speed, mapped to how big that leg
|
||||
/// they're on is.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
private readonly Dictionary<IBodyPart, float> _activeLegs = new Dictionary<IBodyPart, float>();
|
||||
|
||||
/// <summary>
|
||||
/// Maps <see cref="BodyTemplate"/> slot name to the <see cref="IBodyPart"/>
|
||||
/// object filling it (if there is one).
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public IReadOnlyDictionary<string, IBodyPart> Parts => _parts;
|
||||
|
||||
/// <summary>
|
||||
/// List of all occupied slots in this body, taken from the values of
|
||||
/// <see cref="Parts"/>.
|
||||
/// </summary>
|
||||
public IEnumerable<string> OccupiedSlots => Parts.Keys;
|
||||
|
||||
/// <summary>
|
||||
/// List of all slots in this body, taken from the keys of
|
||||
/// <see cref="Template"/> slots.
|
||||
/// </summary>
|
||||
public IEnumerable<string> AllSlots => Template.Slots.Keys;
|
||||
|
||||
public bool TryAddPart(string slot, DroppedBodyPartComponent part, bool force = false)
|
||||
{
|
||||
DebugTools.AssertNotNull(part);
|
||||
|
||||
if (!TryAddPart(slot, part.ContainedBodyPart, force))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
part.Owner.Delete();
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TryAddPart(string slot, IBodyPart part, bool force = false)
|
||||
{
|
||||
DebugTools.AssertNotNull(part);
|
||||
DebugTools.AssertNotNull(slot);
|
||||
|
||||
// Make sure the given slot exists
|
||||
if (!force)
|
||||
{
|
||||
if (!HasSlot(slot))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// And that nothing is in it
|
||||
if (!_parts.TryAdd(slot, part))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_parts[slot] = part;
|
||||
}
|
||||
|
||||
part.Body = this;
|
||||
|
||||
var argsAdded = new BodyPartAddedEventArgs(part, slot);
|
||||
|
||||
foreach (var component in Owner.GetAllComponents<IBodyPartAdded>().ToArray())
|
||||
{
|
||||
component.BodyPartAdded(argsAdded);
|
||||
}
|
||||
|
||||
// TODO: Sort this duplicate out
|
||||
OnBodyChanged();
|
||||
|
||||
if (!Template.Layers.TryGetValue(slot, out var partMap) ||
|
||||
!_reflectionManager.TryParseEnumReference(partMap, out var partEnum))
|
||||
{
|
||||
Logger.Warning($"Template {Template.Name} has an invalid RSI map key {partMap} for body part {part.Name}.");
|
||||
return false;
|
||||
}
|
||||
|
||||
part.RSIMap = partEnum;
|
||||
|
||||
var partMessage = new BodyPartAddedMessage(part.RSIPath, part.RSIState, partEnum);
|
||||
|
||||
SendNetworkMessage(partMessage);
|
||||
|
||||
foreach (var mechanism in part.Mechanisms)
|
||||
{
|
||||
if (!Template.MechanismLayers.TryGetValue(mechanism.Id, out var mechanismMap))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!_reflectionManager.TryParseEnumReference(mechanismMap, out var mechanismEnum))
|
||||
{
|
||||
Logger.Warning($"Template {Template.Name} has an invalid RSI map key {mechanismMap} for mechanism {mechanism.Id}.");
|
||||
continue;
|
||||
}
|
||||
|
||||
var mechanismMessage = new MechanismSpriteAddedMessage(mechanismEnum);
|
||||
|
||||
SendNetworkMessage(mechanismMessage);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool HasPart(string slot)
|
||||
{
|
||||
return _parts.ContainsKey(slot);
|
||||
}
|
||||
|
||||
public void RemovePart(IBodyPart part, bool drop)
|
||||
{
|
||||
DebugTools.AssertNotNull(part);
|
||||
|
||||
var slotName = _parts.FirstOrDefault(x => x.Value == part).Key;
|
||||
|
||||
if (string.IsNullOrEmpty(slotName)) return;
|
||||
|
||||
RemovePart(slotName, drop);
|
||||
}
|
||||
|
||||
public bool RemovePart(string slot, bool drop)
|
||||
{
|
||||
DebugTools.AssertNotNull(slot);
|
||||
|
||||
if (!_parts.Remove(slot, out var part))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
IEntity? dropped = null;
|
||||
if (drop)
|
||||
{
|
||||
part.SpawnDropped(out dropped);
|
||||
}
|
||||
|
||||
part.Body = null;
|
||||
|
||||
var args = new BodyPartRemovedEventArgs(part, slot);
|
||||
|
||||
foreach (var component in Owner.GetAllComponents<IBodyPartRemoved>())
|
||||
{
|
||||
component.BodyPartRemoved(args);
|
||||
}
|
||||
|
||||
if (part.RSIMap != null)
|
||||
{
|
||||
var message = new BodyPartRemovedMessage(part.RSIMap, dropped?.Uid);
|
||||
SendNetworkMessage(message);
|
||||
}
|
||||
|
||||
foreach (var mechanism in part.Mechanisms)
|
||||
{
|
||||
if (!Template.MechanismLayers.TryGetValue(mechanism.Id, out var mechanismMap))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!_reflectionManager.TryParseEnumReference(mechanismMap, out var mechanismEnum))
|
||||
{
|
||||
Logger.Warning($"Template {Template.Name} has an invalid RSI map key {mechanismMap} for mechanism {mechanism.Id}.");
|
||||
continue;
|
||||
}
|
||||
|
||||
var mechanismMessage = new MechanismSpriteRemovedMessage(mechanismEnum);
|
||||
|
||||
SendNetworkMessage(mechanismMessage);
|
||||
}
|
||||
|
||||
if (CurrentDamageState == DamageState.Dead) return true;
|
||||
|
||||
// creadth: fall down if no legs
|
||||
if (part.PartType == BodyPartType.Leg && Parts.Count(x => x.Value.PartType == BodyPartType.Leg) == 0)
|
||||
{
|
||||
EntitySystem.Get<StandingStateSystem>().Down(Owner);
|
||||
}
|
||||
|
||||
// creadth: immediately kill entity if last vital part removed
|
||||
if (part.IsVital && Parts.Count(x => x.Value.PartType == part.PartType) == 0)
|
||||
{
|
||||
CurrentDamageState = DamageState.Dead;
|
||||
ForceHealthChangedEvent();
|
||||
}
|
||||
|
||||
if (TryGetSlotConnections(slot, out var connections))
|
||||
{
|
||||
foreach (var connectionName in connections)
|
||||
{
|
||||
if (TryGetPart(connectionName, out var result) && !ConnectedToCenter(result))
|
||||
{
|
||||
RemovePart(connectionName, drop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
OnBodyChanged();
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool RemovePart(IBodyPart part, [NotNullWhen(true)] out string? slot)
|
||||
{
|
||||
DebugTools.AssertNotNull(part);
|
||||
|
||||
var pair = _parts.FirstOrDefault(kvPair => kvPair.Value == part);
|
||||
|
||||
if (pair.Equals(default))
|
||||
{
|
||||
slot = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
slot = pair.Key;
|
||||
|
||||
return RemovePart(slot, false);
|
||||
}
|
||||
|
||||
public IEntity? DropPart(IBodyPart part)
|
||||
{
|
||||
DebugTools.AssertNotNull(part);
|
||||
|
||||
if (!_parts.ContainsValue(part))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!RemovePart(part, out var slotName))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Call disconnect on all limbs that were hanging off this limb.
|
||||
if (TryGetSlotConnections(slotName, out var connections))
|
||||
{
|
||||
// This loop is an unoptimized travesty. TODO: optimize to be less shit
|
||||
foreach (var connectionName in connections)
|
||||
{
|
||||
if (TryGetPart(connectionName, out var result) && !ConnectedToCenter(result))
|
||||
{
|
||||
RemovePart(connectionName, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
part.SpawnDropped(out var dropped);
|
||||
|
||||
OnBodyChanged();
|
||||
return dropped;
|
||||
}
|
||||
|
||||
public bool ConnectedToCenter(IBodyPart part)
|
||||
{
|
||||
var searchedSlots = new List<string>();
|
||||
|
||||
return TryGetSlot(part, out var result) &&
|
||||
ConnectedToCenterPartRecursion(searchedSlots, result);
|
||||
}
|
||||
|
||||
private bool ConnectedToCenterPartRecursion(ICollection<string> searchedSlots, string slotName)
|
||||
{
|
||||
if (!TryGetPart(slotName, out var part))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (part == CenterPart())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
searchedSlots.Add(slotName);
|
||||
|
||||
if (!TryGetSlotConnections(slotName, out var connections))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var connection in connections)
|
||||
{
|
||||
if (!searchedSlots.Contains(connection) &&
|
||||
ConnectedToCenterPartRecursion(searchedSlots, connection))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public IBodyPart? CenterPart()
|
||||
{
|
||||
Parts.TryGetValue(Template.CenterSlot, out var center);
|
||||
return center;
|
||||
}
|
||||
|
||||
public bool HasSlot(string slot)
|
||||
{
|
||||
return Template.HasSlot(slot);
|
||||
}
|
||||
|
||||
public bool TryGetPart(string slot, [NotNullWhen(true)] out IBodyPart? result)
|
||||
{
|
||||
return Parts.TryGetValue(slot, out result);
|
||||
}
|
||||
|
||||
public bool TryGetSlot(IBodyPart part, [NotNullWhen(true)] out string? slot)
|
||||
{
|
||||
// We enforce that there is only one of each value in the dictionary,
|
||||
// so we can iterate through the dictionary values to get the key from there.
|
||||
var pair = Parts.FirstOrDefault(x => x.Value == part);
|
||||
slot = pair.Key;
|
||||
|
||||
return !pair.Equals(default);
|
||||
}
|
||||
|
||||
public bool TryGetSlotType(string slot, out BodyPartType result)
|
||||
{
|
||||
return Template.Slots.TryGetValue(slot, out result);
|
||||
}
|
||||
|
||||
public bool TryGetSlotConnections(string slot, [NotNullWhen(true)] out List<string>? connections)
|
||||
{
|
||||
return Template.Connections.TryGetValue(slot, out connections);
|
||||
}
|
||||
|
||||
public bool TryGetPartConnections(string slot, [NotNullWhen(true)] out List<IBodyPart>? result)
|
||||
{
|
||||
result = null;
|
||||
|
||||
if (!Template.Connections.TryGetValue(slot, out var connections))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var toReturn = new List<IBodyPart>();
|
||||
foreach (var connection in connections)
|
||||
{
|
||||
if (TryGetPart(connection, out var partResult))
|
||||
{
|
||||
toReturn.Add(partResult);
|
||||
}
|
||||
}
|
||||
|
||||
if (toReturn.Count <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
result = toReturn;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TryGetPartConnections(IBodyPart part, [NotNullWhen(true)] out List<IBodyPart>? connections)
|
||||
{
|
||||
connections = null;
|
||||
|
||||
return TryGetSlot(part, out var slotName) &&
|
||||
TryGetPartConnections(slotName, out connections);
|
||||
}
|
||||
|
||||
public List<IBodyPart> GetPartsOfType(BodyPartType type)
|
||||
{
|
||||
var toReturn = new List<IBodyPart>();
|
||||
|
||||
foreach (var part in Parts.Values)
|
||||
{
|
||||
if (part.PartType == type)
|
||||
{
|
||||
toReturn.Add(part);
|
||||
}
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
private void CalculateSpeed()
|
||||
{
|
||||
if (!Owner.TryGetComponent(out MovementSpeedModifierComponent? playerMover))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float speedSum = 0;
|
||||
foreach (var part in _activeLegs.Keys)
|
||||
{
|
||||
if (!part.HasProperty<LegProperty>())
|
||||
{
|
||||
_activeLegs.Remove(part);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var (key, value) in _activeLegs)
|
||||
{
|
||||
if (key.TryGetProperty(out LegProperty? leg))
|
||||
{
|
||||
// Speed of a leg = base speed * (1+log1024(leg length))
|
||||
speedSum += leg.Speed * (1 + (float) Math.Log(value, 1024.0));
|
||||
}
|
||||
}
|
||||
|
||||
if (speedSum <= 0.001f || _activeLegs.Count <= 0)
|
||||
{
|
||||
playerMover.BaseWalkSpeed = 0.8f;
|
||||
playerMover.BaseSprintSpeed = 2.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Extra legs stack diminishingly.
|
||||
// Final speed = speed sum/(leg count-log4(leg count))
|
||||
playerMover.BaseWalkSpeed =
|
||||
speedSum / (_activeLegs.Count - (float) Math.Log(_activeLegs.Count, 4.0));
|
||||
|
||||
playerMover.BaseSprintSpeed = playerMover.BaseWalkSpeed * 1.75f;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the layout of this body changes.
|
||||
/// </summary>
|
||||
private void OnBodyChanged()
|
||||
{
|
||||
// Calculate move speed based on this body.
|
||||
if (Owner.HasComponent<MovementSpeedModifierComponent>())
|
||||
{
|
||||
_activeLegs.Clear();
|
||||
var legParts = Parts.Values.Where(x => x.HasProperty(typeof(LegProperty)));
|
||||
|
||||
foreach (var part in legParts)
|
||||
{
|
||||
var footDistance = DistanceToNearestFoot(part);
|
||||
|
||||
if (Math.Abs(footDistance - float.MinValue) > 0.001f)
|
||||
{
|
||||
_activeLegs.Add(part, footDistance);
|
||||
}
|
||||
}
|
||||
|
||||
CalculateSpeed();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the combined length of the distance to the nearest <see cref="BodyPart"/> with a
|
||||
/// <see cref="FootProperty"/>. Returns <see cref="float.MinValue"/>
|
||||
/// if there is no foot found. If you consider a <see cref="BodyManagerComponent"/> a node map, then it will look for
|
||||
/// a foot node from the given node. It can
|
||||
/// only search through BodyParts with <see cref="ExtensionProperty"/>.
|
||||
/// </summary>
|
||||
public float DistanceToNearestFoot(IBodyPart source)
|
||||
{
|
||||
if (source.HasProperty<FootProperty>() && source.TryGetProperty<ExtensionProperty>(out var property))
|
||||
{
|
||||
return property.ReachDistance;
|
||||
}
|
||||
|
||||
return LookForFootRecursion(source, new List<BodyPart>());
|
||||
}
|
||||
|
||||
private float LookForFootRecursion(IBodyPart current,
|
||||
ICollection<BodyPart> searchedParts)
|
||||
{
|
||||
if (!current.TryGetProperty<ExtensionProperty>(out var extProperty))
|
||||
{
|
||||
return float.MinValue;
|
||||
}
|
||||
|
||||
// Get all connected parts if the current part has an extension property
|
||||
if (!TryGetPartConnections(current, out var connections))
|
||||
{
|
||||
return float.MinValue;
|
||||
}
|
||||
|
||||
// If a connected BodyPart is a foot, return this BodyPart's length.
|
||||
foreach (var connection in connections)
|
||||
{
|
||||
if (!searchedParts.Contains(connection) && connection.HasProperty<FootProperty>())
|
||||
{
|
||||
return extProperty.ReachDistance;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, get the recursion values of all connected BodyParts and
|
||||
// store them in a list.
|
||||
var distances = new List<float>();
|
||||
foreach (var connection in connections)
|
||||
{
|
||||
if (!searchedParts.Contains(connection))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var result = LookForFootRecursion(connection, searchedParts);
|
||||
|
||||
if (Math.Abs(result - float.MinValue) > 0.001f)
|
||||
{
|
||||
distances.Add(result);
|
||||
}
|
||||
}
|
||||
|
||||
// If one or more of the searches found a foot, return the smallest one
|
||||
// and add this ones length.
|
||||
if (distances.Count > 0)
|
||||
{
|
||||
return distances.Min<float>() + extProperty.ReachDistance;
|
||||
}
|
||||
|
||||
return float.MinValue;
|
||||
|
||||
// No extension property, no go.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,16 +2,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Content.Server.Body;
|
||||
using Content.Server.Body.Network;
|
||||
using Content.Server.GameObjects.Components.Metabolism;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Server.Interfaces.GameObjects.Components.Interaction;
|
||||
using Content.Server.Observer;
|
||||
using Content.Shared.Body.Part;
|
||||
using Content.Shared.Body.Part.Properties.Movement;
|
||||
using Content.Shared.Body.Part.Properties.Other;
|
||||
using Content.Shared.Body.Preset;
|
||||
using Content.Shared.Body.Template;
|
||||
using Content.Shared.GameObjects.Components.Body;
|
||||
@@ -19,11 +15,8 @@ using Content.Shared.GameObjects.Components.Damage;
|
||||
using Content.Shared.GameObjects.Components.Movement;
|
||||
using Robust.Server.Interfaces.Player;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Reflection;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
@@ -39,8 +32,9 @@ namespace Content.Server.GameObjects.Components.Body
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(IDamageableComponent))]
|
||||
[ComponentReference(typeof(ISharedBodyManagerComponent))]
|
||||
[ComponentReference(typeof(IBodyPartManager))]
|
||||
[ComponentReference(typeof(IBodyManagerComponent))]
|
||||
public class BodyManagerComponent : SharedBodyManagerComponent, IBodyPartContainer, IRelayMoveInput, IBodyManagerComponent
|
||||
public partial class BodyManagerComponent : SharedBodyManagerComponent, IBodyPartContainer, IRelayMoveInput, IBodyManagerComponent
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IBodyNetworkFactory _bodyNetworkFactory = default!;
|
||||
@@ -48,41 +42,10 @@ namespace Content.Server.GameObjects.Components.Body
|
||||
|
||||
[ViewVariables] private string _presetName = default!;
|
||||
|
||||
private readonly Dictionary<string, IBodyPart> _parts = new Dictionary<string, IBodyPart>();
|
||||
|
||||
[ViewVariables] private readonly Dictionary<Type, BodyNetwork> _networks = new Dictionary<Type, BodyNetwork>();
|
||||
|
||||
/// <summary>
|
||||
/// All <see cref="IBodyPart"></see> with <see cref="LegProperty"></see>
|
||||
/// that are currently affecting move speed, mapped to how big that leg
|
||||
/// they're on is.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
private readonly Dictionary<IBodyPart, float> _activeLegs = new Dictionary<IBodyPart, float>();
|
||||
|
||||
[ViewVariables] public BodyTemplate Template { get; private set; } = default!;
|
||||
|
||||
[ViewVariables] public BodyPreset Preset { get; private set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// Maps <see cref="BodyTemplate"/> slot name to the <see cref="IBodyPart"/>
|
||||
/// object filling it (if there is one).
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public IReadOnlyDictionary<string, IBodyPart> Parts => _parts;
|
||||
|
||||
/// <summary>
|
||||
/// List of all slots in this body, taken from the keys of
|
||||
/// <see cref="Template"/> slots.
|
||||
/// </summary>
|
||||
public IEnumerable<string> AllSlots => Template.Slots.Keys;
|
||||
|
||||
/// <summary>
|
||||
/// List of all occupied slots in this body, taken from the values of
|
||||
/// <see cref="Parts"/>.
|
||||
/// </summary>
|
||||
public IEnumerable<string> OccupiedSlots => Parts.Keys;
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
@@ -92,14 +55,15 @@ namespace Content.Server.GameObjects.Components.Body
|
||||
"bodyTemplate.Humanoid",
|
||||
template =>
|
||||
{
|
||||
if (!_prototypeManager.TryIndex(template, out BodyTemplatePrototype templateData))
|
||||
if (!_prototypeManager.TryIndex(template, out BodyTemplatePrototype prototype))
|
||||
{
|
||||
// Invalid prototype
|
||||
throw new InvalidOperationException(
|
||||
$"No {nameof(BodyTemplatePrototype)} found with name {template}");
|
||||
}
|
||||
|
||||
Template = new BodyTemplate(templateData);
|
||||
Template = new BodyTemplate();
|
||||
Template.Initialize(prototype);
|
||||
},
|
||||
() => Template.Name);
|
||||
|
||||
@@ -108,14 +72,15 @@ namespace Content.Server.GameObjects.Components.Body
|
||||
"bodyPreset.BasicHuman",
|
||||
preset =>
|
||||
{
|
||||
if (!_prototypeManager.TryIndex(preset, out BodyPresetPrototype presetData))
|
||||
if (!_prototypeManager.TryIndex(preset, out BodyPresetPrototype prototype))
|
||||
{
|
||||
// Invalid prototype
|
||||
throw new InvalidOperationException(
|
||||
$"No {nameof(BodyPresetPrototype)} found with name {preset}");
|
||||
}
|
||||
|
||||
Preset = new BodyPreset(presetData);
|
||||
Preset = new BodyPreset();
|
||||
Preset.Initialize(prototype);
|
||||
},
|
||||
() => _presetName);
|
||||
}
|
||||
@@ -156,7 +121,7 @@ namespace Content.Server.GameObjects.Components.Body
|
||||
}
|
||||
|
||||
// Try and remove an existing limb if that exists.
|
||||
RemoveBodyPart(slotName, false);
|
||||
RemovePart(slotName, false);
|
||||
|
||||
// Add a new BodyPart with the BodyPartPrototype as a baseline to our
|
||||
// BodyComponent.
|
||||
@@ -167,21 +132,21 @@ namespace Content.Server.GameObjects.Components.Body
|
||||
OnBodyChanged(); // TODO: Duplicate code
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the current <see cref="BodyTemplate"/> to the given
|
||||
/// <see cref="BodyTemplate"/>.
|
||||
/// Attempts to keep previous <see cref="IBodyPart"/> if there is a
|
||||
/// slot for them in both <see cref="BodyTemplate"/>.
|
||||
/// </summary>
|
||||
public void ChangeBodyTemplate(BodyTemplatePrototype newTemplate)
|
||||
{
|
||||
foreach (var part in Parts)
|
||||
{
|
||||
// TODO: Make this work.
|
||||
}
|
||||
|
||||
OnBodyChanged();
|
||||
}
|
||||
// /// <summary>
|
||||
// /// Changes the current <see cref="BodyTemplate"/> to the given
|
||||
// /// <see cref="BodyTemplate"/>.
|
||||
// /// Attempts to keep previous <see cref="IBodyPart"/> if there is a
|
||||
// /// slot for them in both <see cref="BodyTemplate"/>.
|
||||
// /// </summary>
|
||||
// public void ChangeBodyTemplate(BodyTemplatePrototype newTemplate)
|
||||
// {
|
||||
// foreach (var part in Parts)
|
||||
// {
|
||||
// // TODO: Make this work.
|
||||
// }
|
||||
//
|
||||
// OnBodyChanged();
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// This method is called by <see cref="BodySystem.Update"/> before
|
||||
@@ -201,7 +166,7 @@ namespace Content.Server.GameObjects.Components.Body
|
||||
|
||||
foreach (var network in _networks.Values)
|
||||
{
|
||||
network.Update(frameTime);
|
||||
network.PreMetabolism(frameTime);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,73 +188,7 @@ namespace Content.Server.GameObjects.Components.Body
|
||||
|
||||
foreach (var network in _networks.Values)
|
||||
{
|
||||
network.Update(frameTime);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the layout of this body changes.
|
||||
/// </summary>
|
||||
private void OnBodyChanged()
|
||||
{
|
||||
// Calculate move speed based on this body.
|
||||
if (Owner.HasComponent<MovementSpeedModifierComponent>())
|
||||
{
|
||||
_activeLegs.Clear();
|
||||
var legParts = Parts.Values.Where(x => x.HasProperty(typeof(LegProperty)));
|
||||
|
||||
foreach (var part in legParts)
|
||||
{
|
||||
var footDistance = DistanceToNearestFoot(this, part);
|
||||
|
||||
if (Math.Abs(footDistance - float.MinValue) > 0.001f)
|
||||
{
|
||||
_activeLegs.Add(part, footDistance);
|
||||
}
|
||||
}
|
||||
|
||||
CalculateSpeed();
|
||||
}
|
||||
}
|
||||
|
||||
private void CalculateSpeed()
|
||||
{
|
||||
if (!Owner.TryGetComponent(out MovementSpeedModifierComponent? playerMover))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float speedSum = 0;
|
||||
foreach (var part in _activeLegs.Keys)
|
||||
{
|
||||
if (!part.HasProperty<LegProperty>())
|
||||
{
|
||||
_activeLegs.Remove(part);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var (key, value) in _activeLegs)
|
||||
{
|
||||
if (key.TryGetProperty(out LegProperty? leg))
|
||||
{
|
||||
// Speed of a leg = base speed * (1+log1024(leg length))
|
||||
speedSum += leg.Speed * (1 + (float) Math.Log(value, 1024.0));
|
||||
}
|
||||
}
|
||||
|
||||
if (speedSum <= 0.001f || _activeLegs.Count <= 0)
|
||||
{
|
||||
playerMover.BaseWalkSpeed = 0.8f;
|
||||
playerMover.BaseSprintSpeed = 2.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Extra legs stack diminishingly.
|
||||
// Final speed = speed sum/(leg count-log4(leg count))
|
||||
playerMover.BaseWalkSpeed =
|
||||
speedSum / (_activeLegs.Count - (float) Math.Log(_activeLegs.Count, 4.0));
|
||||
|
||||
playerMover.BaseSprintSpeed = playerMover.BaseWalkSpeed * 1.75f;
|
||||
network.PostMetabolism(frameTime);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -301,482 +200,6 @@ namespace Content.Server.GameObjects.Components.Body
|
||||
}
|
||||
}
|
||||
|
||||
#region BodyPart Functions
|
||||
|
||||
/// <summary>
|
||||
/// Recursively searches for if <see cref="target"/> is connected to
|
||||
/// the center. Not efficient (O(n^2)), but most bodies don't have a ton
|
||||
/// of <see cref="IBodyPart"/>s.
|
||||
/// </summary>
|
||||
/// <param name="target">The body part to find the center for.</param>
|
||||
/// <returns>True if it is connected to the center, false otherwise.</returns>
|
||||
private bool ConnectedToCenterPart(IBodyPart target)
|
||||
{
|
||||
var searchedSlots = new List<string>();
|
||||
|
||||
return TryGetSlotName(target, out var result) &&
|
||||
ConnectedToCenterPartRecursion(searchedSlots, result);
|
||||
}
|
||||
|
||||
private bool ConnectedToCenterPartRecursion(ICollection<string> searchedSlots, string slotName)
|
||||
{
|
||||
if (!TryGetBodyPart(slotName, out var part))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (part == GetCenterBodyPart())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
searchedSlots.Add(slotName);
|
||||
|
||||
if (!TryGetBodyPartConnections(slotName, out List<string> connections))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var connection in connections)
|
||||
{
|
||||
if (!searchedSlots.Contains(connection) &&
|
||||
ConnectedToCenterPartRecursion(searchedSlots, connection))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds the central <see cref="IBodyPart"/>, if any, of this body based on
|
||||
/// the <see cref="BodyTemplate"/>. For humans, this is the torso.
|
||||
/// </summary>
|
||||
/// <returns>The <see cref="BodyPart"/> if one exists, null otherwise.</returns>
|
||||
private IBodyPart? GetCenterBodyPart()
|
||||
{
|
||||
Parts.TryGetValue(Template.CenterSlot, out var center);
|
||||
return center;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether the given slot name exists within the current
|
||||
/// <see cref="BodyTemplate"/>.
|
||||
/// </summary>
|
||||
private bool SlotExists(string slotName)
|
||||
{
|
||||
return Template.SlotExists(slotName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds the <see cref="IBodyPart"/> in the given <see cref="slotName"/> if
|
||||
/// one exists.
|
||||
/// </summary>
|
||||
/// <param name="slotName">The slot to search in.</param>
|
||||
/// <param name="result">The body part in that slot, if any.</param>
|
||||
/// <returns>True if found, false otherwise.</returns>
|
||||
private bool TryGetBodyPart(string slotName, [NotNullWhen(true)] out IBodyPart? result)
|
||||
{
|
||||
return Parts.TryGetValue(slotName, out result!);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds the slotName that the given <see cref="IBodyPart"/> resides in.
|
||||
/// </summary>
|
||||
/// <param name="part">The <see cref="IBodyPart"/> to find the slot for.</param>
|
||||
/// <param name="result">The slot found, if any.</param>
|
||||
/// <returns>True if a slot was found, false otherwise</returns>
|
||||
private bool TryGetSlotName(IBodyPart part, [NotNullWhen(true)] out string result)
|
||||
{
|
||||
// We enforce that there is only one of each value in the dictionary,
|
||||
// so we can iterate through the dictionary values to get the key from there.
|
||||
var pair = Parts.FirstOrDefault(x => x.Value == part);
|
||||
result = pair.Key;
|
||||
|
||||
return !pair.Equals(default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds the <see cref="BodyPartType"/> in the given
|
||||
/// <see cref="slotName"/> if one exists.
|
||||
/// </summary>
|
||||
/// <param name="slotName">The slot to search in.</param>
|
||||
/// <param name="result">
|
||||
/// The <see cref="BodyPartType"/> of that slot, if any.
|
||||
/// </param>
|
||||
/// <returns>True if found, false otherwise.</returns>
|
||||
public bool TryGetSlotType(string slotName, out BodyPartType result)
|
||||
{
|
||||
return Template.Slots.TryGetValue(slotName, out result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds the names of all slots connected to the given
|
||||
/// <see cref="slotName"/> for the template.
|
||||
/// </summary>
|
||||
/// <param name="slotName">The slot to search in.</param>
|
||||
/// <param name="connections">The connections found, if any.</param>
|
||||
/// <returns>True if the connections are found, false otherwise.</returns>
|
||||
private bool TryGetBodyPartConnections(string slotName, [NotNullWhen(true)] out List<string> connections)
|
||||
{
|
||||
return Template.Connections.TryGetValue(slotName, out connections!);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Grabs all occupied slots connected to the given slot,
|
||||
/// regardless of whether the given <see cref="slotName"/> is occupied.
|
||||
/// </summary>
|
||||
/// <param name="slotName">The slot name to find connections from.</param>
|
||||
/// <param name="result">The connected body parts, if any.</param>
|
||||
/// <returns>
|
||||
/// True if successful, false if there was an error or no connected
|
||||
/// <see cref="BodyPart"/>s were found.
|
||||
/// </returns>
|
||||
public bool TryGetBodyPartConnections(string slotName, [NotNullWhen(true)] out List<IBodyPart> result)
|
||||
{
|
||||
result = null!;
|
||||
|
||||
if (!Template.Connections.TryGetValue(slotName, out var connections))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var toReturn = new List<IBodyPart>();
|
||||
foreach (var connection in connections)
|
||||
{
|
||||
if (TryGetBodyPart(connection, out var bodyPartResult))
|
||||
{
|
||||
toReturn.Add(bodyPartResult);
|
||||
}
|
||||
}
|
||||
|
||||
if (toReturn.Count <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
result = toReturn;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Grabs all parts connected to the given <see cref="part"/>, regardless
|
||||
/// of whether the given <see cref="part"/> is occupied.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// True if successful, false if there was an error or no connected
|
||||
/// <see cref="IBodyPart"/>s were found.
|
||||
/// </returns>
|
||||
private bool TryGetBodyPartConnections(IBodyPart part, [NotNullWhen(true)] out List<IBodyPart> result)
|
||||
{
|
||||
result = null!;
|
||||
|
||||
return TryGetSlotName(part, out var slotName) &&
|
||||
TryGetBodyPartConnections(slotName, out result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Grabs all <see cref="IBodyPart"/> of the given type in this body.
|
||||
/// </summary>
|
||||
public List<IBodyPart> GetBodyPartsOfType(BodyPartType type)
|
||||
{
|
||||
var toReturn = new List<IBodyPart>();
|
||||
|
||||
foreach (var part in Parts.Values)
|
||||
{
|
||||
if (part.PartType == type)
|
||||
{
|
||||
toReturn.Add(part);
|
||||
}
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Installs the given <see cref="DroppedBodyPartComponent"/> into the
|
||||
/// given slot, deleting the <see cref="IEntity"/> afterwards.
|
||||
/// </summary>
|
||||
/// <returns>True if successful, false otherwise.</returns>
|
||||
public bool InstallDroppedBodyPart(DroppedBodyPartComponent part, string slotName)
|
||||
{
|
||||
DebugTools.AssertNotNull(part);
|
||||
|
||||
if (!TryAddPart(slotName, part.ContainedBodyPart))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
part.Owner.Delete();
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disconnects the given <see cref="IBodyPart"/> reference, potentially
|
||||
/// dropping other <see cref="IBodyPart">BodyParts</see> if they were hanging
|
||||
/// off of it.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The <see cref="IEntity"/> representing the dropped
|
||||
/// <see cref="IBodyPart"/>, or null if none was dropped.
|
||||
/// </returns>
|
||||
public IEntity? DropPart(IBodyPart part)
|
||||
{
|
||||
DebugTools.AssertNotNull(part);
|
||||
|
||||
if (!_parts.ContainsValue(part))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!RemoveBodyPart(part, out var slotName))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Call disconnect on all limbs that were hanging off this limb.
|
||||
if (TryGetBodyPartConnections(slotName, out List<string> connections))
|
||||
{
|
||||
// This loop is an unoptimized travesty. TODO: optimize to be less shit
|
||||
foreach (var connectionName in connections)
|
||||
{
|
||||
if (TryGetBodyPart(connectionName, out var result) && !ConnectedToCenterPart(result))
|
||||
{
|
||||
DisconnectBodyPart(connectionName, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
part.SpawnDropped(out var dropped);
|
||||
|
||||
OnBodyChanged();
|
||||
return dropped;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disconnects the given <see cref="IBodyPart"/> reference, potentially
|
||||
/// dropping other <see cref="IBodyPart">BodyParts</see> if they were hanging
|
||||
/// off of it.
|
||||
/// </summary>
|
||||
public void DisconnectBodyPart(IBodyPart part, bool dropEntity)
|
||||
{
|
||||
DebugTools.AssertNotNull(part);
|
||||
|
||||
var slotName = _parts.FirstOrDefault(x => x.Value == part).Key;
|
||||
if (string.IsNullOrEmpty(slotName)) return;
|
||||
DisconnectBodyPart(slotName, dropEntity);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disconnects a body part in the given slot if one exists,
|
||||
/// optionally dropping it.
|
||||
/// </summary>
|
||||
/// <param name="slotName">The slot to remove the body part from</param>
|
||||
/// <param name="dropEntity">
|
||||
/// Whether or not to drop the body part as an entity if it exists.
|
||||
/// </param>
|
||||
private void DisconnectBodyPart(string slotName, bool dropEntity)
|
||||
{
|
||||
DebugTools.AssertNotNull(slotName);
|
||||
|
||||
if (!HasPart(slotName))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RemoveBodyPart(slotName, dropEntity);
|
||||
|
||||
if (TryGetBodyPartConnections(slotName, out List<string> connections))
|
||||
{
|
||||
foreach (var connectionName in connections)
|
||||
{
|
||||
if (TryGetBodyPart(connectionName, out var result) && !ConnectedToCenterPart(result))
|
||||
{
|
||||
DisconnectBodyPart(connectionName, dropEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
OnBodyChanged();
|
||||
}
|
||||
|
||||
public bool TryAddPart(string slot, IBodyPart part, bool force = false)
|
||||
{
|
||||
DebugTools.AssertNotNull(part);
|
||||
DebugTools.AssertNotNull(slot);
|
||||
|
||||
// Make sure the given slot exists
|
||||
if (!force)
|
||||
{
|
||||
if (!SlotExists(slot))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// And that nothing is in it
|
||||
if (!_parts.TryAdd(slot, part))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_parts[slot] = part;
|
||||
}
|
||||
|
||||
part.Body = this;
|
||||
|
||||
var argsAdded = new BodyPartAddedEventArgs(part, slot);
|
||||
|
||||
foreach (var component in Owner.GetAllComponents<IBodyPartAdded>().ToArray())
|
||||
{
|
||||
component.BodyPartAdded(argsAdded);
|
||||
}
|
||||
|
||||
// TODO: Sort this duplicate out
|
||||
OnBodyChanged();
|
||||
|
||||
if (!Template.Layers.TryGetValue(slot, out var partMap) ||
|
||||
!_reflectionManager.TryParseEnumReference(partMap, out var partEnum))
|
||||
{
|
||||
Logger.Warning($"Template {Template.Name} has an invalid RSI map key {partMap} for body part {part.Name}.");
|
||||
return false;
|
||||
}
|
||||
|
||||
part.RSIMap = partEnum;
|
||||
|
||||
var partMessage = new BodyPartAddedMessage(part.RSIPath, part.RSIState, partEnum);
|
||||
|
||||
SendNetworkMessage(partMessage);
|
||||
|
||||
foreach (var mechanism in part.Mechanisms)
|
||||
{
|
||||
if (!Template.MechanismLayers.TryGetValue(mechanism.Id, out var mechanismMap))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!_reflectionManager.TryParseEnumReference(mechanismMap, out var mechanismEnum))
|
||||
{
|
||||
Logger.Warning($"Template {Template.Name} has an invalid RSI map key {mechanismMap} for mechanism {mechanism.Id}.");
|
||||
continue;
|
||||
}
|
||||
|
||||
var mechanismMessage = new MechanismSpriteAddedMessage(mechanismEnum);
|
||||
|
||||
SendNetworkMessage(mechanismMessage);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool HasPart(string slot)
|
||||
{
|
||||
return _parts.ContainsKey(slot);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the body part in slot <see cref="slotName"/> from this body,
|
||||
/// if one exists.
|
||||
/// </summary>
|
||||
/// <param name="slotName">The slot to remove it from.</param>
|
||||
/// <param name="drop">
|
||||
/// Whether or not to drop the removed <see cref="IBodyPart"/>.
|
||||
/// </param>
|
||||
/// <returns></returns>
|
||||
private bool RemoveBodyPart(string slotName, bool drop)
|
||||
{
|
||||
DebugTools.AssertNotNull(slotName);
|
||||
|
||||
if (!_parts.Remove(slotName, out var part))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
IEntity? dropped = null;
|
||||
if (drop)
|
||||
{
|
||||
part.SpawnDropped(out dropped);
|
||||
}
|
||||
|
||||
part.Body = null;
|
||||
|
||||
var args = new BodyPartRemovedEventArgs(part, slotName);
|
||||
|
||||
foreach (var component in Owner.GetAllComponents<IBodyPartRemoved>())
|
||||
{
|
||||
component.BodyPartRemoved(args);
|
||||
}
|
||||
|
||||
if (part.RSIMap != null)
|
||||
{
|
||||
var message = new BodyPartRemovedMessage(part.RSIMap, dropped?.Uid);
|
||||
SendNetworkMessage(message);
|
||||
}
|
||||
|
||||
foreach (var mechanism in part.Mechanisms)
|
||||
{
|
||||
if (!Template.MechanismLayers.TryGetValue(mechanism.Id, out var mechanismMap))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!_reflectionManager.TryParseEnumReference(mechanismMap, out var mechanismEnum))
|
||||
{
|
||||
Logger.Warning($"Template {Template.Name} has an invalid RSI map key {mechanismMap} for mechanism {mechanism.Id}.");
|
||||
continue;
|
||||
}
|
||||
|
||||
var mechanismMessage = new MechanismSpriteRemovedMessage(mechanismEnum);
|
||||
|
||||
SendNetworkMessage(mechanismMessage);
|
||||
}
|
||||
|
||||
if (CurrentDamageState == DamageState.Dead) return true;
|
||||
|
||||
// creadth: fall down if no legs
|
||||
if (part.PartType == BodyPartType.Leg && Parts.Count(x => x.Value.PartType == BodyPartType.Leg) == 0)
|
||||
{
|
||||
EntitySystem.Get<StandingStateSystem>().Down(Owner);
|
||||
}
|
||||
|
||||
// creadth: immediately kill entity if last vital part removed
|
||||
if (part.IsVital && Parts.Count(x => x.Value.PartType == part.PartType) == 0)
|
||||
{
|
||||
CurrentDamageState = DamageState.Dead;
|
||||
ForceHealthChangedEvent();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the body part from this body, if one exists.
|
||||
/// </summary>
|
||||
/// <param name="part">The part to remove from this body.</param>
|
||||
/// <param name="slotName">The slot that the part was in, if any.</param>
|
||||
/// <returns>True if <see cref="part"/> was removed, false otherwise.</returns>
|
||||
private bool RemoveBodyPart(IBodyPart part, [NotNullWhen(true)] out string? slotName)
|
||||
{
|
||||
DebugTools.AssertNotNull(part);
|
||||
|
||||
var pair = _parts.FirstOrDefault(kvPair => kvPair.Value == part);
|
||||
|
||||
if (pair.Equals(default))
|
||||
{
|
||||
slotName = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
slotName = pair.Key;
|
||||
|
||||
return RemoveBodyPart(slotName, false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region BodyNetwork Functions
|
||||
|
||||
private bool EnsureNetwork(BodyNetwork network)
|
||||
@@ -854,81 +277,6 @@ namespace Content.Server.GameObjects.Components.Body
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Recursion Functions
|
||||
|
||||
/// <summary>
|
||||
/// Returns the combined length of the distance to the nearest <see cref="BodyPart"/> with a
|
||||
/// <see cref="FootProperty"/>. Returns <see cref="float.MinValue"/>
|
||||
/// if there is no foot found. If you consider a <see cref="BodyManagerComponent"/> a node map, then it will look for
|
||||
/// a foot node from the given node. It can
|
||||
/// only search through BodyParts with <see cref="ExtensionProperty"/>.
|
||||
/// </summary>
|
||||
private static float DistanceToNearestFoot(BodyManagerComponent body, IBodyPart source)
|
||||
{
|
||||
if (source.HasProperty<FootProperty>() && source.TryGetProperty<ExtensionProperty>(out var property))
|
||||
{
|
||||
return property.ReachDistance;
|
||||
}
|
||||
|
||||
return LookForFootRecursion(body, source, new List<BodyPart>());
|
||||
}
|
||||
|
||||
// TODO: Make this not static and not keep me up at night
|
||||
private static float LookForFootRecursion(BodyManagerComponent body, IBodyPart current,
|
||||
ICollection<BodyPart> searchedParts)
|
||||
{
|
||||
if (!current.TryGetProperty<ExtensionProperty>(out var extProperty))
|
||||
{
|
||||
return float.MinValue;
|
||||
}
|
||||
|
||||
// Get all connected parts if the current part has an extension property
|
||||
if (!body.TryGetBodyPartConnections(current, out var connections))
|
||||
{
|
||||
return float.MinValue;
|
||||
}
|
||||
|
||||
// If a connected BodyPart is a foot, return this BodyPart's length.
|
||||
foreach (var connection in connections)
|
||||
{
|
||||
if (!searchedParts.Contains(connection) && connection.HasProperty<FootProperty>())
|
||||
{
|
||||
return extProperty.ReachDistance;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, get the recursion values of all connected BodyParts and
|
||||
// store them in a list.
|
||||
var distances = new List<float>();
|
||||
foreach (var connection in connections)
|
||||
{
|
||||
if (!searchedParts.Contains(connection))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var result = LookForFootRecursion(body, connection, searchedParts);
|
||||
|
||||
if (Math.Abs(result - float.MinValue) > 0.001f)
|
||||
{
|
||||
distances.Add(result);
|
||||
}
|
||||
}
|
||||
|
||||
// If one or more of the searches found a foot, return the smallest one
|
||||
// and add this ones length.
|
||||
if (distances.Count > 0)
|
||||
{
|
||||
return distances.Min<float>() + extProperty.ReachDistance;
|
||||
}
|
||||
|
||||
return float.MinValue;
|
||||
|
||||
// No extension property, no go.
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public interface IBodyManagerHealthChangeParams
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Content.Server.GameObjects.Components.Body.Circulatory
|
||||
/// <summary>
|
||||
/// Internal solution for reagent storage
|
||||
/// </summary>
|
||||
[ViewVariables] private SolutionComponent _internalSolution;
|
||||
[ViewVariables] private SolutionContainerComponent _internalSolution;
|
||||
|
||||
/// <summary>
|
||||
/// Empty volume of internal solution
|
||||
@@ -31,13 +31,13 @@ namespace Content.Server.GameObjects.Components.Body.Circulatory
|
||||
|
||||
[ViewVariables] public GasMixture Air { get; set; }
|
||||
|
||||
[ViewVariables] public SolutionComponent Solution => _internalSolution;
|
||||
[ViewVariables] public SolutionContainerComponent Solution => _internalSolution;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_internalSolution = Owner.EnsureComponent<SolutionComponent>();
|
||||
_internalSolution = Owner.EnsureComponent<SolutionContainerComponent>();
|
||||
_internalSolution.MaxVolume = _initialMaxVolume;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,10 +24,10 @@ namespace Content.Server.GameObjects.Components.Body.Digestive
|
||||
/// </summary>
|
||||
public ReagentUnit MaxVolume
|
||||
{
|
||||
get => Owner.TryGetComponent(out SolutionComponent? solution) ? solution.MaxVolume : ReagentUnit.Zero;
|
||||
get => Owner.TryGetComponent(out SolutionContainerComponent? solution) ? solution.MaxVolume : ReagentUnit.Zero;
|
||||
set
|
||||
{
|
||||
if (Owner.TryGetComponent(out SolutionComponent? solution))
|
||||
if (Owner.TryGetComponent(out SolutionContainerComponent? solution))
|
||||
{
|
||||
solution.MaxVolume = value;
|
||||
}
|
||||
@@ -64,9 +64,9 @@ namespace Content.Server.GameObjects.Components.Body.Digestive
|
||||
{
|
||||
base.Startup();
|
||||
|
||||
if (!Owner.EnsureComponent(out SolutionComponent solution))
|
||||
if (!Owner.EnsureComponent(out SolutionContainerComponent solution))
|
||||
{
|
||||
Logger.Warning($"Entity {Owner} at {Owner.Transform.MapPosition} didn't have a {nameof(SolutionComponent)}");
|
||||
Logger.Warning($"Entity {Owner} at {Owner.Transform.MapPosition} didn't have a {nameof(SolutionContainerComponent)}");
|
||||
}
|
||||
|
||||
solution.MaxVolume = _initialMaxVolume;
|
||||
@@ -74,7 +74,7 @@ namespace Content.Server.GameObjects.Components.Body.Digestive
|
||||
|
||||
public bool TryTransferSolution(Solution solution)
|
||||
{
|
||||
if (!Owner.TryGetComponent(out SolutionComponent? solutionComponent))
|
||||
if (!Owner.TryGetComponent(out SolutionContainerComponent? solutionComponent))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -104,7 +104,7 @@ namespace Content.Server.GameObjects.Components.Body.Digestive
|
||||
/// <param name="frameTime">The time since the last update in seconds.</param>
|
||||
public void Update(float frameTime)
|
||||
{
|
||||
if (!Owner.TryGetComponent(out SolutionComponent? solutionComponent) ||
|
||||
if (!Owner.TryGetComponent(out SolutionContainerComponent? solutionComponent) ||
|
||||
!Owner.TryGetComponent(out BloodstreamComponent? bloodstream))
|
||||
{
|
||||
return;
|
||||
|
||||
@@ -91,7 +91,7 @@ namespace Content.Server.GameObjects.Components.Body
|
||||
{
|
||||
if (!bodyManager.TryGetSlotType(slot, out var typeResult) ||
|
||||
typeResult != ContainedBodyPart?.PartType ||
|
||||
!bodyManager.TryGetBodyPartConnections(slot, out var parts))
|
||||
!bodyManager.TryGetPartConnections(slot, out var parts))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -151,7 +151,7 @@ namespace Content.Server.GameObjects.Components.Body
|
||||
var target = (string) targetObject!;
|
||||
string message;
|
||||
|
||||
if (_bodyManagerComponentCache.InstallDroppedBodyPart(this, target))
|
||||
if (_bodyManagerComponentCache.TryAddPart(target, this))
|
||||
{
|
||||
message = Loc.GetString("You attach {0:theName}.", ContainedBodyPart);
|
||||
}
|
||||
|
||||
@@ -6,20 +6,14 @@ using Content.Shared.GameObjects.Components.Body;
|
||||
namespace Content.Server.GameObjects.Components.Body
|
||||
{
|
||||
// TODO: Merge with ISharedBodyManagerComponent
|
||||
public interface IBodyManagerComponent : ISharedBodyManagerComponent
|
||||
public interface IBodyManagerComponent : ISharedBodyManagerComponent, IBodyPartManager
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="BodyTemplate"/> that this <see cref="BodyManagerComponent"/>
|
||||
/// is adhering to.
|
||||
/// The <see cref="BodyTemplate"/> that this
|
||||
/// <see cref="BodyManagerComponent"/> is adhering to.
|
||||
/// </summary>
|
||||
public BodyTemplate Template { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="BodyPreset"/> that this <see cref="BodyManagerComponent"/>
|
||||
/// is adhering to.
|
||||
/// </summary>
|
||||
public BodyPreset Preset { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Installs the given <see cref="IBodyPart"/> into the given slot.
|
||||
/// </summary>
|
||||
|
||||
154
Content.Server/GameObjects/Components/Body/IBodyPartManager.cs
Normal file
154
Content.Server/GameObjects/Components/Body/IBodyPartManager.cs
Normal file
@@ -0,0 +1,154 @@
|
||||
#nullable enable
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Server.Body;
|
||||
using Content.Shared.GameObjects.Components.Body;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Body
|
||||
{
|
||||
public interface IBodyPartManager : IComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="BodyPreset"/> that this
|
||||
/// <see cref="BodyManagerComponent"/>
|
||||
/// is adhering to.
|
||||
/// </summary>
|
||||
public BodyPreset Preset { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Installs the given <see cref="DroppedBodyPartComponent"/> into the
|
||||
/// given slot, deleting the <see cref="IEntity"/> afterwards.
|
||||
/// </summary>
|
||||
/// <returns>True if successful, false otherwise.</returns>
|
||||
bool TryAddPart(string slot, DroppedBodyPartComponent part, bool force = false);
|
||||
|
||||
bool TryAddPart(string slot, IBodyPart part, bool force = false);
|
||||
|
||||
bool HasPart(string slot);
|
||||
|
||||
/// <summary>
|
||||
/// Removes the given <see cref="IBodyPart"/> reference, potentially
|
||||
/// dropping other <see cref="IBodyPart">BodyParts</see> if they
|
||||
/// were hanging off of it.
|
||||
/// </summary>
|
||||
void RemovePart(IBodyPart part, bool drop);
|
||||
|
||||
/// <summary>
|
||||
/// Removes the body part in slot <see cref="slot"/> from this body,
|
||||
/// if one exists.
|
||||
/// </summary>
|
||||
/// <param name="slot">The slot to remove it from.</param>
|
||||
/// <param name="drop">
|
||||
/// Whether or not to drop the removed <see cref="IBodyPart"/>.
|
||||
/// </param>
|
||||
/// <returns>True if the part was removed, false otherwise.</returns>
|
||||
bool RemovePart(string slot, bool drop);
|
||||
|
||||
/// <summary>
|
||||
/// Removes the body part from this body, if one exists.
|
||||
/// </summary>
|
||||
/// <param name="part">The part to remove from this body.</param>
|
||||
/// <param name="slotName">The slot that the part was in, if any.</param>
|
||||
/// <returns>True if <see cref="part"/> was removed, false otherwise.</returns>
|
||||
bool RemovePart(IBodyPart part, [NotNullWhen(true)] out string? slotName);
|
||||
|
||||
/// <summary>
|
||||
/// Disconnects the given <see cref="IBodyPart"/> reference, potentially
|
||||
/// dropping other <see cref="IBodyPart">BodyParts</see> if they were hanging
|
||||
/// off of it.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The <see cref="IEntity"/> representing the dropped
|
||||
/// <see cref="IBodyPart"/>, or null if none was dropped.
|
||||
/// </returns>
|
||||
IEntity? DropPart(IBodyPart part);
|
||||
|
||||
/// <summary>
|
||||
/// Recursively searches for if <see cref="part"/> is connected to
|
||||
/// the center.
|
||||
/// </summary>
|
||||
/// <param name="part">The body part to find the center for.</param>
|
||||
/// <returns>True if it is connected to the center, false otherwise.</returns>
|
||||
bool ConnectedToCenter(IBodyPart part);
|
||||
|
||||
/// <summary>
|
||||
/// Finds the central <see cref="IBodyPart"/>, if any, of this body based on
|
||||
/// the <see cref="BodyTemplate"/>. For humans, this is the torso.
|
||||
/// </summary>
|
||||
/// <returns>The <see cref="BodyPart"/> if one exists, null otherwise.</returns>
|
||||
IBodyPart? CenterPart();
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether the given part slot name exists within the current
|
||||
/// <see cref="BodyTemplate"/>.
|
||||
/// </summary>
|
||||
/// <param name="slot">The slot to check for.</param>
|
||||
/// <returns>True if the slot exists in this body, false otherwise.</returns>
|
||||
bool HasSlot(string slot);
|
||||
|
||||
/// <summary>
|
||||
/// Finds the <see cref="IBodyPart"/> in the given <see cref="slot"/> if
|
||||
/// one exists.
|
||||
/// </summary>
|
||||
/// <param name="slot">The part slot to search in.</param>
|
||||
/// <param name="result">The body part in that slot, if any.</param>
|
||||
/// <returns>True if found, false otherwise.</returns>
|
||||
bool TryGetPart(string slot, [NotNullWhen(true)] out IBodyPart? result);
|
||||
|
||||
/// <summary>
|
||||
/// Finds the slotName that the given <see cref="IBodyPart"/> resides in.
|
||||
/// </summary>
|
||||
/// <param name="part">The <see cref="IBodyPart"/> to find the slot for.</param>
|
||||
/// <param name="slot">The slot found, if any.</param>
|
||||
/// <returns>True if a slot was found, false otherwise</returns>
|
||||
bool TryGetSlot(IBodyPart part, [NotNullWhen(true)] out string? slot);
|
||||
|
||||
/// <summary>
|
||||
/// Finds the <see cref="BodyPartType"/> in the given
|
||||
/// <see cref="slot"/> if one exists.
|
||||
/// </summary>
|
||||
/// <param name="slot">The slot to search in.</param>
|
||||
/// <param name="result">
|
||||
/// The <see cref="BodyPartType"/> of that slot, if any.
|
||||
/// </param>
|
||||
/// <returns>True if found, false otherwise.</returns>
|
||||
bool TryGetSlotType(string slot, out BodyPartType result);
|
||||
|
||||
/// <summary>
|
||||
/// Finds the names of all slots connected to the given
|
||||
/// <see cref="slot"/> for the template.
|
||||
/// </summary>
|
||||
/// <param name="slot">The slot to search in.</param>
|
||||
/// <param name="connections">The connections found, if any.</param>
|
||||
/// <returns>True if the connections are found, false otherwise.</returns>
|
||||
bool TryGetSlotConnections(string slot, [NotNullWhen(true)] out List<string>? connections);
|
||||
|
||||
/// <summary>
|
||||
/// Grabs all occupied slots connected to the given slot,
|
||||
/// regardless of whether the given <see cref="slot"/> is occupied.
|
||||
/// </summary>
|
||||
/// <param name="slot">The slot name to find connections from.</param>
|
||||
/// <param name="connections">The connected body parts, if any.</param>
|
||||
/// <returns>
|
||||
/// True if successful, false if the slot couldn't be found on this body.
|
||||
/// </returns>
|
||||
bool TryGetPartConnections(string slot, [NotNullWhen(true)] out List<IBodyPart>? connections);
|
||||
|
||||
/// <summary>
|
||||
/// Grabs all parts connected to the given <see cref="part"/>, regardless
|
||||
/// of whether the given <see cref="part"/> is occupied.
|
||||
/// </summary>
|
||||
/// <param name="part">The part to find connections from.</param>
|
||||
/// <param name="connections">The connected body parts, if any.</param>
|
||||
/// <returns>
|
||||
/// True if successful, false if the part couldn't be found on this body.
|
||||
/// </returns>
|
||||
bool TryGetPartConnections(IBodyPart part, [NotNullWhen(true)] out List<IBodyPart>? connections);
|
||||
|
||||
/// <summary>
|
||||
/// Grabs all <see cref="IBodyPart"/> of the given type in this body.
|
||||
/// </summary>
|
||||
List<IBodyPart> GetPartsOfType(BodyPartType type);
|
||||
}
|
||||
}
|
||||
@@ -42,14 +42,12 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
{
|
||||
[ViewVariables] private ContainerSlot _beakerContainer = default!;
|
||||
[ViewVariables] private string _packPrototypeId = "";
|
||||
|
||||
[ViewVariables] private bool HasBeaker => _beakerContainer.ContainedEntity != null;
|
||||
|
||||
[ViewVariables] private bool _bufferModeTransfer = true;
|
||||
|
||||
private bool Powered => !Owner.TryGetComponent(out PowerReceiverComponent? receiver) || receiver.Powered;
|
||||
|
||||
[ViewVariables] private readonly SolutionComponent BufferSolution = new SolutionComponent();
|
||||
[ViewVariables] private readonly SolutionContainerComponent BufferSolution = new SolutionContainerComponent();
|
||||
|
||||
[ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(ChemMasterUiKey.Key);
|
||||
|
||||
@@ -179,7 +177,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
"", Owner.Name, new List<Solution.ReagentQuantity>(), BufferSolution.ReagentList.ToList(), _bufferModeTransfer, BufferSolution.CurrentVolume, BufferSolution.MaxVolume);
|
||||
}
|
||||
|
||||
var solution = beaker.GetComponent<SolutionComponent>();
|
||||
var solution = beaker.GetComponent<SolutionContainerComponent>();
|
||||
return new ChemMasterBoundUserInterfaceState(Powered, true, solution.CurrentVolume, solution.MaxVolume,
|
||||
beaker.Name, Owner.Name, solution.ReagentList.ToList(), BufferSolution.ReagentList.ToList(), _bufferModeTransfer, BufferSolution.CurrentVolume, BufferSolution.MaxVolume);
|
||||
}
|
||||
@@ -191,7 +189,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If this component contains an entity with a <see cref="SolutionComponent"/>, eject it.
|
||||
/// If this component contains an entity with a <see cref="SolutionContainerComponent"/>, eject it.
|
||||
/// Tries to eject into user's hands first, then ejects onto chem master if both hands are full.
|
||||
/// </summary>
|
||||
private void TryEject(IEntity user)
|
||||
@@ -213,7 +211,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
{
|
||||
if (!HasBeaker && _bufferModeTransfer) return;
|
||||
var beaker = _beakerContainer.ContainedEntity;
|
||||
var beakerSolution = beaker.GetComponent<SolutionComponent>();
|
||||
var beakerSolution = beaker.GetComponent<SolutionContainerComponent>();
|
||||
if (isBuffer)
|
||||
{
|
||||
foreach (var reagent in BufferSolution.Solution.Contents)
|
||||
@@ -283,7 +281,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
|
||||
var bufferSolution = BufferSolution.Solution.SplitSolution(actualVolume);
|
||||
|
||||
bottle.TryGetComponent<SolutionComponent>(out var bottleSolution);
|
||||
bottle.TryGetComponent<SolutionContainerComponent>(out var bottleSolution);
|
||||
bottleSolution?.Solution.AddSolution(bufferSolution);
|
||||
|
||||
//Try to give them the bottle
|
||||
@@ -317,7 +315,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
|
||||
var bufferSolution = BufferSolution.Solution.SplitSolution(actualVolume);
|
||||
|
||||
pill.TryGetComponent<SolutionComponent>(out var pillSolution);
|
||||
pill.TryGetComponent<SolutionContainerComponent>(out var pillSolution);
|
||||
pillSolution?.Solution.AddSolution(bufferSolution);
|
||||
|
||||
//Try to give them the bottle
|
||||
@@ -368,7 +366,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
|
||||
/// <summary>
|
||||
/// Called when you click the owner entity with something in your active hand. If the entity in your hand
|
||||
/// contains a <see cref="SolutionComponent"/>, if you have hands, and if the chem master doesn't already
|
||||
/// contains a <see cref="SolutionContainerComponent"/>, if you have hands, and if the chem master doesn't already
|
||||
/// hold a container, it will be added to the chem master.
|
||||
/// </summary>
|
||||
/// <param name="args">Data relevant to the event such as the actor which triggered it.</param>
|
||||
@@ -377,27 +375,27 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
{
|
||||
if (!args.User.TryGetComponent(out IHandsComponent? hands))
|
||||
{
|
||||
Owner.PopupMessage(args.User, Loc.GetString("You have no hands."));
|
||||
Owner.PopupMessage(args.User, Loc.GetString("You have no hands!"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (hands.GetActiveHand == null)
|
||||
{
|
||||
Owner.PopupMessage(args.User, Loc.GetString("You have nothing on your hand."));
|
||||
Owner.PopupMessage(args.User, Loc.GetString("You have nothing in your hand!"));
|
||||
return false;
|
||||
}
|
||||
|
||||
var activeHandEntity = hands.GetActiveHand.Owner;
|
||||
if (activeHandEntity.TryGetComponent<SolutionComponent>(out var solution))
|
||||
if (activeHandEntity.TryGetComponent<SolutionContainerComponent>(out var solution))
|
||||
{
|
||||
if (HasBeaker)
|
||||
{
|
||||
Owner.PopupMessage(args.User, Loc.GetString("This ChemMaster already has a container in it."));
|
||||
}
|
||||
else if ((solution.Capabilities & SolutionCaps.FitsInDispenser) == 0) //Close enough to a chem master...
|
||||
else if (!solution.CanUseWithChemDispenser)
|
||||
{
|
||||
//If it can't fit in the chem master, don't put it in. For example, buckets and mop buckets can't fit.
|
||||
Owner.PopupMessage(args.User, Loc.GetString("That can't fit in the ChemMaster."));
|
||||
Owner.PopupMessage(args.User, Loc.GetString("The {0:theName} is too large for the ChemMaster!", activeHandEntity));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -407,7 +405,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
}
|
||||
else
|
||||
{
|
||||
Owner.PopupMessage(args.User, Loc.GetString("You can't put this in the ChemMaster."));
|
||||
Owner.PopupMessage(args.User, Loc.GetString("You can't put {0:theName} in the ChemMaster!", activeHandEntity));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -61,12 +61,8 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
{
|
||||
base.Startup();
|
||||
|
||||
Owner.EnsureComponent<SolutionComponent>();
|
||||
|
||||
if (Owner.TryGetComponent(out SolutionComponent? solution))
|
||||
{
|
||||
solution.Capabilities |= SolutionCaps.Injector;
|
||||
}
|
||||
var solution = Owner.EnsureComponent<SolutionContainerComponent>();
|
||||
solution.Capabilities = SolutionContainerCaps.AddTo | SolutionContainerCaps.RemoveFrom;
|
||||
|
||||
// Set _toggleState based on prototype
|
||||
_toggleState = _injectOnly ? InjectorToggleMode.Inject : InjectorToggleMode.Draw;
|
||||
@@ -111,30 +107,51 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true)) return;
|
||||
|
||||
//Make sure we have the attacking entity
|
||||
if (eventArgs.Target == null || !Owner.TryGetComponent(out SolutionComponent? solution) || !solution.Injector)
|
||||
if (eventArgs.Target == null || !Owner.TryGetComponent(out SolutionContainerComponent? solution))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var targetEntity = eventArgs.Target;
|
||||
//Handle injecting/drawing for solutions
|
||||
if (targetEntity.TryGetComponent<SolutionComponent>(out var targetSolution) && targetSolution.Injectable)
|
||||
|
||||
// Handle injecting/drawing for solutions
|
||||
if (targetEntity.TryGetComponent<SolutionContainerComponent>(out var targetSolution))
|
||||
{
|
||||
if (_toggleState == InjectorToggleMode.Inject)
|
||||
{
|
||||
TryInject(targetSolution, eventArgs.User);
|
||||
if (solution.CanRemoveSolutions && targetSolution.CanAddSolutions)
|
||||
{
|
||||
TryInject(targetSolution, eventArgs.User);
|
||||
}
|
||||
else
|
||||
{
|
||||
eventArgs.User.PopupMessage(eventArgs.User, Loc.GetString("You aren't able to transfer to {0:theName}!", targetSolution.Owner));
|
||||
}
|
||||
}
|
||||
else if (_toggleState == InjectorToggleMode.Draw)
|
||||
{
|
||||
TryDraw(targetSolution, eventArgs.User);
|
||||
if (targetSolution.CanRemoveSolutions && solution.CanAddSolutions)
|
||||
{
|
||||
TryDraw(targetSolution, eventArgs.User);
|
||||
}
|
||||
else
|
||||
{
|
||||
eventArgs.User.PopupMessage(eventArgs.User, Loc.GetString("You aren't able to draw from {0:theName}!", targetSolution.Owner));
|
||||
}
|
||||
}
|
||||
}
|
||||
else //Handle injecting into bloodstream
|
||||
else // Handle injecting into bloodstream
|
||||
{
|
||||
if (targetEntity.TryGetComponent(out BloodstreamComponent? bloodstream) &&
|
||||
_toggleState == InjectorToggleMode.Inject)
|
||||
if (targetEntity.TryGetComponent(out BloodstreamComponent? bloodstream) && _toggleState == InjectorToggleMode.Inject)
|
||||
{
|
||||
TryInjectIntoBloodstream(bloodstream, eventArgs.User);
|
||||
if (solution.CanRemoveSolutions)
|
||||
{
|
||||
TryInjectIntoBloodstream(bloodstream, eventArgs.User);
|
||||
}
|
||||
else
|
||||
{
|
||||
eventArgs.User.PopupMessage(eventArgs.User, Loc.GetString("You aren't able to inject {0:theName}!", targetEntity));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -152,88 +169,91 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
|
||||
private void TryInjectIntoBloodstream(BloodstreamComponent targetBloodstream, IEntity user)
|
||||
{
|
||||
if (!Owner.TryGetComponent(out SolutionComponent? solution) ||
|
||||
solution.CurrentVolume == 0)
|
||||
if (!Owner.TryGetComponent(out SolutionContainerComponent? solution) || solution.CurrentVolume == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//Get transfer amount. May be smaller than _transferAmount if not enough room
|
||||
// Get transfer amount. May be smaller than _transferAmount if not enough room
|
||||
var realTransferAmount = ReagentUnit.Min(_transferAmount, targetBloodstream.EmptyVolume);
|
||||
|
||||
if (realTransferAmount <= 0)
|
||||
{
|
||||
Owner.PopupMessage(user, Loc.GetString("Container full."));
|
||||
Owner.PopupMessage(user, Loc.GetString("You aren't able to inject {0:theName}!", targetBloodstream.Owner));
|
||||
return;
|
||||
}
|
||||
|
||||
//Move units from attackSolution to targetSolution
|
||||
// Move units from attackSolution to targetSolution
|
||||
var removedSolution = solution.SplitSolution(realTransferAmount);
|
||||
|
||||
if (!targetBloodstream.TryTransferSolution(removedSolution))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Owner.PopupMessage(user, Loc.GetString("Injected {0}u", removedSolution.TotalVolume));
|
||||
Owner.PopupMessage(user, Loc.GetString("You inject {0}u into {1:theName}!", removedSolution.TotalVolume, targetBloodstream.Owner));
|
||||
Dirty();
|
||||
}
|
||||
|
||||
private void TryInject(SolutionComponent targetSolution, IEntity user)
|
||||
private void TryInject(SolutionContainerComponent targetSolution, IEntity user)
|
||||
{
|
||||
if (!Owner.TryGetComponent(out SolutionComponent? solution) ||
|
||||
solution.CurrentVolume == 0)
|
||||
if (!Owner.TryGetComponent(out SolutionContainerComponent? solution) || solution.CurrentVolume == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//Get transfer amount. May be smaller than _transferAmount if not enough room
|
||||
// Get transfer amount. May be smaller than _transferAmount if not enough room
|
||||
var realTransferAmount = ReagentUnit.Min(_transferAmount, targetSolution.EmptyVolume);
|
||||
|
||||
if (realTransferAmount <= 0)
|
||||
{
|
||||
Owner.PopupMessage(user, Loc.GetString("Container full."));
|
||||
Owner.PopupMessage(user, Loc.GetString("{0:theName} is already full!", targetSolution.Owner));
|
||||
return;
|
||||
}
|
||||
|
||||
//Move units from attackSolution to targetSolution
|
||||
// Move units from attackSolution to targetSolution
|
||||
var removedSolution = solution.SplitSolution(realTransferAmount);
|
||||
|
||||
if (!targetSolution.TryAddSolution(removedSolution))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Owner.PopupMessage(user, Loc.GetString("Injected {0}u", removedSolution.TotalVolume));
|
||||
Owner.PopupMessage(user, Loc.GetString("You transfter {0}u to {1:theName}", removedSolution.TotalVolume, targetSolution.Owner));
|
||||
Dirty();
|
||||
}
|
||||
|
||||
private void TryDraw(SolutionComponent targetSolution, IEntity user)
|
||||
private void TryDraw(SolutionContainerComponent targetSolution, IEntity user)
|
||||
{
|
||||
if (!Owner.TryGetComponent(out SolutionComponent? solution) ||
|
||||
solution.EmptyVolume == 0)
|
||||
if (!Owner.TryGetComponent(out SolutionContainerComponent? solution) || solution.EmptyVolume == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//Get transfer amount. May be smaller than _transferAmount if not enough room
|
||||
// Get transfer amount. May be smaller than _transferAmount if not enough room
|
||||
var realTransferAmount = ReagentUnit.Min(_transferAmount, targetSolution.CurrentVolume);
|
||||
|
||||
if (realTransferAmount <= 0)
|
||||
{
|
||||
Owner.PopupMessage(user, Loc.GetString("Container empty"));
|
||||
Owner.PopupMessage(user, Loc.GetString("{0:theName} is empty!", targetSolution.Owner));
|
||||
return;
|
||||
}
|
||||
|
||||
//Move units from attackSolution to targetSolution
|
||||
// Move units from attackSolution to targetSolution
|
||||
var removedSolution = targetSolution.SplitSolution(realTransferAmount);
|
||||
|
||||
if (!solution.TryAddSolution(removedSolution))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Owner.PopupMessage(user, Loc.GetString("Drew {0}u", removedSolution.TotalVolume));
|
||||
Owner.PopupMessage(user, Loc.GetString("Drew {0}u from {1:theName}", removedSolution.TotalVolume, targetSolution.Owner));
|
||||
Dirty();
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState()
|
||||
{
|
||||
Owner.TryGetComponent(out SolutionComponent? solution);
|
||||
Owner.TryGetComponent(out SolutionContainerComponent? solution);
|
||||
|
||||
var currentVolume = solution?.CurrentVolume ?? ReagentUnit.Zero;
|
||||
var maxVolume = solution?.MaxVolume ?? ReagentUnit.Zero;
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
[ViewVariables]
|
||||
private string _trashPrototype;
|
||||
[ViewVariables]
|
||||
private SolutionComponent _contents;
|
||||
private SolutionContainerComponent _contents;
|
||||
[ViewVariables]
|
||||
private ReagentUnit _transferAmount;
|
||||
|
||||
@@ -45,7 +45,8 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
_contents = Owner.GetComponent<SolutionComponent>();
|
||||
|
||||
_contents = Owner.GetComponent<SolutionContainerComponent>();
|
||||
}
|
||||
|
||||
bool IUse.UseEntity(UseEntityEventArgs eventArgs)
|
||||
|
||||
@@ -48,22 +48,22 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
|
||||
{
|
||||
//Get target solution component
|
||||
if (!Owner.TryGetComponent<SolutionComponent>(out var targetSolution))
|
||||
if (!Owner.TryGetComponent<SolutionContainerComponent>(out var targetSolution))
|
||||
return false;
|
||||
|
||||
//Get attack solution component
|
||||
var attackEntity = eventArgs.Using;
|
||||
if (!attackEntity.TryGetComponent<SolutionComponent>(out var attackSolution))
|
||||
if (!attackEntity.TryGetComponent<SolutionContainerComponent>(out var attackSolution))
|
||||
return false;
|
||||
|
||||
// Calculate possibe solution transfer
|
||||
if (targetSolution.CanPourIn && attackSolution.CanPourOut)
|
||||
if (targetSolution.CanAddSolutions && attackSolution.CanRemoveSolutions)
|
||||
{
|
||||
// default logic (beakers and glasses)
|
||||
// transfer solution from object in hand to attacked
|
||||
return TryTransfer(eventArgs, attackSolution, targetSolution);
|
||||
}
|
||||
else if (targetSolution.CanPourOut && attackSolution.CanPourIn)
|
||||
else if (targetSolution.CanRemoveSolutions && attackSolution.CanAddSolutions)
|
||||
{
|
||||
// storage tanks and sinks logic
|
||||
// drain solution from attacked object to object in hand
|
||||
@@ -74,26 +74,38 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TryTransfer(InteractUsingEventArgs eventArgs, SolutionComponent fromSolution, SolutionComponent toSolution)
|
||||
bool TryTransfer(InteractUsingEventArgs eventArgs, SolutionContainerComponent fromSolution, SolutionContainerComponent toSolution)
|
||||
{
|
||||
var fromEntity = fromSolution.Owner;
|
||||
if (!fromEntity.TryGetComponent<PourableComponent>(out var fromPourable))
|
||||
return false;
|
||||
|
||||
//Get transfer amount. May be smaller than _transferAmount if not enough room
|
||||
var realTransferAmount = ReagentUnit.Min(fromPourable.TransferAmount, toSolution.EmptyVolume);
|
||||
if (realTransferAmount <= 0) //Special message if container is full
|
||||
if (!fromEntity.TryGetComponent<PourableComponent>(out var fromPourable))
|
||||
{
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("Container is full"));
|
||||
return false;
|
||||
}
|
||||
|
||||
//Get transfer amount. May be smaller than _transferAmount if not enough room
|
||||
var realTransferAmount = ReagentUnit.Min(fromPourable.TransferAmount, toSolution.EmptyVolume);
|
||||
|
||||
if (realTransferAmount <= 0) // Special message if container is full
|
||||
{
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("{0:theName} is full!", toSolution.Owner));
|
||||
return false;
|
||||
}
|
||||
|
||||
//Move units from attackSolution to targetSolution
|
||||
var removedSolution = fromSolution.SplitSolution(realTransferAmount);
|
||||
if (!toSolution.TryAddSolution(removedSolution))
|
||||
return false;
|
||||
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("Transferred {0}u", removedSolution.TotalVolume));
|
||||
if (removedSolution.TotalVolume <= ReagentUnit.Zero)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!toSolution.TryAddSolution(removedSolution))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("You transfer {0}u to {1:theName}.", removedSolution.TotalVolume, toSolution.Owner));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -47,9 +47,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
|
||||
[ViewVariables] private bool HasBeaker => _beakerContainer.ContainedEntity != null;
|
||||
[ViewVariables] private ReagentUnit _dispenseAmount = ReagentUnit.New(10);
|
||||
|
||||
[ViewVariables]
|
||||
private SolutionComponent? Solution => _beakerContainer.ContainedEntity?.GetComponent<SolutionComponent>();
|
||||
[ViewVariables] private SolutionContainerComponent? Solution => _beakerContainer.ContainedEntity.GetComponent<SolutionContainerComponent>();
|
||||
|
||||
private bool Powered => !Owner.TryGetComponent(out PowerReceiverComponent? receiver) || receiver.Powered;
|
||||
|
||||
@@ -210,7 +208,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
"", Inventory, Owner.Name, null, _dispenseAmount);
|
||||
}
|
||||
|
||||
var solution = beaker.GetComponent<SolutionComponent>();
|
||||
var solution = beaker.GetComponent<SolutionContainerComponent>();
|
||||
return new ReagentDispenserBoundUserInterfaceState(Powered, true, solution.CurrentVolume, solution.MaxVolume,
|
||||
beaker.Name, Inventory, Owner.Name, solution.ReagentList.ToList(), _dispenseAmount);
|
||||
}
|
||||
@@ -222,7 +220,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If this component contains an entity with a <see cref="SolutionComponent"/>, eject it.
|
||||
/// If this component contains an entity with a <see cref="SolutionContainerComponent"/>, eject it.
|
||||
/// Tries to eject into user's hands first, then ejects onto dispenser if both hands are full.
|
||||
/// </summary>
|
||||
private void TryEject(IEntity user)
|
||||
@@ -241,26 +239,26 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If this component contains an entity with a <see cref="SolutionComponent"/>, remove all of it's reagents / solutions.
|
||||
/// If this component contains an entity with a <see cref="SolutionContainerComponent"/>, remove all of it's reagents / solutions.
|
||||
/// </summary>
|
||||
private void TryClear()
|
||||
{
|
||||
if (!HasBeaker) return;
|
||||
var solution = _beakerContainer.ContainedEntity.GetComponent<SolutionComponent>();
|
||||
var solution = _beakerContainer.ContainedEntity.GetComponent<SolutionContainerComponent>();
|
||||
solution.RemoveAllSolution();
|
||||
|
||||
UpdateUserInterface();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If this component contains an entity with a <see cref="SolutionComponent"/>, attempt to dispense the specified reagent to it.
|
||||
/// If this component contains an entity with a <see cref="SolutionContainerComponent"/>, attempt to dispense the specified reagent to it.
|
||||
/// </summary>
|
||||
/// <param name="dispenseIndex">The index of the reagent in <c>Inventory</c>.</param>
|
||||
private void TryDispense(int dispenseIndex)
|
||||
{
|
||||
if (!HasBeaker) return;
|
||||
|
||||
var solution = _beakerContainer.ContainedEntity.GetComponent<SolutionComponent>();
|
||||
var solution = _beakerContainer.ContainedEntity.GetComponent<SolutionContainerComponent>();
|
||||
solution.TryAddReagent(Inventory[dispenseIndex].ID, _dispenseAmount, out _);
|
||||
|
||||
UpdateUserInterface();
|
||||
@@ -292,7 +290,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
|
||||
/// <summary>
|
||||
/// Called when you click the owner entity with something in your active hand. If the entity in your hand
|
||||
/// contains a <see cref="SolutionComponent"/>, if you have hands, and if the dispenser doesn't already
|
||||
/// contains a <see cref="SolutionContainerComponent"/>, if you have hands, and if the dispenser doesn't already
|
||||
/// hold a container, it will be added to the dispenser.
|
||||
/// </summary>
|
||||
/// <param name="args">Data relevant to the event such as the actor which triggered it.</param>
|
||||
@@ -312,13 +310,13 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
}
|
||||
|
||||
var activeHandEntity = hands.GetActiveHand.Owner;
|
||||
if (activeHandEntity.TryGetComponent<SolutionComponent>(out var solution))
|
||||
if (activeHandEntity.TryGetComponent<SolutionContainerComponent>(out var solution))
|
||||
{
|
||||
if (HasBeaker)
|
||||
{
|
||||
Owner.PopupMessage(args.User, Loc.GetString("This dispenser already has a container in it."));
|
||||
}
|
||||
else if ((solution.Capabilities & SolutionCaps.FitsInDispenser) == 0)
|
||||
else if ((solution.Capabilities & SolutionContainerCaps.FitsInDispenser) == 0)
|
||||
{
|
||||
//If it can't fit in the dispenser, don't put it in. For example, buckets and mop buckets can't fit.
|
||||
Owner.PopupMessage(args.User, Loc.GetString("That can't fit in the dispenser."));
|
||||
|
||||
@@ -20,6 +20,7 @@ using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using System;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Chemistry
|
||||
{
|
||||
@@ -27,41 +28,26 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
/// ECS component that manages a liquid solution of reagents.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public class SolutionComponent : SharedSolutionComponent, IExamine
|
||||
public class SolutionContainerComponent : SharedSolutionContainerComponent, IExamine
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
|
||||
|
||||
private IEnumerable<ReactionPrototype> _reactions;
|
||||
private AudioSystem _audioSystem;
|
||||
private ChemistrySystem _chemistrySystem;
|
||||
|
||||
private SpriteComponent _spriteComponent;
|
||||
|
||||
private Solution _containedSolution = new Solution();
|
||||
private ReagentUnit _maxVolume;
|
||||
private SolutionCaps _capabilities;
|
||||
private string _fillInitState;
|
||||
private int _fillInitSteps;
|
||||
private string _fillPathString = "Objects/Specific/Chemistry/fillings.rsi";
|
||||
private ResourcePath _fillPath;
|
||||
private SpriteSpecifier _fillSprite;
|
||||
|
||||
/// <summary>
|
||||
/// The maximum volume of the container.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public ReagentUnit MaxVolume
|
||||
{
|
||||
get => _maxVolume;
|
||||
set => _maxVolume = value; // Note that the contents won't spill out if the capacity is reduced.
|
||||
}
|
||||
private AudioSystem _audioSystem;
|
||||
private ChemistrySystem _chemistrySystem;
|
||||
private SpriteComponent _spriteComponent;
|
||||
|
||||
/// <summary>
|
||||
/// The total volume of all the of the reagents in the container.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public ReagentUnit CurrentVolume => _containedSolution.TotalVolume;
|
||||
public ReagentUnit CurrentVolume => Solution.TotalVolume;
|
||||
|
||||
/// <summary>
|
||||
/// The volume without reagents remaining in the container.
|
||||
@@ -79,49 +65,35 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
/// The current capabilities of this container (is the top open to pour? can I inject it into another object?).
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public SolutionCaps Capabilities
|
||||
{
|
||||
get => _capabilities;
|
||||
set => _capabilities = value;
|
||||
}
|
||||
public SolutionContainerCaps Capabilities { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The contained solution.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public Solution Solution
|
||||
{
|
||||
get => _containedSolution;
|
||||
set => _containedSolution = value;
|
||||
}
|
||||
|
||||
public IReadOnlyList<Solution.ReagentQuantity> ReagentList => _containedSolution.Contents;
|
||||
public Solution Solution { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Shortcut for Capabilities PourIn flag to avoid binary operators.
|
||||
/// The maximum volume of the container.
|
||||
/// </summary>
|
||||
public bool CanPourIn => (Capabilities & SolutionCaps.PourIn) != 0;
|
||||
/// <summary>
|
||||
/// Shortcut for Capabilities PourOut flag to avoid binary operators.
|
||||
/// </summary>
|
||||
public bool CanPourOut => (Capabilities & SolutionCaps.PourOut) != 0;
|
||||
/// <summary>
|
||||
/// Shortcut for Capabilities Injectable flag
|
||||
/// </summary>
|
||||
public bool Injectable => (Capabilities & SolutionCaps.Injectable) != 0;
|
||||
/// <summary>
|
||||
/// Shortcut for Capabilities Injector flag
|
||||
/// </summary>
|
||||
public bool Injector => (Capabilities & SolutionCaps.Injector) != 0;
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public ReagentUnit MaxVolume { get; set; }
|
||||
|
||||
public bool NoExamine => (Capabilities & SolutionCaps.NoExamine) != 0;
|
||||
public IReadOnlyList<Solution.ReagentQuantity> ReagentList => Solution.Contents;
|
||||
public bool CanExamineContents => (Capabilities & SolutionContainerCaps.NoExamine) == 0;
|
||||
public bool CanUseWithChemDispenser => (Capabilities & SolutionContainerCaps.FitsInDispenser) != 0;
|
||||
public bool CanAddSolutions => (Capabilities & SolutionContainerCaps.AddTo) != 0;
|
||||
public bool CanRemoveSolutions => (Capabilities & SolutionContainerCaps.RemoveFrom) != 0;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(ref _maxVolume, "maxVol", ReagentUnit.New(0));
|
||||
serializer.DataField(ref _containedSolution, "contents", _containedSolution);
|
||||
serializer.DataField(ref _capabilities, "caps", SolutionCaps.None);
|
||||
serializer.DataField(ref _fillInitState, "fillingState", "");
|
||||
serializer.DataField(this, x => MaxVolume, "maxVol", ReagentUnit.New(0));
|
||||
serializer.DataField(this, x => Solution, "contents", new Solution());
|
||||
serializer.DataField(this, x => Capabilities, "caps", SolutionContainerCaps.AddTo | SolutionContainerCaps.RemoveFrom);
|
||||
serializer.DataField(ref _fillInitState, "fillingState", string.Empty);
|
||||
serializer.DataField(ref _fillInitSteps, "fillingSteps", 7);
|
||||
}
|
||||
|
||||
@@ -149,15 +121,18 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
|
||||
public void RemoveAllSolution()
|
||||
{
|
||||
_containedSolution.RemoveAllSolution();
|
||||
Solution.RemoveAllSolution();
|
||||
OnSolutionChanged(false);
|
||||
}
|
||||
|
||||
public bool TryRemoveReagent(string reagentId, ReagentUnit quantity)
|
||||
{
|
||||
if (!ContainsReagent(reagentId, out var currentQuantity)) return false;
|
||||
if (!ContainsReagent(reagentId, out var currentQuantity))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_containedSolution.RemoveReagent(reagentId, quantity);
|
||||
Solution.RemoveReagent(reagentId, quantity);
|
||||
OnSolutionChanged(false);
|
||||
return true;
|
||||
}
|
||||
@@ -170,23 +145,25 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
public bool TryRemoveSolution(ReagentUnit quantity)
|
||||
{
|
||||
if (CurrentVolume == 0)
|
||||
{
|
||||
return false;
|
||||
|
||||
_containedSolution.RemoveSolution(quantity);
|
||||
}
|
||||
|
||||
Solution.RemoveSolution(quantity);
|
||||
OnSolutionChanged(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
public Solution SplitSolution(ReagentUnit quantity)
|
||||
{
|
||||
var solutionSplit = _containedSolution.SplitSolution(quantity);
|
||||
var solutionSplit = Solution.SplitSolution(quantity);
|
||||
OnSolutionChanged(false);
|
||||
return solutionSplit;
|
||||
}
|
||||
|
||||
protected void RecalculateColor()
|
||||
{
|
||||
if (_containedSolution.TotalVolume == 0)
|
||||
if (Solution.TotalVolume == 0)
|
||||
{
|
||||
SubstanceColor = Color.Transparent;
|
||||
return;
|
||||
@@ -195,16 +172,23 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
Color mixColor = default;
|
||||
var runningTotalQuantity = ReagentUnit.New(0);
|
||||
|
||||
foreach (var reagent in _containedSolution)
|
||||
foreach (var reagent in Solution)
|
||||
{
|
||||
runningTotalQuantity += reagent.Quantity;
|
||||
|
||||
if(!_prototypeManager.TryIndex(reagent.ReagentId, out ReagentPrototype proto))
|
||||
if (!_prototypeManager.TryIndex(reagent.ReagentId, out ReagentPrototype proto))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mixColor == default)
|
||||
{
|
||||
mixColor = proto.SubstanceColor;
|
||||
mixColor = Color.InterpolateBetween(mixColor, proto.SubstanceColor,
|
||||
(1 / runningTotalQuantity.Float()) * reagent.Quantity.Float());
|
||||
continue;
|
||||
}
|
||||
|
||||
var interpolateValue = (1 / runningTotalQuantity.Float()) * reagent.Quantity.Float();
|
||||
mixColor = Color.InterpolateBetween(mixColor, proto.SubstanceColor, interpolateValue);
|
||||
}
|
||||
|
||||
SubstanceColor = mixColor;
|
||||
@@ -214,56 +198,53 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
/// Transfers solution from the held container to the target container.
|
||||
/// </summary>
|
||||
[Verb]
|
||||
private sealed class FillTargetVerb : Verb<SolutionComponent>
|
||||
private sealed class FillTargetVerb : Verb<SolutionContainerComponent>
|
||||
{
|
||||
protected override void GetData(IEntity user, SolutionComponent component, VerbData data)
|
||||
protected override void GetData(IEntity user, SolutionContainerComponent component, VerbData data)
|
||||
{
|
||||
if (!ActionBlockerSystem.CanInteract(user) ||
|
||||
!user.TryGetComponent<HandsComponent>(out var hands) ||
|
||||
hands.GetActiveHand == null ||
|
||||
hands.GetActiveHand.Owner == component.Owner ||
|
||||
!hands.GetActiveHand.Owner.TryGetComponent<SolutionComponent>(out var solution))
|
||||
!hands.GetActiveHand.Owner.TryGetComponent<SolutionContainerComponent>(out var solution) ||
|
||||
!solution.CanRemoveSolutions ||
|
||||
!component.CanAddSolutions)
|
||||
{
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
return;
|
||||
}
|
||||
|
||||
if ((solution.Capabilities & SolutionCaps.PourOut) != 0 &&
|
||||
(component.Capabilities & SolutionCaps.PourIn) != 0)
|
||||
{
|
||||
var heldEntityName = hands.GetActiveHand.Owner?.Prototype?.Name ?? "<Item>";
|
||||
var myName = component.Owner.Prototype?.Name ?? "<Item>";
|
||||
var heldEntityName = hands.GetActiveHand.Owner?.Prototype?.Name ?? "<Item>";
|
||||
var myName = component.Owner.Prototype?.Name ?? "<Item>";
|
||||
|
||||
var locHeldEntityName = Loc.GetString(heldEntityName);
|
||||
var locMyName = Loc.GetString(myName);
|
||||
var locHeldEntityName = Loc.GetString(heldEntityName);
|
||||
var locMyName = Loc.GetString(myName);
|
||||
|
||||
data.Text = Loc.GetString("Transfer liquid from [{0}] to [{1}].", locHeldEntityName, locMyName);
|
||||
return;
|
||||
}
|
||||
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
data.Visibility = VerbVisibility.Visible;
|
||||
data.Text = Loc.GetString("Transfer liquid from [{0}] to [{1}].", locHeldEntityName, locMyName);
|
||||
}
|
||||
|
||||
protected override void Activate(IEntity user, SolutionComponent component)
|
||||
protected override void Activate(IEntity user, SolutionContainerComponent component)
|
||||
{
|
||||
if (!user.TryGetComponent<HandsComponent>(out var hands))
|
||||
if (!user.TryGetComponent<HandsComponent>(out var hands) || hands.GetActiveHand == null)
|
||||
{
|
||||
return;
|
||||
|
||||
if (hands.GetActiveHand == null)
|
||||
return;
|
||||
|
||||
if (!hands.GetActiveHand.Owner.TryGetComponent<SolutionComponent>(out var handSolutionComp))
|
||||
return;
|
||||
|
||||
if ((handSolutionComp.Capabilities & SolutionCaps.PourOut) == 0 || (component.Capabilities & SolutionCaps.PourIn) == 0)
|
||||
}
|
||||
|
||||
if (!hands.GetActiveHand.Owner.TryGetComponent<SolutionContainerComponent>(out var handSolutionComp) ||
|
||||
!handSolutionComp.CanRemoveSolutions ||
|
||||
!component.CanAddSolutions)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var transferQuantity = ReagentUnit.Min(component.MaxVolume - component.CurrentVolume, handSolutionComp.CurrentVolume, ReagentUnit.New(10));
|
||||
|
||||
// nothing to transfer
|
||||
if (transferQuantity <= 0)
|
||||
{
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
var transferSolution = handSolutionComp.SplitSolution(transferQuantity);
|
||||
component.TryAddSolution(transferSolution);
|
||||
}
|
||||
@@ -271,44 +252,37 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
|
||||
void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
|
||||
{
|
||||
if (NoExamine)
|
||||
if (!CanExamineContents)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
message.AddText(Loc.GetString("Contains:\n"));
|
||||
if (ReagentList.Count == 0)
|
||||
{
|
||||
message.AddText("Nothing.\n");
|
||||
message.AddText(Loc.GetString("It's empty."));
|
||||
}
|
||||
foreach (var reagent in ReagentList)
|
||||
else if (ReagentList.Count == 1)
|
||||
{
|
||||
var reagent = ReagentList[0];
|
||||
|
||||
if (_prototypeManager.TryIndex(reagent.ReagentId, out ReagentPrototype proto))
|
||||
{
|
||||
if (inDetailsRange)
|
||||
{
|
||||
message.AddText($"{proto.Name}: {reagent.Quantity}u\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
//This is trash but it shows the general idea
|
||||
var color = proto.SubstanceColor;
|
||||
var colorIsh = "Red";
|
||||
if (color.G > color.R)
|
||||
{
|
||||
colorIsh = "Green";
|
||||
}
|
||||
if (color.B > color.G && color.B > color.R)
|
||||
{
|
||||
colorIsh = "Blue";
|
||||
}
|
||||
|
||||
message.AddText(Loc.GetString("A {0} liquid\n", colorIsh));
|
||||
}
|
||||
var colorStr = $" [color={proto.GetSubstanceTextColor().ToHexNoAlpha()}]";
|
||||
message.AddText(Loc.GetString("It contains a"));
|
||||
message.AddMarkup(colorStr + Loc.GetString(proto.PhysicalDescription) + "[/color] ");
|
||||
message.AddText(Loc.GetString("substance."));
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
var reagent = ReagentList.Max();
|
||||
|
||||
if (_prototypeManager.TryIndex(reagent.ReagentId, out ReagentPrototype proto))
|
||||
{
|
||||
message.AddText(Loc.GetString("Unknown reagent: {0}u\n", reagent.Quantity));
|
||||
var colorStr = $" [color={SubstanceColor.ToHexNoAlpha()}]";
|
||||
message.AddText(Loc.GetString("It contains a"));
|
||||
message.AddMarkup(colorStr + Loc.GetString(proto.PhysicalDescription) + "[/color] ");
|
||||
message.AddText(Loc.GetString("mixture of substances."));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -317,55 +291,53 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
/// Transfers solution from a target container to the held container.
|
||||
/// </summary>
|
||||
[Verb]
|
||||
private sealed class EmptyTargetVerb : Verb<SolutionComponent>
|
||||
private sealed class EmptyTargetVerb : Verb<SolutionContainerComponent>
|
||||
{
|
||||
protected override void GetData(IEntity user, SolutionComponent component, VerbData data)
|
||||
protected override void GetData(IEntity user, SolutionContainerComponent component, VerbData data)
|
||||
{
|
||||
if (!ActionBlockerSystem.CanInteract(user) ||
|
||||
!user.TryGetComponent<HandsComponent>(out var hands) ||
|
||||
hands.GetActiveHand == null ||
|
||||
hands.GetActiveHand.Owner == component.Owner ||
|
||||
!hands.GetActiveHand.Owner.TryGetComponent<SolutionComponent>(out var solution))
|
||||
!hands.GetActiveHand.Owner.TryGetComponent<SolutionContainerComponent>(out var solution) ||
|
||||
!solution.CanAddSolutions ||
|
||||
!component.CanRemoveSolutions)
|
||||
{
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
return;
|
||||
}
|
||||
|
||||
if ((solution.Capabilities & SolutionCaps.PourIn) != 0 &&
|
||||
(component.Capabilities & SolutionCaps.PourOut) != 0)
|
||||
var heldEntityName = hands.GetActiveHand.Owner?.Prototype?.Name ?? "<Item>";
|
||||
var myName = component.Owner.Prototype?.Name ?? "<Item>";
|
||||
|
||||
var locHeldEntityName = Loc.GetString(heldEntityName);
|
||||
var locMyName = Loc.GetString(myName);
|
||||
|
||||
data.Visibility = VerbVisibility.Visible;
|
||||
data.Text = Loc.GetString("Transfer liquid from [{0}] to [{1}].", locMyName, locHeldEntityName);
|
||||
return;
|
||||
}
|
||||
|
||||
protected override void Activate(IEntity user, SolutionContainerComponent component)
|
||||
{
|
||||
if (!user.TryGetComponent<HandsComponent>(out var hands) || hands.GetActiveHand == null)
|
||||
{
|
||||
var heldEntityName = hands.GetActiveHand.Owner?.Prototype?.Name ?? "<Item>";
|
||||
var myName = component.Owner.Prototype?.Name ?? "<Item>";
|
||||
|
||||
var locHeldEntityName = Loc.GetString(heldEntityName);
|
||||
var locMyName = Loc.GetString(myName);
|
||||
|
||||
data.Text = Loc.GetString("Transfer liquid from [{0}] to [{1}].", locMyName, locHeldEntityName);
|
||||
return;
|
||||
}
|
||||
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
}
|
||||
|
||||
protected override void Activate(IEntity user, SolutionComponent component)
|
||||
{
|
||||
if (!user.TryGetComponent<HandsComponent>(out var hands))
|
||||
return;
|
||||
|
||||
if (hands.GetActiveHand == null)
|
||||
return;
|
||||
|
||||
if(!hands.GetActiveHand.Owner.TryGetComponent<SolutionComponent>(out var handSolutionComp))
|
||||
return;
|
||||
|
||||
if ((handSolutionComp.Capabilities & SolutionCaps.PourIn) == 0 || (component.Capabilities & SolutionCaps.PourOut) == 0)
|
||||
if(!hands.GetActiveHand.Owner.TryGetComponent<SolutionContainerComponent>(out var handSolutionComp) ||
|
||||
!handSolutionComp.CanAddSolutions ||
|
||||
!component.CanRemoveSolutions)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var transferQuantity = ReagentUnit.Min(handSolutionComp.MaxVolume - handSolutionComp.CurrentVolume, component.CurrentVolume, ReagentUnit.New(10));
|
||||
|
||||
// pulling from an empty container, pointless to continue
|
||||
if (transferQuantity <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var transferSolution = component.SplitSolution(transferQuantity);
|
||||
handSolutionComp.TryAddSolution(transferSolution);
|
||||
@@ -401,7 +373,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
|
||||
public bool TryAddReagent(string reagentId, ReagentUnit quantity, out ReagentUnit acceptedQuantity, bool skipReactionCheck = false, bool skipColor = false)
|
||||
{
|
||||
var toAcceptQuantity = MaxVolume - _containedSolution.TotalVolume;
|
||||
var toAcceptQuantity = MaxVolume - Solution.TotalVolume;
|
||||
if (quantity > toAcceptQuantity)
|
||||
{
|
||||
acceptedQuantity = toAcceptQuantity;
|
||||
@@ -412,7 +384,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
acceptedQuantity = quantity;
|
||||
}
|
||||
|
||||
_containedSolution.AddReagent(reagentId, acceptedQuantity);
|
||||
Solution.AddReagent(reagentId, acceptedQuantity);
|
||||
if (!skipColor) {
|
||||
RecalculateColor();
|
||||
}
|
||||
@@ -424,10 +396,10 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
|
||||
public bool TryAddSolution(Solution solution, bool skipReactionCheck = false, bool skipColor = false)
|
||||
{
|
||||
if (solution.TotalVolume > (MaxVolume - _containedSolution.TotalVolume))
|
||||
if (solution.TotalVolume > (MaxVolume - Solution.TotalVolume))
|
||||
return false;
|
||||
|
||||
_containedSolution.AddSolution(solution);
|
||||
Solution.AddSolution(solution);
|
||||
if (!skipColor) {
|
||||
RecalculateColor();
|
||||
}
|
||||
@@ -487,18 +459,20 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
TryRemoveReagent(reactant.Key, amountToRemove);
|
||||
}
|
||||
}
|
||||
//Add products
|
||||
|
||||
// Add products
|
||||
foreach (var product in reaction.Products)
|
||||
{
|
||||
TryAddReagent(product.Key, product.Value * unitReactions, out var acceptedQuantity, true);
|
||||
}
|
||||
//Trigger reaction effects
|
||||
|
||||
// Trigger reaction effects
|
||||
foreach (var effect in reaction.Effects)
|
||||
{
|
||||
effect.React(Owner, unitReactions.Double());
|
||||
}
|
||||
|
||||
//Play reaction sound client-side
|
||||
// Play reaction sound client-side
|
||||
_audioSystem.PlayAtCoords("/Audio/Effects/Chemistry/bubbles.ogg", Owner.Transform.Coordinates);
|
||||
}
|
||||
|
||||
@@ -510,7 +484,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
/// <returns>Return true if the solution contains the reagent.</returns>
|
||||
public bool ContainsReagent(string reagentId, out ReagentUnit quantity)
|
||||
{
|
||||
foreach (var reagent in _containedSolution.Contents)
|
||||
foreach (var reagent in Solution.Contents)
|
||||
{
|
||||
if (reagent.ReagentId == reagentId)
|
||||
{
|
||||
@@ -518,43 +492,50 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
quantity = ReagentUnit.New(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
public string GetMajorReagentId()
|
||||
{
|
||||
if (_containedSolution.Contents.Count == 0)
|
||||
if (Solution.Contents.Count == 0)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
var majorReagent = _containedSolution.Contents.OrderByDescending(reagent => reagent.Quantity).First();;
|
||||
|
||||
var majorReagent = Solution.Contents.OrderByDescending(reagent => reagent.Quantity).First();;
|
||||
return majorReagent.ReagentId;
|
||||
}
|
||||
|
||||
protected void UpdateFillIcon()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_fillInitState)) return;
|
||||
if (string.IsNullOrEmpty(_fillInitState))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var percentage = (CurrentVolume / MaxVolume).Double();
|
||||
var level = ContentHelpers.RoundToLevels(percentage * 100, 100, _fillInitSteps);
|
||||
|
||||
//Transformed glass uses special fancy sprites so we don't bother
|
||||
if (level == 0 || Owner.TryGetComponent<TransformableContainerComponent>(out var transformableContainerComponent)
|
||||
&& transformableContainerComponent.Transformed)
|
||||
if (level == 0 || (Owner.TryGetComponent<TransformableContainerComponent>(out var transformComp) && transformComp.Transformed))
|
||||
{
|
||||
_spriteComponent.LayerSetColor(1, Color.Transparent);
|
||||
return;
|
||||
}
|
||||
_fillSprite = new SpriteSpecifier.Rsi(_fillPath, _fillInitState+level);
|
||||
|
||||
_fillSprite = new SpriteSpecifier.Rsi(_fillPath, _fillInitState + level);
|
||||
_spriteComponent.LayerSetSprite(1, _fillSprite);
|
||||
_spriteComponent.LayerSetColor(1,SubstanceColor);
|
||||
_spriteComponent.LayerSetColor(1, SubstanceColor);
|
||||
}
|
||||
|
||||
protected virtual void OnSolutionChanged(bool skipColor)
|
||||
{
|
||||
if (!skipColor)
|
||||
{
|
||||
RecalculateColor();
|
||||
}
|
||||
|
||||
UpdateFillIcon();
|
||||
_chemistrySystem.HandleSolutionChange(Owner);
|
||||
@@ -42,13 +42,13 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
{
|
||||
base.Startup();
|
||||
|
||||
if (!Owner.EnsureComponent(out SolutionComponent solution))
|
||||
if (!Owner.EnsureComponent(out SolutionContainerComponent solution))
|
||||
{
|
||||
Logger.Warning(
|
||||
$"Entity {Owner.Name} at {Owner.Transform.MapPosition} didn't have a {nameof(SolutionComponent)}");
|
||||
$"Entity {Owner.Name} at {Owner.Transform.MapPosition} didn't have a {nameof(SolutionContainerComponent)}");
|
||||
}
|
||||
|
||||
solution.Capabilities |= SolutionCaps.FitsInDispenser;
|
||||
solution.Capabilities |= SolutionContainerCaps.FitsInDispenser;
|
||||
}
|
||||
|
||||
public void CancelTransformation()
|
||||
@@ -68,7 +68,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
|
||||
void ISolutionChange.SolutionChanged(SolutionChangeEventArgs eventArgs)
|
||||
{
|
||||
var solution = eventArgs.Owner.GetComponent<SolutionComponent>();
|
||||
var solution = eventArgs.Owner.GetComponent<SolutionContainerComponent>();
|
||||
//Transform container into initial state when emptied
|
||||
if (_currentReagent != null && solution.ReagentList.Count == 0)
|
||||
{
|
||||
|
||||
@@ -31,10 +31,10 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
if (!Owner.EnsureComponent(out SolutionComponent _))
|
||||
if (!Owner.EnsureComponent(out SolutionContainerComponent _))
|
||||
{
|
||||
Logger.Warning(
|
||||
$"Entity {Owner.Name} at {Owner.Transform.MapPosition} didn't have a {nameof(SolutionComponent)}");
|
||||
$"Entity {Owner.Name} at {Owner.Transform.MapPosition} didn't have a {nameof(SolutionContainerComponent)}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (!Owner.TryGetComponent(out SolutionComponent contents))
|
||||
if (!Owner.TryGetComponent(out SolutionContainerComponent contents))
|
||||
return;
|
||||
|
||||
if (!_running)
|
||||
@@ -94,7 +94,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Owner.TryGetComponent(out SolutionComponent contents))
|
||||
if (!Owner.TryGetComponent(out SolutionContainerComponent contents))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -24,17 +24,17 @@ namespace Content.Server.GameObjects.Components.Fluids
|
||||
|
||||
public ReagentUnit MaxVolume
|
||||
{
|
||||
get => Owner.TryGetComponent(out SolutionComponent? solution) ? solution.MaxVolume : ReagentUnit.Zero;
|
||||
get => Owner.TryGetComponent(out SolutionContainerComponent? solution) ? solution.MaxVolume : ReagentUnit.Zero;
|
||||
set
|
||||
{
|
||||
if (Owner.TryGetComponent(out SolutionComponent? solution))
|
||||
if (Owner.TryGetComponent(out SolutionContainerComponent? solution))
|
||||
{
|
||||
solution.MaxVolume = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ReagentUnit CurrentVolume => Owner.TryGetComponent(out SolutionComponent? solution)
|
||||
public ReagentUnit CurrentVolume => Owner.TryGetComponent(out SolutionContainerComponent? solution)
|
||||
? solution.CurrentVolume
|
||||
: ReagentUnit.Zero;
|
||||
|
||||
@@ -50,12 +50,12 @@ namespace Content.Server.GameObjects.Components.Fluids
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
Owner.EnsureComponent<SolutionComponent>();
|
||||
Owner.EnsureComponent<SolutionContainerComponent>();
|
||||
}
|
||||
|
||||
private bool TryGiveToMop(MopComponent mopComponent)
|
||||
{
|
||||
if (!Owner.TryGetComponent(out SolutionComponent? contents))
|
||||
if (!Owner.TryGetComponent(out SolutionContainerComponent? contents))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -88,7 +88,7 @@ namespace Content.Server.GameObjects.Components.Fluids
|
||||
|
||||
public async Task<bool> InteractUsing(InteractUsingEventArgs eventArgs)
|
||||
{
|
||||
if (!Owner.TryGetComponent(out SolutionComponent? contents))
|
||||
if (!Owner.TryGetComponent(out SolutionContainerComponent? contents))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
using Content.Server.GameObjects.Components.Chemistry;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Shared.GameObjects.Verbs;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Fluids
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class CanSpillComponent : Component
|
||||
{
|
||||
public override string Name => "CanSpill";
|
||||
// TODO: If the Owner doesn't have a SolutionComponent straight up just have this remove itself?
|
||||
|
||||
/// <summary>
|
||||
/// Transfers solution from the held container to the target container.
|
||||
/// </summary>
|
||||
[Verb]
|
||||
private sealed class FillTargetVerb : Verb<CanSpillComponent>
|
||||
{
|
||||
protected override void GetData(IEntity user, CanSpillComponent component, VerbData data)
|
||||
{
|
||||
if (!ActionBlockerSystem.CanInteract(user) ||
|
||||
!component.Owner.TryGetComponent(out SolutionComponent solutionComponent))
|
||||
{
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
return;
|
||||
}
|
||||
|
||||
data.Text = Loc.GetString("Spill liquid");
|
||||
data.Visibility = solutionComponent.CurrentVolume > ReagentUnit.Zero
|
||||
? VerbVisibility.Visible
|
||||
: VerbVisibility.Disabled;
|
||||
}
|
||||
|
||||
protected override void Activate(IEntity user, CanSpillComponent component)
|
||||
{
|
||||
var solutionComponent = component.Owner.GetComponent<SolutionComponent>();
|
||||
// Need this as when we split the component's owner may be deleted
|
||||
var entityLocation = component.Owner.Transform.Coordinates;
|
||||
var solution = solutionComponent.SplitSolution(solutionComponent.CurrentVolume);
|
||||
solution.SpillAt(entityLocation, "PuddleSmear");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,14 +22,14 @@ namespace Content.Server.GameObjects.Components.Fluids
|
||||
{
|
||||
public override string Name => "Mop";
|
||||
|
||||
public SolutionComponent? Contents => Owner.GetComponentOrNull<SolutionComponent>();
|
||||
public SolutionContainerComponent? Contents => Owner.GetComponentOrNull<SolutionContainerComponent>();
|
||||
|
||||
public ReagentUnit MaxVolume
|
||||
{
|
||||
get => Owner.GetComponentOrNull<SolutionComponent>()?.MaxVolume ?? ReagentUnit.Zero;
|
||||
get => Owner.GetComponentOrNull<SolutionContainerComponent>()?.MaxVolume ?? ReagentUnit.Zero;
|
||||
set
|
||||
{
|
||||
if (Owner.TryGetComponent(out SolutionComponent? solution))
|
||||
if (Owner.TryGetComponent(out SolutionContainerComponent? solution))
|
||||
{
|
||||
solution.MaxVolume = value;
|
||||
}
|
||||
@@ -37,7 +37,7 @@ namespace Content.Server.GameObjects.Components.Fluids
|
||||
}
|
||||
|
||||
public ReagentUnit CurrentVolume =>
|
||||
Owner.GetComponentOrNull<SolutionComponent>()?.CurrentVolume ?? ReagentUnit.Zero;
|
||||
Owner.GetComponentOrNull<SolutionContainerComponent>()?.CurrentVolume ?? ReagentUnit.Zero;
|
||||
|
||||
// Currently there's a separate amount for pickup and dropoff so
|
||||
// Picking up a puddle requires multiple clicks
|
||||
@@ -60,15 +60,15 @@ namespace Content.Server.GameObjects.Components.Fluids
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
if (!Owner.EnsureComponent(out SolutionComponent _))
|
||||
if (!Owner.EnsureComponent(out SolutionContainerComponent _))
|
||||
{
|
||||
Logger.Warning($"Entity {Owner.Name} at {Owner.Transform.MapPosition} didn't have a {nameof(SolutionComponent)}");
|
||||
Logger.Warning($"Entity {Owner.Name} at {Owner.Transform.MapPosition} didn't have a {nameof(SolutionContainerComponent)}");
|
||||
}
|
||||
}
|
||||
|
||||
void IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
|
||||
{
|
||||
if (!Owner.TryGetComponent(out SolutionComponent? contents)) return;
|
||||
if (!Owner.TryGetComponent(out SolutionContainerComponent? contents)) return;
|
||||
if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true)) return;
|
||||
|
||||
if (CurrentVolume <= 0)
|
||||
@@ -76,7 +76,6 @@ namespace Content.Server.GameObjects.Components.Fluids
|
||||
return;
|
||||
}
|
||||
|
||||
//Solution solution;
|
||||
if (eventArgs.Target == null)
|
||||
{
|
||||
// Drop the liquid on the mop on to the ground
|
||||
@@ -98,7 +97,7 @@ namespace Content.Server.GameObjects.Components.Fluids
|
||||
|
||||
if (transferAmount == 0)
|
||||
{
|
||||
if(puddleComponent.EmptyHolder) //The puddle doesn't actually *have* reagents, for example vomit because there's no "vomit" reagent.
|
||||
if (puddleComponent.EmptyHolder) //The puddle doesn't actually *have* reagents, for example vomit because there's no "vomit" reagent.
|
||||
{
|
||||
puddleComponent.Owner.Delete();
|
||||
transferAmount = ReagentUnit.Min(ReagentUnit.New(5), CurrentVolume);
|
||||
|
||||
@@ -94,7 +94,7 @@ namespace Content.Server.GameObjects.Components.Fluids
|
||||
private ReagentUnit _overflowVolume;
|
||||
private ReagentUnit OverflowLeft => CurrentVolume - OverflowVolume;
|
||||
|
||||
private SolutionComponent _contents;
|
||||
private SolutionContainerComponent _contents;
|
||||
public bool EmptyHolder => _contents.ReagentList.Count == 0;
|
||||
private int _spriteVariants;
|
||||
// Whether the underlying solution color should be used
|
||||
@@ -118,13 +118,13 @@ namespace Content.Server.GameObjects.Components.Fluids
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
if (Owner.TryGetComponent(out SolutionComponent solutionComponent))
|
||||
if (Owner.TryGetComponent(out SolutionContainerComponent solutionComponent))
|
||||
{
|
||||
_contents = solutionComponent;
|
||||
}
|
||||
else
|
||||
{
|
||||
_contents = Owner.AddComponent<SolutionComponent>();
|
||||
_contents = Owner.AddComponent<SolutionContainerComponent>();
|
||||
}
|
||||
|
||||
_snapGrid = Owner.EnsureComponent<SnapGridComponent>();
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
using Content.Server.GameObjects.Components.Chemistry;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Shared.GameObjects.Verbs;
|
||||
using Content.Shared.Interfaces;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Fluids
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class SpillableComponent : Component
|
||||
{
|
||||
public override string Name => "Spillable";
|
||||
|
||||
/// <summary>
|
||||
/// Transfers solution from the held container to the floor.
|
||||
/// </summary>
|
||||
[Verb]
|
||||
private sealed class SpillTargetVerb : Verb<SpillableComponent>
|
||||
{
|
||||
protected override void GetData(IEntity user, SpillableComponent component, VerbData data)
|
||||
{
|
||||
if (!ActionBlockerSystem.CanInteract(user) ||
|
||||
!component.Owner.TryGetComponent(out SolutionContainerComponent solutionComponent) ||
|
||||
!solutionComponent.CanRemoveSolutions)
|
||||
{
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
return;
|
||||
}
|
||||
|
||||
data.Text = Loc.GetString("Spill liquid");
|
||||
data.Visibility = solutionComponent.CurrentVolume > ReagentUnit.Zero ? VerbVisibility.Visible : VerbVisibility.Disabled;
|
||||
}
|
||||
|
||||
protected override void Activate(IEntity user, SpillableComponent component)
|
||||
{
|
||||
if (component.Owner.TryGetComponent<SolutionContainerComponent>(out var solutionComponent))
|
||||
{
|
||||
if (!solutionComponent.CanRemoveSolutions)
|
||||
{
|
||||
user.PopupMessage(user, Loc.GetString("You can't pour anything from {0:theName}!", component.Owner));
|
||||
}
|
||||
|
||||
if (solutionComponent.CurrentVolume.Float() <= 0)
|
||||
{
|
||||
user.PopupMessage(user, Loc.GetString("{0:theName} is empty!", component.Owner));
|
||||
}
|
||||
|
||||
// Need this as when we split the component's owner may be deleted
|
||||
var entityLocation = component.Owner.Transform.Coordinates;
|
||||
var solution = solutionComponent.SplitSolution(solutionComponent.CurrentVolume);
|
||||
solution.SpillAt(entityLocation, "PuddleSmear");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,16 +45,16 @@ namespace Content.Server.GameObjects.Components.Fluids
|
||||
set => _sprayVelocity = value;
|
||||
}
|
||||
|
||||
public ReagentUnit CurrentVolume => Owner.GetComponentOrNull<SolutionComponent>()?.CurrentVolume ?? ReagentUnit.Zero;
|
||||
public ReagentUnit CurrentVolume => Owner.GetComponentOrNull<SolutionContainerComponent>()?.CurrentVolume ?? ReagentUnit.Zero;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
if (!Owner.EnsureComponent(out SolutionComponent _))
|
||||
if (!Owner.EnsureComponent(out SolutionContainerComponent _))
|
||||
{
|
||||
Logger.Warning(
|
||||
$"Entity {Owner.Name} at {Owner.Transform.MapPosition} didn't have a {nameof(SolutionComponent)}");
|
||||
$"Entity {Owner.Name} at {Owner.Transform.MapPosition} didn't have a {nameof(SolutionContainerComponent)}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace Content.Server.GameObjects.Components.Fluids
|
||||
if (eventArgs.ClickLocation.GetGridId(_serverEntityManager) != playerPos.GetGridId(_serverEntityManager))
|
||||
return;
|
||||
|
||||
if (!Owner.TryGetComponent(out SolutionComponent contents))
|
||||
if (!Owner.TryGetComponent(out SolutionContainerComponent contents))
|
||||
return;
|
||||
|
||||
var direction = (eventArgs.ClickLocation.Position - playerPos.Position).Normalized;
|
||||
|
||||
@@ -224,8 +224,10 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
if (!interactionSystem.TryDroppedInteraction(Owner, item.Owner))
|
||||
return false;
|
||||
}
|
||||
|
||||
interactionSystem.DroppedInteraction(Owner, item.Owner);
|
||||
else
|
||||
{
|
||||
interactionSystem.DroppedInteraction(Owner, item.Owner);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -248,7 +250,7 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
public bool Drop(string slot, EntityCoordinates coords, bool doMobChecks = true)
|
||||
{
|
||||
var hand = GetHand(slot);
|
||||
if (!CanDrop(slot) || hand?.Entity == null)
|
||||
if (!CanDrop(slot, doMobChecks) || hand?.Entity == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -260,12 +262,17 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!DroppedInteraction(item, doMobChecks))
|
||||
if (!DroppedInteraction(item, false))
|
||||
return false;
|
||||
|
||||
item.RemovedFromSlot();
|
||||
item.Owner.Transform.Coordinates = coords;
|
||||
|
||||
if (item.Owner.TryGetComponent<SpriteComponent>(out var spriteComponent))
|
||||
{
|
||||
spriteComponent.RenderOrder = item.Owner.EntityManager.CurrentTick.Value;
|
||||
}
|
||||
|
||||
if (ContainerHelpers.TryGetContainer(Owner, out var container))
|
||||
{
|
||||
container.Insert(item.Owner);
|
||||
@@ -294,39 +301,7 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
|
||||
public bool Drop(string slot, bool mobChecks = true)
|
||||
{
|
||||
var hand = GetHand(slot);
|
||||
if (!CanDrop(slot, mobChecks) || hand?.Entity == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var item = hand.Entity.GetComponent<ItemComponent>();
|
||||
|
||||
if (!DroppedInteraction(item, mobChecks))
|
||||
return false;
|
||||
|
||||
if (!hand.Container.Remove(hand.Entity))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
item.RemovedFromSlot();
|
||||
item.Owner.Transform.Coordinates = Owner.Transform.Coordinates;
|
||||
|
||||
if (item.Owner.TryGetComponent<SpriteComponent>(out var spriteComponent))
|
||||
{
|
||||
spriteComponent.RenderOrder = item.Owner.EntityManager.CurrentTick.Value;
|
||||
}
|
||||
|
||||
if (ContainerHelpers.TryGetContainer(Owner, out var container))
|
||||
{
|
||||
container.Insert(item.Owner);
|
||||
}
|
||||
|
||||
OnItemChanged?.Invoke();
|
||||
|
||||
Dirty();
|
||||
return true;
|
||||
return Drop(slot, Owner.Transform.Coordinates, mobChecks);
|
||||
}
|
||||
|
||||
public bool Drop(IEntity entity, bool mobChecks = true)
|
||||
@@ -341,7 +316,7 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
throw new ArgumentException("Entity must be held in one of our hands.", nameof(entity));
|
||||
}
|
||||
|
||||
return Drop(slot, mobChecks);
|
||||
return Drop(slot, Owner.Transform.Coordinates, mobChecks);
|
||||
}
|
||||
|
||||
public bool Drop(string slot, BaseContainer targetContainer, bool doMobChecks = true)
|
||||
@@ -357,16 +332,11 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
}
|
||||
|
||||
var hand = GetHand(slot);
|
||||
if (!CanDrop(slot) || hand?.Entity == null)
|
||||
if (!CanDrop(slot, doMobChecks) || hand?.Entity == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var item = hand.Entity.GetComponent<ItemComponent>();
|
||||
|
||||
if (!DroppedInteraction(item, doMobChecks))
|
||||
return false;
|
||||
|
||||
if (!hand.Container.CanRemove(hand.Entity))
|
||||
{
|
||||
return false;
|
||||
@@ -377,11 +347,16 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
return false;
|
||||
}
|
||||
|
||||
var item = hand.Entity.GetComponent<ItemComponent>();
|
||||
|
||||
if (!hand.Container.Remove(hand.Entity))
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
if (!DroppedInteraction(item, doMobChecks))
|
||||
return false;
|
||||
|
||||
item.RemovedFromSlot();
|
||||
|
||||
if (!targetContainer.Insert(item.Owner))
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace Content.Server.GameObjects.Components.Interactable
|
||||
private bool _welderLit;
|
||||
private WelderSystem _welderSystem = default!;
|
||||
private SpriteComponent? _spriteComponent;
|
||||
private SolutionComponent? _solutionComponent;
|
||||
private SolutionContainerComponent? _solutionComponent;
|
||||
private PointLightComponent? _pointLightComponent;
|
||||
|
||||
public string? WeldSoundCollection { get; set; }
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
private uint _currentCookTimerTime = 1;
|
||||
|
||||
private bool Powered => !Owner.TryGetComponent(out PowerReceiverComponent? receiver) || receiver.Powered;
|
||||
private bool _hasContents => Owner.TryGetComponent(out SolutionComponent? solution) && (solution.ReagentList.Count > 0 || _storage.ContainedEntities.Count > 0);
|
||||
private bool _hasContents => Owner.TryGetComponent(out SolutionContainerComponent? solution) && (solution.ReagentList.Count > 0 || _storage.ContainedEntities.Count > 0);
|
||||
private bool _uiDirty = true;
|
||||
private bool _lostPower = false;
|
||||
private int _currentCookTimeButtonIndex = 0;
|
||||
@@ -88,7 +88,7 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
Owner.EnsureComponent<SolutionComponent>();
|
||||
Owner.EnsureComponent<SolutionContainerComponent>();
|
||||
|
||||
_storage = ContainerManagerComponent.Ensure<Container>("microwave_entity_container", Owner, out var existed);
|
||||
_audioSystem = EntitySystem.Get<AudioSystem>();
|
||||
@@ -165,7 +165,7 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
_uiDirty = true;
|
||||
}
|
||||
|
||||
if (_uiDirty && Owner.TryGetComponent(out SolutionComponent? solution))
|
||||
if (_uiDirty && Owner.TryGetComponent(out SolutionContainerComponent? solution))
|
||||
{
|
||||
UserInterface?.SetState(new MicrowaveUpdateUserInterfaceState
|
||||
(
|
||||
@@ -216,13 +216,13 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
|
||||
if (itemEntity.TryGetComponent<PourableComponent>(out var attackPourable))
|
||||
{
|
||||
if (!itemEntity.TryGetComponent<SolutionComponent>(out var attackSolution)
|
||||
|| !attackSolution.CanPourOut)
|
||||
if (!itemEntity.TryGetComponent<SolutionContainerComponent>(out var attackSolution)
|
||||
|| !attackSolution.CanRemoveSolutions)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Owner.TryGetComponent(out SolutionComponent? solution))
|
||||
if (!Owner.TryGetComponent(out SolutionContainerComponent? solution))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -355,7 +355,7 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
|
||||
private void VaporizeReagents()
|
||||
{
|
||||
if (Owner.TryGetComponent(out SolutionComponent? solution))
|
||||
if (Owner.TryGetComponent(out SolutionContainerComponent? solution))
|
||||
{
|
||||
solution.RemoveAllSolution();
|
||||
}
|
||||
@@ -363,7 +363,7 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
|
||||
private void VaporizeReagentQuantity(Solution.ReagentQuantity reagentQuantity)
|
||||
{
|
||||
if (Owner.TryGetComponent(out SolutionComponent? solution))
|
||||
if (Owner.TryGetComponent(out SolutionContainerComponent? solution))
|
||||
{
|
||||
solution?.TryRemoveReagent(reagentQuantity.ReagentId, reagentQuantity.Quantity);
|
||||
}
|
||||
@@ -399,7 +399,7 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
|
||||
private void SubtractContents(FoodRecipePrototype recipe)
|
||||
{
|
||||
if (!Owner.TryGetComponent(out SolutionComponent? solution))
|
||||
if (!Owner.TryGetComponent(out SolutionContainerComponent? solution))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -434,7 +434,7 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
|
||||
private MicrowaveSuccessState CanSatisfyRecipe(FoodRecipePrototype recipe, Dictionary<string,int> solids)
|
||||
{
|
||||
if (!Owner.TryGetComponent(out SolutionComponent? solution))
|
||||
if (!Owner.TryGetComponent(out SolutionContainerComponent? solution))
|
||||
{
|
||||
return MicrowaveSuccessState.RecipeFail;
|
||||
}
|
||||
@@ -479,7 +479,7 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
var headCount = 0;
|
||||
if (victim.TryGetComponent<BodyManagerComponent>(out var bodyManagerComponent))
|
||||
{
|
||||
var heads = bodyManagerComponent.GetBodyPartsOfType(BodyPartType.Head);
|
||||
var heads = bodyManagerComponent.GetPartsOfType(BodyPartType.Head);
|
||||
foreach (var head in heads)
|
||||
{
|
||||
var droppedHead = bodyManagerComponent.DropPart(head);
|
||||
|
||||
@@ -101,8 +101,8 @@ namespace Content.Server.GameObjects.Components.Movement
|
||||
|
||||
var bodyManager = user.GetComponent<BodyManagerComponent>();
|
||||
|
||||
if (bodyManager.GetBodyPartsOfType(Shared.GameObjects.Components.Body.BodyPartType.Leg).Count == 0 ||
|
||||
bodyManager.GetBodyPartsOfType(Shared.GameObjects.Components.Body.BodyPartType.Foot).Count == 0)
|
||||
if (bodyManager.GetPartsOfType(Shared.GameObjects.Components.Body.BodyPartType.Leg).Count == 0 ||
|
||||
bodyManager.GetPartsOfType(Shared.GameObjects.Components.Body.BodyPartType.Foot).Count == 0)
|
||||
{
|
||||
reason = Loc.GetString("You are unable to climb!");
|
||||
return false;
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
public override string Name => "Drink";
|
||||
|
||||
[ViewVariables]
|
||||
private SolutionComponent _contents;
|
||||
private SolutionContainerComponent _contents;
|
||||
[ViewVariables]
|
||||
private string _useSound;
|
||||
[ViewVariables]
|
||||
@@ -56,9 +56,9 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
serializer.DataField(ref _useSound, "useSound", "/Audio/Items/drink.ogg");
|
||||
serializer.DataField(ref _defaultToOpened, "isOpen", false); //For things like cups of coffee.
|
||||
serializer.DataField(ref _soundCollection, "openSounds","canOpenSounds");
|
||||
serializer.DataField(ref _pressurized, "pressurized",false);
|
||||
serializer.DataField(ref _defaultToOpened, "isOpen", false); // For things like cups of coffee.
|
||||
serializer.DataField(ref _soundCollection, "openSounds", "canOpenSounds");
|
||||
serializer.DataField(ref _pressurized, "pressurized", false);
|
||||
serializer.DataField(ref _burstSound, "burstSound", "/Audio/Effects/flash_bang.ogg");
|
||||
}
|
||||
|
||||
@@ -66,14 +66,13 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
{
|
||||
base.Initialize();
|
||||
Owner.TryGetComponent(out _appearanceComponent);
|
||||
if(!Owner.TryGetComponent(out _contents))
|
||||
|
||||
if (!Owner.TryGetComponent(out _contents))
|
||||
{
|
||||
_contents = Owner.AddComponent<SolutionComponent>();
|
||||
_contents = Owner.AddComponent<SolutionContainerComponent>();
|
||||
}
|
||||
|
||||
_contents.Capabilities = SolutionCaps.PourIn
|
||||
| SolutionCaps.PourOut
|
||||
| SolutionCaps.Injectable;
|
||||
_contents.Capabilities = SolutionContainerCaps.AddTo | SolutionContainerCaps.RemoveFrom;
|
||||
Opened = _defaultToOpened;
|
||||
UpdateAppearance();
|
||||
}
|
||||
@@ -83,11 +82,11 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
UpdateAppearance();
|
||||
}
|
||||
|
||||
|
||||
private void UpdateAppearance()
|
||||
{
|
||||
_appearanceComponent?.SetData(SharedFoodComponent.FoodVisuals.Visual, _contents.CurrentVolume.Float());
|
||||
}
|
||||
|
||||
bool IUse.UseEntity(UseEntityEventArgs args)
|
||||
{
|
||||
if (!Opened)
|
||||
@@ -100,13 +99,20 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
Opened = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_contents.CurrentVolume.Float() <= 0)
|
||||
{
|
||||
args.User.PopupMessage(Loc.GetString("{0:theName} is empty!", Owner));
|
||||
return true;
|
||||
}
|
||||
|
||||
return TryUseDrink(args.User);
|
||||
}
|
||||
|
||||
//Force feeding a drink to someone.
|
||||
void IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
|
||||
{
|
||||
TryUseDrink(eventArgs.Target);
|
||||
TryUseDrink(eventArgs.Target, forced: true);
|
||||
}
|
||||
|
||||
public void Examine(FormattedMessage message, bool inDetailsRange)
|
||||
@@ -118,25 +124,28 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
var color = Empty ? "gray" : "yellow";
|
||||
var openedText = Loc.GetString(Empty ? "Empty" : "Opened");
|
||||
message.AddMarkup(Loc.GetString("[color={0}]{1}[/color]", color, openedText));
|
||||
|
||||
}
|
||||
|
||||
private bool TryUseDrink(IEntity target)
|
||||
private bool TryUseDrink(IEntity target, bool forced = false)
|
||||
{
|
||||
if (target == null)
|
||||
if (target == null || !_contents.CanRemoveSolutions)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Opened)
|
||||
{
|
||||
target.PopupMessage(Loc.GetString("Open it first!"));
|
||||
target.PopupMessage(Loc.GetString("Open {0:theName} first!", Owner));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_contents.CurrentVolume.Float() <= 0)
|
||||
{
|
||||
target.PopupMessage(Loc.GetString("It's empty!"));
|
||||
if (!forced)
|
||||
{
|
||||
target.PopupMessage(Loc.GetString("{0:theName} is empty!", Owner));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -147,18 +156,23 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
|
||||
var transferAmount = ReagentUnit.Min(TransferAmount, _contents.CurrentVolume);
|
||||
var split = _contents.SplitSolution(transferAmount);
|
||||
|
||||
if (stomachComponent.TryTransferSolution(split))
|
||||
{
|
||||
if (_useSound == null) return false;
|
||||
if (_useSound == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
EntitySystem.Get<AudioSystem>().PlayFromEntity(_useSound, target, AudioParams.Default.WithVolume(-2f));
|
||||
target.PopupMessage(Loc.GetString("Slurp"));
|
||||
UpdateAppearance();
|
||||
return true;
|
||||
}
|
||||
|
||||
//Stomach was full or can't handle whatever solution we have.
|
||||
// Stomach was full or can't handle whatever solution we have.
|
||||
_contents.TryAddSolution(split);
|
||||
target.PopupMessage(Loc.GetString("You've had enough {0}!", Owner.Name));
|
||||
target.PopupMessage(Loc.GetString("You've had enough {0:theName}!", Owner));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -167,7 +181,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
if (_pressurized &&
|
||||
!Opened &&
|
||||
_random.Prob(0.25f) &&
|
||||
Owner.TryGetComponent(out SolutionComponent component))
|
||||
Owner.TryGetComponent(out SolutionContainerComponent component))
|
||||
{
|
||||
Opened = true;
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Owner.TryGetComponent(out SolutionComponent? solution))
|
||||
if (!Owner.TryGetComponent(out SolutionContainerComponent? solution))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -83,7 +83,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
Owner.EnsureComponent<SolutionComponent>();
|
||||
Owner.EnsureComponent<SolutionContainerComponent>();
|
||||
}
|
||||
|
||||
bool IUse.UseEntity(UseEntityEventArgs eventArgs)
|
||||
@@ -110,7 +110,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
|
||||
public virtual bool TryUseFood(IEntity? user, IEntity? target, UtensilComponent? utensilUsed = null)
|
||||
{
|
||||
if (!Owner.TryGetComponent(out SolutionComponent? solution))
|
||||
if (!Owner.TryGetComponent(out SolutionContainerComponent? solution))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user