Skip to content

Fix equipment selection bug - clicking one option selects multiple #49

Description

@FirebrickRed

Priority: HIGH
Status: BUG
Found in: Barbarian character creation (likely affects other classes too)

Bug Description

When selecting equipment during character creation, clicking one option sometimes selects MULTIPLE options unintentionally.

Steps to Reproduce

  1. Create a Barbarian character
  2. Navigate to equipment selection
  3. Click "2 Handaxes" in the second equipment choice

Expected: Only "2 Handaxes" gets selected
Actual: BOTH "2 Handaxes" AND "Any Simple Weapon" get selected

  1. Similarly, click "Greataxe" in first equipment choice

Expected: Only "Greataxe" gets selected
Actual: BOTH "Greataxe" AND "Any Martial Melee Weapon" get selected

Barbarian Equipment Choices (YAML)

player_choices:
  - id: class_equipment_1
    title: Starting Equipment 1
    choose: 1
    options:
      - - item: greataxe
      - - tag: martial_melee_weapon

  - id: class_equipment_2
    title: Starting Equipment 2
    choose: 1
    options:
      - - item: handaxe
          quantity: 2
      - - tag: simple_weapon

Root Cause Hypothesis

In MergedChoice.toggleOption() (lines 159-164), when selecting an option:

// Find which source(s) can have this option
List<PendingChoice<?>> candidateSources = new ArrayList<>();
for (PendingChoice<?> pc : sourcePendingChoices) {
    if (pc.optionKeys().contains(optionKey)) {
        candidateSources.add(pc);
    }
}

Problem: If the same option key appears in multiple PendingChoice sources (e.g., greataxe appears in both equipment_1 and equipment_2 due to tag expansion), it will add the option to MULTIPLE sources instead of just one.

Why This Happens

  • greataxe is a martial melee weapon
  • When tag:martial_melee_weapon gets expanded, greataxe becomes an available option in BOTH:
    1. Direct item:greataxe in equipment_1
    2. Expanded from tag:martial_melee_weapon in equipment_1

Similarly for handaxe:

  • handaxe is a simple weapon
  • It appears as both direct item:handaxe AND in the expanded tag:simple_weapon list

Expected Behavior

Clicking an option should only select it in ONE PendingChoice (the specific choice it belongs to), not all choices that happen to contain that option key.

Proposed Fix

MergedChoice.toggleOption() needs to be smarter about which source to select in:

  1. Prioritize the source where this is the primary option (not from tag expansion)
  2. OR: Only select in ONE candidate source, not all of them
  3. OR: Check which specific choice the user clicked from (pass choice ID in payload)

Files to Investigate

  • src/main/java/io/papermc/jkvttplugin/data/model/MergedChoice.java:146-186
  • src/main/java/io/papermc/jkvttplugin/ui/handler/TabbedChoicesHandler.java:41-71
  • Tag expansion logic in equipment option building

Testing Checklist

  • Barbarian equipment selection (both choices)
  • Fighter equipment selection (has similar structure)
  • Other classes with overlapping equipment options
  • Verify tag resolution still works correctly
  • Verify deselection works properly

Related Issues

This might also affect other merged choices where options overlap between sources.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions