Refactored GalacticBankManager (#1089)
This commit is contained in:
@@ -1,21 +1,16 @@
|
||||
using Content.Server.Cargo;
|
||||
using Content.Server.GameObjects.Components.Power;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Shared.GameObjects.Components.Cargo;
|
||||
using Content.Server.GameObjects.Components.Power;
|
||||
using Content.Shared.Prototypes.Cargo;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects.Components.UserInterface;
|
||||
using Robust.Server.Interfaces.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Utility;
|
||||
using Robust.Shared.Map;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Cargo
|
||||
{
|
||||
@@ -24,7 +19,6 @@ namespace Content.Server.GameObjects.Components.Cargo
|
||||
public class CargoConsoleComponent : SharedCargoConsoleComponent, IActivate
|
||||
{
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly IGalacticBankManager _galacticBankManager;
|
||||
[Dependency] private readonly ICargoOrderDataManager _cargoOrderDataManager;
|
||||
#pragma warning restore 649
|
||||
|
||||
@@ -37,13 +31,43 @@ namespace Content.Server.GameObjects.Components.Cargo
|
||||
public GalacticMarketComponent Market { get; private set; }
|
||||
[ViewVariables]
|
||||
public CargoOrderDatabaseComponent Orders { get; private set; }
|
||||
|
||||
private CargoBankAccount _bankAccount;
|
||||
|
||||
[ViewVariables]
|
||||
public int BankId { get; private set; }
|
||||
[CanBeNull]
|
||||
public CargoBankAccount BankAccount
|
||||
{
|
||||
get => _bankAccount;
|
||||
private set
|
||||
{
|
||||
if (_bankAccount == value)
|
||||
return;
|
||||
if (_bankAccount != null)
|
||||
{
|
||||
_bankAccount.OnBalanceChange -= OnBankAccountChange;
|
||||
}
|
||||
|
||||
_bankAccount = value;
|
||||
if (value != null)
|
||||
{
|
||||
_bankAccount.OnBalanceChange += OnBankAccountChange;
|
||||
}
|
||||
|
||||
OnBankAccountChange();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnBankAccountChange()
|
||||
{
|
||||
SetState(_bankAccount.Id, _bankAccount.Name, _bankAccount.Balance);
|
||||
}
|
||||
|
||||
private bool _requestOnly = false;
|
||||
|
||||
private PowerDeviceComponent _powerDevice;
|
||||
private bool Powered => _powerDevice.Powered;
|
||||
private CargoConsoleSystem _cargoConsoleSystem;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -53,8 +77,8 @@ namespace Content.Server.GameObjects.Components.Cargo
|
||||
_userInterface = Owner.GetComponent<ServerUserInterfaceComponent>().GetBoundUserInterface(CargoConsoleUiKey.Key);
|
||||
_userInterface.OnReceiveMessage += UserInterfaceOnOnReceiveMessage;
|
||||
_powerDevice = Owner.GetComponent<PowerDeviceComponent>();
|
||||
_galacticBankManager.AddComponent(this);
|
||||
BankId = 0;
|
||||
_cargoConsoleSystem = EntitySystem.Get<CargoConsoleSystem>();
|
||||
BankAccount = _cargoConsoleSystem.StationAccount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -80,7 +104,7 @@ namespace Content.Server.GameObjects.Components.Cargo
|
||||
{
|
||||
if (msg.Amount <= 0)
|
||||
break;
|
||||
_cargoOrderDataManager.AddOrder(Orders.Database.Id, msg.Requester, msg.Reason, msg.ProductId, msg.Amount, BankId);
|
||||
_cargoOrderDataManager.AddOrder(Orders.Database.Id, msg.Requester, msg.Reason, msg.ProductId, msg.Amount, _bankAccount.Id);
|
||||
break;
|
||||
}
|
||||
case CargoConsoleRemoveOrderMessage msg:
|
||||
@@ -96,7 +120,7 @@ namespace Content.Server.GameObjects.Components.Cargo
|
||||
_prototypeManager.TryIndex(order.ProductId, out CargoProductPrototype product);
|
||||
if (product == null)
|
||||
break;
|
||||
if (!_galacticBankManager.ChangeBalance(BankId, (-product.PointCost) * order.Amount))
|
||||
if (!_cargoConsoleSystem.ChangeBalance(_bankAccount.Id, (-product.PointCost) * order.Amount))
|
||||
break;
|
||||
_cargoOrderDataManager.ApproveOrder(Orders.Database.Id, msg.OrderNumber);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user