* Revert "- fix: YAML linter fixes. (#598)" This reverts commit012bf3c357. * Revert "Automatic changelog update" This reverts commitcf1c3a9af5. * Revert "[Fix] Base Layer Prototype (#597)" This reverts commitb000423999. * Revert "Modules update (#596)" This reverts commit00fbdead77. * Revert "Automatic changelog update" This reverts commit0d7a12b2a2. * Revert "Fixes (#593)" This reverts commit943c77031c. * Revert "minor loadout fixes (#594)" This reverts commit143c010a89. * Revert "Update DryDock.yml (#595)" This reverts commit4cd0100ac7. * Revert "Automatic changelog update" This reverts commit08eadc690f. * Revert "fix: Maximum message size (#591)" This reverts commit343f3612eb. * Revert "Черри пики 7 (#592)" This reverts commit3f97bdce2f. * Revert "Automatic changelog update" This reverts commit0678eca250. * Revert "Рандомфиксы (#590)" This reverts commit2b9e5e2437. * Revert "Нижнее бельё в лодауты (#580)" This reverts commite01a47b089. * Revert "add lathe sounds (#588)" This reverts commitc80a2985f2. * Revert "Добавил параметр группы для некоторых реагентов (#585)" This reverts commit713b16bb98. * Revert "add hrp ++++ aspect (#587)" This reverts commita6a69cc60f. * Revert "Новые амбиенты и пару песен (#586)" This reverts commit48c86bd846. * Revert "Сообщения в ПДА 2 (#583)" This reverts commitcced3cc98b. * Revert "Automatic changelog update" This reverts commitabf435b11d. * Revert "Chem stuff and more (#584)" This reverts commit3608960f5c. * Revert "JobRequiremet refactor (#579)" This reverts commit9a9c9598e0. * Revert "Revert "Reapply "Нижнее бельё в лодауты""" This reverts commit44447d573f. * Revert "Reapply "Нижнее бельё в лодауты"" This reverts commit0c4d082ad3. * Revert "Revert "Нижнее бельё в лодауты"" This reverts commit56473c5492. * Revert "Нижнее бельё в лодауты" This reverts commitd1cb0cb364. * Revert "DryDock and WhiteMoose update (#578)" This reverts commit14755808af. * Revert "Automatic changelog update" This reverts commit0133f82722. * Revert "Fixes (#576)" This reverts commitb7cc49896c. * Revert "порт системы регенерации солюшена цинки (#574)" This reverts commita22cf3d50b. * Revert "Воровские перчатки (#573)" This reverts commitbb7140f3d4. * Revert "mood resprite (#572)" This reverts commit4db96dc569. * Revert "fix missing letter (#571)" This reverts commit94ea756794. * Revert "Сообщения в ПДА (#564)" This reverts commitd023d29e54. * Revert "- fix: No visible aghost." This reverts commit27e7f25f7e. * Revert "- tweak: Nerf cult shield." This reverts commit6a384246b8.
132 lines
4.9 KiB
C#
132 lines
4.9 KiB
C#
using Content.Shared.Emag.Components;
|
|
using Robust.Shared.Prototypes;
|
|
using System.Linq;
|
|
using Content.Shared.DoAfter;
|
|
using Content.Shared.Interaction;
|
|
using Content.Shared.Popups;
|
|
using Robust.Shared.Audio.Systems;
|
|
using Robust.Shared.Network;
|
|
|
|
namespace Content.Shared.VendingMachines;
|
|
|
|
public abstract partial class SharedVendingMachineSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly INetManager _net = default!;
|
|
[Dependency] protected readonly IPrototypeManager PrototypeManager = default!;
|
|
[Dependency] protected readonly SharedAudioSystem Audio = default!;
|
|
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
|
|
[Dependency] protected readonly SharedPopupSystem Popup = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<VendingMachineComponent, ComponentInit>(OnComponentInit);
|
|
SubscribeLocalEvent<VendingMachineRestockComponent, AfterInteractEvent>(OnAfterInteract);
|
|
}
|
|
|
|
protected virtual void OnComponentInit(EntityUid uid, VendingMachineComponent component, ComponentInit args)
|
|
{
|
|
RestockInventoryFromPrototype(uid, component);
|
|
}
|
|
|
|
public void RestockInventoryFromPrototype(EntityUid uid, VendingMachineComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!PrototypeManager.TryIndex(component.PackPrototypeId, out VendingMachineInventoryPrototype? packPrototype))
|
|
return;
|
|
|
|
AddInventoryFromPrototype(uid, packPrototype.StartingInventory, InventoryType.Regular, component);
|
|
AddInventoryFromPrototype(uid, packPrototype.EmaggedInventory, InventoryType.Emagged, component);
|
|
AddInventoryFromPrototype(uid, packPrototype.ContrabandInventory, InventoryType.Contraband, component);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns all of the vending machine's inventory. Only includes emagged and contraband inventories if
|
|
/// <see cref="EmaggedComponent"/> exists and <see cref="VendingMachineComponent.Contraband"/> is true
|
|
/// are <c>true</c> respectively.
|
|
/// </summary>
|
|
/// <param name="uid"></param>
|
|
/// <param name="component"></param>
|
|
/// <returns></returns>
|
|
public List<VendingMachineInventoryEntry> GetAllInventory(EntityUid uid, VendingMachineComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component))
|
|
return new();
|
|
|
|
var inventory = new List<VendingMachineInventoryEntry>(component.Inventory.Values);
|
|
|
|
if (HasComp<EmaggedComponent>(uid))
|
|
inventory.AddRange(component.EmaggedInventory.Values);
|
|
|
|
if (component.Contraband)
|
|
inventory.AddRange(component.ContrabandInventory.Values);
|
|
|
|
return inventory;
|
|
}
|
|
|
|
public List<VendingMachineInventoryEntry> GetAvailableInventory(EntityUid uid, VendingMachineComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component))
|
|
return new();
|
|
|
|
return GetAllInventory(uid, component).Where(inventoryEntry => inventoryEntry.Amount > 0).ToList();
|
|
}
|
|
|
|
private void AddInventoryFromPrototype(
|
|
EntityUid uid,
|
|
Dictionary<string, uint>? entries,
|
|
InventoryType type,
|
|
VendingMachineComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component) || entries == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Dictionary<string, VendingMachineInventoryEntry> inventory;
|
|
switch (type)
|
|
{
|
|
case InventoryType.Regular:
|
|
inventory = component.Inventory;
|
|
break;
|
|
case InventoryType.Emagged:
|
|
inventory = component.EmaggedInventory;
|
|
break;
|
|
case InventoryType.Contraband:
|
|
inventory = component.ContrabandInventory;
|
|
break;
|
|
default:
|
|
return;
|
|
}
|
|
|
|
foreach (var (id, amount) in entries)
|
|
{
|
|
if (PrototypeManager.TryIndex<EntityPrototype>(id, out var proto)) // WD EDIT
|
|
{
|
|
if (inventory.TryGetValue(id, out var entry))
|
|
// Prevent a machine's stock from going over three times
|
|
// the prototype's normal amount. This is an arbitrary
|
|
// number and meant to be a convenience for someone
|
|
// restocking a machine who doesn't want to force vend out
|
|
// all the items just to restock one empty slot without
|
|
// losing the rest of the restock.
|
|
entry.Amount = Math.Min(entry.Amount + amount, 3 * amount);
|
|
else // WD EDIT START
|
|
{
|
|
var price = GetEntryPrice(proto);
|
|
inventory.Add(id, new VendingMachineInventoryEntry(type, id, amount, price));
|
|
} // WD EDIT END
|
|
}
|
|
}
|
|
}
|
|
|
|
protected virtual int GetEntryPrice(EntityPrototype proto)
|
|
{
|
|
return 25;
|
|
} // WD
|
|
}
|