diff --git a/src/app/(frontend)/locker/actions.ts b/src/app/(frontend)/locker/actions.ts index 726e2886..8c627d9e 100644 --- a/src/app/(frontend)/locker/actions.ts +++ b/src/app/(frontend)/locker/actions.ts @@ -1206,11 +1206,17 @@ export async function attachItemFromGrid( if (!weapon || typeof weapon === "number" || weapon.assetType !== "weapon") { return { success: false, error: "Attachments can only be installed on weapons." }; } + if (items[weaponIdx].quantity < 1) { + return { success: false, error: "That weapon is out of stock." }; + } const attachment = items[attIdx].asset as Asset; if (!attachment || typeof attachment === "number") { return { success: false, error: "Invalid item." }; } + if (items[attIdx].quantity < 1) { + return { success: false, error: "That attachment is out of stock." }; + } const category = ATTACHMENT_CATEGORIES.find((c) => c.assetType === attachment.assetType); if (!category) { diff --git a/src/collections/game/GameStructures.ts b/src/collections/game/GameStructures.ts index adadb50e..a80ebaa7 100644 --- a/src/collections/game/GameStructures.ts +++ b/src/collections/game/GameStructures.ts @@ -473,7 +473,7 @@ export const GameStructures: CollectionConfig = { name: "quantity", type: "number", required: true, - min: 1, + min: 0, defaultValue: 1, }, { diff --git a/src/collections/locker/LockerStorages.ts b/src/collections/locker/LockerStorages.ts index 878d56f3..fb4f4a32 100644 --- a/src/collections/locker/LockerStorages.ts +++ b/src/collections/locker/LockerStorages.ts @@ -77,7 +77,7 @@ export const LockerStorages: CollectionConfig = { name: "quantity", type: "number", required: true, - min: 1, + min: 0, defaultValue: 1, }, { diff --git a/src/collections/server/ArmaSyncEvents.ts b/src/collections/server/ArmaSyncEvents.ts index 03e0eefd..0fe48dee 100644 --- a/src/collections/server/ArmaSyncEvents.ts +++ b/src/collections/server/ArmaSyncEvents.ts @@ -7,6 +7,7 @@ import { processLockerEvent } from "@/lib/arma-bridge/lockers"; import { processGarageEvent } from "@/lib/arma-bridge/garages"; import { isOperationLedgerEnabled } from "@/lib/operations/rollout"; import { processOperationEvent } from "@/lib/operations/process"; +import { toRawSyncEvent } from "@/lib/operations/reconcile"; export const ArmaSyncEvents: CollectionConfig = { slug: "arma-sync-events", @@ -16,55 +17,60 @@ export const ArmaSyncEvents: CollectionConfig = { afterChange: [ async ({ doc, req, operation }) => { if (operation !== "create") return; + // Payload hands afterChange a doc whose relationship fields are + // populated at defaultDepth (an object, not the numeric FK). Every + // downstream processor expects `server` to be a number, so normalize + // once here; without this they all bail as "malformed". + const raw = toRawSyncEvent(doc as unknown as Record); // Ledger first: every raw event is consumed into the operation ledger // before any downstream projection runs. Evidence is always stored; // only derived effects are gated by the kill switch. if (isOperationLedgerEnabled()) { - await processOperationEvent(req.payload, doc, req); + await processOperationEvent(req.payload, raw, req); } - if (doc.type === "player.kill") { - processPlayerKill(req.payload, doc).catch((err) => { - req.payload.logger.error(`[KillTracker] Failed to process kill event ${doc.eventId}: ${err}`); + if (raw.type === "player.kill") { + processPlayerKill(req.payload, raw).catch((err) => { + req.payload.logger.error(`[KillTracker] Failed to process kill event ${raw.eventId}: ${err}`); }); } - if (doc.type.startsWith("box.")) { + if (raw.type.startsWith("box.")) { // Awaited (not fire-and-forget) so the crate writes join the raw-event // transaction; processBoxEvent never throws, so ingestion cannot be // rolled back by crate sync. try { - await processBoxEvent(req.payload, doc, req); + await processBoxEvent(req.payload, raw, req); } catch (err) { - req.payload.logger.error(`[CrateSync] Failed to process box event ${doc.eventId}: ${err}`); + req.payload.logger.error(`[CrateSync] Failed to process box event ${raw.eventId}: ${err}`); } } - if (doc.type === "money.delta") { + if (raw.type === "money.delta") { // Awaited so that by the time the game's flush returns, the bank // balance already reflects it (the game pulls balances right after // flushing). processMoneyEvent never throws. - await processMoneyEvent(req.payload, doc); + await processMoneyEvent(req.payload, raw); } - if (doc.type.startsWith("reinforcement.")) { + if (raw.type.startsWith("reinforcement.")) { // Awaited (same posture as money.delta): the pool balance must be // current before the game's next reinforcement pull, and // processReinforcementEvent never throws. - await processReinforcementEvent(req.payload, doc, req); + await processReinforcementEvent(req.payload, raw, req); } - if (doc.type.startsWith("locker.")) { + if (raw.type.startsWith("locker.")) { // Awaited (same posture as box.*): locker writes join the raw-event // transaction; processLockerEvent never throws. try { - await processLockerEvent(req.payload, doc, req); + await processLockerEvent(req.payload, raw, req); } catch (err) { - req.payload.logger.error(`[LockerSync] Failed to process locker event ${doc.eventId}: ${err}`); + req.payload.logger.error(`[LockerSync] Failed to process locker event ${raw.eventId}: ${err}`); } } - if (doc.type.startsWith("garage.")) { + if (raw.type.startsWith("garage.")) { // Awaited (same posture as locker.*): garage writes join the // raw-event transaction; processGarageEvent never throws. try { - await processGarageEvent(req.payload, doc, req); + await processGarageEvent(req.payload, raw, req); } catch (err) { - req.payload.logger.error(`[GarageSync] Failed to process garage event ${doc.eventId}: ${err}`); + req.payload.logger.error(`[GarageSync] Failed to process garage event ${raw.eventId}: ${err}`); } } }, diff --git a/src/components/frontend/locker/LockerGrid.tsx b/src/components/frontend/locker/LockerGrid.tsx index 1e8b1c3b..ddcf3ca5 100644 --- a/src/components/frontend/locker/LockerGrid.tsx +++ b/src/components/frontend/locker/LockerGrid.tsx @@ -595,7 +595,7 @@ export function LockerGrid({ }), )} - {items.map((item) => ( + {items.filter((item) => item.quantity >= 1).map((item) => (
- {items.map((entry, index) => ( + {items.filter((entry) => entry.quantity >= 1).map((entry, index) => (