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,
ICalendarProgress,
IDroneClient,
IUpgradeClient
IUpgradeClient,
ISlots
} from "@/src/types/inventoryTypes/inventoryTypes";
import { IGenericUpdate } from "../types/genericUpdate";
import {
@ -159,10 +160,31 @@ export const getInventory = async (
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 (
inventory: TInventoryDatabaseDocument,
typeName: string,
quantity: number = 1
quantity: number = 1,
premiumPurchase: boolean = false
): 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.
if (typeName in ExportBundles) {
@ -305,11 +327,10 @@ export const addItem = async (
combineInventoryChanges(inventoryChanges, await addItem(inventory, item, 1));
}
}
updateSlots(inventory, InventorySlot.WEAPONS, 0, 1);
return {
InventoryChanges: {
...inventoryChanges,
WeaponBin: { count: 1, platinum: 0, Slots: -1 }
...occupySlot(inventory, InventorySlot.WEAPONS, premiumPurchase)
}
};
} else {
@ -378,44 +399,26 @@ export const addItem = async (
case "Powersuits":
switch (typeName.substr(1).split("/")[2]) {
default: {
const inventoryChanges = addPowerSuit(inventory, typeName);
updateSlots(inventory, InventorySlot.SUITS, 0, 1);
return {
InventoryChanges: {
...inventoryChanges,
SuitBin: {
count: 1,
platinum: 0,
Slots: -1
}
...addPowerSuit(inventory, typeName),
...occupySlot(inventory, InventorySlot.SUITS, premiumPurchase)
}
};
}
case "Archwing": {
const inventoryChanges = addSpaceSuit(inventory, typeName);
updateSlots(inventory, InventorySlot.SPACESUITS, 0, 1);
return {
InventoryChanges: {
...inventoryChanges,
SpaceSuitBin: {
count: 1,
platinum: 0,
Slots: -1
}
...addSpaceSuit(inventory, typeName),
...occupySlot(inventory, InventorySlot.SPACESUITS, premiumPurchase)
}
};
}
case "EntratiMech": {
const inventoryChanges = addMechSuit(inventory, typeName);
updateSlots(inventory, InventorySlot.MECHSUITS, 0, 1);
return {
InventoryChanges: {
...inventoryChanges,
MechBin: {
count: 1,
platinum: 0,
Slots: -1
}
...addMechSuit(inventory, typeName),
...occupySlot(inventory, InventorySlot.MECHSUITS, premiumPurchase)
}
};
}
@ -446,12 +449,10 @@ export const addItem = async (
case "Types":
switch (typeName.substr(1).split("/")[2]) {
case "Sentinels": {
const inventoryChanges = addSentinel(inventory, typeName);
updateSlots(inventory, InventorySlot.SENTINELS, 0, 1);
return {
InventoryChanges: {
...inventoryChanges,
SentinelBin: { count: 1, platinum: 0, Slots: -1 }
...addSentinel(inventory, typeName),
...occupySlot(inventory, InventorySlot.SENTINELS, premiumPurchase)
}
};
}

View File

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