void final_damagecalc_cmd7() { battlescripts_curr_instruction++; if (damage_loc == 0) damage_loc = 1; if (!affected_by_substitute(bank_target)) { u16 target_hp = battle_participants[bank_target].current_hp; if (protect_structs[bank_target].flag0_endure && damage_loc > target_hp) { damage_loc = target_hp - 1; move_outcome.endured = 1; } else if ((current_move == MOVE_FALSE_SWIPE || current_move == MOVE_HOLD_BACK) && damage_loc > target_hp && !(move_outcome.failed || move_outcome.missed || move_outcome.not_affected)) { damage_loc = target_hp - 1; } else if (battle_participants[bank_target].ability_id == ABILITY_STURDY && has_ability_effect(bank_target, 1, 1) && damage_loc > target_hp && target_hp == battle_participants[bank_target].max_hp) { damage_loc = target_hp - 1; move_outcome.sturdied = 1; } else { switch (get_item_effect(bank_target, 1)) { case ITEM_EFFECT_FOCUSSASH: if (damage_loc > target_hp && target_hp == battle_participants[bank_target].max_hp) { damage_loc = target_hp - 1; move_outcome.hanged_on_using_item = 1; last_used_item = battle_participants[bank_target].held_item; battle_participants[bank_target].held_item = 0; active_bank = bank_target; prepare_setattributes_in_battle(0, 2, 0, 2, &battle_participants[bank_target].held_item); mark_buffer_bank_for_execution(bank_target); } break; case ITEM_EFFECT_FOCUSBAND: if (damage_loc > target_hp && (__umodsi3(rng(), 100) + 1) < get_all_item_quality(bank_target)) { damage_loc = target_hp - 1; move_outcome.hanged_on_using_item = 1; last_used_item = battle_participants[bank_target].held_item; } break; } } } return; }
u8 affected_by_substitute(u8 substitute_bank) { if (battle_participants[substitute_bank].status2.substitute) { if (!(hitmarker & HITMARKER_IGNORE_SUBSTITUTE || disable_structs[substitute_bank].substitute_hp == 0 || (has_ability_effect(bank_attacker, 0, 1) && battle_participants[bank_attacker].ability_id == ABILITY_INFILTRATOR && bank_attacker != substitute_bank) || find_move_in_table(current_move, &sound_moves[0]))) { return true; } } return false;; }
void atk07_final_dmg_calc(void) { if (battle_execution_buffer) {return;} battlescripts_curr_instruction++; if(battle_participants[bank_target].species == POKE_MIMIKKYU && check_ability(bank_target,ABILITY_DISGUISE) && has_ability_effect(bank_target, 1, 1) && MOVE_WORKED && !affected_by_substitute(bank_target)) { new_battlestruct->various.bust_mimikyu = 1; damage_loc = 0; move_outcome.super_effective = 0; move_outcome.not_very_effective = 0; move_outcome.one_hit_ko = 0; } else { if (new_battlestruct->various.berry_damage_redux) { u16 item = battle_participants[bank_target].held_item; new_battlestruct->various.berry_damage_redux = 0; if (MOVE_WORKED && DAMAGING_MOVE(current_move) && item) { battle_scripting.active_bank = bank_target; last_used_item = item; bs_push_current(BS_BERRY_DMG_REDUCE); setup_berry_consume_buffers(bank_target); } } damage_loc = ATLEAST_ONE(damage_loc); if (!affected_by_substitute(bank_target)) { u16 target_hp = battle_participants[bank_target].current_hp; if (protect_structs[bank_target].flag0_endure && damage_loc > target_hp) { damage_loc = target_hp - 1; move_outcome.endured = 1; } else if ((current_move == MOVE_FALSE_SWIPE || current_move == MOVE_HOLD_BACK) && damage_loc > target_hp && !(move_outcome.failed || move_outcome.missed || move_outcome.not_affected)) { damage_loc = target_hp - 1; } else if (battle_participants[bank_target].ability_id == ABILITY_STURDY && has_ability_effect(bank_target, 1, 1) && damage_loc > target_hp && target_hp == battle_participants[bank_target].max_hp) { damage_loc = target_hp - 1; move_outcome.sturdied = 1; } else { switch (get_item_effect(bank_target, 1)) { case ITEM_EFFECT_FOCUSSASH: if (damage_loc > target_hp && target_hp == battle_participants[bank_target].max_hp) { damage_loc = target_hp - 1; move_outcome.hanged_on_using_item = 1; last_used_item = battle_participants[bank_target].held_item; battle_participants[bank_target].held_item = 0; active_bank = bank_target; bb2_setattributes_in_battle(0, 2, 0, 2, &battle_participants[bank_target].held_item); mark_buffer_bank_for_execution(bank_target); } break; case ITEM_EFFECT_FOCUSBAND: if (damage_loc > target_hp && (__umodsi3(rng(), 100) + 1) < get_all_item_quality(bank_target)) { damage_loc = target_hp - 1; move_outcome.hanged_on_using_item = 1; last_used_item = battle_participants[bank_target].held_item; } break; } } } } }
u8 change_stats(struct stat stat_change, u8 stat, struct failbank bank, void* battlescript_if_fails) { if (stat_change.decrement) battle_scripting.stat_changer |= 0x80; else battle_scripting.stat_changer &= 0x7F; u8 fail = 0; if (bank.attacker) { active_bank = bank_attacker; battle_scripting.active_bank = bank_attacker; } else { active_bank = bank_target; battle_scripting.active_bank = bank_target; } battle_text_buff1[0] = 0xFD; battle_text_buff1[1] = 5; battle_text_buff1[2] = stat; battle_text_buff1[3] = 0xFF; u8 has_ability=has_ability_effect(active_bank, !bank.attacker, 1); if (has_ability) { if (battle_participants[active_bank].ability_id == ABILITY_CONTRARY) { stat_change.decrement ^= 1; battle_scripting.stat_changer ^= 0x80; record_usage_of_ability(active_bank, ABILITY_CONTRARY); } else if (battle_participants[active_bank].ability_id == ABILITY_SIMPLE) { if ((stat_change.how_much * 2) > 7) { stat_change.how_much = 7; } else { stat_change.how_much *= 2; } record_usage_of_ability(active_bank, ABILITY_SIMPLE); } } u8* stat_ptr = &battle_participants[active_bank].hp_buff; stat_ptr += stat; if (stat_change.decrement) //we're lowering stats { if (side_affecting_halfword[get_battle_side(active_bank) & 1].mist_on && current_move != MOVE_CURSE && bank.cannotfail == 0) { if (special_statuses[active_bank].statloweringflag) { battlescripts_curr_instruction = battlescript_if_fails; } else { ability_affects_stat_reduction(active_bank,(void*) 0x082DAE03, battlescript_if_fails, 0); special_statuses[active_bank].statloweringflag = 1; } return 1; } else if (does_protect_affect_move(0) && current_move != MOVE_CURSE && bank.ignore_opponent_protect == 0) { battlescripts_curr_instruction = (void*) 0x082D9F1C; return 1; } else if (has_ability && (battle_participants[active_bank].ability_id == ABILITY_WHITE_SMOKE || battle_participants[active_bank].ability_id == ABILITY_CLEAR_BODY) && current_move != MOVE_CURSE && bank.cannotfail == 0) { if (special_statuses[active_bank].statloweringflag) { battlescripts_curr_instruction = battlescript_if_fails; } else { ability_affects_stat_reduction(active_bank, (void*) 0x082DB5C7, battlescript_if_fails, 1); special_statuses[active_bank].statloweringflag = 1; } return 1; } if (current_move != MOVE_CURSE && bank.cannotfail == 0 && is_of_type(active_bank, TYPE_GRASS)) { u8 flower = ability_battle_effects(13, active_bank, ABILITY_FLOWER_VEIL, 1, 0); if (flower) { if (special_statuses[active_bank].statloweringflag && battlescript_if_fails) battlescripts_curr_instruction = battlescript_if_fails; else { ability_affects_stat_reduction(flower - 1, (void*) 0x082DB5C7, battlescript_if_fails, 1); special_statuses[active_bank].statloweringflag = 1; } } } if (has_ability && battle_participants[active_bank].ability_id == ABILITY_KEEN_EYE && stat == STAT_ACCURACY && bank.cannotfail == 0) { if (!bank.failsth) { } else { ability_affects_stat_reduction(active_bank, (void*)0x082DB62F, battlescript_if_fails, 1); } return 1; } else if (has_ability && battle_participants[active_bank].ability_id == ABILITY_HYPER_CUTTER && stat == STAT_ATTACK && bank.cannotfail == 0) { if (!bank.failsth) { } else { ability_affects_stat_reduction(active_bank,(void*) 0x082DB62F, battlescript_if_fails, 1); } return 1; } else if (has_ability && battle_participants[active_bank].ability_id == ABILITY_BIG_PECKS && stat == STAT_DEFENCE && bank.cannotfail == 0) { if (!bank.failsth) { } else { ability_affects_stat_reduction(active_bank,(void*) 0x082DB62F, battlescript_if_fails, 1); } return 1; } else if (has_ability && battle_participants[active_bank].ability_id == ABILITY_SHIELD_DUST && bank.failsth == 0) { return 1; } else { if (*stat_ptr == 0) { battle_communication_struct.multistring_chooser = 2; if (bank.failsth) { move_outcome.missed = 1; fail = 0; } else { fail = 1; } } else { if (active_bank == bank_target) { battle_communication_struct.multistring_chooser = 1; } else { battle_communication_struct.multistring_chooser = 0; } u8 lowered_stats = 0; u8 amount = 0; battle_scripting.stat_changer &= 0x8F; while (stat_change.how_much != 0) { stat_change.how_much--; *stat_ptr -= 1; lowered_stats++; amount += 0x10; if (*stat_ptr == 0) break; } battle_scripting.stat_changer ^= amount; u8 i = 2; battle_text_buff2[0] = 0xFD; battle_text_buff2[1] = 0; if (lowered_stats == 2) { battle_text_buff2[2] = 0xD3; battle_text_buff2[3] = 0; battle_text_buff2[4] = 0; i += 3; } else if (lowered_stats >= 3) { battle_text_buff2[2] = 0x97; battle_text_buff2[3] = 1; battle_text_buff2[4] = 0; i += 3; } battle_text_buff2[i] = 0xD4; battle_text_buff2[i + 1] = 0; battle_text_buff2[i + 2] = 0xFF; } } } else // we're raising stats { if (*stat_ptr == 0xC) { battle_communication_struct.multistring_chooser = 2; if (bank.failsth) { move_outcome.missed = 1; fail = 0; } else { fail = 1; } } else { if (active_bank == bank_target) { battle_communication_struct.multistring_chooser = 1; } else { battle_communication_struct.multistring_chooser = 0; } u8 raised_stats = 0; u8 amount = 0; battle_scripting.stat_changer &= 0x8F; while (stat_change.how_much != 0) { stat_change.how_much--; *stat_ptr += 1; raised_stats++; amount += 0x10; if (*stat_ptr == 0xC) break; } battle_scripting.stat_changer ^= amount; u8 i = 2; battle_text_buff2[0] = 0xFD; battle_text_buff2[1] = 0; if (raised_stats == 2) { battle_text_buff2[2] = 0xD1; battle_text_buff2[3] = 0; battle_text_buff2[4] = 0; i += 3; } else if (raised_stats >= 3) { battle_text_buff2[2] = 0x97; battle_text_buff2[3] = 1; battle_text_buff2[4] = 0; i += 3; } battle_text_buff2[i] = 0xD2; battle_text_buff2[i + 1] = 0; battle_text_buff2[i + 2] = 0xFF; } } if (fail == 0 && battle_communication_struct.multistring_chooser != 2 && stat_change.decrement && has_ability && active_bank != bank_attacker) new_battlestruct.ptr->bank_affecting[active_bank].stat_lowered = 1; return fail; }