@xx_amaba_xx/robloxbot 0.1.2 → 0.3.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.
@@ -1,25 +1,29 @@
1
1
  /**
2
- * Movement actions — routed through the active transport.
3
- *
4
- * When RakNet isn't implemented (the common case today), movement still
5
- * updates the bot's local character state so position tracking works.
6
- * Set `simulationMode: true` in bot options to skip transport entirely
7
- * and run purely locally (useful for testing on Termux without RakNet).
2
+ * Movement actions — routed through the RakNet transport.
3
+ * Requires an active RakNet connection to the Roblox game server.
8
4
  */
9
5
 
10
6
  export class Movement {
11
- constructor(transport, character, options = {}) {
7
+ constructor(transport, character) {
12
8
  this.transport = transport;
13
9
  this.character = character;
14
- this.simulationMode = options.simulationMode || false;
15
10
  this._position = { x: 0, y: 0, z: 0 };
16
11
  this._velocity = { x: 0, y: 0, z: 0 };
17
-
18
- // Approximate studs per second for each direction (Roblox default walkspeed ~16 studs/s)
19
12
  this._studsPerSecond = 16;
20
13
  }
21
14
 
15
+ _requireTransport() {
16
+ if (!this.transport || !this.transport.connected) {
17
+ throw new Error("Movement requires an active RakNet transport connection. Call bot.start() first.");
18
+ }
19
+ if (!this.transport.send) {
20
+ throw new Error("Transport does not implement send(). Is RakNet transport active?");
21
+ }
22
+ }
23
+
22
24
  async walk(direction, duration = 1) {
25
+ this._requireTransport();
26
+
23
27
  const dir = String(direction).toLowerCase().trim();
24
28
  if (!["f", "b", "l", "r", "forward", "back", "left", "right"].includes(dir)) {
25
29
  throw new Error(`Invalid walk direction: ${direction}`);
@@ -39,41 +43,36 @@ export class Movement {
39
43
  const move = dirMap[dir];
40
44
  const distance = this._studsPerSecond * duration;
41
45
 
42
- // Try to send via transport if connected and not in simulation mode
43
- if (!this.simulationMode && this.transport && this.transport.connected && this.transport.send) {
44
- try {
45
- await this.transport.send({
46
- opcode: 0x84,
47
- type: "movement",
48
- direction: dir,
49
- duration,
50
- studs: distance,
51
- });
52
- } catch (err) {
53
- if (err.name === "NotImplementedError") {
54
- // RakNet not implemented — fall back to local simulation
55
- console.warn("[robloxbot] walk() falling back to local simulation: RakNet not implemented.");
56
- } else {
57
- throw err;
58
- }
59
- }
60
- } else if (!this.simulationMode) {
61
- console.warn("[robloxbot] walk() running in local simulation: no active transport.");
62
- }
63
-
64
- // Update local character state (works with or without RakNet)
46
+ // Update local position first (prediction)
65
47
  this._position.x += move.x * distance;
66
48
  this._position.z += move.z * distance;
67
49
  this.character.position = { ...this._position };
68
50
  this.character.alive = true;
69
51
 
52
+ // Send movement update packet (ROBLOX_MOVEMENT_UPDATE = 0x88)
53
+ await this.transport.send({
54
+ opcode: 0x88,
55
+ userId: this.character.userId || 0,
56
+ characterId: this.character.userId || 0,
57
+ position: { x: this._position.x, y: this._position.y, z: this._position.z },
58
+ velocity: { x: move.x * this._studsPerSecond, y: this._velocity.y, z: move.z * this._studsPerSecond },
59
+ cframe: {
60
+ position: { x: this._position.x, y: this._position.y, z: this._position.z },
61
+ rotation: { x: 0, y: 0, z: 0, w: 1 },
62
+ },
63
+ moveDirection: { x: move.x, y: 0, z: move.z },
64
+ isGrounded: true,
65
+ isJumping: false,
66
+ walkSpeed: this._studsPerSecond,
67
+ });
68
+
70
69
  return {
71
70
  direction: dir,
72
71
  duration,
73
72
  distance,
74
73
  position: { ...this._position },
75
- sent: !this.simulationMode && this.transport ? this.transport.connected : false,
76
- simulated: this.simulationMode || !this.transport?.connected,
74
+ sent: true,
75
+ simulated: false,
77
76
  };
78
77
  }
79
78
 
@@ -94,39 +93,59 @@ export class Movement {
94
93
  }
95
94
 
96
95
  async jump(count = 1, interval = 0) {
97
- if (!this.simulationMode && this.transport && this.transport.connected && this.transport.send) {
98
- try {
99
- await this.transport.send({
100
- opcode: 0x84,
101
- type: "jump",
102
- count,
103
- interval,
104
- });
105
- } catch (err) {
106
- if (err.name === "NotImplementedError") {
107
- console.warn("[robloxbot] jump() falling back to local simulation: RakNet not implemented.");
108
- } else {
109
- throw err;
110
- }
111
- }
112
- } else if (!this.simulationMode) {
113
- console.warn("[robloxbot] jump() running in local simulation: no active transport.");
114
- }
96
+ this._requireTransport();
115
97
 
116
- // Local jump simulation: briefly raise Y position then return
117
- const jumpHeight = 5; // studs
118
98
  for (let i = 0; i < count; i++) {
119
- this._position.y += jumpHeight;
99
+ // Jump up
100
+ this._position.y += 5;
101
+ this._velocity.y = 20;
120
102
  this.character.position = { ...this._position };
103
+
104
+ await this.transport.send({
105
+ opcode: 0x88,
106
+ userId: this.character.userId || 0,
107
+ characterId: this.character.userId || 0,
108
+ position: { x: this._position.x, y: this._position.y, z: this._position.z },
109
+ velocity: { x: this._velocity.x, y: this._velocity.y, z: this._velocity.z },
110
+ cframe: {
111
+ position: { x: this._position.x, y: this._position.y, z: this._position.z },
112
+ rotation: { x: 0, y: 0, z: 0, w: 1 },
113
+ },
114
+ moveDirection: { x: 0, y: 0, z: 0 },
115
+ isGrounded: false,
116
+ isJumping: true,
117
+ walkSpeed: this._studsPerSecond,
118
+ });
119
+
120
+ // Wait at peak
121
121
  if (i < count - 1 && interval > 0) {
122
122
  await new Promise((resolve) => setTimeout(resolve, interval * 1000));
123
123
  }
124
- this._position.y -= jumpHeight;
124
+
125
+ // Land
126
+ this._position.y -= 5;
127
+ this._velocity.y = 0;
125
128
  this.character.position = { ...this._position };
129
+
130
+ await this.transport.send({
131
+ opcode: 0x88,
132
+ userId: this.character.userId || 0,
133
+ characterId: this.character.userId || 0,
134
+ position: { x: this._position.x, y: this._position.y, z: this._position.z },
135
+ velocity: { x: 0, y: 0, z: 0 },
136
+ cframe: {
137
+ position: { x: this._position.x, y: this._position.y, z: this._position.z },
138
+ rotation: { x: 0, y: 0, z: 0, w: 1 },
139
+ },
140
+ moveDirection: { x: 0, y: 0, z: 0 },
141
+ isGrounded: true,
142
+ isJumping: false,
143
+ walkSpeed: this._studsPerSecond,
144
+ });
126
145
  }
127
- this.character.alive = true;
128
146
 
129
- return { count, interval, position: { ...this._position }, simulated: this.simulationMode || !this.transport?.connected };
147
+ this.character.alive = true;
148
+ return { count, interval, position: { ...this._position }, sent: true, simulated: false };
130
149
  }
131
150
 
132
151
  get position() {
@@ -144,4 +163,4 @@ export class Movement {
144
163
  }
145
164
  }
146
165
 
147
- export default Movement;
166
+ export default Movement;
@@ -54,8 +54,8 @@ export class SettingsPlugin {
54
54
  const save = async () => {
55
55
  if (saveFn) {
56
56
  await saveFn(all());
57
- } else if (typeof localStorage !== "undefined") {
58
- localStorage.setItem("robloxbot-settings", JSON.stringify(all()));
57
+ } else if (typeof globalThis !== "undefined" && globalThis.localStorage) {
58
+ globalThis.localStorage.setItem("robloxbot-settings", JSON.stringify(all()));
59
59
  }
60
60
  };
61
61
 
@@ -63,8 +63,8 @@ export class SettingsPlugin {
63
63
  let data = {};
64
64
  if (loadFn) {
65
65
  data = await loadFn();
66
- } else if (typeof localStorage !== "undefined") {
67
- const raw = localStorage.getItem("robloxbot-settings");
66
+ } else if (typeof globalThis !== "undefined" && globalThis.localStorage) {
67
+ const raw = globalThis.localStorage.getItem("robloxbot-settings");
68
68
  data = raw ? JSON.parse(raw) : {};
69
69
  }
70
70
  store.clear();
@@ -4,6 +4,8 @@
4
4
  * Defines the interface all transports (RakNet, web fallback) must implement.
5
5
  */
6
6
 
7
+ import { NotImplementedError } from "../exceptions.js";
8
+
7
9
  export class Transport {
8
10
  constructor() {
9
11
  this._connected = false;