Skip to content

Commit

Permalink
Change plant clipping mechanics (space-wizards#25326)
Browse files Browse the repository at this point in the history
Make seeds from clipped plants inherit the decreased health from parents.
Also require one growth stage before clipping.
  • Loading branch information
PolterTzi authored and joshepvodka committed Feb 18, 2024
1 parent 6478a46 commit 845cff0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
6 changes: 6 additions & 0 deletions Content.Server/Botany/Components/SeedComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ public sealed partial class SeedComponent : SharedSeedComponent
[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>
Expand Down
3 changes: 2 additions & 1 deletion Content.Server/Botany/Systems/BotanySystem.Seed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,12 @@ private void OnExamined(EntityUid uid, SeedComponent component, ExaminedEvent ar
/// <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);
Expand Down
32 changes: 25 additions & 7 deletions Content.Server/Botany/Systems/PlantHolderSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ public override void Update(float frameTime)
}
}

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)
Expand Down Expand Up @@ -148,6 +159,7 @@ private void OnInteractUsing(Entity<PlantHolderComponent> entity, ref InteractUs
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",
Expand All @@ -157,7 +169,14 @@ private void OnInteractUsing(Entity<PlantHolderComponent> entity, ref InteractUs
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);
Expand Down Expand Up @@ -262,16 +281,15 @@ private void OnInteractUsing(Entity<PlantHolderComponent> entity, ref InteractUs
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",
Expand Down Expand Up @@ -904,7 +922,7 @@ public void UpdateSprite(EntityUid uid, PlantHolderComponent? component = null)
}
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit 845cff0

Please sign in to comment.