quests: QuestMetrics helpers (purchaseOffer/purchaseItem), README quests section
This commit is contained in:
@@ -61,7 +61,7 @@ client.dispose();
|
||||
| Storage | `client.storage` (observable) + `.save(items)` / `.delete(type)` |
|
||||
| Leaderboards | `client.leaderboards.findBySlug(slug)` → `handle.submit(score)` / `handle.list(limit?)` |
|
||||
| Battle pass | `client.battlePass` (getProgress / addXp / claimReward / purchasePremium) |
|
||||
| Quests | `client.quests.list()` / `client.quests.claim(id)` |
|
||||
| Quests | `client.quests.list()` / `client.quests.claim(id)` / `client.quests.reportProgress(metric, amount)` |
|
||||
| Scenario effects | `client.effects.on*` |
|
||||
|
||||
Type the remote config for `client.remoteConfig`:
|
||||
@@ -75,6 +75,37 @@ const client = new RudderClient<GameConfig>({ /* … */ });
|
||||
client.remoteConfig.get('player_speed', 200); // number
|
||||
```
|
||||
|
||||
## Quests
|
||||
|
||||
`client.quests` covers the player's global quests — list with per-objective
|
||||
progress, claim, and metric reports. These are distinct from scenario quest
|
||||
nodes, which advance through the `onQuest` effect's `QuestSession`. Global
|
||||
quests have no live sync: re-list after a claim or report.
|
||||
|
||||
```ts
|
||||
const quests = await client.quests.list();
|
||||
for (const quest of quests) {
|
||||
if (quest.status === 'completed' && quest.id) {
|
||||
await client.quests.claim(quest.id);
|
||||
}
|
||||
}
|
||||
|
||||
// Custom metrics advance matching objectives server-side; the call returns
|
||||
// the ids of quests completed by this report.
|
||||
const completedIds = await client.quests.reportProgress('kills', 1);
|
||||
```
|
||||
|
||||
Purchase metrics are reported automatically when a purchase goes through
|
||||
`client.stores`; the `QuestMetrics` helpers name the format so quest configs
|
||||
and client code agree on it:
|
||||
|
||||
```ts
|
||||
import { QuestMetrics } from '@rudder/js-sdk';
|
||||
|
||||
QuestMetrics.purchaseOffer('starter-pack'); // "purchase.offer:starter-pack"
|
||||
QuestMetrics.purchaseItem('moonberry'); // "purchase.item:moonberry"
|
||||
```
|
||||
|
||||
## Scenario effects
|
||||
|
||||
The scenario runtime is not exposed directly; scenario nodes surface through
|
||||
|
||||
Reference in New Issue
Block a user