Snapshot for release 2026.10.15.1 (internal 6f00bd7)

This commit is contained in:
Tom Bohar 2026-10-15 09:27:14 -04:00
commit a89ae04005
24 changed files with 855 additions and 49 deletions

View file

@ -228,6 +228,18 @@ public partial class BuffManager
/// The plugin's death hold (and a 0-health read): a pending recall is dropped and the macro is
/// left off, so nothing re-sends /lifestone or restarts the macro after the respawn.
/// </summary>
/// <summary>
/// A death or a portal dropped whatever the server had open: a wand use in flight is forgotten,
/// not judged a failed swap (see _directSwapMisses). RynthAiPlugin calls it with the death hold
/// and on entering portal space.
/// </summary>
internal void ForgetPendingWield(string why)
{
if (_pendingWieldId == 0) return;
_pendingWieldId = 0;
_host.Log($"[WieldGate] the wand's use in flight was cut short ({why}): not counted as a failed swap");
}
internal void CancelPendingRecall(string why)
{
if (!_recallPending) return;

View file

@ -388,7 +388,7 @@ public partial class BuffManager : IDisposable
private bool FightsWithMagic() => _combatManager?.FightsWithMagic ?? CurrentCombatMode == CombatMode.Magic;
/// <summary>Mana is under the line vitals refill at: the % line (Get Mana At in combat, Top Off
/// Mana idle; 0 = off) or, for a caster, the reserve. <paramref name="line"/>: the line in points.</summary>
/// Mana idle; 0 = off) or the reserve. <paramref name="line"/>: the line in points.</summary>
internal bool ManaUnderLine(bool inCombat, out int line)
{
line = 0;
@ -397,12 +397,12 @@ public partial class BuffManager : IDisposable
if (pctLine <= 0 || max <= 0) return false;
line = (int)Math.Ceiling(max * pctLine / 100.0);
bool under = _vitals.ManaPct < pctLine;
if (FightsWithMagic())
{
int reserve = ManaReserve();
if (reserve > line) line = reserve;
if (reserve > 0 && _vitals.CurrentMana < reserve) under = true;
}
// Every character, not only casters (2026-10-14): a melee character's buff chain spends mana
// too (Drakkon: 4% after a run of auras, under Stamina to Mana's own cost, so nothing could
// refill it and buffing sat waiting for regeneration).
int reserve = ManaReserve();
if (reserve > line) line = reserve;
if (reserve > 0 && _vitals.CurrentMana < reserve) under = true;
return under;
}
@ -421,10 +421,17 @@ public partial class BuffManager : IDisposable
/// <summary>Stamina lets Stamina to Mana go: over 15%, or a stamina kit or listed stamina potion
/// can bring it there. Not Revitalize: it costs mana itself, and trading mana for stamina and
/// back while attacks wait could keep a caster from attacking for minutes.</summary>
private bool StaminaAllowsStaminaToMana() => _vitals.StaminaPct > 15
private bool StaminaAllowsStaminaToMana() => _vitals.StaminaPct > StaminaToManaFloorPct()
|| BestPackStaminaKit() != null
|| (_settings.UsePotions && HasListedPotion("StaminaPotion", "Stamina"));
/// <summary>
/// Stamina to Mana goes only over this stamina %: Re-stam At (when on), at least 15. Under it,
/// stamina is refilled first (kit, potion, Revitalize). Was a flat 15%: each Stamina to Mana took
/// 110-126 stamina and Drakkon's stamina was run nearly out before anything refilled it (2026-10-14).
/// </summary>
internal int StaminaToManaFloorPct() => Math.Max(15, _settings.RestamAt);
/// <summary>
/// Mana can't pay for Stamina to Mana: under the cost of its lowest known level when costs are
/// known (the highest level it can pay for is cast first, see AttemptVitalCast), or refused
@ -598,8 +605,18 @@ public partial class BuffManager : IDisposable
// DoHandleActionGetAndWieldItem: "the client handles dequipping a lot of conflicting items
// automatically"). Drakkon's axe -> wand took 4.2 s with the pack move first (1.2 s for it,
// then the swap gate's flat 3 s). The pack move stays as the fallback: once a use hasn't
// got the wand into the hand in WieldResolveTimeoutMs, this session moves the weapon first.
private bool _directWandSwapFailed;
// got the wand into the hand in WieldResolveTimeoutMs, the weapon goes into a pack first.
// Not for the rest of the session on one miss (2026-10-14): a swap the server never finished
// because Drakkon died (13:40) set it, and every later heal from melee took the pack route, the
// move plus the swap gate's flat 3 s, 4+ s with nothing healing; he died twice more. Now one miss
// sends the next swap through the pack and the one after tries the use again; two misses in a
// row keep the pack route. A swap a death or a portal cut short counts for nothing
// (ForgetPendingWield).
private int _directSwapMisses; // direct swaps in a row that didn't get the wand into the hand
private bool _packFirstNext; // the next swap goes through the pack (one miss)
private bool _pendingWieldDirect; // the wand's use in flight was a direct swap (a weapon in hand)
internal const int DirectSwapMissesToStick = 2;
private bool PackFirst => _packFirstNext || _directSwapMisses >= DirectSwapMissesToStick;
// The swap gate's claim count when the wand's use went out: a later claim means another swap
// (combat putting the axe back, 12:39 on 10-06) changed the hands, so the result says nothing.
private long _pendingWieldClaim;
@ -1539,7 +1556,7 @@ public partial class BuffManager : IDisposable
// Mana under Get Mana At left buffing waiting on natural regen - one buff every 1-2
// minutes (tester, 10-01: 85 minutes of "buffing waits", Stamina to Mana never cast).
// A low stamina is topped up first (kit, Revitalize, potion) so Stamina to Mana can run.
if (_vitals.StaminaPct > 15 && AttemptVitalCast("Stamina to Mana Self"))
if (_vitals.StaminaPct > StaminaToManaFloorPct() && AttemptVitalCast("Stamina to Mana Self"))
{
_isRechargingMana = true;
return;
@ -1830,14 +1847,14 @@ public partial class BuffManager : IDisposable
if (manaLow)
{
_vitalWhy = "";
if ((curStamPct > 15 && AttemptVitalCast("Stamina to Mana Self")) || AttemptPotion("ManaPotion"))
if ((curStamPct > StaminaToManaFloorPct() && AttemptVitalCast("Stamina to Mana Self")) || AttemptPotion("ManaPotion"))
{
_isRechargingMana = true;
return true;
}
// Stamina too low for Stamina to Mana: a stamina kit, Revitalize or a potion first,
// whatever Re-stam At says (it may be under 15 or off).
if (curStamPct <= 15 && TopStaminaToManaId() != 0
// Stamina too low for Stamina to Mana (StaminaToManaFloorPct: Re-stam At, at least 15): a
// stamina kit, Revitalize or a potion first.
if (curStamPct <= StaminaToManaFloorPct() && TopStaminaToManaId() != 0
&& (AttemptStaminaKitUse() || AttemptVitalCast("Revitalize Self") || AttemptPotion("StaminaPotion", "Stamina")))
{
_isRechargingStamina = true;
@ -1924,8 +1941,12 @@ public partial class BuffManager : IDisposable
bool stamToHealth = StaminaToHealthAllowed(_settings, curHealthPct, curStamPct);
if (!emergencyKit && !stamToHealth) return false;
// 1. Out of Magic mode a kit first (no wand swap at critical health).
if (CurrentCombatMode != CombatMode.Magic && AttemptHealthKitUse()) return true;
// 1. Out of Magic mode a kit first (no wand swap at critical health), then a health
// potion: Heal Self from melee is a wand swap, the Magic stance and the cast, 4-5 s
// with nothing healing. Drakkon, 2026-10-14: 69% to 15% in 0.2 s among Depraved
// Shadows, the kit at 3%, and the swap was still unanswered when he died 3.2 s later;
// the potion came after Heal Self in the chain, so it was never reached.
if (CurrentCombatMode != CombatMode.Magic && (AttemptHealthKitUse() || AttemptPotion("HealthPotion"))) return true;
// 2. Stamina to Health Self, by its own line and stamina floor.
if (stamToHealth && AttemptVitalCast("Stamina to Health Self")) return true;
// 3. Not handled: the normal Heal At chain (kit, Heal Self, potion) gets its turn.
@ -2431,6 +2452,8 @@ public partial class BuffManager : IDisposable
("Lesser Stamina Kit", 100), ("Eternal Stamina Kit", 100),
};
private DateTime _lastKitChanceLog = DateTime.MinValue;
/// <summary>Kit Min Success % with a melee or missile weapon out, when Kit Min Success is higher.</summary>
internal const int WeaponOutKitMinPct = 30;
/// <summary>
/// True when a kit may be used: KitMinSuccessPct is 0, or the kit's chance of working on
@ -2440,6 +2463,11 @@ public partial class BuffManager : IDisposable
private bool KitChanceOk(int kitId, string kitName, uint missing, bool willBePeace)
{
int minPct = _settings.KitMinSuccessPct;
// A weapon out: the spell is a wand swap, the Magic stance and the cast first (4 s and more
// from melee), so a kit gets a lower bar. Drakkon, 2026-10-14 13:50: a 51% kit was skipped
// for Heal Self from melee and he died before the cast went out.
if (CurrentCombatMode == CombatMode.Melee || CurrentCombatMode == CombatMode.Missile)
minPct = Math.Min(minPct, WeaponOutKitMinPct);
if (minPct <= 0 || _charSkills == null) return true;
int boost = 0;
@ -4886,13 +4914,16 @@ public partial class BuffManager : IDisposable
_pendingWieldId = 0; // another swap since ours: not a failed wield
return false;
}
int stillInHand = _directWandSwapFailed ? 0 : FindWieldedNonWandWeapon(wandId);
int stillInHand = _pendingWieldDirect ? FindWieldedNonWandWeapon(wandId) : 0;
if (stillInHand != 0 && IsWieldedLive(stillInHand))
{
_directWandSwapFailed = true;
_directSwapMisses++;
_packFirstNext = true;
_pendingWieldId = 0;
_host.Log($"[WieldGate] using the wand didn't put 0x{(uint)stillInHand:X8} away in {WieldResolveTimeoutMs:0} ms; " +
"from now on the weapon goes into a pack first");
(_directSwapMisses >= DirectSwapMissesToStick
? $"{_directSwapMisses} in a row: from now on the weapon goes into a pack first"
: "the next swap puts the weapon into a pack first, then the use is tried again"));
return false;
}
_host.Log($"[WieldGate] UseObject(0x{(uint)_pendingWieldId:X8}) not confirmed in " +
@ -4932,7 +4963,7 @@ public partial class BuffManager : IDisposable
// non-wand weapon into a capacity-verified open pack FIRST (AutoCram pattern,
// AV-safe), then UseObject(wand) once the hand is free. Fully bounded.
int bowId = FindWieldedNonWandWeapon(wandId);
if (bowId != 0 && (_directWandSwapFailed || !IsWieldedLive(bowId))) // else the use swaps (see _directWandSwapFailed)
if (bowId != 0 && (PackFirst || !IsWieldedLive(bowId))) // else the use swaps (see _directSwapMisses)
{
if (_bowDequipPendingId == bowId
&& (now - _bowDequipAt).TotalMilliseconds < WieldResolveTimeoutMs
@ -4965,7 +4996,8 @@ public partial class BuffManager : IDisposable
_bowDequipPendingId = 0; // bow confirmed unwielded — fall through to wield the wand
}
_host.UseFor((uint)wandId, "Buff", bowId != 0 && !_directWandSwapFailed ? "buffing: switch to the wand" : "buffing: wield the wand");
_pendingWieldDirect = bowId != 0 && !PackFirst;
_host.UseFor((uint)wandId, "Buff", _pendingWieldDirect ? "buffing: switch to the wand" : "buffing: wield the wand");
NoteStanceRequest();
_pendingWieldClaim = _weaponSwapGate?.Claims ?? 0;
_pendingWieldId = wandId;
@ -4979,6 +5011,8 @@ public partial class BuffManager : IDisposable
{
_pendingWieldId = 0;
_wieldCooldownUntil = DateTime.MinValue;
if (_pendingWieldDirect) _directSwapMisses = 0; // the use swapped: back to direct swaps
_packFirstNext = false; // a pack-route swap done: the next one tries the use
}
// Deadlock episode tracking: wand wielded but mode refuses to flip.

View file

@ -3076,8 +3076,12 @@ public partial class CombatManager : IDisposable
// on its own timers, a swing can't land inside a use's server turn because the use above holds
// every attack until it is answered, and waiting for each swing animation would cost DPS. A
// stance change still waits (ChangeCombatModeFor), and so does everything in peace/magic.
// The movement settle is for casts (a cast beside a stop or a turn was held 40.8 s by the server):
// only in Magic mode. From peace the next step is a stance change or a wield, and waiting out the
// nav stop first cost every fight's first swing up to 0.6 s (2026-10-14).
bool attackRepeat = CurrentCombatMode == CombatMode.Melee || CurrentCombatMode == CombatMode.Missile;
if (!ActionPacer.MayStart(_host, "Combat", HealNeed.None, out _, animationGate: !attackRepeat, settleGate: !attackRepeat, attackRepeat: attackRepeat))
if (!ActionPacer.MayStart(_host, "Combat", HealNeed.None, out _, animationGate: !attackRepeat,
settleGate: CurrentCombatMode == CombatMode.Magic, attackRepeat: attackRepeat))
{
LastCombatSkipReason = "server-answering"; // D4 record-only
_tickWait = CombatLatencyTracker.Wait.Busy;
@ -4234,6 +4238,8 @@ public partial class CombatManager : IDisposable
}
private (int TargetId, MonsterRule? Rule, List<ItemRule> List, int Count, int Hand, DateTime At, WeaponPlan Plan)? _planCache;
// Listed weapons found not to be ours (logged once each).
private readonly HashSet<int> _notCarriedNoted = new();
private const double PlanCacheMs = 250;
private WeaponPlan ComputePlan(WorldObject target, MonsterRule? rule)
@ -4380,6 +4386,14 @@ public partial class CombatManager : IDisposable
if (r.Id == 0) continue;
var wo = _worldFilter[r.Id];
if (wo == null) continue;
// Sold, dropped or traded: still known to the client, but not ours to wield (a sold
// Flaming Greataxe was tried three times, the character standing in the fight, 2026-10-14).
if (r.Id != inHand && _worldFilter.PlayerHas(r.Id) == false)
{
if (_notCarriedNoted.Add(r.Id))
_host.Log($"[EquipDiag] listed weapon 0x{(uint)r.Id:X8} '{wo.Name}' isn't in your pack (sold, dropped or traded?): skipped");
continue;
}
if (!admitCasters && !IsUsableCombatWeapon(r.Id)) { (leftOut ??= new List<int>()).Add(r.Id); continue; }
if (list.Any(c => c.Id == r.Id)) continue;
if (wo.ObjectClass == AcObjectClass.MissileWeapon && IsAmmoItem(wo)) continue; // listed arrows are the ammo choice, never a weapon to wield

View file

@ -703,6 +703,21 @@ public class WorldObjectCache
private enum Holder { Unknown, Player, OtherWielder, OtherContainer, Nobody }
/// <summary>
/// The player has <paramref name="id"/> (wielded, main pack or a side pack): true; someone or
/// something else has it, or it lies on the ground: false; null when the engine can't say yet.
/// A sold, dropped or traded item stays known to the client for a while (2026-10-14: a sold
/// Flaming Greataxe was still tried three times as the listed weapon). Any thread.
/// </summary>
public bool? PlayerHas(int id)
{
lock (_gate)
{
Holder h = WhoHas(id);
return h == Holder.Unknown ? null : h == Holder.Player;
}
}
/// <summary>
/// Who has the object: the player (wielded, in the main pack, or in a side pack), another
/// wielder (other players' and NPCs' gear), another container (a corpse, a chest), or

View file

@ -695,6 +695,40 @@ internal sealed class DungeonGeometry
return hit;
}
/// <summary>
/// Line of sight between two points on the floor (the Sweep patrol): no wall of the landblock
/// reaching into knee-to-head height between them (the same band <see cref="SegmentClear"/>
/// uses), whichever cells the walls belong to. Floors aren't looked at: a monster sees across
/// a gap.
/// </summary>
internal bool SightClear(double x0, double y0, double z0, double x1, double y1, double z1)
=> !WallHit(x0, y0, x1, y1, Math.Min(z0, z1) + WallBandLow, Math.Max(z0, z1) + WallBandHigh, out _);
/// <summary>A point on the cell's floor: the centre of its biggest floor polygon. False when
/// the dats give the cell no floor (then its origin stands in).</summary>
internal bool TryCellFloorCentre(uint cell, out double x, out double y, out double z)
{
x = y = z = 0;
if (!_floors.TryGetValue(cell, out var list) || list.Count == 0) return false;
double bestArea = -1;
foreach (var v in list)
{
if (v.Length < 3) continue;
double area = 0, cx = 0, cy = 0, cz = 0;
for (int i = 0; i < v.Length; i++)
{
var a = v[i]; var b = v[(i + 1) % v.Length];
area += a.X * b.Y - b.X * a.Y;
cx += a.X; cy += a.Y; cz += a.Z;
}
area = Math.Abs(area) * 0.5;
if (area <= bestArea) continue;
bestArea = area;
x = cx / v.Length; y = cy / v.Length; z = cz / v.Length;
}
return bestArea > 0;
}
/// <summary>Walls (footprint and height range) within r of (x, y), for offline inspection.</summary>
internal List<(double X0, double Y0, double X1, double Y1, double ZMin, double ZMax, double Dist)> WallsNear(double x, double y, double r)
{

View file

@ -569,6 +569,8 @@ internal static partial class DungeonPathfinder
// short for an exit point and the next approach point (DoorwayStandoffs[0] each) without
// doubling back.
private const double RunGapMeters = 8.0;
// cos(~93 degrees): openings at right angles (a staircase) still continue a run.
private const double RightAngleSlack = 0.05;
private static bool Continues(DungeonGeometry geo, Step a, Step b)
{
@ -578,9 +580,13 @@ internal static partial class DungeonPathfinder
if (dx * dx + dy * dy >= RunGapMeters * RunGapMeters || Math.Abs(da.Z - db.Z) >= 2.0) return false;
// A run goes on: through the next opening no more than 90 degrees off the last. Turning
// back (in at one opening, out at another beside it) is a visit to the room between.
// 90 degrees exactly counts (2026-10-14): a diagonal corridor is a staircase of square
// cells whose openings face north, east, north, east...; each failed the old "> 0" by a
// hair, got its own approach and exit point 4 m out along its facing, and the patrol
// walked the staircase (zig-zag) instead of the corridor's centre line.
var (ax, ay) = da.NormalFrom(a.From);
var (bx, by) = db.NormalFrom(b.From);
return ax * bx + ay * by > 0.0;
return ax * bx + ay * by > -RightAngleSlack;
}
// The approach point before steps[i], the exit point after steps[j], and the opening centres

View file

@ -0,0 +1,290 @@
// DungeonPathfinder, sweep half: Settings > Dungeon Patrol > Coverage "Sweep" (2026-10-14).
//
// Why: Whole dungeon walks every doorway between rooms once. A pillar hall (0x00AE: a grid of
// pillars built from 4.6 m corridor pieces, 1,700 cells, 386 tiny rooms) is all doorways, so
// the patrol walked every lane between every pair of pillars (1,074 points a lap), though a
// monster three lanes over has seen the character long before.
//
// Sweep walks the same cells (GetMainRouteNodes: Whole dungeon's, dead ends and hazards alike)
// but only near enough that each is SEEN:
// 1. Sight: a cell sees another when their floor centres are within SightMeters of each
// other, on about the same level (SweepMaxRise), with no wall between them
// (DungeonGeometry.SightClear). Corridors and crypts barely change: their walls block it.
// 2. Stops: in the patrol's walking order (a depth-first walk from the start, nearest
// neighbour first), each cell not yet seen gets a stop: of the cells it sees (itself
// included), the one that sees the most cells still unseen. Its sight marks them seen.
// 3. Tour: from the start, always the nearest stop not yet visited (by walking distance over
// the cells), improved by 2-opt, and back to the start; each leg the shortest walk.
// 4. Points: the tour's cell path turned into doorway steps and laid by EmitSteps, so
// doorways, room crossings, the wall distance and the corner cutting are the ones every
// other patrol uses.
// No geometry, one stop, or a tour that never leaves one room: null, and the caller builds the
// Whole dungeon patrol instead. The other coverages never come here.
using System;
using System.Collections.Generic;
using RynthCore.Plugin.RynthAi.LegacyUi;
namespace RynthCore.Plugin.RynthAi;
internal static partial class DungeonPathfinder
{
// Cells whose floors differ more than this (metres) are taken as different levels: a balcony
// over a hall, a ramp's other end. A monster on one notices the character on the other less.
internal const double SweepMaxRise = 3.0;
/// <summary>For PatrolProof and the tests: the stops the last sweep chose and the cells it covered.</summary>
[ThreadStatic] internal static int LastSweepStops, LastSweepCells, LastSweepSeen;
private static NavRouteParser? BuildSweepPatrol(
Dictionary<uint, DungeonNavNode> graph, uint startCell, HashSet<uint> mainRoute,
IReadOnlySet<uint>? hazardCells, DungeonGeometry geo, DungeonPatrolOptions o)
{
LastSweepStops = LastSweepCells = LastSweepSeen = 0;
double sight = o.SightMeters;
// Floor centres, and the walkable neighbours within the patrol's cells.
var pos = new Dictionary<uint, (double X, double Y, double Z)>();
foreach (uint c in mainRoute)
{
if (!graph.TryGetValue(c, out var n)) continue;
pos[c] = geo.TryCellFloorCentre(c, out double fx, out double fy, out double fz)
? (fx, fy, fz)
: (DungeonGeometry.NavToWorld(n.EW), DungeonGeometry.NavToWorld(n.NS), n.Z);
}
if (pos.Count < 2) return null;
var adj = new Dictionary<uint, List<uint>>();
foreach (uint c in pos.Keys)
{
var list = new List<uint>();
var cn = graph[c];
foreach (uint nb in cn.Neighbors)
{
if (!pos.ContainsKey(nb) || !graph.TryGetValue(nb, out var nbn) || IsDropEdge(cn, nbn)) continue;
list.Add(nb);
}
list.Sort((a, b) => Dist(pos[c], pos[a]).CompareTo(Dist(pos[c], pos[b])));
adj[c] = list;
}
uint start = pos.ContainsKey(startCell) ? startCell : NearestOf(pos, graph, startCell);
if (start == 0) return null;
// 1. Sight, worked out on demand (cells bucketed by SightMeters).
var buckets = new Dictionary<long, List<uint>>();
foreach (var (c, p) in pos)
{
long k = BucketKey(p.X, p.Y, sight);
if (!buckets.TryGetValue(k, out var b)) buckets[k] = b = new List<uint>();
b.Add(c);
}
var seenFrom = new Dictionary<uint, List<uint>>();
List<uint> Sees(uint c)
{
if (seenFrom.TryGetValue(c, out var list)) return list;
list = new List<uint> { c };
var p = pos[c];
int bx = (int)Math.Floor(p.X / sight), by = (int)Math.Floor(p.Y / sight);
for (int gx = bx - 1; gx <= bx + 1; gx++)
for (int gy = by - 1; gy <= by + 1; gy++)
{
if (!buckets.TryGetValue(((long)gx << 32) ^ (uint)gy, out var b)) continue;
foreach (uint v in b)
{
if (v == c) continue;
var q = pos[v];
if (Math.Abs(q.Z - p.Z) > SweepMaxRise || Dist(p, q) > sight) continue;
if (geo.SightClear(p.X, p.Y, p.Z, q.X, q.Y, q.Z)) list.Add(v);
}
}
seenFrom[c] = list;
return list;
}
// 2. Stops, in the walking order.
var order = new List<uint>();
var visited = new HashSet<uint> { start };
var stack = new Stack<uint>();
stack.Push(start);
while (stack.Count > 0)
{
uint c = stack.Pop();
order.Add(c);
var nbs = adj[c];
for (int i = nbs.Count - 1; i >= 0; i--) // nearest neighbour first
if (visited.Add(nbs[i])) stack.Push(nbs[i]);
}
var covered = new HashSet<uint>();
var stops = new List<uint>();
foreach (uint u in order)
{
if (covered.Contains(u)) continue;
uint best = u;
int bestGain = -1;
foreach (uint v in Sees(u))
{
int gain = 0;
foreach (uint w in Sees(v)) if (!covered.Contains(w)) gain++;
if (gain > bestGain) { bestGain = gain; best = v; }
}
stops.Add(best);
foreach (uint w in Sees(best)) covered.Add(w);
covered.Add(u); // u sees best, so best sees u (sight is symmetric)
}
LastSweepStops = stops.Count;
LastSweepCells = order.Count;
LastSweepSeen = covered.Count;
if (stops.Count < 2) return null;
// 3. Tour: the start, then the nearest unvisited stop each time (by walking distance), then
// 2-opt (reverse any stretch whose ends are closer the other way round) to take out the
// criss-crossing a nearest-next tour leaves; each leg the shortest walk.
var tourCells = new List<uint>(stops.Count + 1) { start };
foreach (uint st in stops) if (st != start) tourCells.Add(st);
int stopCount = tourCells.Count;
var index = new Dictionary<uint, int>();
for (int i = 0; i < stopCount; i++) index[tourCells[i]] = i;
var walk = new double[stopCount, stopCount];
for (int i = 0; i < stopCount; i++)
{
var d = WalkDistances(adj, pos, tourCells[i]);
for (int j = 0; j < stopCount; j++) walk[i, j] = d.TryGetValue(tourCells[j], out double v) ? v : double.PositiveInfinity;
}
var tour = new List<int> { 0 };
var left = new HashSet<int>();
for (int i = 1; i < stopCount; i++) if (!double.IsPositiveInfinity(walk[0, i])) left.Add(i); // unreachable stops dropped
while (left.Count > 0)
{
int last = tour[^1], next = -1;
foreach (int j in left) if (next < 0 || walk[last, j] < walk[last, next]) next = j;
tour.Add(next);
left.Remove(next);
}
TwoOpt(tour, walk);
var path = new List<uint> { start };
for (int k = 0; k < tour.Count; k++)
{
uint from = tourCells[tour[k]], to = tourCells[tour[(k + 1) % tour.Count]];
if (from == to) continue;
var leg = WalkToNearest(adj, pos, from, new HashSet<uint> { to });
if (leg == null) continue;
for (int i = 1; i < leg.Count; i++) path.Add(leg[i]);
}
// 4. Points, through every doorway the tour takes.
var rooms = BuildRooms(graph, geo, hazardCells);
var steps = new List<Step>();
for (int i = 0; i + 1 < path.Count; i++)
{
uint a = path[i], b = path[i + 1];
if (!rooms.RoomOf.TryGetValue(a, out int ra) || !rooms.RoomOf.TryGetValue(b, out int rb) || ra == rb) continue;
steps.Add(new Step(a, b, EdgeKey(a, b)));
}
if (steps.Count == 0) return null;
if (PointLog != null)
MainRouteNote += $"; sweep: {stops.Count} stops see {covered.Count} of {order.Count} cells within {sight:0.#} m, "
+ $"tour {path.Count} cells, {steps.Count} doorway steps";
var route = new NavRouteParser { RouteType = NavRouteType.Circular };
route.Points.AddRange(EmitSteps(graph, geo, rooms, steps, closed: true, null, 0, null, 0, o, out _));
return route;
}
private static double Dist((double X, double Y, double Z) a, (double X, double Y, double Z) b)
{
double dx = a.X - b.X, dy = a.Y - b.Y;
return Math.Sqrt(dx * dx + dy * dy);
}
private static long BucketKey(double x, double y, double size)
=> ((long)(int)Math.Floor(x / size) << 32) ^ (uint)(int)Math.Floor(y / size);
private static uint NearestOf(Dictionary<uint, (double X, double Y, double Z)> pos, Dictionary<uint, DungeonNavNode> graph, uint cell)
{
if (!graph.TryGetValue(cell, out var n)) return 0;
var p = (DungeonGeometry.NavToWorld(n.EW), DungeonGeometry.NavToWorld(n.NS), n.Z);
uint best = 0;
double bestD = double.MaxValue;
foreach (var (c, q) in pos)
{
double d = Dist(p, q) + Math.Abs(q.Z - n.Z);
if (d < bestD) { bestD = d; best = c; }
}
return best;
}
// Dijkstra from src: the walking distance to every cell it reaches.
private static Dictionary<uint, double> WalkDistances(Dictionary<uint, List<uint>> adj,
Dictionary<uint, (double X, double Y, double Z)> pos, uint src)
{
var dist = new Dictionary<uint, double> { [src] = 0 };
var pq = new PriorityQueue<uint, double>();
pq.Enqueue(src, 0);
while (pq.TryDequeue(out uint c, out double d))
{
if (d > dist[c]) continue;
foreach (uint nb in adj[c])
{
double nd = d + Dist(pos[c], pos[nb]) + Math.Abs(pos[c].Z - pos[nb].Z);
if (dist.TryGetValue(nb, out double old) && old <= nd) continue;
dist[nb] = nd;
pq.Enqueue(nb, nd);
}
}
return dist;
}
// 2-opt over a closed tour (tour[0], the start, stays first): reverse tour[i..j] whenever that
// shortens it, until no reversal does (bounded passes). Walking distances need not be symmetric
// to the metre (levels), so each reversal is judged on the full stretch.
internal static void TwoOpt(List<int> tour, double[,] walk)
{
int n = tour.Count;
if (n < 4) return;
double Leg(int a, int b) => walk[tour[a], tour[b % n]];
for (int pass = 0; pass < 50; pass++)
{
bool improved = false;
for (int i = 1; i < n - 1; i++)
for (int j = i + 1; j < n; j++)
{
double before = Leg(i - 1, i) + Leg(j, j + 1);
double after = walk[tour[i - 1], tour[j]] + walk[tour[i], tour[(j + 1) % n]];
if (after + 1e-6 >= before) continue;
tour.Reverse(i, j - i + 1);
improved = true;
}
if (!improved) break;
}
}
// Dijkstra from src (by the distance between floor centres) to the nearest cell in goals; the path, src first.
private static List<uint>? WalkToNearest(Dictionary<uint, List<uint>> adj, Dictionary<uint, (double X, double Y, double Z)> pos,
uint src, HashSet<uint> goals)
{
var dist = new Dictionary<uint, double> { [src] = 0 };
var prev = new Dictionary<uint, uint>();
var pq = new PriorityQueue<uint, double>();
pq.Enqueue(src, 0);
while (pq.TryDequeue(out uint c, out double d))
{
if (d > dist[c]) continue;
if (c != src && goals.Contains(c))
{
var path = new List<uint>();
for (uint at = c; ; at = prev[at]) { path.Add(at); if (at == src) break; }
path.Reverse();
return path;
}
foreach (uint nb in adj[c])
{
double nd = d + Dist(pos[c], pos[nb]) + Math.Abs(pos[c].Z - pos[nb].Z);
if (dist.TryGetValue(nb, out double old) && old <= nd) continue;
dist[nb] = nd;
prev[nb] = c;
pq.Enqueue(nb, nd);
}
}
return null;
}
}

View file

@ -508,7 +508,8 @@ internal static partial class DungeonPathfinder
else
{
result = TrimDeadEndPockets(graph, reachable, startCell, o.MaxDeadEndCells, rooms, o.LookInRoomMeters);
how = (o.Coverage == PatrolCoverage.LoopsOnly ? "loops only, but hazards cut the loops: " : "")
how = (o.Coverage == PatrolCoverage.LoopsOnly ? "loops only, but hazards cut the loops: "
: o.Coverage == PatrolCoverage.Sweep ? "sweep, over " : "")
+ $"all reachable cells but dead-end areas of <= {o.MaxDeadEndCells} cells{(rooms != null ? " (by room)" : "")} ({result.Count} kept)";
}
if (PointLog != null)
@ -807,6 +808,14 @@ internal static partial class DungeonPathfinder
var rooms = geo != null && geo.DoorwayCount > 0 ? BuildRooms(graph, geo, hazardCells) : null;
var mainRoute = GetMainRouteNodes(graph, startCell, hazardCells, o, rooms);
// Sweep (DungeonPathfinder.Sweep.cs): the same cells, walked only near enough to be seen.
// Falls through to the room patrol below when it can't build one. No other coverage comes here.
if (o.Coverage == PatrolCoverage.Sweep && geo != null && geo.DoorwayCount > 0)
{
var sweep = BuildSweepPatrol(graph, startCell, mainRoute, hazardCells, geo, o);
if (sweep != null && sweep.Points.Count > 0) return sweep;
}
// With the dungeon map geometry: the same coverage over rooms instead of cells, rooms
// crossed directly, doorways taken straight on (DungeonPathfinder.Rooms.cs).
if (geo != null && geo.DoorwayCount > 0)

View file

@ -19,6 +19,11 @@ internal enum PatrolCoverage
LoopsOnly = 1,
/// <summary>Every reachable cell, every dead end included.</summary>
Everything = 2,
/// <summary>The Whole dungeon cells, but walked only close enough that every one is seen: a
/// stop within SightMeters, on about the same level, with no wall between (2026-10-14: a pillar
/// hall, 0x00AE, is 1,700 cells of corridor pieces, and Whole dungeon walked every lane).
/// DungeonPathfinder.Sweep.cs.</summary>
Sweep = 3,
}
internal sealed record DungeonPatrolOptions
@ -26,6 +31,7 @@ internal sealed record DungeonPatrolOptions
public const int MaxDeadEndCellsMin = 0, MaxDeadEndCellsMax = 30, MaxDeadEndCellsDefault = 10;
public const double WallClearanceMin = 0.5, WallClearanceMax = 2.0, WallClearanceDefault = 1.0;
public const double LookInRoomMin = 3.0, LookInRoomMax = 40.0, LookInRoomDefault = 10.0;
public const double SightMin = 5.0, SightMax = 60.0, SightDefault = 20.0;
public static readonly DungeonPatrolOptions Default = new();
@ -51,6 +57,10 @@ internal sealed record DungeonPatrolOptions
/// skirts or leaves by the doorway it came in by gets a walk to its middle and back.</summary>
public double LookInRoomMeters { get; init; } = LookInRoomDefault;
/// <summary>Sweep: how far (metres) a monster notices the character, so how far apart the
/// patrol's lanes may be. Settings "Sight Distance (yd)". Unused by the other coverages.</summary>
public double SightMeters { get; init; } = SightDefault;
/// <summary>The options with every value in range (a hand-edited profile or a remote setting).</summary>
public DungeonPatrolOptions Clamped() => this with
{
@ -58,12 +68,14 @@ internal sealed record DungeonPatrolOptions
MaxDeadEndCells = Math.Clamp(MaxDeadEndCells, MaxDeadEndCellsMin, MaxDeadEndCellsMax),
WallClearance = double.IsFinite(WallClearance) ? Math.Clamp(WallClearance, WallClearanceMin, WallClearanceMax) : WallClearanceDefault,
LookInRoomMeters = double.IsFinite(LookInRoomMeters) ? Math.Clamp(LookInRoomMeters, LookInRoomMin, LookInRoomMax) : LookInRoomDefault,
SightMeters = double.IsFinite(SightMeters) ? Math.Clamp(SightMeters, SightMin, SightMax) : SightDefault,
};
public static string CoverageName(PatrolCoverage c) => c switch
{
PatrolCoverage.LoopsOnly => "loops only",
PatrolCoverage.Everything => "everything",
PatrolCoverage.Sweep => "sweep",
_ => "whole dungeon",
};
@ -72,6 +84,7 @@ internal sealed record DungeonPatrolOptions
{
var inv = CultureInfo.InvariantCulture;
string spurs = Coverage == PatrolCoverage.Everything ? "" : $", skip dead ends <= {MaxDeadEndCells}";
if (Coverage == PatrolCoverage.Sweep) spurs += $", sight {SightMeters.ToString("0.#", inv)} m";
return $"coverage {CoverageName(Coverage)}{spurs}, lava/acid floors {(AvoidHazardFloors ? "avoided" : "walked")}, "
+ $"walls {WallClearance.ToString("0.0#", inv)} m, look into rooms >= {LookInRoomMeters.ToString("0.#", inv)} m";
}

View file

@ -1032,6 +1032,9 @@ internal sealed partial class LegacyDashboardRenderer
DeathRecallSpellId = s.DeathRecallSpellId,
DeathRecallItem = s.DeathRecallItem,
StopMacroOnNoComponents = s.StopMacroOnNoComponents,
LowCompsRecall = s.LowCompsRecall,
LowCompsTaperMin = s.LowCompsTaperMin,
LowCompsScarabMin = s.LowCompsScarabMin,
StopLootingWhenPackFull = s.StopLootingWhenPackFull,
StopMacroWhenPackFull = s.StopMacroWhenPackFull,
RestamAt = s.RestamAt,
@ -1107,6 +1110,7 @@ internal sealed partial class LegacyDashboardRenderer
DunPatrolAvoidFloors = s.DunPatrolAvoidFloors,
DunPatrolWallDistance = s.DunPatrolWallDistance,
DunPatrolLookInSize = s.DunPatrolLookInSize,
DunPatrolSightYd = s.DunPatrolSightYd,
T2Speed = s.T2Speed,
T2WalkWithinYd = s.T2WalkWithinYd,
T2DistanceTo = s.T2DistanceTo,
@ -1264,6 +1268,9 @@ internal sealed partial class LegacyDashboardRenderer
if (p.DeathRecallSpellId is int recallSpell && recallSpell > 0) s.DeathRecallSpellId = recallSpell;
if (p.DeathRecallItem is string recallItem) s.DeathRecallItem = recallItem.Trim();
s.StopMacroOnNoComponents = p.StopMacroOnNoComponents;
if (p.LowCompsRecall is bool lowComps) s.LowCompsRecall = lowComps;
if (p.LowCompsTaperMin is int taperMin) s.LowCompsTaperMin = Math.Clamp(taperMin, 0, 1000);
if (p.LowCompsScarabMin is int scarabMin) s.LowCompsScarabMin = Math.Clamp(scarabMin, 0, 100);
s.StopLootingWhenPackFull = p.StopLootingWhenPackFull;
s.StopMacroWhenPackFull = p.StopMacroWhenPackFull;
s.RestamAt = p.RestamAt;
@ -1335,11 +1342,12 @@ internal sealed partial class LegacyDashboardRenderer
s.NavTier1TurnSpeed = p.NavTier1TurnSpeed;
s.PostPortalDelaySec = p.PostPortalDelaySec;
// Dungeon patrol: absent (an older engine) = unchanged.
if (p.DunPatrolCoverage is int patrolCoverage) s.DunPatrolCoverage = Math.Clamp(patrolCoverage, 0, 2);
if (p.DunPatrolCoverage is int patrolCoverage) s.DunPatrolCoverage = Math.Clamp(patrolCoverage, 0, (int)PatrolCoverage.Sweep);
if (p.DunPatrolSkipDeadEnds is int patrolSpurs) s.DunPatrolSkipDeadEnds = Math.Clamp(patrolSpurs, DungeonPatrolOptions.MaxDeadEndCellsMin, DungeonPatrolOptions.MaxDeadEndCellsMax);
if (p.DunPatrolAvoidFloors is bool patrolFloors) s.DunPatrolAvoidFloors = patrolFloors;
if (p.DunPatrolWallDistance is float patrolWalls) s.DunPatrolWallDistance = (float)Math.Clamp(patrolWalls, DungeonPatrolOptions.WallClearanceMin, DungeonPatrolOptions.WallClearanceMax);
if (p.DunPatrolLookInSize is float patrolLookIn) s.DunPatrolLookInSize = (float)Math.Clamp(patrolLookIn, DungeonPatrolOptions.LookInRoomMin, DungeonPatrolOptions.LookInRoomMax);
if (p.DunPatrolSightYd is float patrolSight) s.DunPatrolSightYd = (float)Math.Clamp(patrolSight, DungeonPatrolOptions.SightMin, DungeonPatrolOptions.SightMax);
s.T2Speed = p.T2Speed;
s.T2WalkWithinYd = p.T2WalkWithinYd;
s.T2DistanceTo = p.T2DistanceTo;
@ -1697,6 +1705,7 @@ internal sealed partial class LegacyDashboardRenderer
dst.DunPatrolAvoidFloors = tmp.DunPatrolAvoidFloors;
dst.DunPatrolWallDistance = tmp.DunPatrolWallDistance;
dst.DunPatrolLookInSize = tmp.DunPatrolLookInSize;
dst.DunPatrolSightYd = tmp.DunPatrolSightYd;
dst.T2Speed = tmp.T2Speed;
dst.T2DistanceTo = tmp.T2DistanceTo;
dst.T2ReissueMs = tmp.T2ReissueMs;
@ -1764,6 +1773,9 @@ internal sealed partial class LegacyDashboardRenderer
dst.DeathRecallSpellId = tmp.DeathRecallSpellId > 0 ? tmp.DeathRecallSpellId : 48;
dst.DeathRecallItem = tmp.DeathRecallItem ?? string.Empty;
dst.StopMacroOnNoComponents = tmp.StopMacroOnNoComponents;
dst.LowCompsRecall = tmp.LowCompsRecall;
dst.LowCompsTaperMin = Math.Clamp(tmp.LowCompsTaperMin, 0, 1000);
dst.LowCompsScarabMin = Math.Clamp(tmp.LowCompsScarabMin, 0, 100);
dst.StopLootingWhenPackFull = tmp.StopLootingWhenPackFull;
dst.StopMacroWhenPackFull = tmp.StopMacroWhenPackFull;
dst.RestamAt = tmp.RestamAt;

View file

@ -56,11 +56,12 @@ public sealed class LegacyUiSettings
// Dungeon patrol (/ra dunnav-patrol, Settings > Navigation > Dungeon Patrol; DungeonPatrolOptions).
// The defaults are the patrol as it was before these settings (2026-10-12). A running patrol
// is rebuilt when one changes (RynthAiCommands.TickDunPatrolReroute).
public int DunPatrolCoverage; // PatrolCoverage: 0 whole dungeon, 1 loops only, 2 everything
public int DunPatrolCoverage; // PatrolCoverage: 0 whole dungeon, 1 loops only, 2 everything, 3 sweep
public int DunPatrolSkipDeadEnds = 10; // whole dungeon: dead-end areas of up to this many cells are skipped (0 = none)
public bool DunPatrolAvoidFloors = true; // lava/acid floor cells (HazardTextures.txt) kept out of the patrol
public float DunPatrolWallDistance = 1.0f; // metres every patrol point keeps from walls where there is room
public float DunPatrolLookInSize = 10.0f; // rooms this big (m) the patrol only skirts get a walk to their middle
public float DunPatrolSightYd = 20.0f; // sweep: how far a monster notices you, so how far apart the lanes may be
// On: macro start, loading a Circular or Linear route, and nav taking over again after a
// pause that moved the character (combat, looting, buffing, doors) all head for the closest
// waypoint on the route. Off: a pause carries on to the waypoint it was heading for, a macro
@ -163,6 +164,11 @@ public sealed class LegacyUiSettings
public int DeathRecallSpellId = 48; // Primary Portal Recall
public string DeathRecallItem = string.Empty;
public bool StopMacroOnNoComponents = false;
// Recall When Low On Components (RynthAiPlugin.LowComponents.cs): tapers at or under LowCompsTaperMin,
// or a scarab kind (not Diamond) at or under LowCompsScarabMin, stops the macro and recalls home.
public bool LowCompsRecall = false;
public int LowCompsTaperMin = 10;
public int LowCompsScarabMin = 2;
public bool StopLootingWhenPackFull = true;
public bool StopMacroWhenPackFull = false;
public int RestamAt = 30;
@ -960,6 +966,7 @@ public sealed class SettingsBridgePayload
public bool? DunPatrolAvoidFloors { get; set; }
public float? DunPatrolWallDistance { get; set; }
public float? DunPatrolLookInSize { get; set; }
public float? DunPatrolSightYd { get; set; }
// Absent from an older engine's payload: must not read as off.
public bool YieldToVTank { get; set; } = true;
public bool EnableRaycasting { get; set; }
@ -993,6 +1000,9 @@ public sealed class SettingsBridgePayload
public bool StopMacroOnDeath { get; set; }
public bool StopMacroOnNoComponents { get; set; }
// Absent from an older engine: null keeps the plugin's values.
public bool? LowCompsRecall { get; set; }
public int? LowCompsTaperMin { get; set; }
public int? LowCompsScarabMin { get; set; }
public int? DeathRecallMode { get; set; }
public int? DeathRecallSpellId { get; set; }
public string? DeathRecallItem { get; set; }

View file

@ -2813,11 +2813,12 @@ public sealed partial class RynthAiPlugin
/// <summary>The Dungeon Patrol settings (Settings > Navigation) as patrol options, in range.</summary>
internal static DungeonPatrolOptions PatrolOptionsFrom(LegacyUiSettings s) => new DungeonPatrolOptions
{
Coverage = (PatrolCoverage)Math.Clamp(s.DunPatrolCoverage, 0, 2),
Coverage = (PatrolCoverage)Math.Clamp(s.DunPatrolCoverage, 0, (int)PatrolCoverage.Sweep),
MaxDeadEndCells = s.DunPatrolSkipDeadEnds,
AvoidHazardFloors = s.DunPatrolAvoidFloors,
WallClearance = s.DunPatrolWallDistance,
LookInRoomMeters = s.DunPatrolLookInSize,
SightMeters = s.DunPatrolSightYd,
}.Clamped();
/// <summary>

View file

@ -0,0 +1,91 @@
using System;
using System.Collections.Generic;
using RynthCore.Plugin.RynthAi.LegacyUi;
namespace RynthCore.Plugin.RynthAi;
/// <summary>
/// Recall When Low On Components (2026-10-14; off by default): with the macro running, tapers
/// (all kinds together) at or under Low Tapers At, or any one kind of scarab except Diamond at or
/// under Low Scarabs At, stop the macro and recall to the lifestone, saying which ran low. Lucy died
/// that day with every heal spell refused for components, so the bot goes home before that.
///
/// A kind only counts once it has been seen in the pack this session: a character that never
/// carries a Mana Scarab (or no tapers at all, a pure fighter) isn't "low" on it; one that runs a
/// kind out entirely (0, gone from the pack) still is. Checked every LowCompsCheckMs; it fires once
/// and re-arms when the macro is started again.
/// </summary>
public sealed partial class RynthAiPlugin
{
private const long LowCompsCheckMs = 5_000;
private long _lowCompsCheckedAt;
private bool _lowCompsFired;
private bool _lowCompsWasRunning;
// Component kinds seen in the pack this session ("taper" for all tapers together, else the scarab's name).
private readonly HashSet<string> _compsSeen = new(StringComparer.OrdinalIgnoreCase);
internal const string TaperKey = "tapers";
/// <summary>Every tick with the safety checks; does the work every LowCompsCheckMs.</summary>
private void CheckLowComponents(LegacyUiSettings s)
{
if (s.IsMacroRunning && !_lowCompsWasRunning) _lowCompsFired = false; // a new run re-arms it
_lowCompsWasRunning = s.IsMacroRunning;
if (!s.LowCompsRecall || !s.IsMacroRunning || _lowCompsFired || _objectCache == null) return;
long now = Environment.TickCount64;
if (now - _lowCompsCheckedAt < LowCompsCheckMs) return;
_lowCompsCheckedAt = now;
var counts = CountComponents(_objectCache.GetInventory());
string? low = LowComponents(counts, _compsSeen, s.LowCompsTaperMin, s.LowCompsScarabMin);
if (low == null) return;
_lowCompsFired = true;
HandleMacroRunCommand("stop", Array.Empty<string>());
bool recalled = Host.HasInvokeChatParser;
if (recalled) Host.InvokeChatParser("/lifestone");
string line = $"Low on components ({low}): macro stopped" + (recalled ? ", recalling to the lifestone" : "") +
" (Recall When Low On Components is on).";
ChatLine("[RynthAi] " + line);
Log("[RynthAi] " + line);
}
/// <summary>Tapers (every kind together, under <see cref="TaperKey"/>) and each scarab kind but Diamond, by stack size.</summary>
internal static Dictionary<string, int> CountComponents(IEnumerable<WorldObject> inventory)
{
var counts = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
foreach (var wo in inventory)
{
string name = wo?.Name ?? "";
string? key = name.EndsWith(" Taper", StringComparison.OrdinalIgnoreCase) ? TaperKey
: name.EndsWith(" Scarab", StringComparison.OrdinalIgnoreCase)
&& !name.StartsWith("Diamond", StringComparison.OrdinalIgnoreCase) ? name
: null;
if (key == null) continue;
int n = Math.Max(1, wo!.Values(LongValueKey.StackCount, 1));
counts[key] = counts.TryGetValue(key, out int c) ? c + n : n;
}
return counts;
}
/// <summary>
/// "tapers 9, Lead Scarab 2" for the kinds at or under their line, or null. Kinds in
/// <paramref name="counts"/> join <paramref name="seen"/>; a seen kind missing now counts as 0.
/// A line of 0 or less is off for that kind.
/// </summary>
internal static string? LowComponents(Dictionary<string, int> counts, HashSet<string> seen, int taperMin, int scarabMin)
{
foreach (var k in counts.Keys) seen.Add(k);
var low = new List<string>();
foreach (string kind in seen)
{
int have = counts.TryGetValue(kind, out int c) ? c : 0;
bool taper = kind.Equals(TaperKey, StringComparison.OrdinalIgnoreCase);
int line = taper ? taperMin : scarabMin;
if (line > 0 && have <= line) low.Add($"{(taper ? "tapers" : kind)} {have}");
}
if (low.Count == 0) return null;
low.Sort(StringComparer.OrdinalIgnoreCase);
return string.Join(", ", low);
}
}

View file

@ -62,7 +62,11 @@ public sealed partial class RynthAiPlugin
private void NotePortalForPacer()
{
bool portaling = Host.HasIsPortaling && Host.IsPortaling();
if (portaling && !_wasPortalingForPacer) RynthCore.Plugin.Shared.ActionPacer.Forget("portal space");
if (portaling && !_wasPortalingForPacer)
{
RynthCore.Plugin.Shared.ActionPacer.Forget("portal space");
_buffManager?.ForgetPendingWield("portal space");
}
_wasPortalingForPacer = portaling;
}
@ -95,6 +99,7 @@ public sealed partial class RynthAiPlugin
_navigationEngine?.Stop();
RynthCore.Plugin.Shared.ActionPacer.Forget("death"); // the server dropped whatever was open
_buffManager?.CancelPendingRecall("death"); // no /lifestone or macro restart after the respawn
_buffManager?.ForgetPendingWield("death"); // a swap the death cut short is not a failed swap
}
else
{

View file

@ -1021,9 +1021,10 @@ public sealed partial class RynthAiPlugin : RynthPluginBase
["NavStopTurnAngle"] = (1, 90), ["NavResumeTurnAngle"] = (1, 45), ["NavDeadZone"] = (0.5, 20), ["NavSweepMult"] = (0.5, 10),
["NavLookaheadYards"] = (0, 30), ["NavShortcutYards"] = (0, 10), ["NavTurnRateDegPerSec"] = (30, 720), ["NavTier1TurnSpeed"] = (0.5, 15), ["PostPortalDelaySec"] = (0, 30),
["NavOffTrackYards"] = (160, 1000), ["NavMaxDetourAttempts"] = (1, 10),
["DunPatrolCoverage"] = (0, 2), ["DunPatrolSkipDeadEnds"] = (DungeonPatrolOptions.MaxDeadEndCellsMin, DungeonPatrolOptions.MaxDeadEndCellsMax),
["DunPatrolCoverage"] = (0, (int)PatrolCoverage.Sweep), ["DunPatrolSkipDeadEnds"] = (DungeonPatrolOptions.MaxDeadEndCellsMin, DungeonPatrolOptions.MaxDeadEndCellsMax),
["DunPatrolWallDistance"] = (DungeonPatrolOptions.WallClearanceMin, DungeonPatrolOptions.WallClearanceMax),
["DunPatrolLookInSize"] = (DungeonPatrolOptions.LookInRoomMin, DungeonPatrolOptions.LookInRoomMax),
["DunPatrolSightYd"] = (DungeonPatrolOptions.SightMin, DungeonPatrolOptions.SightMax),
["T2Speed"] = (0.1, 5), ["T2WalkWithinYd"] = (1, 50), ["T2DistanceTo"] = (0.1, 10), ["T2ReissueMs"] = (100, 10000),
["T2MaxRangeYd"] = (50, 2000), ["T2MaxLandblocks"] = (1, 20),
["RebuffSecondsRemaining"] = (30, 1800), ["RebuffTopOffSecondsRemaining"] = (30, 3600),
@ -1621,7 +1622,11 @@ public sealed partial class RynthAiPlugin : RynthPluginBase
_vitals.MaxMana = maxMp;
}
}
if (_dashboard?.Settings is { } safetySettings) CheckPlayerDeath(safetySettings);
if (_dashboard?.Settings is { } safetySettings)
{
CheckPlayerDeath(safetySettings);
CheckLowComponents(safetySettings);
}
// Dead or on the way back from a death: do nothing (HoldForDeath). The
// finally below still submits the nav markers.
RynthCore.Plugin.Shared.ActionPacer.NoteFrame();

View file

@ -130,6 +130,13 @@ internal static class ActionPacer
public const long GestureEmergencyMaxMs = 1500;
/// <summary>A heal behind a stance change: once the client has read the new mode this long.</summary>
public const long HealAfterModeReadMs = 300;
/// <summary>
/// A melee/missile swing behind the stance change into that mode: once the client has read the
/// mode this long, not the full ModeSettleMs (2026-10-14: the first swing of every fight came
/// 0.8 s after the stance; the settle is there for uses, whose server turn a stance stops, and a
/// swing is no use: the server plays it after the stance, as when a player attacks from peace).
/// </summary>
public const long AttackAfterModeReadMs = 300;
/// <summary>An engine without UseDone: an action counts as answered after this (no real pacing).</summary>
public const long NoUseDoneFallbackMs = 600;
@ -383,18 +390,22 @@ internal static class ActionPacer
return false;
}
lock (Gate) _settleLogged.Clear();
if (!OutstandingAllows(host, who, heal, out why)) return false;
if (!OutstandingAllows(host, who, heal, out why, attackRepeat)) return false;
if (animationGate && GestureHolds(host, who, heal, out why)) return false;
return true;
}
private static bool OutstandingAllows(RynthCoreHost host, string who, HealNeed heal, out string why)
private static bool OutstandingAllows(RynthCoreHost host, string who, HealNeed heal, out string why, bool attack = false)
{
why = "";
PacedAction? a = Current(host);
if (a == null) return true;
long age = NowMs() - a.SentMs;
// The first swing after the change into Melee/Missile mode (see AttackAfterModeReadMs).
if (attack && a.Kind == PacedKind.CombatMode && a.ModeSeenMs != 0 && NowMs() - a.ModeSeenMs >= AttackAfterModeReadMs)
return true;
if (heal != HealNeed.None)
{
if (a.Kind == PacedKind.WorldUse && heal == HealNeed.Emergency && age >= EmergencyAfterWorldUseMs)