protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
-
+
if (_machinePreview is not { } && _entityManager.Deleted(_machinePreview))
{
_machinePreview = null;
else if (_currentBoard != null)
{
//todo double trycomp is kinda stinky.
- if (_entityManager.TryGetComponent<MachineBoardComponent>(_currentBoard, out var board) &&
- board.Prototype != null)
- {
- var cost = _flatpack.GetFlatpackCreationCost((_owner, flatpacker),
- (_currentBoard.Value, board));
- PackButton.Disabled = !_materialStorage.CanChangeMaterialAmount(_owner, cost);
- }
+ Dictionary<string, int> cost;
+ if (_entityManager.TryGetComponent<MachineBoardComponent>(_currentBoard, out var machineBoardComp) &&
+ machineBoardComp.Prototype is not null)
+ cost = _flatpack.GetFlatpackCreationCost((_owner, flatpacker), (_currentBoard.Value, machineBoardComp));
+ else
+ cost = _flatpack.GetFlatpackCreationCost((_owner, flatpacker));
+
+ PackButton.Disabled = !_materialStorage.CanChangeMaterialAmount(_owner, cost);
}
if (_currentBoard == itemSlot.Item)
_currentBoard = itemSlot.Item;
CostHeaderLabel.Visible = _currentBoard != null;
- if (_currentBoard != null &&
- _entityManager.TryGetComponent<MachineBoardComponent>(_currentBoard, out var machineBoard) &&
- machineBoard.Prototype != null)
+ if (_currentBoard is not null)
{
- var proto = _prototypeManager.Index<EntityPrototype>(machineBoard.Prototype);
- _machinePreview = _entityManager.Spawn(proto.ID);
- _spriteSystem.ForceUpdate(_machinePreview.Value);
- MachineNameLabel.SetMessage(proto.Name);
- var cost = _flatpack.GetFlatpackCreationCost((_owner, flatpacker),
- (_currentBoard.Value, machineBoard));
- CostLabel.SetMarkup(GetCostString(cost));
+ string? prototype = null;
+ Dictionary<string, int>? cost = null;
+
+ if (_entityManager.TryGetComponent<MachineBoardComponent>(_currentBoard, out var machineBoard))
+ {
+ prototype = machineBoard.Prototype;
+ cost = _flatpack.GetFlatpackCreationCost((_owner, flatpacker), (_currentBoard.Value, machineBoard));
+ }
+ else if (_entityManager.TryGetComponent<ComputerBoardComponent>(_currentBoard, out var computerBoard))
+ {
+ prototype = computerBoard.Prototype;
+ cost = _flatpack.GetFlatpackCreationCost((_owner, flatpacker));
+ }
+
+ if (prototype is not null && cost is not null)
+ {
+ var proto = _prototypeManager.Index<EntityPrototype>(prototype);
+ _machinePreview = _entityManager.Spawn(proto.ID);
+ _spriteSystem.ForceUpdate(_machinePreview.Value);
+ MachineNameLabel.SetMessage(proto.Name);
+ CostLabel.SetMarkup(GetCostString(cost));
+ }
}
else
{
using Content.Shared.Construction.Components;
using Content.Shared.Containers.ItemSlots;
using Robust.Shared.Timing;
+using YamlDotNet.Serialization.NodeTypeResolvers;
namespace Content.Server.Construction;
if (!_itemSlots.TryGetSlot(uid, comp.SlotId, out var itemSlot) || itemSlot.Item is not { } machineBoard)
return;
- if (!TryComp<MachineBoardComponent>(machineBoard, out var boardComp))
+ Dictionary<string, int>? cost = null;
+ if (TryComp<MachineBoardComponent>(machineBoard, out var machineBoardComponent))
+ cost = GetFlatpackCreationCost(ent, (machineBoard, machineBoardComponent));
+ if (TryComp<ComputerBoardComponent>(machineBoard, out var computerBoardComponent))
+ cost = GetFlatpackCreationCost(ent);
+
+ if (cost is null)
return;
- if (!MaterialStorage.CanChangeMaterialAmount(uid, GetFlatpackCreationCost(ent, (machineBoard, boardComp))))
+ if (!MaterialStorage.CanChangeMaterialAmount(uid, cost))
return;
comp.Packing = true;
if (!_itemSlots.TryGetSlot(uid, comp.SlotId, out var itemSlot) || itemSlot.Item is not { } machineBoard)
return;
- if (!TryComp<MachineBoardComponent>(machineBoard, out var boardComp))
+ Dictionary<string, int>? cost = null;
+ if (TryComp<MachineBoardComponent>(machineBoard, out var machineBoardComponent))
+ cost = GetFlatpackCreationCost(ent, (machineBoard, machineBoardComponent));
+ if (TryComp<ComputerBoardComponent>(machineBoard, out var computerBoardComponent))
+ cost = GetFlatpackCreationCost(ent);
+
+ if (cost is null)
return;
- var materialCost = GetFlatpackCreationCost(ent, (machineBoard, boardComp));
- if (!MaterialStorage.TryChangeMaterialAmount((ent, null), materialCost))
+ if (!MaterialStorage.TryChangeMaterialAmount((ent, null), cost))
return;
var flatpack = Spawn(comp.BaseFlatpackPrototype, Transform(ent).Coordinates);
- SetupFlatpack(flatpack, (machineBoard, boardComp));
+ SetupFlatpack(flatpack, machineBoard);
}
public override void Update(float frameTime)
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
-namespace Content.Server.Construction.Components
+namespace Content.Shared.Construction.Components
{
/// <summary>
/// Used for construction graphs in building computers.
/// <summary>
/// A default cost applied to all flatpacks outside of the cost of constructing the machine.
+ /// This one is applied to machines specifically.
/// </summary>
[DataField]
- public Dictionary<ProtoId<MaterialPrototype>, int> BaseMaterialCost = new();
+ public Dictionary<ProtoId<MaterialPrototype>, int> BaseMachineCost = new();
+
+ /// <summary>
+ /// A default cost applied to all flatpacks outside of the cost of constructing the machine.
+ /// This one is applied to computers specifically.
+ /// </summary>
+ [DataField]
+ public Dictionary<ProtoId<MaterialPrototype>, int> BaseComputerCost = new();
[DataField, ViewVariables(VVAccess.ReadWrite)]
public string SlotId = "board_slot";
ent.Comp.PackEndTime += args.PausedTime;
}
- public void SetupFlatpack(Entity<FlatpackComponent?> ent, Entity<MachineBoardComponent?> machineBoard)
+ public void SetupFlatpack(Entity<FlatpackComponent?> ent, EntityUid? board)
{
- if (!Resolve(ent, ref ent.Comp) || !Resolve(machineBoard, ref machineBoard.Comp))
+ if (!Resolve(ent, ref ent.Comp))
return;
- if (machineBoard.Comp.Prototype is not { } machinePrototypeId)
- return;
+ EntProtoId machinePrototypeId;
+ string? entityPrototype;
+ if (TryComp<MachineBoardComponent>(board, out var machineBoard) && machineBoard.Prototype is not null)
+ machinePrototypeId = machineBoard.Prototype;
+ else if (TryComp<ComputerBoardComponent>(board, out var computerBoard) && computerBoard.Prototype is not null)
+ machinePrototypeId = computerBoard.Prototype;
var comp = ent.Comp!;
var machinePrototype = PrototypeManager.Index(machinePrototypeId);
comp.Entity = machinePrototypeId;
Dirty(ent, comp);
- Appearance.SetData(ent, FlatpackVisuals.Machine, MetaData(machineBoard).EntityPrototype?.ID ?? string.Empty);
+ if (board is null)
+ return;
+
+ Appearance.SetData(ent, FlatpackVisuals.Machine, MetaData(board.Value).EntityPrototype?.ID ?? string.Empty);
}
- public Dictionary<string, int> GetFlatpackCreationCost(Entity<FlatpackCreatorComponent> entity, Entity<MachineBoardComponent> machineBoard)
+ public Dictionary<string, int> GetFlatpackCreationCost(Entity<FlatpackCreatorComponent> entity, Entity<MachineBoardComponent>? machineBoard = null)
{
- var cost = MachinePart.GetMachineBoardMaterialCost(machineBoard, -1);
- foreach (var (mat, amount) in entity.Comp.BaseMaterialCost)
+ Dictionary<string, int> cost = new();
+ Dictionary<ProtoId<MaterialPrototype>, int> baseCost;
+ if (machineBoard is not null)
+ {
+ cost = MachinePart.GetMachineBoardMaterialCost(machineBoard.Value, -1);
+ baseCost = entity.Comp.BaseMachineCost;
+ }
+ else
+ baseCost = entity.Comp.BaseComputerCost;
+
+ foreach (var (mat, amount) in baseCost)
{
cost.TryAdd(mat, 0);
cost[mat] -= amount;
security: "#DE3A3A"
science: "#D381C9"
supply: "#A46106"
+ cpu_command: "#334E6D"
+ cpu_medical: "#52B4E9"
+ cpu_service: "#9FED58"
+ cpu_engineering: "#EFB341"
+ cpu_security: "#DE3A3A"
+ cpu_science: "#D381C9"
+ cpu_supply: "#A46106"
- type: StaticPrice
price: 500
- type: Tag
True: { visible: true }
False: { visible: false }
- type: FlatpackCreator
- baseMaterialCost:
+ baseMachineCost:
Steel: 600
Plastic: 200
+ baseComputerCost:
+ Steel: 600
+ Plastic: 200
+ Glass: 200
- type: Machine
board: FlatpackerMachineCircuitboard
- type: MaterialStorage
whitelist:
components:
- MachineBoard
+ - ComputerBoard
- type: ContainerContainer
containers:
machine_board: !type:Container