using Content.Server.Nutrition.EntitySystems;
using Robust.Shared.Audio;
+using Robust.Shared.Prototypes;
-namespace Content.Server.Nutrition.Components
+namespace Content.Server.Nutrition.Components;
+
+[RegisterComponent, Access(typeof(SliceableFoodSystem))]
+public sealed partial class SliceableFoodComponent : Component
{
- [RegisterComponent, Access(typeof(SliceableFoodSystem))]
- internal sealed partial class SliceableFoodComponent : Component
- {
- [DataField("slice")]
- [ViewVariables(VVAccess.ReadWrite)]
- public string Slice = string.Empty;
+ /// <summary>
+ /// Prototype to spawn after slicing.
+ /// If null then it can't be sliced.
+ /// </summary>
+ [DataField, ViewVariables(VVAccess.ReadWrite)]
+ public EntProtoId? Slice;
- [DataField("sound")]
- [ViewVariables(VVAccess.ReadWrite)]
- public SoundSpecifier Sound = new SoundPathSpecifier("/Audio/Items/Culinary/chop.ogg");
+ [DataField, ViewVariables(VVAccess.ReadWrite)]
+ public SoundSpecifier Sound = new SoundPathSpecifier("/Audio/Items/Culinary/chop.ogg");
- [DataField("count")]
- [ViewVariables(VVAccess.ReadWrite)]
- public ushort TotalCount = 5;
+ /// <summary>
+ /// Number of slices the food starts with.
+ /// </summary>
+ [DataField("count"), ViewVariables(VVAccess.ReadWrite)]
+ public ushort TotalCount = 5;
- [ViewVariables(VVAccess.ReadWrite)]
- public ushort Count;
- }
+ /// <summary>
+ /// Number of slices left.
+ /// </summary>
+ [ViewVariables(VVAccess.ReadWrite)]
+ public ushort Count;
}
return false;
}
- var sliceUid = Spawn(component.Slice, transform.Coordinates);
+ var sliceUid = Slice(uid, user, component, transform);
var lostSolution = _solutionContainerSystem.SplitSolution(uid, solution,
solution.Volume / FixedPoint2.New(component.Count));
// Fill new slice
FillSlice(sliceUid, lostSolution);
- var inCont = _containerSystem.IsEntityInContainer(component.Owner);
- if (inCont)
- {
- _handsSystem.PickupOrDrop(user, sliceUid);
- }
- else
- {
- var xform = Transform(sliceUid);
- _containerSystem.AttachParentToContainerOrGrid((sliceUid, xform));
- xform.LocalRotation = 0;
- }
-
_audio.PlayPvs(component.Sound, transform.Coordinates, AudioParams.Default.WithVolume(-2));
// Decrease size of item based on count - Could implement in the future
if (component.Count > 1)
return true;
- sliceUid = Spawn(component.Slice, transform.Coordinates);
+ sliceUid = Slice(uid, user, component, transform);
// Fill last slice with the rest of the solution
FillSlice(sliceUid, solution);
+ DeleteFood(uid, user);
+ return true;
+ }
+
+ /// <summary>
+ /// Create a new slice in the world and returns its entity.
+ /// The solutions must be set afterwards.
+ /// </summary>
+ public EntityUid Slice(EntityUid uid, EntityUid user, SliceableFoodComponent? comp = null, TransformComponent? transform = null)
+ {
+ if (!Resolve(uid, ref comp, ref transform))
+ return EntityUid.Invalid;
+
+ var sliceUid = Spawn(comp.Slice, transform.Coordinates);
+ var inCont = _containerSystem.IsEntityInContainer(uid);
if (inCont)
{
_handsSystem.PickupOrDrop(user, sliceUid);
xform.LocalRotation = 0;
}
- DeleteFood(uid, user);
- return true;
+ return sliceUid;
}
private void DeleteFood(EntityUid uid, EntityUid user)