2021-09-06 15:49:44 +02:00
|
|
|
using Content.Shared.Chemistry.EntitySystems;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Chemistry.Reagent;
|
2020-10-26 23:19:46 +01:00
|
|
|
using Robust.Server.GameObjects;
|
|
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
using Robust.Shared.IoC;
|
2021-09-06 15:49:44 +02:00
|
|
|
using Robust.Shared.Log;
|
2020-10-26 23:19:46 +01:00
|
|
|
using Robust.Shared.Maths;
|
|
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
using Robust.Shared.Serialization;
|
2021-03-05 01:08:38 +01:00
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2020-10-26 23:19:46 +01:00
|
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Botany.Components
|
2020-10-26 23:19:46 +01:00
|
|
|
{
|
|
|
|
|
[RegisterComponent]
|
2021-03-05 01:08:38 +01:00
|
|
|
public class ProduceComponent : Component, ISerializationHooks
|
2020-10-26 23:19:46 +01:00
|
|
|
{
|
2021-03-05 01:08:38 +01:00
|
|
|
public override string Name => "Produce";
|
2021-09-06 15:49:44 +02:00
|
|
|
public const string SolutionName = "produce";
|
2020-10-26 23:19:46 +01:00
|
|
|
|
2021-09-06 15:49:44 +02:00
|
|
|
[DataField("seed")] private string? _seedName;
|
2020-10-26 23:19:46 +01:00
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
[ViewVariables]
|
|
|
|
|
public Seed? Seed
|
2020-10-26 23:19:46 +01:00
|
|
|
{
|
2021-03-05 01:08:38 +01:00
|
|
|
get => _seedName != null ? IoCManager.Resolve<IPrototypeManager>().Index<Seed>(_seedName) : null;
|
|
|
|
|
set => _seedName = value?.ID;
|
2020-10-26 23:19:46 +01:00
|
|
|
}
|
|
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
public float Potency => Seed?.Potency ?? 0;
|
|
|
|
|
|
2020-10-26 23:19:46 +01:00
|
|
|
public void Grown()
|
|
|
|
|
{
|
|
|
|
|
if (Seed == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
if (Owner.TryGetComponent(out SpriteComponent? sprite))
|
2020-10-26 23:19:46 +01:00
|
|
|
{
|
|
|
|
|
sprite.LayerSetRSI(0, Seed.PlantRsi);
|
|
|
|
|
sprite.LayerSetState(0, Seed.PlantIconState);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-06 15:49:44 +02:00
|
|
|
EntitySystem.Get<SolutionContainerSystem>().RemoveAllSolution(Owner.Uid);
|
|
|
|
|
var solutionContainer = EntitySystem.Get<SolutionContainerSystem>().EnsureSolution(Owner, SolutionName);
|
|
|
|
|
if (solutionContainer == null)
|
|
|
|
|
{
|
|
|
|
|
Logger.Warning($"No solution container found in {nameof(ProduceComponent)}.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-10-26 23:19:46 +01:00
|
|
|
|
|
|
|
|
foreach (var (chem, quantity) in Seed.Chemicals)
|
|
|
|
|
{
|
|
|
|
|
var amount = ReagentUnit.New(quantity.Min);
|
2021-09-06 15:49:44 +02:00
|
|
|
if (quantity.PotencyDivisor > 0 && Potency > 0)
|
|
|
|
|
amount += ReagentUnit.New(Potency / quantity.PotencyDivisor);
|
2020-10-26 23:19:46 +01:00
|
|
|
amount = ReagentUnit.New((int) MathHelper.Clamp(amount.Float(), quantity.Min, quantity.Max));
|
|
|
|
|
solutionContainer.MaxVolume += amount;
|
2021-09-06 15:49:44 +02:00
|
|
|
solutionContainer.AddReagent(chem, amount);
|
2020-10-26 23:19:46 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|