Flatpacks and the Flatpacker 1001 (#23338)

* Flatpacker and flatpacks

* ok that's good enough

* convert solars/AME to flatpacks

* mats, mats, we are the mats

* basic mechanics are DONE

* thing

* final UI

* sloth

* rped jumpscare

* rename
This commit is contained in:
Nemanja
2024-01-03 01:16:02 -05:00
committed by GitHub
parent 04fc06e9d4
commit 1c11332fa4
40 changed files with 1066 additions and 101 deletions

View File

@@ -0,0 +1,98 @@
using Content.Server.Audio;
using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems;
using Content.Shared.Construction;
using Content.Shared.Construction.Components;
using Content.Shared.Containers.ItemSlots;
using Robust.Shared.Timing;
namespace Content.Server.Construction;
/// <inheritdoc/>
public sealed class FlatpackSystem : SharedFlatpackSystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly AmbientSoundSystem _ambientSound = default!;
[Dependency] private readonly ItemSlotsSystem _itemSlots = default!;
/// <inheritdoc/>
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<FlatpackCreatorComponent, FlatpackCreatorStartPackBuiMessage>(OnStartPack);
SubscribeLocalEvent<FlatpackCreatorComponent, PowerChangedEvent>(OnPowerChanged);
}
private void OnStartPack(Entity<FlatpackCreatorComponent> ent, ref FlatpackCreatorStartPackBuiMessage args)
{
var (uid, comp) = ent;
if (!this.IsPowered(ent, EntityManager) || comp.Packing)
return;
if (!_itemSlots.TryGetSlot(uid, comp.SlotId, out var itemSlot) || itemSlot.Item is not { } machineBoard)
return;
if (!TryComp<MachineBoardComponent>(machineBoard, out var boardComp))
return;
if (!MaterialStorage.CanChangeMaterialAmount(uid, GetFlatpackCreationCost(ent, (machineBoard, boardComp))))
return;
comp.Packing = true;
comp.PackEndTime = _timing.CurTime + comp.PackDuration;
Appearance.SetData(uid, FlatpackCreatorVisuals.Packing, true);
_ambientSound.SetAmbience(uid, true);
Dirty(uid, comp);
}
private void OnPowerChanged(Entity<FlatpackCreatorComponent> ent, ref PowerChangedEvent args)
{
if (args.Powered)
return;
FinishPacking(ent, true);
}
private void FinishPacking(Entity<FlatpackCreatorComponent> ent, bool interrupted)
{
var (uid, comp) = ent;
comp.Packing = false;
Appearance.SetData(uid, FlatpackCreatorVisuals.Packing, false);
_ambientSound.SetAmbience(uid, false);
Dirty(uid, comp);
if (interrupted)
return;
if (!_itemSlots.TryGetSlot(uid, comp.SlotId, out var itemSlot) || itemSlot.Item is not { } machineBoard)
return;
if (!TryComp<MachineBoardComponent>(machineBoard, out var boardComp))
return;
var materialCost = GetFlatpackCreationCost(ent, (machineBoard, boardComp));
if (!MaterialStorage.TryChangeMaterialAmount((ent, null), materialCost))
return;
var flatpack = Spawn(comp.BaseFlatpackPrototype, Transform(ent).Coordinates);
SetupFlatpack(flatpack, (machineBoard, boardComp));
}
public override void Update(float frameTime)
{
base.Update(frameTime);
var query = EntityQueryEnumerator<FlatpackCreatorComponent>();
while (query.MoveNext(out var uid, out var comp))
{
if (!comp.Packing)
continue;
if (_timing.CurTime < comp.PackEndTime)
continue;
FinishPacking((uid, comp), false);
}
}
}