/// <summary> /// In this method we are printing and attaching order manifests to the orders. /// </summary> private void SpawnAndAttachOrderManifest(EntityUid item, CargoOrderData order, EntityCoordinates coordinates, CargoShuttleComponent component) { if (!_protoMan.TryIndex(order.ProductId, out CargoProductPrototype? prototype)) { return; } // spawn a piece of paper. var printed = EntityManager.SpawnEntity("Paper", coordinates); if (!TryComp <PaperComponent>(printed, out var paper)) { return; } // fill in the order data var val = Loc.GetString("cargo-console-paper-print-name", ("orderNumber", order.OrderNumber)); MetaData(printed).EntityName = val; _paperSystem.SetContent(printed, Loc.GetString( "cargo-console-paper-print-text", ("orderNumber", order.OrderNumber), ("itemName", prototype.Name), ("requester", order.Requester), ("reason", order.Reason), ("approver", order.Approver ?? string.Empty)), paper); // attempt to attach the label if (TryComp <PaperLabelComponent>(item, out var label)) { _slots.TryInsert(item, label.LabelSlot, printed, null); } }
/// <summary> /// Adds an order to the database. /// </summary> /// <param name="order">The order to be added.</param> public virtual void AddOrder(CargoOrderData order) { if (!_orders.Contains(order)) { _orders.Add(order); } }
public void QueueTeleport(CargoTelepadComponent component, CargoOrderData order) { for (var i = 0; i < order.Amount; i++) { component.TeleportQueue.Push(order); } }
public bool TryGetOrder(int id, out CargoOrderData order) { if (_orders.TryGetValue(id, out var _order)) { order = _order; return(true); } order = null; return(false); }
/// <summary> /// Adds an order to the database. /// </summary> /// <param name="requester">The person who requested the item.</param> /// <param name="reason">The reason the product was requested.</param> /// <param name="productId">The ID of the product requested.</param> /// <param name="amount">The amount of the products requested.</param> /// <param name="payingAccountId">The ID of the bank account paying for the order.</param> /// <param name="approved">Whether the order will be bought when the orders are processed.</param> public void AddOrder(string requester, string reason, string productId, int amount, int payingAccountId) { var order = new CargoOrderData(_orderNumber, requester, reason, productId, amount, payingAccountId); if (Contains(order)) { return; } _orders.Add(_orderNumber, order); _orderNumber += 1; }
/// <summary> /// Returns the orders that can fit on the cargo shuttle. /// </summary> private List <CargoOrderData> GetProjectedOrders( StationCargoOrderDatabaseComponent?component = null, CargoShuttleComponent?shuttle = null) { var orders = new List <CargoOrderData>(); if (component == null || shuttle == null || component.Orders.Count == 0) { return(orders); } var space = GetCargoSpace(shuttle); if (space == 0) { return(orders); } var indices = component.Orders.Keys.ToList(); indices.Sort(); var amount = 0; foreach (var index in indices) { var order = component.Orders[index]; if (!order.Approved) { continue; } var cappedAmount = Math.Min(space - amount, order.Amount); amount += cappedAmount; DebugTools.Assert(amount <= space); if (cappedAmount < order.Amount) { var reducedOrder = new CargoOrderData(order.OrderNumber, order.Requester, order.Reason, order.ProductId, cappedAmount); orders.Add(reducedOrder); break; } orders.Add(order); if (amount == space) { break; } } return(orders); }
/// <summary> /// Spawn the product and a piece of paper. Attempt to attach the paper to the product. /// </summary> private void SpawnProduct(CargoTelepadComponent component, CargoOrderData data) { // spawn the order if (!_protoMan.TryIndex(data.ProductId, out CargoProductPrototype? prototype)) { return; } var xform = Transform(component.Owner); var product = EntityManager.SpawnEntity(prototype.Product, xform.Coordinates); Transform(product).Anchored = false; // spawn a piece of paper. var printed = EntityManager.SpawnEntity(component.PrinterOutput, xform.Coordinates); if (!TryComp <PaperComponent>(printed, out var paper)) { return; } // fill in the order data var val = Loc.GetString("cargo-console-paper-print-name", ("orderNumber", data.OrderNumber)); MetaData(printed).EntityName = val; _paperSystem.SetContent(printed, Loc.GetString( "cargo-console-paper-print-text", ("orderNumber", data.OrderNumber), ("itemName", prototype.Name), ("requester", data.Requester), ("reason", data.Reason), ("approver", data.Approver ?? string.Empty)), paper); // attempt to attach the label if (TryComp <PaperLabelComponent>(product, out var label)) { _slots.TryInsert(product, label.LabelSlot, printed, null); } }
/// <summary> /// Returns whether the database contains the order or not. /// </summary> /// <param name="order">The order to check</param> /// <returns>Whether the database contained the order or not.</returns> public bool Contains(CargoOrderData order) { return(_orders.ContainsValue(order)); }
public bool TryAddOrder(StationCargoOrderDatabaseComponent component, CargoOrderData data) { component.Orders.Add(data.OrderNumber, data); UpdateOrders(component); return(true); }