Pokémon Sword and Shield merged friendship and affection, and as a result, merged the affection effects as well. This tutorial implements the chance to endure an attack that would otherwise cause the Pokémon to faint. This effect does not occur for enemy trainers or during link battles. ## Contents 1. [Add the Friendship Endure text](#1-add-the-friendship-endure-text) 2. [Update the ApplyDamage battle command](#2-update-the-applydamage-battle-command) ## 1. Add the Friendship Endure text In [data/text/battle.asm](../blob/master/data/text/battle.asm), we add in a new text string for when an attack is endured through friendship. ```diff EnduredText: text "" line "ENDURED the hit!" prompt +EnduredFriendshipText: + text "" + line "held on for you!" + prompt ``` ## 2. Update the ApplyDamage battle command Next, in [engine/battle/effect_commands.asm](../blob/master/engine/battle/effect_commands.asm), we need to find `BattleCommand_ApplyDamage` label. there are several changes to be made in this section ```diff BattleCommand_ApplyDamage: ld a, BATTLE_VARS_SUBSTATUS1_OPP call GetBattleVar bit SUBSTATUS_ENDURE, a - jr z, .focus_band + jr z, .friendship_endure call BattleCommand_FalseSwipe ld b, 0 jr nc, .damage ld b, 1 jr .damage +.friendship_endure + ld a, [wLinkMode] + cp LINK_COLOSSEUM + jr z, .focus_band + + ld hl, wBattleMonHappiness + ldh a, [hBattleTurn] + and a + jr z, .focus_band + + ld a, [hl] + cp 255 + jr z, .endure_64 + cp 220-1 + jr nc, .endure_48 + cp 180-1 + jr c, .focus_band +; 12.5% of 256 + ld b, 32 + jp .friendship_endure_checks +.endure_64 ; 25% of 256 + ld b, 64 + jp .friendship_endure_checks +.endure_48 ; 18.75% of 256 + ld b, 48 + jp .friendship_endure_checks + +.friendship_endure_checks + call BattleRandom + cp b + jr c, .focus_band + + call BattleCommand_FalseSwipe + ld b, 0 + jr nc, .damage + ld b, 3 + jr .damage + .focus_band ... .done_damage pop bc ld a, b and a ret z - dec a - jr nz, .focus_band_text - ld hl, EnduredText + dec a + jr z,.endured_text + dec a + jr z, .focus_band_text + ld hl, EnduredFriendshipText + jp StdBattleTextbox + +.endured_text + ld hl, EnduredText jp StdBattleTextbox .focus_band_text ... ```