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:
@@ -119,7 +119,6 @@ namespace Content.Client.Entry
|
|||||||
"Flash",
|
"Flash",
|
||||||
"DamageOnToolInteract",
|
"DamageOnToolInteract",
|
||||||
"TrashSpawner",
|
"TrashSpawner",
|
||||||
"Pill",
|
|
||||||
"RCD",
|
"RCD",
|
||||||
"RCDDeconstructWhitelist",
|
"RCDDeconstructWhitelist",
|
||||||
"RCDAmmo",
|
"RCDAmmo",
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -10,7 +10,6 @@ using Content.Shared.Body.Components;
|
|||||||
using Content.Shared.Chemistry.Reagent;
|
using Content.Shared.Chemistry.Reagent;
|
||||||
using Content.Shared.Interaction;
|
using Content.Shared.Interaction;
|
||||||
using Content.Shared.Interaction.Helpers;
|
using Content.Shared.Interaction.Helpers;
|
||||||
using Content.Shared.Notification;
|
|
||||||
using Content.Shared.Notification.Managers;
|
using Content.Shared.Notification.Managers;
|
||||||
using Content.Shared.Sound;
|
using Content.Shared.Sound;
|
||||||
using Robust.Shared.Audio;
|
using Robust.Shared.Audio;
|
||||||
@@ -30,13 +29,23 @@ namespace Content.Server.Nutrition.Components
|
|||||||
{
|
{
|
||||||
public override string Name => "Food";
|
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]
|
[ViewVariables]
|
||||||
public int UsesRemaining
|
public int UsesRemaining
|
||||||
@@ -48,9 +57,12 @@ namespace Content.Server.Nutrition.Components
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (TransferAmount == null)
|
||||||
|
return solution.CurrentVolume == 0 ? 0 : 1;
|
||||||
|
|
||||||
return solution.CurrentVolume == 0
|
return solution.CurrentVolume == 0
|
||||||
? 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;
|
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))
|
if (!Owner.TryGetComponent(out SolutionContainerComponent? solution))
|
||||||
{
|
{
|
||||||
@@ -98,6 +110,7 @@ namespace Content.Server.Nutrition.Components
|
|||||||
if (UsesRemaining <= 0)
|
if (UsesRemaining <= 0)
|
||||||
{
|
{
|
||||||
user.PopupMessage(Loc.GetString("food-component-try-use-food-is-empty", ("entity", Owner)));
|
user.PopupMessage(Loc.GetString("food-component-try-use-food-is-empty", ("entity", Owner)));
|
||||||
|
DeleteAndSpawnTrash(user);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,12 +157,13 @@ namespace Content.Server.Nutrition.Components
|
|||||||
return false;
|
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 split = solution.SplitSolution(transferAmount);
|
||||||
var firstStomach = stomachs.FirstOrDefault(stomach => stomach.CanTransferSolution(split));
|
var firstStomach = stomachs.FirstOrDefault(stomach => stomach.CanTransferSolution(split));
|
||||||
|
|
||||||
if (firstStomach == null)
|
if (firstStomach == null)
|
||||||
{
|
{
|
||||||
|
solution.TryAddSolution(split);
|
||||||
trueTarget.PopupMessage(user, Loc.GetString("food-you-cannot-eat-any-more"));
|
trueTarget.PopupMessage(user, Loc.GetString("food-you-cannot-eat-any-more"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -162,7 +176,7 @@ namespace Content.Server.Nutrition.Components
|
|||||||
|
|
||||||
SoundSystem.Play(Filter.Pvs(trueTarget), UseSound.GetSound(), trueTarget, AudioParams.Default.WithVolume(-1f));
|
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 were used
|
||||||
if (utensils != null)
|
if (utensils != null)
|
||||||
@@ -184,6 +198,13 @@ namespace Content.Server.Nutrition.Components
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DeleteAndSpawnTrash(user);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DeleteAndSpawnTrash(IEntity user)
|
||||||
|
{
|
||||||
//We're empty. Become trash.
|
//We're empty. Become trash.
|
||||||
var position = Owner.Transform.Coordinates;
|
var position = Owner.Transform.Coordinates;
|
||||||
var finisher = Owner.EntityManager.SpawnEntity(TrashPrototype, position);
|
var finisher = Owner.EntityManager.SpawnEntity(TrashPrototype, position);
|
||||||
@@ -205,8 +226,6 @@ namespace Content.Server.Nutrition.Components
|
|||||||
{
|
{
|
||||||
Owner.Delete();
|
Owner.Delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.
|
|
||||||
@@ -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-you-cannot-eat-any-more = You can't eat any more!
|
||||||
food-nom = Nom
|
food-nom = Nom
|
||||||
|
food-swallow = You swallow the {$food}.
|
||||||
|
|
||||||
## Entity
|
## Entity
|
||||||
|
|
||||||
|
|||||||
@@ -236,9 +236,9 @@
|
|||||||
- Gauze
|
- Gauze
|
||||||
- Ointment
|
- Ointment
|
||||||
- CigPack
|
- CigPack
|
||||||
|
- Pill
|
||||||
components:
|
components:
|
||||||
- Hypospray
|
- Hypospray
|
||||||
- Pill
|
|
||||||
- SurgeryTool
|
- SurgeryTool
|
||||||
- Radio
|
- Radio
|
||||||
- type: ItemCounter
|
- type: ItemCounter
|
||||||
@@ -253,7 +253,7 @@
|
|||||||
- Hypospray
|
- Hypospray
|
||||||
pill:
|
pill:
|
||||||
whitelist:
|
whitelist:
|
||||||
components:
|
tags:
|
||||||
- Pill
|
- Pill
|
||||||
bottle_spray:
|
bottle_spray:
|
||||||
whitelist:
|
whitelist:
|
||||||
|
|||||||
@@ -187,7 +187,12 @@
|
|||||||
- type: Sprite
|
- type: Sprite
|
||||||
sprite: Objects/Specific/Chemistry/pills.rsi
|
sprite: Objects/Specific/Chemistry/pills.rsi
|
||||||
state: pill
|
state: pill
|
||||||
- type: Pill
|
- type: Tag
|
||||||
|
tags:
|
||||||
|
- Pill
|
||||||
|
- type: Food
|
||||||
|
transferAmount: null
|
||||||
|
eatMessage: food-swallow
|
||||||
- type: SolutionContainer
|
- type: SolutionContainer
|
||||||
maxVol: 50
|
maxVol: 50
|
||||||
caps: None
|
caps: None
|
||||||
|
|||||||
@@ -142,6 +142,9 @@
|
|||||||
- type: Tag
|
- type: Tag
|
||||||
id: Ore
|
id: Ore
|
||||||
|
|
||||||
|
- type: Tag
|
||||||
|
id: Pill
|
||||||
|
|
||||||
- type: Tag
|
- type: Tag
|
||||||
id: Pizza
|
id: Pizza
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user