-
Notifications
You must be signed in to change notification settings - Fork 4
/
stat-data.ts
50 lines (46 loc) · 1.19 KB
/
stat-data.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
import { Writer } from '../writer';
import { Reader } from '../reader';
import { DataPacket } from '../packet';
import { StatType } from '../models/stat-type';
export class StatData implements DataPacket {
/**
* The type of stat.
*/
statType = 0;
/**
* The number value of this stat, if this is not a string stat.
*/
statValue: number;
/**
* The string value of this stat, if this is a string stat.
*/
stringStatValue: string;
read(reader: Reader): void {
this.statType = reader.readUnsignedByte();
if (this.isStringStat()) {
this.stringStatValue = reader.readString();
} else {
this.statValue = reader.readInt32();
}
}
write(writer: Writer): void {
writer.writeByte(this.statType);
if (this.isStringStat()) {
writer.writeString(this.stringStatValue);
} else {
writer.writeInt32(this.statValue);
}
}
private isStringStat(): boolean {
switch (this.statType) {
case StatType.NAME_STAT:
case StatType.GUILD_NAME_STAT:
case StatType.PET_NAME_STAT:
case StatType.ACCOUNT_ID_STAT:
case StatType.OWNER_ACCOUNT_ID_STAT:
return true;
default:
return false;
}
}
}