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>
This commit is contained in:
101
Assets/Scripts/Gameplay/Reaper.cs
Normal file
101
Assets/Scripts/Gameplay/Reaper.cs
Normal file
@ -0,0 +1,101 @@
|
||||
using Unity.Netcode;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GrassCutter
|
||||
{
|
||||
/// <summary>The Reaper belongs to no dock: it goes from sector to sector over the whole planet and shoots its bundles into a catcher, however far.</summary>
|
||||
public class Reaper : Mowbot
|
||||
{
|
||||
const float ShotEvery = 0.5f, ShowEvery = 0.4f, ReelSpeed = 420f;
|
||||
|
||||
public Transform muzzle, reel;
|
||||
|
||||
float _nextShow, _spun;
|
||||
int _reelAxis = -1;
|
||||
|
||||
protected override Transform Body => transform;
|
||||
protected override Vector3 Origin => At.Value;
|
||||
protected override int Reach => 100000;
|
||||
|
||||
public override string Prompt => Loc.F("{0}: {1}, {2} of {3}", Def.name, MoodText, GameDefs.Kilos(Hopper.Value), GameDefs.Kilos(HopperCap));
|
||||
|
||||
public override void Moved(Vector3 at)
|
||||
{
|
||||
base.Moved(at);
|
||||
Teleported(at);
|
||||
}
|
||||
|
||||
protected override bool Stay(float dt)
|
||||
{
|
||||
int shots = Mathf.CeilToInt(dt / ShotEvery);
|
||||
while (Hopper.Value >= GameDefs.BundleKg && shots-- > 0)
|
||||
{
|
||||
var c = Catcher.WithRoom();
|
||||
if (!c) break;
|
||||
c.ServerCatch(GameDefs.BundleKg);
|
||||
Hopper.Value -= GameDefs.BundleKg;
|
||||
if (Time.time >= _nextShow)
|
||||
{
|
||||
_nextShow = Time.time + ShowEvery;
|
||||
ShotRpc(c.transform.position + c.transform.up * 2f);
|
||||
}
|
||||
}
|
||||
if (Hopper.Value < HopperCap) return false;
|
||||
Mowing.Value = false;
|
||||
Mood.Value = (byte)RobotMood.NoCatcher;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void NoWork() => Mood.Value = (byte)RobotMood.Finished;
|
||||
|
||||
[Rpc(SendTo.Everyone)]
|
||||
void ShotRpc(Vector3 to)
|
||||
{
|
||||
BundleShot.Fly(muzzle ? muzzle.position : At.Value + transform.up * 1.5f, to);
|
||||
Sfx.PlayAt("launcher_fire", At.Value, 0.5f, 1.2f);
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
if (!reel || !Mowing.Value) return;
|
||||
if (_reelAxis < 0) _reelAxis = BaseRot.LocalAxisFor(reel, transform.right);
|
||||
_spun += ReelSpeed * Time.deltaTime;
|
||||
var axis = _reelAxis == 0 ? Vector3.right : _reelAxis == 1 ? Vector3.up : Vector3.forward;
|
||||
reel.localRotation = BaseRot.Of(reel) * Quaternion.Euler(axis * _spun);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>A bundle in the air. Only for the eyes: the catcher has it already.</summary>
|
||||
public class BundleShot : MonoBehaviour
|
||||
{
|
||||
const float Near = 600f;
|
||||
|
||||
Vector3 _from, _to;
|
||||
float _t, _time, _arc;
|
||||
|
||||
public static void Fly(Vector3 from, Vector3 to)
|
||||
{
|
||||
var cam = Camera.main;
|
||||
if (!cam || (Vector3.Distance(cam.transform.position, from) > Near && Vector3.Distance(cam.transform.position, to) > Near)) return;
|
||||
var go = GameObject.CreatePrimitive(PrimitiveType.Cube);
|
||||
Destroy(go.GetComponent<Collider>());
|
||||
go.transform.localScale = Vector3.one * 0.5f;
|
||||
go.GetComponent<Renderer>().sharedMaterial = BuildLook.Mat("M_Bundle", new Color(0.62f, 0.78f, 0.28f));
|
||||
var shot = go.AddComponent<BundleShot>();
|
||||
float far = Vector3.Distance(from, to);
|
||||
shot._from = Planet.Up(from);
|
||||
shot._to = Planet.Up(to);
|
||||
shot._time = Mathf.Clamp(1f + far / 150f, 1f, 8f);
|
||||
shot._arc = Mathf.Min(8f + far * 0.25f, 200f);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
_t += Time.deltaTime / _time;
|
||||
if (_t >= 1f) { Destroy(gameObject); return; }
|
||||
var d = Vector3.Slerp(_from, _to, _t);
|
||||
transform.position = Planet.OnSurface(d) + d * (1.5f + Mathf.Sin(_t * Mathf.PI) * _arc);
|
||||
transform.Rotate(180f * Time.deltaTime, 90f * Time.deltaTime, 0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user