Flatpacks and the Flatpacker 1001 (#23338)

* Flatpacker and flatpacks

* ok that's good enough

* convert solars/AME to flatpacks

* mats, mats, we are the mats

* basic mechanics are DONE

* thing

* final UI

* sloth

* rped jumpscare

* rename
This commit is contained in:
Nemanja
2024-01-03 01:16:02 -05:00
committed by GitHub
parent 04fc06e9d4
commit 1c11332fa4
40 changed files with 1066 additions and 101 deletions

View File

@@ -1,6 +1,10 @@
using System.Linq;
using Content.Shared.Construction.Components;
using Content.Shared.Construction.Prototypes;
using Content.Shared.Examine;
using Content.Shared.Lathe;
using Content.Shared.Materials;
using Content.Shared.Stacks;
using Robust.Shared.Prototypes;
namespace Content.Shared.Construction
@@ -11,6 +15,7 @@ namespace Content.Shared.Construction
public sealed class MachinePartSystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _prototype = default!;
[Dependency] private readonly SharedLatheSystem _lathe = default!;
public override void Initialize()
{
@@ -61,5 +66,87 @@ namespace Content.Shared.Construction
args.PushMarkup(Loc.GetString("machine-part-component-on-examine-type-text", ("type",
Loc.GetString(_prototype.Index<MachinePartPrototype>(component.PartType).Name))));
}
public Dictionary<string, int> GetMachineBoardMaterialCost(Entity<MachineBoardComponent> entity, int coefficient = 1)
{
var (_, comp) = entity;
var materials = new Dictionary<string, int>();
foreach (var (partId, amount) in comp.Requirements)
{
var partProto = _prototype.Index<MachinePartPrototype>(partId);
if (!_lathe.TryGetRecipesFromEntity(partProto.StockPartPrototype, out var recipes))
continue;
var partRecipe = recipes[0];
if (recipes.Count > 1)
partRecipe = recipes.MinBy(p => p.RequiredMaterials.Values.Sum());
foreach (var (mat, matAmount) in partRecipe!.RequiredMaterials)
{
materials.TryAdd(mat, 0);
materials[mat] += matAmount * amount * coefficient;
}
}
foreach (var (stackId, amount) in comp.MaterialIdRequirements)
{
var stackProto = _prototype.Index<StackPrototype>(stackId);
if (_prototype.TryIndex(stackProto.Spawn, out var defaultProto) &&
defaultProto.TryGetComponent<PhysicalCompositionComponent>(out var physComp))
{
foreach (var (mat, matAmount) in physComp.MaterialComposition)
{
materials.TryAdd(mat, 0);
materials[mat] += matAmount * amount * coefficient;
}
}
else if (_lathe.TryGetRecipesFromEntity(stackProto.Spawn, out var recipes))
{
var partRecipe = recipes[0];
if (recipes.Count > 1)
partRecipe = recipes.MinBy(p => p.RequiredMaterials.Values.Sum());
foreach (var (mat, matAmount) in partRecipe!.RequiredMaterials)
{
materials.TryAdd(mat, 0);
materials[mat] += matAmount * amount * coefficient;
}
}
}
var genericPartInfo = comp.ComponentRequirements.Values.Concat(comp.ComponentRequirements.Values);
foreach (var info in genericPartInfo)
{
var amount = info.Amount;
var defaultProtoId = info.DefaultPrototype;
if (_lathe.TryGetRecipesFromEntity(defaultProtoId, out var recipes))
{
var partRecipe = recipes[0];
if (recipes.Count > 1)
partRecipe = recipes.MinBy(p => p.RequiredMaterials.Values.Sum());
foreach (var (mat, matAmount) in partRecipe!.RequiredMaterials)
{
materials.TryAdd(mat, 0);
materials[mat] += matAmount * amount * coefficient;
}
}
else if (_prototype.TryIndex(defaultProtoId, out var defaultProto) &&
defaultProto.TryGetComponent<PhysicalCompositionComponent>(out var physComp))
{
foreach (var (mat, matAmount) in physComp.MaterialComposition)
{
materials.TryAdd(mat, 0);
materials[mat] += matAmount * amount * coefficient;
}
}
}
return materials;
}
}
}