Emaggable vendors + Familiars for Chaplain (#6961)
This commit is contained in:
@@ -10,6 +10,7 @@ using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
using Content.Shared.Acts;
|
||||
using Content.Shared.Emag.Systems;
|
||||
using static Content.Shared.VendingMachines.SharedVendingMachineComponent;
|
||||
using Content.Shared.Throwing;
|
||||
|
||||
@@ -31,6 +32,7 @@ namespace Content.Server.VendingMachines.systems
|
||||
SubscribeLocalEvent<VendingMachineComponent, InventorySyncRequestMessage>(OnInventoryRequestMessage);
|
||||
SubscribeLocalEvent<VendingMachineComponent, VendingMachineEjectMessage>(OnInventoryEjectMessage);
|
||||
SubscribeLocalEvent<VendingMachineComponent, BreakageEventArgs>(OnBreak);
|
||||
SubscribeLocalEvent<VendingMachineComponent, GotEmaggedEvent>(OnEmagged);
|
||||
}
|
||||
|
||||
private void OnComponentInit(EntityUid uid, VendingMachineComponent component, ComponentInit args)
|
||||
@@ -75,6 +77,16 @@ namespace Content.Server.VendingMachines.systems
|
||||
TryUpdateVisualState(uid, VendingMachineVisualState.Broken, vendComponent);
|
||||
}
|
||||
|
||||
private void OnEmagged(EntityUid uid, VendingMachineComponent component, GotEmaggedEvent args)
|
||||
{
|
||||
if (component.Emagged || component.EmagPackPrototypeId == string.Empty)
|
||||
return;
|
||||
|
||||
AddVendEntries(component, component.EmagPackPrototypeId);
|
||||
component.Emagged = true;
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
public bool IsPowered(EntityUid uid, VendingMachineComponent? vendComponent = null)
|
||||
{
|
||||
if (!Resolve(uid, ref vendComponent))
|
||||
@@ -121,6 +133,27 @@ namespace Content.Server.VendingMachines.systems
|
||||
vendComponent.Inventory = inventory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add more entries for any reason AFTER initialization (emag, machine upgrades, etc)
|
||||
/// </summary>
|
||||
public void AddVendEntries(VendingMachineComponent component, string pack)
|
||||
{
|
||||
if (!_prototypeManager.TryIndex(pack, out VendingMachineInventoryPrototype? packPrototype))
|
||||
{
|
||||
Logger.Error($"Pack has no valid inventory prototype: {pack}");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var (id, amount) in packPrototype.StartingInventory)
|
||||
{
|
||||
if (!_prototypeManager.TryIndex(id, out EntityPrototype? prototype))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
component.Inventory.Add(new VendingMachineInventoryEntry(id, amount));
|
||||
}
|
||||
}
|
||||
|
||||
public void Deny(EntityUid uid, VendingMachineComponent? vendComponent = null)
|
||||
{
|
||||
if (!Resolve(uid, ref vendComponent))
|
||||
|
||||
Reference in New Issue
Block a user