@wildshard/shard-format 0.48.1 → 0.49.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wildshard/shard-format",
3
- "version": "0.48.1",
3
+ "version": "0.49.0",
4
4
  "description": "The raw shardfile format: the spec, the validator and a validate CLI. The public, versioned contract every other repo builds on.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -0,0 +1,67 @@
1
+ import {
2
+ check,
3
+ exactOptional,
4
+ finite,
5
+ maxValue,
6
+ minValue,
7
+ number,
8
+ picklist,
9
+ pipe,
10
+ } from 'valibot'
11
+
12
+ import type { CheckAction, ExactOptionalSchema, GenericSchema } from 'valibot'
13
+
14
+ /** How an ability pushes the player it strikes, and where on that player it aims (OF20c1). */
15
+ interface CreatureAbilityPush {
16
+ /** `knockback` slides the struck player; `impulse` throws it along the strike's facing. */
17
+ effect?: 'knockback' | 'impulse'
18
+ /** Knockback: horizontal travel in metres on clear ground. Impulse: horizontal speed in m/s (at most 40). */
19
+ strength?: number
20
+ /** Impulse only: upward speed in m/s. */
21
+ lift?: number
22
+ /** Metres above the target's feet the strike aims at (a stoop at the chest); absent, the feet. */
23
+ aimHeight?: number
24
+ }
25
+
26
+ const ZERO = 0
27
+ const MAX_KNOCKBACK_DISTANCE = 60
28
+ const MAX_IMPULSE_SPEED = 40
29
+ const MAX_AIM_HEIGHT = 10
30
+ const scalar = pipe(number(), finite())
31
+ const knockback = pipe(scalar, minValue(ZERO), maxValue(MAX_KNOCKBACK_DISTANCE))
32
+ const impulse = pipe(scalar, minValue(ZERO), maxValue(MAX_IMPULSE_SPEED))
33
+ const aim = pipe(scalar, minValue(ZERO), maxValue(MAX_AIM_HEIGHT))
34
+
35
+ /** The ability row's push fields, spread into its strict object. */
36
+ type Optional<Value> = ExactOptionalSchema<GenericSchema<Value>, undefined>
37
+ const abilityPushFields: {
38
+ effect: Optional<'knockback' | 'impulse'>
39
+ strength: Optional<number>
40
+ lift: Optional<number>
41
+ aimHeight: Optional<number>
42
+ } = {
43
+ effect: exactOptional(picklist(['knockback', 'impulse'])),
44
+ strength: exactOptional(knockback),
45
+ lift: exactOptional(impulse),
46
+ aimHeight: exactOptional(aim),
47
+ }
48
+ const PUSH_RULE =
49
+ 'Creature push effect and strength go together; lift needs an impulse of at most 40 m/s'
50
+ const pushRule = ({
51
+ effect,
52
+ strength,
53
+ lift,
54
+ }: Readonly<CreatureAbilityPush>): boolean =>
55
+ (effect === undefined) === (strength === undefined) &&
56
+ (lift === undefined || effect === 'impulse') &&
57
+ (effect !== 'impulse' || (strength ?? ZERO) <= MAX_IMPULSE_SPEED)
58
+ /** The push rule, typed to the row it guards. */
59
+ function abilityPushCheck<Row extends CreatureAbilityPush>(): CheckAction<
60
+ Row,
61
+ typeof PUSH_RULE
62
+ > {
63
+ return check<Row, typeof PUSH_RULE>(pushRule, PUSH_RULE)
64
+ }
65
+
66
+ export { abilityPushCheck, abilityPushFields }
67
+ export type { CreatureAbilityPush }
@@ -20,12 +20,14 @@ import {
20
20
  union,
21
21
  } from 'valibot'
22
22
 
23
+ import { abilityPushCheck, abilityPushFields } from './creature-ability-push.ts'
23
24
  import { CreatureProjectileSchema } from './creature-projectile.ts'
24
25
  import { CreatureSocketNameSchema } from './creature-volumes.ts'
25
26
  import { CreatureSkinClipNameSchema } from './skinData.ts'
26
27
  import { StrikeTellKindSchema } from './spawnCombat.ts'
27
28
  import { HuntTuningSchema } from './speciesPrograms.ts'
28
29
 
30
+ import type { CreatureAbilityPush } from './creature-ability-push.ts'
29
31
  import type { CreatureAttackable } from './creature-attackable.ts'
30
32
  import type { CreatureBody } from './creature-body.ts'
31
33
  import type { CreatureMount } from './creature-mount.ts'
@@ -78,7 +80,7 @@ interface CreatureSenses {
78
80
  reveal?: number
79
81
  }
80
82
  /** Ordered strike-row references. A scalar range means zero through that radius. */
81
- interface CreatureAbility {
83
+ interface CreatureAbility extends CreatureAbilityPush {
82
84
  use: string
83
85
  range: number | [number, number]
84
86
  cooldown: number
@@ -90,9 +92,6 @@ interface CreatureAbility {
90
92
  duration?: number
91
93
  from?: string
92
94
  clip?: CreatureSkinClipName
93
- effect?: 'knockback'
94
- /** Horizontal travel in metres on clear ground. */
95
- strength?: number
96
95
  tell?: StrikeTellKind
97
96
  projectile?: CreatureProjectile
98
97
  }
@@ -127,7 +126,6 @@ const MAX_SOUND = 4096
127
126
  const MAX_RADIUS = 500
128
127
  const MAX_SPEED = 15
129
128
  const MAX_TIME = 86_400
130
- const MAX_KNOCKBACK_DISTANCE = 60
131
129
  const MAX_AMOUNT = 10_000_000
132
130
  const MAX_CALLS = 32
133
131
  const MAX_TUNING_FIELDS = 64
@@ -140,11 +138,6 @@ const speed = pipe(scalar, minValue(ZERO), maxValue(MAX_SPEED))
140
138
  const unit = pipe(scalar, minValue(ZERO), maxValue(ONE))
141
139
  const time = pipe(scalar, minValue(ZERO), maxValue(MAX_TIME))
142
140
  const amount = pipe(scalar, minValue(ZERO), maxValue(MAX_AMOUNT))
143
- const knockbackDistance = pipe(
144
- scalar,
145
- minValue(ZERO),
146
- maxValue(MAX_KNOCKBACK_DISTANCE),
147
- )
148
141
  const orderedRadius = pipe(
149
142
  tuple([radius, radius]),
150
143
  check<[number, number], 'Ordered creature ability range'>(
@@ -235,26 +228,14 @@ const abilityRow = strictObject({
235
228
  duration: exactOptional(time),
236
229
  from: exactOptional(CreatureSocketNameSchema),
237
230
  clip: exactOptional(CreatureSkinClipNameSchema),
238
- effect: exactOptional(picklist(['knockback'])),
239
- strength: exactOptional(knockbackDistance),
231
+ ...abilityPushFields,
240
232
  tell: exactOptional(StrikeTellKindSchema),
241
233
  projectile: exactOptional(CreatureProjectileSchema),
242
234
  })
243
- const abilityEffectCheck = check<
244
- CreatureAbility,
245
- 'Creature knockback effect and strength must be specified together'
246
- >(
247
- ({
248
- effect,
249
- strength,
250
- }: Readonly<Pick<CreatureAbility, 'effect' | 'strength'>>): boolean =>
251
- (effect === undefined) === (strength === undefined),
252
- 'Creature knockback effect and strength must be specified together',
253
- )
254
235
  const CreatureAbilitySchema: GenericSchema<
255
236
  CreatureAbilityInput,
256
237
  CreatureAbility
257
- > = pipe(abilityRow, abilityEffectCheck)
238
+ > = pipe(abilityRow, abilityPushCheck<CreatureAbility>())
258
239
  const callVariants = pipe(array(sound), maxLength(MAX_CALLS))
259
240
  const CreaturePresentationSchema: GenericSchema<CreaturePresentation> =
260
241
  strictObject({
@@ -1,13 +1,16 @@
1
1
  import * as v from 'valibot';
2
2
  import { compileDirectorWhen } from './directorWhen.ts';
3
3
 
4
- const key = v.pipe(v.string(), v.regex(/^[a-z][a-z0-9.-]*$/u), v.maxLength(128));
4
+ const KEY_LENGTH = 128;
5
+ const key = v.pipe(v.string(), v.regex(/^[a-z][a-z0-9.-]*$/u), v.maxLength(KEY_LENGTH));
6
+ // A quest flag can include the source's colon-delimited namespace.
7
+ const questFlag = v.pipe(v.string(), v.regex(/^[a-z][a-z0-9.-]*(?::[a-z0-9][a-z0-9.-]*)*$/u), v.maxLength(KEY_LENGTH));
5
8
  const name = v.pipe(v.string(), v.regex(/^[A-Za-z_][A-Za-z0-9_]*$/u), v.maxLength(64));
6
- const bindingSchema = v.pipe(v.string(), v.maxLength(256), v.regex(/^(?:(?:flag|zone|event):[a-z][a-z0-9.-]*|actor:[a-z][a-z0-9.-]*\.(?:dead|present)|day:(?:0(?:\.[0-9]+)?|1)\.\.(?:0(?:\.[0-9]+)?|1))$/u));
9
+ const bindingSchema = v.pipe(v.string(), v.maxLength(256), v.regex(/^(?:flag:[a-z][a-z0-9.-]*(?::[a-z0-9][a-z0-9.-]*)*|(?:zone|event):[a-z][a-z0-9.-]*|actor:[a-z][a-z0-9.-]*\.(?:dead|present)|day:(?:0(?:\.[0-9]+)?|1)\.\.(?:0(?:\.[0-9]+)?|1))$/u));
7
10
  const value = v.pipe(v.number(), v.finite(), v.minValue(-10000), v.maxValue(10000));
8
11
  const action = v.union([
9
12
  v.strictObject({ spawn: key }), v.strictObject({ despawn: key }),
10
- v.strictObject({ flag: v.strictObject({ key, value: v.boolean() }) }),
13
+ v.strictObject({ flag: v.strictObject({ key: questFlag, value: v.boolean() }) }),
11
14
  v.strictObject({ score: key }), v.strictObject({ weather: key }),
12
15
  v.strictObject({ toast: key }), v.strictObject({ reward: key }),
13
16
  v.strictObject({ emit: key, value: v.optional(v.union([v.boolean(), value]), 0) }),
@@ -14,6 +14,8 @@ export const HEADLESS_CONTEXT_SECTIONS = [
14
14
  'world/targets',
15
15
  'sim/runtime-plan',
16
16
  'sim/bodies',
17
+ // The offline simulation reads the ordinary portal ride from this plan.
18
+ 'client/plan',
17
19
  ] as const
18
20
 
19
21
  /** Explicit admitted decision/move context crossing the worker boundary; no ABI is inferred from bytes. */