* Async Interface * Update Content.Server/GameObjects/Components/Fluids/MopComponent.cs Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com> * Changed the glassbeaker * Update Content.Shared/Interfaces/GameObjects/Components/Interaction/IAfterInteract.cs Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com> * Update Content.Shared/Interfaces/GameObjects/Components/Interaction/IAfterInteract.cs Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com> * Interaction system fix * Removed I from the interface * Changed all implementations of the interface I could find * all public void implementation fixed * All built, no errors should remain * Update Resources/Prototypes/Entities/Objects/Specific/chemistry.yml Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Update Content.Server/GameObjects/Components/Portal/TeleporterComponent.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Update Content.Server/GameObjects/Components/ActionBlocking/HandcuffComponent.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Commit based off Sloth's commentary * Removed the Rag file from the PR * Reverted sloth's commentary changes on the publcity of the function * Injector component properly implemented interface * Update Content.Server/GameObjects/Components/Fluids/MopComponent.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Update Content.Server/GameObjects/Components/Fluids/SprayComponent.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: BlueberryShortcake <rubetskoy234@mail.ru> Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
134 lines
3.7 KiB
C#
134 lines
3.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Content.Server.GameObjects.Components.Nutrition;
|
|
using Content.Shared.GameObjects.Components.Utensil;
|
|
using Content.Shared.Interfaces.GameObjects.Components;
|
|
using Content.Shared.Utility;
|
|
using Robust.Server.GameObjects.EntitySystems;
|
|
using Robust.Shared.Audio;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.Interfaces.GameObjects;
|
|
using Robust.Shared.Interfaces.Random;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Random;
|
|
using Robust.Shared.Serialization;
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
namespace Content.Server.GameObjects.Components.Utensil
|
|
{
|
|
[RegisterComponent]
|
|
public class UtensilComponent : SharedUtensilComponent, IAfterInteract
|
|
{
|
|
[Dependency] private readonly IEntitySystemManager _entitySystem = default!;
|
|
[Dependency] private readonly IRobustRandom _random = default!;
|
|
|
|
protected UtensilType _types = UtensilType.None;
|
|
|
|
[ViewVariables]
|
|
public override UtensilType Types
|
|
{
|
|
get => _types;
|
|
set
|
|
{
|
|
_types = value;
|
|
Dirty();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// The chance that the utensil has to break with each use.
|
|
/// A value of 0 means that it is unbreakable.
|
|
/// </summary>
|
|
[ViewVariables]
|
|
private float _breakChance;
|
|
|
|
/// <summary>
|
|
/// The sound to be played if the utensil breaks.
|
|
/// </summary>
|
|
[ViewVariables]
|
|
private string _breakSound;
|
|
|
|
public void AddType(UtensilType type)
|
|
{
|
|
Types |= type;
|
|
}
|
|
|
|
public bool HasAnyType(UtensilType type)
|
|
{
|
|
return (_types & type) != UtensilType.None;
|
|
}
|
|
|
|
public bool HasType(UtensilType type)
|
|
{
|
|
return _types.HasFlag(type);
|
|
}
|
|
|
|
public void RemoveType(UtensilType type)
|
|
{
|
|
Types &= ~type;
|
|
}
|
|
|
|
internal void TryBreak(IEntity user)
|
|
{
|
|
if (_random.Prob(_breakChance))
|
|
{
|
|
_entitySystem.GetEntitySystem<AudioSystem>()
|
|
.PlayFromEntity(_breakSound, user, AudioParams.Default.WithVolume(-2f));
|
|
Owner.Delete();
|
|
}
|
|
}
|
|
|
|
public override void ExposeData(ObjectSerializer serializer)
|
|
{
|
|
base.ExposeData(serializer);
|
|
|
|
serializer.DataReadWriteFunction("types",
|
|
new List<UtensilType>(),
|
|
types => types.ForEach(AddType),
|
|
() =>
|
|
{
|
|
var types = new List<UtensilType>();
|
|
|
|
foreach (UtensilType type in Enum.GetValues(typeof(UtensilType)))
|
|
{
|
|
if ((Types & type) != 0)
|
|
{
|
|
types.Add(type);
|
|
}
|
|
}
|
|
|
|
return types;
|
|
});
|
|
|
|
serializer.DataField(ref _breakChance, "breakChance", 0);
|
|
serializer.DataField(ref _breakSound, "breakSound", "/Audio/Items/snap.ogg");
|
|
}
|
|
|
|
async Task IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
|
|
{
|
|
TryUseUtensil(eventArgs.User, eventArgs.Target);
|
|
}
|
|
|
|
private void TryUseUtensil(IEntity user, IEntity target)
|
|
{
|
|
if (user == null || target == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!target.TryGetComponent(out FoodComponent food))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!user.InRangeUnobstructed(target, popup: true))
|
|
{
|
|
return;
|
|
}
|
|
|
|
food.TryUseFood(user, null, this);
|
|
}
|
|
}
|
|
}
|