RynthSuite as of 2026-10-04 (internal c94715f): RynthOracle (based on Oracle of Dereth by Advis Eveldan) and RynthInventory, RynthAi patrol doorways and rooms, healing priority, strict monster priority, finish the wounded target, slayer weapons, arcs when clear, blasts like rings, learn unknown spells, looting fixes, release 2026.10.4.6

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Tom Bohar 2026-10-04 18:34:29 -04:00
commit 12ca25f911
426 changed files with 108239 additions and 7521 deletions

View file

@ -4,6 +4,7 @@ using System.Linq;
using RynthCore.Loot;
using RynthCore.Plugin.RynthAi.LegacyUi;
using RynthCore.PluginSdk;
using RynthCore.Plugin.Shared;
namespace RynthCore.Plugin.RynthAi;
@ -13,8 +14,9 @@ namespace RynthCore.Plugin.RynthAi;
/// Each think tick from Idle picks one of two actions:
/// 1. If any worn item has CurrentMana below the threshold AND we have a
/// charged stone in inventory, use the stone on the player.
/// 2. Otherwise, if we have an empty stone and an inventory item with at
/// least the threshold of CurrentMana, drain it.
/// 2. Otherwise, if we have an empty stone and an item the looter picked up
/// as "ManaTap" (looted only to be drained) still holds at least the
/// threshold of CurrentMana, drain it. Nothing else is ever drained.
///
/// Single-shot semantics:
/// - Using an empty stone on an item destroys the item and charges the stone.
@ -63,12 +65,36 @@ internal sealed class ManaStoneManager
// below this fraction of its MaxMana. Prevents the bot from continually
// dumping stones on the player just because an item dipped slightly.
private const double WornRefillPctOfMax = 0.25;
// With an Eternal Mana Charge (never used up) there's no reason to wait for 25%: top
// gear up below 75% (Lucy carried one on her Items list and it was never used, 2026-09-30).
private const double WornRefillPctOfMaxEternal = 0.75;
private long _lastGearDiagAt;
private readonly Dictionary<int, long> _manaIdRequestedAt = new();
private const long ThinkIntervalMs = 600;
private const long ActionTimeoutMs = 8000;
private static long NowMs => Environment.TickCount64;
/// <summary>
/// Set by the plugin: true when a Keep or Keep # rule in the active loot profile
/// matches the item. Draining destroys the item, so kept loot is never a tap target.
/// </summary>
public Func<WorldObject, bool>? IsLootKept { get; set; }
// Items the looter picked up as "ManaTap" (looted only to be drained), with the
// time each was recorded. Draining destroys the item, so these are the ONLY tap
// targets: gear, quest items, bought items and loot kept by a rule are never in
// here. Session memory only: a hot reload or relog builds a new manager and the
// set starts empty, so anything looted for tapping before that just stays in
// the pack undrained (the safe direction).
private readonly Dictionary<int, long> _lootedForTap = new();
// An entry is not pruned for "not in the pack" this soon after it was recorded:
// the pickup is recorded when it is sent, before the item arrives.
private const long LootedForTapGraceMs = 30_000;
private const long LootedForTapPruneIntervalMs = 1_000;
private long _lootedForTapPrunedAt;
public ManaStoneManager(RynthCoreHost host, LegacyUiSettings settings, WorldObjectCache objectCache)
{
_host = host;
@ -80,7 +106,12 @@ internal sealed class ManaStoneManager
public void OnHeartbeat(int busyCount)
{
if (!_settings.EnableManaTapping) { Reset(); return; }
// Before the early returns: items sold, given away or dropped while tapping is
// off or the macro is stopped must leave the set too.
PruneLootedForTap(NowMs);
// An Eternal Mana Charge refills gear for free, so it works with tapping off too.
if (!_settings.EnableManaTapping && !HasEternalCharge()) { Reset(); return; }
if (!_settings.IsMacroRunning) { Reset(); return; }
long now = NowMs;
@ -96,6 +127,7 @@ internal sealed class ManaStoneManager
if (itemGone || stoneGone)
{
_host.Log($"[RynthAi] ManaStone: tap completion detected (itemGone={itemGone} stoneGone={stoneGone}).");
if (itemGone) _lootedForTap.Remove(_activeItemId); // drained and destroyed
GoIdle();
}
}
@ -174,6 +206,7 @@ internal sealed class ManaStoneManager
|| text.Contains("is destroyed")
|| text.Contains("has been destroyed"))
{
if (_activeItemId != 0) _lootedForTap.Remove(_activeItemId); // drained and destroyed
GoIdle();
return;
}
@ -206,20 +239,64 @@ internal sealed class ManaStoneManager
}
}
/// <summary>
/// CorpseOpenController calls this when it picks an item up as "ManaTap" (no loot
/// rule matched, it holds enough mana and an empty stone is free): when the pickup
/// is sent, and again when it is confirmed. Only these items are ever drained.
/// </summary>
public void MarkLootedForTap(int itemId)
{
if (itemId != 0) _lootedForTap[itemId] = NowMs;
}
/// <summary>
/// Drops entries whose item has left the pack: drained (destroyed), sold, given
/// away, salvaged, dropped, or never arrived. Also drops items the player has
/// since put on or added to the Weapons tab: that is the player choosing to keep
/// it, so it stops being tap fodder for good.
/// </summary>
private void PruneLootedForTap(long now)
{
if (_lootedForTap.Count == 0) return;
if (now - _lootedForTapPrunedAt < LootedForTapPruneIntervalMs) return;
_lootedForTapPrunedAt = now;
int playerId = unchecked((int)_host.GetPlayerId());
List<int>? drop = null;
foreach (var kv in _lootedForTap)
{
WorldObject? item = _objectCache[kv.Key];
bool keptByPlayer = item != null
&& ((playerId != 0 && item.Wielder == playerId)
|| WorldObjectCache.IsWieldedByPlayer(_host, item)
|| _settings.ItemRules.Any(r => r.Id == item.Id));
if (!keptByPlayer)
{
if (now - kv.Value < LootedForTapGraceMs) continue; // pickup may still be arriving
if (item != null && IsOwnedByPlayer(item, playerId)) continue;
}
(drop ??= new List<int>()).Add(kv.Key);
}
if (drop == null) return;
foreach (int id in drop)
_lootedForTap.Remove(id);
_host.Log($"[RynthAi] ManaStone: {drop.Count} looted-for-tap item(s) left the pack or were kept by the player; {_lootedForTap.Count} left to drain.");
}
// ── Private helpers ───────────────────────────────────────────────────────
private void TryBeginAction()
{
int threshold = _settings.ManaTapMinMana;
// Priority 1 (was 2): drain a tappable looted item into an empty stone.
// Priority 1 (was 2): drain an item looted for tapping into an empty stone.
// This wins over refilling worn gear because:
// * draining is the user's primary goal (loot-for-tap behavior),
// * the use-on-player path only accepts certain equipment slots and
// can loop forever on items like wielded weapons that AC won't
// refill via stone — that loop blacklists stones one by one and
// starves the drain path entirely.
int stoneId = FindEmptyStone();
int stoneId = _settings.EnableManaTapping ? FindEmptyStone() : 0;
int targetId = stoneId != 0 ? FindTapTarget(threshold) : 0;
if (stoneId != 0 && targetId != 0)
@ -251,7 +328,7 @@ internal sealed class ManaStoneManager
{
_state = TapState.TappingItem;
_actionIssuedAt = NowMs;
_host.UseObjectOn(unchecked((uint)stoneId), unchecked((uint)itemId));
_host.UseOnFor(unchecked((uint)stoneId), unchecked((uint)itemId), "ManaStone", "tap an item into a mana stone");
}
private void IssueUseOnPlayer()
@ -265,7 +342,7 @@ internal sealed class ManaStoneManager
_host.Log($"[RynthAi] ManaStone: using charged stone 0x{(uint)_activeStoneId:X8} on player");
_state = TapState.UsingOnPlayer;
_actionIssuedAt = NowMs;
_host.UseObjectOn(unchecked((uint)_activeStoneId), playerId);
_host.UseOnFor(unchecked((uint)_activeStoneId), playerId, "ManaStone", "charged mana stone on yourself");
}
private void GoIdle()
@ -317,8 +394,9 @@ internal sealed class ManaStoneManager
}
/// <summary>
/// Items already in the player's inventory that match the tap-target criteria
/// (mana ≥ threshold, not equipped, not loot-kept, not blacklisted). Each one
/// Items looted for tapping that are in the player's inventory and match the
/// tap-target criteria (mana ≥ threshold, not equipped, not on the Weapons tab,
/// not loot-kept, not blacklisted). Each one
/// will eventually consume one empty stone, so they count against the
/// "free slots" quota that CorpseOpenController uses for ManaTap pickup.
/// </summary>
@ -331,8 +409,10 @@ internal sealed class ManaStoneManager
long now = NowMs;
int count = 0;
foreach (var item in _objectCache.AllKnownObjects())
foreach (int id in _lootedForTap.Keys) // keep in sync with FindTapTarget
{
WorldObject? item = _objectCache[id];
if (item == null) continue;
if (IsManaStone(item)) continue;
if (!IsOwnedByPlayer(item, playerId)) continue;
if (IsWandLike(item)) continue; // wands are never tap targets — keep this in sync with FindTapTarget
@ -341,11 +421,33 @@ internal sealed class ManaStoneManager
&& wield != 0) continue;
if (!_host.TryGetObjectIntProperty(unchecked((uint)item.Id), (uint)AcIntProperty.CurrentMana, out int curMana)
|| curMana < threshold) continue;
if (IsProtectedFromTap(item, playerId)) continue; // keep in sync with FindTapTarget
count++;
}
return count;
}
/// <summary>
/// Items a drain must never touch (the drain destroys the item): gear the player
/// is wearing or wielding, weapons and wands on the Weapons tab (the bow sits in
/// the pack while the wand buffs), and loot the profile keeps. Stype 10 can read 0
/// for a wielded item, so worn gear is also checked by its wielder.
/// </summary>
private bool IsProtectedFromTap(WorldObject item, int playerId)
{
if (playerId != 0 && item.Wielder == playerId) return true;
if (WorldObjectCache.IsWieldedByPlayer(_host, item)) return true;
foreach (var rule in _settings.ItemRules)
if (rule.Id == item.Id) return true;
var kept = IsLootKept;
if (kept != null)
{
try { if (kept(item)) return true; }
catch { return true; }
}
return false;
}
/// <summary>
/// Free empty-stone slots = empty stones in inventory minus drain candidates
/// already in inventory waiting to be tapped. CorpseOpenController only
@ -369,6 +471,7 @@ internal sealed class ManaStoneManager
/// </summary>
public bool IsManaStone(WorldObject item)
{
if (IsEternal(item)) return true;
bool hasRule = false;
foreach (var rule in _settings.ConsumableRules)
{
@ -384,14 +487,57 @@ internal sealed class ManaStoneManager
if (item.ObjectClass == AcObjectClass.ManaStone) return true;
return !string.IsNullOrEmpty(item.Name)
&& item.Name.Contains("Mana Stone", StringComparison.OrdinalIgnoreCase);
&& (item.Name.Contains("Mana Stone", StringComparison.OrdinalIgnoreCase)
|| item.Name.Contains("Mana Charge", StringComparison.OrdinalIgnoreCase));
}
/// <summary>
/// An unlimited mana charge (Eternal Mana Charge: 10,000 mana, never used up). Always
/// "charged", never an empty stone to drain into, and preferred for refilling gear.
/// </summary>
private static bool IsEternal(WorldObject item) =>
!string.IsNullOrEmpty(item.Name) && item.Name.StartsWith("Eternal Mana", StringComparison.OrdinalIgnoreCase);
private bool HasEternalCharge()
{
int playerId = unchecked((int)_host.GetPlayerId());
foreach (var item in _objectCache.GetDirectInventory(forceRefresh: false))
if (IsEternal(item) && IsOwnedByPlayer(item, playerId)) return true;
return false;
}
/// <summary>True if the item's container chain roots at the player's pack.</summary>
// What the player owns, rebuilt at most every 600 ms: the pack walk (GetContainerContents,
// what kits and potions already use) plus the cache's inventory set (wielded items too).
// The per-object container/wielder fields below read 0 off AC's thread, so every item
// looked like it lay on the ground: gear-check logged worn=0 and eternal=False for a
// character wearing gear with an Eternal Mana Charge in the pack (2026-09-30).
private readonly HashSet<int> _ownedIds = new();
private long _ownedIdsAt;
private HashSet<int> OwnedIds()
{
long now = NowMs;
if (now - _ownedIdsAt < ThinkIntervalMs && _ownedIds.Count > 0) return _ownedIds;
_ownedIdsAt = now;
_ownedIds.Clear();
foreach (var wo in _objectCache.GetDirectInventory(forceRefresh: false)) _ownedIds.Add(wo.Id);
foreach (var wo in _objectCache.GetInventory()) _ownedIds.Add(wo.Id);
return _ownedIds;
}
private bool IsOwnedByPlayer(WorldObject item, int playerId)
{
if (item.ObjectClass == AcObjectClass.Corpse) return false;
if (OwnedIds().Contains(item.Id)) return true;
if (item.Wielder != 0 && playerId != 0 && item.Wielder != playerId) return false;
// In no container and wielded by nobody = lying on the ground. Those passed as
// owned (the scans walk every known object), so a Mana Stone on a dungeon floor
// became the "empty stone": the tap could never complete, timed out after 8 s
// and shelved the real tap target for 5 minutes. Only when the engine can read
// ownership; without it every object reads 0 and the old behaviour stays.
if (item.Container == 0 && item.Wielder == 0 && playerId != 0 && _host.HasGetObjectOwnershipInfo)
return false;
if (item.Container != 0 && playerId != 0 && item.Container != playerId)
{
var owner = _objectCache[item.Container];
@ -410,7 +556,7 @@ internal sealed class ManaStoneManager
foreach (var item in _objectCache.AllKnownObjects())
{
if (!IsManaStone(item)) continue;
if (!IsManaStone(item) || IsEternal(item)) continue;
if (!IsOwnedByPlayer(item, playerId)) continue;
// Stones AC has explicitly told us are charged ("already full of
@ -467,6 +613,10 @@ internal sealed class ManaStoneManager
if (_stoneUseOnPlayerCooldownUntil.TryGetValue(item.Id, out long until) && now < until)
continue;
// Eternal: always charged (its mana often can't be read), never used up — first choice.
if (IsEternal(item)) return item.Id;
if (!_settings.EnableManaTapping) continue; // tapping off: only the free charge
if (!_host.TryGetObjectIntProperty(unchecked((uint)item.Id), (uint)AcIntProperty.CurrentMana, out int cur))
continue;
if (cur <= 0) continue;
@ -477,14 +627,22 @@ internal sealed class ManaStoneManager
return bestId;
}
/// <summary>
/// The next item to drain. Only items the looter picked up as "ManaTap" are
/// candidates (the drain destroys the item); every check below is a second
/// safety net on top of that.
/// </summary>
private int FindTapTarget(int threshold)
{
if (!_host.HasGetObjectIntProperty) return 0;
if (_lootedForTap.Count == 0) return 0;
int playerId = unchecked((int)_host.GetPlayerId());
long now = NowMs;
foreach (var item in _objectCache.AllKnownObjects())
foreach (int id in _lootedForTap.Keys)
{
WorldObject? item = _objectCache[id];
if (item == null) continue;
if (IsManaStone(item)) continue;
if (!IsOwnedByPlayer(item, playerId)) continue;
@ -510,6 +668,10 @@ internal sealed class ManaStoneManager
|| curMana < threshold)
continue;
// Worn gear (stype 10 can read 0), Weapons-tab items and kept loot.
if (IsProtectedFromTap(item, playerId))
continue;
return item.Id;
}
@ -550,34 +712,72 @@ internal sealed class ManaStoneManager
{
if (!_host.HasGetObjectIntProperty) return false;
int playerId = unchecked((int)_host.GetPlayerId());
bool eternal = HasEternalCharge();
double pct = eternal ? WornRefillPctOfMaxEternal : WornRefillPctOfMax;
int worn = 0, readable = 0, lowestPct = 101;
string lowestName = "";
bool needs = false;
bool requestedThisPass = false;
foreach (var item in _objectCache.AllKnownObjects())
{
if (IsManaStone(item)) continue;
if (!IsOwnedByPlayer(item, playerId)) continue;
if (!_host.TryGetObjectIntProperty(unchecked((uint)item.Id), (uint)AcIntProperty.WieldedSlot, out int wield)
|| wield == 0)
// The live slot read can fail off AC's thread; the cache's copy (what /ra wielded
// uses) is the fallback.
if (!_host.TryGetObjectIntProperty(unchecked((uint)item.Id), (uint)AcIntProperty.WieldedSlot, out int wield) || wield == 0)
wield = item.Values(LongValueKey.CurrentWieldedLocation, 0);
if (wield == 0)
continue;
worn++;
// Only items that actually consume mana matter
if (!_host.TryGetObjectIntProperty(unchecked((uint)item.Id), (uint)AcIntProperty.MaxMana, out int maxMana)
|| maxMana <= 0)
// Only items that actually consume mana matter. Off AC's thread an item's mana is
// only known once it has been identified (appraisal cache); worn gear often never
// is, so nothing ever read as low and no stone or charge was used. Identify one such
// item per check, each at most every 5 minutes (a request bumps the busy count).
if (!_host.TryGetObjectIntProperty(unchecked((uint)item.Id), (uint)AcIntProperty.MaxMana, out int maxMana))
{
long nowMs = NowMs;
if (!requestedThisPass && _host.HasRequestId
&& (!_manaIdRequestedAt.TryGetValue(item.Id, out long at) || nowMs - at > 300_000))
{
_manaIdRequestedAt[item.Id] = nowMs;
_host.RequestId(unchecked((uint)item.Id));
requestedThisPass = true;
}
continue;
}
if (maxMana <= 0)
continue;
if (!_host.TryGetObjectIntProperty(unchecked((uint)item.Id), (uint)AcIntProperty.CurrentMana, out int curMana))
continue;
readable++;
_manaIdRequestedAt.Remove(item.Id);
int p = (int)(curMana * 100L / maxMana);
if (p < lowestPct) { lowestPct = p; lowestName = item.Name ?? ""; }
// Refill only when an item has dropped to a small fraction of its
// MaxMana. The configured threshold is for *draining* loose items,
// not for "the player's robe is at 88% of full" — using min(threshold,
// maxMana) caused the bot to dump charged stones constantly on
// Refill only when an item has dropped to a fraction of its MaxMana (25%, or
// 75% with an Eternal charge). The configured threshold is for *draining* loose
// items, not for "the player's robe is at 88% of full" — using
// min(threshold, maxMana) caused the bot to dump charged stones constantly on
// near-full equipment.
int floor = (int)(maxMana * WornRefillPctOfMax);
int floor = (int)(maxMana * pct);
if (curMana < floor)
return true;
needs = true;
}
return false;
// Once a minute: what it can see, so "the charge is never used" can be told apart
// from "the gear's mana can't be read".
long now = NowMs;
if (now - _lastGearDiagAt > 60_000)
{
_lastGearDiagAt = now;
_host.Log($"[RynthAi] ManaStone: gear check - worn={worn} manaReadable={readable} lowest={(readable > 0 ? $"{lowestPct}% ({lowestName})" : "n/a")} " +
$"refillBelow={(int)(pct * 100)}% eternal={eternal} needs={needs} tapping={_settings.EnableManaTapping}");
}
return needs;
}
}