Refactor actions to be entities with components (#19900)

This commit is contained in:
DrSmugleaf
2023-09-08 18:16:05 -07:00
committed by GitHub
parent e18f731b91
commit c71f97e3a2
210 changed files with 10693 additions and 11714 deletions

View File

@@ -8,7 +8,6 @@ using Content.Server.UserInterface;
using Content.Shared.Access.Components;
using Content.Shared.Access.Systems;
using Content.Shared.Actions;
using Content.Shared.Actions.ActionTypes;
using Content.Shared.Damage;
using Content.Shared.Destructible;
using Content.Shared.DoAfter;
@@ -44,6 +43,7 @@ namespace Content.Server.VendingMachines
base.Initialize();
_sawmill = Logger.GetSawmill("vending");
SubscribeLocalEvent<VendingMachineComponent, MapInitEvent>(OnComponentMapInit);
SubscribeLocalEvent<VendingMachineComponent, PowerChangedEvent>(OnPowerChanged);
SubscribeLocalEvent<VendingMachineComponent, BreakageEventArgs>(OnBreak);
SubscribeLocalEvent<VendingMachineComponent, GotEmaggedEvent>(OnEmagged);
@@ -62,6 +62,12 @@ namespace Content.Server.VendingMachines
SubscribeLocalEvent<VendingMachineRestockComponent, PriceCalculationEvent>(OnPriceCalculation);
}
private void OnComponentMapInit(EntityUid uid, VendingMachineComponent component, MapInitEvent args)
{
_action.AddAction(uid, ref component.ActionEntity, component.Action, uid);
Dirty(uid, component);
}
private void OnVendingPrice(EntityUid uid, VendingMachineComponent component, ref PriceCalculationEvent args)
{
var price = 0.0;
@@ -88,12 +94,6 @@ namespace Content.Server.VendingMachines
{
TryUpdateVisualState(uid, component);
}
if (component.Action != null)
{
var action = new InstantAction(PrototypeManager.Index<InstantActionPrototype>(component.Action));
_action.AddAction(uid, action, uid);
}
}
private void OnActivatableUIOpenAttempt(EntityUid uid, VendingMachineComponent component, ActivatableUIOpenAttemptEvent args)