RynthSuite as of 2026-09-27 (internal 1816d05): AutoVendor (UtilityBelt port), missile/magic facing and arc line of sight, nav waypoint skipping, rebuff batch and item-enchant fixes, crafting fallback, Loot Editor AutoVendor folder and command-line open, release 2026.9.27.2

This commit is contained in:
Tom Bohar 2026-09-27 20:25:46 -04:00
commit d55ffda4ed
33 changed files with 4364 additions and 207 deletions

View file

@ -0,0 +1,182 @@
using System;
namespace RynthCore.Plugin.RynthAi.Raycasting
{
/// <summary>
/// The flight path of an AC missile (arrow, bolt, dart), as pure math: no host, no
/// geometry, no allocation. Kept dependency-free so Tools/RynthCore.MissileArcTests
/// compiles it directly.
///
/// The server launches every missile at the weapon's fixed speed on the LOW solution of
/// the ballistic arc to the aim point, under gravity (ACE GetProjectileVelocity →
/// Trajectory.solve_ballistic_arc, first solution; PhysicsGlobals.Gravity = 9.8). So the
/// arc height is not a constant: it grows with distance and shrinks with launch speed.
/// At 5 m a bow shot is a straight line; at 40 m with 25 m/s it rises about 3.5 m above
/// the launch point, which is enough to hit a dungeon ceiling the straight line clears.
///
/// Units are meters, Z up. "t" is the horizontal fraction of the shot, 0 at the launch
/// point and 1 at the aim point.
/// </summary>
public readonly struct MissileArc
{
/// <summary>Launch point.</summary>
public readonly float OX, OY, OZ;
/// <summary>Unit horizontal direction from launch point to aim point.</summary>
public readonly float DirX, DirY;
/// <summary>Horizontal distance from launch point to aim point.</summary>
public readonly float HorizDist;
/// <summary>Aim point Z minus launch point Z.</summary>
public readonly float Rise;
/// <summary>Tangent of the launch elevation (low solution).</summary>
public readonly float TanTheta;
/// <summary>Curvature: height(x) = x·TanTheta − K·x², K = g(1+tan²θ)/(2v²).</summary>
public readonly float K;
/// <summary>False when the aim point is out of reach at this launch speed.</summary>
public readonly bool Valid;
/// <summary>True for a (near) vertical shot, flown as a straight line.</summary>
public readonly bool Vertical;
internal MissileArc(float ox, float oy, float oz, float dirX, float dirY, float horizDist,
float rise, float tanTheta, float k, bool valid, bool vertical)
{
OX = ox; OY = oy; OZ = oz;
DirX = dirX; DirY = dirY;
HorizDist = horizDist; Rise = rise;
TanTheta = tanTheta; K = k;
Valid = valid; Vertical = vertical;
}
/// <summary>Height above the launch point at horizontal fraction t (no clearance).</summary>
public float HeightAt(float t)
{
if (!Valid) return 0f;
if (Vertical) return Rise * t;
float x = t * HorizDist;
return x * TanTheta - K * x * x;
}
/// <summary>
/// The point at horizontal fraction t, raised by <paramref name="clearance"/> at
/// mid-flight (see <see cref="MissileBallistics.ClearanceBump"/>). The ends never
/// move: t=0 is the launch point and t=1 the aim point.
/// </summary>
public void PointAt(float t, float clearance, out float x, out float y, out float z)
{
float h = t * HorizDist;
x = OX + DirX * h;
y = OY + DirY * h;
z = OZ + HeightAt(t) + MissileBallistics.ClearanceBump(t, clearance);
}
/// <summary>
/// How far the arc rises above the straight line from launch point to aim point, at
/// its highest. This is the part a straight line-of-sight check never sees.
/// </summary>
public float MaxRiseAboveChord
{
get
{
if (!Valid || Vertical || HorizDist <= 0f || K <= 0f) return 0f;
// height(x) − Rise·x/d = x·(tanθ − Rise/d) − K·x². Its maximum is at
// x* = a/(2K), value a²/(4K), where a = tanθ − Rise/d.
float a = TanTheta - Rise / HorizDist;
if (a <= 0f) return 0f;
float xStar = a / (2f * K);
if (xStar >= HorizDist) xStar = HorizDist;
return a * xStar - K * xStar * xStar;
}
}
/// <summary>Highest point of the flight above the launch point (never below the ends).</summary>
public float ApexAboveLaunch
{
get
{
if (!Valid) return 0f;
if (Vertical) return Math.Max(0f, Rise);
if (K <= 0f) return Math.Max(0f, Rise);
float xApex = TanTheta / (2f * K);
float apex = xApex > 0f && xApex < HorizDist
? TanTheta * xApex - K * xApex * xApex
: 0f;
return Math.Max(apex, Math.Max(0f, Rise));
}
}
}
public static class MissileBallistics
{
/// <summary>AC's gravity (PhysicsGlobals.Gravity = -9.8).</summary>
public const float AcGravity = 9.8f;
/// <summary>Below this horizontal distance a shot is treated as vertical.</summary>
private const float VerticalEpsilon = 0.05f;
/// <summary>
/// Solves the low ballistic arc from the launch point to the aim point at a fixed launch
/// speed. Out of reach (the speed can't carry that far or that high) gives Valid=false.
/// </summary>
public static MissileArc Solve(float ox, float oy, float oz,
float tx, float ty, float tz,
float speed, float gravity = AcGravity)
{
float dx = tx - ox, dy = ty - oy;
float rise = tz - oz;
float d = (float)Math.Sqrt(dx * dx + dy * dy);
if (float.IsNaN(d) || float.IsNaN(rise) || speed <= 0f || gravity <= 0f)
return new MissileArc(ox, oy, oz, 0f, 0f, 0f, 0f, 0f, 0f, valid: false, vertical: false);
if (d < VerticalEpsilon)
return new MissileArc(ox, oy, oz, 0f, 0f, d, rise, 0f, 0f, valid: true, vertical: true);
// Low-angle solution of rise = d·tanθ − g·d²·(1+tan²θ)/(2v²):
// tanθ = (v² − √(v⁴ − g(g·d² + 2·rise·v²))) / (g·d)
double v2 = (double)speed * speed;
double disc = v2 * v2 - gravity * (gravity * (double)d * d + 2.0 * rise * v2);
if (disc < 0.0)
return new MissileArc(ox, oy, oz, dx / d, dy / d, d, rise, 0f, 0f, valid: false, vertical: false);
double tan = (v2 - Math.Sqrt(disc)) / (gravity * (double)d);
double k = gravity * (1.0 + tan * tan) / (2.0 * v2);
return new MissileArc(ox, oy, oz, dx / d, dy / d, d, rise, (float)tan, (float)k, valid: true, vertical: false);
}
/// <summary>
/// Extra height added to the tested path: <paramref name="clearance"/> at mid-flight,
/// tapering to zero at both ends (4t(1−t)), so the launch and aim points stay put. It
/// covers what the model can't know exactly: launch height, the real launch speed, the
/// projectile's own size.
/// </summary>
public static float ClearanceBump(float t, float clearance)
{
if (clearance <= 0f || t <= 0f || t >= 1f) return 0f;
return clearance * 4f * t * (1f - t);
}
/// <summary>Number of straight segments used to test an arc: about one per 2.5 m, 6 to 24.</summary>
public static int SegmentCount(float horizDist)
{
if (float.IsNaN(horizDist) || horizDist <= 0f) return 6;
int n = (int)Math.Ceiling(horizDist / 2.5f);
return Math.Clamp(n, 6, 24);
}
/// <summary>
/// Highest Z the tested path reaches (arc plus clearance), sampled like the geometry
/// test samples it. Lets a caller compare the path against a known ceiling height.
/// </summary>
public static float MaxPathZ(in MissileArc arc, float clearance)
{
if (!arc.Valid) return float.NaN;
int n = SegmentCount(arc.HorizDist) * 4;
float best = Math.Max(arc.OZ, arc.OZ + arc.Rise);
for (int i = 1; i < n; i++)
{
arc.PointAt((float)i / n, clearance, out _, out _, out float z);
if (z > best) best = z;
}
return best;
}
}
}

View file

@ -224,6 +224,89 @@ namespace RynthCore.Plugin.RynthAi.Raycasting
return false; // Arc clears all obstacles
}
/// <summary>What <see cref="IsBallisticArcBlocked"/> found, for the LOS debug log and /ra lostest.</summary>
public struct ArcLosResult
{
public bool Blocked;
public bool OutOfReach; // the launch speed can't carry the shot that far / that high
public float Sag; // how far the arc rises above the straight line, at most (m)
public float Apex; // highest point of the flight above the launch point (m)
public float HitAlong; // horizontal distance from the shooter to the hit (m)
public float HitZ; // height of the hit above the launch point (m)
}
/// <summary>
/// Tests the path a missile really flies: the low ballistic arc at the weapon's launch
/// speed (see <see cref="MissileBallistics"/>), raised by <paramref name="clearance"/>
/// at mid-flight. Unlike <see cref="IsArcPathBlocked"/> (the old flat-ground
/// approximation, kept for magic arcs), the arc passes exactly through the aim point
/// for any height difference. Floors and ceilings are part of the dungeon geometry, so
/// an arc that rises into a ceiling reports blocked. Out of reach counts as blocked.
/// Hits within 0.5 m of the shooter or 0.3 m of the target are ignored, as in the
/// straight-line test.
/// </summary>
public static bool IsBallisticArcBlocked(Vector3 origin, Vector3 target, float speed, float clearance,
List<BoundingVolume> geometry, out ArcLosResult result)
{
result = default;
if (float.IsNaN(origin.X) || float.IsNaN(origin.Y) || float.IsNaN(origin.Z) ||
float.IsNaN(target.X) || float.IsNaN(target.Y) || float.IsNaN(target.Z))
return false;
var arc = MissileBallistics.Solve(origin.X, origin.Y, origin.Z, target.X, target.Y, target.Z, speed);
result.Sag = arc.MaxRiseAboveChord;
result.Apex = arc.ApexAboveLaunch;
if (!arc.Valid)
{
result.OutOfReach = true;
result.Blocked = true;
return true;
}
if (geometry == null || geometry.Count == 0)
return false;
clearance = Math.Max(0f, clearance);
int n = MissileBallistics.SegmentCount(arc.HorizDist);
Vector3 prev = origin;
float travelled = 0f;
for (int i = 1; i <= n; i++)
{
float t = (float)i / n;
Vector3 cur;
if (i == n) cur = target;
else
{
arc.PointAt(t, clearance, out float px, out float py, out float pz);
cur = new Vector3(px, py, pz);
}
Vector3 seg = cur - prev;
float len = seg.Length();
if (len > 1e-4f)
{
Vector3 dir = seg / len;
foreach (var volume in geometry)
{
if (volume.IsDoor) continue;
if (!volume.RayIntersect(prev, dir, len, out float hd)) continue;
if (hd < 0f || hd > len) continue;
if (travelled + hd < 0.5f) continue; // at the shooter
if (i == n && hd > len - 0.3f) continue; // at the target
Vector3 hit = prev + dir * hd;
float hx = hit.X - origin.X, hy = hit.Y - origin.Y;
result.Blocked = true;
result.HitAlong = (float)Math.Sqrt(hx * hx + hy * hy);
result.HitZ = hit.Z - origin.Z;
return true;
}
}
travelled += len;
prev = cur;
}
return false;
}
/// <summary>
/// Tests if a line segment between two points intersects any geometry.
/// Used internally for arc sampling.

View file

@ -45,6 +45,41 @@ namespace RynthCore.Plugin.RynthAi.Raycasting
// If true, use arc checks for missile weapons. If false, treat all as linear.
public bool UseArcs { get; set; } = true;
// Extra headroom (m) the missile arc must have at mid-flight, on top of the modelled
// flight path. Covers launch height, the real launch speed and the projectile's size.
// CombatManager overrides it from LegacyUiSettings.MissileArcClearance each tick.
public float MissileArcClearance { get; set; } = 0.5f;
// An arc that rises less than this above the straight line is flown as that line:
// the straight-line test (multi-ray in dungeons, ±0.3 m) already covers it, and the
// clearance bump is not applied to short, flat shots.
private const float ArcSagIgnoreMeters = 0.15f;
/// <summary>How a LOS verdict was reached, for the LOS debug log.</summary>
public struct LosDetail
{
public AttackType Type;
public bool Dungeon;
public bool Checked; // false = no verdict computed (no geometry near, too far, no position)
public float Velocity; // launch speed used for a missile arc (0 = straight line)
public bool LineBlocked;
public bool ArcChecked;
public RaycastEngine.ArcLosResult Arc;
}
private static bool IsMissileArc(AttackType t) =>
t == AttackType.BowArc || t == AttackType.CrossbowArc || t == AttackType.AtlatlArc;
/// <summary>Launch speed configured for a missile attack type.</summary>
public float VelocityFor(AttackType t) => t switch
{
AttackType.BowArc => BowArcVelocity,
AttackType.CrossbowArc => CrossbowArcVelocity,
AttackType.AtlatlArc => AtlatlArcVelocity,
AttackType.MagicArc => MagicArcVelocity,
_ => 0f,
};
// Max scan distance in meters. Only check LOS for targets within this range.
// Set from CombatManager based on MonsterRange + buffer.
public float MaxScanDistanceMeters { get; set; } = 120.0f;
@ -62,7 +97,23 @@ namespace RynthCore.Plugin.RynthAi.Raycasting
/// Returns false if the target is clear to attack.
/// </summary>
public bool IsTargetBlocked(RynthCoreHost host, uint targetId, AttackType attackType)
=> IsTargetBlocked(host, targetId, attackType, out _);
/// <summary>
/// As <see cref="IsTargetBlocked(RynthCoreHost, uint, AttackType)"/>, and reports how the
/// verdict was reached.
///
/// Missile weapons (bow, crossbow, atlatl) with UseArcs on: the target must pass the
/// straight line (walls, corner seams) AND the arc the missile really flies, low
/// ballistic solution at the weapon's launch speed plus MissileArcClearance headroom.
/// Indoors this is what catches ceilings: the old code forced a straight-line test in
/// dungeons, so a target 20-50 m down a corridor passed LOS while the arrow, rising
/// 2-6 m on its way there, hit the ceiling (2026-09-27, Longbow, Olthoi swarm).
/// </summary>
public bool IsTargetBlocked(RynthCoreHost host, uint targetId, AttackType attackType, out LosDetail detail)
{
detail = default;
detail.Type = attackType;
if (!_geoLoader.IsInitialized)
return false;
@ -90,55 +141,72 @@ namespace RynthCore.Plugin.RynthAi.Raycasting
uint landcell = GetPlayerLandcell(host);
uint cellPart = landcell & 0xFFFF;
bool isDungeon = cellPart >= 0x0100;
detail.Dungeon = isDungeon;
// Force linear checks indoors — arc trajectories hit ceilings
if (isDungeon)
bool missileArc = UseArcs && IsMissileArc(attackType);
// Magic arcs keep the old rule: straight line indoors.
if (isDungeon && !missileArc)
attackType = AttackType.Linear;
detail.Type = attackType;
var geometry = _geoLoader.GetLandblockGeometry(landcell);
if (geometry == null || geometry.Count == 0)
return false;
// The missile's real path: solved up front so the pre-filter box covers its apex.
MissileArc arc = default;
float arcHeadroom = 0f;
if (missileArc)
{
detail.Velocity = VelocityFor(attackType);
arc = MissileBallistics.Solve(origin.X, origin.Y, origin.Z,
targetPos.X, targetPos.Y, targetPos.Z, detail.Velocity);
arcHeadroom = arc.ApexAboveLaunch + Math.Max(0f, MissileArcClearance) + 0.5f;
}
// Pre-filter: skip full ray test if no geometry near the path
float margin = Math.Min(flatDist * 0.3f, 15.0f);
margin = Math.Max(margin, 3.0f);
margin = Math.Max(margin, arcHeadroom);
if (!RaycastEngine.HasNearbyGeometry(origin, targetPos, geometry, margin))
return false;
detail.Checked = true;
if (missileArc)
{
// Walls first (cheap, and most blocked targets stop here). In dungeons use
// multi-ray: 5 rays covering the player silhouette catch thin corner
// geometry that a single center ray slips through.
detail.LineBlocked = RaycastEngine.IsLinearPathBlocked(origin, targetPos, geometry, multiRay: isDungeon);
if (detail.LineBlocked)
return true;
// A short, flat shot is the straight line just tested.
if (arc.Valid && arc.MaxRiseAboveChord < ArcSagIgnoreMeters)
{
detail.Arc.Sag = arc.MaxRiseAboveChord;
detail.Arc.Apex = arc.ApexAboveLaunch;
return false;
}
detail.ArcChecked = true;
return RaycastEngine.IsBallisticArcBlocked(origin, targetPos, detail.Velocity,
MissileArcClearance, geometry, out detail.Arc);
}
// In dungeons use multi-ray checks — 5 rays covering the player silhouette
// catch thin corner geometry that a single center ray slips through.
switch (attackType)
{
case AttackType.Linear:
return RaycastEngine.IsLinearPathBlocked(origin, targetPos, geometry, multiRay: isDungeon);
case AttackType.BowArc:
if (UseArcs)
{
if (!RaycastEngine.IsArcPathBlocked(origin, targetPos, BowArcVelocity, geometry))
return false;
return RaycastEngine.IsLinearPathBlocked(origin, targetPos, geometry, multiRay: isDungeon);
}
return RaycastEngine.IsLinearPathBlocked(origin, targetPos, geometry, multiRay: isDungeon);
case AttackType.BowArc: // arcs off (UseArcs=false) → straight line
case AttackType.CrossbowArc:
if (UseArcs)
{
if (!RaycastEngine.IsArcPathBlocked(origin, targetPos, CrossbowArcVelocity, geometry))
return false;
return RaycastEngine.IsLinearPathBlocked(origin, targetPos, geometry, multiRay: isDungeon);
}
return RaycastEngine.IsLinearPathBlocked(origin, targetPos, geometry, multiRay: isDungeon);
case AttackType.AtlatlArc:
if (UseArcs)
{
if (!RaycastEngine.IsArcPathBlocked(origin, targetPos, AtlatlArcVelocity, geometry))
return false;
return RaycastEngine.IsLinearPathBlocked(origin, targetPos, geometry, multiRay: isDungeon);
}
return RaycastEngine.IsLinearPathBlocked(origin, targetPos, geometry, multiRay: isDungeon);
detail.LineBlocked = RaycastEngine.IsLinearPathBlocked(origin, targetPos, geometry, multiRay: isDungeon);
return detail.LineBlocked;
case AttackType.MagicArc:
if (UseArcs && !isDungeon)
@ -289,8 +357,14 @@ namespace RynthCore.Plugin.RynthAi.Raycasting
if (currentCombatMode == 2)
return AttackType.Linear;
// MISSILE MODE: Check the weapon name for bow vs crossbow vs thrown
if (currentCombatMode == 4 && !string.IsNullOrEmpty(wieldedWeaponName))
// MISSILE MODE: Check the weapon name for bow vs crossbow vs thrown.
// No name (weapon not resolved yet) is still a missile shot: bow arc. The
// combat scan used to pass "" here, which fell through to Linear, so no missile
// LOS check ever used an arc or the per-weapon velocities.
if (currentCombatMode == 4 && string.IsNullOrEmpty(wieldedWeaponName))
return UseArcs ? AttackType.BowArc : AttackType.Linear;
if (currentCombatMode == 4)
{
string name = wieldedWeaponName.ToLower();