Emaggable vendors + Familiars for Chaplain (#6961)

This commit is contained in:
Rane
2022-04-17 03:16:02 -04:00
committed by GitHub
parent 22735ab5ee
commit 7a6d3e69a8
20 changed files with 313 additions and 28 deletions

View File

@@ -9,6 +9,7 @@ using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
using Content.Server.VendingMachines.systems;
using static Content.Shared.Wires.SharedWiresComponent;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Server.VendingMachines
{
@@ -16,9 +17,10 @@ namespace Content.Server.VendingMachines
public sealed class VendingMachineComponent : SharedVendingMachineComponent, IWires
{
public bool Ejecting;
public bool Emagged = false;
public TimeSpan AnimationDuration = TimeSpan.Zero;
[DataField("pack")]
public string PackPrototypeId = string.Empty;
[ViewVariables] [DataField("pack", customTypeSerializer:typeof(PrototypeIdSerializer<VendingMachineInventoryPrototype>))] public string PackPrototypeId = string.Empty;
[ViewVariables] [DataField("emagPack", customTypeSerializer:typeof(PrototypeIdSerializer<VendingMachineInventoryPrototype>))] public string EmagPackPrototypeId = string.Empty;
public string SpriteName = "";
public bool Broken;
/// <summary>

View File

@@ -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))