Handling repel/lure menu

This commit is contained in:
Eduardo Quezada 2022-09-14 00:17:04 -03:00
parent ca048e1bc3
commit dc423ef7ff
4 changed files with 160 additions and 42 deletions

View File

@ -1,46 +1,64 @@
EventScript_RepelWoreOff:: EventScript_RepelWoreOff::
checkitem I_VAR_LAST_REPEL_LURE_USED, 1 .if I_REPEL_LURE_MENU == TRUE
compare VAR_RESULT, TRUE checkitem ITEM_REPEL, 1
goto_if_eq EventScript_UseAnother goto_if_eq VAR_RESULT, TRUE, EventScript_RepelUseAnother
checkitem ITEM_SUPER_REPEL, 1
goto_if_eq VAR_RESULT, TRUE, EventScript_RepelUseAnother
checkitem ITEM_MAX_REPEL, 1
goto_if_eq VAR_RESULT, TRUE, EventScript_RepelUseAnother
.else
checkitem VAR_LAST_REPEL_LURE_USED, 1
goto_if_eq VAR_RESULT, TRUE, EventScript_RepelUseAnother
.endif
lock lock
msgbox Text_RepelWoreOff, MSGBOX_SIGN msgbox Text_RepelWoreOff, MSGBOX_SIGN
release release
end end
EventScript_UseAnother: EventScript_RepelUseAnother:
lock lock
msgbox Text_UseAnother, MSGBOX_YESNO msgbox Text_UseAnotherRepel, MSGBOX_YESNO
compare VAR_RESULT, YES .if I_REPEL_LURE_MENU == TRUE
goto_if_eq EventScript_UsedRepel callnative TryDrawRepelMenu
goto_if_eq VAR_RESULT, FALSE, EventScript_RepelWoreOff_Chose
waitstate
goto_if_eq VAR_RESULT, 127, EventScript_RepelWoreOff_End
EventScript_RepelWoreOff_Chose:
callnative HandleRepelMenuChoice
bufferitemname 1, VAR_0x8004
removeitem VAR_0x8004, 1
playse SE_REPEL
msgbox Text_UsedNewRepelLure, MSGBOX_SIGN
.else
goto_if_eq VAR_RESULT, YES, EventScript_UsedRepel
.endif
EventScript_RepelWoreOff_End:
release release
end end
EventScript_UsedRepel: EventScript_UsedRepel:
bufferitemname 0, I_VAR_LAST_REPEL_LURE_USED bufferitemname 1, VAR_LAST_REPEL_LURE_USED
playse SE_REPEL playse SE_REPEL
lock lock
msgbox Text_UsedNewRepelLure, MSGBOX_SIGN msgbox Text_UsedNewRepelLure, MSGBOX_SIGN
removeitem I_VAR_LAST_REPEL_LURE_USED, 1 removeitem VAR_LAST_REPEL_LURE_USED, 1
waitse waitse
callnative HandleUseExpiredRepel callnative HandleUseExpiredRepel
release release
end end
Text_RepelWoreOff:
.string "REPEL's effect wore off…$"
Text_UseAnother::
.string "REPEL's effect wore off!\n"
.string "Use another?$"
Text_UsedNewRepelLure::
.string "{PLAYER} used the\n"
.string "{STR_VAR_1}.$"
EventScript_LureWoreOff:: EventScript_LureWoreOff::
checkitem I_VAR_LAST_REPEL_LURE_USED, 1 .if I_REPEL_LURE_MENU == TRUE
compare VAR_RESULT, TRUE checkitem ITEM_LURE, 1
goto_if_eq EventScript_LureUseAnother goto_if_eq VAR_RESULT, TRUE, EventScript_LureUseAnother
checkitem ITEM_SUPER_LURE, 1
goto_if_eq VAR_RESULT, TRUE, EventScript_LureUseAnother
checkitem ITEM_MAX_LURE, 1
goto_if_eq VAR_RESULT, TRUE, EventScript_LureUseAnother
.else
checkitem VAR_LAST_REPEL_LURE_USED, 1
goto_if_eq VAR_RESULT, TRUE, EventScript_LureUseAnother
.endif
lock lock
msgbox Text_LureWoreOff, MSGBOX_SIGN msgbox Text_LureWoreOff, MSGBOX_SIGN
release release
@ -49,25 +67,49 @@ EventScript_LureWoreOff::
EventScript_LureUseAnother: EventScript_LureUseAnother:
lock lock
msgbox Text_UseAnotherLure, MSGBOX_YESNO msgbox Text_UseAnotherLure, MSGBOX_YESNO
compare VAR_RESULT, YES .if I_REPEL_LURE_MENU == TRUE
goto_if_eq EventScript_UsedLure callnative TryDrawLureMenu
goto_if_eq VAR_RESULT, FALSE, EventScript_LureWoreOff_Chose
waitstate
goto_if_eq VAR_RESULT, 127, EventScript_LureWoreOff_End
EventScript_LureWoreOff_Chose:
callnative HandleLureMenuChoice
bufferitemname 1, VAR_0x8004
removeitem VAR_0x8004, 1
playse SE_REPEL
msgbox Text_UsedNewRepelLure, MSGBOX_SIGN
.else
goto_if_eq VAR_RESULT, YES, EventScript_UsedLure
.endif
EventScript_LureWoreOff_End:
release release
end end
EventScript_UsedLure: EventScript_UsedLure:
bufferitemname 0, I_VAR_LAST_REPEL_LURE_USED bufferitemname 1, VAR_LAST_REPEL_LURE_USED
playse SE_REPEL playse SE_REPEL
lock lock
msgbox Text_UsedNewRepelLure, MSGBOX_SIGN msgbox Text_UsedNewRepelLure, MSGBOX_SIGN
removeitem I_VAR_LAST_REPEL_LURE_USED, 1 removeitem VAR_LAST_REPEL_LURE_USED, 1
waitse waitse
callnative HandleUseExpiredLure callnative HandleUseExpiredLure
release release
end end
Text_RepelWoreOff:
.string "REPEL's effect wore off…$"
Text_UseAnotherRepel::
.string "REPEL's effect wore off!\n"
.string "Use another?$"
Text_LureWoreOff: Text_LureWoreOff:
.string "Lure's effect wore off…$" .string "Lure's effect wore off…$"
Text_UseAnotherLure:: Text_UseAnotherLure::
.string "Lure's effect wore off!\n" .string "Lure's effect wore off!\n"
.string "Use another?$" .string "Use another?$"
Text_UsedNewRepelLure::
.string "{PLAYER} used the\n"
.string "{STR_VAR_2}.$"

View File

@ -9,9 +9,9 @@
#define I_SITRUS_BERRY_HEAL GEN_LATEST // In Gen4+, Sitrus Berry was changed from healing 30 HP to healing 25% of Max HP. #define I_SITRUS_BERRY_HEAL GEN_LATEST // In Gen4+, Sitrus Berry was changed from healing 30 HP to healing 25% of Max HP.
#define I_VITAMIN_EV_CAP GEN_LATEST // In Gen8, the Vitamins no longer have a cap of 100 EV per stat. #define I_VITAMIN_EV_CAP GEN_LATEST // In Gen8, the Vitamins no longer have a cap of 100 EV per stat.
// Var settings // Repel/Lure config
// To use the following features, replace the 0s with the var ID you're assigning it to. // These two settings are both independent and complementary.
// Eg: Replace with VAR_UNUSED_0x40F7 so you can use I_VAR_LAST_REPEL_LURE_USED for that feature. #define VAR_LAST_REPEL_LURE_USED 0 // If this var has been assigned, last Repel/Lure used will be saved and the player will get prompted with the vanilla repel YES/NO option, unless I_REPEL_LURE_MENU is set to TRUE.
#define I_VAR_LAST_REPEL_LURE_USED 0 // If this var has been assigned, B2W2's Repel prompt will trigger once it runs out. It also applies to Lures. #define I_REPEL_LURE_MENU TRUE // If TRUE, the player is able to choose which Repel/Lure to use once the previous one runs out. Cursor position is saved by VAR_LAST_REPEL_LURE_USED if not 0.
#endif // GUARD_CONSTANTS_ITEM_CONFIG_H #endif // GUARD_CONSTANTS_ITEM_CONFIG_H

View File

@ -873,8 +873,8 @@ static void Task_UseRepel(u8 taskId)
if (!IsSEPlaying()) if (!IsSEPlaying())
{ {
VarSet(VAR_REPEL_STEP_COUNT, ItemId_GetHoldEffectParam(gSpecialVar_ItemId)); VarSet(VAR_REPEL_STEP_COUNT, ItemId_GetHoldEffectParam(gSpecialVar_ItemId));
#if I_VAR_LAST_REPEL_LURE_USED != 0 #if VAR_LAST_REPEL_LURE_USED != 0
VarSet(I_VAR_LAST_REPEL_LURE_USED, gSpecialVar_ItemId); VarSet(VAR_LAST_REPEL_LURE_USED, gSpecialVar_ItemId);
#endif #endif
RemoveUsedItem(); RemoveUsedItem();
if (!InBattlePyramid()) if (!InBattlePyramid())
@ -885,8 +885,8 @@ static void Task_UseRepel(u8 taskId)
} }
void HandleUseExpiredRepel(void) void HandleUseExpiredRepel(void)
{ {
#if I_VAR_LAST_REPEL_LURE_USED != 0 #if VAR_LAST_REPEL_LURE_USED != 0
VarSet(VAR_REPEL_STEP_COUNT, ItemId_GetHoldEffectParam(VarGet(I_VAR_LAST_REPEL_LURE_USED))); VarSet(VAR_REPEL_STEP_COUNT, ItemId_GetHoldEffectParam(VarGet(VAR_LAST_REPEL_LURE_USED)));
#endif #endif
} }
@ -917,8 +917,8 @@ static void Task_UseLure(u8 taskId)
if (!IsSEPlaying()) if (!IsSEPlaying())
{ {
VarSet(VAR_REPEL_STEP_COUNT, ItemId_GetHoldEffectParam(gSpecialVar_ItemId) | REPEL_LURE_MASK); VarSet(VAR_REPEL_STEP_COUNT, ItemId_GetHoldEffectParam(gSpecialVar_ItemId) | REPEL_LURE_MASK);
#if I_VAR_LAST_REPEL_LURE_USED != 0 #if VAR_LAST_REPEL_LURE_USED != 0
VarSet(I_VAR_LAST_REPEL_LURE_USED, gSpecialVar_ItemId); VarSet(VAR_LAST_REPEL_LURE_USED, gSpecialVar_ItemId);
#endif #endif
RemoveUsedItem(); RemoveUsedItem();
if (!InBattlePyramid()) if (!InBattlePyramid())
@ -930,8 +930,8 @@ static void Task_UseLure(u8 taskId)
void HandleUseExpiredLure(void) void HandleUseExpiredLure(void)
{ {
#if I_VAR_LAST_REPEL_LURE_USED != 0 #if VAR_LAST_REPEL_LURE_USED != 0
VarSet(VAR_REPEL_STEP_COUNT, ItemId_GetHoldEffectParam(VarGet(I_VAR_LAST_REPEL_LURE_USED)) | REPEL_LURE_MASK); VarSet(VAR_REPEL_STEP_COUNT, ItemId_GetHoldEffectParam(VarGet(VAR_LAST_REPEL_LURE_USED)) | REPEL_LURE_MASK);
#endif #endif
} }

View File

@ -90,12 +90,10 @@ static u16 GetLengthWithExpandedPlayerName(const u8 *str)
return length; return length;
} }
static void DrawMultichoiceMenu(u8 left, u8 top, u8 multichoiceId, bool8 ignoreBPress, u8 cursorPos) static void DrawMultichoiceMenuInternal(u8 left, u8 top, u8 multichoiceId, bool8 ignoreBPress, u8 cursorPos, const struct MenuAction *actions, int count)
{ {
int i; int i;
u8 windowId; u8 windowId;
u8 count = sMultichoiceLists[multichoiceId].count;
const struct MenuAction *actions = sMultichoiceLists[multichoiceId].list;
int width = 0; int width = 0;
u8 newWidth; u8 newWidth;
@ -114,6 +112,84 @@ static void DrawMultichoiceMenu(u8 left, u8 top, u8 multichoiceId, bool8 ignoreB
InitMultichoiceCheckWrap(ignoreBPress, count, windowId, multichoiceId); InitMultichoiceCheckWrap(ignoreBPress, count, windowId, multichoiceId);
} }
static void DrawMultichoiceMenu(u8 left, u8 top, u8 multichoiceId, bool8 ignoreBPress, u8 cursorPos)
{
DrawMultichoiceMenuInternal(left, top, multichoiceId, ignoreBPress, cursorPos, sMultichoiceLists[multichoiceId].list, sMultichoiceLists[multichoiceId].count);
}
#if I_REPEL_LURE_MENU == TRUE
void TryDrawRepelMenu(void)
{
static const u16 repelItems[] = {ITEM_REPEL, ITEM_SUPER_REPEL, ITEM_MAX_REPEL};
struct MenuAction menuItems[ARRAY_COUNT(repelItems) + 1] = {NULL};
int i, count = 0, menuPos = 0;
for (i = 0; i < ARRAY_COUNT(repelItems); i++)
{
if (CheckBagHasItem(repelItems[i], 1))
{
VarSet(VAR_0x8004 + count, repelItems[i]);
#if VAR_LAST_REPEL_LURE_USED != 0
if (VarGet(VAR_LAST_REPEL_LURE_USED) == repelItems[i])
menuPos = count;
#endif
menuItems[count].text = ItemId_GetName(repelItems[i]);
count++;
}
}
if (count > 1)
DrawMultichoiceMenuInternal(0, 0, 0, FALSE, menuPos, menuItems, count);
gSpecialVar_Result = (count > 1);
}
void HandleRepelMenuChoice(void)
{
gSpecialVar_0x8004 = VarGet(VAR_0x8004 + gSpecialVar_Result); // Get item Id;
VarSet(VAR_REPEL_STEP_COUNT, ItemId_GetHoldEffectParam(gSpecialVar_0x8004));
#if VAR_LAST_REPEL_LURE_USED != 0
VarSet(VAR_LAST_REPEL_LURE_USED, gSpecialVar_0x8004);
#endif
}
void TryDrawLureMenu(void)
{
static const u16 lureItems[] = {ITEM_LURE, ITEM_SUPER_LURE, ITEM_MAX_LURE};
struct MenuAction menuItems[ARRAY_COUNT(lureItems) + 1] = {NULL};
int i, count = 0, menuPos = 0;
for (i = 0; i < ARRAY_COUNT(lureItems); i++)
{
if (CheckBagHasItem(lureItems[i], 1))
{
VarSet(VAR_0x8004 + count, lureItems[i]);
#if VAR_LAST_REPEL_LURE_USED != 0
if (VarGet(VAR_LAST_REPEL_LURE_USED) == lureItems[i])
menuPos = count;
#endif
menuItems[count].text = ItemId_GetName(lureItems[i]);
count++;
}
}
if (count > 1)
DrawMultichoiceMenuInternal(0, 0, 0, FALSE, menuPos, menuItems, count);
gSpecialVar_Result = (count > 1);
}
void HandleLureMenuChoice(void)
{
gSpecialVar_0x8004 = VarGet(VAR_0x8004 + gSpecialVar_Result); // Get item Id;
VarSet(VAR_REPEL_STEP_COUNT, ItemId_GetHoldEffectParam(gSpecialVar_0x8004) | REPEL_LURE_MASK);
#if VAR_LAST_REPEL_LURE_USED != 0
VarSet(VAR_LAST_REPEL_LURE_USED, gSpecialVar_0x8004);
#endif
}
#endif //I_REPEL_LURE_MENU == TRUE
#define tLeft data[0] #define tLeft data[0]
#define tTop data[1] #define tTop data[1]
#define tRight data[2] #define tRight data[2]