forked from space-wizards/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
49dece2
commit f877243
Showing
2 changed files
with
24 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,58 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using Content.Server.Cargo.Components; | ||
using Content.Server.Labels.Components; | ||
using Content.Server.Paper; | ||
using Content.Server.Station.Components; | ||
using Content.Shared.Cargo; | ||
using Content.Server.Cargo.Systems; | ||
using Content.Shared.Cargo.BUI; | ||
using Content.Shared.Cargo.Components; | ||
using Content.Shared.Cargo.Events; | ||
using Content.Shared.Cargo.Prototypes; | ||
using Content.Shared.Database; | ||
using Content.Shared.Interaction; | ||
using Robust.Shared.Map; | ||
using Robust.Shared.Player; | ||
using Robust.Shared.Prototypes; | ||
using Robust.Shared.Random; | ||
using Robust.Shared.Utility; | ||
using Content.Shared.SS220.Cargo.Events; | ||
using Content.Server.Station.Systems; | ||
using Content.Shared.Cargo; | ||
using Robust.Shared.Audio.Systems; | ||
using Content.Shared.Stacks; | ||
using Content.Server.Stack; | ||
using Robust.Shared.Prototypes; | ||
|
||
|
||
namespace Content.Server.SS220.Cargo | ||
namespace Content.Server.SS220.Cargо | ||
{ | ||
public sealed partial class CargoCashOutSystem : SharedCargoSystem | ||
{ | ||
/// <summary> | ||
/// How much time to wait (in seconds) before increasing bank accounts balance. | ||
/// </summary> | ||
private const int Delay = 10; | ||
|
||
/// <summary> | ||
/// Keeps track of how much time has elapsed since last balance increase. | ||
/// </summary> | ||
private float _timer; | ||
|
||
[Dependency] private readonly SharedAudioSystem _audio = default!; | ||
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!; | ||
[Dependency] private readonly IEntityManager _entityManager = default!; | ||
[Dependency] private readonly StationSystem _station = default!; | ||
[Dependency] private readonly IPrototypeManager _protoMan = default!; | ||
[Dependency] private readonly StackSystem _stack = default!; | ||
|
||
private void InitializeConsole() | ||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
SubscribeLocalEvent<CargoOrderConsoleComponent, CargoConsoleCashOutMessage>(CashOut); | ||
} | ||
|
||
private void CashOut(EntityUid uid, CargoOrderConsoleComponent component, ref CargoConsoleCashOutMessage arg) | ||
{ | ||
var stationUid = _station.GetOwningStation(uid); | ||
|
||
if (arg.Amount == 0) | ||
return; | ||
|
||
var stationUid = _station.GetOwningStation(arg.Used); | ||
|
||
if (!TryComp(stationUid, out StationBankAccountComponent? bank)) | ||
return; | ||
|
||
if (bank == null) | ||
return; | ||
|
||
if (arg.Amount > bank.Balance) | ||
{ | ||
_audio.PlayPvs(_audio.GetSound(component.ErrorSound), uid); | ||
return; | ||
} | ||
|
||
var cargoSystem = _entitySystemManager.GetEntitySystem<CargoSystem>(); | ||
var xform = Transform(uid); | ||
var stackPrototype = _protoMan.Index<StackPrototype>("Credit"); | ||
_stack.Spawn(arg.Amount, stackPrototype, xform.Coordinates); | ||
|
||
var cargoSystem = _entitySystemManager.GetEntitySystem<CargoSystem>(); | ||
cargoSystem.UpdateBankAccount(stationUid.Value, bank, -arg.Amount); | ||
_audio.PlayPvs(component.ConfirmSound, uid); | ||
} | ||
} | ||
} |