magic bread wand (#17044)
Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Content.Server.Chemistry.Components.SolutionManager;
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Server.Nutrition;
|
||||
using Content.Server.Nutrition.Components;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Examine;
|
||||
@@ -51,12 +52,12 @@ namespace Content.Server.Nutrition.EntitySystems
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!EntityManager.TryGetComponent(usedItem, out UtensilComponent ? utensil) || (utensil.Types & UtensilType.Knife) == 0)
|
||||
if (!TryComp<UtensilComponent>(usedItem, out var utensil) || (utensil.Types & UtensilType.Knife) == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var sliceUid = EntityManager.SpawnEntity(component.Slice, transform.Coordinates);
|
||||
var sliceUid = Spawn(component.Slice, transform.Coordinates);
|
||||
|
||||
var lostSolution = _solutionContainerSystem.SplitSolution(uid, solution,
|
||||
solution.Volume / FixedPoint2.New(component.Count));
|
||||
@@ -91,7 +92,7 @@ namespace Content.Server.Nutrition.EntitySystems
|
||||
// If someone makes food proto with 1 slice...
|
||||
if (component.Count < 1)
|
||||
{
|
||||
EntityManager.DeleteEntity(uid);
|
||||
DeleteFood(uid, user);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -99,7 +100,7 @@ namespace Content.Server.Nutrition.EntitySystems
|
||||
if (component.Count > 1)
|
||||
return true;
|
||||
|
||||
sliceUid = EntityManager.SpawnEntity(component.Slice, transform.Coordinates);
|
||||
sliceUid = Spawn(component.Slice, transform.Coordinates);
|
||||
|
||||
// Fill last slice with the rest of the solution
|
||||
FillSlice(sliceUid, solution);
|
||||
@@ -115,14 +116,26 @@ namespace Content.Server.Nutrition.EntitySystems
|
||||
xform.LocalRotation = 0;
|
||||
}
|
||||
|
||||
EntityManager.DeleteEntity(uid);
|
||||
DeleteFood(uid, user);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void DeleteFood(EntityUid uid, EntityUid user)
|
||||
{
|
||||
var ev = new BeforeFullySlicedEvent
|
||||
{
|
||||
User = user
|
||||
};
|
||||
RaiseLocalEvent(uid, ev);
|
||||
|
||||
if (!ev.Cancelled)
|
||||
Del(uid);
|
||||
}
|
||||
|
||||
private void FillSlice(EntityUid sliceUid, Solution solution)
|
||||
{
|
||||
// Replace all reagents on prototype not just copying poisons (example: slices of eaten pizza should have less nutrition)
|
||||
if (EntityManager.TryGetComponent<FoodComponent>(sliceUid, out var sliceFoodComp) &&
|
||||
if (TryComp<FoodComponent>(sliceUid, out var sliceFoodComp) &&
|
||||
_solutionContainerSystem.TryGetSolution(sliceUid, sliceFoodComp.SolutionName, out var itsSolution))
|
||||
{
|
||||
_solutionContainerSystem.RemoveAllSolution(sliceUid, itsSolution);
|
||||
@@ -135,9 +148,9 @@ namespace Content.Server.Nutrition.EntitySystems
|
||||
private void OnComponentStartup(EntityUid uid, SliceableFoodComponent component, ComponentStartup args)
|
||||
{
|
||||
component.Count = component.TotalCount;
|
||||
var foodComp = EntityManager.EnsureComponent<FoodComponent>(uid);
|
||||
var foodComp = EnsureComp<FoodComponent>(uid);
|
||||
|
||||
EntityManager.EnsureComponent<SolutionContainerManagerComponent>(uid);
|
||||
EnsureComp<SolutionContainerManagerComponent>(uid);
|
||||
_solutionContainerSystem.EnsureSolution(uid, foodComp.SolutionName);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user