From cb5b673f8a5a79027e5e21ade62c96305fa011d0 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 13 Apr 2020 15:00:17 +0200 Subject: [PATCH] Big Root and STRENGTH Sap --- asm/macros/battle_script.inc | 10 +++++ data/battle_scripts_1.s | 49 +++++++++++++++++++++- include/battle_util.h | 1 + include/constants/battle_move_effects.h | 1 + include/constants/battle_script_commands.h | 3 ++ src/battle_script_commands.c | 16 +++++++ src/battle_util.c | 21 ++++++---- src/data/battle_moves.h | 2 +- 8 files changed, 93 insertions(+), 10 deletions(-) diff --git a/asm/macros/battle_script.inc b/asm/macros/battle_script.inc index fc8ecf8257..8fa8c2d94a 100644 --- a/asm/macros/battle_script.inc +++ b/asm/macros/battle_script.inc @@ -1678,6 +1678,16 @@ .byte \val .endm + .macro getstatvalue battler:req, statId:req + various \battler, VARIOUS_GET_STAT_VALUE + .byte \statId + .endm + + .macro jumpiffullhp battler:req, ptr:req + various \battler, VARIOUS_JUMP_IF_FULL_HP + .4byte \ptr + .endm + @ helpful macros .macro setstatchanger stat:req, stages:req, down:req setbyte sSTATCHANGER \stat | \stages << 3 | \down << 7 diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 2d0a530444..4e91dd84e6 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -355,6 +355,53 @@ gBattleScriptsForMoveEffects:: @ 82D86A8 .4byte BattleScript_EffectGearUp .4byte BattleScript_EffectIncinerate .4byte BattleScript_EffectBugBite + .4byte BattleScript_EffectStrengthSap + +BattleScript_EffectStrengthSap: + setstatchanger STAT_ATK, 1, TRUE + attackcanceler + jumpifsubstituteblocks BattleScript_ButItFailedAtkStringPpReduce + accuracycheck BattleScript_PrintMoveMissed, ACC_CURR_MOVE + attackstring + ppreduce + jumpifstat BS_TARGET, CMP_NOT_EQUAL, STAT_ATK, 0, BattleScript_StrengthSapTryLower + pause 0x20 + statbuffchange STAT_BUFF_ALLOW_PTR, BattleScript_MoveEnd + printfromtable gStatDownStringIds + waitmessage 0x40 + goto BattleScript_MoveEnd +BattleScript_StrengthSapTryLower: + getstatvalue BS_TARGET, STAT_ATK + jumpiffullhp BS_ATTACKER, BattleScript_StrengthSapMustLower + attackanimation + waitanimation + statbuffchange STAT_BUFF_ALLOW_PTR, BattleScript_StrengthSapHp + jumpifbyte CMP_EQUAL, cMULTISTRING_CHOOSER, 0x3, BattleScript_StrengthSapHp +BattleScript_StrengthSapLower: + setgraphicalstatchangevalues + playanimation BS_TARGET, B_ANIM_STATS_CHANGE, sB_ANIM_ARG1 + printfromtable gStatDownStringIds + waitmessage 0x40 + goto BattleScript_StrengthSapHp +@ Drain HP without lowering a stat +BattleScript_StrengthSapTryHp: + jumpiffullhp BS_ATTACKER, BattleScript_ButItFailed + attackanimation + waitanimation +BattleScript_StrengthSapHp: + jumpiffullhp BS_ATTACKER, BattleScript_MoveEnd + manipulatedamage DMG_BIG_ROOT + healthbarupdate BS_ATTACKER + datahpupdate BS_ATTACKER + printstring STRINGID_PKMNENERGYDRAINED + waitmessage 0x40 + goto BattleScript_MoveEnd +BattleScript_StrengthSapMustLower: + statbuffchange STAT_BUFF_ALLOW_PTR, BattleScript_MoveEnd + jumpifbyte CMP_EQUAL, cMULTISTRING_CHOOSER, 0x3, BattleScript_MoveEnd + attackanimation + waitanimation + goto BattleScript_StrengthSapLower BattleScript_EffectBugBite: setmoveeffect MOVE_EFFECT_BUG_BITE | MOVE_EFFECT_CERTAIN @@ -5196,7 +5243,7 @@ BattleScript_LeechSeedTurnDrain:: datahpupdate BS_ATTACKER copyword gBattleMoveDamage, gHpDealt jumpifability BS_ATTACKER, ABILITY_LIQUID_OOZE, BattleScript_LeechSeedTurnPrintLiquidOoze - manipulatedamage DMG_CHANGE_SIGN + manipulatedamage DMG_BIG_ROOT setbyte cMULTISTRING_CHOOSER, 0x3 goto BattleScript_LeechSeedTurnPrintAndUpdateHp BattleScript_LeechSeedTurnPrintLiquidOoze:: diff --git a/include/battle_util.h b/include/battle_util.h index 92d798f7b2..a7a723221f 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -66,6 +66,7 @@ u8 CheckMoveLimitations(u8 battlerId, u8 unusableMoves, u8 check); bool8 AreAllMovesUnusable(void); u8 GetImprisonedMovesCount(u8 battlerId, u16 move); u8 DoFieldEndTurnEffects(void); +s32 GetDrainedBigRootHp(u32 battler, s32 hp); u8 DoBattlerEndTurnEffects(void); bool8 HandleWishPerishSongOnTurnEnd(void); bool8 HandleFaintedMonActions(void); diff --git a/include/constants/battle_move_effects.h b/include/constants/battle_move_effects.h index ea4a76591e..738da3575e 100644 --- a/include/constants/battle_move_effects.h +++ b/include/constants/battle_move_effects.h @@ -343,5 +343,6 @@ #define EFFECT_GEAR_UP 337 #define EFFECT_INCINERATE 338 #define EFFECT_BUG_BITE 339 +#define EFFECT_STRENGTH_SAP 340 #endif // GUARD_CONSTANTS_BATTLE_MOVE_EFFECTS_H diff --git a/include/constants/battle_script_commands.h b/include/constants/battle_script_commands.h index 4e690ab5ea..4d426134c9 100644 --- a/include/constants/battle_script_commands.h +++ b/include/constants/battle_script_commands.h @@ -146,6 +146,8 @@ #define VARIOUS_TRY_ILLUSION_OFF 83 #define VARIOUS_SET_SPRITEIGNORE0HP 84 #define VARIOUS_HANDLE_FORM_CHANGE 85 +#define VARIOUS_GET_STAT_VALUE 86 +#define VARIOUS_JUMP_IF_FULL_HP 87 // Cmd_manipulatedmg #define DMG_CHANGE_SIGN 0 @@ -154,6 +156,7 @@ #define DMG_1_8_TARGET_HP 3 #define DMG_FULL_ATTACKER_HP 4 #define DMG_CURR_ATTACKER_HP 5 +#define DMG_BIG_ROOT 6 // Cmd_jumpifcantswitch #define SWITCH_IGNORE_ESCAPE_PREVENTION 0x80 diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index e524221e79..b4876cb50a 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -6789,6 +6789,19 @@ static void Cmd_various(void) else gBattlescriptCurrInstr += 7; return; + case VARIOUS_GET_STAT_VALUE: + i = gBattlescriptCurrInstr[3]; + gBattleMoveDamage = *(u16*)(&gBattleMons[gActiveBattler].attack) + (i - 1); + gBattleMoveDamage *= gStatStageRatios[gBattleMons[gActiveBattler].statStages[i]][0]; + gBattleMoveDamage /= gStatStageRatios[gBattleMons[gActiveBattler].statStages[i]][1]; + gBattlescriptCurrInstr += 4; + return; + case VARIOUS_JUMP_IF_FULL_HP: + if (BATTLER_MAX_HP(gActiveBattler)) + gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 3); + else + gBattlescriptCurrInstr += 7; + return; case VARIOUS_TRACE_ABILITY: gBattleMons[gActiveBattler].ability = gBattleStruct->tracedAbility[gActiveBattler]; break; @@ -8094,6 +8107,9 @@ static void Cmd_manipulatedamage(void) case DMG_CURR_ATTACKER_HP: gBattleMoveDamage = gBattleMons[gBattlerAttacker].hp; break; + case DMG_BIG_ROOT: + gBattleMoveDamage = GetDrainedBigRootHp(gBattlerAttacker, gBattleMoveDamage); + break; } gBattlescriptCurrInstr += 2; diff --git a/src/battle_util.c b/src/battle_util.c index 9ae9c1843b..8fd6084937 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -1395,6 +1395,17 @@ enum ENDTURN_BATTLER_COUNT }; +// Ingrain, Leech Seed, Strength Sap and Aqua Ring +s32 GetDrainedBigRootHp(u32 battler, s32 hp) +{ + if (GetBattlerHoldEffect(battler, TRUE) == HOLD_EFFECT_BIG_ROOT) + hp = (hp * 1300) / 1000; + if (hp == 0) + hp = 1; + + return hp * -1; +} + u8 DoBattlerEndTurnEffects(void) { u32 ability, effect = 0; @@ -1418,10 +1429,7 @@ u8 DoBattlerEndTurnEffects(void) && !(gStatuses3[gActiveBattler] & STATUS3_HEAL_BLOCK) && gBattleMons[gActiveBattler].hp != 0) { - gBattleMoveDamage = gBattleMons[gActiveBattler].maxHP / 16; - if (gBattleMoveDamage == 0) - gBattleMoveDamage = 1; - gBattleMoveDamage *= -1; + gBattleMoveDamage = GetDrainedBigRootHp(gActiveBattler, gBattleMons[gActiveBattler].maxHP / 16); BattleScriptExecute(BattleScript_IngrainTurnHeal); effect++; } @@ -1433,10 +1441,7 @@ u8 DoBattlerEndTurnEffects(void) && !(gStatuses3[gActiveBattler] & STATUS3_HEAL_BLOCK) && gBattleMons[gActiveBattler].hp != 0) { - gBattleMoveDamage = gBattleMons[gActiveBattler].maxHP / 16; - if (gBattleMoveDamage == 0) - gBattleMoveDamage = 1; - gBattleMoveDamage *= -1; + gBattleMoveDamage = GetDrainedBigRootHp(gActiveBattler, gBattleMons[gActiveBattler].maxHP / 16); BattleScriptExecute(BattleScript_AquaRingHeal); effect++; } diff --git a/src/data/battle_moves.h b/src/data/battle_moves.h index 52981da1ee..ae054262b4 100644 --- a/src/data/battle_moves.h +++ b/src/data/battle_moves.h @@ -8858,7 +8858,7 @@ const struct BattleMove gBattleMoves[MOVES_COUNT] = [MOVE_STRENGTH_SAP] = { - .effect = EFFECT_PLACEHOLDER, + .effect = EFFECT_STRENGTH_SAP, .power = 0, .type = TYPE_GRASS, .accuracy = 100,