Vitals: no wand swap for a vital spell while a kit or potion heals #28

Open
AwfulWaffle wants to merge 2 commits from AwfulWaffle/RynthSuite:vital-wand-gate into main
First-time contributor

Stacks on kit-used-up (#27): review/apply that first.

What went wrong in play

Kits are the standard heal, and the shield should stay on. Putting the shield away for a wand costs more damage than a small heal spell buys back. Yet a melee character under Heal At put its shield away and pulled a wand for Heal Self, Revitalize or Stamina to Mana with kits in the pack. The wand was skipped only at Emergency Heal At.

The fix

Combat/BuffManager.VitalWandGate.cs (new) adds VitalSpellWouldSwap, called from CastVital. It covers Heal Self, Stamina to Health, Revitalize, Stamina to Mana and the script hook's heal.

When all three of these hold, the cast is refused as not handled:

  • the character is out of Magic mode;
  • no caster is in hand;
  • a usable kit or potion for that vital is carried.

The chain then falls through to the potion, and to the kit despite Kit Min Success.

Exceptions (the swap is allowed, or nothing is gated):

  • With no kit and no potion at all, the swap is still allowed: it is the only heal there is.
  • A caster already wielded still gets the Magic stance change (no weapon moves). The wielded-wand check moves out of EnsureMagicMode into IsBuffWandWielded, so the gate and the swap agree.
  • With no wand found, the Magic stance goes bare-handed and no weapon moves, so nothing is gated.
  • A swap already under way finishes.
  • Stamina to Mana never swaps in a fight (InCombatNow), potion or not. Out of a fight it may, even with a mana potion carried, because buffing is about to swap anyway.

Which kits count. A kit counts only if the kit picks would use it:

  • it is in the live pack walk;
  • its result line has not called it used up (kit-used-up (#27)'s KitUsedUp, which is why this stacks on kit-used-up (#27));
  • the server has not refused it 3 times within 10 s. A UseDone error or "You're too busy!" is no answer the kit wait drops, so without this cap such a kit would block every spell heal.
  • A streak with no refusal for 10 s ages out. A kit landing, or the macro stopping, ends every streak.

Stamina sources. The stamina step, the mana step's refill and the buffing mana floor now share one order (AttemptStaminaRestore). It ends with the stamina kit despite Stamina Kit Min Success % as the last resort, since Revitalize is refused here. AttemptStaminaKitUse() keeps its name and calls the new AttemptStaminaKit(bool ignoreMinSuccess, out bool underMinSuccess).

Buffing is unchanged and still swaps.

How it was tested

Run from Tools\RynthCore.RynthAiHostTests on this branch (kit-used-up (#27) plus this):

dotnet build -c Release -r win-x86 -nodeReuse:false          (plugin project and host tests: 0 errors)
dotnet run -c Release -- "vital wand gate"                   17 tests, 171 checks: 17 passed
dotnet run -c Release -- "kit used up"                       6 tests, 47 checks: 6 passed
dotnet run -c Release                                        1518 tests: 1517 passed, 1 failed

The one failure is map bake: 0x6346 ..., the same one pristine main has (1494/1495).

New tests: VitalWandGateTests (17). They cover:

  • Refusals: the refusal in melee, missile and peace modes; Revitalize, Stamina to Mana and the script heal.
  • Fall-through: the kit despite Kit Min Success; the stamina last resort on all three paths.
  • Not gated: a caster in hand; no wand found; Magic with no wand in hand.
  • Swap allowed: the no-kit swap; a potion that Use Potions forbids.
  • Buffing still swaps.
  • Swap state: the swap under way; Stamina to Mana in and out of a fight.
  • Kit counting: the refused-kit streak and its ageing out after 11 s; a kit called used up, or gone from the client's pack, counts as no kit.

Checked against deliberately broken code:

  • with the gate stubbed off, 9 of 15 failed (before the last two tests were added);
  • with the used-up term removed, the gone-kit test fails;
  • with the streak never pruned, the ageing test fails;
  • with the no-wand exception removed, the no-wand test fails.

Scope and risk

  • What changes: which heal a melee or missile character uses under Heal At while kits or potions are carried. A character with nothing else to heal with is unaffected.
  • One-touch heal: /ra heal goes through CastVital too, so it is gated the same way.
  • Overlap with heal-hold (#26): both edit the Stamina Kit Min Success check in AttemptStaminaKit. Applying both gives one conflict hunk; the resolution is in heal-hold (#26)'s body. All four branches together build, and the host tests give 1534 tests, 1533 passed, with only map bake failing.

🤖 Generated with Claude Code

Stacks on kit-used-up (#27): review/apply that first. ## What went wrong in play Kits are the standard heal, and the shield should stay on. Putting the shield away for a wand costs more damage than a small heal spell buys back. Yet a melee character under Heal At put its shield away and pulled a wand for Heal Self, Revitalize or Stamina to Mana with kits in the pack. The wand was skipped only at Emergency Heal At. ## The fix `Combat/BuffManager.VitalWandGate.cs` (new) adds `VitalSpellWouldSwap`, called from `CastVital`. It covers Heal Self, Stamina to Health, Revitalize, Stamina to Mana and the script hook's heal. When all three of these hold, the cast is refused as not handled: - the character is out of Magic mode; - no caster is in hand; - a usable kit or potion for that vital is carried. The chain then falls through to the potion, and to the kit despite Kit Min Success. **Exceptions** (the swap is allowed, or nothing is gated): - With no kit and no potion at all, the swap is still allowed: it is the only heal there is. - A caster already wielded still gets the Magic stance change (no weapon moves). The wielded-wand check moves out of `EnsureMagicMode` into `IsBuffWandWielded`, so the gate and the swap agree. - With no wand found, the Magic stance goes bare-handed and no weapon moves, so nothing is gated. - A swap already under way finishes. - Stamina to Mana never swaps in a fight (`InCombatNow`), potion or not. Out of a fight it may, even with a mana potion carried, because buffing is about to swap anyway. **Which kits count.** A kit counts only if the kit picks would use it: - it is in the live pack walk; - its result line has not called it used up (kit-used-up (#27)'s `KitUsedUp`, which is why this stacks on kit-used-up (#27)); - the server has not refused it 3 times within 10 s. A UseDone error or "You're too busy!" is no answer the kit wait drops, so without this cap such a kit would block every spell heal. - A streak with no refusal for 10 s ages out. A kit landing, or the macro stopping, ends every streak. **Stamina sources.** The stamina step, the mana step's refill and the buffing mana floor now share one order (`AttemptStaminaRestore`). It ends with the stamina kit despite Stamina Kit Min Success % as the last resort, since Revitalize is refused here. `AttemptStaminaKitUse()` keeps its name and calls the new `AttemptStaminaKit(bool ignoreMinSuccess, out bool underMinSuccess)`. **Buffing** is unchanged and still swaps. ## How it was tested Run from `Tools\RynthCore.RynthAiHostTests` on this branch (kit-used-up (#27) plus this): ``` dotnet build -c Release -r win-x86 -nodeReuse:false (plugin project and host tests: 0 errors) dotnet run -c Release -- "vital wand gate" 17 tests, 171 checks: 17 passed dotnet run -c Release -- "kit used up" 6 tests, 47 checks: 6 passed dotnet run -c Release 1518 tests: 1517 passed, 1 failed ``` The one failure is `map bake: 0x6346 ...`, the same one pristine main has (1494/1495). New tests: `VitalWandGateTests` (17). They cover: - **Refusals:** the refusal in melee, missile and peace modes; Revitalize, Stamina to Mana and the script heal. - **Fall-through:** the kit despite Kit Min Success; the stamina last resort on all three paths. - **Not gated:** a caster in hand; no wand found; Magic with no wand in hand. - **Swap allowed:** the no-kit swap; a potion that Use Potions forbids. - **Buffing** still swaps. - **Swap state:** the swap under way; Stamina to Mana in and out of a fight. - **Kit counting:** the refused-kit streak and its ageing out after 11 s; a kit called used up, or gone from the client's pack, counts as no kit. Checked against deliberately broken code: - with the gate stubbed off, 9 of 15 failed (before the last two tests were added); - with the used-up term removed, the gone-kit test fails; - with the streak never pruned, the ageing test fails; - with the no-wand exception removed, the no-wand test fails. ## Scope and risk - **What changes:** which heal a melee or missile character uses under Heal At while kits or potions are carried. A character with nothing else to heal with is unaffected. - **One-touch heal:** `/ra heal` goes through `CastVital` too, so it is gated the same way. - **Overlap with heal-hold (#26):** both edit the Stamina Kit Min Success check in `AttemptStaminaKit`. Applying both gives one conflict hunk; the resolution is in heal-hold (#26)'s body. All four branches together build, and the host tests give 1534 tests, 1533 passed, with only `map bake` failing. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A kit's last heal ends "... Your Treated Healing Kit is used up." (ACE
Healer.DoHealing) and the server removes the kit. A use of an item the
player no longer has is answered with a bare UseDone and no chat, so a
used-up kit picked again is a heal lost.

Kit picks read the client's live pack walk (ConsumableLookup.Resolve,
BestPackHealingKit, BestPackStaminaKit), which drops the removed kit, but
a walk is reused for up to 1 s (DirectInventoryCooldownMs), and the next
kit goes out 700 ms after the line (KitLandGraceMs): inside that reuse
the used-up kit was picked again. An engine without GetContainerContents
has no walk at all; its inventory view is the object cache, which can
keep the removed kit for good.

Now the "is used up" line, when it names the kit in flight, makes every
kit pick skip that kit: for 3 s (UsedUpKitSkipMs) with the live walk, long
enough for a fresh walk to have dropped it, and for the session without
it (the server deleted the object; its id never comes back). A line
naming another kit (a late line from a kit that timed out) is logged and
ignored. ConsumableLookup.Resolve takes an optional skip predicate; a
skipped listed id falls through to the name match. Healing and stamina
kits.

WorldObjectCache.WalkClock: the clock GetDirectInventory's reuse runs on
(RynthClock unless a test sets it), so the tests can hold the walk still
and prove the skip, not a refreshed walk, keeps the kit out.

Ported from the earlier kit-drop work onto the live-walk lookup: the rest
of that work (dropping a kit after two bare answers, the 5 minute drop,
the emergency last resort for dropped kits, dropped potion stacks) is
covered by the live walk and is not carried.

Tests: KitUsedUpTests (new, 6). The walk-window cases fail on main and
with KitUsedUp stubbed to false; the no-walk case fails with a 3 s skip.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Kits are the standard heal, and the shield stays on: putting the shield
away for a wand costs more damage than a small heal spell buys back. A
melee character under Heal At put its shield away and pulled a wand for
Heal Self with kits in the pack; the wand was skipped only at Emergency
Heal At.

CastVital (Heal Self, Stamina to Health, Revitalize, Stamina to Mana and
the script hook's heal) now refuses as not handled when the character is
out of Magic mode, no caster is in hand, and a usable kit or potion for
that vital is carried (BuffManager.VitalWandGate.cs). The chain falls
through to the potion and the kit despite Kit Min Success.

- With no kit and no potion at all the swap is still allowed.
- A caster already wielded still gets the Magic stance change (no weapon
  moves); the wielded-wand check is extracted from EnsureMagicMode into
  IsBuffWandWielded so the gate and the swap agree. With no wand found
  the Magic stance goes bare-handed (no weapon moves): not gated either.
- A swap already under way finishes.
- Stamina to Mana never swaps in a fight (InCombatNow), potion or not;
  out of a fight it may, even with a mana potion carried.
- A kit counts only if the kit picks would use it: the live pack walk,
  minus a kit its line called used up, minus a kit the server refused 3
  times within 10 s. A streak with no refusal for 10 s ages out; a kit
  landing, or the macro stopping, ends every streak.
- The stamina sources share one order (AttemptStaminaRestore) for the
  stamina step, the mana step's refill and the buffing mana floor, ending
  with the stamina kit despite Stamina Kit Min Success % as the last
  resort, since Revitalize is refused here.
- Buffing is unchanged and still swaps.

Tests: VitalWandGateTests (new, 17).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This pull request has changes conflicting with the target branch.
  • Plugins/RynthCore.Plugin.RynthAi/Combat/BuffManager.KitUsedUp.cs
  • Plugins/RynthCore.Plugin.RynthAi/Combat/BuffManager.VitalWandGate.cs
  • Plugins/RynthCore.Plugin.RynthAi/Combat/BuffManager.cs
  • Tools/RynthCore.RynthAiHostTests/Tests/VitalWandGateTests.cs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u vital-wand-gate:AwfulWaffle-vital-wand-gate
git switch AwfulWaffle-vital-wand-gate

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch main
git merge --no-ff AwfulWaffle-vital-wand-gate
git switch AwfulWaffle-vital-wand-gate
git rebase main
git switch main
git merge --ff-only AwfulWaffle-vital-wand-gate
git switch AwfulWaffle-vital-wand-gate
git rebase main
git switch main
git merge --no-ff AwfulWaffle-vital-wand-gate
git switch main
git merge --squash AwfulWaffle-vital-wand-gate
git switch main
git merge --ff-only AwfulWaffle-vital-wand-gate
git switch main
git merge AwfulWaffle-vital-wand-gate
git push origin main
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
rynth/RynthSuite!28
No description provided.