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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 42 additions and 129 deletions

View File

@ -119,7 +119,6 @@ namespace Content.Client.Entry
"Flash",
"DamageOnToolInteract",
"TrashSpawner",
"Pill",
"RCD",
"RCDDeconstructWhitelist",
"RCDAmmo",

View File

@ -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<bool> 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<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("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;
}
}
}

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;
}
}
}

View File

@ -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.

View File

@ -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

View File

@ -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:

View File

@ -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

View File

@ -142,6 +142,9 @@
- type: Tag
id: Ore
- type: Tag
id: Pill
- type: Tag
id: Pizza