@crowdedkingdoms/crowdyjs 8.2.0 → 8.3.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.
Files changed (102) hide show
  1. package/README.md +21 -3
  2. package/dist/crowdy-client.d.ts.map +1 -1
  3. package/dist/crowdy-client.js +5 -1
  4. package/dist/index.d.ts +2 -2
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +2 -2
  7. package/dist/kit/blueprints/combat.d.ts +75 -0
  8. package/dist/kit/blueprints/combat.d.ts.map +1 -0
  9. package/dist/kit/blueprints/combat.js +351 -0
  10. package/dist/kit/blueprints/core.d.ts +222 -0
  11. package/dist/kit/blueprints/core.d.ts.map +1 -0
  12. package/dist/kit/blueprints/core.js +185 -0
  13. package/dist/kit/blueprints/decks.d.ts +50 -0
  14. package/dist/kit/blueprints/decks.d.ts.map +1 -0
  15. package/dist/kit/blueprints/decks.js +163 -0
  16. package/dist/kit/blueprints/economy.d.ts +88 -0
  17. package/dist/kit/blueprints/economy.d.ts.map +1 -0
  18. package/dist/kit/blueprints/economy.js +533 -0
  19. package/dist/kit/blueprints/guild.d.ts +51 -0
  20. package/dist/kit/blueprints/guild.d.ts.map +1 -0
  21. package/dist/kit/blueprints/guild.js +50 -0
  22. package/dist/kit/blueprints/index.d.ts +21 -0
  23. package/dist/kit/blueprints/index.d.ts.map +1 -0
  24. package/dist/kit/blueprints/index.js +20 -0
  25. package/dist/kit/blueprints/inventory.d.ts +38 -0
  26. package/dist/kit/blueprints/inventory.d.ts.map +1 -0
  27. package/dist/kit/blueprints/inventory.js +157 -0
  28. package/dist/kit/blueprints/leaderboards.d.ts +49 -0
  29. package/dist/kit/blueprints/leaderboards.d.ts.map +1 -0
  30. package/dist/kit/blueprints/leaderboards.js +126 -0
  31. package/dist/kit/blueprints/locks.d.ts +82 -0
  32. package/dist/kit/blueprints/locks.d.ts.map +1 -0
  33. package/dist/kit/blueprints/locks.js +155 -0
  34. package/dist/kit/blueprints/loot.d.ts +84 -0
  35. package/dist/kit/blueprints/loot.d.ts.map +1 -0
  36. package/dist/kit/blueprints/loot.js +228 -0
  37. package/dist/kit/blueprints/matches.d.ts +59 -0
  38. package/dist/kit/blueprints/matches.d.ts.map +1 -0
  39. package/dist/kit/blueprints/matches.js +246 -0
  40. package/dist/kit/blueprints/npcs.d.ts +71 -0
  41. package/dist/kit/blueprints/npcs.d.ts.map +1 -0
  42. package/dist/kit/blueprints/npcs.js +122 -0
  43. package/dist/kit/blueprints/plots.d.ts +54 -0
  44. package/dist/kit/blueprints/plots.d.ts.map +1 -0
  45. package/dist/kit/blueprints/plots.js +146 -0
  46. package/dist/kit/blueprints/progression.d.ts +68 -0
  47. package/dist/kit/blueprints/progression.d.ts.map +1 -0
  48. package/dist/kit/blueprints/progression.js +324 -0
  49. package/dist/kit/blueprints/quests.d.ts +65 -0
  50. package/dist/kit/blueprints/quests.d.ts.map +1 -0
  51. package/dist/kit/blueprints/quests.js +284 -0
  52. package/dist/kit/blueprints/worldsim.d.ts +84 -0
  53. package/dist/kit/blueprints/worldsim.d.ts.map +1 -0
  54. package/dist/kit/blueprints/worldsim.js +461 -0
  55. package/dist/kit/combat.d.ts +103 -0
  56. package/dist/kit/combat.d.ts.map +1 -0
  57. package/dist/kit/combat.js +151 -0
  58. package/dist/kit/decks.d.ts +123 -0
  59. package/dist/kit/decks.d.ts.map +1 -0
  60. package/dist/kit/decks.js +138 -0
  61. package/dist/kit/economy.d.ts +244 -0
  62. package/dist/kit/economy.d.ts.map +1 -0
  63. package/dist/kit/economy.js +365 -0
  64. package/dist/kit/features.d.ts +60 -0
  65. package/dist/kit/features.d.ts.map +1 -0
  66. package/dist/kit/features.js +65 -0
  67. package/dist/kit/index.d.ts +13 -2
  68. package/dist/kit/index.d.ts.map +1 -1
  69. package/dist/kit/index.js +12 -1
  70. package/dist/kit/inventory.d.ts +5 -0
  71. package/dist/kit/inventory.d.ts.map +1 -1
  72. package/dist/kit/inventory.js +14 -1
  73. package/dist/kit/kit.d.ts +58 -2
  74. package/dist/kit/kit.d.ts.map +1 -1
  75. package/dist/kit/kit.js +24 -2
  76. package/dist/kit/leaderboards.d.ts +66 -0
  77. package/dist/kit/leaderboards.d.ts.map +1 -0
  78. package/dist/kit/leaderboards.js +94 -0
  79. package/dist/kit/loot.d.ts +106 -0
  80. package/dist/kit/loot.d.ts.map +1 -0
  81. package/dist/kit/loot.js +120 -0
  82. package/dist/kit/matches.d.ts +140 -0
  83. package/dist/kit/matches.d.ts.map +1 -0
  84. package/dist/kit/matches.js +253 -0
  85. package/dist/kit/objects.js +1 -1
  86. package/dist/kit/plots.js +1 -1
  87. package/dist/kit/progression.d.ts +181 -0
  88. package/dist/kit/progression.d.ts.map +1 -0
  89. package/dist/kit/progression.js +265 -0
  90. package/dist/kit/quests.d.ts +110 -0
  91. package/dist/kit/quests.d.ts.map +1 -0
  92. package/dist/kit/quests.js +158 -0
  93. package/dist/kit/social.d.ts +267 -0
  94. package/dist/kit/social.d.ts.map +1 -0
  95. package/dist/kit/social.js +230 -0
  96. package/dist/kit/worldsim.d.ts +225 -0
  97. package/dist/kit/worldsim.d.ts.map +1 -0
  98. package/dist/kit/worldsim.js +231 -0
  99. package/package.json +1 -1
  100. package/dist/kit/blueprints.d.ts +0 -370
  101. package/dist/kit/blueprints.d.ts.map +0 -1
  102. package/dist/kit/blueprints.js +0 -643
@@ -0,0 +1,265 @@
1
+ import { progressionNames, } from './blueprints/index.js';
2
+ import { kitContainerProperties, kitInvoke, } from './shared.js';
3
+ /**
4
+ * Runtime helpers for the {@link progressionBlueprint} conventions: ensure a
5
+ * player's `Progress`, grant XP (trusted — app admins by default), buy
6
+ * skills against the catalog's costs and prerequisites, unlock threshold
7
+ * achievements, and apply match rating results. Everything is
8
+ * authority-checked server-side; denials resolve with `success: false`.
9
+ *
10
+ * Obtained via `client.kit(appId).progression`.
11
+ */
12
+ export class ProgressionKit {
13
+ constructor(appId, gameModel, options = {}) {
14
+ this.appId = appId;
15
+ this.gameModel = gameModel;
16
+ this.names = progressionNames(options.typePrefix ?? '');
17
+ }
18
+ /**
19
+ * Find the player's Progress container, creating it when absent (with the
20
+ * `owner_user_id` mirror the guards read).
21
+ */
22
+ async ensure(ownerUserId, options = {}) {
23
+ const existing = await this.gameModel.containers({
24
+ appId: this.appId,
25
+ typeName: this.names.progressType,
26
+ ...(options.sessionId !== undefined ? { sessionId: options.sessionId } : {}),
27
+ });
28
+ const mine = existing.find((c) => c.ownerUserId != null && String(c.ownerUserId) === String(ownerUserId));
29
+ if (mine)
30
+ return mine;
31
+ return this.gameModel.createContainer({
32
+ appId: this.appId,
33
+ typeName: this.names.progressType,
34
+ displayName: options.displayName ?? `Progress ${ownerUserId}`,
35
+ ...(options.sessionId !== undefined ? { sessionId: options.sessionId } : {}),
36
+ properties: [
37
+ { key: 'owner_user_id', valueType: 'int', valueJson: String(ownerUserId) },
38
+ ],
39
+ });
40
+ }
41
+ /** Read one player's progression state. */
42
+ async state(progressId) {
43
+ const container = await this.gameModel.container({
44
+ appId: this.appId,
45
+ containerId: progressId,
46
+ });
47
+ const props = await kitContainerProperties(this.gameModel, String(this.appId), progressId);
48
+ return {
49
+ containerId: container.containerId,
50
+ displayName: container.displayName,
51
+ ownerUserId: container.ownerUserId != null ? String(container.ownerUserId) : null,
52
+ xp: Number(props.xp ?? 0),
53
+ level: Number(props.level ?? 1),
54
+ skillPoints: Number(props.skill_points ?? 0),
55
+ rating: Number(props.rating ?? 0),
56
+ };
57
+ }
58
+ /**
59
+ * Grant XP — a **trusted** call (default blueprint authority: app admins
60
+ * via server scope; or drive it from an event automation). Awards skill
61
+ * points and levels up when the curve is crossed. Resolves with the new
62
+ * level.
63
+ */
64
+ async grantXp(progressId, amount) {
65
+ return kitInvoke(this.gameModel, {
66
+ appId: String(this.appId),
67
+ functionName: this.names.grantXpFn,
68
+ selfContainerId: progressId,
69
+ params: { amount },
70
+ });
71
+ }
72
+ /** List the skill catalog (admin-seeded SkillDef containers). */
73
+ async skillCatalog() {
74
+ const containers = await this.gameModel.containers({
75
+ appId: this.appId,
76
+ typeName: this.names.skillDefType,
77
+ });
78
+ return Promise.all(containers.map(async (c) => {
79
+ const props = await kitContainerProperties(this.gameModel, String(this.appId), c.containerId);
80
+ return {
81
+ containerId: c.containerId,
82
+ displayName: c.displayName,
83
+ skillId: String(props.skill_id ?? ''),
84
+ cost: Number(props.cost ?? 1),
85
+ requiresSkillId: String(props.requires_skill_id ?? ''),
86
+ maxRank: Number(props.max_rank ?? 1),
87
+ };
88
+ }));
89
+ }
90
+ /** Define a skill (admin — the catalog type is admin-instantiable). */
91
+ async defineSkill(input) {
92
+ return this.gameModel.createContainer({
93
+ appId: this.appId,
94
+ typeName: this.names.skillDefType,
95
+ displayName: input.displayName ?? `Skill ${input.skillId}`,
96
+ properties: [
97
+ { key: 'skill_id', valueType: 'string', valueJson: JSON.stringify(input.skillId) },
98
+ { key: 'cost', valueType: 'int', valueJson: String(input.cost ?? 1) },
99
+ {
100
+ key: 'requires_skill_id',
101
+ valueType: 'string',
102
+ valueJson: JSON.stringify(input.requiresSkillId ?? ''),
103
+ },
104
+ { key: 'max_rank', valueType: 'int', valueJson: String(input.maxRank ?? 1) },
105
+ ...(input.properties ?? []),
106
+ ],
107
+ });
108
+ }
109
+ /**
110
+ * Find-or-create the caller's SkillRank row for a skill (rank 0 until
111
+ * bought).
112
+ */
113
+ async ensureSkillRank(ownerUserId, skillId, options = {}) {
114
+ const mine = await this.skills(ownerUserId);
115
+ const existing = mine.find((s) => s.skillId === skillId);
116
+ if (existing) {
117
+ return this.gameModel.container({
118
+ appId: this.appId,
119
+ containerId: existing.containerId,
120
+ });
121
+ }
122
+ return this.gameModel.createContainer({
123
+ appId: this.appId,
124
+ typeName: this.names.skillRankType,
125
+ displayName: options.displayName ?? `Skill ${skillId} ${ownerUserId}`,
126
+ properties: [
127
+ { key: 'owner_user_id', valueType: 'int', valueJson: String(ownerUserId) },
128
+ { key: 'skill_id', valueType: 'string', valueJson: JSON.stringify(skillId) },
129
+ ],
130
+ });
131
+ }
132
+ /**
133
+ * Buy one rank of a skill. `prereqRankId` is the caller's SkillRank for
134
+ * the prerequisite skill; omit it for skills without one (the rank row
135
+ * itself is passed to satisfy the required param — the condition ignores
136
+ * it when the def declares no prerequisite).
137
+ */
138
+ async buySkill(input) {
139
+ return kitInvoke(this.gameModel, {
140
+ appId: String(this.appId),
141
+ functionName: this.names.buySkillFn,
142
+ selfContainerId: input.skillRankId,
143
+ params: {
144
+ progress_id: input.progressId,
145
+ def_id: input.skillDefId,
146
+ prereq_id: input.prereqRankId ?? input.skillRankId,
147
+ },
148
+ });
149
+ }
150
+ /** List a player's skill ranks. */
151
+ async skills(ownerUserId) {
152
+ const containers = await this.gameModel.containers({
153
+ appId: this.appId,
154
+ typeName: this.names.skillRankType,
155
+ });
156
+ const mine = containers.filter((c) => c.ownerUserId != null && String(c.ownerUserId) === String(ownerUserId));
157
+ return Promise.all(mine.map(async (c) => {
158
+ const props = await kitContainerProperties(this.gameModel, String(this.appId), c.containerId);
159
+ return {
160
+ containerId: c.containerId,
161
+ displayName: c.displayName,
162
+ ownerUserId: c.ownerUserId != null ? String(c.ownerUserId) : null,
163
+ skillId: String(props.skill_id ?? ''),
164
+ rank: Number(props.rank ?? 0),
165
+ };
166
+ }));
167
+ }
168
+ /** List the achievement catalog (admin-seeded AchievementDef containers). */
169
+ async achievementCatalog() {
170
+ const containers = await this.gameModel.containers({
171
+ appId: this.appId,
172
+ typeName: this.names.achievementDefType,
173
+ });
174
+ return Promise.all(containers.map(async (c) => {
175
+ const props = await kitContainerProperties(this.gameModel, String(this.appId), c.containerId);
176
+ return {
177
+ containerId: c.containerId,
178
+ displayName: c.displayName,
179
+ achievementId: String(props.achievement_id ?? ''),
180
+ threshold: Number(props.threshold ?? 0),
181
+ };
182
+ }));
183
+ }
184
+ /** Define an achievement (admin). */
185
+ async defineAchievement(input) {
186
+ return this.gameModel.createContainer({
187
+ appId: this.appId,
188
+ typeName: this.names.achievementDefType,
189
+ displayName: input.displayName ?? `Achievement ${input.achievementId}`,
190
+ properties: [
191
+ {
192
+ key: 'achievement_id',
193
+ valueType: 'string',
194
+ valueJson: JSON.stringify(input.achievementId),
195
+ },
196
+ { key: 'threshold', valueType: 'int', valueJson: String(input.threshold) },
197
+ ],
198
+ });
199
+ }
200
+ /** List a player's achievement unlocks. */
201
+ async achievements(ownerUserId) {
202
+ const containers = await this.gameModel.containers({
203
+ appId: this.appId,
204
+ typeName: this.names.achievementUnlockType,
205
+ });
206
+ const mine = containers.filter((c) => c.ownerUserId != null && String(c.ownerUserId) === String(ownerUserId));
207
+ return Promise.all(mine.map(async (c) => {
208
+ const props = await kitContainerProperties(this.gameModel, String(this.appId), c.containerId);
209
+ return {
210
+ containerId: c.containerId,
211
+ displayName: c.displayName,
212
+ ownerUserId: c.ownerUserId != null ? String(c.ownerUserId) : null,
213
+ achievementId: String(props.achievement_id ?? ''),
214
+ unlocked: props.unlocked === true,
215
+ };
216
+ }));
217
+ }
218
+ /**
219
+ * Unlock an achievement once its xp threshold is met. Creates the caller's
220
+ * unlock row when absent, then invokes the gated function (idempotent).
221
+ */
222
+ async unlockAchievement(input) {
223
+ const mine = await this.achievements(input.ownerUserId);
224
+ let unlockId = mine.find((a) => a.achievementId === input.achievementId)?.containerId;
225
+ if (!unlockId) {
226
+ const created = await this.gameModel.createContainer({
227
+ appId: this.appId,
228
+ typeName: this.names.achievementUnlockType,
229
+ displayName: `Achievement ${input.achievementId} ${input.ownerUserId}`,
230
+ properties: [
231
+ {
232
+ key: 'owner_user_id',
233
+ valueType: 'int',
234
+ valueJson: String(input.ownerUserId),
235
+ },
236
+ {
237
+ key: 'achievement_id',
238
+ valueType: 'string',
239
+ valueJson: JSON.stringify(input.achievementId),
240
+ },
241
+ ],
242
+ });
243
+ unlockId = created.containerId;
244
+ }
245
+ return kitInvoke(this.gameModel, {
246
+ appId: String(this.appId),
247
+ functionName: this.names.unlockAchievementFn,
248
+ selfContainerId: unlockId,
249
+ params: { progress_id: input.progressId, def_id: input.achievementDefId },
250
+ });
251
+ }
252
+ /**
253
+ * Apply a match result as a rating delta (trusted — host-gated by
254
+ * default; `kit.matches` computes the delta). Resolves with the new
255
+ * rating.
256
+ */
257
+ async applyMatchResult(progressId, delta) {
258
+ return kitInvoke(this.gameModel, {
259
+ appId: String(this.appId),
260
+ functionName: this.names.adjustRatingFn,
261
+ selfContainerId: progressId,
262
+ params: { delta },
263
+ });
264
+ }
265
+ }
@@ -0,0 +1,110 @@
1
+ import type { GameModelAPI } from '../domains/gameModel.js';
2
+ import type { Scalars, SeedPropertyInput } from '../generated/graphql.js';
3
+ import { type KitInvokeResult } from './shared.js';
4
+ /** Options for {@link QuestsKit}. Must match the deployed quests blueprint. */
5
+ export interface QuestsKitOptions {
6
+ /** The `typePrefix` the quests blueprint was deployed with. */
7
+ typePrefix?: string;
8
+ }
9
+ /** A parsed view of one quest catalog row. */
10
+ export interface KitQuestDef {
11
+ containerId: string;
12
+ displayName: string;
13
+ questId: string;
14
+ targetCount: number;
15
+ rewardItemId: string;
16
+ rewardQty: number;
17
+ rewardGold: number;
18
+ repeatable: boolean;
19
+ daily: boolean;
20
+ }
21
+ /** A parsed view of one player's quest progress. */
22
+ export interface KitQuestProgress {
23
+ containerId: string;
24
+ displayName: string;
25
+ ownerUserId: string | null;
26
+ questId: string;
27
+ count: number;
28
+ target: number;
29
+ completed: boolean;
30
+ claimed: boolean;
31
+ daily: boolean;
32
+ }
33
+ /**
34
+ * Runtime helpers for the {@link questsBlueprint} conventions: browse the
35
+ * quest catalog, accept quests into per-player progress rows, advance them
36
+ * (trusted — app admins or event automations), and claim rewards atomically
37
+ * into a stack + wallet. Denials resolve with `success: false`.
38
+ *
39
+ * Obtained via `client.kit(appId).quests`.
40
+ */
41
+ export declare class QuestsKit {
42
+ private readonly appId;
43
+ private readonly gameModel;
44
+ private readonly names;
45
+ constructor(appId: Scalars['BigInt']['input'], gameModel: GameModelAPI, options?: QuestsKitOptions);
46
+ /** List the quest catalog (admin-seeded QuestDef containers). */
47
+ catalog(): Promise<KitQuestDef[]>;
48
+ /** Define a quest (admin — the catalog type is admin-instantiable). */
49
+ defineQuest(input: {
50
+ questId: string;
51
+ targetCount?: number;
52
+ rewardItemId?: string;
53
+ rewardQty?: number;
54
+ rewardGold?: number;
55
+ repeatable?: boolean;
56
+ daily?: boolean;
57
+ displayName?: string;
58
+ properties?: SeedPropertyInput[];
59
+ }): Promise<{
60
+ __typename?: "GmContainer";
61
+ containerId: string;
62
+ appId: string;
63
+ sessionId: string | null;
64
+ typeName: string;
65
+ displayName: string;
66
+ description: string | null;
67
+ ownerUserId: string | null;
68
+ metadataJson: string;
69
+ }>;
70
+ /**
71
+ * Accept a quest: creates the caller's progress row seeded from the def
72
+ * (target and daily flag copied at accept time).
73
+ */
74
+ accept(ownerUserId: Scalars['BigInt']['input'], questDefId: string, options?: {
75
+ displayName?: string;
76
+ sessionId?: string;
77
+ }): Promise<{
78
+ __typename?: "GmContainer";
79
+ containerId: string;
80
+ appId: string;
81
+ sessionId: string | null;
82
+ typeName: string;
83
+ displayName: string;
84
+ description: string | null;
85
+ ownerUserId: string | null;
86
+ metadataJson: string;
87
+ }>;
88
+ /** List a player's quest progress rows. */
89
+ mine(ownerUserId: Scalars['BigInt']['input']): Promise<KitQuestProgress[]>;
90
+ /** Read one progress row. */
91
+ state(progressId: string): Promise<KitQuestProgress>;
92
+ /**
93
+ * Advance quest progress — a **trusted** call (default blueprint
94
+ * authority: app admins; or wire `advanceOn` event automations). Resolves
95
+ * with the new count.
96
+ */
97
+ advance(progressId: string, amount?: number): Promise<KitInvokeResult<number>>;
98
+ /**
99
+ * Turn in a completed quest: marks it claimed AND grants the item +
100
+ * currency rewards in one transaction. Resolves with the wallet's new
101
+ * balance.
102
+ */
103
+ claim(input: {
104
+ progressId: string;
105
+ questDefId: string;
106
+ toStackId: string;
107
+ walletId: string;
108
+ }): Promise<KitInvokeResult<number>>;
109
+ }
110
+ //# sourceMappingURL=quests.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AAM,CAAC;KAClB,GAAG,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;CAYrC"}
@@ -0,0 +1,158 @@
1
+ import { questsNames } from './blueprints/index.js';
2
+ import { kitContainerProperties, kitInvoke, } from './shared.js';
3
+ /**
4
+ * Runtime helpers for the {@link questsBlueprint} conventions: browse the
5
+ * quest catalog, accept quests into per-player progress rows, advance them
6
+ * (trusted — app admins or event automations), and claim rewards atomically
7
+ * into a stack + wallet. Denials resolve with `success: false`.
8
+ *
9
+ * Obtained via `client.kit(appId).quests`.
10
+ */
11
+ export class QuestsKit {
12
+ constructor(appId, gameModel, options = {}) {
13
+ this.appId = appId;
14
+ this.gameModel = gameModel;
15
+ this.names = questsNames(options.typePrefix ?? '');
16
+ }
17
+ /** List the quest catalog (admin-seeded QuestDef containers). */
18
+ async catalog() {
19
+ const containers = await this.gameModel.containers({
20
+ appId: this.appId,
21
+ typeName: this.names.defType,
22
+ });
23
+ return Promise.all(containers.map(async (c) => {
24
+ const props = await kitContainerProperties(this.gameModel, String(this.appId), c.containerId);
25
+ return {
26
+ containerId: c.containerId,
27
+ displayName: c.displayName,
28
+ questId: String(props.quest_id ?? ''),
29
+ targetCount: Number(props.target_count ?? 1),
30
+ rewardItemId: String(props.reward_item_id ?? ''),
31
+ rewardQty: Number(props.reward_qty ?? 0),
32
+ rewardGold: Number(props.reward_gold ?? 0),
33
+ repeatable: props.repeatable === true,
34
+ daily: props.daily === true,
35
+ };
36
+ }));
37
+ }
38
+ /** Define a quest (admin — the catalog type is admin-instantiable). */
39
+ async defineQuest(input) {
40
+ return this.gameModel.createContainer({
41
+ appId: this.appId,
42
+ typeName: this.names.defType,
43
+ displayName: input.displayName ?? `Quest ${input.questId}`,
44
+ properties: [
45
+ { key: 'quest_id', valueType: 'string', valueJson: JSON.stringify(input.questId) },
46
+ {
47
+ key: 'target_count',
48
+ valueType: 'int',
49
+ valueJson: String(input.targetCount ?? 1),
50
+ },
51
+ {
52
+ key: 'reward_item_id',
53
+ valueType: 'string',
54
+ valueJson: JSON.stringify(input.rewardItemId ?? ''),
55
+ },
56
+ { key: 'reward_qty', valueType: 'int', valueJson: String(input.rewardQty ?? 0) },
57
+ {
58
+ key: 'reward_gold',
59
+ valueType: 'int',
60
+ valueJson: String(input.rewardGold ?? 0),
61
+ },
62
+ {
63
+ key: 'repeatable',
64
+ valueType: 'bool',
65
+ valueJson: String(input.repeatable ?? false),
66
+ },
67
+ { key: 'daily', valueType: 'bool', valueJson: String(input.daily ?? false) },
68
+ ...(input.properties ?? []),
69
+ ],
70
+ });
71
+ }
72
+ /**
73
+ * Accept a quest: creates the caller's progress row seeded from the def
74
+ * (target and daily flag copied at accept time).
75
+ */
76
+ async accept(ownerUserId, questDefId, options = {}) {
77
+ const props = await kitContainerProperties(this.gameModel, String(this.appId), questDefId);
78
+ const questId = String(props.quest_id ?? '');
79
+ return this.gameModel.createContainer({
80
+ appId: this.appId,
81
+ typeName: this.names.progressType,
82
+ displayName: options.displayName ?? `Quest ${questId} ${ownerUserId}`,
83
+ ...(options.sessionId !== undefined ? { sessionId: options.sessionId } : {}),
84
+ properties: [
85
+ { key: 'owner_user_id', valueType: 'int', valueJson: String(ownerUserId) },
86
+ { key: 'quest_id', valueType: 'string', valueJson: JSON.stringify(questId) },
87
+ {
88
+ key: 'target',
89
+ valueType: 'int',
90
+ valueJson: String(Number(props.target_count ?? 1)),
91
+ },
92
+ {
93
+ key: 'daily',
94
+ valueType: 'bool',
95
+ valueJson: String(props.daily === true),
96
+ },
97
+ ],
98
+ });
99
+ }
100
+ /** List a player's quest progress rows. */
101
+ async mine(ownerUserId) {
102
+ const containers = await this.gameModel.containers({
103
+ appId: this.appId,
104
+ typeName: this.names.progressType,
105
+ });
106
+ const mine = containers.filter((c) => c.ownerUserId != null && String(c.ownerUserId) === String(ownerUserId));
107
+ return Promise.all(mine.map((c) => this.state(c.containerId)));
108
+ }
109
+ /** Read one progress row. */
110
+ async state(progressId) {
111
+ const container = await this.gameModel.container({
112
+ appId: this.appId,
113
+ containerId: progressId,
114
+ });
115
+ const props = await kitContainerProperties(this.gameModel, String(this.appId), progressId);
116
+ return {
117
+ containerId: container.containerId,
118
+ displayName: container.displayName,
119
+ ownerUserId: container.ownerUserId != null ? String(container.ownerUserId) : null,
120
+ questId: String(props.quest_id ?? ''),
121
+ count: Number(props.count ?? 0),
122
+ target: Number(props.target ?? 1),
123
+ completed: props.completed === true,
124
+ claimed: props.claimed === true,
125
+ daily: props.daily === true,
126
+ };
127
+ }
128
+ /**
129
+ * Advance quest progress — a **trusted** call (default blueprint
130
+ * authority: app admins; or wire `advanceOn` event automations). Resolves
131
+ * with the new count.
132
+ */
133
+ async advance(progressId, amount = 1) {
134
+ return kitInvoke(this.gameModel, {
135
+ appId: String(this.appId),
136
+ functionName: this.names.advanceFn,
137
+ selfContainerId: progressId,
138
+ params: { amount },
139
+ });
140
+ }
141
+ /**
142
+ * Turn in a completed quest: marks it claimed AND grants the item +
143
+ * currency rewards in one transaction. Resolves with the wallet's new
144
+ * balance.
145
+ */
146
+ async claim(input) {
147
+ return kitInvoke(this.gameModel, {
148
+ appId: String(this.appId),
149
+ functionName: this.names.claimFn,
150
+ selfContainerId: input.progressId,
151
+ params: {
152
+ def_id: input.questDefId,
153
+ to_stack_id: input.toStackId,
154
+ wallet_id: input.walletId,
155
+ },
156
+ });
157
+ }
158
+ }