From 67c7106fee57e293b6a96c435c0989c41f79cd76 Mon Sep 17 00:00:00 2001 From: Alex <93446519+AlexOn1ine@users.noreply.github.com> Date: Sun, 17 Nov 2024 09:59:04 +0100 Subject: [PATCH] Refactors Absorb to use Moveend (#5670) --- data/battle_scripts_1.s | 22 ++------ include/battle_scripts.h | 1 + include/constants/battle_script_commands.h | 1 + src/battle_script_commands.c | 38 ++++++++++++-- src/data/battle_move_effects.h | 2 +- src/data/moves_info.h | 9 ++++ test/battle/move_effect/absorb.c | 58 +++++++++++++++++++++- 7 files changed, 109 insertions(+), 22 deletions(-) diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index de8bcb92fc..bed58e3d1e 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -3012,30 +3012,18 @@ BattleScript_CantMakeAsleep:: orhalfword gMoveResultFlags, MOVE_RESULT_FAILED goto BattleScript_MoveEnd -BattleScript_EffectAbsorb:: - call BattleScript_EffectHit_Ret - jumpifstatus3 BS_ATTACKER, STATUS3_HEAL_BLOCK, BattleScript_AbsorbHealBlock - setdrainedhp - manipulatedamage DMG_BIG_ROOT - orword gHitMarker, HITMARKER_IGNORE_SUBSTITUTE | HITMARKER_IGNORE_DISGUISE - jumpifability BS_TARGET, ABILITY_LIQUID_OOZE, BattleScript_AbsorbLiquidOoze - setbyte cMULTISTRING_CHOOSER, B_MSG_ABSORB - goto BattleScript_AbsorbUpdateHp -BattleScript_AbsorbLiquidOoze:: +BattleScript_EffectAbsorbLiquidOoze:: call BattleScript_AbilityPopUpTarget - manipulatedamage DMG_CHANGE_SIGN - setbyte cMULTISTRING_CHOOSER, B_MSG_ABSORB_OOZE -BattleScript_AbsorbUpdateHp:: + goto BattleScript_EffectAbsorb + +BattleScript_EffectAbsorb:: healthbarupdate BS_ATTACKER datahpupdate BS_ATTACKER - jumpifmovehadnoeffect BattleScript_AbsorbTryFainting printfromtable gAbsorbDrainStringIds waitmessage B_WAIT_TIME_LONG -BattleScript_AbsorbTryFainting:: tryfaintmon BS_ATTACKER -BattleScript_AbsorbHealBlock:: tryfaintmon BS_TARGET - goto BattleScript_MoveEnd + return BattleScript_EffectExplosion:: attackcanceler diff --git a/include/battle_scripts.h b/include/battle_scripts.h index 27a4402aa2..a1722a511d 100644 --- a/include/battle_scripts.h +++ b/include/battle_scripts.h @@ -561,6 +561,7 @@ extern const u8 BattleScript_MoveBlockedByDynamax[]; // Battle move scripts extern const u8 BattleScript_EffectSleep[]; extern const u8 BattleScript_EffectAbsorb[]; +extern const u8 BattleScript_EffectAbsorbLiquidOoze[]; extern const u8 BattleScript_EffectExplosion[]; extern const u8 BattleScript_EffectDreamEater[]; extern const u8 BattleScript_EffectMirrorMove[]; diff --git a/include/constants/battle_script_commands.h b/include/constants/battle_script_commands.h index 6b162dc487..bfdfceb620 100644 --- a/include/constants/battle_script_commands.h +++ b/include/constants/battle_script_commands.h @@ -263,6 +263,7 @@ enum MoveEndEffects { MOVEEND_SUM_DAMAGE, MOVEEND_PROTECT_LIKE_EFFECT, + MOVEEND_ABSORB, MOVEEND_RAGE, MOVEEND_SYNCHRONIZE_TARGET, MOVEEND_ABILITIES, diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 0293e00f34..e9da9d62e8 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -5712,6 +5712,38 @@ static void Cmd_moveend(void) } gBattleScripting.moveendState++; break; + case MOVEEND_ABSORB: + if (gMovesInfo[gCurrentMove].effect == EFFECT_ABSORB) + { + if (gStatuses3[gBattlerAttacker] & STATUS3_HEAL_BLOCK && gMovesInfo[gCurrentMove].healingMove) + { + gBattleScripting.moveendState++; + break; + } + else if (IsBattlerAlive(gBattlerAttacker) && !(gMoveResultFlags & MOVE_RESULT_NO_EFFECT)) + { + gBattleMoveDamage = (gHpDealt * gMovesInfo[gCurrentMove].argument / 100); + if (gBattleMoveDamage == 0) + gBattleMoveDamage = 1; + gBattleMoveDamage = GetDrainedBigRootHp(gBattlerAttacker, gBattleMoveDamage); + gHitMarker |= HITMARKER_IGNORE_SUBSTITUTE | HITMARKER_IGNORE_DISGUISE; + if (GetBattlerAbility(gBattlerTarget) == ABILITY_LIQUID_OOZE) + { + gBattleMoveDamage *= -1; + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_ABSORB_OOZE; + BattleScriptPushCursor(); + gBattlescriptCurrInstr = BattleScript_EffectAbsorbLiquidOoze; + } + else + { + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_ABSORB; + BattleScriptPushCursor(); + gBattlescriptCurrInstr = BattleScript_EffectAbsorb; + } + } + } + gBattleScripting.moveendState++; + break; case MOVEEND_RAGE: // rage check if (gBattleMons[gBattlerTarget].status2 & STATUS2_RAGE && IsBattlerAlive(gBattlerTarget) @@ -11344,12 +11376,12 @@ static void Cmd_manipulatedamage(void) case DMG_FULL_ATTACKER_HP: gBattleMoveDamage = GetNonDynamaxMaxHP(gBattlerAttacker); break; - case DMG_CURR_ATTACKER_HP: - gBattleMoveDamage = GetNonDynamaxHP(gBattlerAttacker); - break; case DMG_BIG_ROOT: gBattleMoveDamage = GetDrainedBigRootHp(gBattlerAttacker, gBattleMoveDamage); break; + case DMG_CURR_ATTACKER_HP: + gBattleMoveDamage = GetNonDynamaxHP(gBattlerAttacker); + break; case DMG_RECOIL_FROM_IMMUNE: gBattleMoveDamage = GetNonDynamaxMaxHP(gBattlerTarget) / 2; break; diff --git a/src/data/battle_move_effects.h b/src/data/battle_move_effects.h index 956a2d0f23..b5b3e539c8 100644 --- a/src/data/battle_move_effects.h +++ b/src/data/battle_move_effects.h @@ -24,7 +24,7 @@ const struct BattleMoveEffect gBattleMoveEffects[NUM_BATTLE_MOVE_EFFECTS] = [EFFECT_ABSORB] = { - .battleScript = BattleScript_EffectAbsorb, + .battleScript = BattleScript_EffectHit, .battleTvScore = 4, }, diff --git a/src/data/moves_info.h b/src/data/moves_info.h index db5f2eaf75..1bde816281 100644 --- a/src/data/moves_info.h +++ b/src/data/moves_info.h @@ -1874,6 +1874,7 @@ const struct MoveInfo gMovesInfo[MOVES_COUNT_DYNAMAX] = .target = MOVE_TARGET_SELECTED, .priority = 0, .category = DAMAGE_CATEGORY_SPECIAL, + .argument = 50, .ignoresKingsRock = (B_UPDATED_MOVE_FLAGS == GEN_3 || B_UPDATED_MOVE_FLAGS == GEN_4), .healingMove = B_HEAL_BLOCKING >= GEN_6, .contestEffect = CONTEST_EFFECT_STARTLE_PREV_MON, @@ -1895,6 +1896,7 @@ const struct MoveInfo gMovesInfo[MOVES_COUNT_DYNAMAX] = .target = MOVE_TARGET_SELECTED, .priority = 0, .category = DAMAGE_CATEGORY_SPECIAL, + .argument = 50, .zMove = { .powerOverride = 120 }, .ignoresKingsRock = (B_UPDATED_MOVE_FLAGS == GEN_3 || B_UPDATED_MOVE_FLAGS == GEN_4), .healingMove = B_HEAL_BLOCKING >= GEN_6, @@ -3620,6 +3622,7 @@ const struct MoveInfo gMovesInfo[MOVES_COUNT_DYNAMAX] = .target = MOVE_TARGET_SELECTED, .priority = 0, .category = DAMAGE_CATEGORY_PHYSICAL, + .argument = 50, .makesContact = TRUE, .ignoresKingsRock = (B_UPDATED_MOVE_FLAGS == GEN_3 || B_UPDATED_MOVE_FLAGS == GEN_4), .healingMove = B_HEAL_BLOCKING >= GEN_6, @@ -5152,6 +5155,7 @@ const struct MoveInfo gMovesInfo[MOVES_COUNT_DYNAMAX] = .target = MOVE_TARGET_SELECTED, .priority = 0, .category = DAMAGE_CATEGORY_SPECIAL, + .argument = 50, .ignoresKingsRock = (B_UPDATED_MOVE_FLAGS == GEN_3 || B_UPDATED_MOVE_FLAGS == GEN_4), .healingMove = B_HEAL_BLOCKING >= GEN_6, .contestEffect = CONTEST_EFFECT_STARTLE_MON_WITH_JUDGES_ATTENTION, @@ -10264,6 +10268,7 @@ const struct MoveInfo gMovesInfo[MOVES_COUNT_DYNAMAX] = .target = MOVE_TARGET_SELECTED, .priority = 0, .category = DAMAGE_CATEGORY_PHYSICAL, + .argument = 50, .makesContact = TRUE, .punchingMove = TRUE, .healingMove = B_HEAL_BLOCKING >= GEN_6, @@ -13244,6 +13249,7 @@ const struct MoveInfo gMovesInfo[MOVES_COUNT_DYNAMAX] = .target = MOVE_TARGET_SELECTED, .priority = 0, .category = DAMAGE_CATEGORY_PHYSICAL, + .argument = 50, .makesContact = TRUE, .healingMove = B_HEAL_BLOCKING >= GEN_6, .contestEffect = CONTEST_EFFECT_STARTLE_MON_WITH_JUDGES_ATTENTION, @@ -14200,6 +14206,7 @@ const struct MoveInfo gMovesInfo[MOVES_COUNT_DYNAMAX] = .target = MOVE_TARGET_FOES_AND_ALLY, .priority = 0, .category = DAMAGE_CATEGORY_SPECIAL, + .argument = 50, .healingMove = B_HEAL_BLOCKING >= GEN_6, .contestEffect = CONTEST_EFFECT_STARTLE_MON_WITH_JUDGES_ATTENTION, .contestCategory = CONTEST_CATEGORY_BEAUTY, @@ -20021,6 +20028,7 @@ const struct MoveInfo gMovesInfo[MOVES_COUNT_DYNAMAX] = .target = MOVE_TARGET_SELECTED, .priority = 0, .category = DAMAGE_CATEGORY_PHYSICAL, + .argument = 50, .makesContact = TRUE, .slicingMove = TRUE, .healingMove = TRUE, @@ -20322,6 +20330,7 @@ const struct MoveInfo gMovesInfo[MOVES_COUNT_DYNAMAX] = .target = MOVE_TARGET_BOTH, .priority = 0, .category = DAMAGE_CATEGORY_SPECIAL, + .argument = 50, .thawsUser = TRUE, .metronomeBanned = TRUE, .healingMove = B_EXTRAPOLATED_MOVE_FLAGS, diff --git a/test/battle/move_effect/absorb.c b/test/battle/move_effect/absorb.c index 698ea41091..70c1b621af 100644 --- a/test/battle/move_effect/absorb.c +++ b/test/battle/move_effect/absorb.c @@ -24,6 +24,25 @@ SINGLE_BATTLE_TEST("Absorb recovers 50% of the damage dealt") } } +SINGLE_BATTLE_TEST("Absorb deals 50% of the damage dealt to user agains Liquid Ooze") +{ + s16 damage; + s16 healed; + GIVEN { + PLAYER(SPECIES_WOBBUFFET); + OPPONENT(SPECIES_TENTACOOL) { Ability(ABILITY_LIQUID_OOZE); } + } WHEN { + TURN { MOVE(player, MOVE_ABSORB); } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_ABSORB, player); + HP_BAR(opponent, captureDamage: &damage); + HP_BAR(player, captureDamage: &healed); + MESSAGE("Wobbuffet sucked up the liquid ooze!"); + } THEN { + EXPECT_MUL_EQ(damage, Q_4_12(0.5), healed); + } +} + SINGLE_BATTLE_TEST("Absorb fails if Heal Block applies") { GIVEN { @@ -69,5 +88,42 @@ DOUBLE_BATTLE_TEST("Matcha Gatcha recovers 50% of the damage dealt from both tar } } +DOUBLE_BATTLE_TEST("Matcha Gatcha will faint the pokemon if Liquid Ooze drain deals enough damage") +{ + GIVEN { + ASSUME(gMovesInfo[MOVE_MATCHA_GOTCHA].effect == EFFECT_ABSORB); + PLAYER(SPECIES_WOBBUFFET) { HP(1); } + PLAYER(SPECIES_WOBBUFFET); + OPPONENT(SPECIES_TENTACOOL) { Ability(ABILITY_LIQUID_OOZE); } + OPPONENT(SPECIES_WOBBUFFET); + } WHEN { + TURN { MOVE(playerLeft, MOVE_MATCHA_GOTCHA); } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_MATCHA_GOTCHA, playerLeft); + HP_BAR(opponentLeft); + HP_BAR(playerLeft); + MESSAGE("Wobbuffet sucked up the liquid ooze!"); + MESSAGE("Wobbuffet fainted!"); + } +} + + +SINGLE_BATTLE_TEST("Draining Kiss recovers 75% of the damage dealt") +{ + s16 damage; + s16 healed; + GIVEN { + PLAYER(SPECIES_WOBBUFFET) { HP(1); } + OPPONENT(SPECIES_WOBBUFFET); + } WHEN { + TURN { MOVE(player, MOVE_DRAINING_KISS); } + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_DRAINING_KISS, player); + HP_BAR(opponent, captureDamage: &damage); + HP_BAR(player, captureDamage: &healed); + } THEN { + EXPECT_MUL_EQ(damage, Q_4_12(-0.75), healed); + } +} + TO_DO_BATTLE_TEST("Absorb recovers 50% of the damage dealt to a Substitute"); -TO_DO_BATTLE_TEST("Draining Kiss recovers 75% of the damage dealt"); // Tests .argument 's implementation