Merge pull request #2142 from AgustinGDLV/exp_candy

Gen 8 EXP Candies
This commit is contained in:
Eduardo Quezada D'Ottone 2022-08-25 23:03:24 -04:00 committed by GitHub
commit 399a0c9d6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 119 additions and 53 deletions

View File

@ -973,6 +973,13 @@
#define MACH_BIKE 0
#define ACRO_BIKE 1
// Item parameters for EXP Candies
#define EXP_100 1
#define EXP_800 2
#define EXP_3000 3
#define EXP_10000 4
#define EXP_30000 5
// Item type IDs (used to determine the exit callback)
#define ITEM_USE_MAIL 0
#define ITEM_USE_PARTY_MENU 1

View File

@ -499,6 +499,7 @@ extern const u8 gText_12PoofForgotMove[];
extern const u8 gText_StopLearningMove2[];
extern const u8 gText_MoveNotLearned[];
extern const u8 gText_PkmnElevatedToLvVar2[];
extern const u8 gText_PkmnGainedExp[];
extern const u8 gText_RemoveMailBeforeItem[];
extern const u8 gText_PkmnHoldingItemCantHoldMail[];
extern const u8 gText_MailTransferredFromMailbox[];

View File

@ -1371,10 +1371,11 @@ const struct Item gItems[] =
.name = _("Exp.Candy XS"),
.itemId = ITEM_EXP_CANDY_XS,
.price = 20,
.holdEffectParam = EXP_100,
.description = sExpCandyXSDesc,
.pocket = POCKET_ITEMS,
.type = ITEM_USE_BAG_MENU,
.fieldUseFunc = ItemUseOutOfBattle_CannotUse, // Todo
.type = ITEM_USE_PARTY_MENU,
.fieldUseFunc = ItemUseOutOfBattle_RareCandy,
.flingPower = 30,
},
@ -1383,10 +1384,11 @@ const struct Item gItems[] =
.name = _("Exp.Candy S"),
.itemId = ITEM_EXP_CANDY_S,
.price = 240,
.holdEffectParam = EXP_800,
.description = sExpCandyXSDesc,
.pocket = POCKET_ITEMS,
.type = ITEM_USE_BAG_MENU,
.fieldUseFunc = ItemUseOutOfBattle_CannotUse, // Todo
.type = ITEM_USE_PARTY_MENU,
.fieldUseFunc = ItemUseOutOfBattle_RareCandy,
.flingPower = 30,
},
@ -1395,10 +1397,11 @@ const struct Item gItems[] =
.name = _("Exp.Candy M"),
.itemId = ITEM_EXP_CANDY_M,
.price = 1000,
.holdEffectParam = EXP_3000,
.description = sExpCandyMDesc,
.pocket = POCKET_ITEMS,
.type = ITEM_USE_BAG_MENU,
.fieldUseFunc = ItemUseOutOfBattle_CannotUse, // Todo
.type = ITEM_USE_PARTY_MENU,
.fieldUseFunc = ItemUseOutOfBattle_RareCandy,
.flingPower = 30,
},
@ -1407,10 +1410,11 @@ const struct Item gItems[] =
.name = _("Exp.Candy L"),
.itemId = ITEM_EXP_CANDY_L,
.price = 3000,
.holdEffectParam = EXP_10000,
.description = sExpCandyLDesc,
.pocket = POCKET_ITEMS,
.type = ITEM_USE_BAG_MENU,
.fieldUseFunc = ItemUseOutOfBattle_CannotUse, // Todo
.type = ITEM_USE_PARTY_MENU,
.fieldUseFunc = ItemUseOutOfBattle_RareCandy,
.flingPower = 30,
},
@ -1419,10 +1423,11 @@ const struct Item gItems[] =
.name = _("Exp.Candy XL"),
.itemId = ITEM_EXP_CANDY_XL,
.price = 10000,
.holdEffectParam = EXP_30000,
.description = sExpCandyXLDesc,
.pocket = POCKET_ITEMS,
.type = ITEM_USE_BAG_MENU,
.fieldUseFunc = ItemUseOutOfBattle_CannotUse, // Todo
.type = ITEM_USE_PARTY_MENU,
.fieldUseFunc = ItemUseOutOfBattle_RareCandy,
.flingPower = 30,
},

View File

@ -510,11 +510,11 @@ const u8 *const gItemEffectTable[] =
// Candy
[ITEM_RARE_CANDY - ITEM_POTION] = gItemEffect_RareCandy,
//[ITEM_EXP_CANDY_XS - ITEM_POTION] = gItemEffect_ExpCandy, // Todo
//[ITEM_EXP_CANDY_S - ITEM_POTION] = gItemEffect_ExpCandy, // Todo
//[ITEM_EXP_CANDY_M - ITEM_POTION] = gItemEffect_ExpCandy, // Todo
//[ITEM_EXP_CANDY_L - ITEM_POTION] = gItemEffect_ExpCandy, // Todo
//[ITEM_EXP_CANDY_XL - ITEM_POTION] = gItemEffect_ExpCandy, // Todo
[ITEM_EXP_CANDY_XS - ITEM_POTION] = gItemEffect_RareCandy,
[ITEM_EXP_CANDY_S - ITEM_POTION] = gItemEffect_RareCandy,
[ITEM_EXP_CANDY_M - ITEM_POTION] = gItemEffect_RareCandy,
[ITEM_EXP_CANDY_L - ITEM_POTION] = gItemEffect_RareCandy,
[ITEM_EXP_CANDY_XL - ITEM_POTION] = gItemEffect_RareCandy,
//[ITEM_DYNAMAX_CANDY - ITEM_POTION] = gItemEffect_DynamaxCandy, // Todo
// Medicinal Flutes

View File

@ -225,6 +225,8 @@ EWRAM_DATA u8 gSelectedOrderFromParty[MAX_FRONTIER_PARTY_SIZE] = {0};
static EWRAM_DATA u16 sPartyMenuItemId = 0;
static EWRAM_DATA u16 sUnused = 0;
EWRAM_DATA u8 gBattlePartyCurrentOrder[PARTY_SIZE / 2] = {0}; // bits 0-3 are the current pos of Slot 1, 4-7 are Slot 2, and so on
static EWRAM_DATA u8 sInitialLevel = 0;
static EWRAM_DATA u8 sFinalLevel = 0;
// IWRAM common
void (*gItemUseCB)(u8, TaskFunc);
@ -5071,6 +5073,7 @@ static void CB2_ShowSummaryScreenToForgetMove(void)
static void CB2_ReturnToPartyMenuWhileLearningMove(void)
{
SetMonData(&gPlayerParty[gPartyMenu.slotId], MON_DATA_LEVEL, &sFinalLevel); // to avoid displaying incorrect level
InitPartyMenu(PARTY_MENU_TYPE_FIELD, PARTY_LAYOUT_SINGLE, PARTY_ACTION_CHOOSE_MON, TRUE, PARTY_MSG_NONE, Task_ReturnToPartyMenuWhileLearningMove, gPartyMenu.exitCallback);
}
@ -5176,8 +5179,9 @@ void ItemUseCB_RareCandy(u8 taskId, TaskFunc task)
s16 *arrayPtr = ptr->data;
u16 *itemPtr = &gSpecialVar_ItemId;
bool8 cannotUseEffect;
sInitialLevel = GetMonData(mon, MON_DATA_LEVEL);
if (GetMonData(mon, MON_DATA_LEVEL) != MAX_LEVEL)
if (sInitialLevel != MAX_LEVEL)
{
BufferMonStatsToTaskData(mon, arrayPtr);
cannotUseEffect = ExecuteTableBasedItemEffect_(gPartyMenu.slotId, *itemPtr, 0);
@ -5197,16 +5201,29 @@ void ItemUseCB_RareCandy(u8 taskId, TaskFunc task)
}
else
{
sFinalLevel = GetMonData(mon, MON_DATA_LEVEL, NULL);
gPartyMenuUseExitCallback = TRUE;
PlayFanfareByFanfareNum(FANFARE_LEVEL_UP);
UpdateMonDisplayInfoAfterRareCandy(gPartyMenu.slotId, mon);
RemoveBagItem(gSpecialVar_ItemId, 1);
GetMonNickname(mon, gStringVar1);
ConvertIntToDecimalStringN(gStringVar2, GetMonData(mon, MON_DATA_LEVEL), STR_CONV_MODE_LEFT_ALIGN, 3);
StringExpandPlaceholders(gStringVar4, gText_PkmnElevatedToLvVar2);
DisplayPartyMenuMessage(gStringVar4, TRUE);
ScheduleBgCopyTilemapToVram(2);
gTasks[taskId].func = Task_DisplayLevelUpStatsPg1;
if (sFinalLevel > sInitialLevel)
{
PlayFanfareByFanfareNum(FANFARE_LEVEL_UP);
ConvertIntToDecimalStringN(gStringVar2, sFinalLevel, STR_CONV_MODE_LEFT_ALIGN, 3);
StringExpandPlaceholders(gStringVar4, gText_PkmnElevatedToLvVar2);
DisplayPartyMenuMessage(gStringVar4, TRUE);
ScheduleBgCopyTilemapToVram(2);
gTasks[taskId].func = Task_DisplayLevelUpStatsPg1;
}
else
{
PlaySE(SE_USE_ITEM);
gPartyMenuUseExitCallback = FALSE;
StringExpandPlaceholders(gStringVar4, gText_PkmnGainedExp);
DisplayPartyMenuMessage(gStringVar4, FALSE);
ScheduleBgCopyTilemapToVram(2);
gTasks[taskId].func = task;
}
}
}
@ -5239,6 +5256,7 @@ static void Task_DisplayLevelUpStatsPg2(u8 taskId)
{
PlaySE(SE_SELECT);
DisplayLevelUpStatsPg2(taskId);
sInitialLevel += 1; // so the Pokemon doesn't learn a move meant for its previous level
gTasks[taskId].func = Task_TryLearnNewMoves;
}
}
@ -5269,44 +5287,58 @@ static void Task_TryLearnNewMoves(u8 taskId)
if (WaitFanfare(FALSE) && ((JOY_NEW(A_BUTTON)) || (JOY_NEW(B_BUTTON))))
{
RemoveLevelUpStatsWindow();
learnMove = MonTryLearningNewMove(&gPlayerParty[gPartyMenu.slotId], TRUE);
gPartyMenu.learnMoveState = 1;
switch (learnMove)
for (; sInitialLevel <= sFinalLevel; sInitialLevel++)
{
case 0: // No moves to learn
PartyMenuTryEvolution(taskId);
break;
case MON_HAS_MAX_MOVES:
DisplayMonNeedsToReplaceMove(taskId);
break;
case MON_ALREADY_KNOWS_MOVE:
gTasks[taskId].func = Task_TryLearningNextMove;
break;
default:
DisplayMonLearnedMove(taskId, learnMove);
break;
SetMonData(&gPlayerParty[gPartyMenu.slotId], MON_DATA_LEVEL, &sInitialLevel);
learnMove = MonTryLearningNewMove(&gPlayerParty[gPartyMenu.slotId], TRUE);
gPartyMenu.learnMoveState = 1;
switch (learnMove)
{
case 0: // No moves to learn
if (sInitialLevel >= sFinalLevel)
PartyMenuTryEvolution(taskId);
break;
case MON_HAS_MAX_MOVES:
DisplayMonNeedsToReplaceMove(taskId);
break;
case MON_ALREADY_KNOWS_MOVE:
gTasks[taskId].func = Task_TryLearningNextMove;
break;
default:
DisplayMonLearnedMove(taskId, learnMove);
break;
}
if (learnMove)
break;
}
}
}
static void Task_TryLearningNextMove(u8 taskId)
{
u16 result = MonTryLearningNewMove(&gPlayerParty[gPartyMenu.slotId], FALSE);
switch (result)
u16 result;
for (; sInitialLevel <= sFinalLevel; sInitialLevel++)
{
case 0: // No moves to learn
PartyMenuTryEvolution(taskId);
break;
case MON_HAS_MAX_MOVES:
DisplayMonNeedsToReplaceMove(taskId);
break;
case MON_ALREADY_KNOWS_MOVE:
return;
default:
DisplayMonLearnedMove(taskId, result);
break;
SetMonData(&gPlayerParty[gPartyMenu.slotId], MON_DATA_LEVEL, &sInitialLevel);
result = MonTryLearningNewMove(&gPlayerParty[gPartyMenu.slotId], FALSE);
switch (result)
{
case 0: // No moves to learn
break;
case MON_HAS_MAX_MOVES:
DisplayMonNeedsToReplaceMove(taskId);
break;
case MON_ALREADY_KNOWS_MOVE:
return;
default:
DisplayMonLearnedMove(taskId, result);
break;
}
if (result)
break;
}
if (sInitialLevel >= sFinalLevel)
PartyMenuTryEvolution(taskId);
}
static void PartyMenuTryEvolution(u8 taskId)

View File

@ -5470,6 +5470,15 @@ bool8 ExecuteTableBasedItemEffect(struct Pokemon *mon, u16 item, u8 partyIndex,
} \
}
// EXP candies store an index for this table in their holdEffectParam.
static const u32 sExpCandyExperienceTable[] = {
[EXP_100 - 1] = 100,
[EXP_800 - 1] = 800,
[EXP_3000 - 1] = 3000,
[EXP_10000 - 1] = 10000,
[EXP_30000 - 1] = 30000,
};
// Returns TRUE if the item has no effect on the Pokémon, FALSE otherwise
bool8 PokemonUseItemEffects(struct Pokemon *mon, u16 item, u8 partyIndex, u8 moveIndex, bool8 usedByAI)
{
@ -5664,11 +5673,22 @@ bool8 PokemonUseItemEffects(struct Pokemon *mon, u16 item, u8 partyIndex, u8 mov
retVal = FALSE;
}
// Rare Candy
// Rare Candy / EXP Candy
if ((itemEffect[i] & ITEM3_LEVEL_UP)
&& GetMonData(mon, MON_DATA_LEVEL, NULL) != MAX_LEVEL)
{
dataUnsigned = gExperienceTables[gBaseStats[GetMonData(mon, MON_DATA_SPECIES, NULL)].growthRate][GetMonData(mon, MON_DATA_LEVEL, NULL) + 1];
u8 param = ItemId_GetHoldEffectParam(item);
if (param == 0) // Rare Candy
{
dataUnsigned = gExperienceTables[gBaseStats[GetMonData(mon, MON_DATA_SPECIES, NULL)].growthRate][GetMonData(mon, MON_DATA_LEVEL, NULL) + 1];
}
else if (param < ARRAY_COUNT(sExpCandyExperienceTable)) // EXP Candies
{
u16 species = GetMonData(mon, MON_DATA_SPECIES, NULL);
dataUnsigned = sExpCandyExperienceTable[param - 1] + GetMonData(mon, MON_DATA_EXP, NULL);
if (dataUnsigned > gExperienceTables[gBaseStats[species].growthRate][MAX_LEVEL])
dataUnsigned = gExperienceTables[gBaseStats[species].growthRate][MAX_LEVEL];
}
SetMonData(mon, MON_DATA_EXP, &dataUnsigned);
CalculateMonStats(mon);
retVal = FALSE;

View File

@ -417,6 +417,7 @@ const u8 gText_PkmnRegainhedHealth[] = _("{STR_VAR_1} regained health.{PAUSE_UNT
const u8 gText_PkmnBecameHealthy[] = _("{STR_VAR_1} became healthy.{PAUSE_UNTIL_PRESS}");
const u8 gText_MovesPPIncreased[] = _("{STR_VAR_1}'s PP increased.{PAUSE_UNTIL_PRESS}");
const u8 gText_PkmnElevatedToLvVar2[] = _("{STR_VAR_1} was elevated to\nLv. {STR_VAR_2}.");
const u8 gText_PkmnGainedExp[] = _("{STR_VAR_1} gained Exp. Points!{PAUSE_UNTIL_PRESS}");
const u8 gText_PkmnBaseVar2StatIncreased[] = _("{STR_VAR_1}'s base {STR_VAR_2}\nstat was raised.{PAUSE_UNTIL_PRESS}");
const u8 gText_PkmnFriendlyBaseVar2Fell[] = _("{STR_VAR_1} turned friendly.\nThe base {STR_VAR_2} fell!{PAUSE_UNTIL_PRESS}");
const u8 gText_PkmnAdoresBaseVar2Fell[] = _("{STR_VAR_1} adores you!\nThe base {STR_VAR_2} fell!{PAUSE_UNTIL_PRESS}");