-
Notifications
You must be signed in to change notification settings - Fork 4
/
enemy-shoot-packet.ts
80 lines (75 loc) · 2.01 KB
/
enemy-shoot-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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { Writer } from '../../writer';
import { Reader } from '../../reader';
import { PacketType } from '../../packet-type';
import { Packet } from '../../packet';
import { WorldPosData } from '../../data/world-pos-data';
/**
* Received when a visible enemy shoots a projectile.
*/
export class EnemyShootPacket implements Packet {
type = PacketType.ENEMYSHOOT;
propagate = true;
//#region packet-specific members
/**
* The id of the bullet which was fired.
*/
bulletId: number;
/**
* The object id of the enemy which fired the projectile.
*/
ownerId: number;
/**
* The local identifier of the projectile.
* @see `ProjectileInfo.id`
*/
bulletType: number;
/**
* The position at which the projectile was fired.
*/
startingPos: WorldPosData;
/**
* The angle at which the projectile was fired.
*/
angle: number;
/**
* The damage which the projectile will cause.
*/
damage: number;
/**
* The number of projeciles fired.
*/
numShots: number;
/**
* The angle in degrees between the projectiles if `numShots > 1`.
*/
angleInc: number;
//#endregion
read(reader: Reader): void {
this.bulletId = reader.readUnsignedByte();
this.ownerId = reader.readInt32();
this.bulletType = reader.readUnsignedByte();
this.startingPos = new WorldPosData();
this.startingPos.read(reader);
this.angle = reader.readFloat();
this.damage = reader.readShort();
if (reader.index < reader.length) {
this.numShots = reader.readUnsignedByte();
this.angleInc = reader.readFloat();
} else {
this.numShots = 1;
this.angleInc = 0;
}
}
write(writer: Writer): void {
writer.writeUnsignedByte(this.bulletId);
writer.writeInt32(this.ownerId);
writer.writeUnsignedByte(this.bulletType);
this.startingPos.write(writer);
writer.writeFloat(this.angle);
writer.writeShort(this.damage);
if (this.numShots !== 1) {
writer.writeUnsignedByte(this.numShots);
writer.writeFloat(this.angleInc);
}
}
}