Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion Content.Server/ADT/Economy/BankCardSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Content.Shared.Mobs.Systems;
using Robust.Server.Player;
using Robust.Shared.Prototypes;
using Content.Shared.Cargo.Prototypes; // Ganimed-Edit
using Robust.Shared.Random;
using Content.Shared.Cargo.Components;
using Content.Shared.Cargo;
Expand Down Expand Up @@ -75,7 +76,7 @@ public override void Update(float frameTime)
private void PaySalary()
{
foreach (var account in _accounts.Where(account =>
account.Mind is {Comp.UserId: not null, Comp.CurrentEntity: not null} &&
account.Mind is { Comp.UserId: not null, Comp.CurrentEntity: not null } &&
_playerManager.TryGetSessionById(account.Mind.Value.Comp.UserId!.Value, out _) &&
!_mobState.IsDead(account.Mind.Value.Comp.CurrentEntity!.Value)))
{
Expand Down Expand Up @@ -225,5 +226,19 @@ public bool TryChangeBalance(int accountId, int amount)

return true;
}
// Ganimed-Edit start
public bool TryGetDepartmentAccount(string department, out ProtoId<CargoAccountPrototype> proto)
{
proto = new(department);

if (!_protoMan.HasIndex(proto))
{
proto = default;
return false;
}

return true;
}
// Ganimed-Edit end
}

59 changes: 44 additions & 15 deletions Content.Server/VendingMachines/VendingMachineSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Content.Server.Advertise.EntitySystems;
using Content.Server.Cargo.Systems;
using Content.Server.Emp;
using Content.Server.Station.Systems; // Ganimed-Edit
using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems;
using Content.Server.Stack;
Expand All @@ -30,12 +31,14 @@
using Content.Shared.UserInterface;
using Content.Shared.VendingMachines;
using Content.Shared.Wall;
using Content.Shared.Roles; // Ganimed-Edit
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Timing;
using Content.Shared.Cargo.Components; // Ganimed-Edit

namespace Content.Server.VendingMachines
{
Expand All @@ -57,6 +60,12 @@ public sealed class VendingMachineSystem : SharedVendingMachineSystem
[Dependency] private readonly SharedPointLightSystem _light = default!;
[Dependency] private readonly EmagSystem _emag = default!;

// Ganimed-Edit start
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly StationSystem _station = default!;
[Dependency] private readonly CargoSystem _cargo = default!;
// Ganimed-Edit end

private const float WallVendEjectDistanceFromWall = 1f;

public override void Initialize()
Expand Down Expand Up @@ -365,28 +374,48 @@ public void TryEjectVendorItem(EntityUid uid, InventoryType type, string itemId,
if (price > 0 && !vendComponent.AllForFree && sender.HasValue && !_tag.HasTag(sender.Value, "IgnoreBalanceChecks"))
{
var success = false;
if (vendComponent.Credits >= price)

if (TryComp<JobVendingComponent>(uid, out var jobVend) && TryComp<IdCardComponent>(sender.Value, out var idCard) && idCard.JobTitle == jobVend.Job)
{
vendComponent.Credits -= price;
success = true;
}
else
{
var items = _accessReader.FindPotentialAccessItems(sender.Value);
foreach (var item in items)
if (vendComponent.Credits >= price)
{
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.AccountId.HasValue
|| !_bankCard.TryGetAccount(bankCard.AccountId.Value, out var account)
|| account.Balance < price)
continue;

_bankCard.TryChangeBalance(bankCard.AccountId.Value, -price);
vendComponent.Credits -= price;
success = true;
break;
}
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.AccountId.HasValue
|| !_bankCard.TryGetAccount(bankCard.AccountId.Value, out var account)
|| account.Balance < price)
continue;

_bankCard.TryChangeBalance(bankCard.AccountId.Value, -price);

if (!string.IsNullOrEmpty(vendComponent.AccountTarget) &&
_bankCard.TryGetDepartmentAccount(vendComponent.AccountTarget, out var deptProto))
{
var station = _station.GetOwningStation(uid);
if (station != null && TryComp(station, out StationBankAccountComponent? stationAcc) && stationAcc != null)
{
if (station is { } s)
_cargo.UpdateBankAccount((s, stationAcc), price, deptProto);
}
}

success = true;
break;
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions Content.Shared/VendingMachines/VendingMachineComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ public sealed partial class VendingMachineComponent : Component

public int NextItemCount = 1;
//ADT-Economy-End
// Ganimed-Edit
[DataField("accountTarget")]
public string? AccountTarget;
// Ganimed-Edit end
}

[Serializable, NetSerializable]
Expand Down
24 changes: 24 additions & 0 deletions Content.Shared/_Ganimed/VendingMachines/JobVendingComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;

namespace Content.Shared.VendingMachines;

/// <summary>
/// Компонент для торговых автоматов, которые дают скидку конкретным профессиям (JobPrototype).
/// </summary>
[RegisterComponent]
public sealed partial class JobVendingComponent : Component
{
/// <summary>
/// Айди профессии (JobPrototype.id), для которой действует скидка.
/// Например: "Chef", "Bartender".
/// </summary>
[DataField("job")]
public string Job { get; set; } = string.Empty;

/// <summary>
/// Скидка в процентах (100 = бесплатно).
/// </summary>
[DataField("jobDiscount")]
public int JobDiscount { get; set; } = 100;
}
Loading