Pace scroll reads and the stance restore from the read's UseDone
ACE sends "The scroll is destroyed." before the return-to-ready animation and the UseDone after it (Scroll.ActOnUse, Player.TryUseItem); in a client log they were ~0.7 s apart, and the next read went ~0.8 s after the UseDone. - The first UseDone after a read's send is that read's. The next read goes 250 ms after it; with no UseDone seen, 1.5 s after the read's end as before. - The stance restore goes at the last read's UseDone when no scroll is pending, instead of 3.5 s after the read; a pending scroll keeps the settle wait. - Tests: ReadGapFromUseDone, StanceRestoredAtLastUseDone. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
316527227f
commit
bb8ac3e60f
2 changed files with 118 additions and 3 deletions
|
|
@ -84,8 +84,14 @@ internal sealed class ScrollLearner
|
|||
internal const long ArrivalGraceMs = 15_000;
|
||||
/// <summary>Read animation + 1 s read + return to ready is ~3-4 s on ACE; give up after this.</summary>
|
||||
internal const long ReadTimeoutMs = 8_000;
|
||||
/// <summary>Pause between two reads.</summary>
|
||||
/// <summary>
|
||||
/// Pause between two reads, from the read's end (its chat answer), when the read's UseDone is not
|
||||
/// seen. ACE sends "The scroll is destroyed." before the return-to-ready animation and the UseDone
|
||||
/// after it (Scroll.ActOnUse, Player.TryUseItem): about 0.7 s apart in a client log.
|
||||
/// </summary>
|
||||
internal const long ReadGapMs = 1_500;
|
||||
/// <summary>Pause between two reads, from the last read's UseDone (the server is free then).</summary>
|
||||
internal const long ReadGapAfterUseDoneMs = 250;
|
||||
/// <summary>How often the pack is looked through for unknown scrolls.</summary>
|
||||
internal const long PackSweepMs = 5_000;
|
||||
/// <summary>A scroll approved for looting holds its spell this long (one copy per spell).</summary>
|
||||
|
|
@ -146,6 +152,11 @@ internal sealed class ScrollLearner
|
|||
private string _chatText = "";
|
||||
private bool _readItemDeleted;
|
||||
|
||||
// The UseDone of the last read sent: the first UseDone after its send. 0 = not seen (yet).
|
||||
private bool _readUseDoneWatch;
|
||||
private int _readUseDoneSeqAtSend;
|
||||
private long _readUseDoneAt;
|
||||
|
||||
public ScrollLearner(RynthCoreHost host, LegacyUiSettings settings, WorldObjectCache? cache)
|
||||
{
|
||||
_host = host;
|
||||
|
|
@ -352,6 +363,7 @@ internal sealed class ScrollLearner
|
|||
public bool Tick(bool safe, int busyCount)
|
||||
{
|
||||
long now = NowMs();
|
||||
PollReadUseDone(now);
|
||||
if (IsReading)
|
||||
{
|
||||
if (ResolveRead(now)) return false;
|
||||
|
|
@ -376,7 +388,7 @@ internal sealed class ScrollLearner
|
|||
}
|
||||
|
||||
if (!safe || busyCount > 0 || _pending.Count == 0) return false;
|
||||
if (now - _lastReadEndedAt < ReadGapMs) return false;
|
||||
if (!ReadGapOver(now)) return false;
|
||||
if (inv == null)
|
||||
{
|
||||
if (now - _lastStartCheckAt < StartCheckMs) return false; // one pack walk a second at most
|
||||
|
|
@ -466,7 +478,10 @@ internal sealed class ScrollLearner
|
|||
if (_settings.PeaceModeWhenIdle) { CloseSeries(""); return; } // switched on since: Peace is wanted
|
||||
long age = now - _lastReadEndedAt;
|
||||
if (_restoreMode == 0) { if (age >= RestoreSettleMs) CloseSeries(""); return; }
|
||||
if (age < RestoreSettleMs) return; // the next scroll may be about to start
|
||||
// The next scroll may be about to start: wait the settle time, unless the last read's UseDone
|
||||
// is in and no scroll is pending (nothing left to read, so the stance can go back now).
|
||||
bool lastReadDone = LastReadUseDoneSeen && _pending.Count == 0;
|
||||
if (age < RestoreSettleMs && !lastReadDone) return;
|
||||
if (age > RestoreSettleMs + RestoreGiveUpMs) { CloseSeries("too late"); return; }
|
||||
int cur = CurrentMode();
|
||||
if (cur == _restoreMode) { CloseSeries(""); return; } // back in stance
|
||||
|
|
@ -593,6 +608,9 @@ internal sealed class ScrollLearner
|
|||
_chatText = "";
|
||||
_readItemDeleted = false;
|
||||
|
||||
int seqBefore = 0;
|
||||
bool haveSeq = false;
|
||||
try { if (_host.HasUseDoneSeq) { seqBefore = _host.GetUseDoneSeq(); haveSeq = true; } } catch { }
|
||||
bool sent = false;
|
||||
try { sent = _host.UseFor(unchecked((uint)pickId), "Learn", $"read the scroll to learn {j.SpellName} ({j.Why})"); }
|
||||
catch { }
|
||||
|
|
@ -603,10 +621,39 @@ internal sealed class ScrollLearner
|
|||
else pp.NotBefore = now + 3_000;
|
||||
return false;
|
||||
}
|
||||
_readUseDoneWatch = haveSeq;
|
||||
_readUseDoneSeqAtSend = seqBefore;
|
||||
_readUseDoneAt = 0;
|
||||
LogLine($"[Learn] reading '{pick.Name}' ({j.SpellName}: {j.Why})");
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>Notes the first UseDone after the last read's send (the server's end of that read).</summary>
|
||||
private void PollReadUseDone(long now)
|
||||
{
|
||||
if (!_readUseDoneWatch) return;
|
||||
try
|
||||
{
|
||||
if (unchecked(_host.GetUseDoneSeq() - _readUseDoneSeqAtSend) > 0)
|
||||
{
|
||||
_readUseDoneWatch = false;
|
||||
_readUseDoneAt = now;
|
||||
}
|
||||
}
|
||||
catch { _readUseDoneWatch = false; }
|
||||
}
|
||||
|
||||
/// <summary>The last read's UseDone was seen (after its chat answer, or at any time for this read).</summary>
|
||||
private bool LastReadUseDoneSeen => _readUseDoneAt != 0;
|
||||
|
||||
/// <summary>
|
||||
/// May the next read start? ReadGapAfterUseDoneMs after the last read's UseDone, or ReadGapMs
|
||||
/// after its end when no UseDone is seen (an engine without UseDone, or a lost one).
|
||||
/// </summary>
|
||||
private bool ReadGapOver(long now) =>
|
||||
(LastReadUseDoneSeen && now - _readUseDoneAt >= ReadGapAfterUseDoneMs)
|
||||
|| now - _lastReadEndedAt >= ReadGapMs;
|
||||
|
||||
/// <summary>True when the read in flight is over (learned, refused, or timed out).</summary>
|
||||
private bool ResolveRead(long now)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue