equipment

This commit is contained in:
Devin Zuczek
2026-07-21 01:20:03 -04:00
parent 0f301e5788
commit 41fa8b9979
4 changed files with 184 additions and 6 deletions
+32 -4
View File
@@ -28,6 +28,7 @@ import {
getConsumables,
grantConsumable,
} from './consumables-db'
import { getEquipment, grantEquipment } from './equipment-db'
import { getInventory, grantItem } from './inventory-db'
import {
AUTHED,
@@ -59,6 +60,7 @@ import type { GiftContent, StoredGift } from '@repo/domain'
import type { Avatar } from './avatar-db'
import type { ConsumeResult } from './consumables-db'
import type { App } from './context'
import type { Equipment } from './equipment-db'
import type { AvatarItem } from './inventory-db'
import type { Outfit } from './outfit-db'
@@ -275,6 +277,17 @@ function toAvatarItem(giftDrop: StoreGiftDrop): AvatarItem {
}
}
/** Build the owned equipment DTO granted into the buyer's inventory from a gift-drop. */
function toEquipment(giftDrop: StoreGiftDrop): Equipment {
return {
EquipmentModificationGuid: giftDrop.EquipmentModificationGuid,
EquipmentPrefabName: giftDrop.EquipmentPrefabName,
FriendlyName: giftDrop.FriendlyName,
Tooltip: giftDrop.Tooltip,
Rarity: giftDrop.Rarity,
}
}
/** Quantity of a consumable granted per purchase — our storefront catalogs don't specify one. */
const CONSUMABLE_GRANT_COUNT = 1
@@ -688,9 +701,17 @@ const app = new Hono<App>({ strict: false })
}
)
// Unlocked equipment. Returns "[]" with no auth.
.get('/api/equipment/v2/getUnlocked', listRoute('Unlocked equipment', 'Empty for now'), (c) =>
c.json([])
// Unlocked equipment. [Authorize]. The equipment skins the player has bought (from
// `buyItem`, stored in the `equipment` table). A player who has bought none gets an
// empty list.
.get(
'/api/equipment/v2/getUnlocked',
listRoute('Unlocked equipment', 'The equipment skins the player has bought', true),
async (c) => {
const id = await authedId(c)
if (id === null) return unauthorized(c)
return c.json(await getEquipment(c.env.DB, id))
}
)
// Room consumables/currencies for a given room. Stubbed as empty lists so the
@@ -951,10 +972,17 @@ const app = new Hono<App>({ strict: false })
if (!paid) return c.json({ error: 'Insufficient balance' }, 400)
// Grant the item to the recipient. A gift-drop carries an avatar item, a consumable,
// or neither (currency/xp drops aren't granted yet); grant whichever it actually has.
// an equipment skin, or none of these (currency/xp drops aren't granted yet); grant
// whichever it actually has.
if (typeof item.GiftDrop.AvatarItemDesc === 'string' && item.GiftDrop.AvatarItemDesc !== '') {
await grantItem(c.env.DB, receiverId, toAvatarItem(item.GiftDrop))
}
if (
typeof item.GiftDrop.EquipmentModificationGuid === 'string' &&
item.GiftDrop.EquipmentModificationGuid !== ''
) {
await grantEquipment(c.env.DB, receiverId, toEquipment(item.GiftDrop))
}
const isConsumable =
typeof item.GiftDrop.ConsumableItemDesc === 'string' &&
item.GiftDrop.ConsumableItemDesc !== ''