Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Botany Rework Part 3: Plants as Entities #31941

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Content.Client/Botany/Components/PlantVisualsComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Content.Client.Botany.Components;

[RegisterComponent]
public sealed partial class PlantVisualsComponent : Component
{
}
4 changes: 2 additions & 2 deletions Content.Client/Botany/PlantHolderVisualizerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ protected override void OnAppearanceChange(EntityUid uid, PlantHolderVisualsComp
if (args.Sprite == null)
return;

if (AppearanceSystem.TryGetData<string>(uid, PlantHolderVisuals.PlantRsi, out var rsi, args.Component)
&& AppearanceSystem.TryGetData<string>(uid, PlantHolderVisuals.PlantState, out var state, args.Component))
if (AppearanceSystem.TryGetData<string>(uid, PlantVisuals.PlantRsi, out var rsi, args.Component)
&& AppearanceSystem.TryGetData<string>(uid, PlantVisuals.PlantState, out var state, args.Component))
{
var valid = !string.IsNullOrWhiteSpace(state);

Expand Down
48 changes: 48 additions & 0 deletions Content.Client/Botany/PlantVisualizerSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Content.Client.Botany.Components;
using Content.Shared.Botany;
using Robust.Client.GameObjects;

namespace Content.Client.Botany;

public sealed class PlantVisualizerSystem : VisualizerSystem<PlantVisualsComponent>
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<PlantVisualsComponent, ComponentInit>(OnComponentInit);
}

private void OnComponentInit(EntityUid uid, PlantVisualsComponent component, ComponentInit args)
{
if (!TryComp<SpriteComponent>(uid, out var sprite))
return;

sprite.LayerMapReserveBlank(PlantLayers.Plant);
sprite.LayerSetVisible(PlantLayers.Plant, false);
}

protected override void OnAppearanceChange(EntityUid uid, PlantVisualsComponent component, ref AppearanceChangeEvent args)
{
if (args.Sprite == null)
return;

if (AppearanceSystem.TryGetData<string>(uid, PlantVisuals.PlantRsi, out var rsi, args.Component)
&& AppearanceSystem.TryGetData<string>(uid, PlantVisuals.PlantState, out var state, args.Component))
{
var valid = !string.IsNullOrWhiteSpace(state);

args.Sprite.LayerSetVisible(PlantLayers.Plant, valid);

if (valid)
{
args.Sprite.LayerSetRSI(PlantLayers.Plant, rsi);
args.Sprite.LayerSetState(PlantLayers.Plant, state);
}
}
}
}

public enum PlantLayers : byte
{
Plant
}
55 changes: 55 additions & 0 deletions Content.Server/Botany/Components/PlantComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Content.Server.Botany.Systems;
using Content.Shared.EntityEffects;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;

namespace Content.Server.Botany.Components;

[RegisterComponent]
[Access(typeof(BotanySystem), typeof(PlantSystem), typeof(PlantHolderSystem), typeof(EntityEffect))]
public sealed partial class PlantComponent : Component
{
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer))]
public TimeSpan NextUpdate = TimeSpan.Zero;

[DataField]
public TimeSpan UpdateDelay = TimeSpan.FromSeconds(3);

[DataField]
public int LastProduce;

[DataField(customTypeSerializer: typeof(TimeOffsetSerializer))]
public TimeSpan LastCycle = TimeSpan.Zero;

[DataField]
public TimeSpan CycleDelay = TimeSpan.FromSeconds(15f);

[DataField]
public int Age = 1;

[DataField]
public bool Dead;

[DataField]
public bool Harvest;

[DataField]
public int SkipAging;

[DataField]
public bool Sampled;

[DataField]
public float MutationMod = 1f;

[DataField]
public float MutationLevel;

[DataField]
public float Health = 100;

[DataField]
public EntityUid? PlantHolderUid;

[DataField]
public SeedData? Seed;
}
40 changes: 4 additions & 36 deletions Content.Server/Botany/Components/PlantHolderComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ public sealed partial class PlantHolderComponent : Component
{
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer))]
public TimeSpan NextUpdate = TimeSpan.Zero;
[DataField]
public TimeSpan UpdateDelay = TimeSpan.FromSeconds(3);

[DataField]
public int LastProduce;
public TimeSpan UpdateDelay = TimeSpan.FromSeconds(3);

[DataField]
public int MissingGas;
Expand Down Expand Up @@ -44,48 +42,15 @@ public sealed partial class PlantHolderComponent : Component
[DataField]
public float Toxins;

[DataField]
public int Age;

[DataField]
public int SkipAging;

[DataField]
public bool Dead;

[DataField]
public bool Harvest;

[DataField]
public bool Sampled;

[DataField]
public int YieldMod = 1;

[DataField]
public float MutationMod = 1f;

[DataField]
public float MutationLevel;

[DataField]
public float Health;

[DataField]
public float WeedCoefficient = 1f;

[DataField]
public SeedData? Seed;

[DataField]
public bool ImproperHeat;

[DataField]
public bool ImproperPressure;

[DataField]
public bool ImproperLight;

[DataField]
public bool ForceUpdate;

Expand All @@ -94,4 +59,7 @@ public sealed partial class PlantHolderComponent : Component

[DataField]
public Entity<SolutionComponent>? SoilSolution = null;

[DataField]
public EntityUid? PlantUid;
}
3 changes: 2 additions & 1 deletion Content.Server/Botany/Components/SeedComponent.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using Content.Server.Botany.Systems;
using Content.Shared.Botany.Components;
using Content.Shared.EntityEffects;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;

namespace Content.Server.Botany.Components
{
[RegisterComponent, Access(typeof(BotanySystem))]
[RegisterComponent, Access(typeof(BotanySystem), typeof(PlantHolderSystem), typeof(PlantSystem), typeof(EntityEffect), typeof(BotanySwabSystem))]
public sealed partial class SeedComponent : SharedSeedComponent
{
/// <summary>
Expand Down
78 changes: 8 additions & 70 deletions Content.Server/Botany/SeedPrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,6 @@ public enum HarvestType : byte
SelfHarvest
}

/*
public enum PlantSpread : byte
{
NoSpread,
Creepers,
Vines,
}

public enum PlantMutation : byte
{
NoMutation,
Mutable,
HighlyMutable,
}

public enum PlantCarnivorous : byte
{
NotCarnivorous,
EatPests,
EatLivingBeings,
}

public enum PlantJuicy : byte
{
NotJuicy,
Juicy,
Slippery,
}
*/

[DataDefinition]
public partial struct SeedChemQuantity
{
Expand Down Expand Up @@ -81,56 +51,49 @@ public partial struct SeedChemQuantity

// TODO reduce the number of friends to a reasonable level. Requires ECS-ing things like plant holder component.
[Virtual, DataDefinition]
[Access(typeof(BotanySystem), typeof(PlantHolderSystem), typeof(SeedExtractorSystem), typeof(PlantHolderComponent), typeof(EntityEffect), typeof(MutationSystem))]
[Access(typeof(BotanySystem), typeof(PlantHolderSystem), typeof(SeedExtractorSystem), typeof(PlantHolderComponent), typeof(EntityEffect), typeof(MutationSystem), typeof(PlantSystem), typeof(BotanySwabSystem))]
public partial class SeedData
{
#region Tracking

/// <summary>
/// The name of this seed. Determines the name of seed packets.
/// </summary>
[DataField("name")]
[DataField]
public string Name { get; private set; } = "";

/// <summary>
/// The noun for this type of seeds. E.g. for fungi this should probably be "spores" instead of "seeds". Also
/// used to determine the name of seed packets.
/// </summary>
[DataField("noun")]
[DataField]
public string Noun { get; private set; } = "";

/// <summary>
/// Name displayed when examining the hydroponics tray. Describes the actual plant, not the seed itself.
/// </summary>
[DataField("displayName")]
[DataField]
public string DisplayName { get; private set; } = "";

[DataField("mysterious")] public bool Mysterious;
[DataField] public bool Mysterious;

/// <summary>
/// If true, the properties of this seed cannot be modified.
/// </summary>
[DataField("immutable")] public bool Immutable;

/// <summary>
/// If true, there is only a single reference to this seed and it's properties can be directly modified without
/// needing to clone the seed.
/// </summary>
[ViewVariables]
public bool Unique = false; // seed-prototypes or yaml-defined seeds for entity prototypes will not generally be unique.
[DataField] public bool Immutable;
#endregion

#region Output
/// <summary>
/// The entity prototype that is spawned when this type of seed is extracted from produce using a seed extractor.
/// </summary>
[DataField("packetPrototype", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
[DataField(customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
public string PacketPrototype = "SeedBase";

/// <summary>
/// The entity prototype this seed spawns when it gets harvested.
/// </summary>
[DataField("productPrototypes", customTypeSerializer: typeof(PrototypeIdListSerializer<EntityPrototype>))]
[DataField(customTypeSerializer: typeof(PrototypeIdListSerializer<EntityPrototype>))]
public List<string> ProductPrototypes = new();

[DataField] public Dictionary<string, SeedChemQuantity> Chemicals = new();
Expand All @@ -148,8 +111,6 @@ public partial class SeedData
[DataField] public float WaterConsumption = 0.5f;
[DataField] public float IdealHeat = 293f;
[DataField] public float HeatTolerance = 10f;
[DataField] public float IdealLight = 7f;
[DataField] public float LightTolerance = 3f;
[DataField] public float ToxinsTolerance = 4f;

[DataField] public float LowPressureTolerance = 81f;
Expand Down Expand Up @@ -195,19 +156,6 @@ public partial class SeedData
/// </summary>
[DataField] public bool Ligneous;

// No, I'm not removing these.
// if you re-add these, make sure that they get cloned.
//public PlantSpread Spread { get; set; }
//public PlantMutation Mutation { get; set; }
//public float AlterTemperature { get; set; }
//public PlantCarnivorous Carnivorous { get; set; }
//public bool Parasite { get; set; }
//public bool Hematophage { get; set; }
//public bool Thorny { get; set; }
//public bool Stinging { get; set; }
// public bool Teleporting { get; set; }
// public PlantJuicy Juicy { get; set; }

#endregion

#region Cosmetics
Expand Down Expand Up @@ -265,8 +213,6 @@ public SeedData Clone()
WaterConsumption = WaterConsumption,
IdealHeat = IdealHeat,
HeatTolerance = HeatTolerance,
IdealLight = IdealLight,
LightTolerance = LightTolerance,
ToxinsTolerance = ToxinsTolerance,
LowPressureTolerance = LowPressureTolerance,
HighPressureTolerance = HighPressureTolerance,
Expand All @@ -292,9 +238,6 @@ public SeedData Clone()
TurnIntoKudzu = TurnIntoKudzu,
SplatPrototype = SplatPrototype,
Mutations = new List<RandomPlantMutation>(),

// Newly cloned seed is unique. No need to unnecessarily clone if repeatedly modified.
Unique = true,
};

newSeed.Mutations.AddRange(Mutations);
Expand Down Expand Up @@ -326,8 +269,6 @@ public SeedData SpeciesChange(SeedData other)
WaterConsumption = WaterConsumption,
IdealHeat = IdealHeat,
HeatTolerance = HeatTolerance,
IdealLight = IdealLight,
LightTolerance = LightTolerance,
ToxinsTolerance = ToxinsTolerance,
LowPressureTolerance = LowPressureTolerance,
HighPressureTolerance = HighPressureTolerance,
Expand All @@ -354,9 +295,6 @@ public SeedData SpeciesChange(SeedData other)
CanScream = CanScream,
TurnIntoKudzu = TurnIntoKudzu,
SplatPrototype = other.SplatPrototype,

// Newly cloned seed is unique. No need to unnecessarily clone if repeatedly modified.
Unique = true,
};

// Adding the new chemicals from the new species.
Expand Down
Loading
Loading