From 6c6bde8743f467c5be6d1d70f135b2b1620a6113 Mon Sep 17 00:00:00 2001 From: 20kdc Date: Tue, 19 Oct 2021 08:13:43 +0100 Subject: [PATCH] FoodComponent solution un-hardcoding, rehydratable solution name fixes, monkey cubes edible again, slicable food preserves poisons (#4942) --- .../Nutrition/Food/FoodValueCon.cs | 4 +-- .../Botany/Components/PlantHolderComponent.cs | 4 ++- .../AddToSolutionReaction.cs | 5 +++- .../Nutrition/Components/FoodComponent.cs | 4 ++- .../Components/SliceableFoodComponent.cs | 26 ++++++++++++++----- .../Nutrition/EntitySystems/CreamPieSystem.cs | 2 +- .../Objects/Specific/rehydrateable.yml | 6 ++++- .../Prototypes/Entities/Structures/soil.yml | 1 + 8 files changed, 38 insertions(+), 14 deletions(-) diff --git a/Content.Server/AI/Utility/Considerations/Nutrition/Food/FoodValueCon.cs b/Content.Server/AI/Utility/Considerations/Nutrition/Food/FoodValueCon.cs index e6d5858c04..0607e684d8 100644 --- a/Content.Server/AI/Utility/Considerations/Nutrition/Food/FoodValueCon.cs +++ b/Content.Server/AI/Utility/Considerations/Nutrition/Food/FoodValueCon.cs @@ -12,8 +12,8 @@ namespace Content.Server.AI.Utility.Considerations.Nutrition.Food { var target = context.GetState().GetValue(); - if (target == null || target.Deleted || - !EntitySystem.Get().TryGetSolution(target, FoodComponent.SolutionName, out var food)) + if (target == null || target.Deleted || !target.TryGetComponent(out var foodComp) || + !EntitySystem.Get().TryGetSolution(target, foodComp.SolutionName, out var food)) { return 0.0f; } diff --git a/Content.Server/Botany/Components/PlantHolderComponent.cs b/Content.Server/Botany/Components/PlantHolderComponent.cs index 66c55131b9..9635ae24eb 100644 --- a/Content.Server/Botany/Components/PlantHolderComponent.cs +++ b/Content.Server/Botany/Components/PlantHolderComponent.cs @@ -37,7 +37,6 @@ namespace Content.Server.Botany.Components { public const float HydroponicsSpeedMultiplier = 1f; public const float HydroponicsConsumptionMultiplier = 4f; - private const string SoilSolutionName = "soil"; [Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly IPrototypeManager _prototypeManager = default!; @@ -120,6 +119,9 @@ namespace Content.Server.Botany.Components [ViewVariables(VVAccess.ReadWrite)] public bool ForceUpdate { get; set; } + [DataField("solution")] + public string SoilSolutionName { get; set; } = "soil"; + public void WeedInvasion() { // TODO diff --git a/Content.Server/Chemistry/ReagentEntityReactions/AddToSolutionReaction.cs b/Content.Server/Chemistry/ReagentEntityReactions/AddToSolutionReaction.cs index 37e68ffb35..bab1f09a85 100644 --- a/Content.Server/Chemistry/ReagentEntityReactions/AddToSolutionReaction.cs +++ b/Content.Server/Chemistry/ReagentEntityReactions/AddToSolutionReaction.cs @@ -12,6 +12,9 @@ namespace Content.Server.Chemistry.ReagentEntityReactions [UsedImplicitly] public class AddToSolutionReaction : ReagentEntityReaction { + [DataField("solution")] + private string _solution = "reagents"; + [DataField("reagents", true, customTypeSerializer: typeof(PrototypeIdHashSetSerializer))] // ReSharper disable once CollectionNeverUpdated.Local private readonly HashSet _reagents = new(); @@ -20,7 +23,7 @@ namespace Content.Server.Chemistry.ReagentEntityReactions { // TODO see if this is correct if (!EntitySystem.Get() - .TryGetSolution(entity, "reagents", out var solutionContainer) + .TryGetSolution(entity, _solution, out var solutionContainer) || (_reagents.Count > 0 && !_reagents.Contains(reagent.ID))) return; if (EntitySystem.Get() diff --git a/Content.Server/Nutrition/Components/FoodComponent.cs b/Content.Server/Nutrition/Components/FoodComponent.cs index 1df6c71852..50dc14a968 100644 --- a/Content.Server/Nutrition/Components/FoodComponent.cs +++ b/Content.Server/Nutrition/Components/FoodComponent.cs @@ -28,7 +28,9 @@ namespace Content.Server.Nutrition.Components public class FoodComponent : Component, IUse, IAfterInteract { public override string Name => "Food"; - public static string SolutionName = "food"; + + [DataField("solution")] + public string SolutionName { get; set; } = "food"; [ViewVariables] [DataField("useSound")] diff --git a/Content.Server/Nutrition/Components/SliceableFoodComponent.cs b/Content.Server/Nutrition/Components/SliceableFoodComponent.cs index 746b38cd7e..4b6be73b54 100644 --- a/Content.Server/Nutrition/Components/SliceableFoodComponent.cs +++ b/Content.Server/Nutrition/Components/SliceableFoodComponent.cs @@ -44,9 +44,9 @@ namespace Content.Server.Nutrition.Components { base.Initialize(); Count = _totalCount; - Owner.EnsureComponent(); + var foodComp = Owner.EnsureComponent(); Owner.EnsureComponent(); - EntitySystem.Get().EnsureSolution(Owner, FoodComponent.SolutionName); + EntitySystem.Get().EnsureSolution(Owner, foodComp.SolutionName); } async Task IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs) @@ -56,7 +56,9 @@ namespace Content.Server.Nutrition.Components return false; } - if (!EntitySystem.Get().TryGetSolution(Owner, FoodComponent.SolutionName, out var solution)) + var scs = EntitySystem.Get(); + + if (!Owner.TryGetComponent(out var foodComp) || !scs.TryGetSolution(Owner, foodComp.SolutionName, out var solution)) { return false; } @@ -67,6 +69,20 @@ namespace Content.Server.Nutrition.Components } var itemToSpawn = Owner.EntityManager.SpawnEntity(_slice, Owner.Transform.Coordinates); + // This is done this way so that... food additives (read: poisons) remain in the system. + // Basically, we want to: + // 1. Split off a representative chunk + var lostSolution = scs.SplitSolution(Owner.Uid, solution, + solution.CurrentVolume / ReagentUnit.New(Count)); + // 2. Delete the Nutriment (it's already in the target) so we just have additives + // It might be an idea to remove the removal of Nutriment & clear the food + lostSolution.RemoveReagent("Nutriment", lostSolution.GetReagentQuantity("Nutriment")); + // 3. Dump whatever we can into the slice + if (itemToSpawn.TryGetComponent(out var itsFoodComp) && scs.TryGetSolution(itemToSpawn, itsFoodComp.SolutionName, out var itsSolution)) + { + var lostSolutionPart = lostSolution.SplitSolution(itsSolution.AvailableVolume); + scs.TryAddSolution(itemToSpawn.Uid, itsSolution, lostSolutionPart); + } if (eventArgs.User.TryGetComponent(out HandsComponent? handsComponent)) { if (ContainerHelpers.IsInContainer(Owner)) @@ -82,11 +98,7 @@ namespace Content.Server.Nutrition.Components if (Count < 1) { Owner.Delete(); - return true; } - - EntitySystem.Get().TryRemoveReagent(Owner.Uid, solution, "Nutriment", - solution.CurrentVolume / ReagentUnit.New(Count + 1)); return true; } diff --git a/Content.Server/Nutrition/EntitySystems/CreamPieSystem.cs b/Content.Server/Nutrition/EntitySystems/CreamPieSystem.cs index 55ab60e0ff..e4e7531380 100644 --- a/Content.Server/Nutrition/EntitySystems/CreamPieSystem.cs +++ b/Content.Server/Nutrition/EntitySystems/CreamPieSystem.cs @@ -25,7 +25,7 @@ namespace Content.Server.Nutrition.EntitySystems { SoundSystem.Play(Filter.Pvs(creamPie.Owner), creamPie.Sound.GetSound(), creamPie.Owner, AudioHelpers.WithVariation(0.125f)); - if (_solutionsSystem.TryGetSolution(creamPie.Owner, FoodComponent.SolutionName, out var solution)) + if (creamPie.Owner.TryGetComponent(out var foodComp) && _solutionsSystem.TryGetSolution(creamPie.Owner, foodComp.SolutionName, out var solution)) { solution.SpillAt(creamPie.Owner, "PuddleSmear", false); } diff --git a/Resources/Prototypes/Entities/Objects/Specific/rehydrateable.yml b/Resources/Prototypes/Entities/Objects/Specific/rehydrateable.yml index ad38247c43..eec2db044b 100644 --- a/Resources/Prototypes/Entities/Objects/Specific/rehydrateable.yml +++ b/Resources/Prototypes/Entities/Objects/Specific/rehydrateable.yml @@ -11,6 +11,8 @@ reagents: - ReagentId: Nutriment Quantity: 10 + - type: Food + solution: cube - type: RefillableSolution solution: cube - type: Sprite @@ -19,6 +21,7 @@ - type: Reactive reactions: - !type:AddToSolutionReaction + solution: cube touch: true ingestion: true injection: true @@ -56,10 +59,11 @@ - ReagentId: Nutriment Quantity: 10 - type: RefillableSolution - solution: cube + solution: plushie - type: Reactive reactions: - !type:AddToSolutionReaction + solution: plushie touch: true ingestion: true injection: true diff --git a/Resources/Prototypes/Entities/Structures/soil.yml b/Resources/Prototypes/Entities/Structures/soil.yml index f6d8e15920..55bf07b60a 100644 --- a/Resources/Prototypes/Entities/Structures/soil.yml +++ b/Resources/Prototypes/Entities/Structures/soil.yml @@ -52,6 +52,7 @@ - type: Reactive reactions: - !type:AddToSolutionReaction + solution: soil - type: Appearance visuals: - type: PlantHolderVisualizer