lathe machine upgrading (#12032)
This commit is contained in:
@@ -25,7 +25,6 @@ public sealed partial class LatheMenu : DefaultWindow
|
||||
public event Action<string, int>? RecipeQueueAction;
|
||||
|
||||
public List<string> Recipes = new();
|
||||
private List<LatheRecipePrototype> _oldRecipesToShow = new();
|
||||
|
||||
public LatheMenu(LatheBoundUserInterface owner)
|
||||
{
|
||||
@@ -85,6 +84,9 @@ public sealed partial class LatheMenu : DefaultWindow
|
||||
/// <param name="lathe"></param>
|
||||
public void PopulateRecipes(EntityUid lathe)
|
||||
{
|
||||
if (!_entityManager.TryGetComponent<LatheComponent>(lathe, out var component))
|
||||
return;
|
||||
|
||||
var recipesToShow = new List<LatheRecipePrototype>();
|
||||
foreach (var recipe in Recipes)
|
||||
{
|
||||
@@ -106,7 +108,6 @@ public sealed partial class LatheMenu : DefaultWindow
|
||||
quantity = 1;
|
||||
|
||||
RecipeList.Children.Clear();
|
||||
_oldRecipesToShow = recipesToShow;
|
||||
foreach (var prototype in recipesToShow)
|
||||
{
|
||||
StringBuilder sb = new();
|
||||
@@ -121,7 +122,7 @@ public sealed partial class LatheMenu : DefaultWindow
|
||||
else
|
||||
sb.Append('\n');
|
||||
|
||||
sb.Append(amount);
|
||||
sb.Append((int) (amount * component.MaterialUseMultiplier));
|
||||
sb.Append(' ');
|
||||
sb.Append(proto.Name);
|
||||
}
|
||||
|
||||
@@ -7,9 +7,15 @@ namespace Content.Server.Lathe.Components;
|
||||
public sealed class LatheProducingComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// How much production time has passed, in seconds.
|
||||
/// The time at which production began
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float AccumulatedTime;
|
||||
public TimeSpan StartTime;
|
||||
|
||||
/// <summary>
|
||||
/// How long it takes to produce the recipe.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public TimeSpan ProductionLength;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,17 +10,20 @@ using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Prototypes;
|
||||
using JetBrains.Annotations;
|
||||
using System.Linq;
|
||||
using Content.Server.Construction;
|
||||
using Content.Server.Materials;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.Power.EntitySystems;
|
||||
using Content.Server.UserInterface;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Server.Lathe
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class LatheSystem : SharedLatheSystem
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly IPrototypeManager _proto = default!;
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
@@ -35,6 +38,7 @@ namespace Content.Server.Lathe
|
||||
SubscribeLocalEvent<LatheComponent, GetMaterialWhitelistEvent>(OnGetWhitelist);
|
||||
SubscribeLocalEvent<LatheComponent, MapInitEvent>(OnMapInit);
|
||||
SubscribeLocalEvent<LatheComponent, PowerChangedEvent>(OnPowerChanged);
|
||||
SubscribeLocalEvent<LatheComponent, RefreshPartsEvent>(OnPartsRefresh);
|
||||
|
||||
SubscribeLocalEvent<LatheComponent, LatheQueueRecipeMessage>(OnLatheQueueRecipeMessage);
|
||||
SubscribeLocalEvent<LatheComponent, LatheSyncRequestMessage>(OnLatheSyncRequestMessage);
|
||||
@@ -65,9 +69,7 @@ namespace Content.Server.Lathe
|
||||
if (lathe.CurrentRecipe == null)
|
||||
continue;
|
||||
|
||||
comp.AccumulatedTime += frameTime;
|
||||
|
||||
if (comp.AccumulatedTime >= (float) lathe.CurrentRecipe.CompleteTime.TotalSeconds)
|
||||
if ( _timing.CurTime - comp.StartTime >= comp.ProductionLength)
|
||||
FinishProducing(comp.Owner, lathe);
|
||||
}
|
||||
}
|
||||
@@ -132,7 +134,7 @@ namespace Content.Server.Lathe
|
||||
|
||||
foreach (var (mat, amount) in recipe.RequiredMaterials)
|
||||
{
|
||||
_materialStorage.TryChangeMaterialAmount(uid, mat, -amount);
|
||||
_materialStorage.TryChangeMaterialAmount(uid, mat, (int) (-amount * component.MaterialUseMultiplier));
|
||||
}
|
||||
component.Queue.Add(recipe);
|
||||
|
||||
@@ -149,7 +151,9 @@ namespace Content.Server.Lathe
|
||||
var recipe = component.Queue.First();
|
||||
component.Queue.RemoveAt(0);
|
||||
|
||||
EnsureComp<LatheProducingComponent>(uid);
|
||||
var lathe = EnsureComp<LatheProducingComponent>(uid);
|
||||
lathe.StartTime = _timing.CurTime;
|
||||
lathe.ProductionLength = recipe.CompleteTime * component.TimeMultiplier;
|
||||
component.CurrentRecipe = recipe;
|
||||
|
||||
_audio.PlayPvs(component.ProducingSound, component.Owner);
|
||||
@@ -166,7 +170,7 @@ namespace Content.Server.Lathe
|
||||
if (comp.CurrentRecipe != null)
|
||||
Spawn(comp.CurrentRecipe.Result, Transform(uid).Coordinates);
|
||||
comp.CurrentRecipe = null;
|
||||
prodComp.AccumulatedTime = 0;
|
||||
prodComp.StartTime = _timing.CurTime;
|
||||
|
||||
if (!TryStartProducing(uid, comp))
|
||||
{
|
||||
@@ -257,6 +261,17 @@ namespace Content.Server.Lathe
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPartsRefresh(EntityUid uid, LatheComponent component, RefreshPartsEvent args)
|
||||
{
|
||||
var printTimeRating = args.PartRatings[component.MachinePartPrintTime];
|
||||
var materialUseRating = args.PartRatings[component.MachinePartMaterialUse];
|
||||
|
||||
component.TimeMultiplier = MathF.Pow(component.PartRatingPrintTimeMultiplier, printTimeRating - 1);
|
||||
component.MaterialUseMultiplier = MathF.Pow(component.PartRatingMaterialUseMultiplier, materialUseRating - 1);
|
||||
Dirty(component);
|
||||
}
|
||||
|
||||
|
||||
protected override bool HasRecipe(EntityUid uid, LatheRecipePrototype recipe, LatheComponent component)
|
||||
{
|
||||
return GetAvailableRecipes(component).Contains(recipe.ID);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using Content.Shared.Construction.Prototypes;
|
||||
using Content.Shared.Research.Prototypes;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
|
||||
|
||||
namespace Content.Shared.Lathe
|
||||
@@ -56,7 +58,43 @@ namespace Content.Shared.Lathe
|
||||
[ViewVariables]
|
||||
public LatheRecipePrototype? CurrentRecipe;
|
||||
|
||||
#region MachineUpgrading
|
||||
/// <summary>
|
||||
/// A modifier that changes how long it takes to print a recipe
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float TimeMultiplier = 1;
|
||||
|
||||
/// <summary>
|
||||
/// The machine part that reduces how long it takes to print a recipe.
|
||||
/// </summary>
|
||||
[DataField("machinePartPrintSpeed", customTypeSerializer: typeof(PrototypeIdSerializer<MachinePartPrototype>))]
|
||||
public string MachinePartPrintTime = "Manipulator";
|
||||
|
||||
/// <summary>
|
||||
/// The value that is used to calculate the modified <see cref="TimeMultiplier"/>
|
||||
/// </summary>
|
||||
[DataField("partRatingPrintTimeMultiplier")]
|
||||
public float PartRatingPrintTimeMultiplier = 0.5f;
|
||||
|
||||
/// <summary>
|
||||
/// A modifier that changes how much of a material is needed to print a recipe
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float MaterialUseMultiplier = 1;
|
||||
|
||||
/// <summary>
|
||||
/// The machine part that reduces how much material it takes to print a recipe.
|
||||
/// </summary>
|
||||
[DataField("machinePartMaterialUse", customTypeSerializer: typeof(PrototypeIdSerializer<MachinePartPrototype>))]
|
||||
public string MachinePartMaterialUse = "MatterBin";
|
||||
|
||||
/// <summary>
|
||||
/// The value that is used to calculate the modifier <see cref="MaterialUseMultiplier"/>
|
||||
/// </summary>
|
||||
[DataField("partRatingMaterialUseMultiplier")]
|
||||
public float PartRatingMaterialUseMultiplier = 0.75f;
|
||||
#endregion
|
||||
}
|
||||
|
||||
public sealed class LatheGetRecipesEvent : EntityEventArgs
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using Content.Shared.Materials;
|
||||
using Content.Shared.Research.Prototypes;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Lathe;
|
||||
|
||||
@@ -13,6 +15,26 @@ public abstract class SharedLatheSystem : EntitySystem
|
||||
[Dependency] private readonly IPrototypeManager _proto = default!;
|
||||
[Dependency] private readonly SharedMaterialStorageSystem _materialStorage = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<LatheComponent, ComponentGetState>(OnGetState);
|
||||
SubscribeLocalEvent<LatheComponent, ComponentHandleState>(OnHandleState);
|
||||
}
|
||||
|
||||
private void OnGetState(EntityUid uid, LatheComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new LatheComponentState(component.MaterialUseMultiplier);
|
||||
}
|
||||
|
||||
private void OnHandleState(EntityUid uid, LatheComponent component, ref ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is not LatheComponentState state)
|
||||
return;
|
||||
component.MaterialUseMultiplier = state.MaterialUseMultiplier;
|
||||
}
|
||||
|
||||
[PublicAPI]
|
||||
public bool CanProduce(EntityUid uid, string recipe, int amount = 1, LatheComponent? component = null)
|
||||
{
|
||||
@@ -28,7 +50,7 @@ public abstract class SharedLatheSystem : EntitySystem
|
||||
|
||||
foreach (var (material, needed) in recipe.RequiredMaterials)
|
||||
{
|
||||
if (_materialStorage.GetMaterialAmount(component.Owner, material) < (amount * needed))
|
||||
if (_materialStorage.GetMaterialAmount(component.Owner, material) < amount * needed * component.MaterialUseMultiplier)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -36,3 +58,14 @@ public abstract class SharedLatheSystem : EntitySystem
|
||||
|
||||
protected abstract bool HasRecipe(EntityUid uid, LatheRecipePrototype recipe, LatheComponent component);
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class LatheComponentState : ComponentState
|
||||
{
|
||||
public float MaterialUseMultiplier;
|
||||
|
||||
public LatheComponentState(float materialUseMultiplier)
|
||||
{
|
||||
MaterialUseMultiplier = materialUseMultiplier;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,8 +94,7 @@
|
||||
prototype: UniformPrinter
|
||||
requirements:
|
||||
MatterBin: 1
|
||||
Manipulator: 1
|
||||
Laser: 1
|
||||
Laser: 2
|
||||
|
||||
- type: entity
|
||||
id: VaccinatorMachineCircuitboard
|
||||
|
||||
@@ -377,6 +377,7 @@
|
||||
- type: Lathe
|
||||
idleState: icon
|
||||
runningState: icon
|
||||
machinePartPrintSpeed: Laser
|
||||
dynamicRecipes:
|
||||
- HandheldHealthAnalyzer
|
||||
- ClothingHandsGlovesLatex
|
||||
|
||||
Reference in New Issue
Block a user