diff --git a/include/battle.h b/include/battle.h index 466a9138d5..00c7081fb8 100644 --- a/include/battle.h +++ b/include/battle.h @@ -658,6 +658,7 @@ struct BattleStruct u8 storedLunarDance:4; // Each battler as a bit. u16 supremeOverlordModifier[MAX_BATTLERS_COUNT]; u8 itemPartyIndex[MAX_BATTLERS_COUNT]; + u8 itemMoveIndex[MAX_BATTLERS_COUNT]; bool8 trainerSlideHalfHpMsgDone; u8 trainerSlideFirstCriticalHitMsgState:2; u8 trainerSlideFirstSuperEffectiveHitMsgState:2; diff --git a/src/battle_controller_recorded_opponent.c b/src/battle_controller_recorded_opponent.c index 7515840761..d1c60343ac 100644 --- a/src/battle_controller_recorded_opponent.c +++ b/src/battle_controller_recorded_opponent.c @@ -1443,7 +1443,7 @@ static void RecordedOpponentHandleChooseItem(void) u8 byte2 = RecordedBattle_GetBattlerAction(RECORDED_ITEM_ID, gActiveBattler); gBattleStruct->chosenItem[gActiveBattler] = (byte1 << 8) | byte2; gBattleStruct->itemPartyIndex[gActiveBattler] = RecordedBattle_GetBattlerAction(RECORDED_ITEM_TARGET, gActiveBattler); - gChosenMovePos = RecordedBattle_GetBattlerAction(RECORDED_ITEM_MOVE, gActiveBattler); + gBattleStruct->itemMoveIndex[gActiveBattler] = RecordedBattle_GetBattlerAction(RECORDED_ITEM_MOVE, gActiveBattler); BtlController_EmitOneReturnValue(BUFFER_B, gBattleStruct->chosenItem[gActiveBattler]); RecordedOpponentBufferExecCompleted(); } diff --git a/src/battle_controller_recorded_player.c b/src/battle_controller_recorded_player.c index 1a56220d7f..46f3de4f12 100644 --- a/src/battle_controller_recorded_player.c +++ b/src/battle_controller_recorded_player.c @@ -1467,7 +1467,7 @@ static void RecordedPlayerHandleChooseItem(void) u8 byte2 = RecordedBattle_GetBattlerAction(RECORDED_ITEM_ID, gActiveBattler); gBattleStruct->chosenItem[gActiveBattler] = (byte1 << 8) | byte2; gBattleStruct->itemPartyIndex[gActiveBattler] = RecordedBattle_GetBattlerAction(RECORDED_ITEM_TARGET, gActiveBattler); - gChosenMovePos = RecordedBattle_GetBattlerAction(RECORDED_ITEM_MOVE, gActiveBattler); + gBattleStruct->itemMoveIndex[gActiveBattler] = RecordedBattle_GetBattlerAction(RECORDED_ITEM_MOVE, gActiveBattler); BtlController_EmitOneReturnValue(BUFFER_B, gBattleStruct->chosenItem[gActiveBattler]); RecordedPlayerBufferExecCompleted(); } diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 1187267b2a..0842884311 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -16536,10 +16536,10 @@ void BS_ItemRestorePP(void) { // Check whether to apply to all moves. if (effect[4] & ITEM4_HEAL_PP_ONE) { - i = gChosenMovePos; - loopEnd = gChosenMovePos + 1; + i = gBattleStruct->itemMoveIndex[gBattlerAttacker]; + loopEnd = i + 1; } - else + else { i = 0; loopEnd = MAX_MON_MOVES; diff --git a/src/party_menu.c b/src/party_menu.c index 773495a4d5..aa37b1c691 100755 --- a/src/party_menu.c +++ b/src/party_menu.c @@ -4944,7 +4944,7 @@ static void TryUseItemOnMove(u8 taskId) else { gBattleStruct->itemPartyIndex[gBattlerInMenuId] = GetPartyIdFromBattleSlot(gPartyMenu.slotId); - gChosenMovePos = ptr->data1; + gBattleStruct->itemMoveIndex[gBattlerInMenuId] = ptr->data1; gPartyMenuUseExitCallback = TRUE; RemoveBagItem(gSpecialVar_ItemId, 1); ScheduleBgCopyTilemapToVram(2); diff --git a/test/test_runner_battle.c b/test/test_runner_battle.c index 2c26e39180..b7360e19c8 100644 --- a/test/test_runner_battle.c +++ b/test/test_runner_battle.c @@ -1564,6 +1564,10 @@ void UseItem(u32 sourceLine, struct BattlePokemon *battler, struct ItemContext c } INVALID_IF(i == MAX_MON_MOVES, "USE_ITEM on invalid move: %d", ctx.move); } + else + { + i = 0; + } PushBattlerAction(sourceLine, battlerId, RECORDED_ACTION_TYPE, B_ACTION_USE_ITEM); PushBattlerAction(sourceLine, battlerId, RECORDED_ITEM_ID, (ctx.itemId >> 8) & 0xFF); PushBattlerAction(sourceLine, battlerId, RECORDED_ITEM_ID, ctx.itemId & 0xFF);