Solution refactor (#4407)

* Rename SolutionContainerCaps -> Capability

* Move IExamine event to Chemistry System.

* ECS the ISolutionChange into SolutionChangeEvent

* Unify SolutionContainer into a single shared component

* Replace ISolutionInteraction with SolutionContainerComponent

* Move all methods from SolutionContainer to ChemistrySystem

* Refactor EntitySystem calls to Dependencies

* Refactor SolutionContainer to SolutionManager

* Fix yamls

* Fix test fails

* Fix post merge issues

* Fix various issues with SolutionManager

* More fixes

* Fix more components

* Fix events not being directed

* Fixes for Hypospray

* Separate removal and iteration on Metabolism

* Fix creampie problems

* Address some of sloth's issues

* Refactors for Systems

* Refactored solution location

* Fix tests

* Address more sloth issues

* Fix dependency

* Fix merge conflicts

* Add xmldocs for Capabilities components

* Remove HasSolution/TryGetDefaultSolution and Add/Remove Drainable/Refillable

* Replace Grindable/Juiceable with Extractable

* Refactor field names

* Fix Drainable

* Fix some issues with spillable and injector

* Fix issues with Grinder

* Fix Beaker having duplicate solutions

* Fix foaming

* Address some MGS issues

* Fix Uid issues

* Fix errors in solution Tranfer

* Fixed some extra values constant values

* Cola is drinkable now
This commit is contained in:
Ygg01
2021-09-06 15:49:44 +02:00
committed by GitHub
parent b8911d58ac
commit c209e3f29b
166 changed files with 4268 additions and 3278 deletions

View File

@@ -1,9 +1,7 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Content.Server.Atmos;
using Content.Server.Atmos.EntitySystems;
using Content.Server.Chemistry.Components;
using Content.Server.Fluids.Components;
using Content.Server.Hands.Components;
using Content.Server.Notification;
@@ -11,11 +9,10 @@ using Content.Server.Plants;
using Content.Shared.ActionBlocker;
using Content.Shared.Audio;
using Content.Shared.Botany;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Chemistry.Solution.Components;
using Content.Shared.Examine;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
using Content.Shared.Notification.Managers;
using Content.Shared.Random.Helpers;
using Content.Shared.Tag;
@@ -40,17 +37,23 @@ namespace Content.Server.Botany.Components
{
public const float HydroponicsSpeedMultiplier = 1f;
public const float HydroponicsConsumptionMultiplier = 4f;
private const string SoilSolutionName = "soil";
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[ComponentDependency] private readonly AppearanceComponent? _appearanceComponent = default!;
public override string Name => "PlantHolder";
[ViewVariables] private int _lastProduce;
[ViewVariables(VVAccess.ReadWrite)] private int _missingGas;
private readonly TimeSpan _cycleDelay = TimeSpan.FromSeconds(15f);
[ViewVariables] private TimeSpan _lastCycle = TimeSpan.Zero;
[ViewVariables(VVAccess.ReadWrite)] private bool _updateSpriteAfterUpdate;
[ViewVariables(VVAccess.ReadWrite)]
@@ -117,16 +120,6 @@ namespace Content.Server.Botany.Components
[ViewVariables(VVAccess.ReadWrite)]
public bool ForceUpdate { get; set; }
[ComponentDependency] private readonly SolutionContainerComponent? _solutionContainer = default!;
[ComponentDependency] private readonly AppearanceComponent? _appearanceComponent = default!;
protected override void Initialize()
{
base.Initialize();
Owner.EnsureComponentWarn<SolutionContainerComponent>();
}
public void WeedInvasion()
{
// TODO
@@ -142,7 +135,7 @@ namespace Content.Server.Botany.Components
ForceUpdate = false;
else if (curTime < (_lastCycle + _cycleDelay))
{
if(_updateSpriteAfterUpdate)
if (_updateSpriteAfterUpdate)
UpdateSprite();
return;
}
@@ -190,8 +183,8 @@ namespace Content.Server.Botany.Components
SkipAging--;
else
{
if(_random.Prob(0.8f))
Age += (int)(1 * HydroponicsSpeedMultiplier);
if (_random.Prob(0.8f))
Age += (int) (1 * HydroponicsSpeedMultiplier);
_updateSpriteAfterUpdate = true;
}
@@ -207,7 +200,8 @@ namespace Content.Server.Botany.Components
// Water consumption.
if (Seed.WaterConsumption > 0 && WaterLevel > 0 && _random.Prob(0.75f))
{
WaterLevel -= MathF.Max(0f, Seed.NutrientConsumption * HydroponicsConsumptionMultiplier * HydroponicsSpeedMultiplier);
WaterLevel -= MathF.Max(0f,
Seed.NutrientConsumption * HydroponicsConsumptionMultiplier * HydroponicsSpeedMultiplier);
if (DrawWarnings)
_updateSpriteAfterUpdate = true;
}
@@ -248,7 +242,8 @@ namespace Content.Server.Botany.Components
_updateSpriteAfterUpdate = true;
}
var environment = EntitySystem.Get<AtmosphereSystem>().GetTileMixture(Owner.Transform.Coordinates, true)?? GasMixture.SpaceGas;
var environment = EntitySystem.Get<AtmosphereSystem>().GetTileMixture(Owner.Transform.Coordinates, true) ??
GasMixture.SpaceGas;
if (Seed.ConsumeGasses.Count > 0)
{
@@ -306,7 +301,8 @@ namespace Content.Server.Botany.Components
{
foreach (var (gas, amount) in Seed.ExudeGasses)
{
environment.AdjustMoles(gas, MathF.Max(1f, MathF.Round((amount * MathF.Round(Seed.Potency)) / exudeCount)));
environment.AdjustMoles(gas,
MathF.Max(1f, MathF.Round((amount * MathF.Round(Seed.Potency)) / exudeCount)));
}
}
@@ -357,7 +353,7 @@ namespace Content.Server.Botany.Components
if (DrawWarnings)
_updateSpriteAfterUpdate = true;
}
else if(Age < 0) // Revert back to seed packet!
else if (Age < 0) // Revert back to seed packet!
{
Seed.SpawnSeedPacket(Owner.Transform.Coordinates);
RemovePlant();
@@ -393,7 +389,7 @@ namespace Content.Server.Botany.Components
CheckLevelSanity();
if(_updateSpriteAfterUpdate)
if (_updateSpriteAfterUpdate)
UpdateSprite();
}
@@ -428,8 +424,8 @@ namespace Content.Server.Botany.Components
{
if (!Seed.CheckHarvest(user, hands.GetActiveHand?.Owner))
return false;
} else if (!Seed.CheckHarvest(user))
}
else if (!Seed.CheckHarvest(user))
{
return false;
}
@@ -460,7 +456,7 @@ namespace Content.Server.Botany.Components
Harvest = false;
_lastProduce = Age;
if(Seed?.HarvestRepeat == HarvestType.NoRepeat)
if (Seed?.HarvestRepeat == HarvestType.NoRepeat)
RemovePlant();
CheckLevelSanity();
@@ -546,10 +542,11 @@ namespace Content.Server.Botany.Components
public void UpdateReagents()
{
if (_solutionContainer == null)
var solutionSystem = EntitySystem.Get<SolutionContainerSystem>();
if (!solutionSystem.TryGetSolution(Owner, SoilSolutionName, out var solution))
return;
if (_solutionContainer.Solution.TotalVolume <= 0 || MutationLevel >= 25)
if (solution.TotalVolume <= 0 || MutationLevel >= 25)
{
if (MutationLevel >= 0)
{
@@ -560,12 +557,10 @@ namespace Content.Server.Botany.Components
else
{
var one = ReagentUnit.New(1);
foreach (var (reagent, amount) in _solutionContainer.ReagentList.ToArray())
foreach (var reagent in solutionSystem.RemoveEachReagent(solution, one))
{
var reagentProto = _prototypeManager.Index<ReagentPrototype>(reagent);
reagentProto.ReactionPlant(Owner);
_solutionContainer.Solution.RemoveReagent(reagent, amount < one ? amount : one);
}
}
@@ -586,26 +581,30 @@ namespace Content.Server.Botany.Components
if (Seed != null)
{
if(DrawWarnings)
if (DrawWarnings)
_appearanceComponent.SetData(PlantHolderVisuals.HealthLight, Health <= (Seed.Endurance / 2f));
if (Dead)
{
_appearanceComponent.SetData(PlantHolderVisuals.Plant, new SpriteSpecifier.Rsi(Seed.PlantRsi, "dead"));
_appearanceComponent.SetData(PlantHolderVisuals.Plant,
new SpriteSpecifier.Rsi(Seed.PlantRsi, "dead"));
}
else if (Harvest)
{
_appearanceComponent.SetData(PlantHolderVisuals.Plant, new SpriteSpecifier.Rsi(Seed.PlantRsi, "harvest"));
_appearanceComponent.SetData(PlantHolderVisuals.Plant,
new SpriteSpecifier.Rsi(Seed.PlantRsi, "harvest"));
}
else if (Age < Seed.Maturation)
{
var growthStage = Math.Max(1, (int)((Age * Seed.GrowthStages) / Seed.Maturation));
_appearanceComponent.SetData(PlantHolderVisuals.Plant, new SpriteSpecifier.Rsi(Seed.PlantRsi,$"stage-{growthStage}"));
var growthStage = Math.Max(1, (int) ((Age * Seed.GrowthStages) / Seed.Maturation));
_appearanceComponent.SetData(PlantHolderVisuals.Plant,
new SpriteSpecifier.Rsi(Seed.PlantRsi, $"stage-{growthStage}"));
_lastProduce = Age;
}
else
{
_appearanceComponent.SetData(PlantHolderVisuals.Plant, new SpriteSpecifier.Rsi(Seed.PlantRsi,$"stage-{Seed.GrowthStages}"));
_appearanceComponent.SetData(PlantHolderVisuals.Plant,
new SpriteSpecifier.Rsi(Seed.PlantRsi, $"stage-{Seed.GrowthStages}"));
}
}
else
@@ -617,7 +616,9 @@ namespace Content.Server.Botany.Components
if (!DrawWarnings) return;
_appearanceComponent.SetData(PlantHolderVisuals.WaterLight, WaterLevel <= 10);
_appearanceComponent.SetData(PlantHolderVisuals.NutritionLight, NutritionLevel <= 2);
_appearanceComponent.SetData(PlantHolderVisuals.AlertLight, WeedLevel >= 5 || PestLevel >= 5 || Toxins >= 40 || ImproperHeat || ImproperLight || ImproperPressure || _missingGas > 0);
_appearanceComponent.SetData(PlantHolderVisuals.AlertLight,
WeedLevel >= 5 || PestLevel >= 5 || Toxins >= 40 || ImproperHeat || ImproperLight || ImproperPressure ||
_missingGas > 0);
_appearanceComponent.SetData(PlantHolderVisuals.HarvestLight, Harvest);
}
@@ -644,7 +645,7 @@ namespace Content.Server.Botany.Components
var user = eventArgs.User;
var usingItem = eventArgs.Using;
if (usingItem == null || usingItem.Deleted || !EntitySystem.Get<ActionBlockerSystem>().CanInteract(user))
if (usingItem.Deleted || !EntitySystem.Get<ActionBlockerSystem>().CanInteract(user))
return false;
if (usingItem.TryGetComponent(out SeedComponent? seeds))
@@ -659,8 +660,8 @@ namespace Content.Server.Botany.Components
}
user.PopupMessageCursor(Loc.GetString("plant-holder-component-plant-success-message",
("seedName", seeds.Seed.SeedName),
("seedNoun", seeds.Seed.SeedNoun)));
("seedName", seeds.Seed.SeedName),
("seedNoun", seeds.Seed.SeedNoun)));
Seed = seeds.Seed;
Dead = false;
@@ -676,7 +677,8 @@ namespace Content.Server.Botany.Components
return true;
}
user.PopupMessageCursor(Loc.GetString("plant-holder-component-already-seeded-message", ("name", Owner.Name)));
user.PopupMessageCursor(Loc.GetString("plant-holder-component-already-seeded-message",
("name", Owner.Name)));
return false;
}
@@ -684,8 +686,10 @@ namespace Content.Server.Botany.Components
{
if (WeedLevel > 0)
{
user.PopupMessageCursor(Loc.GetString("plant-holder-component-remove-weeds-message",("name", Owner.Name)));
user.PopupMessageOtherClients(Loc.GetString("plant-holder-component-remove-weeds-others-message",("otherName", user.Name)));
user.PopupMessageCursor(Loc.GetString("plant-holder-component-remove-weeds-message",
("name", Owner.Name)));
user.PopupMessageOtherClients(Loc.GetString("plant-holder-component-remove-weeds-others-message",
("otherName", user.Name)));
WeedLevel = 0;
UpdateSprite();
}
@@ -701,8 +705,10 @@ namespace Content.Server.Botany.Components
{
if (Seed != null)
{
user.PopupMessageCursor(Loc.GetString("plant-holder-component-remove-plant-message",("name", Owner.Name)));
user.PopupMessageOtherClients(Loc.GetString("plant-holder-component-remove-plant-others-message",("name", user.Name)));
user.PopupMessageCursor(Loc.GetString("plant-holder-component-remove-plant-message",
("name", Owner.Name)));
user.PopupMessageOtherClients(Loc.GetString("plant-holder-component-remove-plant-others-message",
("name", user.Name)));
RemovePlant();
}
else
@@ -713,31 +719,38 @@ namespace Content.Server.Botany.Components
return true;
}
if (usingItem.TryGetComponent(out ISolutionInteractionsComponent? solution) && solution.CanDrain)
var solutionSystem = EntitySystem.Get<SolutionContainerSystem>();
if (solutionSystem.TryGetDrainableSolution(usingItem.Uid, out var solution)
&& solutionSystem.TryGetSolution(Owner, SoilSolutionName, out var targetSolution))
{
var amount = ReagentUnit.New(5);
var sprayed = false;
var targetEntity = Owner.Uid;
var solutionEntity = usingItem.Uid;
if (usingItem.TryGetComponent(out SprayComponent? spray))
{
sprayed = true;
amount = ReagentUnit.New(1);
SoundSystem.Play(Filter.Pvs(usingItem), spray.SpraySound.GetSound(), usingItem, AudioHelpers.WithVariation(0.125f));
SoundSystem.Play(Filter.Pvs(usingItem), spray.SpraySound.GetSound(), usingItem,
AudioHelpers.WithVariation(0.125f));
}
var split = solution.Drain(amount);
var split = solutionSystem.Drain(solutionEntity, solution, amount);
if (split.TotalVolume == 0)
{
user.PopupMessageCursor(Loc.GetString("plant-holder-component-empty-message",("owner", usingItem)));
user.PopupMessageCursor(Loc.GetString("plant-holder-component-empty-message",
("owner", usingItem)));
return true;
}
user.PopupMessageCursor(Loc.GetString(sprayed ? "plant-holder-component-spray-message" : "plant-holder-component-transfer-message",
("owner",Owner),
("amount",split.TotalVolume)));
user.PopupMessageCursor(Loc.GetString(
sprayed ? "plant-holder-component-spray-message" : "plant-holder-component-transfer-message",
("owner", Owner),
("amount", split.TotalVolume)));
_solutionContainer?.TryAddSolution(split);
solutionSystem.TryAddSolution(targetEntity, targetSolution, split);
ForceUpdateByExternalCause();
@@ -766,7 +779,8 @@ namespace Content.Server.Botany.Components
var seed = Seed.SpawnSeedPacket(user.Transform.Coordinates);
seed.RandomOffset(0.25f);
user.PopupMessageCursor(Loc.GetString("plant-holder-component-take-sample-message", ("seedName", Seed.DisplayName)));
user.PopupMessageCursor(Loc.GetString("plant-holder-component-take-sample-message",
("seedName", Seed.DisplayName)));
Health -= (_random.Next(3, 5) * 10);
if (_random.Prob(0.3f))
@@ -787,17 +801,18 @@ namespace Content.Server.Botany.Components
if (usingItem.HasComponent<ProduceComponent>())
{
user.PopupMessageCursor(Loc.GetString("plant-holder-component-compost-message",
("owner", Owner),
("usingItem", usingItem)));
("owner", Owner),
("usingItem", usingItem)));
user.PopupMessageOtherClients(Loc.GetString("plant-holder-component-compost-others-message",
("user",user),
("usingItem", usingItem),
("owner", Owner)));
("user", user),
("usingItem", usingItem),
("owner", Owner)));
if (usingItem.TryGetComponent(out SolutionContainerComponent? solution2))
if (solutionSystem.TryGetSolution(usingItem, ProduceComponent.SolutionName, out var solution2))
{
// This deliberately discards overfill.
_solutionContainer?.TryAddSolution(solution2.SplitSolution(solution2.Solution.TotalVolume));
solutionSystem.TryAddSolution(usingItem.Uid, solution2,
solutionSystem.SplitSolution(usingItem.Uid, solution2, solution2.TotalVolume));
ForceUpdateByExternalCause();
}
@@ -834,14 +849,17 @@ namespace Content.Server.Botany.Components
else if (!Dead)
{
message.AddMarkup(Loc.GetString("plant-holder-component-something-already-growing-message",
("seedName", Seed.DisplayName),
("toBeForm", Seed.DisplayName.EndsWith('s') ? "are" : "is"))
("seedName", Seed.DisplayName),
("toBeForm", Seed.DisplayName.EndsWith('s') ? "are" : "is"))
+ "\n");
if(Health <= Seed.Endurance / 2)
message.AddMarkup(Loc.GetString("plant-holder-component-something-already-growing-low-health-message",
("healthState", Loc.GetString(Age > Seed.Lifespan ? "plant-holder-component-plant-old-adjective" :
"plant-holder-component-plant-unhealthy-adjective")))
if (Health <= Seed.Endurance / 2)
message.AddMarkup(Loc.GetString(
"plant-holder-component-something-already-growing-low-health-message",
("healthState",
Loc.GetString(Age > Seed.Lifespan
? "plant-holder-component-plant-old-adjective"
: "plant-holder-component-plant-unhealthy-adjective")))
+ "\n");
}
else
@@ -849,30 +867,32 @@ namespace Content.Server.Botany.Components
message.AddMarkup(Loc.GetString("plant-holder-component-dead-plant-matter-message") + "\n");
}
if(WeedLevel >= 5)
if (WeedLevel >= 5)
message.AddMarkup(Loc.GetString("plant-holder-component-weed-high-level-message") + "\n");
if(PestLevel >= 5)
if (PestLevel >= 5)
message.AddMarkup(Loc.GetString("plant-holder-component-pest-high-level-message") + "\n");
message.AddMarkup(Loc.GetString($"plant-holder-component-water-level-message",("waterLevel", (int)WaterLevel)) + "\n");
message.AddMarkup(Loc.GetString($"plant-holder-component-nutrient-level-message", ("nutritionLevel", (int)NutritionLevel)) + "\n");
message.AddMarkup(Loc.GetString($"plant-holder-component-water-level-message",
("waterLevel", (int) WaterLevel)) + "\n");
message.AddMarkup(Loc.GetString($"plant-holder-component-nutrient-level-message",
("nutritionLevel", (int) NutritionLevel)) + "\n");
if (DrawWarnings)
{
if(Toxins > 40f)
if (Toxins > 40f)
message.AddMarkup(Loc.GetString("plant-holder-component-toxins-high-warning") + "\n");
if(ImproperLight)
if (ImproperLight)
message.AddMarkup(Loc.GetString("plant-holder-component-light-improper-warning") + "\n");
if(ImproperHeat)
if (ImproperHeat)
message.AddMarkup(Loc.GetString("plant-holder-component-heat-improper-warning") + "\n");
if(ImproperPressure)
if (ImproperPressure)
message.AddMarkup(Loc.GetString("plant-holder-component-pressure-improper-warning") + "\n");
if(_missingGas > 0)
if (_missingGas > 0)
message.AddMarkup(Loc.GetString("plant-holder-component-gas-missing-warning") + "\n");
}
}