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:
- Code Review Process: Ensure similar functions have consistent data loading patterns
- Integration Tests: Add tests that verify complete data structures are returned
- Documentation: Document the equipment loading requirements for new handlers
The fix ensures both combat and ability execution paths now have consistent behavior.
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
_handleAbilityfunction inHandler.sol. Unlike the_handleCombatfunction which properly loads equipment and inventory data, the ability handler was missing these crucial loading steps:Working Code (Combat Handler)
Broken Code (Ability Handler - Before Fix)
Impact
Files Modified
src/battle-nads/Handler.sol- Fixed ability handlersrc/battle-nads/Storage.sol- Fixed minor variable shadowing warningTesting
Created test script
script/task-manager/get-task-schedule.s.solto validate the fix works correctly.Additional Notes
This inconsistency between combat and ability handlers suggests the need for:
The fix ensures both combat and ability execution paths now have consistent behavior.