43 lines
1.2 KiB
C#
43 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace AfterHours.Economy
|
|
{
|
|
/// <summary>Eine Position einer Großhandelsbestellung.</summary>
|
|
[Serializable]
|
|
public struct OrderLine
|
|
{
|
|
public int ProductId;
|
|
public int Quantity;
|
|
public float UnitPrice;
|
|
|
|
public float LineTotal => Quantity * UnitPrice;
|
|
}
|
|
|
|
/// <summary>Bestellung beim Großhandel. Wird nur serverseitig gehalten.</summary>
|
|
public sealed class PurchaseOrder
|
|
{
|
|
private readonly List<OrderLine> _lines = new();
|
|
|
|
public IReadOnlyList<OrderLine> Lines => _lines;
|
|
|
|
/// <summary>Spielzeit in Sekunden, zu der die Lieferung eintrifft.</summary>
|
|
public float DeliveryTime { get; set; }
|
|
|
|
public bool Delivered { get; set; }
|
|
|
|
public void Add(int productId, int quantity, float unitPrice)
|
|
{
|
|
if (quantity <= 0) return;
|
|
_lines.Add(new OrderLine { ProductId = productId, Quantity = quantity, UnitPrice = unitPrice });
|
|
}
|
|
|
|
public float Total()
|
|
{
|
|
float sum = 0f;
|
|
foreach (var line in _lines) sum += line.LineTotal;
|
|
return sum;
|
|
}
|
|
}
|
|
}
|