mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 13:37:47 +03:00
<!-- This is a semi-strict format, you can add/remove sections as needed but the order/format should be kept the same Remove these comments before submitting --> # Description <!-- Explain this PR in as much detail as applicable Some example prompts to consider: How might this affect the game? The codebase? What might be some alternatives to this? How/Who does this benefit/hurt [the game/codebase]? --> Originally started because I wanted to add some stuff to salvage, but ended up with me porting over whitelisted borg hands, the PKA module, and some other stuff. --- # Changelog <!-- You can add an author after the `🆑` to change the name that appears in the changelog (ex: `🆑 Death`) Leaving it blank will default to your GitHub display name This includes all available types for the changelog --> 🆑 - add: Engi borgs can now carry electronics, and medical borgs can carry organs - add: Salvage borgs now get a PKA module - tweak: All mining drills have had their damage turned to piercing and have received a moderate damage buff - tweak: Exosuit drills now swing at the same speed as normal drills (why were they worse???) - tweak: The RPD and RCD modules for borg have been merged into one - tweak: Salvage can now purchase drills from their vendor - tweak: Salvage borgs mining module no longer contains a shovel --------- Co-authored-by: Your Name <EctoplasmIsGood@users.noreply.github.com> Co-authored-by: Whatstone <whatston3@gmail.com> Co-authored-by: RatherUncreative <RatherUncreativeName@proton.me> Co-authored-by: Aidenkrz <aiden@djkraz.com> (cherry picked from commit ed8850e551bd9c0d533d69cad262a8743442a62a)
161 lines
6.6 KiB
C#
161 lines
6.6 KiB
C#
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
|
|
{
|
|
/// <summary>
|
|
/// Deals with machine parts and machine boards.
|
|
/// </summary>
|
|
public sealed class MachinePartSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly IPrototypeManager _prototype = default!;
|
|
[Dependency] private readonly SharedLatheSystem _lathe = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<MachineBoardComponent, ExaminedEvent>(OnMachineBoardExamined);
|
|
SubscribeLocalEvent<MachinePartComponent, ExaminedEvent>(OnMachinePartExamined);
|
|
}
|
|
|
|
private void OnMachineBoardExamined(EntityUid uid, MachineBoardComponent component, ExaminedEvent args)
|
|
{
|
|
if (!args.IsInDetailsRange)
|
|
return;
|
|
|
|
using (args.PushGroup(nameof(MachineBoardComponent)))
|
|
{
|
|
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))));
|
|
}
|
|
|
|
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))));
|
|
}
|
|
|
|
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))));
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnMachinePartExamined(EntityUid uid, MachinePartComponent component, ExaminedEvent args)
|
|
{
|
|
if (!args.IsInDetailsRange)
|
|
return;
|
|
|
|
using (args.PushGroup(nameof(MachinePartComponent)))
|
|
{
|
|
args.PushMarkup(Loc.GetString("machine-part-component-on-examine-rating-text",
|
|
("rating", component.Rating)));
|
|
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.Materials.Values.Sum());
|
|
|
|
foreach (var (mat, matAmount) in partRecipe!.Materials)
|
|
{
|
|
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.Materials.Values.Sum());
|
|
|
|
foreach (var (mat, matAmount) in partRecipe!.Materials)
|
|
{
|
|
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.Materials.Values.Sum());
|
|
|
|
foreach (var (mat, matAmount) in partRecipe!.Materials)
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
}
|