@crowdedkingdoms/crowdyjs 18.11.0-dev.1 → 18.13.0-dev.1

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.
Files changed (55) hide show
  1. package/MIGRATION.md +51 -0
  2. package/README.md +19 -1
  3. package/dist/generated/graphql-schema.d.ts +5 -5
  4. package/dist/generated/graphql-schema.d.ts.map +1 -1
  5. package/dist/index.d.ts +1 -1
  6. package/dist/index.js +1 -1
  7. package/dist/kit/index.d.ts +11 -0
  8. package/dist/kit/index.d.ts.map +1 -1
  9. package/dist/kit/index.js +11 -0
  10. package/dist/kit/kit.d.ts +99 -2
  11. package/dist/kit/kit.d.ts.map +1 -1
  12. package/dist/kit/kit.js +128 -2
  13. package/dist/kit/modules/arenas.d.ts +87 -0
  14. package/dist/kit/modules/arenas.d.ts.map +1 -0
  15. package/dist/kit/modules/arenas.js +66 -0
  16. package/dist/kit/modules/encounters.d.ts +75 -0
  17. package/dist/kit/modules/encounters.d.ts.map +1 -0
  18. package/dist/kit/modules/encounters.js +57 -0
  19. package/dist/kit/modules/instances.d.ts +78 -0
  20. package/dist/kit/modules/instances.d.ts.map +1 -0
  21. package/dist/kit/modules/instances.js +72 -0
  22. package/dist/kit/modules/leaderboards.d.ts +79 -0
  23. package/dist/kit/modules/leaderboards.d.ts.map +1 -0
  24. package/dist/kit/modules/leaderboards.js +69 -0
  25. package/dist/kit/modules/market.d.ts +159 -0
  26. package/dist/kit/modules/market.d.ts.map +1 -0
  27. package/dist/kit/modules/market.js +141 -0
  28. package/dist/kit/modules/minigames.d.ts +59 -0
  29. package/dist/kit/modules/minigames.d.ts.map +1 -0
  30. package/dist/kit/modules/minigames.js +55 -0
  31. package/dist/kit/modules/player.d.ts +264 -0
  32. package/dist/kit/modules/player.d.ts.map +1 -0
  33. package/dist/kit/modules/player.js +258 -0
  34. package/dist/kit/modules/racing.d.ts +131 -0
  35. package/dist/kit/modules/racing.d.ts.map +1 -0
  36. package/dist/kit/modules/racing.js +113 -0
  37. package/dist/kit/modules/tables.d.ts +76 -0
  38. package/dist/kit/modules/tables.d.ts.map +1 -0
  39. package/dist/kit/modules/tables.js +73 -0
  40. package/dist/kit/modules/tactics.d.ts +79 -0
  41. package/dist/kit/modules/tactics.d.ts.map +1 -0
  42. package/dist/kit/modules/tactics.js +67 -0
  43. package/dist/kit/modules/territory.d.ts +92 -0
  44. package/dist/kit/modules/territory.d.ts.map +1 -0
  45. package/dist/kit/modules/territory.js +84 -0
  46. package/dist/kit/protocol.d.ts +2 -0
  47. package/dist/kit/protocol.d.ts.map +1 -1
  48. package/dist/kit/protocol.js +2 -0
  49. package/dist/kit/runtime.d.ts.map +1 -1
  50. package/dist/kit/runtime.js +6 -1
  51. package/dist/live-coding/assets/browser-authoring-index.json +1 -1
  52. package/dist/live-coding/assets/manifest.json +1 -1
  53. package/dist/live-coding/browser-authoring-index.generated.d.ts.map +1 -1
  54. package/dist/live-coding/browser-authoring-index.generated.js +4776 -149
  55. package/package.json +1 -1
@@ -0,0 +1,57 @@
1
+ import { HubState } from '../mirror.js';
2
+ /** Waves, towers and bosses (the `director` starter): {@link encounter} by key. */
3
+ export class EncountersKit {
4
+ constructor(runtime, nodeType = 'director') {
5
+ this.runtime = runtime;
6
+ this.nodeType = nodeType;
7
+ this.encounters = new Map();
8
+ }
9
+ encounter(key) {
10
+ let e = this.encounters.get(key);
11
+ if (!e) {
12
+ e = new Encounter(this.runtime, this.nodeType, key);
13
+ this.encounters.set(key, e);
14
+ }
15
+ return e;
16
+ }
17
+ }
18
+ /**
19
+ * One encounter: waves of enemies down a lane to the players' base, towers the players build (a
20
+ * tower may not cut the lane), strikes on a cooldown, kills that pay gold, and a boss that changes
21
+ * phase as it weakens. {@link view} mirrors the `encounter` topic: snapshots once a second while it
22
+ * runs, and `event` messages (`type`: `wave_started`, `wave_cleared`, `boss_phase`, `won`, `lost`)
23
+ * through `view.onEvent`.
24
+ */
25
+ export class Encounter {
26
+ constructor(runtime, nodeType, key) {
27
+ this.runtime = runtime;
28
+ this.nodeType = nodeType;
29
+ this.key = key;
30
+ this.view = new HubState(runtime, nodeType, key, 'encounter');
31
+ }
32
+ watch() {
33
+ return this.view.start();
34
+ }
35
+ unwatch() {
36
+ return this.view.stop();
37
+ }
38
+ /** @throws {KitError} `full`. */
39
+ join() {
40
+ return this.runtime.call(this.nodeType, this.key, 'join', null, { action: true });
41
+ }
42
+ /** The first to join, or a developer. @throws {KitError} `forbidden`, `started`, `bad_request` (no way to the base). */
43
+ start() {
44
+ return this.runtime.call(this.nodeType, this.key, 'start', null, { action: true });
45
+ }
46
+ /**
47
+ * Builds a tower at `(x, z)`; resolves with the gold left.
48
+ * @throws {KitError} `blocks_lane`, `insufficient` (gold), `conflict` (taken), `bad_request`, `not_member`.
49
+ */
50
+ build(x, z) {
51
+ return this.runtime.call(this.nodeType, this.key, 'build', { x, z }, { action: true });
52
+ }
53
+ /** Strikes enemy `enemy`; resolves with its hp left. @throws {KitError} `cooldown`, `not_found`, `not_member`. */
54
+ hit(enemy) {
55
+ return this.runtime.call(this.nodeType, this.key, 'hit', { enemy }, { action: true });
56
+ }
57
+ }
@@ -0,0 +1,78 @@
1
+ import { HubState } from '../mirror.js';
2
+ import type { KitRuntime } from '../runtime.js';
3
+ export interface InstanceRoom {
4
+ kind: 'fight' | 'treasure' | 'rest' | 'boss';
5
+ /** What a fight here takes. */
6
+ power: number;
7
+ done: boolean;
8
+ }
9
+ export interface InstanceMember {
10
+ player: number;
11
+ hp: number;
12
+ max_hp: number;
13
+ power: number;
14
+ }
15
+ /** What the `run` topic carries. */
16
+ export interface InstanceRunView {
17
+ phase: 'unopened' | 'running' | 'cleared' | 'wiped' | 'abandoned' | 'expired';
18
+ owner: number | null;
19
+ /** The run's seed: the same seed lays out the same floors. */
20
+ seed: number;
21
+ floor: number;
22
+ floors: number;
23
+ /** The room the party is at on this floor. */
24
+ room: number;
25
+ rooms: InstanceRoom[];
26
+ members: InstanceMember[];
27
+ invited: number[];
28
+ gold: number;
29
+ relics: string[];
30
+ /** The grid reserved for the run, when the hub's config has a volume. */
31
+ grid: number | null;
32
+ log: string[];
33
+ }
34
+ /** Private runs for one party (the `instance` starter): {@link run} by key. */
35
+ export declare class InstancesKit {
36
+ private readonly runtime;
37
+ private readonly nodeType;
38
+ private readonly runs;
39
+ constructor(runtime: KitRuntime, nodeType?: string);
40
+ /** The run with key `key` (a key the game makes up, one per run). */
41
+ run(key: string): InstanceRun;
42
+ }
43
+ /**
44
+ * One run: a party plays down floors the hub generates from the run's seed, the hub resolves each
45
+ * room, a party with nobody standing is wiped (permadeath), and a run nobody touches expires. A
46
+ * cleared or wiped run posts each member's depth to a leaderboard when the hub's config names one.
47
+ */
48
+ export declare class InstanceRun {
49
+ private readonly runtime;
50
+ readonly nodeType: string;
51
+ readonly key: string;
52
+ readonly view: HubState<InstanceRunView>;
53
+ constructor(runtime: KitRuntime, nodeType: string, key: string);
54
+ watch(): Promise<InstanceRunView>;
55
+ unwatch(): Promise<void>;
56
+ /**
57
+ * Opens the run as its owner (a developer kit opens one for `party`); resolves with its seed.
58
+ * @throws {KitError} `started`, `bad_request` (party size), `conflict` (its grid could not be reserved).
59
+ */
60
+ open(options?: {
61
+ seed?: number;
62
+ party?: ReadonlyArray<number | string>;
63
+ }): Promise<number>;
64
+ /** The owner invites a player. @throws {KitError} `forbidden`, `full`. */
65
+ invite(player: number | string): Promise<boolean>;
66
+ /** An invited player joins. @throws {KitError} `forbidden`. */
67
+ join(): Promise<boolean>;
68
+ /**
69
+ * Resolves the room the party is at; resolves with what happened, as the log has it.
70
+ * @throws {KitError} `not_member`, `forbidden` (the caller is down), `conflict` (descend first), `finished`.
71
+ */
72
+ enter(): Promise<string>;
73
+ /** The owner leads the party to the next floor; resolves with it. @throws {KitError} `not_ready` (rooms left), `forbidden`. */
74
+ descend(): Promise<number>;
75
+ /** The owner (or a developer) ends the run. */
76
+ abandon(): Promise<boolean>;
77
+ }
78
+ //# sourceMappingURL=instances.d.ts.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O,CAAC,QAAQ,CAAC,IAAI,CAAkC;gBAGpC,OAAO,EAAE,UAAU,EACnB,QAAQ,SAAa;IAGxC,qEAAqE;IACrE,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW;CAQ9B;AAED;;;;GAIG;AACH,qBAAa,WAAW;IAIpB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM;IACzB,QAAQ,CAAC,GAAG,EAAE,MAAM;IALtB,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,eAAe,CAAC,CAAC;gBAGtB,OAAO,EAAE,UAAU,EAC3B,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM;IAKtB,KAAK,IAAI,OAAO,CAAC,eAAe,CAAC;IAIjC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB;;;OAGG;IACH,IAAI,CAAC,OAAO,GAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,aAAa,CAAC,MAAM,GAAG,MAAM,CAAC,CAAA;KAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAO9F,0EAA0E;IAC1E,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIjD,+DAA+D;IAC/D,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC;IAIxB;;;OAGG;IACH,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC;IAIxB,+HAA+H;IAC/H,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;IAI1B,+CAA+C;IAC/C,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC;CAG5B"}
@@ -0,0 +1,72 @@
1
+ import { HubState } from '../mirror.js';
2
+ /** Private runs for one party (the `instance` starter): {@link run} by key. */
3
+ export class InstancesKit {
4
+ constructor(runtime, nodeType = 'instance') {
5
+ this.runtime = runtime;
6
+ this.nodeType = nodeType;
7
+ this.runs = new Map();
8
+ }
9
+ /** The run with key `key` (a key the game makes up, one per run). */
10
+ run(key) {
11
+ let r = this.runs.get(key);
12
+ if (!r) {
13
+ r = new InstanceRun(this.runtime, this.nodeType, key);
14
+ this.runs.set(key, r);
15
+ }
16
+ return r;
17
+ }
18
+ }
19
+ /**
20
+ * One run: a party plays down floors the hub generates from the run's seed, the hub resolves each
21
+ * room, a party with nobody standing is wiped (permadeath), and a run nobody touches expires. A
22
+ * cleared or wiped run posts each member's depth to a leaderboard when the hub's config names one.
23
+ */
24
+ export class InstanceRun {
25
+ constructor(runtime, nodeType, key) {
26
+ this.runtime = runtime;
27
+ this.nodeType = nodeType;
28
+ this.key = key;
29
+ this.view = new HubState(runtime, nodeType, key, 'run');
30
+ }
31
+ watch() {
32
+ return this.view.start();
33
+ }
34
+ unwatch() {
35
+ return this.view.stop();
36
+ }
37
+ /**
38
+ * Opens the run as its owner (a developer kit opens one for `party`); resolves with its seed.
39
+ * @throws {KitError} `started`, `bad_request` (party size), `conflict` (its grid could not be reserved).
40
+ */
41
+ open(options = {}) {
42
+ const args = {};
43
+ if (options.seed !== undefined)
44
+ args.seed = options.seed;
45
+ if (options.party?.length)
46
+ args.party = options.party.map(Number);
47
+ return this.runtime.call(this.nodeType, this.key, 'open', args, { action: true });
48
+ }
49
+ /** The owner invites a player. @throws {KitError} `forbidden`, `full`. */
50
+ invite(player) {
51
+ return this.runtime.call(this.nodeType, this.key, 'invite', { player: Number(player) }, { action: true });
52
+ }
53
+ /** An invited player joins. @throws {KitError} `forbidden`. */
54
+ join() {
55
+ return this.runtime.call(this.nodeType, this.key, 'join', null, { action: true });
56
+ }
57
+ /**
58
+ * Resolves the room the party is at; resolves with what happened, as the log has it.
59
+ * @throws {KitError} `not_member`, `forbidden` (the caller is down), `conflict` (descend first), `finished`.
60
+ */
61
+ enter() {
62
+ return this.runtime.call(this.nodeType, this.key, 'enter', null, { action: true });
63
+ }
64
+ /** The owner leads the party to the next floor; resolves with it. @throws {KitError} `not_ready` (rooms left), `forbidden`. */
65
+ descend() {
66
+ return this.runtime.call(this.nodeType, this.key, 'descend', null, { action: true });
67
+ }
68
+ /** The owner (or a developer) ends the run. */
69
+ abandon() {
70
+ return this.runtime.call(this.nodeType, this.key, 'abandon', null, { action: true });
71
+ }
72
+ }
@@ -0,0 +1,79 @@
1
+ import { HubState } from '../mirror.js';
2
+ import type { KitRuntime } from '../runtime.js';
3
+ /** A player's place on a board. */
4
+ export interface LeaderboardRank {
5
+ rank: number;
6
+ player: number;
7
+ score: number;
8
+ }
9
+ /** What the `board` topic carries: the top of the board and the season. */
10
+ export interface LeaderboardView {
11
+ season: number;
12
+ /** When the season began (Unix ms). */
13
+ season_started: number;
14
+ /** Players with a score this season. */
15
+ entries: number;
16
+ top: LeaderboardRank[];
17
+ }
18
+ /** The season, and the last one's final standings. */
19
+ export interface LeaderboardSeason {
20
+ season: number;
21
+ started: number;
22
+ entries: number;
23
+ last: LeaderboardRank[];
24
+ }
25
+ /** A board's settings (developers). */
26
+ export interface LeaderboardConfig {
27
+ /** `best` (by `order`), `sum` or `latest` submission. */
28
+ keep?: 'best' | 'sum' | 'latest';
29
+ /** `high` scores rank first (points) or `low` (times). */
30
+ order?: 'high' | 'low';
31
+ top_size?: number;
32
+ /** A cron schedule that ends the season (`0 0 * * 1`: every Monday), or null for none. */
33
+ season_cron?: string | null;
34
+ max_entries?: number;
35
+ }
36
+ /** Leaderboards (the `leaderboard` starter): {@link board} by name. */
37
+ export declare class LeaderboardsKit {
38
+ private readonly runtime;
39
+ private readonly nodeType;
40
+ private readonly boards;
41
+ constructor(runtime: KitRuntime, nodeType?: string);
42
+ /** The board named `name` (`weekly-score`, `fastest-lap`, ...). */
43
+ board(name: string): LeaderboardHandle;
44
+ }
45
+ /**
46
+ * One board. The hub ranks players itself, and only other hubs and developers submit: a client
47
+ * never sends its own score, the hub that decided the result does (a session, a race, a run).
48
+ * {@link view} mirrors the `board` topic (at most once a second).
49
+ */
50
+ export declare class LeaderboardHandle {
51
+ private readonly runtime;
52
+ readonly nodeType: string;
53
+ readonly name: string;
54
+ /** The `board` topic: the top of the board and the season. */
55
+ readonly view: HubState<LeaderboardView>;
56
+ constructor(runtime: KitRuntime, nodeType: string, name: string);
57
+ watch(): Promise<LeaderboardView>;
58
+ unwatch(): Promise<void>;
59
+ /** A page of the board, best first. */
60
+ top(options?: {
61
+ limit?: number;
62
+ offset?: number;
63
+ }): Promise<LeaderboardRank[]>;
64
+ /** The places around a player (the caller's own, without `player`). */
65
+ around(options?: {
66
+ player?: number | string;
67
+ radius?: number;
68
+ }): Promise<LeaderboardRank[]>;
69
+ /** The caller's own place, or null without a score this season. */
70
+ me(): Promise<LeaderboardRank | null>;
71
+ season(): Promise<LeaderboardSeason>;
72
+ /** Submits a score for `player`. Developers only (a developer kit); players are refused. */
73
+ submit(player: number | string, score: number): Promise<number>;
74
+ /** Sets the board's config. Developers only. */
75
+ configure(config: LeaderboardConfig): Promise<boolean>;
76
+ /** Ends the season now; resolves with the new season. Developers only. */
77
+ roll(): Promise<number>;
78
+ }
79
+ //# sourceMappingURL=leaderboards.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"leaderboards.d.ts","sourceRoot":"","sources":["../../../src/kit/modules/leaderboards.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,mCAAmC;AACnC,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf;AAED,2EAA2E;AAC3E,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,uCAAuC;IACvC,cAAc,EAAE,MAAM,CAAC;IACvB,wCAAwC;IACxC,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,eAAe,EAAE,CAAC;CACxB;AAED,sDAAsD;AACtD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MAAM,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;IAIlF,uEAAuE;IACvE,MAAM,CAAC,OAAO,GAAE;QAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;IAO/F,mEAAmE;IACnE,EAAE,IAAI,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IAIrC,MAAM,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAIpC,4FAA4F;IAC5F,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAI/D,gDAAgD;IAChD,SAAS,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,OAAO,CAAC;IAItD,0EAA0E;IAC1E,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;CAGxB"}
@@ -0,0 +1,69 @@
1
+ import { HubState } from '../mirror.js';
2
+ /** Leaderboards (the `leaderboard` starter): {@link board} by name. */
3
+ export class LeaderboardsKit {
4
+ constructor(runtime, nodeType = 'leaderboard') {
5
+ this.runtime = runtime;
6
+ this.nodeType = nodeType;
7
+ this.boards = new Map();
8
+ }
9
+ /** The board named `name` (`weekly-score`, `fastest-lap`, ...). */
10
+ board(name) {
11
+ let b = this.boards.get(name);
12
+ if (!b) {
13
+ b = new LeaderboardHandle(this.runtime, this.nodeType, name);
14
+ this.boards.set(name, b);
15
+ }
16
+ return b;
17
+ }
18
+ }
19
+ /**
20
+ * One board. The hub ranks players itself, and only other hubs and developers submit: a client
21
+ * never sends its own score, the hub that decided the result does (a session, a race, a run).
22
+ * {@link view} mirrors the `board` topic (at most once a second).
23
+ */
24
+ export class LeaderboardHandle {
25
+ constructor(runtime, nodeType, name) {
26
+ this.runtime = runtime;
27
+ this.nodeType = nodeType;
28
+ this.name = name;
29
+ this.view = new HubState(runtime, nodeType, name, 'board');
30
+ }
31
+ watch() {
32
+ return this.view.start();
33
+ }
34
+ unwatch() {
35
+ return this.view.stop();
36
+ }
37
+ /** A page of the board, best first. */
38
+ top(options = {}) {
39
+ return this.runtime.call(this.nodeType, this.name, 'top', options);
40
+ }
41
+ /** The places around a player (the caller's own, without `player`). */
42
+ around(options = {}) {
43
+ const args = {};
44
+ if (options.player !== undefined)
45
+ args.player = Number(options.player);
46
+ if (options.radius !== undefined)
47
+ args.radius = options.radius;
48
+ return this.runtime.call(this.nodeType, this.name, 'around', args);
49
+ }
50
+ /** The caller's own place, or null without a score this season. */
51
+ me() {
52
+ return this.runtime.call(this.nodeType, this.name, 'me');
53
+ }
54
+ season() {
55
+ return this.runtime.call(this.nodeType, this.name, 'season');
56
+ }
57
+ /** Submits a score for `player`. Developers only (a developer kit); players are refused. */
58
+ submit(player, score) {
59
+ return this.runtime.call(this.nodeType, this.name, 'submit', { player: Number(player), score }, { action: true });
60
+ }
61
+ /** Sets the board's config. Developers only. */
62
+ configure(config) {
63
+ return this.runtime.call(this.nodeType, this.name, 'configure', config, { action: true });
64
+ }
65
+ /** Ends the season now; resolves with the new season. Developers only. */
66
+ roll() {
67
+ return this.runtime.call(this.nodeType, this.name, 'roll', null, { action: true });
68
+ }
69
+ }
@@ -0,0 +1,159 @@
1
+ import { HubState, PrivateState } from '../mirror.js';
2
+ import type { KitRuntime } from '../runtime.js';
3
+ import type { EconBundle } from './player.js';
4
+ export interface VendorOfferView {
5
+ item: string;
6
+ price: EconBundle;
7
+ /** Left on the shelf; null for no limit. */
8
+ stock: number | null;
9
+ per_player: number | null;
10
+ /** What the vendor pays for one; null when it does not buy them. */
11
+ buys_for: EconBundle | null;
12
+ }
13
+ export interface VendorView {
14
+ id: string;
15
+ offers: VendorOfferView[];
16
+ restocked_at: number;
17
+ }
18
+ export interface MarketQuote {
19
+ bid: number | null;
20
+ ask: number | null;
21
+ last: number | null;
22
+ }
23
+ /** What the `market` topic carries. */
24
+ export interface MarketView {
25
+ vendors: VendorView[];
26
+ currency: string;
27
+ quotes: Record<string, MarketQuote>;
28
+ open_trades: number;
29
+ pending_steps: number;
30
+ }
31
+ export interface MarketBook {
32
+ item: string;
33
+ currency: string;
34
+ /** `[price, count]` a level, best first. */
35
+ bids: Array<[number, number]>;
36
+ asks: Array<[number, number]>;
37
+ last: number | null;
38
+ }
39
+ export interface MarketOrder {
40
+ id: number;
41
+ player: number;
42
+ item: string;
43
+ side: 'buy' | 'sell';
44
+ price: number;
45
+ count: number;
46
+ /** What is still open. */
47
+ open: number;
48
+ /** The hold that backs it, in the player's hub. */
49
+ hold: string;
50
+ }
51
+ export interface MarketPlaced {
52
+ order: number;
53
+ /** `[price, count]` it traded at once. */
54
+ fills: Array<[number, number]>;
55
+ open: number;
56
+ }
57
+ export interface MarketTradeSide {
58
+ bundle: EconBundle;
59
+ hold: string | null;
60
+ accepted: boolean;
61
+ }
62
+ export interface MarketTrade {
63
+ id: number;
64
+ players: [number, number];
65
+ sides: [MarketTradeSide, MarketTradeSide];
66
+ state: 'open' | 'settling' | 'done' | 'cancelled';
67
+ expires_at: number;
68
+ offers: number;
69
+ }
70
+ /** One market hub's mirrors and calls, shared by its market, shop and trade handles. */
71
+ export declare class MarketCore {
72
+ readonly runtime: KitRuntime;
73
+ readonly nodeType: string;
74
+ readonly key: string;
75
+ readonly view: HubState<MarketView>;
76
+ /** The caller's open orders, read again when the market says they moved. */
77
+ readonly orders: PrivateState<MarketOrder[]>;
78
+ /** The caller's open and settling trades. */
79
+ readonly trades: PrivateState<MarketTrade[]>;
80
+ constructor(runtime: KitRuntime, nodeType: string, key: string);
81
+ change<T>(method: string, args: unknown): Promise<T>;
82
+ }
83
+ /** Markets' order books (the `market` starter): {@link at} a market by its name. */
84
+ export declare class MarketsKit {
85
+ private readonly core;
86
+ constructor(core: (key: string) => MarketCore);
87
+ at(key?: string): MarketHandle;
88
+ }
89
+ /**
90
+ * A market's order books: limit orders matched at price-time priority. An order holds what it
91
+ * offers in the player's own hub until it fills or is cancelled; the market moves each fill
92
+ * between the two players' hubs.
93
+ */
94
+ export declare class MarketHandle {
95
+ private readonly core;
96
+ constructor(core: MarketCore);
97
+ get view(): HubState<MarketView>;
98
+ get orders(): PrivateState<MarketOrder[]>;
99
+ watch(): Promise<MarketView>;
100
+ unwatch(): Promise<void>;
101
+ book(item: string): Promise<MarketBook>;
102
+ /**
103
+ * Places a limit order; a buy holds `price * count` of the market's currency, a sell the items.
104
+ * @throws {KitError} `insufficient`, `limit` (open orders), `not_found` (no book), `unavailable`.
105
+ */
106
+ order(order: {
107
+ item: string;
108
+ side: 'buy' | 'sell';
109
+ price: number;
110
+ count: number;
111
+ }): Promise<MarketPlaced>;
112
+ /** Cancels an open order; what it still holds comes back. @throws {KitError} `not_found`. */
113
+ cancel(order: number): Promise<boolean>;
114
+ }
115
+ /** Markets' vendors (the `market` starter): {@link at} a market by its name. */
116
+ export declare class ShopsKit {
117
+ private readonly core;
118
+ constructor(core: (key: string) => MarketCore);
119
+ at(key?: string): ShopHandle;
120
+ }
121
+ /** A market's vendors: fixed prices, stock that restocks, a limit per player. */
122
+ export declare class ShopHandle {
123
+ private readonly core;
124
+ constructor(core: MarketCore);
125
+ get view(): HubState<MarketView>;
126
+ watch(): Promise<MarketView>;
127
+ unwatch(): Promise<void>;
128
+ vendors(): Promise<VendorView[]>;
129
+ /** Buys `count` (one by default). @throws {KitError} `insufficient` (gold or stock), `limit`, `full`, `not_found`, `unavailable`. */
130
+ buy(vendor: string, item: string, count?: number): Promise<EconBundle>;
131
+ /** Sells `count` (one by default). @throws {KitError} `forbidden` (it does not buy them), `insufficient`, `unavailable`. */
132
+ sell(vendor: string, item: string, count?: number): Promise<EconBundle>;
133
+ }
134
+ /** Trades between two players at a market: {@link at} a market by its name. */
135
+ export declare class TradesKit {
136
+ private readonly core;
137
+ constructor(core: (key: string) => MarketCore);
138
+ at(key?: string): TradeDesk;
139
+ }
140
+ /**
141
+ * Trades between two players: each offers a bundle, held in their own hub; when both accept
142
+ * the last offers, the market moves each to the other. A changed offer clears both acceptances.
143
+ */
144
+ export declare class TradeDesk {
145
+ private readonly core;
146
+ constructor(core: MarketCore);
147
+ get mine(): PrivateState<MarketTrade[]>;
148
+ watch(): Promise<MarketTrade[]>;
149
+ unwatch(): Promise<void>;
150
+ /** Opens a trade with `player`; resolves with its id. */
151
+ open(player: number | string): Promise<number>;
152
+ /** Offers `bundle` (held at once; an empty one withdraws). @throws {KitError} `insufficient`, `forbidden`, `finished`. */
153
+ offer(trade: number, bundle: Partial<EconBundle>): Promise<boolean>;
154
+ /** Accepts the offers as they stand; resolves with the trade's state. @throws {KitError} `not_ready`, `finished`. */
155
+ accept(trade: number): Promise<MarketTrade['state']>;
156
+ /** Calls it off; what each offered comes back. */
157
+ decline(trade: number): Promise<boolean>;
158
+ }
159
+ //# sourceMappingURL=market.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"market.d.ts","sourceRoot":"","sources":["../../../src/kit/modules/market.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,UAAU,CAAC;IAClB,4CAA4C;IAC5C,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,oEAAoE;IACpE,QAAQ,EAAE,UAAU,GAAG,IAAI,CAAC;CAC7B;AAED,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,WAAW;IAC1B,GAAG,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