Skip to content

fix(eherbs): v2.2.1 warn when stocking a survival kit with no stock % set - #2474

Merged
mrhoribu merged 1 commit into
elanthia-online:masterfrom
Nisugi:fix/eherbs-warn-unset-stock-percent
Sep 14, 2026
Merged

mrhoribu merged 1 commit into
elanthia-online:masterfrom
Nisugi:fix/eherbs-warn-unset-stock-percent

Conversation

@Nisugi

@Nisugi Nisugi commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Problem

Reported in Discord: ;eherbs stock reports a Survivalist's Kit is fully stocked and buys nothing. The cause is an empty Stock to % of Capacity setting, which gives no indication that it is the problem.

A Survivalist's Kit holds (tier * 25) + 25 doses per herb slot. The default min_stock_doses targets are herb sack sized — 4–7 doses for scar herbs, 25–50 for the common ones.

determine_survival_kit rescales those targets to the kit's capacity, but only past this guard:

return unless EHerbs.data[:stock].to_i > 0

With the field empty, "".to_i is 0, the method returns early, and the sack defaults stand. A kit exceeds them on its own, so get_current_stock finds total_doses >= min_stock_doses[bippity] for every category, the shopping list comes back empty, and stocking prints "You are fully stocked with herbs at this location."

Fix

Warn rather than guess at a percentage. Changing what an unset setting means would silently alter behavior for every existing user, which did not seem appropriate for a script this long-established, so the default is untouched — stocking still proceeds and still reports fully stocked, it just explains why now and points at the existing ;eherbs set stock <percent> command with a clickable link.

Two guards keep it narrow:

  • Called from stock_herbs, not at startup. Plenty of people use eherbs to tend wounds and never stock; they should not be nagged about a setting irrelevant to them. It is also placed after the Icemule/Pinefar early exit so it does not fire on a run that is about to bail.
  • Only when a survival kit is detected. A plain herb sack's defaults are already correct and need no percentage.

Testing

  • ruby -c passes.
  • rubocop --force-exclusion scripts/eherbs.lic — no offenses.
  • Branched from current origin/master (096a093); the only diff is the new helper, its one call site, and the version/changelog bump.

Note — two unrelated bugs in determine_survival_kit

Spotted while reading the method, deliberately left alone to keep this focused. Happy to open a separate issue or PR.

  1. tier can be nil. Line 2993 uses a trailing-modifier if, so when the Capacity: n/5 line is absent from the analyze output tier stays nil and (tier * 25) raises NoMethodError. It also reads Regexp.last_match(1) after the lines.any? block has finished, which happens to work only because any? short-circuits on the matching line.

  2. Double scaling on redetect. EHerbs.data[:stock] is mutated in place and @@min_stock_doses is overwritten rather than recomputed from the defaults. On the redetect path the already-scaled values get scaled again — 50% applied twice yields 25%. A fix would mean keeping the literal hash as a frozen constant and .dup-ing it before each rescale.

🤖 Generated with Claude Code

… set

A Survivalist's Kit holds (tier * 25) + 25 doses per slot, while the
default min_stock_doses targets are herb sack sized (4-7 doses for scar
herbs, 25-50 for common ones). determine_survival_kit only rescales those
targets to the kit's capacity when a stock % is configured; with the
setting left empty it returns early and the sack defaults stand.

A kit satisfies those defaults on its own, so get_current_stock builds an
empty shopping list and stocking reports "You are fully stocked with herbs
at this location." while buying nothing. Nothing indicates the setting is
the cause.

Warn instead of guessing at a percentage, since changing what an unset
setting means would alter behavior for existing users. The check lives in
stock_herbs rather than at startup because it only matters to stocking,
and is guarded on the kit because a plain herb sack's defaults are already
correct. Stocking still proceeds, it just explains itself now, and the
message includes a clickable command to set the value.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: bb6c1807-b0d0-4129-bbe5-c8b00172db47

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@mrhoribu
mrhoribu merged commit fa4e9b3 into elanthia-online:master Sep 14, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants