Revert "Solution Entities" (#23160)

Revert "Solution Entities (#21916)"

This reverts commit d75e743dd7.
This commit is contained in:
Emisse
2023-12-28 20:45:42 -07:00
committed by GitHub
parent c2c76c2035
commit 938d6d9945
180 changed files with 2959 additions and 3543 deletions

View File

@@ -1,6 +1,6 @@
using System.Linq;
using Content.Server.Body.Components;
using Content.Server.Body.Systems;
using Content.Server.Chemistry.Containers.EntitySystems;
using Content.Server.Inventory;
using Content.Server.Nutrition.Components;
using Content.Server.Popups;
@@ -9,6 +9,7 @@ using Content.Shared.Administration.Logs;
using Content.Shared.Body.Components;
using Content.Shared.Body.Organ;
using Content.Shared.Chemistry;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Database;
using Content.Shared.DoAfter;
@@ -26,9 +27,11 @@ using Content.Shared.Stacks;
using Content.Shared.Storage;
using Content.Shared.Verbs;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Player;
using Robust.Shared.Utility;
using System.Linq;
using Content.Shared.Tag;
using Content.Shared.Storage;
using Robust.Shared.Audio.Systems;
namespace Content.Server.Nutrition.EntitySystems;
@@ -72,24 +75,24 @@ public sealed class FoodSystem : EntitySystem
/// <summary>
/// Eat item
/// </summary>
private void OnUseFoodInHand(Entity<FoodComponent> entity, ref UseInHandEvent ev)
private void OnUseFoodInHand(EntityUid uid, FoodComponent foodComponent, UseInHandEvent ev)
{
if (ev.Handled)
return;
var result = TryFeed(ev.User, ev.User, entity, entity.Comp);
var result = TryFeed(ev.User, ev.User, uid, foodComponent);
ev.Handled = result.Handled;
}
/// <summary>
/// Feed someone else
/// </summary>
private void OnFeedFood(Entity<FoodComponent> entity, ref AfterInteractEvent args)
private void OnFeedFood(EntityUid uid, FoodComponent foodComponent, AfterInteractEvent args)
{
if (args.Handled || args.Target == null || !args.CanReach)
return;
var result = TryFeed(args.User, args.Target.Value, entity, entity.Comp);
var result = TryFeed(args.User, args.Target.Value, uid, foodComponent);
args.Handled = result.Handled;
}
@@ -109,7 +112,7 @@ public sealed class FoodSystem : EntitySystem
if (_openable.IsClosed(food, user))
return (false, true);
if (!_solutionContainer.TryGetSolution(food, foodComp.Solution, out _, out var foodSolution))
if (!_solutionContainer.TryGetSolution(food, foodComp.Solution, out var foodSolution) || foodSolution.Name == null)
return (false, false);
if (!_body.TryGetBodyOrganComponents<StomachComponent>(target, out var stomachs, body))
@@ -174,7 +177,7 @@ public sealed class FoodSystem : EntitySystem
var doAfterArgs = new DoAfterArgs(EntityManager,
user,
forceFeed ? foodComp.ForceFeedDelay : foodComp.Delay,
new ConsumeDoAfterEvent(foodComp.Solution, flavors),
new ConsumeDoAfterEvent(foodSolution.Name, flavors),
eventTarget: food,
target: target,
used: food)
@@ -193,9 +196,9 @@ public sealed class FoodSystem : EntitySystem
return (true, true);
}
private void OnDoAfter(Entity<FoodComponent> entity, ref ConsumeDoAfterEvent args)
private void OnDoAfter(EntityUid uid, FoodComponent component, ConsumeDoAfterEvent args)
{
if (args.Cancelled || args.Handled || entity.Comp.Deleted || args.Target == null)
if (args.Cancelled || args.Handled || component.Deleted || args.Target == null)
return;
if (!TryComp<BodyComponent>(args.Target.Value, out var body))
@@ -204,10 +207,10 @@ public sealed class FoodSystem : EntitySystem
if (!_body.TryGetBodyOrganComponents<StomachComponent>(args.Target.Value, out var stomachs, body))
return;
if (args.Used is null || !_solutionContainer.TryGetSolution(args.Used.Value, args.Solution, out var soln, out var solution))
if (!_solutionContainer.TryGetSolution(args.Used, args.Solution, out var solution))
return;
if (!TryGetRequiredUtensils(args.User, entity.Comp, out var utensils))
if (!TryGetRequiredUtensils(args.User, component, out var utensils))
return;
// TODO this should really be checked every tick.
@@ -221,9 +224,9 @@ public sealed class FoodSystem : EntitySystem
var forceFeed = args.User != args.Target;
args.Handled = true;
var transferAmount = entity.Comp.TransferAmount != null ? FixedPoint2.Min((FixedPoint2) entity.Comp.TransferAmount, solution.Volume) : solution.Volume;
var transferAmount = component.TransferAmount != null ? FixedPoint2.Min((FixedPoint2) component.TransferAmount, solution.Volume) : solution.Volume;
var split = _solutionContainer.SplitSolution(soln.Value, transferAmount);
var split = _solutionContainer.SplitSolution(uid, solution, transferAmount);
//TODO: Get the stomach UID somehow without nabbing owner
// Get the stomach with the highest available solution volume
@@ -232,10 +235,11 @@ public sealed class FoodSystem : EntitySystem
foreach (var (stomach, _) in stomachs)
{
var owner = stomach.Owner;
if (!_stomach.CanTransferSolution(owner, split, stomach))
if (!_stomach.CanTransferSolution(owner, split))
continue;
if (!_solutionContainer.ResolveSolution(owner, StomachSystem.DefaultSolutionName, ref stomach.Solution, out var stomachSol))
if (!_solutionContainer.TryGetSolution(owner, StomachSystem.DefaultSolutionName,
out var stomachSol))
continue;
if (stomachSol.AvailableVolume <= highestAvailable)
@@ -248,7 +252,7 @@ public sealed class FoodSystem : EntitySystem
// No stomach so just popup a message that they can't eat.
if (stomachToUse == null)
{
_solutionContainer.TryAddSolution(soln.Value, split);
_solutionContainer.TryAddSolution(uid, solution, split);
_popup.PopupEntity(forceFeed ? Loc.GetString("food-system-you-cannot-eat-any-more-other") : Loc.GetString("food-system-you-cannot-eat-any-more"), args.Target.Value, args.User);
return;
}
@@ -262,22 +266,23 @@ public sealed class FoodSystem : EntitySystem
{
var targetName = Identity.Entity(args.Target.Value, EntityManager);
var userName = Identity.Entity(args.User, EntityManager);
_popup.PopupEntity(Loc.GetString("food-system-force-feed-success", ("user", userName), ("flavors", flavors)), entity.Owner, entity.Owner);
_popup.PopupEntity(Loc.GetString("food-system-force-feed-success", ("user", userName), ("flavors", flavors)),
uid, uid);
_popup.PopupEntity(Loc.GetString("food-system-force-feed-success-user", ("target", targetName)), args.User, args.User);
// log successful force feed
_adminLogger.Add(LogType.ForceFeed, LogImpact.Medium, $"{ToPrettyString(entity.Owner):user} forced {ToPrettyString(args.User):target} to eat {ToPrettyString(entity.Owner):food}");
_adminLogger.Add(LogType.ForceFeed, LogImpact.Medium, $"{ToPrettyString(uid):user} forced {ToPrettyString(args.User):target} to eat {ToPrettyString(uid):food}");
}
else
{
_popup.PopupEntity(Loc.GetString(entity.Comp.EatMessage, ("food", entity.Owner), ("flavors", flavors)), args.User, args.User);
_popup.PopupEntity(Loc.GetString(component.EatMessage, ("food", uid), ("flavors", flavors)), args.User, args.User);
// log successful voluntary eating
_adminLogger.Add(LogType.Ingestion, LogImpact.Low, $"{ToPrettyString(args.User):target} ate {ToPrettyString(entity.Owner):food}");
_adminLogger.Add(LogType.Ingestion, LogImpact.Low, $"{ToPrettyString(args.User):target} ate {ToPrettyString(uid):food}");
}
_audio.PlayPvs(entity.Comp.UseSound, args.Target.Value, AudioParams.Default.WithVolume(-1f));
_audio.PlayPvs(component.UseSound, args.Target.Value, AudioParams.Default.WithVolume(-1f));
// Try to break all used utensils
foreach (var utensil in utensils)
@@ -287,24 +292,24 @@ public sealed class FoodSystem : EntitySystem
args.Repeat = !forceFeed;
if (TryComp<StackComponent>(entity, out var stack))
if (TryComp<StackComponent>(uid, out var stack))
{
//Not deleting whole stack piece will make troubles with grinding object
if (stack.Count > 1)
{
_stack.SetCount(entity.Owner, stack.Count - 1);
_solutionContainer.TryAddSolution(soln.Value, split);
_stack.SetCount(uid, stack.Count - 1);
_solutionContainer.TryAddSolution(uid, solution, split);
return;
}
}
else if (GetUsesRemaining(entity.Owner, entity.Comp) > 0)
else if (GetUsesRemaining(uid, component) > 0)
{
return;
}
// don't try to repeat if its being deleted
args.Repeat = false;
DeleteAndSpawnTrash(entity.Comp, entity.Owner, args.User);
DeleteAndSpawnTrash(component, uid, args.User);
}
public void DeleteAndSpawnTrash(FoodComponent component, EntityUid food, EntityUid user)
@@ -340,9 +345,9 @@ public sealed class FoodSystem : EntitySystem
QueueDel(food);
}
private void AddEatVerb(Entity<FoodComponent> entity, ref GetVerbsEvent<AlternativeVerb> ev)
private void AddEatVerb(EntityUid uid, FoodComponent component, GetVerbsEvent<AlternativeVerb> ev)
{
if (entity.Owner == ev.User ||
if (uid == ev.User ||
!ev.CanInteract ||
!ev.CanAccess ||
!TryComp<BodyComponent>(ev.User, out var body) ||
@@ -350,21 +355,20 @@ public sealed class FoodSystem : EntitySystem
return;
// have to kill mouse before eating it
if (_mobState.IsAlive(entity) && entity.Comp.RequireDead)
if (_mobState.IsAlive(uid) && component.RequireDead)
return;
// only give moths eat verb for clothes since it would just fail otherwise
if (!IsDigestibleBy(entity, entity.Comp, stomachs))
if (!IsDigestibleBy(uid, component, stomachs))
return;
var user = ev.User;
AlternativeVerb verb = new()
{
Act = () =>
{
TryFeed(user, user, entity, entity.Comp);
TryFeed(ev.User, ev.User, uid, component);
},
Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/VerbIcons/cutlery.svg.192dpi.png")),
Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/cutlery.svg.192dpi.png")),
Text = Loc.GetString("food-system-verb-eat"),
Priority = -1
};
@@ -412,7 +416,7 @@ public sealed class FoodSystem : EntitySystem
}
if (component.RequiresSpecialDigestion)
return false;
return false;
return digestible;
}
@@ -458,14 +462,14 @@ public sealed class FoodSystem : EntitySystem
/// <summary>
/// Block ingestion attempts based on the equipped mask or head-wear
/// </summary>
private void OnInventoryIngestAttempt(Entity<InventoryComponent> entity, ref IngestionAttemptEvent args)
private void OnInventoryIngestAttempt(EntityUid uid, InventoryComponent component, IngestionAttemptEvent args)
{
if (args.Cancelled)
return;
IngestionBlockerComponent? blocker;
if (_inventory.TryGetSlotEntity(entity.Owner, "mask", out var maskUid) &&
if (_inventory.TryGetSlotEntity(uid, "mask", out var maskUid) &&
TryComp(maskUid, out blocker) &&
blocker.Enabled)
{
@@ -474,7 +478,7 @@ public sealed class FoodSystem : EntitySystem
return;
}
if (_inventory.TryGetSlotEntity(entity.Owner, "head", out var headUid) &&
if (_inventory.TryGetSlotEntity(uid, "head", out var headUid) &&
TryComp(headUid, out blocker) &&
blocker.Enabled)
{
@@ -512,7 +516,7 @@ public sealed class FoodSystem : EntitySystem
if (!Resolve(uid, ref comp))
return 0;
if (!_solutionContainer.TryGetSolution(uid, comp.Solution, out _, out var solution) || solution.Volume == 0)
if (!_solutionContainer.TryGetSolution(uid, comp.Solution, out var solution) || solution.Volume == 0)
return 0;
// eat all in 1 go, so non empty is 1 bite