-
Notifications
You must be signed in to change notification settings - Fork 4
/
move-packet.ts
63 lines (57 loc) · 1.54 KB
/
move-packet.ts
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { Writer } from '../../writer';
import { Reader } from '../../reader';
import { PacketType } from '../../packet-type';
import { Packet } from '../../packet';
import { WorldPosData } from '../../data/world-pos-data';
import { MoveRecord } from '../../data/move-record';
/**
* Sent to acknowledge a `NewTickPacket`, and to notify the
* server of the client's current position and time.
*/
export class MovePacket implements Packet {
type = PacketType.MOVE;
propagate = true;
//#region packet-specific members
/**
* The tick id of the `NewTickPacket` which this is acknowledging.
*/
tickId: number;
/**
* The current client time.
*/
time: number;
/**
* The current client position.
*/
newPosition: WorldPosData;
/**
* The move records of the client.
*
* This property can be an empty array.
*/
records: MoveRecord[];
//#endregion
constructor() {
this.records = [];
}
write(writer: Writer): void {
writer.writeInt32(this.tickId);
writer.writeInt32(this.time);
this.newPosition.write(writer);
writer.writeShort(this.records.length);
for (const record of this.records) {
record.write(writer);
}
}
read(reader: Reader): void {
this.tickId = reader.readInt32();
this.time = reader.readInt32();
this.newPosition = new WorldPosData();
this.newPosition.read(reader);
this.records = new Array(reader.readShort());
for (let i = 0; i < this.records.length; i++) {
this.records[i] = new MoveRecord();
this.records[i].read(reader);
}
}
}