Snapshot for release 2026.10.12.2 (internal 2dd3d00)
This commit is contained in:
parent
3c4f093e3d
commit
fe1eca0ca7
4 changed files with 381 additions and 10 deletions
|
|
@ -468,6 +468,40 @@ public class BuffManager : IDisposable
|
|||
return null;
|
||||
}
|
||||
|
||||
private DateTime _buffManaWaitLoggedAt = DateTime.MinValue;
|
||||
|
||||
/// <summary>
|
||||
/// Before a buff: true when it waits for mana. Casting it would leave mana under the reserve
|
||||
/// (ManaReserve, from Stamina to Mana's cost) and Stamina to Mana (or a mana potion) is cast
|
||||
/// now instead; or mana can't pay for the buff or for Stamina to Mana, and buffing waits.
|
||||
/// </summary>
|
||||
internal bool BuffWaitsForMana(int spellId, string buffName)
|
||||
{
|
||||
if (_vitals.MaxMana == 0) return false;
|
||||
int reserve = ManaReserve();
|
||||
int cost = SpellManaCost(spellId);
|
||||
uint cur = _vitals.CurrentMana;
|
||||
bool cantPay = cost > 0 && cur < cost;
|
||||
bool underReserveAfter = reserve > 0 && (long)cur - Math.Max(cost, 0) < reserve;
|
||||
if (!cantPay && !underReserveAfter) return false;
|
||||
|
||||
_vitalWhy = "";
|
||||
if ((StaminaAllowsStaminaToMana() && AttemptVitalCast("Stamina to Mana Self")) || AttemptPotion("ManaPotion"))
|
||||
{
|
||||
_isRechargingMana = true;
|
||||
LastBuffSkipReason = $"mana {cur}/{_vitals.MaxMana} before {buffName}: Stamina to Mana first";
|
||||
return true;
|
||||
}
|
||||
if (!cantPay) return false; // under the reserve after it, but nothing refills: cast the buff anyway
|
||||
LastBuffSkipReason = $"mana {cur}/{_vitals.MaxMana} is under {buffName}'s cost ({cost}); waiting for regen";
|
||||
if ((DateTime.Now - _buffManaWaitLoggedAt).TotalSeconds >= 30)
|
||||
{
|
||||
_buffManaWaitLoggedAt = DateTime.Now;
|
||||
_host.Log($"[RynthAi] Vitals: buffing waits: {LastBuffSkipReason} (Stamina to Mana: {Why(_vitalWhy)})");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private readonly Dictionary<int, DateTime> _castIssuedAtByFamily = new();
|
||||
private readonly Dictionary<int, DateTime> _expiryAtCastByFamily = new();
|
||||
private const double AuditSettleMs = 15_000.0;
|
||||
|
|
@ -2471,6 +2505,13 @@ public class BuffManager : IDisposable
|
|||
return true; // normal in-progress swap — yield the tick (NeedsAnyBuff still holds Buffing)
|
||||
}
|
||||
|
||||
// The mana reserve holds buffs too, melee or caster (2026-10-12, Drakkon: a full rebuff
|
||||
// spent mana spell by spell down to 6%, under Stamina to Mana's cost, and he stood there
|
||||
// until regen reached it). A buff that would leave mana under the reserve waits for
|
||||
// Stamina to Mana first; when even that can't be paid for, buffing waits for regen.
|
||||
if (BuffWaitsForMana(spellId, buffBaseName))
|
||||
return true;
|
||||
|
||||
_pendingSpellId = spellId;
|
||||
if (buffFamily != 0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -88,6 +88,22 @@ internal sealed class ManaStoneManager
|
|||
private const long RefillHoldMs = 2 * 60 * 1000;
|
||||
private long _lastNoStoneDiagAt;
|
||||
|
||||
// Worn gear's mana is read from its last appraisal, and ACE never sends a change to it while the
|
||||
// gear burns mana (Player.ManaConsumersTick), so a mace identified at 90% read 90% all night while
|
||||
// it ran dry, and nothing was refilled (Mana Charges in the pack, 2026-10-11). Two fixes:
|
||||
// * "Your X is low on Mana." / "Your X is out of Mana." (the server's own word) means the gear
|
||||
// needs mana whatever the reads say, until the server says it's full again.
|
||||
// * worn items are identified again every 10 minutes (one every 5 seconds at most), and right
|
||||
// after a stone gave its mana, so the reads follow the gear.
|
||||
private long _serverSaidGearLowAt;
|
||||
private readonly Dictionary<int, long> _gearReadRefreshedAt = new();
|
||||
private long _lastGearRefreshAt;
|
||||
private const long GearRefreshMs = 10 * 60 * 1000;
|
||||
private const long GearRefreshSpacingMs = 5000;
|
||||
|
||||
private const uint StackSizeKey = 12; // STACK_SIZE (the client's live copy)
|
||||
private long _stoneMarksPrunedAt;
|
||||
|
||||
// Worn equipment is only treated as "needs refill" when current mana drops
|
||||
// below this fraction of its MaxMana. Prevents the bot from continually
|
||||
// dumping stones on the player just because an item dipped slightly.
|
||||
|
|
@ -138,6 +154,7 @@ internal sealed class ManaStoneManager
|
|||
// 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);
|
||||
PruneStoneMarks(NowMs);
|
||||
|
||||
// Refilling worn gear from a charged stone (or a free Eternal charge) works with tapping
|
||||
// off too; only draining loot into empty stones needs tapping on. It used to need tapping
|
||||
|
|
@ -229,6 +246,27 @@ internal sealed class ManaStoneManager
|
|||
{
|
||||
if (string.IsNullOrEmpty(text)) return;
|
||||
|
||||
// In any state. ACE: "Your {item} is low on Mana." (about two minutes left) and "Your {item} is
|
||||
// out of Mana." - worn gear needs mana now, whatever its (appraisal) read says.
|
||||
if (text.StartsWith("Your ", StringComparison.Ordinal)
|
||||
&& (text.Contains(" is low on Mana", StringComparison.OrdinalIgnoreCase)
|
||||
|| text.Contains(" is out of Mana", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
if (_serverSaidGearLowAt == 0)
|
||||
_host.Log($"[RynthAi] ManaStone: the server says worn gear is low ('{text.Trim()}') - refilling whatever the gear's mana reads say.");
|
||||
_serverSaidGearLowAt = NowMs;
|
||||
_refillHoldUntil = 0; // the server's word is newer than "fully charged"
|
||||
return;
|
||||
}
|
||||
// The stone-on-player reply's second line; it may arrive as a line of its own.
|
||||
if (text.Contains("Your items are fully charged"))
|
||||
{
|
||||
_serverSaidGearLowAt = 0;
|
||||
HoldRefills("the server says the worn items are fully charged");
|
||||
}
|
||||
if (text.Contains("no items equipped that need mana"))
|
||||
_serverSaidGearLowAt = 0;
|
||||
|
||||
if (_state == TapState.TappingItem)
|
||||
{
|
||||
// "The Mana Stone drains X points of mana from the ..." — single drain,
|
||||
|
|
@ -282,7 +320,9 @@ internal sealed class ManaStoneManager
|
|||
// its read still shows the old charge.
|
||||
WorldObject? stone = _activeStoneId != 0 ? _objectCache[_activeStoneId] : null;
|
||||
if (stone == null || !IsEternal(stone)) MarkStoneEmpty(_activeStoneId);
|
||||
if (text.Contains("fully charged")) HoldRefills("the server says the worn items are fully charged");
|
||||
// ("Your items are fully charged" was handled above.) The gear's reads are from before
|
||||
// the refill: identify the worn items again.
|
||||
_gearReadRefreshedAt.Clear();
|
||||
Reset();
|
||||
return;
|
||||
}
|
||||
|
|
@ -321,10 +361,40 @@ internal sealed class ManaStoneManager
|
|||
private void MarkStoneEmpty(int id)
|
||||
{
|
||||
if (id == 0) return;
|
||||
// A stack of stones or charges gave one item's mana; the rest of the stack is still charged
|
||||
// and keeps its id (retail Mana Charges don't stack and are destroyed by every use, but a
|
||||
// stacked one must not be written off after its first refill).
|
||||
if (_host.TryGetObjectIntProperty(unchecked((uint)id), StackSizeKey, out int stack) && stack > 1)
|
||||
{
|
||||
_host.Log($"[RynthAi] ManaStone: stone 0x{(uint)id:X8} gave its mana, but it is a stack of {stack} - still a source.");
|
||||
return;
|
||||
}
|
||||
_stoneKnownCharged.Remove(id);
|
||||
_stoneKnownEmpty[id] = ReadStoneMana(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Forgets what the server said about stones that left the pack (used up, destroyed, sold). AC
|
||||
/// reuses object ids, so a stale "gave its mana" mark could otherwise write off a new charge.
|
||||
/// </summary>
|
||||
private void PruneStoneMarks(long now)
|
||||
{
|
||||
if (now - _stoneMarksPrunedAt < 5000) return;
|
||||
_stoneMarksPrunedAt = now;
|
||||
if (_stoneKnownEmpty.Count == 0 && _stoneKnownCharged.Count == 0) return;
|
||||
List<int>? gone = null;
|
||||
foreach (int id in _stoneKnownEmpty.Keys)
|
||||
if (id != _activeStoneId && _objectCache[id] == null) (gone ??= new List<int>()).Add(id);
|
||||
foreach (int id in _stoneKnownCharged)
|
||||
if (id != _activeStoneId && _objectCache[id] == null) (gone ??= new List<int>()).Add(id);
|
||||
if (gone == null) return;
|
||||
foreach (int id in gone)
|
||||
{
|
||||
_stoneKnownEmpty.Remove(id);
|
||||
_stoneKnownCharged.Remove(id);
|
||||
}
|
||||
}
|
||||
|
||||
private void MarkStoneCharged(int id)
|
||||
{
|
||||
if (id == 0) return;
|
||||
|
|
@ -478,7 +548,7 @@ internal sealed class ManaStoneManager
|
|||
|
||||
foreach (var item in _objectCache.AllKnownObjects())
|
||||
{
|
||||
if (!IsManaStone(item)) continue;
|
||||
if (!IsManaStone(item) || IsManaCharge(item)) continue; // keep in sync with FindEmptyStone
|
||||
if (!IsOwnedByPlayer(item, playerId)) continue;
|
||||
if (_stoneKnownCharged.Contains(item.Id)) continue;
|
||||
|
||||
|
|
@ -609,6 +679,14 @@ internal sealed class ManaStoneManager
|
|||
private static bool IsEternal(WorldObject item) =>
|
||||
!string.IsNullOrEmpty(item.Name) && item.Name.StartsWith("Eternal Mana", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
/// <summary>
|
||||
/// A bought Mana Charge (Tiny ... Massive, Titan, Superb; Eternal too): always charged, only ever
|
||||
/// a refill source. ACE gives every one a stored charge and destroys it on use (the Eternal one
|
||||
/// excepted), so it is never drained into.
|
||||
/// </summary>
|
||||
internal static bool IsManaCharge(WorldObject item) =>
|
||||
!string.IsNullOrEmpty(item.Name) && item.Name.Contains("Mana Charge", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
/// <summary>
|
||||
/// A stone that may refill worn gear when charged: what <see cref="IsManaStone"/> takes, but
|
||||
/// with tapping off as well (no rules: the ordinary stones and mana charges; with ManaStone
|
||||
|
|
@ -616,6 +694,9 @@ internal sealed class ManaStoneManager
|
|||
/// </summary>
|
||||
internal bool IsRefillStone(WorldObject item)
|
||||
{
|
||||
// Mana Charges are bought to refill gear: ManaStone rules (which pick the stones to loot and
|
||||
// drain into) don't turn them off.
|
||||
if (IsManaCharge(item)) return true;
|
||||
if (IsManaStone(item)) return true;
|
||||
if (_settings.EnableManaTapping || string.IsNullOrEmpty(item.Name)) return false;
|
||||
foreach (var rule in _settings.ConsumableRules)
|
||||
|
|
@ -696,7 +777,10 @@ internal sealed class ManaStoneManager
|
|||
|
||||
foreach (var item in _objectCache.AllKnownObjects())
|
||||
{
|
||||
if (!IsManaStone(item) || IsEternal(item)) continue;
|
||||
// A Mana Charge is never an empty stone: it is sold charged and every use destroys it
|
||||
// (ACE ManaStoneDestroyChance 1.0). One whose charge wasn't read yet was taken for the
|
||||
// empty stone, and "draining" loot with it poured the whole charge into the loot item.
|
||||
if (!IsManaStone(item) || IsManaCharge(item)) continue;
|
||||
if (!IsOwnedByPlayer(item, playerId)) continue;
|
||||
|
||||
// Stones AC has explicitly told us are charged ("already full of
|
||||
|
|
@ -914,6 +998,22 @@ internal sealed class ManaStoneManager
|
|||
continue;
|
||||
readable++;
|
||||
_manaIdRequestedAt.Remove(item.Id);
|
||||
|
||||
// The read is from the item's last appraisal and the server sends no change while the gear
|
||||
// burns mana: identify it again every 10 minutes (and soon after a refill), one item every
|
||||
// 5 seconds at most, so the read follows the gear.
|
||||
{
|
||||
long nowMs = NowMs;
|
||||
if (!requestedThisPass && _host.HasRequestId
|
||||
&& nowMs - _lastGearRefreshAt >= GearRefreshSpacingMs
|
||||
&& (!_gearReadRefreshedAt.TryGetValue(item.Id, out long readAt) || nowMs - readAt >= GearRefreshMs))
|
||||
{
|
||||
_gearReadRefreshedAt[item.Id] = nowMs;
|
||||
_lastGearRefreshAt = nowMs;
|
||||
_host.RequestId(unchecked((uint)item.Id));
|
||||
requestedThisPass = true;
|
||||
}
|
||||
}
|
||||
int p = (int)(curMana * 100L / maxMana);
|
||||
if (p < lowestPct) { lowestPct = p; lowestName = item.Name ?? ""; }
|
||||
|
||||
|
|
@ -927,6 +1027,10 @@ internal sealed class ManaStoneManager
|
|||
needs = true;
|
||||
}
|
||||
|
||||
// The server said an item is low or out of mana: that beats every read.
|
||||
bool serverLow = _serverSaidGearLowAt != 0;
|
||||
if (serverLow) needs = true;
|
||||
|
||||
// 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;
|
||||
|
|
@ -935,6 +1039,7 @@ internal sealed class ManaStoneManager
|
|||
_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}" +
|
||||
(serverLow ? $" serverSaidLow={(now - _serverSaidGearLowAt) / 1000}s ago" : "") +
|
||||
(now < _refillHoldUntil ? $" hold={(_refillHoldUntil - now) / 1000}s" : ""));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ internal static class ManaReserveTests
|
|||
r.Add("mana reserve: combat holds an attack it can't pay for, and casts once mana is back", CombatHoldsCast);
|
||||
r.Add("mana reserve: a melee fighter's attacks aren't held; Get Mana At off means no reserve", MeleeAndOff);
|
||||
r.Add("mana reserve: the dat's BaseMana is read (when this PC has a portal.dat)", DatBaseMana);
|
||||
r.Add("mana reserve: a buff that would leave mana under the reserve waits for Stamina to Mana (melee too)", BuffWaitsForReserve);
|
||||
}
|
||||
|
||||
private static int Family(string name) => SpellTableStub.GetById(SpellTable.Named(name).First().Id)!.Family;
|
||||
|
|
@ -84,6 +85,28 @@ internal static class ManaReserveTests
|
|||
return ActivityArbiter.Decide(in inputs);
|
||||
}
|
||||
|
||||
// 2026-10-12, Drakkon (melee): a full rebuff spent mana down to 6%, under Stamina to Mana's cost.
|
||||
private static void BuffWaitsForReserve()
|
||||
{
|
||||
var r = new Rig(mana: 300); // in Magic stance: the buff path readies magic before this check
|
||||
int bane = Id("Blade Bane VI"); // level VI: cost 60 here
|
||||
int reserve = r.B.ManaReserve();
|
||||
Check.True(reserve > 0, $"a reserve for a melee character too ({reserve})");
|
||||
|
||||
Check.False(r.B.BuffWaitsForMana(bane, "Blade Bane"), "300/383: the buff goes");
|
||||
Check.Eq(FakeHost.Casts.Count, 0, "nothing cast by the check");
|
||||
|
||||
r.V.CurrentMana = (uint)(reserve + 30); // the buff (60) would leave it under the reserve
|
||||
Check.True(r.B.BuffWaitsForMana(bane, "Blade Bane"), "the buff waits");
|
||||
Check.Eq(FakeHost.Casts.Count, 1, "Stamina to Mana is cast instead");
|
||||
Check.Eq(FamilyOfCast(0), Family("Stamina to Mana Self I"), $"it is Stamina to Mana ({NameOf(FakeHost.Casts[0].SpellId)})");
|
||||
|
||||
// Under even the lowest Stamina to Mana's cost (10) and the buff's: buffing waits, no cast.
|
||||
var low = new Rig(mana: 5);
|
||||
Check.True(low.B.BuffWaitsForMana(bane, "Blade Bane"), "5/383: buffing waits for regen");
|
||||
Check.Eq(FakeHost.Casts.Count, 0, "nothing the server would refuse is sent");
|
||||
}
|
||||
|
||||
private static void ReserveChoosesStaminaToMana()
|
||||
{
|
||||
// Over Get Mana At 20% (77 of 383), but under 1.5x the top Stamina to Mana's cost.
|
||||
|
|
|
|||
|
|
@ -21,6 +21,183 @@ internal static class ManaStoneChoiceTests
|
|||
r.Add("mana stones: a stone just drained refills worn gear though its read still says empty", DrainedStoneRefills);
|
||||
r.Add("mana stones: a stone that gave its mana is not used again; 'fully charged' holds refills", GaveManaNotReused);
|
||||
r.Add("mana stones: tapping off, a stone whose charge can't be read is identified, then used", UnreadableStoneIdentified);
|
||||
r.Add("mana charges: a stack of 5 refills the gear 5 times", StackOfFiveRefillsFiveTimes);
|
||||
r.Add("mana charges: a single stone (stack of 1) that gave its mana is not used again", SingleStoneNotReused);
|
||||
r.Add("mana charges: used up, the next charge of that name is found (retail: each use destroys one)", NextChargeFoundByName);
|
||||
r.Add("mana charges: never taken for the empty stone to drain loot into", ChargeIsNeverEmptyStone);
|
||||
r.Add("mana charges: refill gear even when ManaStone rules name only other stones", ChargesIgnoreStoneRules);
|
||||
r.Add("mana stones: the server's 'low on Mana' refills gear whose read is stale-high", ServerLowRefills);
|
||||
r.Add("mana stones: worn gear is identified again, so a stale-high read follows the gear", GearReadRefreshed);
|
||||
r.Add("mana charges: overnight idle, the gear never runs dry (re-identify)", () => Overnight(identify: true));
|
||||
r.Add("mana charges: overnight idle, the gear never runs dry (server warnings only)", () => Overnight(identify: false));
|
||||
}
|
||||
|
||||
private const uint ChargeA = 0x80400031, ChargeB = 0x80400032, ChargeC = 0x80400033;
|
||||
private const string ManaCharge = "Great Mana Charge";
|
||||
private const string NeedMore = "The Mana Stone gives 1,000 points of mana to the following items: Khanda-handled Mace.\nYou need 2,000 more mana to fully charge your items.";
|
||||
|
||||
// 2026-10-11 report: armor ran dry overnight with Mana Charges in the pack. The prime suspect
|
||||
// (a stack of charges marked empty after one refill) doesn't happen with retail data: ACE Mana
|
||||
// Charges (wcid 4612-4616, 9060, 20179, 27329) don't stack and every use destroys one. But a stack
|
||||
// must still count as a source until it's gone.
|
||||
private static void StackOfFiveRefillsFiveTimes()
|
||||
{
|
||||
using var rig = new Rig(tapping: false, new (uint, int?)[] { (ChargeA, 1000) }, stoneName: ManaCharge);
|
||||
FakeHost.Ints[(ChargeA, StackSizeKey)] = 5;
|
||||
for (int i = 1; i <= 5; i++)
|
||||
{
|
||||
rig.Run(1000);
|
||||
Check.Eq(rig.OnPlayer.Count, i, $"refill {i} from the stack");
|
||||
Check.Eq(rig.OnPlayer[i - 1], ChargeA, "the same stack");
|
||||
rig.Chat(NeedMore);
|
||||
int left = FakeHost.Ints[(ChargeA, StackSizeKey)] - 1;
|
||||
if (left > 0) FakeHost.Ints[(ChargeA, StackSizeKey)] = left;
|
||||
else rig.Destroy(ChargeA);
|
||||
}
|
||||
rig.Run(10_000);
|
||||
Check.Eq(rig.OnPlayer.Count, 5, "the stack is used up: nothing more to use");
|
||||
}
|
||||
|
||||
private static void SingleStoneNotReused()
|
||||
{
|
||||
using var rig = new Rig(tapping: false, new (uint, int?)[] { (StoneA, 3000), (StoneB, 1000) });
|
||||
FakeHost.Ints[(StoneA, StackSizeKey)] = 1;
|
||||
FakeHost.Ints[(StoneB, StackSizeKey)] = 1;
|
||||
rig.Run(1000);
|
||||
Check.Eq(rig.OnPlayer.Count, 1, "the fuller stone first");
|
||||
Check.Eq(rig.OnPlayer[0], StoneA, "stone A");
|
||||
rig.Chat(NeedMore); // A survived its destroy roll; its read still says 3000
|
||||
rig.Run(1000);
|
||||
Check.Eq(rig.OnPlayer.Count, 2, "the gear still needs mana");
|
||||
Check.Eq(rig.OnPlayer[1], StoneB, "stone B, not A again");
|
||||
}
|
||||
|
||||
private static void NextChargeFoundByName()
|
||||
{
|
||||
using var rig = new Rig(tapping: false, new (uint, int?)[] { (ChargeA, 1000), (ChargeB, 1000) }, stoneName: ManaCharge);
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
rig.Run(1000);
|
||||
rig.Chat(NeedMore);
|
||||
rig.Destroy(rig.OnPlayer[^1]); // ACE: Mana Charges always break (destroy chance 1.0)
|
||||
rig.Chat("The Mana Stone is destroyed.");
|
||||
}
|
||||
Check.Eq(rig.OnPlayer.Count, 2, "both charges used");
|
||||
Check.True(rig.OnPlayer[0] != rig.OnPlayer[1], "one each");
|
||||
rig.Run(10_000);
|
||||
Check.Eq(rig.OnPlayer.Count, 2, "none left");
|
||||
rig.AddStone(ChargeC, 1000); // bought another
|
||||
rig.Run(6000);
|
||||
Check.Eq(rig.OnPlayer.Count, 3, "the new charge is found by name");
|
||||
Check.Eq(rig.OnPlayer[2], ChargeC, "charge C");
|
||||
}
|
||||
|
||||
private static void ChargeIsNeverEmptyStone()
|
||||
{
|
||||
using var rig = new Rig(tapping: true, new (uint, int?)[] { (ChargeA, null) }, ringToDrain: true, stoneName: ManaCharge, maceMana: 5000);
|
||||
rig.Run(3000);
|
||||
Check.Eq(rig.OnRing.Count, 0, "an unread Mana Charge is not used to drain the looted ring (it would pour its charge into it)");
|
||||
Check.Eq(rig.M.CountEmptyStones(), 0, "no empty stone slots from charges");
|
||||
Check.False(rig.M.HasEmptyManaStone(), "no empty stone");
|
||||
}
|
||||
|
||||
private static void ChargesIgnoreStoneRules()
|
||||
{
|
||||
FakeHost.Reset();
|
||||
var host = FakeHost.Create();
|
||||
var cache = new WorldObjectCache(host);
|
||||
var s = new LegacyUiSettings { EnableManaTapping = true };
|
||||
s.ConsumableRules.Add(new ConsumableRule { Name = "Greater Mana Stone", Type = "ManaStone" });
|
||||
var m = new ManaStoneManager(host, s, cache);
|
||||
WorldObject W(string name) => new(0x60001000, name, AcObjectClass.ManaStone);
|
||||
Check.True(m.IsRefillStone(W("Massive Mana Charge")), "a Mana Charge refills gear though the rules name only a stone");
|
||||
Check.False(m.IsRefillStone(W("Major Mana Stone")), "an unnamed stone still doesn't");
|
||||
s.EnableManaTapping = false;
|
||||
Check.True(m.IsRefillStone(W("Tiny Mana Charge")), "tapping off too");
|
||||
}
|
||||
|
||||
private static void ServerLowRefills()
|
||||
{
|
||||
// The mace was identified at 90% and reads that forever (the fake never updates it).
|
||||
using var rig = new Rig(tapping: false, new (uint, int?)[] { (ChargeA, 1000), (ChargeB, 1000) }, stoneName: ManaCharge, maceMana: 4500);
|
||||
rig.Run(30_000);
|
||||
Check.Eq(rig.OnPlayer.Count, 0, "the read says 90%: nothing to do");
|
||||
rig.Chat("Your Khanda-handled Mace is low on Mana.");
|
||||
rig.Run(1000);
|
||||
Check.Eq(rig.OnPlayer.Count, 1, "the server's warning wins over the read");
|
||||
rig.Chat(NeedMore);
|
||||
rig.Destroy(rig.OnPlayer[0]);
|
||||
rig.Run(1000);
|
||||
Check.Eq(rig.OnPlayer.Count, 2, "still short of full: the next charge");
|
||||
rig.Chat("The Mana Stone gives 1,000 points of mana to the following items: Khanda-handled Mace.");
|
||||
rig.Chat("Your items are fully charged."); // as a line of its own
|
||||
rig.Run(5 * 60_000);
|
||||
Check.Eq(rig.OnPlayer.Count, 2, "full: back to the reads (90%)");
|
||||
}
|
||||
|
||||
private static void GearReadRefreshed()
|
||||
{
|
||||
using var rig = new Rig(tapping: false, new (uint, int?)[] { (ChargeA, 1000) }, stoneName: ManaCharge, maceMana: 4500);
|
||||
rig.Run(2000);
|
||||
int first = FakeHost.IdRequests.Count(i => i == Mace);
|
||||
Check.True(first >= 1, "the worn mace is identified");
|
||||
rig.Run(5 * 60_000);
|
||||
Check.Eq(FakeHost.IdRequests.Count(i => i == Mace), first, "not again within 10 minutes");
|
||||
rig.Run(6 * 60_000);
|
||||
Check.Eq(FakeHost.IdRequests.Count(i => i == Mace), first + 1, "again after 10 minutes");
|
||||
FakeHost.Ints[(Mace, CurManaKey)] = 1000; // that appraisal shows it at 20%
|
||||
rig.Run(1000);
|
||||
Check.Eq(rig.OnPlayer.Count, 1, "the fresh read refills it");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Twelve hours with the macro running and nothing else to do. The mace burns 1 mana every 5 s
|
||||
/// (8,640 over the night, it starts at 4,500 of 5,000); its read changes only when it is
|
||||
/// identified, or never (identify: false). The server side follows ACE: "low on Mana" two
|
||||
/// minutes before empty, a charge gives what the gear needs and is destroyed.
|
||||
/// </summary>
|
||||
private static void Overnight(bool identify)
|
||||
{
|
||||
var charges = new (uint, int?)[10];
|
||||
for (int i = 0; i < charges.Length; i++) charges[i] = (0x80400100u + (uint)i, 1000);
|
||||
using var rig = new Rig(tapping: false, charges, stoneName: ManaCharge, maceMana: 4500, identify: identify);
|
||||
const int max = 5000;
|
||||
int real = 4500, lowest = real, idsSeen = 0;
|
||||
double acc = 0;
|
||||
bool warned = false;
|
||||
const long step = 500;
|
||||
for (long t = 0; t < 12L * 3600 * 1000; t += step)
|
||||
{
|
||||
rig.Now += step;
|
||||
acc += 0.2 * step / 1000.0;
|
||||
if (acc >= 1) { int burn = Math.Min((int)acc, real); real -= burn; acc -= (int)acc; }
|
||||
lowest = Math.Min(lowest, real);
|
||||
if (real * 5 <= 120) { if (!warned) { warned = true; rig.Chat(real > 0 ? "Your Khanda-handled Mace is low on Mana." : "Your Khanda-handled Mace is out of Mana."); } }
|
||||
else warned = false;
|
||||
|
||||
int usesBefore = FakeHost.UsesOn.Count;
|
||||
rig.M.OnHeartbeat(0);
|
||||
|
||||
for (; idsSeen < FakeHost.IdRequests.Count; idsSeen++)
|
||||
if (FakeHost.IdRequests[idsSeen] == Mace) FakeHost.Ints[(Mace, CurManaKey)] = real; // the appraisal lands
|
||||
|
||||
for (int u = usesBefore; u < FakeHost.UsesOn.Count; u++)
|
||||
{
|
||||
var (src, target) = FakeHost.UsesOn[u];
|
||||
if (target != Player) continue;
|
||||
int charge = FakeHost.Ints.TryGetValue((src, CurManaKey), out int c) ? c : 0;
|
||||
int give = Math.Min(max - real, charge);
|
||||
if (give <= 0) { rig.Chat("You have no items equipped that need mana."); continue; }
|
||||
real += give;
|
||||
rig.Chat($"The Mana Stone gives {give:N0} points of mana to the following items: Khanda-handled Mace.\n" +
|
||||
(real >= max ? "Your items are fully charged." : $"You need {max - real:N0} more mana to fully charge your items."));
|
||||
rig.Destroy(src);
|
||||
rig.Chat("The Mana Stone is destroyed.");
|
||||
}
|
||||
}
|
||||
Check.True(lowest > 0, $"the mace never ran dry (lowest {lowest})");
|
||||
Check.True(rig.OnPlayer.Count >= 4, $"charges were used ({rig.OnPlayer.Count})");
|
||||
Check.True(rig.OnPlayer.Count <= 10, "no more uses than charges");
|
||||
}
|
||||
|
||||
// ── Refill rig (2026-10-11) ───────────────────────────────────────────
|
||||
|
|
@ -33,24 +210,29 @@ internal static class ManaStoneChoiceTests
|
|||
private const uint Player = 0x50000E01;
|
||||
private const uint StoneA = 0x80400001, StoneB = 0x80400002, StoneC = 0x80400003;
|
||||
private const uint Mace = 0x80400010, Ring = 0x80400020;
|
||||
private const uint CurManaKey = 107, MaxManaKey = 108, WieldedSlotKey = 10;
|
||||
private const uint CurManaKey = 107, MaxManaKey = 108, WieldedSlotKey = 10, StackSizeKey = 12;
|
||||
|
||||
private sealed class Rig : IDisposable
|
||||
{
|
||||
public long Now = 1_000_000;
|
||||
public readonly LegacyUiSettings S;
|
||||
public readonly ManaStoneManager M;
|
||||
public readonly WorldObjectCache C;
|
||||
private readonly string _stoneName;
|
||||
|
||||
/// <param name="stones">Stone id and its charge read (null = can't be read).</param>
|
||||
public Rig(bool tapping, (uint Id, int? Mana)[] stones, bool ringToDrain = false)
|
||||
/// <param name="identify">The engine can identify objects (RequestId).</param>
|
||||
public Rig(bool tapping, (uint Id, int? Mana)[] stones, bool ringToDrain = false,
|
||||
string stoneName = "Moderate Mana Stone", int maceMana = 0, bool identify = true)
|
||||
{
|
||||
FakeHost.Reset();
|
||||
FakeHost.UseOnCalls = true;
|
||||
FakeHost.WeaponCalls = true; // RequestId, HasAppraisalData
|
||||
FakeHost.WeaponCalls = identify; // RequestId, HasAppraisalData
|
||||
FakeHost.Names[Player] = "Stone Tester";
|
||||
_stoneName = stoneName;
|
||||
foreach (var (id, mana) in stones)
|
||||
{
|
||||
FakeHost.Names[id] = "Moderate Mana Stone";
|
||||
FakeHost.Names[id] = stoneName;
|
||||
FakeHost.Containers[id] = Player;
|
||||
SetMana(id, mana);
|
||||
}
|
||||
|
|
@ -58,7 +240,7 @@ internal static class ManaStoneChoiceTests
|
|||
FakeHost.Wielders[Mace] = Player;
|
||||
FakeHost.Ints[(Mace, WieldedSlotKey)] = 0x100000;
|
||||
FakeHost.Ints[(Mace, MaxManaKey)] = 5000;
|
||||
FakeHost.Ints[(Mace, CurManaKey)] = 0; // and it keeps reading 0: worn-item mana is an appraisal too
|
||||
FakeHost.Ints[(Mace, CurManaKey)] = maceMana; // and it keeps reading that: worn-item mana is an appraisal too
|
||||
var ids = new List<uint>();
|
||||
foreach (var st in stones) ids.Add(st.Id);
|
||||
ids.Add(Mace);
|
||||
|
|
@ -72,11 +254,11 @@ internal static class ManaStoneChoiceTests
|
|||
}
|
||||
|
||||
var host = FakeHost.Create(Player);
|
||||
var cache = FakeHost.MakeCache(host, Player, ids);
|
||||
C = FakeHost.MakeCache(host, Player, ids);
|
||||
S = new LegacyUiSettings { EnableManaTapping = tapping, ManaTapMinMana = 100 };
|
||||
S.IsMacroRunning = true;
|
||||
ManaStoneManager.Clock = () => Now;
|
||||
M = new ManaStoneManager(host, S, cache);
|
||||
M = new ManaStoneManager(host, S, C);
|
||||
if (ringToDrain) M.MarkLootedForTap(unchecked((int)Ring));
|
||||
}
|
||||
|
||||
|
|
@ -97,6 +279,26 @@ internal static class ManaStoneChoiceTests
|
|||
|
||||
public void Chat(string line) => M.OnChatWindowText(line);
|
||||
|
||||
/// <summary>A stone or charge arrives in the pack (bought, looted).</summary>
|
||||
public void AddStone(uint id, int? mana, int stack = 0)
|
||||
{
|
||||
FakeHost.Names[id] = _stoneName;
|
||||
FakeHost.Containers[id] = Player;
|
||||
SetMana(id, mana);
|
||||
if (stack > 0) FakeHost.Ints[(id, StackSizeKey)] = stack;
|
||||
_ = C[unchecked((int)id)];
|
||||
}
|
||||
|
||||
/// <summary>The server destroyed it (used up): it leaves the client and the cache.</summary>
|
||||
public void Destroy(uint id)
|
||||
{
|
||||
FakeHost.Names.Remove(id);
|
||||
FakeHost.Containers.Remove(id);
|
||||
FakeHost.Ints.Remove((id, CurManaKey));
|
||||
FakeHost.Ints.Remove((id, StackSizeKey));
|
||||
C.OnDeleteObject(id);
|
||||
}
|
||||
|
||||
public List<uint> OnPlayer => FakeHost.UsesOn.Where(u => u.Target == Player).Select(u => u.Source).ToList();
|
||||
public List<uint> OnRing => FakeHost.UsesOn.Where(u => u.Target == Ring).Select(u => u.Source).ToList();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue