]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Change plant clipping mechanics (#25326)
authorFlesh <62557990+PolterTzi@users.noreply.github.com>
Sat, 17 Feb 2024 05:02:12 +0000 (06:02 +0100)
committerGitHub <noreply@github.com>
Sat, 17 Feb 2024 05:02:12 +0000 (21:02 -0800)
Make seeds from clipped plants inherit the decreased health from parents.
Also require one growth stage before clipping.

Content.Server/Botany/Components/SeedComponent.cs
Content.Server/Botany/Systems/BotanySystem.Seed.cs
Content.Server/Botany/Systems/PlantHolderSystem.cs
Resources/Locale/en-US/botany/components/plant-holder-component.ftl

index 3e729dc90601398b2e795f1763cc7560d47e020e..f475ec3cfc445a67b1841eb062d6781545410b40 100644 (file)
@@ -15,6 +15,12 @@ namespace Content.Server.Botany.Components
         [DataField("seed")]
         public SeedData? Seed;
 
+        /// <summary>
+        ///     If not null, overrides the plant's initial health. Otherwise, the plant's initial health is set to the Endurance value.
+        /// </summary>
+        [DataField]
+        public float? HealthOverride = null;
+
         /// <summary>
         ///     Name of a base seed prototype that is used if <see cref="Seed"/> is null.
         /// </summary>
index c9389f832e71ecbe9280e260cb3bf41c2a441582..f64fcb3c43dc9478abf491ca3fd2a5893ea655b2 100644 (file)
@@ -104,11 +104,12 @@ public sealed partial class BotanySystem : EntitySystem
     /// <summary>
     /// Spawns a new seed packet on the floor at a position, then tries to put it in the user's hands if possible.
     /// </summary>
-    public EntityUid SpawnSeedPacket(SeedData proto, EntityCoordinates coords, EntityUid user)
+    public EntityUid SpawnSeedPacket(SeedData proto, EntityCoordinates coords, EntityUid user, float? healthOverride = null)
     {
         var seed = Spawn(proto.PacketPrototype, coords);
         var seedComp = EnsureComp<SeedComponent>(seed);
         seedComp.Seed = proto;
+        seedComp.HealthOverride = healthOverride;
 
         var name = Loc.GetString(proto.Name);
         var noun = Loc.GetString(proto.Noun);
index 601dca36856e6fa14c34c1a75bc44d3a05ba67a4..86f7be6d7b036cf8ed4768388e10d9ab3c75a796 100644 (file)
@@ -71,6 +71,17 @@ public sealed class PlantHolderSystem : EntitySystem
         }
     }
 
+    private int GetCurrentGrowthStage(Entity<PlantHolderComponent> entity)
+    {
+        var (uid, component) = entity;
+
+        if (component.Seed == null)
+            return 0;
+
+        var result = Math.Max(1, (int) (component.Age * component.Seed.GrowthStages / component.Seed.Maturation));
+        return result;
+    }
+
     private void OnExamine(Entity<PlantHolderComponent> entity, ref ExaminedEvent args)
     {
         if (!args.IsInDetailsRange)
@@ -148,6 +159,7 @@ public sealed class PlantHolderSystem : EntitySystem
                 if (!_botany.TryGetSeed(seeds, out var seed))
                     return;
 
+                float? seedHealth = seeds.HealthOverride;
                 var name = Loc.GetString(seed.Name);
                 var noun = Loc.GetString(seed.Noun);
                 _popup.PopupCursor(Loc.GetString("plant-holder-component-plant-success-message",
@@ -157,7 +169,14 @@ public sealed class PlantHolderSystem : EntitySystem
                 component.Seed = seed;
                 component.Dead = false;
                 component.Age = 1;
-                component.Health = component.Seed.Endurance;
+                if (seedHealth is float realSeedHealth)
+                {
+                    component.Health = realSeedHealth;
+                }
+                else
+                {
+                    component.Health = component.Seed.Endurance;
+                }
                 component.LastCycle = _gameTiming.CurTime;
 
                 QueueDel(args.Used);
@@ -262,16 +281,15 @@ public sealed class PlantHolderSystem : EntitySystem
                 return;
             }
 
-            component.Health -= (_random.Next(3, 5) * 10);
-
-            if (!component.Harvest)
+            if (GetCurrentGrowthStage(entity) <= 1)
             {
-                _popup.PopupCursor(Loc.GetString("plant-holder-component-early-sample"), args.User);
+                _popup.PopupCursor(Loc.GetString("plant-holder-component-early-sample-message"), args.User);
                 return;
             }
 
+            component.Health -= (_random.Next(3, 5) * 10);
             component.Seed.Unique = false;
-            var seed = _botany.SpawnSeedPacket(component.Seed, Transform(args.User).Coordinates, args.User);
+            var seed = _botany.SpawnSeedPacket(component.Seed, Transform(args.User).Coordinates, args.User, component.Health);
             _randomHelper.RandomOffset(seed, 0.25f);
             var displayName = Loc.GetString(component.Seed.DisplayName);
             _popup.PopupCursor(Loc.GetString("plant-holder-component-take-sample-message",
@@ -904,7 +922,7 @@ public sealed class PlantHolderSystem : EntitySystem
             }
             else if (component.Age < component.Seed.Maturation)
             {
-                var growthStage = Math.Max(1, (int) (component.Age * component.Seed.GrowthStages / component.Seed.Maturation));
+                var growthStage = GetCurrentGrowthStage((uid, component));
 
                 _appearance.SetData(uid, PlantHolderVisuals.PlantRsi, component.Seed.PlantRsi.ToString(), app);
                 _appearance.SetData(uid, PlantHolderVisuals.PlantState, $"stage-{growthStage}", app);
index 01d713ab34e435e9a6e43a4ede9c23c70470ab21..0e8c4137f4ed659b4fce4eab653b1f5839d80662 100644 (file)
@@ -32,4 +32,4 @@ plant-holder-component-light-improper-warning = The [color=yellow]improper light
 plant-holder-component-heat-improper-warning = The [color=orange]improper temperature level alert[/color] is blinking.
 plant-holder-component-pressure-improper-warning = The [color=lightblue]improper environment pressure alert[/color] is blinking.
 plant-holder-component-gas-missing-warning = The [color=cyan]improper gas environment alert[/color] is blinking.
-plant-holder-component-early-sample = It is not ready to sample, but you cut a bit of the plant anyway.
+plant-holder-component-early-sample-message = The plant hasn't grown enough to take a sample yet.