Prevent erroneous materials from being placed in lathes. (#9454)

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
Nemanja
2022-07-06 23:44:31 -04:00
committed by GitHub
parent 9800701978
commit 52d2cc1de2
4 changed files with 44 additions and 6 deletions

View File

@@ -3,6 +3,9 @@ using Content.Shared.Research.Prototypes;
using Robust.Server.GameObjects;
using Content.Shared.Sound;
using Content.Shared.Whitelist;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
using Content.Shared.Materials;
namespace Content.Server.Lathe.Components
{
@@ -16,6 +19,13 @@ namespace Content.Server.Lathe.Components
[DataField("whitelist")]
public EntityWhitelist? LatheWhitelist;
/// <summary>
/// Whitelist generated on runtime for what items are specifically used for the lathe's recipes.
/// </summary>
[ViewVariables]
[DataField("materialWhiteList", customTypeSerializer: typeof(PrototypeIdListSerializer<MaterialPrototype>))]
public List<string> MaterialWhiteList = new();
/// <summary>
/// The lathe's construction queue
/// </summary>

View File

@@ -17,6 +17,7 @@ using Robust.Shared.Prototypes;
using Robust.Shared.Player;
using Robust.Shared.Audio;
using JetBrains.Annotations;
using System.Linq;
namespace Content.Server.Lathe
{
@@ -93,10 +94,26 @@ namespace Content.Server.Lathe
component.UserInterface.OnReceiveMessage += msg => UserInterfaceOnOnReceiveMessage(uid, component, msg);
}
if (!TryComp<AppearanceComponent>(uid, out var appearance))
if (TryComp<AppearanceComponent>(uid, out var appearance))
{
appearance.SetData(LatheVisuals.IsInserting, false);
appearance.SetData(LatheVisuals.IsRunning, false);
}
//Fix this awful shit once Lathes get ECS'd.
List<LatheRecipePrototype>? recipes = null;
if (TryComp<ProtolatheDatabaseComponent>(uid, out var database))
recipes = database.ProtolatheRecipes.ToList();
else if (TryComp<LatheDatabaseComponent>(uid, out var database2))
recipes = database2._recipes;
if (recipes == null)
return;
appearance.SetData(LatheVisuals.IsInserting, false);
appearance.SetData(LatheVisuals.IsRunning, false);
foreach (var recipe in recipes)
foreach (var mat in recipe.RequiredMaterials)
if (!component.MaterialWhiteList.Contains(mat.Key))
component.MaterialWhiteList.Add(mat.Key);
}
/// <summary>
@@ -110,6 +127,17 @@ namespace Content.Server.Lathe
|| component.LatheWhitelist?.IsValid(args.Used) == false)
return;
var matUsed = false;
foreach (var mat in material.Materials)
if (component.MaterialWhiteList.Contains(mat.ID))
matUsed = true;
if (!matUsed)
{
_popupSystem.PopupEntity(Loc.GetString("lathe-popup-material-not-used"), uid, Filter.Pvs(uid));
return;
}
var multiplier = 1;
if (TryComp<StackComponent>(args.Used, out var stack))

View File

@@ -11,8 +11,7 @@ namespace Content.Shared.Lathe
public abstract class SharedLatheDatabaseComponent : Component, IEnumerable<LatheRecipePrototype>, ISerializationHooks
{
[DataField("recipes", customTypeSerializer: typeof(PrototypeIdListSerializer<LatheRecipePrototype>))] private List<string> _recipeIds = new();
private readonly List<LatheRecipePrototype> _recipes = new();
public readonly List<LatheRecipePrototype> _recipes = new();
void ISerializationHooks.BeforeSerialization()
{

View File

@@ -0,0 +1 @@
lathe-popup-material-not-used = This material is not used in this lathe.