Remove pillcomponent (#4469)

* Remove PillComponent

* Make food without any solution left delete and create trash

* Replace PillComponent references with a Pill tag

* Clean up

* Add swallow message to food

* Change to eatMessage override

* Change FoodComponent transferAmount to nullable

* Change properties to private
This commit is contained in:
ShadowCommander
2021-08-17 14:11:07 -07:00
committed by GitHub
parent 13a214e4a0
commit d908684f09
8 changed files with 42 additions and 129 deletions

View File

@@ -10,7 +10,6 @@ using Content.Shared.Body.Components;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Helpers;
using Content.Shared.Notification;
using Content.Shared.Notification.Managers;
using Content.Shared.Sound;
using Robust.Shared.Audio;
@@ -30,13 +29,23 @@ namespace Content.Server.Nutrition.Components
{
public override string Name => "Food";
[ViewVariables] [DataField("useSound")] protected virtual SoundSpecifier UseSound { get; set; } = new SoundPathSpecifier("/Audio/Items/eatfood.ogg");
[ViewVariables]
[DataField("useSound")]
private SoundSpecifier UseSound { get; set; } = new SoundPathSpecifier("/Audio/Items/eatfood.ogg");
[ViewVariables] [DataField("trash", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))] protected virtual string? TrashPrototype { get; set; }
[ViewVariables]
[DataField("trash", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
private string? TrashPrototype { get; set; }
[ViewVariables] [DataField("transferAmount")] protected virtual ReagentUnit TransferAmount { get; set; } = ReagentUnit.New(5);
[ViewVariables]
[DataField("transferAmount")]
private ReagentUnit? TransferAmount { get; set; } = ReagentUnit.New(5);
[DataField("utensilsNeeded")] private UtensilType _utensilsNeeded = UtensilType.None;
[DataField("utensilsNeeded")]
private UtensilType _utensilsNeeded = UtensilType.None;
[DataField("eatMessage")]
private string _eatMessage = "food-nom";
[ViewVariables]
public int UsesRemaining
@@ -48,9 +57,12 @@ namespace Content.Server.Nutrition.Components
return 0;
}
if (TransferAmount == null)
return solution.CurrentVolume == 0 ? 0 : 1;
return solution.CurrentVolume == 0
? 0
: Math.Max(1, (int) Math.Ceiling((solution.CurrentVolume / TransferAmount).Float()));
: Math.Max(1, (int) Math.Ceiling((solution.CurrentVolume / (ReagentUnit)TransferAmount).Float()));
}
}
@@ -83,7 +95,7 @@ namespace Content.Server.Nutrition.Components
return true;
}
public virtual bool TryUseFood(IEntity? user, IEntity? target, UtensilComponent? utensilUsed = null)
public bool TryUseFood(IEntity? user, IEntity? target, UtensilComponent? utensilUsed = null)
{
if (!Owner.TryGetComponent(out SolutionContainerComponent? solution))
{
@@ -98,6 +110,7 @@ namespace Content.Server.Nutrition.Components
if (UsesRemaining <= 0)
{
user.PopupMessage(Loc.GetString("food-component-try-use-food-is-empty", ("entity", Owner)));
DeleteAndSpawnTrash(user);
return false;
}
@@ -144,12 +157,13 @@ namespace Content.Server.Nutrition.Components
return false;
}
var transferAmount = ReagentUnit.Min(TransferAmount, solution.CurrentVolume);
var transferAmount = TransferAmount != null ? ReagentUnit.Min((ReagentUnit)TransferAmount, solution.CurrentVolume) : solution.CurrentVolume;
var split = solution.SplitSolution(transferAmount);
var firstStomach = stomachs.FirstOrDefault(stomach => stomach.CanTransferSolution(split));
if (firstStomach == null)
{
solution.TryAddSolution(split);
trueTarget.PopupMessage(user, Loc.GetString("food-you-cannot-eat-any-more"));
return false;
}
@@ -162,7 +176,7 @@ namespace Content.Server.Nutrition.Components
SoundSystem.Play(Filter.Pvs(trueTarget), UseSound.GetSound(), trueTarget, AudioParams.Default.WithVolume(-1f));
trueTarget.PopupMessage(user, Loc.GetString("food-nom"));
trueTarget.PopupMessage(user, Loc.GetString(_eatMessage));
// If utensils were used
if (utensils != null)
@@ -184,6 +198,13 @@ namespace Content.Server.Nutrition.Components
return true;
}
DeleteAndSpawnTrash(user);
return true;
}
private void DeleteAndSpawnTrash(IEntity user)
{
//We're empty. Become trash.
var position = Owner.Transform.Coordinates;
var finisher = Owner.EntityManager.SpawnEntity(TrashPrototype, position);
@@ -205,8 +226,6 @@ namespace Content.Server.Nutrition.Components
{
Owner.Delete();
}
return true;
}
}
}