Beispiel #1
0
        private StationBankAccountComponent?GetBankAccount(CargoOrderConsoleComponent component)
        {
            var station = _station.GetOwningStation(component.Owner);

            TryComp <StationBankAccountComponent>(station, out var bankComponent);
            return(bankComponent);
        }
Beispiel #2
0
        private StationCargoOrderDatabaseComponent?GetOrderDatabase(CargoOrderConsoleComponent component)
        {
            var station = _station.GetOwningStation(component.Owner);

            TryComp <StationCargoOrderDatabaseComponent>(station, out var orderComponent);
            return(orderComponent);
        }
Beispiel #3
0
        private void OnAddOrderMessage(EntityUid uid, CargoOrderConsoleComponent component, CargoConsoleAddOrderMessage args)
        {
            if (args.Amount <= 0)
            {
                return;
            }

            var bank = GetBankAccount(component);

            if (bank == null)
            {
                return;
            }
            var orderDatabase = GetOrderDatabase(component);

            if (orderDatabase == null)
            {
                return;
            }

            var data = GetOrderData(args, GetNextIndex(orderDatabase));

            if (!TryAddOrder(orderDatabase, data))
            {
                PlayDenySound(uid, component);
                return;
            }
        }
Beispiel #4
0
        private void OnRemoveOrderMessage(EntityUid uid, CargoOrderConsoleComponent component, CargoConsoleRemoveOrderMessage args)
        {
            var orderDatabase = GetOrderDatabase(component);

            if (orderDatabase == null)
            {
                return;
            }
            RemoveOrder(orderDatabase, args.OrderNumber);
        }
Beispiel #5
0
        private void UpdateOrderState(CargoOrderConsoleComponent component, EntityUid?station)
        {
            if (station == null ||
                !TryComp <StationCargoOrderDatabaseComponent>(station, out var orderDatabase) ||
                !TryComp <StationBankAccountComponent>(station, out var bankAccount))
            {
                return;
            }

            var state = new CargoConsoleInterfaceState(
                MetaData(station.Value).EntityName,
                GetOrderCount(orderDatabase),
                orderDatabase.Capacity,
                bankAccount.Balance,
                orderDatabase.Orders.Values.ToList());

            _uiSystem.GetUiOrNull(component.Owner, CargoConsoleUiKey.Orders)?.SetState(state);
        }
Beispiel #6
0
        private void OnApproveOrderMessage(EntityUid uid, CargoOrderConsoleComponent component, CargoConsoleApproveOrderMessage args)
        {
            if (args.Session.AttachedEntity is not {
                Valid : true
            } player)
            {
                return;
            }

            if (!_accessReaderSystem.IsAllowed(player, uid))
            {
                ConsolePopup(args.Session, Loc.GetString("cargo-console-order-not-allowed"));
                PlayDenySound(uid, component);
                return;
            }

            var orderDatabase = GetOrderDatabase(component);
            var bankAccount   = GetBankAccount(component);

            // No station to deduct from.
            if (orderDatabase == null || bankAccount == null)
            {
                ConsolePopup(args.Session, Loc.GetString("cargo-console-station-not-found"));
                PlayDenySound(uid, component);
                return;
            }

            // No order to approve?
            if (!orderDatabase.Orders.TryGetValue(args.OrderNumber, out var order) ||
                order.Approved)
            {
                return;
            }

            // Invalid order
            if (!_protoMan.TryIndex <CargoProductPrototype>(order.ProductId, out var product))
            {
                ConsolePopup(args.Session, Loc.GetString("cargo-console-invalid-product"));
                PlayDenySound(uid, component);
                return;
            }

            var amount   = GetOrderCount(orderDatabase);
            var capacity = orderDatabase.Capacity;

            // Too many orders, avoid them getting spammed in the UI.
            if (amount >= capacity)
            {
                ConsolePopup(args.Session, Loc.GetString("cargo-console-too-many"));
                PlayDenySound(uid, component);
                return;
            }

            // Cap orders so someone can't spam thousands.
            var orderAmount = Math.Min(capacity - amount, order.Amount);

            if (orderAmount != order.Amount)
            {
                order.Amount = orderAmount;
                ConsolePopup(args.Session, Loc.GetString("cargo-console-snip-snip"));
                PlayDenySound(uid, component);
            }

            var cost = product.PointCost * order.Amount;

            // Not enough balance
            if (cost > bankAccount.Balance)
            {
                ConsolePopup(args.Session, Loc.GetString("cargo-console-insufficient-funds", ("cost", cost)));
                PlayDenySound(uid, component);
                return;
            }

            order.Approved = true;
            _idCardSystem.TryFindIdCard(player, out var idCard);
            order.Approver = idCard?.FullName ?? string.Empty;


            SoundSystem.Play(component.ConfirmSound.GetSound(), Filter.Pvs(uid, entityManager: EntityManager), uid);

            DeductFunds(bankAccount, cost);
            UpdateOrders(orderDatabase);
        }
Beispiel #7
0
        private void OnInit(EntityUid uid, CargoOrderConsoleComponent orderConsole, ComponentInit args)
        {
            var station = _station.GetOwningStation(uid);

            UpdateOrderState(orderConsole, station);
        }
Beispiel #8
0
 private void PlayDenySound(EntityUid uid, CargoOrderConsoleComponent component)
 {
     SoundSystem.Play(component.ErrorSound.GetSound(), Filter.Pvs(uid, entityManager: EntityManager), uid);
 }
Beispiel #9
0
        private void OnOrderUIOpened(EntityUid uid, CargoOrderConsoleComponent component, BoundUIOpenedEvent args)
        {
            var station = _station.GetOwningStation(uid);

            UpdateOrderState(component, station);
        }