Skip to content

Commit

Permalink
Merge branch 'xtray85:master' into уааааааааааааааааааа
Browse files Browse the repository at this point in the history
  • Loading branch information
JustKekc authored May 14, 2024
2 parents 56a9e3d + 4b564ec commit 0821068
Show file tree
Hide file tree
Showing 58 changed files with 165 additions and 333 deletions.
6 changes: 0 additions & 6 deletions Content.Client/VendingMachines/UI/VendingMachineMenu.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
xmlns:style="clr-namespace:Content.Client.Stylesheets">
<BoxContainer Orientation="Vertical">
<BoxContainer Orientation="Horizontal" Margin="4">
<Label Text="{Loc 'cargo-console-menu-points-label'}"
StyleClasses="LabelKeyText" />
<Label Name="PointsLabel"
Text="$0" />
</BoxContainer>
<LineEdit Name="SearchBar" PlaceHolder="{Loc 'vending-machine-component-search-filter'}" HorizontalExpand="True" Margin ="4 4" Access="Public"/>
<ItemList Name="VendingContents"
SizeFlagsStretchRatio="8"
Expand Down
7 changes: 1 addition & 6 deletions Content.Client/VendingMachines/UI/VendingMachineMenu.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void Populate(List<VendingMachineInventoryEntry> inventory, out List<int>
if (itemName.Length > longestEntry.Length)
longestEntry = itemName;

vendingItem.Text = $"${entry.Cost} | {itemName} [{entry.Amount}]";
vendingItem.Text = $"{itemName} [{entry.Amount}]";
vendingItem.Icon = icon;
filteredInventory.Add(i);
}
Expand All @@ -106,10 +106,5 @@ private void SetSizeAfterUpdate(int longestEntryLength, int contentCount)
SetSize = new Vector2(Math.Clamp((longestEntryLength + 2) * 12, 250, 300),
Math.Clamp(contentCount * 50, 150, 350));
}

public void UpdateBalance(int points)
{
PointsLabel.Text = Loc.GetString("cargo-console-menu-points-amount", ("amount", points.ToString()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ protected override void UpdateState(BoundUserInterfaceState state)
_cachedInventory = newState.Inventory;

_menu?.Populate(_cachedInventory, out _cachedFilteredIndex, _menu.SearchBar.Text);
_menu?.UpdateBalance(newState.Balance);
}

private void OnItemSelected(ItemList.ItemListSelectedEventArgs args)
Expand Down
1 change: 0 additions & 1 deletion Content.IntegrationTests/Tests/CargoTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Numerics;
using Content.Server.Cargo.Components;
using Content.Server.Cargo.Systems;
using Content.Shared.Cargo.Components;
using Content.Shared.Cargo.Prototypes;
using Content.Shared.Stacks;
using Robust.Shared.GameObjects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public async Task TestRestockInventoryBounds()
var entityManager = server.ResolveDependency<IEntityManager>();
var entitySystemManager = server.ResolveDependency<IEntitySystemManager>();

var vendingMachineSystem = entitySystemManager.GetEntitySystem<VendingMachineSystem>();
var vendingMachineSystem = entitySystemManager.GetEntitySystem<SharedVendingMachineSystem>();

var testMap = await pair.CreateTestMap();

Expand Down
109 changes: 11 additions & 98 deletions Content.Server/VendingMachines/VendingMachineSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,18 @@
using Content.Shared.Access.Components;
using Content.Shared.Access.Systems;
using Content.Shared.Actions;
using Content.Shared.Cargo.Components;
using Content.Shared.Damage;
using Content.Shared.Destructible;
using Content.Shared.DoAfter;
using Content.Shared.Emag.Components;
using Content.Shared.Emag.Systems;
using Content.Shared.Emp;
using Content.Shared.Interaction;
using Content.Shared.Popups;
using Content.Shared.Throwing;
using Content.Shared.UserInterface;
using Content.Shared.VendingMachines;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Timing;
Expand All @@ -43,7 +40,6 @@ public sealed class VendingMachineSystem : SharedVendingMachineSystem
[Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly AdvertiseSystem _advertise = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;

private ISawmill _sawmill = default!;

Expand Down Expand Up @@ -74,18 +70,11 @@ public override void Initialize()
SubscribeLocalEvent<VendingMachineComponent, RestockDoAfterEvent>(OnDoAfter);

SubscribeLocalEvent<VendingMachineRestockComponent, PriceCalculationEvent>(OnPriceCalculation);

SubscribeLocalEvent<VendingMachineComponent, InteractUsingEvent>(OnInteractUsing);
}

private void OnComponentMapInit(EntityUid uid, VendingMachineComponent component, MapInitEvent args)
{
_action.AddAction(uid, ref component.ActionEntity, component.Action, uid);
RestockInventoryFromPrototype(uid, component);
if (HasComp<ApcPowerReceiverComponent>(uid))
{
TryUpdateVisualState(uid, component);
}
Dirty(uid, component);
}

Expand All @@ -107,6 +96,16 @@ private void OnVendingPrice(EntityUid uid, VendingMachineComponent component, re
args.Price += price;
}

protected override void OnComponentInit(EntityUid uid, VendingMachineComponent component, ComponentInit args)
{
base.OnComponentInit(uid, component, args);

if (HasComp<ApcPowerReceiverComponent>(uid))
{
TryUpdateVisualState(uid, component);
}
}

private void OnActivatableUIOpenAttempt(EntityUid uid, VendingMachineComponent component, ActivatableUIOpenAttemptEvent args)
{
if (component.Broken)
Expand All @@ -130,7 +129,7 @@ private void OnBoundUIClosed(EntityUid uid, VendingMachineComponent component, B

private void UpdateVendingMachineInterfaceState(EntityUid uid, VendingMachineComponent component)
{
var state = new VendingMachineInterfaceState(GetAllInventory(uid, component), component.Balance);
var state = new VendingMachineInterfaceState(GetAllInventory(uid, component));

_userInterfaceSystem.TrySetUiState(uid, VendingMachineUiKey.Key, state);
}
Expand Down Expand Up @@ -293,15 +292,8 @@ public void TryEjectVendorItem(EntityUid uid, InventoryType type, string itemId,
if (string.IsNullOrEmpty(entry.ID))
return;

if (vendComponent.Balance < entry.Cost)
{
Popup.PopupEntity(Loc.GetString("vending-machine-component-try-eject-not-enough-money"), uid);
Deny(uid, vendComponent);
return;
}

// Start Ejecting, and prevent users from ordering while anim playing
vendComponent.Balance = Math.Max(0, vendComponent.Balance - entry.Cost);
vendComponent.Ejecting = true;
vendComponent.NextItemToEject = entry.ID;
vendComponent.ThrowNextItem = throwItem;
Expand Down Expand Up @@ -527,84 +519,5 @@ private void OnEmpPulse(EntityUid uid, VendingMachineComponent component, ref Em
component.NextEmpEject = _timing.CurTime;
}
}
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);

UpdateVendingMachineInterfaceState(uid, component);
}

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))
{
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
{
var minCost = Math.Max(0, (int) _pricing.GetEstimatedPrice(proto));
inventory.Add(id, new VendingMachineInventoryEntry(type, id, amount, _random.Next(minCost, 1 * minCost)));
}
}
}
}

private void OnInteractUsing(EntityUid uid, VendingMachineComponent component, ref InteractUsingEvent args)
{
if (!HasComp<CashComponent>(args.Used))
return;

var price = _pricing.GetPrice(args.Used);

if (price == 0)
return;

_audio.PlayPvs(component.SoundConfirm, uid);
component.Balance += (int) price;
UpdateVendingMachineInterfaceState(uid, component);
QueueDel(args.Used);
}
}
}
68 changes: 65 additions & 3 deletions Content.Shared/VendingMachines/SharedVendingMachineSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Network;
using Robust.Shared.Random;

namespace Content.Shared.VendingMachines;

Expand All @@ -18,15 +17,35 @@ public abstract partial class SharedVendingMachineSystem : EntitySystem
[Dependency] protected readonly SharedAudioSystem Audio = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
[Dependency] protected readonly SharedPopupSystem Popup = default!;
[Dependency] private readonly IComponentFactory _factory = default!;
[Dependency] private readonly IRobustRandom _random = 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
Expand Down Expand Up @@ -58,4 +77,47 @@ public List<VendingMachineInventoryEntry> GetAvailableInventory(EntityUid uid, V

return GetAllInventory(uid, component).Where(_ => _.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.HasIndex<EntityPrototype>(id))
{
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
inventory.Add(id, new VendingMachineInventoryEntry(type, id, amount));
}
}
}
}
12 changes: 1 addition & 11 deletions Content.Shared/VendingMachines/VendingMachineComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ public sealed partial class VendingMachineComponent : Component
// Yoinked from: https://github.com/discordia-space/CEV-Eris/blob/35bbad6764b14e15c03a816e3e89aa1751660ba9/sound/machines/Custom_deny.ogg
public SoundSpecifier SoundDeny = new SoundPathSpecifier("/Audio/Machines/custom_deny.ogg");

[DataField]
public SoundSpecifier SoundConfirm = new SoundPathSpecifier("/Audio/Effects/Cargo/ping.ogg");

/// <summary>
/// The action available to the player controlling the vending machine
/// </summary>
Expand All @@ -118,10 +115,6 @@ public sealed partial class VendingMachineComponent : Component
[AutoNetworkedField]
public EntityUid? ActionEntity;

[ViewVariables(VVAccess.ReadWrite)]
[AutoNetworkedField]
public int Balance;

public float NonLimitedEjectForce = 7.5f;

public float NonLimitedEjectRange = 5f;
Expand Down Expand Up @@ -199,14 +192,11 @@ public sealed class VendingMachineInventoryEntry
public string ID;
[ViewVariables(VVAccess.ReadWrite)]
public uint Amount;
[ViewVariables(VVAccess.ReadWrite)]
public int Cost;
public VendingMachineInventoryEntry(InventoryType type, string id, uint amount, int cost)
public VendingMachineInventoryEntry(InventoryType type, string id, uint amount)
{
Type = type;
ID = id;
Amount = amount;
Cost = cost;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ namespace Content.Shared.VendingMachines
public sealed class VendingMachineInterfaceState : BoundUserInterfaceState
{
public List<VendingMachineInventoryEntry> Inventory;
public int Balance;

public VendingMachineInterfaceState(List<VendingMachineInventoryEntry> inventory, int balance)
public VendingMachineInterfaceState(List<VendingMachineInventoryEntry> inventory)
{
Inventory = inventory;
Balance = balance;
}
}

Expand Down
13 changes: 3 additions & 10 deletions Resources/Changelog/ChangelogADT.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1763,16 +1763,9 @@ Entries:
- author: Мудрый дуб
changes:
- {message: "НТ решили не выдавать бесплатные деньги в вещмешках парамедика, а оставить себе.", type: Fix}
id: 55746 #костыль отображения в Обновлениях
time: '2024-05-07T23:25:00.0000000+00:00'

- author: Xelasto
changes:
- {message: "NanoTrasen решило поднять зарплату всем сотрудникам станции.", type: Tweak}
- {message: "Чтобы возместить расходы, торговые автоматы стали брать плату за товар.", type: Add}
id: 55747 #костыль отображения в Обновлениях
time: '2024-05-10T08:20:00.0000000+00:00'

id: 55747
time: '2024-05-07T23:25:00.0000000+00:00'

- author: JustKekc
changes:
- {message: "Добавлена замена '??' в тексте сообщения на 'вопросительно смотрит' эмоцией.", type: Add}
Expand Down
Loading

0 comments on commit 0821068

Please sign in to comment.