From d6bc8a1e63812fa9cda5ff0e3c9757dd6f4fe510 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Tue, 8 Dec 2020 17:45:11 -0300 Subject: [PATCH 1/9] Reworked the effects of the X Items Thanks to Karathan's indications. --- include/constants/battle_config.h | 2 + include/constants/item_effects.h | 14 ++++ src/battle_ai_switch_items.c | 21 ++++++ src/party_menu.c | 4 + src/pokemon.c | 117 ++++++++++++++++++++++++++++++ 5 files changed, 158 insertions(+) diff --git a/include/constants/battle_config.h b/include/constants/battle_config.h index 55c62af987f2..90a50a81c2a2 100644 --- a/include/constants/battle_config.h +++ b/include/constants/battle_config.h @@ -123,6 +123,8 @@ // Item settings #define B_HP_BERRIES GEN_6 // In Gen4+, berries which restore hp activate immediately after hp drops to half. In gen3, the effect occurs at the end of the turn. #define B_BERRIES_INSTANT GEN_6 // In Gen4+, most berries activate on battle start/switch-in if applicable. In gen3, they only activate either at the move end or turn end. +#define X_ITEMS_REWORK FALSE // This flag changes the way in which X Items' effects are implemented in the code and relies on the item_expansion to work. +#define B_X_ITEMS_BUFF GEN_7 // In Gen7+, the X Items raise a stat by 2 stages instead of 1. This flag relies on X_ITEMS_REWORK, and by extension, the item_expansion. // Flag settings. // To use the following features in scripting, replace the 0s with the flag ID you're assigning it to. Eg: Replace with FLAG_UNUSED_0x264 so you can use that flag for toggling the feature. diff --git a/include/constants/item_effects.h b/include/constants/item_effects.h index 6e61c4d7f9b5..8d97cdd7dae0 100644 --- a/include/constants/item_effects.h +++ b/include/constants/item_effects.h @@ -2,18 +2,32 @@ #define GUARD_CONSTANTS_ITEM_EFFECTS_H // field 0 masks +#if X_ITEMS_REWORK == FALSE #define ITEM0_X_ATTACK 0x0F +#endif #define ITEM0_DIRE_HIT 0x30 // Works the same way as the move Focus Energy. #define ITEM0_SACRED_ASH 0x40 #define ITEM0_INFATUATION 0x80 // field 1 masks +#if X_ITEMS_REWORK == FALSE #define ITEM1_X_SPEED 0x0F #define ITEM1_X_DEFEND 0xF0 // field 2 masks #define ITEM2_X_SPATK 0x0F #define ITEM2_X_ACCURACY 0xF0 +#endif + +// alt field 1 masks +#if X_ITEMS_REWORK == TRUE +#define ITEM1_X_ATTACK 0x1 +#define ITEM1_X_DEFEND 0x2 +#define ITEM1_X_SPEED 0x4 +#define ITEM1_X_SPATK 0x8 +#define ITEM1_X_SPDEF 0x10 +#define ITEM1_X_ACCURACY 0x20 +#endif // field 3 masks #define ITEM3_CONFUSION 0x1 diff --git a/src/battle_ai_switch_items.c b/src/battle_ai_switch_items.c index 3d3bdc4c0160..c106d7d9c1fb 100644 --- a/src/battle_ai_switch_items.c +++ b/src/battle_ai_switch_items.c @@ -773,7 +773,11 @@ static u8 GetAI_ItemType(u16 itemId, const u8 *itemEffect) return AI_ITEM_HEAL_HP; else if (itemEffect[3] & ITEM3_STATUS_ALL) return AI_ITEM_CURE_CONDITION; +#if X_ITEMS_REWORK == TRUE + else if ((itemEffect[0] & ITEM0_DIRE_HIT) || itemEffect[1]) +#else else if (itemEffect[0] & (ITEM0_DIRE_HIT | ITEM0_X_ATTACK) || itemEffect[1] != 0 || itemEffect[2] != 0) +#endif return AI_ITEM_X_STAT; else if (itemEffect[3] & ITEM3_GUARD_SPEC) return AI_ITEM_GUARD_SPECS; @@ -883,6 +887,7 @@ static bool8 ShouldUseItem(void) *(gBattleStruct->AI_itemFlags + gActiveBattler / 2) = 0; if (gDisableStructs[gActiveBattler].isFirstTurn == 0) break; + #if X_ITEMS_REWORK == FALSE if (itemEffects[0] & ITEM0_X_ATTACK) *(gBattleStruct->AI_itemFlags + gActiveBattler / 2) |= 0x1; if (itemEffects[1] & ITEM1_X_DEFEND) @@ -895,6 +900,22 @@ static bool8 ShouldUseItem(void) *(gBattleStruct->AI_itemFlags + gActiveBattler / 2) |= 0x20; if (itemEffects[0] & ITEM0_DIRE_HIT) *(gBattleStruct->AI_itemFlags + gActiveBattler / 2) |= 0x80; + #else + if (itemEffects[1] & ITEM1_X_ATTACK) + *(gBattleStruct->AI_itemFlags + gActiveBattler / 2) |= 0x1; + if (itemEffects[1] & ITEM1_X_DEFEND) + *(gBattleStruct->AI_itemFlags + gActiveBattler / 2) |= 0x2; + if (itemEffects[1] & ITEM1_X_SPEED) + *(gBattleStruct->AI_itemFlags + gActiveBattler / 2) |= 0x4; + if (itemEffects[1] & ITEM1_X_SPATK) + *(gBattleStruct->AI_itemFlags + gActiveBattler / 2) |= 0x8; + if (itemEffects[1] & ITEM1_X_SPDEF) + *(gBattleStruct->AI_itemFlags + gActiveBattler / 2) |= 0x10; + if (itemEffects[1] & ITEM1_X_ACCURACY) + *(gBattleStruct->AI_itemFlags + gActiveBattler / 2) |= 0x20; + if (itemEffects[0] & ITEM0_DIRE_HIT) + *(gBattleStruct->AI_itemFlags + gActiveBattler / 2) |= 0x40; + #endif shouldUse = TRUE; break; case AI_ITEM_GUARD_SPECS: diff --git a/src/party_menu.c b/src/party_menu.c index a6fcd15466c9..49906566d040 100755 --- a/src/party_menu.c +++ b/src/party_menu.c @@ -5186,7 +5186,11 @@ u8 GetItemEffectType(u16 item) else itemEffect = gItemEffectTable[item - ITEM_POTION]; +#if X_ITEMS_REWORK == FALSE if ((itemEffect[0] & (ITEM0_DIRE_HIT | ITEM0_X_ATTACK)) || itemEffect[1] || itemEffect[2] || (itemEffect[3] & ITEM3_GUARD_SPEC)) +#else + if ((itemEffect[0] & ITEM0_DIRE_HIT) || itemEffect[1] || (itemEffect[3] & ITEM3_GUARD_SPEC)) +#endif return ITEM_EFFECT_X_ITEM; else if (itemEffect[0] & ITEM0_SACRED_ASH) return ITEM_EFFECT_SACRED_ASH; diff --git a/src/pokemon.c b/src/pokemon.c index a7dd68bbf44a..901b8ab7a432 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -45,6 +45,7 @@ #include "constants/moves.h" #include "constants/songs.h" #include "constants/trainers.h" +#include "constants/battle_config.h" struct SpeciesItem { @@ -2050,7 +2051,11 @@ static const u8 sGetMonDataEVConstants[] = // For stat-raising items static const u8 sStatsToRaise[] = { +#if X_ITEMS_REWORK == FALSE STAT_ATK, STAT_ATK, STAT_SPEED, STAT_DEF, STAT_SPATK, STAT_ACC +#else + STAT_ATK, STAT_ATK, STAT_DEF, STAT_SPEED, STAT_SPATK, STAT_SPDEF, STAT_ACC +#endif }; // 3 modifiers each for how much to change friendship for different ranges @@ -4429,6 +4434,7 @@ bool8 PokemonUseItemEffects(struct Pokemon *mon, u16 item, u8 partyIndex, u8 mov gBattleMons[gActiveBattler].status2 |= STATUS2_FOCUS_ENERGY; retVal = FALSE; } + #if X_ITEMS_REWORK == FALSE if ((itemEffect[cmdIndex] & ITEM0_X_ATTACK) && gBattleMons[gActiveBattler].statStages[STAT_ATK] < MAX_STAT_STAGE) { @@ -4437,8 +4443,10 @@ bool8 PokemonUseItemEffects(struct Pokemon *mon, u16 item, u8 partyIndex, u8 mov gBattleMons[gActiveBattler].statStages[STAT_ATK] = MAX_STAT_STAGE; retVal = FALSE; } + #endif break; // in-battle stat boosting effects + #if X_ITEMS_REWORK == FALSE case 1: if ((itemEffect[cmdIndex] & ITEM1_X_DEFEND) && gBattleMons[gActiveBattler].statStages[STAT_DEF] < MAX_STAT_STAGE) @@ -4476,6 +4484,79 @@ bool8 PokemonUseItemEffects(struct Pokemon *mon, u16 item, u8 partyIndex, u8 mov retVal = FALSE; } break; + #else + // in-battle stat boosting effects + case 1: + if ((itemEffect[cmdIndex] & ITEM1_X_ATTACK) + && gBattleMons[gActiveBattler].statStages[STAT_ATK] < MAX_STAT_STAGE) + { + if (B_X_ITEMS_BUFF == GEN_7) + gBattleMons[gActiveBattler].statStages[STAT_ATK] += 2; + else + gBattleMons[gActiveBattler].statStages[STAT_ATK] += 1; + if (gBattleMons[gActiveBattler].statStages[STAT_ATK] > MAX_STAT_STAGE) + gBattleMons[gActiveBattler].statStages[STAT_ATK] = MAX_STAT_STAGE; + retVal = FALSE; + } + if ((itemEffect[cmdIndex] & ITEM1_X_DEFEND) + && gBattleMons[gActiveBattler].statStages[STAT_DEF] < MAX_STAT_STAGE) + { + if (B_X_ITEMS_BUFF == GEN_7) + gBattleMons[gActiveBattler].statStages[STAT_DEF] += 2; + else + gBattleMons[gActiveBattler].statStages[STAT_DEF] += 1; + if (gBattleMons[gActiveBattler].statStages[STAT_DEF] > MAX_STAT_STAGE) + gBattleMons[gActiveBattler].statStages[STAT_DEF] = MAX_STAT_STAGE; + retVal = FALSE; + } + if ((itemEffect[cmdIndex] & ITEM1_X_SPEED) + && gBattleMons[gActiveBattler].statStages[STAT_SPEED] < MAX_STAT_STAGE) + { + if (B_X_ITEMS_BUFF == GEN_7) + gBattleMons[gActiveBattler].statStages[STAT_SPEED] += 2; + else + gBattleMons[gActiveBattler].statStages[STAT_SPEED] += 1; + if (gBattleMons[gActiveBattler].statStages[STAT_SPEED] > MAX_STAT_STAGE) + gBattleMons[gActiveBattler].statStages[STAT_SPEED] = MAX_STAT_STAGE; + retVal = FALSE; + } + if ((itemEffect[cmdIndex] & ITEM1_X_SPATK) + && gBattleMons[gActiveBattler].statStages[STAT_SPATK] < MAX_STAT_STAGE) + { + if (B_X_ITEMS_BUFF == GEN_7) + gBattleMons[gActiveBattler].statStages[STAT_SPATK] += 2; + else + gBattleMons[gActiveBattler].statStages[STAT_SPATK] += 1; + if (gBattleMons[gActiveBattler].statStages[STAT_SPATK] > MAX_STAT_STAGE) + gBattleMons[gActiveBattler].statStages[STAT_SPATK] = MAX_STAT_STAGE; + retVal = FALSE; + } + if ((itemEffect[cmdIndex] & ITEM1_X_SPDEF) + && gBattleMons[gActiveBattler].statStages[STAT_SPDEF] < MAX_STAT_STAGE) + { + if (B_X_ITEMS_BUFF == GEN_7) + gBattleMons[gActiveBattler].statStages[STAT_SPDEF] += 2; + else + gBattleMons[gActiveBattler].statStages[STAT_SPDEF] += 1; + if (gBattleMons[gActiveBattler].statStages[STAT_SPDEF] > MAX_STAT_STAGE) + gBattleMons[gActiveBattler].statStages[STAT_SPDEF] = MAX_STAT_STAGE; + retVal = FALSE; + } + if ((itemEffect[cmdIndex] & ITEM1_X_ACCURACY) + && gBattleMons[gActiveBattler].statStages[STAT_ACC] < MAX_STAT_STAGE) + { + if (B_X_ITEMS_BUFF == GEN_7) + gBattleMons[gActiveBattler].statStages[STAT_ACC] += 2; + else + gBattleMons[gActiveBattler].statStages[STAT_ACC] += 1; + if (gBattleMons[gActiveBattler].statStages[STAT_ACC] > MAX_STAT_STAGE) + gBattleMons[gActiveBattler].statStages[STAT_ACC] = MAX_STAT_STAGE; + retVal = FALSE; + } + break; + // formerly used by the item effects of the X Sp. Atk and the X Accuracy + case 2: + #endif case 3: if ((itemEffect[cmdIndex] & ITEM3_GUARD_SPEC) && gSideTimers[GetBattlerSide(gActiveBattler)].mistTimer == 0) @@ -5046,6 +5127,7 @@ u8 *UseStatIncreaseItem(u16 itemId) gPotentialItemEffectBattler = gBattlerInMenuId; +#if X_ITEMS_REWORK == FALSE for (i = 0; i < 3; i++) { if (itemEffect[i] & (ITEM0_X_ATTACK | ITEM1_X_SPEED | ITEM2_X_SPATK)) @@ -5070,6 +5152,41 @@ u8 *UseStatIncreaseItem(u16 itemId) gBattlerAttacker = gBattlerInMenuId; BattleStringExpandPlaceholdersToDisplayedString(gText_PkmnShroudedInMist); } +#else + if (itemEffect[0] & ITEM0_DIRE_HIT) + { + gBattlerAttacker = gBattlerInMenuId; + BattleStringExpandPlaceholdersToDisplayedString(gText_PkmnGettingPumped); + } + + switch (itemEffect[1]) + { + case ITEM1_X_ATTACK: + BufferStatRoseMessage(STAT_ATK); + break; + case ITEM1_X_DEFEND: + BufferStatRoseMessage(STAT_DEF); + break; + case ITEM1_X_SPEED: + BufferStatRoseMessage(STAT_SPEED); + break; + case ITEM1_X_SPATK: + BufferStatRoseMessage(STAT_SPATK); + break; + case ITEM1_X_SPDEF: + BufferStatRoseMessage(STAT_SPDEF); + break; + case ITEM1_X_ACCURACY: + BufferStatRoseMessage(STAT_ACC); + break; + } + + if (itemEffect[3] & ITEM3_GUARD_SPEC) + { + gBattlerAttacker = gBattlerInMenuId; + BattleStringExpandPlaceholdersToDisplayedString(gText_PkmnShroudedInMist); + } +#endif return gDisplayedStringBattle; } From cb495efdc6d6fcec1b1fa87554c4de473a12ac13 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Mon, 4 Jan 2021 03:58:31 -0300 Subject: [PATCH 2/9] Tweaked preprocessor directives Changed #ifdef X_ITEMS_REWORK == FALSE to #ifndef ITEM_EXPANSION Changed #ifdef X_ITEMS_REWORK == TRUE to #ifdef ITEM_EXPANSION --- include/constants/battle_config.h | 1 - include/constants/item_effects.h | 6 +++--- src/battle_ai_switch_items.c | 4 ++-- src/party_menu.c | 2 +- src/pokemon.c | 8 ++++---- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/include/constants/battle_config.h b/include/constants/battle_config.h index 90a50a81c2a2..2eaf5e0d3e66 100644 --- a/include/constants/battle_config.h +++ b/include/constants/battle_config.h @@ -123,7 +123,6 @@ // Item settings #define B_HP_BERRIES GEN_6 // In Gen4+, berries which restore hp activate immediately after hp drops to half. In gen3, the effect occurs at the end of the turn. #define B_BERRIES_INSTANT GEN_6 // In Gen4+, most berries activate on battle start/switch-in if applicable. In gen3, they only activate either at the move end or turn end. -#define X_ITEMS_REWORK FALSE // This flag changes the way in which X Items' effects are implemented in the code and relies on the item_expansion to work. #define B_X_ITEMS_BUFF GEN_7 // In Gen7+, the X Items raise a stat by 2 stages instead of 1. This flag relies on X_ITEMS_REWORK, and by extension, the item_expansion. // Flag settings. diff --git a/include/constants/item_effects.h b/include/constants/item_effects.h index 8d97cdd7dae0..7ed183347329 100644 --- a/include/constants/item_effects.h +++ b/include/constants/item_effects.h @@ -2,7 +2,7 @@ #define GUARD_CONSTANTS_ITEM_EFFECTS_H // field 0 masks -#if X_ITEMS_REWORK == FALSE +#ifndef ITEM_EXPANSION #define ITEM0_X_ATTACK 0x0F #endif #define ITEM0_DIRE_HIT 0x30 // Works the same way as the move Focus Energy. @@ -10,7 +10,7 @@ #define ITEM0_INFATUATION 0x80 // field 1 masks -#if X_ITEMS_REWORK == FALSE +#ifndef ITEM_EXPANSION #define ITEM1_X_SPEED 0x0F #define ITEM1_X_DEFEND 0xF0 @@ -20,7 +20,7 @@ #endif // alt field 1 masks -#if X_ITEMS_REWORK == TRUE +#ifdef ITEM_EXPANSION #define ITEM1_X_ATTACK 0x1 #define ITEM1_X_DEFEND 0x2 #define ITEM1_X_SPEED 0x4 diff --git a/src/battle_ai_switch_items.c b/src/battle_ai_switch_items.c index c106d7d9c1fb..93020f6004e0 100644 --- a/src/battle_ai_switch_items.c +++ b/src/battle_ai_switch_items.c @@ -773,7 +773,7 @@ static u8 GetAI_ItemType(u16 itemId, const u8 *itemEffect) return AI_ITEM_HEAL_HP; else if (itemEffect[3] & ITEM3_STATUS_ALL) return AI_ITEM_CURE_CONDITION; -#if X_ITEMS_REWORK == TRUE +#ifdef ITEM_EXPANSION else if ((itemEffect[0] & ITEM0_DIRE_HIT) || itemEffect[1]) #else else if (itemEffect[0] & (ITEM0_DIRE_HIT | ITEM0_X_ATTACK) || itemEffect[1] != 0 || itemEffect[2] != 0) @@ -887,7 +887,7 @@ static bool8 ShouldUseItem(void) *(gBattleStruct->AI_itemFlags + gActiveBattler / 2) = 0; if (gDisableStructs[gActiveBattler].isFirstTurn == 0) break; - #if X_ITEMS_REWORK == FALSE + #ifndef ITEM_EXPANSION if (itemEffects[0] & ITEM0_X_ATTACK) *(gBattleStruct->AI_itemFlags + gActiveBattler / 2) |= 0x1; if (itemEffects[1] & ITEM1_X_DEFEND) diff --git a/src/party_menu.c b/src/party_menu.c index 49906566d040..d9cec4b1c2f7 100755 --- a/src/party_menu.c +++ b/src/party_menu.c @@ -5186,7 +5186,7 @@ u8 GetItemEffectType(u16 item) else itemEffect = gItemEffectTable[item - ITEM_POTION]; -#if X_ITEMS_REWORK == FALSE +#ifndef ITEM_EXPANSION if ((itemEffect[0] & (ITEM0_DIRE_HIT | ITEM0_X_ATTACK)) || itemEffect[1] || itemEffect[2] || (itemEffect[3] & ITEM3_GUARD_SPEC)) #else if ((itemEffect[0] & ITEM0_DIRE_HIT) || itemEffect[1] || (itemEffect[3] & ITEM3_GUARD_SPEC)) diff --git a/src/pokemon.c b/src/pokemon.c index 901b8ab7a432..87160e4d34a3 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -2051,7 +2051,7 @@ static const u8 sGetMonDataEVConstants[] = // For stat-raising items static const u8 sStatsToRaise[] = { -#if X_ITEMS_REWORK == FALSE +#ifndef ITEM_EXPANSION STAT_ATK, STAT_ATK, STAT_SPEED, STAT_DEF, STAT_SPATK, STAT_ACC #else STAT_ATK, STAT_ATK, STAT_DEF, STAT_SPEED, STAT_SPATK, STAT_SPDEF, STAT_ACC @@ -4434,7 +4434,7 @@ bool8 PokemonUseItemEffects(struct Pokemon *mon, u16 item, u8 partyIndex, u8 mov gBattleMons[gActiveBattler].status2 |= STATUS2_FOCUS_ENERGY; retVal = FALSE; } - #if X_ITEMS_REWORK == FALSE + #ifndef ITEM_EXPANSION if ((itemEffect[cmdIndex] & ITEM0_X_ATTACK) && gBattleMons[gActiveBattler].statStages[STAT_ATK] < MAX_STAT_STAGE) { @@ -4446,7 +4446,7 @@ bool8 PokemonUseItemEffects(struct Pokemon *mon, u16 item, u8 partyIndex, u8 mov #endif break; // in-battle stat boosting effects - #if X_ITEMS_REWORK == FALSE + #ifndef ITEM_EXPANSION case 1: if ((itemEffect[cmdIndex] & ITEM1_X_DEFEND) && gBattleMons[gActiveBattler].statStages[STAT_DEF] < MAX_STAT_STAGE) @@ -5127,7 +5127,7 @@ u8 *UseStatIncreaseItem(u16 itemId) gPotentialItemEffectBattler = gBattlerInMenuId; -#if X_ITEMS_REWORK == FALSE +#ifndef ITEM_EXPANSION for (i = 0; i < 3; i++) { if (itemEffect[i] & (ITEM0_X_ATTACK | ITEM1_X_SPEED | ITEM2_X_SPATK)) From 76367b9158510b96429a7322307dde1c04db6d50 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Mon, 4 Jan 2021 04:15:10 -0300 Subject: [PATCH 3/9] Made the old X Items buff code make use of B_X_ITEMS_BUFF --- src/pokemon.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/pokemon.c b/src/pokemon.c index 87160e4d34a3..8985ef4652df 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -4438,7 +4438,10 @@ bool8 PokemonUseItemEffects(struct Pokemon *mon, u16 item, u8 partyIndex, u8 mov if ((itemEffect[cmdIndex] & ITEM0_X_ATTACK) && gBattleMons[gActiveBattler].statStages[STAT_ATK] < MAX_STAT_STAGE) { - gBattleMons[gActiveBattler].statStages[STAT_ATK] += itemEffect[cmdIndex] & ITEM0_X_ATTACK; + if (B_X_ITEMS_BUFF == GEN_7) + gBattleMons[gActiveBattler].statStages[STAT_ATK] += 2; + else + gBattleMons[gActiveBattler].statStages[STAT_ATK] += itemEffect[cmdIndex] & ITEM0_X_ATTACK; if (gBattleMons[gActiveBattler].statStages[STAT_ATK] > MAX_STAT_STAGE) gBattleMons[gActiveBattler].statStages[STAT_ATK] = MAX_STAT_STAGE; retVal = FALSE; @@ -4451,7 +4454,10 @@ bool8 PokemonUseItemEffects(struct Pokemon *mon, u16 item, u8 partyIndex, u8 mov if ((itemEffect[cmdIndex] & ITEM1_X_DEFEND) && gBattleMons[gActiveBattler].statStages[STAT_DEF] < MAX_STAT_STAGE) { - gBattleMons[gActiveBattler].statStages[STAT_DEF] += (itemEffect[cmdIndex] & ITEM1_X_DEFEND) >> 4; + if (B_X_ITEMS_BUFF == GEN_7) + gBattleMons[gActiveBattler].statStages[STAT_DEF] += 2; + else + gBattleMons[gActiveBattler].statStages[STAT_DEF] += (itemEffect[cmdIndex] & ITEM1_X_DEFEND) >> 4; if (gBattleMons[gActiveBattler].statStages[STAT_DEF] > MAX_STAT_STAGE) gBattleMons[gActiveBattler].statStages[STAT_DEF] = MAX_STAT_STAGE; retVal = FALSE; @@ -4459,7 +4465,10 @@ bool8 PokemonUseItemEffects(struct Pokemon *mon, u16 item, u8 partyIndex, u8 mov if ((itemEffect[cmdIndex] & ITEM1_X_SPEED) && gBattleMons[gActiveBattler].statStages[STAT_SPEED] < MAX_STAT_STAGE) { - gBattleMons[gActiveBattler].statStages[STAT_SPEED] += itemEffect[cmdIndex] & ITEM1_X_SPEED; + if (B_X_ITEMS_BUFF == GEN_7) + gBattleMons[gActiveBattler].statStages[STAT_SPEED] += 2; + else + gBattleMons[gActiveBattler].statStages[STAT_SPEED] += itemEffect[cmdIndex] & ITEM1_X_SPEED; if (gBattleMons[gActiveBattler].statStages[STAT_SPEED] > MAX_STAT_STAGE) gBattleMons[gActiveBattler].statStages[STAT_SPEED] = MAX_STAT_STAGE; retVal = FALSE; @@ -4470,7 +4479,10 @@ bool8 PokemonUseItemEffects(struct Pokemon *mon, u16 item, u8 partyIndex, u8 mov if ((itemEffect[cmdIndex] & ITEM2_X_ACCURACY) && gBattleMons[gActiveBattler].statStages[STAT_ACC] < MAX_STAT_STAGE) { - gBattleMons[gActiveBattler].statStages[STAT_ACC] += (itemEffect[cmdIndex] & ITEM2_X_ACCURACY) >> 4; + if (B_X_ITEMS_BUFF == GEN_7) + gBattleMons[gActiveBattler].statStages[STAT_ACC] += 2; + else + gBattleMons[gActiveBattler].statStages[STAT_ACC] += (itemEffect[cmdIndex] & ITEM2_X_ACCURACY) >> 4; if (gBattleMons[gActiveBattler].statStages[STAT_ACC] > MAX_STAT_STAGE) gBattleMons[gActiveBattler].statStages[STAT_ACC] = MAX_STAT_STAGE; retVal = FALSE; @@ -4478,7 +4490,10 @@ bool8 PokemonUseItemEffects(struct Pokemon *mon, u16 item, u8 partyIndex, u8 mov if ((itemEffect[cmdIndex] & ITEM2_X_SPATK) && gBattleMons[gActiveBattler].statStages[STAT_SPATK] < MAX_STAT_STAGE) { - gBattleMons[gActiveBattler].statStages[STAT_SPATK] += itemEffect[cmdIndex] & ITEM2_X_SPATK; + if (B_X_ITEMS_BUFF == GEN_7) + gBattleMons[gActiveBattler].statStages[STAT_SPATK] += 2; + else + gBattleMons[gActiveBattler].statStages[STAT_SPATK] += itemEffect[cmdIndex] & ITEM2_X_SPATK; if (gBattleMons[gActiveBattler].statStages[STAT_SPATK] > MAX_STAT_STAGE) gBattleMons[gActiveBattler].statStages[STAT_SPATK] = MAX_STAT_STAGE; retVal = FALSE; From 9a65747a4a0b8caaa14362fb5a6fc9fb00227eb2 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Mon, 4 Jan 2021 07:41:56 -0300 Subject: [PATCH 4/9] Made BufferStatRoseMessage print an extra string if B_X_ITEMS_BUFF == GEN_7 Also turned sText_StatSharply into gText_StatSharply. --- include/battle_message.h | 1 + src/battle_message.c | 4 ++-- src/pokemon.c | 11 ++++++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/include/battle_message.h b/include/battle_message.h index 06f030860cef..900c3b1eb6d6 100644 --- a/include/battle_message.h +++ b/include/battle_message.h @@ -286,6 +286,7 @@ extern const u8 gText_BattleWallyName[]; extern const u8 gText_Win[]; extern const u8 gText_Loss[]; extern const u8 gText_Draw[]; +extern const u8 gText_StatSharply[]; extern const u8 gText_StatRose[]; extern const u8 gText_PkmnsStatChanged2[]; extern const u8 gText_PkmnGettingPumped[]; diff --git a/src/battle_message.c b/src/battle_message.c index 35ccc6e26807..a6c04fc0d13b 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -305,7 +305,7 @@ static const u8 sText_PkmnsXPreventsFlinching[] = _("{B_EFF_NAME_WITH_PREFIX}'s static const u8 sText_PkmnsXPreventsYsZ[] = _("{B_ATK_NAME_WITH_PREFIX}'s {B_ATK_ABILITY}\nprevents {B_DEF_NAME_WITH_PREFIX}'s\l{B_DEF_ABILITY} from working!"); static const u8 sText_PkmnsXCuredItsYProblem[] = _("{B_SCR_ACTIVE_NAME_WITH_PREFIX}'s {B_SCR_ACTIVE_ABILITY}\ncured its {B_BUFF1} problem!"); static const u8 sText_PkmnsXHadNoEffectOnY[] = _("{B_SCR_ACTIVE_NAME_WITH_PREFIX}'s {B_SCR_ACTIVE_ABILITY}\nhad no effect on {B_EFF_NAME_WITH_PREFIX}!"); -static const u8 sText_StatSharply[] = _("sharply "); +const u8 gText_StatSharply[] = _("sharply "); const u8 gText_StatRose[] = _("rose!"); static const u8 sText_StatHarshly[] = _("harshly "); static const u8 sText_StatFell[] = _("fell!"); @@ -914,7 +914,7 @@ const u8 *const gBattleStringsTable[BATTLESTRINGS_COUNT] = [STRINGID_PKMNPREVENTSSTATLOSSWITH - 12] = sText_PkmnPreventsStatLossWith, [STRINGID_PKMNHURTSWITH - 12] = sText_PkmnHurtsWith, [STRINGID_PKMNTRACED - 12] = sText_PkmnTraced, - [STRINGID_STATSHARPLY - 12] = sText_StatSharply, + [STRINGID_STATSHARPLY - 12] = gText_StatSharply, [STRINGID_STATROSE - 12] = gText_StatRose, [STRINGID_STATHARSHLY - 12] = sText_StatHarshly, [STRINGID_STATFELL - 12] = sText_StatFell, diff --git a/src/pokemon.c b/src/pokemon.c index 8985ef4652df..4fe8464c9a19 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -5119,7 +5119,16 @@ static void BufferStatRoseMessage(s32 arg0) { gBattlerTarget = gBattlerInMenuId; StringCopy(gBattleTextBuff1, gStatNamesTable[sStatsToRaise[arg0]]); - StringCopy(gBattleTextBuff2, gText_StatRose); + if (B_X_ITEMS_BUFF == GEN_7) + { + StringCopy(gBattleTextBuff2, gText_EmptyString3); + StringAppend(gBattleTextBuff2, gText_StatSharply); + StringAppend(gBattleTextBuff2, gText_StatRose); + } + else + { + StringCopy(gBattleTextBuff2, gText_StatRose); + } BattleStringExpandPlaceholdersToDisplayedString(gText_PkmnsStatChanged2); } From 0ad3b1b8e36b1d3d42c621c99b4963b40b76c3dc Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Thu, 7 Jan 2021 15:51:52 -0300 Subject: [PATCH 5/9] Removed pointless EmptyString print --- src/pokemon.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pokemon.c b/src/pokemon.c index 4fe8464c9a19..7a99ff8d7990 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -5121,8 +5121,7 @@ static void BufferStatRoseMessage(s32 arg0) StringCopy(gBattleTextBuff1, gStatNamesTable[sStatsToRaise[arg0]]); if (B_X_ITEMS_BUFF == GEN_7) { - StringCopy(gBattleTextBuff2, gText_EmptyString3); - StringAppend(gBattleTextBuff2, gText_StatSharply); + StringCopy(gBattleTextBuff2, gText_StatSharply); StringAppend(gBattleTextBuff2, gText_StatRose); } else From 32f40f15bb5887cf2973402392f8172eb5f15684 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Thu, 7 Jan 2021 16:06:55 -0300 Subject: [PATCH 6/9] Tweaked preprocessor constant in include/constants/item_effects.h --- include/constants/item_effects.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/include/constants/item_effects.h b/include/constants/item_effects.h index 7ed183347329..3e88ce41952b 100644 --- a/include/constants/item_effects.h +++ b/include/constants/item_effects.h @@ -9,18 +9,16 @@ #define ITEM0_SACRED_ASH 0x40 #define ITEM0_INFATUATION 0x80 -// field 1 masks #ifndef ITEM_EXPANSION +// field 1 masks #define ITEM1_X_SPEED 0x0F #define ITEM1_X_DEFEND 0xF0 // field 2 masks #define ITEM2_X_SPATK 0x0F #define ITEM2_X_ACCURACY 0xF0 -#endif - -// alt field 1 masks -#ifdef ITEM_EXPANSION +#else +// new field 1 masks #define ITEM1_X_ATTACK 0x1 #define ITEM1_X_DEFEND 0x2 #define ITEM1_X_SPEED 0x4 From 51b348bd1f9dd95c32bdad02002fcda5c7b77e47 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Thu, 7 Jan 2021 16:09:23 -0300 Subject: [PATCH 7/9] Review correction to B_X_ITEMS_BUFF's comment --- include/constants/battle_config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/constants/battle_config.h b/include/constants/battle_config.h index 2eaf5e0d3e66..e2d35d408d67 100644 --- a/include/constants/battle_config.h +++ b/include/constants/battle_config.h @@ -123,7 +123,7 @@ // Item settings #define B_HP_BERRIES GEN_6 // In Gen4+, berries which restore hp activate immediately after hp drops to half. In gen3, the effect occurs at the end of the turn. #define B_BERRIES_INSTANT GEN_6 // In Gen4+, most berries activate on battle start/switch-in if applicable. In gen3, they only activate either at the move end or turn end. -#define B_X_ITEMS_BUFF GEN_7 // In Gen7+, the X Items raise a stat by 2 stages instead of 1. This flag relies on X_ITEMS_REWORK, and by extension, the item_expansion. +#define B_X_ITEMS_BUFF GEN_7 // In Gen7+, the X Items raise a stat by 2 stages instead of 1. // Flag settings. // To use the following features in scripting, replace the 0s with the flag ID you're assigning it to. Eg: Replace with FLAG_UNUSED_0x264 so you can use that flag for toggling the feature. From 7d82da0a1758cba9bcf4059ee5d21bb91898b9a2 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Thu, 7 Jan 2021 18:20:53 -0300 Subject: [PATCH 8/9] Review correction to case 2 of PokemonUseItemEffects --- src/pokemon.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pokemon.c b/src/pokemon.c index 7a99ff8d7990..fdb017608994 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -4571,6 +4571,7 @@ bool8 PokemonUseItemEffects(struct Pokemon *mon, u16 item, u8 partyIndex, u8 mov break; // formerly used by the item effects of the X Sp. Atk and the X Accuracy case 2: + break; #endif case 3: if ((itemEffect[cmdIndex] & ITEM3_GUARD_SPEC) From 748562b099e12ee0349a5a1003cd5055e6591643 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Sun, 10 Jan 2021 01:58:02 -0300 Subject: [PATCH 9/9] Renamed some X Defend labels to reflect its new name in the IE --- include/constants/item_effects.h | 2 +- src/battle_ai_switch_items.c | 2 +- src/pokemon.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/constants/item_effects.h b/include/constants/item_effects.h index 3e88ce41952b..e68914c7b181 100644 --- a/include/constants/item_effects.h +++ b/include/constants/item_effects.h @@ -20,7 +20,7 @@ #else // new field 1 masks #define ITEM1_X_ATTACK 0x1 -#define ITEM1_X_DEFEND 0x2 +#define ITEM1_X_DEFENSE 0x2 #define ITEM1_X_SPEED 0x4 #define ITEM1_X_SPATK 0x8 #define ITEM1_X_SPDEF 0x10 diff --git a/src/battle_ai_switch_items.c b/src/battle_ai_switch_items.c index 93020f6004e0..d0fd8224dd01 100644 --- a/src/battle_ai_switch_items.c +++ b/src/battle_ai_switch_items.c @@ -903,7 +903,7 @@ static bool8 ShouldUseItem(void) #else if (itemEffects[1] & ITEM1_X_ATTACK) *(gBattleStruct->AI_itemFlags + gActiveBattler / 2) |= 0x1; - if (itemEffects[1] & ITEM1_X_DEFEND) + if (itemEffects[1] & ITEM1_X_DEFENSE) *(gBattleStruct->AI_itemFlags + gActiveBattler / 2) |= 0x2; if (itemEffects[1] & ITEM1_X_SPEED) *(gBattleStruct->AI_itemFlags + gActiveBattler / 2) |= 0x4; diff --git a/src/pokemon.c b/src/pokemon.c index fdb017608994..afcbf74cd424 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -4513,7 +4513,7 @@ bool8 PokemonUseItemEffects(struct Pokemon *mon, u16 item, u8 partyIndex, u8 mov gBattleMons[gActiveBattler].statStages[STAT_ATK] = MAX_STAT_STAGE; retVal = FALSE; } - if ((itemEffect[cmdIndex] & ITEM1_X_DEFEND) + if ((itemEffect[cmdIndex] & ITEM1_X_DEFENSE) && gBattleMons[gActiveBattler].statStages[STAT_DEF] < MAX_STAT_STAGE) { if (B_X_ITEMS_BUFF == GEN_7) @@ -5188,7 +5188,7 @@ u8 *UseStatIncreaseItem(u16 itemId) case ITEM1_X_ATTACK: BufferStatRoseMessage(STAT_ATK); break; - case ITEM1_X_DEFEND: + case ITEM1_X_DEFENSE: BufferStatRoseMessage(STAT_DEF); break; case ITEM1_X_SPEED: