Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to Opportunist and Mirror Herb adjustments #4928

Merged
merged 9 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions asm/macros/battle_script.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1639,6 +1639,12 @@
.4byte \failInstr
.endm

.macro copyfoesstatincrease battler:req, failInstr:req
callnative BS_CopyFoesStatIncrease
.byte \battler
.4byte \failInstr
.endm

@ various command changed to more readable macros
.macro cancelmultiturnmoves battler:req
various \battler, VARIOUS_CANCEL_MULTI_TURN_MOVES
Expand Down
19 changes: 13 additions & 6 deletions data/battle_scripts_1.s
Original file line number Diff line number Diff line change
Expand Up @@ -9151,16 +9151,23 @@ BattleScript_MirrorHerbCopyStatChange::
printstring STRINGID_MIRRORHERBCOPIED
waitmessage B_WAIT_TIME_LONG
removeitem BS_SCRIPTING
call BattleScript_TotemVar_Ret
copybyte gBattlerAttacker, sSAVED_BATTLER @ restore the original attacker just to be safe
BattleScript_MirrorHerbStartCopyStats:
AlexOn1ine marked this conversation as resolved.
Show resolved Hide resolved
copyfoesstatincrease BS_SCRIPTING, BattleScript_MirrorHerbStartReturn
statbuffchange STAT_CHANGE_ALLOW_PTR, BattleScript_MirrorHerbStartReturn
goto BattleScript_MirrorHerbStartCopyStats
BattleScript_MirrorHerbStartReturn:
return

BattleScript_OpportunistCopyStatChange::
call BattleScript_AbilityPopUp
printstring STRINGID_OPPORTUNISTCOPIED
call BattleScript_AbilityPopUpScripting
playanimation BS_SCRIPTING, B_ANIM_STATS_CHANGE, sB_ANIM_ARG1
BattleScript_OpportunistStartCopyStats:
copyfoesstatincrease BS_SCRIPTING, BattleScript_OpportunistCopyStatChangeEnd
statbuffchange STAT_CHANGE_ALLOW_PTR, BattleScript_OpportunistCopyStatChangeEnd
printfromtable gStatUpStringIds
waitmessage B_WAIT_TIME_LONG
call BattleScript_TotemVar_Ret
copybyte gBattlerAttacker, sSAVED_BATTLER @ restore the original attacker just to be safe
goto BattleScript_OpportunistStartCopyStats
BattleScript_OpportunistCopyStatChangeEnd:
end3

BattleScript_TotemVar::
Expand Down
75 changes: 37 additions & 38 deletions include/constants/battle_string_ids.h
Original file line number Diff line number Diff line change
Expand Up @@ -670,45 +670,44 @@
#define STRINGID_CURRENTMOVECANTSELECT 668
#define STRINGID_TARGETISBEINGSALTCURED 669
#define STRINGID_TARGETISHURTBYSALTCURE 670
#define STRINGID_OPPORTUNISTCOPIED 671
#define STRINGID_TARGETCOVEREDINSTICKYCANDYSYRUP 672
#define STRINGID_SHARPSTEELFLOATS 673
#define STRINGID_SHARPSTEELDMG 674
#define STRINGID_PKMNBLEWAWAYSHARPSTEEL 675
#define STRINGID_SHARPSTEELDISAPPEAREDFROMTEAM 676
#define STRINGID_TEAMTRAPPEDWITHVINES 677
#define STRINGID_PKMNHURTBYVINES 678
#define STRINGID_TEAMCAUGHTINVORTEX 679
#define STRINGID_PKMNHURTBYVORTEX 680
#define STRINGID_TEAMSURROUNDEDBYFIRE 681
#define STRINGID_PKMNBURNINGUP 682
#define STRINGID_TEAMSURROUNDEDBYROCKS 683
#define STRINGID_PKMNHURTBYROCKSTHROWN 684
#define STRINGID_MOVEBLOCKEDBYDYNAMAX 685
#define STRINGID_ZEROTOHEROTRANSFORMATION 686
#define STRINGID_THETWOMOVESBECOMEONE 687
#define STRINGID_ARAINBOWAPPEAREDONSIDE 688
#define STRINGID_THERAINBOWDISAPPEARED 689
#define STRINGID_WAITINGFORPARTNERSMOVE 690
#define STRINGID_SEAOFFIREENVELOPEDSIDE 691
#define STRINGID_HURTBYTHESEAOFFIRE 692
#define STRINGID_THESEAOFFIREDISAPPEARED 693
#define STRINGID_SWAMPENVELOPEDSIDE 694
#define STRINGID_THESWAMPDISAPPEARED 695
#define STRINGID_PKMNTELLCHILLINGRECEPTIONJOKE 696
#define STRINGID_HOSPITALITYRESTORATION 697
#define STRINGID_ELECTROSHOTCHARGING 698
#define STRINGID_ITEMWASUSEDUP 699
#define STRINGID_ATTACKERLOSTITSTYPE 700
#define STRINGID_SHEDITSTAIL 701
#define STRINGID_CLOAKEDINAHARSHLIGHT 702
#define STRINGID_SUPERSWEETAROMAWAFTS 703
#define STRINGID_DIMENSIONSWERETWISTED 704
#define STRINGID_BIZARREARENACREATED 705
#define STRINGID_BIZARREAREACREATED 706
#define STRINGID_TIDYINGUPCOMPLETE 707
#define STRINGID_TARGETCOVEREDINSTICKYCANDYSYRUP 671
#define STRINGID_SHARPSTEELFLOATS 672
#define STRINGID_SHARPSTEELDMG 673
#define STRINGID_PKMNBLEWAWAYSHARPSTEEL 674
#define STRINGID_SHARPSTEELDISAPPEAREDFROMTEAM 675
#define STRINGID_TEAMTRAPPEDWITHVINES 676
#define STRINGID_PKMNHURTBYVINES 677
#define STRINGID_TEAMCAUGHTINVORTEX 678
#define STRINGID_PKMNHURTBYVORTEX 679
#define STRINGID_TEAMSURROUNDEDBYFIRE 680
#define STRINGID_PKMNBURNINGUP 681
#define STRINGID_TEAMSURROUNDEDBYROCKS 682
#define STRINGID_PKMNHURTBYROCKSTHROWN 683
#define STRINGID_MOVEBLOCKEDBYDYNAMAX 684
#define STRINGID_ZEROTOHEROTRANSFORMATION 685
#define STRINGID_THETWOMOVESBECOMEONE 686
#define STRINGID_ARAINBOWAPPEAREDONSIDE 687
#define STRINGID_THERAINBOWDISAPPEARED 688
#define STRINGID_WAITINGFORPARTNERSMOVE 689
#define STRINGID_SEAOFFIREENVELOPEDSIDE 690
#define STRINGID_HURTBYTHESEAOFFIRE 691
#define STRINGID_THESEAOFFIREDISAPPEARED 692
#define STRINGID_SWAMPENVELOPEDSIDE 693
#define STRINGID_THESWAMPDISAPPEARED 694
#define STRINGID_PKMNTELLCHILLINGRECEPTIONJOKE 695
#define STRINGID_HOSPITALITYRESTORATION 696
#define STRINGID_ELECTROSHOTCHARGING 697
#define STRINGID_ITEMWASUSEDUP 698
#define STRINGID_ATTACKERLOSTITSTYPE 699
#define STRINGID_SHEDITSTAIL 700
#define STRINGID_CLOAKEDINAHARSHLIGHT 701
#define STRINGID_SUPERSWEETAROMAWAFTS 702
#define STRINGID_DIMENSIONSWERETWISTED 703
#define STRINGID_BIZARREARENACREATED 704
#define STRINGID_BIZARREAREACREATED 705
#define STRINGID_TIDYINGUPCOMPLETE 706

#define BATTLESTRINGS_COUNT 708
#define BATTLESTRINGS_COUNT 707

// This is the string id that gBattleStringsTable starts with.
// String ids before this (e.g. STRINGID_INTROMSG) are not in the table,
Expand Down
2 changes: 0 additions & 2 deletions src/battle_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,6 @@ static const u8 sText_TeamGainedEXP[] = _("The rest of your team gained EXP.\nPo
static const u8 sText_CurrentMoveCantSelect[] = _("{B_BUFF1} cannot be used!\p");
static const u8 sText_TargetIsBeingSaltCured[] = _("{B_DEF_NAME_WITH_PREFIX} is being salt cured!");
static const u8 sText_TargetIsHurtBySaltCure[] = _("{B_DEF_NAME_WITH_PREFIX} is hurt by {B_BUFF1}!");
static const u8 sText_OpportunistCopied[] = _("{B_SCR_ACTIVE_NAME_WITH_PREFIX} copied its\nopponent's stat changes!");
static const u8 sText_TargetCoveredInStickyCandySyrup[] = _("{B_DEF_NAME_WITH_PREFIX} got covered\nin sticky syrup!");
static const u8 sText_PkmnTellChillingReceptionJoke[] = _("{B_ATK_NAME_WITH_PREFIX} is preparing to tell a\nchillingly bad joke!");
static const u8 sText_ZeroToHeroTransformation[] = _("{B_ATK_NAME_WITH_PREFIX} underwent a heroic\ntransformation!");
Expand Down Expand Up @@ -864,7 +863,6 @@ const u8 *const gBattleStringsTable[BATTLESTRINGS_COUNT] =
[STRINGID_ZEROTOHEROTRANSFORMATION - BATTLESTRINGS_TABLE_START] = sText_ZeroToHeroTransformation,
[STRINGID_PKMNTELLCHILLINGRECEPTIONJOKE - BATTLESTRINGS_TABLE_START] = sText_PkmnTellChillingReceptionJoke,
[STRINGID_MOVEBLOCKEDBYDYNAMAX - BATTLESTRINGS_TABLE_START] = sText_MoveBlockedByDynamax,
[STRINGID_OPPORTUNISTCOPIED - BATTLESTRINGS_TABLE_START] = sText_OpportunistCopied,
[STRINGID_TARGETISHURTBYSALTCURE - BATTLESTRINGS_TABLE_START] = sText_TargetIsHurtBySaltCure,
[STRINGID_TARGETISBEINGSALTCURED - BATTLESTRINGS_TABLE_START] = sText_TargetIsBeingSaltCured,
[STRINGID_CURRENTMOVECANTSELECT - BATTLESTRINGS_TABLE_START] = sText_CurrentMoveCantSelect,
Expand Down
43 changes: 40 additions & 3 deletions src/battle_script_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -11781,10 +11781,16 @@ static u32 ChangeStatBuffs(s8 statValue, u32 statId, u32 flags, const u8 *BS_ptr
}
else
{
u32 statIncrease;
if ((statValue + gBattleMons[battler].statStages[statId]) > MAX_STAT_STAGE)
statIncrease = MAX_STAT_STAGE - gBattleMons[battler].statStages[statId];
else
statIncrease = statValue;

gBattleCommunication[MULTISTRING_CHOOSER] = (gBattlerTarget == battler);
gProtectStructs[battler].statRaised = TRUE;

// check mirror herb
// Check Mirror Herb / Opportuniest
AlexOn1ine marked this conversation as resolved.
Show resolved Hide resolved
for (index = 0; index < gBattlersCount; index++)
{
if (GetBattlerSide(index) == GetBattlerSide(battler))
Expand All @@ -11794,14 +11800,14 @@ static u32 ChangeStatBuffs(s8 statValue, u32 statId, u32 flags, const u8 *BS_ptr
{
gProtectStructs[index].activateOpportunist = 2; // set stats to copy
gQueuedStatBoosts[index].stats |= (1 << (statId - 1)); // -1 to start at atk
gQueuedStatBoosts[index].statChanges[statId - 1] += statValue; // cumulative in case of multiple opponent boosts
gQueuedStatBoosts[index].statChanges[statId - 1] += statIncrease; // cumulative in case of multiple opponent boosts
}
else if (GetBattlerHoldEffect(index, TRUE) == HOLD_EFFECT_MIRROR_HERB
&& gBattleMons[index].statStages[statId] < MAX_STAT_STAGE)
{
gProtectStructs[index].eatMirrorHerb = 1;
gQueuedStatBoosts[index].stats |= (1 << (statId - 1)); // -1 to start at atk
gQueuedStatBoosts[index].statChanges[statId - 1] = statValue;
gQueuedStatBoosts[index].statChanges[statId - 1] = statIncrease;
}
}
}
Expand Down Expand Up @@ -17000,3 +17006,34 @@ void BS_TryQuash(void)
}
gBattlescriptCurrInstr = cmd->nextInstr;
}

void BS_CopyFoesStatIncrease(void)
{
NATIVE_ARGS(u8 battler, const u8 *jumpInstr);
u32 stat = 0;
u32 battler = GetBattlerForBattleScript(cmd->battler);

if (gQueuedStatBoosts[battler].stats == 0)
{
memset(gQueuedStatBoosts, 0, sizeof(gQueuedStatBoosts)); // erase all boosts so they are not stacked
gBattlescriptCurrInstr = cmd->jumpInstr; // stats done, exit
return;
}
AlexOn1ine marked this conversation as resolved.
Show resolved Hide resolved

for (stat = 0; stat < (NUM_BATTLE_STATS - 1); stat++)
AlexOn1ine marked this conversation as resolved.
Show resolved Hide resolved
{
if (gQueuedStatBoosts[battler].stats & (1 << stat))
{
if (gQueuedStatBoosts[battler].statChanges[stat] <= -1)
SET_STATCHANGER(stat + 1, abs(gQueuedStatBoosts[battler].statChanges[stat]), TRUE);
else
SET_STATCHANGER(stat + 1, gQueuedStatBoosts[battler].statChanges[stat], FALSE);

gQueuedStatBoosts[battler].stats &= ~(1 << stat);
gBattlerTarget = battler;
gBattlescriptCurrInstr = cmd->nextInstr;
return;
}
}
gBattlescriptCurrInstr = cmd->jumpInstr;
}
AlexOn1ine marked this conversation as resolved.
Show resolved Hide resolved
22 changes: 18 additions & 4 deletions src/battle_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -5837,9 +5837,24 @@ u32 AbilityBattleEffects(u32 caseID, u32 battler, u32 ability, u32 special, u32
case ABILITY_OPPORTUNIST:
if (gProtectStructs[battler].activateOpportunist == 2)
{
gBattleScripting.savedBattler = gBattlerAttacker;
gBattleScripting.battler = gBattlerAttacker = gBattlerAbility = battler;
bool32 statBuffMoreThan1 = FALSE;
gBattleScripting.battler = battler;
gProtectStructs[battler].activateOpportunist--;

for (i = 0; i < (NUM_BATTLE_STATS - 1); i++)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally you'd have some constant array declaring a "visual stat order" and i is the index in that array which contains stat ids. That way you don't need a handleSpeedAnimLater variable.

{
if ((gQueuedStatBoosts[battler].stats & (1 << i)) == 0)
continue;

if (!statBuffMoreThan1)
statBuffMoreThan1 = ((gQueuedStatBoosts[battler].stats & (1 << i)) > 1);

if (gBattleScripting.animArg1 != 0) //Already set in a different stat so now boosting multiple stats
gBattleScripting.animArg1 = (!statBuffMoreThan1 ? STAT_ANIM_MULTIPLE_PLUS1 : STAT_ANIM_MULTIPLE_PLUS2);
else
gBattleScripting.animArg1 = GET_STAT_BUFF_ID(i) + (!statBuffMoreThan1 ? STAT_ANIM_PLUS1 : STAT_ANIM_PLUS2);
AlexOn1ine marked this conversation as resolved.
Show resolved Hide resolved
}

BattleScriptPushCursorAndCallback(BattleScript_OpportunistCopyStatChange);
effect = 1;
}
Expand Down Expand Up @@ -6820,8 +6835,7 @@ static u8 TryConsumeMirrorHerb(u32 battler, bool32 execute)
if (gProtectStructs[battler].eatMirrorHerb)
{
gLastUsedItem = gBattleMons[battler].item;
gBattleScripting.savedBattler = gBattlerAttacker;
gBattleScripting.battler = gBattlerAttacker = battler;
gBattleScripting.battler = battler;
gProtectStructs[battler].eatMirrorHerb = 0;
if (execute)
{
Expand Down
Loading
Loading