2018-01-28 04:58:44 +01:00
|
|
|
#include "global.h"
|
2018-02-08 00:00:25 +01:00
|
|
|
#include "item_use.h"
|
2018-01-28 04:58:44 +01:00
|
|
|
#include "battle.h"
|
2019-04-01 13:40:42 +02:00
|
|
|
#include "battle_anim.h"
|
2019-02-08 00:41:44 +01:00
|
|
|
#include "battle_pyramid.h"
|
2018-09-11 04:04:19 +02:00
|
|
|
#include "battle_pyramid_bag.h"
|
2018-01-28 04:58:44 +01:00
|
|
|
#include "berry.h"
|
2019-03-24 20:45:09 +01:00
|
|
|
#include "berry_powder.h"
|
2018-01-28 04:58:44 +01:00
|
|
|
#include "bike.h"
|
|
|
|
#include "coins.h"
|
2019-04-04 23:53:06 +02:00
|
|
|
#include "data.h"
|
2018-01-28 04:58:44 +01:00
|
|
|
#include "event_data.h"
|
2019-12-06 08:55:30 +01:00
|
|
|
#include "event_object_lock.h"
|
2018-06-11 15:34:19 +02:00
|
|
|
#include "event_object_movement.h"
|
2019-12-22 01:01:38 +01:00
|
|
|
#include "event_scripts.h"
|
2019-03-02 08:44:02 +01:00
|
|
|
#include "fieldmap.h"
|
|
|
|
#include "field_effect.h"
|
2018-01-28 04:58:44 +01:00
|
|
|
#include "field_player_avatar.h"
|
2018-12-08 22:05:11 +01:00
|
|
|
#include "field_screen_effect.h"
|
2018-01-28 04:58:44 +01:00
|
|
|
#include "field_weather.h"
|
|
|
|
#include "item.h"
|
2018-09-11 04:04:19 +02:00
|
|
|
#include "item_menu.h"
|
2019-03-02 08:44:02 +01:00
|
|
|
#include "item_use.h"
|
2018-01-28 04:58:44 +01:00
|
|
|
#include "mail.h"
|
2018-09-11 04:04:19 +02:00
|
|
|
#include "main.h"
|
|
|
|
#include "menu.h"
|
|
|
|
#include "menu_helpers.h"
|
2018-01-28 04:58:44 +01:00
|
|
|
#include "metatile_behavior.h"
|
|
|
|
#include "overworld.h"
|
|
|
|
#include "palette.h"
|
2018-09-11 04:04:19 +02:00
|
|
|
#include "party_menu.h"
|
|
|
|
#include "pokeblock.h"
|
2018-01-28 04:58:44 +01:00
|
|
|
#include "pokemon.h"
|
|
|
|
#include "script.h"
|
|
|
|
#include "sound.h"
|
2018-09-11 04:04:19 +02:00
|
|
|
#include "strings.h"
|
2018-01-28 04:58:44 +01:00
|
|
|
#include "string_util.h"
|
|
|
|
#include "task.h"
|
|
|
|
#include "text.h"
|
2019-11-21 20:03:35 +01:00
|
|
|
#include "constants/event_bg.h"
|
2018-12-28 19:29:21 +01:00
|
|
|
#include "constants/event_objects.h"
|
2019-04-14 17:20:26 +02:00
|
|
|
#include "constants/item_effects.h"
|
2018-09-11 04:04:19 +02:00
|
|
|
#include "constants/items.h"
|
|
|
|
#include "constants/songs.h"
|
2018-01-28 04:58:44 +01:00
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
static void SetUpItemUseCallback(u8 taskId);
|
|
|
|
static void FieldCB_UseItemOnField(void);
|
|
|
|
static void Task_CallItemUseOnFieldCallback(u8 taskId);
|
|
|
|
static void Task_UseItemfinder(u8 taskId);
|
|
|
|
static void Task_CloseItemfinderMessage(u8 taskId);
|
|
|
|
static void Task_HiddenItemNearby(u8 taskId);
|
|
|
|
static void Task_StandingOnHiddenItem(u8 taskId);
|
|
|
|
static bool8 ItemfinderCheckForHiddenItems(const struct MapEvents *, u8);
|
|
|
|
static u8 GetDirectionToHiddenItem(s16 distanceX, s16 distanceY);
|
|
|
|
static void PlayerFaceHiddenItem(u8 a);
|
|
|
|
static void CheckForHiddenItemsInMapConnection(u8 taskId);
|
2021-01-01 23:02:03 +01:00
|
|
|
static void Task_OpenRegisteredPokeblockCase(u8 taskId);
|
2019-12-22 01:01:38 +01:00
|
|
|
static void ItemUseOnFieldCB_Bike(u8 taskId);
|
|
|
|
static void ItemUseOnFieldCB_Rod(u8);
|
|
|
|
static void ItemUseOnFieldCB_Itemfinder(u8);
|
|
|
|
static void ItemUseOnFieldCB_Berry(u8 taskId);
|
|
|
|
static void ItemUseOnFieldCB_WailmerPailBerry(u8 taskId);
|
|
|
|
static void ItemUseOnFieldCB_WailmerPailSudowoodo(u8 taskId);
|
|
|
|
static bool8 TryToWaterSudowoodo(void);
|
2019-10-18 01:22:03 +02:00
|
|
|
static void BootUpSoundTMHM(u8 taskId);
|
|
|
|
static void Task_ShowTMHMContainedMessage(u8 taskId);
|
|
|
|
static void UseTMHMYesNo(u8 taskId);
|
|
|
|
static void UseTMHM(u8 taskId);
|
2019-12-22 01:01:38 +01:00
|
|
|
static void Task_StartUseRepel(u8 taskId);
|
|
|
|
static void Task_UseRepel(u8 taskId);
|
|
|
|
static void Task_CloseCantUseKeyItemMessage(u8 taskId);
|
|
|
|
static void SetDistanceOfClosestHiddenItem(u8 taskId, s16 x, s16 y);
|
2021-01-01 23:02:03 +01:00
|
|
|
static void CB2_OpenPokeblockFromBag(void);
|
2018-01-28 04:58:44 +01:00
|
|
|
|
2019-02-02 12:44:00 +01:00
|
|
|
// EWRAM variables
|
2019-12-22 01:01:38 +01:00
|
|
|
EWRAM_DATA static void(*sItemUseOnFieldCB)(u8 taskId) = NULL;
|
|
|
|
|
|
|
|
// Below is set TRUE by UseRegisteredKeyItemOnField
|
|
|
|
#define tUsingRegisteredKeyItem data[3]
|
2019-02-02 12:44:00 +01:00
|
|
|
|
2021-01-19 11:49:20 +01:00
|
|
|
// UB here if an item with type ITEM_USE_MAIL or ITEM_USE_BAG_MENU uses SetUpItemUseCallback
|
|
|
|
// Never occurs in vanilla, but can occur with improperly created items
|
2019-11-29 08:00:19 +01:00
|
|
|
static const MainCallback sItemUseCallbacks[] =
|
2018-09-11 04:04:19 +02:00
|
|
|
{
|
2021-01-19 11:49:20 +01:00
|
|
|
[ITEM_USE_PARTY_MENU - 1] = CB2_ShowPartyMenuForItemUse,
|
|
|
|
[ITEM_USE_FIELD - 1] = CB2_ReturnToField,
|
|
|
|
[ITEM_USE_PBLOCK_CASE - 1] = NULL,
|
2018-09-11 04:04:19 +02:00
|
|
|
};
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
static const u8 sClockwiseDirections[] = {DIR_NORTH, DIR_EAST, DIR_SOUTH, DIR_WEST};
|
2018-09-11 04:04:19 +02:00
|
|
|
|
2019-10-18 01:22:03 +02:00
|
|
|
static const struct YesNoFuncTable sUseTMHMYesNoFuncTable =
|
2018-09-11 04:04:19 +02:00
|
|
|
{
|
2019-10-18 01:22:03 +02:00
|
|
|
.yesFunc = UseTMHM,
|
2021-08-03 08:17:01 +02:00
|
|
|
.noFunc = CloseItemMessage,
|
2018-09-11 04:04:19 +02:00
|
|
|
};
|
|
|
|
|
2021-01-19 11:49:20 +01:00
|
|
|
#define tEnigmaBerryType data[4]
|
2019-12-22 01:01:38 +01:00
|
|
|
static void SetUpItemUseCallback(u8 taskId)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
|
|
|
u8 type;
|
|
|
|
if (gSpecialVar_ItemId == ITEM_ENIGMA_BERRY)
|
2021-01-19 11:49:20 +01:00
|
|
|
type = gTasks[taskId].tEnigmaBerryType - 1;
|
2018-01-28 04:58:44 +01:00
|
|
|
else
|
|
|
|
type = ItemId_GetType(gSpecialVar_ItemId) - 1;
|
|
|
|
if (!InBattlePyramid())
|
|
|
|
{
|
2021-08-03 08:17:01 +02:00
|
|
|
gBagMenu->newScreenCallback = sItemUseCallbacks[type];
|
2019-12-22 01:01:38 +01:00
|
|
|
Task_FadeAndCloseBagMenu(taskId);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-03 08:17:01 +02:00
|
|
|
gPyramidBagMenu->newScreenCallback = sItemUseCallbacks[type];
|
2021-04-23 00:49:54 +02:00
|
|
|
CloseBattlePyramidBag(taskId);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
static void SetUpItemUseOnFieldCallback(u8 taskId)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
if (gTasks[taskId].tUsingRegisteredKeyItem != TRUE)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
gFieldCallback = FieldCB_UseItemOnField;
|
2018-01-28 04:58:44 +01:00
|
|
|
SetUpItemUseCallback(taskId);
|
|
|
|
}
|
|
|
|
else
|
2019-12-22 01:01:38 +01:00
|
|
|
sItemUseOnFieldCB(taskId);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
static void FieldCB_UseItemOnField(void)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2019-12-17 09:24:44 +01:00
|
|
|
FadeInFromBlack();
|
2018-01-28 04:58:44 +01:00
|
|
|
CreateTask(Task_CallItemUseOnFieldCallback, 8);
|
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
static void Task_CallItemUseOnFieldCallback(u8 taskId)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2018-05-11 01:36:57 +02:00
|
|
|
if (IsWeatherNotFadingIn() == 1)
|
2019-12-22 01:01:38 +01:00
|
|
|
sItemUseOnFieldCB(taskId);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
static void DisplayCannotUseItemMessage(u8 taskId, bool8 isUsingRegisteredKeyItemOnField, const u8 *str)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
|
|
|
StringExpandPlaceholders(gStringVar4, str);
|
|
|
|
if (!isUsingRegisteredKeyItemOnField)
|
|
|
|
{
|
|
|
|
if (!InBattlePyramid())
|
2021-08-03 08:17:01 +02:00
|
|
|
DisplayItemMessage(taskId, 1, gStringVar4, CloseItemMessage);
|
2018-01-28 04:58:44 +01:00
|
|
|
else
|
2019-12-22 01:01:38 +01:00
|
|
|
DisplayItemMessageInBattlePyramid(taskId, gText_DadsAdvice, Task_CloseBattlePyramidBagMessage);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
else
|
2019-12-22 01:01:38 +01:00
|
|
|
DisplayItemMessageOnField(taskId, gStringVar4, Task_CloseCantUseKeyItemMessage);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
static void DisplayDadsAdviceCannotUseItemMessage(u8 taskId, bool8 isUsingRegisteredKeyItemOnField)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
|
|
|
DisplayCannotUseItemMessage(taskId, isUsingRegisteredKeyItemOnField, gText_DadsAdvice);
|
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
static void DisplayCannotDismountBikeMessage(u8 taskId, bool8 isUsingRegisteredKeyItemOnField)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
|
|
|
DisplayCannotUseItemMessage(taskId, isUsingRegisteredKeyItemOnField, gText_CantDismountBike);
|
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
static void Task_CloseCantUseKeyItemMessage(u8 taskId)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2019-02-22 07:40:11 +01:00
|
|
|
ClearDialogWindowAndFrame(0, 1);
|
2018-01-28 04:58:44 +01:00
|
|
|
DestroyTask(taskId);
|
2019-11-21 04:55:44 +01:00
|
|
|
ScriptUnfreezeObjectEvents();
|
2018-01-28 04:58:44 +01:00
|
|
|
ScriptContext2_Disable();
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 CheckIfItemIsTMHMOrEvolutionStone(u16 itemId)
|
|
|
|
{
|
|
|
|
if (ItemId_GetFieldFunc(itemId) == ItemUseOutOfBattle_TMHM)
|
|
|
|
return 1;
|
|
|
|
else if (ItemId_GetFieldFunc(itemId) == ItemUseOutOfBattle_EvolutionStone)
|
|
|
|
return 2;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
// Mail in the bag menu can't have a message but it can be checked (view the mail background, no message)
|
|
|
|
static void CB2_CheckMail(void)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
|
|
|
struct MailStruct mail;
|
|
|
|
mail.itemId = gSpecialVar_ItemId;
|
2019-12-22 01:01:38 +01:00
|
|
|
ReadMail(&mail, CB2_ReturnToBagMenuPocket, 0);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ItemUseOutOfBattle_Mail(u8 taskId)
|
|
|
|
{
|
2021-08-03 08:17:01 +02:00
|
|
|
gBagMenu->newScreenCallback = CB2_CheckMail;
|
2019-12-22 01:01:38 +01:00
|
|
|
Task_FadeAndCloseBagMenu(taskId);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ItemUseOutOfBattle_Bike(u8 taskId)
|
|
|
|
{
|
|
|
|
s16* data = gTasks[taskId].data;
|
|
|
|
s16 coordsY;
|
|
|
|
s16 coordsX;
|
|
|
|
u8 behavior;
|
|
|
|
PlayerGetDestCoords(&coordsX, &coordsY);
|
|
|
|
behavior = MapGridGetMetatileBehaviorAt(coordsX, coordsY);
|
|
|
|
if (FlagGet(FLAG_SYS_CYCLING_ROAD) == TRUE || MetatileBehavior_IsVerticalRail(behavior) == TRUE || MetatileBehavior_IsHorizontalRail(behavior) == TRUE || MetatileBehavior_IsIsolatedVerticalRail(behavior) == TRUE || MetatileBehavior_IsIsolatedHorizontalRail(behavior) == TRUE)
|
2019-12-22 01:01:38 +01:00
|
|
|
DisplayCannotDismountBikeMessage(taskId, tUsingRegisteredKeyItem);
|
2018-01-28 04:58:44 +01:00
|
|
|
else
|
|
|
|
{
|
2018-02-12 18:26:26 +01:00
|
|
|
if (Overworld_IsBikingAllowed() == TRUE && IsBikingDisallowedByPlayer() == 0)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
sItemUseOnFieldCB = ItemUseOnFieldCB_Bike;
|
2018-01-28 04:58:44 +01:00
|
|
|
SetUpItemUseOnFieldCallback(taskId);
|
|
|
|
}
|
|
|
|
else
|
2019-12-22 01:01:38 +01:00
|
|
|
DisplayDadsAdviceCannotUseItemMessage(taskId, tUsingRegisteredKeyItem);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
static void ItemUseOnFieldCB_Bike(u8 taskId)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2021-01-19 11:49:20 +01:00
|
|
|
if (ItemId_GetSecondaryId(gSpecialVar_ItemId) == MACH_BIKE)
|
2020-04-01 08:54:26 +02:00
|
|
|
GetOnOffBike(PLAYER_AVATAR_FLAG_MACH_BIKE);
|
2021-01-19 11:49:20 +01:00
|
|
|
else // ACRO_BIKE
|
2020-04-01 08:54:26 +02:00
|
|
|
GetOnOffBike(PLAYER_AVATAR_FLAG_ACRO_BIKE);
|
2019-11-21 04:55:44 +01:00
|
|
|
ScriptUnfreezeObjectEvents();
|
2018-01-28 04:58:44 +01:00
|
|
|
ScriptContext2_Disable();
|
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
static bool32 CanFish(void)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
|
|
|
s16 x, y;
|
|
|
|
u16 tileBehavior;
|
|
|
|
|
|
|
|
GetXYCoordsOneStepInFrontOfPlayer(&x, &y);
|
|
|
|
tileBehavior = MapGridGetMetatileBehaviorAt(x, y);
|
|
|
|
|
|
|
|
if (MetatileBehavior_IsWaterfall(tileBehavior))
|
|
|
|
return FALSE;
|
|
|
|
|
2018-10-19 07:05:54 +02:00
|
|
|
if (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_UNDERWATER))
|
2018-01-28 04:58:44 +01:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_SURFING))
|
|
|
|
{
|
|
|
|
if (IsPlayerFacingSurfableFishableWater())
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (MetatileBehavior_IsSurfableWaterOrUnderwater(tileBehavior) && !MapGridIsImpassableAt(x, y))
|
|
|
|
return TRUE;
|
|
|
|
if (MetatileBehavior_8089510(tileBehavior) == TRUE)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemUseOutOfBattle_Rod(u8 taskId)
|
|
|
|
{
|
|
|
|
if (CanFish() == TRUE)
|
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
sItemUseOnFieldCB = ItemUseOnFieldCB_Rod;
|
2018-01-28 04:58:44 +01:00
|
|
|
SetUpItemUseOnFieldCallback(taskId);
|
|
|
|
}
|
|
|
|
else
|
2019-12-22 01:01:38 +01:00
|
|
|
DisplayDadsAdviceCannotUseItemMessage(taskId, gTasks[taskId].tUsingRegisteredKeyItem);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
static void ItemUseOnFieldCB_Rod(u8 taskId)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
|
|
|
StartFishing(ItemId_GetSecondaryId(gSpecialVar_ItemId));
|
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemUseOutOfBattle_Itemfinder(u8 var)
|
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
IncrementGameStat(GAME_STAT_USED_ITEMFINDER);
|
|
|
|
sItemUseOnFieldCB = ItemUseOnFieldCB_Itemfinder;
|
2018-01-28 04:58:44 +01:00
|
|
|
SetUpItemUseOnFieldCallback(var);
|
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
static void ItemUseOnFieldCB_Itemfinder(u8 taskId)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
|
|
|
if (ItemfinderCheckForHiddenItems(gMapHeader.events, taskId) == TRUE)
|
2019-12-22 01:01:38 +01:00
|
|
|
gTasks[taskId].func = Task_UseItemfinder;
|
2018-01-28 04:58:44 +01:00
|
|
|
else
|
2019-12-22 01:01:38 +01:00
|
|
|
DisplayItemMessageOnField(taskId, gText_ItemFinderNothing, Task_CloseItemfinderMessage);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
// Define itemfinder task data
|
|
|
|
#define tItemDistanceX data[0]
|
|
|
|
#define tItemDistanceY data[1]
|
|
|
|
#define tItemFound data[2]
|
|
|
|
#define tCounter data[3] // Used to count delay between beeps and rotations during player spin
|
|
|
|
#define tItemfinderBeeps data[4]
|
|
|
|
#define tFacingDir data[5]
|
|
|
|
|
|
|
|
static void Task_UseItemfinder(u8 taskId)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
|
|
|
u8 playerDir;
|
|
|
|
u8 playerDirToItem;
|
|
|
|
u8 i;
|
|
|
|
s16* data = gTasks[taskId].data;
|
2019-12-22 01:01:38 +01:00
|
|
|
if (tCounter == 0)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
if (tItemfinderBeeps == 4)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
playerDirToItem = GetDirectionToHiddenItem(tItemDistanceX, tItemDistanceY);
|
|
|
|
if (playerDirToItem != DIR_NONE)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
PlayerFaceHiddenItem(sClockwiseDirections[playerDirToItem - 1]);
|
|
|
|
gTasks[taskId].func = Task_HiddenItemNearby;
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
// Player is standing on hidden item
|
2018-06-14 00:51:26 +02:00
|
|
|
playerDir = GetPlayerFacingDirection();
|
2019-12-22 01:01:38 +01:00
|
|
|
for (i = 0; i < ARRAY_COUNT(sClockwiseDirections); i++)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
if (playerDir == sClockwiseDirections[i])
|
|
|
|
tFacingDir = (i + 1) & 3;
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
2019-12-22 01:01:38 +01:00
|
|
|
gTasks[taskId].func = Task_StandingOnHiddenItem;
|
|
|
|
tCounter = 0;
|
|
|
|
tItemFound = 0;
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2020-08-21 00:02:00 +02:00
|
|
|
PlaySE(SE_ITEMFINDER);
|
2019-12-22 01:01:38 +01:00
|
|
|
tItemfinderBeeps++;
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
2019-12-22 01:01:38 +01:00
|
|
|
tCounter = (tCounter + 1) & 0x1F;
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
static void Task_CloseItemfinderMessage(u8 taskId)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2019-02-22 07:40:11 +01:00
|
|
|
ClearDialogWindowAndFrame(0, 1);
|
2019-11-21 04:55:44 +01:00
|
|
|
ScriptUnfreezeObjectEvents();
|
2018-01-28 04:58:44 +01:00
|
|
|
ScriptContext2_Disable();
|
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
static bool8 ItemfinderCheckForHiddenItems(const struct MapEvents *events, u8 taskId)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
int itemX, itemY;
|
|
|
|
s16 playerX, playerY, i, distanceX, distanceY;
|
|
|
|
PlayerGetDestCoords(&playerX, &playerY);
|
|
|
|
gTasks[taskId].tItemFound = FALSE;
|
|
|
|
|
2018-01-28 04:58:44 +01:00
|
|
|
for (i = 0; i < events->bgEventCount; i++)
|
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
// Check if there are any hidden items on the current map that haven't been picked up
|
2019-11-01 01:56:26 +01:00
|
|
|
if (events->bgEvents[i].kind == BG_EVENT_HIDDEN_ITEM && !FlagGet(events->bgEvents[i].bgUnion.hiddenItem.hiddenItemId + FLAG_HIDDEN_ITEMS_START))
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
itemX = (u16)events->bgEvents[i].x + 7;
|
|
|
|
distanceX = itemX - playerX;
|
|
|
|
itemY = (u16)events->bgEvents[i].y + 7;
|
|
|
|
distanceY = itemY - playerY;
|
2018-02-05 17:39:26 +01:00
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
if ((u16)(distanceX + 7) < 15 && (distanceY >= -5) && (distanceY < 6))
|
|
|
|
SetDistanceOfClosestHiddenItem(taskId, distanceX, distanceY);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
}
|
2018-02-05 17:39:26 +01:00
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
CheckForHiddenItemsInMapConnection(taskId);
|
|
|
|
if (gTasks[taskId].tItemFound == TRUE)
|
2018-01-28 04:58:44 +01:00
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
static bool8 IsHiddenItemPresentAtCoords(const struct MapEvents *events, s16 x, s16 y)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
|
|
|
u8 bgEventCount = events->bgEventCount;
|
|
|
|
struct BgEvent *bgEvent = events->bgEvents;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < bgEventCount; i++)
|
|
|
|
{
|
2018-07-11 18:12:26 +02:00
|
|
|
if (bgEvent[i].kind == BG_EVENT_HIDDEN_ITEM && x == (u16)bgEvent[i].x && y == (u16)bgEvent[i].y) // hidden item and coordinates matches x and y passed?
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2019-11-01 01:56:26 +01:00
|
|
|
if (!FlagGet(bgEvent[i].bgUnion.hiddenItem.hiddenItemId + FLAG_HIDDEN_ITEMS_START))
|
2018-01-28 04:58:44 +01:00
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
static bool8 IsHiddenItemPresentInConnection(struct MapConnection *connection, int x, int y)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2019-04-01 13:40:42 +02:00
|
|
|
|
2018-01-28 04:58:44 +01:00
|
|
|
u16 localX, localY;
|
|
|
|
u32 localOffset;
|
|
|
|
s32 localLength;
|
|
|
|
|
2020-06-24 22:27:00 +02:00
|
|
|
struct MapHeader const *const mapHeader = GetMapHeaderFromConnection(connection);
|
2018-01-28 04:58:44 +01:00
|
|
|
|
|
|
|
switch (connection->direction)
|
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
// same weird temp variable behavior seen in IsHiddenItemPresentAtCoords
|
2018-01-28 04:58:44 +01:00
|
|
|
case 2:
|
|
|
|
localOffset = connection->offset + 7;
|
|
|
|
localX = x - localOffset;
|
2018-06-21 00:41:51 +02:00
|
|
|
localLength = mapHeader->mapLayout->height - 7;
|
2018-01-28 04:58:44 +01:00
|
|
|
localY = localLength + y; // additions are reversed for some reason
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
localOffset = connection->offset + 7;
|
|
|
|
localX = x - localOffset;
|
2018-06-21 00:41:51 +02:00
|
|
|
localLength = gMapHeader.mapLayout->height + 7;
|
2018-01-28 04:58:44 +01:00
|
|
|
localY = y - localLength;
|
|
|
|
break;
|
|
|
|
case 3:
|
2018-06-21 00:41:51 +02:00
|
|
|
localLength = mapHeader->mapLayout->width - 7;
|
2018-01-28 04:58:44 +01:00
|
|
|
localX = localLength + x; // additions are reversed for some reason
|
|
|
|
localOffset = connection->offset + 7;
|
|
|
|
localY = y - localOffset;
|
|
|
|
break;
|
|
|
|
case 4:
|
2018-06-21 00:41:51 +02:00
|
|
|
localLength = gMapHeader.mapLayout->width + 7;
|
2018-01-28 04:58:44 +01:00
|
|
|
localX = x - localLength;
|
|
|
|
localOffset = connection->offset + 7;
|
|
|
|
localY = y - localOffset;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
2019-12-22 01:01:38 +01:00
|
|
|
return IsHiddenItemPresentAtCoords(mapHeader->events, localX, localY);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
static void CheckForHiddenItemsInMapConnection(u8 taskId)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
s16 playerX, playerY;
|
2018-01-28 04:58:44 +01:00
|
|
|
s16 x, y;
|
2018-06-21 00:41:51 +02:00
|
|
|
s16 width = gMapHeader.mapLayout->width + 7;
|
|
|
|
s16 height = gMapHeader.mapLayout->height + 7;
|
2018-01-28 04:58:44 +01:00
|
|
|
|
2018-02-06 18:15:10 +01:00
|
|
|
s16 var1 = 7;
|
|
|
|
s16 var2 = 7;
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
PlayerGetDestCoords(&playerX, &playerY);
|
2018-01-28 04:58:44 +01:00
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
for (x = playerX - 7; x <= playerX + 7; x++)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
for (y = playerY - 5; y <= playerY + 5; y++)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
if (var1 > x
|
|
|
|
|| x >= width
|
|
|
|
|| var2 > y
|
|
|
|
|| y >= height)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
struct MapConnection *conn = GetConnectionAtCoords(x, y);
|
|
|
|
if (conn && IsHiddenItemPresentInConnection(conn, x, y) == TRUE)
|
|
|
|
SetDistanceOfClosestHiddenItem(taskId, x - playerX, y - playerY);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
static void SetDistanceOfClosestHiddenItem(u8 taskId, s16 itemDistanceX, s16 itemDistanceY)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
|
|
|
s16 *data = gTasks[taskId].data;
|
2019-12-22 01:01:38 +01:00
|
|
|
s16 oldItemAbsX, oldItemAbsY, newItemAbsX, newItemAbsY;
|
2018-01-28 04:58:44 +01:00
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
if (tItemFound == FALSE)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
// No other items found yet, set this one
|
|
|
|
tItemDistanceX = itemDistanceX;
|
|
|
|
tItemDistanceY = itemDistanceY;
|
|
|
|
tItemFound = TRUE;
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
// Other items have been found, check if this one is closer
|
|
|
|
|
|
|
|
// Get absolute x distance of the already-found item
|
|
|
|
if (tItemDistanceX < 0)
|
|
|
|
oldItemAbsX = tItemDistanceX * -1; // WEST
|
2018-01-28 04:58:44 +01:00
|
|
|
else
|
2019-12-22 01:01:38 +01:00
|
|
|
oldItemAbsX = tItemDistanceX; // EAST
|
2018-01-28 04:58:44 +01:00
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
// Get absolute y distance of the already-found item
|
|
|
|
if (tItemDistanceY < 0)
|
|
|
|
oldItemAbsY = tItemDistanceY * -1; // NORTH
|
2018-01-28 04:58:44 +01:00
|
|
|
else
|
2019-12-22 01:01:38 +01:00
|
|
|
oldItemAbsY = tItemDistanceY; // SOUTH
|
2018-01-28 04:58:44 +01:00
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
// Get absolute x distance of the newly-found item
|
|
|
|
if (itemDistanceX < 0)
|
|
|
|
newItemAbsX = itemDistanceX * -1;
|
2018-01-28 04:58:44 +01:00
|
|
|
else
|
2019-12-22 01:01:38 +01:00
|
|
|
newItemAbsX = itemDistanceX;
|
2018-01-28 04:58:44 +01:00
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
// Get absolute y distance of the newly-found item
|
|
|
|
if (itemDistanceY < 0)
|
|
|
|
newItemAbsY = itemDistanceY * -1;
|
2018-01-28 04:58:44 +01:00
|
|
|
else
|
2019-12-22 01:01:38 +01:00
|
|
|
newItemAbsY = itemDistanceY;
|
2018-01-28 04:58:44 +01:00
|
|
|
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
if (oldItemAbsX + oldItemAbsY > newItemAbsX + newItemAbsY)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
// New item is closer
|
|
|
|
tItemDistanceX = itemDistanceX;
|
|
|
|
tItemDistanceY = itemDistanceY;
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-12-30 18:52:23 +01:00
|
|
|
if (oldItemAbsX + oldItemAbsY == newItemAbsX + newItemAbsY
|
2019-12-22 01:01:38 +01:00
|
|
|
&& (oldItemAbsY > newItemAbsY || (oldItemAbsY == newItemAbsY && tItemDistanceY < itemDistanceY)))
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
// If items are equal distance, use whichever is closer on the Y axis or further south
|
|
|
|
tItemDistanceX = itemDistanceX;
|
|
|
|
tItemDistanceY = itemDistanceY;
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
static u8 GetDirectionToHiddenItem(s16 itemDistanceX, s16 itemDistanceY)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
s16 absX, absY;
|
2018-01-28 04:58:44 +01:00
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
if (itemDistanceX == 0 && itemDistanceY == 0)
|
2018-01-28 04:58:44 +01:00
|
|
|
return DIR_NONE; // player is standing on the item.
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
// Get absolute X distance.
|
|
|
|
if (itemDistanceX < 0)
|
|
|
|
absX = itemDistanceX * -1;
|
2018-01-28 04:58:44 +01:00
|
|
|
else
|
2019-12-22 01:01:38 +01:00
|
|
|
absX = itemDistanceX;
|
2018-01-28 04:58:44 +01:00
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
// Get absolute Y distance.
|
|
|
|
if (itemDistanceY < 0)
|
|
|
|
absY = itemDistanceY * -1;
|
2018-01-28 04:58:44 +01:00
|
|
|
else
|
2019-12-22 01:01:38 +01:00
|
|
|
absY = itemDistanceY;
|
2018-01-28 04:58:44 +01:00
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
if (absX > absY)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
if (itemDistanceX < 0)
|
2018-01-28 04:58:44 +01:00
|
|
|
return DIR_EAST;
|
|
|
|
else
|
|
|
|
return DIR_NORTH;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
if (absX < absY)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
if (itemDistanceY < 0)
|
2018-01-28 04:58:44 +01:00
|
|
|
return DIR_SOUTH;
|
|
|
|
else
|
|
|
|
return DIR_WEST;
|
|
|
|
}
|
2019-12-22 01:01:38 +01:00
|
|
|
if (absX == absY)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
if (itemDistanceY < 0)
|
2018-01-28 04:58:44 +01:00
|
|
|
return DIR_SOUTH;
|
|
|
|
else
|
|
|
|
return DIR_WEST;
|
|
|
|
}
|
2019-12-22 01:01:38 +01:00
|
|
|
return DIR_NONE; // Unreachable
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
static void PlayerFaceHiddenItem(u8 direction)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2019-11-21 05:12:51 +01:00
|
|
|
ObjectEventClearHeldMovementIfFinished(&gObjectEvents[GetObjectEventIdByLocalIdAndMap(OBJ_EVENT_ID_PLAYER, 0, 0)]);
|
|
|
|
ObjectEventClearHeldMovement(&gObjectEvents[GetObjectEventIdByLocalIdAndMap(OBJ_EVENT_ID_PLAYER, 0, 0)]);
|
|
|
|
UnfreezeObjectEvent(&gObjectEvents[GetObjectEventIdByLocalIdAndMap(OBJ_EVENT_ID_PLAYER, 0, 0)]);
|
2018-01-28 04:58:44 +01:00
|
|
|
PlayerTurnInPlace(direction);
|
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
static void Task_HiddenItemNearby(u8 taskId)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2019-11-21 05:12:51 +01:00
|
|
|
if (ObjectEventCheckHeldMovementStatus(&gObjectEvents[GetObjectEventIdByLocalIdAndMap(OBJ_EVENT_ID_PLAYER, 0, 0)]) == TRUE)
|
2019-12-22 01:01:38 +01:00
|
|
|
DisplayItemMessageOnField(taskId, gText_ItemFinderNearby, Task_CloseItemfinderMessage);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
static void Task_StandingOnHiddenItem(u8 taskId)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
|
|
|
s16 *data = gTasks[taskId].data;
|
|
|
|
|
2019-11-21 05:12:51 +01:00
|
|
|
if (ObjectEventCheckHeldMovementStatus(&gObjectEvents[GetObjectEventIdByLocalIdAndMap(OBJ_EVENT_ID_PLAYER, 0, 0)]) == TRUE
|
2019-12-22 01:01:38 +01:00
|
|
|
|| tItemFound == FALSE)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
// Spin player around on item
|
|
|
|
PlayerFaceHiddenItem(sClockwiseDirections[tFacingDir]);
|
|
|
|
tItemFound = TRUE;
|
|
|
|
tFacingDir = (tFacingDir + 1) & 3;
|
|
|
|
tCounter++;
|
|
|
|
|
|
|
|
if (tCounter == 4)
|
|
|
|
DisplayItemMessageOnField(taskId, gText_ItemFinderOnTop, Task_CloseItemfinderMessage);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
// Undefine itemfinder task data
|
|
|
|
#undef tItemDistanceX
|
|
|
|
#undef tItemDistanceY
|
|
|
|
#undef tItemFound
|
|
|
|
#undef tCounter
|
|
|
|
#undef tItemfinderBeeps
|
|
|
|
#undef tFacingDir
|
|
|
|
|
2018-01-28 04:58:44 +01:00
|
|
|
void ItemUseOutOfBattle_PokeblockCase(u8 taskId)
|
|
|
|
{
|
2020-05-14 10:37:09 +02:00
|
|
|
if (MenuHelpers_LinkSomething() == TRUE) // link func
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
DisplayDadsAdviceCannotUseItemMessage(taskId, gTasks[taskId].tUsingRegisteredKeyItem);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
2019-12-22 01:01:38 +01:00
|
|
|
else if (gTasks[taskId].tUsingRegisteredKeyItem != TRUE)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2021-08-03 08:17:01 +02:00
|
|
|
gBagMenu->newScreenCallback = CB2_OpenPokeblockFromBag;
|
2019-12-22 01:01:38 +01:00
|
|
|
Task_FadeAndCloseBagMenu(taskId);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-01 23:02:03 +01:00
|
|
|
gFieldCallback = FieldCB_ReturnToFieldNoScript;
|
2019-12-15 17:42:50 +01:00
|
|
|
FadeScreen(FADE_TO_BLACK, 0);
|
2021-01-01 23:02:03 +01:00
|
|
|
gTasks[taskId].func = Task_OpenRegisteredPokeblockCase;
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-01 23:02:03 +01:00
|
|
|
static void CB2_OpenPokeblockFromBag(void)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
OpenPokeblockCase(PBLOCK_CASE_FIELD, CB2_ReturnToBagMenuPocket);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
|
2021-01-01 23:02:03 +01:00
|
|
|
static void Task_OpenRegisteredPokeblockCase(u8 taskId)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
2018-12-27 23:30:47 +01:00
|
|
|
CleanupOverworldWindowsAndTilemaps();
|
2019-12-22 01:01:38 +01:00
|
|
|
OpenPokeblockCase(PBLOCK_CASE_FIELD, CB2_ReturnToField);
|
2018-01-28 04:58:44 +01:00
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemUseOutOfBattle_CoinCase(u8 taskId)
|
|
|
|
{
|
2019-09-30 21:43:44 +02:00
|
|
|
ConvertIntToDecimalStringN(gStringVar1, GetCoins(), STR_CONV_MODE_LEFT_ALIGN, 4);
|
2018-01-28 04:58:44 +01:00
|
|
|
StringExpandPlaceholders(gStringVar4, gText_CoinCase);
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
if (!gTasks[taskId].tUsingRegisteredKeyItem)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2021-08-03 08:17:01 +02:00
|
|
|
DisplayItemMessage(taskId, 1, gStringVar4, CloseItemMessage);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
DisplayItemMessageOnField(taskId, gStringVar4, Task_CloseCantUseKeyItemMessage);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemUseOutOfBattle_PowderJar(u8 taskId)
|
|
|
|
{
|
2019-09-30 21:43:44 +02:00
|
|
|
ConvertIntToDecimalStringN(gStringVar1, GetBerryPowder(), STR_CONV_MODE_LEFT_ALIGN, 5);
|
2018-01-28 04:58:44 +01:00
|
|
|
StringExpandPlaceholders(gStringVar4, gText_PowderQty);
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
if (!gTasks[taskId].tUsingRegisteredKeyItem)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2021-08-03 08:17:01 +02:00
|
|
|
DisplayItemMessage(taskId, 1, gStringVar4, CloseItemMessage);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
DisplayItemMessageOnField(taskId, gStringVar4, Task_CloseCantUseKeyItemMessage);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-20 08:31:51 +02:00
|
|
|
void ItemUseOutOfBattle_Berry(u8 taskId)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2018-12-31 18:16:45 +01:00
|
|
|
if (IsPlayerFacingEmptyBerryTreePatch() == TRUE)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
sItemUseOnFieldCB = ItemUseOnFieldCB_Berry;
|
|
|
|
gFieldCallback = FieldCB_UseItemOnField;
|
2021-08-03 08:17:01 +02:00
|
|
|
gBagMenu->newScreenCallback = CB2_ReturnToField;
|
2019-12-22 01:01:38 +01:00
|
|
|
Task_FadeAndCloseBagMenu(taskId);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ItemId_GetFieldFunc(gSpecialVar_ItemId)(taskId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
static void ItemUseOnFieldCB_Berry(u8 taskId)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
|
|
|
RemoveBagItem(gSpecialVar_ItemId, 1);
|
|
|
|
ScriptContext2_Enable();
|
2019-10-20 08:31:51 +02:00
|
|
|
ScriptContext1_SetupScript(BerryTree_EventScript_ItemUsePlantBerry);
|
2018-01-28 04:58:44 +01:00
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemUseOutOfBattle_WailmerPail(u8 taskId)
|
|
|
|
{
|
2019-10-20 08:31:51 +02:00
|
|
|
if (TryToWaterSudowoodo() == TRUE)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
sItemUseOnFieldCB = ItemUseOnFieldCB_WailmerPailSudowoodo;
|
2018-01-28 04:58:44 +01:00
|
|
|
SetUpItemUseOnFieldCallback(taskId);
|
|
|
|
}
|
|
|
|
else if (TryToWaterBerryTree() == TRUE)
|
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
sItemUseOnFieldCB = ItemUseOnFieldCB_WailmerPailBerry;
|
2018-01-28 04:58:44 +01:00
|
|
|
SetUpItemUseOnFieldCallback(taskId);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
DisplayDadsAdviceCannotUseItemMessage(taskId, gTasks[taskId].tUsingRegisteredKeyItem);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
static void ItemUseOnFieldCB_WailmerPailBerry(u8 taskId)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
|
|
|
ScriptContext2_Enable();
|
2019-10-20 08:31:51 +02:00
|
|
|
ScriptContext1_SetupScript(BerryTree_EventScript_ItemUseWailmerPail);
|
2018-01-28 04:58:44 +01:00
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
static bool8 TryToWaterSudowoodo(void)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
Undo PokeCodec's PRs
This commit undoes most of PokeCodec's PRs after the debate in chat. Some
harmless or completely superseded PRs have been left alone, as there is not
much benefit in attempting to undo them.
Reverts #1104, #1108, #1115, #1118, #1119, #1124, #1126, #1127, #1132, #1136,
#1137, #1139, #1140, #1144, #1148, #1149, #1150, #1153, #1155, #1177, #1179,
#1180, #1181, #1182 and #1183.
2020-09-13 09:22:50 +02:00
|
|
|
u16 x, y;
|
2018-01-28 04:58:44 +01:00
|
|
|
u8 z;
|
|
|
|
u8 objId;
|
|
|
|
GetXYCoordsOneStepInFrontOfPlayer(&x, &y);
|
|
|
|
z = PlayerGetZCoord();
|
2019-11-21 04:55:44 +01:00
|
|
|
objId = GetObjectEventIdByXYZ(x, y, z);
|
2019-11-21 05:12:51 +01:00
|
|
|
if (objId == OBJECT_EVENTS_COUNT || gObjectEvents[objId].graphicsId != OBJ_EVENT_GFX_SUDOWOODO)
|
2018-01-28 04:58:44 +01:00
|
|
|
return FALSE;
|
|
|
|
else
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
static void ItemUseOnFieldCB_WailmerPailSudowoodo(u8 taskId)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
|
|
|
ScriptContext2_Enable();
|
2019-10-20 08:31:51 +02:00
|
|
|
ScriptContext1_SetupScript(BattleFrontier_OutsideEast_EventScript_WaterSudowoodo);
|
2018-01-28 04:58:44 +01:00
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemUseOutOfBattle_Medicine(u8 taskId)
|
|
|
|
{
|
2019-10-18 01:22:03 +02:00
|
|
|
gItemUseCB = ItemUseCB_Medicine;
|
2018-01-28 04:58:44 +01:00
|
|
|
SetUpItemUseCallback(taskId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemUseOutOfBattle_ReduceEV(u8 taskId)
|
|
|
|
{
|
2019-10-18 01:22:03 +02:00
|
|
|
gItemUseCB = ItemUseCB_ReduceEV;
|
2018-01-28 04:58:44 +01:00
|
|
|
SetUpItemUseCallback(taskId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemUseOutOfBattle_SacredAsh(u8 taskId)
|
|
|
|
{
|
2019-10-18 01:22:03 +02:00
|
|
|
gItemUseCB = ItemUseCB_SacredAsh;
|
2018-01-28 04:58:44 +01:00
|
|
|
SetUpItemUseCallback(taskId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemUseOutOfBattle_PPRecovery(u8 taskId)
|
|
|
|
{
|
2019-10-18 01:22:03 +02:00
|
|
|
gItemUseCB = ItemUseCB_PPRecovery;
|
2018-01-28 04:58:44 +01:00
|
|
|
SetUpItemUseCallback(taskId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemUseOutOfBattle_PPUp(u8 taskId)
|
|
|
|
{
|
2019-10-18 01:22:03 +02:00
|
|
|
gItemUseCB = ItemUseCB_PPUp;
|
2018-01-28 04:58:44 +01:00
|
|
|
SetUpItemUseCallback(taskId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemUseOutOfBattle_RareCandy(u8 taskId)
|
|
|
|
{
|
2019-10-18 01:22:03 +02:00
|
|
|
gItemUseCB = ItemUseCB_RareCandy;
|
2018-01-28 04:58:44 +01:00
|
|
|
SetUpItemUseCallback(taskId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemUseOutOfBattle_TMHM(u8 taskId)
|
|
|
|
{
|
2018-02-05 17:39:26 +01:00
|
|
|
if (gSpecialVar_ItemId >= ITEM_HM01_CUT)
|
2019-10-18 01:22:03 +02:00
|
|
|
DisplayItemMessage(taskId, 1, gText_BootedUpHM, BootUpSoundTMHM); // HM
|
2018-01-28 04:58:44 +01:00
|
|
|
else
|
2019-10-18 01:22:03 +02:00
|
|
|
DisplayItemMessage(taskId, 1, gText_BootedUpTM, BootUpSoundTMHM); // TM
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
|
2019-10-18 01:22:03 +02:00
|
|
|
static void BootUpSoundTMHM(u8 taskId)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
|
|
|
PlaySE(SE_PC_LOGIN);
|
2019-10-18 01:22:03 +02:00
|
|
|
gTasks[taskId].func = Task_ShowTMHMContainedMessage;
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
|
2019-10-18 01:22:03 +02:00
|
|
|
static void Task_ShowTMHMContainedMessage(u8 taskId)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2020-09-05 03:11:55 +02:00
|
|
|
if (JOY_NEW(A_BUTTON | B_BUTTON))
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
|
|
|
StringCopy(gStringVar1, gMoveNames[ItemIdToBattleMoveId(gSpecialVar_ItemId)]);
|
|
|
|
StringExpandPlaceholders(gStringVar4, gText_TMHMContainedVar1);
|
2019-10-18 01:22:03 +02:00
|
|
|
DisplayItemMessage(taskId, 1, gStringVar4, UseTMHMYesNo);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-18 01:22:03 +02:00
|
|
|
static void UseTMHMYesNo(u8 taskId)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2021-08-03 08:17:01 +02:00
|
|
|
BagMenu_YesNo(taskId, ITEMWIN_YESNO_HIGH, &sUseTMHMYesNoFuncTable);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
|
2019-10-18 01:22:03 +02:00
|
|
|
static void UseTMHM(u8 taskId)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2019-10-18 01:22:03 +02:00
|
|
|
gItemUseCB = ItemUseCB_TMHM;
|
2018-01-28 04:58:44 +01:00
|
|
|
SetUpItemUseCallback(taskId);
|
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
static void RemoveUsedItem(void)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
|
|
|
RemoveBagItem(gSpecialVar_ItemId, 1);
|
|
|
|
CopyItemName(gSpecialVar_ItemId, gStringVar2);
|
|
|
|
StringExpandPlaceholders(gStringVar4, gText_PlayerUsedVar2);
|
|
|
|
if (!InBattlePyramid())
|
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
UpdatePocketItemList(ItemId_GetPocket(gSpecialVar_ItemId));
|
2021-08-03 08:17:01 +02:00
|
|
|
UpdatePocketListPosition(ItemId_GetPocket(gSpecialVar_ItemId));
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-04-23 00:49:54 +02:00
|
|
|
UpdatePyramidBagList();
|
|
|
|
UpdatePyramidBagCursorPos();
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemUseOutOfBattle_Repel(u8 taskId)
|
|
|
|
{
|
|
|
|
if (VarGet(VAR_REPEL_STEP_COUNT) == 0)
|
2019-12-22 01:01:38 +01:00
|
|
|
gTasks[taskId].func = Task_StartUseRepel;
|
2018-01-28 04:58:44 +01:00
|
|
|
else if (!InBattlePyramid())
|
2021-08-03 08:17:01 +02:00
|
|
|
DisplayItemMessage(taskId, 1, gText_RepelEffectsLingered, CloseItemMessage);
|
2018-01-28 04:58:44 +01:00
|
|
|
else
|
2019-12-22 01:01:38 +01:00
|
|
|
DisplayItemMessageInBattlePyramid(taskId, gText_RepelEffectsLingered, Task_CloseBattlePyramidBagMessage);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
static void Task_StartUseRepel(u8 taskId)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
|
|
|
s16* data = gTasks[taskId].data;
|
2018-02-05 17:39:26 +01:00
|
|
|
|
2018-01-28 04:58:44 +01:00
|
|
|
if (++data[8] > 7)
|
|
|
|
{
|
|
|
|
data[8] = 0;
|
2020-08-21 00:02:00 +02:00
|
|
|
PlaySE(SE_REPEL);
|
2019-12-22 01:01:38 +01:00
|
|
|
gTasks[taskId].func = Task_UseRepel;
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
static void Task_UseRepel(u8 taskId)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
|
|
|
if (!IsSEPlaying())
|
|
|
|
{
|
|
|
|
VarSet(VAR_REPEL_STEP_COUNT, ItemId_GetHoldEffectParam(gSpecialVar_ItemId));
|
2019-12-22 01:01:38 +01:00
|
|
|
RemoveUsedItem();
|
2018-01-28 04:58:44 +01:00
|
|
|
if (!InBattlePyramid())
|
2021-08-03 08:17:01 +02:00
|
|
|
DisplayItemMessage(taskId, 1, gStringVar4, CloseItemMessage);
|
2018-01-28 04:58:44 +01:00
|
|
|
else
|
2019-12-22 01:01:38 +01:00
|
|
|
DisplayItemMessageInBattlePyramid(taskId, gStringVar4, Task_CloseBattlePyramidBagMessage);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
static void Task_UsedBlackWhiteFlute(u8 taskId)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
|
|
|
if(++gTasks[taskId].data[8] > 7)
|
|
|
|
{
|
2020-08-21 00:02:00 +02:00
|
|
|
PlaySE(SE_GLASS_FLUTE);
|
2018-01-28 04:58:44 +01:00
|
|
|
if (!InBattlePyramid())
|
2021-08-03 08:17:01 +02:00
|
|
|
DisplayItemMessage(taskId, 1, gStringVar4, CloseItemMessage);
|
2018-01-28 04:58:44 +01:00
|
|
|
else
|
2019-12-22 01:01:38 +01:00
|
|
|
DisplayItemMessageInBattlePyramid(taskId, gStringVar4, Task_CloseBattlePyramidBagMessage);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemUseOutOfBattle_BlackWhiteFlute(u8 taskId)
|
|
|
|
{
|
|
|
|
CopyItemName(gSpecialVar_ItemId, gStringVar2);
|
|
|
|
if (gSpecialVar_ItemId == ITEM_WHITE_FLUTE)
|
|
|
|
{
|
|
|
|
FlagSet(FLAG_SYS_ENC_UP_ITEM);
|
|
|
|
FlagClear(FLAG_SYS_ENC_DOWN_ITEM);
|
|
|
|
StringExpandPlaceholders(gStringVar4, gText_UsedVar2WildLured);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FlagSet(FLAG_SYS_ENC_DOWN_ITEM);
|
|
|
|
FlagClear(FLAG_SYS_ENC_UP_ITEM);
|
|
|
|
StringExpandPlaceholders(gStringVar4, gText_UsedVar2WildRepelled);
|
|
|
|
}
|
|
|
|
gTasks[taskId].data[8] = 0;
|
2019-12-22 01:01:38 +01:00
|
|
|
gTasks[taskId].func = Task_UsedBlackWhiteFlute;
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
void Task_UseDigEscapeRopeOnField(u8 taskId)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2018-09-05 00:31:37 +02:00
|
|
|
ResetInitialPlayerAvatarState();
|
2018-10-17 02:11:44 +02:00
|
|
|
StartEscapeRopeFieldEffect();
|
2018-01-28 04:58:44 +01:00
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
static void ItemUseOnFieldCB_EscapeRope(u8 taskId)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2018-02-12 15:01:43 +01:00
|
|
|
Overworld_ResetStateAfterDigEscRope();
|
2019-12-22 01:01:38 +01:00
|
|
|
RemoveUsedItem();
|
2018-01-28 04:58:44 +01:00
|
|
|
gTasks[taskId].data[0] = 0;
|
2019-12-22 01:01:38 +01:00
|
|
|
DisplayItemMessageOnField(taskId, gStringVar4, Task_UseDigEscapeRopeOnField);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
|
2020-03-11 04:13:27 +01:00
|
|
|
bool8 CanUseDigOrEscapeRopeOnCurMap(void)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2021-06-13 23:32:00 +02:00
|
|
|
if (gMapHeader.allowEscaping)
|
2018-01-28 04:58:44 +01:00
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemUseOutOfBattle_EscapeRope(u8 taskId)
|
|
|
|
{
|
2020-03-11 04:13:27 +01:00
|
|
|
if (CanUseDigOrEscapeRopeOnCurMap() == TRUE)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
sItemUseOnFieldCB = ItemUseOnFieldCB_EscapeRope;
|
2018-01-28 04:58:44 +01:00
|
|
|
SetUpItemUseOnFieldCallback(taskId);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
DisplayDadsAdviceCannotUseItemMessage(taskId, gTasks[taskId].tUsingRegisteredKeyItem);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemUseOutOfBattle_EvolutionStone(u8 taskId)
|
|
|
|
{
|
2019-10-18 01:22:03 +02:00
|
|
|
gItemUseCB = ItemUseCB_EvolutionStone;
|
2018-01-28 04:58:44 +01:00
|
|
|
SetUpItemUseCallback(taskId);
|
|
|
|
}
|
|
|
|
|
2021-06-25 21:37:59 +02:00
|
|
|
u32 CanThrowBall(void)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2018-10-14 22:37:07 +02:00
|
|
|
if (IsBattlerAlive(GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT))
|
2021-06-25 21:37:59 +02:00
|
|
|
&& IsBattlerAlive(GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT)))
|
2018-10-14 22:37:07 +02:00
|
|
|
{
|
2021-06-25 21:37:59 +02:00
|
|
|
return 1; // There are two present pokemon.
|
2018-10-14 22:37:07 +02:00
|
|
|
}
|
2021-06-25 21:37:59 +02:00
|
|
|
else if (IsPlayerPartyAndPokemonStorageFull() == TRUE)
|
|
|
|
{
|
2021-09-01 13:37:39 +02:00
|
|
|
return 2; // No room for mon
|
2021-06-25 21:37:59 +02:00
|
|
|
}
|
2021-10-15 20:57:26 +02:00
|
|
|
#if B_SEMI_INVULNERABLE_CATCH >= GEN_4
|
|
|
|
else if (gStatuses3[GetCatchingBattler()] & STATUS3_SEMI_INVULNERABLE)
|
2021-10-15 15:20:32 +02:00
|
|
|
{
|
|
|
|
return 3; // in semi-invulnerable state
|
|
|
|
}
|
|
|
|
#endif
|
2021-06-25 21:37:59 +02:00
|
|
|
|
|
|
|
return 0; // usable
|
|
|
|
}
|
|
|
|
|
2021-10-15 15:20:32 +02:00
|
|
|
static const u8 sText_CantThrowPokeBall_TwoMons[] = _("Cannot throw a ball!\nThere are two Pokémon out there!\p");
|
|
|
|
static const u8 sText_CantThrowPokeBall_SemiInvulnerable[] = _("Cannot throw a ball!\nThere's no Pokémon in sight!\p");
|
2021-06-25 21:37:59 +02:00
|
|
|
void ItemUseInBattle_PokeBall(u8 taskId)
|
|
|
|
{
|
|
|
|
switch (CanThrowBall())
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2021-06-25 21:37:59 +02:00
|
|
|
case 0: // usable
|
|
|
|
default:
|
2018-01-28 04:58:44 +01:00
|
|
|
RemoveBagItem(gSpecialVar_ItemId, 1);
|
|
|
|
if (!InBattlePyramid())
|
2019-12-22 01:01:38 +01:00
|
|
|
Task_FadeAndCloseBagMenu(taskId);
|
2018-01-28 04:58:44 +01:00
|
|
|
else
|
2021-04-23 00:49:54 +02:00
|
|
|
CloseBattlePyramidBag(taskId);
|
2021-06-25 21:37:59 +02:00
|
|
|
break;
|
|
|
|
case 1: // There are two present pokemon.
|
|
|
|
if (!InBattlePyramid())
|
2021-09-01 13:45:41 +02:00
|
|
|
DisplayItemMessage(taskId, 1, sText_CantThrowPokeBall_TwoMons, CloseItemMessage);
|
2021-06-25 21:37:59 +02:00
|
|
|
else
|
|
|
|
DisplayItemMessageInBattlePyramid(taskId, sText_CantThrowPokeBall_TwoMons, Task_CloseBattlePyramidBagMessage);
|
|
|
|
break;
|
2021-09-01 13:37:39 +02:00
|
|
|
case 2: // No room for mon
|
2019-12-30 18:52:23 +01:00
|
|
|
if (!InBattlePyramid())
|
2021-08-17 00:43:27 +02:00
|
|
|
DisplayItemMessage(taskId, 1, gText_BoxFull, CloseItemMessage);
|
2019-12-30 18:52:23 +01:00
|
|
|
else
|
|
|
|
DisplayItemMessageInBattlePyramid(taskId, gText_BoxFull, Task_CloseBattlePyramidBagMessage);
|
2021-06-25 21:37:59 +02:00
|
|
|
break;
|
2021-10-15 20:57:26 +02:00
|
|
|
#if B_SEMI_INVULNERABLE_CATCH >= GEN_4
|
2021-10-15 15:20:32 +02:00
|
|
|
case 3: // Semi-Invulnerable
|
|
|
|
if (!InBattlePyramid())
|
|
|
|
DisplayItemMessage(taskId, 1, sText_CantThrowPokeBall_SemiInvulnerable, CloseItemMessage);
|
|
|
|
else
|
|
|
|
DisplayItemMessageInBattlePyramid(taskId, sText_CantThrowPokeBall_SemiInvulnerable, Task_CloseBattlePyramidBagMessage);
|
|
|
|
break;
|
|
|
|
#endif
|
2018-10-14 22:37:07 +02:00
|
|
|
}
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
static void Task_CloseStatIncreaseMessage(u8 taskId)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2020-09-05 03:11:55 +02:00
|
|
|
if (JOY_NEW(A_BUTTON | B_BUTTON))
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
|
|
|
if (!InBattlePyramid())
|
2019-12-22 01:01:38 +01:00
|
|
|
Task_FadeAndCloseBagMenu(taskId);
|
2018-01-28 04:58:44 +01:00
|
|
|
else
|
2021-04-23 00:49:54 +02:00
|
|
|
CloseBattlePyramidBag(taskId);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
static void Task_UseStatIncreaseItem(u8 taskId)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
|
|
|
if(++gTasks[taskId].data[8] > 7)
|
|
|
|
{
|
2020-08-21 00:02:00 +02:00
|
|
|
PlaySE(SE_USE_ITEM);
|
2018-01-28 04:58:44 +01:00
|
|
|
RemoveBagItem(gSpecialVar_ItemId, 1);
|
|
|
|
if (!InBattlePyramid())
|
2019-12-22 01:01:38 +01:00
|
|
|
DisplayItemMessage(taskId, 1, UseStatIncreaseItem(gSpecialVar_ItemId), Task_CloseStatIncreaseMessage);
|
2018-01-28 04:58:44 +01:00
|
|
|
else
|
2019-12-22 01:01:38 +01:00
|
|
|
DisplayItemMessageInBattlePyramid(taskId, UseStatIncreaseItem(gSpecialVar_ItemId), Task_CloseStatIncreaseMessage);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
// e.g. X Attack, Guard Spec
|
2018-01-28 04:58:44 +01:00
|
|
|
void ItemUseInBattle_StatIncrease(u8 taskId)
|
|
|
|
{
|
2018-02-07 22:53:40 +01:00
|
|
|
u16 partyId = gBattlerPartyIndexes[gBattlerInMenuId];
|
2018-01-28 04:58:44 +01:00
|
|
|
|
2018-02-11 17:35:01 +01:00
|
|
|
if (ExecuteTableBasedItemEffect(&gPlayerParty[partyId], gSpecialVar_ItemId, partyId, 0) != FALSE)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
|
|
|
if (!InBattlePyramid())
|
2021-08-03 08:17:01 +02:00
|
|
|
DisplayItemMessage(taskId, 1, gText_WontHaveEffect, CloseItemMessage);
|
2018-01-28 04:58:44 +01:00
|
|
|
else
|
2019-12-22 01:01:38 +01:00
|
|
|
DisplayItemMessageInBattlePyramid(taskId, gText_WontHaveEffect, Task_CloseBattlePyramidBagMessage);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
gTasks[taskId].func = Task_UseStatIncreaseItem;
|
2018-01-28 04:58:44 +01:00
|
|
|
gTasks[taskId].data[8] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-18 01:22:03 +02:00
|
|
|
static void ItemUseInBattle_ShowPartyMenu(u8 taskId)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
|
|
|
if (!InBattlePyramid())
|
|
|
|
{
|
2021-08-03 08:17:01 +02:00
|
|
|
gBagMenu->newScreenCallback = ChooseMonForInBattleItem;
|
2019-12-22 01:01:38 +01:00
|
|
|
Task_FadeAndCloseBagMenu(taskId);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-03 08:17:01 +02:00
|
|
|
gPyramidBagMenu->newScreenCallback = ChooseMonForInBattleItem;
|
2021-04-23 00:49:54 +02:00
|
|
|
CloseBattlePyramidBag(taskId);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemUseInBattle_Medicine(u8 taskId)
|
|
|
|
{
|
2019-10-18 01:22:03 +02:00
|
|
|
gItemUseCB = ItemUseCB_Medicine;
|
|
|
|
ItemUseInBattle_ShowPartyMenu(taskId);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
|
2019-10-18 01:22:03 +02:00
|
|
|
// Unused. Sacred Ash cannot be used in battle
|
|
|
|
void ItemUseInBattle_SacredAsh(u8 taskId)
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2019-10-18 01:22:03 +02:00
|
|
|
gItemUseCB = ItemUseCB_SacredAsh;
|
|
|
|
ItemUseInBattle_ShowPartyMenu(taskId);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ItemUseInBattle_PPRecovery(u8 taskId)
|
|
|
|
{
|
2019-10-18 01:22:03 +02:00
|
|
|
gItemUseCB = ItemUseCB_PPRecovery;
|
|
|
|
ItemUseInBattle_ShowPartyMenu(taskId);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
// Fluffy Tail / Poke Doll
|
2018-01-28 04:58:44 +01:00
|
|
|
void ItemUseInBattle_Escape(u8 taskId)
|
|
|
|
{
|
|
|
|
|
|
|
|
if((gBattleTypeFlags & BATTLE_TYPE_TRAINER) == FALSE)
|
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
RemoveUsedItem();
|
2018-01-28 04:58:44 +01:00
|
|
|
if (!InBattlePyramid())
|
2019-12-22 01:01:38 +01:00
|
|
|
DisplayItemMessage(taskId, 1, gStringVar4, Task_FadeAndCloseBagMenu);
|
2018-01-28 04:58:44 +01:00
|
|
|
else
|
2021-04-23 00:49:54 +02:00
|
|
|
DisplayItemMessageInBattlePyramid(taskId, gStringVar4, CloseBattlePyramidBag);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
DisplayDadsAdviceCannotUseItemMessage(taskId, gTasks[taskId].tUsingRegisteredKeyItem);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemUseOutOfBattle_EnigmaBerry(u8 taskId)
|
|
|
|
{
|
2019-04-14 17:20:26 +02:00
|
|
|
switch (GetItemEffectType(gSpecialVar_ItemId))
|
2018-01-28 04:58:44 +01:00
|
|
|
{
|
2019-04-14 17:20:26 +02:00
|
|
|
case ITEM_EFFECT_HEAL_HP:
|
|
|
|
case ITEM_EFFECT_CURE_POISON:
|
|
|
|
case ITEM_EFFECT_CURE_SLEEP:
|
|
|
|
case ITEM_EFFECT_CURE_BURN:
|
|
|
|
case ITEM_EFFECT_CURE_FREEZE:
|
|
|
|
case ITEM_EFFECT_CURE_PARALYSIS:
|
|
|
|
case ITEM_EFFECT_CURE_ALL_STATUS:
|
|
|
|
case ITEM_EFFECT_ATK_EV:
|
|
|
|
case ITEM_EFFECT_HP_EV:
|
|
|
|
case ITEM_EFFECT_SPATK_EV:
|
|
|
|
case ITEM_EFFECT_SPDEF_EV:
|
|
|
|
case ITEM_EFFECT_SPEED_EV:
|
|
|
|
case ITEM_EFFECT_DEF_EV:
|
2021-01-19 11:49:20 +01:00
|
|
|
gTasks[taskId].tEnigmaBerryType = ITEM_USE_PARTY_MENU;
|
2018-01-28 04:58:44 +01:00
|
|
|
ItemUseOutOfBattle_Medicine(taskId);
|
|
|
|
break;
|
2019-04-14 17:20:26 +02:00
|
|
|
case ITEM_EFFECT_SACRED_ASH:
|
2021-01-19 11:49:20 +01:00
|
|
|
gTasks[taskId].tEnigmaBerryType = ITEM_USE_PARTY_MENU;
|
2018-01-28 04:58:44 +01:00
|
|
|
ItemUseOutOfBattle_SacredAsh(taskId);
|
|
|
|
break;
|
2019-04-14 17:20:26 +02:00
|
|
|
case ITEM_EFFECT_RAISE_LEVEL:
|
2021-01-19 11:49:20 +01:00
|
|
|
gTasks[taskId].tEnigmaBerryType = ITEM_USE_PARTY_MENU;
|
2018-01-28 04:58:44 +01:00
|
|
|
ItemUseOutOfBattle_RareCandy(taskId);
|
|
|
|
break;
|
2019-04-14 17:20:26 +02:00
|
|
|
case ITEM_EFFECT_PP_UP:
|
|
|
|
case ITEM_EFFECT_PP_MAX:
|
2021-01-19 11:49:20 +01:00
|
|
|
gTasks[taskId].tEnigmaBerryType = ITEM_USE_PARTY_MENU;
|
2018-01-28 04:58:44 +01:00
|
|
|
ItemUseOutOfBattle_PPUp(taskId);
|
|
|
|
break;
|
2019-04-14 17:20:26 +02:00
|
|
|
case ITEM_EFFECT_HEAL_PP:
|
2021-01-19 11:49:20 +01:00
|
|
|
gTasks[taskId].tEnigmaBerryType = ITEM_USE_PARTY_MENU;
|
2018-01-28 04:58:44 +01:00
|
|
|
ItemUseOutOfBattle_PPRecovery(taskId);
|
|
|
|
break;
|
|
|
|
default:
|
2021-01-19 11:49:20 +01:00
|
|
|
gTasks[taskId].tEnigmaBerryType = ITEM_USE_BAG_MENU;
|
2018-01-28 04:58:44 +01:00
|
|
|
ItemUseOutOfBattle_CannotUse(taskId);
|
2019-04-14 17:20:26 +02:00
|
|
|
break;
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemUseInBattle_EnigmaBerry(u8 taskId)
|
|
|
|
{
|
|
|
|
switch (GetItemEffectType(gSpecialVar_ItemId))
|
|
|
|
{
|
2019-04-14 17:20:26 +02:00
|
|
|
case ITEM_EFFECT_X_ITEM:
|
2018-01-28 04:58:44 +01:00
|
|
|
ItemUseInBattle_StatIncrease(taskId);
|
|
|
|
break;
|
2019-04-14 17:20:26 +02:00
|
|
|
case ITEM_EFFECT_HEAL_HP:
|
|
|
|
case ITEM_EFFECT_CURE_POISON:
|
|
|
|
case ITEM_EFFECT_CURE_SLEEP:
|
|
|
|
case ITEM_EFFECT_CURE_BURN:
|
|
|
|
case ITEM_EFFECT_CURE_FREEZE:
|
|
|
|
case ITEM_EFFECT_CURE_PARALYSIS:
|
|
|
|
case ITEM_EFFECT_CURE_ALL_STATUS:
|
|
|
|
case ITEM_EFFECT_CURE_CONFUSION:
|
|
|
|
case ITEM_EFFECT_CURE_INFATUATION:
|
2018-01-28 04:58:44 +01:00
|
|
|
ItemUseInBattle_Medicine(taskId);
|
|
|
|
break;
|
2019-04-14 17:20:26 +02:00
|
|
|
case ITEM_EFFECT_HEAL_PP:
|
2018-01-28 04:58:44 +01:00
|
|
|
ItemUseInBattle_PPRecovery(taskId);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ItemUseOutOfBattle_CannotUse(taskId);
|
2019-04-14 17:20:26 +02:00
|
|
|
break;
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemUseOutOfBattle_CannotUse(u8 taskId)
|
|
|
|
{
|
2019-12-22 01:01:38 +01:00
|
|
|
DisplayDadsAdviceCannotUseItemMessage(taskId, gTasks[taskId].tUsingRegisteredKeyItem);
|
2018-01-28 04:58:44 +01:00
|
|
|
}
|
2019-03-25 22:49:29 +01:00
|
|
|
|
2019-12-22 01:01:38 +01:00
|
|
|
#undef tUsingRegisteredKeyItem
|