Seed extractor construction + upgrading (#11972)

This commit is contained in:
0x6273
2022-10-23 00:26:02 +02:00
committed by GitHub
parent d7bbcb07d4
commit 8718df5622
7 changed files with 81 additions and 11 deletions

View File

@@ -1,4 +1,7 @@
using Content.Server.Botany.Systems;
using Content.Server.Construction;
using Content.Shared.Construction.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Server.Botany.Components;
@@ -6,8 +9,34 @@ namespace Content.Server.Botany.Components;
[Access(typeof(SeedExtractorSystem))]
public sealed class SeedExtractorComponent : Component
{
// TODO: Upgradeable machines.
[DataField("minSeeds")] public int MinSeeds = 1;
/// <summary>
/// The minimum amount of seed packets dropped with no machine upgrades.
/// </summary>
[DataField("baseMinSeeds"), ViewVariables(VVAccess.ReadWrite)]
public int BaseMinSeeds = 1;
[DataField("maxSeeds")] public int MaxSeeds = 4;
/// <summary>
/// The maximum amount of seed packets dropped with no machine upgrades.
/// </summary>
[DataField("baseMaxSeeds"), ViewVariables(VVAccess.ReadWrite)]
public int BaseMaxSeeds = 3;
/// <summary>
/// Modifier to the amount of seeds outputted, set on <see cref="RefreshPartsEvent"/>.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public float SeedAmountMultiplier;
/// <summary>
/// Machine part whose rating modifies the amount of seed packets dropped.
/// </summary>
[DataField("machinePartYieldAmount", customTypeSerializer: typeof(PrototypeIdSerializer<MachinePartPrototype>))]
public string MachinePartSeedAmount = "Manipulator";
/// <summary>
/// How much the machine part quality affects the amount of seeds outputted.
/// Going up a tier will multiply the seed output by this amount.
/// </summary>
[DataField("partRatingSeedAmountMultiplier"), ViewVariables]
public float PartRatingSeedAmountMultiplier = 1.5f;
}

View File

@@ -1,6 +1,6 @@
using Content.Server.Botany.Components;
using Content.Server.Construction;
using Content.Server.Popups;
using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems;
using Content.Shared.Interaction;
using Content.Shared.Popups;
@@ -20,9 +20,10 @@ public sealed class SeedExtractorSystem : EntitySystem
base.Initialize();
SubscribeLocalEvent<SeedExtractorComponent, InteractUsingEvent>(OnInteractUsing);
SubscribeLocalEvent<SeedExtractorComponent, RefreshPartsEvent>(OnRefreshParts);
}
private void OnInteractUsing(EntityUid uid, SeedExtractorComponent component, InteractUsingEvent args)
private void OnInteractUsing(EntityUid uid, SeedExtractorComponent seedExtractor, InteractUsingEvent args)
{
if (!this.IsPowered(uid, EntityManager))
return;
@@ -40,15 +41,21 @@ public sealed class SeedExtractorSystem : EntitySystem
QueueDel(args.Used);
var random = _random.Next(component.MinSeeds, component.MaxSeeds);
var amount = (int) _random.NextFloat(seedExtractor.BaseMinSeeds, seedExtractor.BaseMaxSeeds + 1) * seedExtractor.SeedAmountMultiplier;
var coords = Transform(uid).Coordinates;
if (random > 1)
if (amount > 1)
seed.Unique = false;
for (var i = 0; i < random; i++)
for (var i = 0; i < amount; i++)
{
_botanySystem.SpawnSeedPacket(seed, coords);
}
}
private void OnRefreshParts(EntityUid uid, SeedExtractorComponent seedExtractor, RefreshPartsEvent args)
{
var manipulatorQuality = args.PartRatings[seedExtractor.MachinePartSeedAmount];
seedExtractor.SeedAmountMultiplier = MathF.Pow(seedExtractor.PartRatingSeedAmountMultiplier, manipulatorQuality - 1);
}
}