feat(economy): add Bestellsystem mit Lieferzeit

- SupplierService: Bestellungen mit Lieferzeit-Berechnung
- OrderTerminal: Spieler-Interaktion zum Aufgeben von Bestellungen
- StorageCrateRegistry + StorageCrate.Restock: Server registriert Kisten
  und füllt sie bei Lieferung wieder auf
- GameClock.TotalHours: durchgehende Spielzeit für Lieferzeit-Berechnung
- ROADMAP: Bestellsystem-Punkt als erledigt markiert

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-14 19:17:36 +02:00
co-authored by Claude Sonnet 5
parent 2b48b76a91
commit 7e4cebbf13
11 changed files with 202 additions and 2 deletions
+75
View File
@@ -0,0 +1,75 @@
using System.Collections.Generic;
using AfterHours.Core;
using AfterHours.Data;
using AfterHours.Shop;
using Unity.Netcode;
using UnityEngine;
namespace AfterHours.Economy
{
/// <summary>
/// Bestellungen beim Großhandel: Ware wird sofort bezahlt, trifft aber
/// erst nach einer Lieferzeit in der passenden Lagerkiste ein. Nur Server.
/// </summary>
public sealed class SupplierService : NetworkBehaviour
{
public static SupplierService Instance { get; private set; }
[SerializeField] private ProductCatalog _catalog;
[SerializeField] private float _deliveryLeadHours = 4f;
private readonly List<PurchaseOrder> _pending = new();
private void Awake() => Instance = this;
public override void OnNetworkDespawn()
{
if (Instance == this) Instance = null;
}
private void Update()
{
if (!IsServer || GameClock.Instance == null) return;
float now = GameClock.Instance.TotalHours;
for (int i = _pending.Count - 1; i >= 0; i--)
{
if (now < _pending[i].DeliveryTime) continue;
Deliver(_pending[i]);
_pending.RemoveAt(i);
}
}
/// <summary>Server: Bestellung aufgeben. False, wenn Produkt unbekannt oder Geld nicht reicht.</summary>
public bool PlaceOrder(int productId, int quantity)
{
if (!IsServer || quantity <= 0) return false;
if (!_catalog.TryGet(productId, out var product)) return false;
float cost = product.WholesalePrice * quantity;
if (!ShopEconomy.Instance.TrySpend(cost)) return false;
var order = new PurchaseOrder { DeliveryTime = GameClock.Instance.TotalHours + _deliveryLeadHours };
order.Add(productId, quantity, product.WholesalePrice);
_pending.Add(order);
return true;
}
private void Deliver(PurchaseOrder order)
{
order.Delivered = true;
foreach (var line in order.Lines)
{
var crate = StorageCrateRegistry.Instance.FindFor(line.ProductId);
if (crate == null)
{
Debug.LogWarning($"[SupplierService] Keine Lagerkiste für ProductId {line.ProductId} — Lieferung verworfen.");
continue;
}
crate.Restock(line.Quantity);
}
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: a5e238d8d78eca84e8dec7321b910cb2