diff --git a/Content.Client/Entry/IgnoredComponents.cs b/Content.Client/Entry/IgnoredComponents.cs index 388c56ae43..aa99a0c508 100644 --- a/Content.Client/Entry/IgnoredComponents.cs +++ b/Content.Client/Entry/IgnoredComponents.cs @@ -119,7 +119,6 @@ namespace Content.Client.Entry "Flash", "DamageOnToolInteract", "TrashSpawner", - "Pill", "RCD", "RCDDeconstructWhitelist", "RCDAmmo", diff --git a/Content.Server/Chemistry/Components/PillComponent.cs b/Content.Server/Chemistry/Components/PillComponent.cs deleted file mode 100644 index f3be401e3b..0000000000 --- a/Content.Server/Chemistry/Components/PillComponent.cs +++ /dev/null @@ -1,110 +0,0 @@ -using System.Linq; -using System.Threading.Tasks; -using Content.Server.Body.Behavior; -using Content.Server.Nutrition.Components; -using Content.Shared.Body.Components; -using Content.Shared.Chemistry.Reagent; -using Content.Shared.Interaction; -using Content.Shared.Interaction.Helpers; -using Content.Shared.Notification.Managers; -using Content.Shared.Sound; -using Robust.Shared.Audio; -using Robust.Shared.GameObjects; -using Robust.Shared.Localization; -using Robust.Shared.Player; -using Robust.Shared.Serialization.Manager.Attributes; -using Robust.Shared.ViewVariables; - -namespace Content.Server.Chemistry.Components -{ - [RegisterComponent] - public class PillComponent : FoodComponent, IUse, IAfterInteract - { - public override string Name => "Pill"; - - [ViewVariables] - [DataField("useSound", required: true)] - protected override SoundSpecifier UseSound { get; set; } = default!; - - [ViewVariables] - [DataField("trash")] - protected override string? TrashPrototype { get; set; } = default; - - [ViewVariables] - [DataField("transferAmount")] - protected override ReagentUnit TransferAmount { get; set; } = ReagentUnit.New(1000); - - [ViewVariables] - private SolutionContainerComponent _contents = default!; - - protected override void Initialize() - { - base.Initialize(); - - Owner.EnsureComponentWarn(out _contents); - } - - bool IUse.UseEntity(UseEntityEventArgs eventArgs) - { - return TryUseFood(eventArgs.User, null); - } - - // Feeding someone else - async Task IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs) - { - if (eventArgs.Target == null) - { - return false; - } - - TryUseFood(eventArgs.User, eventArgs.Target); - return true; - } - - public override bool TryUseFood(IEntity? user, IEntity? target, UtensilComponent? utensilUsed = null) - { - if (user == null) - { - return false; - } - - var trueTarget = target ?? user; - - if (!trueTarget.TryGetComponent(out SharedBodyComponent? body) || - !body.TryGetMechanismBehaviors(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("pill-component-cannot-eat-more-message")); - return false; - } - - // TODO: Account for partial transfer. - - split.DoEntityReaction(trueTarget, ReactionMethod.Ingestion); - - firstStomach.TryTransferSolution(split); - - SoundSystem.Play(Filter.Pvs(trueTarget), UseSound.GetSound(), trueTarget, AudioParams.Default.WithVolume(-1f)); - - trueTarget.PopupMessage(user, Loc.GetString("pill-component-swallow-success-message")); - - Owner.QueueDelete(); - return true; - } - } -} diff --git a/Content.Server/Nutrition/Components/FoodComponent.cs b/Content.Server/Nutrition/Components/FoodComponent.cs index 08c9cdbad6..fd88da5117 100644 --- a/Content.Server/Nutrition/Components/FoodComponent.cs +++ b/Content.Server/Nutrition/Components/FoodComponent.cs @@ -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))] protected virtual string? TrashPrototype { get; set; } + [ViewVariables] + [DataField("trash", customTypeSerializer: typeof(PrototypeIdSerializer))] + 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; } } } diff --git a/Resources/Locale/en-US/chemistry/components/pill-component.ftl b/Resources/Locale/en-US/chemistry/components/pill-component.ftl deleted file mode 100644 index 6640e9191a..0000000000 --- a/Resources/Locale/en-US/chemistry/components/pill-component.ftl +++ /dev/null @@ -1,4 +0,0 @@ -## Entity - -pill-component-cannot-eat-more-message = You can't eat any more! -pill-component-swallow-success-message = You swallow the pill. \ No newline at end of file diff --git a/Resources/Locale/en-US/nutrition/components/food-component.ftl b/Resources/Locale/en-US/nutrition/components/food-component.ftl index a68cb3c7b3..1ea007e735 100644 --- a/Resources/Locale/en-US/nutrition/components/food-component.ftl +++ b/Resources/Locale/en-US/nutrition/components/food-component.ftl @@ -9,6 +9,7 @@ food-you-need-to-hold-utensil = You need to be holding a {$utensil} to eat that! food-you-cannot-eat-any-more = You can't eat any more! food-nom = Nom +food-swallow = You swallow the {$food}. ## Entity diff --git a/Resources/Prototypes/Entities/Clothing/Belt/belts.yml b/Resources/Prototypes/Entities/Clothing/Belt/belts.yml index 478c7153f8..46c6baa8f7 100644 --- a/Resources/Prototypes/Entities/Clothing/Belt/belts.yml +++ b/Resources/Prototypes/Entities/Clothing/Belt/belts.yml @@ -236,9 +236,9 @@ - Gauze - Ointment - CigPack + - Pill components: - Hypospray - - Pill - SurgeryTool - Radio - type: ItemCounter @@ -253,7 +253,7 @@ - Hypospray pill: whitelist: - components: + tags: - Pill bottle_spray: whitelist: diff --git a/Resources/Prototypes/Entities/Objects/Specific/chemistry.yml b/Resources/Prototypes/Entities/Objects/Specific/chemistry.yml index bc10f23e37..aa73f2aeca 100644 --- a/Resources/Prototypes/Entities/Objects/Specific/chemistry.yml +++ b/Resources/Prototypes/Entities/Objects/Specific/chemistry.yml @@ -187,7 +187,12 @@ - type: Sprite sprite: Objects/Specific/Chemistry/pills.rsi state: pill - - type: Pill + - type: Tag + tags: + - Pill + - type: Food + transferAmount: null + eatMessage: food-swallow - type: SolutionContainer maxVol: 50 caps: None diff --git a/Resources/Prototypes/tags.yml b/Resources/Prototypes/tags.yml index 856715a2fd..616a6c9f43 100644 --- a/Resources/Prototypes/tags.yml +++ b/Resources/Prototypes/tags.yml @@ -142,6 +142,9 @@ - type: Tag id: Ore +- type: Tag + id: Pill + - type: Tag id: Pizza