#include "macros/btlcmd.inc"


_000:
    CheckBlackOut BTLSCR_DEFENDER, _172
    TryReplaceFaintedMon BTLSCR_ATTACKER, TRUE, _172
    TriggerAbilityOnHit _010
    CallFromVar BTLVAR_SCRIPT_TEMP

_010:
    TriggerHeldItemOnPivotMove _014
    CallFromVar BTLVAR_SCRIPT_TEMP

_014:
    CompareMonDataToValue OPCODE_NEQ, BTLSCR_DEFENDER, BATTLEMON_CUR_HP, 0, _079
    CompareMonDataToValue OPCODE_FLAG_NOT, BTLSCR_DEFENDER, BATTLEMON_VOLATILE_STATUS, VOLATILE_CONDITION_DESTINY_BOND, _079
    IfSameSide BTLSCR_ATTACKER, BTLSCR_DEFENDER, _079
    CompareMonDataToValue OPCODE_EQU, BTLSCR_ATTACKER, BATTLEMON_CUR_HP, 0, _079
    // {0} took {1} down with it!
    PrintMessage pl_msg_00000368_00391, TAG_NICKNAME_NICKNAME, BTLSCR_DEFENDER, BTLSCR_ATTACKER
    UpdateMonDataFromVar OPCODE_GET, BTLSCR_ATTACKER, BATTLEMON_CUR_HP, BTLVAR_HP_CALC_TEMP
    UpdateVar OPCODE_MUL, BTLVAR_HP_CALC_TEMP, -1
    UpdateVarFromVar OPCODE_SET, BTLVAR_MSG_BATTLER_TEMP, BTLVAR_ATTACKER
    UpdateVar OPCODE_FLAG_ON, BTLVAR_BATTLE_CTX_STATUS, SYSCTL_SKIP_SPRITE_BLINK
    Call BATTLE_SUBSCRIPT_UPDATE_HP
    PlayFaintAnimation 
    Wait 
    HealthbarSlideOut BTLSCR_FAINTED_MON
    // {0} fainted!
    PrintMessage pl_msg_00000368_00030, TAG_NICKNAME, BTLSCR_FAINTED_MON
    Wait 
    WaitButtonABTime 30
    IncrementGameRecord BTLSCR_FAINTED_MON, BATTLER_TYPE_SOLO_ENEMY, RECORD_FAINTED_IN_BATTLE
    IncrementGameRecord BTLSCR_FAINTED_MON, BATTLER_TYPE_SOLO_PLAYER, RECORD_FAINTED_ENEMY_MON

_079:
    UpdateVarFromVar OPCODE_GET, BTLVAR_FAINTED_MON, BTLVAR_LAST_BATTLER_ID
    UpdateVarFromVar OPCODE_SET, BTLVAR_FAINTED_MON, BTLVAR_DEFENDER
    CompareMonDataToValue OPCODE_NEQ, BTLSCR_DEFENDER, BATTLEMON_CUR_HP, 0, _103
    TryGrudge _103
    // {0}’s {1} lost all its PP due to the grudge!
    PrintMessage pl_msg_00000368_00568, TAG_NICKNAME_MOVE, BTLSCR_ATTACKER, BTLSCR_MSG_TEMP
    Wait 
    WaitButtonABTime 30

_103:
    UpdateVarFromVar OPCODE_SET, BTLVAR_FAINTED_MON, BTLVAR_LAST_BATTLER_ID
    CompareMonDataToValue OPCODE_EQU, BTLSCR_ATTACKER, BATTLEMON_CUR_HP, 0, _172
    UpdateVarFromVar OPCODE_SET, BTLVAR_SWITCHED_MON, BTLVAR_ATTACKER
    // {0} went back to {1}!
    PrintMessage pl_msg_00000368_01067, TAG_NICKNAME_TRNAME, BTLSCR_SWITCHED_MON, BTLSCR_SWITCHED_MON
    Wait 
    WaitButtonABTime 30
    Call BATTLE_SUBSCRIPT_PURSUIT
    CompareMonDataToValue OPCODE_EQU, BTLSCR_ATTACKER, BATTLEMON_CUR_HP, 0, _172
    TryRestoreStatusOnSwitch BTLSCR_ATTACKER, _141
    UpdateMonData OPCODE_SET, BTLSCR_ATTACKER, BATTLEMON_STATUS, MON_CONDITION_NONE

_141:
    UpdateVar OPCODE_FLAG_OFF, BTLVAR_BATTLE_CTX_STATUS, SYSCTL_PLAYED_MOVE_ANIMATION
    UpdateVar OPCODE_SET, BTLVAR_MOVE_EFFECT_CHANCE, 1
    PlayMoveAnimation BTLSCR_ATTACKER
    Wait 
    DeletePokemon BTLSCR_ATTACKER
    Wait 
    HealthbarSlideOut BTLSCR_ATTACKER
    Wait 
    UpdateVar OPCODE_FLAG_ON, BTLVAR_BATTLE_CTX_STATUS_2, SYSCTL_UTURN_ACTIVE
    UpdateVar OPCODE_FLAG_OFF, BTLVAR_BATTLE_CTX_STATUS, SYSCTL_TRY_SYNCHRONIZE_STATUS
    UpdateVar OPCODE_SET, BTLVAR_ATTACKER_SELF_TURN_STATUS_FLAGS, SELF_TURN_FLAG_CLEAR
    GoToSubscript BATTLE_SUBSCRIPT_SHOW_PARTY_LIST

_172:
    End 
