@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.
- package/LICENSE +21 -0
- package/dist/ai-host.d.ts +15 -0
- package/dist/ai-host.js +1 -0
- package/dist/balance-config.d.ts +50 -0
- package/dist/balance-config.js +41 -0
- package/dist/boss-ai.d.ts +9 -0
- package/dist/boss-ai.js +213 -0
- package/dist/bosses.d.ts +34 -0
- package/dist/bosses.js +47 -0
- package/dist/constants.d.ts +133 -0
- package/dist/constants.js +163 -0
- package/dist/enemy-ai.d.ts +11 -0
- package/dist/enemy-ai.js +361 -0
- package/dist/game-factory.d.ts +16 -0
- package/dist/game-factory.js +78 -0
- package/dist/game-state.d.ts +256 -0
- package/dist/game-state.js +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +27 -0
- package/dist/labels.d.ts +12 -0
- package/dist/labels.js +129 -0
- package/dist/levels.d.ts +45 -0
- package/dist/levels.js +209 -0
- package/dist/movement.d.ts +25 -0
- package/dist/movement.js +158 -0
- package/dist/online/match.d.ts +28 -0
- package/dist/online/match.js +176 -0
- package/dist/online/prediction.d.ts +41 -0
- package/dist/online/prediction.js +97 -0
- package/dist/online/protocol.d.ts +124 -0
- package/dist/online/protocol.js +54 -0
- package/dist/online/room-game.d.ts +5 -0
- package/dist/online/room-game.js +24 -0
- package/dist/online/view.d.ts +43 -0
- package/dist/online/view.js +347 -0
- package/dist/pathfinding.d.ts +8 -0
- package/dist/pathfinding.js +45 -0
- package/dist/power-ups.d.ts +28 -0
- package/dist/power-ups.js +66 -0
- package/dist/random.d.ts +1 -0
- package/dist/random.js +1 -0
- package/dist/sim-effects.d.ts +30 -0
- package/dist/sim-effects.js +1 -0
- package/dist/simulation.d.ts +74 -0
- package/dist/simulation.js +768 -0
- package/dist/sound-names.d.ts +4 -0
- package/dist/sound-names.js +1 -0
- package/dist/spawning.d.ts +3 -0
- package/dist/spawning.js +56 -0
- package/dist/tank-rules.d.ts +20 -0
- package/dist/tank-rules.js +39 -0
- package/dist/visibility.d.ts +20 -0
- package/dist/visibility.js +39 -0
- package/package.json +40 -4
- package/README.md +0 -3
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ShotStyle } from './constants.ts';
|
|
2
|
+
/** Sound effects the game can play; kept apart from the audio code so the online server can name them too. */
|
|
3
|
+
export type SoundName = `shot-${ShotStyle}` | 'eshot' | 'jelly' | 'candy' | 'gift' | 'crack' | 'block' | 'pop' | 'boom' | 'hurt' | 'pet' | 'shield' | 'star' | 'fruit' | 'up' | 'bossIn' | 'bossDown' | 'win' | 'lose' | 'champ' | 'click' | 'cloak' | 'freeze' | 'heal' | 'charge';
|
|
4
|
+
export type MusicMode = 'calm' | 'boss';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/spawning.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ENEMY, SPAWNS, T } from "./constants.js";
|
|
2
|
+
import { pickW } from "./levels.js";
|
|
3
|
+
import { rnd } from "./random.js";
|
|
4
|
+
export function spawnEnemy(g, i, kind, minion) {
|
|
5
|
+
const D = g.D;
|
|
6
|
+
kind = kind || pickW(Math.random, D.mix);
|
|
7
|
+
const s = ENEMY[kind];
|
|
8
|
+
const [c, r] = SPAWNS[i];
|
|
9
|
+
const rr0 = Math.random();
|
|
10
|
+
const sc = (g.spawnCount = (g.spawnCount || 0) + 1);
|
|
11
|
+
const carrier = !minion && kind !== 'bomb' && sc % 4 === 2;
|
|
12
|
+
if (kind === 'bomb' && !g.bombSeen) {
|
|
13
|
+
g.bombSeen = true;
|
|
14
|
+
g.banner = { key: 'bannerBomb', life: 100 };
|
|
15
|
+
}
|
|
16
|
+
else if (kind === 'rainbow' && !g.rainbowSeen) {
|
|
17
|
+
g.rainbowSeen = true;
|
|
18
|
+
g.banner = { key: 'bannerRainbow', life: 110 };
|
|
19
|
+
}
|
|
20
|
+
else if (carrier && !g.carrierSeen && g.lv <= 10) {
|
|
21
|
+
g.carrierSeen = true;
|
|
22
|
+
g.banner = { key: 'bannerCarrier', life: 110 };
|
|
23
|
+
}
|
|
24
|
+
g.enemies.push({
|
|
25
|
+
kind,
|
|
26
|
+
x: c * T + 3,
|
|
27
|
+
y: r * T + 3,
|
|
28
|
+
s: 26,
|
|
29
|
+
dir: 2,
|
|
30
|
+
speed: Math.min(2.4, s.speed * D.spd),
|
|
31
|
+
hp: s.hp,
|
|
32
|
+
color: s.color,
|
|
33
|
+
pts: s.pts,
|
|
34
|
+
cd: Math.max(60, rnd(...D.fire)),
|
|
35
|
+
turnT: rnd(20, 60),
|
|
36
|
+
spawning: 45,
|
|
37
|
+
flash: 0,
|
|
38
|
+
anim: 0,
|
|
39
|
+
angry: g.rush || !!minion || kind === 'bomb',
|
|
40
|
+
carrier,
|
|
41
|
+
aimT: 0,
|
|
42
|
+
stuck: 0,
|
|
43
|
+
minion: !!minion,
|
|
44
|
+
role: minion || kind === 'bomb'
|
|
45
|
+
? 'hunt'
|
|
46
|
+
: rr0 < 0.12 + D.smart * 0.25
|
|
47
|
+
? 'hunt'
|
|
48
|
+
: rr0 < 0.3 + D.smart * 0.35
|
|
49
|
+
? 'flank'
|
|
50
|
+
: 'pet',
|
|
51
|
+
bias: Math.random() < 0.5 ? -1 : 1,
|
|
52
|
+
dodgeT: 0,
|
|
53
|
+
hold: 0,
|
|
54
|
+
cell: -1
|
|
55
|
+
});
|
|
56
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ShotPattern, TankSpec } from './constants.ts';
|
|
2
|
+
import type { Boss, Bullet, Enemy, Player } from './game-state.ts';
|
|
3
|
+
/** Cloak frames a quiet stealthy tank keeps topping up; firing drops a cloak this short at once. */
|
|
4
|
+
export declare const STEALTH_CLOAK = 2;
|
|
5
|
+
/** Fewest frames between two shots of any tank, at any power level. */
|
|
6
|
+
export declare const MIN_COOLDOWN = 6;
|
|
7
|
+
type Shooter = Pick<Player, 'spec' | 'up'>;
|
|
8
|
+
/** Shots one press of fire sends with `pattern`. */
|
|
9
|
+
export declare function volleySize(pattern?: ShotPattern): number;
|
|
10
|
+
/** Most of player `p`'s shots on the field at once: power level 3 adds room for one more volley. */
|
|
11
|
+
export declare function bulletCap(p: Shooter): number;
|
|
12
|
+
/** Frames player `p` waits after firing. */
|
|
13
|
+
export declare function fireCooldown(p: Shooter): number;
|
|
14
|
+
export declare function shotSpeed(p: Shooter): number;
|
|
15
|
+
export declare function shotRadius(p: Shooter): number;
|
|
16
|
+
/** Whether player `p` may fire now, with `live` of their shots still on the field. */
|
|
17
|
+
export declare function canFire(p: Shooter & Pick<Player, 'cd'>, live: number): boolean;
|
|
18
|
+
/** Damage shot `b` from a tank with `spec` does to `target`: a boss always loses exactly 1 per hit. */
|
|
19
|
+
export declare function enemyDamage(spec: TankSpec | undefined, b: Pick<Bullet, 'power'>, target: Enemy | Boss): number;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** Cloak frames a quiet stealthy tank keeps topping up; firing drops a cloak this short at once. */
|
|
2
|
+
export const STEALTH_CLOAK = 2;
|
|
3
|
+
/** Fewest frames between two shots of any tank, at any power level. */
|
|
4
|
+
export const MIN_COOLDOWN = 6;
|
|
5
|
+
/** Speed of a player shot in pixels per frame, before and from power level 2. */
|
|
6
|
+
const SHOT_SPEED = 4.6;
|
|
7
|
+
const FAST_SHOT_SPEED = 6.4;
|
|
8
|
+
const SHOT_RADIUS = 4;
|
|
9
|
+
const POWER_RADIUS = 5.5;
|
|
10
|
+
/** Shots one press of fire sends with `pattern`. */
|
|
11
|
+
export function volleySize(pattern = 'single') {
|
|
12
|
+
return pattern === 'fan3' ? 3 : pattern === 'single' ? 1 : 2;
|
|
13
|
+
}
|
|
14
|
+
/** Most of player `p`'s shots on the field at once: power level 3 adds room for one more volley. */
|
|
15
|
+
export function bulletCap(p) {
|
|
16
|
+
const volley = volleySize(p.spec.pattern);
|
|
17
|
+
return (p.spec.cap ?? volley * 2) + (p.up >= 3 ? volley : 0);
|
|
18
|
+
}
|
|
19
|
+
/** Frames player `p` waits after firing. */
|
|
20
|
+
export function fireCooldown(p) {
|
|
21
|
+
return Math.max(MIN_COOLDOWN, Math.round(p.spec.cd * (p.up >= 3 ? 0.65 : 1)));
|
|
22
|
+
}
|
|
23
|
+
export function shotSpeed(p) {
|
|
24
|
+
return (p.up >= 2 ? FAST_SHOT_SPEED : SHOT_SPEED) * (p.spec.shotSpeed ?? 1);
|
|
25
|
+
}
|
|
26
|
+
export function shotRadius(p) {
|
|
27
|
+
return p.spec.big || p.up >= 4 ? POWER_RADIUS : (p.spec.radius ?? SHOT_RADIUS);
|
|
28
|
+
}
|
|
29
|
+
/** Whether player `p` may fire now, with `live` of their shots still on the field. */
|
|
30
|
+
export function canFire(p, live) {
|
|
31
|
+
return p.cd <= 0 && live < bulletCap(p);
|
|
32
|
+
}
|
|
33
|
+
/** Damage shot `b` from a tank with `spec` does to `target`: a boss always loses exactly 1 per hit. */
|
|
34
|
+
export function enemyDamage(spec, b, target) {
|
|
35
|
+
if (target.boss) {
|
|
36
|
+
return 1;
|
|
37
|
+
}
|
|
38
|
+
return (spec?.dmg ?? 1) * (b.power ? 2 : 1);
|
|
39
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Cell } from './constants.ts';
|
|
2
|
+
import type { Game, Player } from './game-state.ts';
|
|
3
|
+
/** How close an enemy must be to see a cloaked player or one under a blanket. */
|
|
4
|
+
export declare const SIGHT = 60;
|
|
5
|
+
export declare function isActive(p: Player): boolean;
|
|
6
|
+
export declare function isCloaked(p: Player): boolean;
|
|
7
|
+
/** Whether a tank centred on (`cx`, `cy`) cannot see player `p`: cloaked or under a blanket, and not close by. */
|
|
8
|
+
export declare function hiddenFrom(g: Game, p: Player, cx: number, cy: number): boolean;
|
|
9
|
+
/** Players enemies may pick as a target to chase or shoot at. */
|
|
10
|
+
export declare function huntablePlayers(g: Game): Player[];
|
|
11
|
+
/** Whether some player is out there but cloaked, so enemies should search instead of turning on the puppy. */
|
|
12
|
+
export declare function someoneCloaked(g: Game): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Cells the hunters' distance field leads to. `keep` asks to keep the previous field: when every active player is
|
|
15
|
+
* hidden and at least one of them is cloaked, so a cloak never sends the hunters straight at the puppy.
|
|
16
|
+
*/
|
|
17
|
+
export declare function playerFieldSources(g: Game): {
|
|
18
|
+
cells: Cell[];
|
|
19
|
+
keep: boolean;
|
|
20
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { N, T } from "./constants.js";
|
|
2
|
+
/** How close an enemy must be to see a cloaked player or one under a blanket. */
|
|
3
|
+
export const SIGHT = 60;
|
|
4
|
+
export function isActive(p) {
|
|
5
|
+
return p.alive && !p.respawn;
|
|
6
|
+
}
|
|
7
|
+
export function isCloaked(p) {
|
|
8
|
+
return p.cloak > 0;
|
|
9
|
+
}
|
|
10
|
+
function cellOf(p) {
|
|
11
|
+
return [
|
|
12
|
+
Math.max(0, Math.min(N - 1, Math.floor((p.x + 13) / T))),
|
|
13
|
+
Math.max(0, Math.min(N - 1, Math.floor((p.y + 13) / T)))
|
|
14
|
+
];
|
|
15
|
+
}
|
|
16
|
+
function underBlanket(g, p) {
|
|
17
|
+
const [c, r] = cellOf(p);
|
|
18
|
+
return g.map[r][c] === 6;
|
|
19
|
+
}
|
|
20
|
+
/** Whether a tank centred on (`cx`, `cy`) cannot see player `p`: cloaked or under a blanket, and not close by. */
|
|
21
|
+
export function hiddenFrom(g, p, cx, cy) {
|
|
22
|
+
return (isCloaked(p) || underBlanket(g, p)) && Math.hypot(p.x + 13 - cx, p.y + 13 - cy) > SIGHT;
|
|
23
|
+
}
|
|
24
|
+
/** Players enemies may pick as a target to chase or shoot at. */
|
|
25
|
+
export function huntablePlayers(g) {
|
|
26
|
+
return g.players.filter(p => isActive(p) && !isCloaked(p));
|
|
27
|
+
}
|
|
28
|
+
/** Whether some player is out there but cloaked, so enemies should search instead of turning on the puppy. */
|
|
29
|
+
export function someoneCloaked(g) {
|
|
30
|
+
return g.players.some(p => isActive(p) && isCloaked(p));
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Cells the hunters' distance field leads to. `keep` asks to keep the previous field: when every active player is
|
|
34
|
+
* hidden and at least one of them is cloaked, so a cloak never sends the hunters straight at the puppy.
|
|
35
|
+
*/
|
|
36
|
+
export function playerFieldSources(g) {
|
|
37
|
+
const cells = huntablePlayers(g).map(cellOf).filter(([c, r]) => g.map[r][c] !== 6);
|
|
38
|
+
return { cells, keep: !cells.length && someoneCloaked(g) };
|
|
39
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maco-online/paint-tanks-rules",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "The pure Paint Tanks rules (simulation, levels, AI, wire protocol, prediction) and its Maco room definition",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
6
7
|
"repository": {
|
|
7
8
|
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/myangel26/maco-online.git"
|
|
9
|
+
"url": "git+https://github.com/myangel26/maco-online.git",
|
|
10
|
+
"directory": "games/paint-tanks"
|
|
11
|
+
},
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"maco": {
|
|
14
|
+
"protocolVersion": 2
|
|
15
|
+
},
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"default": "./dist/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./*": {
|
|
22
|
+
"types": "./dist/*.d.ts",
|
|
23
|
+
"default": "./dist/*.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@maco-online/online-core": "0.2.0"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"zod": "^4.1.12"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/node": "24.19.2",
|
|
37
|
+
"typescript": "5.9.3",
|
|
38
|
+
"vitest": "3.2.4",
|
|
39
|
+
"zod": "4.1.12"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "node ../../scripts/clean-build.mjs && tsc -p tsconfig.build.json",
|
|
43
|
+
"typecheck": "tsc --noEmit -p .",
|
|
44
|
+
"test": "pnpm build && vitest run"
|
|
9
45
|
}
|
|
10
|
-
}
|
|
46
|
+
}
|
package/README.md
DELETED