using System.Collections.Generic; using UnityEngine; namespace GrassCutter { /// /// Where grass leaves for Earth: E empties the tool in your hands at once or takes the bundle in your arms, thrown /// bundles and bundles arriving on a belt are paid for the moment they drop in. The HUD writes out a receipt. /// public class Depot : MonoBehaviour, IInteractable, ICargoSink, IPorts { public static readonly List All = new List(); public Transform mouth; /// Half the footprint across and along; a base intake has its back to the deck and takes no belt there. public float halfX = 1.05f, halfZ = 1.05f; public bool backToDeck; public Vector3 Mouth => mouth ? mouth.position : transform.position + Vector3.up * 1.1f; void OnEnable() => All.Add(this); void OnDisable() => All.Remove(this); /// Three belts on each side, twelve in all. public void Ports(List into) { for (int side = 0; side < 4; side++) { if (backToDeck && side == 2) continue; var inward = Quaternion.AngleAxis(side * 90f, transform.up) * -transform.forward; var across = Vector3.Cross(transform.up, inward); float reach = side % 2 == 0 ? halfZ : halfX, room = side % 2 == 0 ? halfX : halfZ; float step = Mathf.Min(0.6f, room * 0.45f); for (int k = -1; k <= 1; k++) into.Add(new Port { at = transform.position - inward * reach + across * (k * step) + transform.up * GameDefs.BeltLowest, dir = inward, input = true }); } } public string Prompt { get { var p = PlayerAgent.Local; if (!p) return null; return p.Tank.Value < 0.005f ? (backToDeck ? Loc.T("Base Intake — nothing to hand in") : Loc.T("Grass Depot — nothing to hand in")) : Loc.F("Hand in {0}", GameDefs.Kilos(p.Tank.Value)); } } public bool CanInteract => PlayerAgent.Local && PlayerAgent.Local.Tank.Value >= 0.005f; public void Interact() => PlayerAgent.Local?.Tools.Deposit(this); public bool ServerAccept(Cargo c, Vector3 from, Vector3 dir) { var ts = TeamState.Instance; if (!ts || !c || !c.IsSpawned) return false; ts.ServerDeposit(c.Kg.Value, c.kind, Mouth); c.Grab.Consumed = true; c.NetworkObject.Despawn(true); return true; } } }