Solution refactor (#4407)
* Rename SolutionContainerCaps -> Capability * Move IExamine event to Chemistry System. * ECS the ISolutionChange into SolutionChangeEvent * Unify SolutionContainer into a single shared component * Replace ISolutionInteraction with SolutionContainerComponent * Move all methods from SolutionContainer to ChemistrySystem * Refactor EntitySystem calls to Dependencies * Refactor SolutionContainer to SolutionManager * Fix yamls * Fix test fails * Fix post merge issues * Fix various issues with SolutionManager * More fixes * Fix more components * Fix events not being directed * Fixes for Hypospray * Separate removal and iteration on Metabolism * Fix creampie problems * Address some of sloth's issues * Refactors for Systems * Refactored solution location * Fix tests * Address more sloth issues * Fix dependency * Fix merge conflicts * Add xmldocs for Capabilities components * Remove HasSolution/TryGetDefaultSolution and Add/Remove Drainable/Refillable * Replace Grindable/Juiceable with Extractable * Refactor field names * Fix Drainable * Fix some issues with spillable and injector * Fix issues with Grinder * Fix Beaker having duplicate solutions * Fix foaming * Address some MGS issues * Fix Uid issues * Fix errors in solution Tranfer * Fixed some extra values constant values * Cola is drinkable now
This commit is contained in:
27
Content.Server/Kitchen/Components/ExtractableComponent.cs
Normal file
27
Content.Server/Kitchen/Components/ExtractableComponent.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using Content.Server.Kitchen.EntitySystems;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Robust.Shared.Analyzers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.Kitchen.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Tag component that denotes an entity as Extractable
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
[Friend(typeof(ReagentGrinderSystem))]
|
||||
public class ExtractableComponent : Component
|
||||
{
|
||||
public override string Name => "Extractable";
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("result")]
|
||||
public Solution ResultSolution = new();
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("extractableSolution")]
|
||||
public string? GrindableSolution;
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using Content.Shared.Chemistry.Solution;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.Kitchen.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Tag component that denotes an entity as Juiceable
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public class JuiceableComponent : Component
|
||||
{
|
||||
public override string Name => "Juiceable";
|
||||
[ViewVariables] [DataField("result")] public Solution JuiceResultSolution = new();
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
@@ -13,14 +12,12 @@ using Content.Server.UserInterface;
|
||||
using Content.Shared.Acts;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Body.Part;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Chemistry.Solution;
|
||||
using Content.Shared.Chemistry.Solution.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Kitchen;
|
||||
using Content.Shared.Kitchen.Components;
|
||||
using Content.Shared.Notification;
|
||||
using Content.Shared.Notification.Managers;
|
||||
using Content.Shared.Power;
|
||||
using Content.Shared.Sound;
|
||||
@@ -38,27 +35,28 @@ namespace Content.Server.Kitchen.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(IActivate))]
|
||||
public class MicrowaveComponent : SharedMicrowaveComponent, IActivate, IInteractUsing, ISolutionChange, ISuicideAct, IBreakAct
|
||||
public class MicrowaveComponent : SharedMicrowaveComponent, IActivate, IInteractUsing, ISuicideAct, IBreakAct
|
||||
{
|
||||
[Dependency] private readonly RecipeManager _recipeManager = default!;
|
||||
|
||||
#region YAMLSERIALIZE
|
||||
[DataField("cookTime")]
|
||||
private uint _cookTimeDefault = 5;
|
||||
[DataField("cookTimeMultiplier")]
|
||||
private int _cookTimeMultiplier = 1000; //For upgrades and stuff I guess?
|
||||
[DataField("failureResult")]
|
||||
private string _badRecipeName = "FoodBadRecipe";
|
||||
[DataField("beginCookingSound")]
|
||||
private SoundSpecifier _startCookingSound = new SoundPathSpecifier("/Audio/Machines/microwave_start_beep.ogg");
|
||||
[DataField("foodDoneSound")]
|
||||
private SoundSpecifier _cookingCompleteSound = new SoundPathSpecifier("/Audio/Machines/microwave_done_beep.ogg");
|
||||
|
||||
[DataField("cookTime")] private uint _cookTimeDefault = 5;
|
||||
[DataField("cookTimeMultiplier")] private int _cookTimeMultiplier = 1000; //For upgrades and stuff I guess?
|
||||
[DataField("failureResult")] private string _badRecipeName = "FoodBadRecipe";
|
||||
|
||||
[DataField("beginCookingSound")] private SoundSpecifier _startCookingSound =
|
||||
new SoundPathSpecifier("/Audio/Machines/microwave_start_beep.ogg");
|
||||
|
||||
[DataField("foodDoneSound")] private SoundSpecifier _cookingCompleteSound =
|
||||
new SoundPathSpecifier("/Audio/Machines/microwave_done_beep.ogg");
|
||||
|
||||
[DataField("clickSound")]
|
||||
private SoundSpecifier _clickSound = new SoundPathSpecifier("/Audio/Machines/machine_switch.ogg");
|
||||
|
||||
#endregion YAMLSERIALIZE
|
||||
|
||||
[ViewVariables]
|
||||
private bool _busy = false;
|
||||
[ViewVariables] private bool _busy = false;
|
||||
private bool _broken;
|
||||
|
||||
/// <summary>
|
||||
@@ -66,18 +64,25 @@ namespace Content.Server.Kitchen.Components
|
||||
/// The cook times for all recipes should be divisible by 5,with a minimum of 1 second.
|
||||
/// For right now, I don't think any recipe cook time should be greater than 60 seconds.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
private uint _currentCookTimerTime = 1;
|
||||
[ViewVariables] private uint _currentCookTimerTime = 1;
|
||||
|
||||
private bool Powered => !Owner.TryGetComponent(out ApcPowerReceiverComponent? receiver) || receiver.Powered;
|
||||
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;
|
||||
|
||||
void ISolutionChange.SolutionChanged(SolutionChangeEventArgs eventArgs) => _uiDirty = true;
|
||||
private AudioSystem _audioSystem = default!;
|
||||
private bool HasContents => EntitySystem.Get<SolutionContainerSystem>()
|
||||
.TryGetSolution(Owner, SolutionName, out var solution) &&
|
||||
(solution.Contents.Count > 0 || _storage.ContainedEntities.Count > 0);
|
||||
|
||||
private bool _uiDirty = true;
|
||||
private bool _lostPower;
|
||||
private int _currentCookTimeButtonIndex;
|
||||
|
||||
public void DirtyUi()
|
||||
{
|
||||
_uiDirty = true;
|
||||
}
|
||||
|
||||
private Container _storage = default!;
|
||||
private const string SolutionName = "microwave";
|
||||
|
||||
[ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(MicrowaveUiKey.Key);
|
||||
|
||||
@@ -87,10 +92,10 @@ namespace Content.Server.Kitchen.Components
|
||||
|
||||
_currentCookTimerTime = _cookTimeDefault;
|
||||
|
||||
Owner.EnsureComponent<SolutionContainerComponent>();
|
||||
EntitySystem.Get<SolutionContainerSystem>().EnsureSolution(Owner, SolutionName);
|
||||
|
||||
_storage = ContainerHelpers.EnsureContainer<Container>(Owner, "microwave_entity_container", out var existed);
|
||||
_audioSystem = EntitySystem.Get<AudioSystem>();
|
||||
_storage = ContainerHelpers.EnsureContainer<Container>(Owner, "microwave_entity_container",
|
||||
out _);
|
||||
|
||||
if (UserInterface != null)
|
||||
{
|
||||
@@ -107,33 +112,36 @@ namespace Content.Server.Kitchen.Components
|
||||
|
||||
switch (message.Message)
|
||||
{
|
||||
case MicrowaveStartCookMessage msg:
|
||||
case MicrowaveStartCookMessage:
|
||||
Wzhzhzh();
|
||||
break;
|
||||
case MicrowaveEjectMessage msg:
|
||||
if (_hasContents)
|
||||
case MicrowaveEjectMessage:
|
||||
if (HasContents)
|
||||
{
|
||||
VaporizeReagents();
|
||||
EjectSolids();
|
||||
ClickSound();
|
||||
_uiDirty = true;
|
||||
}
|
||||
|
||||
break;
|
||||
case MicrowaveEjectSolidIndexedMessage msg:
|
||||
if (_hasContents)
|
||||
if (HasContents)
|
||||
{
|
||||
EjectSolid(msg.EntityID);
|
||||
ClickSound();
|
||||
_uiDirty = true;
|
||||
}
|
||||
|
||||
break;
|
||||
case MicrowaveVaporizeReagentIndexedMessage msg:
|
||||
if (_hasContents)
|
||||
if (HasContents)
|
||||
{
|
||||
VaporizeReagentQuantity(msg.ReagentQuantity);
|
||||
ClickSound();
|
||||
_uiDirty = true;
|
||||
}
|
||||
|
||||
break;
|
||||
case MicrowaveSelectCookTimeMessage msg:
|
||||
_currentCookTimeButtonIndex = msg.ButtonIndex;
|
||||
@@ -142,12 +150,10 @@ namespace Content.Server.Kitchen.Components
|
||||
_uiDirty = true;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void OnUpdate()
|
||||
{
|
||||
|
||||
if (!Powered)
|
||||
{
|
||||
//TODO:If someone cuts power currently, microwave magically keeps going. FIX IT!
|
||||
@@ -175,11 +181,12 @@ namespace Content.Server.Kitchen.Components
|
||||
_uiDirty = true;
|
||||
}
|
||||
|
||||
if (_uiDirty && Owner.TryGetComponent(out SolutionContainerComponent? solution))
|
||||
if (_uiDirty && EntitySystem.Get<SolutionContainerSystem>()
|
||||
.TryGetSolution(Owner, SolutionName, out var solution))
|
||||
{
|
||||
UserInterface?.SetState(new MicrowaveUpdateUserInterfaceState
|
||||
(
|
||||
solution.Solution.Contents.ToArray(),
|
||||
solution.Contents.ToArray(),
|
||||
_storage.ContainedEntities.Select(item => item.Uid).ToArray(),
|
||||
_busy,
|
||||
_currentCookTimeButtonIndex,
|
||||
@@ -244,40 +251,41 @@ namespace Content.Server.Kitchen.Components
|
||||
|
||||
if (itemEntity.TryGetComponent<SolutionTransferComponent>(out var attackPourable))
|
||||
{
|
||||
if (!itemEntity.TryGetComponent<ISolutionInteractionsComponent>(out var attackSolution)
|
||||
|| !attackSolution.CanDrain)
|
||||
var solutionsSystem = EntitySystem.Get<SolutionContainerSystem>();
|
||||
if (!solutionsSystem.TryGetDrainableSolution(itemEntity.Uid, out var attackSolution))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Owner.TryGetComponent(out SolutionContainerComponent? solution))
|
||||
if (!solutionsSystem.TryGetSolution(Owner, SolutionName, out var solution))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//Get transfer amount. May be smaller than _transferAmount if not enough room
|
||||
var realTransferAmount = ReagentUnit.Min(attackPourable.TransferAmount, solution.EmptyVolume);
|
||||
var realTransferAmount = ReagentUnit.Min(attackPourable.TransferAmount, solution.AvailableVolume);
|
||||
if (realTransferAmount <= 0) //Special message if container is full
|
||||
{
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("microwave-component-interact-using-container-full"));
|
||||
Owner.PopupMessage(eventArgs.User,
|
||||
Loc.GetString("microwave-component-interact-using-container-full"));
|
||||
return false;
|
||||
}
|
||||
|
||||
//Move units from attackSolution to targetSolution
|
||||
var removedSolution = attackSolution.Drain(realTransferAmount);
|
||||
if (!solution.TryAddSolution(removedSolution))
|
||||
var removedSolution = EntitySystem.Get<SolutionContainerSystem>()
|
||||
.Drain(itemEntity.Uid, attackSolution, realTransferAmount);
|
||||
if (!EntitySystem.Get<SolutionContainerSystem>().TryAddSolution(Owner.Uid, solution, removedSolution))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("microwave-component-interact-using-transfer-success",
|
||||
("amount", removedSolution.TotalVolume)));
|
||||
("amount", removedSolution.TotalVolume)));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!itemEntity.TryGetComponent(typeof(ItemComponent), out var food))
|
||||
{
|
||||
|
||||
Owner.PopupMessage(eventArgs.User, "microwave-component-interact-using-transfer-fail");
|
||||
return false;
|
||||
}
|
||||
@@ -292,7 +300,7 @@ namespace Content.Server.Kitchen.Components
|
||||
// ReSharper disable once IdentifierTypo
|
||||
private void Wzhzhzh()
|
||||
{
|
||||
if (!_hasContents)
|
||||
if (!HasContents)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -331,14 +339,15 @@ namespace Content.Server.Kitchen.Components
|
||||
|
||||
// Check recipes
|
||||
FoodRecipePrototype? recipeToCook = null;
|
||||
foreach (var r in _recipeManager.Recipes.Where(r => CanSatisfyRecipe(r, solidsDict) == MicrowaveSuccessState.RecipePass))
|
||||
foreach (var r in _recipeManager.Recipes.Where(r =>
|
||||
CanSatisfyRecipe(r, solidsDict) == MicrowaveSuccessState.RecipePass))
|
||||
{
|
||||
recipeToCook = r;
|
||||
}
|
||||
|
||||
SetAppearance(MicrowaveVisualState.Cooking);
|
||||
SoundSystem.Play(Filter.Pvs(Owner), _startCookingSound.GetSound(), Owner, AudioParams.Default);
|
||||
Owner.SpawnTimer((int) (_currentCookTimerTime * _cookTimeMultiplier), (Action) (() =>
|
||||
Owner.SpawnTimer((int) (_currentCookTimerTime * _cookTimeMultiplier), () =>
|
||||
{
|
||||
if (_lostPower)
|
||||
{
|
||||
@@ -372,24 +381,25 @@ namespace Content.Server.Kitchen.Components
|
||||
_busy = false;
|
||||
|
||||
_uiDirty = true;
|
||||
}));
|
||||
});
|
||||
_lostPower = false;
|
||||
_uiDirty = true;
|
||||
}
|
||||
|
||||
private void VaporizeReagents()
|
||||
{
|
||||
if (Owner.TryGetComponent(out SolutionContainerComponent? solution))
|
||||
if (EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var solution))
|
||||
{
|
||||
solution.RemoveAllSolution();
|
||||
EntitySystem.Get<SolutionContainerSystem>().RemoveAllSolution(Owner.Uid, solution);
|
||||
}
|
||||
}
|
||||
|
||||
private void VaporizeReagentQuantity(Solution.ReagentQuantity reagentQuantity)
|
||||
{
|
||||
if (Owner.TryGetComponent(out SolutionContainerComponent? solution))
|
||||
if (EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var solution))
|
||||
{
|
||||
solution?.TryRemoveReagent(reagentQuantity.ReagentId, reagentQuantity.Quantity);
|
||||
EntitySystem.Get<SolutionContainerSystem>()
|
||||
.TryRemoveReagent(Owner.Uid, solution, reagentQuantity.ReagentId, reagentQuantity.Quantity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -405,32 +415,32 @@ namespace Content.Server.Kitchen.Components
|
||||
|
||||
private void EjectSolids()
|
||||
{
|
||||
|
||||
for (var i = _storage.ContainedEntities.Count - 1; i >= 0; i--)
|
||||
{
|
||||
_storage.Remove(_storage.ContainedEntities.ElementAt(i));
|
||||
}
|
||||
}
|
||||
|
||||
private void EjectSolid(EntityUid entityID)
|
||||
private void EjectSolid(EntityUid entityId)
|
||||
{
|
||||
if (Owner.EntityManager.EntityExists(entityID))
|
||||
if (Owner.EntityManager.EntityExists(entityId))
|
||||
{
|
||||
_storage.Remove(Owner.EntityManager.GetEntity(entityID));
|
||||
_storage.Remove(Owner.EntityManager.GetEntity(entityId));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void SubtractContents(FoodRecipePrototype recipe)
|
||||
{
|
||||
if (!Owner.TryGetComponent(out SolutionContainerComponent? solution))
|
||||
var solutionUid = Owner.Uid;
|
||||
if (!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var solution))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var recipeReagent in recipe.IngredientsReagents)
|
||||
{
|
||||
solution?.TryRemoveReagent(recipeReagent.Key, ReagentUnit.New(recipeReagent.Value));
|
||||
EntitySystem.Get<SolutionContainerSystem>()
|
||||
.TryRemoveReagent(solutionUid, solution, recipeReagent.Key, ReagentUnit.New(recipeReagent.Value));
|
||||
}
|
||||
|
||||
foreach (var recipeSolid in recipe.IngredientsSolids)
|
||||
@@ -453,7 +463,6 @@ namespace Content.Server.Kitchen.Components
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private MicrowaveSuccessState CanSatisfyRecipe(FoodRecipePrototype recipe, Dictionary<string, int> solids)
|
||||
@@ -463,14 +472,14 @@ namespace Content.Server.Kitchen.Components
|
||||
return MicrowaveSuccessState.RecipeFail;
|
||||
}
|
||||
|
||||
if (!Owner.TryGetComponent(out SolutionContainerComponent? solution))
|
||||
if (!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var solution))
|
||||
{
|
||||
return MicrowaveSuccessState.RecipeFail;
|
||||
}
|
||||
|
||||
foreach (var reagent in recipe.IngredientsReagents)
|
||||
{
|
||||
if (!solution.Solution.ContainsReagent(reagent.Key, out var amount))
|
||||
if (!solution.ContainsReagent(reagent.Key, out var amount))
|
||||
{
|
||||
return MicrowaveSuccessState.RecipeFail;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Content.Server.Chemistry.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Kitchen.Components;
|
||||
using Content.Shared.Sound;
|
||||
using Robust.Shared.Containers;
|
||||
@@ -9,7 +8,6 @@ using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.Kitchen.Components
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// The combo reagent grinder/juicer. The reason why grinding and juicing are seperate is simple,
|
||||
/// think of grinding as a utility to break an object down into its reagents. Think of juicing as
|
||||
@@ -24,7 +22,7 @@ namespace Content.Server.Kitchen.Components
|
||||
/// <summary>
|
||||
/// Can be null since we won't always have a beaker in the grinder.
|
||||
/// </summary>
|
||||
[ViewVariables] public SolutionContainerComponent? HeldBeaker = default!;
|
||||
[ViewVariables] public Solution? HeldBeaker = default!;
|
||||
|
||||
/// <summary>
|
||||
/// Contains the things that are going to be ground or juiced.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Content.Server.Kitchen.Components;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
@@ -7,6 +8,18 @@ namespace Content.Server.Kitchen.EntitySystems
|
||||
[UsedImplicitly]
|
||||
internal sealed class MicrowaveSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<MicrowaveComponent, SolutionChangedEvent>(OnSolutionChange);
|
||||
}
|
||||
|
||||
private void OnSolutionChange(EntityUid uid, MicrowaveComponent component, SolutionChangedEvent args)
|
||||
{
|
||||
component.DirtyUi();
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Server.Chemistry.Components;
|
||||
using Content.Server.Hands.Components;
|
||||
using Content.Server.Items;
|
||||
using Content.Server.Kitchen.Components;
|
||||
using Content.Server.Kitchen.Events;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.Stack;
|
||||
using Content.Server.UserInterface;
|
||||
using Content.Server.Kitchen.Events;
|
||||
using Content.Shared.Chemistry.Solution;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Kitchen.Components;
|
||||
using Content.Shared.Notification.Managers;
|
||||
using Content.Shared.Random.Helpers;
|
||||
using Content.Shared.Tag;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
@@ -30,7 +28,7 @@ namespace Content.Server.Kitchen.EntitySystems
|
||||
[UsedImplicitly]
|
||||
internal sealed class ReagentGrinderSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
[Dependency] private readonly SolutionContainerSystem _solutionsSystem = default!;
|
||||
|
||||
private Queue<ReagentGrinderComponent> _uiUpdateQueue = new();
|
||||
|
||||
@@ -39,13 +37,14 @@ namespace Content.Server.Kitchen.EntitySystems
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<ReagentGrinderComponent, ComponentInit>(OnComponentInit);
|
||||
SubscribeLocalEvent<ReagentGrinderComponent, PowerChangedEvent>((_, component, _) => EnqueueUiUpdate(component));
|
||||
SubscribeLocalEvent<ReagentGrinderComponent, PowerChangedEvent>((_, component, _) =>
|
||||
EnqueueUiUpdate(component));
|
||||
SubscribeLocalEvent<ReagentGrinderComponent, InteractHandEvent>(OnInteractHand);
|
||||
SubscribeLocalEvent<ReagentGrinderComponent, InteractUsingEvent>(OnInteractUsing);
|
||||
SubscribeLocalEvent<StackComponent, JuiceableScalingEvent>(JuiceableScaling);
|
||||
SubscribeLocalEvent<StackComponent, ExtractableScalingEvent>(ExtractableScaling);
|
||||
}
|
||||
|
||||
private void JuiceableScaling(EntityUid uid, StackComponent component, JuiceableScalingEvent args)
|
||||
private void ExtractableScaling(EntityUid uid, StackComponent component, ExtractableScalingEvent args)
|
||||
{
|
||||
args.Scalar *= component.Count; // multiply scalar by amount of items in stack
|
||||
}
|
||||
@@ -54,19 +53,20 @@ namespace Content.Server.Kitchen.EntitySystems
|
||||
{
|
||||
if (args.Handled) return;
|
||||
|
||||
if (!args.User.TryGetComponent(out IHandsComponent? hands))
|
||||
if (!args.User.HasComponent<IHandsComponent>())
|
||||
{
|
||||
component.Owner.PopupMessage(args.User, Loc.GetString("reagent-grinder-component-interact-using-no-hands"));
|
||||
component.Owner.PopupMessage(args.User,
|
||||
Loc.GetString("reagent-grinder-component-interact-using-no-hands"));
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
IEntity heldEnt = args.Used;
|
||||
|
||||
//First, check if user is trying to insert a beaker.
|
||||
//No promise it will be a beaker right now, but whatever.
|
||||
//Maybe this should whitelist "beaker" in the prototype id of heldEnt?
|
||||
if (heldEnt.TryGetComponent(out SolutionContainerComponent? beaker) && beaker.Capabilities.HasFlag(SolutionContainerCaps.FitsInDispenser))
|
||||
// First, check if user is trying to insert a beaker.
|
||||
// No promise it will be a beaker right now, but whatever.
|
||||
// Maybe this should whitelist "beaker" in the prototype id of heldEnt?
|
||||
if (_solutionsSystem.TryGetFitsInDispenser(heldEnt.Uid, out var beaker))
|
||||
{
|
||||
component.BeakerContainer.Insert(heldEnt);
|
||||
component.HeldBeaker = beaker;
|
||||
@@ -74,15 +74,17 @@ namespace Content.Server.Kitchen.EntitySystems
|
||||
//We are done, return. Insert the beaker and exit!
|
||||
if (component.Owner.TryGetComponent(out AppearanceComponent? appearance))
|
||||
{
|
||||
appearance.SetData(SharedReagentGrinderComponent.ReagentGrinderVisualState.BeakerAttached, component.BeakerContainer.ContainedEntity != null);
|
||||
appearance.SetData(SharedReagentGrinderComponent.ReagentGrinderVisualState.BeakerAttached,
|
||||
component.BeakerContainer.ContainedEntity != null);
|
||||
}
|
||||
|
||||
ClickSound(component);
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
//Next, see if the user is trying to insert something they want to be ground/juiced.
|
||||
if (!heldEnt.HasTag("Grindable") && !heldEnt.TryGetComponent(out JuiceableComponent? juice))
|
||||
if (!heldEnt.TryGetComponent(out ExtractableComponent? juice))
|
||||
{
|
||||
//Entity did NOT pass the whitelist for grind/juice.
|
||||
//Wouldn't want the clown grinding up the Captain's ID card now would you?
|
||||
@@ -114,8 +116,10 @@ namespace Content.Server.Kitchen.EntitySystems
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
EnqueueUiUpdate(component);
|
||||
component.Owner.GetUIOrNull(SharedReagentGrinderComponent.ReagentGrinderUiKey.Key)?.Toggle(actor.PlayerSession);
|
||||
component.Owner.GetUIOrNull(SharedReagentGrinderComponent.ReagentGrinderUiKey.Key)
|
||||
?.Toggle(actor.PlayerSession);
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
@@ -130,11 +134,13 @@ namespace Content.Server.Kitchen.EntitySystems
|
||||
|
||||
//A slot for the beaker where the grounds/juices will go.
|
||||
component.BeakerContainer =
|
||||
ContainerHelpers.EnsureContainer<ContainerSlot>(component.Owner, $"{component.Name}-reagentContainerContainer");
|
||||
ContainerHelpers.EnsureContainer<ContainerSlot>(component.Owner,
|
||||
$"{component.Name}-reagentContainerContainer");
|
||||
|
||||
//A container for the things that WILL be ground/juiced. Useful for ejecting them instead of deleting them from the hands of the user.
|
||||
component.Chamber =
|
||||
ContainerHelpers.EnsureContainer<Container>(component.Owner, $"{component.Name}-entityContainerContainer");
|
||||
ContainerHelpers.EnsureContainer<Container>(component.Owner,
|
||||
$"{component.Name}-entityContainerContainer");
|
||||
|
||||
var bui = component.Owner.GetUIOrNull(SharedReagentGrinderComponent.ReagentGrinderUiKey.Key);
|
||||
if (bui != null)
|
||||
@@ -154,15 +160,19 @@ namespace Content.Server.Kitchen.EntitySystems
|
||||
switch (message.Message)
|
||||
{
|
||||
case SharedReagentGrinderComponent.ReagentGrinderGrindStartMessage msg:
|
||||
if (!component.Owner.TryGetComponent(out ApcPowerReceiverComponent? receiver) || !receiver.Powered) break;
|
||||
if (!component.Owner.TryGetComponent(out ApcPowerReceiverComponent? receiver) ||
|
||||
!receiver.Powered) break;
|
||||
ClickSound(component);
|
||||
DoWork(component, message.Session.AttachedEntity!, SharedReagentGrinderComponent.GrinderProgram.Grind);
|
||||
DoWork(component, message.Session.AttachedEntity!,
|
||||
SharedReagentGrinderComponent.GrinderProgram.Grind);
|
||||
break;
|
||||
|
||||
case SharedReagentGrinderComponent.ReagentGrinderJuiceStartMessage msg:
|
||||
if (!component.Owner.TryGetComponent(out ApcPowerReceiverComponent? receiver2) || !receiver2.Powered) break;
|
||||
if (!component.Owner.TryGetComponent(out ApcPowerReceiverComponent? receiver2) ||
|
||||
!receiver2.Powered) break;
|
||||
ClickSound(component);
|
||||
DoWork(component, message.Session.AttachedEntity!, SharedReagentGrinderComponent.GrinderProgram.Juice);
|
||||
DoWork(component, message.Session.AttachedEntity!,
|
||||
SharedReagentGrinderComponent.GrinderProgram.Juice);
|
||||
break;
|
||||
|
||||
case SharedReagentGrinderComponent.ReagentGrinderEjectChamberAllMessage msg:
|
||||
@@ -175,8 +185,10 @@ namespace Content.Server.Kitchen.EntitySystems
|
||||
component.Chamber.Remove(entity);
|
||||
entity.RandomOffset(0.4f);
|
||||
}
|
||||
|
||||
EnqueueUiUpdate(component);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case SharedReagentGrinderComponent.ReagentGrinderEjectChamberContentMessage msg:
|
||||
@@ -187,6 +199,7 @@ namespace Content.Server.Kitchen.EntitySystems
|
||||
EnqueueUiUpdate(component);
|
||||
ClickSound(component);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case SharedReagentGrinderComponent.ReagentGrinderEjectBeakerMessage msg:
|
||||
@@ -203,7 +216,7 @@ namespace Content.Server.Kitchen.EntitySystems
|
||||
|
||||
while (_uiUpdateQueue.TryDequeue(out var comp))
|
||||
{
|
||||
if(comp.Deleted)
|
||||
if (comp.Deleted)
|
||||
continue;
|
||||
|
||||
bool canJuice = false;
|
||||
@@ -212,23 +225,25 @@ namespace Content.Server.Kitchen.EntitySystems
|
||||
{
|
||||
foreach (var entity in comp.Chamber.ContainedEntities)
|
||||
{
|
||||
if (!canJuice && entity.HasComponent<JuiceableComponent>()) canJuice = true;
|
||||
if (!canGrind && entity.HasTag("Grindable")) canGrind = true;
|
||||
if (canJuice && canGrind) break;
|
||||
if (canJuice || !entity.TryGetComponent(out ExtractableComponent? component)) continue;
|
||||
|
||||
canJuice = component.GrindableSolution == null;
|
||||
canGrind = component.GrindableSolution != null;
|
||||
}
|
||||
}
|
||||
|
||||
comp.Owner.GetUIOrNull(SharedReagentGrinderComponent.ReagentGrinderUiKey.Key)?.SetState(new ReagentGrinderInterfaceState
|
||||
(
|
||||
comp.Busy,
|
||||
comp.BeakerContainer.ContainedEntity != null,
|
||||
comp.Owner.TryGetComponent(out ApcPowerReceiverComponent? receiver) && receiver.Powered,
|
||||
canJuice,
|
||||
canGrind,
|
||||
comp.Chamber.ContainedEntities.Select(item => item.Uid).ToArray(),
|
||||
//Remember the beaker can be null!
|
||||
comp.HeldBeaker?.Solution.Contents.ToArray()
|
||||
));
|
||||
comp.Owner.GetUIOrNull(SharedReagentGrinderComponent.ReagentGrinderUiKey.Key)?.SetState(
|
||||
new ReagentGrinderInterfaceState
|
||||
(
|
||||
comp.Busy,
|
||||
comp.BeakerContainer.ContainedEntity != null,
|
||||
comp.Owner.TryGetComponent(out ApcPowerReceiverComponent? receiver) && receiver.Powered,
|
||||
canJuice,
|
||||
canGrind,
|
||||
comp.Chamber.ContainedEntities.Select(item => item.Uid).ToArray(),
|
||||
//Remember the beaker can be null!
|
||||
comp.HeldBeaker?.Contents.ToArray()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,7 +262,8 @@ namespace Content.Server.Kitchen.EntitySystems
|
||||
|
||||
component.BeakerContainer.Remove(beaker);
|
||||
|
||||
if (user == null || !user.TryGetComponent<HandsComponent>(out var hands) || !component.HeldBeaker.Owner.TryGetComponent<ItemComponent>(out var item))
|
||||
if (user == null || !user.TryGetComponent<HandsComponent>(out var hands) ||
|
||||
!beaker.TryGetComponent<ItemComponent>(out var item))
|
||||
return;
|
||||
hands.PutInHandOrDrop(item);
|
||||
|
||||
@@ -255,7 +271,8 @@ namespace Content.Server.Kitchen.EntitySystems
|
||||
EnqueueUiUpdate(component);
|
||||
if (component.Owner.TryGetComponent(out AppearanceComponent? appearance))
|
||||
{
|
||||
appearance.SetData(SharedReagentGrinderComponent.ReagentGrinderVisualState.BeakerAttached, component.BeakerContainer.ContainedEntity != null);
|
||||
appearance.SetData(SharedReagentGrinderComponent.ReagentGrinderVisualState.BeakerAttached,
|
||||
component.BeakerContainer.ContainedEntity != null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,10 +280,13 @@ namespace Content.Server.Kitchen.EntitySystems
|
||||
/// The wzhzhzh of the grinder. Processes the contents of the grinder and puts the output in the beaker.
|
||||
/// </summary>
|
||||
/// <param name="isJuiceIntent">true for wanting to juice, false for wanting to grind.</param>
|
||||
private void DoWork(ReagentGrinderComponent component, IEntity user, SharedReagentGrinderComponent.GrinderProgram program)
|
||||
private void DoWork(ReagentGrinderComponent component, IEntity user,
|
||||
SharedReagentGrinderComponent.GrinderProgram program)
|
||||
{
|
||||
//Have power, are we busy, chamber has anything to grind, a beaker for the grounds to go?
|
||||
if (!component.Owner.TryGetComponent(out ApcPowerReceiverComponent? receiver) || !receiver.Powered || component.Busy || component.Chamber.ContainedEntities.Count <= 0 || component.BeakerContainer.ContainedEntity == null || component.HeldBeaker == null)
|
||||
if (!component.Owner.TryGetComponent(out ApcPowerReceiverComponent? receiver) || !receiver.Powered ||
|
||||
component.Busy || component.Chamber.ContainedEntities.Count <= 0 ||
|
||||
component.BeakerContainer.ContainedEntity == null || component.HeldBeaker == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -275,25 +295,31 @@ namespace Content.Server.Kitchen.EntitySystems
|
||||
|
||||
var bui = component.Owner.GetUIOrNull(SharedReagentGrinderComponent.ReagentGrinderUiKey.Key);
|
||||
bui?.SendMessage(new SharedReagentGrinderComponent.ReagentGrinderWorkStartedMessage(program));
|
||||
var beakerEntity = component.BeakerContainer.ContainedEntity;
|
||||
switch (program)
|
||||
{
|
||||
case SharedReagentGrinderComponent.GrinderProgram.Grind:
|
||||
SoundSystem.Play(Filter.Pvs(component.Owner), component.GrindSound.GetSound(), component.Owner, AudioParams.Default);
|
||||
//Get each item inside the chamber and get the reagents it contains. Transfer those reagents to the beaker, given we have one in.
|
||||
// Get each item inside the chamber and get the reagents it contains.
|
||||
// Transfer those reagents to the beaker, given we have one in.
|
||||
component.Owner.SpawnTimer(component.WorkTime, (Action) (() =>
|
||||
{
|
||||
foreach (var item in component.Chamber.ContainedEntities.ToList())
|
||||
{
|
||||
if (!item.HasTag("Grindable")) continue;
|
||||
if (!item.TryGetComponent<SolutionContainerComponent>(out var solution)) continue;
|
||||
var juiceEvent = new JuiceableScalingEvent(); // default of scalar is always 1.0
|
||||
RaiseLocalEvent<JuiceableScalingEvent>(item.Uid, juiceEvent, false);
|
||||
if (component.HeldBeaker.CurrentVolume + solution.CurrentVolume * juiceEvent.Scalar > component.HeldBeaker.MaxVolume) continue;
|
||||
solution.Solution.ScaleSolution(juiceEvent.Scalar);
|
||||
component.HeldBeaker.TryAddSolution(solution.Solution);
|
||||
solution.RemoveAllSolution();
|
||||
if (!item.TryGetComponent(out ExtractableComponent? extract)
|
||||
|| extract.GrindableSolution == null
|
||||
|| !_solutionsSystem.TryGetSolution(item, extract.GrindableSolution, out var solution)) continue;
|
||||
|
||||
var juiceEvent = new ExtractableScalingEvent(); // default of scalar is always 1.0
|
||||
RaiseLocalEvent(item.Uid, juiceEvent, false);
|
||||
if (component.HeldBeaker.CurrentVolume + solution.CurrentVolume * juiceEvent.Scalar >
|
||||
component.HeldBeaker.MaxVolume) continue;
|
||||
solution.ScaleSolution(juiceEvent.Scalar);
|
||||
_solutionsSystem.TryAddSolution(beakerEntity.Uid, component.HeldBeaker, solution);
|
||||
_solutionsSystem.RemoveAllSolution(beakerEntity.Uid, solution);
|
||||
item.Delete();
|
||||
}
|
||||
|
||||
component.Busy = false;
|
||||
EnqueueUiUpdate(component);
|
||||
bui?.SendMessage(new SharedReagentGrinderComponent.ReagentGrinderWorkCompleteMessage());
|
||||
@@ -306,17 +332,21 @@ namespace Content.Server.Kitchen.EntitySystems
|
||||
{
|
||||
foreach (var item in component.Chamber.ContainedEntities.ToList())
|
||||
{
|
||||
if (!item.TryGetComponent<JuiceableComponent>(out var juiceMe)) continue;
|
||||
var juiceEvent = new JuiceableScalingEvent(); // default of scalar is always 1.0
|
||||
if (!item.TryGetComponent<ExtractableComponent>(out var juiceMe)) continue;
|
||||
var juiceEvent = new ExtractableScalingEvent(); // default of scalar is always 1.0
|
||||
if (item.HasComponent<StackComponent>())
|
||||
{
|
||||
RaiseLocalEvent<JuiceableScalingEvent>(item.Uid, juiceEvent);
|
||||
RaiseLocalEvent(item.Uid, juiceEvent);
|
||||
}
|
||||
if (component.HeldBeaker.CurrentVolume + juiceMe.JuiceResultSolution.TotalVolume * juiceEvent.Scalar > component.HeldBeaker.MaxVolume) continue;
|
||||
juiceMe.JuiceResultSolution.ScaleSolution(juiceEvent.Scalar);
|
||||
component.HeldBeaker.TryAddSolution(juiceMe.JuiceResultSolution);
|
||||
|
||||
if (component.HeldBeaker.CurrentVolume +
|
||||
juiceMe.ResultSolution.TotalVolume * juiceEvent.Scalar >
|
||||
component.HeldBeaker.MaxVolume) continue;
|
||||
juiceMe.ResultSolution.ScaleSolution(juiceEvent.Scalar);
|
||||
_solutionsSystem.TryAddSolution(beakerEntity.Uid, component.HeldBeaker, juiceMe.ResultSolution);
|
||||
item.Delete();
|
||||
}
|
||||
|
||||
bui?.SendMessage(new SharedReagentGrinderComponent.ReagentGrinderWorkCompleteMessage());
|
||||
component.Busy = false;
|
||||
EnqueueUiUpdate(component);
|
||||
|
||||
@@ -5,10 +5,10 @@ namespace Content.Server.Kitchen.Events
|
||||
/// <summary>
|
||||
/// Used in scaling amount of solution to extract in juicing
|
||||
/// </summary>
|
||||
public class JuiceableScalingEvent : EntityEventArgs
|
||||
public class ExtractableScalingEvent : EntityEventArgs
|
||||
{
|
||||
|
||||
public JuiceableScalingEvent()
|
||||
public ExtractableScalingEvent()
|
||||
{
|
||||
Scalar = 1f;
|
||||
}
|
||||
Reference in New Issue
Block a user