funifier-mcp 0.2.26 → 0.2.28
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/.cursor/rules/funifier.mdc +38 -41
- package/.github/copilot-instructions.md +38 -41
- package/AGENTS.md +56 -49
- package/README.md +40 -22
- package/datasource-funifier-docs/.coverage.json +326 -0
- package/datasource-funifier-docs/.validation.json +593 -0
- package/datasource-funifier-docs/knowledge/guides/aggregates.md +182 -70
- package/datasource-funifier-docs/knowledge/guides/database-access.md +174 -88
- package/datasource-funifier-docs/knowledge/guides/java-entities.md +294 -204
- package/datasource-funifier-docs/knowledge/guides/java-libraries.md +202 -226
- package/datasource-funifier-docs/knowledge/guides/java-managers.md +343 -265
- package/datasource-funifier-docs/knowledge/guides/trigger-examples.md +180 -236
- package/datasource-funifier-docs/knowledge/guides/triggers-guide.md +273 -191
- package/datasource-funifier-docs/knowledge/index.md +4 -1
- package/datasource-funifier-docs/knowledge/modules/achievement.md +1126 -28
- package/datasource-funifier-docs/knowledge/modules/action-log.md +469 -62
- package/datasource-funifier-docs/knowledge/modules/action.md +522 -70
- package/datasource-funifier-docs/knowledge/modules/auth.md +718 -69
- package/datasource-funifier-docs/knowledge/modules/avatar.md +483 -18
- package/datasource-funifier-docs/knowledge/modules/backup.md +603 -25
- package/datasource-funifier-docs/knowledge/modules/challenge.md +1048 -220
- package/datasource-funifier-docs/knowledge/modules/compact.md +469 -26
- package/datasource-funifier-docs/knowledge/modules/competition.md +811 -109
- package/datasource-funifier-docs/knowledge/modules/crossword.md +504 -28
- package/datasource-funifier-docs/knowledge/modules/csv-data.md +645 -20
- package/datasource-funifier-docs/knowledge/modules/custom-object.md +701 -36
- package/datasource-funifier-docs/knowledge/modules/database.md +730 -164
- package/datasource-funifier-docs/knowledge/modules/folder.md +935 -280
- package/datasource-funifier-docs/knowledge/modules/kpi-formulas.md +410 -15
- package/datasource-funifier-docs/knowledge/modules/lastmile.md +568 -29
- package/datasource-funifier-docs/knowledge/modules/leaderboard.md +595 -126
- package/datasource-funifier-docs/knowledge/modules/level.md +536 -54
- package/datasource-funifier-docs/knowledge/modules/lottery.md +809 -76
- package/datasource-funifier-docs/knowledge/modules/marketplace.md +688 -17
- package/datasource-funifier-docs/knowledge/modules/mystery.md +662 -52
- package/datasource-funifier-docs/knowledge/modules/notification.md +564 -26
- package/datasource-funifier-docs/knowledge/modules/patterns.md +519 -814
- package/datasource-funifier-docs/knowledge/modules/player.md +773 -73
- package/datasource-funifier-docs/knowledge/modules/point.md +380 -83
- package/datasource-funifier-docs/knowledge/modules/public.md +508 -178
- package/datasource-funifier-docs/knowledge/modules/question.md +619 -99
- package/datasource-funifier-docs/knowledge/modules/quiz.md +565 -120
- package/datasource-funifier-docs/knowledge/modules/scheduler.md +1092 -39
- package/datasource-funifier-docs/knowledge/modules/security.md +674 -112
- package/datasource-funifier-docs/knowledge/modules/staging.md +742 -19
- package/datasource-funifier-docs/knowledge/modules/story.md +565 -29
- package/datasource-funifier-docs/knowledge/modules/studio-page.md +470 -144
- package/datasource-funifier-docs/knowledge/modules/swap.md +552 -84
- package/datasource-funifier-docs/knowledge/modules/team.md +563 -45
- package/datasource-funifier-docs/knowledge/modules/trigger.md +876 -134
- package/datasource-funifier-docs/knowledge/modules/upload.md +468 -95
- package/datasource-funifier-docs/knowledge/modules/virtual-good.md +510 -63
- package/datasource-funifier-docs/knowledge/modules/webhook.md +375 -28
- package/datasource-funifier-docs/knowledge/modules/websocket.md +459 -26
- package/datasource-funifier-docs/knowledge/modules/widget.md +613 -27
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +42 -1
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/init.test.js +74 -3
- package/dist/cli/init.test.js.map +1 -1
- package/dist/cli/persona.d.ts +3 -0
- package/dist/cli/persona.d.ts.map +1 -0
- package/dist/cli/persona.js +25 -0
- package/dist/cli/persona.js.map +1 -0
- package/dist/mcp/bundle.js +119 -93
- package/dist/mcp/check-update.d.ts +5 -0
- package/dist/mcp/check-update.d.ts.map +1 -1
- package/dist/mcp/check-update.js +21 -10
- package/dist/mcp/check-update.js.map +1 -1
- package/dist/mcp/check-update.test.d.ts +2 -0
- package/dist/mcp/check-update.test.d.ts.map +1 -0
- package/dist/mcp/check-update.test.js +33 -0
- package/dist/mcp/check-update.test.js.map +1 -0
- package/dist/mcp/index.js +2 -2
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/prompts/templates.d.ts.map +1 -1
- package/dist/mcp/prompts/templates.js +35 -0
- package/dist/mcp/prompts/templates.js.map +1 -1
- package/dist/mcp/resources/documentation.d.ts +1 -1
- package/dist/mcp/resources/documentation.d.ts.map +1 -1
- package/dist/mcp/resources/documentation.js +39 -3
- package/dist/mcp/resources/documentation.js.map +1 -1
- package/dist/mcp/tools/connect.d.ts.map +1 -1
- package/dist/mcp/tools/connect.js +18 -8
- package/dist/mcp/tools/connect.js.map +1 -1
- package/dist/mcp/tools/database.d.ts.map +1 -1
- package/dist/mcp/tools/database.js +59 -47
- package/dist/mcp/tools/database.js.map +1 -1
- package/dist/mcp/tools/database.test.js +2 -2
- package/dist/mcp/tools/database.test.js.map +1 -1
- package/dist/mcp/tools/delete.d.ts.map +1 -1
- package/dist/mcp/tools/delete.js +13 -3
- package/dist/mcp/tools/delete.js.map +1 -1
- package/dist/mcp/tools/execute.d.ts.map +1 -1
- package/dist/mcp/tools/execute.js +20 -9
- package/dist/mcp/tools/execute.js.map +1 -1
- package/dist/mcp/tools/folder.d.ts.map +1 -1
- package/dist/mcp/tools/folder.js +22 -12
- package/dist/mcp/tools/folder.js.map +1 -1
- package/dist/mcp/tools/get.d.ts.map +1 -1
- package/dist/mcp/tools/get.js +16 -6
- package/dist/mcp/tools/get.js.map +1 -1
- package/dist/mcp/tools/index.d.ts +1 -1
- package/dist/mcp/tools/index.d.ts.map +1 -1
- package/dist/mcp/tools/index.js +28 -1
- package/dist/mcp/tools/index.js.map +1 -1
- package/dist/mcp/tools/list.d.ts.map +1 -1
- package/dist/mcp/tools/list.js +38 -14
- package/dist/mcp/tools/list.js.map +1 -1
- package/dist/mcp/tools/logs.d.ts.map +1 -1
- package/dist/mcp/tools/logs.js +15 -5
- package/dist/mcp/tools/logs.js.map +1 -1
- package/dist/mcp/tools/save.d.ts.map +1 -1
- package/dist/mcp/tools/save.js +14 -4
- package/dist/mcp/tools/save.js.map +1 -1
- package/dist/mcp/tools/save.test.js +3 -3
- package/dist/mcp/tools/save.test.js.map +1 -1
- package/dist/mcp/tools/search-docs.d.ts +3 -0
- package/dist/mcp/tools/search-docs.d.ts.map +1 -0
- package/dist/mcp/tools/search-docs.js +102 -0
- package/dist/mcp/tools/search-docs.js.map +1 -0
- package/package.json +6 -2
- package/skills/acquire-funifier-knowledge/SKILL.md +155 -0
- package/skills/acquire-funifier-knowledge/assets/templates/CONCERNS.md +25 -0
- package/skills/acquire-funifier-knowledge/assets/templates/CUSTOM_ENDPOINTS.md +24 -0
- package/skills/acquire-funifier-knowledge/assets/templates/CUSTOM_PAGES.md +24 -0
- package/skills/acquire-funifier-knowledge/assets/templates/GAME_MECHANICS.md +35 -0
- package/skills/acquire-funifier-knowledge/assets/templates/INTEGRATIONS.md +35 -0
- package/skills/acquire-funifier-knowledge/assets/templates/LEADERBOARDS.md +24 -0
- package/skills/acquire-funifier-knowledge/assets/templates/OVERVIEW.md +86 -0
- package/skills/acquire-funifier-knowledge/assets/templates/PLAYER_MODEL.md +31 -0
- package/skills/acquire-funifier-knowledge/assets/templates/SCHEDULERS.md +25 -0
- package/skills/acquire-funifier-knowledge/assets/templates/TECHNIQUES_AND_PATTERNS.md +26 -0
- package/skills/acquire-funifier-knowledge/assets/templates/TRIGGERS.md +27 -0
- package/skills/acquire-funifier-knowledge/references/funifier-inventory-checklist.md +81 -0
- package/skills/acquire-funifier-knowledge/references/game-techniques-taxonomy.md +62 -0
- package/skills/acquire-funifier-knowledge/references/mcp-call-patterns.md +118 -0
- package/skills/funifier/SKILL.md +88 -0
- package/skills/funifier/references/configure-security.md +96 -0
- package/skills/{funifier-create-action/SKILL.md → funifier/references/create-action.md} +0 -33
- package/skills/funifier/references/create-aggregate.md +144 -0
- package/skills/funifier/references/create-challenge.md +116 -0
- package/skills/funifier/references/create-competition.md +98 -0
- package/skills/funifier/references/create-crossword.md +574 -0
- package/skills/funifier/references/create-custom-object.md +91 -0
- package/skills/funifier/references/create-custom-page.md +135 -0
- package/skills/funifier/references/create-folder.md +104 -0
- package/skills/funifier/references/create-lastmile.md +643 -0
- package/skills/{funifier-create-leaderboard/SKILL.md → funifier/references/create-leaderboard.md} +0 -33
- package/skills/funifier/references/create-level.md +94 -0
- package/skills/funifier/references/create-lottery.md +913 -0
- package/skills/funifier/references/create-mystery.md +769 -0
- package/skills/funifier/references/create-notification.md +75 -0
- package/skills/{funifier-create-point/SKILL.md → funifier/references/create-point.md} +0 -33
- package/skills/funifier/references/create-quiz.md +98 -0
- package/skills/funifier/references/create-scheduler.md +141 -0
- package/skills/funifier/references/create-story.md +636 -0
- package/skills/funifier/references/create-swap.md +95 -0
- package/skills/{funifier-create-trigger/SKILL.md → funifier/references/create-trigger.md} +0 -33
- package/skills/funifier/references/create-virtual-good.md +96 -0
- package/skills/funifier/references/create-webhook.md +72 -0
- package/skills/funifier/references/create-websocket.md +71 -0
- package/skills/funifier/references/create-widget.md +76 -0
- package/skills/funifier/references/debug.md +87 -0
- package/skills/funifier/references/help.md +81 -0
- package/skills/funifier/references/implement-frontend.md +106 -0
- package/skills/funifier/references/import-csv.md +75 -0
- package/skills/funifier/references/manage-player.md +82 -0
- package/skills/funifier/references/manage-team.md +76 -0
- package/skills/funifier/references/upload-file.md +91 -0
- package/skills/funifier-create-aggregate/SKILL.md +0 -127
- package/skills/funifier-create-challenge/SKILL.md +0 -88
- package/skills/funifier-create-custom-page/SKILL.md +0 -127
- package/skills/funifier-create-level/SKILL.md +0 -87
- package/skills/funifier-create-quiz/SKILL.md +0 -87
- package/skills/funifier-create-scheduler/SKILL.md +0 -127
- package/skills/funifier-create-virtual-good/SKILL.md +0 -87
- package/skills/funifier-debug/SKILL.md +0 -92
- package/skills/funifier-help/SKILL.md +0 -86
- package/skills/funifier-implement-frontend/SKILL.md +0 -90
- package/skills/funifier-index/SKILL.md +0 -58
|
@@ -1,181 +1,233 @@
|
|
|
1
1
|
# Java Managers — Referência
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## 1. Visão Geral
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
### 1.1 O que é este documento
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Este documento cataloga os managers da plataforma Funifier — métodos, retornos e quando usar — para operar sobre as entidades em código server-side (triggers, schedulers e public endpoints). Os managers são acessados via o objeto global `manager` (instância de `ManagerFactory`).
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
### 1.2 Quando consultar
|
|
10
|
+
|
|
11
|
+
- Consulte ao precisar de um **método** para criar/buscar/atualizar uma entidade em código.
|
|
12
|
+
- Consulte ao precisar **registrar uma ação** (`track`/`trackSynchonous`) ou **conceder uma conquista** (`addAchievement`).
|
|
13
|
+
- Consulte ao precisar **creditar/debitar/transferir pontos**, **processar compra**, **executar sorteio/competição**, etc.
|
|
14
|
+
|
|
15
|
+
### 1.3 Quando NÃO consultar
|
|
16
|
+
|
|
17
|
+
- **NÃO** consulte para os **campos/tipos** das entidades retornadas — use `datasource-funifier-docs/knowledge/guides/java-entities.md`.
|
|
18
|
+
- **NÃO** consulte para **acesso direto ao banco** (Jongo find/save/aggregate) — use `datasource-funifier-docs/knowledge/guides/database-access.md`.
|
|
19
|
+
- **NÃO** consulte para **bibliotecas utilitárias** (JsonUtil, Guid, DateUtil) — use `java-libraries.md`.
|
|
20
|
+
|
|
21
|
+
### 1.4 Índice de decisão
|
|
22
|
+
|
|
23
|
+
| Problema / Situação | Manager | Seção |
|
|
24
|
+
|---|---|---|
|
|
25
|
+
| CRUD de jogador, roles, contagem | PlayerManager | §2 |
|
|
26
|
+
| Registrar ação / contar logs | ActionManager | §3 |
|
|
27
|
+
| Conceder/somar conquistas, status do jogador | AchievementManager | §4 |
|
|
28
|
+
| Loja: comprar, estornar, validar | CatalogManager | §5 |
|
|
29
|
+
| Desafios | ChallengeManager | §6 |
|
|
30
|
+
| Níveis | LevelManager | §7 |
|
|
31
|
+
| Equipes, vínculo de membros | TeamManager | §8 |
|
|
32
|
+
| Pontos: creditar/debitar/transferir | PointManager | §9 |
|
|
33
|
+
| Sorteios | LotteryManager | §10 |
|
|
34
|
+
| Competições | CompetitionManager | §11 |
|
|
35
|
+
| Caixas surpresa | MysteryBoxManager | §12 |
|
|
36
|
+
| Perguntas / Quiz | QuestionManager / QuizManager | §13 |
|
|
37
|
+
| Rankings | LeaderBoardManager | §14 |
|
|
38
|
+
| Notificações | NotificationManager | §15 |
|
|
39
|
+
| Trocas entre jogadores | SwapManager | §16 |
|
|
40
|
+
| Acesso direto ao MongoDB | `getJongoConnection()` | §17 |
|
|
41
|
+
|
|
42
|
+
### 1.5 Restrições globais críticas
|
|
43
|
+
|
|
44
|
+
> ⚠️ **Todos os managers são acessíveis nos três runtimes.** `manager.get*Manager()` funciona em Trigger, Scheduler **e** Public Endpoint (`patterns.md` §1.5). Por isso a linha "Disponível em" é omitida nas seções abaixo — é sempre "Todos". O que é bloqueado no Public Endpoint são bibliotecas externas (`Unirest`, `BCrypt`), não os managers.
|
|
45
|
+
|
|
46
|
+
> ⚠️ **`PlayerManager` não tem `update`/`save`.** `insert(player)` é upsert e é o único ponto de escrita (`patterns.md` §10). Consequência de procurar `pm.save`/`pm.update`: método inexistente. → Use `insert`.
|
|
47
|
+
|
|
48
|
+
> ⚠️ **`track` ≠ `addLog`.** `track`/`trackSynchonous` processam as regras de gamificação (geram conquistas); `addLog` apenas insere o documento de log **sem** processar regras. Consequência de errar: ou conquistas não são geradas (`addLog`), ou são geradas quando não deviam (`track`). → Escolha pelo efeito desejado (§3).
|
|
49
|
+
|
|
50
|
+
> ⚠️ **Nunca chame `track`/`trackSynchonous` para a mesma ação que disparou o trigger.** Consequência: loop infinito. → Filtre por `entity.actionId` antes ou use outra ação (`trigger-examples.md` Exemplo 7).
|
|
51
|
+
|
|
52
|
+
### 1.6 Documentos relacionados
|
|
53
|
+
|
|
54
|
+
> 📄 `datasource-funifier-docs/knowledge/guides/java-entities.md` — campos/tipos das entidades retornadas
|
|
55
|
+
> 📄 `datasource-funifier-docs/knowledge/guides/database-access.md` — Jongo e `/v3/database`
|
|
56
|
+
> 📄 `datasource-funifier-docs/knowledge/guides/trigger-examples.md` — exemplos de produção que combinam managers
|
|
15
57
|
|
|
16
58
|
---
|
|
17
59
|
|
|
18
|
-
## PlayerManager
|
|
60
|
+
## 2. PlayerManager
|
|
19
61
|
|
|
20
|
-
|
|
62
|
+
Quando usar: criar/buscar/remover jogadores, gerir roles, contar cadastros.
|
|
63
|
+
Não usar quando: precisar dos campos do Player → `java-entities.md` §2.
|
|
64
|
+
Depende de: `Player`, `Principal`.
|
|
21
65
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
66
|
+
### Descrição
|
|
67
|
+
|
|
68
|
+
Gestão de jogadores. Acesso: `manager.getPlayerManager()`.
|
|
69
|
+
|
|
70
|
+
### Uso
|
|
26
71
|
|
|
27
72
|
| Método | Retorno | Descrição |
|
|
28
73
|
|--------|---------|-----------|
|
|
29
74
|
| `findById(String id)` | Player | Busca jogador por ID |
|
|
30
75
|
| `findByAlternativeLogin(String login)` | Player | Busca por login alternativo |
|
|
31
|
-
| `findAll()` | Iterable\<Player\> | Lista todos
|
|
32
|
-
| `findRandom(String match, Jongo jongo)` | Player |
|
|
33
|
-
| `findTotal()` | long | Total de jogadores
|
|
34
|
-
| `findTotalNewUsers(Date start, Date end)` | long | Novos
|
|
35
|
-
| `insert(Player player)` | void | Cria ou atualiza
|
|
76
|
+
| `findAll()` | Iterable\<Player\> | Lista todos |
|
|
77
|
+
| `findRandom(String match, Jongo jongo)` | Player | Aleatório que corresponda ao filtro |
|
|
78
|
+
| `findTotal()` | long | Total de jogadores |
|
|
79
|
+
| `findTotalNewUsers(Date start, Date end)` | long | Novos no período |
|
|
80
|
+
| `insert(Player player)` | void | **Cria ou atualiza (upsert) — único ponto de escrita** |
|
|
36
81
|
| `delete(String userId)` | void | Remove jogador e dados relacionados |
|
|
37
|
-
| `reset(String id)` | Player | Remove e recria
|
|
38
|
-
| `updateProfileImage(String player, String imageUrl)` | void | Atualiza imagem
|
|
39
|
-
| `insertRole(String role, String player)` | Map | Atribui role
|
|
40
|
-
| `removeRole(String role, String player)` | Map | Remove role
|
|
41
|
-
| `findPrincipalByUserId(String id)` | Principal |
|
|
42
|
-
| `findPrincipalByUserOrTeamId(String id)` | Principal |
|
|
43
|
-
|
|
44
|
-
**Exemplos:**
|
|
82
|
+
| `reset(String id)` | Player | Remove e recria (zera progresso) |
|
|
83
|
+
| `updateProfileImage(String player, String imageUrl)` | void | Atualiza imagem |
|
|
84
|
+
| `insertRole(String role, String player)` | Map | Atribui role |
|
|
85
|
+
| `removeRole(String role, String player)` | Map | Remove role |
|
|
86
|
+
| `findPrincipalByUserId(String id)` | Principal | Principal por user ID |
|
|
87
|
+
| `findPrincipalByUserOrTeamId(String id)` | Principal | Principal por user ou team ID |
|
|
45
88
|
|
|
46
89
|
```java
|
|
47
|
-
// Buscar
|
|
90
|
+
// Buscar
|
|
48
91
|
Player p = manager.getPlayerManager().findById("john");
|
|
49
|
-
String name = p.name;
|
|
50
|
-
String email = p.email;
|
|
51
|
-
Map extra = p.extra; // campos customizados
|
|
52
92
|
|
|
53
|
-
// Criar
|
|
93
|
+
// Criar/atualizar (read-merge-write — ver patterns.md §10)
|
|
54
94
|
Player newPlayer = new Player();
|
|
55
|
-
newPlayer.
|
|
95
|
+
newPlayer.id = "maria"; // Groovy: .id, não ._id (java-entities.md §1.5)
|
|
56
96
|
newPlayer.name = "Maria Silva";
|
|
57
97
|
newPlayer.email = "maria@email.com";
|
|
58
98
|
newPlayer.extra = new HashMap();
|
|
59
99
|
newPlayer.extra.put("department", "Sales");
|
|
60
100
|
manager.getPlayerManager().insert(newPlayer);
|
|
61
101
|
|
|
62
|
-
// Contar jogadores
|
|
63
102
|
long total = manager.getPlayerManager().findTotal();
|
|
64
103
|
```
|
|
65
104
|
|
|
105
|
+
### Armadilhas conhecidas
|
|
106
|
+
|
|
107
|
+
- **`pm.save`/`pm.update`** → inexistentes. Correção: `insert` (§1.5).
|
|
108
|
+
- **`pm.find("{}")`** → assinatura inexistente. Correção: `findAll()` (`patterns.md` §10).
|
|
109
|
+
- **`insert` com objeto parcial** → apaga campos. Correção: read-merge-write (`patterns.md` §10).
|
|
110
|
+
|
|
66
111
|
---
|
|
67
112
|
|
|
68
|
-
## ActionManager
|
|
113
|
+
## 3. ActionManager
|
|
69
114
|
|
|
70
|
-
|
|
115
|
+
Quando usar: registrar ações de jogadores, contar/consultar logs, gerir definições de ação.
|
|
116
|
+
Não usar quando: precisar dos campos de ActionLog/Action → `java-entities.md` §4–§5.
|
|
117
|
+
Depende de: `ActionLog`, `Action`, `Achievement`.
|
|
71
118
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
119
|
+
### Descrição
|
|
120
|
+
|
|
121
|
+
Registro e gestão de ações. Acesso: `manager.getActionManager()`.
|
|
122
|
+
|
|
123
|
+
### Uso
|
|
75
124
|
|
|
76
125
|
| Método | Retorno | Descrição |
|
|
77
126
|
|--------|---------|-----------|
|
|
78
|
-
| `track(ActionLog action)` | void | Registra
|
|
79
|
-
| `trackSynchonous(ActionLog action)` | List\<Achievement\> | Registra
|
|
80
|
-
| `trackWithRestrictions(ActionLog log, String async)` | Map | Registra com validações ("sync"
|
|
81
|
-
| `
|
|
82
|
-
| `
|
|
83
|
-
| `
|
|
84
|
-
| `
|
|
85
|
-
| `
|
|
86
|
-
| `
|
|
87
|
-
| `
|
|
88
|
-
| `
|
|
89
|
-
| `
|
|
127
|
+
| `track(ActionLog action)` | void | Registra e **processa regras** (assíncrono) |
|
|
128
|
+
| `trackSynchonous(ActionLog action)` | List\<Achievement\> | Registra, processa regras e **retorna conquistas** (síncrono) |
|
|
129
|
+
| `trackWithRestrictions(ActionLog log, String async)` | Map | Registra com validações (`"sync"`/`"async"`) |
|
|
130
|
+
| `addLog(ActionLog action)` | void | Insere o log **sem processar regras** (não gera conquistas) |
|
|
131
|
+
| `findActionById(String id)` | Action | Definição da ação |
|
|
132
|
+
| `findActionByIdOrName(String idOrName)` | Action | Por ID ou nome |
|
|
133
|
+
| `findAllActions()` | Iterable\<Action\> | Lista definições |
|
|
134
|
+
| `addAction(Action action)` | void | Cria definição |
|
|
135
|
+
| `updateAction(Action action)` | void | Atualiza definição |
|
|
136
|
+
| `deleteAction(String id)` | void | Remove definição |
|
|
137
|
+
| `findActionLogById(String id)` | ActionLog | Log por ID |
|
|
138
|
+
| `deleteActionLog(String id)` | void | Remove log |
|
|
90
139
|
| `countActionLogsRegisteredByUser(String userId, String typeId)` | long | Conta logs do jogador |
|
|
91
140
|
| `countActionLogsRegisteredBetweenDatesByUser(String userId, String typeId, Date start, Date end)` | long | Conta logs no período |
|
|
92
141
|
| `findLatestActionLogDateRegisteredByUser(String userId, String typeId)` | Date | Data do último log |
|
|
93
142
|
|
|
94
|
-
|
|
143
|
+
**`track` vs `trackSynchonous` vs `addLog`:**
|
|
144
|
+
- `track` — dispara e não bloqueia; conquistas processadas em background. Use quando não precisa do resultado.
|
|
145
|
+
- `trackSynchonous` — bloqueia e retorna as conquistas geradas. Use quando precisa saber o que foi concedido.
|
|
146
|
+
- `addLog` — só grava o log; **nenhuma** regra roda. Use para registrar histórico sem efeito de gamificação.
|
|
95
147
|
|
|
96
148
|
```java
|
|
97
|
-
// Registrar ação (assíncrono — mais rápido)
|
|
98
149
|
ActionLog log = new ActionLog();
|
|
99
|
-
log.
|
|
150
|
+
log.id = Guid.newShortGuid(); // Groovy: .id
|
|
100
151
|
log.actionId = "sell";
|
|
101
152
|
log.userId = "john";
|
|
102
153
|
log.time = new Date();
|
|
103
154
|
log.attributes = new HashMap();
|
|
104
|
-
log.attributes.put("product", "book");
|
|
105
155
|
log.attributes.put("price", 120);
|
|
106
|
-
manager.getActionManager().track(log);
|
|
107
156
|
|
|
108
|
-
//
|
|
109
|
-
List<Achievement>
|
|
110
|
-
|
|
111
|
-
// Contar ações de um jogador
|
|
112
|
-
long total = manager.getActionManager().countActionLogsRegisteredByUser("john", "sell");
|
|
157
|
+
manager.getActionManager().track(log); // async
|
|
158
|
+
List<Achievement> earned = manager.getActionManager().trackSynchonous(log); // sync
|
|
113
159
|
```
|
|
114
160
|
|
|
161
|
+
### Armadilhas conhecidas
|
|
162
|
+
|
|
163
|
+
- **`track` para a mesma ação que disparou o trigger** → loop infinito (§1.5).
|
|
164
|
+
- **Esperar conquistas do `track`** → ele retorna `void`. Correção: `trackSynchonous`.
|
|
165
|
+
- **`addLog` esperando que conquistas sejam geradas** → não processa regras. Correção: `track`.
|
|
166
|
+
|
|
115
167
|
---
|
|
116
168
|
|
|
117
|
-
## AchievementManager
|
|
169
|
+
## 4. AchievementManager
|
|
118
170
|
|
|
119
|
-
|
|
171
|
+
Quando usar: conceder conquistas manualmente, somar pontos/recompensas, consultar status/nível.
|
|
172
|
+
Não usar quando: precisar das constantes `TYPE_*` → `java-entities.md` §3.
|
|
173
|
+
Depende de: `Achievement`, `PlayerStatus`, `Level`, `Requirement`, `Jongo`.
|
|
120
174
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
175
|
+
### Descrição
|
|
176
|
+
|
|
177
|
+
Gestão de conquistas. Acesso: `manager.getAchievementManager()`.
|
|
178
|
+
|
|
179
|
+
### Uso
|
|
124
180
|
|
|
125
181
|
| Método | Retorno | Descrição |
|
|
126
182
|
|--------|---------|-----------|
|
|
127
183
|
| `addAchievement(Achievement achievement)` | void | Adiciona conquista manualmente |
|
|
128
184
|
| `deleteAchievement(String id)` | void | Remove conquista |
|
|
129
|
-
| `findAchievement(String id, Jongo jongo)` | Achievement |
|
|
185
|
+
| `findAchievement(String id, Jongo jongo)` | Achievement | Conquista por ID |
|
|
130
186
|
| `findPlayerStatus(String player)` | PlayerStatus | Status completo do jogador |
|
|
131
187
|
| `updatePlayerStatus(String player, Jongo jongo)` | List\<Achievement\> | Recalcula status |
|
|
132
188
|
| `sumTotalRewards(String player, int type, String item, Jongo jongo)` | long | Soma recompensas |
|
|
133
189
|
| `sumTotalPoints(String player, Jongo jongo)` | double | Soma total de pontos |
|
|
134
|
-
| `findLatestLevelAchieved(String player, Jongo jongo)` | Level | Nível atual
|
|
135
|
-
| `evaluateRequirements(Requirement[] all, String player)` | boolean | Verifica
|
|
190
|
+
| `findLatestLevelAchieved(String player, Jongo jongo)` | Level | Nível atual |
|
|
191
|
+
| `evaluateRequirements(Requirement[] all, String player)` | boolean | Verifica requisitos |
|
|
136
192
|
| `deductRequirements(Requirement[] all, String player)` | void | Deduz requisitos (pontos, etc.) |
|
|
137
193
|
| `fireAction(ActionLog trigger)` | List\<Achievement\> | Processa ação e concede conquistas |
|
|
138
194
|
|
|
139
|
-
**Tipos de Achievement:**
|
|
140
|
-
```java
|
|
141
|
-
Achievement.TYPE_POINT = 0; // Pontos
|
|
142
|
-
Achievement.TYPE_CHALLENGE = 1; // Desafio completado
|
|
143
|
-
Achievement.TYPE_VIRTUAL_GOOD = 2; // Item comprado
|
|
144
|
-
Achievement.TYPE_LEVEL = 3; // Nível alcançado
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
**Exemplos:**
|
|
148
|
-
|
|
149
195
|
```java
|
|
150
|
-
// Dar pontos manualmente
|
|
151
196
|
Achievement a = new Achievement();
|
|
152
|
-
a.
|
|
197
|
+
a.id = Guid.newShortGuid(); // Groovy: .id
|
|
153
198
|
a.player = "john";
|
|
154
199
|
a.total = 50;
|
|
155
|
-
a.type = Achievement.TYPE_POINT;
|
|
200
|
+
a.type = Achievement.TYPE_POINT; // ver java-entities.md §3
|
|
156
201
|
a.item = "xp";
|
|
157
202
|
a.time = new Date();
|
|
158
203
|
manager.getAchievementManager().addAchievement(a);
|
|
159
204
|
|
|
160
|
-
// Consultar saldo de pontos
|
|
161
205
|
Jongo jongo = manager.getJongoConnection();
|
|
162
206
|
long xp = manager.getAchievementManager().sumTotalRewards("john", 0, "xp", jongo);
|
|
163
207
|
```
|
|
164
208
|
|
|
209
|
+
### Armadilhas conhecidas
|
|
210
|
+
|
|
211
|
+
- **`addAchievement` sem `id`/`time`** → registro inconsistente. Correção: setar ambos (`java-entities.md` §3).
|
|
212
|
+
|
|
165
213
|
---
|
|
166
214
|
|
|
167
|
-
## CatalogManager
|
|
215
|
+
## 5. CatalogManager
|
|
168
216
|
|
|
169
|
-
|
|
217
|
+
Quando usar: processar compras, validar requisitos, gerir itens da loja.
|
|
218
|
+
Não usar quando: precisar dos campos de CatalogItem → `java-entities.md` §7.
|
|
219
|
+
Depende de: `CatalogItem`, `Achievement`, `Requirement`, `Principal`, `Jongo`.
|
|
170
220
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
221
|
+
### Descrição
|
|
222
|
+
|
|
223
|
+
Gestão da loja virtual. Acesso: `manager.getCatalogManager()`.
|
|
224
|
+
|
|
225
|
+
### Uso
|
|
174
226
|
|
|
175
227
|
| Método | Retorno | Descrição |
|
|
176
228
|
|--------|---------|-----------|
|
|
177
|
-
| `findItemById(String id)` | CatalogItem |
|
|
178
|
-
| `findAllItems()` | Iterable\<CatalogItem\> | Lista todos
|
|
229
|
+
| `findItemById(String id)` | CatalogItem | Item por ID |
|
|
230
|
+
| `findAllItems()` | Iterable\<CatalogItem\> | Lista todos |
|
|
179
231
|
| `findAllItemsByCatalogId(String catalogId)` | Iterable\<CatalogItem\> | Itens de um catálogo |
|
|
180
232
|
| `addItem(CatalogItem item)` | void | Adiciona item |
|
|
181
233
|
| `updateItem(CatalogItem item)` | void | Atualiza item |
|
|
@@ -183,265 +235,301 @@ CatalogManager cm = manager.getCatalogManager();
|
|
|
183
235
|
| `purchase(Achievement purchase, boolean async)` | Map | Processa compra |
|
|
184
236
|
| `undoPurchase(String id)` | void | Estorna compra |
|
|
185
237
|
| `findMissingRequirements(String player, String item)` | List\<Requirement\> | Requisitos faltantes |
|
|
186
|
-
| `findValidRandom(String player, String q)` | CatalogItem | Item aleatório válido
|
|
187
|
-
| `isValid(CatalogItem item, int total, String player, Principal principal, Jongo jongo)` | boolean | Valida se
|
|
188
|
-
|
|
189
|
-
**Exemplos:**
|
|
238
|
+
| `findValidRandom(String player, String q)` | CatalogItem | Item aleatório válido |
|
|
239
|
+
| `isValid(CatalogItem item, int total, String player, Principal principal, Jongo jongo)` | boolean | Valida se pode comprar |
|
|
190
240
|
|
|
191
241
|
```java
|
|
192
|
-
// Comprar item para jogador
|
|
193
242
|
Achievement purchase = new Achievement();
|
|
194
|
-
purchase.
|
|
243
|
+
purchase.id = Guid.newShortGuid();
|
|
195
244
|
purchase.player = "john";
|
|
196
|
-
purchase.item = "DTj7lVn";
|
|
245
|
+
purchase.item = "DTj7lVn";
|
|
197
246
|
purchase.total = 1;
|
|
198
|
-
purchase.type = Achievement.TYPE_VIRTUAL_GOOD;
|
|
247
|
+
purchase.type = Achievement.TYPE_VIRTUAL_GOOD; // 2
|
|
199
248
|
purchase.time = new Date();
|
|
200
249
|
manager.getCatalogManager().purchase(purchase, true);
|
|
201
|
-
|
|
202
|
-
// Estornar compra
|
|
203
|
-
manager.getCatalogManager().undoPurchase("achievement_id");
|
|
204
250
|
```
|
|
205
251
|
|
|
252
|
+
### Armadilhas conhecidas
|
|
253
|
+
|
|
254
|
+
- **Comprar sem validar requisitos** → compra inválida pode passar. Correção: `isValid`/`findMissingRequirements` antes.
|
|
255
|
+
|
|
206
256
|
---
|
|
207
257
|
|
|
208
|
-
## ChallengeManager
|
|
258
|
+
## 6. ChallengeManager
|
|
209
259
|
|
|
210
|
-
|
|
260
|
+
Quando usar: CRUD de desafios, descrição em linguagem natural.
|
|
261
|
+
Não usar quando: precisar dos campos de Challenge → `java-entities.md` §6.
|
|
262
|
+
Depende de: `Challenge`.
|
|
211
263
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
264
|
+
### Descrição
|
|
265
|
+
|
|
266
|
+
Gestão de desafios e missões. Acesso: `manager.getChallengeManager()`.
|
|
267
|
+
|
|
268
|
+
### Uso
|
|
215
269
|
|
|
216
270
|
| Método | Retorno | Descrição |
|
|
217
271
|
|--------|---------|-----------|
|
|
218
|
-
| `findById(String id)` | Challenge |
|
|
219
|
-
| `findAll()` | Iterable\<Challenge\> | Lista todos
|
|
220
|
-
| `add(Challenge challenge)` | void | Cria
|
|
221
|
-
| `update(Challenge challenge)` | void | Atualiza
|
|
222
|
-
| `delete(String id)` | void | Remove
|
|
272
|
+
| `findById(String id)` | Challenge | Desafio por ID |
|
|
273
|
+
| `findAll()` | Iterable\<Challenge\> | Lista todos |
|
|
274
|
+
| `add(Challenge challenge)` | void | Cria |
|
|
275
|
+
| `update(Challenge challenge)` | void | Atualiza |
|
|
276
|
+
| `delete(String id)` | void | Remove |
|
|
223
277
|
| `describe(Challenge challenge, String lang)` | String | Descrição em linguagem natural |
|
|
224
278
|
|
|
279
|
+
### Armadilhas conhecidas
|
|
280
|
+
|
|
281
|
+
- **Editar regras via `/v3/database/challenge`** → use o manager (`java-entities.md` §6).
|
|
282
|
+
|
|
225
283
|
---
|
|
226
284
|
|
|
227
|
-
## LevelManager
|
|
285
|
+
## 7. LevelManager
|
|
228
286
|
|
|
229
|
-
|
|
287
|
+
Quando usar: CRUD de níveis, cálculo de nível atual/próximo por pontos.
|
|
288
|
+
Não usar quando: precisar dos campos de Level → `java-entities.md` §8.
|
|
289
|
+
Depende de: `Level`, `LevelConfig`.
|
|
230
290
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
291
|
+
### Descrição
|
|
292
|
+
|
|
293
|
+
Gestão de níveis de progressão. Acesso: `manager.getLevelManager()`.
|
|
294
|
+
|
|
295
|
+
### Uso
|
|
234
296
|
|
|
235
297
|
| Método | Retorno | Descrição |
|
|
236
298
|
|--------|---------|-----------|
|
|
237
|
-
| `findById(String id)` | Level |
|
|
238
|
-
| `findAll()` | Iterable\<Level\> | Lista todos
|
|
299
|
+
| `findById(String id)` | Level | Nível por ID |
|
|
300
|
+
| `findAll()` | Iterable\<Level\> | Lista todos |
|
|
239
301
|
| `findConfig()` | LevelConfig | Configuração de níveis |
|
|
240
302
|
| `findCurrentByPoints(int points)` | Level | Nível atual para X pontos |
|
|
241
303
|
| `findNextByPoints(int points)` | Level | Próximo nível para X pontos |
|
|
242
|
-
| `add(Level level)` | void | Cria
|
|
243
|
-
| `update(Level level)` | void | Atualiza
|
|
244
|
-
| `delete(String id)` | void | Remove
|
|
304
|
+
| `add(Level level)` | void | Cria |
|
|
305
|
+
| `update(Level level)` | void | Atualiza |
|
|
306
|
+
| `delete(String id)` | void | Remove |
|
|
245
307
|
|
|
246
308
|
---
|
|
247
309
|
|
|
248
|
-
## TeamManager
|
|
310
|
+
## 8. TeamManager
|
|
249
311
|
|
|
250
|
-
|
|
312
|
+
Quando usar: CRUD de equipes, vincular/remover membros, consultar associações.
|
|
313
|
+
Não usar quando: precisar dos campos de Team → `java-entities.md` §8.
|
|
314
|
+
Depende de: `Team`.
|
|
251
315
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
316
|
+
### Descrição
|
|
317
|
+
|
|
318
|
+
Gestão de equipes e grupos. Acesso: `manager.getTeamManager()`.
|
|
319
|
+
|
|
320
|
+
### Uso
|
|
255
321
|
|
|
256
322
|
| Método | Retorno | Descrição |
|
|
257
323
|
|--------|---------|-----------|
|
|
258
|
-
| `findById(String id)` | Team |
|
|
259
|
-
| `findAll()` | Iterable\<Team\> | Lista todas
|
|
260
|
-
| `add(Team team)` | void | Cria
|
|
261
|
-
| `update(Team team)` | void | Atualiza
|
|
262
|
-
| `delete(String id)` | void | Remove
|
|
263
|
-
| `linkUser(Team team, String userId)` | void | Vincula jogador
|
|
264
|
-
| `removeUsers(String[] userIds, String teamId)` | void | Remove jogadores
|
|
324
|
+
| `findById(String id)` | Team | Equipe por ID |
|
|
325
|
+
| `findAll()` | Iterable\<Team\> | Lista todas |
|
|
326
|
+
| `add(Team team)` | void | Cria |
|
|
327
|
+
| `update(Team team)` | void | Atualiza |
|
|
328
|
+
| `delete(String id)` | void | Remove |
|
|
329
|
+
| `linkUser(Team team, String userId)` | void | Vincula jogador |
|
|
330
|
+
| `removeUsers(String[] userIds, String teamId)` | void | Remove jogadores |
|
|
265
331
|
| `findUserIdsByTeamId(String teamId)` | List\<String\> | IDs dos membros |
|
|
266
332
|
| `findTeamIdsByUserId(String userId)` | List\<String\> | Equipes do jogador |
|
|
267
|
-
| `isUserOfTeam(String userId, String teamId)` | boolean | Verifica
|
|
333
|
+
| `isUserOfTeam(String userId, String teamId)` | boolean | Verifica membro |
|
|
268
334
|
| `findByUserId(String userId)` | Iterable\<Team\> | Equipes do jogador |
|
|
269
335
|
|
|
336
|
+
### Armadilhas conhecidas
|
|
337
|
+
|
|
338
|
+
- **Escrever `player.teams` direto** → use `linkUser` (mantém os índices de associação).
|
|
339
|
+
|
|
270
340
|
---
|
|
271
341
|
|
|
272
|
-
## PointManager
|
|
342
|
+
## 9. PointManager
|
|
273
343
|
|
|
274
|
-
|
|
344
|
+
Quando usar: creditar/debitar/transferir pontos, CRUD de categorias.
|
|
345
|
+
Não usar quando: precisar dos campos de PointCategory → `java-entities.md` §8.
|
|
346
|
+
Depende de: `PointCategory`, `Point`.
|
|
275
347
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
348
|
+
### Descrição
|
|
349
|
+
|
|
350
|
+
Gestão de categorias de pontos e operações de crédito/débito. Acesso: `manager.getPointManager()`.
|
|
351
|
+
|
|
352
|
+
### Uso
|
|
279
353
|
|
|
280
354
|
| Método | Retorno | Descrição |
|
|
281
355
|
|--------|---------|-----------|
|
|
282
|
-
| `findById(String id)` | PointCategory |
|
|
356
|
+
| `findById(String id)` | PointCategory | Categoria por ID |
|
|
283
357
|
| `findAll()` | Iterable\<PointCategory\> | Lista categorias |
|
|
284
|
-
| `add(PointCategory point)` | void | Cria
|
|
285
|
-
| `update(PointCategory point)` | void | Atualiza
|
|
286
|
-
| `delete(String id)` | void | Remove
|
|
287
|
-
| `creditPoints(String categoryId, String userId, int total)` | void | Credita
|
|
288
|
-
| `debitPoints(String categoryId, String userId, int total)` | void | Debita
|
|
289
|
-
| `transferPoints(String fromUserId, int total, String categoryId, String toUserId)` | void | Transfere
|
|
358
|
+
| `add(PointCategory point)` | void | Cria |
|
|
359
|
+
| `update(PointCategory point)` | void | Atualiza |
|
|
360
|
+
| `delete(String id)` | void | Remove |
|
|
361
|
+
| `creditPoints(String categoryId, String userId, int total)` | void | Credita |
|
|
362
|
+
| `debitPoints(String categoryId, String userId, int total)` | void | Debita |
|
|
363
|
+
| `transferPoints(String fromUserId, int total, String categoryId, String toUserId)` | void | Transfere entre jogadores |
|
|
290
364
|
| `findByUserId(String userId)` | Iterable\<Point\> | Pontos do jogador |
|
|
291
365
|
|
|
292
|
-
**Exemplos:**
|
|
293
|
-
|
|
294
366
|
```java
|
|
295
|
-
// Creditar pontos
|
|
296
367
|
manager.getPointManager().creditPoints("xp", "john", 100);
|
|
297
|
-
|
|
298
|
-
// Transferir pontos entre jogadores
|
|
299
368
|
manager.getPointManager().transferPoints("john", 50, "coins", "maria");
|
|
300
369
|
```
|
|
301
370
|
|
|
371
|
+
### Armadilhas conhecidas
|
|
372
|
+
|
|
373
|
+
- **Confundir crédito de ponto com `addAchievement`** → ambos afetam saldo; `creditPoints` é a via direta para a categoria.
|
|
374
|
+
|
|
302
375
|
---
|
|
303
376
|
|
|
304
|
-
## LotteryManager
|
|
377
|
+
## 10. LotteryManager
|
|
305
378
|
|
|
306
|
-
|
|
379
|
+
Quando usar: gerir sorteios, adicionar tickets, executar.
|
|
380
|
+
Não usar quando: precisar dos campos de Lottery → `java-entities.md` §9.
|
|
381
|
+
Depende de: `Lottery`, `LotteryTicket`, `Participant`.
|
|
307
382
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
383
|
+
### Descrição
|
|
384
|
+
|
|
385
|
+
Gestão de sorteios e rifas. Acesso: `manager.getLotteryManager()`.
|
|
386
|
+
|
|
387
|
+
### Uso
|
|
311
388
|
|
|
312
389
|
| Método | Retorno | Descrição |
|
|
313
390
|
|--------|---------|-----------|
|
|
314
|
-
| `find(String id)` | Lottery |
|
|
315
|
-
| `findAll()` | Iterable\<Lottery\> | Lista todos
|
|
316
|
-
| `insert(Lottery lottery)` | void | Cria ou atualiza
|
|
317
|
-
| `delete(String id)` | void | Remove
|
|
318
|
-
| `insertTicket(LotteryTicket ticket)` | void | Adiciona ticket
|
|
391
|
+
| `find(String id)` | Lottery | Sorteio por ID |
|
|
392
|
+
| `findAll()` | Iterable\<Lottery\> | Lista todos |
|
|
393
|
+
| `insert(Lottery lottery)` | void | Cria ou atualiza |
|
|
394
|
+
| `delete(String id)` | void | Remove |
|
|
395
|
+
| `insertTicket(LotteryTicket ticket)` | void | Adiciona ticket |
|
|
319
396
|
| `deleteTicket(String id)` | void | Remove ticket |
|
|
320
397
|
| `execute(String id)` | Iterable\<LotteryTicket\> | Executa sorteio |
|
|
321
|
-
| `undoExecute(String id)` | void | Estorna
|
|
322
|
-
| `findParticipants(String lottery)` | Iterable\<Participant\> | Participantes
|
|
398
|
+
| `undoExecute(String id)` | void | Estorna |
|
|
399
|
+
| `findParticipants(String lottery)` | Iterable\<Participant\> | Participantes |
|
|
323
400
|
| `checkRestrictions(String lottery, String player)` | List\<String\> | Verifica restrições |
|
|
324
401
|
|
|
325
402
|
---
|
|
326
403
|
|
|
327
|
-
## CompetitionManager
|
|
404
|
+
## 11. CompetitionManager
|
|
328
405
|
|
|
329
|
-
|
|
406
|
+
Quando usar: gerir competições, inscrever jogadores, executar e premiar.
|
|
407
|
+
Não usar quando: precisar dos campos de Competition → `java-entities.md` §9.
|
|
408
|
+
Depende de: `Competition`, `CompetitionJoin`, `Achievement`.
|
|
330
409
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
410
|
+
### Descrição
|
|
411
|
+
|
|
412
|
+
Gestão de competições entre jogadores. Acesso: `manager.getCompetitionManager()`.
|
|
413
|
+
|
|
414
|
+
### Uso
|
|
334
415
|
|
|
335
416
|
| Método | Retorno | Descrição |
|
|
336
417
|
|--------|---------|-----------|
|
|
337
|
-
| `find(String id)` | Competition |
|
|
338
|
-
| `insert(Competition competition)` | void | Cria ou atualiza
|
|
339
|
-
| `delete(String id)` | void | Remove
|
|
418
|
+
| `find(String id)` | Competition | Competição por ID |
|
|
419
|
+
| `insert(Competition competition)` | void | Cria ou atualiza |
|
|
420
|
+
| `delete(String id)` | void | Remove |
|
|
340
421
|
| `insertJoin(CompetitionJoin join)` | Map | Inscreve jogador |
|
|
341
422
|
| `deleteJoin(CompetitionJoin join)` | void | Remove inscrição |
|
|
342
|
-
| `execute(String id)` | List\<Achievement\> | Executa e premia
|
|
343
|
-
| `undoExecute(String id)` | void | Estorna
|
|
423
|
+
| `execute(String id)` | List\<Achievement\> | Executa e premia |
|
|
424
|
+
| `undoExecute(String id)` | void | Estorna |
|
|
344
425
|
| `findLeaders(String id, String range)` | Map | Ranking da competição |
|
|
345
426
|
|
|
346
427
|
---
|
|
347
428
|
|
|
348
|
-
## MysteryBoxManager
|
|
429
|
+
## 12. MysteryBoxManager
|
|
349
430
|
|
|
350
|
-
|
|
431
|
+
Quando usar: gerir e abrir caixas surpresa.
|
|
432
|
+
Não usar quando: precisar dos campos de MysteryBox → `java-entities.md` §9.
|
|
433
|
+
Depende de: `MysteryBox`, `MysteryResult`.
|
|
351
434
|
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
435
|
+
### Descrição
|
|
436
|
+
|
|
437
|
+
Gestão de caixas surpresa. Acesso: `manager.getMysteryBoxManager()`.
|
|
438
|
+
|
|
439
|
+
### Uso
|
|
355
440
|
|
|
356
441
|
| Método | Retorno | Descrição |
|
|
357
442
|
|--------|---------|-----------|
|
|
358
|
-
| `find(String id)` | MysteryBox |
|
|
359
|
-
| `findAll()` | Iterable\<MysteryBox\> | Lista todas
|
|
360
|
-
| `insert(MysteryBox mystery)` | void | Cria ou atualiza
|
|
361
|
-
| `delete(String id)` | void | Remove
|
|
443
|
+
| `find(String id)` | MysteryBox | Caixa por ID |
|
|
444
|
+
| `findAll()` | Iterable\<MysteryBox\> | Lista todas |
|
|
445
|
+
| `insert(MysteryBox mystery)` | void | Cria ou atualiza |
|
|
446
|
+
| `delete(String id)` | void | Remove |
|
|
362
447
|
| `execute(String id, String player)` | MysteryResult | Abre caixa para jogador |
|
|
363
448
|
| `undoExecute(String achievementId)` | void | Estorna abertura |
|
|
364
449
|
|
|
365
450
|
---
|
|
366
451
|
|
|
367
|
-
## QuestionManager
|
|
452
|
+
## 13. QuestionManager / QuizManager
|
|
368
453
|
|
|
369
|
-
|
|
454
|
+
Quando usar: gerir perguntas/quizzes e registrar respostas/tentativas.
|
|
455
|
+
Não usar quando: precisar dos campos de Question/Quiz → `java-entities.md` §9.
|
|
456
|
+
Depende de: `Question`, `QuestionLog`, `Quiz`, `QuizLog`.
|
|
370
457
|
|
|
371
|
-
|
|
372
|
-
QuestionManager qm = manager.getQuestionManager();
|
|
373
|
-
```
|
|
458
|
+
### Descrição
|
|
374
459
|
|
|
375
|
-
|
|
376
|
-
|--------|---------|-----------|
|
|
377
|
-
| `find(String id)` | Question | Busca pergunta por ID |
|
|
378
|
-
| `insert(Question question)` | List\<String\> | Cria pergunta |
|
|
379
|
-
| `delete(String id)` | void | Remove pergunta |
|
|
380
|
-
| `insertLog(QuestionLog log, String async)` | Map | Registra resposta ("sync"/"async") |
|
|
381
|
-
| `deleteLog(String id)` | void | Remove resposta |
|
|
382
|
-
| `findRandomNotAnsweredForPlayer(String player, String q, String answered_min, String answered_max)` | Question | Pergunta aleatória não respondida |
|
|
460
|
+
Gestão de perguntas (`manager.getQuestionManager()`) e questionários completos (`manager.getQuizManager()`).
|
|
383
461
|
|
|
384
|
-
|
|
462
|
+
### Uso
|
|
385
463
|
|
|
386
|
-
|
|
464
|
+
**QuestionManager**
|
|
387
465
|
|
|
388
|
-
|
|
466
|
+
| Método | Retorno | Descrição |
|
|
467
|
+
|--------|---------|-----------|
|
|
468
|
+
| `find(String id)` | Question | Pergunta por ID |
|
|
469
|
+
| `insert(Question question)` | List\<String\> | Cria |
|
|
470
|
+
| `delete(String id)` | void | Remove |
|
|
471
|
+
| `insertLog(QuestionLog log, String async)` | Map | Registra resposta (`"sync"`/`"async"`) |
|
|
472
|
+
| `deleteLog(String id)` | void | Remove resposta |
|
|
473
|
+
| `findRandomNotAnsweredForPlayer(String player, String q, String answered_min, String answered_max)` | Question | Aleatória não respondida |
|
|
389
474
|
|
|
390
|
-
|
|
391
|
-
QuizManager quizm = manager.getQuizManager();
|
|
392
|
-
```
|
|
475
|
+
**QuizManager**
|
|
393
476
|
|
|
394
477
|
| Método | Retorno | Descrição |
|
|
395
478
|
|--------|---------|-----------|
|
|
396
|
-
| `find(String id)` | Quiz |
|
|
397
|
-
| `insert(Quiz quiz)` | void | Cria ou atualiza
|
|
398
|
-
| `delete(String id)` | void | Remove
|
|
479
|
+
| `find(String id)` | Quiz | Quiz por ID |
|
|
480
|
+
| `insert(Quiz quiz)` | void | Cria ou atualiza |
|
|
481
|
+
| `delete(String id)` | void | Remove |
|
|
399
482
|
| `startLog(QuizLog log)` | Map | Inicia tentativa |
|
|
400
483
|
| `finishLog(String id, String async)` | Map | Finaliza e calcula pontuação |
|
|
401
484
|
| `deleteLog(String id)` | void | Remove tentativa |
|
|
402
485
|
|
|
403
486
|
---
|
|
404
487
|
|
|
405
|
-
## LeaderBoardManager
|
|
488
|
+
## 14. LeaderBoardManager
|
|
406
489
|
|
|
407
|
-
|
|
490
|
+
Quando usar: CRUD de rankings.
|
|
491
|
+
Não usar quando: precisar de queries de ranking customizadas → `aggregates.md`.
|
|
492
|
+
Depende de: `LeaderBoard_V2`.
|
|
408
493
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
494
|
+
### Descrição
|
|
495
|
+
|
|
496
|
+
Gestão de rankings e classificações. Acesso: `manager.getLeaderBoardManager()`.
|
|
497
|
+
|
|
498
|
+
### Uso
|
|
412
499
|
|
|
413
500
|
| Método | Retorno | Descrição |
|
|
414
501
|
|--------|---------|-----------|
|
|
415
|
-
| `findById(String id)` | LeaderBoard_V2 |
|
|
416
|
-
| `findAll()` | Iterable\<LeaderBoard_V2\> | Lista todos
|
|
417
|
-
| `addLeaderboard(LeaderBoard_V2 board)` | void | Cria ou atualiza
|
|
418
|
-
| `delete(String id)` | void | Remove
|
|
502
|
+
| `findById(String id)` | LeaderBoard_V2 | Leaderboard por ID |
|
|
503
|
+
| `findAll()` | Iterable\<LeaderBoard_V2\> | Lista todos |
|
|
504
|
+
| `addLeaderboard(LeaderBoard_V2 board)` | void | Cria ou atualiza |
|
|
505
|
+
| `delete(String id)` | void | Remove |
|
|
419
506
|
|
|
420
507
|
---
|
|
421
508
|
|
|
422
|
-
## NotificationManager
|
|
509
|
+
## 15. NotificationManager
|
|
423
510
|
|
|
424
|
-
|
|
511
|
+
Quando usar: enviar notificações in-app/push, consultar não lidas.
|
|
512
|
+
Não usar quando: precisar enviar **email** → `java-libraries.md` §EmailBuilder.
|
|
513
|
+
Depende de: `Notification`.
|
|
425
514
|
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
515
|
+
### Descrição
|
|
516
|
+
|
|
517
|
+
Envio de notificações para jogadores. Acesso: `manager.getNotificationManager()`.
|
|
518
|
+
|
|
519
|
+
### Uso
|
|
429
520
|
|
|
430
521
|
| Método | Retorno | Descrição |
|
|
431
522
|
|--------|---------|-----------|
|
|
432
|
-
| `send(Notification notification)` | void | Envia
|
|
433
|
-
| `sendPrivate(Notification notification)` | void | Envia
|
|
434
|
-
| `sendPublic(Notification notification)` | void | Envia
|
|
435
|
-
| `receiveNotification(String userId)` | List\<Notification\> |
|
|
523
|
+
| `send(Notification notification)` | void | Envia |
|
|
524
|
+
| `sendPrivate(Notification notification)` | void | Envia privada |
|
|
525
|
+
| `sendPublic(Notification notification)` | void | Envia pública |
|
|
526
|
+
| `receiveNotification(String userId)` | List\<Notification\> | Notificações do jogador |
|
|
436
527
|
| `deleteByPlayer(String player)` | void | Remove notificações do jogador |
|
|
437
528
|
| `totalUnreadPrivateMessages(String player, String published_min, String published_max)` | long | Total de não lidas |
|
|
438
529
|
|
|
439
|
-
**Exemplos:**
|
|
440
|
-
|
|
441
530
|
```java
|
|
442
|
-
// Enviar notificação
|
|
443
531
|
Notification n = new Notification();
|
|
444
|
-
n.
|
|
532
|
+
n.id = Guid.newShortGuid(); // Groovy: .id
|
|
445
533
|
n.player = "john";
|
|
446
534
|
n.title = "Parabéns!";
|
|
447
535
|
n.message = "Você completou o desafio!";
|
|
@@ -451,59 +539,49 @@ manager.getNotificationManager().send(n);
|
|
|
451
539
|
|
|
452
540
|
---
|
|
453
541
|
|
|
454
|
-
## SwapManager
|
|
542
|
+
## 16. SwapManager
|
|
455
543
|
|
|
456
|
-
|
|
544
|
+
Quando usar: gerir ofertas de troca entre jogadores.
|
|
545
|
+
Não usar quando: precisar dos campos de Swap → `java-entities.md` §9.
|
|
546
|
+
Depende de: `Swap`, `SwapCounterOffer`.
|
|
457
547
|
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
548
|
+
### Descrição
|
|
549
|
+
|
|
550
|
+
Gestão de trocas entre jogadores. Acesso: `manager.getSwapManager()`.
|
|
551
|
+
|
|
552
|
+
### Uso
|
|
461
553
|
|
|
462
554
|
| Método | Retorno | Descrição |
|
|
463
555
|
|--------|---------|-----------|
|
|
464
|
-
| `find(String id)` | Swap |
|
|
465
|
-
| `insert(Swap swap, String author)` | Map | Cria oferta
|
|
466
|
-
| `delete(String id)` | Map | Remove
|
|
556
|
+
| `find(String id)` | Swap | Troca por ID |
|
|
557
|
+
| `insert(Swap swap, String author)` | Map | Cria oferta |
|
|
558
|
+
| `delete(String id)` | Map | Remove |
|
|
467
559
|
| `buyerAcquire(String id, String buyer, String author, Map extra)` | Map | Comprador aceita |
|
|
468
560
|
| `sellerReceive(String id)` | Map | Vendedor recebe |
|
|
469
561
|
| `counterOfferInsert(SwapCounterOffer offer, String author)` | Map | Cria contra-oferta |
|
|
470
562
|
|
|
471
563
|
---
|
|
472
564
|
|
|
473
|
-
## Acesso Direto ao Banco (Jongo)
|
|
565
|
+
## 17. Acesso Direto ao Banco (Jongo)
|
|
474
566
|
|
|
475
|
-
|
|
567
|
+
Quando usar: ler/escrever coleções sem manager dedicado (ex: `__c`), ou queries/aggregates.
|
|
568
|
+
Não usar quando: existir um manager para a operação → seções acima.
|
|
569
|
+
Depende de: `database-access.md`.
|
|
570
|
+
|
|
571
|
+
### Descrição
|
|
572
|
+
|
|
573
|
+
`manager.getJongoConnection()` retorna a conexão Jongo para acesso direto ao MongoDB.
|
|
574
|
+
|
|
575
|
+
### Uso
|
|
576
|
+
|
|
577
|
+
> Operações completas (find, save, remove, count, aggregate, placeholders `#`) em **`datasource-funifier-docs/knowledge/guides/database-access.md`** (dono único).
|
|
476
578
|
|
|
477
579
|
```java
|
|
478
|
-
// Obter conexão
|
|
479
580
|
Jongo jongo = manager.getJongoConnection();
|
|
480
|
-
|
|
481
|
-
// Salvar documento
|
|
581
|
+
Object p = jongo.getCollection("player").findOne("{_id: #}", "john").as(Map.class);
|
|
482
582
|
jongo.getCollection("email__c").save(documento);
|
|
483
|
-
|
|
484
|
-
// Buscar documento
|
|
485
|
-
Object result = jongo.getCollection("player")
|
|
486
|
-
.findOne("{_id: 'john'}").as(Map.class);
|
|
487
|
-
|
|
488
|
-
// Buscar com parâmetros
|
|
489
|
-
Object result = jongo.getCollection("product__c")
|
|
490
|
-
.findOne("{_id: #}", productId).as(Object.class);
|
|
491
|
-
|
|
492
|
-
// Listar com filtro
|
|
493
|
-
Iterable<Map> items = jongo.getCollection("action_log")
|
|
494
|
-
.find("{userId: #, actionId: #}", "john", "sell")
|
|
495
|
-
.as(Map.class);
|
|
496
|
-
|
|
497
|
-
// Deletar
|
|
498
|
-
jongo.getCollection("car__c").remove("{_id: 'car001'}");
|
|
499
|
-
|
|
500
|
-
// Aggregate
|
|
501
|
-
Iterable<Map> result = jongo.getCollection("achievement")
|
|
502
|
-
.aggregate("{$match: {type: 0, item: 'xp'}}")
|
|
503
|
-
.and("{$group: {_id: '$player', total: {$sum: '$total'}}}")
|
|
504
|
-
.and("{$sort: {total: -1}}")
|
|
505
|
-
.and("{$limit: 10}")
|
|
506
|
-
.as(Map.class);
|
|
507
583
|
```
|
|
508
584
|
|
|
509
|
-
|
|
585
|
+
### Armadilhas conhecidas
|
|
586
|
+
|
|
587
|
+
- **Usar Jongo onde há manager** → perde validações de domínio. Prefira o manager quando existir.
|