| 387 | const HZ = 20; |
| 388 | |
| 389 | class MousePosFaker { |
| 390 | constructor(puzzleX) { |
| 391 | this.x = parseInt(Math.random() * 20 + 20, 10); |
| 392 | this.y = parseInt(Math.random() * 80 + 80, 10); |
| 393 | this.t = Date.now(); |
| 394 | this.pos = [[this.x, this.y, this.t]]; |
| 395 | this.minDuration = parseInt(1000 / HZ, 10); |
| 396 | // this.puzzleX = puzzleX; |
| 397 | this.puzzleX = puzzleX + parseInt(Math.random() * 2 - 1, 10); |
| 398 | |
| 399 | this.STEP = parseInt(Math.random() * 6 + 5, 10); |
| 400 | this.DURATION = parseInt(Math.random() * 7 + 14, 10) * 100; |
| 401 | // [9,1600] [10,1400] |
| 402 | this.STEP = 9; |
| 403 | // this.DURATION = 2000; |
| 404 | console.log(this.STEP, this.DURATION); |
| 405 | } |
| 406 | |
| 407 | run() { |
| 408 | const perX = this.puzzleX / this.STEP; |
| 409 | const perDuration = this.DURATION / this.STEP; |
| 410 | const firstPos = [this.x - parseInt(Math.random() * 6, 10), this.y + parseInt(Math.random() * 11, 10), this.t]; |
| 411 | |
| 412 | this.pos.unshift(firstPos); |
| 413 | this.stepPos(perX, perDuration); |
| 414 | this.fixPos(); |
| 415 | |
| 416 | const reactTime = parseInt(60 + Math.random() * 100, 10); |
| 417 | const lastIdx = this.pos.length - 1; |
| 418 | const lastPos = [this.pos[lastIdx][0], this.pos[lastIdx][1], this.pos[lastIdx][2] + reactTime]; |
| 419 | |
| 420 | this.pos.push(lastPos); |
| 421 | return this.pos; |
| 422 | } |
| 423 | |
| 424 | stepPos(x, duration) { |
| 425 | let n = 0; |
| 426 | const sqrt2 = Math.sqrt(2); |
| 427 | for (let i = 1; i <= this.STEP; i++) { |
| 428 | n += 1 / i; |
| 429 | } |
| 430 | for (let i = 0; i < this.STEP; i++) { |
| 431 | x = this.puzzleX / (n * (i + 1)); |
| 432 | const currX = parseInt((Math.random() * 30 - 15) + x, 10); |
| 433 | const currY = parseInt(Math.random() * 7 - 3, 10); |
| 434 | const currDuration = parseInt((Math.random() * 0.4 + 0.8) * duration, 10); |
| 435 | |
| 436 | this.moveToAndCollect({ |
| 437 | x: currX, |
| 438 | y: currY, |
| 439 | duration: currDuration, |
| 440 | }); |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | fixPos() { |
| 445 | const actualX = this.pos[this.pos.length - 1][0] - this.pos[1][0]; |
| 446 | const deviation = this.puzzleX - actualX; |
nothing calls this directly
no outgoing calls
no test coverage detected