From: Mervill Date: Fri, 2 Aug 2024 07:30:45 +0000 (-0700) Subject: Remove obsolete code from Food, Drink and Respirator systems. (#30560) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=af752586018fa7323caa6e2047dcc8f6dbaa6d48;p=space-station-14.git Remove obsolete code from Food, Drink and Respirator systems. (#30560) * Remove obsolete code from Food, Drink and Respirator systems * remove obsolete comment --- diff --git a/Content.Server/Body/Systems/RespiratorSystem.cs b/Content.Server/Body/Systems/RespiratorSystem.cs index 5190ba37d5..45074dc826 100644 --- a/Content.Server/Body/Systems/RespiratorSystem.cs +++ b/Content.Server/Body/Systems/RespiratorSystem.cs @@ -287,10 +287,10 @@ public sealed class RespiratorSystem : EntitySystem if (ent.Comp.SuffocationCycles >= ent.Comp.SuffocationCycleThreshold) { // TODO: This is not going work with multiple different lungs, if that ever becomes a possibility - var organs = _bodySystem.GetBodyOrganComponents(ent); - foreach (var (comp, _) in organs) + var organs = _bodySystem.GetBodyOrganEntityComps((ent, null)); + foreach (var entity in organs) { - _alertsSystem.ShowAlert(ent, comp.Alert); + _alertsSystem.ShowAlert(entity.Owner, entity.Comp1.Alert); } } @@ -303,10 +303,10 @@ public sealed class RespiratorSystem : EntitySystem _adminLogger.Add(LogType.Asphyxiation, $"{ToPrettyString(ent):entity} stopped suffocating"); // TODO: This is not going work with multiple different lungs, if that ever becomes a possibility - var organs = _bodySystem.GetBodyOrganComponents(ent); - foreach (var (comp, _) in organs) + var organs = _bodySystem.GetBodyOrganEntityComps((ent, null)); + foreach (var entity in organs) { - _alertsSystem.ClearAlert(ent, comp.Alert); + _alertsSystem.ClearAlert(entity.Owner, entity.Comp1.Alert); } _damageableSys.TryChangeDamage(ent, ent.Comp.DamageRecovery); diff --git a/Content.Server/Nutrition/EntitySystems/DrinkSystem.cs b/Content.Server/Nutrition/EntitySystems/DrinkSystem.cs index 36c4ef4b55..ab4ce450d8 100644 --- a/Content.Server/Nutrition/EntitySystems/DrinkSystem.cs +++ b/Content.Server/Nutrition/EntitySystems/DrinkSystem.cs @@ -258,7 +258,7 @@ public sealed class DrinkSystem : SharedDrinkSystem if (transferAmount <= 0) return; - if (!_body.TryGetBodyOrganComponents(args.Target.Value, out var stomachs, body)) + if (!_body.TryGetBodyOrganEntityComps((args.Target.Value, body), out var stomachs)) { _popup.PopupEntity(Loc.GetString(forceDrink ? "drink-component-try-use-drink-cannot-drink-other" : "drink-component-try-use-drink-had-enough"), args.Target.Value, args.User); @@ -272,7 +272,7 @@ public sealed class DrinkSystem : SharedDrinkSystem return; } - var firstStomach = stomachs.FirstOrNull(stomach => _stomach.CanTransferSolution(stomach.Comp.Owner, drained, stomach.Comp)); + var firstStomach = stomachs.FirstOrNull(stomach => _stomach.CanTransferSolution(stomach.Owner, drained, stomach.Comp1)); //All stomachs are full or can't handle whatever solution we have. if (firstStomach == null) @@ -321,8 +321,7 @@ public sealed class DrinkSystem : SharedDrinkSystem _audio.PlayPvs(entity.Comp.UseSound, args.Target.Value, AudioParams.Default.WithVolume(-2f)); _reaction.DoEntityReaction(args.Target.Value, solution, ReactionMethod.Ingestion); - //TODO: Grab the stomach UIDs somehow without using Owner - _stomach.TryTransferSolution(firstStomach.Value.Comp.Owner, drained, firstStomach.Value.Comp); + _stomach.TryTransferSolution(firstStomach.Value.Owner, drained, firstStomach.Value.Comp1); _forensics.TransferDna(entity, args.Target.Value); @@ -336,7 +335,7 @@ public sealed class DrinkSystem : SharedDrinkSystem !ev.CanInteract || !ev.CanAccess || !TryComp(ev.User, out var body) || - !_body.TryGetBodyOrganComponents(ev.User, out var stomachs, body)) + !_body.TryGetBodyOrganEntityComps((ev.User, body), out var stomachs)) return; // Make sure the solution exists diff --git a/Content.Server/Nutrition/EntitySystems/FoodSystem.cs b/Content.Server/Nutrition/EntitySystems/FoodSystem.cs index 4d670a3eb7..53c1b39982 100644 --- a/Content.Server/Nutrition/EntitySystems/FoodSystem.cs +++ b/Content.Server/Nutrition/EntitySystems/FoodSystem.cs @@ -1,6 +1,6 @@ using Content.Server.Body.Components; using Content.Server.Body.Systems; -using Content.Server.Chemistry.Containers.EntitySystems; +using Content.Shared.Chemistry.EntitySystems; using Content.Server.Inventory; using Content.Server.Nutrition.Components; using Content.Shared.Nutrition.Components; @@ -53,7 +53,7 @@ public sealed class FoodSystem : EntitySystem [Dependency] private readonly SharedDoAfterSystem _doAfter = default!; [Dependency] private readonly SharedHandsSystem _hands = default!; [Dependency] private readonly SharedInteractionSystem _interaction = default!; - [Dependency] private readonly SolutionContainerSystem _solutionContainer = default!; + [Dependency] private readonly SharedSolutionContainerSystem _solutionContainer = default!; [Dependency] private readonly TransformSystem _transform = default!; [Dependency] private readonly StackSystem _stack = default!; [Dependency] private readonly StomachSystem _stomach = default!; @@ -121,7 +121,7 @@ public sealed class FoodSystem : EntitySystem if (!_solutionContainer.TryGetSolution(food, foodComp.Solution, out _, out var foodSolution)) return (false, false); - if (!_body.TryGetBodyOrganComponents(target, out var stomachs, body)) + if (!_body.TryGetBodyOrganEntityComps((target, body), out var stomachs)) return (false, false); // Check for special digestibles @@ -182,12 +182,12 @@ public sealed class FoodSystem : EntitySystem user, target); // logging - _adminLogger.Add(LogType.ForceFeed, LogImpact.Medium, $"{ToPrettyString(user):user} is forcing {ToPrettyString(target):target} to eat {ToPrettyString(food):food} {SolutionContainerSystem.ToPrettyString(foodSolution)}"); + _adminLogger.Add(LogType.ForceFeed, LogImpact.Medium, $"{ToPrettyString(user):user} is forcing {ToPrettyString(target):target} to eat {ToPrettyString(food):food} {SharedSolutionContainerSystem.ToPrettyString(foodSolution)}"); } else { // log voluntary eating - _adminLogger.Add(LogType.Ingestion, LogImpact.Low, $"{ToPrettyString(target):target} is eating {ToPrettyString(food):food} {SolutionContainerSystem.ToPrettyString(foodSolution)}"); + _adminLogger.Add(LogType.Ingestion, LogImpact.Low, $"{ToPrettyString(target):target} is eating {ToPrettyString(food):food} {SharedSolutionContainerSystem.ToPrettyString(foodSolution)}"); } var doAfterArgs = new DoAfterArgs(EntityManager, @@ -220,7 +220,7 @@ public sealed class FoodSystem : EntitySystem if (!TryComp(args.Target.Value, out var body)) return; - if (!_body.TryGetBodyOrganComponents(args.Target.Value, out var stomachs, body)) + if (!_body.TryGetBodyOrganEntityComps((args.Target.Value, body), out var stomachs)) return; if (args.Used is null || !_solutionContainer.TryGetSolution(args.Used.Value, args.Solution, out var soln, out var solution)) @@ -244,23 +244,22 @@ public sealed class FoodSystem : EntitySystem var split = _solutionContainer.SplitSolution(soln.Value, transferAmount); - //TODO: Get the stomach UID somehow without nabbing owner // Get the stomach with the highest available solution volume var highestAvailable = FixedPoint2.Zero; - StomachComponent? stomachToUse = null; - foreach (var (stomach, _) in stomachs) + Entity? stomachToUse = null; + foreach (var ent in stomachs) { - var owner = stomach.Owner; - if (!_stomach.CanTransferSolution(owner, split, stomach)) + var owner = ent.Owner; + if (!_stomach.CanTransferSolution(owner, split, ent.Comp1)) continue; - if (!_solutionContainer.ResolveSolution(owner, StomachSystem.DefaultSolutionName, ref stomach.Solution, out var stomachSol)) + if (!_solutionContainer.ResolveSolution(owner, StomachSystem.DefaultSolutionName, ref ent.Comp1.Solution, out var stomachSol)) continue; if (stomachSol.AvailableVolume <= highestAvailable) continue; - stomachToUse = stomach; + stomachToUse = ent; highestAvailable = stomachSol.AvailableVolume; } @@ -273,7 +272,7 @@ public sealed class FoodSystem : EntitySystem } _reaction.DoEntityReaction(args.Target.Value, solution, ReactionMethod.Ingestion); - _stomach.TryTransferSolution(stomachToUse.Owner, split, stomachToUse); + _stomach.TryTransferSolution(stomachToUse!.Value.Owner, split, stomachToUse); var flavors = args.FlavorMessage; @@ -365,7 +364,7 @@ public sealed class FoodSystem : EntitySystem !ev.CanInteract || !ev.CanAccess || !TryComp(ev.User, out var body) || - !_body.TryGetBodyOrganComponents(ev.User, out var stomachs, body)) + !_body.TryGetBodyOrganEntityComps((ev.User, body), out var stomachs)) return; // have to kill mouse before eating it @@ -399,7 +398,7 @@ public sealed class FoodSystem : EntitySystem if (!Resolve(food, ref foodComp, false)) return false; - if (!_body.TryGetBodyOrganComponents(uid, out var stomachs)) + if (!_body.TryGetBodyOrganEntityComps(uid, out var stomachs)) return false; return IsDigestibleBy(food, foodComp, stomachs); @@ -409,7 +408,7 @@ public sealed class FoodSystem : EntitySystem /// Returns true if has a that whitelists /// this (or if they even have enough stomachs in the first place). /// - private bool IsDigestibleBy(EntityUid food, FoodComponent component, List<(StomachComponent, OrganComponent)> stomachs) + private bool IsDigestibleBy(EntityUid food, FoodComponent component, List> stomachs) { var digestible = true; @@ -418,13 +417,13 @@ public sealed class FoodSystem : EntitySystem return false; // Run through the mobs' stomachs - foreach (var (comp, _) in stomachs) + foreach (var ent in stomachs) { // Find a stomach with a SpecialDigestible - if (comp.SpecialDigestible == null) + if (ent.Comp1.SpecialDigestible == null) continue; // Check if the food is in the whitelist - if (_whitelistSystem.IsWhitelistPass(comp.SpecialDigestible, food)) + if (_whitelistSystem.IsWhitelistPass(ent.Comp1.SpecialDigestible, food)) return true; // They can only eat whitelist food and the food isn't in the whitelist. It's not edible. return false; diff --git a/Content.Shared/Body/Systems/SharedBodySystem.Organs.cs b/Content.Shared/Body/Systems/SharedBodySystem.Organs.cs index 30fed573b8..1c315869c8 100644 --- a/Content.Shared/Body/Systems/SharedBodySystem.Organs.cs +++ b/Content.Shared/Body/Systems/SharedBodySystem.Organs.cs @@ -157,32 +157,6 @@ public partial class SharedBodySystem return false; } - /// - /// Returns a list of ValueTuples of and OrganComponent on each organ - /// in the given body. - /// - /// The body entity id to check on. - /// The body to check for organs on. - /// The component to check for. - public List<(T Comp, OrganComponent Organ)> GetBodyOrganComponents( - EntityUid uid, - BodyComponent? body = null) - where T : IComponent - { - if (!Resolve(uid, ref body)) - return new List<(T Comp, OrganComponent Organ)>(); - - var query = GetEntityQuery(); - var list = new List<(T Comp, OrganComponent Organ)>(3); - foreach (var organ in GetBodyOrgans(uid, body)) - { - if (query.TryGetComponent(organ.Id, out var comp)) - list.Add((comp, organ.Component)); - } - - return list; - } - /// /// Returns a list of Entity<, > /// for each organ of the body @@ -216,19 +190,18 @@ public partial class SharedBodySystem /// The body to check for organs on. /// The component to check for. /// Whether any were found. - public bool TryGetBodyOrganComponents( - EntityUid uid, - [NotNullWhen(true)] out List<(T Comp, OrganComponent Organ)>? comps, - BodyComponent? body = null) + public bool TryGetBodyOrganEntityComps( + Entity entity, + [NotNullWhen(true)] out List>? comps) where T : IComponent { - if (!Resolve(uid, ref body)) + if (!Resolve(entity.Owner, ref entity.Comp)) { comps = null; return false; } - comps = GetBodyOrganComponents(uid, body); + comps = GetBodyOrganEntityComps(entity); if (comps.Count != 0) return true;