This commit is contained in:
2026-08-11 20:17:42 +02:00
parent 404d15a56c
commit d5b5d200a6
12 changed files with 56 additions and 461 deletions
+26 -5
View File
@@ -57,25 +57,46 @@ namespace AfterHours.Shop
public void Interact(NetworkObject actor)
{
if (!IsServer) return;
if (!actor.TryGetComponent<PlayerHands>(out var hands) || hands.IsEmpty) return;
// TODO: Debug.Log-Zeilen entfernen, sobald Regal-Befüllen zuverlässig läuft.
if (!actor.TryGetComponent<PlayerHands>(out var hands) || hands.IsEmpty)
{
Debug.Log("[ShelfSlot] Abbruch: keine PlayerHands am Actor oder Hände leer.");
return;
}
int incomingProductId = hands.ProductId;
// Fach ist mit anderer Ware belegt -> nichts tun.
if (!IsEmpty && _productId.Value != hands.ProductId) return;
if (!IsEmpty && _productId.Value != incomingProductId)
{
Debug.Log($"[ShelfSlot] Abbruch: Fach belegt mit ProductId {_productId.Value}, Hand trägt {incomingProductId}.");
return;
}
int free = Capacity() - _quantity.Value;
if (free <= 0) return;
if (free <= 0)
{
Debug.Log($"[ShelfSlot] Abbruch: Fach voll ({_quantity.Value}/{Capacity()}).");
return;
}
int moved = hands.TryGive(Mathf.Min(free, hands.Quantity));
if (moved <= 0) return;
if (moved <= 0)
{
Debug.Log("[ShelfSlot] Abbruch: TryGive() lieferte 0 Stück.");
return;
}
if (IsEmpty)
{
_productId.Value = hands.ProductId >= 0 ? hands.ProductId : _productId.Value;
_productId.Value = incomingProductId;
var def = _catalog.Get(_productId.Value);
if (def != null && _price.Value <= 0f) _price.Value = def.RecommendedPrice;
}
_quantity.Value += moved;
Debug.Log($"[ShelfSlot] Eingeräumt: {moved} Stück, jetzt {_quantity.Value}/{Capacity()}.");
}
/// <summary>Server: Kunde entnimmt ein Stück.</summary>