Add kitchen knife & sliceable foods (#2891)

* sliceable food, kitchen knives

* sprite fixes, sounds

* add to vendor

* address reviews

* address reviews

* stereo -> mono

* fix wrong amount of nutriment being removed

* oops im dumb

* meta.json

* fix merge

* probably fix test

* remove all instances of [ComponentReference(typeof(IAfterInteract))]

Co-authored-by: cyclowns <cyclowns@protonmail.ch>
This commit is contained in:
mirrorcult
2021-01-06 18:48:08 -07:00
committed by GitHub
parent a7c4571075
commit 7977992e5a
63 changed files with 597 additions and 301 deletions

View File

@@ -2,7 +2,7 @@
using System.Threading.Tasks;
using Content.Server.GameObjects.Components.Body.Behavior;
using Content.Server.GameObjects.Components.Nutrition;
using Content.Server.GameObjects.Components.Utensil;
using Content.Server.GameObjects.Components.Culinary;
using Content.Shared.Chemistry;
using Content.Shared.GameObjects.Components.Body;
using Content.Shared.Interfaces;
@@ -21,7 +21,6 @@ using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Chemistry
{
[RegisterComponent]
[ComponentReference(typeof(IAfterInteract))]
public class PillComponent : FoodComponent, IUse, IAfterInteract
{
[Dependency] private readonly IEntitySystemManager _entitySystem = default!;

View File

@@ -0,0 +1,92 @@
using System.Threading.Tasks;
using Content.Shared.Chemistry;
using Content.Shared.Interfaces.GameObjects.Components;
using Content.Shared.GameObjects.EntitySystems;
using Content.Server.GameObjects.Components.Nutrition;
using Content.Server.GameObjects.Components.Chemistry;
using Content.Server.GameObjects.Components.GUI;
using Content.Server.GameObjects.Components.Items.Storage;
using Robust.Server.GameObjects.EntitySystems;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.GameObjects;
using Robust.Shared.Containers;
using Robust.Shared.Serialization;
using Robust.Shared.Localization;
using Robust.Shared.ViewVariables;
using Robust.Shared.Utility;
using Robust.Shared.Audio;
namespace Content.Server.GameObjects.Components.Culinary
{
[RegisterComponent]
class SliceableFoodComponent : Component, IInteractUsing, IExamine
{
public override string Name => "SliceableFood";
int IInteractUsing.Priority => 1; // take priority over eating with utensils
[ViewVariables(VVAccess.ReadWrite)] private string _slice;
private ushort _totalCount;
[ViewVariables(VVAccess.ReadWrite)] private string _sound;
[ViewVariables(VVAccess.ReadWrite)] public ushort Count;
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataField(ref _slice, "slice", string.Empty);
serializer.DataField(ref _sound, "sound", "/Audio/Items/Culinary/chop.ogg");
serializer.DataField<ushort>(ref _totalCount, "count", 5);
}
public override void Initialize()
{
base.Initialize();
Count = _totalCount;
Owner.EnsureComponent<FoodComponent>();
Owner.EnsureComponent<SolutionContainerComponent>();
}
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
{
if (string.IsNullOrEmpty(_slice))
{
return false;
}
if (!Owner.TryGetComponent(out SolutionContainerComponent solution))
{
return false;
}
if (!eventArgs.Using.TryGetComponent(out UtensilComponent utensil) || !utensil.HasType(UtensilType.Knife))
{
return false;
}
var itemToSpawn = Owner.EntityManager.SpawnEntity(_slice, Owner.Transform.Coordinates);
if (eventArgs.User.TryGetComponent(out HandsComponent handsComponent))
{
if (ContainerHelpers.IsInContainer(Owner))
{
handsComponent.PutInHandOrDrop(itemToSpawn.GetComponent<ItemComponent>());
}
}
EntitySystem.Get<AudioSystem>().PlayAtCoords(_sound, Owner.Transform.Coordinates,
AudioParams.Default.WithVolume(-2));
Count--;
if (Count < 1)
{
Owner.Delete();
return true;
}
solution.TryRemoveReagent("chem.Nutriment", solution.CurrentVolume / ReagentUnit.New(Count + 1));
return true;
}
public void Examine(FormattedMessage message, bool inDetailsRange)
{
message.AddMarkup(Loc.GetString($"There are { Count } slices remaining."));
}
}
}

View File

@@ -16,7 +16,7 @@ using Robust.Shared.Random;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Utensil
namespace Content.Server.GameObjects.Components.Culinary
{
[RegisterComponent]
public class UtensilComponent : Component, IAfterInteract

View File

@@ -30,7 +30,6 @@ using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Nutrition
{
[RegisterComponent]
[ComponentReference(typeof(IAfterInteract))]
public class DrinkComponent : Component, IUse, IAfterInteract, ISolutionChange, IExamine, ILand
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;

View File

@@ -7,7 +7,7 @@ using Content.Server.GameObjects.Components.Body.Behavior;
using Content.Server.GameObjects.Components.Chemistry;
using Content.Server.GameObjects.Components.GUI;
using Content.Server.GameObjects.Components.Items.Storage;
using Content.Server.GameObjects.Components.Utensil;
using Content.Server.GameObjects.Components.Culinary;
using Content.Shared.Chemistry;
using Content.Shared.GameObjects.Components.Body;
using Content.Shared.Interfaces;
@@ -26,7 +26,6 @@ using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Nutrition
{
[RegisterComponent]
[ComponentReference(typeof(IAfterInteract))]
public class FoodComponent : Component, IUse, IAfterInteract
{
[Dependency] private readonly IEntitySystemManager _entitySystem = default!;

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using Content.Server.GameObjects.EntitySystems;
@@ -65,7 +65,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
serializer.DataField(this, x => x.Arc, "arc", "default");
serializer.DataField(this, x => x.ClickArc, "clickArc", "punch");
serializer.DataField(this, x => x._hitSound, "hitSound", "/Audio/Weapons/genhit1.ogg");
serializer.DataField(this, x => x._missSound, "hitSound", "/Audio/Weapons/punchmiss.ogg");
serializer.DataField(this, x => x._missSound, "missSound", "/Audio/Weapons/punchmiss.ogg");
serializer.DataField(this, x => x.ArcCooldownTime, "arcCooldownTime", 1f);
serializer.DataField(this, x => x.CooldownTime, "cooldownTime", 1f);
serializer.DataField(this, x => x.DamageType, "damageType", DamageType.Blunt);