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::
checkitem I_VAR_LAST_REPEL_LURE_USED, 1
compare VAR_RESULT, TRUE
goto_if_eq EventScript_UseAnother
.if I_REPEL_LURE_MENU == TRUE
checkitem ITEM_REPEL, 1
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
msgbox Text_RepelWoreOff, MSGBOX_SIGN
release
end
EventScript_UseAnother:
EventScript_RepelUseAnother:
lock
msgbox Text_UseAnother, MSGBOX_YESNO
compare VAR_RESULT, YES
goto_if_eq EventScript_UsedRepel
msgbox Text_UseAnotherRepel, MSGBOX_YESNO
.if I_REPEL_LURE_MENU == TRUE
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
end
EventScript_UsedRepel:
bufferitemname 0, I_VAR_LAST_REPEL_LURE_USED
bufferitemname 1, VAR_LAST_REPEL_LURE_USED
playse SE_REPEL
lock
msgbox Text_UsedNewRepelLure, MSGBOX_SIGN
removeitem I_VAR_LAST_REPEL_LURE_USED, 1
removeitem VAR_LAST_REPEL_LURE_USED, 1
waitse
callnative HandleUseExpiredRepel
release
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::
checkitem I_VAR_LAST_REPEL_LURE_USED, 1
compare VAR_RESULT, TRUE
goto_if_eq EventScript_LureUseAnother
.if I_REPEL_LURE_MENU == TRUE
checkitem ITEM_LURE, 1
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
msgbox Text_LureWoreOff, MSGBOX_SIGN
release
@ -49,25 +67,49 @@ EventScript_LureWoreOff::
EventScript_LureUseAnother:
lock
msgbox Text_UseAnotherLure, MSGBOX_YESNO
compare VAR_RESULT, YES
goto_if_eq EventScript_UsedLure
.if I_REPEL_LURE_MENU == TRUE
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
end
EventScript_UsedLure:
bufferitemname 0, I_VAR_LAST_REPEL_LURE_USED
bufferitemname 1, VAR_LAST_REPEL_LURE_USED
playse SE_REPEL
lock
msgbox Text_UsedNewRepelLure, MSGBOX_SIGN
removeitem I_VAR_LAST_REPEL_LURE_USED, 1
removeitem VAR_LAST_REPEL_LURE_USED, 1
waitse
callnative HandleUseExpiredLure
release
end
Text_RepelWoreOff:
.string "REPEL's effect wore off…$"
Text_UseAnotherRepel::
.string "REPEL's effect wore off!\n"
.string "Use another?$"
Text_LureWoreOff:
.string "Lure's effect wore off…$"
Text_UseAnotherLure::
.string "Lure's effect wore off!\n"
.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_VITAMIN_EV_CAP GEN_LATEST // In Gen8, the Vitamins no longer have a cap of 100 EV per stat.
// Var settings
// To use the following features, replace the 0s with the var ID you're assigning it to.
// Eg: Replace with VAR_UNUSED_0x40F7 so you can use I_VAR_LAST_REPEL_LURE_USED for that feature.
#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.
// Repel/Lure config
// These two settings are both independent and complementary.
#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_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

View File

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

View File

@ -90,12 +90,10 @@ static u16 GetLengthWithExpandedPlayerName(const u8 *str)
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;
u8 windowId;
u8 count = sMultichoiceLists[multichoiceId].count;
const struct MenuAction *actions = sMultichoiceLists[multichoiceId].list;
int width = 0;
u8 newWidth;
@ -114,6 +112,84 @@ static void DrawMultichoiceMenu(u8 left, u8 top, u8 multichoiceId, bool8 ignoreB
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 tTop data[1]
#define tRight data[2]