@maco-online/paint-tanks-rules 0.0.0 → 0.2.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 (55) hide show
  1. package/LICENSE +21 -0
  2. package/dist/ai-host.d.ts +15 -0
  3. package/dist/ai-host.js +1 -0
  4. package/dist/balance-config.d.ts +50 -0
  5. package/dist/balance-config.js +41 -0
  6. package/dist/boss-ai.d.ts +9 -0
  7. package/dist/boss-ai.js +213 -0
  8. package/dist/bosses.d.ts +34 -0
  9. package/dist/bosses.js +47 -0
  10. package/dist/constants.d.ts +133 -0
  11. package/dist/constants.js +163 -0
  12. package/dist/enemy-ai.d.ts +11 -0
  13. package/dist/enemy-ai.js +361 -0
  14. package/dist/game-factory.d.ts +16 -0
  15. package/dist/game-factory.js +78 -0
  16. package/dist/game-state.d.ts +256 -0
  17. package/dist/game-state.js +1 -0
  18. package/dist/index.d.ts +25 -0
  19. package/dist/index.js +27 -0
  20. package/dist/labels.d.ts +12 -0
  21. package/dist/labels.js +129 -0
  22. package/dist/levels.d.ts +45 -0
  23. package/dist/levels.js +209 -0
  24. package/dist/movement.d.ts +25 -0
  25. package/dist/movement.js +158 -0
  26. package/dist/online/match.d.ts +28 -0
  27. package/dist/online/match.js +176 -0
  28. package/dist/online/prediction.d.ts +41 -0
  29. package/dist/online/prediction.js +97 -0
  30. package/dist/online/protocol.d.ts +124 -0
  31. package/dist/online/protocol.js +54 -0
  32. package/dist/online/room-game.d.ts +5 -0
  33. package/dist/online/room-game.js +24 -0
  34. package/dist/online/view.d.ts +43 -0
  35. package/dist/online/view.js +347 -0
  36. package/dist/pathfinding.d.ts +8 -0
  37. package/dist/pathfinding.js +45 -0
  38. package/dist/power-ups.d.ts +28 -0
  39. package/dist/power-ups.js +66 -0
  40. package/dist/random.d.ts +1 -0
  41. package/dist/random.js +1 -0
  42. package/dist/sim-effects.d.ts +30 -0
  43. package/dist/sim-effects.js +1 -0
  44. package/dist/simulation.d.ts +74 -0
  45. package/dist/simulation.js +768 -0
  46. package/dist/sound-names.d.ts +4 -0
  47. package/dist/sound-names.js +1 -0
  48. package/dist/spawning.d.ts +3 -0
  49. package/dist/spawning.js +56 -0
  50. package/dist/tank-rules.d.ts +20 -0
  51. package/dist/tank-rules.js +39 -0
  52. package/dist/visibility.d.ts +20 -0
  53. package/dist/visibility.js +39 -0
  54. package/package.json +40 -4
  55. package/README.md +0 -3
@@ -0,0 +1,256 @@
1
+ import type { BossId, BossShot } from './bosses.ts';
2
+ import type { EnemyKind, TankKind, TankSpec } from './constants.ts';
3
+ import type { LabelParams, PaintTanksLabelKey } from './labels.ts';
4
+ import type { Difficulty, TileMap } from './levels.ts';
5
+ /** A square thing on the map; `x` and `y` are its top-left corner in map pixels. */
6
+ export interface Box {
7
+ x: number;
8
+ y: number;
9
+ s: number;
10
+ }
11
+ interface Body extends Box {
12
+ dir: number;
13
+ anim: number;
14
+ }
15
+ export interface Player extends Body {
16
+ player: true;
17
+ boss?: undefined;
18
+ up: number;
19
+ idx: number;
20
+ kind: TankKind;
21
+ spec: TankSpec;
22
+ sx: number;
23
+ sy: number;
24
+ speed: number;
25
+ cd: number;
26
+ lives: number;
27
+ alive: boolean;
28
+ respawn: number;
29
+ shield: number;
30
+ /** Frames left of the cloak power-up: enemies further than a few tiles away cannot see this player. */
31
+ cloak: number;
32
+ color: string;
33
+ /** Frames until a guarding tank's front can stop another shot. */
34
+ guard?: number;
35
+ /** Frames since this player last fired, for a tank that hides when quiet. */
36
+ quiet?: number;
37
+ /** Frames until a support tank can shield a teammate again, and heal the puppy again. */
38
+ shieldT?: number;
39
+ healT?: number;
40
+ }
41
+ export type EnemyRole = 'hunt' | 'flank' | 'pet';
42
+ export interface Enemy extends Body {
43
+ player?: undefined;
44
+ boss?: undefined;
45
+ kind: EnemyKind;
46
+ speed: number;
47
+ hp: number;
48
+ color: string;
49
+ pts: number;
50
+ cd: number;
51
+ turnT: number;
52
+ spawning: number;
53
+ flash: number;
54
+ angry: boolean;
55
+ carrier: boolean;
56
+ aimT: number;
57
+ stuck: number;
58
+ minion: boolean;
59
+ role: EnemyRole;
60
+ bias: number;
61
+ dodgeT: number;
62
+ hold: number;
63
+ cell: number;
64
+ dead?: boolean;
65
+ /** A bomb tank about to blow. */
66
+ fuse?: boolean;
67
+ age?: number;
68
+ /** Frames a bomb tank keeps its heading instead of re-aiming. */
69
+ route?: number;
70
+ /** Game tick of the last shot. */
71
+ ls?: number;
72
+ /** Frames left of a slowing hit, and the share of its speed the enemy keeps meanwhile. */
73
+ slow?: number;
74
+ slowF?: number;
75
+ }
76
+ export interface Boss extends Body {
77
+ player?: undefined;
78
+ boss: true;
79
+ kind: 'boss';
80
+ id: BossId;
81
+ hp: number;
82
+ maxHp: number;
83
+ color: string;
84
+ cd: number;
85
+ flash: number;
86
+ spd: number;
87
+ tx: number;
88
+ ty: number;
89
+ retarget: number;
90
+ sc: number;
91
+ shielded: boolean;
92
+ inv: number;
93
+ last: boolean;
94
+ still: number;
95
+ dodgeT: number;
96
+ axis: boolean;
97
+ dodgeDir: number;
98
+ /** Frames left of the warning before the next volley; the boss holds still meanwhile. */
99
+ charge: number;
100
+ /** Volleys fired so far. */
101
+ volley: number;
102
+ /** The volley being announced, fired when `charge` runs out. */
103
+ plan: BossShot[];
104
+ /** Shots of the current volley still waiting for their delay. */
105
+ queue: BossShot[];
106
+ dead?: boolean;
107
+ spawning?: undefined;
108
+ }
109
+ /** Anything that drives around and blocks others. */
110
+ export type Tank = Player | Enemy | Boss;
111
+ export interface Bullet {
112
+ x: number;
113
+ y: number;
114
+ vx: number;
115
+ vy: number;
116
+ r: number;
117
+ /** 0 for an enemy shot, otherwise the player number (1 to `MAX_TEAM`). */
118
+ owner: number;
119
+ kind?: TankKind;
120
+ big?: boolean;
121
+ power?: boolean;
122
+ /** Pixels left before the shot fades; unlimited when absent. */
123
+ range?: number;
124
+ /** Bounces left off solid tiles and the edge of the field. */
125
+ bounce?: number;
126
+ /** Enemies the shot may still pass through. */
127
+ pierce?: number;
128
+ /** Enemies a piercing shot already hit, which it never hits again. */
129
+ hits?: (Enemy | Boss)[];
130
+ /** An enemy rainbow shot, drawn with a rainbow trail. */
131
+ rainbow?: boolean;
132
+ /** The shot has bounced, and no longer hurts the puppy. */
133
+ bounced?: boolean;
134
+ dead?: boolean;
135
+ }
136
+ export type ParticleType = 'dot' | 'bubble' | 'star' | 'line' | 'sq' | 'ring';
137
+ export interface Particle {
138
+ x: number;
139
+ y: number;
140
+ vx: number;
141
+ vy: number;
142
+ r: number;
143
+ life: number;
144
+ max: number;
145
+ color: string;
146
+ type: ParticleType;
147
+ }
148
+ export interface FloatingText {
149
+ x: number;
150
+ y: number;
151
+ s: string;
152
+ color: string;
153
+ life: number;
154
+ }
155
+ /** Support items that drop in play and act as soon as a player drives over them. */
156
+ export type PowerUpType = 'shield' | 'cloak' | 'freeze' | 'bone';
157
+ export interface Pickup {
158
+ x: number;
159
+ y: number;
160
+ type: 'star' | 'fruit' | 'up' | PowerUpType;
161
+ life: number;
162
+ dead?: boolean;
163
+ }
164
+ /**
165
+ * A message across the middle of the field. It is kept as a key, not as text, so it follows a change of language
166
+ * and can travel from the online server, which has no language of its own.
167
+ */
168
+ export interface Banner {
169
+ key: PaintTanksLabelKey;
170
+ params?: LabelParams;
171
+ /** Boss whose translated name fills the `{name}` placeholder. */
172
+ boss?: BossId;
173
+ life: number;
174
+ }
175
+ /** Cost of reaching each cell from a target; used to steer tanks. */
176
+ export type DistanceField = number[][];
177
+ export interface Game {
178
+ state: 'play' | 'pause' | 'over';
179
+ t: number;
180
+ lv: number;
181
+ D: Difficulty;
182
+ mult: number;
183
+ map: TileMap;
184
+ hp: number[][];
185
+ players: Player[];
186
+ enemies: Enemy[];
187
+ bullets: Bullet[];
188
+ parts: Particle[];
189
+ picks: Pickup[];
190
+ texts: FloatingText[];
191
+ boss: Boss | null;
192
+ bossDone: boolean;
193
+ bossT: number | null;
194
+ toSpawn: number;
195
+ total: number;
196
+ kills: number;
197
+ spawnT: number;
198
+ spawnIdx: number;
199
+ spawnCount: number;
200
+ petHp: number;
201
+ petFlash: number;
202
+ /** Frames left of the freeze power-up: ordinary enemies neither move nor shoot. */
203
+ freeze: number;
204
+ stars: number;
205
+ score: number;
206
+ rush: boolean;
207
+ field: DistanceField | null;
208
+ pfield: DistanceField | null;
209
+ bfield: DistanceField | null;
210
+ fieldDirty: boolean;
211
+ banner: Banner | null;
212
+ endT: number;
213
+ result: 'pet' | 'tanks' | 'win' | null;
214
+ shake: number;
215
+ bombSeen: boolean;
216
+ carrierSeen: boolean;
217
+ rainbowSeen: boolean;
218
+ }
219
+ export type OverlayKind = 'start' | 'garage'
220
+ /** The same garage, opened from an online room before its match starts. */
221
+ | 'onlineGarage' | 'pause' | 'end' | 'none'
222
+ /** Open or join a room. */
223
+ | 'online'
224
+ /** The room before a match. */
225
+ | 'lobby' | 'onlineEnd'
226
+ /** The menu over a running online level, which does not stop. */
227
+ | 'onlinePause';
228
+ /** What the end-of-play screen says; kept as a key so it follows a change of language. */
229
+ export interface EndMessage {
230
+ key: PaintTanksLabelKey;
231
+ params?: LabelParams;
232
+ plural?: number;
233
+ }
234
+ export interface EndData {
235
+ win: boolean;
236
+ champ: boolean;
237
+ lv: number;
238
+ score: number;
239
+ stars: number;
240
+ prog: number;
241
+ msg: EndMessage | null;
242
+ }
243
+ /** Where a player moves and whether they fire, from keys or touch. */
244
+ export interface PlayerInput {
245
+ dir: number;
246
+ fire: boolean;
247
+ /**
248
+ * The position the player claims to be at after this tick, for online play where the browser decides its own
249
+ * position and the server checks it. Undefined for local play, where the simulation moves the tank itself.
250
+ */
251
+ x?: number;
252
+ y?: number;
253
+ /** The browser's number for this input, one per browser tick; it tells how many ticks of movement a claim covers. */
254
+ n?: number;
255
+ }
256
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,25 @@
1
+ export * from './ai-host.ts';
2
+ export * from './balance-config.ts';
3
+ export * from './bosses.ts';
4
+ export * from './boss-ai.ts';
5
+ export * from './constants.ts';
6
+ export * from './enemy-ai.ts';
7
+ export * from './game-factory.ts';
8
+ export * from './game-state.ts';
9
+ export * from './labels.ts';
10
+ export * from './levels.ts';
11
+ export * from './movement.ts';
12
+ export * from './pathfinding.ts';
13
+ export * from './power-ups.ts';
14
+ export * from './random.ts';
15
+ export * from './sim-effects.ts';
16
+ export * from './simulation.ts';
17
+ export * from './sound-names.ts';
18
+ export * from './spawning.ts';
19
+ export * from './tank-rules.ts';
20
+ export * from './visibility.ts';
21
+ export * from './online/match.ts';
22
+ export * from './online/prediction.ts';
23
+ export * from './online/protocol.ts';
24
+ export * from './online/room-game.ts';
25
+ export * from './online/view.ts';
package/dist/index.js ADDED
@@ -0,0 +1,27 @@
1
+ // Every rules module from one entry. Each module is also its own subpath export, for example
2
+ // '@maco-online/paint-tanks-rules/simulation' or '@maco-online/paint-tanks-rules/online/room-game'.
3
+ export * from "./ai-host.js";
4
+ export * from "./balance-config.js";
5
+ export * from "./bosses.js";
6
+ export * from "./boss-ai.js";
7
+ export * from "./constants.js";
8
+ export * from "./enemy-ai.js";
9
+ export * from "./game-factory.js";
10
+ export * from "./game-state.js";
11
+ export * from "./labels.js";
12
+ export * from "./levels.js";
13
+ export * from "./movement.js";
14
+ export * from "./pathfinding.js";
15
+ export * from "./power-ups.js";
16
+ export * from "./random.js";
17
+ export * from "./sim-effects.js";
18
+ export * from "./simulation.js";
19
+ export * from "./sound-names.js";
20
+ export * from "./spawning.js";
21
+ export * from "./tank-rules.js";
22
+ export * from "./visibility.js";
23
+ export * from "./online/match.js";
24
+ export * from "./online/prediction.js";
25
+ export * from "./online/protocol.js";
26
+ export * from "./online/room-game.js";
27
+ export * from "./online/view.js";
@@ -0,0 +1,12 @@
1
+ import type { BossId } from './bosses.ts';
2
+ import type { TankKind, TierKey } from './constants.ts';
3
+ export declare const PAINT_TANKS_STATIC_LABELS: readonly ["soundMute", "soundUnmute", "keysSolo", "keysDuo", "fire", "pause", "level", "difficulty", "rewardPoints", "levelBest", "onePlayer", "twoPlayers", "play", "sound", "on", "off", "music", "garage", "autoFire", "touchPad", "garageHint", "back", "paused", "resume", "toMenu", "gameCleared", "champion", "cleared", "soClose", "ohNo", "progress", "score", "stars", "startAgain", "nextLevel", "replay", "tryAgain", "bannerBoss", "bannerProtect", "bannerTeddyComing", "bannerFinalRush", "bannerBomb", "bannerRainbow", "bannerCarrier", "bannerTeddyFurious", "bannerAllBubbles", "boom", "msgChampion", "msgChampionGuest", "msgUnlockAll", "msgNewBest", "msgTeddyLow", "msgFewLeft", "msgPuppyMuddy", "msgNoTanks", "hudLevel", "hudPlayer", "hudPower", "bossTag", "levelBack10", "levelBack", "levelNext", "levelNext10", "hudPup", "hudFoes", "hudPick", "pickShield", "pickCloak", "pickFreeze", "pickBone", "playOnline", "onlineTitle", "onlineHint", "createRoom", "roomCode", "joinRoom", "copyLink", "linkCopied", "roomPlayers", "roomHost", "roomYou", "roomGuest", "roomAway", "waitHost", "startMatch", "leaveRoom", "toRoom", "yourTank", "connecting", "reconnecting", "ping", "voiceStart", "voiceMute", "voiceUnmute", "voiceConnecting", "voiceDenied", "voiceUnavailable", "voiceTitle", "voiceMicOn", "voiceMicOff", "voicePeerConnecting", "voicePeerMute", "voicePeerUnmute", "voicePeerVolume", "voiceAlone", "voicePlaybackBlocked", "spectating", "onlinePaused", "errorUnavailable", "errorInvalid", "errorFull", "errorReplaced", "errorGone", "errorOutdated", "errorLost"];
4
+ export type PaintTanksLabelKey = typeof PAINT_TANKS_STATIC_LABELS[number] | `tanks.${TankKind}.${'name' | 'trait'}` | `tiers.${TierKey}` | `bosses.${BossId}.name`;
5
+ export type LabelParams = Record<string, string | number>;
6
+ /**
7
+ * Looks up a message of `gamification.paintTanks.game`. `plural` selects between the singular and plural forms
8
+ * of messages that have both, as in vue-i18n.
9
+ */
10
+ export type Label = (key: PaintTanksLabelKey, params?: LabelParams, plural?: number) => string;
11
+ /** Every key the engine can ask for, to check that the dictionaries are complete. */
12
+ export declare function allLabelKeys(): PaintTanksLabelKey[];
package/dist/labels.js ADDED
@@ -0,0 +1,129 @@
1
+ import { BOSSES } from "./bosses.js";
2
+ import { TANKS, TIERS } from "./constants.js";
3
+ // Keys of `gamification.paintTanks.game` that the engine uses; the vi and en dictionaries must define every one.
4
+ export const PAINT_TANKS_STATIC_LABELS = [
5
+ 'soundMute',
6
+ 'soundUnmute',
7
+ 'keysSolo',
8
+ 'keysDuo',
9
+ 'fire',
10
+ 'pause',
11
+ 'level',
12
+ 'difficulty',
13
+ 'rewardPoints',
14
+ 'levelBest',
15
+ 'onePlayer',
16
+ 'twoPlayers',
17
+ 'play',
18
+ 'sound',
19
+ 'on',
20
+ 'off',
21
+ 'music',
22
+ 'garage',
23
+ 'autoFire',
24
+ 'touchPad',
25
+ 'garageHint',
26
+ 'back',
27
+ 'paused',
28
+ 'resume',
29
+ 'toMenu',
30
+ 'gameCleared',
31
+ 'champion',
32
+ 'cleared',
33
+ 'soClose',
34
+ 'ohNo',
35
+ 'progress',
36
+ 'score',
37
+ 'stars',
38
+ 'startAgain',
39
+ 'nextLevel',
40
+ 'replay',
41
+ 'tryAgain',
42
+ 'bannerBoss',
43
+ 'bannerProtect',
44
+ 'bannerTeddyComing',
45
+ 'bannerFinalRush',
46
+ 'bannerBomb',
47
+ 'bannerRainbow',
48
+ 'bannerCarrier',
49
+ 'bannerTeddyFurious',
50
+ 'bannerAllBubbles',
51
+ 'boom',
52
+ 'msgChampion',
53
+ 'msgChampionGuest',
54
+ 'msgUnlockAll',
55
+ 'msgNewBest',
56
+ 'msgTeddyLow',
57
+ 'msgFewLeft',
58
+ 'msgPuppyMuddy',
59
+ 'msgNoTanks',
60
+ 'hudLevel',
61
+ 'hudPlayer',
62
+ 'hudPower',
63
+ 'bossTag',
64
+ 'levelBack10',
65
+ 'levelBack',
66
+ 'levelNext',
67
+ 'levelNext10',
68
+ 'hudPup',
69
+ 'hudFoes',
70
+ 'hudPick',
71
+ 'pickShield',
72
+ 'pickCloak',
73
+ 'pickFreeze',
74
+ 'pickBone',
75
+ 'playOnline',
76
+ 'onlineTitle',
77
+ 'onlineHint',
78
+ 'createRoom',
79
+ 'roomCode',
80
+ 'joinRoom',
81
+ 'copyLink',
82
+ 'linkCopied',
83
+ 'roomPlayers',
84
+ 'roomHost',
85
+ 'roomYou',
86
+ 'roomGuest',
87
+ 'roomAway',
88
+ 'waitHost',
89
+ 'startMatch',
90
+ 'leaveRoom',
91
+ 'toRoom',
92
+ 'yourTank',
93
+ 'connecting',
94
+ 'reconnecting',
95
+ 'ping',
96
+ 'voiceStart',
97
+ 'voiceMute',
98
+ 'voiceUnmute',
99
+ 'voiceConnecting',
100
+ 'voiceDenied',
101
+ 'voiceUnavailable',
102
+ 'voiceTitle',
103
+ 'voiceMicOn',
104
+ 'voiceMicOff',
105
+ 'voicePeerConnecting',
106
+ 'voicePeerMute',
107
+ 'voicePeerUnmute',
108
+ 'voicePeerVolume',
109
+ 'voiceAlone',
110
+ 'voicePlaybackBlocked',
111
+ 'spectating',
112
+ 'onlinePaused',
113
+ 'errorUnavailable',
114
+ 'errorInvalid',
115
+ 'errorFull',
116
+ 'errorReplaced',
117
+ 'errorGone',
118
+ 'errorOutdated',
119
+ 'errorLost'
120
+ ];
121
+ /** Every key the engine can ask for, to check that the dictionaries are complete. */
122
+ export function allLabelKeys() {
123
+ return [
124
+ ...PAINT_TANKS_STATIC_LABELS,
125
+ ...TANKS.flatMap(tank => [`tanks.${tank.id}.name`, `tanks.${tank.id}.trait`]),
126
+ ...TIERS.map(tier => `tiers.${tier.key}`),
127
+ ...Object.values(BOSSES).map(boss => `bosses.${boss.id}.name`)
128
+ ];
129
+ }
@@ -0,0 +1,45 @@
1
+ import type { Cell, EnemyKind } from './constants.ts';
2
+ /** Map tiles by row then column: 0 floor, 1 jelly, 2 candy, 3 block, 4 water, 5 puppy, 6 blanket, 7 gift. */
3
+ export type TileMap = number[][];
4
+ export interface Difficulty {
5
+ /** Eased difficulty, 0 (first level) to about 1. */
6
+ e: number;
7
+ boss: boolean;
8
+ count: number;
9
+ max: number;
10
+ gap: number;
11
+ spd: number;
12
+ fire: readonly [min: number, max: number];
13
+ eb: number;
14
+ /** Bullet speed of the boss, before its per-attack factor. */
15
+ bossEb: number;
16
+ mix: ReadonlyArray<readonly [EnemyKind, number]>;
17
+ smart: number;
18
+ aim: number;
19
+ lives: number;
20
+ pet: number;
21
+ shield: number;
22
+ drop: number;
23
+ rush: boolean;
24
+ bossHp: number;
25
+ bossShield: boolean;
26
+ bossLast: boolean;
27
+ bossEarly: number;
28
+ bossSpd: number;
29
+ dodge: number;
30
+ edodge: number;
31
+ }
32
+ /** A `N`×`N` grid filled with `value`. */
33
+ export declare function blankGrid<V>(value: V): V[][];
34
+ export declare const OL: (L: number) => number;
35
+ export declare const tierOf: (L: number) => number;
36
+ export declare function mulberry(a: number): () => number;
37
+ export declare function pickW<V>(R: () => number, arr: ReadonlyArray<readonly [V, number]>): V;
38
+ export declare function reach(m: TileMap, from: Cell, to: Cell): boolean;
39
+ export declare function genMap(L0: number): TileMap;
40
+ /**
41
+ * The level as a team of `size` plays it. Levels are balanced for one or two players, so a bigger team faces more
42
+ * tanks at once and a tougher boss; one or two players get the level unchanged.
43
+ */
44
+ export declare function teamDifficulty(D: Difficulty, size: number): Difficulty;
45
+ export declare function diffOf(L0: number, k?: number): Difficulty;