Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pickup Table Refactor #3351

Merged
merged 8 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/battle_script_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ struct StatFractions
u8 divisor;
};

struct PickupItem
{
u16 itemId;
u8 percentage[10];
};

s32 CalcCritChanceStageArgs(u32 battlerAtk, u32 battlerDef, u32 move, bool32 recordAbility, u32 abilityAtk, u32 abilityDef, u32 holdEffectAtk);
s32 CalcCritChanceStage(u32 battlerAtk, u32 battlerDef, u32 move, bool32 recordAbility);
s32 GetCritHitChance(s32 critChanceIndex);
Expand Down
87 changes: 40 additions & 47 deletions src/battle_script_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -1060,47 +1060,43 @@ static const u16 sNaturePowerMoves[BATTLE_TERRAIN_COUNT] =
[BATTLE_TERRAIN_ULTRA_SPACE] = MOVE_PSYSHOCK,
};

static const u16 sPickupItems[] =
{
ITEM_POTION,
ITEM_ANTIDOTE,
ITEM_SUPER_POTION,
ITEM_GREAT_BALL,
ITEM_REPEL,
ITEM_ESCAPE_ROPE,
ITEM_X_ATTACK,
ITEM_FULL_HEAL,
ITEM_ULTRA_BALL,
ITEM_HYPER_POTION,
ITEM_RARE_CANDY,
ITEM_PROTEIN,
ITEM_REVIVE,
ITEM_HP_UP,
ITEM_FULL_RESTORE,
ITEM_MAX_REVIVE,
ITEM_PP_UP,
ITEM_MAX_ELIXIR,
#define _ 0

static const struct PickupItem sPickupTable[] =
{// Item 1+ 11+ 21+ 31+ 41+ 51+ 61+ 71+ 81+ 91+ Levels
{ ITEM_POTION, { 35, _, _, _, _, _, _, _, _, _, } },
{ ITEM_TINY_MUSHROOM, { 25, 10, _, _, _, _, _, _, _, _, } },
{ ITEM_REPEL, { 8, 30, _, _, _, _, _, _, _, _, } },
{ ITEM_SUPER_POTION, { 8, 10, 30, _, _, _, _, _, _, _, } },
{ ITEM_POKE_DOLL, { 8, 10, 9, 30, _, _, _, _, _, _, } },
{ ITEM_BIG_MUSHROOM, { 3, 10, 9, _, _, _, _, _, _, _, } },
{ ITEM_SUPER_REPEL, { 3, 10, 9, 9, 30, _, _, _, _, _, } },
{ ITEM_FULL_HEAL, { 3, 3, 9, 8, 9, 30, _, _, _, _, } },
{ ITEM_REVIVE, { 3, 3, 3, 8, 8, 9, 30, _, _, _, } },
{ ITEM_HYPER_POTION, { 3, 3, 3, 4, 8, 9, 8, 30, _, _, } },
{ ITEM_ETHER, { 1, 1, 3, 4, 4, _, _, _, _, _, } },
{ ITEM_MAX_REPEL, { _, 3, 3, 4, 4, 9, 8, 8, 30, _, } },
{ ITEM_MOON_STONE, { _, 3, 3, 4, 4, 4, 4, 5, 9, 10, } },
{ ITEM_SUN_STONE, { _, 3, 3, 4, 4, 4, 4, 5, 9, 10, } },
{ ITEM_RARE_CANDY, { _, 1, 1, 1, 1, 4, 4, 5, 4, 5, } },
{ ITEM_NUGGET, { _, _, 3, 4, 4, 4, 4, 5, 4, 5, } },
{ ITEM_MAX_POTION, { _, _, 3, 4, 4, 4, 8, 8, 9, 30, } },
{ ITEM_MAX_ETHER, { _, _, 1, 1, 4, 4, 4, _, _, _, } },
{ ITEM_PP_UP, { _, _, 1, 1, 1, 4, 4, 5, 4, 5, } },
{ ITEM_BIG_NUGGET, { _, _, 1, 1, 1, 1, 4, 5, 4, 5, } },
{ ITEM_DESTINY_KNOT, { _, _, 1, 1, 1, 1, 1, 1, 1, 1, } },
{ ITEM_LEFTOVERS, { _, _, 1, 1, 1, 1, 1, 1, 1, 1, } },
{ ITEM_MENTAL_HERB, { _, _, 1, 1, 1, 1, 1, 1, 1, 1, } },
{ ITEM_POWER_HERB, { _, _, 1, 1, 1, 1, 1, 1, 1, 1, } },
{ ITEM_WHITE_HERB, { _, _, 1, 1, 1, 1, 1, 1, 1, 1, } },
{ ITEM_BALM_MUSHROOM, { _, _, 1, 4, 4, 4, 4, 5, 4, 5, } },
{ ITEM_MAX_REVIVE, { _, _, _, 4, 4, 4, 4, 7, 9, 9, } },
{ ITEM_ELIXIR, { _, _, _, _, 1, 1, 4, 5, 4, 5, } },
{ ITEM_MAX_ELIXIR, { _, _, _, _, _, _, 1, 1, 4, 5, } },
{ ITEM_BOTTLE_CAP, { _, _, _, _, _, _, _, 1, 1, 1, } },
};

static const u16 sRarePickupItems[] =
{
ITEM_HYPER_POTION,
ITEM_NUGGET,
ITEM_KINGS_ROCK,
ITEM_FULL_RESTORE,
ITEM_ETHER,
ITEM_WHITE_HERB,
ITEM_TM_REST,
ITEM_ELIXIR,
ITEM_TM_FOCUS_PUNCH,
ITEM_LEFTOVERS,
ITEM_TM_EARTHQUAKE,
};

static const u8 sPickupProbabilities[] =
{
30, 40, 50, 60, 70, 80, 90, 94, 98
};
#undef _

static const u8 sTerrainToType[BATTLE_TERRAIN_COUNT] =
{
Expand Down Expand Up @@ -14618,17 +14614,14 @@ static void Cmd_pickup(void)
else
{
u32 rand = Random() % 100;
u32 percentTotal = 0;

for (j = 0; j < ARRAY_COUNT(sPickupProbabilities); j++)
for (j = 0; j < ARRAY_COUNT(sPickupTable); j++)
{
if (sPickupProbabilities[j] > rand)
{
SetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM, &sPickupItems[lvlDivBy10 + j]);
break;
}
else if (rand == 99 || rand == 98)
percentTotal += sPickupTable[j].percentage[lvlDivBy10];
if (rand < percentTotal)
{
SetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM, &sRarePickupItems[lvlDivBy10 + (99 - rand)]);
SetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM, &sPickupTable[j].itemId);
break;
}
}
Expand Down
Loading