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>
84 lines
2.8 KiB
C#
84 lines
2.8 KiB
C#
using System;
|
|
using Unity.Collections;
|
|
using Unity.Netcode;
|
|
using UnityEngine;
|
|
|
|
namespace GrassCutter
|
|
{
|
|
public partial class TeamState
|
|
{
|
|
/// <summary>Sector, what it paid.</summary>
|
|
public static event Action<int, double> SectorClosed;
|
|
/// <summary>Who, which landmark, what it paid.</summary>
|
|
public static event Action<string, int, double> MarkFound;
|
|
|
|
float _mownAt;
|
|
|
|
void WatchSectors()
|
|
{
|
|
MowMap.SectorDone += OnSectorDone;
|
|
Found.OnListChanged += _ => { if (Landmarks.Instance) Landmarks.Instance.Refresh(); Changed?.Invoke(); };
|
|
if (Landmarks.Instance) Landmarks.Instance.Refresh();
|
|
}
|
|
|
|
void UnwatchSectors() => MowMap.SectorDone -= OnSectorDone;
|
|
|
|
/// <summary>Each peer finishes sectors for itself, a little apart: whoever gets there first tells the host.</summary>
|
|
void OnSectorDone(int id)
|
|
{
|
|
if (IsServer) ServerCloseSector(id);
|
|
else SectorDoneRpc(id);
|
|
}
|
|
|
|
[Rpc(SendTo.Server)]
|
|
void SectorDoneRpc(int id, RpcParams rpc = default) => ServerCloseSector(id);
|
|
|
|
void ServerCloseSector(int id)
|
|
{
|
|
if (id < 0 || id >= HexGrid.Cells || !MowMap.Claim(id)) return;
|
|
double pay = GameDefs.SectorBonus(Level(PerkId.RegionBonus)) * Crops.Pays(Crops.At(id));
|
|
Money.Value += pay;
|
|
Closed.Value++;
|
|
SectorClosedRpc(id, pay);
|
|
}
|
|
|
|
[Rpc(SendTo.Everyone)]
|
|
void SectorClosedRpc(int id, double pay)
|
|
{
|
|
MowMap.Close(id);
|
|
SectorClosed?.Invoke(id, pay);
|
|
}
|
|
|
|
void TickSectors()
|
|
{
|
|
if (Time.time < _mownAt) return;
|
|
_mownAt = Time.time + 1f;
|
|
Mown.Value = MowMap.MownArea();
|
|
}
|
|
|
|
// ───────────────────────── stakes & survey points ─────────────────────────
|
|
|
|
[Rpc(SendTo.Server)]
|
|
public void ClaimMarkRpc(int id, RpcParams rpc = default)
|
|
{
|
|
var who = PlayerOf(rpc.Receive.SenderClientId);
|
|
if (!who || id < 0 || id >= Landmarks.Count || Found.Contains(id)) return;
|
|
if ((who.transform.position - Landmarks.Spot(id)).sqrMagnitude > 64f) return;
|
|
double pay = Landmarks.Pay(id);
|
|
Found.Add(id);
|
|
Money.Value += pay;
|
|
MarkFoundRpc(who.DisplayName, id, pay);
|
|
}
|
|
|
|
[Rpc(SendTo.Everyone)]
|
|
void MarkFoundRpc(FixedString64Bytes who, int id, double pay) => MarkFound?.Invoke(who.ToString(), id, pay);
|
|
|
|
public int FoundCount(bool points)
|
|
{
|
|
int n = 0;
|
|
foreach (int id in Found) if (Landmarks.IsPoint(id) == points) n++;
|
|
return n;
|
|
}
|
|
}
|
|
}
|