@muvtacode/cli 0.1.9 → 0.1.11
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/README.md +175 -147
- package/dist/agent/loop.js +4 -1
- package/dist/agent/loop.js.map +1 -1
- package/dist/agent/prompt.js +101 -0
- package/dist/agent/prompt.js.map +1 -1
- package/dist/cli.js +103 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/index.js +28 -0
- package/dist/commands/index.js.map +1 -1
- package/dist/i18n/en.js +4 -0
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/pt.js +4 -0
- package/dist/i18n/pt.js.map +1 -1
- package/dist/remote/claudeSessions.js +82 -0
- package/dist/remote/claudeSessions.js.map +1 -0
- package/dist/remote/host.js +607 -0
- package/dist/remote/host.js.map +1 -0
- package/dist/remote/passagem.js +558 -0
- package/dist/remote/passagem.js.map +1 -0
- package/dist/remote/pastas.js +156 -0
- package/dist/remote/pastas.js.map +1 -0
- package/dist/state/templates.js +43 -10
- package/dist/state/templates.js.map +1 -1
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/AssaultRifle_1.mtl +42 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/AssaultRifle_1.obj +1472 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Grip.mtl +12 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Grip.obj +890 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/LICENCA.txt +25 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Pistol_1.mtl +52 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Pistol_1.obj +1444 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Pistol_4.mtl +32 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Pistol_4.obj +1789 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Revolver_1.mtl +32 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Revolver_1.obj +1273 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Scope_1.mtl +32 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Scope_1.obj +485 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Shotgun_1.mtl +42 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Shotgun_1.obj +1589 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Silencer_1.mtl +12 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Silencer_1.obj +309 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/SniperRifle_1.mtl +52 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/SniperRifle_1.obj +1681 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/SubmachineGun_1.mtl +42 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/SubmachineGun_1.obj +1275 -0
- package/dist/templates/game/adapt-assets-3d-01/files/src/assets/modelos.ts +270 -0
- package/dist/templates/game/adapt-assets-3d-01/meta.json +30 -0
- package/dist/templates/game/adapt-audio-01/files/src/audio/audio.ts +123 -6
- package/dist/templates/game/adapt-audio-01/meta.json +47 -34
- package/dist/templates/game/adapt-camera-rig-01/files/src/camera/rig.ts +226 -55
- package/dist/templates/game/adapt-camera-rig-01/meta.json +53 -38
- package/dist/templates/game/adapt-controle-teclado-01/files/src/controles/teclado.ts +175 -171
- package/dist/templates/game/adapt-controle-teclado-01/meta.json +36 -34
- package/dist/templates/game/adapt-controle-toque-01/files/src/controles/toque.ts +152 -36
- package/dist/templates/game/adapt-controle-toque-01/meta.json +43 -36
- package/dist/templates/game/adapt-dia-noite-01/files/src/world/dianoite.ts +274 -53
- package/dist/templates/game/adapt-dia-noite-01/meta.json +21 -9
- package/dist/templates/game/adapt-hud-01/files/src/hud/hud.ts +859 -263
- package/dist/templates/game/adapt-hud-01/meta.json +69 -36
- package/dist/templates/game/adapt-menu-01/files/src/ui/menu.ts +427 -273
- package/dist/templates/game/adapt-menu-01/meta.json +41 -36
- package/dist/templates/game/adapt-particulas-01/files/src/vfx/particulas.ts +107 -39
- package/dist/templates/game/adapt-particulas-01/meta.json +50 -38
- package/dist/templates/game/adapt-perf-mobile-01/files/src/engine/performance.ts +108 -33
- package/dist/templates/game/adapt-perf-mobile-01/meta.json +20 -6
- package/dist/templates/game/adapt-primeira-pessoa-01/files/src/camera/primeirapessoa.ts +595 -0
- package/dist/templates/game/adapt-primeira-pessoa-01/meta.json +63 -0
- package/dist/templates/game/estruturas-3d-01/files/src/world/estruturas.ts +490 -0
- package/dist/templates/game/estruturas-3d-01/meta.json +13 -0
- package/dist/templates/game/fps-3d-01/files/src/fps/arena.ts +324 -0
- package/dist/templates/game/fps-3d-01/files/src/fps/armas.ts +398 -0
- package/dist/templates/game/fps-3d-01/files/src/fps/cena.ts +801 -0
- package/dist/templates/game/fps-3d-01/files/src/fps/coletaveis.ts +129 -0
- package/dist/templates/game/fps-3d-01/files/src/fps/fisica.ts +257 -0
- package/dist/templates/game/fps-3d-01/files/src/fps/inimigos.ts +608 -0
- package/dist/templates/game/fps-3d-01/files/src/fps/jogador.ts +224 -0
- package/dist/templates/game/fps-3d-01/files/src/main.ts +21 -0
- package/dist/templates/game/fps-3d-01/meta.json +48 -0
- package/dist/templates/game/game-engine-base-01/files/index.html +37 -0
- package/dist/templates/game/game-engine-base-01/files/package.json +19 -0
- package/dist/templates/game/game-engine-base-01/files/src/engine/engine.ts +22 -2
- package/dist/templates/game/game-engine-base-01/files/src/engine/index.ts +22 -2
- package/dist/templates/game/game-engine-base-01/files/src/engine/input.ts +430 -58
- package/dist/templates/game/game-engine-base-01/files/src/engine/layout.ts +192 -0
- package/dist/templates/game/game-engine-base-01/files/tsconfig.json +14 -0
- package/dist/templates/game/game-engine-base-01/files/vite.config.ts +10 -0
- package/dist/templates/game/game-engine-base-01/meta.json +70 -13
- package/dist/templates/game/mundo-3d-01/files/src/world/mundo3d.ts +2953 -73
- package/dist/templates/game/mundo-3d-01/meta.json +125 -6
- package/dist/templates/game/npc-3d-01/files/src/ai/npc3d.ts +658 -0
- package/dist/templates/game/npc-3d-01/meta.json +13 -0
- package/dist/templates/game/personagem-3d-01/files/src/models/personagem3d.ts +428 -107
- package/dist/templates/game/personagem-3d-01/meta.json +60 -6
- package/package.json +2 -1
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Armas: dados, munição, dispersão e modelos.
|
|
3
|
+
//
|
|
4
|
+
// Cada arma é uma TABELA (`ARMAS`), não uma classe. Balancear o jogo é mexer em
|
|
5
|
+
// números com nome — dano, cadência, dispersão, recuo — sem caçar valor mágico
|
|
6
|
+
// no meio do código de tiro. Para criar uma arma nova: copie uma entrada,
|
|
7
|
+
// mude os números e ponha o id em `new Arsenal([...])`.
|
|
8
|
+
//
|
|
9
|
+
// A sensação de cada arma vem de quatro números trabalhando juntos:
|
|
10
|
+
// dispersão (o cone onde a bala pode sair), "bloom" (o cone ABRE a cada tiro
|
|
11
|
+
// e fecha sozinho), recuo (a mira sobe — parte volta, parte fica) e queda de
|
|
12
|
+
// dano com a distância (escopeta é rainha de perto e inútil de longe).
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
|
|
15
|
+
import * as THREE from 'three';
|
|
16
|
+
import { getPalette } from '../design/tokens';
|
|
17
|
+
import { criarArmaProcedural } from '../camera/primeirapessoa';
|
|
18
|
+
import type { InfoMunicao } from '../hud/hud';
|
|
19
|
+
|
|
20
|
+
export type IdArma = 'pistola' | 'fuzil' | 'escopeta';
|
|
21
|
+
|
|
22
|
+
export interface DefArma {
|
|
23
|
+
id: IdArma;
|
|
24
|
+
nome: string;
|
|
25
|
+
/** Dano por projétil até `quedaInicio` metros. */
|
|
26
|
+
dano: number;
|
|
27
|
+
/** Tiros por segundo. */
|
|
28
|
+
cadencia: number;
|
|
29
|
+
/** true = segurar o gatilho dispara em rajada. */
|
|
30
|
+
automatica: boolean;
|
|
31
|
+
pente: number;
|
|
32
|
+
reservaInicial: number;
|
|
33
|
+
reservaMaxima: number;
|
|
34
|
+
/** Segundos de recarga (a animação do viewmodel usa o mesmo valor). */
|
|
35
|
+
tempoRecarga: number;
|
|
36
|
+
/** Projéteis por disparo — escopeta > 1. */
|
|
37
|
+
projeteis: number;
|
|
38
|
+
/** Meio-ângulo do cone de dispersão (rad) atirando do quadril / mirando. */
|
|
39
|
+
dispersaoQuadril: number;
|
|
40
|
+
dispersaoMira: number;
|
|
41
|
+
/** Extra (rad) correndo na velocidade máxima; proporcional à velocidade. */
|
|
42
|
+
dispersaoMovimento: number;
|
|
43
|
+
/** Quanto cada tiro ABRE o cone (rad). Fecha sozinho (`tuning.fechamentoBloom`). */
|
|
44
|
+
dispersaoPorTiro: number;
|
|
45
|
+
dispersaoMaxima: number;
|
|
46
|
+
/** Recuo na câmera (rad): vertical sobe a mira, horizontal sorteia o lado. */
|
|
47
|
+
recuoV: number;
|
|
48
|
+
recuoH: number;
|
|
49
|
+
/** Força do coice no viewmodel e do tremor de câmera. */
|
|
50
|
+
coice: number;
|
|
51
|
+
tremor: number;
|
|
52
|
+
alcance: number;
|
|
53
|
+
/** O dano cai de 100% em `quedaInicio` até `quedaMinima` (fração) em `quedaFim`. */
|
|
54
|
+
quedaInicio: number;
|
|
55
|
+
quedaFim: number;
|
|
56
|
+
quedaMinima: number;
|
|
57
|
+
/** Efeito do adapt-audio-01 (SFX_RUIDO). */
|
|
58
|
+
som: 'disparo' | 'disparoPesado';
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export const ARMAS: Record<IdArma, DefArma> = {
|
|
62
|
+
pistola: {
|
|
63
|
+
id: 'pistola', nome: 'Pistola', dano: 26, cadencia: 5, automatica: false,
|
|
64
|
+
pente: 12, reservaInicial: 60, reservaMaxima: 96, tempoRecarga: 1.15, projeteis: 1,
|
|
65
|
+
dispersaoQuadril: 0.012, dispersaoMira: 0.003, dispersaoMovimento: 0.02,
|
|
66
|
+
dispersaoPorTiro: 0.012, dispersaoMaxima: 0.06,
|
|
67
|
+
recuoV: 0.022, recuoH: 0.008, coice: 0.8, tremor: 0.02,
|
|
68
|
+
alcance: 120, quedaInicio: 18, quedaFim: 45, quedaMinima: 0.6, som: 'disparo'
|
|
69
|
+
},
|
|
70
|
+
fuzil: {
|
|
71
|
+
id: 'fuzil', nome: 'Fuzil', dano: 19, cadencia: 10, automatica: true,
|
|
72
|
+
pente: 30, reservaInicial: 120, reservaMaxima: 210, tempoRecarga: 1.9, projeteis: 1,
|
|
73
|
+
dispersaoQuadril: 0.018, dispersaoMira: 0.004, dispersaoMovimento: 0.03,
|
|
74
|
+
dispersaoPorTiro: 0.006, dispersaoMaxima: 0.07,
|
|
75
|
+
recuoV: 0.014, recuoH: 0.009, coice: 0.55, tremor: 0.018,
|
|
76
|
+
alcance: 150, quedaInicio: 30, quedaFim: 70, quedaMinima: 0.65, som: 'disparo'
|
|
77
|
+
},
|
|
78
|
+
escopeta: {
|
|
79
|
+
id: 'escopeta', nome: 'Escopeta', dano: 13, cadencia: 1.3, automatica: false,
|
|
80
|
+
pente: 6, reservaInicial: 24, reservaMaxima: 42, tempoRecarga: 2.3, projeteis: 9,
|
|
81
|
+
dispersaoQuadril: 0.075, dispersaoMira: 0.055, dispersaoMovimento: 0.02,
|
|
82
|
+
dispersaoPorTiro: 0, dispersaoMaxima: 0.09,
|
|
83
|
+
recuoV: 0.07, recuoH: 0.02, coice: 1.5, tremor: 0.06,
|
|
84
|
+
alcance: 45, quedaInicio: 8, quedaFim: 22, quedaMinima: 0.25, som: 'disparoPesado'
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export const tuning = {
|
|
89
|
+
/** Quanto o "bloom" fecha por segundo (rad/s). */
|
|
90
|
+
fechamentoBloom: 0.18,
|
|
91
|
+
/** Bloqueio de tiro durante a troca de arma (s) — casa com o tempoTroca do viewmodel. */
|
|
92
|
+
tempoTroca: 0.4
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/** Dano de um projétil na distância `dist`, com a queda da arma aplicada. */
|
|
96
|
+
export function danoNaDistancia(def: DefArma, dist: number): number {
|
|
97
|
+
if (dist <= def.quedaInicio) return def.dano;
|
|
98
|
+
if (dist >= def.quedaFim) return def.dano * def.quedaMinima;
|
|
99
|
+
const t = (dist - def.quedaInicio) / (def.quedaFim - def.quedaInicio);
|
|
100
|
+
return def.dano * (1 - t * (1 - def.quedaMinima));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const _direita = new THREE.Vector3();
|
|
104
|
+
const _cima = new THREE.Vector3();
|
|
105
|
+
/**
|
|
106
|
+
* Direção de um projétil dentro do cone de dispersão, sorteada uniformemente
|
|
107
|
+
* no DISCO (raiz quadrada no raio). Sem a raiz, as balas se amontoam no centro
|
|
108
|
+
* e a dispersão "mente" — o cone desenhado na mira não é o cone real.
|
|
109
|
+
* Atualize a matriz da câmera antes (`camera.updateMatrixWorld()`).
|
|
110
|
+
*/
|
|
111
|
+
export function direcaoComDispersao(
|
|
112
|
+
camera: THREE.Camera, dispersao: number, saida: THREE.Vector3
|
|
113
|
+
): THREE.Vector3 {
|
|
114
|
+
camera.getWorldDirection(saida);
|
|
115
|
+
if (dispersao <= 0) return saida;
|
|
116
|
+
_direita.setFromMatrixColumn(camera.matrixWorld, 0).normalize();
|
|
117
|
+
_cima.setFromMatrixColumn(camera.matrixWorld, 1).normalize();
|
|
118
|
+
const r = Math.tan(dispersao) * Math.sqrt(Math.random());
|
|
119
|
+
const a = Math.random() * Math.PI * 2;
|
|
120
|
+
return saida
|
|
121
|
+
.addScaledVector(_direita, Math.cos(a) * r)
|
|
122
|
+
.addScaledVector(_cima, Math.sin(a) * r)
|
|
123
|
+
.normalize();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// ------------------------------------------------------------------ arsenal
|
|
127
|
+
|
|
128
|
+
export interface EstadoArma {
|
|
129
|
+
def: DefArma;
|
|
130
|
+
pente: number;
|
|
131
|
+
reserva: number;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Munição, cadência, recarga e troca. Não sabe nada de tela nem de som: quem
|
|
136
|
+
* chama (cena.ts) é que toca o efeito e anima o viewmodel — assim dá para
|
|
137
|
+
* reaproveitar o arsenal num jogo de 3ª pessoa sem mexer aqui.
|
|
138
|
+
*/
|
|
139
|
+
export class Arsenal {
|
|
140
|
+
readonly armas: EstadoArma[];
|
|
141
|
+
indice = 0;
|
|
142
|
+
private espera = 0;
|
|
143
|
+
private recargaT = 0;
|
|
144
|
+
private bloom = 0;
|
|
145
|
+
|
|
146
|
+
constructor(private readonly ids: IdArma[] = ['fuzil', 'pistola', 'escopeta']) {
|
|
147
|
+
this.armas = ids.map((id) => {
|
|
148
|
+
const def = ARMAS[id];
|
|
149
|
+
return { def, pente: def.pente, reserva: def.reservaInicial };
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
get atual(): EstadoArma { return this.armas[this.indice]!; }
|
|
154
|
+
get recarregando(): boolean { return this.recargaT > 0; }
|
|
155
|
+
/** 0..1 da recarga em andamento, ou -1 se não está recarregando. */
|
|
156
|
+
get progressoRecarga(): number {
|
|
157
|
+
return this.recargaT > 0 ? 1 - this.recargaT / this.atual.def.tempoRecarga : -1;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** Um passo. Devolve true no passo em que a recarga terminou. */
|
|
161
|
+
atualizar(passo: number): boolean {
|
|
162
|
+
this.espera = Math.max(0, this.espera - passo);
|
|
163
|
+
this.bloom = Math.max(0, this.bloom - tuning.fechamentoBloom * passo);
|
|
164
|
+
if (this.recargaT <= 0) return false;
|
|
165
|
+
this.recargaT -= passo;
|
|
166
|
+
if (this.recargaT > 0) return false;
|
|
167
|
+
this.recargaT = 0;
|
|
168
|
+
const a = this.atual;
|
|
169
|
+
const falta = a.def.pente - a.pente;
|
|
170
|
+
const veio = Math.min(falta, a.reserva);
|
|
171
|
+
a.pente += veio;
|
|
172
|
+
a.reserva -= veio;
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Dispersão atual (rad). `mira` = fração de mira 0..1 (vm.fracaoMira),
|
|
178
|
+
* `movimento` = fração da velocidade máxima de corrida 0..1.
|
|
179
|
+
*/
|
|
180
|
+
dispersao(mira: number, movimento: number): number {
|
|
181
|
+
const d = this.atual.def;
|
|
182
|
+
const base = d.dispersaoQuadril + (d.dispersaoMira - d.dispersaoQuadril) * mira;
|
|
183
|
+
const mov = d.dispersaoMovimento * Math.min(1, movimento) * (1 - mira * 0.6);
|
|
184
|
+
return Math.min(d.dispersaoMaxima, base + mov + this.bloom);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** Pode disparar AGORA (cadência, recarga, troca)? Não olha a munição. */
|
|
188
|
+
pronta(): boolean {
|
|
189
|
+
return this.espera <= 0 && this.recargaT <= 0;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** Gasta uma bala e arma a cadência. false = pente vazio (toque o clique seco). */
|
|
193
|
+
disparar(): boolean {
|
|
194
|
+
const a = this.atual;
|
|
195
|
+
if (!this.pronta() || a.pente <= 0) return false;
|
|
196
|
+
a.pente--;
|
|
197
|
+
this.espera = 1 / a.def.cadencia;
|
|
198
|
+
this.bloom = Math.min(a.def.dispersaoMaxima, this.bloom + a.def.dispersaoPorTiro);
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** Começa a recarga se fizer sentido. Devolve true se começou. */
|
|
203
|
+
recarregar(): boolean {
|
|
204
|
+
const a = this.atual;
|
|
205
|
+
if (this.recargaT > 0 || a.pente >= a.def.pente || a.reserva <= 0) return false;
|
|
206
|
+
this.recargaT = a.def.tempoRecarga;
|
|
207
|
+
return true;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** Troca para a arma `i`. Cancela a recarga. Devolve true se trocou. */
|
|
211
|
+
trocar(i: number): boolean {
|
|
212
|
+
if (i === this.indice || i < 0 || i >= this.armas.length) return false;
|
|
213
|
+
this.indice = i;
|
|
214
|
+
this.recargaT = 0;
|
|
215
|
+
this.bloom = 0;
|
|
216
|
+
this.espera = tuning.tempoTroca;
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** Próxima (+1) ou anterior (-1), dando a volta. */
|
|
221
|
+
proxima(direcao: number): boolean {
|
|
222
|
+
const n = this.armas.length;
|
|
223
|
+
return this.trocar((this.indice + (direcao >= 0 ? 1 : -1) + n) % n);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** Para o painel de munição do HUD. */
|
|
227
|
+
municao(): InfoMunicao {
|
|
228
|
+
const a = this.atual;
|
|
229
|
+
return {
|
|
230
|
+
pente: a.pente,
|
|
231
|
+
capacidade: a.def.pente,
|
|
232
|
+
reserva: a.reserva,
|
|
233
|
+
nome: a.def.nome,
|
|
234
|
+
recarga: this.progressoRecarga
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** Fração média da reserva cheia (0..1) — decide se o drop é munição ou vida. */
|
|
239
|
+
fracaoReserva(): number {
|
|
240
|
+
const soma = this.armas.reduce((s, a) => s + a.reserva / a.def.reservaMaxima, 0);
|
|
241
|
+
return soma / this.armas.length;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** Soma `fracao` de um pente cheio em cada arma (até o teto). true se coube algo. */
|
|
245
|
+
reabastecer(fracao: number): boolean {
|
|
246
|
+
let coube = false;
|
|
247
|
+
for (const a of this.armas) {
|
|
248
|
+
const antes = a.reserva;
|
|
249
|
+
a.reserva = Math.min(a.def.reservaMaxima, a.reserva + Math.ceil(a.def.pente * fracao));
|
|
250
|
+
if (a.reserva > antes) coube = true;
|
|
251
|
+
}
|
|
252
|
+
return coube;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
reiniciar(): void {
|
|
256
|
+
this.armas.forEach((a) => { a.pente = a.def.pente; a.reserva = a.def.reservaInicial; });
|
|
257
|
+
this.indice = 0;
|
|
258
|
+
this.espera = 0;
|
|
259
|
+
this.recargaT = 0;
|
|
260
|
+
this.bloom = 0;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
get ordem(): readonly IdArma[] { return this.ids; }
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// ------------------------------------------------------------------ modelos
|
|
267
|
+
|
|
268
|
+
export interface ModeloArma {
|
|
269
|
+
objeto: THREE.Group;
|
|
270
|
+
dispose(): void;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Modelo procedural de cada arma, no padrão do viewmodel: aponta para -Z com o
|
|
275
|
+
* pivô perto do punho. Silhuetas DIFERENTES de propósito — trocar de arma tem
|
|
276
|
+
* que ser visível de canto de olho. Para modelo de verdade (.obj/.glb), o
|
|
277
|
+
* adapt-assets-3d-01 traz `carregarArma('pistola' | 'fuzil' | 'escopeta' ...)`:
|
|
278
|
+
* passe o objeto dele no lugar deste.
|
|
279
|
+
*/
|
|
280
|
+
export function modeloArma(id: IdArma): ModeloArma {
|
|
281
|
+
if (id === 'fuzil') return criarArmaProcedural('#3a3f45', '#3b3f46');
|
|
282
|
+
|
|
283
|
+
const p = getPalette();
|
|
284
|
+
const geos: THREE.BufferGeometry[] = [];
|
|
285
|
+
const metal = new THREE.MeshStandardMaterial({ color: '#33373d', roughness: 0.4, metalness: 0.6 });
|
|
286
|
+
const polimero = new THREE.MeshStandardMaterial({ color: '#202327', roughness: 0.75, metalness: 0.1 });
|
|
287
|
+
const madeira = new THREE.MeshStandardMaterial({ color: '#5a4030', roughness: 0.8, metalness: 0.02 });
|
|
288
|
+
const neon = new THREE.MeshBasicMaterial({ color: p.primaria });
|
|
289
|
+
const mats: THREE.Material[] = [metal, polimero, madeira, neon];
|
|
290
|
+
|
|
291
|
+
const g = new THREE.Group();
|
|
292
|
+
g.name = id;
|
|
293
|
+
const caixa = (mat: THREE.Material, l: number, a: number, c: number, x: number, y: number, z: number) => {
|
|
294
|
+
const geo = new THREE.BoxGeometry(l, a, c);
|
|
295
|
+
geos.push(geo);
|
|
296
|
+
const m = new THREE.Mesh(geo, mat);
|
|
297
|
+
m.position.set(x, y, z);
|
|
298
|
+
g.add(m);
|
|
299
|
+
return m;
|
|
300
|
+
};
|
|
301
|
+
const cano = (mat: THREE.Material, r: number, comp: number, y: number, z: number) => {
|
|
302
|
+
const geo = new THREE.CylinderGeometry(r, r, comp, 10);
|
|
303
|
+
geos.push(geo);
|
|
304
|
+
const m = new THREE.Mesh(geo, mat);
|
|
305
|
+
m.rotation.x = Math.PI / 2;
|
|
306
|
+
m.position.set(0, y, z);
|
|
307
|
+
g.add(m);
|
|
308
|
+
return m;
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
if (id === 'pistola') {
|
|
312
|
+
caixa(metal, 0.034, 0.038, 0.19, 0, 0.012, -0.07); // ferrolho
|
|
313
|
+
caixa(polimero, 0.03, 0.026, 0.16, 0, -0.019, -0.06); // armação
|
|
314
|
+
caixa(polimero, 0.03, 0.1, 0.044, 0, -0.07, 0.012).rotation.x = -0.24; // cabo
|
|
315
|
+
caixa(metal, 0.006, 0.012, 0.006, 0, 0.037, -0.155); // massa de mira
|
|
316
|
+
caixa(metal, 0.022, 0.01, 0.006, 0, 0.036, 0.015); // alça de mira
|
|
317
|
+
caixa(neon, 0.004, 0.004, 0.002, 0, 0.042, 0.019); // ponto luminoso
|
|
318
|
+
cano(metal, 0.007, 0.03, 0.012, -0.172); // boca
|
|
319
|
+
} else {
|
|
320
|
+
// escopeta (pump): cano longo, tubo de munição embaixo e telha de madeira.
|
|
321
|
+
cano(metal, 0.016, 0.62, 0.022, -0.34); // cano
|
|
322
|
+
cano(metal, 0.013, 0.46, -0.012, -0.27); // tubo
|
|
323
|
+
cano(madeira, 0.024, 0.17, -0.012, -0.31); // telha (pump)
|
|
324
|
+
caixa(metal, 0.05, 0.07, 0.2, 0, 0.0, -0.02); // ferrolho
|
|
325
|
+
caixa(polimero, 0.036, 0.09, 0.045, 0, -0.07, 0.03).rotation.x = -0.3; // cabo
|
|
326
|
+
caixa(madeira, 0.042, 0.065, 0.22, 0, -0.03, 0.18).rotation.x = 0.08; // coronha
|
|
327
|
+
caixa(neon, 0.006, 0.006, 0.006, 0, 0.044, -0.64); // mira de fibra
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
return {
|
|
331
|
+
objeto: g,
|
|
332
|
+
dispose() {
|
|
333
|
+
geos.forEach((x) => x.dispose());
|
|
334
|
+
mats.forEach((x) => x.dispose());
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// ------------------------------------------------------------------ traçantes
|
|
340
|
+
|
|
341
|
+
export interface Tracos {
|
|
342
|
+
/** Adicione na cena do mundo. */
|
|
343
|
+
objeto: THREE.LineSegments;
|
|
344
|
+
/** Risco de luz do cano até onde a bala parou. */
|
|
345
|
+
disparar(de: THREE.Vector3, para: THREE.Vector3): void;
|
|
346
|
+
atualizar(passo: number): void;
|
|
347
|
+
definirCor(cor: string): void;
|
|
348
|
+
dispose(): void;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Traçantes: o risco de luz de cada tiro. Sem eles o jogador não lê de onde a
|
|
353
|
+
* bala saiu nem onde parou — principalmente errando, que é quando ele precisa
|
|
354
|
+
* corrigir a mira. Pool fixo num único LineSegments (1 draw call).
|
|
355
|
+
*/
|
|
356
|
+
export function criarTracos(cor: string, maximo = 40, duracao = 0.06): Tracos {
|
|
357
|
+
const pos = new Float32Array(maximo * 6);
|
|
358
|
+
const cores = new Float32Array(maximo * 6);
|
|
359
|
+
const vida = new Float32Array(maximo);
|
|
360
|
+
const geo = new THREE.BufferGeometry();
|
|
361
|
+
geo.setAttribute('position', new THREE.BufferAttribute(pos, 3));
|
|
362
|
+
geo.setAttribute('color', new THREE.BufferAttribute(cores, 3));
|
|
363
|
+
const mat = new THREE.LineBasicMaterial({
|
|
364
|
+
vertexColors: true, transparent: true, depthWrite: false, blending: THREE.AdditiveBlending
|
|
365
|
+
});
|
|
366
|
+
const objeto = new THREE.LineSegments(geo, mat);
|
|
367
|
+
objeto.frustumCulled = false;
|
|
368
|
+
const base = new THREE.Color(cor);
|
|
369
|
+
let proximo = 0;
|
|
370
|
+
|
|
371
|
+
return {
|
|
372
|
+
objeto,
|
|
373
|
+
disparar(de, para) {
|
|
374
|
+
const i = proximo;
|
|
375
|
+
proximo = (proximo + 1) % maximo;
|
|
376
|
+
const j = i * 6;
|
|
377
|
+
// O risco começa um pouco À FRENTE do cano: colado na boca, ele atravessa
|
|
378
|
+
// o viewmodel e parece sair da barriga.
|
|
379
|
+
pos[j] = de.x; pos[j + 1] = de.y; pos[j + 2] = de.z;
|
|
380
|
+
pos[j + 3] = para.x; pos[j + 4] = para.y; pos[j + 5] = para.z;
|
|
381
|
+
vida[i] = duracao;
|
|
382
|
+
},
|
|
383
|
+
atualizar(passo) {
|
|
384
|
+
for (let i = 0; i < maximo; i++) {
|
|
385
|
+
const j = i * 6;
|
|
386
|
+
if (vida[i]! > 0) vida[i] = Math.max(0, vida[i]! - passo);
|
|
387
|
+
const k = vida[i]! / duracao;
|
|
388
|
+
// Ponta de trás mais fraca que a da frente: lê como movimento.
|
|
389
|
+
cores[j] = base.r * k * 0.35; cores[j + 1] = base.g * k * 0.35; cores[j + 2] = base.b * k * 0.35;
|
|
390
|
+
cores[j + 3] = base.r * k; cores[j + 4] = base.g * k; cores[j + 5] = base.b * k;
|
|
391
|
+
}
|
|
392
|
+
geo.attributes.position!.needsUpdate = true;
|
|
393
|
+
geo.attributes.color!.needsUpdate = true;
|
|
394
|
+
},
|
|
395
|
+
definirCor(c) { base.set(c); },
|
|
396
|
+
dispose() { geo.dispose(); mat.dispose(); }
|
|
397
|
+
};
|
|
398
|
+
}
|