* 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>
128 lines
4.1 KiB
C#
128 lines
4.1 KiB
C#
using System.Linq;
|
|
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.Shared.Chemistry;
|
|
using Content.Shared.GameObjects.Components.Body;
|
|
using Content.Shared.Interfaces;
|
|
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.IoC;
|
|
using Robust.Shared.Localization;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Serialization;
|
|
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!;
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
|
|
public override string Name => "Pill";
|
|
|
|
[ViewVariables]
|
|
private string _useSound;
|
|
[ViewVariables]
|
|
private string _trashPrototype;
|
|
[ViewVariables]
|
|
private SolutionContainerComponent _contents;
|
|
[ViewVariables]
|
|
private ReagentUnit _transferAmount;
|
|
|
|
|
|
public override void ExposeData(ObjectSerializer serializer)
|
|
{
|
|
base.ExposeData(serializer);
|
|
serializer.DataField(ref _useSound, "useSound", null);
|
|
serializer.DataField(ref _transferAmount, "transferAmount", ReagentUnit.New(1000));
|
|
serializer.DataField(ref _trashPrototype, "trash", null);
|
|
}
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
Owner.EnsureComponentWarn(out _contents);
|
|
}
|
|
|
|
bool IUse.UseEntity(UseEntityEventArgs eventArgs)
|
|
{
|
|
return TryUseFood(eventArgs.User, null);
|
|
}
|
|
|
|
// Feeding someone else
|
|
public async Task AfterInteract(AfterInteractEventArgs eventArgs)
|
|
{
|
|
if (eventArgs.Target == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
TryUseFood(eventArgs.User, eventArgs.Target);
|
|
}
|
|
|
|
public override bool TryUseFood(IEntity user, IEntity target, UtensilComponent utensilUsed = null)
|
|
{
|
|
if (user == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var trueTarget = target ?? user;
|
|
|
|
if (!trueTarget.TryGetComponent(out IBody body) ||
|
|
!body.TryGetMechanismBehaviors<StomachBehavior>(out var stomachs))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (!user.InRangeUnobstructed(trueTarget, popup: true))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var transferAmount = ReagentUnit.Min(_transferAmount, _contents.CurrentVolume);
|
|
var split = _contents.SplitSolution(transferAmount);
|
|
|
|
var firstStomach = stomachs.FirstOrDefault(stomach => stomach.CanTransferSolution(split));
|
|
|
|
if (firstStomach == null)
|
|
{
|
|
_contents.TryAddSolution(split);
|
|
trueTarget.PopupMessage(user, Loc.GetString("You can't eat any more!"));
|
|
return false;
|
|
}
|
|
|
|
// TODO: Account for partial transfer.
|
|
|
|
foreach (var (reagentId, quantity) in split.Contents)
|
|
{
|
|
if (!_prototypeManager.TryIndex(reagentId, out ReagentPrototype reagent)) continue;
|
|
split.RemoveReagent(reagentId, reagent.ReactionEntity(trueTarget, ReactionMethod.Ingestion, quantity));
|
|
}
|
|
|
|
firstStomach.TryTransferSolution(split);
|
|
|
|
if (_useSound != null)
|
|
{
|
|
_entitySystem.GetEntitySystem<AudioSystem>()
|
|
.PlayFromEntity(_useSound, trueTarget, AudioParams.Default.WithVolume(-1f));
|
|
}
|
|
|
|
trueTarget.PopupMessage(user, Loc.GetString("You swallow the pill."));
|
|
|
|
Owner.Delete();
|
|
return true;
|
|
}
|
|
}
|
|
}
|