@@ -483,4 +483,132 @@ contract BattleNadsAbilityTest is BattleNadsBaseTest {
483483 }
484484 }
485485 }
486+
487+ // =============================================================================
488+ // EQUIPMENT AND INVENTORY LOADING TESTS (Issue #20)
489+ // =============================================================================
490+
491+ /**
492+ * @dev Tests that equipment and inventory data are properly loaded when using abilities
493+ * This test verifies the fix for issue #20 where ability usage returned empty equipment data
494+ */
495+ function test_Ability_EquipmentAndInventoryLoading () public {
496+ bytes32 character = character1;
497+
498+ // First equip some items to the character by setting weapon and armor IDs
499+ _modifyCharacterStat (character, "weaponID " , 4 ); // Set weapon ID
500+ _modifyCharacterStat (character, "armorID " , 4 ); // Set armor ID
501+
502+ // Get character data before ability to verify equipment is set
503+ BattleNad memory beforeAbility = battleNads.getBattleNad (character);
504+ console.log ("=== Before Ability Usage === " );
505+ console.log ("Weapon ID: " , beforeAbility.stats.weaponID);
506+ console.log ("Armor ID: " , beforeAbility.stats.armorID);
507+ console.log ("Weapon Name: " , beforeAbility.weapon.name);
508+ console.log ("Armor Name: " , beforeAbility.armor.name);
509+
510+ // Verify character has equipment IDs
511+ assertTrue (beforeAbility.stats.weaponID > 0 , "Character should have weapon equipped " );
512+ assertTrue (beforeAbility.stats.armorID > 0 , "Character should have armor equipped " );
513+
514+ // Enter combat to use abilities
515+ bool combatStarted = _triggerRandomCombat (character);
516+ assertTrue (combatStarted, "Should enter combat " );
517+
518+ // Use a non-offensive ability (doesn't require target)
519+ vm.prank (userSessionKey1);
520+ battleNads.useAbility (character, 0 , 1 );
521+
522+ // Get character data after ability usage
523+ BattleNad memory afterAbility = battleNads.getBattleNad (character);
524+ console.log ("=== After Ability Usage === " );
525+ console.log ("Weapon ID: " , afterAbility.stats.weaponID);
526+ console.log ("Armor ID: " , afterAbility.stats.armorID);
527+ console.log ("Weapon Name: " , afterAbility.weapon.name);
528+ console.log ("Weapon Base Damage: " , afterAbility.weapon.baseDamage);
529+ console.log ("Armor Name: " , afterAbility.armor.name);
530+ console.log ("Armor Factor: " , afterAbility.armor.armorFactor);
531+ console.log ("Inventory Weapon Bitmap: " , afterAbility.inventory.weaponBitmap);
532+ console.log ("Inventory Armor Bitmap: " , afterAbility.inventory.armorBitmap);
533+
534+ // Verify equipment data is still loaded (not empty) after ability usage
535+ if (afterAbility.stats.weaponID > 0 ) {
536+ assertTrue (
537+ bytes (afterAbility.weapon.name).length > 0 || afterAbility.weapon.baseDamage > 0 ,
538+ "Weapon data should be loaded when weapon is equipped "
539+ );
540+ }
541+
542+ if (afterAbility.stats.armorID > 0 ) {
543+ assertTrue (
544+ bytes (afterAbility.armor.name).length > 0 || afterAbility.armor.armorFactor > 0 ,
545+ "Armor data should be loaded when armor is equipped "
546+ );
547+ }
548+
549+ // Verify inventory data is loaded
550+ assertTrue (
551+ afterAbility.inventory.weaponBitmap > 0 || afterAbility.inventory.armorBitmap > 0 || afterAbility.inventory.balance > 0 ,
552+ "Inventory data should be loaded "
553+ );
554+
555+ console.log ("Equipment and inventory data properly loaded during ability usage! " );
556+ }
557+
558+ /**
559+ * @dev Tests equipment loading for offensive abilities with targets
560+ */
561+ function test_Ability_OffensiveWithEquipmentLoading () public {
562+ bytes32 attacker = character1;
563+ bytes32 defender = character2;
564+
565+ // Equip items to both characters by setting weapon and armor IDs
566+ _modifyCharacterStat (attacker, "weaponID " , 3 ); // Set weapon ID
567+ _modifyCharacterStat (attacker, "armorID " , 3 ); // Set armor ID
568+ _modifyCharacterStat (defender, "weaponID " , 5 ); // Set weapon ID
569+ _modifyCharacterStat (defender, "armorID " , 5 ); // Set armor ID
570+
571+ // Enter combat
572+ bool combatStarted = _triggerRandomCombat (attacker);
573+ assertTrue (combatStarted, "Should enter combat " );
574+
575+ // Find target for offensive ability
576+ uint256 targetIndex = _findCombatTarget (attacker);
577+ assertTrue (targetIndex > 0 , "Should find valid target " );
578+
579+ // Determine offensive ability index based on class
580+ BattleNad memory attackerData = battleNads.getBattleNad (attacker);
581+ uint256 offensiveAbilityIndex = attackerData.stats.class == CharacterClass.Warrior ? 1 : 2 ;
582+
583+ // Use offensive ability
584+ vm.prank (userSessionKey1);
585+ battleNads.useAbility (attacker, targetIndex, offensiveAbilityIndex);
586+
587+ // Get updated attacker data
588+ BattleNad memory afterAbility = battleNads.getBattleNad (attacker);
589+
590+ // Verify both attacker's equipment is loaded
591+ console.log ("=== Attacker Equipment After Offensive Ability === " );
592+ console.log ("Weapon ID: " , afterAbility.stats.weaponID);
593+ console.log ("Weapon Name: " , afterAbility.weapon.name);
594+ console.log ("Armor ID: " , afterAbility.stats.armorID);
595+ console.log ("Armor Name: " , afterAbility.armor.name);
596+
597+ if (afterAbility.stats.weaponID > 0 ) {
598+ assertTrue (
599+ bytes (afterAbility.weapon.name).length > 0 || afterAbility.weapon.baseDamage > 0 ,
600+ "Attacker weapon data should be loaded "
601+ );
602+ }
603+
604+ if (afterAbility.stats.armorID > 0 ) {
605+ assertTrue (
606+ bytes (afterAbility.armor.name).length > 0 || afterAbility.armor.armorFactor > 0 ,
607+ "Attacker armor data should be loaded "
608+ );
609+ }
610+
611+ // The defender's equipment should also be loaded in the handler
612+ console.log ("Offensive ability with equipment loading test passed! " );
613+ }
486614}
0 commit comments