fix: consume a slot when item is crafted instead of bought via plat
All checks were successful
Build / build (18) (push) Successful in 50s
Build / build (20) (push) Successful in 1m6s
Build / build (22) (push) Successful in 1m24s
Build / build (18) (pull_request) Successful in 47s
Build / build (20) (pull_request) Successful in 1m4s
Build / build (22) (pull_request) Successful in 1m8s

This commit is contained in:
Sainan 2025-02-26 06:41:31 +01:00
parent 6a6e333011
commit 3a527e029d
2 changed files with 34 additions and 33 deletions

View File

@ -26,7 +26,8 @@ import {
ILibraryDailyTaskInfo, ILibraryDailyTaskInfo,
ICalendarProgress, ICalendarProgress,
IDroneClient, IDroneClient,
IUpgradeClient IUpgradeClient,
ISlots
} from "@/src/types/inventoryTypes/inventoryTypes"; } from "@/src/types/inventoryTypes/inventoryTypes";
import { IGenericUpdate } from "../types/genericUpdate"; import { IGenericUpdate } from "../types/genericUpdate";
import { import {
@ -159,10 +160,31 @@ export const getInventory = async (
return inventory; return inventory;
}; };
const occupySlot = (
inventory: TInventoryDatabaseDocument,
bin: InventorySlot,
premiumPurchase: boolean
): IInventoryChanges => {
const slotChanges = {
Slots: 0,
Extra: 0
};
if (premiumPurchase) {
slotChanges.Extra += 1;
} else {
slotChanges.Slots -= 1;
}
updateSlots(inventory, bin, slotChanges.Slots, slotChanges.Extra);
return {
[bin]: slotChanges satisfies ISlots
};
};
export const addItem = async ( export const addItem = async (
inventory: TInventoryDatabaseDocument, inventory: TInventoryDatabaseDocument,
typeName: string, typeName: string,
quantity: number = 1 quantity: number = 1,
premiumPurchase: boolean = false
): Promise<{ InventoryChanges: IInventoryChanges }> => { ): Promise<{ InventoryChanges: IInventoryChanges }> => {
// Bundles are technically StoreItems but a) they don't have a normal counterpart, and b) they are used in non-StoreItem contexts, e.g. email attachments. // Bundles are technically StoreItems but a) they don't have a normal counterpart, and b) they are used in non-StoreItem contexts, e.g. email attachments.
if (typeName in ExportBundles) { if (typeName in ExportBundles) {
@ -305,11 +327,10 @@ export const addItem = async (
combineInventoryChanges(inventoryChanges, await addItem(inventory, item, 1)); combineInventoryChanges(inventoryChanges, await addItem(inventory, item, 1));
} }
} }
updateSlots(inventory, InventorySlot.WEAPONS, 0, 1);
return { return {
InventoryChanges: { InventoryChanges: {
...inventoryChanges, ...inventoryChanges,
WeaponBin: { count: 1, platinum: 0, Slots: -1 } ...occupySlot(inventory, InventorySlot.WEAPONS, premiumPurchase)
} }
}; };
} else { } else {
@ -378,44 +399,26 @@ export const addItem = async (
case "Powersuits": case "Powersuits":
switch (typeName.substr(1).split("/")[2]) { switch (typeName.substr(1).split("/")[2]) {
default: { default: {
const inventoryChanges = addPowerSuit(inventory, typeName);
updateSlots(inventory, InventorySlot.SUITS, 0, 1);
return { return {
InventoryChanges: { InventoryChanges: {
...inventoryChanges, ...addPowerSuit(inventory, typeName),
SuitBin: { ...occupySlot(inventory, InventorySlot.SUITS, premiumPurchase)
count: 1,
platinum: 0,
Slots: -1
}
} }
}; };
} }
case "Archwing": { case "Archwing": {
const inventoryChanges = addSpaceSuit(inventory, typeName);
updateSlots(inventory, InventorySlot.SPACESUITS, 0, 1);
return { return {
InventoryChanges: { InventoryChanges: {
...inventoryChanges, ...addSpaceSuit(inventory, typeName),
SpaceSuitBin: { ...occupySlot(inventory, InventorySlot.SPACESUITS, premiumPurchase)
count: 1,
platinum: 0,
Slots: -1
}
} }
}; };
} }
case "EntratiMech": { case "EntratiMech": {
const inventoryChanges = addMechSuit(inventory, typeName);
updateSlots(inventory, InventorySlot.MECHSUITS, 0, 1);
return { return {
InventoryChanges: { InventoryChanges: {
...inventoryChanges, ...addMechSuit(inventory, typeName),
MechBin: { ...occupySlot(inventory, InventorySlot.MECHSUITS, premiumPurchase)
count: 1,
platinum: 0,
Slots: -1
}
} }
}; };
} }
@ -446,12 +449,10 @@ export const addItem = async (
case "Types": case "Types":
switch (typeName.substr(1).split("/")[2]) { switch (typeName.substr(1).split("/")[2]) {
case "Sentinels": { case "Sentinels": {
const inventoryChanges = addSentinel(inventory, typeName);
updateSlots(inventory, InventorySlot.SENTINELS, 0, 1);
return { return {
InventoryChanges: { InventoryChanges: {
...inventoryChanges, ...addSentinel(inventory, typeName),
SentinelBin: { count: 1, platinum: 0, Slots: -1 } ...occupySlot(inventory, InventorySlot.SENTINELS, premiumPurchase)
} }
}; };
} }

View File

@ -251,7 +251,7 @@ export const handleStoreItemAcquisition = async (
} }
switch (storeCategory) { switch (storeCategory) {
default: { default: {
purchaseResponse = await addItem(inventory, internalName, quantity); purchaseResponse = await addItem(inventory, internalName, quantity, true);
break; break;
} }
case "Types": case "Types":