* Initial * Cleanup a bunch of things * some changes dunno * RequireAnchored * a * stuff * more work * Lots of progress * delete pipe visualizer * a * b * pipenet and pipenode cleanup * Fixes * Adds GasValve * Adds GasMiner * Fix stuff, maybe? * More fixes * Ignored components on the client * Adds thermomachine behavior, change a bunch of stuff * Remove Anchored * some work, but it's shitcode * significantly more ECS * ECS AtmosDevices * Cleanup * fix appearance * when the pipe direction is sus * Gas tanks and canisters * pipe anchoring and stuff * coding is my passion * Unsafe pipes take longer to unanchor * turns out we're no longer using eris canisters * Gas canister inserted tank appearance, improvements * Work on a bunch of appearances * Scrubber appearance * Reorganize AtmosphereSystem.Piping into a bunch of different systems * Appearance for vent/scrubber/pump turns off when leaving atmosphere * ThermoMachine appearance * Cleanup gas tanks * Remove passive gate unused imports * remove old canister UI functionality * PipeNode environment air, make everything use AssumeAir instead of merging manually * a * Reorganize atmos to follow new structure * ????? * Canister UI, restructure client * Restructure shared * Fix build tho * listen, at least the canister UI works entirely... * fix build : ) * Atmos device prototypes have names and descriptions * gas canister ui slider doesn't jitter * trinary prototypes * sprite for miners * ignore components * fix YAML * Fix port system doing useless thing * Fix build * fix thinking moment * fix build again because * canister direction * pipenode is a word * GasTank Air will throw on invalid states * fix build.... * Unhardcode volume pump thresholds * Volume pump and filter take time into account * Rename Join/Leave atmosphere events to AtmosDeviceEnabled/Disabled Event * Gas tank node volume is set by initial mixtuer * I love node container
128 lines
4.9 KiB
C#
128 lines
4.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Content.Server.Stack;
|
|
using Robust.Shared.Containers;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
|
|
|
namespace Content.Server.Construction.Components
|
|
{
|
|
[RegisterComponent]
|
|
public class MachineComponent : Component, IMapInit
|
|
{
|
|
public override string Name => "Machine";
|
|
|
|
[DataField("board")]
|
|
public string? BoardPrototype { get; private set; }
|
|
|
|
private Container _boardContainer = default!;
|
|
private Container _partContainer = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
_boardContainer = Owner.EnsureContainer<Container>(MachineFrameComponent.BoardContainer);
|
|
_partContainer = Owner.EnsureContainer<Container>(MachineFrameComponent.PartContainer);
|
|
}
|
|
|
|
public IEnumerable<MachinePartComponent> GetAllParts()
|
|
{
|
|
foreach (var entity in _partContainer.ContainedEntities)
|
|
{
|
|
if (entity.TryGetComponent<MachinePartComponent>(out var machinePart))
|
|
yield return machinePart;
|
|
}
|
|
}
|
|
|
|
public void RefreshParts()
|
|
{
|
|
foreach (var refreshable in Owner.GetAllComponents<IRefreshParts>())
|
|
{
|
|
refreshable.RefreshParts(GetAllParts());
|
|
}
|
|
}
|
|
|
|
public void CreateBoardAndStockParts()
|
|
{
|
|
// Entity might not be initialized yet.
|
|
var boardContainer = Owner.EnsureContainer<Container>(MachineFrameComponent.BoardContainer, out var existedBoard);
|
|
var partContainer = Owner.EnsureContainer<Container>(MachineFrameComponent.PartContainer, out var existedParts);
|
|
|
|
if (string.IsNullOrEmpty(BoardPrototype))
|
|
return;
|
|
|
|
var entityManager = Owner.EntityManager;
|
|
|
|
if (existedBoard || existedParts)
|
|
{
|
|
// We're done here, let's suppose all containers are correct just so we don't screw SaveLoadSave.
|
|
if (boardContainer.ContainedEntities.Count > 0)
|
|
return;
|
|
}
|
|
|
|
var board = entityManager.SpawnEntity(BoardPrototype, Owner.Transform.Coordinates);
|
|
|
|
if (!_boardContainer.Insert(board))
|
|
{
|
|
throw new Exception($"Couldn't insert board with prototype {BoardPrototype} to machine with prototype {Owner.Prototype?.ID ?? "N/A"}!");
|
|
}
|
|
|
|
if (!board.TryGetComponent<MachineBoardComponent>(out var machineBoard))
|
|
{
|
|
throw new Exception($"Entity with prototype {BoardPrototype} doesn't have a {nameof(MachineBoardComponent)}!");
|
|
}
|
|
|
|
foreach (var (part, amount) in machineBoard.Requirements)
|
|
{
|
|
for (var i = 0; i < amount; i++)
|
|
{
|
|
var p = entityManager.SpawnEntity(MachinePartComponent.Prototypes[part], Owner.Transform.Coordinates);
|
|
|
|
if (!partContainer.Insert(p))
|
|
throw new Exception($"Couldn't insert machine part of type {part} to machine with prototype {Owner.Prototype?.ID ?? "N/A"}!");
|
|
}
|
|
}
|
|
|
|
foreach (var (stackType, amount) in machineBoard.MaterialRequirements)
|
|
{
|
|
var stack = EntitySystem.Get<StackSystem>().Spawn(amount, stackType, Owner.Transform.Coordinates);
|
|
|
|
if (stack == null)
|
|
throw new Exception($"Couldn't spawn stack of type {stackType}!");
|
|
|
|
if (!partContainer.Insert(stack))
|
|
throw new Exception($"Couldn't insert machine material of type {stackType} to machine with prototype {Owner.Prototype?.ID ?? "N/A"}");
|
|
}
|
|
|
|
foreach (var (compName, info) in machineBoard.ComponentRequirements)
|
|
{
|
|
for (var i = 0; i < info.Amount; i++)
|
|
{
|
|
var c = entityManager.SpawnEntity(info.DefaultPrototype, Owner.Transform.Coordinates);
|
|
|
|
if(!partContainer.Insert(c))
|
|
throw new Exception($"Couldn't insert machine component part with default prototype '{compName}' to machine with prototype {Owner.Prototype?.ID ?? "N/A"}");
|
|
}
|
|
}
|
|
|
|
foreach (var (tagName, info) in machineBoard.TagRequirements)
|
|
{
|
|
for (var i = 0; i < info.Amount; i++)
|
|
{
|
|
var c = entityManager.SpawnEntity(info.DefaultPrototype, Owner.Transform.Coordinates);
|
|
|
|
if(!partContainer.Insert(c))
|
|
throw new Exception($"Couldn't insert machine component part with default prototype '{tagName}' to machine with prototype {Owner.Prototype?.ID ?? "N/A"}");
|
|
}
|
|
}
|
|
}
|
|
|
|
public void MapInit()
|
|
{
|
|
CreateBoardAndStockParts();
|
|
RefreshParts();
|
|
}
|
|
}
|
|
}
|