feat(gameplay): add versioned SRD rules migration
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { AbilityScoresSchema } from '@dng/shared'
|
||||
import { AbilityKeySchema, AbilityScoresSchema, SkillKeySchema } from '@dng/shared'
|
||||
import { z } from 'zod'
|
||||
import { requireCampaignAccess, requireStageTwoSafeText, requireStageTwoUser, stageTwoApiError, stageTwoDatabase, stageTwoRpc, stageTwoUuid } from '~/server/utils/stage-two-supabase'
|
||||
|
||||
@@ -13,8 +13,15 @@ const BodySchema = z.object({
|
||||
proficiency: z.number().int().min(1).max(10).default(2),
|
||||
inventory: z.array(z.string().trim().min(1).max(120)).max(50).default([]),
|
||||
statuses: z.array(z.string().trim().min(1).max(80)).max(12).default([]),
|
||||
skillProficiencies: z.array(SkillKeySchema).max(8).default([]),
|
||||
skillExpertise: z.array(SkillKeySchema).max(4).default([]),
|
||||
savingThrowProficiencies: z.array(AbilityKeySchema).max(3).default([]),
|
||||
persona: z.record(z.string(), z.unknown()).default({}),
|
||||
}).strict().refine(value => value.hp <= value.maxHp, { message: 'hp must not exceed maxHp', path: ['hp'] })
|
||||
}).strict()
|
||||
.refine(value => value.hp <= value.maxHp, { message: 'hp must not exceed maxHp', path: ['hp'] })
|
||||
.refine(value => value.skillExpertise.every(skill => value.skillProficiencies.includes(skill)), {
|
||||
message: 'expertise requires skill proficiency', path: ['skillExpertise'],
|
||||
})
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
try {
|
||||
@@ -26,7 +33,7 @@ export default defineEventHandler(async (event) => {
|
||||
throw createError({ statusCode: 403, statusMessage: 'Only the campaign owner can add AI heroes.' })
|
||||
}
|
||||
requireStageTwoSafeText([body.name, body.concept, ...body.inventory, ...body.statuses, JSON.stringify(body.persona)].join('\n'))
|
||||
const characterId = await stageTwoRpc<string>('stage_four_create_character', {
|
||||
const characterId = await stageTwoRpc<string>('stage_five_create_character', {
|
||||
p_campaign_id: campaignId,
|
||||
p_actor_id: user.id,
|
||||
p_controller: body.controller,
|
||||
@@ -40,6 +47,21 @@ export default defineEventHandler(async (event) => {
|
||||
p_inventory: body.inventory,
|
||||
p_statuses: body.statuses,
|
||||
p_persona: body.persona,
|
||||
p_rules_state: {
|
||||
version: 2,
|
||||
level: 1,
|
||||
skillProficiencies: body.skillProficiencies,
|
||||
skillExpertise: body.skillExpertise,
|
||||
savingThrowProficiencies: body.savingThrowProficiencies,
|
||||
temporaryHp: 0,
|
||||
deathSaves: { successes: 0, failures: 0 },
|
||||
exhaustion: 0,
|
||||
damageResistances: [],
|
||||
damageVulnerabilities: [],
|
||||
damageImmunities: [],
|
||||
resources: { hitDice: { current: 1, max: 1, recovery: 'longRest' } },
|
||||
legacyProficiencyFallback: false,
|
||||
},
|
||||
})
|
||||
const rows = await stageTwoDatabase<Array<Record<string, unknown>>>(
|
||||
`characters?select=*&id=eq.${characterId}&campaign_id=eq.${campaignId}&limit=1`,
|
||||
|
||||
Reference in New Issue
Block a user