using System.Collections.Generic; using Unity.Netcode; using UnityEngine; namespace GrassCutter { /// Catches what a Reaper shoots from anywhere on the planet and puts it on the belt. public class Catcher : SiloPiece { const float Room = 100f; static readonly List s_all = new List(); public override string Prompt => Loc.F("Bundle Catcher: {0} of {1}", GameDefs.Kilos(Silo.Value), GameDefs.Kilos(Room)); public override void Interact() => Sfx.Play("ui_click", 0.6f); public override void OnNetworkSpawn() => s_all.Add(this); public override void OnNetworkDespawn() => s_all.Remove(this); public override void OnDestroy() { s_all.Remove(this); base.OnDestroy(); } public override void Ports(List into) { into.Add(BeltNet.Front(transform)); } /// The emptiest catcher that still has room. public static Catcher WithRoom() { Catcher best = null; foreach (var c in s_all) if (c && c.Silo.Value + GameDefs.BundleKg <= Room && (!best || c.Silo.Value < best.Silo.Value)) best = c; return best; } public void ServerCatch(float kg) { Silo.Value += kg; CaughtRpc(); } [Rpc(SendTo.Everyone)] void CaughtRpc() => Sfx.PlayAt("cargo_load", transform.position, 0.5f, 1f, 0.1f, 0.4f); } }