2020-08-13 14:40:27 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using Content.Server.Chemistry;
|
|
|
|
|
|
using Content.Server.GameObjects.Components.GUI;
|
|
|
|
|
|
using Content.Server.GameObjects.EntitySystems;
|
2019-07-31 05:10:06 -07:00
|
|
|
|
using Content.Shared.Chemistry;
|
2020-04-12 14:44:14 +02:00
|
|
|
|
using Content.Shared.GameObjects.Components.Chemistry;
|
2020-08-13 14:40:27 +02:00
|
|
|
|
using Content.Shared.GameObjects.EntitySystems;
|
|
|
|
|
|
using Content.Shared.GameObjects.Verbs;
|
2020-04-09 16:43:56 +05:00
|
|
|
|
using Content.Shared.Utility;
|
|
|
|
|
|
using Robust.Server.GameObjects;
|
2019-10-11 16:57:16 -04:00
|
|
|
|
using Robust.Server.GameObjects.EntitySystems;
|
2019-07-31 15:02:36 +02:00
|
|
|
|
using Robust.Shared.GameObjects;
|
2020-08-13 14:40:27 +02:00
|
|
|
|
using Robust.Shared.GameObjects.Systems;
|
2019-07-31 05:10:06 -07:00
|
|
|
|
using Robust.Shared.Interfaces.GameObjects;
|
Reagent dispensers (#360)
* Expose more private values of Solution and SolutionComponent
Expose SolutionComponent.ContainedSolution and Solution.Contents. Both needed by ReagentDispenserComponent.
* Implement IExamine for SolutionComponent
Allows players to see the contents of a solution by examining the entity which contains it.
* Implement ReagentDispenserComponent
Adds ReagentDispenserComponent. A component which can add or remove reagents from a solution container. It's written in a general way so that it can be used for things such as the Chemical dispensers in chemistry, but also the booze and soda dispensers in the bar.
The chemicals it may dispense are defined in yaml, similar to the way that vending machines define which entities they can dispense, by defining a reagent pack.
* Add chemical dispenser and equipment
Adds the chemical dispenser, beaker, large beaker, dropper, and a few more chemicals.
* Add booze and soda dispensers.
Adds the booze and soda dispensers, and a few chemicals for them to dispense. There's no drink mixing or drunkenness yet.
* Update engine submodule.
* Remove unneeded and commented out code
Had a few WIP notes and debug code bits I forgot to remove beforehand.
* Make SolutionComponent._containedSolution and it's values private again
- Remove `SolutionComponent.ContainedSolution` property, replace with specific access functions to maintain safety.
- Make Solution.Contents return a `ReadOnlyCollection` instead of `_contents` to prevent uncontrolled access to the Solution values.
- Add `SolutionComponent.RemoveAllSolution()`
* Update Content.Shared/Chemistry/Solution.cs
Commits a suggestion from RemieRichards to match the coding style of the rest of the codebase. Using `IReadOnlyList` instead of `IReadOnlyCollection`.
Co-Authored-By: Remie Richards <remierichards@gmail.com>
* Update Content.Shared/GameObjects/Components/Chemistry/SolutionComponent.cs
Commits a suggestion from RemieRichards to match the coding style of the rest of the codebase. Using `IReadOnlyList` instead of `IReadOnlyCollection`.
Co-Authored-By: Remie Richards <remierichards@gmail.com>
* Add import for IReadOnlyList to Shared/SolutionComponent.cs
* Add documentation
* Improve localization
Improve use of ILocalizationManager.
* Resolve ReagentDispenserWindow._localizationManager before using it
Forgot to do this in the last commit, resulting in a crash. Oops.
* Add SolutionCaps.FitsInDispenser. Use in ReagentDispenserComponent.
Used to limit large containers like buckets or mop buckets from being placed in a dispenser. Both have large capacities (500) and weren't designed to hold certain chemicals like a beaker is, so for now they can be blocked from being put in a dispenser by giving them that flag.
* Add colors to new reagents
* Update engine submodule
2019-10-05 09:10:05 -04:00
|
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
|
using Robust.Shared.Localization;
|
2020-04-08 15:53:15 +05:00
|
|
|
|
using Robust.Shared.Maths;
|
Reagent dispensers (#360)
* Expose more private values of Solution and SolutionComponent
Expose SolutionComponent.ContainedSolution and Solution.Contents. Both needed by ReagentDispenserComponent.
* Implement IExamine for SolutionComponent
Allows players to see the contents of a solution by examining the entity which contains it.
* Implement ReagentDispenserComponent
Adds ReagentDispenserComponent. A component which can add or remove reagents from a solution container. It's written in a general way so that it can be used for things such as the Chemical dispensers in chemistry, but also the booze and soda dispensers in the bar.
The chemicals it may dispense are defined in yaml, similar to the way that vending machines define which entities they can dispense, by defining a reagent pack.
* Add chemical dispenser and equipment
Adds the chemical dispenser, beaker, large beaker, dropper, and a few more chemicals.
* Add booze and soda dispensers.
Adds the booze and soda dispensers, and a few chemicals for them to dispense. There's no drink mixing or drunkenness yet.
* Update engine submodule.
* Remove unneeded and commented out code
Had a few WIP notes and debug code bits I forgot to remove beforehand.
* Make SolutionComponent._containedSolution and it's values private again
- Remove `SolutionComponent.ContainedSolution` property, replace with specific access functions to maintain safety.
- Make Solution.Contents return a `ReadOnlyCollection` instead of `_contents` to prevent uncontrolled access to the Solution values.
- Add `SolutionComponent.RemoveAllSolution()`
* Update Content.Shared/Chemistry/Solution.cs
Commits a suggestion from RemieRichards to match the coding style of the rest of the codebase. Using `IReadOnlyList` instead of `IReadOnlyCollection`.
Co-Authored-By: Remie Richards <remierichards@gmail.com>
* Update Content.Shared/GameObjects/Components/Chemistry/SolutionComponent.cs
Commits a suggestion from RemieRichards to match the coding style of the rest of the codebase. Using `IReadOnlyList` instead of `IReadOnlyCollection`.
Co-Authored-By: Remie Richards <remierichards@gmail.com>
* Add import for IReadOnlyList to Shared/SolutionComponent.cs
* Add documentation
* Improve localization
Improve use of ILocalizationManager.
* Resolve ReagentDispenserWindow._localizationManager before using it
Forgot to do this in the last commit, resulting in a crash. Oops.
* Add SolutionCaps.FitsInDispenser. Use in ReagentDispenserComponent.
Used to limit large containers like buckets or mop buckets from being placed in a dispenser. Both have large capacities (500) and weren't designed to hold certain chemicals like a beaker is, so for now they can be blocked from being put in a dispenser by giving them that flag.
* Add colors to new reagents
* Update engine submodule
2019-10-05 09:10:05 -04:00
|
|
|
|
using Robust.Shared.Prototypes;
|
2020-04-08 15:53:15 +05:00
|
|
|
|
using Robust.Shared.Serialization;
|
Reagent dispensers (#360)
* Expose more private values of Solution and SolutionComponent
Expose SolutionComponent.ContainedSolution and Solution.Contents. Both needed by ReagentDispenserComponent.
* Implement IExamine for SolutionComponent
Allows players to see the contents of a solution by examining the entity which contains it.
* Implement ReagentDispenserComponent
Adds ReagentDispenserComponent. A component which can add or remove reagents from a solution container. It's written in a general way so that it can be used for things such as the Chemical dispensers in chemistry, but also the booze and soda dispensers in the bar.
The chemicals it may dispense are defined in yaml, similar to the way that vending machines define which entities they can dispense, by defining a reagent pack.
* Add chemical dispenser and equipment
Adds the chemical dispenser, beaker, large beaker, dropper, and a few more chemicals.
* Add booze and soda dispensers.
Adds the booze and soda dispensers, and a few chemicals for them to dispense. There's no drink mixing or drunkenness yet.
* Update engine submodule.
* Remove unneeded and commented out code
Had a few WIP notes and debug code bits I forgot to remove beforehand.
* Make SolutionComponent._containedSolution and it's values private again
- Remove `SolutionComponent.ContainedSolution` property, replace with specific access functions to maintain safety.
- Make Solution.Contents return a `ReadOnlyCollection` instead of `_contents` to prevent uncontrolled access to the Solution values.
- Add `SolutionComponent.RemoveAllSolution()`
* Update Content.Shared/Chemistry/Solution.cs
Commits a suggestion from RemieRichards to match the coding style of the rest of the codebase. Using `IReadOnlyList` instead of `IReadOnlyCollection`.
Co-Authored-By: Remie Richards <remierichards@gmail.com>
* Update Content.Shared/GameObjects/Components/Chemistry/SolutionComponent.cs
Commits a suggestion from RemieRichards to match the coding style of the rest of the codebase. Using `IReadOnlyList` instead of `IReadOnlyCollection`.
Co-Authored-By: Remie Richards <remierichards@gmail.com>
* Add import for IReadOnlyList to Shared/SolutionComponent.cs
* Add documentation
* Improve localization
Improve use of ILocalizationManager.
* Resolve ReagentDispenserWindow._localizationManager before using it
Forgot to do this in the last commit, resulting in a crash. Oops.
* Add SolutionCaps.FitsInDispenser. Use in ReagentDispenserComponent.
Used to limit large containers like buckets or mop buckets from being placed in a dispenser. Both have large capacities (500) and weren't designed to hold certain chemicals like a beaker is, so for now they can be blocked from being put in a dispenser by giving them that flag.
* Add colors to new reagents
* Update engine submodule
2019-10-05 09:10:05 -04:00
|
|
|
|
using Robust.Shared.Utility;
|
2020-04-08 15:53:15 +05:00
|
|
|
|
using Robust.Shared.ViewVariables;
|
2019-07-31 05:10:06 -07:00
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.GameObjects.Components.Chemistry
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
2020-04-08 15:53:15 +05:00
|
|
|
|
/// ECS component that manages a liquid solution of reagents.
|
2019-07-31 05:10:06 -07:00
|
|
|
|
/// </summary>
|
2019-07-31 15:02:36 +02:00
|
|
|
|
[RegisterComponent]
|
2020-10-10 15:25:13 +02:00
|
|
|
|
[ComponentReference(typeof(SharedSolutionContainerComponent))]
|
2020-09-09 18:32:31 -04:00
|
|
|
|
public class SolutionContainerComponent : SharedSolutionContainerComponent, IExamine
|
2019-07-31 05:10:06 -07:00
|
|
|
|
{
|
2020-08-24 14:10:28 +02:00
|
|
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
|
|
|
|
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
|
Reagent dispensers (#360)
* Expose more private values of Solution and SolutionComponent
Expose SolutionComponent.ContainedSolution and Solution.Contents. Both needed by ReagentDispenserComponent.
* Implement IExamine for SolutionComponent
Allows players to see the contents of a solution by examining the entity which contains it.
* Implement ReagentDispenserComponent
Adds ReagentDispenserComponent. A component which can add or remove reagents from a solution container. It's written in a general way so that it can be used for things such as the Chemical dispensers in chemistry, but also the booze and soda dispensers in the bar.
The chemicals it may dispense are defined in yaml, similar to the way that vending machines define which entities they can dispense, by defining a reagent pack.
* Add chemical dispenser and equipment
Adds the chemical dispenser, beaker, large beaker, dropper, and a few more chemicals.
* Add booze and soda dispensers.
Adds the booze and soda dispensers, and a few chemicals for them to dispense. There's no drink mixing or drunkenness yet.
* Update engine submodule.
* Remove unneeded and commented out code
Had a few WIP notes and debug code bits I forgot to remove beforehand.
* Make SolutionComponent._containedSolution and it's values private again
- Remove `SolutionComponent.ContainedSolution` property, replace with specific access functions to maintain safety.
- Make Solution.Contents return a `ReadOnlyCollection` instead of `_contents` to prevent uncontrolled access to the Solution values.
- Add `SolutionComponent.RemoveAllSolution()`
* Update Content.Shared/Chemistry/Solution.cs
Commits a suggestion from RemieRichards to match the coding style of the rest of the codebase. Using `IReadOnlyList` instead of `IReadOnlyCollection`.
Co-Authored-By: Remie Richards <remierichards@gmail.com>
* Update Content.Shared/GameObjects/Components/Chemistry/SolutionComponent.cs
Commits a suggestion from RemieRichards to match the coding style of the rest of the codebase. Using `IReadOnlyList` instead of `IReadOnlyCollection`.
Co-Authored-By: Remie Richards <remierichards@gmail.com>
* Add import for IReadOnlyList to Shared/SolutionComponent.cs
* Add documentation
* Improve localization
Improve use of ILocalizationManager.
* Resolve ReagentDispenserWindow._localizationManager before using it
Forgot to do this in the last commit, resulting in a crash. Oops.
* Add SolutionCaps.FitsInDispenser. Use in ReagentDispenserComponent.
Used to limit large containers like buckets or mop buckets from being placed in a dispenser. Both have large capacities (500) and weren't designed to hold certain chemicals like a beaker is, so for now they can be blocked from being put in a dispenser by giving them that flag.
* Add colors to new reagents
* Update engine submodule
2019-10-05 09:10:05 -04:00
|
|
|
|
|
2019-10-11 16:57:16 -04:00
|
|
|
|
private IEnumerable<ReactionPrototype> _reactions;
|
2020-06-08 14:14:37 +02:00
|
|
|
|
private string _fillInitState;
|
2020-04-09 16:43:56 +05:00
|
|
|
|
private int _fillInitSteps;
|
2020-07-07 13:19:00 -04:00
|
|
|
|
private string _fillPathString = "Objects/Specific/Chemistry/fillings.rsi";
|
2020-04-09 16:43:56 +05:00
|
|
|
|
private ResourcePath _fillPath;
|
|
|
|
|
|
private SpriteSpecifier _fillSprite;
|
2020-09-09 18:32:31 -04:00
|
|
|
|
private AudioSystem _audioSystem;
|
|
|
|
|
|
private ChemistrySystem _chemistrySystem;
|
|
|
|
|
|
private SpriteComponent _spriteComponent;
|
2020-02-23 19:47:33 -05:00
|
|
|
|
|
2020-04-08 15:53:15 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// The volume without reagents remaining in the container.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[ViewVariables]
|
2020-04-12 14:44:14 +02:00
|
|
|
|
public ReagentUnit EmptyVolume => MaxVolume - CurrentVolume;
|
2020-04-08 15:53:15 +05:00
|
|
|
|
|
2020-09-09 18:32:31 -04:00
|
|
|
|
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;
|
2020-04-18 01:10:26 +02:00
|
|
|
|
|
2020-04-08 15:53:15 +05:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public override void ExposeData(ObjectSerializer serializer)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.ExposeData(serializer);
|
|
|
|
|
|
|
2020-09-09 18:32:31 -04:00
|
|
|
|
serializer.DataField(this, x => MaxVolume, "maxVol", ReagentUnit.New(0));
|
|
|
|
|
|
serializer.DataField(this, x => Solution, "contents", new Solution());
|
2020-09-26 14:48:24 +02:00
|
|
|
|
serializer.DataField(this, x => Capabilities, "caps", SolutionContainerCaps.AddTo | SolutionContainerCaps.RemoveFrom);
|
2020-09-09 18:32:31 -04:00
|
|
|
|
serializer.DataField(ref _fillInitState, "fillingState", string.Empty);
|
2020-04-09 16:43:56 +05:00
|
|
|
|
serializer.DataField(ref _fillInitSteps, "fillingSteps", 7);
|
2020-04-08 15:53:15 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Initialize();
|
2020-05-31 12:40:36 -05:00
|
|
|
|
_audioSystem = EntitySystem.Get<AudioSystem>();
|
2020-04-08 15:53:15 +05:00
|
|
|
|
_chemistrySystem = _entitySystemManager.GetEntitySystem<ChemistrySystem>();
|
|
|
|
|
|
_reactions = _prototypeManager.EnumeratePrototypes<ReactionPrototype>();
|
|
|
|
|
|
}
|
2019-10-11 16:57:16 -04:00
|
|
|
|
|
|
|
|
|
|
protected override void Startup()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Startup();
|
2020-04-08 15:53:15 +05:00
|
|
|
|
RecalculateColor();
|
2020-04-09 16:43:56 +05:00
|
|
|
|
if (!string.IsNullOrEmpty(_fillInitState))
|
|
|
|
|
|
{
|
|
|
|
|
|
_spriteComponent = Owner.GetComponent<SpriteComponent>();
|
|
|
|
|
|
_fillPath = new ResourcePath(_fillPathString);
|
|
|
|
|
|
_fillSprite = new SpriteSpecifier.Rsi(_fillPath, _fillInitState + (_fillInitSteps - 1));
|
|
|
|
|
|
_spriteComponent.AddLayerWithSprite(_fillSprite);
|
|
|
|
|
|
UpdateFillIcon();
|
|
|
|
|
|
}
|
2020-02-23 19:47:33 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-08 15:53:15 +05:00
|
|
|
|
public void RemoveAllSolution()
|
2020-02-23 19:47:33 -05:00
|
|
|
|
{
|
2020-09-09 18:32:31 -04:00
|
|
|
|
Solution.RemoveAllSolution();
|
2020-04-09 16:43:56 +05:00
|
|
|
|
OnSolutionChanged(false);
|
2020-04-08 15:53:15 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-10-10 15:25:13 +02:00
|
|
|
|
public override bool TryRemoveReagent(string reagentId, ReagentUnit quantity)
|
2020-04-08 15:53:15 +05:00
|
|
|
|
{
|
2020-09-09 18:32:31 -04:00
|
|
|
|
if (!ContainsReagent(reagentId, out var currentQuantity))
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2020-04-08 15:53:15 +05:00
|
|
|
|
|
2020-09-09 18:32:31 -04:00
|
|
|
|
Solution.RemoveReagent(reagentId, quantity);
|
2020-04-09 16:43:56 +05:00
|
|
|
|
OnSolutionChanged(false);
|
2020-04-08 15:53:15 +05:00
|
|
|
|
return true;
|
2019-10-11 16:57:16 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-11-12 08:20:03 +11:00
|
|
|
|
/// <summary>
|
2020-04-08 15:53:15 +05:00
|
|
|
|
/// Attempt to remove the specified quantity from this solution
|
2019-11-12 08:20:03 +11:00
|
|
|
|
/// </summary>
|
2020-04-08 15:53:15 +05:00
|
|
|
|
/// <param name="quantity">Quantity of this solution to remove</param>
|
|
|
|
|
|
/// <returns>Whether or not the solution was successfully removed</returns>
|
2020-04-12 14:44:14 +02:00
|
|
|
|
public bool TryRemoveSolution(ReagentUnit quantity)
|
2019-11-12 08:20:03 +11:00
|
|
|
|
{
|
2020-04-08 15:53:15 +05:00
|
|
|
|
if (CurrentVolume == 0)
|
2020-09-09 18:32:31 -04:00
|
|
|
|
{
|
2020-04-08 15:53:15 +05:00
|
|
|
|
return false;
|
2020-09-09 18:32:31 -04:00
|
|
|
|
}
|
2020-09-26 14:48:24 +02:00
|
|
|
|
|
2020-09-09 18:32:31 -04:00
|
|
|
|
Solution.RemoveSolution(quantity);
|
2020-04-09 16:43:56 +05:00
|
|
|
|
OnSolutionChanged(false);
|
2020-04-08 15:53:15 +05:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-12 14:44:14 +02:00
|
|
|
|
public Solution SplitSolution(ReagentUnit quantity)
|
2020-04-08 15:53:15 +05:00
|
|
|
|
{
|
2020-09-09 18:32:31 -04:00
|
|
|
|
var solutionSplit = Solution.SplitSolution(quantity);
|
2020-04-09 16:43:56 +05:00
|
|
|
|
OnSolutionChanged(false);
|
2020-04-08 15:53:15 +05:00
|
|
|
|
return solutionSplit;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected void RecalculateColor()
|
|
|
|
|
|
{
|
2020-09-09 18:32:31 -04:00
|
|
|
|
if (Solution.TotalVolume == 0)
|
2020-04-09 16:43:56 +05:00
|
|
|
|
{
|
|
|
|
|
|
SubstanceColor = Color.Transparent;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2020-04-08 15:53:15 +05:00
|
|
|
|
|
|
|
|
|
|
Color mixColor = default;
|
2020-04-12 14:44:14 +02:00
|
|
|
|
var runningTotalQuantity = ReagentUnit.New(0);
|
2020-04-08 15:53:15 +05:00
|
|
|
|
|
2020-09-09 18:32:31 -04:00
|
|
|
|
foreach (var reagent in Solution)
|
2020-04-08 15:53:15 +05:00
|
|
|
|
{
|
|
|
|
|
|
runningTotalQuantity += reagent.Quantity;
|
|
|
|
|
|
|
2020-09-09 18:32:31 -04:00
|
|
|
|
if (!_prototypeManager.TryIndex(reagent.ReagentId, out ReagentPrototype proto))
|
|
|
|
|
|
{
|
2020-04-08 15:53:15 +05:00
|
|
|
|
continue;
|
2020-09-09 18:32:31 -04:00
|
|
|
|
}
|
2020-09-26 14:48:24 +02:00
|
|
|
|
|
2020-04-08 15:53:15 +05:00
|
|
|
|
if (mixColor == default)
|
2020-09-09 18:32:31 -04:00
|
|
|
|
{
|
2020-04-08 15:53:15 +05:00
|
|
|
|
mixColor = proto.SubstanceColor;
|
2020-09-09 18:32:31 -04:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var interpolateValue = (1 / runningTotalQuantity.Float()) * reagent.Quantity.Float();
|
|
|
|
|
|
mixColor = Color.InterpolateBetween(mixColor, proto.SubstanceColor, interpolateValue);
|
2020-04-08 15:53:15 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-09 16:43:56 +05:00
|
|
|
|
SubstanceColor = mixColor;
|
2019-11-12 08:20:03 +11:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-07-31 05:10:06 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Transfers solution from the held container to the target container.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[Verb]
|
2020-09-09 18:32:31 -04:00
|
|
|
|
private sealed class FillTargetVerb : Verb<SolutionContainerComponent>
|
2019-10-13 22:49:07 +02:00
|
|
|
|
{
|
2020-09-09 18:32:31 -04:00
|
|
|
|
protected override void GetData(IEntity user, SolutionContainerComponent component, VerbData data)
|
2019-07-31 05:10:06 -07:00
|
|
|
|
{
|
2020-06-22 18:54:56 +02:00
|
|
|
|
if (!ActionBlockerSystem.CanInteract(user) ||
|
|
|
|
|
|
!user.TryGetComponent<HandsComponent>(out var hands) ||
|
|
|
|
|
|
hands.GetActiveHand == null ||
|
2020-07-08 02:53:50 +02:00
|
|
|
|
hands.GetActiveHand.Owner == component.Owner ||
|
2020-09-09 18:32:31 -04:00
|
|
|
|
!hands.GetActiveHand.Owner.TryGetComponent<SolutionContainerComponent>(out var solution) ||
|
|
|
|
|
|
!solution.CanRemoveSolutions ||
|
|
|
|
|
|
!component.CanAddSolutions)
|
2019-07-31 05:10:06 -07:00
|
|
|
|
{
|
2020-06-22 18:54:56 +02:00
|
|
|
|
data.Visibility = VerbVisibility.Invisible;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-09 18:32:31 -04:00
|
|
|
|
var heldEntityName = hands.GetActiveHand.Owner?.Prototype?.Name ?? "<Item>";
|
|
|
|
|
|
var myName = component.Owner.Prototype?.Name ?? "<Item>";
|
2020-08-29 13:36:02 +02:00
|
|
|
|
|
2020-09-09 18:32:31 -04:00
|
|
|
|
var locHeldEntityName = Loc.GetString(heldEntityName);
|
|
|
|
|
|
var locMyName = Loc.GetString(myName);
|
2019-07-31 05:10:06 -07:00
|
|
|
|
|
2020-09-09 18:32:31 -04:00
|
|
|
|
data.Visibility = VerbVisibility.Visible;
|
|
|
|
|
|
data.Text = Loc.GetString("Transfer liquid from [{0}] to [{1}].", locHeldEntityName, locMyName);
|
2019-07-31 05:10:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-09 18:32:31 -04:00
|
|
|
|
protected override void Activate(IEntity user, SolutionContainerComponent component)
|
2019-07-31 05:10:06 -07:00
|
|
|
|
{
|
2020-09-09 18:32:31 -04:00
|
|
|
|
if (!user.TryGetComponent<HandsComponent>(out var hands) || hands.GetActiveHand == null)
|
|
|
|
|
|
{
|
2019-07-31 05:10:06 -07:00
|
|
|
|
return;
|
2020-09-09 18:32:31 -04:00
|
|
|
|
}
|
2020-09-26 14:48:24 +02:00
|
|
|
|
|
2020-09-09 18:32:31 -04:00
|
|
|
|
if (!hands.GetActiveHand.Owner.TryGetComponent<SolutionContainerComponent>(out var handSolutionComp) ||
|
|
|
|
|
|
!handSolutionComp.CanRemoveSolutions ||
|
|
|
|
|
|
!component.CanAddSolutions)
|
|
|
|
|
|
{
|
2019-07-31 05:10:06 -07:00
|
|
|
|
return;
|
2020-09-26 14:48:24 +02:00
|
|
|
|
}
|
2019-07-31 05:10:06 -07:00
|
|
|
|
|
2020-04-05 11:36:12 +02:00
|
|
|
|
var transferQuantity = ReagentUnit.Min(component.MaxVolume - component.CurrentVolume, handSolutionComp.CurrentVolume, ReagentUnit.New(10));
|
2019-07-31 05:10:06 -07:00
|
|
|
|
|
|
|
|
|
|
if (transferQuantity <= 0)
|
2020-09-09 18:32:31 -04:00
|
|
|
|
{
|
2019-07-31 05:10:06 -07:00
|
|
|
|
return;
|
2020-09-09 18:32:31 -04:00
|
|
|
|
}
|
2020-09-26 14:48:24 +02:00
|
|
|
|
|
2019-07-31 05:10:06 -07:00
|
|
|
|
var transferSolution = handSolutionComp.SplitSolution(transferQuantity);
|
|
|
|
|
|
component.TryAddSolution(transferSolution);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-05-31 19:29:06 +01:00
|
|
|
|
void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
|
Reagent dispensers (#360)
* Expose more private values of Solution and SolutionComponent
Expose SolutionComponent.ContainedSolution and Solution.Contents. Both needed by ReagentDispenserComponent.
* Implement IExamine for SolutionComponent
Allows players to see the contents of a solution by examining the entity which contains it.
* Implement ReagentDispenserComponent
Adds ReagentDispenserComponent. A component which can add or remove reagents from a solution container. It's written in a general way so that it can be used for things such as the Chemical dispensers in chemistry, but also the booze and soda dispensers in the bar.
The chemicals it may dispense are defined in yaml, similar to the way that vending machines define which entities they can dispense, by defining a reagent pack.
* Add chemical dispenser and equipment
Adds the chemical dispenser, beaker, large beaker, dropper, and a few more chemicals.
* Add booze and soda dispensers.
Adds the booze and soda dispensers, and a few chemicals for them to dispense. There's no drink mixing or drunkenness yet.
* Update engine submodule.
* Remove unneeded and commented out code
Had a few WIP notes and debug code bits I forgot to remove beforehand.
* Make SolutionComponent._containedSolution and it's values private again
- Remove `SolutionComponent.ContainedSolution` property, replace with specific access functions to maintain safety.
- Make Solution.Contents return a `ReadOnlyCollection` instead of `_contents` to prevent uncontrolled access to the Solution values.
- Add `SolutionComponent.RemoveAllSolution()`
* Update Content.Shared/Chemistry/Solution.cs
Commits a suggestion from RemieRichards to match the coding style of the rest of the codebase. Using `IReadOnlyList` instead of `IReadOnlyCollection`.
Co-Authored-By: Remie Richards <remierichards@gmail.com>
* Update Content.Shared/GameObjects/Components/Chemistry/SolutionComponent.cs
Commits a suggestion from RemieRichards to match the coding style of the rest of the codebase. Using `IReadOnlyList` instead of `IReadOnlyCollection`.
Co-Authored-By: Remie Richards <remierichards@gmail.com>
* Add import for IReadOnlyList to Shared/SolutionComponent.cs
* Add documentation
* Improve localization
Improve use of ILocalizationManager.
* Resolve ReagentDispenserWindow._localizationManager before using it
Forgot to do this in the last commit, resulting in a crash. Oops.
* Add SolutionCaps.FitsInDispenser. Use in ReagentDispenserComponent.
Used to limit large containers like buckets or mop buckets from being placed in a dispenser. Both have large capacities (500) and weren't designed to hold certain chemicals like a beaker is, so for now they can be blocked from being put in a dispenser by giving them that flag.
* Add colors to new reagents
* Update engine submodule
2019-10-05 09:10:05 -04:00
|
|
|
|
{
|
2020-09-09 18:32:31 -04:00
|
|
|
|
if (!CanExamineContents)
|
2020-04-18 01:10:26 +02:00
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-08 15:53:15 +05:00
|
|
|
|
if (ReagentList.Count == 0)
|
|
|
|
|
|
{
|
2020-09-09 18:32:31 -04:00
|
|
|
|
message.AddText(Loc.GetString("It's empty."));
|
2020-04-08 15:53:15 +05:00
|
|
|
|
}
|
2020-09-09 18:32:31 -04:00
|
|
|
|
else if (ReagentList.Count == 1)
|
Reagent dispensers (#360)
* Expose more private values of Solution and SolutionComponent
Expose SolutionComponent.ContainedSolution and Solution.Contents. Both needed by ReagentDispenserComponent.
* Implement IExamine for SolutionComponent
Allows players to see the contents of a solution by examining the entity which contains it.
* Implement ReagentDispenserComponent
Adds ReagentDispenserComponent. A component which can add or remove reagents from a solution container. It's written in a general way so that it can be used for things such as the Chemical dispensers in chemistry, but also the booze and soda dispensers in the bar.
The chemicals it may dispense are defined in yaml, similar to the way that vending machines define which entities they can dispense, by defining a reagent pack.
* Add chemical dispenser and equipment
Adds the chemical dispenser, beaker, large beaker, dropper, and a few more chemicals.
* Add booze and soda dispensers.
Adds the booze and soda dispensers, and a few chemicals for them to dispense. There's no drink mixing or drunkenness yet.
* Update engine submodule.
* Remove unneeded and commented out code
Had a few WIP notes and debug code bits I forgot to remove beforehand.
* Make SolutionComponent._containedSolution and it's values private again
- Remove `SolutionComponent.ContainedSolution` property, replace with specific access functions to maintain safety.
- Make Solution.Contents return a `ReadOnlyCollection` instead of `_contents` to prevent uncontrolled access to the Solution values.
- Add `SolutionComponent.RemoveAllSolution()`
* Update Content.Shared/Chemistry/Solution.cs
Commits a suggestion from RemieRichards to match the coding style of the rest of the codebase. Using `IReadOnlyList` instead of `IReadOnlyCollection`.
Co-Authored-By: Remie Richards <remierichards@gmail.com>
* Update Content.Shared/GameObjects/Components/Chemistry/SolutionComponent.cs
Commits a suggestion from RemieRichards to match the coding style of the rest of the codebase. Using `IReadOnlyList` instead of `IReadOnlyCollection`.
Co-Authored-By: Remie Richards <remierichards@gmail.com>
* Add import for IReadOnlyList to Shared/SolutionComponent.cs
* Add documentation
* Improve localization
Improve use of ILocalizationManager.
* Resolve ReagentDispenserWindow._localizationManager before using it
Forgot to do this in the last commit, resulting in a crash. Oops.
* Add SolutionCaps.FitsInDispenser. Use in ReagentDispenserComponent.
Used to limit large containers like buckets or mop buckets from being placed in a dispenser. Both have large capacities (500) and weren't designed to hold certain chemicals like a beaker is, so for now they can be blocked from being put in a dispenser by giving them that flag.
* Add colors to new reagents
* Update engine submodule
2019-10-05 09:10:05 -04:00
|
|
|
|
{
|
2020-09-09 18:32:31 -04:00
|
|
|
|
var reagent = ReagentList[0];
|
|
|
|
|
|
|
Reagent dispensers (#360)
* Expose more private values of Solution and SolutionComponent
Expose SolutionComponent.ContainedSolution and Solution.Contents. Both needed by ReagentDispenserComponent.
* Implement IExamine for SolutionComponent
Allows players to see the contents of a solution by examining the entity which contains it.
* Implement ReagentDispenserComponent
Adds ReagentDispenserComponent. A component which can add or remove reagents from a solution container. It's written in a general way so that it can be used for things such as the Chemical dispensers in chemistry, but also the booze and soda dispensers in the bar.
The chemicals it may dispense are defined in yaml, similar to the way that vending machines define which entities they can dispense, by defining a reagent pack.
* Add chemical dispenser and equipment
Adds the chemical dispenser, beaker, large beaker, dropper, and a few more chemicals.
* Add booze and soda dispensers.
Adds the booze and soda dispensers, and a few chemicals for them to dispense. There's no drink mixing or drunkenness yet.
* Update engine submodule.
* Remove unneeded and commented out code
Had a few WIP notes and debug code bits I forgot to remove beforehand.
* Make SolutionComponent._containedSolution and it's values private again
- Remove `SolutionComponent.ContainedSolution` property, replace with specific access functions to maintain safety.
- Make Solution.Contents return a `ReadOnlyCollection` instead of `_contents` to prevent uncontrolled access to the Solution values.
- Add `SolutionComponent.RemoveAllSolution()`
* Update Content.Shared/Chemistry/Solution.cs
Commits a suggestion from RemieRichards to match the coding style of the rest of the codebase. Using `IReadOnlyList` instead of `IReadOnlyCollection`.
Co-Authored-By: Remie Richards <remierichards@gmail.com>
* Update Content.Shared/GameObjects/Components/Chemistry/SolutionComponent.cs
Commits a suggestion from RemieRichards to match the coding style of the rest of the codebase. Using `IReadOnlyList` instead of `IReadOnlyCollection`.
Co-Authored-By: Remie Richards <remierichards@gmail.com>
* Add import for IReadOnlyList to Shared/SolutionComponent.cs
* Add documentation
* Improve localization
Improve use of ILocalizationManager.
* Resolve ReagentDispenserWindow._localizationManager before using it
Forgot to do this in the last commit, resulting in a crash. Oops.
* Add SolutionCaps.FitsInDispenser. Use in ReagentDispenserComponent.
Used to limit large containers like buckets or mop buckets from being placed in a dispenser. Both have large capacities (500) and weren't designed to hold certain chemicals like a beaker is, so for now they can be blocked from being put in a dispenser by giving them that flag.
* Add colors to new reagents
* Update engine submodule
2019-10-05 09:10:05 -04:00
|
|
|
|
if (_prototypeManager.TryIndex(reagent.ReagentId, out ReagentPrototype proto))
|
|
|
|
|
|
{
|
2020-09-19 23:36:48 +02:00
|
|
|
|
message.AddMarkup(
|
|
|
|
|
|
Loc.GetString("It contains a [color={0}]{1}[/color] substance.",
|
|
|
|
|
|
proto.GetSubstanceTextColor().ToHexNoAlpha(),
|
|
|
|
|
|
Loc.GetString(proto.PhysicalDescription)));
|
Reagent dispensers (#360)
* Expose more private values of Solution and SolutionComponent
Expose SolutionComponent.ContainedSolution and Solution.Contents. Both needed by ReagentDispenserComponent.
* Implement IExamine for SolutionComponent
Allows players to see the contents of a solution by examining the entity which contains it.
* Implement ReagentDispenserComponent
Adds ReagentDispenserComponent. A component which can add or remove reagents from a solution container. It's written in a general way so that it can be used for things such as the Chemical dispensers in chemistry, but also the booze and soda dispensers in the bar.
The chemicals it may dispense are defined in yaml, similar to the way that vending machines define which entities they can dispense, by defining a reagent pack.
* Add chemical dispenser and equipment
Adds the chemical dispenser, beaker, large beaker, dropper, and a few more chemicals.
* Add booze and soda dispensers.
Adds the booze and soda dispensers, and a few chemicals for them to dispense. There's no drink mixing or drunkenness yet.
* Update engine submodule.
* Remove unneeded and commented out code
Had a few WIP notes and debug code bits I forgot to remove beforehand.
* Make SolutionComponent._containedSolution and it's values private again
- Remove `SolutionComponent.ContainedSolution` property, replace with specific access functions to maintain safety.
- Make Solution.Contents return a `ReadOnlyCollection` instead of `_contents` to prevent uncontrolled access to the Solution values.
- Add `SolutionComponent.RemoveAllSolution()`
* Update Content.Shared/Chemistry/Solution.cs
Commits a suggestion from RemieRichards to match the coding style of the rest of the codebase. Using `IReadOnlyList` instead of `IReadOnlyCollection`.
Co-Authored-By: Remie Richards <remierichards@gmail.com>
* Update Content.Shared/GameObjects/Components/Chemistry/SolutionComponent.cs
Commits a suggestion from RemieRichards to match the coding style of the rest of the codebase. Using `IReadOnlyList` instead of `IReadOnlyCollection`.
Co-Authored-By: Remie Richards <remierichards@gmail.com>
* Add import for IReadOnlyList to Shared/SolutionComponent.cs
* Add documentation
* Improve localization
Improve use of ILocalizationManager.
* Resolve ReagentDispenserWindow._localizationManager before using it
Forgot to do this in the last commit, resulting in a crash. Oops.
* Add SolutionCaps.FitsInDispenser. Use in ReagentDispenserComponent.
Used to limit large containers like buckets or mop buckets from being placed in a dispenser. Both have large capacities (500) and weren't designed to hold certain chemicals like a beaker is, so for now they can be blocked from being put in a dispenser by giving them that flag.
* Add colors to new reagents
* Update engine submodule
2019-10-05 09:10:05 -04:00
|
|
|
|
}
|
2020-09-09 18:32:31 -04:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
var reagent = ReagentList.Max();
|
|
|
|
|
|
|
|
|
|
|
|
if (_prototypeManager.TryIndex(reagent.ReagentId, out ReagentPrototype proto))
|
Reagent dispensers (#360)
* Expose more private values of Solution and SolutionComponent
Expose SolutionComponent.ContainedSolution and Solution.Contents. Both needed by ReagentDispenserComponent.
* Implement IExamine for SolutionComponent
Allows players to see the contents of a solution by examining the entity which contains it.
* Implement ReagentDispenserComponent
Adds ReagentDispenserComponent. A component which can add or remove reagents from a solution container. It's written in a general way so that it can be used for things such as the Chemical dispensers in chemistry, but also the booze and soda dispensers in the bar.
The chemicals it may dispense are defined in yaml, similar to the way that vending machines define which entities they can dispense, by defining a reagent pack.
* Add chemical dispenser and equipment
Adds the chemical dispenser, beaker, large beaker, dropper, and a few more chemicals.
* Add booze and soda dispensers.
Adds the booze and soda dispensers, and a few chemicals for them to dispense. There's no drink mixing or drunkenness yet.
* Update engine submodule.
* Remove unneeded and commented out code
Had a few WIP notes and debug code bits I forgot to remove beforehand.
* Make SolutionComponent._containedSolution and it's values private again
- Remove `SolutionComponent.ContainedSolution` property, replace with specific access functions to maintain safety.
- Make Solution.Contents return a `ReadOnlyCollection` instead of `_contents` to prevent uncontrolled access to the Solution values.
- Add `SolutionComponent.RemoveAllSolution()`
* Update Content.Shared/Chemistry/Solution.cs
Commits a suggestion from RemieRichards to match the coding style of the rest of the codebase. Using `IReadOnlyList` instead of `IReadOnlyCollection`.
Co-Authored-By: Remie Richards <remierichards@gmail.com>
* Update Content.Shared/GameObjects/Components/Chemistry/SolutionComponent.cs
Commits a suggestion from RemieRichards to match the coding style of the rest of the codebase. Using `IReadOnlyList` instead of `IReadOnlyCollection`.
Co-Authored-By: Remie Richards <remierichards@gmail.com>
* Add import for IReadOnlyList to Shared/SolutionComponent.cs
* Add documentation
* Improve localization
Improve use of ILocalizationManager.
* Resolve ReagentDispenserWindow._localizationManager before using it
Forgot to do this in the last commit, resulting in a crash. Oops.
* Add SolutionCaps.FitsInDispenser. Use in ReagentDispenserComponent.
Used to limit large containers like buckets or mop buckets from being placed in a dispenser. Both have large capacities (500) and weren't designed to hold certain chemicals like a beaker is, so for now they can be blocked from being put in a dispenser by giving them that flag.
* Add colors to new reagents
* Update engine submodule
2019-10-05 09:10:05 -04:00
|
|
|
|
{
|
2020-09-19 23:36:48 +02:00
|
|
|
|
message.AddMarkup(
|
|
|
|
|
|
Loc.GetString("It contains a [color={0}]{1}[/color] mixture of substances.",
|
|
|
|
|
|
SubstanceColor.ToHexNoAlpha(),
|
|
|
|
|
|
Loc.GetString(proto.PhysicalDescription)));
|
Reagent dispensers (#360)
* Expose more private values of Solution and SolutionComponent
Expose SolutionComponent.ContainedSolution and Solution.Contents. Both needed by ReagentDispenserComponent.
* Implement IExamine for SolutionComponent
Allows players to see the contents of a solution by examining the entity which contains it.
* Implement ReagentDispenserComponent
Adds ReagentDispenserComponent. A component which can add or remove reagents from a solution container. It's written in a general way so that it can be used for things such as the Chemical dispensers in chemistry, but also the booze and soda dispensers in the bar.
The chemicals it may dispense are defined in yaml, similar to the way that vending machines define which entities they can dispense, by defining a reagent pack.
* Add chemical dispenser and equipment
Adds the chemical dispenser, beaker, large beaker, dropper, and a few more chemicals.
* Add booze and soda dispensers.
Adds the booze and soda dispensers, and a few chemicals for them to dispense. There's no drink mixing or drunkenness yet.
* Update engine submodule.
* Remove unneeded and commented out code
Had a few WIP notes and debug code bits I forgot to remove beforehand.
* Make SolutionComponent._containedSolution and it's values private again
- Remove `SolutionComponent.ContainedSolution` property, replace with specific access functions to maintain safety.
- Make Solution.Contents return a `ReadOnlyCollection` instead of `_contents` to prevent uncontrolled access to the Solution values.
- Add `SolutionComponent.RemoveAllSolution()`
* Update Content.Shared/Chemistry/Solution.cs
Commits a suggestion from RemieRichards to match the coding style of the rest of the codebase. Using `IReadOnlyList` instead of `IReadOnlyCollection`.
Co-Authored-By: Remie Richards <remierichards@gmail.com>
* Update Content.Shared/GameObjects/Components/Chemistry/SolutionComponent.cs
Commits a suggestion from RemieRichards to match the coding style of the rest of the codebase. Using `IReadOnlyList` instead of `IReadOnlyCollection`.
Co-Authored-By: Remie Richards <remierichards@gmail.com>
* Add import for IReadOnlyList to Shared/SolutionComponent.cs
* Add documentation
* Improve localization
Improve use of ILocalizationManager.
* Resolve ReagentDispenserWindow._localizationManager before using it
Forgot to do this in the last commit, resulting in a crash. Oops.
* Add SolutionCaps.FitsInDispenser. Use in ReagentDispenserComponent.
Used to limit large containers like buckets or mop buckets from being placed in a dispenser. Both have large capacities (500) and weren't designed to hold certain chemicals like a beaker is, so for now they can be blocked from being put in a dispenser by giving them that flag.
* Add colors to new reagents
* Update engine submodule
2019-10-05 09:10:05 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-07-31 05:10:06 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Transfers solution from a target container to the held container.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[Verb]
|
2020-09-09 18:32:31 -04:00
|
|
|
|
private sealed class EmptyTargetVerb : Verb<SolutionContainerComponent>
|
2019-07-31 05:10:06 -07:00
|
|
|
|
{
|
2020-09-09 18:32:31 -04:00
|
|
|
|
protected override void GetData(IEntity user, SolutionContainerComponent component, VerbData data)
|
2019-07-31 05:10:06 -07:00
|
|
|
|
{
|
2020-06-22 18:54:56 +02:00
|
|
|
|
if (!ActionBlockerSystem.CanInteract(user) ||
|
|
|
|
|
|
!user.TryGetComponent<HandsComponent>(out var hands) ||
|
|
|
|
|
|
hands.GetActiveHand == null ||
|
2020-07-08 02:53:50 +02:00
|
|
|
|
hands.GetActiveHand.Owner == component.Owner ||
|
2020-09-09 18:32:31 -04:00
|
|
|
|
!hands.GetActiveHand.Owner.TryGetComponent<SolutionContainerComponent>(out var solution) ||
|
|
|
|
|
|
!solution.CanAddSolutions ||
|
|
|
|
|
|
!component.CanRemoveSolutions)
|
2019-07-31 05:10:06 -07:00
|
|
|
|
{
|
2020-06-22 18:54:56 +02:00
|
|
|
|
data.Visibility = VerbVisibility.Invisible;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-09 18:32:31 -04:00
|
|
|
|
var heldEntityName = hands.GetActiveHand.Owner?.Prototype?.Name ?? "<Item>";
|
|
|
|
|
|
var myName = component.Owner.Prototype?.Name ?? "<Item>";
|
2020-08-29 13:36:02 +02:00
|
|
|
|
|
2020-09-09 18:32:31 -04:00
|
|
|
|
var locHeldEntityName = Loc.GetString(heldEntityName);
|
|
|
|
|
|
var locMyName = Loc.GetString(myName);
|
2019-07-31 05:10:06 -07:00
|
|
|
|
|
2020-09-09 18:32:31 -04:00
|
|
|
|
data.Visibility = VerbVisibility.Visible;
|
|
|
|
|
|
data.Text = Loc.GetString("Transfer liquid from [{0}] to [{1}].", locMyName, locHeldEntityName);
|
|
|
|
|
|
return;
|
2019-07-31 05:10:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-09 18:32:31 -04:00
|
|
|
|
protected override void Activate(IEntity user, SolutionContainerComponent component)
|
2019-07-31 05:10:06 -07:00
|
|
|
|
{
|
2020-09-09 18:32:31 -04:00
|
|
|
|
if (!user.TryGetComponent<HandsComponent>(out var hands) || hands.GetActiveHand == null)
|
|
|
|
|
|
{
|
2019-07-31 05:10:06 -07:00
|
|
|
|
return;
|
2020-09-09 18:32:31 -04:00
|
|
|
|
}
|
2019-07-31 05:10:06 -07:00
|
|
|
|
|
2020-09-09 18:32:31 -04:00
|
|
|
|
if(!hands.GetActiveHand.Owner.TryGetComponent<SolutionContainerComponent>(out var handSolutionComp) ||
|
|
|
|
|
|
!handSolutionComp.CanAddSolutions ||
|
|
|
|
|
|
!component.CanRemoveSolutions)
|
|
|
|
|
|
{
|
2019-07-31 05:10:06 -07:00
|
|
|
|
return;
|
2020-09-09 18:32:31 -04:00
|
|
|
|
}
|
2019-07-31 05:10:06 -07:00
|
|
|
|
|
2020-04-05 11:36:12 +02:00
|
|
|
|
var transferQuantity = ReagentUnit.Min(handSolutionComp.MaxVolume - handSolutionComp.CurrentVolume, component.CurrentVolume, ReagentUnit.New(10));
|
2019-07-31 05:10:06 -07:00
|
|
|
|
|
|
|
|
|
|
if (transferQuantity <= 0)
|
2020-09-09 18:32:31 -04:00
|
|
|
|
{
|
2019-07-31 05:10:06 -07:00
|
|
|
|
return;
|
2020-09-09 18:32:31 -04:00
|
|
|
|
}
|
2019-07-31 15:02:36 +02:00
|
|
|
|
|
2019-07-31 05:10:06 -07:00
|
|
|
|
var transferSolution = component.SplitSolution(transferQuantity);
|
|
|
|
|
|
handSolutionComp.TryAddSolution(transferSolution);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-10-11 16:57:16 -04:00
|
|
|
|
|
|
|
|
|
|
private void CheckForReaction()
|
|
|
|
|
|
{
|
2019-12-04 07:51:05 -05:00
|
|
|
|
bool checkForNewReaction = false;
|
|
|
|
|
|
while (true)
|
2019-10-11 16:57:16 -04:00
|
|
|
|
{
|
2020-04-08 19:07:33 +02:00
|
|
|
|
//TODO: make a hashmap at startup and then look up reagents in the contents for a reaction
|
2019-12-04 07:51:05 -05:00
|
|
|
|
//Check the solution for every reaction
|
|
|
|
|
|
foreach (var reaction in _reactions)
|
2019-10-11 16:57:16 -04:00
|
|
|
|
{
|
2020-03-14 12:55:07 +01:00
|
|
|
|
if (SolutionValidReaction(reaction, out var unitReactions))
|
2019-12-04 07:51:05 -05:00
|
|
|
|
{
|
|
|
|
|
|
PerformReaction(reaction, unitReactions);
|
2020-03-06 20:11:24 +01:00
|
|
|
|
checkForNewReaction = true;
|
2019-12-04 07:51:05 -05:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Check for a new reaction if a reaction occurs, run loop again.
|
|
|
|
|
|
if (checkForNewReaction)
|
|
|
|
|
|
{
|
|
|
|
|
|
checkForNewReaction = false;
|
|
|
|
|
|
continue;
|
2019-10-11 16:57:16 -04:00
|
|
|
|
}
|
2019-12-04 07:51:05 -05:00
|
|
|
|
return;
|
2019-10-11 16:57:16 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-05 11:36:12 +02:00
|
|
|
|
public bool TryAddReagent(string reagentId, ReagentUnit quantity, out ReagentUnit acceptedQuantity, bool skipReactionCheck = false, bool skipColor = false)
|
2019-10-11 16:57:16 -04:00
|
|
|
|
{
|
2020-09-09 18:32:31 -04:00
|
|
|
|
var toAcceptQuantity = MaxVolume - Solution.TotalVolume;
|
2020-03-14 12:55:07 +01:00
|
|
|
|
if (quantity > toAcceptQuantity)
|
2019-10-11 16:57:16 -04:00
|
|
|
|
{
|
2020-03-14 12:55:07 +01:00
|
|
|
|
acceptedQuantity = toAcceptQuantity;
|
2019-10-11 16:57:16 -04:00
|
|
|
|
if (acceptedQuantity == 0) return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
acceptedQuantity = quantity;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-09 18:32:31 -04:00
|
|
|
|
Solution.AddReagent(reagentId, acceptedQuantity);
|
2019-11-12 08:20:03 +11:00
|
|
|
|
if (!skipColor) {
|
|
|
|
|
|
RecalculateColor();
|
|
|
|
|
|
}
|
2019-10-11 16:57:16 -04:00
|
|
|
|
if(!skipReactionCheck)
|
|
|
|
|
|
CheckForReaction();
|
2020-04-09 16:43:56 +05:00
|
|
|
|
OnSolutionChanged(skipColor);
|
2019-10-11 16:57:16 -04:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-10-10 15:25:13 +02:00
|
|
|
|
public override bool CanAddSolution(Solution solution)
|
2020-09-26 14:48:24 +02:00
|
|
|
|
{
|
|
|
|
|
|
return solution.TotalVolume <= (MaxVolume - Solution.TotalVolume);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-10-10 15:25:13 +02:00
|
|
|
|
public override bool TryAddSolution(Solution solution, bool skipReactionCheck = false, bool skipColor = false)
|
2019-10-11 16:57:16 -04:00
|
|
|
|
{
|
2020-09-26 14:48:24 +02:00
|
|
|
|
if (!CanAddSolution(solution))
|
2019-10-11 16:57:16 -04:00
|
|
|
|
return false;
|
|
|
|
|
|
|
2020-09-09 18:32:31 -04:00
|
|
|
|
Solution.AddSolution(solution);
|
2019-11-12 08:20:03 +11:00
|
|
|
|
if (!skipColor) {
|
|
|
|
|
|
RecalculateColor();
|
|
|
|
|
|
}
|
2019-10-11 16:57:16 -04:00
|
|
|
|
if(!skipReactionCheck)
|
|
|
|
|
|
CheckForReaction();
|
2020-04-09 16:43:56 +05:00
|
|
|
|
OnSolutionChanged(skipColor);
|
2019-10-11 16:57:16 -04:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Checks if a solution has the reactants required to cause a specified reaction.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="solution">The solution to check for reaction conditions.</param>
|
|
|
|
|
|
/// <param name="reaction">The reaction whose reactants will be checked for in the solution.</param>
|
|
|
|
|
|
/// <param name="unitReactions">The number of times the reaction can occur with the given solution.</param>
|
|
|
|
|
|
/// <returns></returns>
|
2020-04-05 11:36:12 +02:00
|
|
|
|
private bool SolutionValidReaction(ReactionPrototype reaction, out ReagentUnit unitReactions)
|
2019-10-11 16:57:16 -04:00
|
|
|
|
{
|
2020-04-05 11:36:12 +02:00
|
|
|
|
unitReactions = ReagentUnit.MaxValue; //Set to some impossibly large number initially
|
2019-10-11 16:57:16 -04:00
|
|
|
|
foreach (var reactant in reaction.Reactants)
|
|
|
|
|
|
{
|
2020-04-05 11:36:12 +02:00
|
|
|
|
if (!ContainsReagent(reactant.Key, out ReagentUnit reagentQuantity))
|
2019-10-11 16:57:16 -04:00
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2020-04-05 11:36:12 +02:00
|
|
|
|
var currentUnitReactions = reagentQuantity / reactant.Value.Amount;
|
2019-10-11 16:57:16 -04:00
|
|
|
|
if (currentUnitReactions < unitReactions)
|
|
|
|
|
|
{
|
|
|
|
|
|
unitReactions = currentUnitReactions;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (unitReactions == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Perform a reaction on a solution. This assumes all reaction criteria have already been checked and are met.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="solution">Solution to be reacted.</param>
|
|
|
|
|
|
/// <param name="reaction">Reaction to occur.</param>
|
|
|
|
|
|
/// <param name="unitReactions">The number of times to cause this reaction.</param>
|
2020-04-05 11:36:12 +02:00
|
|
|
|
private void PerformReaction(ReactionPrototype reaction, ReagentUnit unitReactions)
|
2019-10-11 16:57:16 -04:00
|
|
|
|
{
|
|
|
|
|
|
//Remove non-catalysts
|
|
|
|
|
|
foreach (var reactant in reaction.Reactants)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!reactant.Value.Catalyst)
|
|
|
|
|
|
{
|
2020-04-05 11:36:12 +02:00
|
|
|
|
var amountToRemove = unitReactions * reactant.Value.Amount;
|
2019-10-11 16:57:16 -04:00
|
|
|
|
TryRemoveReagent(reactant.Key, amountToRemove);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-09-09 18:32:31 -04:00
|
|
|
|
|
|
|
|
|
|
// Add products
|
2019-10-11 16:57:16 -04:00
|
|
|
|
foreach (var product in reaction.Products)
|
|
|
|
|
|
{
|
2020-04-05 11:36:12 +02:00
|
|
|
|
TryAddReagent(product.Key, product.Value * unitReactions, out var acceptedQuantity, true);
|
2019-10-11 16:57:16 -04:00
|
|
|
|
}
|
2020-09-09 18:32:31 -04:00
|
|
|
|
|
|
|
|
|
|
// Trigger reaction effects
|
2019-10-11 16:57:16 -04:00
|
|
|
|
foreach (var effect in reaction.Effects)
|
|
|
|
|
|
{
|
2020-06-13 01:28:28 -04:00
|
|
|
|
effect.React(Owner, unitReactions.Double());
|
2019-10-11 16:57:16 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-09 18:32:31 -04:00
|
|
|
|
// Play reaction sound client-side
|
2020-09-06 16:11:53 +02:00
|
|
|
|
_audioSystem.PlayAtCoords("/Audio/Effects/Chemistry/bubbles.ogg", Owner.Transform.Coordinates);
|
2019-10-11 16:57:16 -04:00
|
|
|
|
}
|
2020-04-08 15:53:15 +05:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Check if the solution contains the specified reagent.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="reagentId">The reagent to check for.</param>
|
|
|
|
|
|
/// <param name="quantity">Output the quantity of the reagent if it is contained, 0 if it isn't.</param>
|
|
|
|
|
|
/// <returns>Return true if the solution contains the reagent.</returns>
|
2020-04-12 14:44:14 +02:00
|
|
|
|
public bool ContainsReagent(string reagentId, out ReagentUnit quantity)
|
2020-04-08 15:53:15 +05:00
|
|
|
|
{
|
2020-09-09 18:32:31 -04:00
|
|
|
|
foreach (var reagent in Solution.Contents)
|
2020-04-08 15:53:15 +05:00
|
|
|
|
{
|
|
|
|
|
|
if (reagent.ReagentId == reagentId)
|
|
|
|
|
|
{
|
|
|
|
|
|
quantity = reagent.Quantity;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-09-09 18:32:31 -04:00
|
|
|
|
|
2020-04-12 14:44:14 +02:00
|
|
|
|
quantity = ReagentUnit.New(0);
|
2020-04-08 15:53:15 +05:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string GetMajorReagentId()
|
|
|
|
|
|
{
|
2020-09-09 18:32:31 -04:00
|
|
|
|
if (Solution.Contents.Count == 0)
|
2020-04-08 15:53:15 +05:00
|
|
|
|
{
|
|
|
|
|
|
return "";
|
|
|
|
|
|
}
|
2020-09-09 18:32:31 -04:00
|
|
|
|
|
|
|
|
|
|
var majorReagent = Solution.Contents.OrderByDescending(reagent => reagent.Quantity).First();;
|
2020-04-08 15:53:15 +05:00
|
|
|
|
return majorReagent.ReagentId;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-09 16:43:56 +05:00
|
|
|
|
protected void UpdateFillIcon()
|
|
|
|
|
|
{
|
2020-09-09 18:32:31 -04:00
|
|
|
|
if (string.IsNullOrEmpty(_fillInitState))
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2020-04-09 16:43:56 +05:00
|
|
|
|
|
2020-04-12 14:44:14 +02:00
|
|
|
|
var percentage = (CurrentVolume / MaxVolume).Double();
|
2020-04-09 16:43:56 +05:00
|
|
|
|
var level = ContentHelpers.RoundToLevels(percentage * 100, 100, _fillInitSteps);
|
|
|
|
|
|
|
|
|
|
|
|
//Transformed glass uses special fancy sprites so we don't bother
|
2020-09-09 18:32:31 -04:00
|
|
|
|
if (level == 0 || (Owner.TryGetComponent<TransformableContainerComponent>(out var transformComp) && transformComp.Transformed))
|
2020-04-09 16:43:56 +05:00
|
|
|
|
{
|
|
|
|
|
|
_spriteComponent.LayerSetColor(1, Color.Transparent);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2020-09-09 18:32:31 -04:00
|
|
|
|
|
|
|
|
|
|
_fillSprite = new SpriteSpecifier.Rsi(_fillPath, _fillInitState + level);
|
2020-04-09 16:43:56 +05:00
|
|
|
|
_spriteComponent.LayerSetSprite(1, _fillSprite);
|
2020-09-09 18:32:31 -04:00
|
|
|
|
_spriteComponent.LayerSetColor(1, SubstanceColor);
|
2020-04-09 16:43:56 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual void OnSolutionChanged(bool skipColor)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!skipColor)
|
2020-09-09 18:32:31 -04:00
|
|
|
|
{
|
2020-04-09 16:43:56 +05:00
|
|
|
|
RecalculateColor();
|
2020-09-09 18:32:31 -04:00
|
|
|
|
}
|
2020-04-09 16:43:56 +05:00
|
|
|
|
|
|
|
|
|
|
UpdateFillIcon();
|
|
|
|
|
|
_chemistrySystem.HandleSolutionChange(Owner);
|
|
|
|
|
|
}
|
2019-07-31 05:10:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|