* nasrano

* Add station budget & salary

* Initial balance

* Vending machine UI

* Pricing for vending machines

* Finish economy

* Eftpos

* Finish eftpos

* Put eftpos into lockers

* Vending machine prices

* Small fixes

* Fix atm UI

* Add atms to maps

* fix

* reset

* Add PDA program

* Maps again

---------

Co-authored-by: Mona Hmiza <>
Co-authored-by: rhailrake <49613070+rhailrake@users.noreply.github.com>
This commit is contained in:
Aviu00
2023-10-02 16:50:02 +09:00
committed by Aviu00
parent 707cdf3afa
commit 16c8b95da4
109 changed files with 2043 additions and 30 deletions

View File

@@ -5,7 +5,11 @@ using Content.Server.Chat.Systems;
using Content.Server.Emp;
using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems;
using Content.Server.Stack;
using Content.Server.Storage.Components;
using Content.Server.Store.Components;
using Content.Server.UserInterface;
using Content.Server.White.Economy;
using Content.Shared.Access.Components;
using Content.Shared.Access.Systems;
using Content.Shared.Actions;
@@ -15,9 +19,14 @@ 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.PDA;
using Content.Shared.Popups;
using Content.Shared.Stacks;
using Content.Shared.Tag;
using Content.Shared.Throwing;
using Content.Shared.VendingMachines;
using Content.Shared.White.Economy;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.Prototypes;
@@ -37,9 +46,16 @@ namespace Content.Server.VendingMachines
[Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly ChatSystem _chat = default!;
// WD START
[Dependency] private readonly BankCardSystem _bankCard = default!;
[Dependency] private readonly TagSystem _tag = default!;
[Dependency] private readonly StackSystem _stackSystem = default!;
// WD END
private ISawmill _sawmill = default!;
private double _priceMultiplier = 1.0; // WD
public override void Initialize()
{
base.Initialize();
@@ -60,6 +76,12 @@ namespace Content.Server.VendingMachines
SubscribeLocalEvent<VendingMachineComponent, VendingMachineSelfDispenseEvent>(OnSelfDispense);
SubscribeLocalEvent<VendingMachineComponent, RestockDoAfterEvent>(OnDoAfter);
//WD EDIT
SubscribeLocalEvent<VendingMachineComponent, InteractUsingEvent>(OnInteractUsing);
SubscribeLocalEvent<VendingMachineComponent, VendingMachineWithdrawMessage>(OnWithdrawMessage);
//WD EDIT END
SubscribeLocalEvent<VendingMachineRestockComponent, PriceCalculationEvent>(OnPriceCalculation);
}
@@ -111,7 +133,8 @@ namespace Content.Server.VendingMachines
private void UpdateVendingMachineInterfaceState(EntityUid uid, VendingMachineComponent component)
{
var state = new VendingMachineInterfaceState(GetAllInventory(uid, component));
var state = new VendingMachineInterfaceState(GetAllInventory(uid, component), GetPriceMultiplier(component),
component.Credits); // WD EDIT
_userInterfaceSystem.TrySetUiState(uid, VendingMachineUiKey.Key, state);
}
@@ -190,6 +213,54 @@ namespace Content.Server.VendingMachines
args.Handled = true;
}
//WD EDIT
private void OnInteractUsing(EntityUid uid, VendingMachineComponent component, InteractUsingEvent args)
{
if (args.Handled)
return;
if (component.Broken || !this.IsPowered(uid, EntityManager))
return;
if (!TryComp<CurrencyComponent>(args.Used, out var currency) ||
!currency.Price.Keys.Contains(component.CurrencyType))
return;
var stack = Comp<StackComponent>(args.Used);
component.Credits += stack.Count;
Del(args.Used);
UpdateVendingMachineInterfaceState(uid, component);
Audio.PlayPvs(component.SoundInsertCurrency, uid);
args.Handled = true;
}
protected override int GetEntryPrice(EntityPrototype proto)
{
return (int) _pricing.GetEstimatedPrice(proto);
}
private int GetPrice(VendingMachineInventoryEntry entry, VendingMachineComponent comp)
{
return (int) (entry.Price * GetPriceMultiplier(comp));
}
private double GetPriceMultiplier(VendingMachineComponent comp)
{
return comp.PriceMultiplier * _priceMultiplier;
}
private void OnWithdrawMessage(EntityUid uid, VendingMachineComponent component, VendingMachineWithdrawMessage args)
{
_stackSystem.Spawn(component.Credits,
PrototypeManager.Index<StackPrototype>(component.CreditStackPrototype), Transform(uid).Coordinates);
component.Credits = 0;
Audio.PlayPvs(component.SoundWithdrawCurrency, uid);
UpdateVendingMachineInterfaceState(uid, component);
}
//WD EDIT END
/// <summary>
/// Sets the <see cref="VendingMachineComponent.CanShoot"/> property of the vending machine.
/// </summary>
@@ -245,7 +316,7 @@ namespace Content.Server.VendingMachines
/// <param name="itemId">The prototype ID of the item</param>
/// <param name="throwItem">Whether the item should be thrown in a random direction after ejection</param>
/// <param name="vendComponent"></param>
public void TryEjectVendorItem(EntityUid uid, InventoryType type, string itemId, bool throwItem, VendingMachineComponent? vendComponent = null)
public void TryEjectVendorItem(EntityUid uid, InventoryType type, string itemId, bool throwItem, VendingMachineComponent? vendComponent = null, EntityUid? sender = null) // WD EDIT
{
if (!Resolve(uid, ref vendComponent))
return;
@@ -274,6 +345,44 @@ namespace Content.Server.VendingMachines
if (string.IsNullOrEmpty(entry.ID))
return;
// WD START
var price = GetPrice(entry, vendComponent);
if (price > 0 && sender.HasValue && !_tag.HasTag(sender.Value, "IgnoreBalanceChecks"))
{
var success = false;
if (vendComponent.Credits >= price)
{
vendComponent.Credits -= price;
success = true;
}
else
{
var items = _accessReader.FindPotentialAccessItems(sender.Value);
foreach (var item in items)
{
var nextItem = item;
if (TryComp(item, out PdaComponent? pda) && pda.ContainedId is { Valid: true } id)
nextItem = id;
if (!TryComp<BankCardComponent>(nextItem, out var bankCard) || !bankCard.BankAccountId.HasValue
|| !_bankCard.TryGetAccount(bankCard.BankAccountId.Value, out var account)
|| account.Balance < price)
continue;
_bankCard.TryChangeBalance(bankCard.BankAccountId.Value, -price);
success = true;
break;
}
}
if (!success)
{
Popup.PopupEntity(Loc.GetString("vending-machine-component-no-balance"), uid);
Deny(uid, vendComponent);
return;
}
}
// WD END
// Start Ejecting, and prevent users from ordering while anim playing
vendComponent.Ejecting = true;
@@ -297,7 +406,7 @@ namespace Content.Server.VendingMachines
{
if (IsAuthorized(uid, sender, component))
{
TryEjectVendorItem(uid, type, itemId, component.CanShoot, component);
TryEjectVendorItem(uid, type, itemId, component.CanShoot, component, sender);
}
}