Files

147 lines
6.0 KiB
C#
Raw Permalink Normal View History

using System.Linq;
using Content.Shared.Construction.Components;
2023-04-28 23:23:49 -04:00
using Content.Shared.Construction.Prototypes;
2022-04-08 17:17:25 -04:00
using Content.Shared.Examine;
using Content.Shared.Lathe;
using Content.Shared.Materials;
using Content.Shared.Stacks;
2023-04-28 23:23:49 -04:00
using Robust.Shared.Prototypes;
2022-04-08 17:17:25 -04:00
namespace Content.Shared.Construction
2022-04-08 17:17:25 -04:00
{
/// <summary>
/// Deals with machine parts and machine boards.
/// </summary>
public sealed class MachinePartSystem : EntitySystem
{
2023-04-28 23:23:49 -04:00
[Dependency] private readonly IPrototypeManager _prototype = default!;
[Dependency] private readonly SharedLatheSystem _lathe = default!;
2023-04-28 23:23:49 -04:00
2022-04-08 17:17:25 -04:00
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<MachineBoardComponent, ExaminedEvent>(OnMachineBoardExamined);
}
private void OnMachineBoardExamined(EntityUid uid, MachineBoardComponent component, ExaminedEvent args)
{
if (!args.IsInDetailsRange)
return;
using (args.PushGroup(nameof(MachineBoardComponent)))
2022-04-08 17:17:25 -04:00
{
args.PushMarkup(Loc.GetString("machine-board-component-on-examine-label"));
foreach (var (part, amount) in component.Requirements)
{
args.PushMarkup(Loc.GetString("machine-board-component-required-element-entry-text",
("amount", amount),
("requiredElement", Loc.GetString(_prototype.Index<MachinePartPrototype>(part).Name))));
}
2022-04-08 17:17:25 -04:00
foreach (var (material, amount) in component.MaterialRequirements)
{
args.PushMarkup(Loc.GetString("machine-board-component-required-element-entry-text",
("amount", amount),
("requiredElement", Loc.GetString(material.Name))));
}
2022-04-08 17:17:25 -04:00
foreach (var (_, info) in component.ComponentRequirements)
{
args.PushMarkup(Loc.GetString("machine-board-component-required-element-entry-text",
("amount", info.Amount),
("requiredElement", Loc.GetString(info.ExamineName))));
}
foreach (var (_, info) in component.TagRequirements)
{
args.PushMarkup(Loc.GetString("machine-board-component-required-element-entry-text",
("amount", info.Amount),
("requiredElement", Loc.GetString(info.ExamineName))));
}
2022-04-08 17:17:25 -04:00
}
}
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);
Cherrypicks 5 (#399) * Give moldy food the "Trash" tag (#29380) Make moldy food items have the "Trash" tag, so they can be collected. * Add "Structure" tag to switches, buttons, and levers (#29378) shit Co-authored-by: Eoin Mcloughlin <helloworld@eoinrul.es> * Revamped Meteor Swarm (#28974) * meteor code and balanced values * Meteor Swarms * Update meteors.yml * Update meteors.yml * HOO! (fix overkill bug and buff space dust) * undo BloodstreamComponent.cs changes * DamageDistribution -> DamageTypes * part 2. * meteor fixes * improve meteor spawning (#29057) * Decrease meteor frequency (#29194) * Make Projectiles Only Hit a Variety of Station Objects Unless Clicked on (#28571) * Revert "Make Projectiles Only Hit a Variety of Station Objects Unless Clicked on (#28571)" This reverts commit 4f934f02f17ce55cabc03b965eb1df7738d63148. * Makes machine parts stackable, removes unused field in stack prototypes (#28434) * Makes machine parts stacks, removes unused field in stack prototypes * forgor * Fix tests * Fixes lathe construction. Yes. This sucks but there's no better way that doesnt involve refactoring machine parts completely * detail * a * Add pressure and temperature warning text to firelocks (#28341) * fix firelocks * missing nukies can be filled in by ghost roles (#28316) * Revert "missing nukies can be filled in by ghost roles (#28316)" This reverts commit 99f13e1e45bc778a4941316fde5d89d7b91337ce. * welding gas mask (#27108) * welding gas mask * eek * Canes + Cane Blade for Syndicate Librarians (#25873) * Cane + Cane Blade * Add - type: ContainerContainer * Add another - type: ContainerContainer * Fix and add proper ContainerContainer component * Add UserInterface component * Remove Space * Stat Changes * review --------- Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com> * Fix stupid NPC. (#26868) * init commit * Review --------- Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com> * fixes --------- Co-authored-by: VeritableCalamity <34698192+Veritable-Calamity@users.noreply.github.com> Co-authored-by: eoineoineoin <github@eoinrul.es> Co-authored-by: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> Co-authored-by: Cojoke <83733158+Cojoke-dot@users.noreply.github.com> Co-authored-by: AJCM-git <60196617+AJCM-git@users.noreply.github.com> Co-authored-by: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com> Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com> Co-authored-by: Ps3Moira <113228053+ps3moira@users.noreply.github.com> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com> Co-authored-by: Vigers Ray <60344369+VigersRay@users.noreply.github.com>
2024-06-30 10:04:27 +03:00
var defaultProto = _prototype.Index(stackProto.Spawn);
Cherrypicks 5 (#399) * Give moldy food the "Trash" tag (#29380) Make moldy food items have the "Trash" tag, so they can be collected. * Add "Structure" tag to switches, buttons, and levers (#29378) shit Co-authored-by: Eoin Mcloughlin <helloworld@eoinrul.es> * Revamped Meteor Swarm (#28974) * meteor code and balanced values * Meteor Swarms * Update meteors.yml * Update meteors.yml * HOO! (fix overkill bug and buff space dust) * undo BloodstreamComponent.cs changes * DamageDistribution -> DamageTypes * part 2. * meteor fixes * improve meteor spawning (#29057) * Decrease meteor frequency (#29194) * Make Projectiles Only Hit a Variety of Station Objects Unless Clicked on (#28571) * Revert "Make Projectiles Only Hit a Variety of Station Objects Unless Clicked on (#28571)" This reverts commit 4f934f02f17ce55cabc03b965eb1df7738d63148. * Makes machine parts stackable, removes unused field in stack prototypes (#28434) * Makes machine parts stacks, removes unused field in stack prototypes * forgor * Fix tests * Fixes lathe construction. Yes. This sucks but there's no better way that doesnt involve refactoring machine parts completely * detail * a * Add pressure and temperature warning text to firelocks (#28341) * fix firelocks * missing nukies can be filled in by ghost roles (#28316) * Revert "missing nukies can be filled in by ghost roles (#28316)" This reverts commit 99f13e1e45bc778a4941316fde5d89d7b91337ce. * welding gas mask (#27108) * welding gas mask * eek * Canes + Cane Blade for Syndicate Librarians (#25873) * Cane + Cane Blade * Add - type: ContainerContainer * Add another - type: ContainerContainer * Fix and add proper ContainerContainer component * Add UserInterface component * Remove Space * Stat Changes * review --------- Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com> * Fix stupid NPC. (#26868) * init commit * Review --------- Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com> * fixes --------- Co-authored-by: VeritableCalamity <34698192+Veritable-Calamity@users.noreply.github.com> Co-authored-by: eoineoineoin <github@eoinrul.es> Co-authored-by: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> Co-authored-by: Cojoke <83733158+Cojoke-dot@users.noreply.github.com> Co-authored-by: AJCM-git <60196617+AJCM-git@users.noreply.github.com> Co-authored-by: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com> Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com> Co-authored-by: Ps3Moira <113228053+ps3moira@users.noreply.github.com> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com> Co-authored-by: Vigers Ray <60344369+VigersRay@users.noreply.github.com>
2024-06-30 10:04:27 +03:00
if (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;
}
2022-04-08 17:17:25 -04:00
}
}