Utensils changes (#2929)

* Utensils changes

* Burn it all

Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
This commit is contained in:
metalgearsloth
2021-01-06 22:49:19 +11:00
committed by GitHub
parent 258ae55441
commit 2bd4bf12a4
3 changed files with 24 additions and 42 deletions

View File

@@ -10,9 +10,6 @@ using Content.Server.GameObjects.Components.Items.Storage;
using Content.Server.GameObjects.Components.Utensil; using Content.Server.GameObjects.Components.Utensil;
using Content.Shared.Chemistry; using Content.Shared.Chemistry;
using Content.Shared.GameObjects.Components.Body; using Content.Shared.GameObjects.Components.Body;
using Content.Shared.GameObjects.Components.Body.Behavior;
using Content.Shared.GameObjects.Components.Body.Mechanism;
using Content.Shared.GameObjects.Components.Utensil;
using Content.Shared.Interfaces; using Content.Shared.Interfaces;
using Content.Shared.Interfaces.GameObjects.Components; using Content.Shared.Interfaces.GameObjects.Components;
using Content.Shared.Utility; using Content.Shared.Utility;

View File

@@ -1,13 +1,14 @@
using System; #nullable enable
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Content.Server.GameObjects.Components.Nutrition; using Content.Server.GameObjects.Components.Nutrition;
using Content.Shared.GameObjects.Components.Utensil;
using Content.Shared.Interfaces.GameObjects.Components; using Content.Shared.Interfaces.GameObjects.Components;
using Content.Shared.Utility; using Content.Shared.Utility;
using Robust.Server.GameObjects.EntitySystems; using Robust.Server.GameObjects.EntitySystems;
using Robust.Shared.Audio; using Robust.Shared.Audio;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Random; using Robust.Shared.Interfaces.Random;
using Robust.Shared.IoC; using Robust.Shared.IoC;
@@ -18,21 +19,22 @@ using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Utensil namespace Content.Server.GameObjects.Components.Utensil
{ {
[RegisterComponent] [RegisterComponent]
public class UtensilComponent : SharedUtensilComponent, IAfterInteract public class UtensilComponent : Component, IAfterInteract
{ {
[Dependency] private readonly IEntitySystemManager _entitySystem = default!; public override string Name => "Utensil";
[Dependency] private readonly IRobustRandom _random = default!;
protected UtensilType _types = UtensilType.None; private UtensilType _types = UtensilType.None;
[ViewVariables] [ViewVariables]
public override UtensilType Types public UtensilType Types
{ {
get => _types; get => _types;
set set
{ {
if (_types.Equals(value))
return;
_types = value; _types = value;
Dirty();
} }
} }
@@ -47,7 +49,7 @@ namespace Content.Server.GameObjects.Components.Utensil
/// The sound to be played if the utensil breaks. /// The sound to be played if the utensil breaks.
/// </summary> /// </summary>
[ViewVariables] [ViewVariables]
private string _breakSound; private string? _breakSound;
public void AddType(UtensilType type) public void AddType(UtensilType type)
{ {
@@ -61,7 +63,7 @@ namespace Content.Server.GameObjects.Components.Utensil
public bool HasType(UtensilType type) public bool HasType(UtensilType type)
{ {
return _types.HasFlag(type); return (_types & type) != 0;
} }
public void RemoveType(UtensilType type) public void RemoveType(UtensilType type)
@@ -71,9 +73,9 @@ namespace Content.Server.GameObjects.Components.Utensil
internal void TryBreak(IEntity user) internal void TryBreak(IEntity user)
{ {
if (_random.Prob(_breakChance)) if (_breakSound != null && IoCManager.Resolve<IRobustRandom>().Prob(_breakChance))
{ {
_entitySystem.GetEntitySystem<AudioSystem>() EntitySystem.Get<AudioSystem>()
.PlayFromEntity(_breakSound, user, AudioParams.Default.WithVolume(-2f)); .PlayFromEntity(_breakSound, user, AudioParams.Default.WithVolume(-2f));
Owner.Delete(); Owner.Delete();
} }
@@ -112,12 +114,7 @@ namespace Content.Server.GameObjects.Components.Utensil
private void TryUseUtensil(IEntity user, IEntity target) private void TryUseUtensil(IEntity user, IEntity target)
{ {
if (user == null || target == null) if (!target.TryGetComponent(out FoodComponent? food))
{
return;
}
if (!target.TryGetComponent(out FoodComponent food))
{ {
return; return;
} }
@@ -130,4 +127,13 @@ namespace Content.Server.GameObjects.Components.Utensil
food.TryUseFood(user, null, this); food.TryUseFood(user, null, this);
} }
} }
[Flags]
public enum UtensilType : byte
{
None = 0,
Fork = 1,
Spoon = 1 << 1,
Knife = 1 << 2
}
} }

View File

@@ -1,21 +0,0 @@
using System;
using Robust.Shared.GameObjects;
namespace Content.Shared.GameObjects.Components.Utensil
{
[Flags]
public enum UtensilType : byte
{
None = 0,
Fork = 1,
Spoon = 1 << 1,
Knife = 1 << 2
}
public class SharedUtensilComponent : Component
{
public override string Name => "Utensil";
public virtual UtensilType Types { get; set; }
}
}