Make constructed hydro trays start empty (#19620)

This commit is contained in:
deltanedas
2023-09-05 21:15:06 +01:00
committed by GitHub
parent 048c7f8e04
commit 6d5c310b36
4 changed files with 941 additions and 928 deletions

View File

@@ -1,90 +1,93 @@
namespace Content.Server.Botany.Components
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
namespace Content.Server.Botany.Components;
[RegisterComponent]
public sealed partial class PlantHolderComponent : Component
{
[RegisterComponent]
public sealed partial class PlantHolderComponent : Component
{
[ViewVariables]
[DataField("nextUpdate", customTypeSerializer: typeof(TimeOffsetSerializer))]
public TimeSpan NextUpdate = TimeSpan.Zero;
[ViewVariables(VVAccess.ReadWrite), DataField("updateDelay")]
public TimeSpan UpdateDelay = TimeSpan.FromSeconds(3);
[ViewVariables]
[DataField("lastProduce")]
public int LastProduce;
[ViewVariables(VVAccess.ReadWrite)]
[ViewVariables(VVAccess.ReadWrite), DataField("missingGas")]
public int MissingGas;
public readonly TimeSpan CycleDelay = TimeSpan.FromSeconds(15f);
[DataField("cycleDelay")]
public TimeSpan CycleDelay = TimeSpan.FromSeconds(15f);
[ViewVariables]
[DataField("lastCycle", customTypeSerializer: typeof(TimeOffsetSerializer))]
public TimeSpan LastCycle = TimeSpan.Zero;
[ViewVariables(VVAccess.ReadWrite)]
[ViewVariables(VVAccess.ReadWrite), DataField("updateSpriteAfterUpdate")]
public bool UpdateSpriteAfterUpdate;
[ViewVariables(VVAccess.ReadWrite)] [DataField("drawWarnings")]
[ViewVariables(VVAccess.ReadWrite), DataField("drawWarnings")]
public bool DrawWarnings = false;
[ViewVariables(VVAccess.ReadWrite)]
[ViewVariables(VVAccess.ReadWrite), DataField("waterLevel")]
public float WaterLevel = 100f;
[ViewVariables(VVAccess.ReadWrite)]
[ViewVariables(VVAccess.ReadWrite), DataField("nutritionLevel")]
public float NutritionLevel = 100f;
[ViewVariables(VVAccess.ReadWrite)]
public float PestLevel { get; set; }
[ViewVariables(VVAccess.ReadWrite), DataField("pestLevel")]
public float PestLevel;
[ViewVariables(VVAccess.ReadWrite)]
public float WeedLevel { get; set; }
[ViewVariables(VVAccess.ReadWrite), DataField("weedLevel")]
public float WeedLevel;
[ViewVariables(VVAccess.ReadWrite)]
public float Toxins { get; set; }
[ViewVariables(VVAccess.ReadWrite), DataField("toxins")]
public float Toxins;
[ViewVariables(VVAccess.ReadWrite)]
public int Age { get; set; }
[ViewVariables(VVAccess.ReadWrite), DataField("age")]
public int Age;
[ViewVariables(VVAccess.ReadWrite)]
public int SkipAging { get; set; }
[ViewVariables(VVAccess.ReadWrite), DataField("skipAging")]
public int SkipAging;
[ViewVariables(VVAccess.ReadWrite)]
public bool Dead { get; set; }
[ViewVariables(VVAccess.ReadWrite), DataField("dead")]
public bool Dead;
[ViewVariables(VVAccess.ReadWrite)]
public bool Harvest { get; set; }
[ViewVariables(VVAccess.ReadWrite), DataField("harvest")]
public bool Harvest;
[ViewVariables(VVAccess.ReadWrite)]
public bool Sampled { get; set; }
[ViewVariables(VVAccess.ReadWrite), DataField("sampled")]
public bool Sampled;
[ViewVariables(VVAccess.ReadWrite)]
public int YieldMod { get; set; } = 1;
[ViewVariables(VVAccess.ReadWrite), DataField("yieldMod")]
public int YieldMod = 1;
[ViewVariables(VVAccess.ReadWrite)]
public float MutationMod { get; set; } = 1f;
[ViewVariables(VVAccess.ReadWrite), DataField("mutationMod")]
public float MutationMod = 1f;
[ViewVariables(VVAccess.ReadWrite)]
public float MutationLevel { get; set; }
[ViewVariables(VVAccess.ReadWrite), DataField("mutationLevel")]
public float MutationLevel;
[ViewVariables(VVAccess.ReadWrite)]
public float Health { get; set; }
[ViewVariables(VVAccess.ReadWrite), DataField("health")]
public float Health;
[ViewVariables(VVAccess.ReadWrite)]
public float WeedCoefficient { get; set; } = 1f;
[ViewVariables(VVAccess.ReadWrite), DataField("weedCoefficient")]
public float WeedCoefficient = 1f;
[ViewVariables(VVAccess.ReadWrite)]
public SeedData? Seed { get; set; }
[ViewVariables(VVAccess.ReadWrite), DataField("seed")]
public SeedData? Seed;
[ViewVariables(VVAccess.ReadWrite)]
public bool ImproperHeat { get; set; }
[ViewVariables(VVAccess.ReadWrite), DataField("improperHeat")]
public bool ImproperHeat;
[ViewVariables(VVAccess.ReadWrite)]
public bool ImproperPressure { get; set; }
[ViewVariables(VVAccess.ReadWrite), DataField("improperPressure")]
public bool ImproperPressure;
[ViewVariables(VVAccess.ReadWrite)]
public bool ImproperLight { get; set; }
[ViewVariables(VVAccess.ReadWrite), DataField("improperLight")]
public bool ImproperLight;
[ViewVariables(VVAccess.ReadWrite)]
public bool ForceUpdate { get; set; }
[ViewVariables(VVAccess.ReadWrite), DataField("forceUpdate")]
public bool ForceUpdate;
[DataField("solution")]
public string SoilSolutionName { get; set; } = "soil";
}
[ViewVariables(VVAccess.ReadWrite), DataField("solution")]
public string SoilSolutionName = "soil";
}

View File

@@ -25,16 +25,16 @@ using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Timing;
namespace Content.Server.Botany.Systems
namespace Content.Server.Botany.Systems;
public sealed class PlantHolderSystem : EntitySystem
{
public sealed class PlantHolderSystem : EntitySystem
{
[Dependency] private readonly BotanySystem _botanySystem = default!;
[Dependency] private readonly BotanySystem _botany = default!;
[Dependency] private readonly IPrototypeManager _prototype = default!;
[Dependency] private readonly MutationSystem _mutation = default!;
[Dependency] private readonly AppearanceSystem _appearance = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly TagSystem _tagSystem = default!;
[Dependency] private readonly SolutionContainerSystem _solutionSystem = default!;
@@ -133,12 +133,12 @@ namespace Content.Server.Botany.Systems
{
if (component.Seed == null)
{
if (!_botanySystem.TryGetSeed(seeds, out var seed))
if (!_botany.TryGetSeed(seeds, out var seed))
return;
var name = Loc.GetString(seed.Name);
var noun = Loc.GetString(seed.Noun);
_popupSystem.PopupCursor(Loc.GetString("plant-holder-component-plant-success-message",
_popup.PopupCursor(Loc.GetString("plant-holder-component-plant-success-message",
("seedName", name),
("seedNoun", noun)), args.User, PopupType.Medium);
@@ -148,7 +148,7 @@ namespace Content.Server.Botany.Systems
component.Health = component.Seed.Endurance;
component.LastCycle = _gameTiming.CurTime;
EntityManager.QueueDeleteEntity(args.Used);
QueueDel(args.Used);
CheckLevelSanity(uid, component);
UpdateSprite(uid, component);
@@ -156,7 +156,7 @@ namespace Content.Server.Botany.Systems
return;
}
_popupSystem.PopupCursor(Loc.GetString("plant-holder-component-already-seeded-message",
_popup.PopupCursor(Loc.GetString("plant-holder-component-already-seeded-message",
("name", Comp<MetaDataComponent>(uid).EntityName)), args.User, PopupType.Medium);
return;
}
@@ -165,16 +165,16 @@ namespace Content.Server.Botany.Systems
{
if (component.WeedLevel > 0)
{
_popupSystem.PopupCursor(Loc.GetString("plant-holder-component-remove-weeds-message",
_popup.PopupCursor(Loc.GetString("plant-holder-component-remove-weeds-message",
("name", Comp<MetaDataComponent>(uid).EntityName)), args.User, PopupType.Medium);
_popupSystem.PopupEntity(Loc.GetString("plant-holder-component-remove-weeds-others-message",
_popup.PopupEntity(Loc.GetString("plant-holder-component-remove-weeds-others-message",
("otherName", Comp<MetaDataComponent>(args.User).EntityName)), uid, Filter.PvsExcept(args.User), true);
component.WeedLevel = 0;
UpdateSprite(uid, component);
}
else
{
_popupSystem.PopupCursor(Loc.GetString("plant-holder-component-no-weeds-message"), args.User);
_popup.PopupCursor(Loc.GetString("plant-holder-component-no-weeds-message"), args.User);
}
return;
@@ -184,15 +184,15 @@ namespace Content.Server.Botany.Systems
{
if (component.Seed != null)
{
_popupSystem.PopupCursor(Loc.GetString("plant-holder-component-remove-plant-message",
_popup.PopupCursor(Loc.GetString("plant-holder-component-remove-plant-message",
("name", Comp<MetaDataComponent>(uid).EntityName)), args.User, PopupType.Medium);
_popupSystem.PopupEntity(Loc.GetString("plant-holder-component-remove-plant-others-message",
_popup.PopupEntity(Loc.GetString("plant-holder-component-remove-plant-others-message",
("name", Comp<MetaDataComponent>(args.User).EntityName)), uid, Filter.PvsExcept(args.User), true);
RemovePlant(uid, component);
}
else
{
_popupSystem.PopupCursor(Loc.GetString("plant-holder-component-no-plant-message",
_popup.PopupCursor(Loc.GetString("plant-holder-component-no-plant-message",
("name", Comp<MetaDataComponent>(uid).EntityName)), args.User);
}
@@ -214,12 +214,12 @@ namespace Content.Server.Botany.Systems
if (split.Volume == 0)
{
_popupSystem.PopupCursor(Loc.GetString("plant-holder-component-no-plant-message",
_popup.PopupCursor(Loc.GetString("plant-holder-component-no-plant-message",
("owner", args.Used)), args.User);
return;
}
_popupSystem.PopupCursor(Loc.GetString("plant-holder-component-spray-message",
_popup.PopupCursor(Loc.GetString("plant-holder-component-spray-message",
("owner", uid),
("amount", split.Volume)), args.User, PopupType.Medium);
@@ -234,27 +234,27 @@ namespace Content.Server.Botany.Systems
{
if (component.Seed == null)
{
_popupSystem.PopupCursor(Loc.GetString("plant-holder-component-nothing-to-sample-message"), args.User);
_popup.PopupCursor(Loc.GetString("plant-holder-component-nothing-to-sample-message"), args.User);
return;
}
if (component.Sampled)
{
_popupSystem.PopupCursor(Loc.GetString("plant-holder-component-already-sampled-message"), args.User);
_popup.PopupCursor(Loc.GetString("plant-holder-component-already-sampled-message"), args.User);
return;
}
if (component.Dead)
{
_popupSystem.PopupCursor(Loc.GetString("plant-holder-component-dead-plant-message"), args.User);
_popup.PopupCursor(Loc.GetString("plant-holder-component-dead-plant-message"), args.User);
return;
}
component.Seed.Unique = false;
var seed = _botanySystem.SpawnSeedPacket(component.Seed, Transform(args.User).Coordinates, args.User);
var seed = _botany.SpawnSeedPacket(component.Seed, Transform(args.User).Coordinates, args.User);
seed.RandomOffset(0.25f);
var displayName = Loc.GetString(component.Seed.DisplayName);
_popupSystem.PopupCursor(Loc.GetString("plant-holder-component-take-sample-message",
_popup.PopupCursor(Loc.GetString("plant-holder-component-take-sample-message",
("seedName", displayName)), args.User);
component.Health -= (_random.Next(3, 5) * 10);
@@ -278,10 +278,10 @@ namespace Content.Server.Botany.Systems
if (TryComp<ProduceComponent?>(args.Used, out var produce))
{
_popupSystem.PopupCursor(Loc.GetString("plant-holder-component-compost-message",
_popup.PopupCursor(Loc.GetString("plant-holder-component-compost-message",
("owner", uid),
("usingItem", args.Used)), args.User, PopupType.Medium);
_popupSystem.PopupEntity(Loc.GetString("plant-holder-component-compost-others-message",
_popup.PopupEntity(Loc.GetString("plant-holder-component-compost-others-message",
("user", Identity.Entity(args.User, EntityManager)),
("usingItem", args.Used),
("owner", uid)), uid, Filter.PvsExcept(args.User), true);
@@ -306,7 +306,7 @@ namespace Content.Server.Botany.Systems
var nutrientBonus = seed.Potency / 2.5f;
AdjustNutrient(uid, nutrientBonus, component);
}
EntityManager.QueueDeleteEntity(args.Used);
QueueDel(args.Used);
}
}
@@ -584,7 +584,7 @@ namespace Content.Server.Botany.Systems
else if (component.Age < 0) // Revert back to seed packet!
{
// will put it in the trays hands if it has any, please do not try doing this
_botanySystem.SpawnSeedPacket(component.Seed, Transform(uid).Coordinates, uid);
_botany.SpawnSeedPacket(component.Seed, Transform(uid).Coordinates, uid);
RemovePlant(uid, component);
component.ForceUpdate = true;
Update(uid, component);
@@ -667,15 +667,15 @@ namespace Content.Server.Botany.Systems
{
if (TryComp<HandsComponent>(user, out var hands))
{
if (!_botanySystem.CanHarvest(component.Seed, hands.ActiveHandEntity))
if (!_botany.CanHarvest(component.Seed, hands.ActiveHandEntity))
return false;
}
else if (!_botanySystem.CanHarvest(component.Seed))
else if (!_botany.CanHarvest(component.Seed))
{
return false;
}
_botanySystem.Harvest(component.Seed, user, component.YieldMod);
_botany.Harvest(component.Seed, user, component.YieldMod);
AfterHarvest(plantholder, component);
return true;
}
@@ -696,7 +696,7 @@ namespace Content.Server.Botany.Systems
if (component.Seed == null || !component.Harvest)
return;
_botanySystem.AutoHarvest(component.Seed, Transform(uid).Coordinates);
_botany.AutoHarvest(component.Seed, Transform(uid).Coordinates);
AfterHarvest(uid, component);
}
@@ -859,7 +859,7 @@ namespace Content.Server.Botany.Systems
light.Radius = component.Seed.BioluminescentRadius;
light.Color = component.Seed.BioluminescentColor;
light.CastShadows = false; // this is expensive, and botanists make lots of plants
Dirty(light);
Dirty(uid, light);
}
else
{
@@ -939,5 +939,4 @@ namespace Content.Server.Botany.Systems
component.ForceUpdate = true;
Update(uid, component);
}
}
}

View File

@@ -435,7 +435,7 @@
- type: Sprite
state: service
- type: MachineBoard
prototype: hydroponicsTray
prototype: HydroponicsTrayEmpty
materialRequirements:
# replacing the console screen
Glass: 5

View File

@@ -89,3 +89,14 @@
- type: GuideHelp
guides:
- Botany
- type: entity
parent: hydroponicsTray
id: HydroponicsTrayEmpty
suffix: Empty
components:
- type: PlantHolder
waterLevel: 0
nutritionLevel: 0
# for the lights to update immediately
updateSpriteAfterUpdate: true