From 03c21c3b71f848340baf90bad318c0027622b6e5 Mon Sep 17 00:00:00 2001 From: AgustinGDLV Date: Sun, 15 May 2022 21:28:23 -0700 Subject: [PATCH] implementation of EXP candies --- src/data/items.h | 36 ++++++++++++++++++++++++--------- src/data/pokemon/item_effects.h | 10 ++++----- src/pokemon.c | 26 +++++++++++++++++++++++- 3 files changed, 56 insertions(+), 16 deletions(-) diff --git a/src/data/items.h b/src/data/items.h index 63ad66dfe..298f65b4a 100644 --- a/src/data/items.h +++ b/src/data/items.h @@ -1354,11 +1354,17 @@ const struct Item gItems[] = // Candy +#define ONE_HUNDRED 1 << 4 +#define ONE_THOUSAND 1 << 5 +#define TEN_THOUSAND 1 << 6 +#define FULL_LEVEL 1 << 7 + [ITEM_RARE_CANDY] = { .name = _("Rare Candy"), .itemId = ITEM_RARE_CANDY, .price = 10000, + .holdEffectParam = FULL_LEVEL, .description = sRareCandyDesc, .pocket = POCKET_ITEMS, .type = ITEM_USE_PARTY_MENU, @@ -1371,10 +1377,11 @@ const struct Item gItems[] = .name = _("Exp.Candy XS"), .itemId = ITEM_EXP_CANDY_XS, .price = 20, + .holdEffectParam = 1 | ONE_HUNDRED, .description = sExpCandyXSDesc, .pocket = POCKET_ITEMS, - .type = ITEM_USE_BAG_MENU, - .fieldUseFunc = ItemUseOutOfBattle_CannotUse, // Todo + .type = ITEM_USE_PARTY_MENU, + .fieldUseFunc = ItemUseOutOfBattle_RareCandy, // Todo .flingPower = 30, }, @@ -1383,10 +1390,11 @@ const struct Item gItems[] = .name = _("Exp.Candy S"), .itemId = ITEM_EXP_CANDY_S, .price = 240, + .holdEffectParam = 8 | ONE_HUNDRED, .description = sExpCandyXSDesc, .pocket = POCKET_ITEMS, - .type = ITEM_USE_BAG_MENU, - .fieldUseFunc = ItemUseOutOfBattle_CannotUse, // Todo + .type = ITEM_USE_PARTY_MENU, + .fieldUseFunc = ItemUseOutOfBattle_RareCandy, // Todo .flingPower = 30, }, @@ -1395,10 +1403,11 @@ const struct Item gItems[] = .name = _("Exp.Candy M"), .itemId = ITEM_EXP_CANDY_M, .price = 1000, + .holdEffectParam = 3 | ONE_THOUSAND, .description = sExpCandyMDesc, .pocket = POCKET_ITEMS, - .type = ITEM_USE_BAG_MENU, - .fieldUseFunc = ItemUseOutOfBattle_CannotUse, // Todo + .type = ITEM_USE_PARTY_MENU, + .fieldUseFunc = ItemUseOutOfBattle_RareCandy, // Todo .flingPower = 30, }, @@ -1407,10 +1416,11 @@ const struct Item gItems[] = .name = _("Exp.Candy L"), .itemId = ITEM_EXP_CANDY_L, .price = 3000, + .holdEffectParam = 1 | TEN_THOUSAND, .description = sExpCandyLDesc, .pocket = POCKET_ITEMS, - .type = ITEM_USE_BAG_MENU, - .fieldUseFunc = ItemUseOutOfBattle_CannotUse, // Todo + .type = ITEM_USE_PARTY_MENU, + .fieldUseFunc = ItemUseOutOfBattle_RareCandy, // Todo .flingPower = 30, }, @@ -1419,10 +1429,11 @@ const struct Item gItems[] = .name = _("Exp.Candy XL"), .itemId = ITEM_EXP_CANDY_XL, .price = 10000, + .holdEffectParam = 3 | TEN_THOUSAND, .description = sExpCandyXLDesc, .pocket = POCKET_ITEMS, - .type = ITEM_USE_BAG_MENU, - .fieldUseFunc = ItemUseOutOfBattle_CannotUse, // Todo + .type = ITEM_USE_PARTY_MENU, + .fieldUseFunc = ItemUseOutOfBattle_RareCandy, // Todo .flingPower = 30, }, @@ -1438,6 +1449,11 @@ const struct Item gItems[] = .flingPower = 30, }, +#undef ONE_HUNDRED +#undef ONE_THOUSAND +#undef TEN_THOUSAND +#undef FULL_LEVEL + // Medicinal Flutes [ITEM_BLUE_FLUTE] = diff --git a/src/data/pokemon/item_effects.h b/src/data/pokemon/item_effects.h index ff621356e..8892cb66f 100644 --- a/src/data/pokemon/item_effects.h +++ b/src/data/pokemon/item_effects.h @@ -532,11 +532,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, // Todo + [ITEM_EXP_CANDY_S - ITEM_POTION] = gItemEffect_RareCandy, // Todo + [ITEM_EXP_CANDY_M - ITEM_POTION] = gItemEffect_RareCandy, // Todo + [ITEM_EXP_CANDY_L - ITEM_POTION] = gItemEffect_RareCandy, // Todo + [ITEM_EXP_CANDY_XL - ITEM_POTION] = gItemEffect_RareCandy, // Todo //[ITEM_DYNAMAX_CANDY - ITEM_POTION] = gItemEffect_DynamaxCandy, // Todo // Medicinal Flutes diff --git a/src/pokemon.c b/src/pokemon.c index 11be4da1f..f987b24a8 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -4873,16 +4873,40 @@ bool8 PokemonUseItemEffects(struct Pokemon *mon, u16 item, u8 partyIndex, u8 mov retVal = FALSE; } +#define ONE_HUNDRED 1 << 4 +#define ONE_THOUSAND 1 << 5 +#define TEN_THOUSAND 1 << 6 +#define FULL_LEVEL 1 << 7 + // Rare 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]; + if (ItemId_GetHoldEffectParam(item) & FULL_LEVEL) + dataUnsigned = gExperienceTables[gBaseStats[GetMonData(mon, MON_DATA_SPECIES, NULL)].growthRate][GetMonData(mon, MON_DATA_LEVEL, NULL) + 1]; + else + { + temp1 = ItemId_GetHoldEffectParam(item) & 0x0F; + if (ItemId_GetHoldEffectParam(item) & ONE_HUNDRED) + temp1 *= 100; + if (ItemId_GetHoldEffectParam(item) & ONE_THOUSAND) + temp1 *= 1000; + if (ItemId_GetHoldEffectParam(item) & TEN_THOUSAND) + temp1 *= 10000; + dataUnsigned = temp1 + gExperienceTables[gBaseStats[GetMonData(mon, MON_DATA_SPECIES, NULL)].growthRate][GetMonData(mon, MON_DATA_LEVEL, NULL)]; + if (dataUnsigned > gExperienceTables[gBaseStats[GetMonData(mon, MON_DATA_SPECIES, NULL)].growthRate][MAX_LEVEL]) + dataUnsigned = gExperienceTables[gBaseStats[GetMonData(mon, MON_DATA_SPECIES, NULL)].growthRate][MAX_LEVEL]; + } SetMonData(mon, MON_DATA_EXP, &dataUnsigned); CalculateMonStats(mon); retVal = FALSE; } +#undef ONE_HUNDRED +#undef ONE_THOUSAND +#undef TEN_THOUSAND +#undef FULL_LEVEL + // Cure status if ((itemEffect[i] & ITEM3_SLEEP) && HealStatusConditions(mon, partyIndex, STATUS1_SLEEP, battlerId) == 0)