using Content.Shared.Atmos; using Content.Shared.Botany.Components; using Content.Shared.Botany.Events; using Content.Shared.Random.Helpers; using JetBrains.Annotations; using Robust.Shared.Random; using Robust.Shared.Timing; namespace Content.Shared.Botany.Systems; /// /// Consumes and emits configured gases around plants each growth tick, then merges /// the adjusted gas mixture back into the environment. /// public abstract partial class SharedPlantConsumeExudeGasSystem : EntitySystem { [Dependency] private BotanySystem _botany = default!; [Dependency] private IGameTiming _timing = default!; [Dependency] private PlantMutationSystem _mutation = default!; [SubscribeLocalEvent] private void OnCrossPollinate(Entity ent, ref PlantCrossPollinateEvent args) { if (!_botany.TryGetPlantComponent(args.PollenData, args.PollenProtoId, out var pollenData)) return; _mutation.CrossGasses(ent, ref ent.Comp.ConsumeGasses, pollenData.ConsumeGasses); _mutation.CrossGasses(ent, ref ent.Comp.ExudeGasses, pollenData.ExudeGasses); Dirty(ent); } /// /// Adds a random amount of a random gas to the exude gasses. /// [PublicAPI] public void MutateRandomExudeGasses(Entity ent, float amount) { if (!Resolve(ent, ref ent.Comp, false)) return; var random = SharedRandomExtensions.PredictedRandom(_timing, GetNetEntity(ent)); var gas = random.Pick(Enum.GetValues()); var gasses = ent.Comp.ExudeGasses; if (!gasses.TryAdd(gas, amount)) gasses[gas] += amount; DirtyField(ent, nameof(ent.Comp.ExudeGasses)); } /// /// Adds a random amount of a random gas to the consume gasses. /// [PublicAPI] public void MutateRandomConsumeGasses(Entity ent, float amount) { if (!Resolve(ent, ref ent.Comp, false)) return; var random = SharedRandomExtensions.PredictedRandom(_timing, GetNetEntity(ent)); var gasses = ent.Comp.ConsumeGasses; var gas = random.Pick(Enum.GetValues()); if (!gasses.TryAdd(gas, amount)) gasses[gas] += amount; DirtyField(ent, nameof(ent.Comp.ConsumeGasses)); } }