Fix tossing items applying to the wrong stack (#8282)

This commit is contained in:
FosterProgramming 2025-11-22 07:13:15 +01:00 committed by GitHub
parent 8ba99b09d7
commit 29ac028c9e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 34 additions and 2 deletions

View File

@ -215,6 +215,7 @@ bool32 CheckBagHasSpace(u16 itemId, u16 count);
u32 GetFreeSpaceForItemInBag(u16 itemId);
bool32 AddBagItem(u16 itemId, u16 count);
bool32 RemoveBagItem(u16 itemId, u16 count);
void RemoveBagItemFromSlot(struct BagPocket *pocket, u16 slotId, u16 count);
u8 CountUsedPCItemSlots(void);
bool32 CheckPCHasItem(u16 itemId, u16 count);
bool32 AddPCItem(u16 itemId, u16 count);

View File

@ -411,6 +411,13 @@ bool32 RemoveBagItem(u16 itemId, u16 count)
return BagPocket_RemoveItem(&gBagPockets[GetItemPocket(itemId)], itemId, count);
}
// Unsafe function: Only use with functions that already check the slot and count are valid
void RemoveBagItemFromSlot(struct BagPocket *pocket, u16 slotId, u16 count)
{
struct ItemSlot itemSlot = BagPocket_GetSlotData(pocket, slotId);
BagPocket_SetSlotItemIdAndCount(pocket, slotId, itemSlot.itemId, itemSlot.quantity - count);
}
static u8 NONNULL BagPocket_CountUsedItemSlots(struct BagPocket *pocket)
{
u8 usedSlots = 0;

View File

@ -170,6 +170,7 @@ static void PrintThereIsNoPokemon(u8);
static void Task_ChooseHowManyToToss(u8);
static void AskTossItems(u8);
static void Task_RemoveItemFromBag(u8);
static void Task_TossItemFromBag(u8 taskId);
static void ItemMenu_Cancel(u8);
static void HandleErrorMessage(u8);
static void PrintItemCantBeHeld(u8);
@ -1958,11 +1959,34 @@ static void ConfirmToss(u8 taskId)
StringExpandPlaceholders(gStringVar4, gText_ThrewAwayVar2Var1s);
FillWindowPixelBuffer(WIN_DESCRIPTION, PIXEL_FILL(0));
BagMenu_Print(WIN_DESCRIPTION, FONT_NORMAL, gStringVar4, 3, 1, 0, 0, 0, COLORID_NORMAL);
gTasks[taskId].func = Task_RemoveItemFromBag;
if (CurrentBattlePyramidLocation() != PYRAMID_LOCATION_NONE || FlagGet(FLAG_STORING_ITEMS_IN_PYRAMID_BAG) == TRUE)
gTasks[taskId].func = Task_RemoveItemFromBag;
else
gTasks[taskId].func = Task_TossItemFromBag;
}
static void Task_TossItemFromBag(u8 taskId)
{
s16 *data = gTasks[taskId].data;
u16 *scrollPos = &gBagPosition.scrollPosition[gBagPosition.pocket];
u16 *cursorPos = &gBagPosition.cursorPosition[gBagPosition.pocket];
if (JOY_NEW(A_BUTTON | B_BUTTON))
{
PlaySE(SE_SELECT);
RemoveBagItemFromSlot(&gBagPockets[gBagPosition.pocket], *scrollPos + *cursorPos, tItemCount);
DestroyListMenuTask(tListTaskId, scrollPos, cursorPos);
UpdatePocketItemList(gBagPosition.pocket);
UpdatePocketListPosition(gBagPosition.pocket);
LoadBagItemListBuffers(gBagPosition.pocket);
tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, *scrollPos, *cursorPos);
ScheduleBgCopyTilemapToVram(0);
ReturnToItemList(taskId);
}
}
// Remove selected item(s) from the bag and update list
// For when items are tossed or deposited
// For when items are deposited
static void Task_RemoveItemFromBag(u8 taskId)
{
s16 *data = gTasks[taskId].data;