grindable/juiceable stacks (#4391)
* grindable/juiceable stacks reagent grinder now takes stacks into account added ScaleSolution that allows easy scaling of solution contents * grindable/juiceable stacks revision grinder/juicer stack fix now ECS added JuiceableScalingEvent * Update Content.Server/Kitchen/EntitySystems/ReagentGrinderSystem.cs Co-authored-by: mirrorcult <lunarautomaton6@gmail.com> * Update Content.Server/Kitchen/EntitySystems/ReagentGrinderSystem.cs Co-authored-by: mirrorcult <lunarautomaton6@gmail.com> Co-authored-by: Vera Aguilera Puerto <6766154+Zumorica@users.noreply.github.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Server.Chemistry.Components;
|
||||
@@ -6,7 +6,9 @@ using Content.Server.Hands.Components;
|
||||
using Content.Server.Items;
|
||||
using Content.Server.Kitchen.Components;
|
||||
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.Interaction;
|
||||
using Content.Shared.Kitchen.Components;
|
||||
@@ -40,6 +42,12 @@ namespace Content.Server.Kitchen.EntitySystems
|
||||
SubscribeLocalEvent<ReagentGrinderComponent, PowerChangedEvent>((_, component, _) => EnqueueUiUpdate(component));
|
||||
SubscribeLocalEvent<ReagentGrinderComponent, InteractHandEvent>(OnInteractHand);
|
||||
SubscribeLocalEvent<ReagentGrinderComponent, InteractUsingEvent>(OnInteractUsing);
|
||||
SubscribeLocalEvent<StackComponent, JuiceableScalingEvent>(JuiceableScaling);
|
||||
}
|
||||
|
||||
private void JuiceableScaling(EntityUid uid, StackComponent component, JuiceableScalingEvent args)
|
||||
{
|
||||
args.Scalar *= component.Count; // multiply scalar by amount of items in stack
|
||||
}
|
||||
|
||||
private void OnInteractUsing(EntityUid uid, ReagentGrinderComponent component, InteractUsingEvent args)
|
||||
@@ -278,12 +286,14 @@ namespace Content.Server.Kitchen.EntitySystems
|
||||
{
|
||||
if (!item.HasTag("Grindable")) continue;
|
||||
if (!item.TryGetComponent<SolutionContainerComponent>(out var solution)) continue;
|
||||
if (component.HeldBeaker.CurrentVolume + solution.CurrentVolume > component.HeldBeaker.MaxVolume) 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();
|
||||
item.Delete();
|
||||
}
|
||||
|
||||
component.Busy = false;
|
||||
EnqueueUiUpdate(component);
|
||||
bui?.SendMessage(new SharedReagentGrinderComponent.ReagentGrinderWorkCompleteMessage());
|
||||
@@ -297,7 +307,13 @@ namespace Content.Server.Kitchen.EntitySystems
|
||||
foreach (var item in component.Chamber.ContainedEntities.ToList())
|
||||
{
|
||||
if (!item.TryGetComponent<JuiceableComponent>(out var juiceMe)) continue;
|
||||
if (component.HeldBeaker.CurrentVolume + juiceMe.JuiceResultSolution.TotalVolume > component.HeldBeaker.MaxVolume) continue;
|
||||
var juiceEvent = new JuiceableScalingEvent(); // default of scalar is always 1.0
|
||||
if (item.HasComponent<StackComponent>())
|
||||
{
|
||||
RaiseLocalEvent<JuiceableScalingEvent>(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);
|
||||
item.Delete();
|
||||
}
|
||||
|
||||
23
Content.Server/Kitchen/Events/JuiceableScalingEvent.cs
Normal file
23
Content.Server/Kitchen/Events/JuiceableScalingEvent.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.Kitchen.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// Used in scaling amount of solution to extract in juicing
|
||||
/// </summary>
|
||||
public class JuiceableScalingEvent : EntityEventArgs
|
||||
{
|
||||
|
||||
public JuiceableScalingEvent()
|
||||
{
|
||||
Scalar = 1f;
|
||||
}
|
||||
|
||||
public float Scalar
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -115,6 +115,27 @@ namespace Content.Shared.Chemistry.Solution
|
||||
TotalVolume += quantity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scales the amount of solution.
|
||||
/// </summary>
|
||||
/// <param name="scale">The scalar to modify the solution by.</param>
|
||||
public void ScaleSolution(float scale)
|
||||
{
|
||||
if (scale == 1) return;
|
||||
var tempContents = new List<ReagentQuantity>(_contents);
|
||||
foreach(ReagentQuantity current in tempContents)
|
||||
{
|
||||
if(scale > 1)
|
||||
{
|
||||
AddReagent(current.ReagentId, current.Quantity * scale - current.Quantity);
|
||||
}
|
||||
else
|
||||
{
|
||||
RemoveReagent(current.ReagentId, current.Quantity - current.Quantity * scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the amount of a single reagent inside the solution.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user