ECS botany except for plantholder (#6466)

This commit is contained in:
mirrorcult
2022-02-06 13:14:41 -07:00
committed by GitHub
parent f049305f0f
commit 19bbbefdf5
14 changed files with 566 additions and 566 deletions

View File

@@ -1,37 +1,19 @@
using System.Threading.Tasks;
using Content.Shared.ActionBlocker;
using Content.Shared.Interaction;
using Content.Shared.Random.Helpers;
using Content.Shared.Tag;
using Content.Server.Botany.Systems;
using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Server.Botany.Components
namespace Content.Server.Botany.Components;
// TODO: This should probably be merged with SliceableFood somehow or made into a more generic Choppable.
[RegisterComponent]
[Friend(typeof(LogSystem))]
public sealed class LogComponent : Component
{
[RegisterComponent]
public class LogComponent : Component, IInteractUsing
{
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
{
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(eventArgs.User))
return false;
[DataField("spawnedPrototype", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
public string SpawnedPrototype = "MaterialWoodPlank1";
var entMan = IoCManager.Resolve<IEntityManager>();
if (eventArgs.Using.HasTag("BotanySharp"))
{
for (var i = 0; i < 2; i++)
{
var plank = entMan.SpawnEntity("MaterialWoodPlank1", entMan.GetComponent<TransformComponent>(Owner).Coordinates);
plank.RandomOffset(0.25f);
}
entMan.QueueDeleteEntity(Owner);
return true;
}
return false;
}
}
[DataField("spawnCount")] public int SpawnCount = 2;
}

View File

@@ -2,6 +2,7 @@ using System;
using System.Threading.Tasks;
using Content.Server.Atmos;
using Content.Server.Atmos.EntitySystems;
using Content.Server.Botany.Systems;
using Content.Server.Chemistry.EntitySystems;
using Content.Server.Chemistry.Components;
using Content.Server.Fluids.Components;
@@ -107,7 +108,7 @@ namespace Content.Server.Botany.Components
public float WeedCoefficient { get; set; } = 1f;
[ViewVariables(VVAccess.ReadWrite)]
public Seed? Seed { get; set; }
public SeedPrototype? Seed { get; set; }
[ViewVariables(VVAccess.ReadWrite)]
public bool ImproperHeat { get; set; }
@@ -146,6 +147,8 @@ namespace Content.Server.Botany.Components
_lastCycle = curTime;
// todo ecs.
var botanySystem = EntitySystem.Get<BotanySystem>();
// Weeds like water and nutrients! They may appear even if there's not a seed planted.
if (WaterLevel > 10 && NutritionLevel > 2 && _random.Prob(Seed == null ? 0.05f : 0.01f))
@@ -272,7 +275,7 @@ namespace Content.Server.Botany.Components
}
}
// Seed pressure resistance.
// SeedPrototype pressure resistance.
var pressure = environment.Pressure;
if (pressure < Seed.LowPressureTolerance || pressure > Seed.HighPressureTolerance)
{
@@ -286,7 +289,7 @@ namespace Content.Server.Botany.Components
ImproperPressure = false;
}
// Seed ideal temperature.
// SeedPrototype ideal temperature.
if (MathF.Abs(environment.Temperature - Seed.IdealHeat) > Seed.HeatTolerance)
{
Health -= healthMod;
@@ -359,7 +362,7 @@ namespace Content.Server.Botany.Components
}
else if (Age < 0) // Revert back to seed packet!
{
Seed.SpawnSeedPacket(_entMan.GetComponent<TransformComponent>(Owner).Coordinates);
botanySystem.SpawnSeedPacket(Seed, _entMan.GetComponent<TransformComponent>(Owner).Coordinates);
RemovePlant();
ForceUpdate = true;
Update();
@@ -422,19 +425,21 @@ namespace Content.Server.Botany.Components
if (Seed == null || _entMan.Deleted(user) || !EntitySystem.Get<ActionBlockerSystem>().CanInteract(user))
return false;
var botanySystem = EntitySystem.Get<BotanySystem>();
if (Harvest && !Dead)
{
if (_entMan.TryGetComponent(user, out HandsComponent? hands))
{
if (!Seed.CheckHarvest(user, hands.GetActiveHandItem?.Owner))
if (!botanySystem.CanHarvest(Seed, hands.GetActiveHandItem?.Owner))
return false;
}
else if (!Seed.CheckHarvest(user))
else if (!botanySystem.CanHarvest(Seed))
{
return false;
}
Seed.Harvest(user, YieldMod);
botanySystem.Harvest(Seed, user, YieldMod);
AfterHarvest();
return true;
}
@@ -451,7 +456,9 @@ namespace Content.Server.Botany.Components
if (Seed == null || !Harvest)
return;
Seed.AutoHarvest(_entMan.GetComponent<TransformComponent>(Owner).Coordinates);
var botanySystem = EntitySystem.Get<BotanySystem>();
botanySystem.AutoHarvest(Seed, _entMan.GetComponent<TransformComponent>(Owner).Coordinates);
AfterHarvest();
}
@@ -633,7 +640,7 @@ namespace Content.Server.Botany.Components
// If this seed is not in the global seed list, then no products of this line have been harvested yet.
// It is then safe to assume it's restricted to this tray.
if (Seed == null) return;
var plantSystem = EntitySystem.Get<PlantSystem>();
var plantSystem = EntitySystem.Get<BotanySystem>();
if (plantSystem.Seeds.ContainsKey(Seed.Uid))
Seed = Seed.Diverge(modified);
}
@@ -653,22 +660,21 @@ namespace Content.Server.Botany.Components
if ((!_entMan.EntityExists(usingItem) ? EntityLifeStage.Deleted : _entMan.GetComponent<MetaDataComponent>(usingItem).EntityLifeStage) >= EntityLifeStage.Deleted || !EntitySystem.Get<ActionBlockerSystem>().CanInteract(user))
return false;
var botanySystem = EntitySystem.Get<BotanySystem>();
if (_entMan.TryGetComponent(usingItem, out SeedComponent? seeds))
{
if (Seed == null)
{
if (seeds.Seed == null)
{
user.PopupMessageCursor(Loc.GetString("plant-holder-component-empty-seed-packet-message"));
_entMan.QueueDeleteEntity(usingItem);
var protoMan = IoCManager.Resolve<IPrototypeManager>();
if (!protoMan.TryIndex<SeedPrototype>(seeds.SeedName, out var seed))
return false;
}
user.PopupMessageCursor(Loc.GetString("plant-holder-component-plant-success-message",
("seedName", seeds.Seed.SeedName),
("seedNoun", seeds.Seed.SeedNoun)));
("seedName", seed.SeedName),
("seedNoun", seed.SeedNoun)));
Seed = seeds.Seed;
Seed = seed;
Dead = false;
Age = 1;
Health = Seed.Endurance;
@@ -778,7 +784,7 @@ namespace Content.Server.Botany.Components
return false;
}
var seed = Seed.SpawnSeedPacket(_entMan.GetComponent<TransformComponent>(user).Coordinates);
var seed = botanySystem.SpawnSeedPacket(Seed, _entMan.GetComponent<TransformComponent>(user).Coordinates);
seed.RandomOffset(0.25f);
user.PopupMessageCursor(Loc.GetString("plant-holder-component-take-sample-message",
("seedName", Seed.DisplayName)));

View File

@@ -1,62 +1,15 @@
using Content.Server.Chemistry.EntitySystems;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Robust.Server.GameObjects;
using Content.Server.Botany.Systems;
using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Maths;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Content.Server.Botany.Components
namespace Content.Server.Botany.Components;
[RegisterComponent]
[Friend(typeof(BotanySystem))]
public sealed class ProduceComponent : Component
{
[RegisterComponent]
public class ProduceComponent : Component, ISerializationHooks
{
[DataField("targetSolution")] public string SolutionName { get; set; } = "food";
[DataField("targetSolution")] public string SolutionName { get; set; } = "food";
[DataField("seed")] private string? _seedName;
[ViewVariables]
public Seed? Seed
{
get => _seedName != null ? IoCManager.Resolve<IPrototypeManager>().Index<Seed>(_seedName) : null;
set => _seedName = value?.ID;
}
public float Potency => Seed?.Potency ?? 0;
public void Grown()
{
if (Seed == null)
return;
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out SpriteComponent? sprite))
{
sprite.LayerSetRSI(0, Seed.PlantRsi);
sprite.LayerSetState(0, Seed.PlantIconState);
}
var solutionContainer = EntitySystem.Get<SolutionContainerSystem>().EnsureSolution(Owner, SolutionName);
if (solutionContainer == null)
{
Logger.Warning($"No solution container found in {nameof(ProduceComponent)}.");
return;
}
solutionContainer.RemoveAllSolution();
foreach (var (chem, quantity) in Seed.Chemicals)
{
var amount = FixedPoint2.New(quantity.Min);
if (quantity.PotencyDivisor > 0 && Potency > 0)
amount += FixedPoint2.New(Potency / quantity.PotencyDivisor);
amount = FixedPoint2.New((int) MathHelper.Clamp(amount.Float(), quantity.Min, quantity.Max));
solutionContainer.MaxVolume += amount;
solutionContainer.AddReagent(chem, amount);
}
}
}
[DataField("seed", required: true)] public string SeedName = default!;
}

View File

@@ -1,51 +1,15 @@
using Content.Shared.Examine;
using Content.Server.Botany.Systems;
using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Server.Botany.Components
{
[RegisterComponent]
#pragma warning disable 618
public class SeedComponent : Component, IExamine
#pragma warning restore 618
[RegisterComponent, Friend(typeof(BotanySystem))]
public sealed class SeedComponent : Component
{
[DataField("seed")]
private string? _seedName;
[ViewVariables]
public Seed? Seed
{
get => _seedName != null ? IoCManager.Resolve<IPrototypeManager>().Index<Seed>(_seedName) : null;
set => _seedName = value?.ID;
}
public void Examine(FormattedMessage message, bool inDetailsRange)
{
if (!inDetailsRange)
return;
if (Seed == null)
{
message.AddMarkup(Loc.GetString("seed-component-no-seeds-message") + "\n");
return;
}
message.AddMarkup(Loc.GetString($"seed-component-description", ("seedName", Seed.DisplayName)) + "\n");
if (!Seed.RoundStart)
{
message.AddMarkup(Loc.GetString($"seed-component-has-variety-tag", ("seedUid", Seed.Uid)) + "\n");
}
else
{
message.AddMarkup(Loc.GetString($"seed-component-plant-yield-text", ("seedYield", Seed.Yield)) + "\n");
message.AddMarkup(Loc.GetString($"seed-component-plant-potency-text", ("seedPotency", Seed.Potency)) + "\n");
}
}
[DataField("seed", required: true, customTypeSerializer:typeof(PrototypeIdSerializer<SeedPrototype>))]
public string SeedName = default!;
}
}

View File

@@ -1,46 +1,16 @@
using System.Threading.Tasks;
using Content.Server.Power.Components;
using Content.Shared.Interaction;
using Content.Shared.Popups;
using Content.Server.Botany.Systems;
using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Random;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Server.Botany.Components
namespace Content.Server.Botany.Components;
[RegisterComponent]
[Friend(typeof(SeedExtractorSystem))]
public sealed class SeedExtractorComponent : Component
{
[RegisterComponent]
public class SeedExtractorComponent : Component, IInteractUsing
{
[Dependency] private readonly IEntityManager _entMan = default!;
[Dependency] private readonly IRobustRandom _random = default!;
// TODO: Upgradeable machines.
[DataField("minSeeds")] public int MinSeeds = 1;
// TODO: Upgradeable machines.
private int _minSeeds = 1;
private int _maxSeeds = 4;
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
{
if (!_entMan.TryGetComponent<ApcPowerReceiverComponent>(Owner, out var powerReceiverComponent) || !powerReceiverComponent.Powered)
return false;
if (_entMan.TryGetComponent(eventArgs.Using, out ProduceComponent? produce) && produce.Seed != null)
{
eventArgs.User.PopupMessageCursor(Loc.GetString("seed-extractor-component-interact-message",("name", _entMan.GetComponent<MetaDataComponent>(eventArgs.Using).EntityName)));
_entMan.QueueDeleteEntity(eventArgs.Using);
var random = _random.Next(_minSeeds, _maxSeeds);
for (var i = 0; i < random; i++)
{
produce.Seed.SpawnSeedPacket(_entMan.GetComponent<TransformComponent>(Owner).Coordinates, _entMan);
}
return true;
}
return false;
}
}
[DataField("maxSeeds")] public int MaxSeeds = 4;
}