Fix sell price display (#7123)

This commit is contained in:
cawtds 2025-06-15 11:52:51 +02:00 committed by GitHub
parent 459946ac9a
commit 3491cd95e8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 7 deletions

View File

@ -22,4 +22,6 @@
#define LURE_STEP_COUNT (IS_LAST_USED_LURE(VarGet(VAR_REPEL_STEP_COUNT)) ? REPEL_LURE_STEPS(VarGet(VAR_REPEL_STEP_COUNT)) : 0)
#define REPEL_STEP_COUNT (!IS_LAST_USED_LURE(VarGet(VAR_REPEL_STEP_COUNT)) ? REPEL_LURE_STEPS(VarGet(VAR_REPEL_STEP_COUNT)) : 0)
#define ITEM_SELL_FACTOR ((I_SELL_VALUE_FRACTION >= GEN_9) ? 4 : 2)
#endif // GUARD_ITEM_CONSTANTS_H

View File

@ -84,6 +84,7 @@ u32 GetItemSecondaryId(u32 itemId);
u32 GetItemFlingPower(u32 itemId);
u32 GetItemStatus1Mask(u16 itemId);
u32 GetItemStatus2Mask(u16 itemId);
u32 GetItemSellPrice(u32 itemId);
/* Expands to:
* enum

View File

@ -1013,3 +1013,8 @@ u32 GetItemStatus2Mask(u16 itemId)
else
return 0;
}
u32 GetItemSellPrice(u32 itemId)
{
return GetItemPrice(itemId) / ITEM_SELL_FACTOR;
}

View File

@ -2122,6 +2122,11 @@ static void Task_ItemContext_Sell(u8 taskId)
}
else
{
u32 maxQuantity = MAX_MONEY / GetItemSellPrice(gSpecialVar_ItemId);
if (tQuantity > maxQuantity)
tQuantity = maxQuantity;
CopyItemName(gSpecialVar_ItemId, gStringVar2);
StringExpandPlaceholders(gStringVar4, gText_HowManyToSell);
DisplayItemMessage(taskId, FONT_NORMAL, gStringVar4, InitSellHowManyInput);
@ -2129,13 +2134,11 @@ static void Task_ItemContext_Sell(u8 taskId)
}
}
#define ITEM_SELL_FACTOR ((I_SELL_VALUE_FRACTION >= GEN_9) ? 4 : 2)
static void DisplaySellItemPriceAndConfirm(u8 taskId)
{
s16 *data = gTasks[taskId].data;
ConvertIntToDecimalStringN(gStringVar1, (GetItemPrice(gSpecialVar_ItemId) / ITEM_SELL_FACTOR) * tItemCount, STR_CONV_MODE_LEFT_ALIGN, MAX_MONEY_DIGITS);
ConvertIntToDecimalStringN(gStringVar1, GetItemSellPrice(gSpecialVar_ItemId) * tItemCount, STR_CONV_MODE_LEFT_ALIGN, MAX_MONEY_DIGITS);
StringExpandPlaceholders(gStringVar4, gText_ICanPayVar1);
DisplayItemMessage(taskId, FONT_NORMAL, gStringVar4, AskSellItems);
}
@ -2160,7 +2163,7 @@ static void InitSellHowManyInput(u8 taskId)
s16 *data = gTasks[taskId].data;
u8 windowId = BagMenu_AddWindow(ITEMWIN_QUANTITY_WIDE);
PrintItemSoldAmount(windowId, 1, (GetItemPrice(gSpecialVar_ItemId) / ITEM_SELL_FACTOR) * tItemCount);
PrintItemSoldAmount(windowId, 1, GetItemSellPrice(gSpecialVar_ItemId) * tItemCount);
DisplayCurrentMoneyWindow();
gTasks[taskId].func = Task_ChooseHowManyToSell;
}
@ -2171,7 +2174,7 @@ static void Task_ChooseHowManyToSell(u8 taskId)
if (AdjustQuantityAccordingToDPadInput(&tItemCount, tQuantity) == TRUE)
{
PrintItemSoldAmount(gBagMenu->windowIds[ITEMWIN_QUANTITY_WIDE], tItemCount, (GetItemPrice(gSpecialVar_ItemId) / ITEM_SELL_FACTOR) * tItemCount);
PrintItemSoldAmount(gBagMenu->windowIds[ITEMWIN_QUANTITY_WIDE], tItemCount, GetItemSellPrice(gSpecialVar_ItemId) * tItemCount);
}
else if (JOY_NEW(A_BUTTON))
{
@ -2195,7 +2198,7 @@ static void ConfirmSell(u8 taskId)
s16 *data = gTasks[taskId].data;
CopyItemName(gSpecialVar_ItemId, gStringVar2);
ConvertIntToDecimalStringN(gStringVar1, (GetItemPrice(gSpecialVar_ItemId) / ITEM_SELL_FACTOR) * tItemCount, STR_CONV_MODE_LEFT_ALIGN, MAX_MONEY_DIGITS);
ConvertIntToDecimalStringN(gStringVar1, GetItemSellPrice(gSpecialVar_ItemId) * tItemCount, STR_CONV_MODE_LEFT_ALIGN, MAX_MONEY_DIGITS);
StringExpandPlaceholders(gStringVar4, gText_TurnedOverVar1ForVar2);
DisplayItemMessage(taskId, FONT_NORMAL, gStringVar4, SellItem);
}
@ -2208,7 +2211,7 @@ static void SellItem(u8 taskId)
PlaySE(SE_SHOP);
RemoveBagItem(gSpecialVar_ItemId, tItemCount);
AddMoney(&gSaveBlock1Ptr->money, (GetItemPrice(gSpecialVar_ItemId) / ITEM_SELL_FACTOR) * tItemCount);
AddMoney(&gSaveBlock1Ptr->money, GetItemSellPrice(gSpecialVar_ItemId) * tItemCount);
DestroyListMenuTask(tListTaskId, scrollPos, cursorPos);
UpdatePocketItemList(gBagPosition.pocket);
UpdatePocketListPosition(gBagPosition.pocket);