teeworlds 2.4.4 → 2.4.7

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,5 +1,6 @@
1
1
 
2
2
  import { MsgPacker } from "../MsgPacker";
3
+ import { PlayerInput, PlayerInfo, Projectile, Laser, Pickup, Flag, GameInfo, GameData, CharacterCore, Character, ClientInfo, SpectatorInfo, Common, Explosion, Spawn, HammerHit, Death, SoundGlobal, SoundWorld, DamageInd } from "../snapshots";
3
4
 
4
5
  import { Client } from "../client";
5
6
  enum NETMSGTYPE { EX, SV_MOTD, SV_BROADCAST, SV_CHAT, SV_KILLMSG, SV_SOUNDGLOBAL, SV_TUNEPARAMS, SV_EXTRAPROJECTILE, SV_READYTOENTER, SV_WEAPONPICKUP, SV_EMOTICON, SV_VOTECLEAROPTIONS, SV_VOTEOPTIONLISTADD, SV_VOTEOPTIONADD, SV_VOTEOPTIONREMOVE, SV_VOTESET, SV_VOTESTATUS, CL_SAY, CL_SETTEAM, CL_SETSPECTATORMODE, CL_STARTINFO, CL_CHANGEINFO, CL_KILL, CL_EMOTICON, CL_VOTE, CL_CALLVOTE, CL_ISDDNETLEGACY, SV_DDRACETIMELEGACY, SV_RECORDLEGACY, UNUSED, SV_TEAMSSTATELEGACY, CL_SHOWOTHERSLEGACY, NUM };
@@ -29,23 +30,26 @@ export class Game {
29
30
  this.send(packer);
30
31
  }
31
32
 
32
- /* Set the team of an bot. (-1 spectator team, 0 team red/normal team, 1 team blue) */
33
- SetTeam(team: number) {
33
+
34
+ /** Set the team of an bot. (-1 spectator team, 0 team red/normal team, 1 team blue) */
35
+ SetTeam(team: number) {
34
36
  var packer = new MsgPacker(NETMSGTYPE.CL_SETTEAM, false, 1);
35
37
  packer.AddInt(team);
36
38
  this.send(packer);
37
39
  }
38
40
 
39
- /* Spectate an player, taking their id as parameter. pretty useless */
40
- SpectatorMode(SpectatorID: number) {
41
+
42
+ /** Spectate an player, taking their id as parameter. pretty useless */
43
+ SpectatorMode(SpectatorID: number) {
41
44
  var packer = new MsgPacker(NETMSGTYPE.CL_SETSPECTATORMODE, false, 1);
42
45
  packer.AddInt(SpectatorID);
43
46
  this.send(packer);
44
47
  }
45
48
 
46
49
 
47
- /* Change the player info */
48
- ChangePlayerInfo(playerInfo: ClientInfo) {
50
+
51
+ /** Change the player info */
52
+ ChangePlayerInfo(playerInfo: ClientInfo) {
49
53
  var packer = new MsgPacker(NETMSGTYPE.CL_CHANGEINFO, false, 1);
50
54
  packer.AddString(playerInfo.name);
51
55
  packer.AddString(playerInfo.clan);
@@ -57,21 +61,24 @@ export class Game {
57
61
  this.send(packer);
58
62
  }
59
63
 
60
- /* Kill */
61
- Kill() {
64
+
65
+ /** Kill */
66
+ Kill() {
62
67
  var packer = new MsgPacker(NETMSGTYPE.CL_KILL, false, 1);
63
68
  this.send(packer);
64
69
  }
65
70
 
66
- /* Send emote */
67
- Emote(emote: number) {
71
+
72
+ /** Send emote */
73
+ Emote(emote: number) {
68
74
  var packer = new MsgPacker(NETMSGTYPE.CL_EMOTICON, false, 1);
69
75
  packer.AddInt(emote);
70
76
  this.send(packer);
71
77
  }
72
78
 
73
- /* Vote for an already running vote (f3 / f4) */
74
- Vote(vote: boolean) {
79
+
80
+ /** Vote for an already running vote (true = f3 / false = f4) */
81
+ Vote(vote: boolean) {
75
82
  var packer = new MsgPacker(NETMSGTYPE.CL_VOTE, false, 1);
76
83
  packer.AddInt(vote ? 1 : -1);
77
84
  this.send(packer);
@@ -84,27 +91,32 @@ export class Game {
84
91
  packer.AddString(Reason);
85
92
  this.send(packer);
86
93
  }
87
- /* Call a vote for an server option (for example ddnet maps) */
88
- CallVoteOption(Value: string, Reason: string) {
94
+
95
+ /** Call a vote for an server option (for example ddnet maps) */
96
+ CallVoteOption(Value: string, Reason: string) {
89
97
  this.CallVote("option", Value, Reason)
90
98
  }
91
- /* Call a vote to kick a player. Requires the player id */
92
- CallVoteKick(PlayerID: string|number, Reason: string) {
99
+
100
+ /** Call a vote to kick a player. Requires the player id */
101
+ CallVoteKick(PlayerID: string|number, Reason: string) {
93
102
  this.CallVote("kick", PlayerID, Reason)
94
103
  }
95
- /* Call a vote to set a player in spectator mode. Requires the player id */
96
- CallVoteSpectate(PlayerID: string|number, Reason: string) {
104
+
105
+ /** Call a vote to set a player in spectator mode. Requires the player id */
106
+ CallVoteSpectate(PlayerID: string|number, Reason: string) {
97
107
  this.CallVote("spectate", PlayerID, Reason)
98
108
  }
99
109
 
100
110
 
101
- /** probably some verification of using ddnet client.*/
111
+
112
+ /** probably some verification of using ddnet client. */
102
113
  IsDDNetLegacy() {
103
114
  var packer = new MsgPacker(NETMSGTYPE.CL_ISDDNETLEGACY, false, 1);
104
115
  this.send(packer);
105
116
  }
106
- /* returns the ping in ms */
107
- Ping(): Promise<number> {
117
+
118
+ /** returns the ping in ms (as a promise) */
119
+ Ping(): Promise<number> {
108
120
  return new Promise((resolve, reject) => {
109
121
  var packer = new MsgPacker(22, true, 0);
110
122
  let startTime = new Date().getTime();
@@ -40,6 +40,34 @@ var Movement = /** @class */ (function () {
40
40
  this.input.m_TargetX = x;
41
41
  this.input.m_TargetY = y;
42
42
  };
43
+ Movement.prototype.Flag = function (toggle, num) {
44
+ if (toggle) {
45
+ this.input.m_PlayerFlags |= num;
46
+ }
47
+ else {
48
+ this.input.m_PlayerFlags &= ~num;
49
+ }
50
+ };
51
+ Movement.prototype.FlagPlaying = function (toggle) {
52
+ if (toggle === void 0) { toggle = true; }
53
+ this.Flag(toggle, 1);
54
+ };
55
+ Movement.prototype.FlagInMenu = function (toggle) {
56
+ if (toggle === void 0) { toggle = true; }
57
+ this.Flag(toggle, 2);
58
+ };
59
+ Movement.prototype.FlagChatting = function (toggle) {
60
+ if (toggle === void 0) { toggle = true; }
61
+ this.Flag(toggle, 4);
62
+ };
63
+ Movement.prototype.FlagScoreboard = function (toggle) {
64
+ if (toggle === void 0) { toggle = true; }
65
+ this.Flag(toggle, 8);
66
+ };
67
+ Movement.prototype.FlagHookline = function (toggle) {
68
+ if (toggle === void 0) { toggle = true; }
69
+ this.Flag(toggle, 16);
70
+ };
43
71
  Movement.prototype.Reset = function () {
44
72
  this.input.m_Direction = 0;
45
73
  this.input.m_Jump = 0;
@@ -50,6 +50,31 @@ class Movement {
50
50
  this.input.m_TargetX = x;
51
51
  this.input.m_TargetY = y;
52
52
  }
53
+
54
+ private Flag(toggle: boolean, num: number) {
55
+ if (toggle) {
56
+ this.input.m_PlayerFlags |= num;
57
+ } else {
58
+ this.input.m_PlayerFlags &= ~num;
59
+
60
+ }
61
+ }
62
+ FlagPlaying(toggle = true) {
63
+ this.Flag(toggle, 1);
64
+ }
65
+ FlagInMenu(toggle = true) {
66
+ this.Flag(toggle, 2);
67
+ }
68
+ FlagChatting(toggle = true) {
69
+ this.Flag(toggle, 4);
70
+ }
71
+ FlagScoreboard(toggle = true) {
72
+ this.Flag(toggle, 8);
73
+ }
74
+ FlagHookline(toggle = true) {
75
+ this.Flag(toggle, 16);
76
+ }
77
+
53
78
  Reset() {
54
79
  this.input.m_Direction = 0;
55
80
  this.input.m_Jump = 0;
@@ -0,0 +1,258 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.SnapshotWrapper = void 0;
19
+ var stream_1 = require("stream");
20
+ var items;
21
+ (function (items) {
22
+ items[items["OBJ_EX"] = 0] = "OBJ_EX";
23
+ items[items["OBJ_PLAYER_INPUT"] = 1] = "OBJ_PLAYER_INPUT";
24
+ items[items["OBJ_PROJECTILE"] = 2] = "OBJ_PROJECTILE";
25
+ items[items["OBJ_LASER"] = 3] = "OBJ_LASER";
26
+ items[items["OBJ_PICKUP"] = 4] = "OBJ_PICKUP";
27
+ items[items["OBJ_FLAG"] = 5] = "OBJ_FLAG";
28
+ items[items["OBJ_GAME_INFO"] = 6] = "OBJ_GAME_INFO";
29
+ items[items["OBJ_GAME_DATA"] = 7] = "OBJ_GAME_DATA";
30
+ items[items["OBJ_CHARACTER_CORE"] = 8] = "OBJ_CHARACTER_CORE";
31
+ items[items["OBJ_CHARACTER"] = 9] = "OBJ_CHARACTER";
32
+ items[items["OBJ_PLAYER_INFO"] = 10] = "OBJ_PLAYER_INFO";
33
+ items[items["OBJ_CLIENT_INFO"] = 11] = "OBJ_CLIENT_INFO";
34
+ items[items["OBJ_SPECTATOR_INFO"] = 12] = "OBJ_SPECTATOR_INFO";
35
+ items[items["EVENT_COMMON"] = 13] = "EVENT_COMMON";
36
+ items[items["EVENT_EXPLOSION"] = 14] = "EVENT_EXPLOSION";
37
+ items[items["EVENT_SPAWN"] = 15] = "EVENT_SPAWN";
38
+ items[items["EVENT_HAMMERHIT"] = 16] = "EVENT_HAMMERHIT";
39
+ items[items["EVENT_DEATH"] = 17] = "EVENT_DEATH";
40
+ items[items["EVENT_SOUND_GLOBAL"] = 18] = "EVENT_SOUND_GLOBAL";
41
+ items[items["EVENT_SOUND_WORLD"] = 19] = "EVENT_SOUND_WORLD";
42
+ items[items["EVENT_DAMAGE_INDICATOR"] = 20] = "EVENT_DAMAGE_INDICATOR";
43
+ })(items || (items = {}));
44
+ var SnapshotWrapper = /** @class */ (function (_super) {
45
+ __extends(SnapshotWrapper, _super);
46
+ function SnapshotWrapper(_client) {
47
+ var _this =
48
+ // this.SendMsgEx = callback;
49
+ _super.call(this) || this;
50
+ _this._client = _client;
51
+ return _this;
52
+ }
53
+ SnapshotWrapper.prototype.getParsed = function (type_id, id) {
54
+ var _a;
55
+ if (type_id == -1)
56
+ return undefined;
57
+ return (_a = this._client.rawSnapUnpacker.deltas.find(function (delta) { return delta.type_id == type_id && delta.id == id; })) === null || _a === void 0 ? void 0 : _a.parsed;
58
+ };
59
+ SnapshotWrapper.prototype.getAll = function (type_id) {
60
+ var _all = [];
61
+ if (type_id == -1)
62
+ return _all;
63
+ this._client.rawSnapUnpacker.deltas.forEach(function (delta) {
64
+ if (delta.type_id == type_id)
65
+ _all.push(delta.parsed);
66
+ });
67
+ return _all;
68
+ // return this._client.rawSnapUnpacker.deltas.filter(delta => delta.type_id == type_id && delta.id == id).map(a => a.parsed);
69
+ };
70
+ SnapshotWrapper.prototype.getObjPlayerInput = function (player_id) {
71
+ return this.getParsed(items.OBJ_PLAYER_INPUT, player_id);
72
+ };
73
+ Object.defineProperty(SnapshotWrapper.prototype, "AllObjPlayerInput", {
74
+ get: function () {
75
+ return this.getAll(items.OBJ_PLAYER_INPUT);
76
+ },
77
+ enumerable: false,
78
+ configurable: true
79
+ });
80
+ SnapshotWrapper.prototype.getObjProjectile = function (id) {
81
+ return this.getParsed(items.OBJ_PROJECTILE, id);
82
+ };
83
+ Object.defineProperty(SnapshotWrapper.prototype, "AllProjectiles", {
84
+ get: function () {
85
+ return this.getAll(items.OBJ_PROJECTILE);
86
+ },
87
+ enumerable: false,
88
+ configurable: true
89
+ });
90
+ SnapshotWrapper.prototype.getObjLaser = function (id) {
91
+ return this.getParsed(items.OBJ_LASER, id);
92
+ };
93
+ Object.defineProperty(SnapshotWrapper.prototype, "AllObjLaser", {
94
+ get: function () {
95
+ return this.getAll(items.OBJ_LASER);
96
+ },
97
+ enumerable: false,
98
+ configurable: true
99
+ });
100
+ SnapshotWrapper.prototype.getObjPickup = function (id) {
101
+ return this.getParsed(items.OBJ_PICKUP, id);
102
+ };
103
+ Object.defineProperty(SnapshotWrapper.prototype, "AllObjPickup", {
104
+ get: function () {
105
+ return this.getAll(items.OBJ_PICKUP);
106
+ },
107
+ enumerable: false,
108
+ configurable: true
109
+ });
110
+ SnapshotWrapper.prototype.getObjFlag = function (id) {
111
+ return this.getParsed(items.OBJ_FLAG, id);
112
+ };
113
+ Object.defineProperty(SnapshotWrapper.prototype, "AllObjFlag", {
114
+ get: function () {
115
+ return this.getAll(items.OBJ_FLAG);
116
+ },
117
+ enumerable: false,
118
+ configurable: true
119
+ });
120
+ SnapshotWrapper.prototype.getObjGameInfo = function (id) {
121
+ return this.getParsed(items.OBJ_GAME_INFO, id);
122
+ };
123
+ Object.defineProperty(SnapshotWrapper.prototype, "AllObjGameInfo", {
124
+ get: function () {
125
+ return this.getAll(items.OBJ_GAME_INFO);
126
+ },
127
+ enumerable: false,
128
+ configurable: true
129
+ });
130
+ SnapshotWrapper.prototype.getObjGameData = function (id) {
131
+ return this.getParsed(items.OBJ_GAME_DATA, id);
132
+ };
133
+ Object.defineProperty(SnapshotWrapper.prototype, "AllObjGameData", {
134
+ get: function () {
135
+ return this.getAll(items.OBJ_GAME_DATA);
136
+ },
137
+ enumerable: false,
138
+ configurable: true
139
+ });
140
+ /** NOTICE: x & y positions always differ from the positions in the ingame debug menu. If you want the debug menu positions, you can calculate them like this: Math.round((myChar.character_core.x / 32) * 100)/100 */
141
+ SnapshotWrapper.prototype.getObjCharacterCore = function (player_id) {
142
+ return this.getParsed(items.OBJ_CHARACTER_CORE, player_id);
143
+ };
144
+ Object.defineProperty(SnapshotWrapper.prototype, "AllObjCharacterCore", {
145
+ /** NOTICE: x & y positions always differ from the positions in the ingame debug menu. If you want the debug menu positions, you can calculate them like this: Math.round((myChar.character_core.x / 32) * 100)/100 */
146
+ get: function () {
147
+ return this.getAll(items.OBJ_CHARACTER_CORE);
148
+ },
149
+ enumerable: false,
150
+ configurable: true
151
+ });
152
+ /** NOTICE: x & y positions always differ from the positions in the ingame debug menu. If you want the debug menu positions, you can calculate them like this: Math.round((myChar.character_core.x / 32) * 100)/100 */
153
+ SnapshotWrapper.prototype.getObjCharacter = function (player_id) {
154
+ return this.getParsed(items.OBJ_CHARACTER, player_id);
155
+ };
156
+ Object.defineProperty(SnapshotWrapper.prototype, "AllObjCharacter", {
157
+ /** NOTICE: x & y positions always differ from the positions in the ingame debug menu. If you want the debug menu positions, you can calculate them like this: Math.round((myChar.character_core.x / 32) * 100)/100 */
158
+ get: function () {
159
+ return this.getAll(items.OBJ_CHARACTER);
160
+ },
161
+ enumerable: false,
162
+ configurable: true
163
+ });
164
+ SnapshotWrapper.prototype.getObjPlayerInfo = function (player_id) {
165
+ return this.getParsed(items.OBJ_PLAYER_INFO, player_id);
166
+ };
167
+ Object.defineProperty(SnapshotWrapper.prototype, "AllObjPlayerInfo", {
168
+ get: function () {
169
+ return this.getAll(items.OBJ_PLAYER_INFO);
170
+ },
171
+ enumerable: false,
172
+ configurable: true
173
+ });
174
+ SnapshotWrapper.prototype.getObjClientInfo = function (player_id) {
175
+ return this.getParsed(items.OBJ_CLIENT_INFO, player_id);
176
+ };
177
+ Object.defineProperty(SnapshotWrapper.prototype, "AllObjClientInfo", {
178
+ get: function () {
179
+ return this.getAll(items.OBJ_CLIENT_INFO);
180
+ },
181
+ enumerable: false,
182
+ configurable: true
183
+ });
184
+ SnapshotWrapper.prototype.getObjSpectatorInfo = function (player_id) {
185
+ return this.getParsed(items.OBJ_SPECTATOR_INFO, player_id);
186
+ };
187
+ Object.defineProperty(SnapshotWrapper.prototype, "AllObjSpectatorInfo", {
188
+ get: function () {
189
+ return this.getAll(items.OBJ_SPECTATOR_INFO);
190
+ },
191
+ enumerable: false,
192
+ configurable: true
193
+ });
194
+ SnapshotWrapper.prototype.getTypeId = function (name) {
195
+ var _a;
196
+ return ((_a = this._client.rawSnapUnpacker.uuid_manager.LookupName(name)) === null || _a === void 0 ? void 0 : _a.type_id) || -1;
197
+ };
198
+ SnapshotWrapper.prototype.getObjExMyOwnObject = function (id) {
199
+ return this.getParsed(this.getTypeId("my-own-object@heinrich5991.de"), id);
200
+ };
201
+ Object.defineProperty(SnapshotWrapper.prototype, "AllObjExMyOwnObject", {
202
+ get: function () {
203
+ return this.getAll(this.getTypeId("my-own-object@heinrich5991.de"));
204
+ },
205
+ enumerable: false,
206
+ configurable: true
207
+ });
208
+ SnapshotWrapper.prototype.getObjExDDNetCharacter = function (id) {
209
+ return this.getParsed(this.getTypeId("character@netobj.ddnet.tw"), id);
210
+ };
211
+ Object.defineProperty(SnapshotWrapper.prototype, "AllObjExDDNetCharacter", {
212
+ get: function () {
213
+ return this.getAll(this.getTypeId("character@netobj.ddnet.tw"));
214
+ },
215
+ enumerable: false,
216
+ configurable: true
217
+ });
218
+ SnapshotWrapper.prototype.getObjExGameInfo = function (id) {
219
+ return this.getParsed(this.getTypeId("gameinfo@netobj.ddnet.tw"), id);
220
+ };
221
+ Object.defineProperty(SnapshotWrapper.prototype, "AllObjExGameInfo", {
222
+ get: function () {
223
+ return this.getAll(this.getTypeId("gameinfo@netobj.ddnet.tw"));
224
+ },
225
+ enumerable: false,
226
+ configurable: true
227
+ });
228
+ SnapshotWrapper.prototype.getObjExDDNetProjectile = function (id) {
229
+ return this.getParsed(this.getTypeId("projectile@netobj.ddnet.tw"), id);
230
+ };
231
+ Object.defineProperty(SnapshotWrapper.prototype, "AllObjExDDNetProjectile", {
232
+ get: function () {
233
+ return this.getAll(this.getTypeId("projectile@netobj.ddnet.tw"));
234
+ },
235
+ enumerable: false,
236
+ configurable: true
237
+ });
238
+ SnapshotWrapper.prototype.getObjExLaser = function (id) {
239
+ return this.getParsed(this.getTypeId("laser@netobj.ddnet.tw"), id);
240
+ };
241
+ Object.defineProperty(SnapshotWrapper.prototype, "AllObjExLaser", {
242
+ get: function () {
243
+ return this.getAll(this.getTypeId("laser@netobj.ddnet.tw"));
244
+ },
245
+ enumerable: false,
246
+ configurable: true
247
+ });
248
+ Object.defineProperty(SnapshotWrapper.prototype, "OwnID", {
249
+ get: function () {
250
+ var _a;
251
+ return (_a = this.AllObjPlayerInfo.find(function (parsed) { return parsed.local; })) === null || _a === void 0 ? void 0 : _a.client_id;
252
+ },
253
+ enumerable: false,
254
+ configurable: true
255
+ });
256
+ return SnapshotWrapper;
257
+ }(stream_1.EventEmitter));
258
+ exports.SnapshotWrapper = SnapshotWrapper;
@@ -0,0 +1,219 @@
1
+
2
+ import { Client } from "../client";
3
+ import { EventEmitter } from "stream";
4
+ import { PlayerInput, PlayerInfo, Projectile, Laser, Pickup, Flag, GameInfo, GameData, CharacterCore, Character, ClientInfo, SpectatorInfo, Common, Explosion, Spawn, HammerHit, Death, SoundGlobal, SoundWorld, DamageInd, MyOwnObject, DDNetCharacter, DDNetProjectile, DDNetLaser, GameInfoEx } from "../snapshots";
5
+
6
+ enum items {
7
+ OBJ_EX,
8
+ OBJ_PLAYER_INPUT,
9
+ OBJ_PROJECTILE,
10
+ OBJ_LASER,
11
+ OBJ_PICKUP,
12
+ OBJ_FLAG,
13
+ OBJ_GAME_INFO,
14
+ OBJ_GAME_DATA,
15
+ OBJ_CHARACTER_CORE,
16
+ OBJ_CHARACTER,
17
+ OBJ_PLAYER_INFO,
18
+ OBJ_CLIENT_INFO,
19
+ OBJ_SPECTATOR_INFO,
20
+ EVENT_COMMON,
21
+ EVENT_EXPLOSION,
22
+ EVENT_SPAWN,
23
+ EVENT_HAMMERHIT,
24
+ EVENT_DEATH,
25
+ EVENT_SOUND_GLOBAL,
26
+ EVENT_SOUND_WORLD,
27
+ EVENT_DAMAGE_INDICATOR
28
+ }
29
+ export declare interface SnapshotWrapper {
30
+
31
+
32
+ // on(event: 'connected', listener: () => void): this;
33
+ // on(event: 'disconnect', listener: (reason: string) => void): this;
34
+
35
+ // on(event: 'emote', listener: (message: iEmoticon) => void): this;
36
+ // on(event: 'message', listener: (message: iMessage) => void): this;
37
+ // on(event: 'broadcast', listener: (message: string) => void): this;
38
+ // on(event: 'kill', listener: (kill: iKillMsg) => void): this;
39
+ // on(event: 'motd', listener: (message: string) => void): this;
40
+
41
+ on(event: 'common', listener: (common: Common) => void): this;
42
+ on(event: 'explosion', listener: (explosion: Explosion) => void): this;
43
+ on(event: 'spawn', listener: (spawn: Spawn) => void): this;
44
+ on(event: 'hammerhit', listener: (hammerhit: HammerHit) => void): this;
45
+ on(event: 'death', listener: (death: Death) => void): this;
46
+ on(event: 'sound_global', listener: (sound_global: SoundGlobal) => void): this;
47
+ on(event: 'sound_world', listener: (sound_world: SoundWorld) => void): this;
48
+ on(event: 'damage_indicator', listener: (damage_indicator: DamageInd) => void): this;
49
+
50
+ }
51
+
52
+ export class SnapshotWrapper extends EventEmitter {
53
+ private _client: Client;
54
+ constructor(_client: Client) {
55
+ // this.SendMsgEx = callback;
56
+ super();
57
+ this._client = _client;
58
+ }
59
+
60
+ private getParsed<T>(type_id: number, id: number) {
61
+ if (type_id == -1)
62
+ return undefined;
63
+ return this._client.rawSnapUnpacker.deltas.find(delta => delta.type_id == type_id && delta.id == id)?.parsed as unknown as T;
64
+ }
65
+
66
+ private getAll<T>(type_id: number): T[] {
67
+ let _all: T[] = [];
68
+ if (type_id == -1)
69
+ return _all;
70
+ this._client.rawSnapUnpacker.deltas.forEach(delta => {
71
+ if (delta.type_id == type_id)
72
+ _all.push(delta.parsed as T);
73
+ })
74
+
75
+
76
+ return _all;
77
+ // return this._client.rawSnapUnpacker.deltas.filter(delta => delta.type_id == type_id && delta.id == id).map(a => a.parsed);
78
+ }
79
+
80
+ getObjPlayerInput(player_id: number): PlayerInput | undefined {
81
+ return this.getParsed(items.OBJ_PLAYER_INPUT, player_id);
82
+ }
83
+
84
+ get AllObjPlayerInput(): PlayerInput[] {
85
+ return this.getAll(items.OBJ_PLAYER_INPUT);
86
+ }
87
+
88
+ getObjProjectile(id: number): Projectile | undefined {
89
+ return this.getParsed(items.OBJ_PROJECTILE, id);
90
+ }
91
+ get AllProjectiles(): Projectile[] {
92
+ return this.getAll(items.OBJ_PROJECTILE);
93
+ }
94
+
95
+ getObjLaser(id: number): Laser | undefined {
96
+ return this.getParsed(items.OBJ_LASER, id);
97
+ }
98
+ get AllObjLaser(): Laser[] {
99
+ return this.getAll(items.OBJ_LASER);
100
+ }
101
+
102
+ getObjPickup(id: number): Pickup | undefined {
103
+ return this.getParsed(items.OBJ_PICKUP, id);
104
+ }
105
+ get AllObjPickup(): Pickup[] {
106
+ return this.getAll(items.OBJ_PICKUP);
107
+ }
108
+
109
+ getObjFlag(id: number): Flag | undefined {
110
+ return this.getParsed(items.OBJ_FLAG, id);
111
+ }
112
+ get AllObjFlag(): Flag[] {
113
+ return this.getAll(items.OBJ_FLAG);
114
+ }
115
+
116
+ getObjGameInfo(id: number): GameInfo | undefined {
117
+ return this.getParsed(items.OBJ_GAME_INFO, id);
118
+ }
119
+ get AllObjGameInfo(): GameInfo[] {
120
+ return this.getAll(items.OBJ_GAME_INFO);
121
+ }
122
+
123
+ getObjGameData(id: number): GameData | undefined {
124
+ return this.getParsed(items.OBJ_GAME_DATA, id);
125
+ }
126
+ get AllObjGameData(): GameData[] {
127
+ return this.getAll(items.OBJ_GAME_DATA);
128
+ }
129
+
130
+ /** NOTICE: x & y positions always differ from the positions in the ingame debug menu. If you want the debug menu positions, you can calculate them like this: Math.round((myChar.character_core.x / 32) * 100)/100 */
131
+ getObjCharacterCore(player_id: number): CharacterCore | undefined {
132
+ return this.getParsed(items.OBJ_CHARACTER_CORE, player_id);
133
+ }
134
+ /** NOTICE: x & y positions always differ from the positions in the ingame debug menu. If you want the debug menu positions, you can calculate them like this: Math.round((myChar.character_core.x / 32) * 100)/100 */
135
+ get AllObjCharacterCore(): CharacterCore[] {
136
+ return this.getAll(items.OBJ_CHARACTER_CORE);
137
+ }
138
+
139
+ /** NOTICE: x & y positions always differ from the positions in the ingame debug menu. If you want the debug menu positions, you can calculate them like this: Math.round((myChar.character_core.x / 32) * 100)/100 */
140
+ getObjCharacter(player_id: number): Character | undefined {
141
+ return this.getParsed(items.OBJ_CHARACTER, player_id);
142
+ }
143
+ /** NOTICE: x & y positions always differ from the positions in the ingame debug menu. If you want the debug menu positions, you can calculate them like this: Math.round((myChar.character_core.x / 32) * 100)/100 */
144
+ get AllObjCharacter(): Character[] {
145
+
146
+ return this.getAll(items.OBJ_CHARACTER);
147
+ }
148
+
149
+ getObjPlayerInfo(player_id: number): PlayerInfo | undefined {
150
+ return this.getParsed(items.OBJ_PLAYER_INFO, player_id);
151
+ }
152
+ get AllObjPlayerInfo(): PlayerInfo[] {
153
+ return this.getAll(items.OBJ_PLAYER_INFO);
154
+ }
155
+
156
+ getObjClientInfo(player_id: number): ClientInfo | undefined {
157
+ return this.getParsed(items.OBJ_CLIENT_INFO, player_id);
158
+ }
159
+ get AllObjClientInfo(): ClientInfo[] {
160
+ return this.getAll(items.OBJ_CLIENT_INFO);
161
+ }
162
+
163
+ getObjSpectatorInfo(player_id: number): SpectatorInfo | undefined {
164
+ return this.getParsed(items.OBJ_SPECTATOR_INFO, player_id);
165
+ }
166
+ get AllObjSpectatorInfo(): SpectatorInfo[] {
167
+ return this.getAll(items.OBJ_SPECTATOR_INFO);
168
+ }
169
+
170
+ private getTypeId(name: string) {
171
+ return this._client.rawSnapUnpacker.uuid_manager.LookupName(name)?.type_id || -1;
172
+ }
173
+
174
+ getObjExMyOwnObject(id: number): MyOwnObject | undefined {
175
+ return this.getParsed(this.getTypeId("my-own-object@heinrich5991.de"), id);
176
+ }
177
+ get AllObjExMyOwnObject(): MyOwnObject[] {
178
+ return this.getAll(this.getTypeId("my-own-object@heinrich5991.de"));
179
+ }
180
+
181
+ getObjExDDNetCharacter(id: number): DDNetCharacter | undefined {
182
+ return this.getParsed(this.getTypeId("character@netobj.ddnet.tw"), id);
183
+ }
184
+ get AllObjExDDNetCharacter(): DDNetCharacter[] {
185
+ return this.getAll(this.getTypeId("character@netobj.ddnet.tw"));
186
+ }
187
+
188
+ getObjExGameInfo(id: number): GameInfoEx | undefined {
189
+ return this.getParsed(this.getTypeId("gameinfo@netobj.ddnet.tw"), id);
190
+ }
191
+ get AllObjExGameInfo(): GameInfoEx[] {
192
+ return this.getAll(this.getTypeId("gameinfo@netobj.ddnet.tw"));
193
+ }
194
+
195
+ getObjExDDNetProjectile(id: number): DDNetProjectile | undefined {
196
+ return this.getParsed(this.getTypeId("projectile@netobj.ddnet.tw"), id);
197
+ }
198
+ get AllObjExDDNetProjectile(): DDNetProjectile[] {
199
+ return this.getAll(this.getTypeId("projectile@netobj.ddnet.tw"));
200
+ }
201
+
202
+ getObjExLaser(id: number): DDNetLaser | undefined {
203
+ return this.getParsed(this.getTypeId("laser@netobj.ddnet.tw"), id);
204
+ }
205
+ get AllObjExLaser(): DDNetLaser[] {
206
+ return this.getAll(this.getTypeId("laser@netobj.ddnet.tw"));
207
+ }
208
+
209
+
210
+
211
+
212
+
213
+ get OwnID(): number | undefined {
214
+ return this.AllObjPlayerInfo.find(parsed => parsed.local)?.client_id;
215
+ }
216
+
217
+
218
+
219
+ }