62e48a3b0b
The 2026-08-06 audit found the shipping scene was still the abandoned co-op-Hades game with LANTERN combat bolted on, and that a third of the codebase was live code for a direction abandoned on 2026-07-13. Operator chose deletion over freezing: "everything is saved in source control if needed. I want the project to be clean." DELETED (~140 source files, Scripts 335->231, Tests 77->43): - Enemy variants + boss (H3). ChargerAuthoring / SpitterAuthoring / SwarmerAuthoring were attached to ZERO prefabs, so LungeState / SpitterState / SwarmerTag were never baked: ~272 lines of Bursted AI passes, BossAISystem (261 lines) and the whole MixBands escalation curve could not match a single chunk at runtime, while 734 lines of green tests certified them. Both shipping enemy prefabs were already byte-identical in stats. - Run/room lifecycle: RunDirector FSM, RunInfo/RunMap/RoomPlan/RoomTag, route select, portal interact, ready-check, room field/teardown. - Meta shop, prep loadout, boons (incl. KillRewardSystem and DashTrailDamageSystem, which existed only to serve boon flags). - Build palette + structures, shared storage, inventory/equipment (already recorded PAUSED in CLAUDE.md). - The HUD panels driving all of the above (HudSystem 1168 -> 610). KEPT deliberately: BaseGridMath + BaseAnchor (8 systems use PlotCenter for spawn rings, respawn and dynamic light), the resource ledger + StorageMath, the save system, region/relevancy. Three of these were in the delete set until I checked their consumers — worth remembering that the file-level manifest was wrong about them. Also folds in audit finding M5: PlayerClass was a second, server-only copy of the byte FrameId already replicates. It existed for the meta shop; with that gone, FrameId is the single frame identity. Harvest is now single-sink (ledger). HarvestMath keeps its shape so LANTERN's carried-vs-banked cargo split lands in one place, not two. 295/295 EditMode green, zero compile errors. Subscene re-bake and Play validation follow in the next commit. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
185 lines
8.4 KiB
C#
185 lines
8.4 KiB
C#
using System.Collections.Generic;
|
|
using ProjectM.Simulation;
|
|
using Unity.Entities;
|
|
using Unity.Mathematics;
|
|
using Unity.NetCode;
|
|
using Unity.Transforms;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
namespace ProjectM.Client
|
|
{
|
|
/// <summary>
|
|
/// Client-only ENEMY VISIBILITY markers — makes living enemies (especially the last one) easy to find so a room
|
|
/// never devolves into hunting an unseen straggler. Observe-only presentation <see cref="SystemBase"/> in
|
|
/// <see cref="PresentationSystemGroup"/> (same shape as <see cref="OnboardingSystem"/> / <see cref="HudSystem"/>:
|
|
/// reads replicated state, never mutates the sim, never destroys a ghost). Owns its own runtime UIDocument
|
|
/// (sortingOrder 48 — just under the HUD's 50) and a POOL of marker glyphs: each living enemy within
|
|
/// <see cref="FeelConfig.EnemyMarkerRange"/> of the local player gets either a clamped EDGE ARROW when off-screen
|
|
/// (rotated toward it — the "it's over here" cue, reusing OnboardingSystem's WorldToScreen edge math) or a subtle
|
|
/// overhead PIP when on-screen. The pips fade toward <see cref="FeelConfig.EnemyMarkerMinAlpha"/> as the on-screen
|
|
/// enemy count rises (declutter a swarm); off-screen arrows always stay full so a straggler is never missed. The
|
|
/// boss is excluded (it has its own HUD presence bar); corpses (<see cref="Dying"/>) are excluded.
|
|
/// </summary>
|
|
[WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation)]
|
|
[UpdateInGroup(typeof(PresentationSystemGroup))]
|
|
public partial class EnemyMarkerSystem : SystemBase
|
|
{
|
|
const int MaxMarkers = 32; // pool cap (a room never fields this many; when few remain, all are marked)
|
|
const float Margin = 48f; // screen-edge inset for off-screen arrows (panel units)
|
|
|
|
GameObject _go;
|
|
UIDocument _doc;
|
|
bool _built;
|
|
readonly List<Label> _pool = new();
|
|
readonly List<float3> _positions = new();
|
|
|
|
protected override void OnStartRunning()
|
|
{
|
|
if (_go != null) return;
|
|
_go = new GameObject("~EnemyMarkers");
|
|
_doc = _go.AddComponent<UIDocument>();
|
|
_doc.panelSettings = MenuUi.LoadPanelSettings();
|
|
_doc.sortingOrder = 48; // just below the HUD (50)
|
|
}
|
|
|
|
protected override void OnDestroy()
|
|
{
|
|
if (_go != null) Object.Destroy(_go);
|
|
}
|
|
|
|
protected override void OnUpdate()
|
|
{
|
|
if (_doc == null) return;
|
|
var root = _doc.rootVisualElement;
|
|
if (root == null) return;
|
|
if (!_built)
|
|
{
|
|
root.style.position = Position.Absolute;
|
|
root.style.left = 0; root.style.right = 0; root.style.top = 0; root.style.bottom = 0;
|
|
root.pickingMode = PickingMode.Ignore; // never eat world clicks
|
|
_built = true;
|
|
}
|
|
|
|
var cam = Camera.main;
|
|
if (!FeelConfig.EnemyMarkerEnabled || cam == null)
|
|
{
|
|
HideFrom(0);
|
|
return;
|
|
}
|
|
|
|
// Local player position (range gate — scopes markers to the current room / region).
|
|
bool haveLocal = false; float3 localPos = default;
|
|
foreach (var lt in SystemAPI.Query<RefRO<LocalTransform>>().WithAll<GhostOwnerIsLocal, PlayerTag>())
|
|
{ haveLocal = true; localPos = lt.ValueRO.Position; break; }
|
|
|
|
// Collect living enemies within range (nearest-capped by MaxMarkers).
|
|
_positions.Clear();
|
|
float rangeSq = FeelConfig.EnemyMarkerRange * FeelConfig.EnemyMarkerRange;
|
|
foreach (var lt in SystemAPI.Query<RefRO<LocalTransform>>().WithAll<EnemyTag>().WithNone<Dying>())
|
|
{
|
|
float3 p = lt.ValueRO.Position;
|
|
if (haveLocal && math.distancesq(p, localPos) > rangeSq) continue;
|
|
_positions.Add(p);
|
|
if (_positions.Count >= MaxMarkers) break;
|
|
}
|
|
|
|
float pw = root.layout.width, ph = root.layout.height;
|
|
if (pw <= 1f || ph <= 1f) { HideFrom(0); return; }
|
|
|
|
// First pass: how many are on-screen (drives the pip declutter fade).
|
|
int onScreen = 0;
|
|
for (int i = 0; i < _positions.Count; i++)
|
|
if (!IsOffScreen(cam, _positions[i], pw, ph)) onScreen++;
|
|
int fadeStart = math.max(1, FeelConfig.EnemyMarkerFadeStartCount);
|
|
float pipAlpha = math.lerp(1f, math.clamp(FeelConfig.EnemyMarkerMinAlpha, 0f, 1f),
|
|
math.saturate((onScreen - fadeStart) / (float)fadeStart));
|
|
|
|
// Second pass: place each marker.
|
|
Color baseCol = FeelConfig.EnemyMarkerColor;
|
|
float size = FeelConfig.EnemyMarkerSize;
|
|
for (int i = 0; i < _positions.Count; i++)
|
|
{
|
|
var lbl = GetMarker(i, root);
|
|
Place(lbl, cam, _positions[i], pw, ph, baseCol, size, pipAlpha);
|
|
}
|
|
HideFrom(_positions.Count);
|
|
}
|
|
|
|
bool IsOffScreen(Camera cam, float3 world, float pw, float ph)
|
|
{
|
|
Vector3 sp = cam.WorldToScreenPoint((Vector3)world);
|
|
bool behind = sp.z < 0f;
|
|
float px = (sp.x / Mathf.Max(1f, Screen.width)) * pw;
|
|
float py = (1f - sp.y / Mathf.Max(1f, Screen.height)) * ph;
|
|
if (behind) { px = pw - px; py = ph - py; }
|
|
return behind || px < Margin || px > pw - Margin || py < Margin || py > ph - Margin;
|
|
}
|
|
|
|
void Place(Label lbl, Camera cam, float3 world, float pw, float ph, Color baseCol, float size, float pipAlpha)
|
|
{
|
|
Vector3 sp = cam.WorldToScreenPoint((Vector3)world);
|
|
bool behind = sp.z < 0f;
|
|
float px = (sp.x / Mathf.Max(1f, Screen.width)) * pw;
|
|
float py = (1f - sp.y / Mathf.Max(1f, Screen.height)) * ph;
|
|
if (behind) { px = pw - px; py = ph - py; }
|
|
|
|
bool off = behind || px < Margin || px > pw - Margin || py < Margin || py > ph - Margin;
|
|
float cx = pw * 0.5f, cy = ph * 0.5f;
|
|
float dx = px - cx, dy = py - cy;
|
|
float len = Mathf.Sqrt(dx * dx + dy * dy);
|
|
if (len < 0.001f) { dx = 0f; dy = -1f; len = 1f; }
|
|
float ndx = dx / len, ndy = dy / len;
|
|
|
|
lbl.style.fontSize = size;
|
|
|
|
if (off)
|
|
{
|
|
// Clamp to the margin rectangle along the center->enemy ray, rotate a triangle toward it.
|
|
float tx = (ndx > 0 ? (pw - Margin - cx) : (Margin - cx)) / (Mathf.Abs(ndx) < 1e-4f ? (ndx < 0 ? -1e-4f : 1e-4f) : ndx);
|
|
float ty = (ndy > 0 ? (ph - Margin - cy) : (Margin - cy)) / (Mathf.Abs(ndy) < 1e-4f ? (ndy < 0 ? -1e-4f : 1e-4f) : ndy);
|
|
float tt = Mathf.Min(Mathf.Abs(tx), Mathf.Abs(ty));
|
|
float ax = cx + ndx * tt, ay = cy + ndy * tt;
|
|
float angle = Mathf.Atan2(dy, dx) * Mathf.Rad2Deg; // "▶" points +x at 0 deg
|
|
lbl.text = "▶";
|
|
lbl.style.left = ax - size * 0.5f;
|
|
lbl.style.top = ay - size * 0.5f;
|
|
lbl.style.rotate = new StyleRotate(new Rotate(new Angle(angle)));
|
|
lbl.style.color = new Color(baseCol.r, baseCol.g, baseCol.b, baseCol.a); // arrows stay full alpha
|
|
}
|
|
else
|
|
{
|
|
// Overhead pip pointing down at the enemy; fades when the screen is crowded.
|
|
lbl.text = "▾";
|
|
lbl.style.left = px - size * 0.5f;
|
|
lbl.style.top = py - size - 20f; // float above the enemy
|
|
lbl.style.rotate = new StyleRotate(new Rotate(new Angle(0f)));
|
|
lbl.style.color = new Color(baseCol.r, baseCol.g, baseCol.b, baseCol.a * pipAlpha);
|
|
}
|
|
lbl.style.display = DisplayStyle.Flex;
|
|
}
|
|
|
|
Label GetMarker(int i, VisualElement root)
|
|
{
|
|
while (_pool.Count <= i)
|
|
{
|
|
var l = new Label("▶");
|
|
l.style.position = Position.Absolute;
|
|
l.style.unityFontStyleAndWeight = FontStyle.Bold;
|
|
l.style.unityTextAlign = TextAnchor.MiddleCenter;
|
|
l.pickingMode = PickingMode.Ignore;
|
|
l.style.display = DisplayStyle.None;
|
|
root.Add(l);
|
|
_pool.Add(l);
|
|
}
|
|
return _pool[i];
|
|
}
|
|
|
|
void HideFrom(int start)
|
|
{
|
|
for (int i = start; i < _pool.Count; i++)
|
|
_pool[i].style.display = DisplayStyle.None;
|
|
}
|
|
}
|
|
}
|