-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Gen 6 style Exp. Share Alternative Option
voloved edited this page Feb 17, 2023
·
4 revisions
By devolov
Goal: Change the effect of EXP Share, where all Pokemon not in battle will gain half of the total experience given. It can be toggled as a key item.
Credit goes to Lunos for the original method. The biggest difference for this one is that the message that states the amount of Exp given from Exp Share is shown as a single message so a party of 6 won't show an Exp message 6 times.
------------------------- src/battle_script_commands.c -------------------------
index f73cae167..45995acdb 100644
@@ -3251,9 +3251,8 @@ static void Cmd_getexp(void)
u16 item;
s32 i; // also used as stringId
u8 holdEffect;
s32 sentIn;
- s32 viaExpShare = 0;
u16 *exp = &gBattleStruct->expValue;
gBattlerFainted = GetBattlerForBattleScript(gBattlescriptCurrInstr[1]);
sentIn = gSentPokesToOpponent[(gBattlerFainted & 2) >> 1];
@@ -3285,8 +3284,9 @@ static void Cmd_getexp(void)
case 1: // calculate experience points to redistribute
{
u16 calculatedExp;
s32 viaSentIn;
+ gExpShareCheck = FALSE;
for (viaSentIn = 0, i = 0; i < PARTY_SIZE; i++)
{
- if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES) == SPECIES_NONE || GetMonData(&gPlayerParty[i], MON_DATA_HP) == 0)
+ if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES) == SPECIES_NONE || GetMonData(&gPlayerParty[i], MON_DATA_IS_EGG)
+ || GetMonData(&gPlayerParty[i], MON_DATA_HP) == 0)
continue;
if (gBitTable[i] & sentIn)
viaSentIn++;
@@ -3299,11 +3299,8 @@ static void Cmd_getexp(void)
if (item == ITEM_ENIGMA_BERRY)
holdEffect = gSaveBlock1Ptr->enigmaBerry.holdEffect;
else
holdEffect = ItemId_GetHoldEffect(item);
-
- if (holdEffect == HOLD_EFFECT_EXP_SHARE)
- viaExpShare++;
}
calculatedExp = gSpeciesInfo[gBattleMons[gBattlerFainted].species].expYield * gBattleMons[gBattlerFainted].level / 7;
@@ -3324,25 +3321,15 @@ static void Cmd_getexp(void)
calculatedExp = 0;
break;
}
- if (viaExpShare) // at least one mon is getting exp via exp share
- {
- *exp = SAFE_DIV(calculatedExp / 2, viaSentIn);
- if (*exp == 0)
- *exp = 1;
+ *exp = SAFE_DIV(calculatedExp, viaSentIn);
+ if (*exp == 0)
+ *exp = 1;
- gExpShareExp = calculatedExp / 2 / viaExpShare;
- if (gExpShareExp == 0)
- gExpShareExp = 1;
- }
- else
- {
- *exp = SAFE_DIV(calculatedExp, viaSentIn);
- if (*exp == 0)
- *exp = 1;
- gExpShareExp = 0;
- }
+ gExpShareExp = calculatedExp / 2;
+ if (gExpShareExp == 0)
+ gExpShareExp = 1;
gBattleScripting.getexpState++;
gBattleStruct->expGetterMonId = 0;
gBattleStruct->sentInPokes = sentIn;
@@ -3357,19 +3344,17 @@ static void Cmd_getexp(void)
holdEffect = gSaveBlock1Ptr->enigmaBerry.holdEffect;
else
holdEffect = ItemId_GetHoldEffect(item);
- if (holdEffect != HOLD_EFFECT_EXP_SHARE && !(gBattleStruct->sentInPokes & 1))
+ if (gExpShareCheck == ((gBattleStruct->sentInPokes & (1 << gBattleStruct->expGetterMonId)) != 0))
{
- *(&gBattleStruct->sentInPokes) >>= 1;
gBattleScripting.getexpState = 5;
gBattleMoveDamage = 0; // used for exp
}
else if (GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_LEVEL) == MAX_LEVEL
|| levelCappedNuzlocke(GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_LEVEL))
|| VarGet(VAR_EXP_MULT) == 4)
{
- *(&gBattleStruct->sentInPokes) >>= 1;
gBattleScripting.getexpState = 5;
gBattleMoveDamage = 0; // used for exp
}
+ else if (GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_SPECIES) == SPECIES_NONE
+ || GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_IS_EGG))
+ {
+ gBattleScripting.getexpState = 5;
+ gBattleMoveDamage = 0; // used for exp
+ }
else
{
// music change in wild battle after fainting a poke
if (!(gBattleTypeFlags & BATTLE_TYPE_TRAINER) && gBattleMons[0].hp && !gBattleStruct->wildVictorySong)
@@ -3383,17 +3368,17 @@ static void Cmd_getexp(void)
}
if (GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_HP))
{
- if (gBattleStruct->sentInPokes & 1)
+ if (gBattleStruct->sentInPokes & (1 << gBattleStruct->expGetterMonId))
gBattleMoveDamage = *exp;
+ else if (gExpShareCheck)
+ gBattleMoveDamage += gExpShareExp;
else
gBattleMoveDamage = 0;
- if (holdEffect == HOLD_EFFECT_EXP_SHARE)
- gBattleMoveDamage += gExpShareExp;
if (holdEffect == HOLD_EFFECT_LUCKY_EGG)
gBattleMoveDamage = (gBattleMoveDamage * 150) / 100;
if (gBattleTypeFlags & BATTLE_TYPE_TRAINER)
gBattleMoveDamage = (gBattleMoveDamage * 150) / 100;
if (IsTradedMon(&gPlayerParty[gBattleStruct->expGetterMonId]))
@@ -3435,13 +3420,12 @@ static void Cmd_getexp(void)
PREPARE_MON_NICK_WITH_PREFIX_BUFFER(gBattleTextBuff1, gBattleStruct->expGetterBattlerId, gBattleStruct->expGetterMonId);
// buffer 'gained' or 'gained a boosted'
PREPARE_STRING_BUFFER(gBattleTextBuff2, i);
PREPARE_WORD_NUMBER_BUFFER(gBattleTextBuff3, 5, gBattleMoveDamage);
-
- PrepareStringBattle(STRINGID_PKMNGAINEDEXP, gBattleStruct->expGetterBattlerId);
+ if (gBattleStruct->sentInPokes & (1 << gBattleStruct->expGetterMonId))
+ PrepareStringBattle(STRINGID_PKMNGAINEDEXP, gBattleStruct->expGetterBattlerId);
MonGainEVs(&gPlayerParty[gBattleStruct->expGetterMonId], gBattleMons[gBattlerFainted].species);
}
- gBattleStruct->sentInPokes >>= 1;
gBattleScripting.getexpState++;
}
}
break;
@@ -3533,8 +3517,15 @@ static void Cmd_getexp(void)
{
gBattleStruct->expGetterMonId++;
if (gBattleStruct->expGetterMonId < PARTY_SIZE)
gBattleScripting.getexpState = 2; // loop again
- else
- gBattleScripting.getexpState = 6; // we're done
+ else{
+ s32 totalMon = 0;
+ s32 viaSentIn = 0;
+ sentIn = gSentPokesToOpponent[(gBattlerFainted & 2) >> 1];
+ for (viaSentIn = 0, i = 0; i < PARTY_SIZE; i++) // To see if every mon has seen battle
+ {
+ if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES) == SPECIES_NONE || GetMonData(&gPlayerParty[i], MON_DATA_IS_EGG)
+ || GetMonData(&gPlayerParty[i], MON_DATA_HP) == 0)
+ continue;
+ totalMon++;
+ if (gBitTable[i] & sentIn)
+ viaSentIn++;
+ }
+ if (!gExpShareCheck && FlagGet(FLAG_EXP_SHARE) && totalMon>viaSentIn){
+ gExpShareCheck = TRUE;
+ gBattleStruct->expGetterMonId = 0;
+ PREPARE_WORD_NUMBER_BUFFER(gBattleTextBuff3, 5, gExpShareExp);
+ PrepareStringBattle(STRINGID_PKMNGAINEDEXPALL, gBattleStruct->expGetterBattlerId);
+ gBattleScripting.getexpState = 2; // loop again
+ }
+ else
+ gBattleScripting.getexpState = 6; // we're done
+ }
}
break;
------------------------------ src/battle_main.c ------------------------------
index 2f7a5906e..b6f858a17 100644
@@ -219,8 +219,9 @@ EWRAM_DATA struct WishFutureKnock gWishFutureKnock = {0};
EWRAM_DATA u16 gIntroSlideFlags = 0;
EWRAM_DATA u8 gSentPokesToOpponent[2] = {0};
EWRAM_DATA u16 gDynamicBasePower = 0;
EWRAM_DATA u16 gExpShareExp = 0;
+EWRAM_DATA bool8 gExpShareCheck = 0;
EWRAM_DATA struct BattleEnigmaBerry gEnigmaBerries[MAX_BATTLERS_COUNT] = {0};
EWRAM_DATA struct BattleScripting gBattleScripting = {0};
EWRAM_DATA struct BattleStruct *gBattleStruct = NULL;
EWRAM_DATA u8 *gLinkBattleSendBuffer = NULL;
------------------------------- include/battle.h -------------------------------
index 09571efb9..ae058777a 100644
@@ -688,8 +688,9 @@ extern struct WishFutureKnock gWishFutureKnock;
extern u16 gIntroSlideFlags;
extern u8 gSentPokesToOpponent[2];
extern u16 gDynamicBasePower;
extern u16 gExpShareExp;
+extern bool8 gExpShareCheck;
extern struct BattleEnigmaBerry gEnigmaBerries[MAX_BATTLERS_COUNT];
extern struct BattleScripting gBattleScripting;
extern struct BattleStruct *gBattleStruct;
extern u8 *gLinkBattleSendBuffer;
----------------------------- src/battle_message.c -----------------------------
index a9dc15a38..11f7f8d5f 100644
@@ -56,8 +56,9 @@ EWRAM_DATA struct BattleMsgData *gBattleMsgDataPtr = NULL;
static const u8 sText_PlayerLostToEnemyTrainer[] = _("{B_PLAYER_NAME} is out of\nusable POKéMON!\pPlayer lost against\n{B_TRAINER1_CLASS} {B_TRAINER1_NAME}!{PAUSE_UNTIL_PRESS}");
static const u8 sText_PlayerPaidPrizeMoney[] = _("{B_PLAYER_NAME} paid ¥{B_BUFF1} as the prize\nmoney…\p{B_PLAYER_NAME} whited out!{PAUSE_UNTIL_PRESS}");
static const u8 sText_Trainer1LoseText[] = _("{B_TRAINER1_LOSE_TEXT}");
static const u8 sText_PkmnGainedEXP[] = _("{B_BUFF1} gained{B_BUFF2}\n{B_BUFF3} EXP. Points!\p");
+static const u8 sText_PkmnGainedEXPAll[] = _("All others in party gained at least\n{B_BUFF3} EXP due to EXP SHARE.\p");
static const u8 sText_EmptyString4[] = _("");
static const u8 sText_ABoosted[] = _(" a boosted");
static const u8 sText_PkmnGrewToLv[] = _("{B_BUFF1} grew to\nLV. {B_BUFF2}!{WAIT_SE}\p");
static const u8 sText_PkmnLearnedMove[] = _("{B_BUFF1} learned\n{B_BUFF2}!{WAIT_SE}\p");
@@ -899,8 +900,9 @@ const u8 * const gBattleStringsTable[BATTLESTRINGS_COUNT - BATTLESTRINGS_TABLE_S
[STRINGID_CANTWITHTHIEF - BATTLESTRINGS_TABLE_START] = sText_CantWithThief,
[STRINGID_TOOMANYWITNESSES - BATTLESTRINGS_TABLE_START] = sText_TooManyWitnesses,
[STRINGID_GOTCHAPKMNCAUGHTNOBGM - BATTLESTRINGS_TABLE_START] = sText_GotchaPkmnCaughtNoBgm,
[STRINGID_CANTWITHNUZLOCKE - BATTLESTRINGS_TABLE_START] = sText_CantWithNuzlocke,
+ [STRINGID_PKMNGAINEDEXPALL - BATTLESTRINGS_TABLE_START] = sText_PkmnGainedEXPAll,
};
const u16 gMissStringIds[] =
{
-------------------- include/constants/battle_string_ids.h --------------------
index 4681fc010..a8ca696c5 100644
@@ -385,10 +385,11 @@
#define STRINGID_CANTWITHTHIEF 383
#define STRINGID_TOOMANYWITNESSES 384
#define STRINGID_GOTCHAPKMNCAUGHTNOBGM 385
#define STRINGID_CANTWITHNUZLOCKE 386
+#define STRINGID_PKMNGAINEDEXPALL 387
-#define BATTLESTRINGS_COUNT 387
+#define BATTLESTRINGS_COUNT 388
// This is the string id that gBattleStringsTable starts with.
// String ids before this (e.g. STRINGID_INTROMSG) are not in the table,
// and are instead handled explicitly by BufferStringBattle.
---------------------- src/data/text/item_descriptions.h ----------------------
index 8ee0cb369..2be1d969b 100644
@@ -729,10 +729,10 @@ static const u8 sMachoBraceDesc[] = _(
"but reduces SPEED.");
static const u8 sExpShareDesc[] = _(
- "A hold item that\n"
- "gets EXP. points\n"
- "from battles.");
+ "Turning this on\n"
+ "gives all in party\n"
+ "EXP. points.");
static const u8 sQuickClawDesc[] = _(
"A hold item that\n"
"occasionally allows\n"
--------------- data/maps/RustboroCity_DevonCorp_3F/scripts.inc ---------------
index ebf9044c5..3dc3a4fcf 100644
@@ -250,13 +250,12 @@ RustboroCity_DevonCorp_3F_Text_ThankYouForDeliveringLetter:
.string "This is my way of thanking you.\n"
.string "It should help you, a TRAINER.$"
RustboroCity_DevonCorp_3F_Text_ExplainExpShare:
- .string "MR. STONE: A POKéMON holding that\n"
- .string "EXP. SHARE will be given some of the\l"
- .string "EXP Points from battle.\p"
+ .string "MR. STONE: If you turn EXP. SHARE on,\n"
+ .string "all POKéMON in the party will gain\l"
+ .string "half the EXP Points from battle.\p"
- .string "It will get EXP Points even if it didn't\n"
- .string "actually battle.\p"
.string "I would say EXP. SHARE is quite useful\n"
.string "for raising weak POKéMON.$"
RustboroCity_DevonCorp_3F_Text_NotFamiliarWithTrends:
------------------------------- src/data/items.h -------------------------------
index 0658f9438..c93ccdb2a 100644
@@ -2223,14 +2223,15 @@ const struct Item gItems[] =
[ITEM_EXP_SHARE] =
{
.name = _("EXP. SHARE"),
.itemId = ITEM_EXP_SHARE,
- .price = 3000,
- .holdEffect = HOLD_EFFECT_EXP_SHARE,
+ .price = 0,
+ .importance = 1,
+ .registrability = TRUE,
.description = sExpShareDesc,
- .pocket = POCKET_ITEMS,
- .type = ITEM_USE_BAG_MENU,
- .fieldUseFunc = ItemUseOutOfBattle_CannotUse,
+ .pocket = POCKET_KEY_ITEMS,
+ .type = ITEM_USE_FIELD,
+ .fieldUseFunc = ItemUseOutOfBattle_ExpShare,
},
[ITEM_QUICK_CLAW] =
{
-------------------------------- src/item_use.c --------------------------------
index 8e62af305..bb8d8d60f 100755
@@ -1142,5 +1142,28 @@ void ItemUseOutOfBattle_CannotUse(u8 taskId)
{
DisplayDadsAdviceCannotUseItemMessage(taskId, gTasks[taskId].tUsingRegisteredKeyItem);
}
+void ItemUseOutOfBattle_ExpShare(u8 taskId)
+{
+ bool8 expShareOn = FlagGet(FLAG_EXP_SHARE);
+ if (!expShareOn)
+ {
+ FlagSet(FLAG_EXP_SHARE);
+ PlaySE(SE_EXP_MAX);
+ if (gTasks[taskId].tUsingRegisteredKeyItem) // to account for pressing select in the overworld
+ DisplayItemMessageOnField(taskId, gText_ExpShareTurnOn, Task_CloseCantUseKeyItemMessage);
+ else
+ DisplayItemMessage(taskId, 1, gText_ExpShareTurnOn, CloseItemMessage);
+ }
+ else
+ {
+ FlagClear(FLAG_EXP_SHARE);
+ PlaySE(SE_PC_OFF);
+ if (gTasks[taskId].tUsingRegisteredKeyItem) // to account for pressing select in the overworld
+ DisplayItemMessageOnField(taskId, gText_ExpShareTurnOff, Task_CloseCantUseKeyItemMessage);
+ else
+ DisplayItemMessage(taskId, 1, gText_ExpShareTurnOff, CloseItemMessage);
+ }
+}
+
#undef tUsingRegisteredKeyItem
------------------------------ include/item_use.h ------------------------------
index f577f8d46..7173a9751 100644
@@ -23,8 +23,9 @@ void ItemUseOutOfBattle_BlackWhiteFlute(u8);
void ItemUseOutOfBattle_EvolutionStone(u8);
void ItemUseOutOfBattle_Berry(u8);
void ItemUseOutOfBattle_EnigmaBerry(u8);
void ItemUseOutOfBattle_CannotUse(u8);
+void ItemUseOutOfBattle_ExpShare(u8);
void ItemUseInBattle_PokeBall(u8);
void ItemUseInBattle_StatIncrease(u8);
void ItemUseInBattle_Medicine(u8);
void ItemUseInBattle_PPRecovery(u8);
-------------------------------- src/strings.c --------------------------------
index e5a52ebe5..27e812889 100644
@@ -235,8 +235,10 @@ const u8 gText_TooImportantToToss[] = _("That's much too\nimportant to toss\nout
const u8 gText_TossHowManyVar1s[] = _("Toss out how many\n{STR_VAR_1}(s)?");
const u8 gText_ThrewAwayVar2Var1s[] = _("Threw away {STR_VAR_2}\n{STR_VAR_1}(s).");
const u8 gText_ConfirmTossItems[] = _("Is it okay to\nthrow away {STR_VAR_2}\n{STR_VAR_1}(s)?");
const u8 gText_DadsAdvice[] = _("DAD's advice…\n{PLAYER}, there's a time and place for\leverything!{PAUSE_UNTIL_PRESS}");
+const u8 gText_ExpShareTurnOn[] = _("Turned on the Exp. Share.\pParty will now gain a portion\nof the Experience Points.{PAUSE_UNTIL_PRESS}");
+const u8 gText_ExpShareTurnOff[] = _("Turned off the Exp. Share.\pParty will no longer gain a portion\nof any Experience Points.{PAUSE_UNTIL_PRESS}");
const u8 gText_CantDismountBike[] = _("You can't dismount your BIKE here.{PAUSE_UNTIL_PRESS}");
const u8 gText_ItemFinderNearby[] = _("Huh?\nThe ITEMFINDER's responding!\pThere's an item buried around here!{PAUSE_UNTIL_PRESS}");
const u8 gText_ItemFinderOnTop[] = _("Oh!\nThe ITEMFINDER's shaking wildly!{PAUSE_UNTIL_PRESS}");
const u8 gText_ItemFinderNothing[] = _("… … … …Nope!\nThere's no response.{PAUSE_UNTIL_PRESS}");
------------------------------ include/strings.h ------------------------------
index 59263096a..021b6fefa 100644
@@ -932,8 +932,10 @@ extern const u8 gText_John[];
extern const u8 gText_Roy[];
extern const u8 gText_Gabby[];
extern const u8 gText_Anna[];
+extern const u8 gText_ExpShareTurnOn[];
+extern const u8 gText_ExpShareTurnOff[];
extern const u8 gText_DadsAdvice[];
extern const u8 gText_CantDismountBike[];
extern const u8 gText_ItemFinderNothing[];
extern const u8 gText_ItemFinderNearby[];
-------------------------- include/constants/flags.h --------------------------
index 63b491195..c28a7bf65 100644
@@ -1235,9 +1235,9 @@
#define FLAG_NUZLOCKE_BATTLE_SET 0x4A2
#define FLAG_NUZLOCKE_LEVEL_CAP 0x4A3
#define FLAG_NUZLOCKE_NO_HELD_ITEMS 0x4A4
#define FLAG_NUZLOCKE_NO_BATTLE_ITEMS 0x4A5
-#define FLAG_UNUSED_0x4A6 0x4A6 // Unused Flag
+#define FLAG_EXP_SHARE 0x4A6
#define FLAG_UNUSED_0x4A7 0x4A7 // Unused Flag
#define FLAG_UNUSED_0x4A8 0x4A8 // Unused Flag
#define FLAG_UNUSED_0x4A9 0x4A9 // Unused Flag
#define FLAG_UNUSED_0x4AA 0x4AA // Unused Flag