ddbot.js-0374 4.4.3 → 4.4.4
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/lib/ddutils.js +22 -22
- package/lib/modules/snap.js +12 -5
- package/lib/types.d.ts +10 -10
- package/package.json +1 -1
package/lib/ddutils.js
CHANGED
|
@@ -18,39 +18,39 @@ function DefaultIdentity(name = 'nameless tee') {
|
|
|
18
18
|
*/
|
|
19
19
|
function reconstructPlayerInput(char, ddnetChar = null, tick = null) {
|
|
20
20
|
const input = {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
m_Direction: char.character_core.direction,
|
|
22
|
+
m_TargetX: 0,
|
|
23
|
+
m_TargetY: -1,
|
|
24
|
+
m_Jump: 0,
|
|
25
|
+
m_Fire: 0,
|
|
26
|
+
m_Hook: 0,
|
|
27
|
+
m_PlayerFlags: char.player_flags || 0,
|
|
28
|
+
m_WantedWeapon: char.weapon,
|
|
29
|
+
m_NextWeapon: 0,
|
|
30
|
+
m_PrevWeapon: 0
|
|
31
31
|
};
|
|
32
32
|
if (ddnetChar && (ddnetChar.m_TargetX !== 0 || ddnetChar.m_TargetY !== 0)) {
|
|
33
|
-
input.
|
|
34
|
-
input.
|
|
33
|
+
input.m_TargetX = ddnetChar.m_TargetX;
|
|
34
|
+
input.m_TargetY = ddnetChar.m_TargetY;
|
|
35
35
|
}
|
|
36
36
|
else {
|
|
37
37
|
const angleRad = (char.character_core.angle / 256.0) * Math.PI / 128.0;
|
|
38
|
-
input.
|
|
39
|
-
input.
|
|
38
|
+
input.m_TargetX = Math.cos(angleRad) * 256;
|
|
39
|
+
input.m_TargetY = Math.sin(angleRad) * 256;
|
|
40
40
|
}
|
|
41
|
-
if (input.
|
|
42
|
-
input.
|
|
41
|
+
if (input.m_TargetX === 0 && input.m_TargetY === 0) {
|
|
42
|
+
input.m_TargetY = -1;
|
|
43
43
|
}
|
|
44
44
|
const hookActive = char.character_core.hook_state !== 0 ||
|
|
45
45
|
char.character_core.hooked_player !== -1;
|
|
46
|
-
input.
|
|
46
|
+
input.m_Hook = hookActive ? 1 : 0;
|
|
47
47
|
const jumped = char.character_core.jumped;
|
|
48
48
|
const grounded = Math.abs(char.character_core.vel_y) < 1 && jumped === 0;
|
|
49
|
-
input.
|
|
49
|
+
input.m_Jump = jumped > 0 && !grounded ? 1 : 0;
|
|
50
50
|
const isNinja = ddnetChar != null && (ddnetChar.m_Flags & 0x20) !== 0;
|
|
51
|
-
input.
|
|
52
|
-
const isAutofireWeapon = [2, 3, 4].includes(input.
|
|
53
|
-
const isJetpackGun = input.
|
|
54
|
-
input.
|
|
51
|
+
input.m_WantedWeapon = isNinja ? 5 : char.weapon;
|
|
52
|
+
const isAutofireWeapon = [2, 3, 4].includes(input.m_WantedWeapon);
|
|
53
|
+
const isJetpackGun = input.m_WantedWeapon === 1 && ddnetChar?.m_Flags != null;
|
|
54
|
+
input.m_Fire = isAutofireWeapon || isJetpackGun ? 0 : 0;
|
|
55
55
|
return input;
|
|
56
56
|
}
|
package/lib/modules/snap.js
CHANGED
|
@@ -73,12 +73,19 @@ class Snap extends module_js_1.default {
|
|
|
73
73
|
return this._isFrozen;
|
|
74
74
|
}
|
|
75
75
|
lookatplayer(client_id) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
try {
|
|
77
|
+
const pl_character = this.bot.bot_client?.SnapshotUnpacker.getObjCharacter(client_id);
|
|
78
|
+
const own_character = this.bot.bot_client?.SnapshotUnpacker.getObjCharacter(this.bot.OwnID);
|
|
79
|
+
if (!pl_character || !own_character) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const angle = Math.atan2(pl_character.character_core.y - own_character.character_core.y, pl_character.character_core.x - own_character.character_core.x);
|
|
83
|
+
this.bot.send_input({ m_TargetX: Math.cos(angle) * 256, m_TargetY: Math.sin(angle) * 256 });
|
|
79
84
|
return;
|
|
80
|
-
|
|
81
|
-
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
82
89
|
}
|
|
83
90
|
_start() {
|
|
84
91
|
this.bot.on('snapshot', this.snapslistener);
|
package/lib/types.d.ts
CHANGED
|
@@ -3,16 +3,16 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export declare namespace SnapshotItemTypes {
|
|
5
5
|
interface PlayerInput {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
m_Direction: number;
|
|
7
|
+
m_TargetX: number;
|
|
8
|
+
m_TargetY: number;
|
|
9
|
+
m_Jump: number;
|
|
10
|
+
m_Fire: number;
|
|
11
|
+
m_Hook: number;
|
|
12
|
+
m_PlayerFlags: number;
|
|
13
|
+
m_WantedWeapon: number;
|
|
14
|
+
m_NextWeapon: number;
|
|
15
|
+
m_PrevWeapon: number;
|
|
16
16
|
}
|
|
17
17
|
interface iOptions {
|
|
18
18
|
identity?: Identity;
|