Add material arbitrage tests (#13315)

This commit is contained in:
Leon Friedrich
2023-01-15 21:57:59 +13:00
committed by GitHub
parent 9f3256730d
commit cf509c1e38
28 changed files with 415 additions and 34 deletions

View File

@@ -4,6 +4,7 @@ using JetBrains.Annotations;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using System.Net.Mail;
namespace Content.Shared.Lathe;
@@ -50,9 +51,7 @@ public abstract class SharedLatheSystem : EntitySystem
foreach (var (material, needed) in recipe.RequiredMaterials)
{
var adjustedAmount = recipe.ApplyMaterialDiscount
? (int) (needed * component.MaterialUseMultiplier)
: needed;
var adjustedAmount = AdjustMaterial(needed, recipe.ApplyMaterialDiscount, component.MaterialUseMultiplier);
if (_materialStorage.GetMaterialAmount(component.Owner, material) < adjustedAmount * amount)
return false;
@@ -60,6 +59,9 @@ public abstract class SharedLatheSystem : EntitySystem
return true;
}
public static int AdjustMaterial(int original, bool reduce, float multiplier)
=> reduce ? (int) MathF.Ceiling(original * multiplier) : original;
protected abstract bool HasRecipe(EntityUid uid, LatheRecipePrototype recipe, LatheComponent component);
}