Files
wwdpublic/Content.Server/Abilities/Borgs/FabricateActionsSystem.cs
Mnemotechnican cf0498e89a Refactor FabricateCandySystem Into Its Generic Equivalent (#566)
# Description
Refactors the nyano shitcode responsible for allowing borgs to dispense
candies into a more generic variant, that allows to define what action
dispenses what entity, and allowing an arbitrary number of such actions
on an entity.

Requested by @DangerRevolution 

<details><summary><h1>Media</h1></summary><p>


https://github.com/user-attachments/assets/b4d643e2-c9b0-4367-8b9c-2d0cd4a228b9

</p></details>

# Changelog
No cl no fun

---------

Signed-off-by: Mnemotechnican <69920617+Mnemotechnician@users.noreply.github.com>
Co-authored-by: DEATHB4DEFEAT <77995199+DEATHB4DEFEAT@users.noreply.github.com>
2024-07-23 10:38:55 +01:00

54 lines
1.8 KiB
C#

using Content.Shared.ActionBlocker;
using Content.Shared.Actions;
using Content.Shared.Actions.Events;
namespace Content.Server.Abilities.Borgs;
public sealed partial class FabricateActionsSystem : EntitySystem
{
[Dependency] private readonly ActionBlockerSystem _actionBlocker = default!;
[Dependency] private readonly SharedActionsSystem _actions = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<FabricateActionsComponent, ComponentStartup>(OnStartup);
SubscribeLocalEvent<FabricateActionsComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<FabricateActionsComponent, FabricateActionEvent>(OnFabricate);
}
private void OnStartup(Entity<FabricateActionsComponent> entity, ref ComponentStartup args)
{
foreach (var actionId in entity.Comp.Actions)
{
EntityUid? actionEntity = null;
if (_actions.AddAction(entity, ref actionEntity, actionId))
entity.Comp.ActionEntities[actionId] = actionEntity.Value;
}
}
private void OnShutdown(Entity<FabricateActionsComponent> entity, ref ComponentShutdown args)
{
foreach (var (actionId, actionEntity) in entity.Comp.ActionEntities)
{
if (actionEntity is not { Valid: true })
continue;
_actions.RemoveAction(entity, actionEntity);
entity.Comp.ActionEntities.Remove(actionId);
}
}
private void OnFabricate(Entity<FabricateActionsComponent> entity, ref FabricateActionEvent args)
{
if (args.Handled || !_actionBlocker.CanConsciouslyPerformAction(entity))
return;
SpawnNextToOrDrop(args.Fabrication, entity);
args.Handled = true;
}
}