Change plant clipping mechanics (#25326)

Make seeds from clipped plants inherit the decreased health from parents.
Also require one growth stage before clipping.
This commit is contained in:
Flesh
2024-02-17 06:02:12 +01:00
committed by GitHub
parent 95c9500630
commit dab2c48849
4 changed files with 34 additions and 9 deletions

View 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);