From 2c172a36369d7bf6d6dc88337858fecf32f16eba Mon Sep 17 00:00:00 2001 From: Eduardo Alvaro Quezada D'Ottone Date: Mon, 17 Feb 2020 07:08:06 -0300 Subject: [PATCH] Shiny charm (#276) * Shiny Charm Item * Shiny Charm Rerolls --- graphics/items/icon_palettes/shiny_charm.pal | 19 +++++++++++++++++++ graphics/items/icons/shiny_charm.png | Bin 0 -> 356 bytes include/constants/items.h | 4 +++- include/constants/pokemon.h | 1 + include/graphics.h | 2 ++ src/data/graphics/items.h | 3 +++ src/data/item_icon_table.h | 1 + src/data/items.h | 14 +++++++++++++- src/data/text/item_descriptions.h | 5 +++++ src/pokemon.c | 15 +++++++++++++-- 10 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 graphics/items/icon_palettes/shiny_charm.pal create mode 100644 graphics/items/icons/shiny_charm.png diff --git a/graphics/items/icon_palettes/shiny_charm.pal b/graphics/items/icon_palettes/shiny_charm.pal new file mode 100644 index 000000000..ab6e64a6e --- /dev/null +++ b/graphics/items/icon_palettes/shiny_charm.pal @@ -0,0 +1,19 @@ +JASC-PAL +0100 +16 +245 218 38 +82 123 230 +90 156 246 +156 255 106 +41 115 148 +156 246 246 +57 205 246 +132 214 255 +189 189 239 +222 222 255 +90 90 90 +32 32 32 +206 173 247 +140 140 247 +173 107 255 +230 206 255 diff --git a/graphics/items/icons/shiny_charm.png b/graphics/items/icons/shiny_charm.png new file mode 100644 index 0000000000000000000000000000000000000000..3829154cd5a3e2702d4039e89e8e4b59d205cdd4 GIT binary patch literal 356 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaN3?zjj6;1;w_7YEDSN11N+zc|J=~?q01BJv( zTq8OS5>&oNwPO&we{_;6Ot|!+)R}5C&2I zfvo=^kXI~g3KU>W@^*Lmzm)ycQ6Q(o)5S5QVovILUExCpJZuljt(MJoZJg`!$WVC2 zF`oqo-keV@2p2xs|L8(;lgeJ@Mc1ESsuB6YAH=KkB4$d1A5W!q*|Z?v#$HW@h&5~` z!ObsAKZQ@7&$sKti{w|ocHU;&8snX~@yyx^wyI|rU*Dfv+a*`}sXle-&-TOn#3NSU i;otZtc|wEPceQ=CA?k*!{(WcxIoZ?I&t;ucLK6Tsaf)yN literal 0 HcmV?d00001 diff --git a/include/constants/items.h b/include/constants/items.h index 32c36a357..262219a59 100644 --- a/include/constants/items.h +++ b/include/constants/items.h @@ -700,7 +700,9 @@ #define ITEM_MAGMA_EMBLEM 614 #define ITEM_OLD_SEA_MAP 615 -#define ITEMS_COUNT 616 +#define ITEM_SHINY_CHARM 616 + +#define ITEMS_COUNT 617 #define ITEM_FIELD_ARROW ITEMS_COUNT #define FIRST_BERRY_INDEX ITEM_CHERI_BERRY diff --git a/include/constants/pokemon.h b/include/constants/pokemon.h index 6c82404a1..9179658b0 100644 --- a/include/constants/pokemon.h +++ b/include/constants/pokemon.h @@ -86,6 +86,7 @@ // Shiny odds #define SHINY_ODDS 8 // Actual probability is SHINY_ODDS/65536 +#define SHINY_CHARM_REROLLS 3 // Amount of re-rolls if has Shiny Charm. // Flags for Get(Box)MonData / Set(Box)MonData #define MON_DATA_PERSONALITY 0 diff --git a/include/graphics.h b/include/graphics.h index 3e25aa210..9e4e12486 100644 --- a/include/graphics.h +++ b/include/graphics.h @@ -4056,6 +4056,8 @@ extern const u32 gItemIcon_NormalGem[]; extern const u32 gItemIconPalette_NormalGem[]; extern const u32 gItemIcon_FairyGem[]; extern const u32 gItemIconPalette_FairyGem[]; +extern const u32 gItemIcon_ShinyCharm[]; +extern const u32 gItemIconPalette_ShinyCharm[]; // Gen 6 Items extern const u32 gItemIcon_AssaultVest[]; extern const u32 gItemIconPalette_AssaultVest[]; diff --git a/src/data/graphics/items.h b/src/data/graphics/items.h index 701e23e4a..8e6fe9012 100644 --- a/src/data/graphics/items.h +++ b/src/data/graphics/items.h @@ -1002,6 +1002,9 @@ const u32 gItemIconPalette_NormalGem[] = INCBIN_U32("graphics/items/icon_palette const u32 gItemIcon_FairyGem[] = INCBIN_U32("graphics/items/icons/fairy_gem.4bpp.lz"); const u32 gItemIconPalette_FairyGem[] = INCBIN_U32("graphics/items/icon_palettes/fairy_gem.gbapal.lz"); +const u32 gItemIcon_ShinyCharm[] = INCBIN_U32("graphics/items/icons/shiny_charm.4bpp.lz"); +const u32 gItemIconPalette_ShinyCharm[] = INCBIN_U32("graphics/items/icon_palettes/shiny_charm.gbapal.lz"); + // Gen 6 Items const u32 gItemIcon_AssaultVest[] = INCBIN_U32("graphics/items/icons/assault_vest.4bpp.lz"); diff --git a/src/data/item_icon_table.h b/src/data/item_icon_table.h index a5d3afd33..a53afe88d 100644 --- a/src/data/item_icon_table.h +++ b/src/data/item_icon_table.h @@ -417,6 +417,7 @@ const u32 *const gItemIconTable[][2] = [ITEM_STEEL_GEM] = {gItemIcon_SteelGem, gItemIconPalette_SteelGem}, [ITEM_NORMAL_GEM] = {gItemIcon_NormalGem, gItemIconPalette_NormalGem}, [ITEM_FAIRY_GEM] = {gItemIcon_FairyGem, gItemIconPalette_FairyGem}, + [ITEM_SHINY_CHARM] = {gItemIcon_ShinyCharm, gItemIconPalette_ShinyCharm}, // Gen 6 Items [ITEM_ASSAULT_VEST] = {gItemIcon_AssaultVest, gItemIconPalette_AssaultVest}, [ITEM_PIXIE_PLATE] = {gItemIcon_PixiePlate, gItemIconPalette_PixiePlate}, diff --git a/src/data/items.h b/src/data/items.h index c359d1c96..9940f2ee3 100644 --- a/src/data/items.h +++ b/src/data/items.h @@ -7448,5 +7448,17 @@ const struct Item gItems[] = .type = 4, .fieldUseFunc = ItemUseOutOfBattle_CannotUse, .secondaryId = 0, - } + }, + + [ITEM_SHINY_CHARM] = + { + .name = _("Shiny Charm"), + .itemId = ITEM_SHINY_CHARM, + .price = 0, + .description = sShinyCharmDesc, + .pocket = POCKET_KEY_ITEMS, + .type = 4, + .fieldUseFunc = ItemUseOutOfBattle_CannotUse, + .secondaryId = 0, + }, }; diff --git a/src/data/text/item_descriptions.h b/src/data/text/item_descriptions.h index 9c722e4dc..d159eab23 100644 --- a/src/data/text/item_descriptions.h +++ b/src/data/text/item_descriptions.h @@ -2788,3 +2788,8 @@ static const u8 sPrettyWingDesc[] = _( "A beautiful yet\n" "plain feather that\n" "does nothing."); + +static const u8 sShinyCharmDesc[] = _( + "A charm that will\n" + "raise the chance\n" + "of Shiny Pokémon."); diff --git a/src/pokemon.c b/src/pokemon.c index 2504d1a3c..94634cacd 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -2175,8 +2175,6 @@ void CreateBoxMon(struct BoxPokemon *boxMon, u16 species, u8 level, u8 fixedIV, else personality = Random32(); - SetBoxMonData(boxMon, MON_DATA_PERSONALITY, &personality); - //Determine original trainer ID if (otIdType == OT_ID_RANDOM_NO_SHINY) //Pokemon cannot be shiny { @@ -2197,8 +2195,21 @@ void CreateBoxMon(struct BoxPokemon *boxMon, u16 species, u8 level, u8 fixedIV, | (gSaveBlock2Ptr->playerTrainerId[1] << 8) | (gSaveBlock2Ptr->playerTrainerId[2] << 16) | (gSaveBlock2Ptr->playerTrainerId[3] << 24); + + if (CheckBagHasItem(ITEM_SHINY_CHARM, 1)) + { + u32 shinyValue; + u32 rolls = 0; + do + { + personality = Random32(); + shinyValue = HIHALF(value) ^ LOHALF(value) ^ HIHALF(personality) ^ LOHALF(personality); + rolls++; + } while (shinyValue >= SHINY_ODDS && rolls < SHINY_CHARM_REROLLS); + } } + SetBoxMonData(boxMon, MON_DATA_PERSONALITY, &personality); SetBoxMonData(boxMon, MON_DATA_OT_ID, &value); checksum = CalculateBoxMonChecksum(boxMon);