initial
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user