Merge pull request #1822 from ghoulslash/harvest

fix recycle and harvest
This commit is contained in:
BuffelSaft 2021-10-30 15:00:56 +13:00 committed by GitHub
commit f0e9b09258
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 23 additions and 14 deletions

View file

@ -7501,9 +7501,11 @@ BattleScript_CheekPouchActivates::
BattleScript_HarvestActivates::
pause 5
tryrecycleitem BattleScript_HarvestActivatesEnd
call BattleScript_AbilityPopUp
printstring STRINGID_HARVESTBERRY
waitmessage B_WAIT_TIME_LONG
BattleScript_HarvestActivatesEnd:
end3
BattleScript_SolarPowerActivates::

View file

@ -547,7 +547,7 @@ struct BattleStruct
u16 synchronizeMoveEffect;
bool8 anyMonHasTransformed;
void (*savedCallback)(void);
u16 usedHeldItems[MAX_BATTLERS_COUNT];
u16 usedHeldItems[PARTY_SIZE][2]; // For each party member and side. For harvest, recycle
u16 chosenItem[MAX_BATTLERS_COUNT];
u8 AI_itemType[2];
u8 AI_itemFlags[2];

View file

@ -155,6 +155,7 @@ bool32 TryRoomService(u8 battlerId);
void BufferStatChange(u8 battlerId, u8 statId, u8 stringId);
void DoBurmyFormChange(u32 monId);
bool32 BlocksPrankster(u16 move, u8 battlerPrankster, u8 battlerDef, bool32 checkTarget);
u16 GetUsedHeldItem(u8 battler);
// ability checks
bool32 IsRolePlayBannedAbilityAtk(u16 ability);

View file

@ -1530,7 +1530,7 @@ static s16 AI_CheckBadMove(u8 battlerAtk, u8 battlerDef, u16 move, s16 score)
score -= 10;
break;
case EFFECT_RECYCLE:
if (gBattleStruct->usedHeldItems[battlerAtk] == 0 || gBattleMons[battlerAtk].item != 0)
if (GetUsedHeldItem(battlerAtk) == 0 || gBattleMons[battlerAtk].item != 0)
score -= 10;
break;
case EFFECT_IMPRISON:
@ -1951,7 +1951,7 @@ static s16 AI_CheckBadMove(u8 battlerAtk, u8 battlerDef, u16 move, s16 score)
score -= 10;
break;
case EFFECT_BELCH:
if (ItemId_GetPocket(gBattleStruct->usedHeldItems[battlerAtk]) != POCKET_BERRIES)
if (ItemId_GetPocket(GetUsedHeldItem(battlerAtk)) != POCKET_BERRIES)
score -= 10; // attacker has not consumed a berry
break;
case EFFECT_YAWN:
@ -4097,9 +4097,9 @@ static s16 AI_CheckViability(u8 battlerAtk, u8 battlerDef, u16 move, s16 score)
score += 3;
break;
case EFFECT_RECYCLE:
if (gBattleStruct->usedHeldItems[battlerAtk] != ITEM_NONE)
if (GetUsedHeldItem(battlerAtk) != ITEM_NONE)
score++;
if (IsRecycleEncouragedItem(gBattleStruct->usedHeldItems[battlerAtk]))
if (IsRecycleEncouragedItem(GetUsedHeldItem(battlerAtk)))
score++;
break;
case EFFECT_BRICK_BREAK:

View file

@ -2862,7 +2862,6 @@ static void BattleStartClearSetData(void)
gBattleResources->flags->flags[i] = 0;
gPalaceSelectionBattleScripts[i] = 0;
gBattleStruct->lastTakenMove[i] = 0;
gBattleStruct->usedHeldItems[i] = 0;
gBattleStruct->choicedMove[i] = 0;
gBattleStruct->changedItems[i] = 0;
gBattleStruct->lastTakenMoveFrom[i][0] = 0;
@ -2935,8 +2934,12 @@ static void BattleStartClearSetData(void)
gBattleStruct->mega.triggerSpriteId = 0xFF;
for (i = 0; i < PARTY_SIZE; i++)
{
gBattleStruct->usedHeldItems[i][0] = 0;
gBattleStruct->usedHeldItems[i][1] = 0;
gBattleStruct->itemStolen[i].originalItem = GetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM);
}
}
void SwitchInClearSetData(void)
{

View file

@ -6796,9 +6796,9 @@ static void Cmd_removeitem(void)
gActiveBattler = GetBattlerForBattleScript(gBattlescriptCurrInstr[1]);
itemId = gBattleMons[gActiveBattler].item;
// Popped Air Balloon cannot be restored by no means.
// Popped Air Balloon cannot be restored by any means.
if (GetBattlerHoldEffect(gActiveBattler, TRUE) != HOLD_EFFECT_AIR_BALLOON)
gBattleStruct->usedHeldItems[gActiveBattler] = itemId;
gBattleStruct->usedHeldItems[gBattlerPartyIndexes[gActiveBattler]][GetBattlerSide(gActiveBattler)] = itemId; // Remember if switched out
gBattleMons[gActiveBattler].item = 0;
CheckSetUnburden(gActiveBattler);
@ -12547,7 +12547,7 @@ static void Cmd_tryrecycleitem(void)
u16 *usedHeldItem;
gActiveBattler = gBattlerAttacker;
usedHeldItem = &gBattleStruct->usedHeldItems[gActiveBattler];
usedHeldItem = &gBattleStruct->usedHeldItems[gBattlerPartyIndexes[gActiveBattler]][GetBattlerSide(gActiveBattler)];
if (*usedHeldItem != 0 && gBattleMons[gActiveBattler].item == 0)
{
gLastUsedItem = *usedHeldItem;

View file

@ -4373,11 +4373,9 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move
case ABILITY_HARVEST:
if (((WEATHER_HAS_EFFECT && gBattleWeather & WEATHER_SUN_ANY) || Random() % 2 == 0)
&& gBattleMons[battler].item == ITEM_NONE
&& gBattleStruct->changedItems[battler] == ITEM_NONE
&& ItemId_GetPocket(gBattleStruct->usedHeldItems[battler]) == POCKET_BERRIES)
&& gBattleStruct->changedItems[battler] == ITEM_NONE // Will not inherit an item
&& ItemId_GetPocket(GetUsedHeldItem(battler)) == POCKET_BERRIES)
{
gLastUsedItem = gBattleStruct->changedItems[battler] = gBattleStruct->usedHeldItems[battler];
gBattleStruct->usedHeldItems[battler] = ITEM_NONE;
BattleScriptPushCursorAndCallback(BattleScript_HarvestActivates);
effect++;
}
@ -9519,3 +9517,8 @@ bool32 BlocksPrankster(u16 move, u8 battlerPrankster, u8 battlerDef, bool32 chec
#endif
return FALSE;
}
u16 GetUsedHeldItem(u8 battler)
{
return gBattleStruct->usedHeldItems[gBattlerPartyIndexes[battler]][GetBattlerSide(battler)];
}