-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnpc-dev.js
40 lines (35 loc) · 1.22 KB
/
npc-dev.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { WebSocket } from 'ws';
import { WarpFactory } from 'warp-contracts';
import Const from './src/game/common/const.mjs';
import { mockDataItem } from './tools/common.mjs';
const direction = Object.values(Const.Direction);
const characters = ['hacker_beaver', 'speedy_beaver', 'heavy_beaver'];
export default async function runNpc() {
const ws = new WebSocket('ws://localhost:8097');
ws.addEventListener('open', async () => {
for (let i = 0; i < 29; i++) {
const warp = WarpFactory.forMainnet();
const { address } = await warp.generateWallet();
ws.send(
JSON.stringify(
mockDataItem(
{
cmd: Const.Command.register,
beaverId: characters[Math.floor(Math.random() * characters.length)],
},
address
)
)
);
setTimeout(() => {
// setInterval(() => {
const randomDirection = Math.floor(Math.random() * direction.length);
const di = mockDataItem({ cmd: 'move', dir: direction[randomDirection] }, address);
ws.send(JSON.stringify(di));
// }, 2000);
}, 300);
console.log(`NPC ${address} in the game.`);
}
});
}
runNpc().catch((e) => console.error(e));