Merge branch 'master-upstream' into expl_int_analyzer

# Conflicts:
#	Content.Server/GameObjects/Components/Body/Part/BodyPartComponent.cs
#	Content.Server/GameObjects/Components/Botany/PlantHolderComponent.cs
#	Content.Server/GameObjects/Components/Chemistry/PillComponent.cs
#	Content.Server/GameObjects/Components/Interactable/TilePryingComponent.cs
#	Content.Server/GameObjects/Components/Items/FloorTileItemComponent.cs
#	Content.Server/GameObjects/Components/Items/RCD/RCDAmmoComponent.cs
#	Content.Server/GameObjects/Components/Items/RCD/RCDComponent.cs
#	Content.Server/GameObjects/Components/Medical/HealingComponent.cs
#	Content.Server/GameObjects/Components/Power/WirePlacerComponent.cs
#	Content.Shared/Chemistry/Solution.cs
This commit is contained in:
Paul
2021-02-04 17:50:28 +01:00
499 changed files with 6357 additions and 8689 deletions

View File

@@ -1,4 +1,5 @@
#nullable enable
using System;
using System.Collections.Generic;
using Content.Server.Interfaces.Chemistry;
using Content.Shared.Interfaces;
@@ -20,7 +21,7 @@ namespace Content.Shared.Chemistry
private string _name = default!;
private Dictionary<string, ReactantPrototype> _reactants = default!;
private Dictionary<string, ReagentUnit> _products = default!;
private List<IReactionEffect> _effects = default!;
private IReactionEffect[] _effects = default!;
public string ID => _id;
public string Name => _name;
@@ -55,11 +56,11 @@ namespace Content.Shared.Chemistry
{
//TODO: Don't have a check for if this is the server
//Some implementations of IReactionEffect can't currently be moved to shared, so this is here to prevent the client from breaking when reading server-only IReactionEffects.
serializer.DataField(ref _effects, "effects", new List<IReactionEffect>());
serializer.DataField(ref _effects, "effects", Array.Empty<IReactionEffect>());
}
else
{
_effects = new(); //To ensure _effects isn't null since it is only serializable on the server right snow
_effects = Array.Empty<IReactionEffect>(); //To ensure _effects isn't null since it is only serializable on the server right snow
}
}
}

View File

@@ -19,7 +19,7 @@ namespace Content.Shared.Chemistry
public static ReagentUnit Epsilon { get; } = new(1);
public static ReagentUnit Zero { get; } = new(0);
private double ShiftDown()
private readonly double ShiftDown()
{
return _value / Math.Pow(10, Shift);
}
@@ -164,17 +164,17 @@ namespace Content.Shared.Chemistry
return a._value > b._value;
}
public float Float()
public readonly float Float()
{
return (float) ShiftDown();
}
public double Double()
public readonly double Double()
{
return ShiftDown();
}
public int Int()
public readonly int Int()
{
return (int) ShiftDown();
}
@@ -204,14 +204,15 @@ namespace Content.Shared.Chemistry
return reagent < min ? min : reagent > max ? max : reagent;
}
public override bool Equals(object obj)
public override readonly bool Equals(object obj)
{
return obj is ReagentUnit unit &&
_value == unit._value;
}
public override int GetHashCode()
public override readonly int GetHashCode()
{
// ReSharper disable once NonReadonlyMemberInGetHashCode
return HashCode.Combine(_value);
}
@@ -220,19 +221,19 @@ namespace Content.Shared.Chemistry
_value = FromFloat(FloatFromString(value));
}
public override string ToString() => $"{ShiftDown().ToString(CultureInfo.InvariantCulture)}";
public override readonly string ToString() => $"{ShiftDown().ToString(CultureInfo.InvariantCulture)}";
public string Serialize()
public readonly string Serialize()
{
return ToString();
}
public bool Equals(ReagentUnit other)
public readonly bool Equals(ReagentUnit other)
{
return _value == other._value;
}
public int CompareTo(ReagentUnit other)
public readonly int CompareTo(ReagentUnit other)
{
if(other._value > _value)
{

View File

@@ -4,6 +4,8 @@ using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Robust.Shared.Analyzers;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Serialization;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
@@ -91,7 +93,7 @@ namespace Content.Shared.Chemistry
return "";
}
var majorReagent = Contents.OrderByDescending(reagent => reagent.Quantity).First(); ;
var majorReagent = Contents.OrderByDescending(reagent => reagent.Quantity).First();
return majorReagent.ReagentId;
}
@@ -316,6 +318,20 @@ namespace Content.Shared.Chemistry
return newSolution;
}
public void DoEntityReaction(IEntity entity, ReactionMethod method)
{
var proto = IoCManager.Resolve<IPrototypeManager>();
foreach (var (reagentId, quantity) in _contents.ToArray())
{
if (!proto.TryIndex(reagentId, out ReagentPrototype reagent))
continue;
var removedAmount = reagent.ReactionEntity(entity, method, quantity);
RemoveReagent(reagentId, removedAmount);
}
}
[Serializable, NetSerializable]
public readonly struct ReagentQuantity: IComparable<ReagentQuantity>
{

View File

@@ -1,46 +0,0 @@
using System;
using Robust.Shared.Serialization;
namespace Content.Shared.Chemistry
{
/// <summary>
/// These are the defined capabilities of a container of a solution.
/// </summary>
[Flags]
[Serializable, NetSerializable]
public enum SolutionContainerCaps
{
None = 0,
/// <summary>
/// Can solutions be added into the container?
/// </summary>
AddTo = 1,
/// <summary>
/// Can solutions be removed from the container?
/// </summary>
RemoveFrom = 2,
/// <summary>
/// Allows the container to be placed in a <c>ReagentDispenserComponent</c>.
/// <para>Otherwise it's considered to be too large or the improper shape to fit.</para>
/// <para>Allows us to have obscenely large containers that are harder to abuse in chem dispensers
/// since they can't be placed directly in them.</para>
/// </summary>
FitsInDispenser = 4,
/// <summary>
/// Can people examine the solution in the container or is it impossible to see?
/// </summary>
CanExamine = 8,
}
public static class SolutionContainerCapsHelpers
{
public static bool HasCap(this SolutionContainerCaps cap, SolutionContainerCaps other)
{
return (cap & other) == other;
}
}
}

View File

@@ -0,0 +1,62 @@
using System;
using Content.Shared.GameObjects.Components.Chemistry;
using Robust.Shared.Serialization;
namespace Content.Shared.Chemistry
{
/// <summary>
/// Define common interaction behaviors for <see cref="SharedSolutionContainerComponent"/>
/// </summary>
/// <seealso cref="ISolutionInteractionsComponent"/>
[Flags]
[Serializable, NetSerializable]
public enum SolutionContainerCaps : ushort
{
None = 0,
/// <summary>
/// Reagents can be added with syringes.
/// </summary>
Injectable = 1 << 0,
/// <summary>
/// Reagents can be removed with syringes.
/// </summary>
Drawable = 1 << 1,
/// <summary>
/// Reagents can be easily added via all reagent containers.
/// Think pouring something into another beaker or into the gas tank of a car.
/// </summary>
Refillable = 1 << 2,
/// <summary>
/// Reagents can be easily removed through any reagent container.
/// Think pouring this or draining from a water tank.
/// </summary>
Drainable = 1 << 3,
/// <summary>
/// The contents of the solution can be examined directly.
/// </summary>
CanExamine = 1 << 4,
/// <summary>
/// Allows the container to be placed in a <c>ReagentDispenserComponent</c>.
/// <para>Otherwise it's considered to be too large or the improper shape to fit.</para>
/// <para>Allows us to have obscenely large containers that are harder to abuse in chem dispensers
/// since they can't be placed directly in them.</para>
/// </summary>
FitsInDispenser = 1 << 5,
OpenContainer = Refillable | Drainable | CanExamine
}
public static class SolutionContainerCapsHelpers
{
public static bool HasCap(this SolutionContainerCaps cap, SolutionContainerCaps other)
{
return (cap & other) == other;
}
}
}