FoodComponent solution un-hardcoding, rehydratable solution name fixes, monkey cubes edible again, slicable food preserves poisons (#4942)

This commit is contained in:
20kdc
2021-10-19 08:13:43 +01:00
committed by GitHub
parent eae8ab96d8
commit 6c6bde8743
8 changed files with 38 additions and 14 deletions

View File

@@ -44,9 +44,9 @@ namespace Content.Server.Nutrition.Components
{
base.Initialize();
Count = _totalCount;
Owner.EnsureComponent<FoodComponent>();
var foodComp = Owner.EnsureComponent<FoodComponent>();
Owner.EnsureComponent<SolutionContainerManagerComponent>();
EntitySystem.Get<SolutionContainerSystem>().EnsureSolution(Owner, FoodComponent.SolutionName);
EntitySystem.Get<SolutionContainerSystem>().EnsureSolution(Owner, foodComp.SolutionName);
}
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
@@ -56,7 +56,9 @@ namespace Content.Server.Nutrition.Components
return false;
}
if (!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner, FoodComponent.SolutionName, out var solution))
var scs = EntitySystem.Get<SolutionContainerSystem>();
if (!Owner.TryGetComponent<FoodComponent>(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<FoodComponent>(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<SolutionContainerSystem>().TryRemoveReagent(Owner.Uid, solution, "Nutriment",
solution.CurrentVolume / ReagentUnit.New(Count + 1));
return true;
}