Skip to content

BUG: Ability usage returns empty equipment data despite valid equipment IDs #20

@0x1NotMe

Description

@0x1NotMe

Problem Description

When characters use abilities (e.g., "ChargeUp"), the returned BattleNad struct contains empty weapon and armor data, even though the character has valid equipment IDs.

Observed Behavior

Actual Result:

BattleNad {
  id: 1,
  weaponID: 4,     // ✅ Valid ID
  armorID: 4,      // ✅ Valid ID  
  weapon: { name: "", baseDamage: 0, bonusDamage: 0, accuracy: 0, speed: 0 },  // ❌ Empty
  armor: { name: "", armorFactor: 0, armorQuality: 0, flexibility: 0, weight: 0 }, // ❌ Empty
  inventory: { weaponBitmap: 0, armorBitmap: 0, balance: 0 }  // ❌ Empty
}

Expected Result:
Equipment structs should be populated with actual weapon/armor data based on the valid IDs.

Root Cause Analysis

The issue was in the _handleAbility function in Handler.sol. Unlike the _handleCombat function which properly loads equipment and inventory data, the ability handler was missing these crucial loading steps:

Working Code (Combat Handler)

function _handleCombat(/* params */) internal {
    // ... 
    attacker = attacker.loadEquipment();     // ✅ Loads equipment data
    attacker.inventory = inventories[attacker.id]; // ✅ Loads inventory
    // ...
}

Broken Code (Ability Handler - Before Fix)

function _handleAbility(/* params */) internal {
    // ... 
    // ❌ Missing equipment loading
    // ❌ Missing inventory loading
    // ...
}

Impact

  • Severity: High - Core game functionality affected
  • Scope: All ability usage in the game
  • User Experience: Players see incomplete character data when using abilities
  • Data Integrity: No data corruption, just missing display information

Files Modified

  • src/battle-nads/Handler.sol - Fixed ability handler
  • src/battle-nads/Storage.sol - Fixed minor variable shadowing warning

Testing

Created test script script/task-manager/get-task-schedule.s.sol to validate the fix works correctly.

Additional Notes

This inconsistency between combat and ability handlers suggests the need for:

  1. Code Review Process: Ensure similar functions have consistent data loading patterns
  2. Integration Tests: Add tests that verify complete data structures are returned
  3. Documentation: Document the equipment loading requirements for new handlers

The fix ensures both combat and ability execution paths now have consistent behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions