Skip to content

Commit

Permalink
Refactor FabricateCandySystem Into Its Generic Equivalent (#566)
Browse files Browse the repository at this point in the history
# 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>
  • Loading branch information
Mnemotechnician and DEATHB4DEFEAT authored Jul 23, 2024
1 parent fe84704 commit cf0498e
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 75 deletions.
19 changes: 19 additions & 0 deletions Content.Server/Abilities/Borgs/FabricateActionsComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Robust.Shared.Prototypes;

namespace Content.Server.Abilities.Borgs;

[RegisterComponent]
public sealed partial class FabricateActionsComponent : Component
{
/// <summary>
/// IDs of fabrication actions that the entity should receive with this component.
/// </summary>
[DataField]
public List<ProtoId<EntityPrototype>> Actions = new();

/// <summary>
/// Action entities added by this component.
/// </summary>
[DataField]
public Dictionary<ProtoId<EntityPrototype>, EntityUid> ActionEntities = new();
}
53 changes: 53 additions & 0 deletions Content.Server/Abilities/Borgs/FabricateActionsSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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;
}
}

This file was deleted.

37 changes: 0 additions & 37 deletions Content.Server/Nyanotrasen/Abilities/Borgs/FabricateCandySystem.cs

This file was deleted.

9 changes: 9 additions & 0 deletions Content.Shared/Actions/Events/FabricateActionEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Robust.Shared.Prototypes;

namespace Content.Shared.Actions.Events;

public sealed partial class FabricateActionEvent : InstantActionEvent
{
[DataField(required: true)]
public ProtoId<EntityPrototype> Fabrication;
}
4 changes: 0 additions & 4 deletions Content.Shared/Nyanotrasen/Actions/FabricateCandyEvent.cs

This file was deleted.

26 changes: 26 additions & 0 deletions Resources/Prototypes/Actions/types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,29 @@
itemIconStyle: NoItem
useDelay: 1 # emote spam
event: !type:ToggleActionEvent

- type: entity
id: ActionFabricateLollipop
name: action-name-fabricate-lollipop
description: action-description-fabricate-lollipop
noSpawn: true
components:
- type: InstantAction
icon: { sprite: Nyanotrasen/Objects/Consumable/Food/candy.rsi, state: lollipop }
useDelay: 120
event:
!type:FabricateActionEvent
fabrication: FoodLollipop

- type: entity
id: ActionFabricateGumball
name: action-name-fabricate-gumball
description: action-description-fabricate-gumball
noSpawn: true
components:
- type: InstantAction
icon: { sprite: Nyanotrasen/Objects/Consumable/Food/candy.rsi, state: gumball }
useDelay: 40
event:
!type:FabricateActionEvent
fabrication: FoodGumball
7 changes: 5 additions & 2 deletions Resources/Prototypes/Entities/Mobs/Cyborgs/borg_chassis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
- type: Inventory
templateId: borgShort
- type: SiliconLawProvider # Delta-V - Adds custom lawset for Engineering Cyborg
laws: Engineer
laws: Engineer

- type: entity
id: BorgChassisJanitor
Expand Down Expand Up @@ -224,7 +224,10 @@
access: [["Medical"], ["Command"], ["Research"]]
- type: Inventory
templateId: borgDutch
- type: FabricateCandy # Nyanotrasen - The medical cyborg can generate candies filled with medicine.
- type: FabricateActions
actions:
- ActionFabricateLollipop
- ActionFabricateGumball
- type: SiliconLawProvider # Delta-V - Adds custom lawset for Medical cyborg
laws: Medical

Expand Down
21 changes: 0 additions & 21 deletions Resources/Prototypes/Nyanotrasen/Actions/types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,24 +156,3 @@
icon: Nyanotrasen/Interface/VerbIcons/psionic_invisibility_off.png
event: !type:RemovePsionicInvisibilityOffPowerActionEvent

- type: entity
id: ActionFabricateLollipop
name: action-name-fabricate-lollipop
description: action-description-fabricate-lollipop
noSpawn: true
components:
- type: InstantAction
icon: { sprite: Nyanotrasen/Objects/Consumable/Food/candy.rsi, state: lollipop }
useDelay: 120
event: !type:FabricateLollipopActionEvent

- type: entity
id: ActionFabricateGumball
name: action-name-fabricate-gumball
description: action-description-fabricate-gumball
noSpawn: true
components:
- type: InstantAction
icon: { sprite: Nyanotrasen/Objects/Consumable/Food/candy.rsi, state: gumball }
useDelay: 40
event: !type:FabricateGumballActionEvent

0 comments on commit cf0498e

Please sign in to comment.