- Carryable: generic pickup/carry component, cosmetic per-peer follow of the carrier's HandSocket instead of NGO reparenting (camera pitch isn't networked, so root-level reparenting wouldn't tilt with the view) - PlayerCarry: mutual exclusion with PlayerHands, server-timed hold-to-pour tick (client only signals start/stop, never per-unit requests) - IPourSource/IPourTarget: decouple PlayerInteractor from concrete Shop types, same pattern as IInteractable - Lieferkarton: gains product data (productId/quantity), two-stage Interact() (open, then pick up), IPourSource - ShelfSlot: implements IPourTarget, fills the previous RefreshVisuals TODO - PackageDisplay: renders quantity as a proper column x row grid that stacks into further layers as space runs out, reused by both containers - FlyingPackage: small non-networked cosmetic visual that arcs a package from the carried box to its exact landing slot in the shelf grid on every successful pour tick, broadcast via Rpc(SendTo.Everyone) - StorageCrate: rejects pickup while the player is carrying a box Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
66 lines
2.2 KiB
C#
66 lines
2.2 KiB
C#
using AfterHours.Data;
|
|
using AfterHours.Interaction;
|
|
using AfterHours.Networking;
|
|
using Unity.Netcode;
|
|
using UnityEngine;
|
|
|
|
namespace AfterHours.Shop
|
|
{
|
|
/// <summary>
|
|
/// Lagerkiste im Backroom: hält Nachschub einer einzigen Produktsorte.
|
|
/// Spieler nehmen daraus in die Hände auf und tragen die Ware zum Regal
|
|
/// (siehe ShelfSlot.Interact).
|
|
/// </summary>
|
|
public sealed class StorageCrate : NetworkBehaviour, IInteractable
|
|
{
|
|
[SerializeField] private ProductCatalog _catalog;
|
|
[SerializeField] private int _productId = -1;
|
|
[SerializeField] private int _startingQuantity = 200;
|
|
|
|
private readonly NetworkVariable<int> _quantity = new(0);
|
|
|
|
public int ProductId => _productId;
|
|
public int Quantity => _quantity.Value;
|
|
public bool IsEmpty => _quantity.Value <= 0;
|
|
|
|
public override void OnNetworkSpawn()
|
|
{
|
|
if (!IsServer) return;
|
|
|
|
_quantity.Value = _startingQuantity;
|
|
StorageCrateRegistry.Instance.Register(this);
|
|
}
|
|
|
|
public override void OnNetworkDespawn()
|
|
{
|
|
if (IsServer) StorageCrateRegistry.Instance.Unregister(this);
|
|
}
|
|
|
|
public string GetPrompt(ulong clientId)
|
|
{
|
|
var product = _catalog.Get(_productId);
|
|
string name = product != null ? product.DisplayName : "?";
|
|
return IsEmpty ? $"{name} — Lager leer" : $"{name} nehmen — {_quantity.Value} im Lager";
|
|
}
|
|
|
|
/// <summary>Server: Spieler nimmt Ware in die Hände auf.</summary>
|
|
public void Interact(NetworkObject actor)
|
|
{
|
|
if (!IsServer || IsEmpty) return;
|
|
if (!actor.TryGetComponent<PlayerHands>(out var hands)) return;
|
|
if (actor.TryGetComponent<PlayerCarry>(out var carry) && carry.IsCarrying) return;
|
|
|
|
int want = Mathf.Min(_quantity.Value, PlayerHands.MaxCarry);
|
|
int taken = hands.TryTake(_productId, want);
|
|
_quantity.Value -= taken;
|
|
}
|
|
|
|
/// <summary>Server: Lieferung trifft ein.</summary>
|
|
public void Restock(int quantity)
|
|
{
|
|
if (!IsServer || quantity <= 0) return;
|
|
_quantity.Value += quantity;
|
|
}
|
|
}
|
|
}
|