Recast a buff at a higher level once one becomes castable
The buff level comes from the live buffed skill (SpellManager.ComputeTier over
BuffMinSkillLevelTier1..8) and the spellbook. Inside a force or batch run a family
cast earlier in the run read active, so Creature Enchantment Mastery, Focus and
Willpower cast at the level the skill allowed before they landed stayed there for
the whole run; between passes a failed upgrade could arm the landed-tier cap and
lose the upgrade until the plugin reloaded.
- In a run, a family already cast reads active only while the level castable now is
not strictly higher than the level the run CONFIRMED for it; a higher level is cast
again right away (after the priority buffs). Never lower.
- The attempted tier kept since load is written on confirmation, so a fizzled or refused
upgrade is cast again at the next opportunity, in the run or on the next pass.
- No try cap, and no rest after a fizzle, a client refusal or a no-show; a server mana or
component refusal still rests the family as it does for any buff. Casting thresholds
are consistent, so the bot keeps trying until it lands. Pacing stays: a client-refused cast waits
SpellCastIntervalMs, and a fizzled upgrade is sent once per server answer, never
while one is unanswered.
- While the pending cast is an upgrade, the registry counts the family as landed only
when its entry moved (a later expiry, or the pending level or higher). A late "You
cast" line for a lower level, or one the cast tracker credits to an earlier send,
does not confirm the pending upgrade.
- An upgrade's no-show is never a silent-no-show strike, a 30 min park or a
blacklist entry, so the lower level it was cast over is still recast when it runs low.
- One "[Buff] upgrade: <buff> level a -> b" line per cast that replaces an active
lower level (BuffUpgrades counts them), at the same effective level IsBuffActive
uses: refreshing an Incantation that lands a level low is not an upgrade.
- A scroll read that teaches a spell ("The scroll is destroyed.") makes the next buff
check read the spellbook at once.
- Integrates with the mana reserve hold (BuffWaitsForMana): the hold runs first, on
the upgrade's own spell id, so an upgrade that would leave mana under the reserve
is not sent, counted or logged; Stamina to Mana goes and the upgrade follows.
Tests: in-run order, next-pass upgrade with equal-level and lower-skill controls,
the scroll case, fizzle and refusal retries (run, next pass, heartbeat, client
refusal pacing), registry no-shows, late lines, no park on no-shows (self and item
spells), and an upgrade held by the mana reserve (fails with the hold disabled).
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
36565dca33
commit
88502d4efa
3 changed files with 879 additions and 51 deletions
|
|
@ -77,6 +77,23 @@ internal static class BuffTests
|
|||
r.Add("buff timers: tier-8 weapon auras last 90 minutes", TierEightAuras); // was a known failure; fixed by 9a317a8
|
||||
r.Add("buff chat: another player's speech can't record a buff timer", SpeechIsNotACast); // was a known failure; fixed by 0e384d2
|
||||
r.Add("buff school: Armor Tinkering Expertise is a Creature Enchantment spell", ArmorTinkeringSchool); // was a known failure
|
||||
r.Add("buff upgrade: in a force run, the priority buffs go first, then the families cast before the skill rose are recast a level higher", UpgradeInRun);
|
||||
r.Add("buff upgrade: the next pass recasts every buff a level higher once the skill allows it; equal level or a lower skill casts nothing", UpgradeNextPass);
|
||||
r.Add("buff upgrade: a higher level learned from a scroll is cast at once (the spellbook is read again)", UpgradeAfterScroll);
|
||||
r.Add("buff upgrade: an in-run upgrade that fizzles is cast again; one that always fizzles keeps being cast", UpgradeFizzleRetried);
|
||||
r.Add("buff upgrade: an upgrade failing on a next pass is cast again every time, with no rest, until it lands", UpgradeFizzleNextPass);
|
||||
r.Add("buff upgrade: an Incantation landing a level low is not logged or counted as an upgrade when refreshed", IncantationRefreshNotUpgrade);
|
||||
r.Add("buff upgrade: 'too busy' refusals of an upgrade: it is sent again and lands", UpgradeBusyNotATry);
|
||||
r.Add("buff upgrade: a late line for the lower level does not confirm the pending upgrade", UpgradeLateLowerLine);
|
||||
r.Add("buff upgrade: the upgrade line names the level the upgrade is counted at (an Incantation's capped level)", UpgradeLineEffectiveLevel);
|
||||
r.Add("buff upgrade: through the heartbeat, an always-fizzling upgrade is sent once per answered beat, never unanswered", UpgradeCapViaHeartbeat);
|
||||
r.Add("buff upgrade: a client-refused upgrade is retried once per SpellCastIntervalMs, not every heartbeat", UpgradeClientRefusalPaced);
|
||||
r.Add("buff upgrade: an upgrade the registry never shows (still the lower level) is a no-show, not a landing", UpgradeNoShowIsATry);
|
||||
r.Add("buff upgrade: a late line for the level below a pending Incantation leaves it pending", UpgradeIncantationLateLine);
|
||||
r.Add("buff upgrade: a late line the cast tracker credits to an earlier send does not confirm the pending cast", UpgradeLateLineFromEarlierSend);
|
||||
r.Add("buff upgrade: two upgrade no-shows do not park the family; its lower level running low is recast", UpgradeNoShowsDoNotPark);
|
||||
r.Add("buff upgrade: two item spell upgrades with no chat do not park the family; its lower level running low is recast", UpgradeArmorNoChatDoesNotPark);
|
||||
r.Add("buff upgrade: an upgrade that would leave mana under the reserve waits for Stamina to Mana, then goes", UpgradeWaitsForManaReserve);
|
||||
}
|
||||
|
||||
// ── Rig ───────────────────────────────────────────────────────────────────
|
||||
|
|
@ -135,6 +152,8 @@ internal static class BuffTests
|
|||
public readonly BuffManager B;
|
||||
public readonly SpellManager Sm;
|
||||
public readonly RynthCoreHost Host;
|
||||
/// <summary>The vitals BuffManager reads (all zero unless a test sets them).</summary>
|
||||
public readonly PlayerVitalsCache V = new();
|
||||
|
||||
/// <summary>Call FakeHost.Reset(), set skills and the spellbook first.</summary>
|
||||
public BuffRig()
|
||||
|
|
@ -143,7 +162,7 @@ internal static class BuffTests
|
|||
Host = host;
|
||||
var skills = Skills(host);
|
||||
Sm = NewSpells(host, S, skills);
|
||||
B = new BuffManager(host, S, Sm, new PlayerVitalsCache());
|
||||
B = new BuffManager(host, S, Sm, V);
|
||||
B.SetCharacterSkills(skills);
|
||||
FakeHost.ServerTime = 100_000;
|
||||
}
|
||||
|
|
@ -845,6 +864,678 @@ internal static class BuffTests
|
|||
rig.B.OnChatWindowText($"You cast Aura of {aura} Self VI on Rune Sword", 7);
|
||||
}
|
||||
|
||||
// -- Level upgrades: when a higher level of a buff becomes castable (Creature Enchantment Mastery,
|
||||
// Focus and Willpower raise the skill), the buff is recast at it -----------------------------
|
||||
|
||||
/// <summary>Every spell known; Creature, Life and Item Magic at <paramref name="buffed"/>; Magic stance; no items listed.</summary>
|
||||
private static BuffRig UpgradeRig(int buffed)
|
||||
{
|
||||
FakeHost.Reset();
|
||||
foreach (var row in SpellTable.Rows) FakeHost.Spellbook.Add((uint)row.Id);
|
||||
FakeHost.Skills[(Player, STypeCreature)] = (buffed, 2);
|
||||
FakeHost.Skills[(Player, STypeLife)] = (buffed, 2);
|
||||
FakeHost.Skills[(Player, STypeItem)] = (buffed, 2);
|
||||
FakeHost.WeaponCalls = true;
|
||||
FakeHost.CombatModeValue = CombatMode.Magic;
|
||||
var rig = new BuffRig();
|
||||
rig.B.SetWorldObjectCache(FakeHost.MakeCache(rig.Host, Player, Array.Empty<uint>()));
|
||||
return rig;
|
||||
}
|
||||
|
||||
private static int LevelOf(int id) => SpellTableStub.GetById(id) is { } s ? BuffManager.GetSpellLevel(s) : 0;
|
||||
private static int FamilyOf(int id) => SpellTableStub.GetById(id)?.Family ?? 0;
|
||||
private static int FamilyOfBuff(string anyTierName) => FamilyOf(Id(anyTierName));
|
||||
|
||||
/// <summary>Runs the buff step to the end (confirming each cast by chat), calling
|
||||
/// <paramref name="afterCast"/> after each cast with the casts so far.</summary>
|
||||
private static List<int> RunBuffs(BuffRig rig, Action<List<int>>? afterCast = null, int max = 200)
|
||||
{
|
||||
var ids = new List<int>();
|
||||
for (int i = 0; i < max; i++)
|
||||
{
|
||||
int before = FakeHost.Casts.Count;
|
||||
CastSelfBuffs.Invoke(rig.B, null);
|
||||
if (FakeHost.Casts.Count == before) break;
|
||||
int id = FakeHost.Casts.Last().SpellId;
|
||||
ids.Add(id);
|
||||
string name = NameOf(id);
|
||||
rig.B.OnChatWindowText($"You cast {name} on {(BuffManager.IsItemEnchantment(name) ? "Rune Robe" : "yourself")}", 7);
|
||||
afterCast?.Invoke(ids);
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
private static string Show(IEnumerable<int> ids) => string.Join(", ", ids.Select(NameOf));
|
||||
|
||||
/// <summary>The run's end as OnHeartbeat does it when CheckAndCastSelfBuffs has nothing left
|
||||
/// (flag off first, the audit, then the family set cleared).</summary>
|
||||
private static void EndRun(BuffRig rig)
|
||||
{
|
||||
const BindingFlags F = BindingFlags.NonPublic | BindingFlags.Instance;
|
||||
if (!(bool)typeof(BuffManager).GetField("_isForceRebuffing", F)!.GetValue(rig.B)!) return;
|
||||
typeof(BuffManager).GetField("_isForceRebuffing", F)!.SetValue(rig.B, false);
|
||||
typeof(BuffManager).GetField("_isAutoBatchRebuff", F)!.SetValue(rig.B, false);
|
||||
typeof(BuffManager).GetMethod("AuditBatchSatisfied", F)!.Invoke(rig.B, null);
|
||||
typeof(BuffManager).GetMethod("ClearRunFamilies", F)!.Invoke(rig.B, null);
|
||||
}
|
||||
|
||||
/// <summary>A fake BuffManager clock (the cast tracker's send and give-up times).</summary>
|
||||
private static Action<double> FakeClock(BuffRig rig)
|
||||
{
|
||||
DateTime t0 = new DateTime(2026, 10, 10, 12, 0, 0), now = t0;
|
||||
rig.B.Clock = () => now;
|
||||
return s => now = t0.AddSeconds(s);
|
||||
}
|
||||
|
||||
/// <summary>CEM sends of a cast list, as levels ("6,7,7").</summary>
|
||||
private static string CemLevels(IEnumerable<int> sent) =>
|
||||
string.Join(",", sent.Where(id => FamilyOf(id) == FamilyOfBuff("Creature Enchantment Mastery Self VI")).Select(LevelOf));
|
||||
|
||||
private static void UpgradeInRun()
|
||||
{
|
||||
int cem = FamilyOfBuff("Creature Enchantment Mastery Self VI"), focus = FamilyOfBuff("Focus Self VI"), will = FamilyOfBuff("Willpower Self VI");
|
||||
var rig = UpgradeRig(300); // tier 6
|
||||
rig.Live(("Strength Self I", 3000)); // a registry read, nothing of ours on
|
||||
rig.B.ForceFullRebuff();
|
||||
// Creature Enchantment Mastery, Focus and Willpower land and lift Creature Magic to tier 7.
|
||||
var cast = RunBuffs(rig, ids => { if (ids.Count == 3) FakeHost.Skills[(Player, STypeCreature)] = (340, 2); });
|
||||
Check.True(cast.Count > 7, "the run casts the suite: " + Show(cast));
|
||||
Check.Eq(string.Join(",", cast.Take(3).Select(FamilyOf)), $"{cem},{focus},{will}", "the priority buffs first: " + Show(cast.Take(3)));
|
||||
Check.True(cast.Take(3).All(id => LevelOf(id) == 6), "at the level the skill allowed then (6)");
|
||||
Check.Eq(string.Join(",", cast.Skip(3).Take(3).Select(FamilyOf)), $"{cem},{focus},{will}", "then the same three again: " + Show(cast.Skip(3).Take(3)));
|
||||
Check.True(cast.Skip(3).Take(3).All(id => LevelOf(id) == 7), "a level higher (7)");
|
||||
Check.Eq(rig.B.BuffUpgrades, 3, "three upgrades");
|
||||
Check.Eq(FakeHost.Logs.Count(l => l.Contains("[Buff] upgrade:")), 3, "one line each");
|
||||
Check.True(FakeHost.Logs.Any(l => l.Contains("[Buff] upgrade: Creature Enchantment Mastery level 6 -> 7")), "the line names the levels");
|
||||
// After the head: every cast is at its school's level now (Creature 7; Life and Item still 6).
|
||||
var under = cast.Skip(6).Where(id => LevelOf(id) < (BuffManager.SkillForBuff(NameOf(id)) == AcSkillType.CreatureEnchantment ? 7 : 6)).ToList();
|
||||
Check.Eq(under.Count, 0, "nothing after the head under its school's level: " + Show(under));
|
||||
Check.Eq(cast.Distinct().Count(), cast.Count, "nothing is cast twice at the same level (no churn)");
|
||||
|
||||
// The skill falls back (a buff ran out) during the run: nothing is cast a level lower.
|
||||
var down = UpgradeRig(300);
|
||||
down.Live(("Strength Self I", 3000));
|
||||
down.B.ForceFullRebuff();
|
||||
var dcast = RunBuffs(down, ids => { if (ids.Count == 3) FakeHost.Skills[(Player, STypeCreature)] = (250, 2); });
|
||||
Check.False(dcast.Skip(3).Any(id => FamilyOf(id) == cem || FamilyOf(id) == focus || FamilyOf(id) == will), "no downgrade of the head: " + Show(dcast));
|
||||
Check.Eq(down.B.BuffUpgrades, 0, "no upgrades");
|
||||
}
|
||||
|
||||
private static void UpgradeNextPass()
|
||||
{
|
||||
var rig = UpgradeRig(300);
|
||||
rig.Live(("Strength Self I", 3000));
|
||||
rig.B.ForceFullRebuff();
|
||||
var first = RunBuffs(rig);
|
||||
EndRun(rig);
|
||||
Check.True(first.Count > 7 && first.All(id => LevelOf(id) <= 6), "the run at tier 6: " + Show(first));
|
||||
Check.Eq(RunBuffs(rig).Count, 0, "the same skill: nothing more (equal level is no upgrade)");
|
||||
EndRun(rig);
|
||||
|
||||
FakeHost.Skills[(Player, STypeCreature)] = (340, 2); // Creature Magic now allows 7
|
||||
var next = RunBuffs(rig);
|
||||
EndRun(rig);
|
||||
Check.True(next.Count > 0, "the next pass recasts");
|
||||
Check.True(next.All(id => LevelOf(id) == 7), "every recast is a level higher: " + Show(next));
|
||||
Check.True(next.Select(FamilyOf).Contains(FamilyOfBuff("Creature Enchantment Mastery Self VI")) && next.Select(FamilyOf).Contains(FamilyOfBuff("Focus Self VI"))
|
||||
&& next.Select(FamilyOf).Contains(FamilyOfBuff("Willpower Self VI")), "including Creature Enchantment Mastery, Focus and Willpower");
|
||||
Check.Eq(rig.B.BuffUpgrades, next.Count, "each one an upgrade");
|
||||
Check.Eq(FakeHost.Logs.Count(l => l.Contains("[Buff] upgrade:")), next.Count, "one line each");
|
||||
Check.Eq(RunBuffs(rig).Count, 0, "then nothing (no churn)");
|
||||
EndRun(rig);
|
||||
|
||||
// One buff runs low: recast at the same level, which is not an upgrade.
|
||||
var onNow = first.Concat(next).GroupBy(FamilyOf).Select(g => g.Last()).Where(id => !BuffManager.IsItemEnchantment(NameOf(id))).ToList();
|
||||
int low = next.First(id => FamilyOf(id) == FamilyOfBuff("Focus Self VI"));
|
||||
rig.Live(onNow.Select(id => (NameOf(id), id == low ? 200.0 : 3000.0)).ToArray());
|
||||
int upgradesBefore = rig.B.BuffUpgrades;
|
||||
var refresh = RunBuffs(rig);
|
||||
Check.True(refresh.Contains(low), "the low one is recast: " + Show(refresh) + " (last skip: " + rig.B.LastBuffSkipReason + ")");
|
||||
Check.Eq(rig.B.BuffUpgrades, upgradesBefore, "at the same level: not an upgrade, no line");
|
||||
EndRun(rig);
|
||||
|
||||
FakeHost.Skills[(Player, STypeCreature)] = (250, 2); // the skill drops (tier 5)
|
||||
Check.Eq(RunBuffs(rig).Count, 0, "a lower skill: nothing is recast lower");
|
||||
}
|
||||
|
||||
// The upgrade path sits after the mana reserve hold (BuffWaitsForMana): a higher level that
|
||||
// would leave mana under the reserve is not sent, counted or logged as an upgrade; Stamina to
|
||||
// Mana goes instead, and the upgrade goes once mana is back.
|
||||
private static void UpgradeWaitsForManaReserve()
|
||||
{
|
||||
var rig = UpgradeRig(300); // tier 6
|
||||
BuffManager.ManaCostOverride = id => LevelOf(id) * 10; // level x 10 (FakeHost.Reset sets 0)
|
||||
rig.S.GetManaAt = 20; rig.S.TopOffMana = 20;
|
||||
rig.V.MaxHealth = 400; rig.V.CurrentHealth = 400;
|
||||
rig.V.MaxStamina = 383; rig.V.CurrentStamina = 289;
|
||||
rig.V.MaxMana = 383; rig.V.CurrentMana = 300;
|
||||
rig.Live(("Strength Self I", 3000));
|
||||
rig.B.ForceFullRebuff();
|
||||
var first = RunBuffs(rig);
|
||||
EndRun(rig);
|
||||
Check.True(first.Count > 7 && first.All(id => LevelOf(id) <= 6), "300/383: the run at tier 6: " + Show(first));
|
||||
|
||||
FakeHost.Skills[(Player, STypeCreature)] = (340, 2); // Creature Magic now allows 7
|
||||
int reserve = rig.B.ManaReserve();
|
||||
Check.True(reserve > 0, $"a reserve ({reserve})");
|
||||
rig.V.CurrentMana = (uint)(reserve + 30); // a level VII (70) would leave it under the reserve
|
||||
int upgradesBefore = rig.B.BuffUpgrades, castsBefore = FakeHost.Casts.Count;
|
||||
CastSelfBuffs.Invoke(rig.B, null);
|
||||
Check.Eq(FakeHost.Casts.Count, castsBefore + 1, "one cast");
|
||||
int held = FakeHost.Casts.Last().SpellId;
|
||||
Check.Eq(FamilyOf(held), FamilyOfBuff("Stamina to Mana Self I"), $"it is Stamina to Mana, not the upgrade ({NameOf(held)})");
|
||||
Check.Eq(rig.B.BuffUpgrades, upgradesBefore, "the held upgrade is not counted");
|
||||
Check.Eq(FakeHost.Logs.Count(l => l.Contains("[Buff] upgrade:")), 0, "and not logged");
|
||||
|
||||
rig.B.OnChatWindowText($"You cast {NameOf(held)} on yourself", 7);
|
||||
rig.V.CurrentMana = 300;
|
||||
var next = RunBuffs(rig);
|
||||
EndRun(rig);
|
||||
Check.True(next.Count > 0 && next.All(id => LevelOf(id) == 7), "mana back: the upgrades go at 7: " + Show(next));
|
||||
Check.Eq(rig.B.BuffUpgrades, upgradesBefore + next.Count, "each one an upgrade");
|
||||
}
|
||||
|
||||
private static void UpgradeAfterScroll()
|
||||
{
|
||||
FakeHost.Reset();
|
||||
int cemFam = FamilyOfBuff("Creature Enchantment Mastery Self VI");
|
||||
int seven = SpellTable.Rows.Select(r => r.Id).First(id => FamilyOf(id) == cemFam && LevelOf(id) == 7 && NameOf(id).IndexOf("Other", StringComparison.Ordinal) < 0);
|
||||
Know("Creature Enchantment Mastery Self VI");
|
||||
FakeHost.Skills[(Player, STypeCreature)] = (340, 2); // tier 7, but only VI is known
|
||||
FakeHost.WeaponCalls = true;
|
||||
FakeHost.CombatModeValue = CombatMode.Magic;
|
||||
var rig = new BuffRig();
|
||||
rig.B.SetWorldObjectCache(FakeHost.MakeCache(rig.Host, Player, Array.Empty<uint>()));
|
||||
rig.Live(("Strength Self I", 3000));
|
||||
var first = RunBuffs(rig);
|
||||
Check.Eq(Show(first), "Creature Enchantment Mastery Self VI", "only VI is known: VI");
|
||||
EndRun(rig);
|
||||
FakeHost.Spellbook.Add((uint)seven); // the scroll's spell is now in the spellbook
|
||||
Check.Eq(RunBuffs(rig).Count, 0, "before the learn line: the spellbook is not read again yet (3 s throttle)");
|
||||
rig.B.OnChatWindowText("The scroll is destroyed.", 0);
|
||||
var after = RunBuffs(rig);
|
||||
Check.Eq(Show(after), NameOf(seven), "the learned level is cast at once");
|
||||
Check.Eq(rig.B.BuffUpgrades, 1, "an upgrade");
|
||||
}
|
||||
|
||||
/// <summary>A force run where the cast numbered (1-based) in <paramref name="fizzle"/> fizzles;
|
||||
/// Creature Magic rises to tier 7 after the third cast. Returns every cast sent and the confirmed ones.</summary>
|
||||
private static (List<int> Sent, List<int> Confirmed) RunWithFizzles(BuffRig rig, Func<int, int, bool> fizzle, int max = 300)
|
||||
{
|
||||
var sent = new List<int>(); var confirmed = new List<int>();
|
||||
for (int i = 0; i < max; i++)
|
||||
{
|
||||
int before = FakeHost.Casts.Count;
|
||||
CastSelfBuffs.Invoke(rig.B, null);
|
||||
if (FakeHost.Casts.Count == before) break;
|
||||
int id = FakeHost.Casts.Last().SpellId;
|
||||
sent.Add(id);
|
||||
if (fizzle(sent.Count, id)) { rig.B.OnChatWindowText("Your spell fizzled.", 7); continue; }
|
||||
confirmed.Add(id);
|
||||
string name = NameOf(id);
|
||||
rig.B.OnChatWindowText($"You cast {name} on {(BuffManager.IsItemEnchantment(name) ? "Rune Robe" : "yourself")}", 7);
|
||||
if (sent.Count == 3) FakeHost.Skills[(Player, STypeCreature)] = (340, 2);
|
||||
}
|
||||
return (sent, confirmed);
|
||||
}
|
||||
|
||||
// The upgrade's issue was taken as done, so a fizzled upgrade was never retried.
|
||||
private static void UpgradeFizzleRetried()
|
||||
{
|
||||
int cem = FamilyOfBuff("Creature Enchantment Mastery Self VI");
|
||||
var rig = UpgradeRig(300);
|
||||
rig.Live(("Strength Self I", 3000));
|
||||
rig.B.ForceFullRebuff();
|
||||
var (sent, _) = RunWithFizzles(rig, (n, _) => n == 4); // the first upgrade (CEM 7) fizzles
|
||||
var cemLevels = sent.Where(id => FamilyOf(id) == cem).Select(LevelOf).ToList();
|
||||
Check.Eq(string.Join(",", cemLevels), "6,7,7", "CEM 6, CEM 7 (fizzled), CEM 7 again in the same run: " + Show(sent.Take(8)));
|
||||
|
||||
// CEM 7 always fizzles: it is cast again every time, with no limit and no rest, and
|
||||
// nothing else gets ahead of it (it heads the list).
|
||||
var all = UpgradeRig(300);
|
||||
all.Live(("Strength Self I", 3000));
|
||||
all.B.ForceFullRebuff();
|
||||
var (sent2, _) = RunWithFizzles(all, (n, id) => n > 3 && FamilyOf(id) == cem && LevelOf(id) == 7, 40);
|
||||
Check.Eq(sent2.Count, 40, "the run goes on");
|
||||
Check.Eq(sent2.Skip(3).Count(id => FamilyOf(id) == cem && LevelOf(id) == 7), 37, "every send after the first three is CEM 7 again: " + Show(sent2.Take(8)));
|
||||
}
|
||||
|
||||
// A failed upgrade on a next pass is cast again at once each time, at any time (no rest), and
|
||||
// stops once it lands.
|
||||
private static void UpgradeFizzleNextPass()
|
||||
{
|
||||
int cem = FamilyOfBuff("Creature Enchantment Mastery Self VI");
|
||||
var rig = UpgradeRig(300);
|
||||
var at = FakeClock(rig);
|
||||
at(0);
|
||||
rig.Live(("Strength Self I", 3000));
|
||||
rig.B.ForceFullRebuff();
|
||||
RunBuffs(rig);
|
||||
EndRun(rig);
|
||||
FakeHost.Skills[(Player, STypeCreature)] = (340, 2); // Creature Magic now allows 7
|
||||
bool FizzleCem7(int n, int id) => FamilyOf(id) == cem && LevelOf(id) == 7;
|
||||
var (sent, _) = RunWithFizzles(rig, FizzleCem7, 20);
|
||||
Check.Eq(sent.Count(id => FamilyOf(id) == cem && LevelOf(id) == 7), 20, "CEM 7 sent again after every fizzle: " + Show(sent.Take(6)));
|
||||
Check.False(FakeHost.Logs.Any(l => l.Contains("no upgrade of it for")), "no rest");
|
||||
at(30);
|
||||
var (later, _) = RunWithFizzles(rig, FizzleCem7, 5);
|
||||
Check.Eq(CemLevels(later), "7,7,7,7,7", "30 s later: still tried every time");
|
||||
at(31);
|
||||
var (landed, _) = RunWithFizzles(rig, (n, id) => false, 60);
|
||||
EndRun(rig);
|
||||
Check.Eq(landed.Count(id => FamilyOf(id) == cem), 1, "it lands, once");
|
||||
Check.Eq(RunWithFizzles(rig, (n, id) => false, 60).Sent.Count, 0, "then nothing (no churn)");
|
||||
}
|
||||
|
||||
// "You're too busy!" for an upgrade is not a failed try.
|
||||
private static void UpgradeBusyNotATry()
|
||||
{
|
||||
int cem = FamilyOfBuff("Creature Enchantment Mastery Self VI");
|
||||
var rig = UpgradeRig(300);
|
||||
rig.Live(("Strength Self I", 3000));
|
||||
rig.B.ForceFullRebuff();
|
||||
var backoff = typeof(BuffManager).GetField("_busyBackoffUntil", BindingFlags.NonPublic | BindingFlags.Instance)!;
|
||||
int busy = 0;
|
||||
var sent = new List<int>();
|
||||
for (int i = 0; i < 200; i++)
|
||||
{
|
||||
int before = FakeHost.Casts.Count;
|
||||
CastSelfBuffs.Invoke(rig.B, null);
|
||||
if (FakeHost.Casts.Count == before) break;
|
||||
int id = FakeHost.Casts.Last().SpellId;
|
||||
sent.Add(id);
|
||||
if (FamilyOf(id) == cem && LevelOf(id) == 7 && busy < 2)
|
||||
{
|
||||
busy++;
|
||||
rig.B.OnChatWindowText("You're too busy!", 0);
|
||||
backoff.SetValue(rig.B, DateTime.MinValue); // the backoff runs on the real clock; not what is tested
|
||||
continue;
|
||||
}
|
||||
rig.B.OnChatWindowText($"You cast {NameOf(id)} on {(BuffManager.IsItemEnchantment(NameOf(id)) ? "Rune Robe" : "yourself")}", 7);
|
||||
if (sent.Count == 3) FakeHost.Skills[(Player, STypeCreature)] = (340, 2);
|
||||
}
|
||||
Check.Eq(busy, 2, "two refusals");
|
||||
Check.Eq(CemLevels(sent), "6,7,7,7", "CEM 6, two refused 7s, then 7 lands: " + Show(sent));
|
||||
Check.Eq(rig.B.BuffUpgrades, 3 + 2, "the upgrade line counts sends (CEM 3 times, Focus, Willpower)");
|
||||
}
|
||||
|
||||
// A late "You cast ... VI" while VII is pending is the lower cast's line.
|
||||
private static void UpgradeLateLowerLine()
|
||||
{
|
||||
int cem = FamilyOfBuff("Creature Enchantment Mastery Self VI");
|
||||
var rig = UpgradeRig(300);
|
||||
rig.Live(("Strength Self I", 3000));
|
||||
rig.B.ForceFullRebuff();
|
||||
var sent = new List<int>();
|
||||
bool late = false;
|
||||
for (int i = 0; i < 200; i++)
|
||||
{
|
||||
int before = FakeHost.Casts.Count;
|
||||
CastSelfBuffs.Invoke(rig.B, null);
|
||||
if (FakeHost.Casts.Count == before) break;
|
||||
int id = FakeHost.Casts.Last().SpellId;
|
||||
sent.Add(id);
|
||||
if (FamilyOf(id) == cem && LevelOf(id) == 7 && !late)
|
||||
{
|
||||
late = true;
|
||||
rig.B.OnChatWindowText("You cast Creature Enchantment Mastery Self VI on yourself", 7); // the earlier cast's line
|
||||
Check.Eq(rig.B.PendingSpellId, id, "the VI line leaves VII pending");
|
||||
rig.B.OnChatWindowText("Your spell fizzled.", 7); // VII's own result
|
||||
continue;
|
||||
}
|
||||
rig.B.OnChatWindowText($"You cast {NameOf(id)} on {(BuffManager.IsItemEnchantment(NameOf(id)) ? "Rune Robe" : "yourself")}", 7);
|
||||
if (sent.Count == 3) FakeHost.Skills[(Player, STypeCreature)] = (340, 2);
|
||||
}
|
||||
Check.Eq(CemLevels(sent), "6,7,7", "CEM 6, CEM 7 (late VI line, then its fizzle), CEM 7 again: " + Show(sent));
|
||||
}
|
||||
|
||||
// The line printed "6 -> 8" for an Incantation counted as an upgrade to its capped 7.
|
||||
private static void UpgradeLineEffectiveLevel()
|
||||
{
|
||||
FakeHost.Reset();
|
||||
Know("Incantation of Strength Self");
|
||||
FakeHost.Skills[(Player, STypeCreature)] = (500, 2); // tier 8
|
||||
FakeHost.WeaponCalls = true;
|
||||
FakeHost.CombatModeValue = CombatMode.Magic;
|
||||
var rig = new BuffRig();
|
||||
rig.B.SetWorldObjectCache(FakeHost.MakeCache(rig.Host, Player, Array.Empty<uint>()));
|
||||
rig.Live(("Armor Self I", 3000));
|
||||
RunBuffs(rig);
|
||||
EndRun(rig);
|
||||
rig.Live(("Might of the Lugians", 3000)); // it landed as 7 (the cap)
|
||||
Check.Eq(RunBuffs(rig).Count, 0, "at its cap: not recast");
|
||||
EndRun(rig);
|
||||
rig.Live(("Strength Self VI", 3000)); // ours is gone, someone's VI is on
|
||||
var up = RunBuffs(rig);
|
||||
EndRun(rig);
|
||||
Check.Eq(Show(up), "Incantation of Strength Self", "recast to reach the cap again");
|
||||
var line = FakeHost.Logs.LastOrDefault(l => l.Contains("[Buff] upgrade:")) ?? "";
|
||||
Check.True(line.Contains("level 6 -> 7 (Incantation of Strength Self)"), "the line says 6 -> 7, the level counted: " + line);
|
||||
}
|
||||
|
||||
private static T Fld<T>(BuffManager b, string name) => (T)typeof(BuffManager).GetField(name, BindingFlags.NonPublic | BindingFlags.Instance)!.GetValue(b)!;
|
||||
private static void SetFld(BuffManager b, string name, object v) => typeof(BuffManager).GetField(name, BindingFlags.NonPublic | BindingFlags.Instance)!.SetValue(b, v);
|
||||
|
||||
private static int AttemptedOf(BuffRig rig, int family) => Fld<Dictionary<int, int>>(rig.B, "_familyAttemptedTier").TryGetValue(family, out int n) ? n : 0;
|
||||
|
||||
/// <summary>The macro's path: heartbeats on a fake clock, the buff step running itself.</summary>
|
||||
private sealed class BeatRig
|
||||
{
|
||||
public readonly BuffRig R;
|
||||
private readonly Action<double> _at;
|
||||
private double _t;
|
||||
public BeatRig(int buffed)
|
||||
{
|
||||
R = UpgradeRig(buffed);
|
||||
R.S.IsMacroRunning = true;
|
||||
R.S.SpellCastIntervalMs = 0;
|
||||
_at = FakeClock(R);
|
||||
_at(0);
|
||||
R.B.MarkLiveBuffsReadyForTests();
|
||||
}
|
||||
public void Tick(double s) { _t += s; _at(_t); }
|
||||
/// <summary>Up to <paramref name="n"/> beats of 3 s, confirming every cast by chat except
|
||||
/// the first one <paramref name="hold"/> picks, which is returned unanswered (0 = none).</summary>
|
||||
public int Beats(int n, Func<int, bool> hold)
|
||||
{
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
Tick(3);
|
||||
int before = FakeHost.Casts.Count;
|
||||
R.B.OnHeartbeat();
|
||||
if (FakeHost.Casts.Count == before) continue;
|
||||
int id = FakeHost.Casts.Last().SpellId;
|
||||
if (hold(id)) return id;
|
||||
R.B.OnChatWindowText($"You cast {NameOf(id)} on {(BuffManager.IsItemEnchantment(NameOf(id)) ? "Rune Robe" : "yourself")}", 7);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/// <summary>A force run at the rig's skill, to its end, through the heartbeat.</summary>
|
||||
public void FirstRun()
|
||||
{
|
||||
R.Live(("Strength Self I", 3000));
|
||||
R.B.ForceFullRebuff();
|
||||
Beats(150, _ => false);
|
||||
Check.False(R.B.GetStateSnapshot().IsForceRebuffing, "the first run ends");
|
||||
}
|
||||
/// <summary>The pending cast's settle and give-up are read on the real clock too: put the send in the past.</summary>
|
||||
public void SendLongAgo(double seconds)
|
||||
{
|
||||
SetFld(R.B, "_lastCastAttempt", DateTime.Now.AddSeconds(-seconds));
|
||||
SetFld(R.B, "_lastSelfBuffPollAt", DateTime.MinValue);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>A pass after a run at tier 6 with Creature Magic now at 7, stopped with CEM 7 sent and pending.</summary>
|
||||
private static (BuffRig Rig, int Seven) PendingCem7(Action<BuffRig>? setup = null)
|
||||
{
|
||||
int cem = FamilyOfBuff("Creature Enchantment Mastery Self VI");
|
||||
var rig = UpgradeRig(300);
|
||||
setup?.Invoke(rig);
|
||||
rig.Live(("Strength Self I", 3000));
|
||||
rig.B.ForceFullRebuff();
|
||||
var first = RunBuffs(rig);
|
||||
EndRun(rig);
|
||||
FakeHost.Skills[(Player, STypeCreature)] = (340, 2);
|
||||
rig.Live(first.GroupBy(FamilyOf).Select(g => g.Last()).Where(id => !BuffManager.IsItemEnchantment(NameOf(id))).Select(id => (NameOf(id), 3000.0)).ToArray());
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
int before = FakeHost.Casts.Count;
|
||||
CastSelfBuffs.Invoke(rig.B, null);
|
||||
if (FakeHost.Casts.Count == before) break;
|
||||
int id = FakeHost.Casts.Last().SpellId;
|
||||
if (FamilyOf(id) == cem && LevelOf(id) == 7) return (rig, id);
|
||||
rig.B.OnChatWindowText($"You cast {NameOf(id)} on {(BuffManager.IsItemEnchantment(NameOf(id)) ? "Rune Robe" : "yourself")}", 7);
|
||||
}
|
||||
return (rig, 0);
|
||||
}
|
||||
|
||||
// The registry still holding VI at the give-up was taken as VII landing.
|
||||
// registryAtGiveUp: what the registry holds when the poll judges the pending CEM 7.
|
||||
private static (BeatRig H, int Seven) NoShowCase((string, double)[] registryAtGiveUp)
|
||||
{
|
||||
int cem = FamilyOfBuff("Creature Enchantment Mastery Self VI");
|
||||
var h = new BeatRig(300);
|
||||
h.FirstRun();
|
||||
FakeHost.Skills[(Player, STypeCreature)] = (340, 2);
|
||||
h.R.Live(("Creature Enchantment Mastery Self VI", 3000), ("Focus Self VI", 3000), ("Willpower Self VI", 3000));
|
||||
int seven = h.Beats(60, id => FamilyOf(id) == cem && LevelOf(id) == 7);
|
||||
Check.True(seven != 0 && h.R.B.PendingSpellId == seven, "CEM 7 is sent over the live VI and waits");
|
||||
h.R.Live(registryAtGiveUp);
|
||||
h.SendLongAgo(3); // no chat
|
||||
h.Tick(3);
|
||||
h.R.B.OnHeartbeat();
|
||||
return (h, seven);
|
||||
}
|
||||
|
||||
private static void UpgradeNoShowIsATry()
|
||||
{
|
||||
int cem = FamilyOfBuff("Creature Enchantment Mastery Self VI");
|
||||
var others = new[] { ("Focus Self VI", 3000.0), ("Willpower Self VI", 3000.0) };
|
||||
|
||||
var (h, seven) = NoShowCase(others.Prepend(("Creature Enchantment Mastery Self VI", 3000.0)).ToArray());
|
||||
Check.True(FakeHost.Logs.Any(l => l.Contains("not in the live registry") && l.Contains("no strike, tried again")), "VI unmoved: a no-show");
|
||||
Check.True(AttemptedOf(h.R, cem) < 7, $"VII is not taken as landed (attempted {AttemptedOf(h.R, cem)})");
|
||||
Check.Eq(FakeHost.Casts.Count(c => c.SpellId == seven), 2, "given up, and VII is sent again (the same beat)");
|
||||
|
||||
// The entry moved: VII at the same expiry (a higher level) ...
|
||||
(h, seven) = NoShowCase(others.Prepend(("Adja's Blessing", 3000.0)).ToArray());
|
||||
Check.Eq(AttemptedOf(h.R, cem), 7, "VII in the registry: landed");
|
||||
Check.Eq(FakeHost.Casts.Count(c => c.SpellId == seven), 1, "not sent again");
|
||||
|
||||
// ... or the same level with a later expiry (an Incantation landing low shows this way).
|
||||
(h, seven) = NoShowCase(others.Prepend(("Creature Enchantment Mastery Self VI", 3600.0)).ToArray());
|
||||
Check.Eq(AttemptedOf(h.R, cem), 7, "a later expiry: landed");
|
||||
Check.Eq(FakeHost.Casts.Count(c => c.SpellId == seven), 1, "not sent again");
|
||||
}
|
||||
// A pending Incantation took a late VII line as its own result.
|
||||
private static void UpgradeIncantationLateLine()
|
||||
{
|
||||
int cem = FamilyOfBuff("Creature Enchantment Mastery Self VI");
|
||||
var rig = UpgradeRig(340);
|
||||
rig.Live(("Strength Self I", 3000));
|
||||
rig.B.ForceFullRebuff();
|
||||
var first = RunBuffs(rig);
|
||||
EndRun(rig);
|
||||
var on = first.GroupBy(FamilyOf).Select(g => g.Last()).Where(id => !BuffManager.IsItemEnchantment(NameOf(id))).ToList();
|
||||
FakeHost.Skills[(Player, STypeCreature)] = (500, 2);
|
||||
rig.Live(on.Select(id => (NameOf(id), 3000.0)).ToArray());
|
||||
int inc = 0;
|
||||
for (int i = 0; i < 100 && inc == 0; i++)
|
||||
{
|
||||
int before = FakeHost.Casts.Count;
|
||||
CastSelfBuffs.Invoke(rig.B, null);
|
||||
if (FakeHost.Casts.Count == before) break;
|
||||
int id = FakeHost.Casts.Last().SpellId;
|
||||
if (FamilyOf(id) == cem && LevelOf(id) == 8) { inc = id; break; }
|
||||
rig.B.OnChatWindowText($"You cast {NameOf(id)} on {(BuffManager.IsItemEnchantment(NameOf(id)) ? "Rune Robe" : "yourself")}", 7);
|
||||
}
|
||||
Check.True(inc != 0, "the CEM Incantation is sent over VII");
|
||||
rig.B.OnChatWindowText($"You cast {NameOf(on.First(id => FamilyOf(id) == cem))} on yourself", 7); // the VII cast's late line
|
||||
Check.Eq(rig.B.PendingSpellId, inc, "the late VII line leaves the Incantation pending");
|
||||
Check.True(AttemptedOf(rig, cem) < 8, "and not taken as landed");
|
||||
rig.B.OnChatWindowText("Your spell fizzled.", 7);
|
||||
Check.Eq(rig.B.PendingSpellId, 0, "its own fizzle ends it");
|
||||
int sentBefore = FakeHost.Casts.Count;
|
||||
CastSelfBuffs.Invoke(rig.B, null);
|
||||
Check.True(FakeHost.Casts.Count > sentBefore && FakeHost.Casts.Last().SpellId == inc, "and it is cast again");
|
||||
}
|
||||
|
||||
// An Incantation heard (open on the server) and given up; the
|
||||
// skill drops; VII goes out; then the Incantation's own line arrives. It names a HIGHER level than
|
||||
// the pending VII, so only the tracker (it credits the line to the open Incantation) says it is late.
|
||||
private static void UpgradeLateLineFromEarlierSend()
|
||||
{
|
||||
int cem = FamilyOfBuff("Creature Enchantment Mastery Self VI");
|
||||
var h = new BeatRig(340);
|
||||
h.FirstRun();
|
||||
FakeHost.Skills[(Player, STypeCreature)] = (500, 2);
|
||||
h.R.Live(("Adja's Blessing", 200), ("Inner Calm", 3000), ("Mind Blossom", 3000)); // CEM VII running low
|
||||
int inc = h.Beats(60, id => FamilyOf(id) == cem);
|
||||
Check.True(inc != 0 && LevelOf(inc) == 8, "the CEM Incantation is sent: " + NameOf(inc));
|
||||
h.R.B.OnChatWindowText("You say, \"Puish Zharil\"", 17); // its incantation: the server runs it
|
||||
FakeHost.Skills[(Player, STypeCreature)] = (340, 2); // the skill drops
|
||||
for (int i = 0; i < 6 && h.R.B.PendingSpellId == inc; i++)
|
||||
{
|
||||
h.SendLongAgo(6);
|
||||
h.Tick(3);
|
||||
h.R.B.OnHeartbeat(); // no result: given up, VII goes out
|
||||
}
|
||||
int seven = h.R.B.PendingSpellId;
|
||||
Check.True(seven != 0 && FamilyOf(seven) == cem && LevelOf(seven) == 7, "given up; VII is pending: " + NameOf(seven));
|
||||
h.R.B.OnChatWindowText($"You cast {NameOf(inc)} on yourself", 7); // the Incantation's late line
|
||||
Check.Eq(h.R.B.PendingSpellId, seven, "VII still waits for its own result");
|
||||
}
|
||||
|
||||
/// <summary>Lets the pending <paramref name="id"/> reach its give-up unanswered twice (it is resent
|
||||
/// in between); returns the give-ups done. Every other cast is confirmed.</summary>
|
||||
private static int FailTwice(BeatRig h, int id)
|
||||
{
|
||||
int gaveUp = 0;
|
||||
for (int k = 0; k < 20 && gaveUp < 2; k++)
|
||||
{
|
||||
if (h.R.B.PendingSpellId != id) { if (h.Beats(40, x => x == id) == 0) break; continue; }
|
||||
h.SendLongAgo(6);
|
||||
h.Tick(6);
|
||||
h.R.B.OnHeartbeat();
|
||||
if (h.R.B.PendingSpellId != id || FakeHost.Casts.Count(c => c.SpellId == id) > gaveUp + 1) gaveUp++;
|
||||
}
|
||||
// The last give-up's beat may have sent the next cast: answer it, as Beats does.
|
||||
int next = h.R.B.PendingSpellId;
|
||||
if (next != 0 && next != id)
|
||||
h.R.B.OnChatWindowText($"You cast {NameOf(next)} on {(BuffManager.IsItemEnchantment(NameOf(next)) ? "Rune Robe" : "yourself")}", 7);
|
||||
return gaveUp;
|
||||
}
|
||||
|
||||
private static bool Parked(BuffRig rig, int family) => Fld<Dictionary<int, DateTime>>(rig.B, "_buffFailCooldownUntil").ContainsKey(family);
|
||||
|
||||
// The no-show strikes parked the family 30 min after two upgrade no-shows, so the
|
||||
// lower level it was cast over was not recast when it ran low.
|
||||
private static void UpgradeNoShowsDoNotPark()
|
||||
{
|
||||
int cem = FamilyOfBuff("Creature Enchantment Mastery Self VI");
|
||||
var h = new BeatRig(300);
|
||||
h.FirstRun();
|
||||
// The registry holds the first run's player buffs (so a batch is the few upgrades, not the suite).
|
||||
var six = FakeHost.Casts.Select(c => c.SpellId).Where(id => !BuffManager.IsItemEnchantment(NameOf(id))).Distinct().ToList();
|
||||
(string, double)[] Registry(double cemLeft) => six.Select(id => (NameOf(id), FamilyOf(id) == cem ? cemLeft : 3000.0)).ToArray();
|
||||
FakeHost.Skills[(Player, STypeCreature)] = (340, 2);
|
||||
h.R.Live(Registry(3000));
|
||||
int seven = h.Beats(60, id => FamilyOf(id) == cem && LevelOf(id) == 7);
|
||||
Check.True(seven != 0, "CEM 7 is sent over the live VI");
|
||||
Check.Eq(FailTwice(h, seven), 2, "two no-shows");
|
||||
Check.False(Parked(h.R, cem), "the family is not parked");
|
||||
h.R.Live(Registry(100)); // VI running low
|
||||
// No limit: CEM is still being cast (already resent, or on a later beat). A 30 min park (the
|
||||
// bug) runs on the real clock and would hold it throughout.
|
||||
Check.True(FamilyOf(h.R.B.PendingSpellId) == cem || h.Beats(150, id => FamilyOf(id) == cem) != 0, "CEM is still being cast");
|
||||
Check.False(Parked(h.R, cem), "never parked"); }
|
||||
|
||||
// The item spell (armor) twin of the test above.
|
||||
private static void UpgradeArmorNoChatDoesNotPark()
|
||||
{
|
||||
var h = new BeatRig(300);
|
||||
h.FirstRun();
|
||||
FakeHost.Skills[(Player, STypeItem)] = (340, 2);
|
||||
int item7 = h.Beats(80, id => BuffManager.IsItemEnchantment(NameOf(id)) && LevelOf(id) == 7);
|
||||
Check.True(item7 != 0, "an item spell is upgraded to 7: " + NameOf(item7));
|
||||
int fam = FamilyOf(item7);
|
||||
Check.Eq(FailTwice(h, item7), 2, "two no-chat give-ups");
|
||||
Check.False(Parked(h.R, fam), "the family is not parked");
|
||||
// Its VI record runs low.
|
||||
object rec = ((System.Collections.IDictionary)Fld<object>(h.R.B, "_itemSpellTimers"))[fam]!;
|
||||
rec.GetType().GetField("ExpiresAt")!.SetValue(rec, DateTime.Now.AddSeconds(100));
|
||||
Check.True(h.Beats(40, id => FamilyOf(id) == fam) != 0, "running low: recast");
|
||||
}
|
||||
|
||||
// No limit and no rest, through OnHeartbeat: an always-fizzling CEM 7 is sent on
|
||||
// every beat (one per answer), the late VI line confirms nothing, and nothing goes out unanswered.
|
||||
private static void UpgradeCapViaHeartbeat()
|
||||
{
|
||||
int cem = FamilyOfBuff("Creature Enchantment Mastery Self VI");
|
||||
var h = new BeatRig(300);
|
||||
h.FirstRun();
|
||||
var six = FakeHost.Casts.Select(c => c.SpellId).Where(id => !BuffManager.IsItemEnchantment(NameOf(id))).Distinct().ToList();
|
||||
FakeHost.Skills[(Player, STypeCreature)] = (340, 2);
|
||||
h.R.Live(six.Select(id => (NameOf(id), 3000.0)).ToArray());
|
||||
int seven = h.Beats(60, id => FamilyOf(id) == cem && LevelOf(id) == 7);
|
||||
Check.True(seven != 0, "CEM 7 is sent");
|
||||
h.R.B.OnChatWindowText("You cast Creature Enchantment Mastery Self VI on yourself", 7); // a late VI line
|
||||
Check.Eq(h.R.B.PendingSpellId, seven, "the late VI line confirms nothing");
|
||||
h.R.B.OnChatWindowText("Your spell fizzled.", 7);
|
||||
int sends = 1;
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
h.Tick(3);
|
||||
int before = FakeHost.Casts.Count;
|
||||
h.R.B.OnHeartbeat();
|
||||
Check.Eq(FakeHost.Casts.Count - before, 1, $"beat {i}: one send");
|
||||
Check.Eq(FakeHost.Casts.Last().SpellId, seven, $"beat {i}: CEM 7 again");
|
||||
sends++;
|
||||
h.R.B.OnChatWindowText("Your spell fizzled.", 7);
|
||||
}
|
||||
Check.Eq(sends, 21, "21 sends in 21 answered beats");
|
||||
// Unanswered: nothing more goes out while it waits.
|
||||
int held = FakeHost.Casts.Count;
|
||||
h.Tick(3);
|
||||
h.R.B.OnHeartbeat(); // sends CEM 7
|
||||
for (int i = 0; i < 10; i++) { h.Tick(0.1); h.R.B.OnHeartbeat(); }
|
||||
Check.Eq(FakeHost.Casts.Count - held, 1, "unanswered: one send, then it waits");
|
||||
}
|
||||
|
||||
// With no limit, a cast the client refuses (nothing goes out, no answer comes)
|
||||
// must still wait SpellCastIntervalMs between attempts, not re-send on every heartbeat.
|
||||
private static void UpgradeClientRefusalPaced()
|
||||
{
|
||||
int cem = FamilyOfBuff("Creature Enchantment Mastery Self VI");
|
||||
var h = new BeatRig(300);
|
||||
h.FirstRun();
|
||||
var six = FakeHost.Casts.Select(c => c.SpellId).Where(id => !BuffManager.IsItemEnchantment(NameOf(id))).Distinct().ToList();
|
||||
FakeHost.Skills[(Player, STypeCreature)] = (340, 2);
|
||||
h.R.Live(six.Select(id => (NameOf(id), 3000.0)).ToArray());
|
||||
h.R.S.SpellCastIntervalMs = 600_000; // the interval runs on the real clock: shut for this test
|
||||
try
|
||||
{
|
||||
FakeHost.CastRefused = true;
|
||||
h.SendLongAgo(700); // an interval has passed
|
||||
for (int i = 0; i < 30; i++) { h.Tick(0.1); h.R.B.OnHeartbeat(); }
|
||||
Check.Eq(FakeHost.CastsRefused, 1, "30 heartbeats inside one interval: one refused attempt");
|
||||
Check.Eq(h.R.B.PendingSpellId, 0, "nothing pending");
|
||||
h.SendLongAgo(700); // the next interval
|
||||
h.Tick(0.1);
|
||||
h.R.B.OnHeartbeat();
|
||||
Check.Eq(FakeHost.CastsRefused, 2, "the next interval: tried again");
|
||||
Check.True(FakeHost.Logs.Count(l => l.Contains("did not take (the client refused it)")) >= 2 && FakeHost.Logs.Any(l => l.Contains("Adja's Blessing")), "the refused cast was the CEM upgrade");
|
||||
}
|
||||
finally { FakeHost.CastRefused = false; }
|
||||
}
|
||||
|
||||
// "Incantation of Strength Self" lands as Strength Self VI here; refreshing it is
|
||||
// not an upgrade.
|
||||
private static void IncantationRefreshNotUpgrade()
|
||||
{
|
||||
FakeHost.Reset();
|
||||
Know("Incantation of Strength Self");
|
||||
FakeHost.Skills[(Player, STypeCreature)] = (500, 2); // tier 8
|
||||
FakeHost.WeaponCalls = true;
|
||||
FakeHost.CombatModeValue = CombatMode.Magic;
|
||||
var rig = new BuffRig();
|
||||
rig.B.SetWorldObjectCache(FakeHost.MakeCache(rig.Host, Player, Array.Empty<uint>()));
|
||||
rig.Live(("Armor Self I", 3000) /* a registry read with no Strength on */);
|
||||
var first = RunBuffs(rig);
|
||||
EndRun(rig);
|
||||
Check.Eq(Show(first), "Incantation of Strength Self", "the Incantation is cast and confirmed");
|
||||
rig.Live(("Strength Self VI", 3000)); // it landed as VI
|
||||
Check.Eq(RunBuffs(rig).Count, 0, "landed a level low: not recast (the cap)");
|
||||
EndRun(rig);
|
||||
rig.Live(("Strength Self VI", 200)); // running low
|
||||
var refresh = RunBuffs(rig);
|
||||
EndRun(rig);
|
||||
Check.Eq(Show(refresh), "Incantation of Strength Self", "refreshed");
|
||||
Check.Eq(rig.B.BuffUpgrades, 0, "not an upgrade");
|
||||
Check.False(FakeHost.Logs.Any(l => l.Contains("[Buff] upgrade:")), "no upgrade line");
|
||||
}
|
||||
|
||||
private static void PriorityOrder()
|
||||
{
|
||||
var rig = SuiteRig(MeleeItem, WandItem);
|
||||
|
|
|
|||
Loading…
Reference in a new issue