Files
NiemandKG d1c3761e58 Grass Cutters Together: the project as of moon-sweepers f3666f0
A clean start for the shared repository: the Unity project (Assets, Packages, ProjectSettings), ArtSource, Docs and
Tools as they stood at f3666f0 in the old local repository, with its generated prefabs and scene brought up to date.
Images, audio, models and binaries go through Git LFS (.gitattributes).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 18:44:40 +06:00

69 lines
2.3 KiB
C#

using System.Collections.Generic;
using Unity.Netcode;
using UnityEngine;
namespace GrassCutter
{
/// <summary>A building that holds loose grass and sends it out of its ports as bundles, one every fifth of a second.</summary>
public abstract class SiloPiece : NetworkBehaviour, IInteractable, IPorts, IPieceState
{
const float Every = 0.2f;
/// <summary>Everything a mower can unload onto: garages and unload bays.</summary>
public static readonly List<SiloPiece> Pads = new List<SiloPiece>();
/// <summary>Is this spot on the part a mower drives onto to unload?</summary>
public virtual bool OnPad(Vector3 p) => false;
/// <summary>The middle of that part, for markers.</summary>
public virtual Vector3 PadSpot => transform.position;
public virtual string PadName => Loc.T("Unload");
public static SiloPiece PadUnder(Vector3 p)
{
foreach (var s in Pads) if (s && s.IsSpawned && s.OnPad(p)) return s;
return null;
}
public override void OnNetworkSpawn() { if (!Pads.Contains(this)) Pads.Add(this); }
public override void OnNetworkDespawn() => Pads.Remove(this);
public override void OnDestroy()
{
Pads.Remove(this);
base.OnDestroy();
}
public readonly NetworkVariable<float> Silo = new NetworkVariable<float>();
float _nextOut;
int _turn;
public abstract string Prompt { get; }
public virtual bool CanInteract => TeamState.Instance;
public abstract void Interact();
public abstract void Ports(List<Port> into);
public float[] State
{
get => new[] { Silo.Value };
set { if (value != null && value.Length > 0) Silo.Value = value[0]; }
}
[Rpc(SendTo.Server)]
public void TakeRpc(float kg)
{
if (kg > 0f) Silo.Value += kg;
}
protected virtual void Update()
{
if (!IsServer || !IsSpawned || Time.time < _nextOut) return;
var piece = GetComponent<BuildPiece>();
_nextOut = Time.time + Every / (piece ? piece.TierMul : 1f);
// hatches shut: it only fills up
if (piece && piece.Switched) return;
BeltNet.Drain(GetComponent<BuildPiece>(), Silo, ref _turn);
}
}
}