RynthSuite/Plugins/RynthCore.Plugin.RynthAi/LegacyUi/RadarSnapshot.cs

88 lines
4.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
namespace RynthCore.Plugin.RynthAi.LegacyUi;
// DTOs polled by the engine-side Avalonia radar panel. Geometry (walls/fills)
// is only emitted when the engine's cached MapVersion (= landblock id) differs
// from the live one, so the steady-state payload is small.
//
// Coordinate convention: world-space landblock coords (px + (lb>>8 & 0xFF)*192,
// py + (lb & 0xFF)*192). The engine projects to screen using player pose +
// zoom + heading.
internal sealed class RadarSnapshotPayload
{
[JsonPropertyName("mapVersion")] public uint MapVersion { get; set; }
[JsonPropertyName("geometryIncluded")] public bool GeometryIncluded { get; set; }
[JsonPropertyName("isIndoor")] public bool IsIndoor { get; set; }
[JsonPropertyName("player")] public RadarPlayer Player { get; set; } = new();
// AC NS/EW (positive = N/E). Only meaningful outdoors; indoor renders the
// landblock id instead. Set to NaN when the host can't resolve them.
[JsonPropertyName("ns")] public double Ns { get; set; } = double.NaN;
[JsonPropertyName("ew")] public double Ew { get; set; } = double.NaN;
[JsonPropertyName("layerZs")] public List<float> LayerZs { get; set; } = new();
[JsonPropertyName("currentLayerZ")] public float CurrentLayerZ { get; set; }
// Per-layer wall segments. Flattened: ax, ay, bx, by, gx, gy × N (6 floats/seg).
[JsonPropertyName("walls")] public List<RadarWallLayer> Walls { get; set; } = new();
// Fallback floor strips when no baked texture exists. x0, y0, x1, y1, type × N.
[JsonPropertyName("fills")] public List<RadarFillLayer> Fills { get; set; } = new();
// Per-layer pre-merged visited floor strips. x0, y0, x1, y1 × N.
[JsonPropertyName("visited")] public List<RadarVisitedLayer> Visited { get; set; } = new();
// All marker kinds included; engine filters by user setting.
[JsonPropertyName("markers")] public List<RadarMarker> Markers { get; set; } = new();
}
internal sealed class RadarPlayer
{
[JsonPropertyName("cellId")] public uint CellId { get; set; }
[JsonPropertyName("landblock")] public uint Landblock { get; set; }
[JsonPropertyName("x")] public float X { get; set; } // landblock-local
[JsonPropertyName("y")] public float Y { get; set; }
[JsonPropertyName("z")] public float Z { get; set; }
[JsonPropertyName("worldX")] public float WorldX { get; set; } // global (px + lb*192)
[JsonPropertyName("worldY")] public float WorldY { get; set; }
[JsonPropertyName("heading")] public float Heading { get; set; } // degrees, AC convention
}
internal sealed class RadarWallLayer
{
[JsonPropertyName("z")] public float Z { get; set; }
[JsonPropertyName("segments")] public float[] Segments { get; set; } = Array.Empty<float>();
}
internal sealed class RadarFillLayer
{
[JsonPropertyName("z")] public float Z { get; set; }
[JsonPropertyName("strips")] public float[] Strips { get; set; } = Array.Empty<float>();
}
internal sealed class RadarVisitedLayer
{
[JsonPropertyName("z")] public float Z { get; set; }
[JsonPropertyName("strips")] public float[] Strips { get; set; } = Array.Empty<float>();
}
// Kind (RadarKind in the engine's UI/Data/RadarSnapshotJson.cs): 0 monster, 1 NPC, 2 portal,
// 3 door; appended 2026-10-04: 4 player, 5 fellow, 6 your pet, 7 vendor, 8 corpse, 9 your
// corpse, 10 lifestone, 11 item on the ground. Engines before that drop kinds 4+ (not drawn).
internal sealed class RadarMarker
{
[JsonPropertyName("kind")] public byte Kind { get; set; }
[JsonPropertyName("x")] public float X { get; set; } // world-space
[JsonPropertyName("y")] public float Y { get; set; }
[JsonPropertyName("z")] public float Z { get; set; }
[JsonPropertyName("label")] public string? Label { get; set; }
// The object's id, so the engine's radar click selects exactly this object
// (engines from 2026-10-01). Older engines skip the unknown field.
[JsonPropertyName("id")] public uint Id { get; set; }
}
[JsonSerializable(typeof(RadarSnapshotPayload))]
[JsonSourceGenerationOptions(WriteIndented = false)]
internal partial class RadarSnapshotJsonContext : JsonSerializerContext { }