@@ -4,6 +4,7 @@ using Content.Server.Power.EntitySystems;
|
||||
using Content.Shared.Construction;
|
||||
using Content.Shared.Construction.Components;
|
||||
using Content.Shared.Containers.ItemSlots;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Server.Construction;
|
||||
@@ -30,21 +31,24 @@ public sealed class FlatpackSystem : SharedFlatpackSystem
|
||||
if (!this.IsPowered(ent, EntityManager) || comp.Packing)
|
||||
return;
|
||||
|
||||
if (!_itemSlots.TryGetSlot(uid, comp.SlotId, out var itemSlot) || itemSlot.Item is not { } machineBoard)
|
||||
if (!_itemSlots.TryGetSlot(uid, comp.SlotId, out var itemSlot) || itemSlot.Item is not { } board)
|
||||
return;
|
||||
|
||||
Dictionary<string, int>? cost = null;
|
||||
if (TryComp<MachineBoardComponent>(machineBoard, out var machineBoardComponent))
|
||||
cost = GetFlatpackCreationCost(ent, (machineBoard, machineBoardComponent));
|
||||
if (HasComp<ComputerBoardComponent>(machineBoard))
|
||||
cost = GetFlatpackCreationCost(ent);
|
||||
|
||||
if (cost is null)
|
||||
Dictionary<string, int> cost;
|
||||
if (TryComp<MachineBoardComponent>(board, out var machine))
|
||||
cost = GetFlatpackCreationCost(ent, (board, machine));
|
||||
else if (TryComp<ComputerBoardComponent>(board, out var computer) && computer.Prototype != null)
|
||||
cost = GetFlatpackCreationCost(ent, null);
|
||||
else
|
||||
{
|
||||
Log.Error($"Encountered invalid flatpack board while packing: {ToPrettyString(board)}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!MaterialStorage.CanChangeMaterialAmount(uid, cost))
|
||||
return;
|
||||
|
||||
_itemSlots.SetLock(uid, comp.SlotId, true);
|
||||
comp.Packing = true;
|
||||
comp.PackEndTime = _timing.CurTime + comp.PackDuration;
|
||||
Appearance.SetData(uid, FlatpackCreatorVisuals.Packing, true);
|
||||
@@ -63,6 +67,7 @@ public sealed class FlatpackSystem : SharedFlatpackSystem
|
||||
{
|
||||
var (uid, comp) = ent;
|
||||
|
||||
_itemSlots.SetLock(uid, comp.SlotId, false);
|
||||
comp.Packing = false;
|
||||
Appearance.SetData(uid, FlatpackCreatorVisuals.Packing, false);
|
||||
_ambientSound.SetAmbience(uid, false);
|
||||
@@ -71,24 +76,33 @@ public sealed class FlatpackSystem : SharedFlatpackSystem
|
||||
if (interrupted)
|
||||
return;
|
||||
|
||||
if (!_itemSlots.TryGetSlot(uid, comp.SlotId, out var itemSlot) || itemSlot.Item is not { } machineBoard)
|
||||
if (!_itemSlots.TryGetSlot(uid, comp.SlotId, out var itemSlot) || itemSlot.Item is not { } board)
|
||||
return;
|
||||
|
||||
Dictionary<string, int>? cost = null;
|
||||
if (TryComp<MachineBoardComponent>(machineBoard, out var machineBoardComponent))
|
||||
cost = GetFlatpackCreationCost(ent, (machineBoard, machineBoardComponent));
|
||||
if (HasComp<ComputerBoardComponent>(machineBoard))
|
||||
cost = GetFlatpackCreationCost(ent);
|
||||
|
||||
if (cost is null)
|
||||
Dictionary<string, int> cost;
|
||||
EntProtoId proto;
|
||||
if (TryComp<MachineBoardComponent>(board, out var machine))
|
||||
{
|
||||
cost = GetFlatpackCreationCost(ent, (board, machine));
|
||||
proto = machine.Prototype;
|
||||
}
|
||||
else if (TryComp<ComputerBoardComponent>(board, out var computer) && computer.Prototype != null)
|
||||
{
|
||||
cost = GetFlatpackCreationCost(ent, null);
|
||||
proto = computer.Prototype;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error($"Encountered invalid flatpack board while packing: {ToPrettyString(board)}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!MaterialStorage.TryChangeMaterialAmount((ent, null), cost))
|
||||
return;
|
||||
|
||||
var flatpack = Spawn(comp.BaseFlatpackPrototype, Transform(ent).Coordinates);
|
||||
SetupFlatpack(flatpack, machineBoard);
|
||||
Del(machineBoard);
|
||||
SetupFlatpack(flatpack, proto, board);
|
||||
Del(board);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
|
||||
Reference in New Issue
Block a user