From 7d3980de589d0c645c9f31838937b0da463a8611 Mon Sep 17 00:00:00 2001 From: BuffelSaft Date: Sun, 12 Sep 2021 18:33:04 +1200 Subject: [PATCH 1/8] Fix multihit moves vs damage reducing berries The extra waitmessage command is ugly but appears to be needed - if it's moved before the printstring, the message isn't displayed long enough on single hit moves. --- data/battle_scripts_1.s | 1 + src/battle_script_commands.c | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 2d6db5a28..7c37be63c 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -7519,6 +7519,7 @@ BattleScript_BerryReduceDmg:: BattleScript_PrintBerryReduceString:: waitmessage B_WAIT_TIME_LONG printstring STRINGID_BERRYDMGREDUCES + waitmessage B_WAIT_TIME_LONG return BattleScript_BerryCureConfusionEnd2:: diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 05702aec6..c7df3406e 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -1967,6 +1967,15 @@ static void Cmd_multihitresultmessage(void) } } gBattlescriptCurrInstr++; + + // Print berry reducing message after result message. + if (gSpecialStatuses[gBattlerTarget].berryReduced + && !(gMoveResultFlags & MOVE_RESULT_NO_EFFECT)) + { + gSpecialStatuses[gBattlerTarget].berryReduced = 0; + BattleScriptPushCursor(); + gBattlescriptCurrInstr = BattleScript_PrintBerryReduceString; + } } static void Cmd_attackanimation(void) From 6eced3f7a439010ce03e600b028d8c11fb7c2929 Mon Sep 17 00:00:00 2001 From: BuffelSaft Date: Wed, 22 Sep 2021 11:53:44 +1200 Subject: [PATCH 2/8] Fix Download Raises user's stat instead of a random target's, and determines stat boosts using the opposing Pokemon's stats. --- src/battle_util.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/battle_util.c b/src/battle_util.c index ccc0c558a..fdc4277d8 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -4045,7 +4045,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move u32 opposingDef = 0, opposingSpDef = 0; opposingBattler = BATTLE_OPPOSITE(battler); - for (i = 0; i < 2; opposingBattler ^= BIT_SIDE, i++) + for (i = 0; i < 2; opposingBattler ^= BIT_FLANK, i++) { if (IsBattlerAlive(opposingBattler)) { @@ -4069,6 +4069,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move { gBattleMons[battler].statStages[statId]++; SET_STATCHANGER(statId, 1, FALSE); + gBattlerAttacker = battler; PREPARE_STAT_BUFFER(gBattleTextBuff1, statId); BattleScriptPushCursorAndCallback(BattleScript_AttackerAbilityStatRaiseEnd3); effect++; From b65b27c0dd7dc1e51a80ee5dca14db43288d60a2 Mon Sep 17 00:00:00 2001 From: Eduardo Quezada D'Ottone Date: Wed, 22 Sep 2021 00:20:34 -0300 Subject: [PATCH 3/8] Adds missing check for Egg in Illusion --- src/battle_util.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/battle_util.c b/src/battle_util.c index 0f18efb9a..fce7c1eeb 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -8746,6 +8746,7 @@ bool32 SetIllusionMon(struct Pokemon *mon, u32 battlerId) id = i; if (GetMonData(&party[id], MON_DATA_SANITY_HAS_SPECIES) && GetMonData(&party[id], MON_DATA_HP) + && !GetMonData(&party[id], MON_DATA_IS_EGG) && &party[id] != mon && &party[id] != partnerMon) { From 35af7a9cc1b614d12578ff87cea699ee9dd76aa9 Mon Sep 17 00:00:00 2001 From: BuffelSaft Date: Wed, 22 Sep 2021 15:44:13 +1200 Subject: [PATCH 4/8] Fix Foul Play if != else if. Pretty sure I broke this when adding Body Press. --- src/battle_util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/battle_util.c b/src/battle_util.c index 0f18efb9a..fa38778ab 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -7791,7 +7791,7 @@ static u32 CalcAttackStat(u16 move, u8 battlerAtk, u8 battlerDef, u8 moveType, b atkStage = gBattleMons[battlerDef].statStages[STAT_SPATK]; } } - if (gBattleMoves[move].effect == EFFECT_BODY_PRESS) + else if (gBattleMoves[move].effect == EFFECT_BODY_PRESS) { atkStat = gBattleMons[battlerAtk].defense; atkStage = gBattleMons[battlerAtk].statStages[STAT_DEF]; From 0ee13418dc5c8867673fecab6e61c40fc6b78243 Mon Sep 17 00:00:00 2001 From: sbird Date: Wed, 22 Sep 2021 13:15:43 +0200 Subject: [PATCH 5/8] [ai] use expected value move dmg calculation --- include/battle_script_commands.h | 1 + src/battle_ai_util.c | 16 +++++++++++++--- src/battle_script_commands.c | 9 +++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/include/battle_script_commands.h b/include/battle_script_commands.h index 2e6a0aa4e..dec1596f2 100644 --- a/include/battle_script_commands.h +++ b/include/battle_script_commands.h @@ -13,6 +13,7 @@ struct StatFractions }; s32 CalcCritChanceStage(u8 battlerAtk, u8 battlerDef, u32 move, bool32 recordAbility); +s8 GetInverseCritChance(u8 battlerAtk, u8 battlerDef, u32 move); u32 GetTotalAccuracy(u32 battlerAtk, u32 battlerDef, u32 move); u8 GetBattlerTurnOrderNum(u8 battlerId); bool32 NoAliveMonsForEitherParty(void); diff --git a/src/battle_ai_util.c b/src/battle_ai_util.c index 48d3817c8..b68c68e1b 100644 --- a/src/battle_ai_util.c +++ b/src/battle_ai_util.c @@ -711,7 +711,8 @@ static bool32 AI_GetIfCrit(u32 move, u8 battlerAtk, u8 battlerDef) s32 AI_CalcDamage(u16 move, u8 battlerAtk, u8 battlerDef) { - s32 dmg, moveType; + s32 dmg, moveType, critDmg, normalDmg; + s8 critChance; SaveBattlerData(battlerAtk); SaveBattlerData(battlerDef); @@ -722,7 +723,15 @@ s32 AI_CalcDamage(u16 move, u8 battlerAtk, u8 battlerDef) gBattleStruct->dynamicMoveType = 0; SetTypeBeforeUsingMove(move, battlerAtk); GET_MOVE_TYPE(move, moveType); - dmg = CalculateMoveDamage(move, battlerAtk, battlerDef, moveType, 0, AI_GetIfCrit(move, battlerAtk, battlerDef), FALSE, FALSE); + + critChance = GetInverseCritChance(battlerAtk, battlerDef, move); + normalDmg = CalculateMoveDamage(move, battlerAtk, battlerDef, moveType, 0, FALSE, FALSE, FALSE); + critDmg = CalculateMoveDamage(move, battlerAtk, battlerDef, moveType, 0, TRUE, FALSE, FALSE); + + if(critChance == -1) + dmg = normalDmg; + else + dmg = (critDmg + normalDmg * (critChance - 1)) / critChance; // handle dynamic move damage switch (gBattleMoves[move].effect) @@ -749,7 +758,8 @@ s32 AI_CalcDamage(u16 move, u8 battlerAtk, u8 battlerDef) //case EFFECT_METAL_BURST: //case EFFECT_COUNTER: default: - dmg *= (100 - (Random() % 10)) / 100; // add random factor + //do not add the random factor, it's an average case analysis + //dmg *= (100 - (Random() % 10)) / 100; // add random factor break; } diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index e1d51bd05..a10635e1a 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -1822,6 +1822,15 @@ s32 CalcCritChanceStage(u8 battlerAtk, u8 battlerDef, u32 move, bool32 recordAbi return critChance; } +s8 GetInverseCritChance(u8 battlerAtk, u8 battlerDef, u32 move) +{ + s32 critChanceIndex = CalcCritChanceStage(battlerAtk, battlerDef, move, FALSE); + if(critChanceIndex < 0) + return -1; + else + return sCriticalHitChance[critChanceIndex]; +} + static void Cmd_critcalc(void) { s32 critChance = CalcCritChanceStage(gBattlerAttacker, gBattlerTarget, gCurrentMove, TRUE); From 53d985eeddafe743711e2b92c6be514ce95df768 Mon Sep 17 00:00:00 2001 From: Eduardo Quezada D'Ottone Date: Wed, 22 Sep 2021 10:29:32 -0300 Subject: [PATCH 6/8] Scald thaw flag config for = GEN_6 + .flags = FLAG_PROTECT_AFFECTED | FLAG_MIRROR_MOVE_AFFECTED | FLAG_KINGS_ROCK_AFFECTED | FLAG_SHEER_FORCE_BOOST | FLAG_THAW_USER, + #else + .flags = FLAG_PROTECT_AFFECTED | FLAG_MIRROR_MOVE_AFFECTED | FLAG_KINGS_ROCK_AFFECTED | FLAG_SHEER_FORCE_BOOST, + #endif .effect = EFFECT_SCALD, .power = 80, .type = TYPE_WATER, @@ -7943,7 +7948,6 @@ const struct BattleMove gBattleMoves[MOVES_COUNT] = .secondaryEffectChance = 30, .target = MOVE_TARGET_SELECTED, .priority = 0, - .flags = FLAG_PROTECT_AFFECTED | FLAG_MIRROR_MOVE_AFFECTED | FLAG_KINGS_ROCK_AFFECTED | FLAG_SHEER_FORCE_BOOST | FLAG_THAW_USER, .split = SPLIT_SPECIAL, }, From 707d49242e8f733f5bc797b219364cdc9d73b394 Mon Sep 17 00:00:00 2001 From: Eduardo Quezada D'Ottone Date: Wed, 22 Sep 2021 12:31:23 -0300 Subject: [PATCH 7/8] Revert "Scald thaw flag config for Gen 5" --- src/data/battle_moves.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/data/battle_moves.h b/src/data/battle_moves.h index 0fc3b3e42..657341b5e 100644 --- a/src/data/battle_moves.h +++ b/src/data/battle_moves.h @@ -7935,11 +7935,6 @@ const struct BattleMove gBattleMoves[MOVES_COUNT] = [MOVE_SCALD] = { - #if B_UPDATED_MOVE_DATA >= GEN_6 - .flags = FLAG_PROTECT_AFFECTED | FLAG_MIRROR_MOVE_AFFECTED | FLAG_KINGS_ROCK_AFFECTED | FLAG_SHEER_FORCE_BOOST | FLAG_THAW_USER, - #else - .flags = FLAG_PROTECT_AFFECTED | FLAG_MIRROR_MOVE_AFFECTED | FLAG_KINGS_ROCK_AFFECTED | FLAG_SHEER_FORCE_BOOST, - #endif .effect = EFFECT_SCALD, .power = 80, .type = TYPE_WATER, @@ -7948,6 +7943,7 @@ const struct BattleMove gBattleMoves[MOVES_COUNT] = .secondaryEffectChance = 30, .target = MOVE_TARGET_SELECTED, .priority = 0, + .flags = FLAG_PROTECT_AFFECTED | FLAG_MIRROR_MOVE_AFFECTED | FLAG_KINGS_ROCK_AFFECTED | FLAG_SHEER_FORCE_BOOST | FLAG_THAW_USER, .split = SPLIT_SPECIAL, }, From 303e31ae251b289fc46774314140617228d9e44e Mon Sep 17 00:00:00 2001 From: sbird Date: Wed, 22 Sep 2021 18:05:58 +0200 Subject: [PATCH 8/8] [ai] use expected value to simulate EFFECT_PSYWAVE --- src/battle_ai_util.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/battle_ai_util.c b/src/battle_ai_util.c index b68c68e1b..95d979e94 100644 --- a/src/battle_ai_util.c +++ b/src/battle_ai_util.c @@ -737,6 +737,8 @@ s32 AI_CalcDamage(u16 move, u8 battlerAtk, u8 battlerDef) switch (gBattleMoves[move].effect) { case EFFECT_LEVEL_DAMAGE: + case EFFECT_PSYWAVE: + //psywave's expected damage is equal to the user's level dmg = gBattleMons[battlerAtk].level; break; case EFFECT_DRAGON_RAGE: @@ -745,16 +747,6 @@ s32 AI_CalcDamage(u16 move, u8 battlerAtk, u8 battlerDef) case EFFECT_SONICBOOM: dmg = 20; break; - case EFFECT_PSYWAVE: - { - u32 randDamage; - if (B_PSYWAVE_DMG >= GEN_6) - randDamage = (Random() % 101); - else - randDamage = (Random() % 11) * 10; - dmg = gBattleMons[battlerAtk].level * (randDamage + 50) / 100; - } - break; //case EFFECT_METAL_BURST: //case EFFECT_COUNTER: default: