lathe machine upgrading (#12032)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user